@equationalapplications/core-llm-wiki 4.18.1 → 4.20.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.
@@ -13,6 +13,15 @@ interface SQLiteAdapter {
13
13
  }>;
14
14
  getAllAsync<T>(sql: string, params?: unknown[]): Promise<T[]>;
15
15
  getFirstAsync<T>(sql: string, params?: unknown[]): Promise<T | null>;
16
+ /**
17
+ * Runs `fn` inside a transaction. A bare adapter implementation is not required to
18
+ * serialize concurrent calls itself — `WikiMemory` wraps every adapter it's given in
19
+ * `withSerializedTransactions` (see `db/serializedAdapter.ts`), which is what makes
20
+ * transactions serialize in practice. Once wrapped, inside the callback use ONLY the
21
+ * provided `tx` handle — never the outer database handle (captured via closure or
22
+ * `this.db`). Calling the outer handle deadlocks against the transaction mutex;
23
+ * calling `tx.withTransactionAsync` throws (nested transactions are unsupported).
24
+ */
16
25
  withTransactionAsync<T>(fn: (tx: SQLiteAdapter) => Promise<T>): Promise<T>;
17
26
  closeAsync(): Promise<void>;
18
27
  }
@@ -468,6 +477,19 @@ declare class WikiBusyError extends Error {
468
477
  readonly entityId: string;
469
478
  constructor(operation: WikiBusyOperation, entityId: string);
470
479
  }
480
+ /**
481
+ * Thrown by the serialized transaction wrapper when a SQLite driver error
482
+ * escapes a transaction callback (nested BEGIN, SQLITE_BUSY, constraint
483
+ * violation). Domain errors thrown from callback logic pass through unwrapped.
484
+ * Stable `instanceof` target for observability, mirroring {@link WikiBusyError}.
485
+ */
486
+ declare class WikiTransactionError extends Error {
487
+ /** Best-effort SQLite code lifted from the driver error, e.g. 'SQLITE_BUSY'. */
488
+ readonly sqliteErrorCode?: string;
489
+ constructor(message: string, options: {
490
+ cause: unknown;
491
+ });
492
+ }
471
493
  declare class PrunePartialFailureError extends Error {
472
494
  readonly deleted: number;
473
495
  readonly failedAt: string;
@@ -709,6 +731,7 @@ declare class MetadataRepository extends BaseRepository {
709
731
  deleteCheckpoint(entityId: string, tx: SQLiteAdapter): Promise<void>;
710
732
  getMeta(key: string, tx?: SQLiteAdapter): Promise<string | null>;
711
733
  setMeta(key: string, value: string, tx: SQLiteAdapter): Promise<void>;
734
+ deleteMeta(key: string, tx?: SQLiteAdapter): Promise<void>;
712
735
  clearDimensionMismatch(tx: SQLiteAdapter): Promise<void>;
713
736
  tableExists(tableName: string, tx?: SQLiteAdapter): Promise<boolean>;
714
737
  getTableDdl(tableName: string, tx?: SQLiteAdapter): Promise<string | null>;
@@ -1302,6 +1325,8 @@ declare class WikiMemory {
1302
1325
  subscribeEntityStatus(entityId: string, callback: (status: EntityStatus) => void): () => void;
1303
1326
  clearVectorCache(): void;
1304
1327
  exportDump(entityIds?: string[]): Promise<MemoryDump>;
1328
+ /** Entity summary prose persisted from an OKF profile ≥ 1 import; null when none stored. */
1329
+ getEntitySummary(entityId: string): Promise<string | null>;
1305
1330
  importDump(dump: MemoryDump, opts?: {
1306
1331
  merge?: boolean;
1307
1332
  }): Promise<void>;
@@ -1362,4 +1387,4 @@ declare class WikiMemory {
1362
1387
  }): Promise<void>;
1363
1388
  }
1364
1389
 
1365
- export { type WikiMemoryTestAccess as A, type WikiOutboxEvent as B, type WikiTask as C, EmbeddingService as D, type EntityStatus as E, type FormatContextOptions as F, type GraphNeighborhood as G, HOOK_TIMEOUT_MARKER as H, ImportExportService as I, IngestionService as J, JobManager as K, type LLMProvider as L, type MemoryBundle as M, MaintenanceService as N, type OntologyConfig as O, type PromptOverrides as P, RetrievalService as Q, type ReadOptions as R, type SQLiteAdapter as S, SearchService as T, WriteService as U, type VectorRanker as V, type WikiOptions as W, type MemoryDump as a, type FormattedMemoryDump as b, WikiMemory as c, type ExtractedFact as d, type ExtractedFactEdge as e, type ExtractedFactWithOntology as f, type ExtractedTask as g, type GraphTraversalOptions as h, type OntologyEdgeType as i, type OntologyManifest as j, type OntologyMode as k, type OntologyNodeType as l, type OntologyPromptContext as m, type OntologyUpdates as n, PromptService as o, PrunePartialFailureError as p, type VectorRankerFallback as q, type VectorRankerRankArgs as r, type VectorRankerSemanticResult as s, WikiBusyError as t, type WikiBusyOperation as u, type WikiCheckpoint as v, type WikiConfig as w, type WikiEdge as x, type WikiEvent as y, type WikiFact as z };
1390
+ export { type WikiMemoryTestAccess as A, type WikiOutboxEvent as B, type WikiTask as C, WikiTransactionError as D, type EntityStatus as E, type FormatContextOptions as F, type GraphNeighborhood as G, HOOK_TIMEOUT_MARKER as H, EmbeddingService as I, ImportExportService as J, IngestionService as K, type LLMProvider as L, type MemoryBundle as M, JobManager as N, type OntologyConfig as O, type PromptOverrides as P, MaintenanceService as Q, type ReadOptions as R, type SQLiteAdapter as S, RetrievalService as T, SearchService as U, type VectorRanker as V, type WikiOptions as W, WriteService as X, type MemoryDump as a, type FormattedMemoryDump as b, WikiMemory as c, type ExtractedFact as d, type ExtractedFactEdge as e, type ExtractedFactWithOntology as f, type ExtractedTask as g, type GraphTraversalOptions as h, type OntologyEdgeType as i, type OntologyManifest as j, type OntologyMode as k, type OntologyNodeType as l, type OntologyPromptContext as m, type OntologyUpdates as n, PromptService as o, PrunePartialFailureError as p, type VectorRankerFallback as q, type VectorRankerRankArgs as r, type VectorRankerSemanticResult as s, WikiBusyError as t, type WikiBusyOperation as u, type WikiCheckpoint as v, type WikiConfig as w, type WikiEdge as x, type WikiEvent as y, type WikiFact as z };
@@ -13,6 +13,15 @@ interface SQLiteAdapter {
13
13
  }>;
14
14
  getAllAsync<T>(sql: string, params?: unknown[]): Promise<T[]>;
15
15
  getFirstAsync<T>(sql: string, params?: unknown[]): Promise<T | null>;
16
+ /**
17
+ * Runs `fn` inside a transaction. A bare adapter implementation is not required to
18
+ * serialize concurrent calls itself — `WikiMemory` wraps every adapter it's given in
19
+ * `withSerializedTransactions` (see `db/serializedAdapter.ts`), which is what makes
20
+ * transactions serialize in practice. Once wrapped, inside the callback use ONLY the
21
+ * provided `tx` handle — never the outer database handle (captured via closure or
22
+ * `this.db`). Calling the outer handle deadlocks against the transaction mutex;
23
+ * calling `tx.withTransactionAsync` throws (nested transactions are unsupported).
24
+ */
16
25
  withTransactionAsync<T>(fn: (tx: SQLiteAdapter) => Promise<T>): Promise<T>;
17
26
  closeAsync(): Promise<void>;
18
27
  }
@@ -468,6 +477,19 @@ declare class WikiBusyError extends Error {
468
477
  readonly entityId: string;
469
478
  constructor(operation: WikiBusyOperation, entityId: string);
470
479
  }
480
+ /**
481
+ * Thrown by the serialized transaction wrapper when a SQLite driver error
482
+ * escapes a transaction callback (nested BEGIN, SQLITE_BUSY, constraint
483
+ * violation). Domain errors thrown from callback logic pass through unwrapped.
484
+ * Stable `instanceof` target for observability, mirroring {@link WikiBusyError}.
485
+ */
486
+ declare class WikiTransactionError extends Error {
487
+ /** Best-effort SQLite code lifted from the driver error, e.g. 'SQLITE_BUSY'. */
488
+ readonly sqliteErrorCode?: string;
489
+ constructor(message: string, options: {
490
+ cause: unknown;
491
+ });
492
+ }
471
493
  declare class PrunePartialFailureError extends Error {
472
494
  readonly deleted: number;
473
495
  readonly failedAt: string;
@@ -709,6 +731,7 @@ declare class MetadataRepository extends BaseRepository {
709
731
  deleteCheckpoint(entityId: string, tx: SQLiteAdapter): Promise<void>;
710
732
  getMeta(key: string, tx?: SQLiteAdapter): Promise<string | null>;
711
733
  setMeta(key: string, value: string, tx: SQLiteAdapter): Promise<void>;
734
+ deleteMeta(key: string, tx?: SQLiteAdapter): Promise<void>;
712
735
  clearDimensionMismatch(tx: SQLiteAdapter): Promise<void>;
713
736
  tableExists(tableName: string, tx?: SQLiteAdapter): Promise<boolean>;
714
737
  getTableDdl(tableName: string, tx?: SQLiteAdapter): Promise<string | null>;
@@ -1302,6 +1325,8 @@ declare class WikiMemory {
1302
1325
  subscribeEntityStatus(entityId: string, callback: (status: EntityStatus) => void): () => void;
1303
1326
  clearVectorCache(): void;
1304
1327
  exportDump(entityIds?: string[]): Promise<MemoryDump>;
1328
+ /** Entity summary prose persisted from an OKF profile ≥ 1 import; null when none stored. */
1329
+ getEntitySummary(entityId: string): Promise<string | null>;
1305
1330
  importDump(dump: MemoryDump, opts?: {
1306
1331
  merge?: boolean;
1307
1332
  }): Promise<void>;
@@ -1362,4 +1387,4 @@ declare class WikiMemory {
1362
1387
  }): Promise<void>;
1363
1388
  }
1364
1389
 
1365
- export { type WikiMemoryTestAccess as A, type WikiOutboxEvent as B, type WikiTask as C, EmbeddingService as D, type EntityStatus as E, type FormatContextOptions as F, type GraphNeighborhood as G, HOOK_TIMEOUT_MARKER as H, ImportExportService as I, IngestionService as J, JobManager as K, type LLMProvider as L, type MemoryBundle as M, MaintenanceService as N, type OntologyConfig as O, type PromptOverrides as P, RetrievalService as Q, type ReadOptions as R, type SQLiteAdapter as S, SearchService as T, WriteService as U, type VectorRanker as V, type WikiOptions as W, type MemoryDump as a, type FormattedMemoryDump as b, WikiMemory as c, type ExtractedFact as d, type ExtractedFactEdge as e, type ExtractedFactWithOntology as f, type ExtractedTask as g, type GraphTraversalOptions as h, type OntologyEdgeType as i, type OntologyManifest as j, type OntologyMode as k, type OntologyNodeType as l, type OntologyPromptContext as m, type OntologyUpdates as n, PromptService as o, PrunePartialFailureError as p, type VectorRankerFallback as q, type VectorRankerRankArgs as r, type VectorRankerSemanticResult as s, WikiBusyError as t, type WikiBusyOperation as u, type WikiCheckpoint as v, type WikiConfig as w, type WikiEdge as x, type WikiEvent as y, type WikiFact as z };
1390
+ export { type WikiMemoryTestAccess as A, type WikiOutboxEvent as B, type WikiTask as C, WikiTransactionError as D, type EntityStatus as E, type FormatContextOptions as F, type GraphNeighborhood as G, HOOK_TIMEOUT_MARKER as H, EmbeddingService as I, ImportExportService as J, IngestionService as K, type LLMProvider as L, type MemoryBundle as M, JobManager as N, type OntologyConfig as O, type PromptOverrides as P, MaintenanceService as Q, type ReadOptions as R, type SQLiteAdapter as S, RetrievalService as T, SearchService as U, type VectorRanker as V, type WikiOptions as W, WriteService as X, type MemoryDump as a, type FormattedMemoryDump as b, WikiMemory as c, type ExtractedFact as d, type ExtractedFactEdge as e, type ExtractedFactWithOntology as f, type ExtractedTask as g, type GraphTraversalOptions as h, type OntologyEdgeType as i, type OntologyManifest as j, type OntologyMode as k, type OntologyNodeType as l, type OntologyPromptContext as m, type OntologyUpdates as n, PromptService as o, PrunePartialFailureError as p, type VectorRankerFallback as q, type VectorRankerRankArgs as r, type VectorRankerSemanticResult as s, WikiBusyError as t, type WikiBusyOperation as u, type WikiCheckpoint as v, type WikiConfig as w, type WikiEdge as x, type WikiEvent as y, type WikiFact as z };
@@ -1,2 +1,2 @@
1
- export { D as EmbeddingService, I as ImportExportService, J as IngestionService, K as JobManager, K as JobManagerType, N as MaintenanceService, Q as RetrievalService, T as SearchService, T as SearchServiceType, A as WikiMemoryTestAccess, U as WriteService } from './testing-BfxdUHg9.mjs';
1
+ export { I as EmbeddingService, J as ImportExportService, K as IngestionService, N as JobManager, N as JobManagerType, Q as MaintenanceService, T as RetrievalService, U as SearchService, U as SearchServiceType, A as WikiMemoryTestAccess, X as WriteService } from './testing-BVN_g414.mjs';
2
2
  import 'minisearch';
package/dist/testing.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { D as EmbeddingService, I as ImportExportService, J as IngestionService, K as JobManager, K as JobManagerType, N as MaintenanceService, Q as RetrievalService, T as SearchService, T as SearchServiceType, A as WikiMemoryTestAccess, U as WriteService } from './testing-BfxdUHg9.js';
1
+ export { I as EmbeddingService, J as ImportExportService, K as IngestionService, N as JobManager, N as JobManagerType, Q as MaintenanceService, T as RetrievalService, U as SearchService, U as SearchServiceType, A as WikiMemoryTestAccess, X as WriteService } from './testing-BVN_g414.js';
2
2
  import 'minisearch';
package/dist/testing.js CHANGED
@@ -369,6 +369,16 @@ var EmbeddingService = class {
369
369
  }
370
370
  };
371
371
 
372
+ // src/utils/ontology.ts
373
+ function normalizeTitleKey(title) {
374
+ return title.trim().toLowerCase().replace(/\s+/g, " ");
375
+ }
376
+
377
+ // src/repositories/MetadataRepository.ts
378
+ function entitySummaryMetaKey(entityId) {
379
+ return `entity_summary:${entityId}`;
380
+ }
381
+
372
382
  // src/services/ImportExportService.ts
373
383
  var MAX_EMBEDDING_BLOB_BYTES = 32 * 1024;
374
384
  var IMPORT_TITLE_MAX = 500;
@@ -424,11 +434,12 @@ var ImportExportService = class {
424
434
  }
425
435
  }
426
436
  async getFullBundle(entityId, opts) {
427
- const [factsRaw, tasks, events, edges] = await Promise.all([
437
+ const [factsRaw, tasks, events, edges, summaryValue] = await Promise.all([
428
438
  opts?.includeBlobs ? this.entryRepo.findAllByEntityIdWithBlobs(entityId) : this.entryRepo.findAllByEntityId(entityId),
429
439
  this.taskRepo.findAllByEntityId(entityId),
430
440
  this.eventRepo.getByEntityId(entityId, opts?.maxEvents),
431
- this.edgeRepo.getByEntityId(entityId)
441
+ this.edgeRepo.getByEntityId(entityId),
442
+ this.metadataRepo.getMeta(entitySummaryMetaKey(entityId))
432
443
  ]);
433
444
  const facts = factsRaw.map((f) => {
434
445
  const {
@@ -447,7 +458,13 @@ var ImportExportService = class {
447
458
  tags: typeof factBase.tags === "string" ? JSON.parse(factBase.tags) : factBase.tags
448
459
  };
449
460
  });
450
- return { facts, tasks, events, edges };
461
+ return {
462
+ facts,
463
+ tasks,
464
+ events,
465
+ edges,
466
+ ...summaryValue != null ? { summary: summaryValue } : {}
467
+ };
451
468
  }
452
469
  /** Single-entity import transaction + post-processing; package-internal hook for tests. */
453
470
  async doImportEntity(entityId, bundle, merge) {
@@ -472,6 +489,11 @@ var ImportExportService = class {
472
489
  await this.edgeRepo.bulkDeleteByEntityId(entityId, tx);
473
490
  await this.metadataRepo.deleteCheckpoint(entityId, tx);
474
491
  }
492
+ if (bundle.summary !== void 0) {
493
+ await this.metadataRepo.setMeta(entitySummaryMetaKey(entityId), bundle.summary, tx);
494
+ } else if (!merge) {
495
+ await this.metadataRepo.deleteMeta(entitySummaryMetaKey(entityId), tx);
496
+ }
475
497
  const factIds = bundle.facts.map((fact) => fact.id);
476
498
  const existingFactsById = /* @__PURE__ */ new Map();
477
499
  const existingFacts = await this.entryRepo.findExistingMetadataByIds(
@@ -795,11 +817,6 @@ After running the migration SQL, restart your application.`
795
817
  );
796
818
  }
797
819
  };
798
-
799
- // src/utils/ontology.ts
800
- function normalizeTitleKey(title) {
801
- return title.trim().toLowerCase().replace(/\s+/g, " ");
802
- }
803
820
  function generateId(prefix = "") {
804
821
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
805
822
  return prefix + crypto.randomUUID().replace(/-/g, "").substring(0, 24);
@@ -1278,6 +1295,7 @@ var MaintenanceService = class {
1278
1295
  deletedEntries = await this.entryRepo.bulkSoftDeleteByEntityId(entityId, tx);
1279
1296
  deletedTasks = await this.taskRepo.bulkSoftDeleteByEntityId(entityId, tx);
1280
1297
  await this.metadataRepo.updateCheckpoint(entityId, { memory: 0, heal: 0 }, tx);
1298
+ await this.metadataRepo.deleteMeta(entitySummaryMetaKey(entityId), tx);
1281
1299
  } else {
1282
1300
  const hasIdSelectors = params.entryId !== void 0 || params.taskId !== void 0;
1283
1301
  const hasSourceSelectors = params.sourceRef !== void 0 || params.sourceHash !== void 0;