nuxt-ai-ready 0.3.3 → 0.3.5
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/module.json +1 -1
- package/dist/module.mjs +4 -0
- package/dist/runtime/server/mcp/prod/resources/pages-chunks.js +9 -6
- package/dist/runtime/server/mcp/prod/resources/pages.js +9 -6
- package/dist/runtime/server/mcp/prod/tools/list-pages.js +8 -5
- package/dist/runtime/server/middleware/mdream.js +5 -2
- package/dist/runtime/server/utils.js +7 -3
- package/package.json +2 -2
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -155,6 +155,10 @@ function setupPrerenderHandler(llmsTxtConfig, timestampsConfig) {
|
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
nitro.hooks.hook("prerender:generate", async (route) => {
|
|
158
|
+
if (route.route === "/sitemap.xml" && contentHashManager) {
|
|
159
|
+
await contentHashManager.saveManifest();
|
|
160
|
+
logger.debug("Saved content hash manifest before sitemap generation");
|
|
161
|
+
}
|
|
158
162
|
if (!route.fileName?.endsWith(".md")) {
|
|
159
163
|
return;
|
|
160
164
|
}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
+
import { getNitroOrigin } from "#site-config/server/composables";
|
|
2
|
+
import { useEvent } from "nitropack/runtime";
|
|
1
3
|
export default {
|
|
2
4
|
uri: "resource://nuxt-ai-ready/pages-chunks",
|
|
3
5
|
name: "All Page Chunks",
|
|
4
6
|
description: "Chunk-level content (id, route, content) in TOON format for RAG/embeddings. Join with pages resource using id field - match chunk.id with page.chunkIds[] to get title, description, headings. TOON is token-efficient JSON encoding (see https://toonformat.dev)",
|
|
5
7
|
metadata: {
|
|
6
|
-
mimeType: "text/
|
|
8
|
+
mimeType: "text/toon"
|
|
7
9
|
},
|
|
8
10
|
cache: "1h",
|
|
9
11
|
async handler(uri) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const event = useEvent();
|
|
13
|
+
const nitroOrigin = getNitroOrigin(event);
|
|
14
|
+
const text = await $fetch(`/llms-full.toon`, {
|
|
15
|
+
baseURL: nitroOrigin
|
|
16
|
+
});
|
|
14
17
|
return {
|
|
15
18
|
contents: [{
|
|
16
19
|
uri: uri.toString(),
|
|
17
|
-
mimeType: "text/
|
|
20
|
+
mimeType: "text/toon",
|
|
18
21
|
text
|
|
19
22
|
}]
|
|
20
23
|
};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
+
import { getNitroOrigin } from "#site-config/server/composables";
|
|
2
|
+
import { useEvent } from "nitropack/runtime";
|
|
1
3
|
export default {
|
|
2
4
|
uri: "resource://nuxt-ai-ready/pages",
|
|
3
5
|
name: "All Pages",
|
|
4
6
|
description: "Page-level metadata (route, title, description, markdown, headings, chunkIds) in TOON format. Each page includes chunkIds[] array to join with pages-chunks resource for chunk-level content. TOON is token-efficient JSON encoding (see https://toonformat.dev)",
|
|
5
7
|
metadata: {
|
|
6
|
-
mimeType: "text/
|
|
8
|
+
mimeType: "text/toon"
|
|
7
9
|
},
|
|
8
10
|
cache: "1h",
|
|
9
11
|
async handler(uri) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const event = useEvent();
|
|
13
|
+
const nitroOrigin = getNitroOrigin(event);
|
|
14
|
+
const text = await $fetch(`/llms.toon`, {
|
|
15
|
+
baseURL: nitroOrigin
|
|
16
|
+
});
|
|
14
17
|
return {
|
|
15
18
|
contents: [{
|
|
16
19
|
uri: uri.toString(),
|
|
17
|
-
mimeType: "text/
|
|
20
|
+
mimeType: "text/toon",
|
|
18
21
|
text
|
|
19
22
|
}]
|
|
20
23
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getNitroOrigin } from "#site-config/server/composables";
|
|
2
|
+
import { useEvent } from "nitropack/runtime";
|
|
1
3
|
import { z } from "zod";
|
|
2
4
|
import { toonResult } from "../../utils.js";
|
|
3
5
|
const schema = {
|
|
@@ -9,10 +11,11 @@ export default {
|
|
|
9
11
|
inputSchema: schema,
|
|
10
12
|
cache: "1h",
|
|
11
13
|
async handler({ mode }) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const event = useEvent();
|
|
15
|
+
const nitroOrigin = getNitroOrigin(event);
|
|
16
|
+
const text = await $fetch(mode === "chunks" ? "/llms-full.toon" : "/llms.toon", {
|
|
17
|
+
baseURL: nitroOrigin
|
|
18
|
+
});
|
|
19
|
+
return toonResult(text);
|
|
17
20
|
}
|
|
18
21
|
};
|
|
@@ -6,6 +6,9 @@ import { withMinimalPreset } from "mdream/preset/minimal";
|
|
|
6
6
|
import { useNitroApp, useRuntimeConfig } from "nitropack/runtime";
|
|
7
7
|
import { logger } from "../logger.js";
|
|
8
8
|
import { convertHtmlToMarkdownChunks } from "../utils.js";
|
|
9
|
+
function normalizeWhitespace(text) {
|
|
10
|
+
return text.replace(/\u00A0/g, " ");
|
|
11
|
+
}
|
|
9
12
|
function shouldServeMarkdown(event) {
|
|
10
13
|
const accept = getHeader(event, "accept") || "";
|
|
11
14
|
const secFetchDest = getHeader(event, "sec-fetch-dest") || "";
|
|
@@ -58,8 +61,8 @@ async function convertHtmlToMarkdown(html, url, config, route, event) {
|
|
|
58
61
|
event
|
|
59
62
|
};
|
|
60
63
|
await nitroApp.hooks.callHook("ai-ready:markdown", context);
|
|
61
|
-
markdown = context.markdown;
|
|
62
|
-
return { markdown, title, description, headings };
|
|
64
|
+
markdown = normalizeWhitespace(context.markdown);
|
|
65
|
+
return { markdown, title: normalizeWhitespace(title), description: normalizeWhitespace(description), headings };
|
|
63
66
|
}
|
|
64
67
|
export default defineEventHandler(async (event) => {
|
|
65
68
|
let path = event.path;
|
|
@@ -11,6 +11,9 @@ function stripFrontmatter(text) {
|
|
|
11
11
|
return text;
|
|
12
12
|
return text.slice(endIdx + 4).trimStart();
|
|
13
13
|
}
|
|
14
|
+
function normalizeWhitespace(text) {
|
|
15
|
+
return text.replace(/\u00A0/g, " ");
|
|
16
|
+
}
|
|
14
17
|
export function convertHtmlToMarkdownChunks(html, url, mdreamOptions) {
|
|
15
18
|
let title = "";
|
|
16
19
|
let description = "";
|
|
@@ -39,7 +42,7 @@ export function convertHtmlToMarkdownChunks(html, url, mdreamOptions) {
|
|
|
39
42
|
options.plugins = [extractPlugin, ...options.plugins || []];
|
|
40
43
|
}
|
|
41
44
|
const rawMarkdown = htmlToMarkdown(html, options);
|
|
42
|
-
const markdown = stripFrontmatter(rawMarkdown);
|
|
45
|
+
const markdown = normalizeWhitespace(stripFrontmatter(rawMarkdown));
|
|
43
46
|
const rawChunks = htmlToMarkdownSplitChunks(html, {
|
|
44
47
|
...options,
|
|
45
48
|
headersToSplitOn: [TagIdMap.h1, TagIdMap.h2, TagIdMap.h3],
|
|
@@ -51,6 +54,7 @@ export function convertHtmlToMarkdownChunks(html, url, mdreamOptions) {
|
|
|
51
54
|
}
|
|
52
55
|
});
|
|
53
56
|
const chunks = rawChunks.filter((chunk, idx) => {
|
|
57
|
+
chunk.content = normalizeWhitespace(chunk.content);
|
|
54
58
|
if (idx === 0 && chunk.content.startsWith("---\n")) {
|
|
55
59
|
const endIdx = chunk.content.indexOf("\n---", 4);
|
|
56
60
|
if (endIdx !== -1) {
|
|
@@ -72,8 +76,8 @@ export function convertHtmlToMarkdownChunks(html, url, mdreamOptions) {
|
|
|
72
76
|
return {
|
|
73
77
|
markdown,
|
|
74
78
|
chunks,
|
|
75
|
-
title,
|
|
76
|
-
description,
|
|
79
|
+
title: normalizeWhitespace(title),
|
|
80
|
+
description: normalizeWhitespace(description),
|
|
77
81
|
headings,
|
|
78
82
|
...updatedAt && { updatedAt }
|
|
79
83
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-ai-ready",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.5",
|
|
5
5
|
"description": "Best practice AI & LLM discoverability for Nuxt sites.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@toon-format/toon": "^2.1.0",
|
|
37
37
|
"consola": "^3.4.2",
|
|
38
38
|
"defu": "^6.1.4",
|
|
39
|
-
"mdream": "^0.15.
|
|
39
|
+
"mdream": "^0.15.3",
|
|
40
40
|
"minimatch": "^10.1.1",
|
|
41
41
|
"nuxt-site-config": "^3.2.11",
|
|
42
42
|
"pathe": "^2.0.3",
|