Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

markdown-pages.ts

66 lines2.2 KB

1/**
2 * Markdown content negotiation (PLAN.md task 10.5). Agents that send
3 * `Accept: text/markdown` on HTML pages get markdown instead of an SSR
4 * page: /docs serves the llms.txt source verbatim, / serves a landing
5 * summary. Browsers (no text/markdown in Accept) keep HTML.
6 */
7import { llmsTxt } from '#/server/llms-txt.ts'
8​
9export function wantsMarkdown(request: Request): boolean {
10 if (request.method !== 'GET' && request.method !== 'HEAD') return false
11 const accept = request.headers.get('accept') ?? ''
12 return accept.includes('text/markdown')
14​
15function landingMd(origin: string): string {
16 return `# modelschemas
17​
18Live AI model schemas: which models exist right now, and what their
19request/response payloads look like. Model lists refresh every 15 minutes,
20full provider specs daily.
21​
22## Quickstart
23​
24\`\`\`
25GET ${origin}/v1/models?activity=chat&q=claude # what can I call right now
26GET ${origin}/v1/schemas/{provider} # endpoint ids per activity
27POST ${origin}/v1/validate # check a payload before spending tokens
28POST ${origin}/v1/estimate # amount + currency from the stored rate card
29\`\`\`
30​
31No signup for reads (60 req/h per IP; 5,000/h with a key — see ${origin}/auth.md).
32​
33## Surfaces
34​
35- ${origin}/llms.txt — full agent guide (also served at /docs with this header)
36- ${origin}/openapi.json — typed spec, operationIds on every operation
37- ${origin}/mcp — MCP server (streamable HTTP): list_models, get_model, get_schema, validate_payload, estimate_cost, recent_changes
38- ${origin}/skill — installable agent skill (SKILL.md)
39- ${origin}/.well-known/api-catalog — RFC 9727 linkset
40- ${origin}/.well-known/agent-configuration — agent-auth discovery
43​
44/** Markdown body for an HTML page path, or null when the path has none. */
45export function markdownForPath(
46 pathname: string,
47 origin: string,
48): string | null {
49 switch (pathname) {
50 case '/':
51 return landingMd(origin)
52 case '/docs':
53 return llmsTxt
54 default:
55 return null
56 }
58​
59export function markdownResponse(body: string): Response {
60 return new Response(body, {
61 headers: {
62 'Content-Type': 'text/markdown; charset=utf-8',
63 Vary: 'Accept',
64 },
65 })