Skip to content

Replace local ai-agent-detection with @vercel/agent-readability#354

Open
molebox wants to merge 5 commits intomainfrom
replace-agent-detection-with-package
Open

Replace local ai-agent-detection with @vercel/agent-readability#354
molebox wants to merge 5 commits intomainfrom
replace-agent-detection-with-package

Conversation

@molebox
Copy link
Copy Markdown
Contributor

@molebox molebox commented Apr 1, 2026

Summary

  • Replaces local ai-agent-detection.ts with the shared @vercel/agent-readability package
  • UA pattern updates now propagate from one place via version bumps
  • Adds generateNotFoundMarkdown response for agents hitting non-existent docs URLs

Same approach as vercel/front#65649 and vercel/geistdocs#58.

Test plan

  • AI agent hitting a valid docs URL gets markdown rewrite
  • AI agent hitting a non-existent docs URL gets helpful not-found markdown
  • Accept header content negotiation still works
  • Build passes

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flags-playground Ready Ready Preview, Comment, Open in v0 Apr 7, 2026 0:13am
flags-sdk-dev Ready Ready Preview, Comment, Open in v0 Apr 7, 2026 0:13am
flags-sdk-next-15 Ready Ready Preview, Comment, Open in v0 Apr 7, 2026 0:13am
flags-sdk-next-16 Ready Ready Preview, Comment, Open in v0 Apr 7, 2026 0:13am
flags-sdk-snippets Ready Ready Preview, Comment, Open in v0 Apr 7, 2026 0:13am
flags-sdk-sveltekit-snippets Ready Ready Preview, Comment, Open in v0 Apr 7, 2026 0:13am
shirt-shop Ready Ready Preview, Comment, Open in v0 Apr 7, 2026 0:13am
shirt-shop-api Ready Ready Preview, Comment, Open in v0 Apr 7, 2026 0:13am

@socket-security
Copy link
Copy Markdown

socket-security bot commented Apr 1, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​vercel/​agent-readability@​0.2.17810010095100

View full report

Copy link
Copy Markdown
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

Import of DetectionMethod type from deleted file @/lib/ai-agent-detection causes a TypeScript compilation error.

Fix on Vercel

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

@vercel vercel bot Apr 1, 2026

Choose a reason for hiding this comment

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

AI agent not-found response returns HTTP 200 instead of 404, causing agents to incorrectly believe the page exists.

Fix on Vercel

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@molebox should these be 404s?

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.

Yes — the comment on line 92 says "Agent requested a non-existent docs URL" and the function is called generateNotFoundMarkdown, so this is clearly a 404 scenario. Without an explicit status: 404, NextResponse defaults to 200, which would mislead AI agents that check status codes to determine if a resource exists.

The fix is adding status: 404 to the response options (see the suggestion above).

- Change DetectionMethod import from deleted local file to @vercel/agent-readability
- Add Vary: Accept header on agent-rewrite responses
- Add discovery options (sitemapUrl, indexUrl) to generateNotFoundMarkdown

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants