@anuma/sdk 10.2.6 → 10.3.1

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.
@@ -14294,6 +14294,25 @@ async function migrateChatsToRemote(options) {
14294
14294
  // src/lib/chatStore/vaultBackend.ts
14295
14295
  var import_uuid3 = require("uuid");
14296
14296
 
14297
+ // src/lib/chatStore/vaultCache.ts
14298
+ async function saveChatCache(storage, encrypt, snapshot) {
14299
+ await storage.set(snapshot.account, await encrypt(JSON.stringify({ schema: 1, ...snapshot })));
14300
+ }
14301
+ async function loadChatCache(storage, account, decrypt) {
14302
+ const sealed2 = await storage.get(account);
14303
+ if (!sealed2) return void 0;
14304
+ const parsed = JSON.parse(await decrypt(sealed2));
14305
+ if (parsed.schema !== 1 || parsed.account !== account || typeof parsed.cursor !== "string" || !Array.isArray(parsed.records) || !Array.isArray(parsed.threads) || !Array.isArray(parsed.absent))
14306
+ return void 0;
14307
+ return {
14308
+ account,
14309
+ cursor: parsed.cursor,
14310
+ records: parsed.records,
14311
+ threads: parsed.threads,
14312
+ absent: parsed.absent
14313
+ };
14314
+ }
14315
+
14297
14316
  // src/lib/chatStore/vaultOutbox.ts
14298
14317
  function patchKey(patch) {
14299
14318
  return `${patch.kind}/${patch.id}`;
@@ -14398,6 +14417,10 @@ async function loadOutbox(storage, slot, decrypt) {
14398
14417
 
14399
14418
  // src/lib/chatStore/vaultBackend.ts
14400
14419
  var terminalCodes = /* @__PURE__ */ new Set(["key_mismatch", "account_changed", "account_not_found"]);
14420
+ var cacheSaveDelayMs = 500;
14421
+ function cursorRejected(error) {
14422
+ return error instanceof ChatStoreError && (error.status === 400 || error.status === 410);
14423
+ }
14401
14424
  function key2(kind, id2) {
14402
14425
  return `${kind}/${id2}`;
14403
14426
  }
@@ -14442,7 +14465,7 @@ function defaultActivity() {
14442
14465
  };
14443
14466
  }
14444
14467
  function createVaultChatBackend(options) {
14445
- const { store } = options;
14468
+ const { cache } = options;
14446
14469
  const now = options.now ?? Date.now;
14447
14470
  const threadLimit = options.threadCacheSize ?? 30;
14448
14471
  const pollIntervalMs = options.pollIntervalMs ?? 6e4;
@@ -14469,6 +14492,13 @@ function createVaultChatBackend(options) {
14469
14492
  let persisting = Promise.resolve();
14470
14493
  let readyPromise = null;
14471
14494
  let adopting = null;
14495
+ let connected = typeof options.store === "function" ? void 0 : options.store;
14496
+ const complete = /* @__PURE__ */ new Set();
14497
+ let fromCache = false;
14498
+ let caching = false;
14499
+ let cacheOff = false;
14500
+ let cacheTimer;
14501
+ let saving = Promise.resolve();
14472
14502
  const slot = (0, import_uuid3.v7)();
14473
14503
  const locks = options.outbox?.locks ?? globalThis.navigator?.locks;
14474
14504
  let releaseSlot;
@@ -14505,13 +14535,55 @@ function createVaultChatBackend(options) {
14505
14535
  }
14506
14536
  return out;
14507
14537
  };
14538
+ const cacheSnapshot = () => {
14539
+ const kept = [...threads.keys()].filter((id2) => complete.has(id2) && confirmedLive(id2));
14540
+ const keep = new Set(kept);
14541
+ return {
14542
+ account: cache.account,
14543
+ cursor: cursor ?? "",
14544
+ records: [...confirmed.values()].filter(
14545
+ ({ record: record2 }) => record2.kind === "conversation" || record2.kind !== "project" && keep.has(record2.conversationId)
14546
+ ),
14547
+ threads: kept,
14548
+ absent: [...checked].filter((k) => {
14549
+ const [kind, ...rest] = k.split("/");
14550
+ return (kind === "summary" || kind === "memory_links") && !confirmed.has(k) && keep.has(rest.join("/"));
14551
+ })
14552
+ };
14553
+ };
14554
+ const saveCache = () => {
14555
+ if (!cache || !caching || cacheOff || closed || cacheTimer || cursor === void 0) return;
14556
+ cacheTimer = setTimeout(() => {
14557
+ cacheTimer = void 0;
14558
+ saving = saving.then(
14559
+ () => cacheOff || closed ? void 0 : saveChatCache(cache.storage, cache.seal.encrypt, cacheSnapshot())
14560
+ ).catch(() => void 0);
14561
+ }, cacheSaveDelayMs);
14562
+ };
14563
+ const clearCache = async () => {
14564
+ fromCache = false;
14565
+ cacheOff = true;
14566
+ clearTimeout(cacheTimer);
14567
+ cacheTimer = void 0;
14568
+ await saving;
14569
+ if (cache) await cache.storage.set(cache.account, null);
14570
+ };
14571
+ const wipeIfTerminal = (error) => {
14572
+ if (error instanceof ChatStoreError && terminalCodes.has(error.code ?? ""))
14573
+ void clearCache().catch(() => void 0);
14574
+ };
14508
14575
  const merge = (snapshot) => {
14509
14576
  const k = key2(snapshot.record.kind, snapshot.record.id);
14510
14577
  const known = confirmed.get(k);
14511
14578
  if (known && known.version >= snapshot.version) return false;
14512
14579
  confirmed.set(k, snapshot);
14580
+ saveCache();
14513
14581
  return true;
14514
14582
  };
14583
+ const remote = async () => {
14584
+ await ready();
14585
+ return connected;
14586
+ };
14515
14587
  const persist = () => {
14516
14588
  const storage = options.outbox;
14517
14589
  if (!storage) return Promise.resolve();
@@ -14566,7 +14638,7 @@ function createVaultChatBackend(options) {
14566
14638
  return { kind, id: rest.join("/") };
14567
14639
  });
14568
14640
  if (refs.length === 0) return;
14569
- const found = await store.getMany(refs);
14641
+ const found = await (await remote()).getMany(refs);
14570
14642
  const seen = new Set(found.map((s) => key2(s.record.kind, s.record.id)));
14571
14643
  for (const snapshot of found) merge(snapshot);
14572
14644
  for (const ref3 of refs) {
@@ -14574,6 +14646,7 @@ function createVaultChatBackend(options) {
14574
14646
  if (!seen.has(k)) confirmed.delete(k);
14575
14647
  checked.add(k);
14576
14648
  }
14649
+ saveCache();
14577
14650
  };
14578
14651
  const drop = (patch, reason) => {
14579
14652
  inflight.delete(patchKey(patch));
@@ -14628,7 +14701,7 @@ function createVaultChatBackend(options) {
14628
14701
  sent.push(patch);
14629
14702
  }
14630
14703
  if (writes.length === 0) return;
14631
- const results = await store.putMany(writes);
14704
+ const results = await (await remote()).putMany(writes);
14632
14705
  results.forEach((snapshot, i) => {
14633
14706
  merge(snapshot);
14634
14707
  checked.add(patchKey(sent[i]));
@@ -14662,6 +14735,7 @@ function createVaultChatBackend(options) {
14662
14735
  }
14663
14736
  if (terminalCodes.has(error.code ?? "")) {
14664
14737
  stopped = error.code;
14738
+ wipeIfTerminal(error);
14665
14739
  reportOutbox();
14666
14740
  return "stop";
14667
14741
  }
@@ -14728,6 +14802,7 @@ function createVaultChatBackend(options) {
14728
14802
  const forget = (k) => {
14729
14803
  confirmed.delete(k);
14730
14804
  checked.delete(k);
14805
+ saveCache();
14731
14806
  };
14732
14807
  const forgetConversation = (conversationId) => {
14733
14808
  threads.delete(conversationId);
@@ -14754,9 +14829,10 @@ function createVaultChatBackend(options) {
14754
14829
  }
14755
14830
  const loading = (async () => {
14756
14831
  if (!confirmedLive(conversationId)) return;
14832
+ const source = await remote();
14757
14833
  let page;
14758
14834
  do {
14759
- const result = await store.list({
14835
+ const result = await source.list({
14760
14836
  kind: "message",
14761
14837
  conversationId,
14762
14838
  limit: 200,
@@ -14766,7 +14842,15 @@ function createVaultChatBackend(options) {
14766
14842
  page = result.nextCursor;
14767
14843
  } while (page);
14768
14844
  })();
14769
- loading.catch(() => threads.delete(conversationId));
14845
+ void loading.then(
14846
+ () => {
14847
+ if (threads.get(conversationId) !== loading) return;
14848
+ complete.add(conversationId);
14849
+ saveCache();
14850
+ },
14851
+ () => threads.delete(conversationId)
14852
+ );
14853
+ complete.delete(conversationId);
14770
14854
  threads.set(conversationId, loading);
14771
14855
  evict();
14772
14856
  return loading;
@@ -14784,20 +14868,58 @@ function createVaultChatBackend(options) {
14784
14868
  const relevant2 = threads.has(record2.conversationId) || confirmed.has(k) || checked.has(k) && record2.kind !== "message";
14785
14869
  if (relevant2 && merge(snapshot)) announce([record2]);
14786
14870
  };
14871
+ const listIndex = async (source) => {
14872
+ const index = [];
14873
+ let page;
14874
+ do {
14875
+ const result = await source.list({
14876
+ kind: "conversation",
14877
+ limit: 200,
14878
+ ...page ? { cursor: page } : {}
14879
+ });
14880
+ index.push(...result.items);
14881
+ page = result.nextCursor;
14882
+ } while (page);
14883
+ return index;
14884
+ };
14885
+ const catchUp = async (source) => {
14886
+ let next = cursor ?? "";
14887
+ for (; ; ) {
14888
+ const page = await source.changes(next || void 0, { limit: 200 });
14889
+ page.items.forEach(applyRemote);
14890
+ next = page.nextCursor ?? page.changesCursor;
14891
+ if (!page.nextCursor) break;
14892
+ }
14893
+ cursor = next;
14894
+ };
14895
+ const refetch = async (source) => {
14896
+ const account = await source.account();
14897
+ const index = await listIndex(source);
14898
+ const reopened = [...threads.keys()];
14899
+ confirmed.clear();
14900
+ checked.clear();
14901
+ threads.clear();
14902
+ complete.clear();
14903
+ cursor = account.changesCursor ?? "";
14904
+ index.forEach(merge);
14905
+ emit({ type: "conversations", origin: "remote" });
14906
+ for (const conversationId of reopened)
14907
+ emit({ type: "messages", conversationId, origin: "remote" });
14908
+ };
14787
14909
  const poll = () => {
14788
14910
  polling ?? (polling = (async () => {
14789
- await ready();
14790
- let next = cursor ?? "";
14791
- for (; ; ) {
14792
- const page = await store.changes(next || void 0, { limit: 200 });
14793
- page.items.forEach(applyRemote);
14794
- next = page.nextCursor ?? page.changesCursor;
14795
- if (!page.nextCursor) break;
14796
- }
14797
- cursor = next;
14911
+ const source = await remote();
14912
+ try {
14913
+ await catchUp(source);
14914
+ } catch (error) {
14915
+ if (!cursorRejected(error)) throw error;
14916
+ await refetch(source);
14917
+ }
14798
14918
  pollFailures = 0;
14799
- })().catch(() => {
14919
+ saveCache();
14920
+ })().catch((error) => {
14800
14921
  pollFailures++;
14922
+ wipeIfTerminal(error);
14801
14923
  }).finally(() => {
14802
14924
  polling = null;
14803
14925
  schedulePoll();
@@ -14813,26 +14935,27 @@ function createVaultChatBackend(options) {
14813
14935
  };
14814
14936
  const ready = () => {
14815
14937
  readyPromise ?? (readyPromise = (async () => {
14816
- const account = await store.account();
14817
- cursor = account.changesCursor ?? "";
14818
- let page;
14819
- do {
14820
- const result = await store.list({
14821
- kind: "conversation",
14822
- limit: 200,
14823
- ...page ? { cursor: page } : {}
14824
- });
14825
- result.items.forEach(merge);
14826
- page = result.nextCursor;
14827
- } while (page);
14938
+ await seeding;
14939
+ if (!connected && typeof options.store === "function") connected = await options.store();
14940
+ const source = connected;
14941
+ const account = await source.account();
14942
+ if (!fromCache) {
14943
+ cursor = account.changesCursor ?? "";
14944
+ (await listIndex(source)).forEach(merge);
14945
+ }
14828
14946
  await adopt();
14829
14947
  schedulePoll();
14830
14948
  })());
14831
- readyPromise.catch(() => {
14949
+ readyPromise.catch((error) => {
14832
14950
  readyPromise = null;
14951
+ wipeIfTerminal(error);
14833
14952
  });
14834
14953
  return readyPromise;
14835
14954
  };
14955
+ const available2 = async () => {
14956
+ await seeding;
14957
+ if (!fromCache) await ready();
14958
+ };
14836
14959
  const adoptSlot = async (outbox, other) => {
14837
14960
  const patches = await loadOutbox(outbox.storage, other, outbox.seal.decrypt);
14838
14961
  for (const patch of patches) {
@@ -14877,20 +15000,20 @@ function createVaultChatBackend(options) {
14877
15000
  });
14878
15001
  if (channel) channel.onmessage = () => void poll();
14879
15002
  const conversation = async (conversationId) => {
14880
- await ready();
15003
+ await available2();
14881
15004
  const k = key2("conversation", conversationId);
14882
15005
  if (!view(k) && !checked.has(k)) {
14883
- const found = await store.get("conversation", conversationId);
15006
+ const found = await (await remote()).get("conversation", conversationId);
14884
15007
  checked.add(k);
14885
15008
  if (found) merge(found);
14886
15009
  }
14887
15010
  return view(k);
14888
15011
  };
14889
15012
  const message = async (uniqueId) => {
14890
- await ready();
15013
+ await available2();
14891
15014
  const k = key2("message", uniqueId);
14892
15015
  if (!view(k) && !checked.has(k)) {
14893
- const found = await store.get("message", uniqueId);
15016
+ const found = await (await remote()).get("message", uniqueId);
14894
15017
  checked.add(k);
14895
15018
  if (found) merge(found);
14896
15019
  }
@@ -14898,17 +15021,18 @@ function createVaultChatBackend(options) {
14898
15021
  return record2 && !record2.isDeleted && conversationLive(record2.conversationId) ? record2 : void 0;
14899
15022
  };
14900
15023
  const child = async (kind, conversationId) => {
14901
- await ready();
15024
+ await available2();
14902
15025
  const k = key2(kind, conversationId);
14903
15026
  if (!view(k) && !checked.has(k) && conversationLive(conversationId)) {
14904
- const found = await store.get(kind, conversationId);
15027
+ const found = await (await remote()).get(kind, conversationId);
14905
15028
  checked.add(k);
14906
15029
  if (found) merge(found);
15030
+ saveCache();
14907
15031
  }
14908
15032
  return view(k);
14909
15033
  };
14910
15034
  const thread = async (conversationId) => {
14911
- await ready();
15035
+ await available2();
14912
15036
  if (!conversationLive(conversationId)) return [];
14913
15037
  await loadThread(conversationId);
14914
15038
  return all("message", conversationId).sort(
@@ -14972,7 +15096,7 @@ function createVaultChatBackend(options) {
14972
15096
  return record2 && !record2.isDeleted ? toConversation(record2) : null;
14973
15097
  },
14974
15098
  async getConversations(query) {
14975
- await ready();
15099
+ await available2();
14976
15100
  return all("conversation").map(toConversation).filter(
14977
15101
  (c) => query?.projectId === void 0 || (query.projectId === null ? !c.projectId : c.projectId === query.projectId)
14978
15102
  ).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
@@ -15042,7 +15166,7 @@ function createVaultChatBackend(options) {
15042
15166
  return toSkeletons(await thread(conversationId));
15043
15167
  },
15044
15168
  async getMessagesByIds(uniqueIds) {
15045
- await ready();
15169
+ await available2();
15046
15170
  const ids = [...new Set(uniqueIds)];
15047
15171
  const unknown = ids.map((id2) => key2("message", id2)).filter((k) => !view(k) && !checked.has(k));
15048
15172
  await refresh(unknown);
@@ -15174,7 +15298,7 @@ function createVaultChatBackend(options) {
15174
15298
  );
15175
15299
  },
15176
15300
  async getAllFiles(query) {
15177
- await ready();
15301
+ await available2();
15178
15302
  if (query?.conversationId) await loadThread(query.conversationId);
15179
15303
  const files = [];
15180
15304
  for (const record2 of all("message", query?.conversationId)) {
@@ -15199,7 +15323,7 @@ function createVaultChatBackend(options) {
15199
15323
  const vector2 = acceptedVector(queryVector);
15200
15324
  if (!vector2) return [];
15201
15325
  await flush();
15202
- const hits = await store.search(vector2, {
15326
+ const hits = await (await remote()).search(vector2, {
15203
15327
  limit: Math.min(50, limit),
15204
15328
  kinds: ["message"],
15205
15329
  ...conversationId ? { conversationId } : {},
@@ -15306,8 +15430,9 @@ function createVaultChatBackend(options) {
15306
15430
  let messageCount = 0;
15307
15431
  try {
15308
15432
  for (const batch of batches(conversations))
15309
- conversationCount += await store.importRecords(batch);
15310
- for (const batch of batches(messages)) messageCount += await store.importRecords(batch);
15433
+ conversationCount += await connected.importRecords(batch);
15434
+ for (const batch of batches(messages))
15435
+ messageCount += await connected.importRecords(batch);
15311
15436
  } finally {
15312
15437
  for (const { record: record2 } of messages) checked.delete(key2("message", record2.id));
15313
15438
  await refresh(conversations.map(({ record: record2 }) => key2("conversation", record2.id))).catch(
@@ -15322,8 +15447,10 @@ function createVaultChatBackend(options) {
15322
15447
  return { conversations: conversationCount, messages: messageCount };
15323
15448
  },
15324
15449
  status: () => ({ pending: pending.size + inflight.size, ...stopped ? { stopped } : {} }),
15450
+ clearCache,
15325
15451
  close() {
15326
15452
  closed = true;
15453
+ clearTimeout(cacheTimer);
15327
15454
  clearTimeout(flushTimer);
15328
15455
  clearTimeout(retryTimer);
15329
15456
  clearTimeout(pollTimer);
@@ -15340,7 +15467,31 @@ function createVaultChatBackend(options) {
15340
15467
  emit({ type: "conversations", origin: "local" });
15341
15468
  return true;
15342
15469
  };
15470
+ const seed = async () => {
15471
+ if (!cache) return;
15472
+ try {
15473
+ const snapshot = await loadChatCache(cache.storage, cache.account, cache.seal.decrypt).catch(
15474
+ () => void 0
15475
+ );
15476
+ if (!snapshot || cacheOff) return;
15477
+ snapshot.records.forEach(merge);
15478
+ for (const conversationId of snapshot.threads) {
15479
+ if (!confirmedLive(conversationId)) continue;
15480
+ threads.set(conversationId, Promise.resolve());
15481
+ complete.add(conversationId);
15482
+ }
15483
+ evict();
15484
+ for (const k of snapshot.absent) checked.add(k);
15485
+ cursor = snapshot.cursor;
15486
+ fromCache = true;
15487
+ await adopt().catch(() => void 0);
15488
+ } finally {
15489
+ caching = true;
15490
+ }
15491
+ };
15492
+ const seeding = seed();
15343
15493
  void ready().catch(() => void 0);
15494
+ if (cache) void seeding.then(() => fromCache ? poll() : void 0);
15344
15495
  return backend;
15345
15496
  }
15346
15497
  function vaultChatBackend(backend) {
@@ -28123,7 +28274,7 @@ function createRemoteMemoryStore(options) {
28123
28274
  };
28124
28275
  const mutate = (id2, change, edit, writeOptions) => serialized(id2, () => mutateLocked(id2, change, edit, writeOptions));
28125
28276
  const serializedAll = (ids, task) => [...new Set(ids)].sort().reduceRight((inner, id2) => () => serialized(id2, inner), task)();
28126
- const mutateMany = async (ids, change, edit, leaseToken, signal) => {
28277
+ const mutateMany = async (ids, change, edit, leaseToken, signal, includeEmbeddings = false) => {
28127
28278
  const saved = /* @__PURE__ */ new Map();
28128
28279
  const failed = /* @__PURE__ */ new Map();
28129
28280
  for (const slice of chunks2([...new Set(ids)], MAX_BATCH)) {
@@ -28132,7 +28283,7 @@ function createRemoteMemoryStore(options) {
28132
28283
  const writes = [];
28133
28284
  let read;
28134
28285
  try {
28135
- read = await readEveryState(slice, signal);
28286
+ read = await readEveryState(slice, signal, includeEmbeddings);
28136
28287
  } catch (error) {
28137
28288
  signal?.throwIfAborted();
28138
28289
  for (const id2 of slice) failed.set(id2, error);
@@ -28191,21 +28342,55 @@ function createRemoteMemoryStore(options) {
28191
28342
  }
28192
28343
  return { saved, failed };
28193
28344
  };
28194
- const embedInBackground = ({ memory: { memory_id: id2, content } }) => {
28195
- generateEmbedding(content, embeddingOptions).then(
28196
- (vector2) => serialized(id2, async () => {
28197
- const current = await live(id2);
28198
- if (!current || current.memory.content !== content || current.memory.embedding?.length)
28199
- return;
28200
- const saved = await persistence.put(
28201
- { ...current.memory, embedding: storedVector(vector2), embedding_model: model },
28202
- current
28203
- );
28204
- notify("embedding", [saved]);
28205
- })
28206
- ).catch((error) => {
28207
- getLogger().warn("[memory/remote-store] Failed to embed memory:", error);
28208
- });
28345
+ const pendingEmbeddings = /* @__PURE__ */ new Map();
28346
+ let embeddingActive = false;
28347
+ const drainEmbeddings = async () => {
28348
+ try {
28349
+ while (pendingEmbeddings.size) {
28350
+ const batch = /* @__PURE__ */ new Map();
28351
+ for (const [id2, content] of pendingEmbeddings) {
28352
+ pendingEmbeddings.delete(id2);
28353
+ batch.set(id2, content);
28354
+ if (batch.size === MAX_BATCH) break;
28355
+ }
28356
+ try {
28357
+ const vectors = await generateEmbeddings([...batch.values()], embeddingOptions);
28358
+ const embeddings2 = /* @__PURE__ */ new Map();
28359
+ [...batch.keys()].forEach((id2, i) => {
28360
+ try {
28361
+ embeddings2.set(id2, storedVector(vectors[i]));
28362
+ } catch (error) {
28363
+ getLogger().warn("[memory/remote-store] Failed to embed memory:", error);
28364
+ }
28365
+ });
28366
+ if (!embeddings2.size) continue;
28367
+ const { failed } = await mutateMany(
28368
+ [...embeddings2.keys()],
28369
+ () => "embedding",
28370
+ (memory) => memory.content !== batch.get(memory.memory_id) || memory.embedding?.length ? null : {
28371
+ ...memory,
28372
+ embedding: embeddings2.get(memory.memory_id),
28373
+ embedding_model: model
28374
+ },
28375
+ void 0,
28376
+ void 0,
28377
+ true
28378
+ );
28379
+ for (const error of failed.values())
28380
+ getLogger().warn("[memory/remote-store] Failed to embed memory:", error);
28381
+ } catch (error) {
28382
+ getLogger().warn("[memory/remote-store] Failed to embed memories:", error);
28383
+ }
28384
+ }
28385
+ } finally {
28386
+ embeddingActive = false;
28387
+ }
28388
+ };
28389
+ const embedInBackground = (records) => {
28390
+ for (const { memory } of records) pendingEmbeddings.set(memory.memory_id, memory.content);
28391
+ if (embeddingActive || !pendingEmbeddings.size) return;
28392
+ embeddingActive = true;
28393
+ void drainEmbeddings();
28209
28394
  };
28210
28395
  const newRow = (input) => {
28211
28396
  const now = Date.now();
@@ -28239,9 +28424,7 @@ function createRemoteMemoryStore(options) {
28239
28424
  };
28240
28425
  };
28241
28426
  const created = (records, inputs) => {
28242
- records.forEach((record2, i) => {
28243
- if (inputs[i].embedding === void 0) embedInBackground(record2);
28244
- });
28427
+ embedInBackground(records.filter((_, i) => inputs[i].embedding === void 0));
28245
28428
  notify("membership", records);
28246
28429
  return records.map((record2) => stored(record2.memory));
28247
28430
  };
@@ -28271,7 +28454,7 @@ function createRemoteMemoryStore(options) {
28271
28454
  };
28272
28455
  };
28273
28456
  const withKnownKinds = async (topics) => topics.map(await knownKinds(topics));
28274
- const readEveryState = async (ids, signal) => {
28457
+ const readEveryState = async (ids, signal, includeEmbeddings = false) => {
28275
28458
  const records = /* @__PURE__ */ new Map();
28276
28459
  const unreadable = /* @__PURE__ */ new Set();
28277
28460
  for (const memory_ids of chunks2(ids, MAX_QUERY_IDS)) {
@@ -28283,6 +28466,7 @@ function createRemoteMemoryStore(options) {
28283
28466
  include_archived: true,
28284
28467
  include_quarantined: true,
28285
28468
  include_superseded: true,
28469
+ ...includeEmbeddings && { include_embeddings: true },
28286
28470
  limit: 200,
28287
28471
  ...signal && { signal },
28288
28472
  ...cursor2 && { cursor: cursor2 }
@@ -28945,7 +29129,7 @@ function createRemoteMemoryStore(options) {
28945
29129
  }
28946
29130
  return memory;
28947
29131
  });
28948
- if (saved && patch.embedding === void 0) embedInBackground(saved);
29132
+ if (saved && patch.embedding === void 0) embedInBackground([saved]);
28949
29133
  return asStored(saved);
28950
29134
  },
28951
29135
  delete: async (id2) => !!await mutate(id2, "membership", (memory) => ({ ...memory, is_deleted: true })),