@anuma/sdk 7.0.4-next.20261015012621 → 7.0.5

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.
@@ -27824,11 +27824,6 @@ function parseTopics(value) {
27824
27824
  }
27825
27825
 
27826
27826
  // src/lib/db/entities/operations.ts
27827
- async function assertCanWrite(ctx) {
27828
- if (ctx.canWrite && !await ctx.canWrite()) {
27829
- throw new Error("Memory source is no longer eligible");
27830
- }
27831
- }
27832
27827
  function entityToStored(e) {
27833
27828
  return {
27834
27829
  uniqueId: e.id,
@@ -27969,7 +27964,6 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
27969
27964
  let skipped = false;
27970
27965
  let entities = [];
27971
27966
  await ctx.database.write(async () => {
27972
- await assertCanWrite(ctx);
27973
27967
  const {
27974
27968
  entities: byName,
27975
27969
  operations: entityOps,
@@ -28045,7 +28039,6 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
28045
28039
  let skipped = false;
28046
28040
  let entities = [];
28047
28041
  await ctx.database.write(async () => {
28048
- await assertCanWrite(ctx);
28049
28042
  const vaultRow = await findVaultRowInWrite(ctx, memoryId);
28050
28043
  if (options.guarded && autoLinkBlocked(vaultRow)) {
28051
28044
  skipped = true;
@@ -28106,7 +28099,6 @@ async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
28106
28099
  const links = await ctx.memoryEntityCollection.query(import_watermelondb18.Q.where("memory_id", import_watermelondb18.Q.oneOf(Array.from(memoryIds)))).fetch();
28107
28100
  if (links.length === 0) return;
28108
28101
  await ctx.database.write(async () => {
28109
- await assertCanWrite(ctx);
28110
28102
  await ctx.database.batch(...links.map((l) => l.prepareDestroyPermanently()));
28111
28103
  });
28112
28104
  }
@@ -28115,7 +28107,6 @@ async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
28115
28107
  const links = await ctx.memoryEntityCollection.query(import_watermelondb18.Q.where("user_id", userId)).fetch();
28116
28108
  if (links.length === 0) return;
28117
28109
  await ctx.database.write(async () => {
28118
- await assertCanWrite(ctx);
28119
28110
  await ctx.database.batch(...links.map((l) => l.prepareDestroyPermanently()));
28120
28111
  });
28121
28112
  }
@@ -28280,11 +28271,6 @@ function visibilityConditions(requested) {
28280
28271
  function isKinded(record) {
28281
28272
  return record.kind !== null && record.kind !== void 0;
28282
28273
  }
28283
- async function assertCanWrite2(ctx) {
28284
- if (ctx.canWrite && !await ctx.canWrite()) {
28285
- throw new Error("Memory source is no longer eligible");
28286
- }
28287
- }
28288
28274
  function assertValidKindLevel(kind, level) {
28289
28275
  const hasKind = kind !== null && kind !== void 0;
28290
28276
  if (hasKind && !MEMORY_KINDS.includes(kind)) {
@@ -28465,7 +28451,8 @@ async function createVaultMemoryOp(ctx, opts) {
28465
28451
  ctx.embeddedWalletSigner
28466
28452
  ) : opts.content;
28467
28453
  const created = await ctx.database.write(async () => {
28468
- await assertCanWrite2(ctx);
28454
+ if (ctx.canWrite && !await ctx.canWrite())
28455
+ throw new Error("Memory source is no longer eligible");
28469
28456
  return ctx.vaultMemoryCollection.create(
28470
28457
  (record) => populateNewVaultMemory(record, ctx, opts, encryptedContent, encryptedKindValue)
28471
28458
  );
@@ -28484,7 +28471,8 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
28484
28471
  ) : opts.content;
28485
28472
  let createdRecord = null;
28486
28473
  await ctx.database.write(async () => {
28487
- await assertCanWrite2(ctx);
28474
+ if (ctx.canWrite && !await ctx.canWrite())
28475
+ throw new Error("Memory source is no longer eligible");
28488
28476
  let target;
28489
28477
  try {
28490
28478
  target = await ctx.vaultMemoryCollection.find(targetId);
@@ -28576,7 +28564,8 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
28576
28564
  })
28577
28565
  );
28578
28566
  const created = await ctx.database.write(async () => {
28579
- await assertCanWrite2(ctx);
28567
+ if (ctx.canWrite && !await ctx.canWrite())
28568
+ throw new Error("Memory source is no longer eligible");
28580
28569
  const prepared = optionsArray.map(
28581
28570
  (opts, i) => ctx.vaultMemoryCollection.prepareCreate(
28582
28571
  (record) => populateNewVaultMemory(record, ctx, opts, encryptedContents[i], encryptedKindValues[i])
@@ -28867,7 +28856,8 @@ async function updateVaultMemoryOp(ctx, id, opts) {
28867
28856
  const record = probe;
28868
28857
  const originalUpdatedAt = record.updatedAt.getTime();
28869
28858
  await ctx.database.write(async () => {
28870
- await assertCanWrite2(ctx);
28859
+ if (ctx.canWrite && !await ctx.canWrite())
28860
+ throw new Error("Memory source is no longer eligible");
28871
28861
  if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record) || opts.freeFormOnly && isKinded(record)) {
28872
28862
  stale = true;
28873
28863
  return;
@@ -28978,7 +28968,6 @@ async function setMemoryEntitiesOp(ctx, memoryId, entities) {
28978
28968
  let stale = false;
28979
28969
  const originalUpdatedAt = record.updatedAt.getTime();
28980
28970
  await ctx.database.write(async (writer) => {
28981
- await assertCanWrite2(ctx);
28982
28971
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
28983
28972
  stale = true;
28984
28973
  return;
@@ -29020,7 +29009,6 @@ async function clearMemoryTopicsOverrideOp(ctx, memoryId, options) {
29020
29009
  const originalUpdatedAt = record.updatedAt.getTime();
29021
29010
  let cleared = false;
29022
29011
  await ctx.database.write(async () => {
29023
- await assertCanWrite2(ctx);
29024
29012
  if (options?.unlessTopicsRecorded && parseTopics(record.topics) !== null) return;
29025
29013
  cleared = true;
29026
29014
  await record.update((r) => {
@@ -29044,7 +29032,6 @@ async function setMemoryVisibilityOp(ctx, id, opts) {
29044
29032
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return null;
29045
29033
  let stale = false;
29046
29034
  await ctx.database.write(async () => {
29047
- await assertCanWrite2(ctx);
29048
29035
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
29049
29036
  stale = true;
29050
29037
  return;
@@ -29073,7 +29060,6 @@ async function deleteVaultMemoryOp(ctx, id) {
29073
29060
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return false;
29074
29061
  let stale = false;
29075
29062
  await ctx.database.write(async () => {
29076
- await assertCanWrite2(ctx);
29077
29063
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
29078
29064
  stale = true;
29079
29065
  return;
@@ -29111,7 +29097,8 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
29111
29097
  }
29112
29098
  let stale = false;
29113
29099
  await ctx.database.write(async () => {
29114
- await assertCanWrite2(ctx);
29100
+ if (ctx.canWrite && !await ctx.canWrite())
29101
+ throw new Error("Memory source is no longer eligible");
29115
29102
  if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
29116
29103
  stale = true;
29117
29104
  return;
@@ -29273,7 +29260,6 @@ async function stampTopicsExtractedAtOp(ctx, memoryIds, extractedAt, version = T
29273
29260
  for (let i = 0; i < uniqueIds.length; i += CHUNK) {
29274
29261
  const chunkIds = uniqueIds.slice(i, i + CHUNK);
29275
29262
  await ctx.database.write(async () => {
29276
- await assertCanWrite2(ctx);
29277
29263
  const records = [];
29278
29264
  for (const id of chunkIds) {
29279
29265
  try {
@@ -29307,7 +29293,6 @@ async function relinkMemoryTopicsOp(ctx, memoryIds) {
29307
29293
  for (const id of Array.from(new Set(memoryIds))) {
29308
29294
  try {
29309
29295
  await ctx.database.write(async (writer) => {
29310
- await assertCanWrite2(ctx);
29311
29296
  let record;
29312
29297
  try {
29313
29298
  record = await ctx.vaultMemoryCollection.find(id);
@@ -29338,7 +29323,6 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
29338
29323
  for (let i = 0; i < uniqueIds.length; i += CHUNK) {
29339
29324
  const chunkIds = uniqueIds.slice(i, i + CHUNK);
29340
29325
  await ctx.database.write(async () => {
29341
- await assertCanWrite2(ctx);
29342
29326
  const writes = [];
29343
29327
  for (const id of chunkIds) {
29344
29328
  let record;
@@ -29371,7 +29355,6 @@ async function deleteAllVaultMemoriesForUserOp(ctx, userId) {
29371
29355
  const records = await ctx.vaultMemoryCollection.query(import_watermelondb19.Q.where("user_id", userId), import_watermelondb19.Q.where("is_deleted", false)).fetch();
29372
29356
  if (records.length === 0) return 0;
29373
29357
  await ctx.database.write(async () => {
29374
- await assertCanWrite2(ctx);
29375
29358
  const prepared = records.map(
29376
29359
  (record) => record.prepareUpdate((r) => {
29377
29360
  r._setRaw("is_deleted", true);
@@ -29426,7 +29409,6 @@ async function archiveVaultMemoryOp(ctx, id, opts) {
29426
29409
  let stale = false;
29427
29410
  const archivedAtValue = opts?.now ?? Date.now();
29428
29411
  await ctx.database.write(async () => {
29429
- await assertCanWrite2(ctx);
29430
29412
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record) || record.archivedAt !== null) {
29431
29413
  stale = true;
29432
29414
  return;
@@ -29450,7 +29432,6 @@ async function restoreVaultMemoryOp(ctx, id) {
29450
29432
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return false;
29451
29433
  let stale = false;
29452
29434
  await ctx.database.write(async () => {
29453
- await assertCanWrite2(ctx);
29454
29435
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
29455
29436
  stale = true;
29456
29437
  return;
@@ -29471,7 +29452,6 @@ async function hardDeleteDecayedOp(ctx, id, opts) {
29471
29452
  const now = opts.now ?? Date.now();
29472
29453
  let stale = false;
29473
29454
  await ctx.database.write(async () => {
29474
- await assertCanWrite2(ctx);
29475
29455
  const archivedAt = record.archivedAt;
29476
29456
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record) || archivedAt === null || now - archivedAt <= opts.hardDeleteWindowMs) {
29477
29457
  stale = true;
@@ -29511,7 +29491,6 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding, embeddingModel,
29511
29491
  }
29512
29492
  let written = false;
29513
29493
  await ctx.database.write(async () => {
29514
- await assertCanWrite2(ctx);
29515
29494
  if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return;
29516
29495
  const originalUpdatedAt = record.updatedAt.getTime();
29517
29496
  if (originalUpdatedAt !== readUpdatedAt || record._getRaw("content") !== readStoredContent)
@@ -33204,13 +33183,6 @@ function restoreCandidates(candidates, redactor, ownNames) {
33204
33183
  ).map((c) => c.candidate);
33205
33184
  }
33206
33185
  async function extractAndRetain(messages, retainCtx, options) {
33207
- const { memoryStore, signal } = options;
33208
- if (memoryStore === null) throw new Error("Memory store is not ready");
33209
- if (memoryStore && options.folderId !== void 0 && options.folderId !== null)
33210
- throw new Error("Remote memory extraction does not support folders");
33211
- if (memoryStore && options.extract.piiRedaction && !memoryStore.masksEmbeddingInput)
33212
- throw new Error("PII-redacted extraction requires a memory store that masks embedding inputs");
33213
- signal?.throwIfAborted();
33214
33186
  const minConfidence = options.minConfidence ?? DEFAULT_MIN_CONFIDENCE;
33215
33187
  const resolvedConsolidatePii = options.consolidateOptions?.piiRedaction ?? options.extract.piiRedaction;
33216
33188
  const consolidateOptions = options.consolidateOptions !== void 0 ? {
@@ -33244,7 +33216,6 @@ async function extractAndRetain(messages, retainCtx, options) {
33244
33216
  }
33245
33217
  });
33246
33218
  const extractMs = Date.now() - tExtract;
33247
- signal?.throwIfAborted();
33248
33219
  const filtered = candidates.filter((c) => c.confidence >= minConfidence);
33249
33220
  const log = getLogger();
33250
33221
  const screened = screenCandidatesForInjection(filtered);
@@ -33292,33 +33263,16 @@ async function extractAndRetain(messages, retainCtx, options) {
33292
33263
  const results = [];
33293
33264
  const quarantinedInfo = [];
33294
33265
  let failedWrites = 0;
33295
- let auditRows;
33296
33266
  const tRetain = Date.now();
33297
33267
  for (const { candidate, isQuarantined, reason, signature } of toRetain) {
33298
33268
  try {
33299
- signal?.throwIfAborted();
33300
33269
  if (isQuarantined) {
33301
- let existingId;
33302
- if (memoryStore) {
33303
- auditRows ?? (auditRows = memoryStore.list({
33304
- scopes: [options.scope ?? "private"],
33305
- includeArchived: true,
33306
- includeQuarantined: true,
33307
- includeSuperseded: true
33308
- }));
33309
- const sourceKey = [...new Set(candidate.sourceMessageIds)].sort().join("\0");
33310
- const normalize = (value) => value.normalize("NFKC").trim().replace(/\s+/g, " ").toLowerCase();
33311
- existingId = (await auditRows).find(
33312
- (row) => row.trustTier === "quarantined" && row.scope === (options.scope ?? "private") && [...new Set(row.sourceChunkIds ?? [])].sort().join("\0") === sourceKey && normalize(row.content) === normalize(candidate.content)
33313
- )?.uniqueId ?? null;
33314
- } else {
33315
- existingId = await findQuarantinedDuplicateOp(
33316
- retainCtx.vaultCtx,
33317
- candidate.content,
33318
- candidate.sourceMessageIds,
33319
- { scope: options.scope ?? "private", folderId: options.folderId ?? null }
33320
- ).catch(() => null);
33321
- }
33270
+ const existingId = await findQuarantinedDuplicateOp(
33271
+ retainCtx.vaultCtx,
33272
+ candidate.content,
33273
+ candidate.sourceMessageIds,
33274
+ { scope: options.scope ?? "private", folderId: options.folderId ?? null }
33275
+ ).catch(() => null);
33322
33276
  if (existingId) {
33323
33277
  quarantinedInfo.push({
33324
33278
  candidate,
@@ -33329,26 +33283,18 @@ async function extractAndRetain(messages, retainCtx, options) {
33329
33283
  continue;
33330
33284
  }
33331
33285
  }
33332
- const retainOptions = {
33286
+ const result = await retain(candidate.content, retainCtx, {
33333
33287
  source: "auto-extracted",
33334
33288
  sourceChunkIds: candidate.sourceMessageIds,
33335
33289
  respectTombstones: true,
33336
33290
  ...options.scope !== void 0 && { scope: options.scope },
33291
+ ...options.folderId !== void 0 && { folderId: options.folderId },
33337
33292
  ...consolidateOptions !== void 0 && { consolidateOptions },
33338
33293
  ...candidate.eventTime !== null && { eventTime: candidate.eventTime },
33339
33294
  factType: candidate.type,
33340
33295
  ...isQuarantined && { trustTier: "quarantined", enableAutoMerge: false }
33341
- };
33342
- const result = memoryStore ? await memoryStore.retain(candidate.content, {
33343
- ...retainOptions,
33344
- canWrite: retainCtx.vaultCtx.canWrite,
33345
- signal
33346
- }) : await retain(candidate.content, retainCtx, {
33347
- ...retainOptions,
33348
- ...options.folderId !== void 0 && { folderId: options.folderId }
33349
33296
  });
33350
33297
  if (isQuarantined) {
33351
- auditRows = void 0;
33352
33298
  const info = {
33353
33299
  candidate,
33354
33300
  memoryId: result.memoryId,
@@ -33367,16 +33313,9 @@ async function extractAndRetain(messages, retainCtx, options) {
33367
33313
  }
33368
33314
  succeededCandidates.push(candidate);
33369
33315
  results.push(result);
33370
- if (result.action !== "suppressed" && candidate.entities.length > 0) {
33316
+ if (result.action !== "suppressed" && options.entityCtx && candidate.entities.length > 0) {
33371
33317
  try {
33372
- signal?.throwIfAborted();
33373
- if (memoryStore) {
33374
- await memoryStore.addTopics(result.memoryId, candidate.entities, {
33375
- unlessUserManaged: true,
33376
- canWrite: retainCtx.vaultCtx.canWrite,
33377
- signal
33378
- });
33379
- } else if (options.entityCtx && !await isMemoryTopicsUserManaged(options.entityCtx, result.memoryId)) {
33318
+ if (!await isMemoryTopicsUserManaged(options.entityCtx, result.memoryId)) {
33380
33319
  await linkMemoryEntitiesOp(options.entityCtx, result.memoryId, candidate.entities, {
33381
33320
  unlessTopicsUserManaged: true
33382
33321
  });
@@ -33626,7 +33565,7 @@ function createAutoExtractor(options) {
33626
33565
  };
33627
33566
  const consolidateOptions = options.consolidate ? { ...options.consolidate, ...subPassAuth(options.consolidate.baseUrl) } : void 0;
33628
33567
  const injectionClassifierOptions = options.injectionClassifier ? { ...options.injectionClassifier, ...subPassAuth(options.injectionClassifier.baseUrl) } : void 0;
33629
- if (!options.memoryStore && options.retainCtx.vaultCtx.entityCtx && !options.entityCtx) {
33568
+ if (options.retainCtx.vaultCtx.entityCtx && !options.entityCtx) {
33630
33569
  getLogger().warn(
33631
33570
  "[memory/extract] retainCtx.vaultCtx.entityCtx is set but extractor was created without `entityCtx` \u2014 W5 graph lane will receive no writes"
33632
33571
  );
@@ -33671,8 +33610,6 @@ function createAutoExtractor(options) {
33671
33610
  try {
33672
33611
  const { candidates, results, failedCount, outcome, failure, funnel, timings, model } = await extractAndRetain(window2, retainCtx, {
33673
33612
  extract,
33674
- memoryStore: options.memoryStore,
33675
- signal: options.signal,
33676
33613
  ...options.minConfidence !== void 0 && { minConfidence: options.minConfidence },
33677
33614
  ...options.entityCtx !== void 0 && { entityCtx: options.entityCtx },
33678
33615
  ...options.scope !== void 0 && { scope: options.scope },
@@ -35804,7 +35741,6 @@ function createLocalMemoryStore(options) {
35804
35741
  database,
35805
35742
  entityCollection: database.get("entity"),
35806
35743
  memoryEntityCollection: database.get("memory_entity"),
35807
- canWrite: options.canWrite,
35808
35744
  ...userId !== void 0 && { userId },
35809
35745
  ...options.allowUnscopedRows !== void 0 && {
35810
35746
  allowUnscopedRows: options.allowUnscopedRows
@@ -35816,21 +35752,10 @@ function createLocalMemoryStore(options) {
35816
35752
  walletAddress: options.walletAddress,
35817
35753
  signMessage: options.signMessage,
35818
35754
  embeddedWalletSigner: options.embeddedWalletSigner,
35819
- canWrite: options.canWrite,
35820
35755
  ...userId !== void 0 && { userId },
35821
35756
  ...options.singleTenant !== void 0 && { singleTenant: options.singleTenant },
35822
35757
  entityCtx
35823
35758
  };
35824
- const assertWrite = async (writeOptions) => {
35825
- writeOptions?.signal?.throwIfAborted();
35826
- if (writeOptions?.canWrite && !await writeOptions.canWrite()) {
35827
- throw new Error("Memory source is no longer eligible");
35828
- }
35829
- if (options.canWrite && !await options.canWrite()) {
35830
- throw new Error("Memory source is no longer eligible");
35831
- }
35832
- writeOptions?.signal?.throwIfAborted();
35833
- };
35834
35759
  const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
35835
35760
  const ownedBy = userId !== void 0 ? [import_watermelondb24.Q.where("user_id", userId)] : [];
35836
35761
  const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [import_watermelondb24.Q.or(import_watermelondb24.Q.where("user_id", userId), import_watermelondb24.Q.where("user_id", null))] : [import_watermelondb24.Q.where("user_id", userId)];
@@ -35942,25 +35867,9 @@ function createLocalMemoryStore(options) {
35942
35867
  archive: (id) => archiveVaultMemoryOp(vaultCtx, id),
35943
35868
  restore: (id) => restoreVaultMemoryOp(vaultCtx, id),
35944
35869
  setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
35945
- addTopics: (memoryId, topics, writeOptions) => database.write(async (writer) => {
35946
- await assertWrite(writeOptions);
35870
+ addTopics: (memoryId, topics) => database.write(async (writer) => {
35947
35871
  const owned = await vaultCtx.vaultMemoryCollection.query(import_watermelondb24.Q.where("id", memoryId), import_watermelondb24.Q.where("is_deleted", false), ...ownedBy).fetchCount();
35948
- return owned > 0 ? writer.callWriter(
35949
- () => linkMemoryEntitiesOp(
35950
- {
35951
- ...entityCtx,
35952
- canWrite: async () => {
35953
- await assertWrite(writeOptions);
35954
- return true;
35955
- }
35956
- },
35957
- memoryId,
35958
- topics,
35959
- {
35960
- unlessTopicsUserManaged: writeOptions?.unlessUserManaged
35961
- }
35962
- )
35963
- ) : [];
35872
+ return owned > 0 ? writer.callWriter(() => linkMemoryEntitiesOp(entityCtx, memoryId, topics)) : [];
35964
35873
  }),
35965
35874
  setVisibility: (id, visibility, visibilityOptions) => setMemoryVisibilityOp(vaultCtx, id, { visibility, ...visibilityOptions }),
35966
35875
  recall: (query, recallOptions) => recall(
@@ -35970,17 +35879,7 @@ function createLocalMemoryStore(options) {
35970
35879
  ),
35971
35880
  retain: (content, retainOptions) => retain(
35972
35881
  content,
35973
- {
35974
- vaultCtx: {
35975
- ...vaultCtx,
35976
- canWrite: async () => {
35977
- await assertWrite(retainOptions);
35978
- return true;
35979
- }
35980
- },
35981
- embeddingOptions: options.embeddingOptions,
35982
- vaultCache
35983
- },
35882
+ { vaultCtx, embeddingOptions: options.embeddingOptions, vaultCache },
35984
35883
  retainOptions
35985
35884
  ),
35986
35885
  factSource: {
@@ -36832,7 +36731,6 @@ function createDurableAutoExtractor(options) {
36832
36731
  };
36833
36732
  const folderId = options.folderId ?? null;
36834
36733
  let disposed = false;
36835
- let activeBatch = null;
36836
36734
  let running = false;
36837
36735
  let wakeRequested = false;
36838
36736
  let timer;
@@ -36869,18 +36767,14 @@ function createDurableAutoExtractor(options) {
36869
36767
  }, delay);
36870
36768
  }
36871
36769
  async function extractBatch(messages, conversationId, ids, jobScope, jobFolderId) {
36872
- if (disposed) throw new Error("Extraction session was disposed");
36873
36770
  let watchdog;
36874
36771
  let cancelled = false;
36875
- const controller = new AbortController();
36876
- activeBatch = controller;
36877
36772
  const model = options.modelForScope?.(jobScope) ?? options.extract.model;
36878
36773
  try {
36879
36774
  return await Promise.race([
36880
36775
  new Promise((resolve, reject) => {
36881
36776
  const worker = createAutoExtractor({
36882
36777
  ...options,
36883
- signal: controller.signal,
36884
36778
  retainCtx: {
36885
36779
  ...options.retainCtx,
36886
36780
  vaultCtx: {
@@ -36909,8 +36803,6 @@ function createDurableAutoExtractor(options) {
36909
36803
  ]);
36910
36804
  } finally {
36911
36805
  cancelled = true;
36912
- controller.abort();
36913
- if (activeBatch === controller) activeBatch = null;
36914
36806
  if (watchdog !== void 0) clearTimeout(watchdog);
36915
36807
  }
36916
36808
  }
@@ -36922,7 +36814,6 @@ function createDurableAutoExtractor(options) {
36922
36814
  for (const message of loaded)
36923
36815
  if (message && message.messageId > 0) sequences.set(message.uniqueId, message.messageId);
36924
36816
  await database.write(async () => {
36925
- if (disposed) return;
36926
36817
  const current = idsOf(job);
36927
36818
  const acknowledged = ids.filter((id) => current.includes(id));
36928
36819
  if (!acknowledged.length) return;
@@ -37095,7 +36986,6 @@ function createDurableAutoExtractor(options) {
37095
36986
  jobScope,
37096
36987
  jobFolderId
37097
36988
  );
37098
- if (disposed) throw new Error("Extraction session was disposed");
37099
36989
  options.onTurnComplete?.(result);
37100
36990
  return result;
37101
36991
  };
@@ -37132,7 +37022,6 @@ function createDurableAutoExtractor(options) {
37132
37022
  );
37133
37023
  scheduleAfterSuccess = true;
37134
37024
  } catch (error) {
37135
- if (disposed) break;
37136
37025
  attempts.set(job.id, attempted + 1);
37137
37026
  retry = true;
37138
37027
  reportError(error, conversationId);
@@ -37155,14 +37044,6 @@ function createDurableAutoExtractor(options) {
37155
37044
  schedule(retry ? options.retryDelayMs ?? 3e4 : 0);
37156
37045
  }
37157
37046
  }
37158
- function dispose() {
37159
- disposed = true;
37160
- activeBatch?.abort(options.signal?.reason);
37161
- if (timer !== void 0) clearTimeout(timer);
37162
- options.signal?.removeEventListener("abort", dispose);
37163
- }
37164
- if (options.signal?.aborted) dispose();
37165
- else options.signal?.addEventListener("abort", dispose, { once: true });
37166
37047
  schedule(0);
37167
37048
  return {
37168
37049
  processTurn(messages, conversationId) {
@@ -37242,7 +37123,10 @@ function createDurableAutoExtractor(options) {
37242
37123
  return true;
37243
37124
  },
37244
37125
  isProcessing: () => running,
37245
- dispose
37126
+ dispose() {
37127
+ disposed = true;
37128
+ if (timer !== void 0) clearTimeout(timer);
37129
+ }
37246
37130
  };
37247
37131
  }
37248
37132
 
@@ -2779,7 +2779,6 @@ interface EntityOperationsContext {
2779
2779
  * (server / SQLite, where the migration backfill is authoritative).
2780
2780
  */
2781
2781
  allowUnscopedRows?: boolean;
2782
- canWrite?: () => Promise<boolean>;
2783
2782
  }
2784
2783
 
2785
2784
  /**
@@ -4934,10 +4933,6 @@ type ExtractOutcome = "extracted" | "no-facts" | "empty-after-retry" | "dropped-
4934
4933
  */
4935
4934
  declare function extractAndRetain(messages: AutoExtractMessage[], retainCtx: RetainContext, options: {
4936
4935
  extract: ExtractFactsOptions;
4937
- /** Route extracted facts through this store instead of the local vault. */
4938
- memoryStore?: MemoryStore | null;
4939
- /** Cancel remote writes for this extraction batch. */
4940
- signal?: AbortSignal;
4941
4936
  minConfidence?: number;
4942
4937
  /** Override scope/folder for all retained facts. */
4943
4938
  scope?: string;
@@ -6185,12 +6180,7 @@ type MemoryRecallOptions = Omit<RecallOptions, "types" | "includeChunks" | "conv
6185
6180
  * and never receives these credentials, callbacks or redactor instances.
6186
6181
  * @public
6187
6182
  */
6188
- type MemoryRetainOptions = Omit<RetainOptions, "folderId"> & {
6189
- /** Reject writes when the originating extraction is no longer eligible. */
6190
- canWrite?: () => Promise<boolean>;
6191
- /** Abort pending remote requests when the originating extraction is cancelled. */
6192
- signal?: AbortSignal;
6193
- };
6183
+ type MemoryRetainOptions = Omit<RetainOptions, "folderId">;
6194
6184
  /**
6195
6185
  * A topic and how many memories link to it.
6196
6186
  * @public
@@ -6319,11 +6309,7 @@ interface MemoryStore {
6319
6309
  /** Replace the memory's topics with a user-chosen set and stop auto-tagging it. */
6320
6310
  setTopics(memoryId: string, topics: readonly EntityInput[]): Promise<StoredVaultMemory | null>;
6321
6311
  /** Add topics alongside the existing ones (auto-tagging stays on). */
6322
- addTopics(memoryId: string, topics: readonly EntityInput[], options?: {
6323
- unlessUserManaged?: boolean;
6324
- canWrite?: () => Promise<boolean>;
6325
- signal?: AbortSignal;
6326
- }): Promise<StoredEntity[]>;
6312
+ addTopics(memoryId: string, topics: readonly EntityInput[]): Promise<StoredEntity[]>;
6327
6313
  setVisibility(id: string, visibility: VaultMemoryVisibility, options?: {
6328
6314
  twinOptIn?: boolean;
6329
6315
  }): Promise<StoredVaultMemory | null>;
@@ -9093,10 +9079,6 @@ interface SyncKeyValueStore {
9093
9079
  declare function createPlatformCursorStore(storage: SyncKeyValueStore, keyPrefix?: string): ExtractionCursorStore;
9094
9080
  interface CreateAutoExtractorOptions {
9095
9081
  retainCtx: RetainContext;
9096
- /** Route retained facts and topics through this store; null disables memory writes. */
9097
- memoryStore?: MemoryStore | null;
9098
- /** Cancel remote writes for an extraction batch. */
9099
- signal?: AbortSignal;
9100
9082
  extract: ExtractFactsOptions;
9101
9083
  /** Confidence floor for retained facts. Default 0.7. */
9102
9084
  minConfidence?: number;
@@ -9704,8 +9686,6 @@ interface LocalMemoryStoreOptions {
9704
9686
  walletAddress?: string;
9705
9687
  signMessage?: SignMessageFn;
9706
9688
  embeddedWalletSigner?: EmbeddedWalletSignerFn;
9707
- /** Rechecked inside each serialized memory write. */
9708
- canWrite?: () => Promise<boolean>;
9709
9689
  /**
9710
9690
  * Scope every read/write to this user — for a shared, multi-tenant database
9711
9691
  * whose rows all carry their `user_id`. Rows with no `user_id` are invisible
@@ -2779,7 +2779,6 @@ interface EntityOperationsContext {
2779
2779
  * (server / SQLite, where the migration backfill is authoritative).
2780
2780
  */
2781
2781
  allowUnscopedRows?: boolean;
2782
- canWrite?: () => Promise<boolean>;
2783
2782
  }
2784
2783
 
2785
2784
  /**
@@ -4934,10 +4933,6 @@ type ExtractOutcome = "extracted" | "no-facts" | "empty-after-retry" | "dropped-
4934
4933
  */
4935
4934
  declare function extractAndRetain(messages: AutoExtractMessage[], retainCtx: RetainContext, options: {
4936
4935
  extract: ExtractFactsOptions;
4937
- /** Route extracted facts through this store instead of the local vault. */
4938
- memoryStore?: MemoryStore | null;
4939
- /** Cancel remote writes for this extraction batch. */
4940
- signal?: AbortSignal;
4941
4936
  minConfidence?: number;
4942
4937
  /** Override scope/folder for all retained facts. */
4943
4938
  scope?: string;
@@ -6185,12 +6180,7 @@ type MemoryRecallOptions = Omit<RecallOptions, "types" | "includeChunks" | "conv
6185
6180
  * and never receives these credentials, callbacks or redactor instances.
6186
6181
  * @public
6187
6182
  */
6188
- type MemoryRetainOptions = Omit<RetainOptions, "folderId"> & {
6189
- /** Reject writes when the originating extraction is no longer eligible. */
6190
- canWrite?: () => Promise<boolean>;
6191
- /** Abort pending remote requests when the originating extraction is cancelled. */
6192
- signal?: AbortSignal;
6193
- };
6183
+ type MemoryRetainOptions = Omit<RetainOptions, "folderId">;
6194
6184
  /**
6195
6185
  * A topic and how many memories link to it.
6196
6186
  * @public
@@ -6319,11 +6309,7 @@ interface MemoryStore {
6319
6309
  /** Replace the memory's topics with a user-chosen set and stop auto-tagging it. */
6320
6310
  setTopics(memoryId: string, topics: readonly EntityInput[]): Promise<StoredVaultMemory | null>;
6321
6311
  /** Add topics alongside the existing ones (auto-tagging stays on). */
6322
- addTopics(memoryId: string, topics: readonly EntityInput[], options?: {
6323
- unlessUserManaged?: boolean;
6324
- canWrite?: () => Promise<boolean>;
6325
- signal?: AbortSignal;
6326
- }): Promise<StoredEntity[]>;
6312
+ addTopics(memoryId: string, topics: readonly EntityInput[]): Promise<StoredEntity[]>;
6327
6313
  setVisibility(id: string, visibility: VaultMemoryVisibility, options?: {
6328
6314
  twinOptIn?: boolean;
6329
6315
  }): Promise<StoredVaultMemory | null>;
@@ -9093,10 +9079,6 @@ interface SyncKeyValueStore {
9093
9079
  declare function createPlatformCursorStore(storage: SyncKeyValueStore, keyPrefix?: string): ExtractionCursorStore;
9094
9080
  interface CreateAutoExtractorOptions {
9095
9081
  retainCtx: RetainContext;
9096
- /** Route retained facts and topics through this store; null disables memory writes. */
9097
- memoryStore?: MemoryStore | null;
9098
- /** Cancel remote writes for an extraction batch. */
9099
- signal?: AbortSignal;
9100
9082
  extract: ExtractFactsOptions;
9101
9083
  /** Confidence floor for retained facts. Default 0.7. */
9102
9084
  minConfidence?: number;
@@ -9704,8 +9686,6 @@ interface LocalMemoryStoreOptions {
9704
9686
  walletAddress?: string;
9705
9687
  signMessage?: SignMessageFn;
9706
9688
  embeddedWalletSigner?: EmbeddedWalletSignerFn;
9707
- /** Rechecked inside each serialized memory write. */
9708
- canWrite?: () => Promise<boolean>;
9709
9689
  /**
9710
9690
  * Scope every read/write to this user — for a shared, multi-tenant database
9711
9691
  * whose rows all carry their `user_id`. Rows with no `user_id` are invisible