-
Notifications
You must be signed in to change notification settings - Fork 336
fix(developer-hub): address agent-friendly docs check failures #3704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { NextResponse } from "next/server"; | ||
| import type { NextRequest } from "next/server"; | ||
|
|
||
| const SKIP_PREFIXES = [ | ||
| "/_next", | ||
| "/api", | ||
| "/playground", | ||
| "/mdx", | ||
| ]; | ||
|
|
||
| const SKIP_EXACT = new Set([ | ||
| "/", | ||
| "/favicon.ico", | ||
| "/robots.txt", | ||
| "/sitemap.xml", | ||
| "/llms.txt", | ||
| "/llms-full.txt", | ||
| "/llms-manifest.json", | ||
| "/llms-entropy.txt", | ||
| "/llms-price-feeds.txt", | ||
| "/llms-price-feeds-core.txt", | ||
| "/llms-price-feeds-pro.txt", | ||
| "/SKILL.md", | ||
| ]); | ||
|
|
||
| function prefersMarkdown(accept: string | null): boolean { | ||
| if (!accept) return false; | ||
| const entries = accept.split(",").map((part) => { | ||
| const [media = "", ...params] = part.trim().split(";").map((s) => s.trim()); | ||
| const qParam = params.find((p) => p.startsWith("q=")); | ||
| const q = qParam ? Number.parseFloat(qParam.slice(2)) : 1; | ||
| return { media, q: Number.isFinite(q) ? q : 1 }; | ||
| }); | ||
| const markdown = entries.find( | ||
| (e) => e.media === "text/markdown" || e.media === "text/x-markdown", | ||
| ); | ||
| if (!markdown) return false; | ||
| const html = entries.find((e) => e.media === "text/html"); | ||
| return !html || markdown.q >= html.q; | ||
| } | ||
|
|
||
| export function middleware(request: NextRequest) { | ||
| if (request.method !== "GET" && request.method !== "HEAD") { | ||
| return NextResponse.next(); | ||
| } | ||
| if (!prefersMarkdown(request.headers.get("accept"))) { | ||
| return NextResponse.next(); | ||
| } | ||
|
|
||
| const { pathname } = request.nextUrl; | ||
| if (SKIP_EXACT.has(pathname)) return NextResponse.next(); | ||
| if (SKIP_PREFIXES.some((p) => pathname === p || pathname.startsWith(`${p}/`))) { | ||
| return NextResponse.next(); | ||
| } | ||
| // Already a .md/.mdx URL — let the existing rewrite handle it. | ||
| if (/\.[a-z0-9]+$/i.test(pathname)) return NextResponse.next(); | ||
|
|
||
| const url = request.nextUrl.clone(); | ||
| url.pathname = `/mdx${pathname}`; | ||
| const response = NextResponse.rewrite(url); | ||
| response.headers.set("Vary", "Accept"); | ||
| return response; | ||
|
Comment on lines
+42
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Missing The middleware sets On Vercel the impact is mitigated because middleware runs before CDN cache lookup, and rewrites use a different internal URL. But on any other deployment platform or when an external CDN sits in front, this is a correctness bug. Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| } | ||
|
|
||
| export const config = { | ||
| matcher: [ | ||
| "/((?!_next/static|_next/image|_next/data|favicon.ico).*)", | ||
| ], | ||
| }; | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 No test coverage for new middleware content negotiation
The new middleware (
apps/developer-hub/src/middleware.ts) introduces non-trivial content negotiation logic including Accept header parsing, quality factor comparison, path skip lists, and URL rewriting. Per REVIEW.md, new functionality should have tests. TheprefersMarkdownfunction in particular has enough edge cases (multiple entries, quality factors, missing entries, malformed input) that unit tests would be valuable. The AGENTS.md file notes that linting and type-checking are the primary gate, but the middleware logic is complex enough that tests would help catch regressions.Was this helpful? React with 👍 or 👎 to provide feedback.