nuxt-ai-ready 3.5.1 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/chunks/agent-skills.mjs +5 -3
  2. package/dist/chunks/prerender.mjs +48 -24
  3. package/dist/cli.mjs +5 -5
  4. package/dist/module.d.mts +4 -0
  5. package/dist/module.json +2 -2
  6. package/dist/module.mjs +5 -3
  7. package/dist/runtime/ai-terms.d.ts +76 -0
  8. package/dist/runtime/ai-terms.js +1 -0
  9. package/dist/runtime/app/plugins/md-alternate.server.js +11 -3
  10. package/dist/runtime/llms-txt-utils.js +2 -1
  11. package/dist/runtime/server/db/schema/postgres.d.ts +8 -0
  12. package/dist/runtime/server/db/schema/sqlite.d.ts +8 -0
  13. package/dist/runtime/server/middleware/markdown.js +13 -175
  14. package/dist/runtime/server/middleware/render-markdown.d.ts +2 -0
  15. package/dist/runtime/server/middleware/render-markdown.js +163 -0
  16. package/dist/runtime/server/plugins/ai-terms.d.ts +2 -0
  17. package/dist/runtime/server/plugins/ai-terms.js +11 -0
  18. package/dist/runtime/server/plugins/markdown-negotiation.js +11 -1
  19. package/dist/runtime/server/routes/ai-terms.d.ts +2 -0
  20. package/dist/runtime/server/routes/ai-terms.js +22 -0
  21. package/dist/runtime/server/routes/api-catalog.js +6 -2
  22. package/dist/runtime/server/routes/llms.txt.get.js +3 -0
  23. package/dist/runtime/server/utils/auth.d.ts +1 -3
  24. package/dist/runtime/server/utils/auth.js +55 -25
  25. package/dist/runtime/server/utils/cloudflare-prerendered.d.ts +1 -1
  26. package/dist/runtime/server/utils/cloudflare-prerendered.js +17 -15
  27. package/dist/runtime/server/utils/link-header.d.ts +4 -0
  28. package/dist/runtime/server/utils/link-header.js +6 -2
  29. package/dist/runtime/server/utils/negotiation-decision.d.ts +4 -0
  30. package/dist/runtime/server/utils/negotiation-decision.js +8 -1
  31. package/dist/runtime/server/utils/negotiation-response.d.ts +3 -1
  32. package/dist/runtime/server/utils/negotiation-response.js +31 -9
  33. package/dist/runtime/sync-secret.d.ts +1 -0
  34. package/dist/runtime/sync-secret.js +2 -1
  35. package/dist/runtime/types.d.ts +12 -0
  36. package/dist/shared/{nuxt-ai-ready.BaNK8yfw.mjs → nuxt-ai-ready.Bzx0dNWj.mjs} +324 -36
  37. package/dist/shared/{nuxt-ai-ready.B3hAuOLQ.mjs → nuxt-ai-ready.DCd-1s1G.mjs} +1 -1
  38. package/dist/types.d.mts +2 -0
  39. package/package.json +31 -31
  40. package/skills/nuxt-ai-ready/SKILL.md +52 -96
  41. package/dist/cli.d.mts +0 -1
@@ -1,12 +1,15 @@
1
- import { readFile, access, mkdir, writeFile, rm } from 'node:fs/promises';
1
+ import { readFile, access, mkdir, mkdtemp, writeFile, rename, rm } from 'node:fs/promises';
2
2
  import { createRequire } from 'node:module';
3
3
  import { dirname, basename, join, resolve, relative } from 'node:path';
4
4
  import { fileURLToPath, pathToFileURL } from 'node:url';
5
5
  import { hasNuxtModule, useNuxt, useLogger, addTypeTemplate, addTemplate, defineNuxtModule, createResolver, getLayerDirectories, tryResolveModule, directoryToURL, addServerImports, addServerHandler, extendRouteRules, getNitroVersion, addPlugin, addNitroPlugin, addImports } from '@nuxt/kit';
6
6
  import defu$1, { defu } from 'defu';
7
7
  import { useSiteConfig, withSiteUrl } from 'nuxt-site-config/kit';
8
- import { resolveNuxtContentVersion, renderNitroTypeAugmentations, setupRuntimeAliases, setupNitroRuntimeCompatibility } from 'nuxtseo-shared/kit';
9
- import { r as readPackageMetadata, a as resolvePackageMetadataPath } from './nuxt-ai-ready.B3hAuOLQ.mjs';
8
+ import { resolveNuxtContentVersion, renderNitroTypeAugmentations, setupRuntimeAliases, setupNitroRuntimeCompatibility, isAgent, isCI } from 'nuxtseo-shared/kit';
9
+ import { createNitroRouteRuleMatcher } from 'nuxtseo-shared/server';
10
+ import { decodePath } from 'ufo';
11
+ import { r as readPackageMetadata, a as resolvePackageMetadataPath } from './nuxt-ai-ready.DCd-1s1G.mjs';
12
+ import { AI_TERMS_PATH } from '../../dist/runtime/ai-terms.js';
10
13
  import { parseLlmsTxtConfig } from '../../dist/runtime/llms-txt-files.js';
11
14
  import { toDeployedRoute } from '../../dist/runtime/route-path.js';
12
15
  import { SITEMAP_MD_ROUTE } from '../../dist/runtime/server/utils/sitemap-md.js';
@@ -15,8 +18,7 @@ import { publicCacheControl, mergeVaryHeader } from '../../dist/runtime/cache-co
15
18
  import { createHash } from 'node:crypto';
16
19
  import { MCP_SERVER_CARD_MEDIA_TYPE, AI_CATALOG_MEDIA_TYPE } from '../../dist/runtime/server/utils/discovery-response.js';
17
20
  import { parseTOML, parseJSONC } from 'confbox';
18
- import { toMarkdownPath, hasMarkdownTwin, normalizePagePath } from '../../dist/runtime/markdown-path.js';
19
- import { createNitroRouteRuleMatcher } from 'nuxtseo-shared/server';
21
+ import { hasMarkdownTwin, toMarkdownPath, normalizePagePath } from '../../dist/runtime/markdown-path.js';
20
22
  import { getContentNegotiationVary, resolveContentNegotiation } from '../../dist/runtime/server/utils/content-negotiation.js';
21
23
  import { isAbsolute, join as join$1 } from 'pathe';
22
24
  import { resolveI18nConfig, toRuntimeI18nConfig as toRuntimeI18nConfig$1 } from 'nuxtseo-shared/i18n';
@@ -325,6 +327,192 @@ function createAiCatalogEtag(catalog) {
325
327
  return `"${createHash("sha256").update(JSON.stringify(catalog)).digest("hex")}"`;
326
328
  }
327
329
 
330
+ const purposes = ["search", "answer", "training", "agent"];
331
+ const accesses = ["allow", "paid", "deny"];
332
+ function isRecord$1(value) {
333
+ return typeof value === "object" && value !== null && !Array.isArray(value);
334
+ }
335
+ function checkPayment(value, field, errors) {
336
+ if (!isRecord$1(value)) {
337
+ errors.push(`${field}: configure an x402 payment endpoint.`);
338
+ return;
339
+ }
340
+ if (value.protocol !== "x402")
341
+ errors.push(`${field}.protocol: use x402.`);
342
+ const endpoint = typeof value.endpoint === "string" && /^https:\/\/[^/?#\\\s][^?#\\\s]*$/.test(value.endpoint) ? URL.parse(value.endpoint) : null;
343
+ if (!endpoint || endpoint.username || endpoint.password)
344
+ errors.push(`${field}.endpoint: use an absolute HTTPS URL without credentials, query parameters, or a fragment.`);
345
+ if (value.version !== void 0 && !Number.isInteger(value.version))
346
+ errors.push(`${field}.version: use an integer.`);
347
+ for (const key of ["network", "asset"]) {
348
+ if (value[key] !== void 0 && typeof value[key] !== "string")
349
+ errors.push(`${field}.${key}: use a string.`);
350
+ }
351
+ }
352
+ function checkUses(value, field, payment, partial, errors) {
353
+ if (!isRecord$1(value)) {
354
+ errors.push(`${field}: set the AI use rules.`);
355
+ return;
356
+ }
357
+ if (partial && !purposes.some((purpose) => value[purpose] !== void 0))
358
+ errors.push(`${field}: set at least one AI use rule.`);
359
+ for (const purpose of purposes) {
360
+ const rule = value[purpose];
361
+ const path = `${field}.${purpose}`;
362
+ if (rule === void 0 && partial)
363
+ continue;
364
+ if (!isRecord$1(rule)) {
365
+ errors.push(`${path}: set an access rule.`);
366
+ continue;
367
+ }
368
+ if (!accesses.includes(rule.access))
369
+ errors.push(`${path}.access: use allow, paid, or deny.`);
370
+ if (rule.attribution !== void 0 && !["required", "requested", "none"].includes(rule.attribution))
371
+ errors.push(`${path}.attribution: use required, requested, or none.`);
372
+ if (rule.access === "paid") {
373
+ if (!isRecord$1(rule.price)) {
374
+ errors.push(`${path}.price: set the paid use price.`);
375
+ } else {
376
+ if (typeof rule.price.amount !== "string" || !/^\d+(?:\.\d+)?$/.test(rule.price.amount))
377
+ errors.push(`${path}.price.amount: use a decimal string.`);
378
+ if (rule.price.currency !== "USD")
379
+ errors.push(`${path}.price.currency: use USD.`);
380
+ if (!["page", "request"].includes(rule.price.per))
381
+ errors.push(`${path}.price.per: use page or request.`);
382
+ }
383
+ if (!payment)
384
+ errors.push(`${field === "uses" ? "payment" : field.replace(/\.uses$/, ".payment")}: paid uses need a payment endpoint.`);
385
+ } else if (rule.price !== void 0) {
386
+ errors.push(`${path}.price: only paid uses have a price.`);
387
+ }
388
+ if (rule.free !== void 0) {
389
+ if (!isRecord$1(rule.free) || !Number.isInteger(rule.free.requests) || Number(rule.free.requests) < 1 || Number(rule.free.requests) > 1e9 || !["hour", "day"].includes(rule.free.per))
390
+ errors.push(`${path}.free: set 1 to 1000000000 requests per hour or day.`);
391
+ if (rule.access === "allow")
392
+ errors.push(`${path}.free: only paid or denied uses have a free allowance.`);
393
+ }
394
+ }
395
+ }
396
+ function publicPayment({ protocol, endpoint, version, network, asset }) {
397
+ return { protocol, endpoint, version, network, asset };
398
+ }
399
+ function publicUse(use) {
400
+ const { access, attribution, free } = use;
401
+ if (access === "allow")
402
+ return { access, attribution };
403
+ const allowance = free && { requests: free.requests, per: free.per };
404
+ if (access === "deny")
405
+ return { access, attribution, free: allowance };
406
+ const { amount, currency, per } = use.price;
407
+ return { access, attribution, free: allowance, price: { amount, currency, per } };
408
+ }
409
+ function publicDocument(policy, site) {
410
+ const { updated, uses, paths, payment, identity, receipts, report_only, contact, preview } = policy;
411
+ return {
412
+ ai_terms: "0.1",
413
+ site,
414
+ updated,
415
+ default: policy.default,
416
+ uses: {
417
+ search: publicUse(uses.search),
418
+ answer: publicUse(uses.answer),
419
+ training: publicUse(uses.training),
420
+ agent: publicUse(uses.agent)
421
+ },
422
+ paths: paths?.map(({ match, uses: uses2, payment: payment2 }) => {
423
+ const overrides = {};
424
+ for (const purpose of purposes) {
425
+ const rule = uses2[purpose];
426
+ if (rule)
427
+ overrides[purpose] = publicUse(rule);
428
+ }
429
+ return { match, uses: overrides, payment: payment2 && publicPayment(payment2) };
430
+ }),
431
+ payment: payment && publicPayment(payment),
432
+ identity: identity && { verify: identity.verify && [...identity.verify], unverified: identity.unverified },
433
+ receipts,
434
+ report_only,
435
+ contact: contact && { licensing: contact.licensing },
436
+ preview: preview && { shows: preview.shows && [...preview.shows], delivery: preview.delivery, described_quote: preview.described_quote },
437
+ purpose_header: "AI-Purpose",
438
+ spec: "https://aipaygen.com/ai-terms"
439
+ };
440
+ }
441
+ function resolveAiTermsConfig(input, siteBaseURL) {
442
+ if (input === void 0 || input === false)
443
+ return { _tag: "Disabled" };
444
+ if (!isRecord$1(input))
445
+ return { _tag: "Invalid", errors: ["aiTerms: configure an explicit AI Terms policy, or use false."] };
446
+ const errors = [];
447
+ const site = siteBaseURL && URL.canParse(siteBaseURL) ? new URL(siteBaseURL) : void 0;
448
+ if (!site || !["https:", "http:"].includes(site.protocol) || site.username || site.password)
449
+ errors.push("site.url: set an absolute HTTP or HTTPS URL to publish AI Terms.");
450
+ if (typeof input.updated !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(input.updated) || !Number.isFinite(Date.parse(input.updated)) || new Date(input.updated).toISOString().slice(0, 10) !== input.updated)
451
+ errors.push("updated: set the policy change date in YYYY-MM-DD format.");
452
+ if (!accesses.includes(input.default))
453
+ errors.push("default: use allow, paid, or deny.");
454
+ if (input.payment !== void 0)
455
+ checkPayment(input.payment, "payment", errors);
456
+ if (input.default === "paid" && !input.payment)
457
+ errors.push("payment: a paid default needs a payment endpoint.");
458
+ checkUses(input.uses, "uses", input.payment, false, errors);
459
+ if (input.paths !== void 0) {
460
+ if (!Array.isArray(input.paths)) {
461
+ errors.push("paths: use an array of path overrides.");
462
+ } else {
463
+ for (const [index, entry] of input.paths.entries()) {
464
+ const field = `paths[${index}]`;
465
+ if (!isRecord$1(entry)) {
466
+ errors.push(`${field}: set a path match and AI use rules.`);
467
+ continue;
468
+ }
469
+ if (typeof entry.match !== "string" || !/^\/[^?#]*$/.test(entry.match))
470
+ errors.push(`${field}.match: start the path pattern with / and omit any query or fragment.`);
471
+ if (entry.payment !== void 0)
472
+ checkPayment(entry.payment, `${field}.payment`, errors);
473
+ checkUses(entry.uses, `${field}.uses`, entry.payment ?? input.payment, true, errors);
474
+ }
475
+ }
476
+ }
477
+ if (input.identity !== void 0) {
478
+ if (!isRecord$1(input.identity)) {
479
+ errors.push("identity: configure the identity checks used by your server.");
480
+ } else {
481
+ if (input.identity.verify !== void 0 && (!Array.isArray(input.identity.verify) || [...input.identity.verify].some((value) => typeof value !== "string")))
482
+ errors.push("identity.verify: use an array of verification methods.");
483
+ if (input.identity.unverified !== void 0 && typeof input.identity.unverified !== "string")
484
+ errors.push("identity.unverified: use a string.");
485
+ }
486
+ }
487
+ if (input.receipts !== void 0 && typeof input.receipts !== "string")
488
+ errors.push("receipts: use a string.");
489
+ if (input.report_only !== void 0 && typeof input.report_only !== "boolean")
490
+ errors.push("report_only: use true or false.");
491
+ if (input.contact !== void 0 && (!isRecord$1(input.contact) || input.contact.licensing !== void 0 && typeof input.contact.licensing !== "string"))
492
+ errors.push("contact.licensing: use a string.");
493
+ if (input.preview !== void 0) {
494
+ if (!isRecord$1(input.preview) || !["must-match", "per-quote", "not-checked"].includes(input.preview.delivery)) {
495
+ errors.push("preview.delivery: use must-match, per-quote, or not-checked.");
496
+ } else {
497
+ if (input.preview.shows !== void 0 && (!Array.isArray(input.preview.shows) || [...input.preview.shows].some((value) => !["title", "description", "excerpt", "words"].includes(value))))
498
+ errors.push("preview.shows: use title, description, excerpt, or words.");
499
+ if (input.preview.described_quote !== void 0 && typeof input.preview.described_quote !== "string")
500
+ errors.push("preview.described_quote: use a string.");
501
+ }
502
+ }
503
+ if (errors.length || !site)
504
+ return { _tag: "Invalid", errors };
505
+ const href = new URL(site.origin);
506
+ href.pathname = `${site.pathname.replace(/\/$/, "")}${AI_TERMS_PATH}`;
507
+ return {
508
+ _tag: "Enabled",
509
+ config: {
510
+ href: href.href,
511
+ document: publicDocument(input, site.origin)
512
+ }
513
+ };
514
+ }
515
+
328
516
  const API_CATALOG_PATH = "/.well-known/api-catalog";
329
517
  const API_CATALOG_PROFILE = "https://www.rfc-editor.org/info/rfc9727";
330
518
  const API_CATALOG_MEDIA_TYPE = `application/linkset+json; profile="${API_CATALOG_PROFILE}"`;
@@ -668,7 +856,7 @@ function matchingStaticContentSignals(routeRules, route) {
668
856
  return Object.entries(headers || {}).filter(([name]) => name.toLowerCase() === "content-signal").map(([, value]) => value);
669
857
  });
670
858
  }
671
- function normalizeStaticContentSignalHeaders(contents) {
859
+ function normalizeStaticContentSignalHeaders(contents, generatedDiscovery = []) {
672
860
  const parsed = splitHeaderBlocks(contents);
673
861
  if (!parsed.some((block) => /^\s+content-signal\s*:/im.test(block.text)))
674
862
  return contents;
@@ -693,7 +881,17 @@ function normalizeStaticContentSignalHeaders(contents) {
693
881
  ${[...lines, ...policy].join("\n")}
694
882
  ` }];
695
883
  });
696
- const policyOnly = (block) => hasPolicy(block) && block.text.split(/\r?\n/).slice(1).every((line) => !line.trim() || line.trimStart().startsWith("#") || policyLine.test(line));
884
+ const discoveryLinks = new Set(generatedDiscovery);
885
+ const isGeneratedDiscovery = (line) => {
886
+ if (discoveryLinks.size === 0)
887
+ return false;
888
+ const header = parseHeaderLine(line);
889
+ if (header?.name.toLowerCase() !== "link")
890
+ return false;
891
+ const links = splitLinkEntries(header.value);
892
+ return links.length > 0 && links.every((link) => discoveryLinks.has(link));
893
+ };
894
+ const policyOnly = (block) => hasPolicy(block) && block.text.split(/\r?\n/).slice(1).every((line) => !line.trim() || line.trimStart().startsWith("#") || policyLine.test(line) || isGeneratedDiscovery(line));
697
895
  const policyValue = (block) => block.text.match(/^[\t ]+content-signal[\t ]*:(.*)$/im)?.[1]?.trim() ?? null;
698
896
  const edges = blocks.map(() => /* @__PURE__ */ new Set());
699
897
  const incoming = blocks.map(() => 0);
@@ -919,7 +1117,7 @@ function pageRouteFromMarkdownTwin(fileName) {
919
1117
  return "/";
920
1118
  return isStaticMarkdownSourceRoute(pageRoute) ? pageRoute : null;
921
1119
  }
922
- function prerenderedMarkdownHeaderRules(prerenderedRoutes, baseURL, describedby, artifactRoutes) {
1120
+ function prerenderedMarkdownHeaderRules(prerenderedRoutes, baseURL, describedby, artifactRoutes, aiTermsLink) {
923
1121
  const artifacts = new Set(artifactRoutes);
924
1122
  const rules = /* @__PURE__ */ new Map();
925
1123
  for (const entry of prerenderedRoutes) {
@@ -936,7 +1134,7 @@ function prerenderedMarkdownHeaderRules(prerenderedRoutes, baseURL, describedby,
936
1134
  headers: {
937
1135
  "Content-Type": "text/markdown; charset=utf-8",
938
1136
  "Vary": "Accept",
939
- "Link": buildStaticMarkdownLinkHeader(pageRoute, baseURL, describedby),
1137
+ "Link": [buildStaticMarkdownLinkHeader(pageRoute, baseURL, describedby), aiTermsLink].filter(Boolean).join(", "),
940
1138
  ...entry.contentSignal !== void 0 && { "Content-Signal": entry.contentSignal }
941
1139
  }
942
1140
  });
@@ -985,6 +1183,7 @@ function applyStaticMarkdownHeaderPlan(routeRules, plan) {
985
1183
  rule.headers = void 0;
986
1184
  }
987
1185
  }
1186
+ const applied = [];
988
1187
  for (const { route, headers } of plan.rules) {
989
1188
  const existing = routeRules[route];
990
1189
  const merged = defu({ headers: { ...headers } }, existing);
@@ -1007,7 +1206,9 @@ function applyStaticMarkdownHeaderPlan(routeRules, plan) {
1007
1206
  merged.headers.Vary = mergeVaryHeader(vary, headers.Vary);
1008
1207
  }
1009
1208
  routeRules[route] = merged;
1209
+ applied.push([route, merged.headers]);
1010
1210
  }
1211
+ return applied;
1011
1212
  }
1012
1213
 
1013
1214
  const MAX_WORKER_FIRST_PATTERNS = 100;
@@ -1083,7 +1284,7 @@ function cacheFix(botNegotiation = false) {
1083
1284
  function resolveConfigurationWarnings(input) {
1084
1285
  const warnings = [];
1085
1286
  const hostname = input.siteUrl && URL.canParse(input.siteUrl) ? new URL(input.siteUrl).hostname : "";
1086
- if (!hostname || hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "127.0.0.1" || hostname === "[::1]") {
1287
+ if (input.reportSiteUrl !== false && (!hostname || hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "127.0.0.1" || hostname === "[::1]")) {
1087
1288
  warnings.push('Set site.url to the public production URL. Discovery catalogs and canonical Markdown links need a public origin.\n In nuxt.config.ts, set site: { url: "https://your-domain.com" }. Replace the example with your production origin.');
1088
1289
  }
1089
1290
  if (input.policy === "disabled") {
@@ -1875,6 +2076,15 @@ ${details}`);
1875
2076
  const hasMcpSiteTools = Object.values(siteToolsConfig).some((tool) => tool.mcp.enabled);
1876
2077
  const nitroCompatibility = setupNitroRuntimeCompatibility(nuxt);
1877
2078
  const siteConfig = useSiteConfig();
2079
+ const aiTermsResult = resolveAiTermsConfig(config.aiTerms, siteConfig.url ? withSiteUrl("/", { withBase: true }) : void 0);
2080
+ if (aiTermsResult._tag === "Invalid") {
2081
+ throw new Error([
2082
+ "[nuxt-ai-ready] Invalid AI Terms configuration:",
2083
+ ...aiTermsResult.errors.map((error) => `- ${error}`)
2084
+ ].join("\n"));
2085
+ }
2086
+ const aiTermsConfig = aiTermsResult._tag === "Enabled" ? aiTermsResult.config : void 0;
2087
+ const aiTermsLink = aiTermsConfig ? `<${aiTermsConfig.href}>; rel="ai-terms"` : void 0;
1878
2088
  const apiCatalogResult = resolveApiCatalogConfig(config.apiCatalog, {
1879
2089
  siteBaseURL: siteConfig.url ? withSiteUrl("/", { withBase: true }) : void 0,
1880
2090
  generatedEntries: []
@@ -2030,9 +2240,11 @@ ${details}`);
2030
2240
  const webmcpResult = resolveWebMcpConfig(config.webmcp, siteToolsConfig);
2031
2241
  const webmcpConfig = webmcpResult._tag === "Enabled" ? webmcpResult.config : null;
2032
2242
  const isStatic = nuxt.options.nitro.static || nuxt.options._generate || false;
2243
+ const zeroRuntimeMarkdown = config.zeroRuntimeMarkdown === true && !nuxt.options.dev;
2033
2244
  const hasPrerenderedRoutes = !!(nuxt.options.nitro.prerender?.routes?.length || nuxt.options.nitro.prerender?.crawlLinks);
2034
2245
  const preparing = nuxt.options._prepare === true;
2035
2246
  const prerenderEnabled = !preparing && !!(isStatic || hasPrerenderedRoutes);
2247
+ const prerenderMarkdown = prerenderEnabled || zeroRuntimeMarkdown && !preparing;
2036
2248
  const isSPA = nuxt.options.ssr === false;
2037
2249
  let apiCatalogRegistered = false;
2038
2250
  const registerApiCatalog = (catalog) => {
@@ -2044,12 +2256,12 @@ ${details}`);
2044
2256
  addServerHandler({ route: API_CATALOG_PATH, handler: resolve$1("./runtime/server/routes/api-catalog"), lazy: true });
2045
2257
  const apiCatalogLink = `<${catalog.href}>; rel="api-catalog"`;
2046
2258
  extendRouteRules("/**", {
2047
- headers: { Link: apiCatalogLink }
2259
+ headers: { Link: [apiCatalogLink, aiTermsLink].filter(Boolean).join(", ") }
2048
2260
  });
2049
2261
  extendRouteRules(API_CATALOG_PATH, {
2050
2262
  headers: {
2051
2263
  "Content-Type": catalog.mediaType,
2052
- "Link": apiCatalogLink
2264
+ "Link": [apiCatalogLink, aiTermsLink].filter(Boolean).join(", ")
2053
2265
  }
2054
2266
  });
2055
2267
  if (prerenderEnabled) {
@@ -2070,6 +2282,7 @@ ${details}`);
2070
2282
  runtimeSync: runtimeSyncEnabled,
2071
2283
  cron: !!config.cron,
2072
2284
  apiCatalog: !!apiCatalogConfig,
2285
+ aiTerms: !!aiTermsConfig,
2073
2286
  database: databaseEnabled ? database.type : false
2074
2287
  };
2075
2288
  }
@@ -2251,10 +2464,20 @@ ${details}`);
2251
2464
  const syncSecret = typeof appSecret === "string" && appSecret.length >= 32 ? await deriveRuntimeSyncSecret(appSecret) : appSecret === void 0 || appSecret === "" ? legacySecret : void 0;
2252
2465
  if (runtimeSyncEnabled && syncSecret) {
2253
2466
  await mkdir(dirname(secretPath), { recursive: true });
2254
- await writeFile(secretPath, syncSecret, { mode: 384 });
2467
+ const temporaryDir = await mkdtemp(join(dirname(secretPath), "secret-"));
2468
+ try {
2469
+ const temporaryPath = join(temporaryDir, "token");
2470
+ await writeFile(temporaryPath, syncSecret, { mode: 384 });
2471
+ await rename(temporaryPath, secretPath);
2472
+ } finally {
2473
+ await rm(temporaryDir, { recursive: true, force: true });
2474
+ }
2255
2475
  } else {
2256
2476
  await rm(secretPath, { force: true });
2257
2477
  }
2478
+ let cloudflareFallbackPaths = [];
2479
+ let prerenderedMarkdownHeaders = [];
2480
+ let prerenderedMarkdownPaths = [];
2258
2481
  nuxt.hooks.hook("nitro:config", (nitroConfig) => {
2259
2482
  if (getNitroVersion(nuxt) === 3) {
2260
2483
  const nativeConfig = nitroConfig;
@@ -2352,6 +2575,10 @@ export { unavailable as computeLocaleAlternates, unavailable as localePath, unav
2352
2575
  });
2353
2576
  nitroConfig.virtual["#ai-ready-virtual/page-data.mjs"] = `export const pages = []
2354
2577
  export const errorRoutes = []`;
2578
+ nitroConfig.virtual["#ai-ready-virtual/cloudflare-fallback-paths.mjs"] = () => `export default new Set(${JSON.stringify(cloudflareFallbackPaths)})`;
2579
+ nitroConfig.virtual["#ai-ready-virtual/prerendered-markdown-headers.mjs"] = () => `export default new Map(${JSON.stringify(prerenderedMarkdownHeaders)})`;
2580
+ nitroConfig.virtual["#ai-ready-virtual/prerendered-markdown-paths.mjs"] = () => zeroRuntimeMarkdown ? `export default new Set(${JSON.stringify(prerenderedMarkdownPaths.map(decodePath))})` : "export default null";
2581
+ nitroConfig.virtual["#ai-ready-virtual/render-markdown.mjs"] = zeroRuntimeMarkdown ? "export const renderMarkdown = undefined" : `export { renderMarkdown } from '#ai-ready/server/middleware/render-markdown'`;
2355
2582
  nitroConfig.virtual["#ai-ready-virtual/logger.mjs"] = `
2356
2583
  import { createModuleLogger } from ${JSON.stringify(nuxtSeoSharedUtilsPath)}
2357
2584
  export const logger = createModuleLogger('nuxt-ai-ready', ${!!config.debug})
@@ -2427,6 +2654,7 @@ export function trackDrizzleWork(event, work) { return work }
2427
2654
  debugCron: config.debugCron || false,
2428
2655
  contentNegotiation: config.contentNegotiation === void 0 ? "auto" : config.contentNegotiation ? "enabled" : "disabled",
2429
2656
  botNegotiation: config.botNegotiation === true,
2657
+ zeroRuntimeMarkdown,
2430
2658
  mdreamOptions: config.mdreamOptions || {},
2431
2659
  sitemapMd: config.sitemapMd !== false,
2432
2660
  describedby: config.describedby !== false,
@@ -2449,9 +2677,10 @@ export function trackDrizzleWork(event, work) { return work }
2449
2677
  sitemapPrerendered,
2450
2678
  i18n: i18nConfig,
2451
2679
  ftsTokenizer,
2452
- apiCatalog: apiCatalogConfig
2680
+ apiCatalog: apiCatalogConfig,
2681
+ aiTerms: aiTermsConfig
2453
2682
  };
2454
- if (prerenderEnabled) {
2683
+ if (prerenderMarkdown) {
2455
2684
  addServerHandler({
2456
2685
  middleware: true,
2457
2686
  env: "prerender",
@@ -2555,16 +2784,36 @@ export function trackDrizzleWork(event, work) { return work }
2555
2784
  if (config.cron && !nuxt.options.dev) {
2556
2785
  addServerHandler({ route: "/__ai-ready/cron", handler: resolve$1("./runtime/server/routes/__ai-ready/cron.get"), lazy: true });
2557
2786
  }
2787
+ if (aiTermsConfig) {
2788
+ addServerHandler({ route: AI_TERMS_PATH, handler: resolve$1("./runtime/server/routes/ai-terms"), lazy: true });
2789
+ addNitroPlugin(resolve$1("./runtime/server/plugins/ai-terms"));
2790
+ extendRouteRules("/**", {
2791
+ headers: {
2792
+ Link: [apiCatalogConfig && `<${apiCatalogConfig.href}>; rel="api-catalog"`, aiTermsLink].filter(Boolean).join(", ")
2793
+ }
2794
+ });
2795
+ extendRouteRules(AI_TERMS_PATH, {
2796
+ headers: {
2797
+ "Content-Type": "application/json; charset=utf-8",
2798
+ "Access-Control-Allow-Origin": "*",
2799
+ "Cache-Control": "public, max-age=3600"
2800
+ }
2801
+ });
2802
+ nuxt.hook("prerender:routes", ({ routes }) => {
2803
+ if (prerenderEnabled || routes.size > 0)
2804
+ routes.add(AI_TERMS_PATH);
2805
+ });
2806
+ }
2558
2807
  if (apiCatalogConfig)
2559
2808
  registerApiCatalog(apiCatalogConfig);
2560
2809
  if (!nuxt.options.dev && !nuxt.options._prepare) {
2561
2810
  if (isSPA && !hasPrerenderedRoutes) {
2562
2811
  logger.warn("SPA mode detected without prerendering. llms-full.txt will not be generated.");
2563
- } else if (!isStatic && !hasPrerenderedRoutes) {
2812
+ } else if (!isStatic && !hasPrerenderedRoutes && !zeroRuntimeMarkdown) {
2564
2813
  logger.info("SSR-only mode: llms-full.txt requires prerendering. Runtime markdown conversion available.");
2565
2814
  }
2566
2815
  }
2567
- if (prerenderEnabled) {
2816
+ if (prerenderMarkdown) {
2568
2817
  const { setupPrerenderHandler } = await import('../chunks/prerender.mjs');
2569
2818
  setupPrerenderHandler({ ...config, llmsTxt: generateLlmsTxt ? config.llmsTxt : false }, buildDbPath, {
2570
2819
  name: siteConfig.name,
@@ -2574,7 +2823,10 @@ export function trackDrizzleWork(event, work) { return work }
2574
2823
  ftsTokenizer,
2575
2824
  i18n: i18nConfig,
2576
2825
  artifactRoutes: agentSkillsResult._tag === "Enabled" ? Object.keys(agentSkillsResult.localArtifacts) : [],
2577
- runtimeDatabase: database._tag
2826
+ runtimeDatabase: database._tag,
2827
+ onMarkdownPaths: zeroRuntimeMarkdown ? (paths) => {
2828
+ prerenderedMarkdownPaths = paths;
2829
+ } : void 0
2578
2830
  });
2579
2831
  }
2580
2832
  if (databaseEnabled) {
@@ -2600,11 +2852,13 @@ export function trackDrizzleWork(event, work) { return work }
2600
2852
  const warnConfiguration = (nitro) => {
2601
2853
  if (preparing)
2602
2854
  return;
2855
+ const nuxtSeoReportsSiteUrl = nuxt.options.dev && !isAgent && !isCI && nuxt.options._installedModules.some(({ meta }) => meta.name === "nuxtseo" && !meta.disabled);
2603
2856
  const warnings = resolveConfigurationWarnings({
2604
2857
  policy: nuxt.options.runtimeConfig["nuxt-ai-ready"].contentNegotiation,
2605
2858
  botNegotiation: config.botNegotiation === true,
2606
2859
  static: nitro.options.static === true || isStatic,
2607
2860
  siteUrl: siteConfig.url || void 0,
2861
+ reportSiteUrl: !nuxtSeoReportsSiteUrl,
2608
2862
  routeRules: nitro.options.routeRules
2609
2863
  });
2610
2864
  for (const warning of warnings) {
@@ -2616,7 +2870,7 @@ export function trackDrizzleWork(event, work) { return work }
2616
2870
  };
2617
2871
  nuxt.hook("nitro:init", (nitro) => {
2618
2872
  warnConfiguration(nitro);
2619
- nitro.hooks.hook("rollup:reload", () => warnConfiguration(nitro));
2873
+ nitro.hooks.hook(getNitroVersion(nuxt) === 3 ? "build:reload" : "rollup:reload", () => warnConfiguration(nitro));
2620
2874
  });
2621
2875
  nuxt.hook("nitro:build:before", warnConfiguration);
2622
2876
  let sharedMarkdownRuleNoted = false;
@@ -2628,6 +2882,24 @@ export function trackDrizzleWork(event, work) { return work }
2628
2882
  };
2629
2883
  nuxt.hooks.hook("nitro:build:before", (nitro) => {
2630
2884
  const isCloudflarePreset = String(nitro.options.preset || "").startsWith("cloudflare");
2885
+ const applyMarkdownHeaders = () => {
2886
+ const plan = planStaticMarkdownHeaderRules(
2887
+ nitro.options.routeRules,
2888
+ prerenderedMarkdownHeaderRules(
2889
+ nitro._prerenderedRoutes || [],
2890
+ staticBaseURL,
2891
+ config.describedby !== false,
2892
+ agentSkillsResult._tag === "Enabled" ? Object.keys(agentSkillsResult.localArtifacts) : [],
2893
+ isCloudflarePreset ? void 0 : aiTermsLink
2894
+ ),
2895
+ isCloudflarePreset ? CLOUDFLARE_STATIC_HEADER_RULE_LIMIT : null
2896
+ );
2897
+ const headers = applyStaticMarkdownHeaderPlan(nitro.options.routeRules, plan);
2898
+ if (plan._tag === "skip")
2899
+ noteSharedMarkdownRule(plan.total, plan.dropped);
2900
+ return headers;
2901
+ };
2902
+ let prerenderFinished = false;
2631
2903
  nitro.hooks.hook("prerender:done", async () => {
2632
2904
  if (["cloudflare", "cloudflare-module", "cloudflare-durable"].includes(String(nitro.options.preset)) && !nitro.options.static && config.contentNegotiation === true) {
2633
2905
  const pages = cloudflarePrerenderedPages(nitro._prerenderedRoutes || [], staticBaseURL);
@@ -2639,27 +2911,41 @@ export function trackDrizzleWork(event, work) { return work }
2639
2911
  const additions = cloudflareWorkerFirstAdditions(routing, pages);
2640
2912
  const environmentConfig = wrangler;
2641
2913
  const configuredEnvironments = Object.values(environmentConfig.env || {}).flatMap((env) => env.assets?.run_worker_first === void 0 ? [] : [env.assets.run_worker_first]);
2642
- const fallbackPaths = cloudflareStaticFallbackPaths(routing, pages, [...fileRouting.environments, ...configuredEnvironments]);
2914
+ cloudflareFallbackPaths = cloudflareStaticFallbackPaths(routing, pages, [...fileRouting.environments, ...configuredEnvironments]);
2643
2915
  if (additions.length > 0)
2644
2916
  assets.run_worker_first = [...Array.isArray(assets.run_worker_first) ? assets.run_worker_first : [], ...additions];
2645
- nitro.options.runtimeConfig["nuxt-ai-ready"].cloudflarePrerenderedPages = fallbackPaths;
2646
2917
  }
2647
- const plan = planStaticMarkdownHeaderRules(
2648
- nitro.options.routeRules,
2649
- prerenderedMarkdownHeaderRules(
2650
- nitro._prerenderedRoutes || [],
2651
- staticBaseURL,
2652
- config.describedby !== false,
2653
- agentSkillsResult._tag === "Enabled" ? Object.keys(agentSkillsResult.localArtifacts) : []
2654
- ),
2655
- isCloudflarePreset ? CLOUDFLARE_STATIC_HEADER_RULE_LIMIT : null
2656
- );
2657
- if (plan._tag === "skip") {
2658
- applyStaticMarkdownHeaderPlan(nitro.options.routeRules, plan);
2659
- noteSharedMarkdownRule(plan.total, plan.dropped);
2918
+ prerenderFinished = true;
2919
+ });
2920
+ const bundlerHooks = new Set(nitroCompatibility._tag === "nitro-v2" ? ["rollup:before"] : ["build:config", "vite:compile:before"]);
2921
+ nitro.hooks.afterEach(({ name }) => {
2922
+ if (nitro.options.static) {
2923
+ if (name === "prerender:done")
2924
+ applyMarkdownHeaders();
2660
2925
  return;
2661
2926
  }
2662
- applyStaticMarkdownHeaderPlan(nitro.options.routeRules, plan);
2927
+ if (!prerenderFinished || !bundlerHooks.has(name))
2928
+ return;
2929
+ prerenderFinished = false;
2930
+ const runtimeRouteRules = { ...nitro.options.runtimeConfig.nitro.routeRules };
2931
+ const headers = applyMarkdownHeaders();
2932
+ const matchRouteRules = createNitroRouteRuleMatcher({ nitro: { routeRules: runtimeRouteRules } });
2933
+ prerenderedMarkdownHeaders = [];
2934
+ for (const [path, values] of headers) {
2935
+ const rule = matchRouteRules(path);
2936
+ if (rule.redirect || rule.proxy) {
2937
+ const deploymentRule = nitro.options.routeRules[path];
2938
+ const runtimeRule = runtimeRouteRules[path];
2939
+ runtimeRouteRules[path] = {
2940
+ ...deploymentRule,
2941
+ ...runtimeRule,
2942
+ headers: defu$1(values, runtimeRule?.headers)
2943
+ };
2944
+ } else {
2945
+ prerenderedMarkdownHeaders.push([decodePath(path), values]);
2946
+ }
2947
+ }
2948
+ nitro.options.runtimeConfig.nitro.routeRules = runtimeRouteRules;
2663
2949
  });
2664
2950
  nitro.hooks.hook("compiled", async () => {
2665
2951
  const generatedHeadersPath = join(nitro.options.output.publicDir, "_headers");
@@ -2720,9 +3006,11 @@ export function trackDrizzleWork(event, work) { return work }
2720
3006
  discovery.push(staticDescribedbyEntry(staticBaseURL));
2721
3007
  if (staticDiscoverySupported && apiCatalogConfig && await hasArtifact(API_CATALOG_PATH))
2722
3008
  discovery.push(`<${encodeURI(apiCatalogConfig.href)}>; rel="api-catalog"`);
3009
+ if (staticDiscoverySupported && aiTermsLink && await hasArtifact(AI_TERMS_PATH))
3010
+ discovery.push(aiTermsLink);
2723
3011
  mergedHeaders = mergeStaticDiscoveryHeaders(mergedHeaders, staticBaseURL, discovery);
2724
3012
  mergedHeaders = dedupeStaticHeaders(mergedHeaders, ["Content-Type", "Link", "Vary"]);
2725
- mergedHeaders = normalizeStaticContentSignalHeaders(mergedHeaders);
3013
+ mergedHeaders = normalizeStaticContentSignalHeaders(mergedHeaders, aiTermsLink ? [...discovery, aiTermsLink] : discovery);
2726
3014
  const budget = enforceStaticHeaderBudget(mergedHeaders, CLOUDFLARE_STATIC_HEADER_RULE_LIMIT);
2727
3015
  if (budget.dropped > 0) {
2728
3016
  mergedHeaders = budget.contents;
@@ -1,8 +1,8 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { readFile } from 'node:fs/promises';
3
- import { findPackageJSON } from 'node:module';
4
3
  import { isAbsolute, join } from 'node:path';
5
4
  import { pathToFileURL } from 'node:url';
5
+ import { findPackageJSON } from 'nuxtseo-shared/kit';
6
6
 
7
7
  function resolvePackageMetadataPath(specifier, base, options) {
8
8
  if (options) {
package/dist/types.d.mts CHANGED
@@ -5,6 +5,8 @@ declare module '@nuxt/schema' {
5
5
  interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
6
6
  }
7
7
 
8
+ export { type AiTermsAccess, type AiTermsConfig, type AiTermsDocument, type AiTermsFreeAllowance, type AiTermsPath, type AiTermsPayment, type AiTermsPrice, type AiTermsPurpose, type AiTermsUse } from '../dist/runtime/ai-terms.js'
9
+
8
10
  export { type AgentSkillConfig, type AgentSkillsConfig, type AgentSkillsIndex, type AgentSkillsIndexEntry, type ApiCatalogConfig, type ApiCatalogEntry, type ApiCatalogLinkTarget, type ApiCatalogLinks, type ExternalAgentSkillConfig, type LocalAgentSkillConfig, type McpServerCardConfig, type ModuleOptions } from '../dist/runtime/types.js'
9
11
 
10
12
  export { type GetPageMarkdownToolOptions, type ListPagesToolOptions, type McpSiteToolAttachmentOptions, type SearchPagesToolOptions, type SiteToolOptions, type SiteToolsConfig, type WebMcpSiteToolAttachmentOptions } from '../dist/runtime/site-tool-config.js'