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

discovery-links.ts

23 lines946 Bytes

1/**
2 * RFC 8288 Link headers for agent discovery (PLAN.md task 10.2), appended to
3 * HTML responses by the worker fetch wrapper. JSON/API responses are left
4 * untouched.
5 */
6​
7export const DISCOVERY_LINK_HEADER = [
8 '</.well-known/api-catalog>; rel="api-catalog"',
9 '</openapi.json>; rel="service-desc"; type="application/json"',
10 '</docs>; rel="service-doc"',
11 '</llms.txt>; rel="describedby"; type="text/markdown"',
12 '</.well-known/agent-configuration>; rel="agent-configuration"',
13].join(', ')
14​
15/** Append the discovery Link header to HTML responses (new Response — the
16 * SSR response's headers are immutable). */
17export function withDiscoveryLinks(response: Response): Response {
18 const contentType = response.headers.get('content-type') ?? ''
19 if (!contentType.includes('text/html')) return response
20 const wrapped = new Response(response.body, response)
21 wrapped.headers.append('Link', DISCOVERY_LINK_HEADER)
22 return wrapped