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.
Files changed (161) hide show
  1. package/dist/agent-skills-config-CmZq9uWW.mjs +18 -0
  2. package/dist/agent-skills-zGLgFB6H.mjs +468 -0
  3. package/dist/cli.d.mts +1 -0
  4. package/dist/cli.mjs +656 -570
  5. package/dist/devtools/pages/ai-ready/debug.vue +9 -3
  6. package/dist/devtools/pages/ai-ready/index.vue +3 -1
  7. package/dist/devtools/pages/ai-ready/llms-txt.vue +15 -4
  8. package/dist/devtools/pages/ai-ready.vue +28 -4
  9. package/dist/module.d.mts +106 -112
  10. package/dist/module.json +3 -3
  11. package/dist/module.mjs +2732 -26
  12. package/dist/package-metadata-B1darl8W.mjs +28 -0
  13. package/dist/prerender-QMv07W4h.mjs +650 -0
  14. package/dist/runtime/app/composables/webmcp.js +90 -97
  15. package/dist/runtime/app/plugins/md-alternate.server.js +29 -26
  16. package/dist/runtime/app/plugins/md-hints.prerender.js +13 -15
  17. package/dist/runtime/app/plugins/webmcp.client.js +49 -53
  18. package/dist/runtime/app/webmcp-config.js +2 -2
  19. package/dist/runtime/cache-control.js +16 -10
  20. package/dist/runtime/i18n-url.js +6 -6
  21. package/dist/runtime/index.js +4 -12
  22. package/dist/runtime/llms-txt-directive.js +20 -13
  23. package/dist/runtime/llms-txt-files.js +188 -187
  24. package/dist/runtime/llms-txt-format.js +54 -55
  25. package/dist/runtime/llms-txt-i18n.js +22 -19
  26. package/dist/runtime/llms-txt-utils.js +140 -95
  27. package/dist/runtime/markdown-links.js +45 -39
  28. package/dist/runtime/markdown-path.js +29 -9
  29. package/dist/runtime/markdown-text.js +2 -1
  30. package/dist/runtime/mcp.js +5 -1
  31. package/dist/runtime/route-path.js +14 -8
  32. package/dist/runtime/server/db/drizzle/client.js +71 -75
  33. package/dist/runtime/server/db/drizzle/index.js +16 -28
  34. package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -1
  35. package/dist/runtime/server/db/drizzle/providers/bun.js +10 -7
  36. package/dist/runtime/server/db/drizzle/providers/d1.js +16 -13
  37. package/dist/runtime/server/db/drizzle/providers/dbPath.js +60 -37
  38. package/dist/runtime/server/db/drizzle/providers/libsql.js +23 -11
  39. package/dist/runtime/server/db/drizzle/providers/neon.js +13 -10
  40. package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +10 -7
  41. package/dist/runtime/server/db/drizzle/providers/postgres.js +13 -10
  42. package/dist/runtime/server/db/drizzle/queries.js +633 -532
  43. package/dist/runtime/server/db/drizzle/raw.js +200 -176
  44. package/dist/runtime/server/db/index.js +3 -0
  45. package/dist/runtime/server/db/queries.js +816 -607
  46. package/dist/runtime/server/db/schema/postgres.js +56 -50
  47. package/dist/runtime/server/db/schema/sqlite.js +56 -50
  48. package/dist/runtime/server/db/schema-sql.js +35 -38
  49. package/dist/runtime/server/db/seed.js +60 -45
  50. package/dist/runtime/server/db/shared.js +300 -213
  51. package/dist/runtime/server/index.js +1 -17
  52. package/dist/runtime/server/mcp/cache-key.js +5 -1
  53. package/dist/runtime/server/mcp/resources/pages.js +32 -33
  54. package/dist/runtime/server/mcp/tools/get-page-markdown.js +41 -27
  55. package/dist/runtime/server/mcp/tools/list-pages.js +40 -34
  56. package/dist/runtime/server/mcp/tools/search-pages.js +24 -16
  57. package/dist/runtime/server/middleware/markdown.d.ts +1 -1
  58. package/dist/runtime/server/middleware/markdown.js +15 -13
  59. package/dist/runtime/server/middleware/markdown.prerender.d.ts +1 -1
  60. package/dist/runtime/server/middleware/markdown.prerender.js +135 -119
  61. package/dist/runtime/server/middleware/render-markdown.d.ts +1 -1
  62. package/dist/runtime/server/middleware/render-markdown.js +164 -144
  63. package/dist/runtime/server/plugins/ai-terms.d.ts +1 -1
  64. package/dist/runtime/server/plugins/ai-terms.js +4 -8
  65. package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.d.ts +1 -1
  66. package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.js +7 -8
  67. package/dist/runtime/server/plugins/content-signal-capture.prerender.d.ts +1 -1
  68. package/dist/runtime/server/plugins/content-signal-capture.prerender.js +7 -7
  69. package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +1 -1
  70. package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +13 -14
  71. package/dist/runtime/server/plugins/db-lifecycle.js +13 -11
  72. package/dist/runtime/server/plugins/html-capture.prerender.js +6 -6
  73. package/dist/runtime/server/plugins/link-header-nitro3.d.ts +1 -1
  74. package/dist/runtime/server/plugins/link-header-nitro3.js +23 -13
  75. package/dist/runtime/server/plugins/link-header.d.ts +1 -1
  76. package/dist/runtime/server/plugins/link-header.js +30 -30
  77. package/dist/runtime/server/plugins/llms-txt-directive-html.d.ts +1 -1
  78. package/dist/runtime/server/plugins/llms-txt-directive-html.js +4 -3
  79. package/dist/runtime/server/plugins/markdown-negotiation.d.ts +1 -1
  80. package/dist/runtime/server/plugins/markdown-negotiation.js +64 -45
  81. package/dist/runtime/server/plugins/sitemap-seeder.js +144 -112
  82. package/dist/runtime/server/routes/__ai-ready/cron.get.d.ts +1 -1
  83. package/dist/runtime/server/routes/__ai-ready/cron.get.js +17 -11
  84. package/dist/runtime/server/routes/__ai-ready/devtools.get.d.ts +1 -1
  85. package/dist/runtime/server/routes/__ai-ready/devtools.get.js +60 -45
  86. package/dist/runtime/server/routes/__ai-ready/pages.get.d.ts +36 -1
  87. package/dist/runtime/server/routes/__ai-ready/pages.get.js +44 -40
  88. package/dist/runtime/server/routes/__ai-ready/poll.post.d.ts +15 -1
  89. package/dist/runtime/server/routes/__ai-ready/poll.post.js +30 -30
  90. package/dist/runtime/server/routes/__ai-ready/prune.post.d.ts +13 -1
  91. package/dist/runtime/server/routes/__ai-ready/prune.post.js +29 -15
  92. package/dist/runtime/server/routes/__ai-ready/reindex.post.d.ts +22 -1
  93. package/dist/runtime/server/routes/__ai-ready/reindex.post.js +31 -21
  94. package/dist/runtime/server/routes/__ai-ready/restore.post.d.ts +4 -1
  95. package/dist/runtime/server/routes/__ai-ready/restore.post.js +28 -22
  96. package/dist/runtime/server/routes/__ai-ready/status.get.d.ts +1 -1
  97. package/dist/runtime/server/routes/__ai-ready/status.get.js +52 -53
  98. package/dist/runtime/server/routes/__ai-ready-debug.get.d.ts +83 -1
  99. package/dist/runtime/server/routes/__ai-ready-debug.get.js +209 -189
  100. package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
  101. package/dist/runtime/server/routes/agent-skills-artifact.js +16 -14
  102. package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
  103. package/dist/runtime/server/routes/agent-skills-index.js +8 -6
  104. package/dist/runtime/server/routes/ai-catalog.js +19 -19
  105. package/dist/runtime/server/routes/ai-terms.js +23 -19
  106. package/dist/runtime/server/routes/api-catalog.js +23 -23
  107. package/dist/runtime/server/routes/llms-full.txt.get.d.ts +1 -1
  108. package/dist/runtime/server/routes/llms-full.txt.get.js +42 -41
  109. package/dist/runtime/server/routes/llms.txt.get.d.ts +1 -1
  110. package/dist/runtime/server/routes/llms.txt.get.js +38 -33
  111. package/dist/runtime/server/routes/mcp-server-card.js +19 -19
  112. package/dist/runtime/server/routes/sitemap.md.get.d.ts +1 -1
  113. package/dist/runtime/server/routes/sitemap.md.get.js +38 -39
  114. package/dist/runtime/server/tasks/ai-ready-cron.d.ts +1 -1
  115. package/dist/runtime/server/tasks/ai-ready-cron.js +17 -14
  116. package/dist/runtime/server/utils/auth.js +76 -53
  117. package/dist/runtime/server/utils/batchIndex.js +72 -60
  118. package/dist/runtime/server/utils/checkStale.js +181 -134
  119. package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -20
  120. package/dist/runtime/server/utils/cloudflare.js +69 -51
  121. package/dist/runtime/server/utils/content-negotiation.js +30 -18
  122. package/dist/runtime/server/utils/content.js +4 -1
  123. package/dist/runtime/server/utils/context.js +30 -19
  124. package/dist/runtime/server/utils/cron-plan.js +6 -6
  125. package/dist/runtime/server/utils/discovery-response.js +5 -6
  126. package/dist/runtime/server/utils/fetch.js +2 -1
  127. package/dist/runtime/server/utils/frontmatter.js +44 -57
  128. package/dist/runtime/server/utils/i18n.js +3 -8
  129. package/dist/runtime/server/utils/indexPage.js +152 -113
  130. package/dist/runtime/server/utils/keywords.js +278 -277
  131. package/dist/runtime/server/utils/link-header.js +67 -56
  132. package/dist/runtime/server/utils/llms-full.js +39 -49
  133. package/dist/runtime/server/utils/markdown-redirect.js +26 -14
  134. package/dist/runtime/server/utils/markdown-request.js +62 -47
  135. package/dist/runtime/server/utils/negotiation-decision.d.ts +8 -0
  136. package/dist/runtime/server/utils/negotiation-decision.js +106 -34
  137. package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
  138. package/dist/runtime/server/utils/negotiation-response.js +195 -144
  139. package/dist/runtime/server/utils/page-updated-at.js +23 -15
  140. package/dist/runtime/server/utils/prerender-html.js +31 -17
  141. package/dist/runtime/server/utils/runCron.js +263 -192
  142. package/dist/runtime/server/utils/sitemap-crawl-state.js +57 -39
  143. package/dist/runtime/server/utils/sitemap-lastmod.js +16 -14
  144. package/dist/runtime/server/utils/sitemap-md.js +39 -50
  145. package/dist/runtime/server/utils/sitemap-routes.js +7 -7
  146. package/dist/runtime/server/utils/sitemap.js +459 -414
  147. package/dist/runtime/server/utils.js +141 -122
  148. package/dist/runtime/site-tool-catalog.js +39 -43
  149. package/dist/runtime/site-tool-config.js +1 -0
  150. package/dist/runtime/sync-secret.js +11 -11
  151. package/dist/runtime/types.js +1 -0
  152. package/dist/runtime/webmcp-site-tools.js +278 -250
  153. package/dist/runtime/webmcp.js +53 -42
  154. package/dist/static-headers-G7hFL3wE.mjs +328 -0
  155. package/dist/types.d.mts +1 -9
  156. package/package.json +18 -22
  157. package/skills/nuxt-ai-ready/SKILL.md +8 -2
  158. package/dist/chunks/agent-skills.mjs +0 -383
  159. package/dist/chunks/prerender.mjs +0 -683
  160. package/dist/shared/nuxt-ai-ready.Bzx0dNWj.mjs +0 -3034
  161. package/dist/shared/nuxt-ai-ready.DCd-1s1G.mjs +0 -29
@@ -2,195 +2,196 @@ import { formatLlmsTxtPageLink, normalizeLlmsTxtConfig } from "./llms-txt-format
2
2
  const FILE_PATH = /^\/llms\/[a-z0-9][\w-]*\.txt$/i;
3
3
  const SITEMAP_NAME = /^[a-z0-9][\w-]*$/i;
4
4
  export function llmsTxtSectionPath(section) {
5
- const name = Array.isArray(section.sitemap) ? section.sitemap[0] : section.sitemap;
6
- return section.path || `/llms/${name}.txt`;
5
+ const name = Array.isArray(section.sitemap) ? section.sitemap[0] : section.sitemap;
6
+ return section.path || `/llms/${name}.txt`;
7
7
  }
8
+ /** Parse the public configuration once, before Nitro registers routes. */
8
9
  export function parseLlmsTxtConfig(input) {
9
- const invalid = (message) => ({ _tag: "Invalid", message });
10
- if (!input || typeof input !== "object" || Array.isArray(input))
11
- return invalid("llmsTxt must be an object or false.");
12
- const config = input;
13
- if (config.pages !== void 0 && config.pages !== false && config.pages !== "sitemap" && config.pages !== "all")
14
- return invalid("llmsTxt.pages must be sitemap, all, or false.");
15
- if (config.maxLength !== void 0 && (!Number.isSafeInteger(config.maxLength) || config.maxLength < 1024))
16
- return invalid("llmsTxt.maxLength must be an integer of at least 1024.");
17
- if (config.sitemaps !== void 0 && (!Array.isArray(config.sitemaps) || config.sitemaps.some((name) => typeof name !== "string" || !SITEMAP_NAME.test(name))))
18
- return invalid("llmsTxt.sitemaps must contain sitemap names.");
19
- if (config.sections !== void 0 && !Array.isArray(config.sections))
20
- return invalid("llmsTxt.sections must be an array.");
21
- const paths = /* @__PURE__ */ new Set();
22
- for (const section of config.sections || []) {
23
- if (!section || typeof section !== "object" || typeof section.title !== "string")
24
- return invalid("Each llmsTxt section needs a title.");
25
- if (section.sitemap === void 0) {
26
- if (section.path !== void 0)
27
- return invalid("A section path requires a sitemap.");
28
- continue;
29
- }
30
- const names = Array.isArray(section.sitemap) ? section.sitemap : [section.sitemap];
31
- if (!names.length || names.some((name) => typeof name !== "string" || !SITEMAP_NAME.test(name)))
32
- return invalid("Each section sitemap must contain a sitemap name.");
33
- const path = llmsTxtSectionPath(section);
34
- if (!FILE_PATH.test(path))
35
- return invalid("A section path must use /llms/<name>.txt.");
36
- if (paths.has(path))
37
- return invalid(`Duplicate llmsTxt section path: ${path}.`);
38
- paths.add(path);
39
- }
40
- return { _tag: "Valid", config };
10
+ const invalid = (message) => ({
11
+ _tag: "Invalid",
12
+ message
13
+ });
14
+ if (!input || typeof input !== "object" || Array.isArray(input)) return invalid("llmsTxt must be an object or false.");
15
+ const config = input;
16
+ if (config.pages !== undefined && config.pages !== false && config.pages !== "sitemap" && config.pages !== "all") return invalid("llmsTxt.pages must be sitemap, all, or false.");
17
+ if (config.maxLength !== undefined && (!Number.isSafeInteger(config.maxLength) || config.maxLength < 1024)) return invalid("llmsTxt.maxLength must be an integer of at least 1024.");
18
+ if (config.sitemaps !== undefined && (!Array.isArray(config.sitemaps) || config.sitemaps.some((name) => typeof name !== "string" || !SITEMAP_NAME.test(name)))) return invalid("llmsTxt.sitemaps must contain sitemap names.");
19
+ if (config.sections !== undefined && !Array.isArray(config.sections)) return invalid("llmsTxt.sections must be an array.");
20
+ const paths = new Set();
21
+ for (const section of config.sections || []) {
22
+ if (!section || typeof section !== "object" || typeof section.title !== "string") return invalid("Each llmsTxt section needs a title.");
23
+ if (section.sitemap === undefined) {
24
+ if (section.path !== undefined) return invalid("A section path requires a sitemap.");
25
+ continue;
26
+ }
27
+ const names = Array.isArray(section.sitemap) ? section.sitemap : [section.sitemap];
28
+ if (!names.length || names.some((name) => typeof name !== "string" || !SITEMAP_NAME.test(name))) return invalid("Each section sitemap must contain a sitemap name.");
29
+ const path = llmsTxtSectionPath(section);
30
+ if (!FILE_PATH.test(path)) return invalid("A section path must use /llms/<name>.txt.");
31
+ if (paths.has(path)) return invalid(`Duplicate llmsTxt section path: ${path}.`);
32
+ paths.add(path);
33
+ }
34
+ return {
35
+ _tag: "Valid",
36
+ config
37
+ };
41
38
  }
39
+ /** A bounded tree of file lists. Every page appears once; every file is reachable from the root. */
42
40
  export function createLlmsTxtFiles(input) {
43
- const files = /* @__PURE__ */ new Map();
44
- const maxLength = input.config.maxLength ?? 8e4;
45
- const link = (title, path, description) => formatLlmsTxtPageLink({ pathname: path, href: input.resolveUrl(path), title, description });
46
- const render = (header, title, lines) => `${header.trim()}
47
-
48
- ## ${title.replace(/\s+/g, " ").trim()}
49
-
50
- ${lines.join("\n")}
51
- `;
52
- function tree(path, prefix, header, title, lines, level = 0) {
53
- const body = render(header, title, lines);
54
- if (body.length <= maxLength) {
55
- files.set(path, body);
56
- return;
57
- }
58
- const overhead = render(header, title, []).length;
59
- const chunks = [];
60
- let chunk = [];
61
- let length = overhead;
62
- for (const line of lines) {
63
- if (overhead + line.length + 1 > maxLength)
64
- throw new Error("An llms.txt entry exceeds llmsTxt.maxLength. Shorten the entry or increase the limit.");
65
- if (length + line.length + 1 > maxLength) {
66
- chunks.push(chunk);
67
- chunk = [];
68
- length = overhead;
69
- }
70
- chunk.push(line);
71
- length += line.length + 1;
72
- }
73
- if (chunk.length)
74
- chunks.push(chunk);
75
- const links = chunks.map((entries, index) => {
76
- const child = `/llms/_${prefix}-${level}-${index + 1}.txt`;
77
- files.set(child, render(header, title, entries));
78
- return link(`${title} ${index + 1}`, child);
79
- });
80
- if (chunks.length >= lines.length && render(header, title, links).length >= body.length)
81
- throw new Error("llmsTxt.maxLength cannot fit an index. Increase the limit.");
82
- tree(path, prefix, header, title, links, level + 1);
83
- }
84
- const sections = [];
85
- const assigned = /* @__PURE__ */ new Set();
86
- for (const [index, section] of input.sections.entries()) {
87
- if (!section.sitemap) {
88
- sections.push(section);
89
- continue;
90
- }
91
- const names = Array.isArray(section.sitemap) ? section.sitemap : [section.sitemap];
92
- const pages2 = /* @__PURE__ */ new Map();
93
- for (const name of names) {
94
- for (const page of input.sitemapPages.get(name) || []) {
95
- if (!assigned.has(page.pathname))
96
- pages2.set(page.pathname, page);
97
- }
98
- }
99
- const entries = [...(section.links || []).map((entry) => formatLlmsTxtPageLink({ pathname: entry.href, ...entry })), ...[...pages2.values()].map(formatLlmsTxtPageLink)];
100
- if (!entries.length)
101
- continue;
102
- for (const pathname of pages2.keys())
103
- assigned.add(pathname);
104
- const path = llmsTxtSectionPath(section);
105
- const description = Array.isArray(section.description) ? section.description.join(" ") : section.description;
106
- const preamble = normalizeLlmsTxtConfig({ notes: description });
107
- tree(path, `section-${index + 1}`, `${input.header.trim()}
108
-
109
- ${preamble}
110
-
111
- ${link("llms.txt", "/llms.txt")}`, section.title, entries);
112
- sections.push({ ...section, sitemap: void 0, path: void 0, links: [{ title: section.title, href: input.resolveUrl(path), description }] });
113
- }
114
- const rootPreamble = `${input.header.trim()}
115
-
116
- ${normalizeLlmsTxtConfig({ notes: input.config.notes })}${input.rootContent ? `
117
-
118
- ${input.rootContent}` : ""}`;
119
- const pageIndexSpace = input.pages.some((page) => !assigned.has(page.pathname)) ? render("", "Pages", [link("Pages", "/llms/_pages.txt")]).length : 1;
120
- let rootHeader = `${input.header.trim()}
121
-
122
- ${normalizeLlmsTxtConfig({ ...input.config, sections })}${input.rootContent ? `
123
-
124
- ${input.rootContent}` : ""}`;
125
- if (rootHeader.length + pageIndexSpace > maxLength) {
126
- const references = sections.flatMap((section, index) => {
127
- const path = `/llms/_configured-${index + 1}.txt`;
128
- if (!section.links?.length) {
129
- const context = normalizeLlmsTxtConfig({ sections: [section] });
130
- if (!context)
131
- return [];
132
- const body = `${input.header.trim()}
133
-
134
- ${context}
135
-
136
- ${link("llms.txt", "/llms.txt")}
137
- `;
138
- if (body.length > maxLength)
139
- throw new Error("An llms.txt entry exceeds llmsTxt.maxLength. Shorten the entry or increase the limit.");
140
- files.set(path, body);
141
- return [{ title: section.title, links: [{ title: section.title, href: input.resolveUrl(path) }] }];
142
- }
143
- const text = normalizeLlmsTxtConfig({ sections: [{ ...section, description: section.optional ? section.description : void 0 }] });
144
- const lines = text.split("\n").slice(2);
145
- const description = Array.isArray(section.description) ? section.description.join(" ") : section.description;
146
- const preamble = section.optional ? "" : normalizeLlmsTxtConfig({ notes: description });
147
- tree(path, `configured-${index + 1}`, `${input.header.trim()}
148
-
149
- ${preamble}
150
-
151
- ${link("llms.txt", "/llms.txt")}`, section.optional ? "Optional" : section.title, lines);
152
- return [{ title: section.title, optional: section.optional, links: [{ title: section.title, href: input.resolveUrl(path), description }] }];
153
- });
154
- rootHeader = `${rootPreamble}
155
-
156
- ${normalizeLlmsTxtConfig({ sections: references })}`;
157
- if (rootHeader.length + pageIndexSpace > maxLength) {
158
- const indexes = [];
159
- for (const optional of [false, true]) {
160
- const selected = references.filter((section) => Boolean(section.optional) === optional);
161
- if (!selected.length)
162
- continue;
163
- const title = optional ? "Optional" : "Sections";
164
- const path = optional ? "/llms/_optional.txt" : "/llms/_sections.txt";
165
- const text = normalizeLlmsTxtConfig({ sections: selected.map((section) => ({ ...section, optional: true })) });
166
- tree(path, optional ? "optional" : "sections", input.header, title, text.split("\n").slice(2));
167
- indexes.push({ title, optional, links: [{ title, href: input.resolveUrl(path) }] });
168
- }
169
- rootHeader = `${rootPreamble}
170
-
171
- ${normalizeLlmsTxtConfig({ sections: indexes })}`;
172
- }
173
- }
174
- const pages = input.pages.filter((page) => !assigned.has(page.pathname)).map(formatLlmsTxtPageLink);
175
- if (!pages.length && rootHeader.length + 1 <= maxLength) {
176
- files.set("/llms.txt", `${rootHeader.trim()}
177
- `);
178
- } else {
179
- const inline = render(rootHeader, "Pages", pages);
180
- if (inline.length <= maxLength) {
181
- files.set("/llms.txt", inline);
182
- } else {
183
- tree("/llms/_pages.txt", "pages", input.header, "Pages", pages);
184
- const root = `${rootHeader.trim()}
185
-
186
- ## Pages
187
-
188
- ${link("Pages", "/llms/_pages.txt")}
189
- `;
190
- if (root.length > maxLength)
191
- throw new Error("llms.txt sections exceed llmsTxt.maxLength. Shorten the sections or increase the limit.");
192
- files.set("/llms.txt", root);
193
- }
194
- }
195
- return files;
41
+ const files = new Map();
42
+ const maxLength = input.config.maxLength ?? 8e4;
43
+ const link = (title, path, description) => formatLlmsTxtPageLink({
44
+ pathname: path,
45
+ href: input.resolveUrl(path),
46
+ title,
47
+ description
48
+ });
49
+ const render = (header, title, lines) => `${header.trim()}\n\n## ${title.replace(/\s+/g, " ").trim()}\n\n${lines.join("\n")}\n`;
50
+ function tree(path, prefix, header, title, lines, level = 0) {
51
+ const body = render(header, title, lines);
52
+ if (body.length <= maxLength) {
53
+ files.set(path, body);
54
+ return;
55
+ }
56
+ const overhead = render(header, title, []).length;
57
+ const chunks = [];
58
+ let chunk = [];
59
+ let length = overhead;
60
+ for (const line of lines) {
61
+ if (overhead + line.length + 1 > maxLength) throw new Error("An llms.txt entry exceeds llmsTxt.maxLength. Shorten the entry or increase the limit.");
62
+ if (length + line.length + 1 > maxLength) {
63
+ chunks.push(chunk);
64
+ chunk = [];
65
+ length = overhead;
66
+ }
67
+ chunk.push(line);
68
+ length += line.length + 1;
69
+ }
70
+ if (chunk.length) chunks.push(chunk);
71
+ const links = chunks.map((entries, index) => {
72
+ const child = `/llms/_${prefix}-${level}-${index + 1}.txt`;
73
+ files.set(child, render(header, title, entries));
74
+ return link(`${title} ${index + 1}`, child);
75
+ });
76
+ if (chunks.length >= lines.length && render(header, title, links).length >= body.length) throw new Error("llmsTxt.maxLength cannot fit an index. Increase the limit.");
77
+ tree(path, prefix, header, title, links, level + 1);
78
+ }
79
+ const sections = [];
80
+ const assigned = new Set();
81
+ for (const [index, section] of input.sections.entries()) {
82
+ if (!section.sitemap) {
83
+ sections.push(section);
84
+ continue;
85
+ }
86
+ const names = Array.isArray(section.sitemap) ? section.sitemap : [section.sitemap];
87
+ const pages = new Map();
88
+ for (const name of names) {
89
+ for (const page of input.sitemapPages.get(name) || []) {
90
+ // A page in several sitemaps belongs to the first configured section.
91
+ if (!assigned.has(page.pathname)) pages.set(page.pathname, page);
92
+ }
93
+ }
94
+ const entries = [...(section.links || []).map((entry) => formatLlmsTxtPageLink({
95
+ pathname: entry.href,
96
+ ...entry
97
+ })), ...[...pages.values()].map(formatLlmsTxtPageLink)];
98
+ if (!entries.length) continue;
99
+ for (const pathname of pages.keys()) assigned.add(pathname);
100
+ const path = llmsTxtSectionPath(section);
101
+ const description = Array.isArray(section.description) ? section.description.join(" ") : section.description;
102
+ const preamble = normalizeLlmsTxtConfig({ notes: description });
103
+ tree(path, `section-${index + 1}`, `${input.header.trim()}\n\n${preamble}\n\n${link("llms.txt", "/llms.txt")}`, section.title, entries);
104
+ sections.push({
105
+ ...section,
106
+ sitemap: undefined,
107
+ path: undefined,
108
+ links: [{
109
+ title: section.title,
110
+ href: input.resolveUrl(path),
111
+ description
112
+ }]
113
+ });
114
+ }
115
+ const rootPreamble = `${input.header.trim()}\n\n${normalizeLlmsTxtConfig({ notes: input.config.notes })}${input.rootContent ? `\n\n${input.rootContent}` : ""}`;
116
+ const pageIndexSpace = input.pages.some((page) => !assigned.has(page.pathname)) ? render("", "Pages", [link("Pages", "/llms/_pages.txt")]).length : 1;
117
+ let rootHeader = `${input.header.trim()}\n\n${normalizeLlmsTxtConfig({
118
+ ...input.config,
119
+ sections
120
+ })}${input.rootContent ? `\n\n${input.rootContent}` : ""}`;
121
+ if (rootHeader.length + pageIndexSpace > maxLength) {
122
+ const references = sections.flatMap((section, index) => {
123
+ const path = `/llms/_configured-${index + 1}.txt`;
124
+ if (!section.links?.length) {
125
+ const context = normalizeLlmsTxtConfig({ sections: [section] });
126
+ if (!context) return [];
127
+ const body = `${input.header.trim()}\n\n${context}\n\n${link("llms.txt", "/llms.txt")}\n`;
128
+ if (body.length > maxLength) throw new Error("An llms.txt entry exceeds llmsTxt.maxLength. Shorten the entry or increase the limit.");
129
+ files.set(path, body);
130
+ return [{
131
+ title: section.title,
132
+ links: [{
133
+ title: section.title,
134
+ href: input.resolveUrl(path)
135
+ }]
136
+ }];
137
+ }
138
+ const text = normalizeLlmsTxtConfig({ sections: [{
139
+ ...section,
140
+ description: section.optional ? section.description : undefined
141
+ }] });
142
+ const lines = text.split("\n").slice(2);
143
+ const description = Array.isArray(section.description) ? section.description.join(" ") : section.description;
144
+ const preamble = section.optional ? "" : normalizeLlmsTxtConfig({ notes: description });
145
+ tree(path, `configured-${index + 1}`, `${input.header.trim()}\n\n${preamble}\n\n${link("llms.txt", "/llms.txt")}`, section.optional ? "Optional" : section.title, lines);
146
+ return [{
147
+ title: section.title,
148
+ optional: section.optional,
149
+ links: [{
150
+ title: section.title,
151
+ href: input.resolveUrl(path),
152
+ description
153
+ }]
154
+ }];
155
+ });
156
+ rootHeader = `${rootPreamble}\n\n${normalizeLlmsTxtConfig({ sections: references })}`;
157
+ if (rootHeader.length + pageIndexSpace > maxLength) {
158
+ const indexes = [];
159
+ for (const optional of [false, true]) {
160
+ const selected = references.filter((section) => Boolean(section.optional) === optional);
161
+ if (!selected.length) continue;
162
+ const title = optional ? "Optional" : "Sections";
163
+ const path = optional ? "/llms/_optional.txt" : "/llms/_sections.txt";
164
+ const text = normalizeLlmsTxtConfig({ sections: selected.map((section) => ({
165
+ ...section,
166
+ optional: true
167
+ })) });
168
+ tree(path, optional ? "optional" : "sections", input.header, title, text.split("\n").slice(2));
169
+ indexes.push({
170
+ title,
171
+ optional,
172
+ links: [{
173
+ title,
174
+ href: input.resolveUrl(path)
175
+ }]
176
+ });
177
+ }
178
+ rootHeader = `${rootPreamble}\n\n${normalizeLlmsTxtConfig({ sections: indexes })}`;
179
+ }
180
+ }
181
+ const pages = input.pages.filter((page) => !assigned.has(page.pathname)).map(formatLlmsTxtPageLink);
182
+ if (!pages.length && rootHeader.length + 1 <= maxLength) {
183
+ files.set("/llms.txt", `${rootHeader.trim()}\n`);
184
+ } else {
185
+ // Child lists carry only the site header, not the root's custom sections.
186
+ const inline = render(rootHeader, "Pages", pages);
187
+ if (inline.length <= maxLength) {
188
+ files.set("/llms.txt", inline);
189
+ } else {
190
+ tree("/llms/_pages.txt", "pages", input.header, "Pages", pages);
191
+ const root = `${rootHeader.trim()}\n\n## Pages\n\n${link("Pages", "/llms/_pages.txt")}\n`;
192
+ if (root.length > maxLength) throw new Error("llms.txt sections exceed llmsTxt.maxLength. Shorten the sections or increase the limit.");
193
+ files.set("/llms.txt", root);
194
+ }
195
+ }
196
+ return files;
196
197
  }
@@ -4,81 +4,80 @@ const RE_LINK_TITLE_BRACKET = /[[\]]/g;
4
4
  const RE_LINK_HREF_UNSAFE = /[\s()]/g;
5
5
  const RE_PREAMBLE_ATX_HEADING = /^( {0,3})(#{1,6})(?=\s)/gm;
6
6
  function normalizeInlineText(value) {
7
- return value.trim().replace(RE_INLINE_WHITESPACE, " ");
7
+ return value.trim().replace(RE_INLINE_WHITESPACE, " ");
8
8
  }
9
9
  function normalizeLinkTitle(value) {
10
- return escapeMarkdownHtml(normalizeInlineText(value)).replace(RE_LINK_TITLE_BRACKET, (bracket) => bracket === "[" ? "&#91;" : "&#93;");
10
+ return escapeMarkdownHtml(normalizeInlineText(value)).replace(RE_LINK_TITLE_BRACKET, (bracket) => bracket === "[" ? "&#91;" : "&#93;");
11
11
  }
12
12
  function normalizeLinkHref(value) {
13
- return value.trim().replace(RE_LINK_HREF_UNSAFE, (character) => {
14
- if (character === "(")
15
- return "%28";
16
- if (character === ")")
17
- return "%29";
18
- return encodeURIComponent(character);
19
- });
13
+ return value.trim().replace(RE_LINK_HREF_UNSAFE, (character) => {
14
+ if (character === "(") return "%28";
15
+ if (character === ")") return "%29";
16
+ return encodeURIComponent(character);
17
+ });
20
18
  }
21
19
  function normalizeDescriptions(value) {
22
- return (Array.isArray(value) ? value : value ? [value] : []).filter((description) => description.trim()).map(normalizeInlineText);
20
+ return (Array.isArray(value) ? value : value ? [value] : []).filter((description) => description.trim()).map(normalizeInlineText);
23
21
  }
24
22
  function normalizePreambleBlocks(value) {
25
- return (Array.isArray(value) ? value : value ? [value] : []).filter((block) => block.trim()).map((block) => block.trim().replace(RE_PREAMBLE_ATX_HEADING, "$1\\$2"));
23
+ return (Array.isArray(value) ? value : value ? [value] : []).filter((block) => block.trim()).map((block) => block.trim().replace(RE_PREAMBLE_ATX_HEADING, "$1\\$2"));
26
24
  }
27
25
  function normalizeLink(link, descriptionPrefixes = []) {
28
- const descriptions = [...descriptionPrefixes, link.description].filter((value) => Boolean(value?.trim())).map(normalizeInlineText);
29
- const description = descriptions.join("; ");
30
- return `- [${normalizeLinkTitle(link.title)}](${normalizeLinkHref(link.href)})${description ? `: ${description}` : ""}`;
26
+ const descriptions = [...descriptionPrefixes, link.description].filter((value) => Boolean(value?.trim())).map(normalizeInlineText);
27
+ const description = descriptions.join("; ");
28
+ return `- [${normalizeLinkTitle(link.title)}](${normalizeLinkHref(link.href)})${description ? `: ${description}` : ""}`;
31
29
  }
32
30
  function normalizeSection(section) {
33
- const parts = [`## ${escapeMarkdownHtml(normalizeInlineText(section.title))}`];
34
- if (section.links?.length)
35
- parts.push("", ...section.links.map((link) => normalizeLink(link)));
36
- return parts.join("\n");
31
+ const parts = [`## ${escapeMarkdownHtml(normalizeInlineText(section.title))}`];
32
+ if (section.links?.length) parts.push("", ...section.links.map((link) => normalizeLink(link)));
33
+ return parts.join("\n");
37
34
  }
38
35
  function normalizePreamble(config) {
39
- const parts = [];
40
- if (config.notes) {
41
- const notes = normalizePreambleBlocks(config.notes);
42
- if (notes.length)
43
- parts.push(["**Notes:**", ...notes].join("\n\n"));
44
- }
45
- for (const section of config.sections?.filter((section2) => !section2.optional) ?? []) {
46
- if (!section.description)
47
- continue;
48
- const descriptions = normalizePreambleBlocks(section.description);
49
- if (descriptions.length)
50
- parts.push([`**${escapeMarkdownHtml(normalizeInlineText(section.title))}:**`, ...descriptions].join("\n\n"));
51
- }
52
- return parts;
36
+ const parts = [];
37
+ if (config.notes) {
38
+ const notes = normalizePreambleBlocks(config.notes);
39
+ if (notes.length) parts.push(["**Notes:**", ...notes].join("\n\n"));
40
+ }
41
+ for (const section of config.sections?.filter((section) => !section.optional) ?? []) {
42
+ if (!section.description) continue;
43
+ const descriptions = normalizePreambleBlocks(section.description);
44
+ if (descriptions.length) parts.push([`**${escapeMarkdownHtml(normalizeInlineText(section.title))}:**`, ...descriptions].join("\n\n"));
45
+ }
46
+ return parts;
53
47
  }
54
48
  function normalizeOptionalSections(sections) {
55
- const links = sections.flatMap(
56
- (section) => section.links?.map((link) => normalizeLink(link, [section.title, ...normalizeDescriptions(section.description)])) ?? []
57
- );
58
- if (!links.length)
59
- return void 0;
60
- return ["## Optional", "", ...links].join("\n");
49
+ const links = sections.flatMap((section) => section.links?.map((link) => normalizeLink(link, [section.title, ...normalizeDescriptions(section.description)])) ?? []);
50
+ if (!links.length) return undefined;
51
+ return [
52
+ "## Optional",
53
+ "",
54
+ ...links
55
+ ].join("\n");
61
56
  }
62
57
  function normalizeRequiredSections(sections) {
63
- return sections.filter((section) => section.links?.length).map(normalizeSection);
58
+ return sections.filter((section) => section.links?.length).map(normalizeSection);
64
59
  }
65
60
  export function formatLlmsTxtPageLink(page) {
66
- const description = page.description?.trim().replace(RE_INLINE_WHITESPACE, " ");
67
- const normalizedTitle = page.title ? normalizeInlineText(page.title) : "";
68
- const title = normalizedTitle && normalizedTitle !== page.pathname ? normalizedTitle : page.pathname;
69
- const href = (page.href || page.pathname).trim();
70
- const truncatedDescription = description ? `${description.substring(0, 160)}${description.length > 160 ? "..." : ""}` : void 0;
71
- return normalizeLink({ title, href, description: truncatedDescription ? escapeMarkdownHtml(truncatedDescription) : void 0 });
61
+ const description = page.description?.trim().replace(RE_INLINE_WHITESPACE, " ");
62
+ const normalizedTitle = page.title ? normalizeInlineText(page.title) : "";
63
+ const title = normalizedTitle && normalizedTitle !== page.pathname ? normalizedTitle : page.pathname;
64
+ const href = (page.href || page.pathname).trim();
65
+ const truncatedDescription = description ? `${description.substring(0, 160)}${description.length > 160 ? "..." : ""}` : undefined;
66
+ return normalizeLink({
67
+ title,
68
+ href,
69
+ description: truncatedDescription ? escapeMarkdownHtml(truncatedDescription) : undefined
70
+ });
72
71
  }
72
+ /**
73
+ * Normalize llms.txt structured configuration to the llmstxt.org Markdown format.
74
+ * Preamble prose must appear before the first H2; every H2 body is a file list.
75
+ */
73
76
  export function normalizeLlmsTxtConfig(config) {
74
- const required = config.sections?.filter((section) => !section.optional) ?? [];
75
- const optional = config.sections?.filter((section) => section.optional) ?? [];
76
- const parts = [
77
- ...normalizePreamble(config),
78
- ...normalizeRequiredSections(required)
79
- ];
80
- const optionalSection = normalizeOptionalSections(optional);
81
- if (optionalSection)
82
- parts.push(optionalSection);
83
- return parts.join("\n\n");
77
+ const required = config.sections?.filter((section) => !section.optional) ?? [];
78
+ const optional = config.sections?.filter((section) => section.optional) ?? [];
79
+ const parts = [...normalizePreamble(config), ...normalizeRequiredSections(required)];
80
+ const optionalSection = normalizeOptionalSections(optional);
81
+ if (optionalSection) parts.push(optionalSection);
82
+ return parts.join("\n\n");
84
83
  }
@@ -3,23 +3,26 @@ import { formatLlmsTxtPageLink } from "./llms-txt-format.js";
3
3
  import { computeLocaleAlternates, localePath } from "./server/utils/i18n.js";
4
4
  export { resolveLocaleFromRoute } from "./server/utils/i18n.js";
5
5
  export function formatAvailableLanguagesSection(i18n, pageCounts, resolveHref = (pathname) => pathname, routeContext = {}) {
6
- const lines = ["## Available Languages on Website", ""];
7
- const rootAlternates = new Map(computeLocaleAlternates("/", i18n, routeContext).map((alternate) => [alternate.code, alternate]));
8
- for (const locale of i18n.locales) {
9
- const isDefault = locale.code === i18n.defaultLocale;
10
- const alternate = rootAlternates.get(locale.code);
11
- const prefix = alternate?.path ?? localePath("/", locale.code, i18n, routeContext);
12
- const resolvedPath = resolveHref(prefix);
13
- const href = alternate ? resolveLocaleAlternateUrl({ ...alternate, path: resolvedPath }, (candidate) => candidate) : resolvedPath;
14
- const count = pageCounts.get(locale.code) ?? 0;
15
- const display = locale.nativeName ? `${locale.nativeName} (${locale.code})` : locale.name ? `${locale.name} (${locale.code})` : locale.code;
16
- const suffix = isDefault ? "content included below" : "visit this language for content";
17
- lines.push(formatLlmsTxtPageLink({
18
- pathname: href,
19
- title: display,
20
- href,
21
- description: `${count} pages; ${suffix}.`
22
- }));
23
- }
24
- return lines;
6
+ const lines = ["## Available Languages on Website", ""];
7
+ const rootAlternates = new Map(computeLocaleAlternates("/", i18n, routeContext).map((alternate) => [alternate.code, alternate]));
8
+ for (const locale of i18n.locales) {
9
+ const isDefault = locale.code === i18n.defaultLocale;
10
+ const alternate = rootAlternates.get(locale.code);
11
+ const prefix = alternate?.path ?? localePath("/", locale.code, i18n, routeContext);
12
+ const resolvedPath = resolveHref(prefix);
13
+ const href = alternate ? resolveLocaleAlternateUrl({
14
+ ...alternate,
15
+ path: resolvedPath
16
+ }, (candidate) => candidate) : resolvedPath;
17
+ const count = pageCounts.get(locale.code) ?? 0;
18
+ const display = locale.nativeName ? `${locale.nativeName} (${locale.code})` : locale.name ? `${locale.name} (${locale.code})` : locale.code;
19
+ const suffix = isDefault ? "content included below" : "visit this language for content";
20
+ lines.push(formatLlmsTxtPageLink({
21
+ pathname: href,
22
+ title: display,
23
+ href,
24
+ description: `${count} pages; ${suffix}.`
25
+ }));
26
+ }
27
+ return lines;
25
28
  }