@equationalapplications/core-llm-wiki 8.3.0 → 9.0.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/README.md +1 -1
- package/dist/{chunk-V432RHCG.mjs → chunk-G2H6TJUC.mjs} +1101 -132
- package/dist/chunk-G2H6TJUC.mjs.map +1 -0
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +1507 -293
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +277 -34
- package/dist/index.mjs.map +1 -1
- package/dist/{testing-BT5qSnGB.d.mts → testing-s6DBqXxQ.d.mts} +406 -36
- package/dist/{testing-BT5qSnGB.d.ts → testing-s6DBqXxQ.d.ts} +406 -36
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +521 -124
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-V432RHCG.mjs.map +0 -1
|
@@ -39,9 +39,18 @@ interface SQLiteAdapter {
|
|
|
39
39
|
}
|
|
40
40
|
interface PromptOverrides {
|
|
41
41
|
ingestSystemPrompt?: string;
|
|
42
|
-
librarianSystemPrompt?: string;
|
|
43
42
|
healSystemPrompt?: string;
|
|
44
43
|
ontologyBackfillSystemPrompt?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Short domain guidance added, in a marked section, to the prompts that
|
|
46
|
+
* author fact text (ingest, legacy librarian, ops extract), plus the
|
|
47
|
+
* general leave-out rule sentence. Database-level default; per entity,
|
|
48
|
+
* `librarian.guidanceForEntity` wins when it returns a non-empty string.
|
|
49
|
+
* Capped at 2,000 characters (UTF-16 units); over-cap guidance is not
|
|
50
|
+
* sent and emits `guidance_too_long`. Holds no secrets: it is sent to
|
|
51
|
+
* the model on every authoring call.
|
|
52
|
+
*/
|
|
53
|
+
guidance?: string;
|
|
45
54
|
}
|
|
46
55
|
type OntologyMode = 'strict' | 'emergent' | 'off';
|
|
47
56
|
interface OntologyNodeType {
|
|
@@ -257,6 +266,16 @@ interface LibrarianGateConfig {
|
|
|
257
266
|
interface LibrarianConfig {
|
|
258
267
|
strategy?: 'legacy' | 'ops';
|
|
259
268
|
gate?: LibrarianGateConfig;
|
|
269
|
+
/**
|
|
270
|
+
* Per-entity librarian guidance (specs/librarian-guidance). Returns the
|
|
271
|
+
* short domain instruction for `entityId`, or `undefined`/empty to fall
|
|
272
|
+
* back to `config.prompts.guidance`. Called synchronously once per
|
|
273
|
+
* librarian pass / ingest call; a throw or non-string return is treated
|
|
274
|
+
* as no value (fallback + `guidance_resolver_failed` diagnostic). The
|
|
275
|
+
* engine stores neither value. Lives under `librarian`, not `prompts`,
|
|
276
|
+
* so `WikiConfig.prompts` stays a struct of plain strings.
|
|
277
|
+
*/
|
|
278
|
+
guidanceForEntity?: (entityId: string) => string | undefined;
|
|
260
279
|
}
|
|
261
280
|
interface WikiConfig {
|
|
262
281
|
/**
|
|
@@ -778,11 +797,11 @@ interface VectorRanker {
|
|
|
778
797
|
* Called after a fact's embedding is successfully persisted to embedding_blob (or cleared).
|
|
779
798
|
* Hosts use this to keep sqlite-vec / external indexes consistent with SQLite as source of truth.
|
|
780
799
|
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
800
|
+
* When a fact is deleted, core records it and calls this hook with `vector: null` until it
|
|
801
|
+
* resolves once for that id, across retries, restarts and crashes. Delivery is at least once:
|
|
802
|
+
* make removal idempotent (a missing id must succeed) and do not resolve without removing.
|
|
803
|
+
* One failing id does not block the others. `forget()` throws `WikiExternalDeletionError` for
|
|
804
|
+
* ids not confirmed; `runPrune()` keeps unconfirmed rows. See the "Deleting data" guide.
|
|
786
805
|
*
|
|
787
806
|
* Treat `vector` as readonly — core provides a defensive copy, but adapters MUST NOT mutate.
|
|
788
807
|
*
|
|
@@ -804,9 +823,9 @@ type WikiDiagnosticSeverity = 'info' | 'warn' | 'error';
|
|
|
804
823
|
* Closed for this release series, but new codes are added in minor versions:
|
|
805
824
|
* hosts must tolerate codes they do not recognize.
|
|
806
825
|
*/
|
|
807
|
-
type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'contradicts_document' | 'resolve_failed' | 'read_budget' | 'event_retention_held' | 'event_created_at_clamped' | 'event_created_at_restamped';
|
|
826
|
+
type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'contradicts_document' | 'resolve_failed' | 'read_budget' | 'event_retention_held' | 'event_created_at_clamped' | 'event_created_at_restamped' | 'external_deletion_pending' | 'external_deletion_discarded' | 'guidance_too_long' | 'guidance_resolver_failed';
|
|
808
827
|
/** The service run that emitted the diagnostic. */
|
|
809
|
-
type WikiDiagnosticOperation = 'ingest' | 'upsertGraph' | 'librarian' | 'heal' | 'ontologyBackfill' | 'reembed' | 'importDump' | 'write' | 'supersede' | 'remember' | 'read' | 'prune';
|
|
828
|
+
type WikiDiagnosticOperation = 'ingest' | 'upsertGraph' | 'librarian' | 'heal' | 'ontologyBackfill' | 'reembed' | 'importDump' | 'write' | 'supersede' | 'remember' | 'read' | 'prune' | 'externalDeletion';
|
|
810
829
|
/** `'auto'` when a write threshold started the run (auto-librarian / auto-heal); `'call'` when the host did. */
|
|
811
830
|
type WikiDiagnosticTrigger = 'call' | 'auto';
|
|
812
831
|
/** Identifiers only — never titles, bodies, quotes, LLM output, provider messages, or hashes of content. */
|
|
@@ -845,12 +864,21 @@ interface WikiDiagnosticDetail {
|
|
|
845
864
|
packed?: number;
|
|
846
865
|
/** read_budget only. */
|
|
847
866
|
tokensUsed?: number;
|
|
867
|
+
/** external_deletion_pending only: epoch milliseconds (second resolution) of the oldest pending row. */
|
|
868
|
+
oldestEnqueuedAt?: number;
|
|
869
|
+
/** external_deletion_pending only: highest attempt count among pending rows. */
|
|
870
|
+
maxAttempts?: number;
|
|
871
|
+
/** guidance_too_long only: length of the refused value in UTF-16 code units. */
|
|
872
|
+
guidanceLength?: number;
|
|
873
|
+
/** guidance_too_long only: which configured value was refused. */
|
|
874
|
+
guidanceSource?: 'per_entity' | 'default';
|
|
848
875
|
}
|
|
849
876
|
interface WikiDiagnostic {
|
|
850
877
|
code: WikiDiagnosticCode;
|
|
851
878
|
severity: WikiDiagnosticSeverity;
|
|
852
879
|
operation: WikiDiagnosticOperation;
|
|
853
880
|
trigger: WikiDiagnosticTrigger;
|
|
881
|
+
/** Entity the diagnostic concerns; `''` means store-wide (e.g. the setup removal drain's `background_job_failed`). */
|
|
854
882
|
entityId: string;
|
|
855
883
|
/** Epoch ms, sampled at emission. */
|
|
856
884
|
at: number;
|
|
@@ -920,9 +948,26 @@ interface WikiOptions {
|
|
|
920
948
|
* Escape hatch: skip onEmbeddingPersisted on deletion paths entirely.
|
|
921
949
|
* Use ONLY when the ANN backend is permanently decommissioned. Vectors
|
|
922
950
|
* orphaned in the (unreachable) external index are accepted as a tradeoff.
|
|
923
|
-
*
|
|
951
|
+
* Means the index is decommissioned: no removal call is made on any path
|
|
952
|
+
* (forget, prune, heal, ingest, import), and owed removals are discarded
|
|
953
|
+
* (`external_deletion_discarded`). NOT GDPR-safe for live indexes. Default false.
|
|
924
954
|
*/
|
|
925
955
|
forceDeleteIgnoreRankerHook?: boolean;
|
|
956
|
+
/**
|
|
957
|
+
* Opt in to a background drain of owed removals after `setup()`: when a
|
|
958
|
+
* removal hook is configured and removals are owed, `setup()` starts one
|
|
959
|
+
* drain (not awaited; `drain()` joins it, 10 s deadline, backoff).
|
|
960
|
+
*
|
|
961
|
+
* Default false. The drain opens short transactions on the connection you
|
|
962
|
+
* gave `createWiki`; a transaction you open on that connection yourself (for
|
|
963
|
+
* example `db.withTransactionAsync(tx => wiki.upsertGraph(…, tx))`) throws
|
|
964
|
+
* "cannot start a transaction within a transaction" while one of them is
|
|
965
|
+
* open. Turn it on only if you never open your own transactions on it.
|
|
966
|
+
* When off, `setup()` emits `external_deletion_pending` per entity with
|
|
967
|
+
* owed removals. `runPendingMaintenance()` and `runExternalDeletions()`
|
|
968
|
+
* deliver them; `forget()` and `runPrune()` deliver the ids they touch.
|
|
969
|
+
*/
|
|
970
|
+
drainExternalDeletionsOnSetup?: boolean;
|
|
926
971
|
/**
|
|
927
972
|
* Receives typed, content-free diagnostics for events core previously
|
|
928
973
|
* dropped silently or only logged (spec §4). Synchronous; a returned promise
|
|
@@ -1007,6 +1052,26 @@ declare class WikiBusyError extends Error {
|
|
|
1007
1052
|
readonly entityId: string;
|
|
1008
1053
|
constructor(operation: WikiBusyOperation, entityId: string);
|
|
1009
1054
|
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Thrown by forget() when the external vector index has not confirmed the
|
|
1057
|
+
* removal of every selected id. The local delete stays committed and the
|
|
1058
|
+
* unconfirmed ids stay owed in the ledger.
|
|
1059
|
+
*/
|
|
1060
|
+
declare class WikiExternalDeletionError extends Error {
|
|
1061
|
+
readonly code: "WIKI_EXTERNAL_DELETION";
|
|
1062
|
+
readonly entityId: string;
|
|
1063
|
+
/** At most 100 ids; see unconfirmedCount for the full count. */
|
|
1064
|
+
readonly unconfirmedIds: string[];
|
|
1065
|
+
readonly unconfirmedCount: number;
|
|
1066
|
+
readonly timedOut: boolean;
|
|
1067
|
+
constructor(message: string, params: {
|
|
1068
|
+
entityId: string;
|
|
1069
|
+
unconfirmedIds: string[];
|
|
1070
|
+
unconfirmedCount: number;
|
|
1071
|
+
timedOut: boolean;
|
|
1072
|
+
cause?: Error;
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1010
1075
|
/**
|
|
1011
1076
|
* Thrown by `ingestDocument({ onDuplicateHash: 'throw' })` when a different
|
|
1012
1077
|
* source_ref in the same entity already holds the supplied source_hash against
|
|
@@ -1123,6 +1188,13 @@ interface ForgetResult {
|
|
|
1123
1188
|
};
|
|
1124
1189
|
metadataReset?: boolean;
|
|
1125
1190
|
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Thrown by `runPrune()` after it has finished its other work, when the host's
|
|
1193
|
+
* removal hook did not confirm some prunable facts. Those rows are kept, every
|
|
1194
|
+
* other prunable row is hard-deleted. The deleted and kept rows are not
|
|
1195
|
+
* contiguous: `deleted` counts rows hard-deleted, `remaining` counts rows kept,
|
|
1196
|
+
* and `failedAt` names the first unconfirmed id in drain order.
|
|
1197
|
+
*/
|
|
1126
1198
|
declare class PrunePartialFailureError extends Error {
|
|
1127
1199
|
readonly deleted: number;
|
|
1128
1200
|
readonly failedAt: string;
|
|
@@ -1313,7 +1385,9 @@ interface WikiInstructions {
|
|
|
1313
1385
|
heal: string;
|
|
1314
1386
|
ontologyBackfill: string;
|
|
1315
1387
|
}
|
|
1316
|
-
type MaintenanceJob = 'librarian' | 'heal' | 'reembed';
|
|
1388
|
+
type MaintenanceJob = 'librarian' | 'heal' | 'reembed' | 'externalDeletions';
|
|
1389
|
+
/** The jobs that hold a per-entity lock (everything but `externalDeletions`). */
|
|
1390
|
+
type LockedMaintenanceJob = Exclude<MaintenanceJob, 'externalDeletions'>;
|
|
1317
1391
|
interface PendingMaintenance {
|
|
1318
1392
|
entityId: string;
|
|
1319
1393
|
/** Events after the librarian watermark. */
|
|
@@ -1328,6 +1402,8 @@ interface PendingMaintenance {
|
|
|
1328
1402
|
* Always false without `embed`.
|
|
1329
1403
|
*/
|
|
1330
1404
|
reembedPending: boolean;
|
|
1405
|
+
/** Removals still owed to the host's vector index for this entity (absent when none). */
|
|
1406
|
+
pendingExternalDeletions?: number;
|
|
1331
1407
|
}
|
|
1332
1408
|
interface RunPendingMaintenanceOptions {
|
|
1333
1409
|
/** Default: every entity with pending work. */
|
|
@@ -1336,7 +1412,7 @@ interface RunPendingMaintenanceOptions {
|
|
|
1336
1412
|
tokenBudget?: number;
|
|
1337
1413
|
/** Wall-clock milliseconds from the call. Checked between units; a unit in flight is never interrupted. */
|
|
1338
1414
|
deadlineMs?: number;
|
|
1339
|
-
/** Default all
|
|
1415
|
+
/** Default all four. `externalDeletions` runs first and is not metered by `tokenBudget`. */
|
|
1340
1416
|
jobs?: MaintenanceJob[];
|
|
1341
1417
|
}
|
|
1342
1418
|
type MaintenanceStopReason = {
|
|
@@ -1358,13 +1434,13 @@ interface EntityMaintenanceReport {
|
|
|
1358
1434
|
healPasses: number;
|
|
1359
1435
|
reembedded: boolean;
|
|
1360
1436
|
/** Set when a lock was held elsewhere; nothing ran for that job. */
|
|
1361
|
-
busy?:
|
|
1437
|
+
busy?: LockedMaintenanceJob[];
|
|
1362
1438
|
/**
|
|
1363
1439
|
* Set when keyword search is unavailable and the job could not run for this
|
|
1364
1440
|
* entity (spec #280). Its watermark/checkpoint is kept; retry after
|
|
1365
1441
|
* `syncSearchIndex()` restores keyword search.
|
|
1366
1442
|
*/
|
|
1367
|
-
searchUnavailable?:
|
|
1443
|
+
searchUnavailable?: LockedMaintenanceJob[];
|
|
1368
1444
|
}
|
|
1369
1445
|
interface RunPendingMaintenanceResult {
|
|
1370
1446
|
perEntity: EntityMaintenanceReport[];
|
|
@@ -1374,6 +1450,11 @@ interface RunPendingMaintenanceResult {
|
|
|
1374
1450
|
/** null when no tokenBudget was given. */
|
|
1375
1451
|
remaining: number | null;
|
|
1376
1452
|
stoppedReason: MaintenanceStopReason;
|
|
1453
|
+
/** Vector-index removals this run confirmed, and those still owed (all entities in scope). */
|
|
1454
|
+
externalDeletions: {
|
|
1455
|
+
confirmed: number;
|
|
1456
|
+
pending: number;
|
|
1457
|
+
};
|
|
1377
1458
|
}
|
|
1378
1459
|
type MigrationPolicy = 'allow' | 'refuse' | 'auto';
|
|
1379
1460
|
/** Work the migration gate found pending on an existing store. Watermarks are resume rowids (0 = not started). */
|
|
@@ -1687,7 +1768,10 @@ declare class EntryRepository extends BaseRepository {
|
|
|
1687
1768
|
* Used by runPrune(). Returns total number of deleted rows.
|
|
1688
1769
|
* `tx` is REQUIRED so outbox deletion events are staged atomically.
|
|
1689
1770
|
*/
|
|
1690
|
-
bulkDeletePruned(entityId: string, cutoff: number, ids: string[], tx: SQLiteAdapter
|
|
1771
|
+
bulkDeletePruned(entityId: string, cutoff: number, ids: string[], tx: SQLiteAdapter, opts?: {
|
|
1772
|
+
keepUnconfirmedRemovals?: boolean;
|
|
1773
|
+
deletedIds?: string[];
|
|
1774
|
+
}): Promise<number>;
|
|
1691
1775
|
/**
|
|
1692
1776
|
* Mark orphaned entries (never accessed, old) as deleted.
|
|
1693
1777
|
* Used by MaintenanceService.doRunHeal().
|
|
@@ -1755,7 +1839,10 @@ declare class EntryRepository extends BaseRepository {
|
|
|
1755
1839
|
body: string;
|
|
1756
1840
|
tags: string;
|
|
1757
1841
|
}>>;
|
|
1758
|
-
|
|
1842
|
+
/** Returns `changes: 0` when the row is soft-deleted or gone (spec durable-vector-removal §5.7, G10). */
|
|
1843
|
+
updateEmbeddingBlob(id: string, blob: Uint8Array, tx?: SQLiteAdapter): Promise<{
|
|
1844
|
+
changes: number;
|
|
1845
|
+
}>;
|
|
1759
1846
|
/**
|
|
1760
1847
|
* Record a failed embedding attempt. Deliberately does NOT touch updated_at
|
|
1761
1848
|
* (import merge is last-write-wins on it) and pushes no outbox event —
|
|
@@ -2102,7 +2189,7 @@ interface IndexSearchResult {
|
|
|
2102
2189
|
entity_id: string;
|
|
2103
2190
|
}
|
|
2104
2191
|
/** One drain turn's shape (spec #280 Change 3 "drain interface"). */
|
|
2105
|
-
interface DrainOptions {
|
|
2192
|
+
interface DrainOptions$1 {
|
|
2106
2193
|
/** `monotonicNow()` timestamp, checked between chunk transactions. Full mode only; default now + the strategy's budget. */
|
|
2107
2194
|
deadline?: number;
|
|
2108
2195
|
/**
|
|
@@ -2199,7 +2286,7 @@ interface IndexStrategy {
|
|
|
2199
2286
|
* called from inside a `withTransactionAsync` callback; it opens its own
|
|
2200
2287
|
* transactions.
|
|
2201
2288
|
*/
|
|
2202
|
-
drain?(opts?: DrainOptions): Promise<void>;
|
|
2289
|
+
drain?(opts?: DrainOptions$1): Promise<void>;
|
|
2203
2290
|
}
|
|
2204
2291
|
|
|
2205
2292
|
interface ScoredRow {
|
|
@@ -2592,7 +2679,135 @@ declare class EdgeRepository extends BaseRepository {
|
|
|
2592
2679
|
}>;
|
|
2593
2680
|
}
|
|
2594
2681
|
|
|
2595
|
-
|
|
2682
|
+
interface LedgerRow {
|
|
2683
|
+
seq: number;
|
|
2684
|
+
entity_id: string;
|
|
2685
|
+
fact_id: string;
|
|
2686
|
+
attempts: number;
|
|
2687
|
+
last_attempt_at: number | null;
|
|
2688
|
+
fact_state: 'live' | 'deleted' | 'gone';
|
|
2689
|
+
}
|
|
2690
|
+
interface VectorRemovalScope {
|
|
2691
|
+
entityId?: string;
|
|
2692
|
+
ids?: string[];
|
|
2693
|
+
}
|
|
2694
|
+
interface VectorRemovalCursor {
|
|
2695
|
+
maxSeq: number;
|
|
2696
|
+
attempts: number;
|
|
2697
|
+
seq: number;
|
|
2698
|
+
}
|
|
2699
|
+
/**
|
|
2700
|
+
* Ledger of facts whose vectors the host's external index still owes a
|
|
2701
|
+
* removal for (spec durable-vector-removal §5.1). Rows are enqueued by
|
|
2702
|
+
* triggers on `entries`; this class reads and settles them.
|
|
2703
|
+
*/
|
|
2704
|
+
declare class VectorRemovalRepository extends BaseRepository {
|
|
2705
|
+
/** Name of the ledger table. */
|
|
2706
|
+
get ledgerTable(): string;
|
|
2707
|
+
/** Whether `factId` exists and is not soft-deleted. */
|
|
2708
|
+
isLive(factId: string): Promise<boolean>;
|
|
2709
|
+
/**
|
|
2710
|
+
* Owe the host a removal for `factId` unless a live row exists (a missing row
|
|
2711
|
+
* counts as not live). The liveness test is part of the write, so it is
|
|
2712
|
+
* atomic. Returns whether a row was enqueued.
|
|
2713
|
+
*/
|
|
2714
|
+
enqueueIfNotLive(entityId: string, factId: string, now: number): Promise<boolean>;
|
|
2715
|
+
/** Unconfirmed rows after `cursor`, ordered by (attempts, seq). */
|
|
2716
|
+
readPage(scope: VectorRemovalScope, cursor: VectorRemovalCursor, limit: number, tx: SQLiteAdapter): Promise<LedgerRow[]>;
|
|
2717
|
+
maxSeq(tx?: SQLiteAdapter): Promise<number>;
|
|
2718
|
+
/** Returns the number of rows changed. */
|
|
2719
|
+
confirm(seqs: number[], now: number, tx: SQLiteAdapter): Promise<number>;
|
|
2720
|
+
bumpAttempts(seqs: number[], now: number, tx: SQLiteAdapter): Promise<void>;
|
|
2721
|
+
/** Delete the given rows when they are confirmed and their fact row is gone. */
|
|
2722
|
+
deleteConfirmedGone(seqs: number[], tx: SQLiteAdapter): Promise<void>;
|
|
2723
|
+
/** For stale, gone or resurrected rows. Applies to the given seqs only. */
|
|
2724
|
+
deleteBySeq(seqs: number[], tx: SQLiteAdapter): Promise<number>;
|
|
2725
|
+
/** Unconfirmed rows of `entityId` among `ids`. */
|
|
2726
|
+
pendingCountForIds(entityId: string, ids: string[]): Promise<number>;
|
|
2727
|
+
/** Enqueue ids that have no row yet. Returns the number inserted. */
|
|
2728
|
+
backstopEnqueue(entityId: string, ids: string[], now: number, tx: SQLiteAdapter): Promise<number>;
|
|
2729
|
+
/**
|
|
2730
|
+
* Remove rows together with a hard delete of the facts. `'all'` drops every
|
|
2731
|
+
* row of those ids; `'confirmedGone'` drops only confirmed rows whose fact
|
|
2732
|
+
* row no longer exists, so a removal re-owed meanwhile is never erased.
|
|
2733
|
+
*/
|
|
2734
|
+
deleteForFacts(entityId: string, ids: string[], tx: SQLiteAdapter, mode?: 'all' | 'confirmedGone'): Promise<void>;
|
|
2735
|
+
/** Drop unconfirmed rows. Returns the count removed. */
|
|
2736
|
+
discardPending(entityId?: string, tx?: SQLiteAdapter): Promise<number>;
|
|
2737
|
+
pendingStats(entityId?: string): Promise<{
|
|
2738
|
+
count: number;
|
|
2739
|
+
oldestEnqueuedAt: number | null;
|
|
2740
|
+
maxAttempts: number;
|
|
2741
|
+
}>;
|
|
2742
|
+
entitiesWithPending(): Promise<string[]>;
|
|
2743
|
+
/**
|
|
2744
|
+
* Entities with at least one pending row outside backoff (never attempted,
|
|
2745
|
+
* or last attempted longer ago than removalBackoffMs). Same rule as the drain.
|
|
2746
|
+
*/
|
|
2747
|
+
entitiesWithDuePending(now: number): Promise<string[]>;
|
|
2748
|
+
statusFor(ids: string[], tx?: SQLiteAdapter): Promise<Map<string, 'pending' | 'confirmed'>>;
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
type DrainScope = {
|
|
2752
|
+
entityId: string;
|
|
2753
|
+
ids?: string[];
|
|
2754
|
+
} | {
|
|
2755
|
+
all: true;
|
|
2756
|
+
};
|
|
2757
|
+
interface DrainResult {
|
|
2758
|
+
confirmed: number;
|
|
2759
|
+
pending: number;
|
|
2760
|
+
failedIds: string[];
|
|
2761
|
+
timedOut: boolean;
|
|
2762
|
+
/** Fact id of the call that timed out, when known. */
|
|
2763
|
+
timedOutId?: string;
|
|
2764
|
+
/** True when a page read or a settling write failed; rows stay pending. */
|
|
2765
|
+
transient?: boolean;
|
|
2766
|
+
firstCause?: Error;
|
|
2767
|
+
}
|
|
2768
|
+
interface DrainOptions {
|
|
2769
|
+
/** Absolute `Date.now()` time after which no further calls are made. */
|
|
2770
|
+
deadlineAt?: number;
|
|
2771
|
+
backoff?: boolean;
|
|
2772
|
+
trigger?: WikiDiagnosticTrigger;
|
|
2773
|
+
}
|
|
2774
|
+
/** Drains the vector_removals ledger through the host's removal hook (spec §5.3-5.4). */
|
|
2775
|
+
declare class VectorRemovalService {
|
|
2776
|
+
private db;
|
|
2777
|
+
private options;
|
|
2778
|
+
private repo;
|
|
2779
|
+
private embeddingService;
|
|
2780
|
+
private metadataRepo;
|
|
2781
|
+
private inFlight;
|
|
2782
|
+
constructor(db: SQLiteAdapter, options: WikiOptions, repo: VectorRemovalRepository, embeddingService: EmbeddingService, metadataRepo: MetadataRepository);
|
|
2783
|
+
gate(): 'hook' | 'none' | 'force';
|
|
2784
|
+
private ledgerSeen;
|
|
2785
|
+
ledgerPresent(): Promise<boolean>;
|
|
2786
|
+
/** One `hook_failed` diagnostic per id (the removal stays owed). */
|
|
2787
|
+
emitHookFailed(entityId: string, ids: string[], operation: WikiDiagnosticOperation, trigger: WikiDiagnosticTrigger): void;
|
|
2788
|
+
/**
|
|
2789
|
+
* Post-commit delivery for heal, ingest and import (spec §5.7). Never throws:
|
|
2790
|
+
* a failed id emits `hook_failed` and stays owed on the ledger. Without a
|
|
2791
|
+
* ledger table (setup never ran) it falls back to a best-effort call per id.
|
|
2792
|
+
* Under `forceDeleteIgnoreRankerHook` no removal call is made.
|
|
2793
|
+
*/
|
|
2794
|
+
deliverRemovals(entityId: string, ids: string[], operation: WikiDiagnosticOperation, trigger: WikiDiagnosticTrigger, fallbackIds?: string[]): Promise<void>;
|
|
2795
|
+
markExternalIndexInUse(tx: SQLiteAdapter): Promise<void>;
|
|
2796
|
+
clearExternalIndexMarker(): Promise<void>;
|
|
2797
|
+
externalIndexInUse(): Promise<boolean>;
|
|
2798
|
+
drain(scope: DrainScope, opts?: DrainOptions): Promise<DrainResult>;
|
|
2799
|
+
/**
|
|
2800
|
+
* Makes the removal call for `row`, or joins another drain's call for the
|
|
2801
|
+
* same seq. Never throws: the outcome says whether it succeeded, whether
|
|
2802
|
+
* this drain joined (only the owner bumps attempts on failure), and whether
|
|
2803
|
+
* the failure was a timeout.
|
|
2804
|
+
*/
|
|
2805
|
+
private callFor;
|
|
2806
|
+
private pendingFor;
|
|
2807
|
+
emitPending(entityId: string | undefined, trigger: WikiDiagnosticTrigger): Promise<void>;
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
type EmbedFailureKind = EmbeddingMarkerKind | 'no_provider' | 'storage_error' | 'fact_deleted';
|
|
2596
2811
|
type EmbedFactResult = {
|
|
2597
2812
|
ok: true;
|
|
2598
2813
|
dimension: number;
|
|
@@ -2674,13 +2889,21 @@ declare class EmbeddingService {
|
|
|
2674
2889
|
}>;
|
|
2675
2890
|
/**
|
|
2676
2891
|
* Storage half: persist the computed vector to the entry row, then fire the
|
|
2677
|
-
* `onEmbeddingPersisted` hook. Failure kinds: `storage_error`
|
|
2678
|
-
*
|
|
2892
|
+
* `onEmbeddingPersisted` hook. Failure kinds: `storage_error` (a DB error) and
|
|
2893
|
+
* `fact_deleted` (the row was soft-deleted or gone: no blob, no vector call, no
|
|
2894
|
+
* marker). Embed failures do not originate here, so they cannot be marked as
|
|
2895
|
+
* such (spec §3.2, D3).
|
|
2679
2896
|
*/
|
|
2680
2897
|
storeFactVector(fact: {
|
|
2681
2898
|
id: string;
|
|
2682
2899
|
entity_id: string;
|
|
2683
2900
|
}, float32Vector: Float32Array, ctx?: EmbedDiagnosticContext): Promise<EmbedFactResult>;
|
|
2901
|
+
hasVectorHook(): boolean;
|
|
2902
|
+
/**
|
|
2903
|
+
* Run after a vector call (resolved or not) by every path that sends one.
|
|
2904
|
+
* Never throws: a failure here leaves the removal owed or unrecorded, as before.
|
|
2905
|
+
*/
|
|
2906
|
+
settleAfterVectorCall(entityId: string, factId: string, operation: WikiDiagnosticOperation, trigger: WikiDiagnosticTrigger): Promise<void>;
|
|
2684
2907
|
private reportEmbed;
|
|
2685
2908
|
/** For callers that invoke `notifyEmbeddingPersisted` directly and catch its failure. */
|
|
2686
2909
|
reportHookFailed(ctx: EmbedDiagnosticContext, entityId: string, factId: string): void;
|
|
@@ -2698,7 +2921,43 @@ declare class EmbeddingService {
|
|
|
2698
2921
|
body: string;
|
|
2699
2922
|
tags: string | string[];
|
|
2700
2923
|
}, ctx?: EmbedDiagnosticContext): Promise<boolean>;
|
|
2924
|
+
private vectorRemoval?;
|
|
2925
|
+
/** Wired by WikiMemory (VectorRemovalService itself depends on this class). */
|
|
2926
|
+
attachVectorRemoval(service: VectorRemovalService, repo: VectorRemovalRepository): void;
|
|
2927
|
+
/**
|
|
2928
|
+
* After an embed (and its vector call) settles: owe a removal if the fact is
|
|
2929
|
+
* no longer live, so a vector the host just received is taken back (§5.7, G10).
|
|
2930
|
+
* Never throws. `'enqueued'`: a ledger row was written. `'none'`: no
|
|
2931
|
+
* removal hook (or the hook gate is off). `'live'`: the fact is live. A row already pending is
|
|
2932
|
+
* replaced (attempts reset, spec §5.2), so it counts as `'enqueued'` and
|
|
2933
|
+
* is sent now: the last call the host sees after this vector is `null`.
|
|
2934
|
+
* `'owed'`: the write failed but a pending row already holds the removal.
|
|
2935
|
+
* `'write_failed'`: the fact is known not live, the write failed, and its
|
|
2936
|
+
* row is confirmed or missing; or the store has no ledger table and the
|
|
2937
|
+
* fact is known not live.
|
|
2938
|
+
* `'unknown'`: the liveness read and the guarded write both failed.
|
|
2939
|
+
*/
|
|
2940
|
+
private recordAfterVectorCall;
|
|
2701
2941
|
notifyEmbeddingPersisted(entityId: string, factId: string, vector: Float32Array | null): Promise<void>;
|
|
2942
|
+
validateDeletionTimeout(): number;
|
|
2943
|
+
/** Send a removal (`vector: null`) to the hook. No gate check; the caller owns the gate. */
|
|
2944
|
+
callRemovalHook(entityId: string, factId: string, timeoutMs: number): Promise<void>;
|
|
2945
|
+
/**
|
|
2946
|
+
* One removal call per id for a store with no ledger table (setup() never
|
|
2947
|
+
* ran), so nothing records what is owed (spec §5.5.5). Stops at the first
|
|
2948
|
+
* timeout: a dead index costs one timeout, as in a drain (spec rev 5).
|
|
2949
|
+
* `failed` lists the ids not confirmed, in order; after a timeout it ends
|
|
2950
|
+
* with the timed-out id and every id after it. Throws only for an invalid
|
|
2951
|
+
* `deletionHookTimeoutMs`.
|
|
2952
|
+
*/
|
|
2953
|
+
callRemovalHookEach(entityId: string, ids: readonly string[], opts?: {
|
|
2954
|
+
warn?: boolean;
|
|
2955
|
+
}): Promise<{
|
|
2956
|
+
failed: string[];
|
|
2957
|
+
timedOut: boolean;
|
|
2958
|
+
timedOutId?: string;
|
|
2959
|
+
cause?: unknown;
|
|
2960
|
+
}>;
|
|
2702
2961
|
notifyEmbeddingPersistedOrThrow(entityId: string, factId: string, vector: Float32Array | null): Promise<void>;
|
|
2703
2962
|
}
|
|
2704
2963
|
|
|
@@ -2771,25 +3030,58 @@ type LabeledEvent = {
|
|
|
2771
3030
|
at: number;
|
|
2772
3031
|
};
|
|
2773
3032
|
|
|
3033
|
+
/** Why a pass or call will not carry guidance (specs/librarian-guidance). */
|
|
3034
|
+
interface GuidanceDiagnostic {
|
|
3035
|
+
code: 'guidance_too_long' | 'guidance_resolver_failed';
|
|
3036
|
+
detail?: {
|
|
3037
|
+
guidanceLength?: number;
|
|
3038
|
+
guidanceSource?: 'per_entity' | 'default';
|
|
3039
|
+
reason?: 'threw' | 'non_string';
|
|
3040
|
+
};
|
|
3041
|
+
}
|
|
3042
|
+
|
|
2774
3043
|
declare class PromptService {
|
|
2775
3044
|
private globalOverrides?;
|
|
2776
3045
|
private grounding;
|
|
2777
3046
|
constructor(globalOverrides?: PromptOverrides | undefined, grounding?: ResolvedGrounding | null);
|
|
3047
|
+
/**
|
|
3048
|
+
* Specs/librarian-guidance: resolve the effective guidance for one pass
|
|
3049
|
+
* or call — default `config.prompts.guidance`, per-entity
|
|
3050
|
+
* `config.librarian.guidanceForEntity` winning when it returns a
|
|
3051
|
+
* non-empty (trimmed) string. Synchronous: a resolver that throws,
|
|
3052
|
+
* returns a thenable (its rejection is swallowed with a no-op handler;
|
|
3053
|
+
* a throwing `then` counts too), or returns any non-string value is
|
|
3054
|
+
* treated as "no value" and reported in `diagnostic`. Over-cap text
|
|
3055
|
+
* (UTF-16 units, verbatim) is not sent and reported in `diagnostic`.
|
|
3056
|
+
* Emits nothing itself; the caller emits, immediately at resolution.
|
|
3057
|
+
*/
|
|
3058
|
+
static resolveGuidance(config: WikiConfig | undefined, entityId: string): {
|
|
3059
|
+
guidance?: string;
|
|
3060
|
+
diagnostic?: GuidanceDiagnostic;
|
|
3061
|
+
};
|
|
2778
3062
|
/** The resolved grounding config when `writer` is in `grounding.writers`; otherwise null (spec §6.2). */
|
|
2779
3063
|
groundingFor(writer: GroundingWriter): ResolvedGrounding | null;
|
|
2780
3064
|
/** Appended after any override and after ontology context, so it is always last. */
|
|
2781
3065
|
private appendGrounding;
|
|
3066
|
+
/**
|
|
3067
|
+
* Specs/librarian-guidance: append the marked guidance section (with the
|
|
3068
|
+
* general leave-out rule) to the ALREADY-HYDRATED system prompt — after
|
|
3069
|
+
* ontology, immediately before grounding. The guidance text is never
|
|
3070
|
+
* run through hydration, so `{{…}}` inside it cannot change a builder's
|
|
3071
|
+
* template branch or be expanded with data. No-op on empty input.
|
|
3072
|
+
*/
|
|
3073
|
+
private appendGuidance;
|
|
2782
3074
|
private hydrate;
|
|
2783
3075
|
private hasOntologyPlaceholders;
|
|
2784
3076
|
/** Removes ontology placeholders until none remain, so a nested form cannot reassemble one (closes CodeQL #11). */
|
|
2785
3077
|
private stripOntologyPlaceholders;
|
|
2786
3078
|
private buildSystemPrompt;
|
|
2787
3079
|
private appendOntology;
|
|
2788
|
-
buildIngestPrompt(documentChunk: string, runtimeOverride?: string, ontologyContext?: OntologyPromptContext | null): {
|
|
3080
|
+
buildIngestPrompt(documentChunk: string, runtimeOverride?: string, ontologyContext?: OntologyPromptContext | null, guidance?: string): {
|
|
2789
3081
|
systemPrompt: string;
|
|
2790
3082
|
userPrompt: string;
|
|
2791
3083
|
};
|
|
2792
|
-
buildLibrarianPrompt(events: unknown[], currentFacts: unknown[], runtimeOverride?: string, ontologyContext?: OntologyPromptContext | null): {
|
|
3084
|
+
buildLibrarianPrompt(events: unknown[], currentFacts: unknown[], runtimeOverride?: string, ontologyContext?: OntologyPromptContext | null, guidance?: string): {
|
|
2793
3085
|
systemPrompt: string;
|
|
2794
3086
|
userPrompt: string;
|
|
2795
3087
|
groundingCorpus?: string[];
|
|
@@ -2829,7 +3121,7 @@ declare class PromptService {
|
|
|
2829
3121
|
userPrompt: string;
|
|
2830
3122
|
};
|
|
2831
3123
|
/** Ops extract (spec §5.2): events only — no existing facts. */
|
|
2832
|
-
buildOpsExtractPrompt(events: LabeledEvent[], ontologyContext?: OntologyPromptContext | null): {
|
|
3124
|
+
buildOpsExtractPrompt(events: LabeledEvent[], ontologyContext?: OntologyPromptContext | null, guidance?: string): {
|
|
2833
3125
|
systemPrompt: string;
|
|
2834
3126
|
userPrompt: string;
|
|
2835
3127
|
groundingCorpus?: string[];
|
|
@@ -2856,7 +3148,7 @@ declare class PromptService {
|
|
|
2856
3148
|
* placeholders and leaves data placeholders verbatim; heal never receives
|
|
2857
3149
|
* ontology context, matching `buildHealPrompt`.
|
|
2858
3150
|
*/
|
|
2859
|
-
buildInstructionTemplates(ontologyContext: OntologyPromptContext | null, librarianStrategy: 'legacy' | 'ops'): WikiInstructions;
|
|
3151
|
+
buildInstructionTemplates(ontologyContext: OntologyPromptContext | null, librarianStrategy: 'legacy' | 'ops', guidance?: string): WikiInstructions;
|
|
2860
3152
|
}
|
|
2861
3153
|
|
|
2862
3154
|
declare class IngestionService {
|
|
@@ -2871,8 +3163,9 @@ declare class IngestionService {
|
|
|
2871
3163
|
private jobManager;
|
|
2872
3164
|
private embeddingService;
|
|
2873
3165
|
private ontologyService?;
|
|
3166
|
+
private vectorRemoval?;
|
|
2874
3167
|
private promptService;
|
|
2875
|
-
constructor(db: SQLiteAdapter, prefix: string, options: WikiOptions, entryRepo: EntryRepository, sourceRefIndexRepo: SourceRefIndexRepository, metadataRepo: MetadataRepository, edgeRepo: EdgeRepository, searchService: SearchService, jobManager: JobManager, embeddingService: EmbeddingService, promptService?: PromptService, ontologyService?: OntologyService | undefined);
|
|
3168
|
+
constructor(db: SQLiteAdapter, prefix: string, options: WikiOptions, entryRepo: EntryRepository, sourceRefIndexRepo: SourceRefIndexRepository, metadataRepo: MetadataRepository, edgeRepo: EdgeRepository, searchService: SearchService, jobManager: JobManager, embeddingService: EmbeddingService, promptService?: PromptService, ontologyService?: OntologyService | undefined, vectorRemoval?: VectorRemovalService | undefined);
|
|
2876
3169
|
ingestDocument(entityId: string, params: {
|
|
2877
3170
|
sourceRef: string;
|
|
2878
3171
|
sourceHash: string;
|
|
@@ -3198,6 +3491,14 @@ interface LibrarianContext {
|
|
|
3198
3491
|
entityId: string;
|
|
3199
3492
|
trigger: WikiDiagnosticTrigger;
|
|
3200
3493
|
promptOverride?: string;
|
|
3494
|
+
/**
|
|
3495
|
+
* Specs/librarian-guidance: the effective guidance for this pass, resolved
|
|
3496
|
+
* by `MaintenanceService.runLibrarianPass` (never read as caller input —
|
|
3497
|
+
* that method overwrites whatever a caller supplies here, so "resolved
|
|
3498
|
+
* once per pass" holds for every caller). Strategies pass it to the
|
|
3499
|
+
* prompt builders verbatim.
|
|
3500
|
+
*/
|
|
3501
|
+
guidance?: string;
|
|
3201
3502
|
/** Optional meter (Phase C budgeted maintenance). Legacy honors it:
|
|
3202
3503
|
* `callLlm` pre-flights the prompt estimate against it, usage is recorded
|
|
3203
3504
|
* on every call, and the pass returns `budgetStop` when the budget is
|
|
@@ -3256,8 +3557,10 @@ declare class MaintenanceService {
|
|
|
3256
3557
|
private jobManager;
|
|
3257
3558
|
private embeddingService;
|
|
3258
3559
|
private ontologyService?;
|
|
3560
|
+
private vectorRemoval?;
|
|
3561
|
+
private vectorRemovalRepo?;
|
|
3259
3562
|
private promptService;
|
|
3260
|
-
constructor(db: SQLiteAdapter, prefix: string, options: WikiOptions, entryRepo: EntryRepository, sourceRefIndexRepo: SourceRefIndexRepository, taskRepo: TaskRepository, eventRepo: EventRepository, metadataRepo: MetadataRepository, searchService: SearchService, jobManager: JobManager, embeddingService: EmbeddingService, promptService?: PromptService, ontologyService?: OntologyService | undefined, edgeRepo?: EdgeRepository);
|
|
3563
|
+
constructor(db: SQLiteAdapter, prefix: string, options: WikiOptions, entryRepo: EntryRepository, sourceRefIndexRepo: SourceRefIndexRepository, taskRepo: TaskRepository, eventRepo: EventRepository, metadataRepo: MetadataRepository, searchService: SearchService, jobManager: JobManager, embeddingService: EmbeddingService, promptService?: PromptService, ontologyService?: OntologyService | undefined, edgeRepo?: EdgeRepository, vectorRemoval?: VectorRemovalService | undefined, vectorRemovalRepo?: VectorRemovalRepository | undefined);
|
|
3261
3564
|
private edgeRepo;
|
|
3262
3565
|
runPrune(entityId: string, options?: {
|
|
3263
3566
|
retainSoftDeletedFor?: number | null;
|
|
@@ -3310,6 +3613,8 @@ declare class MaintenanceService {
|
|
|
3310
3613
|
forget(entityId: string, params: ForgetParams, opts?: {
|
|
3311
3614
|
dryRun?: boolean;
|
|
3312
3615
|
}): Promise<ForgetResult>;
|
|
3616
|
+
/** Heal's post-commit removal delivery (spec §5.7). Never throws. */
|
|
3617
|
+
private deliverHealRemovals;
|
|
3313
3618
|
/**
|
|
3314
3619
|
* Whether forget() should soft-delete in source_ref_index (#316,
|
|
3315
3620
|
* specs/forget-pre-v9 §3.1). Normally true: setup()'s DDL creates the table.
|
|
@@ -3471,7 +3776,9 @@ declare class MaintenanceScheduler {
|
|
|
3471
3776
|
private eventRepo;
|
|
3472
3777
|
private entryRepo;
|
|
3473
3778
|
private jobManager;
|
|
3474
|
-
|
|
3779
|
+
private vectorRemovalService;
|
|
3780
|
+
private vectorRemovalRepo;
|
|
3781
|
+
constructor(db: SQLiteAdapter, options: WikiOptions, maintenanceService: MaintenanceService, metadataRepo: MetadataRepository, eventRepo: EventRepository, entryRepo: EntryRepository, jobManager: JobManager, vectorRemovalService: VectorRemovalService, vectorRemovalRepo: VectorRemovalRepository);
|
|
3475
3782
|
/**
|
|
3476
3783
|
* Entities with **any** pending work only, sorted by `pendingEvents` desc
|
|
3477
3784
|
* then `entityId` asc. Token estimate is ceil(pending summary chars / 4),
|
|
@@ -3493,6 +3800,12 @@ declare class MaintenanceScheduler {
|
|
|
3493
3800
|
* only; embeddings are never metered.
|
|
3494
3801
|
*/
|
|
3495
3802
|
run(opts?: RunPendingMaintenanceOptions): Promise<RunPendingMaintenanceResult>;
|
|
3803
|
+
/**
|
|
3804
|
+
* Runs first and outside the token budget: delivers owed vector-index
|
|
3805
|
+
* removals per entity (wiped entities included), without backoff. Pending is
|
|
3806
|
+
* reported even when the job is not listed or no hook is configured.
|
|
3807
|
+
*/
|
|
3808
|
+
private runExternalDeletions;
|
|
3496
3809
|
}
|
|
3497
3810
|
|
|
3498
3811
|
declare class ImportExportService {
|
|
@@ -3506,7 +3819,8 @@ declare class ImportExportService {
|
|
|
3506
3819
|
private jobManager;
|
|
3507
3820
|
private embeddingService;
|
|
3508
3821
|
private options;
|
|
3509
|
-
|
|
3822
|
+
private vectorRemoval?;
|
|
3823
|
+
constructor(db: SQLiteAdapter, entryRepo: EntryRepository, taskRepo: TaskRepository, eventRepo: EventRepository, edgeRepo: EdgeRepository, metadataRepo: MetadataRepository, searchService: SearchService, jobManager: JobManager, embeddingService: EmbeddingService, options?: Pick<WikiOptions, 'onDiagnostic' | 'forceDeleteIgnoreRankerHook'>, vectorRemoval?: VectorRemovalService | undefined);
|
|
3510
3824
|
exportDump(entityIds?: string[]): Promise<MemoryDump>;
|
|
3511
3825
|
importDump(dump: MemoryDump, opts?: {
|
|
3512
3826
|
merge?: boolean;
|
|
@@ -3662,6 +3976,8 @@ declare class WikiMemory {
|
|
|
3662
3976
|
private edgeRepo;
|
|
3663
3977
|
private metadataRepo;
|
|
3664
3978
|
private embeddingService;
|
|
3979
|
+
private vectorRemovalRepo;
|
|
3980
|
+
private vectorRemovalService;
|
|
3665
3981
|
private searchService;
|
|
3666
3982
|
private jobManager;
|
|
3667
3983
|
private ingestionService;
|
|
@@ -3684,7 +4000,7 @@ declare class WikiMemory {
|
|
|
3684
4000
|
* If `NODE_ENV` is not `"test"`, emits a single `console.warn` per instance (skipped when `process` is undefined).
|
|
3685
4001
|
*/
|
|
3686
4002
|
get __testAccess(): WikiMemoryTestAccess;
|
|
3687
|
-
/** Max upsertGraph node ids held for their post-commit sync (spec #280 id threading). */
|
|
4003
|
+
/** Max upsertGraph node and superseded-fact ids held for their post-commit sync (spec #280 id threading). */
|
|
3688
4004
|
static readonly UPSERT_ID_STASH_CAP = 10000;
|
|
3689
4005
|
/**
|
|
3690
4006
|
* upsertGraph node and superseded-fact ids per entity, awaiting syncSearchIndex(), each with the
|
|
@@ -3697,6 +4013,19 @@ declare class WikiMemory {
|
|
|
3697
4013
|
/** Bumped per stashed id; a re-stash during an in-flight drain outlives that drain's drop. */
|
|
3698
4014
|
private upsertIdStashGen;
|
|
3699
4015
|
private stashUpsertIds;
|
|
4016
|
+
/** Max superseded-fact ids held for post-commit removal delivery. */
|
|
4017
|
+
static readonly REMOVAL_STASH_CAP = 10000;
|
|
4018
|
+
/** Superseded fact ids per entity awaiting a post-commit delivery from syncSearchIndex(). */
|
|
4019
|
+
private removalStash;
|
|
4020
|
+
private removalStashSize;
|
|
4021
|
+
/**
|
|
4022
|
+
* Overflow past the cap drops the id from the stash only: the trigger already
|
|
4023
|
+
* put it on the ledger, so it stays owed and runExternalDeletions or
|
|
4024
|
+
* runPendingMaintenance delivers it later.
|
|
4025
|
+
*/
|
|
4026
|
+
private stashRemovalIds;
|
|
4027
|
+
/** Removes and returns the stashed removal ids (one entity, or all). */
|
|
4028
|
+
private takeRemovalIds;
|
|
3700
4029
|
/** Snapshot of the stash (one entity, or all) with generations, without removing anything. */
|
|
3701
4030
|
private peekStashedIds;
|
|
3702
4031
|
/**
|
|
@@ -3730,6 +4059,30 @@ declare class WikiMemory {
|
|
|
3730
4059
|
setup(opts?: {
|
|
3731
4060
|
migrations?: MigrationPolicy;
|
|
3732
4061
|
}): Promise<void>;
|
|
4062
|
+
private setupRemovalDrain;
|
|
4063
|
+
/** Marks the external index in use, then drains owed removals in the background (spec §5.7). */
|
|
4064
|
+
private startSetupRemovalDrain;
|
|
4065
|
+
/**
|
|
4066
|
+
* Delivers owed vector-index removals now (spec §5.9). No backoff. With an
|
|
4067
|
+
* entity id only that entity's rows; otherwise all. `deadlineMs` is a duration.
|
|
4068
|
+
* `transient: true` means a ledger read or write could not run (for example,
|
|
4069
|
+
* you held a transaction open on the connection); the rows stay pending.
|
|
4070
|
+
*/
|
|
4071
|
+
runExternalDeletions(entityId?: string, opts?: {
|
|
4072
|
+
deadlineMs?: number;
|
|
4073
|
+
}): Promise<{
|
|
4074
|
+
confirmed: number;
|
|
4075
|
+
pending: number;
|
|
4076
|
+
failedIds: string[];
|
|
4077
|
+
timedOut: boolean;
|
|
4078
|
+
transient?: boolean;
|
|
4079
|
+
}>;
|
|
4080
|
+
/** Removals still owed to the host's vector index (all entities, or one). */
|
|
4081
|
+
getPendingExternalDeletions(entityId?: string): Promise<{
|
|
4082
|
+
count: number;
|
|
4083
|
+
oldestEnqueuedAt: number | null;
|
|
4084
|
+
maxAttempts: number;
|
|
4085
|
+
}>;
|
|
3733
4086
|
hasChanged(entityId: string, sourceRef: string, sourceHash: string): Promise<boolean>;
|
|
3734
4087
|
/**
|
|
3735
4088
|
* Batched overload.
|
|
@@ -3837,7 +4190,7 @@ declare class WikiMemory {
|
|
|
3837
4190
|
traverseGraph(entityId: string, options: GraphTraversalOptions): Promise<GraphNeighborhood>;
|
|
3838
4191
|
getMemoryBundle(entityId: string): Promise<MemoryBundle>;
|
|
3839
4192
|
write(entityId: string, event: Omit<WikiEvent, 'id' | 'entity_id' | 'created_at'>): Promise<void>;
|
|
3840
|
-
/** Await auto-mode background librarian/heal jobs started by write()
|
|
4193
|
+
/** Await auto-mode background librarian/heal jobs started by write(), and the removal drain `setup()` started under `drainExternalDeletionsOnSetup`. */
|
|
3841
4194
|
drain(): Promise<void>;
|
|
3842
4195
|
/**
|
|
3843
4196
|
* Report which entities have pending maintenance work (librarian events
|
|
@@ -3846,12 +4199,12 @@ declare class WikiMemory {
|
|
|
3846
4199
|
* `pendingEvents` desc then `entityId` asc.
|
|
3847
4200
|
*/
|
|
3848
4201
|
getPendingMaintenance(entityIds?: string[]): Promise<PendingMaintenance[]>;
|
|
3849
|
-
/** Run pending librarian
|
|
4202
|
+
/** Run pending removals, librarian, heal and reembed work under an optional token budget and deadline (spec §6.2). Awaits the setup removal drain first, when `drainExternalDeletionsOnSetup` started one. */
|
|
3850
4203
|
runPendingMaintenance(options?: RunPendingMaintenanceOptions): Promise<RunPendingMaintenanceResult>;
|
|
3851
4204
|
/**
|
|
3852
4205
|
* @param options.promptOverride - Applies only to this manual call. Does NOT affect
|
|
3853
4206
|
* WriteService-triggered auto-runs. For persistent prompt customization across auto-runs,
|
|
3854
|
-
* set `options.config.prompts.
|
|
4207
|
+
* set `options.config.prompts.guidance` at WikiMemory construction time.
|
|
3855
4208
|
*/
|
|
3856
4209
|
runLibrarian(entityId: string, options?: {
|
|
3857
4210
|
promptOverride?: string;
|
|
@@ -3925,6 +4278,11 @@ declare class WikiMemory {
|
|
|
3925
4278
|
* waits at least 5 s, doubling per consecutive failure up to 5 min (longer
|
|
3926
4279
|
* when an attempt is itself slow), before retrying again.
|
|
3927
4280
|
*
|
|
4281
|
+
* It also calls the host's removal hook (`onEmbeddingPersisted(…, null)`) for
|
|
4282
|
+
* the stashed ids that `upsertGraph` superseded, and can take up to
|
|
4283
|
+
* `deletionHookTimeoutMs` per id when the host's index is slow. It never
|
|
4284
|
+
* drains an entity's wider removal backlog.
|
|
4285
|
+
*
|
|
3928
4286
|
* Call only after the host's transaction commits: called inside it, the
|
|
3929
4287
|
* rebuild may index rows that later roll back, or miss them and clear the
|
|
3930
4288
|
* stale flag anyway. Serialized with core's internal index syncs and takes
|
|
@@ -3940,6 +4298,7 @@ declare class WikiMemory {
|
|
|
3940
4298
|
* @throws {TypeError} when `entityId` is given but is not a non-empty string.
|
|
3941
4299
|
*/
|
|
3942
4300
|
syncSearchIndex(entityId?: string): Promise<void>;
|
|
4301
|
+
private syncSearchIndexCore;
|
|
3943
4302
|
/**
|
|
3944
4303
|
* True when a sync applied the stashed ids. While keyword search is
|
|
3945
4304
|
* unavailable the stand-in strategy's drain is a no-op that reports success,
|
|
@@ -3961,6 +4320,14 @@ declare class WikiMemory {
|
|
|
3961
4320
|
* hard-deletes the soft-deleted rows once they are older than
|
|
3962
4321
|
* `retainSoftDeletedFor` (7 days by default; pass 0 to remove them now).
|
|
3963
4322
|
* `dryRun` previews the counts.
|
|
4323
|
+
*
|
|
4324
|
+
* With a removal hook (`vectorRanker.onEmbeddingPersisted`), the deleted
|
|
4325
|
+
* facts are recorded as owed in the same transaction and then delivered to
|
|
4326
|
+
* the hook before this resolves.
|
|
4327
|
+
*
|
|
4328
|
+
* @throws {WikiExternalDeletionError} when the hook didn't confirm every
|
|
4329
|
+
* removal. The local delete stays committed and the rest stay owed; retry,
|
|
4330
|
+
* or call `runExternalDeletions()`.
|
|
3964
4331
|
*/
|
|
3965
4332
|
forget(entityId: string, params: ForgetParams, opts?: {
|
|
3966
4333
|
dryRun?: boolean;
|
|
@@ -4019,12 +4386,15 @@ declare class WikiMemory {
|
|
|
4019
4386
|
* semantics identical to `ingestDocument`, minus the LLM extraction step.
|
|
4020
4387
|
*
|
|
4021
4388
|
* MUST be called from inside an open `db.withTransactionAsync` callback —
|
|
4022
|
-
* the third argument is the caller's `tx
|
|
4389
|
+
* the third argument is the caller's `tx`, and that transaction must be
|
|
4390
|
+
* opened through the adapter given to `createWiki` (the removal ledger is
|
|
4391
|
+
* filled by triggers inside it, and a rollback discards the rows). The method does not open a
|
|
4023
4392
|
* nested transaction, does not acquire any lock, and does not perform
|
|
4024
4393
|
* post-commit work (search sync, embedding, cache eviction). After the
|
|
4025
4394
|
* transaction commits, call `syncSearchIndex(entityId)` — or
|
|
4026
4395
|
* `syncSearchIndex()` after writing several entities in one transaction —
|
|
4027
|
-
* to make the new nodes keyword-searchable
|
|
4396
|
+
* to make the new nodes keyword-searchable and to deliver, through the
|
|
4397
|
+
* host's removal hook, the vectors of any facts the call superseded: both forms drain this call's node ids
|
|
4028
4398
|
* first, to completion, so the nodes are searchable under any backlog (up to
|
|
4029
4399
|
* `WikiMemory.UPSERT_ID_STASH_CAP` pending ids; beyond that they converge with
|
|
4030
4400
|
* the backlog). Embeddings still come from the maintenance
|
|
@@ -4188,5 +4558,5 @@ declare class WikiMemory {
|
|
|
4188
4558
|
setGeneratedByTask(taskId: string, entityId: string, actor: string): Promise<void>;
|
|
4189
4559
|
}
|
|
4190
4560
|
|
|
4191
|
-
export { HEAL_BATCH_SIZE as H,
|
|
4192
|
-
export type {
|
|
4561
|
+
export { HEAL_BATCH_SIZE as H, ONTOLOGY_BACKFILL_BATCH_SIZE as K, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS as N, ONTOLOGY_BACKFILL_RECHECK_MS as P, PromptService as a2, PrunePartialFailureError as a3, WikiParseError as aB, WikiSearchUnavailableError as aC, WikiSourceRefHashCollision as aD, WikiStrictOntologyViolation as aE, WikiSupersedeError as aF, WikiTransactionError as aI, isWikiSearchUnavailableError as aJ, validateManifest as aK, EmbeddingService as aL, ImportExportService as aM, IngestionService as aN, JobManager as aO, MaintenanceService as aP, RetrievalService as aQ, SearchService as aR, WriteService as aS, WikiBusyError as ad, WikiDraftNotFound as an, WikiDuplicateHashError as ao, WikiExternalDeletionError as ar, WikiGraphNodeOwnershipConflict as at, WikiIngestEmptyError as au, WikiInvalidReadOptions as aw, WikiMigrationRequiredError as az, WikiMemory as c, HEAL_RECHECK_MS as u, HOOK_TIMEOUT_MARKER as v };
|
|
4562
|
+
export type { PendingMigrationWork as $, MaintenanceJob as A, MaintenanceStopReason as B, ChunkFailure as C, DegradedRecord as D, EmbedFactResult as E, FormatContextOptions as F, GraphNeighborhood as G, IngestDocumentResult as I, MigrationPolicy as J, LLMProvider as L, MemoryBundle as M, OntologyMode as O, OntologyBackfillResult as Q, ReadOptions as R, SQLiteAdapter as S, OntologyConfig as T, OntologyEdgeType as U, OntologyManifest as V, WikiOptions as W, OntologyNodeType as X, OntologyPromptContext as Y, OntologyUpdates as Z, PendingMaintenance as _, MemoryDump as a, PendingSourceStatus as a0, PromptOverrides as a1, ReembedResult as a4, RememberInput as a5, RunPendingMaintenanceOptions as a6, RunPendingMaintenanceResult as a7, SupersedeReplacement as a8, VectorRanker as a9, WikiOutboxEvent as aA, WikiSupersedeReason as aG, WikiTask as aH, VectorRankerFallback as aa, VectorRankerRankArgs as ab, VectorRankerSemanticResult as ac, WikiBusyOperation as ae, WikiCheckpoint as af, WikiConfig as ag, WikiDiagnostic as ah, WikiDiagnosticCode as ai, WikiDiagnosticDetail as aj, WikiDiagnosticOperation as ak, WikiDiagnosticSeverity as al, WikiDiagnosticTrigger as am, WikiEdge as ap, WikiEvent as aq, WikiFact as as, WikiInstructions as av, WikiLintReport as ax, WikiMemoryTestAccess as ay, FormattedMemoryDump as b, ClassifierAnswer as d, ClassifierQuestion as e, ClassifyRequest as f, ClassifyResponse as g, DraftPage as h, EmbedFailureKind as i, EmbeddingMarkerKind as j, EntityMaintenanceReport as k, EntityStatus as l, ExtractedFact as m, ExtractedFactEdge as n, ExtractedFactWithOntology as o, ExtractedTask as p, ForgetParams as q, ForgetResult as r, GraphTraversalOptions as s, GroundingConfig as t, HealResult as w, LibrarianConfig as x, LibrarianGateConfig as y, LockedMaintenanceJob as z };
|