@equationalapplications/core-llm-wiki 4.19.0 → 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.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { __privateAdd, MetadataRepository, EmbeddingService, SearchService, JobManager, PromptService, IngestionService, MaintenanceService, ImportExportService, RetrievalService, WriteService, __privateGet, __privateSet, normalizeSourceRef, normalizeSourceHash, entitySummaryMetaKey, generateId, BaseRepository, emptyManifest, resolveNodeType, validateInlineEdges, resolveEdgeDefinition, normalizeTitleKey } from './chunk-3GMXRLKU.mjs';
2
- export { HOOK_TIMEOUT_MARKER, PromptService, PrunePartialFailureError, WikiBusyError, configureRandomSource, parseEmbedding } from './chunk-3GMXRLKU.mjs';
1
+ import { __privateAdd, MetadataRepository, EmbeddingService, SearchService, JobManager, PromptService, IngestionService, MaintenanceService, ImportExportService, RetrievalService, WriteService, __privateGet, __privateSet, normalizeSourceRef, normalizeSourceHash, entitySummaryMetaKey, generateId, BaseRepository, emptyManifest, resolveNodeType, validateInlineEdges, resolveEdgeDefinition, normalizeTitleKey, WikiTransactionError, extractSqliteCode } from './chunk-HKB5FEJG.mjs';
2
+ export { HOOK_TIMEOUT_MARKER, PromptService, PrunePartialFailureError, WikiBusyError, WikiTransactionError, configureRandomSource, parseEmbedding } from './chunk-HKB5FEJG.mjs';
3
3
  import { appendRelatedSection, buildConceptDocument, buildLogMd, buildEntityIndexMd, buildRootIndexMd, isAllowedOkfPath, parseRootIndexMd, parseEntityIndexMd, parseConcept, splitRelatedSection, extractMarkdownLinks, parseLogMd, parseEventIdComment, appendEventIdComment } from '@equationalapplications/core-okf';
4
4
 
5
5
  // src/db/schema.ts
@@ -104,6 +104,50 @@ async function setupDatabase(db, prefix) {
104
104
  `);
105
105
  }
106
106
 
107
+ // src/db/serializedAdapter.ts
108
+ function isDriverError(err) {
109
+ return extractSqliteCode(err) !== void 0;
110
+ }
111
+ function withOverrides(target, overrides) {
112
+ return new Proxy(target, {
113
+ get(obj, prop, receiver) {
114
+ if (prop in overrides) return Reflect.get(overrides, prop, receiver);
115
+ const value = Reflect.get(obj, prop, obj);
116
+ return typeof value === "function" ? value.bind(obj) : value;
117
+ }
118
+ });
119
+ }
120
+ function guardReentrancy(tx) {
121
+ return withOverrides(tx, {
122
+ withTransactionAsync() {
123
+ throw new Error(
124
+ "Nested withTransactionAsync is not supported: you are already inside a transaction. Pass the current `tx` down instead of opening a new transaction."
125
+ );
126
+ }
127
+ });
128
+ }
129
+ var DEADLOCK_WARN_MS = 1e4;
130
+ function withSerializedTransactions(db) {
131
+ let queue = Promise.resolve();
132
+ return withOverrides(db, {
133
+ withTransactionAsync(fn) {
134
+ const warn = setTimeout(() => {
135
+ console.warn(
136
+ "[core-llm-wiki] Transaction queued >10s \u2014 possible deadlock. Inside a transaction callback, use the `tx` parameter, never the outer database handle."
137
+ );
138
+ }, DEADLOCK_WARN_MS);
139
+ const run = queue.catch(() => void 0).then(() => {
140
+ clearTimeout(warn);
141
+ return db.withTransactionAsync((tx) => fn(guardReentrancy(tx ?? db)));
142
+ }).catch((e) => {
143
+ throw isDriverError(e) ? new WikiTransactionError("Transaction failed", { cause: e }) : e;
144
+ });
145
+ queue = run;
146
+ return run;
147
+ }
148
+ });
149
+ }
150
+
107
151
  // src/db/migrations.ts
108
152
  var MIGRATIONS = [
109
153
  {
@@ -1651,7 +1695,7 @@ var WikiMemory = class {
1651
1695
  constructor(db, options) {
1652
1696
  /** Emits `__testAccess` console warning at most once per instance when NODE_ENV ≠ "test". */
1653
1697
  __privateAdd(this, _testAccessNonTestEnvWarned, false);
1654
- this.db = db;
1698
+ this.db = withSerializedTransactions(db);
1655
1699
  this.options = options;
1656
1700
  this.prefix = options.config?.tablePrefix ?? "llm_wiki_";
1657
1701
  if (!TABLE_PREFIX_PATTERN.test(this.prefix)) {
@@ -1659,12 +1703,12 @@ var WikiMemory = class {
1659
1703
  `Invalid tablePrefix: ${JSON.stringify(this.prefix)}. Must match ${TABLE_PREFIX_PATTERN} (letter, then alphanumeric/underscore, ending in "_", max 32 chars total).`
1660
1704
  );
1661
1705
  }
1662
- this.outboxRepo = new OutboxRepository(db, this.prefix, !!options.config?.enableOutbox);
1663
- this.entryRepo = new EntryRepository(db, this.prefix, this.outboxRepo);
1664
- this.taskRepo = new TaskRepository(db, this.prefix, this.outboxRepo);
1665
- this.eventRepo = new EventRepository(db, this.prefix);
1666
- this.edgeRepo = new EdgeRepository(db, this.prefix);
1667
- this.metadataRepo = new MetadataRepository(db, this.prefix);
1706
+ this.outboxRepo = new OutboxRepository(this.db, this.prefix, !!options.config?.enableOutbox);
1707
+ this.entryRepo = new EntryRepository(this.db, this.prefix, this.outboxRepo);
1708
+ this.taskRepo = new TaskRepository(this.db, this.prefix, this.outboxRepo);
1709
+ this.eventRepo = new EventRepository(this.db, this.prefix);
1710
+ this.edgeRepo = new EdgeRepository(this.db, this.prefix);
1711
+ this.metadataRepo = new MetadataRepository(this.db, this.prefix);
1668
1712
  this.ontologyService = new OntologyService(
1669
1713
  this.metadataRepo,
1670
1714
  this.edgeRepo,