-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(docs): AI-ready content negotiation #2338
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
Conversation
Enables AI agents to request pure markdown content via: - URL extension: /docs/quickstart.md or .mdx - Accept header: text/markdown Components: - lib/mdx-to-markdown.ts - JSX to markdown converter - lib/path-validation.ts - Security validation - proxy.ts - Content negotiation middleware - /api/mdx-content/[...path] - Pure markdown API - Improved /llms.txt and /llms-full.txt endpoints 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Add boundary check to prefix validation (prevents /docsextra matching /docs) - Add YAML reserved word escaping (true, false, null, yes, no, etc.) - Add YAML number detection to prevent type coercion - Fix Callout regex to capture title/type in any order - Fix Accordion regex to properly capture title attribute 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix NaN regex precedence bug (use non-capturing group) - Fix YouTube/Video/ProviderCard regex to handle attributes in any order 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
| const timeoutPromise = new Promise<never>((_, reject) => | ||
| setTimeout(() => reject(new Error('Content retrieval timeout')), 10000) | ||
| ); | ||
| rawContent = await Promise.race([contentPromise, timeoutPromise]); |
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.
Timeout promise causes unhandled rejection after successful requests
Medium Severity
The timeoutPromise created with setTimeout is never cancelled when contentPromise resolves first. When content is successfully fetched before the 10-second timeout, Promise.race resolves with the content and the function continues, but the timer keeps running. After 10 seconds, the timeout promise rejects with new Error('Content retrieval timeout'), and since nothing awaits or catches this rejection, it becomes an unhandled promise rejection. This will cause error logs and potentially process termination in Node.js 15+. The timer reference needs to be stored and cleared with clearTimeout when content resolves successfully.
| * - Validates paths to prevent traversal attacks | ||
| * - Handles double encoding, unicode normalization | ||
| */ | ||
| export function proxy(request: NextRequest) { |
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.
Middleware function not exported with correct name for Next.js
High Severity
The file exports a function named proxy and a config with a matcher, but Next.js middleware requires the function to be exported as middleware (either default or named) from a file named middleware.ts at the project root. Currently, proxy.ts exports proxy, which Next.js won't recognize as middleware. The content negotiation feature (.md/.mdx URL extensions and Accept header handling) won't work because requests won't be intercepted. The test plan items like visiting /docs/quickstart.mdx will not return markdown as expected.
Additional Locations (1)
|
Superseded by smaller PRs for easier review:
|
Summary
Enables AI agents to request pure markdown content from documentation pages.
Features
/docs/quickstart.mdor.mdxtext/markdownortext/x-markdownNew Files
lib/mdx-to-markdown.ts- JSX to markdown converterlib/path-validation.ts- Security validation (prevents traversal attacks)proxy.ts- Content negotiation middleware/api/mdx-content/[...path]- Pure markdown APITest Plan
/docs/quickstart.mdx- should return markdowncurl -H "Accept: text/markdown" /docs/quickstart- should return markdown/llms.txt- should show improved index🤖 Generated with Claude Code