nuxt-ai-ready 3.5.0 → 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.
- package/dist/chunks/agent-skills.mjs +5 -3
- package/dist/chunks/prerender.mjs +48 -24
- package/dist/cli.mjs +5 -5
- package/dist/module.d.mts +4 -0
- package/dist/module.json +2 -2
- package/dist/module.mjs +5 -3
- package/dist/runtime/ai-terms.d.ts +76 -0
- package/dist/runtime/ai-terms.js +1 -0
- package/dist/runtime/app/plugins/md-alternate.server.js +11 -3
- package/dist/runtime/llms-txt-utils.js +7 -9
- package/dist/runtime/server/db/schema/postgres.d.ts +8 -0
- package/dist/runtime/server/db/schema/sqlite.d.ts +8 -0
- package/dist/runtime/server/middleware/markdown.js +13 -175
- package/dist/runtime/server/middleware/render-markdown.d.ts +2 -0
- package/dist/runtime/server/middleware/render-markdown.js +163 -0
- package/dist/runtime/server/plugins/ai-terms.d.ts +2 -0
- package/dist/runtime/server/plugins/ai-terms.js +11 -0
- package/dist/runtime/server/plugins/markdown-negotiation.js +11 -1
- package/dist/runtime/server/routes/ai-terms.d.ts +2 -0
- package/dist/runtime/server/routes/ai-terms.js +22 -0
- package/dist/runtime/server/routes/api-catalog.js +6 -2
- package/dist/runtime/server/routes/llms.txt.get.js +3 -0
- package/dist/runtime/server/utils/auth.d.ts +1 -3
- package/dist/runtime/server/utils/auth.js +55 -25
- package/dist/runtime/server/utils/cloudflare-prerendered.d.ts +1 -1
- package/dist/runtime/server/utils/cloudflare-prerendered.js +17 -15
- package/dist/runtime/server/utils/link-header.d.ts +4 -0
- package/dist/runtime/server/utils/link-header.js +6 -2
- package/dist/runtime/server/utils/negotiation-decision.d.ts +4 -0
- package/dist/runtime/server/utils/negotiation-decision.js +8 -1
- package/dist/runtime/server/utils/negotiation-response.d.ts +3 -1
- package/dist/runtime/server/utils/negotiation-response.js +31 -9
- package/dist/runtime/sync-secret.d.ts +1 -0
- package/dist/runtime/sync-secret.js +2 -1
- package/dist/runtime/types.d.ts +12 -0
- package/dist/shared/{nuxt-ai-ready.BaNK8yfw.mjs → nuxt-ai-ready.Bzx0dNWj.mjs} +324 -36
- package/dist/shared/{nuxt-ai-ready.B3hAuOLQ.mjs → nuxt-ai-ready.DCd-1s1G.mjs} +1 -1
- package/dist/types.d.mts +2 -0
- package/package.json +36 -36
- package/skills/nuxt-ai-ready/SKILL.md +52 -96
- package/dist/cli.d.mts +0 -1
|
@@ -15,6 +15,7 @@ export interface NegotiationInput {
|
|
|
15
15
|
routeRule: NegotiationRouteRule;
|
|
16
16
|
policy: ContentNegotiationPolicy;
|
|
17
17
|
botNegotiation?: boolean;
|
|
18
|
+
hasPrerenderedMarkdown?: (path: string) => boolean;
|
|
18
19
|
/**
|
|
19
20
|
* Routes that already serve a Markdown file verbatim, such as an agent skill
|
|
20
21
|
* alias. They are answered by their own handler, never rendered.
|
|
@@ -31,6 +32,7 @@ export type NegotiationDecision = {
|
|
|
31
32
|
_tag: 'html';
|
|
32
33
|
path: string;
|
|
33
34
|
negotiation: ContentNegotiationResolution;
|
|
35
|
+
markdownAvailable?: false;
|
|
34
36
|
} | {
|
|
35
37
|
_tag: 'redirect';
|
|
36
38
|
path: string;
|
|
@@ -38,6 +40,8 @@ export type NegotiationDecision = {
|
|
|
38
40
|
} | {
|
|
39
41
|
_tag: 'render';
|
|
40
42
|
path: string;
|
|
43
|
+
} | {
|
|
44
|
+
_tag: 'missing-markdown';
|
|
41
45
|
};
|
|
42
46
|
/**
|
|
43
47
|
* Decide how one request maps to an HTML or Markdown representation.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toMarkdownPath } from "../../markdown-path.js";
|
|
1
2
|
import { getContentNegotiationVary, resolveContentNegotiation } from "./content-negotiation.js";
|
|
2
3
|
import { getRequestRenderInfo } from "./markdown-request.js";
|
|
3
4
|
export const INTERNAL_HEADER = "x-ai-ready-internal";
|
|
@@ -21,8 +22,14 @@ export function resolveNegotiationDecision(input) {
|
|
|
21
22
|
if ("notAcceptable" in renderInfo)
|
|
22
23
|
return { _tag: "not-acceptable", vary: getContentNegotiationVary(input.botNegotiation) };
|
|
23
24
|
if (renderInfo.isExplicit) {
|
|
24
|
-
|
|
25
|
+
if (stage === "early")
|
|
26
|
+
return { _tag: "skip", reason: "deferred" };
|
|
27
|
+
if (input.hasPrerenderedMarkdown)
|
|
28
|
+
return input.hasPrerenderedMarkdown(path) ? { _tag: "skip", reason: "deferred" } : { _tag: "missing-markdown" };
|
|
29
|
+
return { _tag: "render", path: renderInfo.path };
|
|
25
30
|
}
|
|
31
|
+
if (input.hasPrerenderedMarkdown?.(toMarkdownPath(renderInfo.path)) === false)
|
|
32
|
+
return { _tag: "html", path: renderInfo.path, negotiation, markdownAvailable: false };
|
|
26
33
|
if (renderInfo.negotiation === "markdown")
|
|
27
34
|
return { _tag: "redirect", path: renderInfo.path, vary: getContentNegotiationVary(input.botNegotiation) };
|
|
28
35
|
return { _tag: "html", path: renderInfo.path, negotiation };
|
|
@@ -7,7 +7,9 @@ import { sendRedirect } from '#nuxtseo/h3';
|
|
|
7
7
|
export declare function agentSkillArtifactPaths(): ReadonlySet<string>;
|
|
8
8
|
export type LinkUrlResolver = (path: string) => string;
|
|
9
9
|
export interface NegotiationContext {
|
|
10
|
-
config: ModulePublicRuntimeConfig
|
|
10
|
+
config: ModulePublicRuntimeConfig & {
|
|
11
|
+
markdownAvailable?: false;
|
|
12
|
+
};
|
|
11
13
|
path: string;
|
|
12
14
|
resolvePath: LinkUrlResolver;
|
|
13
15
|
resolveUrl: LinkUrlResolver;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createNitroRouteRuleMatcher } from "nuxtseo-shared/server";
|
|
2
|
+
import { decodePath } from "ufo";
|
|
2
3
|
import { localAgentSkillArtifacts } from "#ai-ready-virtual/agent-skills.mjs";
|
|
4
|
+
import prerenderedMarkdownPaths from "#ai-ready-virtual/prerendered-markdown-paths.mjs";
|
|
3
5
|
import { appendHeader, createError, getHeader, getRequestHost, getRequestURL, getResponseHeader, sendRedirect, setHeader } from "#nuxtseo/h3";
|
|
4
6
|
import { useRuntimeConfig } from "#nuxtseo/nitro";
|
|
5
7
|
import * as siteConfigUtils from "#site-config/server/composables/utils";
|
|
@@ -81,7 +83,7 @@ export function setMarkdownHeaders(event, ctx, sourceHeaders) {
|
|
|
81
83
|
}
|
|
82
84
|
export async function ensureSiteConfig(event) {
|
|
83
85
|
if (!event.context._initedSiteConfig)
|
|
84
|
-
await initRequestSiteConfig(event, getRequestURL(event, { xForwardedHost: true, xForwardedProto: true }).origin,
|
|
86
|
+
await initRequestSiteConfig(event, getRequestURL(event, { xForwardedHost: true, xForwardedProto: true }).origin, getRouteRuleMatcher(useRuntimeConfig(event))(event.path));
|
|
85
87
|
}
|
|
86
88
|
export function buildNegotiationContext(event, path) {
|
|
87
89
|
const runtimeConfig = useRuntimeConfig(event);
|
|
@@ -98,17 +100,32 @@ export function buildNegotiationContext(event, path) {
|
|
|
98
100
|
const REQUEST_DECISION = Symbol("nuxt-ai-ready:negotiation");
|
|
99
101
|
let matcherCache;
|
|
100
102
|
function getRouteRuleMatcher(runtimeConfig) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
const key = JSON.stringify([runtimeConfig.app?.baseURL, runtimeConfig.nitro?.routeRules]);
|
|
104
|
+
if (matcherCache?.key !== key)
|
|
105
|
+
matcherCache = { key, match: createNitroRouteRuleMatcher(runtimeConfig) };
|
|
103
106
|
return matcherCache.match;
|
|
104
107
|
}
|
|
105
108
|
export function decideNegotiation(event, stage) {
|
|
106
|
-
const runtimeConfig = useRuntimeConfig(event);
|
|
107
|
-
const config = runtimeConfig["nuxt-ai-ready"];
|
|
108
109
|
const context = event.context;
|
|
109
110
|
const owner = event.node?.req ?? event.req ?? event;
|
|
110
111
|
let cached = context[REQUEST_DECISION];
|
|
112
|
+
let request;
|
|
113
|
+
if (!cached || cached.owner !== owner || cached.path !== event.path) {
|
|
114
|
+
request = toMarkdownRequest(event);
|
|
115
|
+
const eligibility = resolveNegotiationDecision({
|
|
116
|
+
stage: "middleware",
|
|
117
|
+
request,
|
|
118
|
+
routeRule: {},
|
|
119
|
+
policy: "disabled",
|
|
120
|
+
artifactPaths: agentSkillArtifactPaths()
|
|
121
|
+
});
|
|
122
|
+
if (eligibility._tag === "skip")
|
|
123
|
+
return eligibility;
|
|
124
|
+
}
|
|
125
|
+
const runtimeConfig = useRuntimeConfig(event);
|
|
126
|
+
const config = runtimeConfig["nuxt-ai-ready"];
|
|
111
127
|
if (!cached || cached.owner !== owner || cached.path !== event.path || cached.policy !== config.contentNegotiation || cached.botNegotiation !== config.botNegotiation) {
|
|
128
|
+
const markdownPaths = prerenderedMarkdownPaths;
|
|
112
129
|
cached = {
|
|
113
130
|
owner,
|
|
114
131
|
path: event.path,
|
|
@@ -116,19 +133,20 @@ export function decideNegotiation(event, stage) {
|
|
|
116
133
|
botNegotiation: config.botNegotiation,
|
|
117
134
|
decision: resolveNegotiationDecision({
|
|
118
135
|
stage: "middleware",
|
|
119
|
-
request: toMarkdownRequest(event),
|
|
136
|
+
request: request ?? toMarkdownRequest(event),
|
|
120
137
|
routeRule: getRouteRuleMatcher(runtimeConfig)(event.path),
|
|
121
138
|
policy: config.contentNegotiation,
|
|
122
139
|
botNegotiation: config.botNegotiation,
|
|
123
|
-
artifactPaths: agentSkillArtifactPaths()
|
|
140
|
+
artifactPaths: agentSkillArtifactPaths(),
|
|
141
|
+
hasPrerenderedMarkdown: markdownPaths && !import.meta.prerender ? (path) => markdownPaths.has(decodePath(toDeployedRoute(path, runtimeConfig.app.baseURL))) : void 0
|
|
124
142
|
})
|
|
125
143
|
};
|
|
126
144
|
context[REQUEST_DECISION] = cached;
|
|
127
145
|
}
|
|
128
|
-
return stage === "early" && cached.decision._tag === "render" ? { _tag: "skip", reason: "deferred" } : cached.decision;
|
|
146
|
+
return stage === "early" && (cached.decision._tag === "render" || cached.decision._tag === "missing-markdown") ? { _tag: "skip", reason: "deferred" } : cached.decision;
|
|
129
147
|
}
|
|
130
148
|
export async function applyNegotiation(event, decision) {
|
|
131
|
-
if (decision._tag === "skip" || decision._tag === "render")
|
|
149
|
+
if (decision._tag === "skip" || decision._tag === "render" || decision._tag === "missing-markdown")
|
|
132
150
|
return;
|
|
133
151
|
const context = event.context;
|
|
134
152
|
if (context[APPLIED_KEY])
|
|
@@ -148,6 +166,10 @@ export async function applyNegotiation(event, decision) {
|
|
|
148
166
|
if (decision._tag === "html") {
|
|
149
167
|
if (decision.negotiation._tag === "enabled")
|
|
150
168
|
appendHeader(event, "vary", decision.negotiation.vary);
|
|
169
|
+
if (decision.markdownAvailable === false) {
|
|
170
|
+
event.context.aiReadyMarkdownAvailable = false;
|
|
171
|
+
ctx.config = { ...ctx.config, markdownAvailable: false };
|
|
172
|
+
}
|
|
151
173
|
setStatusAwareHeader(event, ctx, "html");
|
|
152
174
|
return;
|
|
153
175
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const RUNTIME_SYNC_SECRET_PURPOSE = "nuxt-ai-ready:runtime-sync";
|
|
2
|
+
export declare const APPLICATION_SECRET_ERROR = "Set NUXT_APP_SECRET to a string with at least 32 characters. Generate one with openssl rand -base64 32.";
|
|
2
3
|
export declare const LEGACY_RUNTIME_SYNC_SECRET_WARNING = "runtimeSyncSecret and NUXT_AI_READY_RUNTIME_SYNC_SECRET are deprecated. Set NUXT_APP_SECRET. Refresh scheduler tokens with `nuxt-ai-ready token`.";
|
|
3
4
|
/** Nuxt deriveSecret's HKDF, for the CLI and event-bound Worker secrets. */
|
|
4
5
|
export declare function deriveRuntimeSyncSecret(root: unknown): Promise<string>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export const RUNTIME_SYNC_SECRET_PURPOSE = "nuxt-ai-ready:runtime-sync";
|
|
2
|
+
export const APPLICATION_SECRET_ERROR = "Set NUXT_APP_SECRET to a string with at least 32 characters. Generate one with openssl rand -base64 32.";
|
|
2
3
|
export const LEGACY_RUNTIME_SYNC_SECRET_WARNING = "runtimeSyncSecret and NUXT_AI_READY_RUNTIME_SYNC_SECRET are deprecated. Set NUXT_APP_SECRET. Refresh scheduler tokens with `nuxt-ai-ready token`.";
|
|
3
4
|
export async function deriveRuntimeSyncSecret(root) {
|
|
4
5
|
if (typeof root !== "string" || root.length < 32)
|
|
5
|
-
throw new Error(
|
|
6
|
+
throw new Error(APPLICATION_SECRET_ERROR);
|
|
6
7
|
const encoder = new TextEncoder();
|
|
7
8
|
const key = await crypto.subtle.importKey("raw", encoder.encode(root), "HKDF", false, ["deriveBits"]);
|
|
8
9
|
const bits = await crypto.subtle.deriveBits({
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { H3Event } from 'h3';
|
|
2
2
|
import type { MdreamOptions } from 'mdream';
|
|
3
|
+
import type { AiTermsConfig } from './ai-terms.js';
|
|
3
4
|
import type { SiteToolsConfig } from './site-tool-config.js';
|
|
4
5
|
export type ContentNegotiationPolicy = 'auto' | 'enabled' | 'disabled';
|
|
5
6
|
export interface ApiCatalogLinkTarget {
|
|
@@ -136,6 +137,11 @@ export interface ModuleOptions {
|
|
|
136
137
|
* @default Automatic per route
|
|
137
138
|
*/
|
|
138
139
|
contentNegotiation?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Generate page Markdown at build time and disable request-time conversion.
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
zeroRuntimeMarkdown?: boolean;
|
|
139
145
|
/**
|
|
140
146
|
* Offer Markdown to AI bots even when their Accept header prefers HTML.
|
|
141
147
|
* Requires cache variation on Accept, Sec-Fetch-Dest, and User-Agent.
|
|
@@ -150,6 +156,12 @@ export interface ModuleOptions {
|
|
|
150
156
|
* @default undefined
|
|
151
157
|
*/
|
|
152
158
|
apiCatalog?: false | ApiCatalogConfig;
|
|
159
|
+
/**
|
|
160
|
+
* Publish an explicit AI Terms 0.1 policy at `/.well-known/ai-terms`.
|
|
161
|
+
* Requires site.url. Publishing does not enforce access or collect payments.
|
|
162
|
+
* @default false
|
|
163
|
+
*/
|
|
164
|
+
aiTerms?: false | AiTermsConfig;
|
|
153
165
|
/**
|
|
154
166
|
* Read a page's Markdown from the installed content module instead of
|
|
155
167
|
* rendering the page and converting its HTML.
|