feat: serve markdown to agents via Accept header negotiation - #1332
feat: serve markdown to agents via Accept header negotiation#1332devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Signed-off-by: Ramiro Berrelleza <rberrelleza@gmail.com> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Signed-off-by: Ramiro Berrelleza <rberrelleza@gmail.com> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Original prompt from Ramiro
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
✅ Deploy Preview for okteto-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Summary
Agents asking for
Accept: text/markdowngot HTML back, even though@signalwire/docusaurus-plugin-llms-txtalready emits a markdown twin for every page (/docs/reference/okteto-manifest/→/docs/reference/okteto-manifest.md). This adds a Netlify Edge Function that serves the twin when markdown is explicitly preferred, leaving HTML as the default for browsers.Cloudflare's Markdown for Agents doesn't apply — the site is served by Netlify — and Netlify
[[redirects]]can't branch on a request header, so the negotiation lives innetlify/edge-functions/markdown-negotiation.js:Details worth knowing:
acceptsMarkdowncompares q-values:text/markdownmust be listed explicitly and rank at least as high astext/html,application/xhtml+xml, or*/*, so a browser'stext/html,...,*/*;q=0.8keeps getting HTML./docs/1.47/...) hit this path by design, sinceincludeVersionedDocs: falsemeans they have no twins.Vary: Acceptis set on both branches so caches don't cross-serve HTML and markdown.x-markdown-tokensis a deterministiclength / 4estimate (no tokenizer dependency at the edge), and is omitted forHEADwhere there is no body.Content-Length/Content-Encoding/Transfer-Encodingare stripped because the body is re-serialized, andexcludedPatternuses RE2-safe regexes (Netlify compiles these with Go's regexp — no lookaheads).Verified locally against the built site with the Netlify edge runtime: markdown Accept on
/docs/and/docs/reference/okteto-manifest/returnstext/markdown+x-markdown-tokens, browser-like Accept returnstext/html, and a versioned path stays HTML.yarn buildpasses.Link to Devin session: https://app.devin.ai/sessions/7151c6c899e64895a9eec5f436cc7354
Requested by: @rberrelleza