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
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* H3 1 uses stack position 1, after Nitro's route-rules layer. H3 2 prepends
|
|
10
10
|
* the global middleware list. Its dispatcher adds route-rule middleware first.
|
|
11
11
|
*/
|
|
12
|
-
declare const _default:
|
|
12
|
+
declare const _default: import("nitropack").NitroAppPlugin;
|
|
13
13
|
export default _default;
|
|
@@ -2,61 +2,80 @@ import { decodePath, withoutBase, withoutTrailingSlash } from "ufo";
|
|
|
2
2
|
import prerenderedMarkdownHeaders from "#ai-ready-virtual/prerendered-markdown-headers.mjs";
|
|
3
3
|
import { defineEventHandler, getRequestURL, setHeader } from "#nuxtseo/h3";
|
|
4
4
|
import { defineNitroPlugin, useRuntimeConfig } from "#nuxtseo/nitro";
|
|
5
|
+
import { isReservedPath } from "../../markdown-path.js";
|
|
5
6
|
import { logger } from "../logger.js";
|
|
6
7
|
import { serveCloudflarePrerenderedPage } from "../utils/cloudflare-prerendered.js";
|
|
8
|
+
import { withoutQuery } from "../utils/negotiation-decision.js";
|
|
7
9
|
import { applyNegotiation, decideNegotiation } from "../utils/negotiation-response.js";
|
|
8
10
|
function isH3App(candidate) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return Array.isArray(app.stack) && typeof app.use === "function";
|
|
11
|
+
if (!candidate || typeof candidate !== "object") return false;
|
|
12
|
+
const app = candidate;
|
|
13
|
+
return Array.isArray(app.stack) && typeof app.use === "function";
|
|
13
14
|
}
|
|
14
15
|
function isH3Core(candidate) {
|
|
15
|
-
|
|
16
|
+
return !!candidate && typeof candidate === "object" && Array.isArray(candidate["~middleware"]);
|
|
16
17
|
}
|
|
17
18
|
function resolveH3Runtime(candidate) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
if (!candidate || typeof candidate !== "object") return { _tag: "unsupported" };
|
|
20
|
+
const nitro = candidate;
|
|
21
|
+
if (isH3App(nitro.h3App)) return {
|
|
22
|
+
_tag: "h3-v1",
|
|
23
|
+
app: nitro.h3App
|
|
24
|
+
};
|
|
25
|
+
if (isH3Core(nitro.h3)) return {
|
|
26
|
+
_tag: "h3-v2",
|
|
27
|
+
app: nitro.h3
|
|
28
|
+
};
|
|
29
|
+
return { _tag: "unsupported" };
|
|
26
30
|
}
|
|
27
31
|
const negotiationHandler = defineEventHandler(async (event) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
if (prerenderedMarkdownHeaders.size) {
|
|
33
|
+
const pathname = withoutQuery(event.path);
|
|
34
|
+
if ((pathname.includes(".md") || pathname.includes("%")) && !isReservedPath(pathname)) {
|
|
35
|
+
const path = decodePath(withoutTrailingSlash(withoutBase(getRequestURL(event).pathname, useRuntimeConfig().app.baseURL)));
|
|
36
|
+
const headers = prerenderedMarkdownHeaders.get(path);
|
|
37
|
+
if (headers) {
|
|
38
|
+
for (const [name, value] of Object.entries(headers)) setHeader(event, name, value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const decision = decideNegotiation(event, "early");
|
|
43
|
+
const response = await applyNegotiation(event, decision);
|
|
44
|
+
if (response !== undefined || decision._tag !== "html") return response;
|
|
45
|
+
return serveCloudflarePrerenderedPage(event);
|
|
41
46
|
});
|
|
47
|
+
/**
|
|
48
|
+
* Run Accept negotiation in front of the Nitro static asset handler.
|
|
49
|
+
*
|
|
50
|
+
* Nitro unshifts that handler ahead of every server middleware when
|
|
51
|
+
* `serveStatic` is on, which is the default for the node-server preset. A
|
|
52
|
+
* prerendered route is then answered before the Markdown middleware runs, so
|
|
53
|
+
* negotiation never happens. See issue #82.
|
|
54
|
+
*
|
|
55
|
+
* H3 1 uses stack position 1, after Nitro's route-rules layer. H3 2 prepends
|
|
56
|
+
* the global middleware list. Its dispatcher adds route-rule middleware first.
|
|
57
|
+
*/
|
|
42
58
|
export default defineNitroPlugin((nitro) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const runtime = resolveH3Runtime(nitro);
|
|
60
|
+
if (runtime._tag === "unsupported") {
|
|
61
|
+
logger.debug("[markdown] No h3 stack found. Accept negotiation stays in the middleware.");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (runtime._tag === "h3-v2") {
|
|
65
|
+
// Nitro 3 exposes H3 2's global middleware list after static assets are
|
|
66
|
+
// registered. Route-rule middleware stays ahead through ~getMiddleware.
|
|
67
|
+
runtime.app["~middleware"].unshift(negotiationHandler);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const app = runtime.app;
|
|
71
|
+
const baseURL = useRuntimeConfig().app?.baseURL || "/";
|
|
72
|
+
app.use(`${baseURL}/`.replace(/\/+/g, "/"), negotiationHandler);
|
|
73
|
+
const layer = app.stack.at(-1);
|
|
74
|
+
if (layer?.handler !== negotiationHandler) {
|
|
75
|
+
// The layer is not where h3 puts it. Leave the stack as it is.
|
|
76
|
+
logger.debug("[markdown] Unexpected h3 stack shape. Accept negotiation runs after static assets.");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
app.stack.pop();
|
|
80
|
+
app.stack.splice(1, 0, layer);
|
|
62
81
|
});
|
|
@@ -4,133 +4,165 @@ import { getPageLastmods, getSitemapLastCrawledAt, markSitemapSeeded, resolveSee
|
|
|
4
4
|
import { logger } from "../logger.js";
|
|
5
5
|
import { markIndexedSitemapLastmods } from "../utils/sitemap-lastmod.js";
|
|
6
6
|
import { mapSitemapRoutes } from "../utils/sitemap-routes.js";
|
|
7
|
+
// Per-request diagnostics, stashed on event.context (the only attach point
|
|
8
|
+
// shared between sitemap:resolved and sitemap:output). @nuxtjs/sitemap has no
|
|
9
|
+
// diagnostics field of its own to surface, so we render these into the sitemap
|
|
10
|
+
// XML ourselves via the output hook.
|
|
7
11
|
const DIAGNOSTICS_KEY = "_aiReadySitemapDiagnostics";
|
|
8
12
|
const INDEXED_LASTMODS_KEY = "_aiReadyIndexedSitemapLastmods";
|
|
9
13
|
function isDebug(_event) {
|
|
10
|
-
|
|
14
|
+
return !!useRuntimeConfig()["nuxt-ai-ready"]?.debug;
|
|
11
15
|
}
|
|
12
16
|
function recordDiagnostic(event, message) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
const ctx = event.context;
|
|
18
|
+
const list = ctx[DIAGNOSTICS_KEY] ??= [];
|
|
19
|
+
list.push(message);
|
|
16
20
|
}
|
|
21
|
+
// Re-seed a given sitemap at most once per interval. The hook fires on every
|
|
22
|
+
// sitemap request; without this throttle we issued a DB write per route on
|
|
23
|
+
// every hit, which timed out large sitemaps on D1.
|
|
17
24
|
const SEED_INTERVAL_MS = 5 * 60 * 1e3;
|
|
18
|
-
|
|
25
|
+
// In-process throttle timestamps. The durable value can be unavailable when
|
|
26
|
+
// the DB read times out, so this keeps the throttle engaged against the same
|
|
27
|
+
// process even while reads fail; Math.max with the durable value below makes
|
|
28
|
+
// it a guard, never a bypass.
|
|
29
|
+
const lastSeedAt = new Map();
|
|
30
|
+
// Hard cap on DB work that runs before the sitemap renders. The DB driver has
|
|
31
|
+
// no cancellation, so a slow/hung D1 read would otherwise stall the response.
|
|
32
|
+
// On timeout we fall back and still render the sitemap (without that round's
|
|
33
|
+
// enrichment/seeding) rather than hanging.
|
|
19
34
|
const READ_TIMEOUT_MS = 3e3;
|
|
35
|
+
// Soft latency threshold. DB work below the hard timeout but above this is the
|
|
36
|
+
// early-warning signal that the database is degrading, before it becomes a
|
|
37
|
+
// response-blocking outage.
|
|
20
38
|
const SLOW_READ_WARN_MS = 1e3;
|
|
39
|
+
// A deferred seed taking this long signals write-path degradation (and risks
|
|
40
|
+
// exceeding the platform's background-work budget, e.g. Cloudflare waitUntil).
|
|
21
41
|
const SLOW_SEED_WARN_MS = 1e4;
|
|
22
42
|
function withTimeout(promise, ms, label, fallback, onIssue) {
|
|
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
|
-
});
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
let settled = false;
|
|
45
|
+
const timer = setTimeout(() => {
|
|
46
|
+
if (settled) return;
|
|
47
|
+
settled = true;
|
|
48
|
+
const message = `${label} timed out after ${ms}ms`;
|
|
49
|
+
logger.warn(`[sitemap-seeder] ${message}`);
|
|
50
|
+
onIssue?.(message);
|
|
51
|
+
resolve(fallback);
|
|
52
|
+
}, ms);
|
|
53
|
+
const done = (value) => {
|
|
54
|
+
if (settled) return;
|
|
55
|
+
settled = true;
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
resolve(value);
|
|
58
|
+
};
|
|
59
|
+
promise.then(done, (e) => {
|
|
60
|
+
const message = `${label} failed: ${e?.message}`;
|
|
61
|
+
logger.warn(`[sitemap-seeder] ${message}`);
|
|
62
|
+
onIssue?.(message);
|
|
63
|
+
done(fallback);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
48
66
|
}
|
|
67
|
+
// XML comments cannot contain "--"; neutralise it so injected diagnostics keep
|
|
68
|
+
// the sitemap well-formed.
|
|
49
69
|
function toXmlComment(messages) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
${body}
|
|
53
|
-
-->
|
|
54
|
-
`;
|
|
70
|
+
const body = messages.map((m) => ` - ${m.replace(/-{2,}/g, "- ")}`).join("\n");
|
|
71
|
+
return `<!-- nuxt-ai-ready sitemap-seeder diagnostics:\n${body}\n-->\n`;
|
|
55
72
|
}
|
|
73
|
+
// Insert in the prolog, after the XML declaration and any processing
|
|
74
|
+
// instructions (e.g. the xsl stylesheet) but before the root element.
|
|
56
75
|
function injectComment(xml, comment) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
const prolog = xml.match(/^\s*(?:<\?[^>]*\?>\s*)*/);
|
|
77
|
+
const idx = prolog ? prolog[0].length : 0;
|
|
78
|
+
return xml.slice(0, idx) + comment + xml.slice(idx);
|
|
60
79
|
}
|
|
61
80
|
export default function sitemapSeederPlugin(nitroApp) {
|
|
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
|
-
|
|
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
|
-
|
|
81
|
+
// Hook into @nuxtjs/sitemap's resolved hook
|
|
82
|
+
// This fires when a sitemap is rendered, giving us the URLs directly
|
|
83
|
+
nitroApp.hooks.hook("sitemap:resolved", async (ctx) => {
|
|
84
|
+
// Skip in dev - DB not available
|
|
85
|
+
if (import.meta.dev) return;
|
|
86
|
+
const { urls, sitemapName, event } = ctx;
|
|
87
|
+
if (urls.length === 0) return;
|
|
88
|
+
const routeToUrl = mapSitemapRoutes(urls);
|
|
89
|
+
if (routeToUrl.size === 0) return;
|
|
90
|
+
// Capture source dates before enriching the public sitemap from our index.
|
|
91
|
+
// Each URL also carries the host used for multi-domain locale resolution.
|
|
92
|
+
const routes = [...routeToUrl.entries()].map(([route, url]) => ({
|
|
93
|
+
route,
|
|
94
|
+
url: url.loc,
|
|
95
|
+
lastmod: url.lastmod
|
|
96
|
+
}));
|
|
97
|
+
logger.debug(`[sitemap-seeder] Processing ${routeToUrl.size} routes from ${sitemapName}`);
|
|
98
|
+
// Surface diagnostics into the served sitemap XML only under debug, so
|
|
99
|
+
// normal sitemaps stay clean. The output hook below renders whatever we record.
|
|
100
|
+
const record = isDebug(event) ? (m) => recordDiagnostic(event, m) : undefined;
|
|
101
|
+
// Enrich sitemap entries with lastmod from our indexed pages. This mutates
|
|
102
|
+
// the rendered output, so it must complete before the hook returns. Single
|
|
103
|
+
// SELECT, cheap.
|
|
104
|
+
const readStart = Date.now();
|
|
105
|
+
const lastmods = await withTimeout(getPageLastmods(event), READ_TIMEOUT_MS, "getPageLastmods", new Map(), record);
|
|
106
|
+
let enriched = 0;
|
|
107
|
+
for (const [route, url] of routeToUrl) {
|
|
108
|
+
const lastmod = lastmods.get(route);
|
|
109
|
+
if (lastmod && !url.lastmod) {
|
|
110
|
+
url.lastmod = lastmod;
|
|
111
|
+
const context = event.context;
|
|
112
|
+
const enrichedUrls = context[INDEXED_LASTMODS_KEY] ??= new Set();
|
|
113
|
+
enrichedUrls.add(url.loc);
|
|
114
|
+
enriched++;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (enriched > 0) {
|
|
118
|
+
logger.debug(`[sitemap-seeder] Enriched ${enriched} URLs with lastmod`);
|
|
119
|
+
}
|
|
120
|
+
// Throttle re-seeding: skip if this sitemap was seeded recently. Seeding
|
|
121
|
+
// writes don't affect the rendered output, so this never delays the response.
|
|
122
|
+
const lastCrawled = await withTimeout(getSitemapLastCrawledAt(event, sitemapName), READ_TIMEOUT_MS, "getSitemapLastCrawledAt", null, record);
|
|
123
|
+
// On-path DB latency is what stalls the sitemap response; warn before it
|
|
124
|
+
// crosses the hard timeout so a degrading DB is visible early.
|
|
125
|
+
const readMs = Date.now() - readStart;
|
|
126
|
+
if (readMs >= SLOW_READ_WARN_MS) {
|
|
127
|
+
const message = `slow DB reads: ${readMs}ms (timeout ${READ_TIMEOUT_MS}ms)`;
|
|
128
|
+
logger.warn(`[sitemap-seeder] ${message} for ${sitemapName}`);
|
|
129
|
+
record?.(message);
|
|
130
|
+
}
|
|
131
|
+
const lastSeed = Math.max(lastCrawled ?? 0, lastSeedAt.get(sitemapName) ?? 0);
|
|
132
|
+
if (Date.now() - lastSeed < SEED_INTERVAL_MS) return;
|
|
133
|
+
lastSeedAt.set(sitemapName, Date.now());
|
|
134
|
+
const urlCount = urls.length;
|
|
135
|
+
// Defer the writes off the response path. On Cloudflare, waitUntil keeps the
|
|
136
|
+
// worker alive until they finish without blocking the sitemap response.
|
|
137
|
+
const seed = async () => {
|
|
138
|
+
const seedStart = Date.now();
|
|
139
|
+
const pruneTtl = useRuntimeConfig()["nuxt-ai-ready"]?.runtimeSync?.pruneTtl ?? 0;
|
|
140
|
+
const seeded = await seedRoutes(event, routes, { refreshWindowMs: resolveSeedRefreshWindowMs(pruneTtl) }).catch((e) => {
|
|
141
|
+
logger.warn(`[sitemap-seeder] Failed to seed routes: ${e.message}`);
|
|
142
|
+
return 0;
|
|
143
|
+
});
|
|
144
|
+
await markSitemapSeeded(event, sitemapName, urlCount, lastCrawled).catch((e) => {
|
|
145
|
+
logger.warn(`[sitemap-seeder] Failed to mark sitemap: ${e.message}`);
|
|
146
|
+
});
|
|
147
|
+
const seedMs = Date.now() - seedStart;
|
|
148
|
+
if (seedMs >= SLOW_SEED_WARN_MS) logger.warn(`[sitemap-seeder] Slow seed: ${seedMs}ms for ${seeded} routes in ${sitemapName}`);
|
|
149
|
+
else if (seeded > 0) logger.debug(`[sitemap-seeder] Seeded ${seeded} routes from ${sitemapName} in ${seedMs}ms`);
|
|
150
|
+
};
|
|
151
|
+
if (event.waitUntil) {
|
|
152
|
+
const backgroundSeed = trackDrizzleWork(event, seed()).catch((err) => logger.error(`[sitemap-seeder] Background seed failed: ${err.message}`));
|
|
153
|
+
event.waitUntil(backgroundSeed);
|
|
154
|
+
} else {
|
|
155
|
+
await seed();
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
// Render any diagnostics recorded during sitemap:resolved into the served
|
|
159
|
+
// sitemap XML, so they can be inspected with a plain request to the sitemap
|
|
160
|
+
// when nuxt-ai-ready debug is enabled.
|
|
161
|
+
nitroApp.hooks.hook("sitemap:output", (ctx) => {
|
|
162
|
+
const enrichedUrls = ctx.event.context[INDEXED_LASTMODS_KEY];
|
|
163
|
+
if (enrichedUrls?.size) ctx.sitemap = markIndexedSitemapLastmods(ctx.sitemap, enrichedUrls);
|
|
164
|
+
const diagnostics = ctx.event.context[DIAGNOSTICS_KEY];
|
|
165
|
+
if (!diagnostics?.length) return;
|
|
166
|
+
ctx.sitemap = injectComment(ctx.sitemap, toXmlComment(diagnostics));
|
|
167
|
+
});
|
|
136
168
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cron endpoint for platforms that use HTTP-based cron (Vercel, etc.)
|
|
3
3
|
*/
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: import("#nuxtseo/h3").EventHandlerWithFetch<import("#nuxtseo/h3").EventHandlerRequest, Promise<import("../../utils/runCron.js").CronResult>>;
|
|
5
5
|
export default _default;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { createError, eventHandler } from "#nuxtseo/h3";
|
|
2
2
|
import { runCron } from "../../utils/runCron.js";
|
|
3
|
+
/**
|
|
4
|
+
* Cron endpoint for platforms that use HTTP-based cron (Vercel, etc.)
|
|
5
|
+
*/
|
|
3
6
|
export default eventHandler(async (event) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
const { requireAuth } = await import("../../utils/auth.js");
|
|
8
|
+
await requireAuth(event);
|
|
9
|
+
const result = await runCron(event);
|
|
10
|
+
// Unlike the scheduled task, this endpoint has an HTTP status as its failure
|
|
11
|
+
// signal: cron monitors judge success by status code, so a failed run must
|
|
12
|
+
// not answer 200. `data` carries the structured failure in the error body.
|
|
13
|
+
if (result.failed) {
|
|
14
|
+
throw createError({
|
|
15
|
+
statusCode: 500,
|
|
16
|
+
message: `Cron run failed at the ${result.failed.stage} stage: ${result.failed.message}`,
|
|
17
|
+
data: result.failed
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
15
21
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default:
|
|
1
|
+
declare const _default: import("#nuxtseo/h3").EventHandlerWithFetch<import("#nuxtseo/h3").EventHandlerRequest, Promise<Record<string, unknown>>>;
|
|
2
2
|
export default _default;
|
|
@@ -3,49 +3,64 @@ import { useRuntimeConfig } from "#nuxtseo/nitro";
|
|
|
3
3
|
import { getSiteConfig } from "#site-config/server/composables";
|
|
4
4
|
import { countPages, queryPages } from "../../db/queries.js";
|
|
5
5
|
export default eventHandler(async (event) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
6
|
+
const runtimeConfig = useRuntimeConfig(event)["nuxt-ai-ready"];
|
|
7
|
+
// Site URL for production toggle
|
|
8
|
+
const siteConfigUrl = getSiteConfig(event).url;
|
|
9
|
+
// Build-time metadata not available in runtime config
|
|
10
|
+
let devtoolsMeta = {
|
|
11
|
+
contentSignal: false,
|
|
12
|
+
mcp: {
|
|
13
|
+
enabled: false,
|
|
14
|
+
tools: false,
|
|
15
|
+
resources: false
|
|
16
|
+
},
|
|
17
|
+
cron: false
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const m = await import("#ai-ready-virtual/devtools-meta.mjs");
|
|
21
|
+
devtoolsMeta = m.devtoolsMeta;
|
|
22
|
+
} catch {}
|
|
23
|
+
const response = {
|
|
24
|
+
version: runtimeConfig.version,
|
|
25
|
+
siteConfigUrl,
|
|
26
|
+
isDev: import.meta.dev,
|
|
27
|
+
config: {
|
|
28
|
+
database: { type: runtimeConfig.database?._tag === "Disabled" ? "none" : runtimeConfig.database?.type || "sqlite" },
|
|
29
|
+
runtimeSync: runtimeConfig.runtimeSync,
|
|
30
|
+
sitemapPrerendered: runtimeConfig.sitemapPrerendered,
|
|
31
|
+
markdownCacheHeaders: runtimeConfig.markdownCacheHeaders,
|
|
32
|
+
llmsTxtCacheSeconds: runtimeConfig.llmsTxtCacheSeconds,
|
|
33
|
+
contentSignal: devtoolsMeta.contentSignal,
|
|
34
|
+
mcp: devtoolsMeta.mcp,
|
|
35
|
+
cron: devtoolsMeta.cron
|
|
36
|
+
},
|
|
37
|
+
llmsTxt: runtimeConfig.llmsTxt
|
|
38
|
+
};
|
|
39
|
+
// In production, include page stats and list
|
|
40
|
+
if (!import.meta.dev) {
|
|
41
|
+
try {
|
|
42
|
+
const [total, pending, errors] = await Promise.all([
|
|
43
|
+
countPages(event),
|
|
44
|
+
countPages(event, { where: { pending: true } }),
|
|
45
|
+
countPages(event, { where: { hasError: true } })
|
|
46
|
+
]);
|
|
47
|
+
response.stats = {
|
|
48
|
+
total,
|
|
49
|
+
indexed: total - pending,
|
|
50
|
+
pending,
|
|
51
|
+
errors
|
|
52
|
+
};
|
|
53
|
+
const pages = await queryPages(event);
|
|
54
|
+
response.pages = pages.map((p) => ({
|
|
55
|
+
route: p.route,
|
|
56
|
+
title: p.title,
|
|
57
|
+
description: p.description,
|
|
58
|
+
updatedAt: p.updatedAt
|
|
59
|
+
}));
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
setHeader(event, "Content-Type", "application/json; charset=utf-8");
|
|
63
|
+
// Allow cross-origin for devtools production toggle
|
|
64
|
+
setHeader(event, "Access-Control-Allow-Origin", "*");
|
|
65
|
+
return response;
|
|
51
66
|
});
|
|
@@ -2,5 +2,40 @@
|
|
|
2
2
|
* Public page index powering the WebMCP site tools. Read-only and returns the
|
|
3
3
|
* same content already published through llms.txt and the `.md` routes.
|
|
4
4
|
*/
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: import("#nuxtseo/h3").EventHandlerWithFetch<import("#nuxtseo/h3").EventHandlerRequest, Promise<{
|
|
6
|
+
page: {
|
|
7
|
+
route: string;
|
|
8
|
+
title: string;
|
|
9
|
+
description: string;
|
|
10
|
+
} | null;
|
|
11
|
+
query?: undefined;
|
|
12
|
+
results?: undefined;
|
|
13
|
+
pages?: undefined;
|
|
14
|
+
total?: undefined;
|
|
15
|
+
limit?: undefined;
|
|
16
|
+
offset?: undefined;
|
|
17
|
+
hasMore?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
query: string;
|
|
20
|
+
results: import("../../index.js").SearchResult[];
|
|
21
|
+
page?: undefined;
|
|
22
|
+
pages?: undefined;
|
|
23
|
+
total?: undefined;
|
|
24
|
+
limit?: undefined;
|
|
25
|
+
offset?: undefined;
|
|
26
|
+
hasMore?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
pages: {
|
|
29
|
+
route: string;
|
|
30
|
+
title: string;
|
|
31
|
+
description: string;
|
|
32
|
+
}[];
|
|
33
|
+
total: number;
|
|
34
|
+
limit: number;
|
|
35
|
+
offset: number;
|
|
36
|
+
hasMore: boolean;
|
|
37
|
+
page?: undefined;
|
|
38
|
+
query?: undefined;
|
|
39
|
+
results?: undefined;
|
|
40
|
+
}>>;
|
|
6
41
|
export default _default;
|