@vercel/agent-readability 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/agent-readability",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Detect AI agents. Serve them markdown. Audit your site against the Agent Readability Spec.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -27,6 +27,26 @@
27
27
  "types": "./dist/next/index.d.cts",
28
28
  "default": "./dist/next/index.cjs"
29
29
  }
30
+ },
31
+ "./sveltekit": {
32
+ "import": {
33
+ "types": "./dist/sveltekit/index.d.ts",
34
+ "default": "./dist/sveltekit/index.js"
35
+ },
36
+ "require": {
37
+ "types": "./dist/sveltekit/index.d.cts",
38
+ "default": "./dist/sveltekit/index.cjs"
39
+ }
40
+ },
41
+ "./nuxt": {
42
+ "import": {
43
+ "types": "./dist/nuxt/index.d.ts",
44
+ "default": "./dist/nuxt/index.js"
45
+ },
46
+ "require": {
47
+ "types": "./dist/nuxt/index.d.cts",
48
+ "default": "./dist/nuxt/index.cjs"
49
+ }
30
50
  }
31
51
  },
32
52
  "bin": {
@@ -40,9 +60,17 @@
40
60
  "node": ">=20.0.0"
41
61
  },
42
62
  "peerDependencies": {
63
+ "@sveltejs/kit": ">=2",
64
+ "h3": ">=1.8 <2",
43
65
  "next": ">=14"
44
66
  },
45
67
  "peerDependenciesMeta": {
68
+ "@sveltejs/kit": {
69
+ "optional": true
70
+ },
71
+ "h3": {
72
+ "optional": true
73
+ },
46
74
  "next": {
47
75
  "optional": true
48
76
  }
@@ -50,13 +78,16 @@
50
78
  "devDependencies": {
51
79
  "@biomejs/biome": "^1.9",
52
80
  "@changesets/cli": "^2",
81
+ "@sveltejs/kit": "^2",
53
82
  "@types/node": "^22",
54
83
  "@vitest/coverage-v8": "^3",
55
84
  "cheerio": "^1",
56
85
  "citty": "^0.1",
86
+ "h3": ">=1.8 <2",
57
87
  "next": "^15",
58
88
  "p-limit": "^6",
59
89
  "picocolors": "^1",
90
+ "svelte": "^5",
60
91
  "tsup": "^8",
61
92
  "typescript": "^5.8",
62
93
  "vitest": "^3"
@@ -76,6 +107,8 @@
76
107
  "markdown",
77
108
  "detection",
78
109
  "next.js",
110
+ "sveltekit",
111
+ "nuxt",
79
112
  "middleware"
80
113
  ],
81
114
  "scripts": {
package/skill/SKILL.md CHANGED
@@ -23,9 +23,11 @@ Make a website readable by AI agents by adding discovery files, content negotiat
23
23
  pnpm add @vercel/agent-readability
24
24
  ```
25
25
 
26
- ### 2. Add middleware (Next.js)
26
+ ### 2. Add middleware
27
27
 
28
- Create or update `middleware.ts`:
28
+ Detect framework: `next.config.*` → Next.js, `svelte.config.js` → SvelteKit, `nuxt.config.ts` → Nuxt.
29
+
30
+ #### Next.js — `middleware.ts`
29
31
 
30
32
  ```ts
31
33
  import { withAgentReadability } from '@vercel/agent-readability/next'
@@ -52,13 +54,46 @@ export default withAgentReadability(
52
54
  )
53
55
  ```
54
56
 
55
- For non-Next.js frameworks, use the core API directly:
57
+ #### SvelteKit `hooks.server.ts`
58
+
59
+ ```ts
60
+ import { handleAgentReadability } from '@vercel/agent-readability/sveltekit'
61
+ import { sequence } from '@sveltejs/kit/hooks'
62
+
63
+ export const handle = sequence(
64
+ handleAgentReadability({
65
+ docsPrefix: '/docs',
66
+ rewrite: (pathname) => `/api/docs-md${pathname}`,
67
+ }),
68
+ // other handles...
69
+ )
70
+ ```
71
+
72
+ The `rewrite` function maps to a `+server.ts` route that returns markdown. SvelteKit's `event.fetch()` resolves it internally with zero network hop.
73
+
74
+ #### Nuxt — `server/middleware/agent.ts`
75
+
76
+ ```ts
77
+ import { defineAgentMiddleware } from '@vercel/agent-readability/nuxt'
78
+
79
+ export default defineAgentMiddleware({
80
+ docsPrefix: '/docs',
81
+ getMarkdown: async (pathname, event) => {
82
+ const doc = await queryContent(pathname).findOne()
83
+ return doc.body
84
+ },
85
+ })
86
+ ```
87
+
88
+ `getMarkdown` receives the pathname and h3 event. Return a string (auto-wrapped in `text/markdown` Response) or a full `Response`.
89
+
90
+ #### Other frameworks — core API
56
91
 
57
92
  ```ts
58
- import { isAIAgent, acceptsMarkdown } from '@vercel/agent-readability'
93
+ import { shouldServeMarkdown } from '@vercel/agent-readability'
59
94
 
60
- // In your request handler:
61
- if (isAIAgent(request).detected || acceptsMarkdown(request)) {
95
+ const { serve } = shouldServeMarkdown(request)
96
+ if (serve) {
62
97
  return new Response(markdownContent, {
63
98
  headers: { 'Content-Type': 'text/markdown', 'Vary': 'Accept' },
64
99
  })
@@ -169,4 +204,6 @@ The audit scores your site on 25 checks across reachability, discovery, content
169
204
  - Set `Vary: Accept` on all markdown responses for correct CDN caching
170
205
  - For missing pages, return 200 with markdown body on the canonical URL (agents discard 404 bodies)
171
206
  - Prefer canonical page URLs and negotiate markdown with `Accept: text/markdown` instead of exposing `.md` page URLs
172
- - The `onDetection` callback in the Next.js adapter runs via `event.waitUntil()`
207
+ - Next.js: `onDetection` runs via `event.waitUntil()`
208
+ - SvelteKit: `onDetection` is fire-and-forget (errors swallowed)
209
+ - Nuxt: `onDetection` is fire-and-forget (errors swallowed)