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 docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@orama/tokenizers": "^3.1.16",
"@streamdown/cjk": "^1.0.1",
"@streamdown/code": "^1.0.1",
"@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 @@ -60,4 +61,4 @@
"typescript": "^5.9.3"
},
"workspaces": []
}
}
34 changes: 34 additions & 0 deletions docs/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",
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.

The TrackMdRequestParams interface is missing the "agent-rewrite" request type and detectionMethod field, causing a TypeScript build failure.

Fix on Vercel

detectionMethod: agentResult.method,
})
);
return NextResponse.rewrite(new URL(result, request.nextUrl));
}
// Agent requested a non-existent docs URL
return new NextResponse(generateNotFoundMarkdown(pathname), {
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