@utaba/deep-memory 0.15.0 → 0.16.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.cts CHANGED
@@ -323,6 +323,15 @@ declare class MemoryRepository {
323
323
  totalEntities: number;
324
324
  failed: number;
325
325
  }) => void | Promise<void>;
326
+ /**
327
+ * Called for every entity that fails to re-embed (embedBatch retries
328
+ * exhausted, or storage write failure). Internal plumbing — the facade
329
+ * wires this to `globalEventBus.emit('reembed:item-failed', ...)`.
330
+ */
331
+ onItemFailed?: (failure: {
332
+ entityId: string;
333
+ error: string;
334
+ }) => void | Promise<void>;
326
335
  /**
327
336
  * Caller-supplied abort signal. Honoured at batch boundaries.
328
337
  * Any vectors already written by completed batches are left in place.
package/dist/index.d.ts CHANGED
@@ -323,6 +323,15 @@ declare class MemoryRepository {
323
323
  totalEntities: number;
324
324
  failed: number;
325
325
  }) => void | Promise<void>;
326
+ /**
327
+ * Called for every entity that fails to re-embed (embedBatch retries
328
+ * exhausted, or storage write failure). Internal plumbing — the facade
329
+ * wires this to `globalEventBus.emit('reembed:item-failed', ...)`.
330
+ */
331
+ onItemFailed?: (failure: {
332
+ entityId: string;
333
+ error: string;
334
+ }) => void | Promise<void>;
326
335
  /**
327
336
  * Caller-supplied abort signal. Honoured at batch boundaries.
328
337
  * Any vectors already written by completed batches are left in place.
package/dist/index.js CHANGED
@@ -833,10 +833,15 @@ var EntityManager = class {
833
833
  attempt++;
834
834
  if (attempt > maxRetries) {
835
835
  const errorMsg = err instanceof Error ? err.message : String(err);
836
+ const failureMessage = `embedBatch failed after ${maxRetries} retries: ${errorMsg}`;
837
+ const failed = entries.map(([id]) => ({ entityId: id, error: failureMessage }));
838
+ for (const { entityId, error } of failed) {
839
+ await options?.onItemFailed?.(entityId, error);
840
+ }
836
841
  return {
837
842
  processed: 0,
838
843
  failed: entries.length,
839
- errors: entries.map(([id]) => ({ entityId: id, error: `embedBatch failed after ${maxRetries} retries: ${errorMsg}` })),
844
+ errors: failed,
840
845
  modelId: this.embedding.modelId(),
841
846
  dimensions: this.embedding.dimensions()
842
847
  };
@@ -859,7 +864,9 @@ var EntityManager = class {
859
864
  });
860
865
  processed++;
861
866
  } catch (err) {
862
- errors.push({ entityId: id, error: err instanceof Error ? err.message : String(err) });
867
+ const errorMessage = err instanceof Error ? err.message : String(err);
868
+ errors.push({ entityId: id, error: errorMessage });
869
+ await options?.onItemFailed?.(id, errorMessage);
863
870
  }
864
871
  }
865
872
  return {
@@ -902,7 +909,8 @@ var EntityManager = class {
902
909
  if (page.items.length === 0) break;
903
910
  const ids = page.items.map((e) => e.id);
904
911
  const result = await this.reembedEntities(ids, {
905
- maxRetries: options?.maxRetries
912
+ maxRetries: options?.maxRetries,
913
+ onItemFailed: options?.onItemFailed
906
914
  });
907
915
  totalProcessed += result.processed;
908
916
  totalFailed += result.failed;
@@ -2331,6 +2339,9 @@ var MemoryRepository = class {
2331
2339
  signal: options?.signal,
2332
2340
  onProgress: async (processed, total, failed) => {
2333
2341
  await options?.onProgress?.({ processed, totalEntities: total, failed });
2342
+ },
2343
+ onItemFailed: async (entityId, error) => {
2344
+ await options?.onItemFailed?.({ entityId, error });
2334
2345
  }
2335
2346
  });
2336
2347
  await this.storage.updateRepository(this.repositoryId, {
@@ -3453,7 +3464,7 @@ var EventBus = class {
3453
3464
  };
3454
3465
 
3455
3466
  // src/portability/RepositoryExporter.ts
3456
- var LIBRARY_VERSION = true ? "0.15.0" : "0.1.0";
3467
+ var LIBRARY_VERSION = true ? "0.16.0" : "0.1.0";
3457
3468
  var RepositoryExporter = class {
3458
3469
  storage;
3459
3470
  provenance;
@@ -3807,12 +3818,14 @@ var RepositoryImporter = class {
3807
3818
  storage;
3808
3819
  actorId;
3809
3820
  onProgress;
3821
+ onItemFailed;
3810
3822
  signal;
3811
3823
  migrationEngine = new MigrationEngine();
3812
3824
  constructor(config) {
3813
3825
  this.storage = config.storage;
3814
3826
  this.actorId = config.actorId;
3815
3827
  this.onProgress = config.onProgress;
3828
+ this.onItemFailed = config.onItemFailed;
3816
3829
  this.signal = config.signal;
3817
3830
  }
3818
3831
  throwIfAborted() {
@@ -3909,6 +3922,8 @@ var RepositoryImporter = class {
3909
3922
  message: `Failed to import ${e.item}: ${e.error}`,
3910
3923
  id: e.item
3911
3924
  });
3925
+ const itemType = chunk.entities?.some((x) => x.id === e.item) ? "entity" : chunk.relationships?.some((x) => x.id === e.item) ? "relationship" : "entity";
3926
+ await this.onItemFailed?.({ itemId: e.item, itemType, error: e.error });
3912
3927
  }
3913
3928
  await this.onProgress?.({
3914
3929
  repositoryId: target.repositoryId,
@@ -4045,11 +4060,13 @@ var RepositoryImporter = class {
4045
4060
  const targetExists = await this.storage.getEntity(repositoryId, rel.targetEntityId);
4046
4061
  if (!sourceExists || !targetExists) {
4047
4062
  relationshipsSkipped++;
4063
+ const errorMsg = `source or target entity missing`;
4048
4064
  warnings.push({
4049
4065
  code: "relationship_orphaned",
4050
- message: `Relationship "${rel.id}" skipped \u2014 source or target entity missing`,
4066
+ message: `Relationship "${rel.id}" skipped \u2014 ${errorMsg}`,
4051
4067
  relationshipId: rel.id
4052
4068
  });
4069
+ await this.onItemFailed?.({ itemId: rel.id, itemType: "relationship", error: errorMsg });
4053
4070
  } else {
4054
4071
  try {
4055
4072
  await this.storage.createRelationship(repositoryId, rel);
@@ -4396,6 +4413,12 @@ var DeepMemory = class {
4396
4413
  storage: this.storage,
4397
4414
  actorId: this.provenance.getContext().actorId,
4398
4415
  onProgress: (progress) => this.globalEventBus.emit("import:progress", progress),
4416
+ onItemFailed: (failure) => this.globalEventBus.emit("import:item-failed", {
4417
+ repositoryId: options.target.repositoryId,
4418
+ itemId: failure.itemId,
4419
+ itemType: failure.itemType,
4420
+ error: failure.error
4421
+ }),
4399
4422
  signal: options.signal
4400
4423
  });
4401
4424
  try {
@@ -4489,6 +4512,12 @@ var DeepMemory = class {
4489
4512
  storage: this.storage,
4490
4513
  actorId: this.provenance.getContext().actorId,
4491
4514
  onProgress: (progress) => this.globalEventBus.emit("import:progress", progress),
4515
+ onItemFailed: (failure) => this.globalEventBus.emit("import:item-failed", {
4516
+ repositoryId: options.target.repositoryId,
4517
+ itemId: failure.itemId,
4518
+ itemType: failure.itemType,
4519
+ error: failure.error
4520
+ }),
4492
4521
  signal: options.signal
4493
4522
  });
4494
4523
  await this.globalEventBus.emit("import:started", { repositoryId: options.target.repositoryId });
@@ -4543,6 +4572,11 @@ var DeepMemory = class {
4543
4572
  processed: progress.processed,
4544
4573
  totalEntities: progress.totalEntities,
4545
4574
  failed: progress.failed
4575
+ }),
4576
+ onItemFailed: (failure) => this.globalEventBus.emit("reembed:item-failed", {
4577
+ repositoryId,
4578
+ entityId: failure.entityId,
4579
+ error: failure.error
4546
4580
  })
4547
4581
  });
4548
4582
  await this.globalEventBus.emit("reembed:completed", {