@equationalapplications/core-llm-wiki 9.18.0 → 9.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-CI0n5qQk.mjs';
2
- export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as IngestTypingCounters, N as LLMProvider, P as LibrarianConfig, Q as LibrarianGateConfig, T as LockedMaintenanceJob, U as MaintenanceJob, V as MaintenanceStopReason, X as MemoryDumpEntity, Y as MigrationPolicy, Z as ONTOLOGY_ABSTAIN_SENTINEL, _ as ONTOLOGY_BACKFILL_BATCH_SIZE, $ as ONTOLOGY_BACKFILL_RECHECK_MS, a0 as OntologyBackfillResult, a1 as OntologyEdgeType, a2 as OntologyManifest, a3 as OntologyNodeType, a4 as OntologyPromptContext, a5 as OntologyUpdates, a6 as PendingMaintenance, a7 as PendingMigrationWork, a8 as PendingSourceStatus, a9 as PromptOverrides, aa as PromptService, ab as PrunePartialFailureError, ac as ReembedResult, ad as RememberInput, ae as RunPendingMaintenanceOptions, af as RunPendingMaintenanceResult, ag as SourcePassage, ah as StoreSourceResult, ai as StoredSource, aj as StoredSourceDump, ak as StoredSourceSummary, al as SupersedeReplacement, am as SystemOneConfig, an as SystemOneThresholdSite, ao as VectorRanker, ap as VectorRankerFallback, aq as VectorRankerRankArgs, ar as VectorRankerSemanticResult, as as WikiBusyError, at as WikiBusyOperation, au as WikiCheckpoint, av as WikiDiagnostic, aw as WikiDiagnosticCode, ax as WikiDiagnosticDetail, ay as WikiDiagnosticOperation, az as WikiDiagnosticSeverity, aA as WikiDiagnosticTrigger, aB as WikiDraftNotFound, aC as WikiDuplicateHashError, aD as WikiEdge, aE as WikiEvent, aF as WikiExternalDeletionError, aG as WikiFact, aH as WikiGraphNodeOwnershipConflict, aI as WikiIngestEmptyError, aJ as WikiInstructions, aK as WikiInvalidReadOptions, aL as WikiLintReport, aM as WikiMemoryTestAccess, aN as WikiMigrationRequiredError, aO as WikiOutboxEvent, aP as WikiParseError, aQ as WikiSearchUnavailableError, aR as WikiSourcePointer, aS as WikiSourceRefHashCollision, aT as WikiStrictOntologyViolation, aU as WikiSupersedeError, aV as WikiSupersedeReason, aW as WikiTask, aX as WikiTransactionError, aY as WriteOntologyPromptContext, aZ as isReservedAbstainSlug, a_ as isWikiSearchUnavailableError, a$ as validateManifest } from './testing-CI0n5qQk.mjs';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-hg6O6N-X.mjs';
2
+ export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as IngestTypingCounters, N as LLMProvider, P as LibrarianConfig, Q as LibrarianGateConfig, T as LockedMaintenanceJob, U as MaintenanceJob, V as MaintenanceStopReason, X as MemoryDumpEntity, Y as MigrationPolicy, Z as ONTOLOGY_ABSTAIN_SENTINEL, _ as ONTOLOGY_BACKFILL_BATCH_SIZE, $ as ONTOLOGY_BACKFILL_RECHECK_MS, a0 as OntologyBackfillResult, a1 as OntologyEdgeType, a2 as OntologyManifest, a3 as OntologyNodeType, a4 as OntologyPromptContext, a5 as OntologyUpdates, a6 as PendingMaintenance, a7 as PendingMigrationWork, a8 as PendingSourceStatus, a9 as PromptOverrides, aa as PromptService, ab as PrunePartialFailureError, ac as ReembedResult, ad as RememberInput, ae as RunPendingMaintenanceOptions, af as RunPendingMaintenanceResult, ag as SourcePassage, ah as StoreSourceResult, ai as StoredSource, aj as StoredSourceDump, ak as StoredSourceSummary, al as SupersedeReplacement, am as SystemOneConfig, an as SystemOneThresholdSite, ao as VectorRanker, ap as VectorRankerFallback, aq as VectorRankerRankArgs, ar as VectorRankerSemanticResult, as as WikiBusyError, at as WikiBusyOperation, au as WikiCheckpoint, av as WikiDiagnostic, aw as WikiDiagnosticCode, ax as WikiDiagnosticDetail, ay as WikiDiagnosticOperation, az as WikiDiagnosticSeverity, aA as WikiDiagnosticTrigger, aB as WikiDraftNotFound, aC as WikiDuplicateHashError, aD as WikiEdge, aE as WikiEvent, aF as WikiExternalDeletionError, aG as WikiFact, aH as WikiGraphNodeOwnershipConflict, aI as WikiIngestEmptyError, aJ as WikiInstructions, aK as WikiInvalidReadOptions, aL as WikiLintReport, aM as WikiMemoryTestAccess, aN as WikiMigrationRequiredError, aO as WikiOutboxEvent, aP as WikiParseError, aQ as WikiSearchUnavailableError, aR as WikiSourcePointer, aS as WikiSourceRefHashCollision, aT as WikiStrictOntologyViolation, aU as WikiSupersedeError, aV as WikiSupersedeReason, aW as WikiTask, aX as WikiTransactionError, aY as WriteOntologyPromptContext, aZ as isReservedAbstainSlug, a_ as isWikiSearchUnavailableError, a$ as validateManifest } from './testing-hg6O6N-X.mjs';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
 
5
5
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-CI0n5qQk.js';
2
- export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as IngestTypingCounters, N as LLMProvider, P as LibrarianConfig, Q as LibrarianGateConfig, T as LockedMaintenanceJob, U as MaintenanceJob, V as MaintenanceStopReason, X as MemoryDumpEntity, Y as MigrationPolicy, Z as ONTOLOGY_ABSTAIN_SENTINEL, _ as ONTOLOGY_BACKFILL_BATCH_SIZE, $ as ONTOLOGY_BACKFILL_RECHECK_MS, a0 as OntologyBackfillResult, a1 as OntologyEdgeType, a2 as OntologyManifest, a3 as OntologyNodeType, a4 as OntologyPromptContext, a5 as OntologyUpdates, a6 as PendingMaintenance, a7 as PendingMigrationWork, a8 as PendingSourceStatus, a9 as PromptOverrides, aa as PromptService, ab as PrunePartialFailureError, ac as ReembedResult, ad as RememberInput, ae as RunPendingMaintenanceOptions, af as RunPendingMaintenanceResult, ag as SourcePassage, ah as StoreSourceResult, ai as StoredSource, aj as StoredSourceDump, ak as StoredSourceSummary, al as SupersedeReplacement, am as SystemOneConfig, an as SystemOneThresholdSite, ao as VectorRanker, ap as VectorRankerFallback, aq as VectorRankerRankArgs, ar as VectorRankerSemanticResult, as as WikiBusyError, at as WikiBusyOperation, au as WikiCheckpoint, av as WikiDiagnostic, aw as WikiDiagnosticCode, ax as WikiDiagnosticDetail, ay as WikiDiagnosticOperation, az as WikiDiagnosticSeverity, aA as WikiDiagnosticTrigger, aB as WikiDraftNotFound, aC as WikiDuplicateHashError, aD as WikiEdge, aE as WikiEvent, aF as WikiExternalDeletionError, aG as WikiFact, aH as WikiGraphNodeOwnershipConflict, aI as WikiIngestEmptyError, aJ as WikiInstructions, aK as WikiInvalidReadOptions, aL as WikiLintReport, aM as WikiMemoryTestAccess, aN as WikiMigrationRequiredError, aO as WikiOutboxEvent, aP as WikiParseError, aQ as WikiSearchUnavailableError, aR as WikiSourcePointer, aS as WikiSourceRefHashCollision, aT as WikiStrictOntologyViolation, aU as WikiSupersedeError, aV as WikiSupersedeReason, aW as WikiTask, aX as WikiTransactionError, aY as WriteOntologyPromptContext, aZ as isReservedAbstainSlug, a_ as isWikiSearchUnavailableError, a$ as validateManifest } from './testing-CI0n5qQk.js';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-hg6O6N-X.js';
2
+ export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as IngestTypingCounters, N as LLMProvider, P as LibrarianConfig, Q as LibrarianGateConfig, T as LockedMaintenanceJob, U as MaintenanceJob, V as MaintenanceStopReason, X as MemoryDumpEntity, Y as MigrationPolicy, Z as ONTOLOGY_ABSTAIN_SENTINEL, _ as ONTOLOGY_BACKFILL_BATCH_SIZE, $ as ONTOLOGY_BACKFILL_RECHECK_MS, a0 as OntologyBackfillResult, a1 as OntologyEdgeType, a2 as OntologyManifest, a3 as OntologyNodeType, a4 as OntologyPromptContext, a5 as OntologyUpdates, a6 as PendingMaintenance, a7 as PendingMigrationWork, a8 as PendingSourceStatus, a9 as PromptOverrides, aa as PromptService, ab as PrunePartialFailureError, ac as ReembedResult, ad as RememberInput, ae as RunPendingMaintenanceOptions, af as RunPendingMaintenanceResult, ag as SourcePassage, ah as StoreSourceResult, ai as StoredSource, aj as StoredSourceDump, ak as StoredSourceSummary, al as SupersedeReplacement, am as SystemOneConfig, an as SystemOneThresholdSite, ao as VectorRanker, ap as VectorRankerFallback, aq as VectorRankerRankArgs, ar as VectorRankerSemanticResult, as as WikiBusyError, at as WikiBusyOperation, au as WikiCheckpoint, av as WikiDiagnostic, aw as WikiDiagnosticCode, ax as WikiDiagnosticDetail, ay as WikiDiagnosticOperation, az as WikiDiagnosticSeverity, aA as WikiDiagnosticTrigger, aB as WikiDraftNotFound, aC as WikiDuplicateHashError, aD as WikiEdge, aE as WikiEvent, aF as WikiExternalDeletionError, aG as WikiFact, aH as WikiGraphNodeOwnershipConflict, aI as WikiIngestEmptyError, aJ as WikiInstructions, aK as WikiInvalidReadOptions, aL as WikiLintReport, aM as WikiMemoryTestAccess, aN as WikiMigrationRequiredError, aO as WikiOutboxEvent, aP as WikiParseError, aQ as WikiSearchUnavailableError, aR as WikiSourcePointer, aS as WikiSourceRefHashCollision, aT as WikiStrictOntologyViolation, aU as WikiSupersedeError, aV as WikiSupersedeReason, aW as WikiTask, aX as WikiTransactionError, aY as WriteOntologyPromptContext, aZ as isReservedAbstainSlug, a_ as isWikiSearchUnavailableError, a$ as validateManifest } from './testing-hg6O6N-X.js';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
 
5
5
  /**
package/dist/index.js CHANGED
@@ -363,6 +363,8 @@ var SEVERITY = {
363
363
  external_deletion_pending: "warn",
364
364
  supersede_scheduled_end_replaced: "info",
365
365
  external_deletion_discarded: "warn",
366
+ vector_removals_backlog: "warn",
367
+ vector_removals_trim_failed: "warn",
366
368
  guidance_too_long: "warn",
367
369
  guidance_resolver_failed: "warn",
368
370
  source_pointer_unresolved: "warn",
@@ -423,6 +425,8 @@ var MESSAGE = {
423
425
  supersede_scheduled_end_replaced: "A supersede replaced a scheduled end date on the old fact; the prior end is kept in prior_valid_to and reopen() can restore it.",
424
426
  external_deletion_pending: "Removals owed to the external vector index are still pending.",
425
427
  external_deletion_discarded: "Pending external vector removals were discarded because forceDeleteIgnoreRankerHook is set.",
428
+ vector_removals_backlog: "Pending external vector removals are accumulating faster than the host drains them.",
429
+ vector_removals_trim_failed: "The prune-time check of pending external vector removals failed; it will retry on the next prune pass.",
426
430
  guidance_too_long: "The configured guidance exceeded the length cap and was not sent for this pass.",
427
431
  guidance_resolver_failed: "The per-entity guidance resolver failed; its value was not used for this pass.",
428
432
  source_pointer_unresolved: "A stored librarian fact carries no source pointer because the model answer could not yield one, or the librarian merged such an unattributed candidate into this fact in place (its derived_events list was not extended).",
@@ -6810,6 +6814,14 @@ var DEFAULT_MAX_TOTAL_CHARS = 5e6;
6810
6814
  function limitOr(value, fallback) {
6811
6815
  return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.floor(value) : fallback;
6812
6816
  }
6817
+ function listStoredSourcesSql(prefix) {
6818
+ return `SELECT d.source_ref, d.source_hash, d.char_count, d.created_at,
6819
+ (SELECT COUNT(*) FROM ${prefix}source_passages p
6820
+ WHERE p.document_id = d.id AND +p.entity_id = d.entity_id) AS passage_count
6821
+ FROM ${prefix}source_documents d
6822
+ WHERE d.entity_id = ?
6823
+ ORDER BY d.source_ref COLLATE BINARY`;
6824
+ }
6813
6825
  var SourceStoreService = class {
6814
6826
  constructor(db, prefix, options, jobManager) {
6815
6827
  this.db = db;
@@ -6888,15 +6900,7 @@ var SourceStoreService = class {
6888
6900
  }
6889
6901
  /** Spec §4/§7: full store listing, including sources stored with no ingest. */
6890
6902
  async listStoredSources(entityId) {
6891
- const rows = await this.db.getAllAsync(
6892
- `SELECT d.source_ref, d.source_hash, d.char_count, d.created_at,
6893
- (SELECT COUNT(*) FROM ${this.prefix}source_passages p
6894
- WHERE p.entity_id = d.entity_id AND p.document_id = d.id) AS passage_count
6895
- FROM ${this.prefix}source_documents d
6896
- WHERE d.entity_id = ?
6897
- ORDER BY d.source_ref COLLATE BINARY`,
6898
- [entityId]
6899
- );
6903
+ const rows = await this.db.getAllAsync(listStoredSourcesSql(this.prefix), [entityId]);
6900
6904
  return rows.map((r) => ({
6901
6905
  sourceRef: r.source_ref,
6902
6906
  sourceHash: r.source_hash,
@@ -10178,6 +10182,40 @@ var VectorRemovalRepository = class extends BaseRepository {
10178
10182
  );
10179
10183
  return { count: row?.c ?? 0, oldestEnqueuedAt: row?.o ?? null, maxAttempts: row?.m ?? 0 };
10180
10184
  }
10185
+ /**
10186
+ * Trim an entity's pending rows down toward `cap`, deleting at most `chunk`
10187
+ * of the oldest per call. Uses the lower of the two cutoffs (cap overflow,
10188
+ * chunk bound); a no-op when at or under cap or when the external-index
10189
+ * marker is set. Without `tx` it opens its own single short transaction.
10190
+ * Returns the number of rows deleted.
10191
+ */
10192
+ async trimPendingOverflow(entityId, cap, chunk, tx) {
10193
+ if (chunk > cap) throw new Error(`trimPendingOverflow: chunk (${chunk}) must be <= cap (${cap})`);
10194
+ const run = async (ex) => {
10195
+ const t = `${this.prefix}vector_removals`;
10196
+ const capRow = await ex.getFirstAsync(
10197
+ `SELECT seq FROM ${t} WHERE entity_id = ? AND confirmed_at IS NULL
10198
+ ORDER BY seq DESC LIMIT 1 OFFSET ?`,
10199
+ [entityId, cap]
10200
+ );
10201
+ if (!capRow) return 0;
10202
+ const chunkRow = await ex.getFirstAsync(
10203
+ `SELECT seq FROM ${t} WHERE entity_id = ? AND confirmed_at IS NULL
10204
+ ORDER BY seq ASC LIMIT 1 OFFSET ?`,
10205
+ [entityId, chunk - 1]
10206
+ );
10207
+ const cuts = [capRow.seq, chunkRow?.seq].filter((x) => x != null);
10208
+ const cutoff = Math.min(...cuts);
10209
+ const r = await ex.runAsync(
10210
+ `DELETE FROM ${t}
10211
+ WHERE entity_id = ? AND confirmed_at IS NULL AND seq <= ?
10212
+ AND NOT EXISTS (SELECT 1 FROM ${this.prefix}meta WHERE key = 'external_index_in_use' AND value = '1')`,
10213
+ [entityId, cutoff]
10214
+ );
10215
+ return r.changes;
10216
+ };
10217
+ return tx ? run(tx) : this.db.withTransactionAsync(run);
10218
+ }
10181
10219
  async entitiesWithPending() {
10182
10220
  const rows = await this.db.getAllAsync(
10183
10221
  `SELECT DISTINCT entity_id FROM ${this.prefix}vector_removals
@@ -11641,6 +11679,9 @@ async function runLibrarianStrategy(deps, ctx) {
11641
11679
 
11642
11680
  // src/services/MaintenanceService.ts
11643
11681
  var CHAIN_TRUNCATED_NOTICE = `includeChain walk stopped at the depth cap (${HISTORY_MAX_DEPTH} links per direction); the chain is longer than the ids listed. Run forget again on a remaining chain id to continue.`;
11682
+ var MAX_PENDING_LEDGER_ROWS = 1e4;
11683
+ var WARN_PENDING_LEDGER_ROWS = 500;
11684
+ var TRIM_CHUNK_ROWS = 5e3;
11644
11685
  var ONTOLOGY_BACKFILL_BATCH_SIZE = 25;
11645
11686
  var ONTOLOGY_BACKFILL_RECHECK_MS = 7 * 24 * 60 * 60 * 1e3;
11646
11687
  var HEAL_ANCHOR_SEARCH_OVERFETCH = 4;
@@ -11885,6 +11926,33 @@ var _MaintenanceService = class _MaintenanceService {
11885
11926
  }
11886
11927
  }
11887
11928
  }
11929
+ if (gate === "none" && this.vectorRemoval && this.vectorRemovalRepo) {
11930
+ try {
11931
+ if (await this.vectorRemoval.ledgerPresent()) {
11932
+ if (!await this.vectorRemoval.externalIndexInUse()) {
11933
+ await this.vectorRemovalRepo.trimPendingOverflow(entityId, MAX_PENDING_LEDGER_ROWS, TRIM_CHUNK_ROWS);
11934
+ } else if (owner === "host") {
11935
+ const st = await this.vectorRemovalRepo.pendingStats(entityId);
11936
+ if (st.count > WARN_PENDING_LEDGER_ROWS) {
11937
+ emitDiagnostic(this.options, {
11938
+ code: "vector_removals_backlog",
11939
+ operation: "prune",
11940
+ trigger: "call",
11941
+ entityId,
11942
+ detail: {
11943
+ count: st.count,
11944
+ ...st.oldestEnqueuedAt !== null ? { oldestEnqueuedAt: st.oldestEnqueuedAt } : {},
11945
+ maxAttempts: st.maxAttempts
11946
+ }
11947
+ });
11948
+ }
11949
+ }
11950
+ }
11951
+ } catch (err) {
11952
+ const reason = err instanceof Error ? typeof err.code === "string" ? err.code : err.name : "unknown";
11953
+ emitDiagnostic(this.options, { code: "vector_removals_trim_failed", operation: "prune", trigger: "call", entityId, detail: { reason } });
11954
+ }
11955
+ }
11888
11956
  let vacuumCheckpointErr;
11889
11957
  if (vacuum) {
11890
11958
  try {