nuxt-ai-ready 2.5.1 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +2 -0
- package/dist/module.json +1 -1
- package/dist/runtime/server/db/drizzle/queries.js +0 -1
- package/dist/runtime/server/db/queries.d.ts +2 -0
- package/dist/runtime/server/db/queries.js +6 -1
- package/dist/runtime/server/db/seed.d.ts +2 -2
- package/dist/runtime/server/routes/__ai-ready/reindex.post.js +2 -0
- package/dist/runtime/server/utils/batchIndex.js +4 -2
- package/dist/runtime/server/utils/checkStale.d.ts +1 -1
- package/dist/runtime/server/utils/checkStale.js +1 -1
- package/dist/runtime/server/utils/indexPage.d.ts +8 -1
- package/dist/runtime/server/utils/indexPage.js +13 -5
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -320,6 +320,8 @@ const main = defineCommand({
|
|
|
320
320
|
}
|
|
321
321
|
} else if (res.skipped) {
|
|
322
322
|
consola.info(`Skipped: ${colors.yellow(res.route)} (still fresh)`);
|
|
323
|
+
} else if (res.gone) {
|
|
324
|
+
consola.success(`Removed: ${colors.green(res.route)} (HTTP 410)`);
|
|
323
325
|
} else {
|
|
324
326
|
throw new Error(`Failed to reindex ${res.route ?? args.route}${res.error ? `: ${res.error}` : ""}`);
|
|
325
327
|
}
|
package/dist/module.json
CHANGED
|
@@ -706,7 +706,6 @@ export async function seedRoutes(event, routes, options = {}) {
|
|
|
706
706
|
indexed = CASE WHEN ai_ready_pages.is_error = 1 THEN 0 ELSE ai_ready_pages.indexed END
|
|
707
707
|
WHERE ai_ready_pages.last_seen_at IS NULL
|
|
708
708
|
OR ai_ready_pages.last_seen_at < excluded.last_seen_at - ${refreshWindowMs}
|
|
709
|
-
OR ai_ready_pages.is_error = 1
|
|
710
709
|
OR ai_ready_pages.locale IS DISTINCT FROM excluded.locale
|
|
711
710
|
`,
|
|
712
711
|
params
|
|
@@ -147,6 +147,8 @@ export declare function seedRoutes(event: H3Event | undefined, routes: Array<str
|
|
|
147
147
|
locale?: string;
|
|
148
148
|
url?: string;
|
|
149
149
|
}>, options?: SeedRoutesOptions): Promise<number>;
|
|
150
|
+
/** Remove a page after its route returns HTTP 410. */
|
|
151
|
+
export declare function prunePage(event: H3Event | undefined, route: string): Promise<void>;
|
|
150
152
|
/**
|
|
151
153
|
* Prune routes not seen in sitemap for longer than threshold
|
|
152
154
|
* Only prunes routes with source='runtime' (never prerendered pages)
|
|
@@ -403,7 +403,6 @@ export async function seedRoutes(event, routes, options = {}) {
|
|
|
403
403
|
indexed = CASE WHEN ai_ready_pages.is_error = 1 THEN 0 ELSE ai_ready_pages.indexed END
|
|
404
404
|
WHERE ai_ready_pages.last_seen_at IS NULL
|
|
405
405
|
OR ai_ready_pages.last_seen_at < excluded.last_seen_at - ${refreshWindowMs}
|
|
406
|
-
OR ai_ready_pages.is_error = 1
|
|
407
406
|
OR ai_ready_pages.locale IS DISTINCT FROM excluded.locale
|
|
408
407
|
`,
|
|
409
408
|
params
|
|
@@ -412,6 +411,12 @@ export async function seedRoutes(event, routes, options = {}) {
|
|
|
412
411
|
await db.batch(stmts);
|
|
413
412
|
return byRoute.size;
|
|
414
413
|
}
|
|
414
|
+
export async function prunePage(event, route) {
|
|
415
|
+
const db = await getDb(event);
|
|
416
|
+
if (!db)
|
|
417
|
+
return;
|
|
418
|
+
await db.exec("DELETE FROM ai_ready_pages WHERE route = ?", [normalizeRoute(route)]);
|
|
419
|
+
}
|
|
415
420
|
export async function pruneStaleRoutes(event, staleThresholdSeconds, protectedSince, refreshWindowMs = SEED_REFRESH_WINDOW_MS) {
|
|
416
421
|
const db = await getDb(event);
|
|
417
422
|
if (!db)
|
|
@@ -24,8 +24,8 @@ export declare const SEED_REFRESH_WINDOW_MS: number;
|
|
|
24
24
|
export declare function resolveSeedRefreshWindowMs(pruneTtlSeconds: number): number;
|
|
25
25
|
export interface SeedRoutesOptions {
|
|
26
26
|
/**
|
|
27
|
-
* An existing row is rewritten
|
|
28
|
-
*
|
|
27
|
+
* An existing row is rewritten when its `last_seen_at` is older than this
|
|
28
|
+
* or its locale changed. Error rows retry after this interval.
|
|
29
29
|
* @default SEED_REFRESH_WINDOW_MS
|
|
30
30
|
*/
|
|
31
31
|
refreshWindowMs?: number;
|
|
@@ -10,6 +10,8 @@ export default eventHandler(async (event) => {
|
|
|
10
10
|
}
|
|
11
11
|
const force = query.force !== "false" && query.force !== "0";
|
|
12
12
|
const result = await indexPageByRoute(route, event, { force });
|
|
13
|
+
if (result.gone)
|
|
14
|
+
return { route, indexed: false, gone: true };
|
|
13
15
|
if (!result.success) {
|
|
14
16
|
setResponseStatus(event, 502);
|
|
15
17
|
return { route, indexed: false, error: result.error ?? `Failed to index ${route}` };
|
|
@@ -36,12 +36,14 @@ export async function batchIndexPages(event, options = {}) {
|
|
|
36
36
|
markFailedAsError: true,
|
|
37
37
|
force: true
|
|
38
38
|
});
|
|
39
|
-
return { route: page.route,
|
|
39
|
+
return { route: page.route, result };
|
|
40
40
|
})
|
|
41
41
|
);
|
|
42
42
|
for (const result of results) {
|
|
43
43
|
processed++;
|
|
44
|
-
if (result.
|
|
44
|
+
if (result.result.gone) {
|
|
45
|
+
logger.debug(`[batchIndex] Pruned gone route: ${result.route}`);
|
|
46
|
+
} else if (result.result.success) {
|
|
45
47
|
indexed++;
|
|
46
48
|
logger.debug(`[batchIndex] Indexed: ${result.route}`);
|
|
47
49
|
} else {
|
|
@@ -21,7 +21,7 @@ export declare const STALE_CHECK_INTERVAL_MS: number;
|
|
|
21
21
|
/**
|
|
22
22
|
* Check if data is stale and handle restore/mark-pending
|
|
23
23
|
* Called at start of cron - handles:
|
|
24
|
-
* 1. Empty DB → restore from dump
|
|
24
|
+
* 1. Empty DB with a different build ID → restore from dump
|
|
25
25
|
* 2. Build ID changed → compare hashes, only mark changed pages pending, add new pages from dump
|
|
26
26
|
* Skips HTTP fetch if checked within 5 minutes and DB is populated
|
|
27
27
|
*/
|
|
@@ -78,7 +78,7 @@ export async function checkAndHandleStale(event) {
|
|
|
78
78
|
logger.info("[stale-check] No build metadata found, skipping stale check");
|
|
79
79
|
return { action: "none", dbCount, reason: "no_dump_metadata" };
|
|
80
80
|
}
|
|
81
|
-
if (dbCount === 0) {
|
|
81
|
+
if (dbCount === 0 && storedBuildId !== meta.buildId) {
|
|
82
82
|
if (debug)
|
|
83
83
|
logger.info("[stale-check] DB empty, restoring from dump...");
|
|
84
84
|
const rows = await fetchDump(event);
|
|
@@ -9,7 +9,7 @@ export interface IndexPageOptions {
|
|
|
9
9
|
/** Mark failed fetches as errors in DB to prevent retry loops */
|
|
10
10
|
markFailedAsError?: boolean;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
interface IndexedPageResult {
|
|
13
13
|
success: boolean;
|
|
14
14
|
/** True if page was already fresh and skipped */
|
|
15
15
|
skipped?: boolean;
|
|
@@ -31,6 +31,12 @@ export interface IndexPageResult {
|
|
|
31
31
|
/** Error message if failed */
|
|
32
32
|
error?: string;
|
|
33
33
|
}
|
|
34
|
+
export type IndexPageResult = IndexedPageResult & ({
|
|
35
|
+
success: false;
|
|
36
|
+
gone: true;
|
|
37
|
+
} | {
|
|
38
|
+
gone?: never;
|
|
39
|
+
});
|
|
34
40
|
/**
|
|
35
41
|
* Manually index a page's HTML content into database
|
|
36
42
|
* Use this from custom plugins or API routes to trigger indexing
|
|
@@ -41,3 +47,4 @@ export declare function indexPage(route: string, html: string, options?: IndexPa
|
|
|
41
47
|
* Convenience wrapper around indexPage that handles fetching
|
|
42
48
|
*/
|
|
43
49
|
export declare function indexPageByRoute(route: string, event: H3Event | undefined, options?: IndexPageOptions): Promise<IndexPageResult>;
|
|
50
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fetchWithEvent, useNitroApp, useRuntimeConfig } from "#nuxtseo/nitro";
|
|
2
|
-
import { getPageIndexState, upsertPage } from "../db/queries.js";
|
|
2
|
+
import { getPageIndexState, prunePage, upsertPage } from "../db/queries.js";
|
|
3
3
|
import { computeContentHash } from "../db/shared.js";
|
|
4
4
|
import { logger } from "../logger.js";
|
|
5
5
|
import { convertHtmlToMarkdown } from "../utils.js";
|
|
@@ -79,18 +79,26 @@ export async function indexPage(route, html, options = {}, event) {
|
|
|
79
79
|
}
|
|
80
80
|
export async function indexPageByRoute(route, event, options = {}) {
|
|
81
81
|
logger.debug(`[indexPageByRoute] Fetching HTML for ${route} (timeout: 10000ms)`);
|
|
82
|
-
const
|
|
82
|
+
const fetched = await (event ? fetchWithEvent(event, route, {
|
|
83
83
|
headers: { accept: "text/html", [INTERNAL_HEADER]: "1" },
|
|
84
84
|
timeout: 1e4
|
|
85
85
|
}) : globalThis.$fetch(route, {
|
|
86
86
|
headers: { accept: "text/html", [INTERNAL_HEADER]: "1" },
|
|
87
87
|
timeout: 1e4
|
|
88
88
|
// 10s timeout per page (must fit within CF worker limit)
|
|
89
|
-
})).catch((err) => {
|
|
89
|
+
})).then((html2) => ({ _tag: "Html", html: html2 })).catch((err) => {
|
|
90
|
+
const status = err.status ?? err.statusCode ?? err.response?.status;
|
|
91
|
+
if (status === 410)
|
|
92
|
+
return { _tag: "Gone" };
|
|
90
93
|
logger.warn(`[indexPageByRoute] Failed to fetch ${route}:`, err.message);
|
|
91
|
-
return
|
|
94
|
+
return { _tag: "Failed" };
|
|
92
95
|
});
|
|
93
|
-
if (
|
|
96
|
+
if (fetched._tag === "Gone") {
|
|
97
|
+
await prunePage(event, route);
|
|
98
|
+
return { success: false, gone: true };
|
|
99
|
+
}
|
|
100
|
+
const html = fetched._tag === "Html" ? fetched.html : null;
|
|
101
|
+
if (typeof html === "string" && html) {
|
|
94
102
|
logger.debug(`[indexPageByRoute] Fetched ${route} (${html.length} bytes)`);
|
|
95
103
|
}
|
|
96
104
|
if (!html || typeof html !== "string") {
|