@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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-DP3lus54.mjs';
2
- export { E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, O as OntologyConfig, i as OntologyEdgeType, j as OntologyManifest, k as OntologyMode, l as OntologyNodeType, m as OntologyPromptContext, n as OntologyUpdates, P as PromptOverrides, o as PromptService, p as PrunePartialFailureError, V as VectorRanker, q as VectorRankerFallback, r as VectorRankerRankArgs, s as VectorRankerSemanticResult, t as WikiBusyError, u as WikiBusyOperation, v as WikiCheckpoint, w as WikiConfig, x as WikiEdge, y as WikiEvent, z as WikiFact, A as WikiMemoryTestAccess, B as WikiOutboxEvent, C as WikiTask } from './testing-DP3lus54.mjs';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-BVN_g414.mjs';
2
+ export { E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, O as OntologyConfig, i as OntologyEdgeType, j as OntologyManifest, k as OntologyMode, l as OntologyNodeType, m as OntologyPromptContext, n as OntologyUpdates, P as PromptOverrides, o as PromptService, p as PrunePartialFailureError, V as VectorRanker, q as VectorRankerFallback, r as VectorRankerRankArgs, s as VectorRankerSemanticResult, t as WikiBusyError, u as WikiBusyOperation, v as WikiCheckpoint, w as WikiConfig, x as WikiEdge, y as WikiEvent, z as WikiFact, A as WikiMemoryTestAccess, B as WikiOutboxEvent, C as WikiTask, D as WikiTransactionError } from './testing-BVN_g414.mjs';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
  import 'minisearch';
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, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-DP3lus54.js';
2
- export { E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, O as OntologyConfig, i as OntologyEdgeType, j as OntologyManifest, k as OntologyMode, l as OntologyNodeType, m as OntologyPromptContext, n as OntologyUpdates, P as PromptOverrides, o as PromptService, p as PrunePartialFailureError, V as VectorRanker, q as VectorRankerFallback, r as VectorRankerRankArgs, s as VectorRankerSemanticResult, t as WikiBusyError, u as WikiBusyOperation, v as WikiCheckpoint, w as WikiConfig, x as WikiEdge, y as WikiEvent, z as WikiFact, A as WikiMemoryTestAccess, B as WikiOutboxEvent, C as WikiTask } from './testing-DP3lus54.js';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-BVN_g414.js';
2
+ export { E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, O as OntologyConfig, i as OntologyEdgeType, j as OntologyManifest, k as OntologyMode, l as OntologyNodeType, m as OntologyPromptContext, n as OntologyUpdates, P as PromptOverrides, o as PromptService, p as PrunePartialFailureError, V as VectorRanker, q as VectorRankerFallback, r as VectorRankerRankArgs, s as VectorRankerSemanticResult, t as WikiBusyError, u as WikiBusyOperation, v as WikiCheckpoint, w as WikiConfig, x as WikiEdge, y as WikiEvent, z as WikiFact, A as WikiMemoryTestAccess, B as WikiOutboxEvent, C as WikiTask, D as WikiTransactionError } from './testing-BVN_g414.js';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
  import 'minisearch';
5
5
 
package/dist/index.js CHANGED
@@ -117,6 +117,127 @@ async function setupDatabase(db, prefix) {
117
117
  `);
118
118
  }
119
119
 
120
+ // src/db/sqliteCodes.ts
121
+ var SQLITE_RESULT_CODE_NAMES = {
122
+ 1: "SQLITE_ERROR",
123
+ 2: "SQLITE_INTERNAL",
124
+ 3: "SQLITE_PERM",
125
+ 4: "SQLITE_ABORT",
126
+ 5: "SQLITE_BUSY",
127
+ 6: "SQLITE_LOCKED",
128
+ 7: "SQLITE_NOMEM",
129
+ 8: "SQLITE_READONLY",
130
+ 9: "SQLITE_INTERRUPT",
131
+ 10: "SQLITE_IOERR",
132
+ 11: "SQLITE_CORRUPT",
133
+ 12: "SQLITE_NOTFOUND",
134
+ 13: "SQLITE_FULL",
135
+ 14: "SQLITE_CANTOPEN",
136
+ 15: "SQLITE_PROTOCOL",
137
+ 16: "SQLITE_EMPTY",
138
+ 17: "SQLITE_SCHEMA",
139
+ 18: "SQLITE_TOOBIG",
140
+ 19: "SQLITE_CONSTRAINT",
141
+ 20: "SQLITE_MISMATCH",
142
+ 21: "SQLITE_MISUSE",
143
+ 22: "SQLITE_NOLFS",
144
+ 23: "SQLITE_AUTH",
145
+ 24: "SQLITE_FORMAT",
146
+ 25: "SQLITE_RANGE",
147
+ 26: "SQLITE_NOTADB",
148
+ 27: "SQLITE_NOTICE",
149
+ 28: "SQLITE_WARNING",
150
+ 100: "SQLITE_ROW",
151
+ 101: "SQLITE_DONE"
152
+ };
153
+ function nameForSqliteResultCode(n) {
154
+ return SQLITE_RESULT_CODE_NAMES[n] ?? `SQLITE_${n}`;
155
+ }
156
+ function extractSqliteCode(err) {
157
+ if (typeof err !== "object" || err === null) return void 0;
158
+ const { code, message } = err;
159
+ if (typeof code === "string" && code.startsWith("SQLITE_")) return code;
160
+ if (typeof message === "string") {
161
+ const m = /^Error code (\d+):/.exec(message);
162
+ if (m) return nameForSqliteResultCode(Number(m[1]));
163
+ }
164
+ return void 0;
165
+ }
166
+
167
+ // src/types.ts
168
+ var WikiBusyError = class extends Error {
169
+ constructor(operation, entityId) {
170
+ super(`${operation} already running for entity ${entityId}`);
171
+ this.name = "WikiBusyError";
172
+ this.operation = operation;
173
+ this.entityId = entityId;
174
+ }
175
+ };
176
+ var WikiTransactionError = class extends Error {
177
+ constructor(message, options) {
178
+ super(message, options);
179
+ this.name = "WikiTransactionError";
180
+ this.sqliteErrorCode = extractSqliteCode(options.cause);
181
+ }
182
+ };
183
+ var PrunePartialFailureError = class extends Error {
184
+ constructor(deleted, failedAt, remaining, cause, deletedTasks = 0, deletedEvents = 0) {
185
+ super(`Prune partially failed: deleted ${deleted}, failed at ${failedAt}, ${remaining} remaining`);
186
+ this.name = "PrunePartialFailureError";
187
+ this.deleted = deleted;
188
+ this.failedAt = failedAt;
189
+ this.remaining = remaining;
190
+ this.deletedTasks = deletedTasks;
191
+ this.deletedEvents = deletedEvents;
192
+ this.cause = cause;
193
+ }
194
+ };
195
+ var HOOK_TIMEOUT_MARKER = /* @__PURE__ */ Symbol("WikiMemoryHookTimeout");
196
+
197
+ // src/db/serializedAdapter.ts
198
+ function isDriverError(err) {
199
+ return extractSqliteCode(err) !== void 0;
200
+ }
201
+ function withOverrides(target, overrides) {
202
+ return new Proxy(target, {
203
+ get(obj, prop, receiver) {
204
+ if (prop in overrides) return Reflect.get(overrides, prop, receiver);
205
+ const value = Reflect.get(obj, prop, obj);
206
+ return typeof value === "function" ? value.bind(obj) : value;
207
+ }
208
+ });
209
+ }
210
+ function guardReentrancy(tx) {
211
+ return withOverrides(tx, {
212
+ withTransactionAsync() {
213
+ throw new Error(
214
+ "Nested withTransactionAsync is not supported: you are already inside a transaction. Pass the current `tx` down instead of opening a new transaction."
215
+ );
216
+ }
217
+ });
218
+ }
219
+ var DEADLOCK_WARN_MS = 1e4;
220
+ function withSerializedTransactions(db) {
221
+ let queue = Promise.resolve();
222
+ return withOverrides(db, {
223
+ withTransactionAsync(fn) {
224
+ const warn = setTimeout(() => {
225
+ console.warn(
226
+ "[core-llm-wiki] Transaction queued >10s \u2014 possible deadlock. Inside a transaction callback, use the `tx` parameter, never the outer database handle."
227
+ );
228
+ }, DEADLOCK_WARN_MS);
229
+ const run = queue.catch(() => void 0).then(() => {
230
+ clearTimeout(warn);
231
+ return db.withTransactionAsync((tx) => fn(guardReentrancy(tx ?? db)));
232
+ }).catch((e) => {
233
+ throw isDriverError(e) ? new WikiTransactionError("Transaction failed", { cause: e }) : e;
234
+ });
235
+ queue = run;
236
+ return run;
237
+ }
238
+ });
239
+ }
240
+
120
241
  // src/db/migrations.ts
121
242
  var MIGRATIONS = [
122
243
  {
@@ -2036,29 +2157,6 @@ _SearchService.MAX_VECTOR_CACHE_ENTITIES = 16;
2036
2157
  _SearchService.MAX_VECTOR_CACHE_FACTS_PER_ENTITY = 500;
2037
2158
  var SearchService = _SearchService;
2038
2159
 
2039
- // src/types.ts
2040
- var WikiBusyError = class extends Error {
2041
- constructor(operation, entityId) {
2042
- super(`${operation} already running for entity ${entityId}`);
2043
- this.name = "WikiBusyError";
2044
- this.operation = operation;
2045
- this.entityId = entityId;
2046
- }
2047
- };
2048
- var PrunePartialFailureError = class extends Error {
2049
- constructor(deleted, failedAt, remaining, cause, deletedTasks = 0, deletedEvents = 0) {
2050
- super(`Prune partially failed: deleted ${deleted}, failed at ${failedAt}, ${remaining} remaining`);
2051
- this.name = "PrunePartialFailureError";
2052
- this.deleted = deleted;
2053
- this.failedAt = failedAt;
2054
- this.remaining = remaining;
2055
- this.deletedTasks = deletedTasks;
2056
- this.deletedEvents = deletedEvents;
2057
- this.cause = cause;
2058
- }
2059
- };
2060
- var HOOK_TIMEOUT_MARKER = /* @__PURE__ */ Symbol("WikiMemoryHookTimeout");
2061
-
2062
2160
  // src/services/JobManager.ts
2063
2161
  var JobManager = class {
2064
2162
  constructor(prefix) {
@@ -4647,7 +4745,7 @@ var WikiMemory = class {
4647
4745
  constructor(db, options) {
4648
4746
  /** Emits `__testAccess` console warning at most once per instance when NODE_ENV ≠ "test". */
4649
4747
  __privateAdd(this, _testAccessNonTestEnvWarned, false);
4650
- this.db = db;
4748
+ this.db = withSerializedTransactions(db);
4651
4749
  this.options = options;
4652
4750
  this.prefix = options.config?.tablePrefix ?? "llm_wiki_";
4653
4751
  if (!TABLE_PREFIX_PATTERN.test(this.prefix)) {
@@ -4655,12 +4753,12 @@ var WikiMemory = class {
4655
4753
  `Invalid tablePrefix: ${JSON.stringify(this.prefix)}. Must match ${TABLE_PREFIX_PATTERN} (letter, then alphanumeric/underscore, ending in "_", max 32 chars total).`
4656
4754
  );
4657
4755
  }
4658
- this.outboxRepo = new OutboxRepository(db, this.prefix, !!options.config?.enableOutbox);
4659
- this.entryRepo = new EntryRepository(db, this.prefix, this.outboxRepo);
4660
- this.taskRepo = new TaskRepository(db, this.prefix, this.outboxRepo);
4661
- this.eventRepo = new EventRepository(db, this.prefix);
4662
- this.edgeRepo = new EdgeRepository(db, this.prefix);
4663
- this.metadataRepo = new MetadataRepository(db, this.prefix);
4756
+ this.outboxRepo = new OutboxRepository(this.db, this.prefix, !!options.config?.enableOutbox);
4757
+ this.entryRepo = new EntryRepository(this.db, this.prefix, this.outboxRepo);
4758
+ this.taskRepo = new TaskRepository(this.db, this.prefix, this.outboxRepo);
4759
+ this.eventRepo = new EventRepository(this.db, this.prefix);
4760
+ this.edgeRepo = new EdgeRepository(this.db, this.prefix);
4761
+ this.metadataRepo = new MetadataRepository(this.db, this.prefix);
4664
4762
  this.ontologyService = new OntologyService(
4665
4763
  this.metadataRepo,
4666
4764
  this.edgeRepo,
@@ -5687,6 +5785,7 @@ exports.PromptService = PromptService;
5687
5785
  exports.PrunePartialFailureError = PrunePartialFailureError;
5688
5786
  exports.WikiBusyError = WikiBusyError;
5689
5787
  exports.WikiMemory = WikiMemory;
5788
+ exports.WikiTransactionError = WikiTransactionError;
5690
5789
  exports.configureRandomSource = configureRandomSource;
5691
5790
  exports.createWiki = createWiki;
5692
5791
  exports.formatContext = formatContext;