nuxt-ai-ready 0.7.0 → 0.7.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 (29) hide show
  1. package/dist/module.d.mts +2 -6
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +33 -23
  4. package/dist/runtime/mcp.d.ts +25 -0
  5. package/dist/runtime/mcp.js +5 -0
  6. package/dist/runtime/server/db/queries.d.ts +46 -0
  7. package/dist/runtime/server/db/queries.js +73 -0
  8. package/dist/runtime/server/db/schema-sql.d.ts +1 -1
  9. package/dist/runtime/server/db/schema-sql.js +19 -2
  10. package/dist/runtime/server/middleware/markdown.js +13 -1
  11. package/dist/runtime/server/routes/__ai-ready/cron.get.d.ts +5 -0
  12. package/dist/runtime/server/routes/__ai-ready/cron.get.js +3 -0
  13. package/dist/runtime/server/routes/__ai-ready/indexnow.post.js +4 -4
  14. package/dist/runtime/server/routes/__ai-ready/poll.post.js +2 -2
  15. package/dist/runtime/server/routes/__ai-ready/prune.post.js +2 -2
  16. package/dist/runtime/server/routes/__ai-ready/status.get.js +1 -1
  17. package/dist/runtime/server/routes/__ai-ready-debug.get.d.ts +25 -0
  18. package/dist/runtime/server/routes/__ai-ready-debug.get.js +45 -1
  19. package/dist/runtime/server/tasks/ai-ready-cron.d.ts +2 -0
  20. package/dist/runtime/server/tasks/ai-ready-cron.js +17 -0
  21. package/dist/runtime/server/utils/indexnow.d.ts +0 -5
  22. package/dist/runtime/server/utils/indexnow.js +2 -2
  23. package/dist/runtime/server/utils/runCron.d.ts +21 -0
  24. package/dist/runtime/server/utils/runCron.js +52 -0
  25. package/dist/runtime/types.d.ts +21 -39
  26. package/mcp.d.ts +4 -0
  27. package/package.json +7 -2
  28. package/dist/runtime/server/tasks/ai-ready-index.d.ts +0 -11
  29. package/dist/runtime/server/tasks/ai-ready-index.js +0 -39
package/dist/module.d.mts CHANGED
@@ -43,14 +43,10 @@ interface ModulePublicRuntimeConfig {
43
43
  enabled: boolean;
44
44
  ttl: number;
45
45
  batchSize: number;
46
- secret?: string;
47
46
  pruneTtl: number;
48
47
  };
49
- indexNow?: {
50
- enabled: boolean;
51
- key?: string;
52
- host?: string;
53
- };
48
+ runtimeSyncSecret?: string;
49
+ indexNowKey?: string;
54
50
  }
55
51
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
56
52
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "nuxt": ">=4.0.0"
5
5
  },
6
6
  "configKey": "aiReady",
7
- "version": "0.7.0",
7
+ "version": "0.7.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -541,16 +541,27 @@ const module$1 = defineNuxtModule({
541
541
  nuxt.hooks.hook("nitro:config", (nitroConfig) => {
542
542
  nitroConfig.experimental = nitroConfig.experimental || {};
543
543
  nitroConfig.experimental.asyncContext = true;
544
- const runtimeSyncEnabled2 = config.runtimeSync?.enabled ?? false;
545
- const cron = config.runtimeSync?.cron;
546
- if (runtimeSyncEnabled2 && cron) {
547
- nitroConfig.tasks = nitroConfig.tasks || {};
548
- nitroConfig.tasks["ai-ready:index"] = {
549
- handler: resolve("./runtime/server/tasks/ai-ready-index")
550
- };
551
- nitroConfig.scheduledTasks = nitroConfig.scheduledTasks || {};
552
- nitroConfig.scheduledTasks[cron] = nitroConfig.scheduledTasks[cron] || [];
553
- nitroConfig.scheduledTasks[cron].push("ai-ready:index");
544
+ if (config.cron) {
545
+ const cronSchedule = "* * * * *";
546
+ const isVercel = nitroConfig.preset === "vercel" || nitroConfig.preset === "vercel-edge";
547
+ if (isVercel) {
548
+ nitroConfig.vercel = nitroConfig.vercel || {};
549
+ nitroConfig.vercel.config = nitroConfig.vercel.config || {};
550
+ nitroConfig.vercel.config.crons = nitroConfig.vercel.config.crons || [];
551
+ nitroConfig.vercel.config.crons.push({
552
+ schedule: cronSchedule,
553
+ path: "/__ai-ready/cron"
554
+ });
555
+ } else {
556
+ nitroConfig.experimental.tasks = true;
557
+ nitroConfig.tasks = nitroConfig.tasks || {};
558
+ nitroConfig.tasks["ai-ready:cron"] = {
559
+ handler: resolve("./runtime/server/tasks/ai-ready-cron")
560
+ };
561
+ nitroConfig.scheduledTasks = nitroConfig.scheduledTasks || {};
562
+ nitroConfig.scheduledTasks[cronSchedule] = nitroConfig.scheduledTasks[cronSchedule] || [];
563
+ nitroConfig.scheduledTasks[cronSchedule].push("ai-ready:cron");
564
+ }
554
565
  }
555
566
  nitroConfig.virtual = nitroConfig.virtual || {};
556
567
  nitroConfig.virtual["#ai-ready-virtual/read-page-data.mjs"] = `
@@ -592,9 +603,9 @@ export async function readPageDataFromFilesystem() {
592
603
  export const errorRoutes = []`;
593
604
  });
594
605
  const database = refineDatabaseConfig(config.database || {}, nuxt.options.rootDir);
595
- const runtimeSyncEnabled = config.runtimeSync?.enabled ?? false;
596
- const indexNowKey = config.indexNow?.key || process.env.NUXT_AI_READY_INDEXNOW_KEY;
597
- const indexNowEnabled = !!(config.indexNow?.enabled !== false && indexNowKey);
606
+ const runtimeSyncConfig = typeof config.runtimeSync === "object" ? config.runtimeSync : {};
607
+ const runtimeSyncEnabled = !!config.runtimeSync || !!config.cron;
608
+ const indexNowKey = config.indexNowKey || process.env.NUXT_AI_READY_INDEX_NOW_KEY;
598
609
  nuxt.options.runtimeConfig["nuxt-ai-ready"] = {
599
610
  version: version || "0.0.0",
600
611
  debug: config.debug || false,
@@ -609,16 +620,12 @@ export const errorRoutes = []`;
609
620
  database,
610
621
  runtimeSync: {
611
622
  enabled: runtimeSyncEnabled,
612
- ttl: config.runtimeSync?.ttl ?? 3600,
613
- batchSize: config.runtimeSync?.batchSize ?? 20,
614
- secret: config.runtimeSync?.secret,
615
- pruneTtl: config.runtimeSync?.pruneTtl ?? 0
623
+ ttl: runtimeSyncConfig.ttl ?? 3600,
624
+ batchSize: runtimeSyncConfig.batchSize ?? 20,
625
+ pruneTtl: runtimeSyncConfig.pruneTtl ?? 0
616
626
  },
617
- indexNow: indexNowEnabled ? {
618
- enabled: true,
619
- key: indexNowKey,
620
- host: config.indexNow?.host || "api.indexnow.org"
621
- } : void 0
627
+ runtimeSyncSecret: config.runtimeSyncSecret,
628
+ indexNowKey
622
629
  };
623
630
  nuxt.options.nitro.plugins = nuxt.options.nitro.plugins || [];
624
631
  nuxt.options.nitro.plugins.push(resolve("./runtime/server/plugins/db-restore"));
@@ -648,13 +655,16 @@ export const errorRoutes = []`;
648
655
  addServerHandler({ route: "/__ai-ready/poll", method: "post", handler: resolve("./runtime/server/routes/__ai-ready/poll.post") });
649
656
  addServerHandler({ route: "/__ai-ready/prune", method: "post", handler: resolve("./runtime/server/routes/__ai-ready/prune.post") });
650
657
  }
651
- if (indexNowEnabled && indexNowKey) {
658
+ if (indexNowKey) {
652
659
  addServerHandler({ route: `/${indexNowKey}.txt`, handler: resolve("./runtime/server/routes/indexnow-key.get") });
653
660
  addServerHandler({ route: "/__ai-ready/indexnow", method: "post", handler: resolve("./runtime/server/routes/__ai-ready/indexnow.post") });
654
661
  if (!runtimeSyncEnabled) {
655
662
  addServerHandler({ route: "/__ai-ready/status", handler: resolve("./runtime/server/routes/__ai-ready/status.get") });
656
663
  }
657
664
  }
665
+ if (config.cron) {
666
+ addServerHandler({ route: "/__ai-ready/cron", handler: resolve("./runtime/server/routes/__ai-ready/cron.get") });
667
+ }
658
668
  const isStatic = nuxt.options.nitro.static || nuxt.options._generate || false;
659
669
  const hasPrerenderedRoutes = nuxt.options.nitro.prerender?.routes?.length;
660
670
  const isSPA = nuxt.options.ssr === false;
@@ -0,0 +1,25 @@
1
+ export declare const tools: readonly [import("@nuxtjs/mcp-toolkit").McpToolDefinition<Readonly<{
2
+ [k: string]: import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
3
+ }>, Readonly<{
4
+ [k: string]: import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
5
+ }>>, import("@nuxtjs/mcp-toolkit").McpToolDefinition<Readonly<{
6
+ [k: string]: import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
7
+ }>, Readonly<{
8
+ [k: string]: import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
9
+ }>>];
10
+ export declare const resources: readonly [{
11
+ uri: string;
12
+ name: string;
13
+ description: string;
14
+ metadata: {
15
+ mimeType: string;
16
+ };
17
+ cache: "1h";
18
+ handler(uri: URL): Promise<{
19
+ contents: {
20
+ uri: string;
21
+ mimeType: string;
22
+ text: string;
23
+ }[];
24
+ }>;
25
+ }];
@@ -0,0 +1,5 @@
1
+ import pages from "./server/mcp/resources/pages.js";
2
+ import listPages from "./server/mcp/tools/list-pages.js";
3
+ import searchPages from "./server/mcp/tools/search-pages.js";
4
+ export const tools = [listPages, searchPages];
5
+ export const resources = [pages];
@@ -162,3 +162,49 @@ export interface IndexNowStats {
162
162
  * Get IndexNow stats
163
163
  */
164
164
  export declare function getIndexNowStats(event: H3Event | undefined): Promise<IndexNowStats>;
165
+ export interface CronRunRow {
166
+ id: number;
167
+ started_at: number;
168
+ finished_at: number | null;
169
+ duration_ms: number | null;
170
+ pages_indexed: number;
171
+ pages_remaining: number;
172
+ indexnow_submitted: number;
173
+ indexnow_remaining: number;
174
+ errors: string;
175
+ status: 'running' | 'success' | 'partial' | 'error';
176
+ }
177
+ export interface CronRun {
178
+ id: number;
179
+ startedAt: number;
180
+ finishedAt: number | null;
181
+ durationMs: number | null;
182
+ pagesIndexed: number;
183
+ pagesRemaining: number;
184
+ indexNowSubmitted: number;
185
+ indexNowRemaining: number;
186
+ errors: string[];
187
+ status: 'running' | 'success' | 'partial' | 'error';
188
+ }
189
+ /**
190
+ * Start a cron run and return its ID
191
+ */
192
+ export declare function startCronRun(event: H3Event | undefined): Promise<number | null>;
193
+ /**
194
+ * Complete a cron run with results
195
+ */
196
+ export declare function completeCronRun(event: H3Event | undefined, runId: number, result: {
197
+ pagesIndexed: number;
198
+ pagesRemaining: number;
199
+ indexNowSubmitted: number;
200
+ indexNowRemaining: number;
201
+ errors: string[];
202
+ }): Promise<void>;
203
+ /**
204
+ * Get recent cron runs
205
+ */
206
+ export declare function getRecentCronRuns(event: H3Event | undefined, limit?: number): Promise<CronRun[]>;
207
+ /**
208
+ * Clean up old cron runs (keep last N)
209
+ */
210
+ export declare function cleanupOldCronRuns(event: H3Event | undefined, keepCount?: number): Promise<number>;
@@ -374,3 +374,76 @@ export async function getIndexNowStats(event) {
374
374
  lastError: stats.indexnow_last_error || null
375
375
  };
376
376
  }
377
+ function rowToCronRun(row) {
378
+ return {
379
+ id: row.id,
380
+ startedAt: row.started_at,
381
+ finishedAt: row.finished_at,
382
+ durationMs: row.duration_ms,
383
+ pagesIndexed: row.pages_indexed,
384
+ pagesRemaining: row.pages_remaining,
385
+ indexNowSubmitted: row.indexnow_submitted,
386
+ indexNowRemaining: row.indexnow_remaining,
387
+ errors: JSON.parse(row.errors || "[]"),
388
+ status: row.status
389
+ };
390
+ }
391
+ export async function startCronRun(event) {
392
+ const db = await getDb(event);
393
+ if (!db)
394
+ return null;
395
+ const now = Date.now();
396
+ await db.exec(
397
+ "INSERT INTO ai_ready_cron_runs (started_at, status) VALUES (?, ?)",
398
+ [now, "running"]
399
+ );
400
+ const row = await db.first("SELECT last_insert_rowid() as id");
401
+ return row?.id || null;
402
+ }
403
+ export async function completeCronRun(event, runId, result) {
404
+ const db = await getDb(event);
405
+ if (!db)
406
+ return;
407
+ const now = Date.now();
408
+ const row = await db.first("SELECT started_at FROM ai_ready_cron_runs WHERE id = ?", [runId]);
409
+ const durationMs = row ? now - row.started_at : null;
410
+ const status = result.errors.length > 0 ? result.pagesIndexed > 0 ? "partial" : "error" : "success";
411
+ await db.exec(`
412
+ UPDATE ai_ready_cron_runs SET
413
+ finished_at = ?,
414
+ duration_ms = ?,
415
+ pages_indexed = ?,
416
+ pages_remaining = ?,
417
+ indexnow_submitted = ?,
418
+ indexnow_remaining = ?,
419
+ errors = ?,
420
+ status = ?
421
+ WHERE id = ?
422
+ `, [now, durationMs, result.pagesIndexed, result.pagesRemaining, result.indexNowSubmitted, result.indexNowRemaining, JSON.stringify(result.errors), status, runId]);
423
+ }
424
+ export async function getRecentCronRuns(event, limit = 10) {
425
+ const db = await getDb(event);
426
+ if (!db)
427
+ return [];
428
+ const rows = await db.all(
429
+ "SELECT * FROM ai_ready_cron_runs ORDER BY started_at DESC LIMIT ?",
430
+ [limit]
431
+ );
432
+ return rows.map(rowToCronRun);
433
+ }
434
+ export async function cleanupOldCronRuns(event, keepCount = 50) {
435
+ const db = await getDb(event);
436
+ if (!db)
437
+ return 0;
438
+ const countRow = await db.first("SELECT COUNT(*) as count FROM ai_ready_cron_runs");
439
+ const total = countRow?.count || 0;
440
+ if (total <= keepCount)
441
+ return 0;
442
+ const deleteCount = total - keepCount;
443
+ await db.exec(`
444
+ DELETE FROM ai_ready_cron_runs WHERE id IN (
445
+ SELECT id FROM ai_ready_cron_runs ORDER BY started_at ASC LIMIT ?
446
+ )
447
+ `, [deleteCount]);
448
+ return deleteCount;
449
+ }
@@ -1,3 +1,3 @@
1
- export declare const SCHEMA_VERSION = "v1.6.0";
1
+ export declare const SCHEMA_VERSION = "v1.7.0";
2
2
  export declare const DROP_TABLES_SQL: string[];
3
3
  export declare const ALL_SCHEMA_SQL: string[];
@@ -1,4 +1,4 @@
1
- export const SCHEMA_VERSION = "v1.6.0";
1
+ export const SCHEMA_VERSION = "v1.7.0";
2
2
  const PAGES_TABLE_SQL = `
3
3
  CREATE TABLE IF NOT EXISTS ai_ready_pages (
4
4
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -54,9 +54,24 @@ CREATE TABLE IF NOT EXISTS _ai_ready_info (
54
54
  checksum TEXT,
55
55
  ready INTEGER DEFAULT 0
56
56
  )`;
57
+ const CRON_RUNS_TABLE_SQL = `
58
+ CREATE TABLE IF NOT EXISTS ai_ready_cron_runs (
59
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
60
+ started_at INTEGER NOT NULL,
61
+ finished_at INTEGER,
62
+ duration_ms INTEGER,
63
+ pages_indexed INTEGER DEFAULT 0,
64
+ pages_remaining INTEGER DEFAULT 0,
65
+ indexnow_submitted INTEGER DEFAULT 0,
66
+ indexnow_remaining INTEGER DEFAULT 0,
67
+ errors TEXT DEFAULT '[]',
68
+ status TEXT DEFAULT 'running'
69
+ )`;
70
+ const CRON_RUNS_INDEX_SQL = "CREATE INDEX IF NOT EXISTS idx_ai_ready_cron_runs_started ON ai_ready_cron_runs(started_at DESC)";
57
71
  export const DROP_TABLES_SQL = [
58
72
  "DROP TABLE IF EXISTS ai_ready_pages_fts",
59
73
  "DROP TABLE IF EXISTS ai_ready_pages",
74
+ "DROP TABLE IF EXISTS ai_ready_cron_runs",
60
75
  "DROP TABLE IF EXISTS _ai_ready_info",
61
76
  // Legacy unprefixed tables (migration from v1.0.0)
62
77
  "DROP TABLE IF EXISTS pages_fts",
@@ -67,5 +82,7 @@ export const ALL_SCHEMA_SQL = [
67
82
  ...PAGES_INDEXES_SQL,
68
83
  FTS_TABLE_SQL,
69
84
  ...FTS_TRIGGERS_SQL,
70
- INFO_TABLE_SQL
85
+ INFO_TABLE_SQL,
86
+ CRON_RUNS_TABLE_SQL,
87
+ CRON_RUNS_INDEX_SQL
71
88
  ];
@@ -13,7 +13,8 @@ export default defineEventHandler(async (event) => {
13
13
  const { path, isExplicit } = renderInfo;
14
14
  const config = useRuntimeConfig(event)["nuxt-ai-ready"];
15
15
  const response = await event.fetch(path, {
16
- headers: { [INTERNAL_HEADER]: "1" }
16
+ headers: { [INTERNAL_HEADER]: "1" },
17
+ redirect: "manual"
17
18
  }).catch((e) => {
18
19
  logger.error(`Failed to fetch HTML for ${path}`, e);
19
20
  return null;
@@ -28,6 +29,17 @@ export default defineEventHandler(async (event) => {
28
29
  }
29
30
  return;
30
31
  }
32
+ if (response.status >= 300 && response.status < 400) {
33
+ const location = response.headers.get("location");
34
+ if (location) {
35
+ const redirectTarget = location.endsWith("/") ? `${location.slice(0, -1)}.md` : `${location}.md`;
36
+ setHeader(event, "location", redirectTarget);
37
+ return createError({
38
+ statusCode: response.status,
39
+ statusMessage: response.statusText
40
+ });
41
+ }
42
+ }
31
43
  if (!response.ok) {
32
44
  if (isExplicit) {
33
45
  return createError({
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Cron endpoint for platforms that use HTTP-based cron (Vercel, etc.)
3
+ */
4
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("../../utils/runCron.js").CronResult>>;
5
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { eventHandler } from "h3";
2
+ import { runCron } from "../../utils/runCron.js";
3
+ export default eventHandler((event) => runCron(event));
@@ -3,13 +3,13 @@ import { useRuntimeConfig } from "nitropack/runtime";
3
3
  import { syncToIndexNow } from "../../utils/indexnow.js";
4
4
  export default eventHandler(async (event) => {
5
5
  const config = useRuntimeConfig(event)["nuxt-ai-ready"];
6
- if (!config.indexNow?.enabled) {
7
- throw createError({ statusCode: 400, message: "IndexNow not enabled" });
6
+ if (!config.indexNowKey) {
7
+ throw createError({ statusCode: 400, message: "IndexNow not configured" });
8
8
  }
9
9
  const query = getQuery(event);
10
- if (config.runtimeSync?.secret) {
10
+ if (config.runtimeSyncSecret) {
11
11
  const secret = query.secret;
12
- if (secret !== config.runtimeSync.secret) {
12
+ if (secret !== config.runtimeSyncSecret) {
13
13
  throw createError({ statusCode: 401, message: "Unauthorized" });
14
14
  }
15
15
  }
@@ -4,9 +4,9 @@ import { batchIndexPages } from "../../utils/batchIndex.js";
4
4
  export default eventHandler(async (event) => {
5
5
  const config = useRuntimeConfig()["nuxt-ai-ready"];
6
6
  const query = getQuery(event);
7
- if (config.runtimeSync.secret) {
7
+ if (config.runtimeSyncSecret) {
8
8
  const secret = query.secret;
9
- if (secret !== config.runtimeSync.secret) {
9
+ if (secret !== config.runtimeSyncSecret) {
10
10
  throw createError({ statusCode: 401, message: "Unauthorized" });
11
11
  }
12
12
  }
@@ -5,9 +5,9 @@ export default eventHandler(async (event) => {
5
5
  const config = useRuntimeConfig()["nuxt-ai-ready"];
6
6
  const query = getQuery(event);
7
7
  const dry = query.dry === "true" || query.dry === "1";
8
- if (!dry && config.runtimeSync.secret) {
8
+ if (!dry && config.runtimeSyncSecret) {
9
9
  const secret = query.secret;
10
- if (secret !== config.runtimeSync.secret) {
10
+ if (secret !== config.runtimeSyncSecret) {
11
11
  throw createError({ statusCode: 401, message: "Unauthorized" });
12
12
  }
13
13
  }
@@ -12,7 +12,7 @@ export default eventHandler(async (event) => {
12
12
  indexed: total - pending,
13
13
  pending
14
14
  };
15
- if (config.indexNow?.enabled) {
15
+ if (config.indexNowKey) {
16
16
  const [indexNowPending, indexNowStats] = await Promise.all([
17
17
  countPagesNeedingIndexNowSync(event),
18
18
  getIndexNowStats(event)
@@ -1,3 +1,15 @@
1
+ interface CronRunInfo {
2
+ id: number;
3
+ startedAt: string;
4
+ finishedAt: string | null;
5
+ durationMs: number | null;
6
+ status: string;
7
+ pagesIndexed: number;
8
+ pagesRemaining: number;
9
+ indexNowSubmitted: number;
10
+ indexNowRemaining: number;
11
+ errors: string[];
12
+ }
1
13
  interface DebugInfo {
2
14
  version: string;
3
15
  environment: {
@@ -10,6 +22,19 @@ interface DebugInfo {
10
22
  cacheMaxAgeSeconds: number;
11
23
  mdreamOptions: unknown;
12
24
  };
25
+ runtimeSync?: {
26
+ total: number;
27
+ indexed: number;
28
+ pending: number;
29
+ sitemapSeededAt: string | null;
30
+ };
31
+ indexNow?: {
32
+ pending: number;
33
+ totalSubmitted: number;
34
+ lastSubmittedAt: string | null;
35
+ lastError: string | null;
36
+ };
37
+ cronRuns?: CronRunInfo[];
13
38
  pageData: {
14
39
  source: string;
15
40
  pageCount: number;
@@ -1,6 +1,6 @@
1
1
  import { createError, eventHandler, setHeader } from "h3";
2
2
  import { useRuntimeConfig } from "nitropack/runtime";
3
- import { queryPages } from "../db/queries.js";
3
+ import { countPages, countPagesNeedingIndexNowSync, getIndexNowStats, getRecentCronRuns, getSitemapSeededAt, queryPages } from "../db/queries.js";
4
4
  export default eventHandler(async (event) => {
5
5
  const runtimeConfig = useRuntimeConfig(event)["nuxt-ai-ready"];
6
6
  if (!runtimeConfig.debug) {
@@ -90,6 +90,47 @@ export default eventHandler(async (event) => {
90
90
  issues.push("Prerender mode but no pages found");
91
91
  suggestions.push("Check if pages.db exists in .data/ai-ready/");
92
92
  }
93
+ let runtimeSyncInfo;
94
+ let indexNowInfo;
95
+ let cronRunsInfo;
96
+ if (!isDev && !isPrerender) {
97
+ const [total, pending, sitemapSeededAt, cronRuns] = await Promise.all([
98
+ countPages(event),
99
+ countPages(event, { where: { pending: true } }),
100
+ getSitemapSeededAt(event),
101
+ getRecentCronRuns(event, 20)
102
+ ]);
103
+ runtimeSyncInfo = {
104
+ total,
105
+ indexed: total - pending,
106
+ pending,
107
+ sitemapSeededAt: sitemapSeededAt ? new Date(sitemapSeededAt).toISOString() : null
108
+ };
109
+ cronRunsInfo = cronRuns.map((run) => ({
110
+ id: run.id,
111
+ startedAt: new Date(run.startedAt).toISOString(),
112
+ finishedAt: run.finishedAt ? new Date(run.finishedAt).toISOString() : null,
113
+ durationMs: run.durationMs,
114
+ status: run.status,
115
+ pagesIndexed: run.pagesIndexed,
116
+ pagesRemaining: run.pagesRemaining,
117
+ indexNowSubmitted: run.indexNowSubmitted,
118
+ indexNowRemaining: run.indexNowRemaining,
119
+ errors: run.errors
120
+ }));
121
+ if (runtimeConfig.indexNowKey) {
122
+ const [indexNowPending, indexNowStats] = await Promise.all([
123
+ countPagesNeedingIndexNowSync(event),
124
+ getIndexNowStats(event)
125
+ ]);
126
+ indexNowInfo = {
127
+ pending: indexNowPending,
128
+ totalSubmitted: indexNowStats.totalSubmitted,
129
+ lastSubmittedAt: indexNowStats.lastSubmittedAt ? new Date(indexNowStats.lastSubmittedAt).toISOString() : null,
130
+ lastError: indexNowStats.lastError
131
+ };
132
+ }
133
+ }
93
134
  const debugInfo = {
94
135
  version: runtimeConfig.version || "unknown",
95
136
  environment: {
@@ -102,6 +143,9 @@ export default eventHandler(async (event) => {
102
143
  cacheMaxAgeSeconds: runtimeConfig.cacheMaxAgeSeconds,
103
144
  mdreamOptions: runtimeConfig.mdreamOptions
104
145
  },
146
+ runtimeSync: runtimeSyncInfo,
147
+ indexNow: indexNowInfo,
148
+ cronRuns: cronRunsInfo,
105
149
  pageData: {
106
150
  source,
107
151
  pageCount: pages.length,
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nitropack/types").Task<import("../utils/runCron.js").CronResult>;
2
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import { defineTask } from "nitropack/runtime";
2
+ import { runCron } from "../utils/runCron.js";
3
+ export default defineTask({
4
+ meta: {
5
+ name: "ai-ready:cron",
6
+ description: "Scheduled task for AI Ready - runs indexing and IndexNow sync"
7
+ },
8
+ async run({ payload }) {
9
+ const mockEvent = {
10
+ $fetch: globalThis.$fetch
11
+ };
12
+ const result = await runCron(mockEvent, {
13
+ batchSize: payload?.limit
14
+ });
15
+ return { result };
16
+ }
17
+ });
@@ -5,11 +5,6 @@ export interface IndexNowResult {
5
5
  remaining: number;
6
6
  error?: string;
7
7
  }
8
- export interface IndexNowConfig {
9
- enabled?: boolean;
10
- key?: string;
11
- host?: string;
12
- }
13
8
  /**
14
9
  * Submit URLs to IndexNow API
15
10
  */
@@ -38,7 +38,7 @@ export async function submitToIndexNow(routes, config, siteUrl) {
38
38
  export async function syncToIndexNow(event, limit = 100) {
39
39
  const config = useRuntimeConfig(event)["nuxt-ai-ready"];
40
40
  const siteConfig = useSiteConfig();
41
- if (!config.indexNow?.enabled || !config.indexNow?.key) {
41
+ if (!config.indexNowKey) {
42
42
  return { success: false, submitted: 0, remaining: 0, error: "IndexNow not configured" };
43
43
  }
44
44
  if (!siteConfig.url) {
@@ -49,7 +49,7 @@ export async function syncToIndexNow(event, limit = 100) {
49
49
  return { success: true, submitted: 0, remaining: 0 };
50
50
  }
51
51
  const routes = pages.map((p) => p.route);
52
- const result = await submitToIndexNow(routes, config.indexNow, siteConfig.url);
52
+ const result = await submitToIndexNow(routes, { key: config.indexNowKey }, siteConfig.url);
53
53
  if (result.success) {
54
54
  await markIndexNowSynced(event, routes);
55
55
  await updateIndexNowStats(event, routes.length);
@@ -0,0 +1,21 @@
1
+ import type { H3Event } from 'h3';
2
+ export interface CronResult {
3
+ runId?: number | null;
4
+ index?: {
5
+ indexed: number;
6
+ remaining: number;
7
+ errors?: string[];
8
+ complete: boolean;
9
+ };
10
+ indexNow?: {
11
+ submitted: number;
12
+ remaining: number;
13
+ error?: string;
14
+ };
15
+ }
16
+ /**
17
+ * Run cron job logic - shared between scheduled task and HTTP endpoint
18
+ */
19
+ export declare function runCron(event: H3Event, options?: {
20
+ batchSize?: number;
21
+ }): Promise<CronResult>;
@@ -0,0 +1,52 @@
1
+ import { useRuntimeConfig } from "nitropack/runtime";
2
+ import { cleanupOldCronRuns, completeCronRun, startCronRun } from "../db/queries.js";
3
+ import { batchIndexPages } from "./batchIndex.js";
4
+ import { syncToIndexNow } from "./indexnow.js";
5
+ export async function runCron(event, options) {
6
+ const config = useRuntimeConfig()["nuxt-ai-ready"];
7
+ const results = {};
8
+ const allErrors = [];
9
+ const runId = await startCronRun(event);
10
+ results.runId = runId;
11
+ if (config.runtimeSync.enabled) {
12
+ const limit = options?.batchSize ?? config.runtimeSync.batchSize;
13
+ const indexResult = await batchIndexPages(event, {
14
+ limit,
15
+ all: false
16
+ });
17
+ results.index = {
18
+ indexed: indexResult.indexed,
19
+ remaining: indexResult.remaining,
20
+ errors: indexResult.errors.length > 0 ? indexResult.errors : void 0,
21
+ complete: indexResult.complete
22
+ };
23
+ if (indexResult.errors.length > 0) {
24
+ allErrors.push(...indexResult.errors);
25
+ }
26
+ }
27
+ if (config.indexNowKey) {
28
+ const indexNowResult = await syncToIndexNow(event, 100).catch((err) => {
29
+ console.warn("[ai-ready:cron] IndexNow sync failed:", err.message);
30
+ return { success: false, submitted: 0, remaining: 0, error: err.message };
31
+ });
32
+ results.indexNow = {
33
+ submitted: indexNowResult.submitted,
34
+ remaining: indexNowResult.remaining,
35
+ error: indexNowResult.error
36
+ };
37
+ if (indexNowResult.error) {
38
+ allErrors.push(`IndexNow: ${indexNowResult.error}`);
39
+ }
40
+ }
41
+ if (runId) {
42
+ await completeCronRun(event, runId, {
43
+ pagesIndexed: results.index?.indexed || 0,
44
+ pagesRemaining: results.index?.remaining || 0,
45
+ indexNowSubmitted: results.indexNow?.submitted || 0,
46
+ indexNowRemaining: results.indexNow?.remaining || 0,
47
+ errors: allErrors
48
+ });
49
+ await cleanupOldCronRuns(event, 50);
50
+ }
51
+ return results;
52
+ }
@@ -103,18 +103,31 @@ export interface ModuleOptions {
103
103
  */
104
104
  authToken?: string;
105
105
  };
106
+ /**
107
+ * Enable scheduled cron task (runs every minute)
108
+ * When true, automatically enables runtimeSync for background indexing
109
+ * Also runs IndexNow sync if indexNowKey is configured
110
+ */
111
+ cron?: boolean;
112
+ /**
113
+ * IndexNow API key for instant search engine notifications
114
+ * When set, enables IndexNow submissions to Bing, Yandex, Naver, Seznam
115
+ * Get one from https://www.bing.com/indexnow
116
+ * Can also be set via NUXT_AI_READY_INDEX_NOW_KEY env var
117
+ */
118
+ indexNowKey?: string;
119
+ /**
120
+ * Secret token for authenticating runtime sync endpoints
121
+ * When set, requires ?secret=<token> query param for poll/prune/indexnow endpoints
122
+ */
123
+ runtimeSyncSecret?: string;
106
124
  /**
107
125
  * Runtime sync configuration (opt-in for dynamic content sites)
108
126
  * When enabled, pages are re-indexed at runtime from sitemap
109
- * @default disabled - prerendered data is used
127
+ * Set to `true` for defaults or object to customize
128
+ * @default false - prerendered data is used
110
129
  */
111
- runtimeSync?: {
112
- /**
113
- * Enable runtime sync
114
- * When false (default), runtime uses prerendered data only
115
- * @default false
116
- */
117
- enabled?: boolean;
130
+ runtimeSync?: boolean | {
118
131
  /**
119
132
  * TTL for refresh in seconds (sitemap + page re-indexing)
120
133
  * Controls how often to refresh sitemap routes and re-index stale pages
@@ -126,16 +139,6 @@ export interface ModuleOptions {
126
139
  * @default 20
127
140
  */
128
141
  batchSize?: number;
129
- /**
130
- * Cron expression for scheduled indexing (e.g. every 5 minutes)
131
- * When set, enables automatic background indexing via Nitro task
132
- */
133
- cron?: string;
134
- /**
135
- * Secret token for authenticating poll endpoint
136
- * When set, requires ?secret=<token> query param
137
- */
138
- secret?: string;
139
142
  /**
140
143
  * TTL for pruning stale routes in seconds
141
144
  * Routes not seen in sitemap for longer than this are deleted
@@ -144,27 +147,6 @@ export interface ModuleOptions {
144
147
  */
145
148
  pruneTtl?: number;
146
149
  };
147
- /**
148
- * IndexNow configuration for instant search engine notifications
149
- * Submits changed URLs to Bing, Yandex, Naver, Seznam via IndexNow protocol
150
- */
151
- indexNow?: {
152
- /**
153
- * Enable IndexNow submissions
154
- * @default false
155
- */
156
- enabled?: boolean;
157
- /**
158
- * Your IndexNow API key
159
- * Get one from https://www.bing.com/indexnow
160
- */
161
- key?: string;
162
- /**
163
- * IndexNow endpoint host
164
- * @default 'api.indexnow.org'
165
- */
166
- host?: string;
167
- };
168
150
  }
169
151
  /**
170
152
  * Page-level entry for discovery and metadata queries
package/mcp.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { McpResourceDefinition, McpToolDefinition } from '@nuxtjs/mcp-toolkit'
2
+
3
+ export declare const tools: readonly [McpToolDefinition, McpToolDefinition]
4
+ export declare const resources: readonly [McpResourceDefinition]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-ai-ready",
3
3
  "type": "module",
4
- "version": "0.7.0",
4
+ "version": "0.7.2",
5
5
  "description": "Best practice AI & LLM discoverability for Nuxt sites.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -25,11 +25,16 @@
25
25
  ".": {
26
26
  "types": "./dist/types.d.mts",
27
27
  "import": "./dist/module.mjs"
28
+ },
29
+ "./mcp": {
30
+ "types": "./mcp.d.ts",
31
+ "import": "./dist/runtime/mcp.js"
28
32
  }
29
33
  },
30
34
  "main": "./dist/module.mjs",
31
35
  "files": [
32
- "dist"
36
+ "dist",
37
+ "mcp.d.ts"
33
38
  ],
34
39
  "peerDependencies": {
35
40
  "@nuxtjs/sitemap": "^7.0.0",
@@ -1,11 +0,0 @@
1
- declare const _default: import("nitropack/types").Task<{
2
- indexed: number;
3
- remaining: number;
4
- errors: string[];
5
- complete: boolean;
6
- indexNow: {
7
- submitted: number;
8
- error: any;
9
- } | undefined;
10
- }>;
11
- export default _default;
@@ -1,39 +0,0 @@
1
- import { defineTask, useRuntimeConfig } from "nitropack/runtime";
2
- import { batchIndexPages } from "../utils/batchIndex.js";
3
- import { syncToIndexNow } from "../utils/indexnow.js";
4
- export default defineTask({
5
- meta: {
6
- name: "ai-ready:index",
7
- description: "Index pending pages for AI Ready"
8
- },
9
- async run({ payload }) {
10
- const config = useRuntimeConfig()["nuxt-ai-ready"];
11
- const limit = payload?.limit ?? config.runtimeSync.batchSize;
12
- const mockEvent = {
13
- $fetch: globalThis.$fetch
14
- };
15
- const result = await batchIndexPages(mockEvent, {
16
- limit,
17
- all: false
18
- });
19
- let indexNowResult;
20
- if (config.indexNow?.enabled) {
21
- indexNowResult = await syncToIndexNow(mockEvent, 100).catch((err) => {
22
- console.warn("[ai-ready:index] IndexNow sync failed:", err.message);
23
- return { success: false, submitted: 0, error: err.message };
24
- });
25
- }
26
- return {
27
- result: {
28
- indexed: result.indexed,
29
- remaining: result.remaining,
30
- errors: result.errors,
31
- complete: result.complete,
32
- indexNow: indexNowResult ? {
33
- submitted: indexNowResult.submitted,
34
- error: indexNowResult.error
35
- } : void 0
36
- }
37
- };
38
- }
39
- });