@equationalapplications/core-llm-wiki 4.8.0 → 4.9.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, EmbeddingService, SearchService, JobManager, PromptService, IngestionService, MaintenanceService, ImportExportService, RetrievalService, WriteService, __privateGet, __privateSet, normalizeSourceRef, normalizeSourceHash, generateId } from './chunk-2FGDZKC2.mjs';
2
- export { HOOK_TIMEOUT_MARKER, PromptService, PrunePartialFailureError, WikiBusyError, parseEmbedding } from './chunk-2FGDZKC2.mjs';
1
+ import { __privateAdd, EmbeddingService, SearchService, JobManager, PromptService, IngestionService, MaintenanceService, ImportExportService, RetrievalService, WriteService, __privateGet, __privateSet, normalizeSourceRef, normalizeSourceHash, generateId } from './chunk-6FWG2DG4.mjs';
2
+ export { HOOK_TIMEOUT_MARKER, PromptService, PrunePartialFailureError, WikiBusyError, parseEmbedding } from './chunk-6FWG2DG4.mjs';
3
3
 
4
4
  // src/db/schema.ts
5
5
  async function setupDatabase(db, prefix) {
@@ -76,6 +76,9 @@ async function setupDatabase(db, prefix) {
76
76
 
77
77
  CREATE INDEX IF NOT EXISTS ${prefix}outbox_entity_id_created_at
78
78
  ON ${prefix}outbox (entity_id, created_at);
79
+
80
+ CREATE INDEX IF NOT EXISTS ${prefix}outbox_created_at
81
+ ON ${prefix}outbox (created_at);
79
82
  `);
80
83
  }
81
84
 
@@ -901,12 +904,18 @@ var EntryRepository = class extends BaseRepository {
901
904
 
902
905
  // src/repositories/OutboxRepository.ts
903
906
  var OutboxRepository = class extends BaseRepository {
907
+ constructor(db, prefix, enableOutbox = false) {
908
+ super(db, prefix);
909
+ this.enableOutbox = enableOutbox;
910
+ }
904
911
  /**
905
912
  * Insert a new outbox event within the provided transaction.
913
+ * No-op when enableOutbox is false.
906
914
  * `tx` is required — callers must always pass the active transaction
907
915
  * so the write is atomic with the main table mutation.
908
916
  */
909
917
  async push(params, tx) {
918
+ if (!this.enableOutbox) return;
910
919
  const executor = this.getExecutor(tx);
911
920
  const id = generateId("out_");
912
921
  const now = Date.now();
@@ -917,12 +926,12 @@ var OutboxRepository = class extends BaseRepository {
917
926
  );
918
927
  }
919
928
  /**
920
- * Fetch pending outbox rows ordered by created_at ASC.
929
+ * Fetch pending outbox rows ordered by created_at ASC, rowid ASC.
921
930
  * Reads directly from `this.db` (not a transaction).
922
931
  */
923
932
  async fetchPending(limit = 50) {
924
933
  return this.db.getAllAsync(
925
- `SELECT * FROM ${this.prefix}outbox ORDER BY created_at ASC LIMIT ?`,
934
+ `SELECT * FROM ${this.prefix}outbox ORDER BY created_at ASC, rowid ASC LIMIT ?`,
926
935
  [limit]
927
936
  );
928
937
  }
@@ -933,11 +942,15 @@ var OutboxRepository = class extends BaseRepository {
933
942
  */
934
943
  async acknowledge(ids) {
935
944
  if (ids.length === 0) return;
936
- const placeholders = ids.map(() => "?").join(", ");
937
- await this.db.runAsync(
938
- `DELETE FROM ${this.prefix}outbox WHERE id IN (${placeholders})`,
939
- ids
940
- );
945
+ const chunkSize = 500;
946
+ for (let i = 0; i < ids.length; i += chunkSize) {
947
+ const chunk = ids.slice(i, i + chunkSize);
948
+ const placeholders = chunk.map(() => "?").join(", ");
949
+ await this.db.runAsync(
950
+ `DELETE FROM ${this.prefix}outbox WHERE id IN (${placeholders})`,
951
+ chunk
952
+ );
953
+ }
941
954
  }
942
955
  };
943
956
 
@@ -1404,7 +1417,7 @@ var WikiMemory = class {
1404
1417
  this.db = db;
1405
1418
  this.options = options;
1406
1419
  this.prefix = options.config?.tablePrefix || "llm_wiki_";
1407
- this.outboxRepo = new OutboxRepository(db, this.prefix);
1420
+ this.outboxRepo = new OutboxRepository(db, this.prefix, !!options.config?.enableOutbox);
1408
1421
  this.entryRepo = new EntryRepository(db, this.prefix, this.outboxRepo);
1409
1422
  this.taskRepo = new TaskRepository(db, this.prefix, this.outboxRepo);
1410
1423
  this.eventRepo = new EventRepository(db, this.prefix);
@@ -1603,6 +1616,30 @@ var WikiMemory = class {
1603
1616
  async ingestDocument(entityId, params) {
1604
1617
  return this.ingestionService.ingestDocument(entityId, params);
1605
1618
  }
1619
+ /**
1620
+ * Returns up to `limit` unprocessed outbox events, oldest first.
1621
+ * Works regardless of enableOutbox value — allows draining after disabling.
1622
+ */
1623
+ async getUnprocessedOutboxEvents(limit = 100) {
1624
+ if (Number.isFinite(limit) && limit <= 0) return [];
1625
+ const safeLimit = Number.isFinite(limit) && limit >= 1 ? Math.trunc(limit) : 100;
1626
+ const rows = await this.outboxRepo.fetchPending(safeLimit);
1627
+ return rows.map((row) => {
1628
+ let payload = null;
1629
+ try {
1630
+ payload = JSON.parse(row.payload);
1631
+ } catch {
1632
+ }
1633
+ return { ...row, payload };
1634
+ });
1635
+ }
1636
+ /**
1637
+ * Deletes the given event IDs from the outbox table.
1638
+ * Call after successfully committing events to the external system.
1639
+ */
1640
+ async markOutboxEventsProcessed(eventIds) {
1641
+ await this.outboxRepo.acknowledge(eventIds);
1642
+ }
1606
1643
  };
1607
1644
  _testAccessNonTestEnvWarned = new WeakMap();
1608
1645