nuxt-ai-ready 3.6.0 → 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 +20 -24
- 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
|
@@ -12,103 +12,148 @@ import { logger } from "./server/logger.js";
|
|
|
12
12
|
import { fetchSitemapUrlGroups, getSitemapsFromConfig } from "./server/utils/sitemap.js";
|
|
13
13
|
export { normalizeLlmsTxtConfig } from "./llms-txt-format.js";
|
|
14
14
|
async function findMarkdownLinkAvailability() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
if (!import.meta.prerender) return {
|
|
16
|
+
runtimeMarkdownAvailable: prerenderedMarkdownPaths === null,
|
|
17
|
+
paths: prerenderedMarkdownPaths ?? new Set()
|
|
18
|
+
};
|
|
19
|
+
const { readMarkdownLinkAvailabilityFromFilesystem } = await import("#ai-ready-virtual/read-page-data.mjs");
|
|
20
|
+
const availability = await readMarkdownLinkAvailabilityFromFilesystem();
|
|
21
|
+
return {
|
|
22
|
+
runtimeMarkdownAvailable: availability.runtimeMarkdownAvailable,
|
|
23
|
+
paths: new Set(availability.paths.map(decodePath))
|
|
24
|
+
};
|
|
23
25
|
}
|
|
26
|
+
/** One discovery snapshot supplies the root and every bounded child file. */
|
|
24
27
|
export async function buildLlmsTxtFiles(event) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
28
|
+
const runtimeConfig = useRuntimeConfig(event);
|
|
29
|
+
const aiReadyConfig = runtimeConfig["nuxt-ai-ready"];
|
|
30
|
+
const siteConfig = getSiteConfig(event);
|
|
31
|
+
const config = aiReadyConfig.llmsTxt;
|
|
32
|
+
const baseURL = runtimeConfig.app.baseURL;
|
|
33
|
+
const resolveUrl = (path) => withSiteUrl(event, toDeployedRoute(path, baseURL), { withBase: true });
|
|
34
|
+
const resolvePageUrl = (path) => resolveUrl(withSiteTrailingSlash(event, path));
|
|
35
|
+
const canonicalSiteUrl = siteConfig.url ? resolveUrl("/") : undefined;
|
|
36
|
+
const i18n = aiReadyConfig.i18n;
|
|
37
|
+
const i18nRuntime = i18n ? {
|
|
38
|
+
_tag: "enabled",
|
|
39
|
+
config: i18n,
|
|
40
|
+
...await import("./llms-txt-i18n.js")
|
|
41
|
+
} : { _tag: "disabled" };
|
|
42
|
+
const i18nContext = { host: getRequestHost(event, { xForwardedHost: true }) };
|
|
43
|
+
const parts = [`# ${(siteConfig.name || canonicalSiteUrl || "Site").replace(/\s+/g, " ").trim()}`];
|
|
44
|
+
if (siteConfig.description) parts.push("", `> ${siteConfig.description.replace(/\s+/g, " ").trim()}`);
|
|
45
|
+
if (canonicalSiteUrl) parts.push("", `Canonical Origin: ${canonicalSiteUrl}`);
|
|
46
|
+
const sections = config.sections?.map((section) => ({
|
|
47
|
+
...section,
|
|
48
|
+
links: section.links ? [...section.links] : undefined
|
|
49
|
+
})) ?? [];
|
|
50
|
+
const resources = sections.find((section) => section.title === "LLM Resources" && !section.sitemap);
|
|
51
|
+
if (resources) {
|
|
52
|
+
resources.links ||= [];
|
|
53
|
+
for (const sitemap of getSitemapsFromConfig(event).filter((sitemap) => config.sitemaps === undefined || config.sitemaps.includes(sitemap.name))) {
|
|
54
|
+
resources.links.push({
|
|
55
|
+
title: sitemap.route.split("/").pop() || `${sitemap.name}.xml`,
|
|
56
|
+
href: resolveUrl(toLogicalRoute(sitemap.route, baseURL)),
|
|
57
|
+
description: "XML sitemap for search engines and crawlers."
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (!getSitemapsFromConfig(event).length && (config.sitemaps === undefined || config.sitemaps.includes("sitemap"))) {
|
|
61
|
+
resources.links.push({
|
|
62
|
+
title: "sitemap.xml",
|
|
63
|
+
href: resolveUrl("/sitemap.xml"),
|
|
64
|
+
description: "XML sitemap for search engines and crawlers."
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
resources.links.push({
|
|
68
|
+
title: "robots.txt",
|
|
69
|
+
href: resolveUrl("/robots.txt"),
|
|
70
|
+
description: "Crawler rules and permissions."
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (config.pages === false && !sections.some((section) => section.sitemap)) {
|
|
74
|
+
return Object.fromEntries(createLlmsTxtFiles({
|
|
75
|
+
header: parts.join("\n"),
|
|
76
|
+
config,
|
|
77
|
+
sections,
|
|
78
|
+
pages: [],
|
|
79
|
+
sitemapPages: new Map(),
|
|
80
|
+
resolveUrl
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
// Database rows supply metadata. The selected sitemap supplies admission.
|
|
84
|
+
const groups = await fetchSitemapUrlGroups(event, config.sitemaps);
|
|
85
|
+
const allowedOrigin = canonicalSiteUrl ? new URL(canonicalSiteUrl).origin : undefined;
|
|
86
|
+
const requestOrigin = getRequestURL(event, {
|
|
87
|
+
xForwardedHost: true,
|
|
88
|
+
xForwardedProto: true
|
|
89
|
+
}).origin;
|
|
90
|
+
const sitemapPaths = new Map();
|
|
91
|
+
for (const [name, urls] of groups) {
|
|
92
|
+
const paths = new Set();
|
|
93
|
+
for (const entry of urls) {
|
|
94
|
+
const url = URL.canParse(entry.loc, canonicalSiteUrl || "http://localhost") ? new URL(entry.loc, canonicalSiteUrl || "http://localhost") : undefined;
|
|
95
|
+
if (!url || url.search || url.hash || allowedOrigin && url.origin !== allowedOrigin && url.origin !== requestOrigin) continue;
|
|
96
|
+
const path = toLogicalRoute(url.pathname, baseURL);
|
|
97
|
+
paths.add(path);
|
|
98
|
+
}
|
|
99
|
+
sitemapPaths.set(name, paths);
|
|
100
|
+
}
|
|
101
|
+
const admitted = new Set([...sitemapPaths.values()].flatMap((paths) => [...paths]));
|
|
102
|
+
// The query layer selects build storage during prerender and runtime storage otherwise.
|
|
103
|
+
const read = config.pages === "all" ? Promise.all([queryPages(event), queryPages(event, { where: { hasError: true } })]).then((results) => results.flat()) : queryPageMetadata(event, [...admitted].flatMap((path) => [path, toDeployedRoute(path, baseURL)]));
|
|
104
|
+
const stored = await read.catch((error) => {
|
|
105
|
+
logger.warn(`[ai-ready] Database unavailable for llms.txt. Using sitemap metadata: ${error instanceof Error ? error.message : String(error)}`);
|
|
106
|
+
return [];
|
|
107
|
+
});
|
|
108
|
+
const errorPaths = new Set(stored.filter((page) => page.isError).map((page) => normalizePersistedRoute(page.route, admitted, baseURL)));
|
|
109
|
+
const metadata = new Map(stored.map((page) => [normalizePersistedRoute(page.route, admitted, baseURL), page]));
|
|
110
|
+
const availability = config.markdownLinks ? await findMarkdownLinkAvailability() : undefined;
|
|
111
|
+
const href = (path) => {
|
|
112
|
+
const markdownPath = toMarkdownPath(path);
|
|
113
|
+
if (availability && (availability.paths.has(decodePath(toDeployedRoute(markdownPath, baseURL))) || availability.runtimeMarkdownAvailable && hasMarkdownTwin(path))) return resolveUrl(markdownPath);
|
|
114
|
+
return resolvePageUrl(path);
|
|
115
|
+
};
|
|
116
|
+
const pageMap = new Map();
|
|
117
|
+
const candidates = config.pages === "all" ? new Set([...admitted, ...metadata.keys()]) : admitted;
|
|
118
|
+
for (const pathname of [...candidates].sort()) {
|
|
119
|
+
if (errorPaths.has(pathname)) continue;
|
|
120
|
+
const page = metadata.get(pathname);
|
|
121
|
+
const locale = page?.locale || (i18nRuntime._tag === "enabled" ? i18nRuntime.resolveLocaleFromRoute(pathname, i18nRuntime.config, i18nContext).locale : undefined);
|
|
122
|
+
pageMap.set(pathname, {
|
|
123
|
+
pathname,
|
|
124
|
+
href: href(pathname),
|
|
125
|
+
title: page?.title,
|
|
126
|
+
description: page?.description,
|
|
127
|
+
locale
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
let rootContent;
|
|
131
|
+
if (i18nRuntime._tag === "enabled") {
|
|
132
|
+
const counts = new Map();
|
|
133
|
+
for (const page of pageMap.values()) counts.set(page.locale, (counts.get(page.locale) || 0) + 1);
|
|
134
|
+
rootContent = i18nRuntime.formatAvailableLanguagesSection(i18nRuntime.config, counts, href, i18nContext).join("\n");
|
|
135
|
+
for (const [path, page] of pageMap) {
|
|
136
|
+
if (page.locale !== i18nRuntime.config.defaultLocale) pageMap.delete(path);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const sitemapPages = new Map([...sitemapPaths].map(([name, paths]) => [name, [...paths].flatMap((path) => pageMap.has(path) ? [pageMap.get(path)] : [])]));
|
|
140
|
+
return Object.fromEntries(createLlmsTxtFiles({
|
|
141
|
+
header: parts.join("\n"),
|
|
142
|
+
config,
|
|
143
|
+
sections,
|
|
144
|
+
rootContent,
|
|
145
|
+
pages: config.pages === false ? [] : [...pageMap.values()],
|
|
146
|
+
sitemapPages,
|
|
147
|
+
resolveUrl
|
|
148
|
+
}));
|
|
106
149
|
}
|
|
107
150
|
export async function buildLlmsTxt(event) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
151
|
+
const files = await buildLlmsTxtFiles(event);
|
|
152
|
+
const path = toLogicalRoute(event.path.split("?")[0], useRuntimeConfig(event).app.baseURL);
|
|
153
|
+
const content = files[path];
|
|
154
|
+
if (content === undefined) throw createError({
|
|
155
|
+
statusCode: 404,
|
|
156
|
+
statusMessage: "llms.txt file not found"
|
|
157
|
+
});
|
|
158
|
+
return content;
|
|
114
159
|
}
|
|
@@ -2,51 +2,57 @@ const RE_FENCE = /^ {0,3}(`{3,}|~{3,})/;
|
|
|
2
2
|
const RE_INLINE_ROOT_LINK = /\]\((<?)\/(?!\/)/g;
|
|
3
3
|
const RE_REFERENCE_ROOT_LINK = /^( {0,3}\[[^\]]+\]:[\t ]*<?)\/(?!\/)/;
|
|
4
4
|
function closesFence(line, fence) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const trimmed = line.trim();
|
|
6
|
+
return trimmed.length >= fence.length && trimmed[0] === fence[0] && [...trimmed].every((char) => char === fence[0]);
|
|
7
7
|
}
|
|
8
8
|
function backtickRun(line, start) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return end - start;
|
|
9
|
+
let end = start;
|
|
10
|
+
while (line[end] === "`") end++;
|
|
11
|
+
return end - start;
|
|
13
12
|
}
|
|
13
|
+
/** Code spans open and close with backtick runs of the same length. */
|
|
14
14
|
function rewriteOutsideCodeSpans(line, rewrite) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return output + rewrite(line.slice(last));
|
|
15
|
+
let output = "";
|
|
16
|
+
let last = 0;
|
|
17
|
+
let index = line.indexOf("`");
|
|
18
|
+
while (index !== -1) {
|
|
19
|
+
const length = backtickRun(line, index);
|
|
20
|
+
let close = line.indexOf("`", index + length);
|
|
21
|
+
while (close !== -1 && backtickRun(line, close) !== length) close = line.indexOf("`", close + backtickRun(line, close));
|
|
22
|
+
if (close === -1) {
|
|
23
|
+
index = line.indexOf("`", index + length);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
output += rewrite(line.slice(last, index)) + line.slice(index, close + length);
|
|
27
|
+
last = close + length;
|
|
28
|
+
index = line.indexOf("`", last);
|
|
29
|
+
}
|
|
30
|
+
return output + rewrite(line.slice(last));
|
|
32
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolve root-relative link and image destinations against a site origin.
|
|
34
|
+
*
|
|
35
|
+
* A Markdown page read on its own, by an agent or from `llms-full.txt`, has
|
|
36
|
+
* no page URL to resolve `/docs/api` against, so such a link loses its
|
|
37
|
+
* target. Fenced code and inline code spans keep their text.
|
|
38
|
+
*/
|
|
33
39
|
export function absoluteMarkdownLinks(markdown, siteUrl) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}).join("");
|
|
40
|
+
const origin = new URL(siteUrl).origin;
|
|
41
|
+
let fence;
|
|
42
|
+
return markdown.split(/(?<=\n)/).map((line) => {
|
|
43
|
+
if (fence) {
|
|
44
|
+
if (closesFence(line, fence)) fence = undefined;
|
|
45
|
+
return line;
|
|
46
|
+
}
|
|
47
|
+
const opening = line.match(RE_FENCE);
|
|
48
|
+
if (opening) {
|
|
49
|
+
fence = opening[1];
|
|
50
|
+
return line;
|
|
51
|
+
}
|
|
52
|
+
return rewriteOutsideCodeSpans(line, (text) => text.replace(RE_REFERENCE_ROOT_LINK, `$1${origin}/`).replace(RE_INLINE_ROOT_LINK, `]($1${origin}/`));
|
|
53
|
+
}).join("");
|
|
49
54
|
}
|
|
55
|
+
/** A deployed path on the site's origin, or the path itself when no site URL is known. */
|
|
50
56
|
export function absoluteSiteUrl(path, siteUrl) {
|
|
51
|
-
|
|
57
|
+
return siteUrl ? new URL(path, new URL(siteUrl).origin).href : path;
|
|
52
58
|
}
|
|
@@ -1,22 +1,42 @@
|
|
|
1
1
|
const RE_TRAILING_SLASHES = /\/+$/;
|
|
2
|
+
// A file extension starts with a letter: `.png`, `.avif`, `.md`. The `.2` in
|
|
3
|
+
// `/v1.2` does not, so that segment names a page.
|
|
2
4
|
const RE_FILE_EXTENSION = /\.[a-z][a-z\d]*$/i;
|
|
5
|
+
/**
|
|
6
|
+
* Nitro's `/_*` and `/api` namespaces, plus Vite's dev-server internals.
|
|
7
|
+
*
|
|
8
|
+
* The `@` group names each Vite prefix rather than all of `/@`. A bare `/@`
|
|
9
|
+
* also matches a profile namespace such as `/@login`, which Mastodon, Bluesky
|
|
10
|
+
* and skilld.dev all use for their most agent-facing pages. Reserving those
|
|
11
|
+
* left every profile page advertising a `.md` sibling that the markdown
|
|
12
|
+
* handler then refused to serve.
|
|
13
|
+
*/
|
|
3
14
|
const RE_RESERVED_PATH = /^\/(?:api(?:\/|$)|_|@(?:id|fs|vite|react-refresh)(?:\/|$))/;
|
|
15
|
+
/** True for the `/api` namespace, Nitro's `/_*` paths, and Vite's `/@*` internals. */
|
|
4
16
|
export function isReservedPath(path) {
|
|
5
|
-
|
|
17
|
+
return RE_RESERVED_PATH.test(path);
|
|
6
18
|
}
|
|
7
19
|
export function normalizePagePath(path) {
|
|
8
|
-
|
|
20
|
+
return path.replace(RE_TRAILING_SLASHES, "") || "/";
|
|
9
21
|
}
|
|
10
22
|
export function toMarkdownPath(path) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return `${normalizedPath}.md`;
|
|
23
|
+
const normalizedPath = normalizePagePath(path);
|
|
24
|
+
if (normalizedPath === "/") return "/index.md";
|
|
25
|
+
return `${normalizedPath}.md`;
|
|
15
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* True when a path names a page with a `.md` twin: outside the reserved
|
|
29
|
+
* namespaces, and not a file such as `/feed.xml`. A dot alone does not make a
|
|
30
|
+
* file, so `/v1.2` is a page.
|
|
31
|
+
*
|
|
32
|
+
* Prerendering and every advertisement read this one predicate, so a page
|
|
33
|
+
* cannot link a representation the build or the markdown handler lacks.
|
|
34
|
+
*/
|
|
16
35
|
export function hasMarkdownTwin(path) {
|
|
17
|
-
|
|
18
|
-
|
|
36
|
+
const lastSegment = normalizePagePath(path).split("/").pop() || "";
|
|
37
|
+
return !isReservedPath(path) && !RE_FILE_EXTENSION.test(lastSegment);
|
|
19
38
|
}
|
|
39
|
+
/** The `.md` sibling a page may advertise, or null when it has none. */
|
|
20
40
|
export function markdownAlternatePath(path) {
|
|
21
|
-
|
|
41
|
+
return hasMarkdownTwin(path) ? toMarkdownPath(path) : null;
|
|
22
42
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Keep plain metadata literal when Markdown allows inline HTML. */
|
|
1
2
|
export function escapeMarkdownHtml(value) {
|
|
2
|
-
|
|
3
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
3
4
|
}
|
package/dist/runtime/mcp.js
CHANGED
|
@@ -2,5 +2,9 @@ import pages from "./server/mcp/resources/pages.js";
|
|
|
2
2
|
import getPageMarkdown from "./server/mcp/tools/get-page-markdown.js";
|
|
3
3
|
import listPages from "./server/mcp/tools/list-pages.js";
|
|
4
4
|
import searchPages from "./server/mcp/tools/search-pages.js";
|
|
5
|
-
export const tools = [
|
|
5
|
+
export const tools = [
|
|
6
|
+
listPages,
|
|
7
|
+
searchPages,
|
|
8
|
+
getPageMarkdown
|
|
9
|
+
];
|
|
6
10
|
export const resources = [pages];
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { joinURL, parseURL, withLeadingSlash, withoutBase } from "ufo";
|
|
2
2
|
import { normalizePagePath } from "./markdown-path.js";
|
|
3
|
+
/** Convert a sitemap URL (which includes app.baseURL) to a logical route. */
|
|
3
4
|
export function toLogicalRoute(pathOrUrl, baseURL) {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
const pathname = withLeadingSlash(parseURL(pathOrUrl).pathname);
|
|
6
|
+
return normalizePagePath(withoutBase(pathname, baseURL));
|
|
6
7
|
}
|
|
8
|
+
/** Apply app.baseURL to a logical route exactly once. */
|
|
7
9
|
export function toDeployedRoute(route, baseURL) {
|
|
8
|
-
|
|
10
|
+
return joinURL(baseURL, withLeadingSlash(route));
|
|
9
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Normalize rows written by older releases, which stored deployed paths.
|
|
14
|
+
* A sitemap match disambiguates those rows from real logical routes whose
|
|
15
|
+
* first segment happens to match app.baseURL.
|
|
16
|
+
*/
|
|
10
17
|
export function normalizePersistedRoute(route, sitemapRoutes, baseURL) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return sitemapRoutes.has(logicalRoute) ? logicalRoute : normalizedRoute;
|
|
18
|
+
const normalizedRoute = normalizePagePath(withLeadingSlash(parseURL(route).pathname));
|
|
19
|
+
if (sitemapRoutes.has(normalizedRoute)) return normalizedRoute;
|
|
20
|
+
const logicalRoute = toLogicalRoute(normalizedRoute, baseURL);
|
|
21
|
+
return sitemapRoutes.has(logicalRoute) ? logicalRoute : normalizedRoute;
|
|
16
22
|
}
|
|
@@ -3,91 +3,87 @@ import { closeDriver } from "./raw.js";
|
|
|
3
3
|
let fallbackClient;
|
|
4
4
|
let fallbackClientPromise;
|
|
5
5
|
function createDrizzleClient(event) {
|
|
6
|
-
|
|
6
|
+
return import("#ai-ready-virtual/db-provider.mjs").then(({ createClient }) => createClient(event));
|
|
7
7
|
}
|
|
8
8
|
function getRequestOwner(event) {
|
|
9
|
-
|
|
9
|
+
return event.node?.req ?? event.req ?? event;
|
|
10
10
|
}
|
|
11
11
|
function getDrizzleWorkState(event) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const context = event.context;
|
|
13
|
+
return context[DB_WORK_CONTEXT_KEY] ??= {
|
|
14
|
+
_tag: "ResponseOpen",
|
|
15
|
+
owner: getRequestOwner(event),
|
|
16
|
+
pending: new Set(),
|
|
17
|
+
cleanup: () => closeDrizzle(event)
|
|
18
|
+
};
|
|
19
19
|
}
|
|
20
|
+
/** Keep request-scoped clients alive until deferred database work finishes. */
|
|
20
21
|
export function trackDrizzleWork(event, work) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return tracked;
|
|
22
|
+
const state = getDrizzleWorkState(event);
|
|
23
|
+
const tracked = work.finally(async () => {
|
|
24
|
+
state.pending.delete(tracked);
|
|
25
|
+
if (state._tag === "ResponseEnded" && state.pending.size === 0) await state.cleanup();
|
|
26
|
+
});
|
|
27
|
+
state.pending.add(tracked);
|
|
28
|
+
return tracked;
|
|
29
29
|
}
|
|
30
|
+
/** Transfer client cleanup to deferred work after the response ends. */
|
|
30
31
|
export async function finishDrizzleResponse(event) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (state.pending.size === 0)
|
|
36
|
-
await closeDrizzle(event);
|
|
32
|
+
const state = getDrizzleWorkState(event);
|
|
33
|
+
if (state.owner !== getRequestOwner(event)) return;
|
|
34
|
+
state._tag = "ResponseEnded";
|
|
35
|
+
if (state.pending.size === 0) await closeDrizzle(event);
|
|
37
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Get Drizzle database instance
|
|
39
|
+
*/
|
|
38
40
|
export async function useDrizzle(event) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
fallbackClientPromise = promise;
|
|
71
|
-
return promise;
|
|
41
|
+
if (event?.context?.[DB_CONTEXT_KEY]) {
|
|
42
|
+
return event.context[DB_CONTEXT_KEY];
|
|
43
|
+
}
|
|
44
|
+
if (event?.context?.[DB_PROMISE_CONTEXT_KEY]) {
|
|
45
|
+
return event.context[DB_PROMISE_CONTEXT_KEY];
|
|
46
|
+
}
|
|
47
|
+
if (!event && fallbackClient) {
|
|
48
|
+
return fallbackClient;
|
|
49
|
+
}
|
|
50
|
+
if (!event && fallbackClientPromise) return fallbackClientPromise;
|
|
51
|
+
if (event?.context) {
|
|
52
|
+
getDrizzleWorkState(event);
|
|
53
|
+
const context = event.context;
|
|
54
|
+
const promise = createDrizzleClient(event).then((client) => {
|
|
55
|
+
context[DB_CONTEXT_KEY] = client;
|
|
56
|
+
return client;
|
|
57
|
+
}).finally(() => {
|
|
58
|
+
if (context[DB_PROMISE_CONTEXT_KEY] === promise) delete context[DB_PROMISE_CONTEXT_KEY];
|
|
59
|
+
});
|
|
60
|
+
context[DB_PROMISE_CONTEXT_KEY] = promise;
|
|
61
|
+
return promise;
|
|
62
|
+
}
|
|
63
|
+
const promise = createDrizzleClient().then((client) => {
|
|
64
|
+
fallbackClient = client;
|
|
65
|
+
return client;
|
|
66
|
+
}).finally(() => {
|
|
67
|
+
if (fallbackClientPromise === promise) fallbackClientPromise = undefined;
|
|
68
|
+
});
|
|
69
|
+
fallbackClientPromise = promise;
|
|
70
|
+
return promise;
|
|
72
71
|
}
|
|
73
72
|
export async function closeDrizzle(event) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
fallbackClient = void 0;
|
|
91
|
-
fallbackClientPromise = void 0;
|
|
92
|
-
}
|
|
73
|
+
if (event?.context) {
|
|
74
|
+
const context = event.context;
|
|
75
|
+
const state = context[DB_WORK_CONTEXT_KEY];
|
|
76
|
+
if (state && state.owner !== getRequestOwner(event)) return;
|
|
77
|
+
const client = context[DB_CONTEXT_KEY] ?? await context[DB_PROMISE_CONTEXT_KEY];
|
|
78
|
+
if (!client) return;
|
|
79
|
+
await closeDriver(client.db);
|
|
80
|
+
delete context[DB_CONTEXT_KEY];
|
|
81
|
+
delete context[DB_PROMISE_CONTEXT_KEY];
|
|
82
|
+
} else if (!event) {
|
|
83
|
+
const client = fallbackClient ?? await fallbackClientPromise;
|
|
84
|
+
if (!client) return;
|
|
85
|
+
await closeDriver(client.db);
|
|
86
|
+
fallbackClient = undefined;
|
|
87
|
+
fallbackClientPromise = undefined;
|
|
88
|
+
}
|
|
93
89
|
}
|