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
168 changes: 0 additions & 168 deletions docs/lib/ai-agent-detection.ts

This file was deleted.

3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@types/node": "catalog:",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.9",
"@vercel/agent-readability": "^0.2.1",
"@vercel/analytics": "^1.6.1",
"@vercel/edge-config": "^1.4.0",
"@vercel/speed-insights": "1.3.1",
Expand Down Expand Up @@ -97,4 +98,4 @@
"tw-animate-css": "^1.4.0",
"typescript": "catalog:"
}
}
}
24 changes: 13 additions & 11 deletions docs/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { generateNotFoundMarkdown, isAIAgent } from '@vercel/agent-readability';
import { createI18nMiddleware } from 'fumadocs-core/i18n/middleware';
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';
import {
Expand All @@ -7,7 +8,6 @@ import {
} from 'next/server';
import { i18n } from '@/lib/geistdocs/i18n';
import { trackMdRequest } from '@/lib/md-tracking';
import { isAIAgent } from '@/lib/ai-agent-detection';

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

// AI agent detection — rewrite docs pages to markdown for agents
// so they always get structured content without needing .md URLs or Accept headers
if (
(pathname === "/docs" || pathname.startsWith("/docs/")) &&
!pathname.includes("/llms.mdx/")
(pathname === '/docs' || pathname.startsWith('/docs/')) &&
!pathname.includes('/llms.mdx/')
) {
const agentResult = isAIAgent(request);
if (agentResult.detected && !isMarkdownPreferred(request)) {
const result =
pathname === "/docs"
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",
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 helpful markdown
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 markdown response for AI agents returns HTTP 200 instead of HTTP 404, creating a soft 404 anti-pattern that misleads agents into treating "Page Not Found" content as valid page content.

Fix on Vercel

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

Expand All @@ -107,10 +110,9 @@ const proxy = (request: NextRequest, context: NextFetchEvent) => {
};

export const config = {
// Matcher ignoring `/_next/`, `/api/`, static assets, favicon, sitemap, robots, etc.
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|og|.*\\.tgz$|.*\\.svg$|.*\\.zip$).*)',
],
};

export default proxy;
export default proxy;
Loading