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
|
@@ -6,46 +6,47 @@ import { publicCacheControl } from "../../cache-control.js";
|
|
|
6
6
|
import { toDeployedRoute } from "../../route-path.js";
|
|
7
7
|
import { countPages, streamPages } from "../db/queries.js";
|
|
8
8
|
import { buildLlmsFullTxtHeader, formatPageForLlmsFullTxt } from "../utils/llms-full.js";
|
|
9
|
+
// llms-full.txt is streamed during prerender directly to public dir
|
|
10
|
+
// At runtime, this handler streams pages from the database
|
|
9
11
|
export default eventHandler(async (event) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
return sendIterable(event, generateContent());
|
|
12
|
+
assertMethod(event, "GET", true);
|
|
13
|
+
// During prerender, return placeholder (static file will be used)
|
|
14
|
+
if (import.meta.prerender) {
|
|
15
|
+
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
16
|
+
return "# llms-full.txt\n\nThis file is generated during prerender.";
|
|
17
|
+
}
|
|
18
|
+
const runtimeConfig = useRuntimeConfig(event);
|
|
19
|
+
const config = runtimeConfig["nuxt-ai-ready"];
|
|
20
|
+
const siteConfig = getSiteConfig(event);
|
|
21
|
+
const baseURL = runtimeConfig.app.baseURL;
|
|
22
|
+
const canonicalSiteUrl = siteConfig.url ? withSiteUrl(event, toDeployedRoute("/", baseURL), { withBase: true }) : undefined;
|
|
23
|
+
// Build header
|
|
24
|
+
const header = buildLlmsFullTxtHeader({
|
|
25
|
+
name: siteConfig.name,
|
|
26
|
+
url: canonicalSiteUrl,
|
|
27
|
+
description: siteConfig.description
|
|
28
|
+
}, config.llmsTxt);
|
|
29
|
+
// Check if any pages exist
|
|
30
|
+
let total = 0;
|
|
31
|
+
try {
|
|
32
|
+
total = await countPages(event);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
35
|
+
return `${header}Database error: ${err.message || String(err)}\n\nRuntime indexing may not be configured correctly for this environment.`;
|
|
36
|
+
}
|
|
37
|
+
if (total === 0) {
|
|
38
|
+
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
39
|
+
return `${header}No pages indexed. Run \`nuxi generate\` or enable runtime indexing.`;
|
|
40
|
+
}
|
|
41
|
+
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
42
|
+
setResponseHeader(event, "Cache-Control", publicCacheControl(3600, 86400));
|
|
43
|
+
// Stream pages from database using async generator
|
|
44
|
+
const siteUrl = siteConfig.url;
|
|
45
|
+
async function* generateContent() {
|
|
46
|
+
yield header;
|
|
47
|
+
for await (const page of streamPages(event)) {
|
|
48
|
+
yield formatPageForLlmsFullTxt(page.route, page.title, page.description, page.markdown, siteUrl);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return sendIterable(event, generateContent());
|
|
51
52
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("#nuxtseo/h3").EventHandlerWithFetch<import("#nuxtseo/h3").EventHandlerRequest, Promise<string | undefined>>;
|
|
2
2
|
export default _default;
|
|
@@ -3,40 +3,45 @@ import { defineCachedFunction, useRuntimeConfig } from "#nuxtseo/nitro";
|
|
|
3
3
|
import { publicCacheControl } from "../../cache-control.js";
|
|
4
4
|
import { buildLlmsTxtFiles } from "../../llms-txt-utils.js";
|
|
5
5
|
import { toLogicalRoute } from "../../route-path.js";
|
|
6
|
-
const cachedBuilders =
|
|
6
|
+
const cachedBuilders = new Map();
|
|
7
7
|
function getBuildLlmsTxtCached(maxAge) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
let cached = cachedBuilders.get(maxAge);
|
|
9
|
+
if (!cached) {
|
|
10
|
+
cached = defineCachedFunction(buildLlmsTxtFiles, {
|
|
11
|
+
name: "llms-txt-files",
|
|
12
|
+
group: "ai-ready",
|
|
13
|
+
maxAge,
|
|
14
|
+
swr: true,
|
|
15
|
+
// Share one discovery snapshot between root and child files, separated by origin.
|
|
16
|
+
getKey: (event) => getRequestURL(event, {
|
|
17
|
+
xForwardedHost: true,
|
|
18
|
+
xForwardedProto: true
|
|
19
|
+
}).origin
|
|
20
|
+
});
|
|
21
|
+
cachedBuilders.set(maxAge, cached);
|
|
22
|
+
}
|
|
23
|
+
return cached;
|
|
21
24
|
}
|
|
22
25
|
export default eventHandler(async (event) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
// Check the suffix before resolving a request-time base URL.
|
|
27
|
+
const requestPath = event.path.split("?")[0];
|
|
28
|
+
if (!requestPath.endsWith("/llms.txt") && !/\/llms\/[^/]+\.txt$/i.test(requestPath)) return;
|
|
29
|
+
const runtimeConfig = useRuntimeConfig(event);
|
|
30
|
+
const path = toLogicalRoute(event.path.split("?")[0], runtimeConfig.app.baseURL);
|
|
31
|
+
if (path !== "/llms.txt" && !/^\/llms\/[^/]+\.txt$/i.test(path)) return;
|
|
32
|
+
assertMethod(event, "GET", true);
|
|
33
|
+
const config = runtimeConfig["nuxt-ai-ready"];
|
|
34
|
+
const cacheSeconds = config.llmsTxtCacheSeconds;
|
|
35
|
+
// Build output must reflect this build's page index and configuration.
|
|
36
|
+
// An early queued request or a previous build can populate Nitro's cache.
|
|
37
|
+
const cacheEnabled = !import.meta.dev && !import.meta.prerender && cacheSeconds > 0;
|
|
38
|
+
const files = cacheEnabled ? await getBuildLlmsTxtCached(cacheSeconds)(event) : await buildLlmsTxtFiles(event);
|
|
39
|
+
const content = files[path];
|
|
40
|
+
if (content === undefined) throw createError({
|
|
41
|
+
statusCode: 404,
|
|
42
|
+
statusMessage: "llms.txt file not found"
|
|
43
|
+
});
|
|
44
|
+
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
45
|
+
if (cacheEnabled) setHeader(event, "Cache-Control", publicCacheControl(cacheSeconds, 3600));
|
|
46
|
+
return content;
|
|
42
47
|
});
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { defineEventHandler, getRequestHeader, setResponseStatus, useRuntimeConfig } from "nuxt/server";
|
|
2
2
|
import { matchesDiscoveryEtag, MCP_SERVER_CARD_MEDIA_TYPE } from "../utils/discovery-response.js";
|
|
3
3
|
export default defineEventHandler((event) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
const config = useRuntimeConfig()["nuxt-ai-ready"];
|
|
5
|
+
Object.entries({
|
|
6
|
+
"Access-Control-Allow-Headers": "Content-Type, If-None-Match",
|
|
7
|
+
"Access-Control-Allow-Methods": "GET, HEAD",
|
|
8
|
+
"Access-Control-Allow-Origin": "*",
|
|
9
|
+
"Access-Control-Expose-Headers": "ETag",
|
|
10
|
+
"Cache-Control": `public, max-age=${config.mcpServerCard.cacheMaxAge}`,
|
|
11
|
+
"Content-Type": MCP_SERVER_CARD_MEDIA_TYPE,
|
|
12
|
+
"ETag": config.mcpServerCard.etag
|
|
13
|
+
}).forEach(([name, value]) => event.res.headers.set(name, value));
|
|
14
|
+
if (event.req.method === "OPTIONS") {
|
|
15
|
+
setResponseStatus(event, 204);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (matchesDiscoveryEtag(getRequestHeader(event, "if-none-match"), config.mcpServerCard.etag)) {
|
|
19
|
+
setResponseStatus(event, 304);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return config.mcpServerCard.card;
|
|
23
23
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("#nuxtseo/h3").EventHandlerWithFetch<import("#nuxtseo/h3").EventHandlerRequest, Promise<string>>;
|
|
2
2
|
export default _default;
|
|
@@ -9,47 +9,46 @@ import { queryPages } from "../db/queries.js";
|
|
|
9
9
|
import { logger } from "../logger.js";
|
|
10
10
|
import { buildSitemapMd } from "../utils/sitemap-md.js";
|
|
11
11
|
async function buildSitemapMarkdown(event) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
12
|
+
let pages = [];
|
|
13
|
+
try {
|
|
14
|
+
pages = await queryPages(event);
|
|
15
|
+
} catch (err) {
|
|
16
|
+
logger.warn(`[ai-ready] Database unavailable for sitemap.md, serving an empty sitemap: ` + `${err instanceof Error ? err.message : String(err)}`);
|
|
17
|
+
}
|
|
18
|
+
const baseURL = useRuntimeConfig(event).app.baseURL;
|
|
19
|
+
const siteConfig = getSiteConfig(event);
|
|
20
|
+
return buildSitemapMd(pages.map((page) => ({
|
|
21
|
+
route: page.route,
|
|
22
|
+
title: page.title,
|
|
23
|
+
updatedAt: page.updatedAt
|
|
24
|
+
})), {
|
|
25
|
+
siteName: siteConfig.name,
|
|
26
|
+
resolveHref: (route) => absoluteSiteUrl(toDeployedRoute(toMarkdownPath(route), baseURL), siteConfig.url)
|
|
27
|
+
});
|
|
29
28
|
}
|
|
30
|
-
const cachedBuilders =
|
|
29
|
+
const cachedBuilders = new Map();
|
|
31
30
|
function getBuildSitemapMdCached(maxAge) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
let cached = cachedBuilders.get(maxAge);
|
|
32
|
+
if (!cached) {
|
|
33
|
+
cached = defineCachedFunction(buildSitemapMarkdown, {
|
|
34
|
+
name: "sitemap-md",
|
|
35
|
+
group: "ai-ready",
|
|
36
|
+
maxAge,
|
|
37
|
+
swr: true
|
|
38
|
+
});
|
|
39
|
+
cachedBuilders.set(maxAge, cached);
|
|
40
|
+
}
|
|
41
|
+
return cached;
|
|
43
42
|
}
|
|
44
43
|
export default eventHandler(async (event) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
assertMethod(event, "GET", true);
|
|
45
|
+
const fullRuntimeConfig = useRuntimeConfig(event);
|
|
46
|
+
const runtimeConfig = fullRuntimeConfig["nuxt-ai-ready"];
|
|
47
|
+
const cacheSeconds = runtimeConfig.llmsTxtCacheSeconds ?? 600;
|
|
48
|
+
const cacheEnabled = !import.meta.dev && cacheSeconds > 0;
|
|
49
|
+
setHeader(event, "Content-Type", "text/markdown; charset=utf-8");
|
|
50
|
+
if (cacheEnabled) {
|
|
51
|
+
setHeader(event, "Cache-Control", publicCacheControl(cacheSeconds, 3600));
|
|
52
|
+
}
|
|
53
|
+
return cacheEnabled ? await getBuildSitemapMdCached(cacheSeconds)(event) : await buildSitemapMarkdown(event);
|
|
55
54
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("nitropack").Task<import("../utils/runCron.js").CronResult>;
|
|
2
2
|
export default _default;
|
|
@@ -2,18 +2,21 @@ import { defineTask } from "#nuxtseo/nitro";
|
|
|
2
2
|
import { logger } from "../logger.js";
|
|
3
3
|
import { runCron } from "../utils/runCron.js";
|
|
4
4
|
export default defineTask({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
meta: {
|
|
6
|
+
name: "ai-ready:cron",
|
|
7
|
+
description: "Scheduled task for AI Ready indexing"
|
|
8
|
+
},
|
|
9
|
+
async run({ payload }) {
|
|
10
|
+
// Skip in dev - context not fully available
|
|
11
|
+
if (import.meta.dev) return { result: {} };
|
|
12
|
+
// Don't pass an event - tasks run outside request context
|
|
13
|
+
// runCron and its dependencies use useRuntimeConfig() without event
|
|
14
|
+
const result = await runCron(undefined, { batchSize: payload?.limit });
|
|
15
|
+
// runCron reports a failure rather than throwing, because a throw from a
|
|
16
|
+
// scheduled task has no handler above it and reaches the platform as an
|
|
17
|
+
// opaque exception. Logging it here is what makes it visible to whatever
|
|
18
|
+
// reads the task's output.
|
|
19
|
+
if (result.failed) logger.error(`[ai-ready:cron] Run failed at the ${result.failed.stage} stage: ${result.failed.message}`);
|
|
20
|
+
return { result };
|
|
21
|
+
}
|
|
19
22
|
});
|
|
@@ -4,68 +4,91 @@ import { createError, getHeader, getQuery } from "#nuxtseo/h3";
|
|
|
4
4
|
import { useRuntimeConfig } from "#nuxtseo/nitro";
|
|
5
5
|
import { APPLICATION_SECRET_ERROR, deriveRuntimeSyncSecret, LEGACY_RUNTIME_SYNC_SECRET_WARNING, RUNTIME_SYNC_SECRET_PURPOSE } from "../../sync-secret.js";
|
|
6
6
|
import { getCfEnv } from "./cloudflare.js";
|
|
7
|
-
const HMAC = {
|
|
7
|
+
const HMAC = {
|
|
8
|
+
name: "HMAC",
|
|
9
|
+
hash: "SHA-256"
|
|
10
|
+
};
|
|
11
|
+
// Keep one successful or pending verifier. Rotation replaces the entry.
|
|
8
12
|
let tokenVerifier;
|
|
9
13
|
let warnedLegacy = false;
|
|
10
14
|
function encodeToken(token) {
|
|
11
|
-
|
|
15
|
+
// UTF-8 replaces unpaired surrogates and can collapse distinct legacy tokens.
|
|
16
|
+
return Uint16Array.from({ length: token.length }, (_, index) => token.charCodeAt(index));
|
|
12
17
|
}
|
|
13
18
|
async function createTokenVerifier(token) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
const { subtle } = globalThis.crypto;
|
|
20
|
+
const key = await subtle.generateKey(HMAC, false, ["sign", "verify"]);
|
|
21
|
+
const signature = await subtle.sign(HMAC, key, encodeToken(token));
|
|
22
|
+
return {
|
|
23
|
+
length: token.length,
|
|
24
|
+
key,
|
|
25
|
+
signature
|
|
26
|
+
};
|
|
18
27
|
}
|
|
19
28
|
function resolveToken(source, mode) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return entry.promise;
|
|
29
|
+
if (tokenVerifier?.source === source && tokenVerifier.mode === mode) return tokenVerifier.promise;
|
|
30
|
+
// Nuxt reads its root synchronously, before the first crypto await.
|
|
31
|
+
const token = mode === "nuxt" ? deriveSecret(RUNTIME_SYNC_SECRET_PURPOSE) : mode === "binding" ? deriveRuntimeSyncSecret(source) : Promise.resolve(source);
|
|
32
|
+
const entry = {
|
|
33
|
+
source,
|
|
34
|
+
mode,
|
|
35
|
+
promise: token.then(createTokenVerifier)
|
|
36
|
+
};
|
|
37
|
+
tokenVerifier = entry;
|
|
38
|
+
entry.promise = entry.promise.catch((cause) => {
|
|
39
|
+
if (tokenVerifier === entry) tokenVerifier = undefined;
|
|
40
|
+
throw cause;
|
|
41
|
+
});
|
|
42
|
+
return entry.promise;
|
|
35
43
|
}
|
|
36
44
|
async function resolveExpectedToken(event) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
const bindings = getCfEnv(event);
|
|
46
|
+
const bindingRoot = bindings?.NUXT_APP_SECRET;
|
|
47
|
+
const configuredRoot = bindingRoot === undefined ? useRuntimeConfig(event).appSecret : bindingRoot;
|
|
48
|
+
if (configuredRoot === undefined || configuredRoot === "") {
|
|
49
|
+
const moduleConfig = useRuntimeConfig(event)["nuxt-ai-ready"];
|
|
50
|
+
const legacy = bindings?.NUXT_NUXT_AI_READY_RUNTIME_SYNC_SECRET ?? bindings?.NUXT_AI_READY_RUNTIME_SYNC_SECRET ?? globalThis.process?.env?.NUXT_NUXT_AI_READY_RUNTIME_SYNC_SECRET ?? globalThis.process?.env?.NUXT_AI_READY_RUNTIME_SYNC_SECRET ?? moduleConfig?.runtimeSyncSecret;
|
|
51
|
+
if (typeof legacy !== "string" || !legacy) throw createError({
|
|
52
|
+
statusCode: 500,
|
|
53
|
+
message: APPLICATION_SECRET_ERROR
|
|
54
|
+
});
|
|
55
|
+
if (!warnedLegacy) {
|
|
56
|
+
warnedLegacy = true;
|
|
57
|
+
logger.warn(LEGACY_RUNTIME_SYNC_SECRET_WARNING);
|
|
58
|
+
}
|
|
59
|
+
return resolveToken(legacy, "legacy");
|
|
60
|
+
}
|
|
61
|
+
// Nuxt derives with no event argument. Nitro 2 bindings require direct derivation.
|
|
62
|
+
const mode = bindingRoot === undefined ? "nuxt" : "binding";
|
|
63
|
+
const root = mode === "nuxt" ? useRuntimeConfig().appSecret : bindingRoot;
|
|
64
|
+
if (typeof root !== "string" || root.length < 32) throw createError({
|
|
65
|
+
statusCode: 500,
|
|
66
|
+
message: APPLICATION_SECRET_ERROR
|
|
67
|
+
});
|
|
68
|
+
return resolveToken(root, mode).catch((cause) => {
|
|
69
|
+
throw createError({
|
|
70
|
+
statusCode: 500,
|
|
71
|
+
message: APPLICATION_SECRET_ERROR,
|
|
72
|
+
cause
|
|
73
|
+
});
|
|
74
|
+
});
|
|
58
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Verify the runtime sync token. Throws 401 if the token is missing or invalid.
|
|
78
|
+
*/
|
|
59
79
|
export async function requireAuth(event) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
const secret = await resolveExpectedToken(event);
|
|
81
|
+
const authHeader = getHeader(event, "authorization");
|
|
82
|
+
const bearer = authHeader?.startsWith("Bearer ") ? authHeader.slice(7) : undefined;
|
|
83
|
+
const querySecret = bearer ? undefined : getQuery(event).secret;
|
|
84
|
+
const received = bearer || (querySecret ? String(querySecret) : "");
|
|
85
|
+
if (received.length !== secret.length || !await globalThis.crypto.subtle.verify(HMAC, secret.key, secret.signature, encodeToken(received))) {
|
|
86
|
+
throw createError({
|
|
87
|
+
statusCode: 401,
|
|
88
|
+
message: "Unauthorized"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (querySecret) {
|
|
92
|
+
logger.warn("Using `?secret=` is deprecated. Use the Authorization header with a bearer token.");
|
|
93
|
+
}
|
|
71
94
|
}
|