nuxt-ai-ready 3.6.1 → 3.6.2
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/dist/agent-skills-config-CmZq9uWW.mjs +18 -0
- package/dist/agent-skills-zGLgFB6H.mjs +468 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +656 -570
- package/dist/devtools/pages/ai-ready/debug.vue +9 -3
- package/dist/devtools/pages/ai-ready/index.vue +3 -1
- package/dist/devtools/pages/ai-ready/llms-txt.vue +15 -4
- package/dist/devtools/pages/ai-ready.vue +28 -4
- package/dist/module.d.mts +106 -112
- package/dist/module.json +3 -3
- package/dist/module.mjs +2732 -26
- package/dist/package-metadata-B1darl8W.mjs +28 -0
- package/dist/prerender-QMv07W4h.mjs +650 -0
- package/dist/runtime/app/composables/webmcp.js +90 -97
- package/dist/runtime/app/plugins/md-alternate.server.js +29 -26
- package/dist/runtime/app/plugins/md-hints.prerender.js +13 -15
- package/dist/runtime/app/plugins/webmcp.client.js +49 -53
- package/dist/runtime/app/webmcp-config.js +2 -2
- package/dist/runtime/cache-control.js +16 -10
- package/dist/runtime/i18n-url.js +6 -6
- package/dist/runtime/index.js +4 -12
- package/dist/runtime/llms-txt-directive.js +20 -13
- package/dist/runtime/llms-txt-files.js +188 -187
- package/dist/runtime/llms-txt-format.js +54 -55
- package/dist/runtime/llms-txt-i18n.js +22 -19
- package/dist/runtime/llms-txt-utils.js +140 -95
- package/dist/runtime/markdown-links.js +45 -39
- package/dist/runtime/markdown-path.js +29 -9
- package/dist/runtime/markdown-text.js +2 -1
- package/dist/runtime/mcp.js +5 -1
- package/dist/runtime/route-path.js +14 -8
- package/dist/runtime/server/db/drizzle/client.js +71 -75
- package/dist/runtime/server/db/drizzle/index.js +16 -28
- package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -1
- package/dist/runtime/server/db/drizzle/providers/bun.js +10 -7
- package/dist/runtime/server/db/drizzle/providers/d1.js +16 -13
- package/dist/runtime/server/db/drizzle/providers/dbPath.js +60 -37
- package/dist/runtime/server/db/drizzle/providers/libsql.js +23 -11
- package/dist/runtime/server/db/drizzle/providers/neon.js +13 -10
- package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +10 -7
- package/dist/runtime/server/db/drizzle/providers/postgres.js +13 -10
- package/dist/runtime/server/db/drizzle/queries.js +633 -532
- package/dist/runtime/server/db/drizzle/raw.js +200 -176
- package/dist/runtime/server/db/index.js +3 -0
- package/dist/runtime/server/db/queries.js +816 -607
- package/dist/runtime/server/db/schema/postgres.js +56 -50
- package/dist/runtime/server/db/schema/sqlite.js +56 -50
- package/dist/runtime/server/db/schema-sql.js +35 -38
- package/dist/runtime/server/db/seed.js +60 -45
- package/dist/runtime/server/db/shared.js +300 -213
- package/dist/runtime/server/index.js +1 -17
- package/dist/runtime/server/mcp/cache-key.js +5 -1
- package/dist/runtime/server/mcp/resources/pages.js +32 -33
- package/dist/runtime/server/mcp/tools/get-page-markdown.js +41 -27
- package/dist/runtime/server/mcp/tools/list-pages.js +40 -34
- package/dist/runtime/server/mcp/tools/search-pages.js +24 -16
- package/dist/runtime/server/middleware/markdown.d.ts +1 -1
- package/dist/runtime/server/middleware/markdown.js +15 -13
- package/dist/runtime/server/middleware/markdown.prerender.d.ts +1 -1
- package/dist/runtime/server/middleware/markdown.prerender.js +135 -119
- package/dist/runtime/server/middleware/render-markdown.d.ts +1 -1
- package/dist/runtime/server/middleware/render-markdown.js +164 -144
- package/dist/runtime/server/plugins/ai-terms.d.ts +1 -1
- package/dist/runtime/server/plugins/ai-terms.js +4 -8
- package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.d.ts +1 -1
- package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.js +7 -8
- package/dist/runtime/server/plugins/content-signal-capture.prerender.d.ts +1 -1
- package/dist/runtime/server/plugins/content-signal-capture.prerender.js +7 -7
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +1 -1
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +13 -14
- package/dist/runtime/server/plugins/db-lifecycle.js +13 -11
- package/dist/runtime/server/plugins/html-capture.prerender.js +6 -6
- package/dist/runtime/server/plugins/link-header-nitro3.d.ts +1 -1
- package/dist/runtime/server/plugins/link-header-nitro3.js +23 -13
- package/dist/runtime/server/plugins/link-header.d.ts +1 -1
- package/dist/runtime/server/plugins/link-header.js +30 -30
- package/dist/runtime/server/plugins/llms-txt-directive-html.d.ts +1 -1
- package/dist/runtime/server/plugins/llms-txt-directive-html.js +4 -3
- package/dist/runtime/server/plugins/markdown-negotiation.d.ts +1 -1
- package/dist/runtime/server/plugins/markdown-negotiation.js +64 -45
- package/dist/runtime/server/plugins/sitemap-seeder.js +144 -112
- package/dist/runtime/server/routes/__ai-ready/cron.get.d.ts +1 -1
- package/dist/runtime/server/routes/__ai-ready/cron.get.js +17 -11
- package/dist/runtime/server/routes/__ai-ready/devtools.get.d.ts +1 -1
- package/dist/runtime/server/routes/__ai-ready/devtools.get.js +60 -45
- package/dist/runtime/server/routes/__ai-ready/pages.get.d.ts +36 -1
- package/dist/runtime/server/routes/__ai-ready/pages.get.js +44 -40
- package/dist/runtime/server/routes/__ai-ready/poll.post.d.ts +15 -1
- package/dist/runtime/server/routes/__ai-ready/poll.post.js +30 -30
- package/dist/runtime/server/routes/__ai-ready/prune.post.d.ts +13 -1
- package/dist/runtime/server/routes/__ai-ready/prune.post.js +29 -15
- package/dist/runtime/server/routes/__ai-ready/reindex.post.d.ts +22 -1
- package/dist/runtime/server/routes/__ai-ready/reindex.post.js +31 -21
- package/dist/runtime/server/routes/__ai-ready/restore.post.d.ts +4 -1
- package/dist/runtime/server/routes/__ai-ready/restore.post.js +28 -22
- package/dist/runtime/server/routes/__ai-ready/status.get.d.ts +1 -1
- package/dist/runtime/server/routes/__ai-ready/status.get.js +52 -53
- package/dist/runtime/server/routes/__ai-ready-debug.get.d.ts +83 -1
- package/dist/runtime/server/routes/__ai-ready-debug.get.js +209 -189
- package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-artifact.js +16 -14
- package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-index.js +8 -6
- package/dist/runtime/server/routes/ai-catalog.js +19 -19
- package/dist/runtime/server/routes/ai-terms.js +23 -19
- package/dist/runtime/server/routes/api-catalog.js +23 -23
- package/dist/runtime/server/routes/llms-full.txt.get.d.ts +1 -1
- package/dist/runtime/server/routes/llms-full.txt.get.js +42 -41
- package/dist/runtime/server/routes/llms.txt.get.d.ts +1 -1
- package/dist/runtime/server/routes/llms.txt.get.js +38 -33
- package/dist/runtime/server/routes/mcp-server-card.js +19 -19
- package/dist/runtime/server/routes/sitemap.md.get.d.ts +1 -1
- package/dist/runtime/server/routes/sitemap.md.get.js +38 -39
- package/dist/runtime/server/tasks/ai-ready-cron.d.ts +1 -1
- package/dist/runtime/server/tasks/ai-ready-cron.js +17 -14
- package/dist/runtime/server/utils/auth.js +76 -53
- package/dist/runtime/server/utils/batchIndex.js +72 -60
- package/dist/runtime/server/utils/checkStale.js +181 -134
- package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -20
- package/dist/runtime/server/utils/cloudflare.js +69 -51
- package/dist/runtime/server/utils/content-negotiation.js +30 -18
- package/dist/runtime/server/utils/content.js +4 -1
- package/dist/runtime/server/utils/context.js +30 -19
- package/dist/runtime/server/utils/cron-plan.js +6 -6
- package/dist/runtime/server/utils/discovery-response.js +5 -6
- package/dist/runtime/server/utils/fetch.js +2 -1
- package/dist/runtime/server/utils/frontmatter.js +44 -57
- package/dist/runtime/server/utils/i18n.js +3 -8
- package/dist/runtime/server/utils/indexPage.js +152 -113
- package/dist/runtime/server/utils/keywords.js +278 -277
- package/dist/runtime/server/utils/link-header.js +67 -56
- package/dist/runtime/server/utils/llms-full.js +39 -49
- package/dist/runtime/server/utils/markdown-redirect.js +26 -14
- package/dist/runtime/server/utils/markdown-request.js +62 -47
- package/dist/runtime/server/utils/negotiation-decision.d.ts +8 -0
- package/dist/runtime/server/utils/negotiation-decision.js +106 -34
- package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
- package/dist/runtime/server/utils/negotiation-response.js +195 -144
- package/dist/runtime/server/utils/page-updated-at.js +23 -15
- package/dist/runtime/server/utils/prerender-html.js +31 -17
- package/dist/runtime/server/utils/runCron.js +263 -192
- package/dist/runtime/server/utils/sitemap-crawl-state.js +57 -39
- package/dist/runtime/server/utils/sitemap-lastmod.js +16 -14
- package/dist/runtime/server/utils/sitemap-md.js +39 -50
- package/dist/runtime/server/utils/sitemap-routes.js +7 -7
- package/dist/runtime/server/utils/sitemap.js +459 -414
- package/dist/runtime/server/utils.js +141 -122
- package/dist/runtime/site-tool-catalog.js +39 -43
- package/dist/runtime/site-tool-config.js +1 -0
- package/dist/runtime/sync-secret.js +11 -11
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/webmcp-site-tools.js +278 -250
- package/dist/runtime/webmcp.js +53 -42
- package/dist/static-headers-G7hFL3wE.mjs +328 -0
- package/dist/types.d.mts +1 -9
- package/package.json +18 -22
- package/skills/nuxt-ai-ready/SKILL.md +8 -2
- package/dist/chunks/agent-skills.mjs +0 -383
- package/dist/chunks/prerender.mjs +0 -683
- package/dist/shared/nuxt-ai-ready.Bzx0dNWj.mjs +0 -3034
- package/dist/shared/nuxt-ai-ready.DCd-1s1G.mjs +0 -29
|
@@ -2,281 +2,309 @@ import { toMarkdownPath } from "./markdown-path.js";
|
|
|
2
2
|
import { toDeployedRoute } from "./route-path.js";
|
|
3
3
|
import { normalizeSiteRoute, SITE_TOOL_CATALOG } from "./site-tool-catalog.js";
|
|
4
4
|
import { toolError, toolText, truncateToolOutput, WEB_MCP_BUDGET } from "./webmcp.js";
|
|
5
|
-
|
|
5
|
+
/** Page content is whatever the site indexed, so treat it as untrusted input. */
|
|
6
|
+
const READ_ONLY = {
|
|
7
|
+
readOnlyHint: true,
|
|
8
|
+
untrustedContentHint: true
|
|
9
|
+
};
|
|
6
10
|
const RE_FTS_CHARS = /[*:^"()]/g;
|
|
7
11
|
const RE_WHITESPACE = /\s+/;
|
|
12
|
+
/** Field weights matching the server-side FTS query, excluding unavailable markdown. */
|
|
8
13
|
const SEARCH_WEIGHTS = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
["route", 5],
|
|
15
|
+
["title", 3],
|
|
16
|
+
["headings", 2],
|
|
17
|
+
["keywords", 2],
|
|
18
|
+
["description", 1]
|
|
14
19
|
];
|
|
15
20
|
function isRecord(input) {
|
|
16
|
-
|
|
21
|
+
return typeof input === "object" && input !== null;
|
|
17
22
|
}
|
|
18
23
|
function parsePageSummary(input) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
24
|
+
if (!isRecord(input) || typeof input.route !== "string" || !input.route) return undefined;
|
|
25
|
+
return {
|
|
26
|
+
route: input.route,
|
|
27
|
+
...typeof input.title === "string" ? { title: input.title } : {},
|
|
28
|
+
...typeof input.description === "string" ? { description: input.description } : {},
|
|
29
|
+
...typeof input.headings === "string" ? { headings: input.headings } : {},
|
|
30
|
+
...Array.isArray(input.keywords) ? { keywords: input.keywords.filter((keyword) => typeof keyword === "string") } : {}
|
|
31
|
+
};
|
|
28
32
|
}
|
|
29
33
|
function parsePageList(input) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return input.map(parsePageSummary).filter((page) => !!page);
|
|
34
|
+
if (!Array.isArray(input)) return [];
|
|
35
|
+
return input.map(parsePageSummary).filter((page) => !!page);
|
|
33
36
|
}
|
|
34
37
|
function parsePagesResponse(input) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
38
|
+
if (!isRecord(input)) return {};
|
|
39
|
+
const page = input.page === null ? null : parsePageSummary(input.page);
|
|
40
|
+
return {
|
|
41
|
+
...page !== undefined ? { page } : {},
|
|
42
|
+
pages: parsePageList(input.pages),
|
|
43
|
+
results: parsePageList(input.results),
|
|
44
|
+
...typeof input.total === "number" && Number.isFinite(input.total) ? { total: input.total } : {}
|
|
45
|
+
};
|
|
44
46
|
}
|
|
45
47
|
function getErrorStatus(error) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return response.status;
|
|
51
|
-
return typeof error.statusCode === "number" ? error.statusCode : void 0;
|
|
48
|
+
if (!isRecord(error)) return undefined;
|
|
49
|
+
const response = error.response;
|
|
50
|
+
if (isRecord(response) && typeof response.status === "number") return response.status;
|
|
51
|
+
return typeof error.statusCode === "number" ? error.statusCode : undefined;
|
|
52
52
|
}
|
|
53
53
|
function fetchResource(path, options) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
return Promise.resolve().then(() => options ? globalThis.$fetch(path, options) : globalThis.$fetch(path)).then((value) => ({
|
|
55
|
+
_tag: "Ok",
|
|
56
|
+
value
|
|
57
|
+
}), (error) => getErrorStatus(error) === 404 ? { _tag: "NotFound" } : {
|
|
58
|
+
_tag: "Error",
|
|
59
|
+
error
|
|
60
|
+
});
|
|
58
61
|
}
|
|
59
62
|
function reportFetchError(source, result) {
|
|
60
|
-
|
|
61
|
-
console.error(`[nuxt-ai-ready] Failed to read WebMCP ${source}.`, result.error);
|
|
63
|
+
if (result._tag === "Error") console.error(`[nuxt-ai-ready] Failed to read WebMCP ${source}.`, result.error);
|
|
62
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Rank the prerendered index in the browser. Only reached on fully static
|
|
67
|
+
* deployments, where there is no server left to run the FTS query.
|
|
68
|
+
*/
|
|
63
69
|
function searchIndex(pages, query, limit) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
const terms = query.replace(RE_FTS_CHARS, " ").toLowerCase().split(RE_WHITESPACE).filter(Boolean);
|
|
71
|
+
if (!terms.length) return [];
|
|
72
|
+
return pages.map((page) => {
|
|
73
|
+
let score = 0;
|
|
74
|
+
for (const [field, weight] of SEARCH_WEIGHTS) {
|
|
75
|
+
const value = page[field];
|
|
76
|
+
const haystack = (Array.isArray(value) ? value.join(" ") : value || "").toLowerCase();
|
|
77
|
+
for (const term of terms) {
|
|
78
|
+
if (haystack.includes(term)) score += weight;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
page,
|
|
83
|
+
score
|
|
84
|
+
};
|
|
85
|
+
}).filter((entry) => entry.score > 0).sort((a, b) => b.score - a.score).slice(0, limit).map((entry) => entry.page);
|
|
79
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Coerce whatever the agent passed into a site route. Schemas stay loose so the
|
|
89
|
+
* model is not penalised for sending `about` or `/about.md` instead of `/about`.
|
|
90
|
+
*/
|
|
80
91
|
function clamp(input, fallback, max) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return Math.min(value, max);
|
|
92
|
+
const value = Math.trunc(Number(input));
|
|
93
|
+
if (!Number.isFinite(value) || value < 1) return fallback;
|
|
94
|
+
return Math.min(value, max);
|
|
85
95
|
}
|
|
86
96
|
function positiveInteger(input, fallback) {
|
|
87
|
-
|
|
88
|
-
|
|
97
|
+
const value = Math.trunc(Number(input));
|
|
98
|
+
return Number.isFinite(value) && value > 0 ? value : fallback;
|
|
89
99
|
}
|
|
90
100
|
function cleanSummaryPart(input) {
|
|
91
|
-
|
|
101
|
+
return input.replace(RE_WHITESPACE, " ").trim();
|
|
92
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Read-only tools mirroring the MCP server, so an agent running inside the
|
|
105
|
+
* browser can discover and read site content without leaving the page.
|
|
106
|
+
*/
|
|
93
107
|
export function createSiteTools(options = {}) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
108
|
+
const baseURL = options.baseURL || "/";
|
|
109
|
+
const listPagesOptions = options.tools?.listPages;
|
|
110
|
+
const searchPagesOptions = options.tools?.searchPages;
|
|
111
|
+
const getPageMarkdownOptions = options.tools?.getPageMarkdown;
|
|
112
|
+
const listPagesLimit = clamp(listPagesOptions?.defaultLimit, 20, 50);
|
|
113
|
+
const searchPagesLimit = clamp(searchPagesOptions?.defaultLimit, 10, 50);
|
|
114
|
+
const listPagesMaxOutputChars = positiveInteger(listPagesOptions?.maxOutputChars, WEB_MCP_BUDGET.output);
|
|
115
|
+
const searchPagesMaxOutputChars = positiveInteger(searchPagesOptions?.maxOutputChars, WEB_MCP_BUDGET.output);
|
|
116
|
+
const getPageMarkdownMaxOutputChars = positiveInteger(getPageMarkdownOptions?.maxOutputChars, WEB_MCP_BUDGET.output);
|
|
117
|
+
const pagesPath = toDeployedRoute("/__ai-ready/pages", baseURL);
|
|
118
|
+
const indexPath = toDeployedRoute("/__ai-ready/pages.json", baseURL);
|
|
119
|
+
/**
|
|
120
|
+
* One page per line rather than JSON, so trimming to the output budget drops
|
|
121
|
+
* whole entries instead of leaving the agent with a half-parsed blob.
|
|
122
|
+
*/
|
|
123
|
+
function formatPages(pages, summaryForCount, recovery, maxOutputChars) {
|
|
124
|
+
const pageLines = pages.map((page) => `\n${[
|
|
125
|
+
page.route,
|
|
126
|
+
page.title,
|
|
127
|
+
page.description
|
|
128
|
+
].filter((part) => !!part).map(cleanSummaryPart).join(" | ")}`);
|
|
129
|
+
let lines = [];
|
|
130
|
+
const render = (visibleLines) => {
|
|
131
|
+
const omitted = pageLines.length - visibleLines.length;
|
|
132
|
+
const note = omitted ? ` ${omitted} left out to fit; ${recovery}.` : "";
|
|
133
|
+
return `${summaryForCount(visibleLines.length)}${note}${visibleLines.join("")}`;
|
|
134
|
+
};
|
|
135
|
+
for (const line of pageLines) {
|
|
136
|
+
const candidate = [...lines, line];
|
|
137
|
+
if (maxOutputChars > 0 && render(candidate).length > maxOutputChars) break;
|
|
138
|
+
lines = candidate;
|
|
139
|
+
}
|
|
140
|
+
return toolText(truncateToolOutput(render(lines), maxOutputChars));
|
|
141
|
+
}
|
|
142
|
+
function fetchPages(query) {
|
|
143
|
+
return fetchResource(pagesPath, { query }).then((result) => result._tag === "Ok" ? {
|
|
144
|
+
_tag: "Ok",
|
|
145
|
+
value: parsePagesResponse(result.value)
|
|
146
|
+
} : result);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The index written during prerendering. Used when there is no server route,
|
|
150
|
+
* and when the runtime database has not been populated yet.
|
|
151
|
+
*/
|
|
152
|
+
let index;
|
|
153
|
+
function fetchIndex() {
|
|
154
|
+
index ??= fetchResource(indexPath).then((result) => {
|
|
155
|
+
if (result._tag === "Error") index = undefined;
|
|
156
|
+
if (result._tag !== "Ok") return result;
|
|
157
|
+
const data = isRecord(result.value) ? result.value.pages : undefined;
|
|
158
|
+
return {
|
|
159
|
+
_tag: "Ok",
|
|
160
|
+
value: parsePageList(data)
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
return index;
|
|
164
|
+
}
|
|
165
|
+
async function indexedRouteExists(route) {
|
|
166
|
+
const runtime = await fetchPages({ route });
|
|
167
|
+
reportFetchError("page index", runtime);
|
|
168
|
+
if (runtime._tag === "Ok" && runtime.value.page) return {
|
|
169
|
+
_tag: "Ok",
|
|
170
|
+
value: true
|
|
171
|
+
};
|
|
172
|
+
const prerendered = await fetchIndex();
|
|
173
|
+
reportFetchError("prerendered page index", prerendered);
|
|
174
|
+
if (prerendered._tag === "Ok") {
|
|
175
|
+
return {
|
|
176
|
+
_tag: "Ok",
|
|
177
|
+
value: prerendered.value.some((page) => page.route === route)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (runtime._tag === "Ok") return {
|
|
181
|
+
_tag: "Ok",
|
|
182
|
+
value: false
|
|
183
|
+
};
|
|
184
|
+
if (runtime._tag === "Error") return runtime;
|
|
185
|
+
if (prerendered._tag === "Error") return prerendered;
|
|
186
|
+
return {
|
|
187
|
+
_tag: "Ok",
|
|
188
|
+
value: false
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const tools = [
|
|
192
|
+
{
|
|
193
|
+
name: SITE_TOOL_CATALOG.list_pages.name,
|
|
194
|
+
title: SITE_TOOL_CATALOG.list_pages.title,
|
|
195
|
+
description: SITE_TOOL_CATALOG.list_pages.description,
|
|
196
|
+
inputSchema: {
|
|
197
|
+
type: "object",
|
|
198
|
+
properties: {
|
|
199
|
+
limit: {
|
|
200
|
+
type: "number",
|
|
201
|
+
description: `${SITE_TOOL_CATALOG.list_pages.parameters.limit} Defaults to ${listPagesLimit}.`
|
|
202
|
+
},
|
|
203
|
+
offset: {
|
|
204
|
+
type: "number",
|
|
205
|
+
description: SITE_TOOL_CATALOG.list_pages.parameters.offset
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
annotations: READ_ONLY,
|
|
210
|
+
async execute({ limit, offset }) {
|
|
211
|
+
const size = clamp(limit, listPagesLimit, 50);
|
|
212
|
+
const start = Math.max(0, Math.trunc(Number(offset)) || 0);
|
|
213
|
+
const runtime = await fetchPages({
|
|
214
|
+
limit: size,
|
|
215
|
+
offset: start
|
|
216
|
+
});
|
|
217
|
+
reportFetchError("page index", runtime);
|
|
218
|
+
let pages = runtime._tag === "Ok" ? runtime.value.pages || [] : [];
|
|
219
|
+
let total = runtime._tag === "Ok" ? runtime.value.total ?? 0 : 0;
|
|
220
|
+
if (!pages.length) {
|
|
221
|
+
const prerendered = await fetchIndex();
|
|
222
|
+
reportFetchError("prerendered page index", prerendered);
|
|
223
|
+
if (prerendered._tag === "Ok") {
|
|
224
|
+
pages = prerendered.value.slice(start, start + size);
|
|
225
|
+
total = prerendered.value.length;
|
|
226
|
+
} else if (runtime._tag === "Error" || prerendered._tag === "Error") {
|
|
227
|
+
return toolError("The page index is temporarily unavailable. Retry list_pages shortly.");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!pages.length) {
|
|
231
|
+
return toolText(start ? `No pages past offset ${start}.` : "This site has no indexed pages yet.");
|
|
232
|
+
}
|
|
233
|
+
return formatPages(pages, (count) => count ? `Pages ${start + 1} to ${start + count} of ${total || pages.length}.` : `Pages from offset ${start} of ${total || pages.length}.`, "use a higher offset", listPagesMaxOutputChars);
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: SITE_TOOL_CATALOG.search_pages.name,
|
|
238
|
+
title: SITE_TOOL_CATALOG.search_pages.title,
|
|
239
|
+
description: SITE_TOOL_CATALOG.search_pages.description,
|
|
240
|
+
inputSchema: {
|
|
241
|
+
type: "object",
|
|
242
|
+
properties: {
|
|
243
|
+
query: {
|
|
244
|
+
type: "string",
|
|
245
|
+
description: SITE_TOOL_CATALOG.search_pages.parameters.query
|
|
246
|
+
},
|
|
247
|
+
limit: {
|
|
248
|
+
type: "number",
|
|
249
|
+
description: `How many results to return. Defaults to ${searchPagesLimit}.`
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
required: ["query"]
|
|
253
|
+
},
|
|
254
|
+
annotations: READ_ONLY,
|
|
255
|
+
async execute({ query, limit }) {
|
|
256
|
+
const q = cleanSummaryPart(String(query ?? ""));
|
|
257
|
+
if (!q) return toolError("A search query is required. Pass the words to search for as `query`.");
|
|
258
|
+
const size = clamp(limit, searchPagesLimit, 50);
|
|
259
|
+
const runtime = await fetchPages({
|
|
260
|
+
q,
|
|
261
|
+
limit: size
|
|
262
|
+
});
|
|
263
|
+
reportFetchError("page search", runtime);
|
|
264
|
+
let results = runtime._tag === "Ok" ? runtime.value.results || [] : [];
|
|
265
|
+
if (!results.length) {
|
|
266
|
+
const prerendered = await fetchIndex();
|
|
267
|
+
reportFetchError("prerendered page index", prerendered);
|
|
268
|
+
if (prerendered._tag === "Ok") results = searchIndex(prerendered.value, q, size);
|
|
269
|
+
else if (runtime._tag === "Error" || prerendered._tag === "Error") return toolError("Page search is temporarily unavailable. Retry search_pages shortly.");
|
|
270
|
+
}
|
|
271
|
+
if (!results.length) return toolText(`Nothing matched "${q}". Try fewer or broader words, or call list_pages to see what the site covers.`);
|
|
272
|
+
return formatPages(results, (count) => count ? `${count} result${count === 1 ? "" : "s"} for "${q}".` : `Results for "${q}".`, "narrow the query", searchPagesMaxOutputChars);
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
name: SITE_TOOL_CATALOG.get_page_markdown.name,
|
|
277
|
+
title: SITE_TOOL_CATALOG.get_page_markdown.title,
|
|
278
|
+
description: SITE_TOOL_CATALOG.get_page_markdown.description,
|
|
279
|
+
inputSchema: {
|
|
280
|
+
type: "object",
|
|
281
|
+
properties: { route: {
|
|
282
|
+
type: "string",
|
|
283
|
+
description: SITE_TOOL_CATALOG.get_page_markdown.parameters.route
|
|
284
|
+
} },
|
|
285
|
+
required: ["route"]
|
|
286
|
+
},
|
|
287
|
+
annotations: READ_ONLY,
|
|
288
|
+
async execute({ route }) {
|
|
289
|
+
const path = normalizeSiteRoute(route);
|
|
290
|
+
if (!path) return toolError("A site route is required, such as /about. Call list_pages to see the available routes.");
|
|
291
|
+
const indexed = await indexedRouteExists(path);
|
|
292
|
+
if (indexed._tag === "Error") return toolError("The page index is temporarily unavailable. Retry get_page_markdown shortly.");
|
|
293
|
+
if (!indexed.value) return toolError(`No indexed page found at ${path}. Call search_pages or list_pages to find the correct route.`);
|
|
294
|
+
const markdownPath = toDeployedRoute(toMarkdownPath(path), baseURL);
|
|
295
|
+
const markdown = await fetchResource(markdownPath, { responseType: "text" });
|
|
296
|
+
reportFetchError("page markdown", markdown);
|
|
297
|
+
if (markdown._tag === "Error") return toolError(`Markdown for ${path} is temporarily unavailable. Retry get_page_markdown shortly.`);
|
|
298
|
+
if (markdown._tag === "NotFound" || typeof markdown.value !== "string") return toolError(`No page found at ${path}. Call search_pages or list_pages to find the correct route.`);
|
|
299
|
+
if (!markdown.value) return toolText(`The indexed page at ${path} has no markdown content.`);
|
|
300
|
+
return toolText(truncateToolOutput(markdown.value, getPageMarkdownMaxOutputChars, `Read ${markdownPath} directly for the full page.`));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
];
|
|
304
|
+
const enabled = new Set([
|
|
305
|
+
...listPagesOptions?.enabled === false ? [] : [SITE_TOOL_CATALOG.list_pages.name],
|
|
306
|
+
...searchPagesOptions?.enabled === false ? [] : [SITE_TOOL_CATALOG.search_pages.name],
|
|
307
|
+
...getPageMarkdownOptions?.enabled === false ? [] : [SITE_TOOL_CATALOG.get_page_markdown.name]
|
|
308
|
+
]);
|
|
309
|
+
return tools.filter((tool) => enabled.has(tool.name));
|
|
282
310
|
}
|