Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@streamdown/code": "workspace:*",
"@streamdown/math": "workspace:*",
"@streamdown/mermaid": "workspace:*",
"@vercel/agent-readability": "^0.2.1",
"@vercel/analytics": "^1.6.1",
"@vercel/speed-insights": "^1.3.1",
"ai": "^5.0.106",
Expand Down Expand Up @@ -65,4 +66,4 @@
"tw-animate-css": "^1.4.0",
"typescript": "^5.9.3"
}
}
}
34 changes: 34 additions & 0 deletions apps/website/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "next/server";
import { i18n } from "@/lib/geistdocs/i18n";
import { trackMdRequest } from "@/lib/geistdocs/md-tracking";
import { generateNotFoundMarkdown, isAIAgent } from "@vercel/agent-readability";

const { rewrite: rewriteLLM } = rewritePath(
"/docs/*path",
Expand Down Expand Up @@ -57,6 +58,39 @@ const proxy = (request: NextRequest, context: NextFetchEvent) => {
}
}

// AI agent detection — rewrite docs pages to markdown for agents
if (
(pathname === "/docs" || pathname.startsWith("/docs/")) &&
!pathname.includes("/llms.mdx/")
) {
const agentResult = isAIAgent(request);
if (agentResult.detected && !isMarkdownPreferred(request)) {
const result =
pathname === "/docs"
? `/${i18n.defaultLanguage}/llms.mdx`
: rewriteLLM(pathname);

if (result) {
context.waitUntil(
trackMdRequest({
path: pathname,
userAgent: request.headers.get("user-agent"),
referer: request.headers.get("referer"),
acceptHeader: request.headers.get("accept"),
requestType: "agent-rewrite",
detectionMethod: agentResult.method,
})
);
return NextResponse.rewrite(new URL(result, request.nextUrl));
}
// Agent requested a non-existent docs URL
return new NextResponse(generateNotFoundMarkdown(pathname), {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not-found response for AI agents returns HTTP 200 instead of 404 when requesting non-existent docs URLs.

Fix on Vercel

headers: { "Content-Type": "text/markdown; charset=utf-8" },
});
}
}


// Handle Accept header content negotiation and track the request
if (isMarkdownPreferred(request)) {
const result = rewriteLLM(pathname);
Expand Down
Loading