@prenta/core 5.6.0 → 5.8.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.
Files changed (109) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/api/handler-factory.d.ts.map +1 -1
  3. package/dist/api/handler-factory.js +8 -4
  4. package/dist/api/handler-factory.js.map +1 -1
  5. package/dist/api/handlers.d.ts.map +1 -1
  6. package/dist/api/handlers.js +2 -0
  7. package/dist/api/handlers.js.map +1 -1
  8. package/dist/api/routes/redirects.d.ts.map +1 -1
  9. package/dist/api/routes/redirects.js +113 -53
  10. package/dist/api/routes/redirects.js.map +1 -1
  11. package/dist/api/routes/seo-autopilot.d.ts +12 -0
  12. package/dist/api/routes/seo-autopilot.d.ts.map +1 -0
  13. package/dist/api/routes/seo-autopilot.js +257 -0
  14. package/dist/api/routes/seo-autopilot.js.map +1 -0
  15. package/dist/db/model-types.d.ts +26 -0
  16. package/dist/db/model-types.d.ts.map +1 -1
  17. package/dist/generated/browser.d.ts +8 -0
  18. package/dist/generated/client.d.ts +8 -0
  19. package/dist/generated/internal/class.d.ts +11 -0
  20. package/dist/generated/internal/class.js +4 -4
  21. package/dist/generated/internal/prismaNamespace.d.ts +120 -1
  22. package/dist/generated/internal/prismaNamespace.js +42 -0
  23. package/dist/generated/internal/prismaNamespaceBrowser.d.ts +44 -0
  24. package/dist/generated/internal/prismaNamespaceBrowser.js +42 -0
  25. package/dist/generated/models/SeoAutoApply.d.ts +1495 -0
  26. package/dist/generated/models/SeoAutoApply.js +1 -0
  27. package/dist/generated/models.d.ts +1 -0
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/public-redirects.d.ts +12 -0
  33. package/dist/public-redirects.d.ts.map +1 -1
  34. package/dist/public-redirects.js +21 -7
  35. package/dist/public-redirects.js.map +1 -1
  36. package/dist/redirects/index.d.ts +2 -0
  37. package/dist/redirects/index.d.ts.map +1 -1
  38. package/dist/redirects/index.js +1 -0
  39. package/dist/redirects/index.js.map +1 -1
  40. package/dist/redirects/match.d.ts +52 -0
  41. package/dist/redirects/match.d.ts.map +1 -0
  42. package/dist/redirects/match.js +101 -0
  43. package/dist/redirects/match.js.map +1 -0
  44. package/dist/redirects/recovery.d.ts +15 -9
  45. package/dist/redirects/recovery.d.ts.map +1 -1
  46. package/dist/redirects/recovery.js +15 -61
  47. package/dist/redirects/recovery.js.map +1 -1
  48. package/dist/redirects/suggestion-accept.d.ts +3 -2
  49. package/dist/redirects/suggestion-accept.d.ts.map +1 -1
  50. package/dist/redirects/suggestion-accept.js +24 -14
  51. package/dist/redirects/suggestion-accept.js.map +1 -1
  52. package/dist/seo/audit-runner.d.ts.map +1 -1
  53. package/dist/seo/audit-runner.js +0 -2
  54. package/dist/seo/audit-runner.js.map +1 -1
  55. package/dist/seo/autopilot-gate.d.ts +101 -0
  56. package/dist/seo/autopilot-gate.d.ts.map +1 -0
  57. package/dist/seo/autopilot-gate.js +272 -0
  58. package/dist/seo/autopilot-gate.js.map +1 -0
  59. package/dist/seo/autopilot-ledger.d.ts +74 -0
  60. package/dist/seo/autopilot-ledger.d.ts.map +1 -0
  61. package/dist/seo/autopilot-ledger.js +118 -0
  62. package/dist/seo/autopilot-ledger.js.map +1 -0
  63. package/dist/seo/autopilot-outcome.d.ts +93 -0
  64. package/dist/seo/autopilot-outcome.d.ts.map +1 -0
  65. package/dist/seo/autopilot-outcome.js +206 -0
  66. package/dist/seo/autopilot-outcome.js.map +1 -0
  67. package/dist/seo/autopilot-policy.d.ts +169 -0
  68. package/dist/seo/autopilot-policy.d.ts.map +1 -0
  69. package/dist/seo/autopilot-policy.js +267 -0
  70. package/dist/seo/autopilot-policy.js.map +1 -0
  71. package/dist/seo/autopilot-revert.d.ts +40 -0
  72. package/dist/seo/autopilot-revert.d.ts.map +1 -0
  73. package/dist/seo/autopilot-revert.js +155 -0
  74. package/dist/seo/autopilot-revert.js.map +1 -0
  75. package/dist/seo/autopilot.d.ts +91 -0
  76. package/dist/seo/autopilot.d.ts.map +1 -0
  77. package/dist/seo/autopilot.js +1060 -0
  78. package/dist/seo/autopilot.js.map +1 -0
  79. package/dist/seo/config-store.d.ts +35 -2
  80. package/dist/seo/config-store.d.ts.map +1 -1
  81. package/dist/seo/config-store.js +58 -1
  82. package/dist/seo/config-store.js.map +1 -1
  83. package/dist/seo/deep-equal.d.ts +12 -0
  84. package/dist/seo/deep-equal.d.ts.map +1 -0
  85. package/dist/seo/deep-equal.js +42 -0
  86. package/dist/seo/deep-equal.js.map +1 -0
  87. package/dist/seo/digest.d.ts +27 -0
  88. package/dist/seo/digest.d.ts.map +1 -1
  89. package/dist/seo/digest.js +77 -1
  90. package/dist/seo/digest.js.map +1 -1
  91. package/dist/seo/index.d.ts +14 -0
  92. package/dist/seo/index.d.ts.map +1 -1
  93. package/dist/seo/index.js +7 -0
  94. package/dist/seo/index.js.map +1 -1
  95. package/dist/seo/issue-fix-apply.d.ts +20 -1
  96. package/dist/seo/issue-fix-apply.d.ts.map +1 -1
  97. package/dist/seo/issue-fix-apply.js +10 -4
  98. package/dist/seo/issue-fix-apply.js.map +1 -1
  99. package/dist/seo/proposals-generate.d.ts +2 -0
  100. package/dist/seo/proposals-generate.d.ts.map +1 -1
  101. package/dist/seo/proposals-generate.js +7 -1
  102. package/dist/seo/proposals-generate.js.map +1 -1
  103. package/dist/seo/proposals.d.ts +9 -0
  104. package/dist/seo/proposals.d.ts.map +1 -1
  105. package/dist/seo/proposals.js +35 -1
  106. package/dist/seo/proposals.js.map +1 -1
  107. package/package.json +1 -1
  108. package/prisma/migrations/0017_seo_auto_applies/migration.sql +35 -0
  109. package/prisma/schema.prisma +43 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autopilot-policy.js","sourceRoot":"","sources":["../../src/seo/autopilot-policy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,w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BAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC7B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,+CAA+C,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;YACzF,CAAC;YACD,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA;AACjD,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Field-level undo for an autopilot change (spec §4). Issue fixes restore the
3
+ * `before` values through `updateDocumentSeoFields` (a normal write: Version
4
+ * row, hooks, webhooks). Redirects are deleted (autopilot never overwrites an
5
+ * existing rule, so `before` is always null) and the suggestion reopened.
6
+ */
7
+ import type { PrentaDB } from '../db/client-types.js';
8
+ import type { SeoAutoApply } from '../db/model-types.js';
9
+ import type { SeoAutoApplyRevertReason } from './autopilot-ledger.js';
10
+ export type RevertResult = {
11
+ status: 'reverted';
12
+ row: SeoAutoApply;
13
+ } | {
14
+ status: 'not-found';
15
+ } | {
16
+ status: 'not-revertible';
17
+ current: string;
18
+ } | {
19
+ status: 'conflict';
20
+ fields: string[];
21
+ };
22
+ export interface RevertSeoAutoApplyOptions {
23
+ actor: {
24
+ userId: string;
25
+ role: string;
26
+ };
27
+ reason: SeoAutoApplyRevertReason;
28
+ /** Restore `before` even when a human has changed a field since the apply. */
29
+ force?: boolean;
30
+ }
31
+ /**
32
+ * Revert one ledger row. Returns a `RevertResult` for every expected outcome
33
+ * (not found, not revertible, conflict, reverted).
34
+ *
35
+ * Throws when the document write, redirect delete (non-P2025), or ledger
36
+ * update fails — callers in unattended loops must catch per row. On a throw
37
+ * the ledger row is left `applied`, so the revert can be retried.
38
+ */
39
+ export declare function revertSeoAutoApply(db: PrentaDB, id: string, opts: RevertSeoAutoApplyOptions): Promise<RevertResult>;
40
+ //# sourceMappingURL=autopilot-revert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autopilot-revert.d.ts","sourceRoot":"","sources":["../../src/seo/autopilot-revert.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAIxD,OAAO,KAAK,EAAE,wBAAwB,EAAsB,MAAM,uBAAuB,CAAA;AAEzF,MAAM,MAAM,YAAY,GACpB;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,YAAY,CAAA;CAAE,GACzC;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,GACvB;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AAE5C,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACvC,MAAM,EAAE,wBAAwB,CAAA;IAChC,8EAA8E;IAC9E,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AA4GD;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,QAAQ,EACZ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,YAAY,CAAC,CAqCvB"}
@@ -0,0 +1,155 @@
1
+ import { updateDocumentSeoFields } from '../actions.js';
2
+ import { logEvent } from '../security/audit.js';
3
+ function asRecord(v) {
4
+ return v && typeof v === 'object' && !Array.isArray(v) ? v : {};
5
+ }
6
+ function sameValue(a, b) {
7
+ if (a === b)
8
+ return true;
9
+ if (a == null && b == null)
10
+ return true;
11
+ return JSON.stringify(a) === JSON.stringify(b);
12
+ }
13
+ /** Prisma "record not found" (thrown by `update`/`delete` on a missing row). */
14
+ function isRecordNotFound(err) {
15
+ return typeof err === 'object' && err !== null && err.code === 'P2025';
16
+ }
17
+ function statusForReason(reason) {
18
+ switch (reason) {
19
+ case 'outcome_regression':
20
+ return 'outcome_reverted';
21
+ case 'manual':
22
+ case 'verify_failed':
23
+ return 'reverted';
24
+ default: {
25
+ const exhaustive = reason;
26
+ return exhaustive;
27
+ }
28
+ }
29
+ }
30
+ /**
31
+ * Undo an issue fix: verify the live document still carries the autopilot
32
+ * `after` values (otherwise a human edited since → conflict unless forced),
33
+ * then write `before` back and reopen the originating issue.
34
+ *
35
+ * Keys are the union of `before` and `after`: a key autopilot introduced that
36
+ * had no prior value (absent from `before`, since JSON drops `undefined`) is
37
+ * restored to `null`. A field whose live value already equals `before` is not
38
+ * a conflict — a previous partial revert (doc write ok, ledger flip failed)
39
+ * already restored it, so retrying is idempotent.
40
+ */
41
+ async function revertIssueFix(db, row, ctx, force) {
42
+ if (!row.entityId || !row.collection) {
43
+ return { status: 'not-revertible', current: 'missing-entity' };
44
+ }
45
+ const before = asRecord(row.before);
46
+ const after = asRecord(row.after);
47
+ const doc = await db.document.findFirst({
48
+ where: { id: row.entityId, deletedAt: null },
49
+ select: { id: true, collection: true, data: true },
50
+ });
51
+ if (!doc)
52
+ return { status: 'not-revertible', current: 'document-missing' };
53
+ const live = asRecord(doc.data);
54
+ const fields = [...new Set([...Object.keys(after), ...Object.keys(before)])];
55
+ const conflicts = fields.filter((field) => !sameValue(live[field], after[field]) && !sameValue(live[field], before[field]));
56
+ if (conflicts.length > 0 && !force)
57
+ return { status: 'conflict', fields: conflicts };
58
+ const restore = {};
59
+ for (const field of fields)
60
+ restore[field] = before[field] ?? null;
61
+ await updateDocumentSeoFields(row.collection, row.entityId, restore, ctx);
62
+ if (row.issueId) {
63
+ try {
64
+ await db.seoIssue.update({
65
+ where: { id: row.issueId },
66
+ data: { status: 'open', resolvedAt: null, resolvedById: null },
67
+ });
68
+ }
69
+ catch {
70
+ // The audit may have removed the issue since; the field restore is what matters.
71
+ }
72
+ }
73
+ return null;
74
+ }
75
+ /**
76
+ * Undo a redirect: delete the rule autopilot created and reopen the suggestion.
77
+ * Only "record not found" (P2025 — a human already deleted it) is tolerated;
78
+ * any other delete failure propagates so the ledger row stays `applied`.
79
+ */
80
+ async function revertRedirect(db, row) {
81
+ if (!row.redirectId)
82
+ return { status: 'not-revertible', current: 'missing-redirect' };
83
+ try {
84
+ await db.redirect.delete({ where: { id: row.redirectId } });
85
+ }
86
+ catch (err) {
87
+ if (!isRecordNotFound(err))
88
+ throw err;
89
+ // Already deleted by a human — the desired end state holds.
90
+ }
91
+ const suggestionId = asRecord(row.after).suggestionId;
92
+ if (typeof suggestionId === 'string') {
93
+ try {
94
+ await db.redirectSuggestion.update({
95
+ where: { id: suggestionId },
96
+ data: { status: 'open' },
97
+ });
98
+ }
99
+ catch {
100
+ // Suggestion rows are advisory; never fail the revert on them.
101
+ }
102
+ }
103
+ return null;
104
+ }
105
+ /**
106
+ * Revert one ledger row. Returns a `RevertResult` for every expected outcome
107
+ * (not found, not revertible, conflict, reverted).
108
+ *
109
+ * Throws when the document write, redirect delete (non-P2025), or ledger
110
+ * update fails — callers in unattended loops must catch per row. On a throw
111
+ * the ledger row is left `applied`, so the revert can be retried.
112
+ */
113
+ export async function revertSeoAutoApply(db, id, opts) {
114
+ const row = await db.seoAutoApply.findUnique({ where: { id } });
115
+ if (!row)
116
+ return { status: 'not-found' };
117
+ if (row.status !== 'applied')
118
+ return { status: 'not-revertible', current: row.status };
119
+ const ctx = { userId: opts.actor.userId, role: opts.actor.role, db };
120
+ // `kind` is a String column; anything outside the known union is refused.
121
+ if (row.kind === 'issue-fix') {
122
+ const early = await revertIssueFix(db, row, ctx, opts.force === true);
123
+ if (early)
124
+ return early;
125
+ }
126
+ else if (row.kind === 'redirect') {
127
+ const early = await revertRedirect(db, row);
128
+ if (early)
129
+ return early;
130
+ }
131
+ else {
132
+ return { status: 'not-revertible', current: `unknown-kind:${row.kind}` };
133
+ }
134
+ const updated = await db.seoAutoApply.update({
135
+ where: { id },
136
+ data: {
137
+ status: statusForReason(opts.reason),
138
+ revertedAt: new Date(),
139
+ revertedById: opts.actor.userId,
140
+ revertReason: opts.reason,
141
+ },
142
+ });
143
+ try {
144
+ await logEvent({
145
+ event: 'seo_autopilot_reverted',
146
+ userId: opts.actor.userId,
147
+ details: { id, kind: row.kind, reason: opts.reason, force: opts.force === true },
148
+ });
149
+ }
150
+ catch {
151
+ /* audit-log failures never block */
152
+ }
153
+ return { status: 'reverted', row: updated };
154
+ }
155
+ //# sourceMappingURL=autopilot-revert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autopilot-revert.js","sourceRoot":"","sources":["../../src/seo/autopilot-revert.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAgB/C,SAAS,QAAQ,CAAC,CAAU;IAC1B,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAA6B,CAAC,CAAC,CAAC,EAAE,CAAA;AAC9F,CAAC;AAED,SAAS,SAAS,CAAC,CAAU,EAAE,CAAU;IACvC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACxB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI;QAAE,OAAO,IAAI,CAAA;IACvC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;AAChD,CAAC;AAED,gFAAgF;AAChF,SAAS,gBAAgB,CAAC,GAAY;IACpC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAK,GAA0B,CAAC,IAAI,KAAK,OAAO,CAA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,EAAE;SACjF,CAAC,CAAA;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,oCAAoC;IACtC,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA;AAC7C,CAAC"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * SEO Autopilot run (spec §3): preflight → outcome watch → generate → gate →
3
+ * apply → verify → ledger → summary. Reuses the inbox pipeline end to end so
4
+ * anything the gate refuses simply waits in the Proposals tab for a human.
5
+ *
6
+ * Every write the engine performs lands in the `SeoAutoApply` ledger with the
7
+ * prior values (`before`), the values written (`after`), the gate snapshot,
8
+ * and the policy owner as `appliedById`. Snapshots are keyed on the fix's
9
+ * PATCH keys (document data-layer names such as `canonical`), not on the
10
+ * display `changes[].field` names (`canonicalUrl`, rendered `metaTitle`), so
11
+ * the verify-failed restore writes the right keys and a later
12
+ * `revertSeoAutoApply` conflict check compares like with like.
13
+ *
14
+ * Invariant: the value written is the value the gate approved. AI-tier
15
+ * candidates are applied with `preferCached` so `applyIssueFix` writes the
16
+ * cached text the gate scored, and every apply is re-read and compared to the
17
+ * gated patch; drift is a verify failure (`applyOutcomes.gate_mismatch`), and
18
+ * so is a re-read that fails (`applyOutcomes.after_unreadable`).
19
+ */
20
+ import type { PrentaDB } from '../db/client-types.js';
21
+ import { acceptRedirectSuggestion } from '../redirects/suggestion-accept.js';
22
+ import { type AutopilotRunSummary } from './autopilot-policy.js';
23
+ import { runOutcomeWatch } from './autopilot-outcome.js';
24
+ import { type SeoConfigOverrides } from './config-store.js';
25
+ import { applyIssueFix } from './issue-fix-apply.js';
26
+ import { generateSeoProposals } from './proposals-generate.js';
27
+ import { listSeoProposals, type SeoProposal } from './proposals.js';
28
+ /** Whole-tick wall clock, inside the 30 s function ceiling. */
29
+ export declare const AUTOPILOT_BUDGET_MS = 20000;
30
+ /**
31
+ * Grace added to the run budget before a held run lease is considered abandoned
32
+ * (a tick that died without reaching its `finally`). Below this age a second
33
+ * tick halts `already_running`; at or above it the lease is taken over.
34
+ */
35
+ export declare const AUTOPILOT_LEASE_STALE_MARGIN_MS = 10000;
36
+ /** Cap on the AI generate phase. */
37
+ export declare const AUTOPILOT_GENERATE_BUDGET_MS = 10000;
38
+ /** Wall clock that must remain for the apply phase after generate. */
39
+ export declare const AUTOPILOT_APPLY_RESERVE_MS = 5000;
40
+ /**
41
+ * Budget for the outcome watch, passed to `runOutcomeWatch` as its `deadline`:
42
+ * it stops judging rows once reached (the rest stay `pending` for the next
43
+ * tick). The in-flight row may still overrun slightly — that is logged and
44
+ * shrinks the generate window; the apply reserve holds.
45
+ */
46
+ export declare const AUTOPILOT_OUTCOME_BUDGET_MS = 3000;
47
+ /** Max issue contexts loaded per tick while scanning for deterministic-tier fixes. */
48
+ export declare const AUTOPILOT_DETERMINISTIC_SCAN_MAX = 50;
49
+ /**
50
+ * The deterministic scan stops loading issue contexts this long before the
51
+ * run deadline so the gate context build and at least one apply still fit.
52
+ */
53
+ export declare const AUTOPILOT_SCAN_DEADLINE_MARGIN_MS = 1000;
54
+ export type RestoreFieldsFn = (db: PrentaDB, collection: string, entityId: string, fields: Record<string, unknown>, actor: {
55
+ userId: string;
56
+ role: string;
57
+ }) => Promise<unknown>;
58
+ /**
59
+ * A deterministic-tier proposal carries the data-layer `patch` its suggestion
60
+ * produced, so the run can snapshot `before` without a cache lookup, and the
61
+ * issue's sticky dismissal marker so the gate can refuse it (`dismissed`).
62
+ */
63
+ export type DeterministicCandidate = SeoProposal & {
64
+ patch: Record<string, unknown>;
65
+ dismissedFingerprint?: string | null;
66
+ };
67
+ export interface DeterministicScanOptions {
68
+ now: () => number;
69
+ /** Absolute `now()` value the run must finish by; the scan stops a margin before it. */
70
+ deadline: number;
71
+ /** SEO overrides the run already loaded (`null` = no row) — never re-read per issue. */
72
+ overrides: SeoConfigOverrides | null;
73
+ }
74
+ export interface RunAutopilotDeps {
75
+ generate?: typeof generateSeoProposals;
76
+ listProposals?: typeof listSeoProposals;
77
+ applyFix?: typeof applyIssueFix;
78
+ acceptRedirect?: typeof acceptRedirectSuggestion;
79
+ restoreFields?: RestoreFieldsFn;
80
+ deterministicCandidates?: (db: PrentaDB, types: ReadonlySet<string>, opts: DeterministicScanOptions) => Promise<DeterministicCandidate[]>;
81
+ outcomeWatch?: typeof runOutcomeWatch;
82
+ }
83
+ export interface RunAutopilotOptions {
84
+ budgetMs?: number;
85
+ now?: () => number;
86
+ deps?: RunAutopilotDeps;
87
+ }
88
+ /** Ledger `path`: pathname only, no origin / query / hash, no trailing slash, root kept. */
89
+ export declare function normalizeAutopilotPath(url: string | null): string | null;
90
+ export declare function runSeoAutopilot(db: PrentaDB, opts?: RunAutopilotOptions): Promise<AutopilotRunSummary>;
91
+ //# sourceMappingURL=autopilot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autopilot.d.ts","sourceRoot":"","sources":["../../src/seo/autopilot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAWrD,OAAO,EACL,wBAAwB,EAEzB,MAAM,mCAAmC,CAAA;AAE1C,OAAO,EAIL,KAAK,mBAAmB,EAGzB,MAAM,uBAAuB,CAAA;AAe9B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAiD,MAAM,sBAAsB,CAAA;AAGnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,EAGL,gBAAgB,EAGhB,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAA;AAGvB,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,QAAS,CAAA;AACzC;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,QAAS,CAAA;AACrD,oCAAoC;AACpC,eAAO,MAAM,4BAA4B,QAAS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