@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.
- package/dist/expo/index.cjs +247 -63
- package/dist/expo/index.d.mts +17 -2
- package/dist/expo/index.d.ts +17 -2
- package/dist/expo/index.mjs +247 -63
- package/dist/react/index.cjs +247 -63
- package/dist/react/index.d.mts +17 -2
- package/dist/react/index.d.ts +17 -2
- package/dist/react/index.mjs +247 -63
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -12426,6 +12426,25 @@ async function migrateChatsToRemote(options) {
|
|
|
12426
12426
|
// src/lib/chatStore/vaultBackend.ts
|
|
12427
12427
|
import { v7 as uuidv73 } from "uuid";
|
|
12428
12428
|
|
|
12429
|
+
// src/lib/chatStore/vaultCache.ts
|
|
12430
|
+
async function saveChatCache(storage, encrypt, snapshot) {
|
|
12431
|
+
await storage.set(snapshot.account, await encrypt(JSON.stringify({ schema: 1, ...snapshot })));
|
|
12432
|
+
}
|
|
12433
|
+
async function loadChatCache(storage, account, decrypt) {
|
|
12434
|
+
const sealed2 = await storage.get(account);
|
|
12435
|
+
if (!sealed2) return void 0;
|
|
12436
|
+
const parsed = JSON.parse(await decrypt(sealed2));
|
|
12437
|
+
if (parsed.schema !== 1 || parsed.account !== account || typeof parsed.cursor !== "string" || !Array.isArray(parsed.records) || !Array.isArray(parsed.threads) || !Array.isArray(parsed.absent))
|
|
12438
|
+
return void 0;
|
|
12439
|
+
return {
|
|
12440
|
+
account,
|
|
12441
|
+
cursor: parsed.cursor,
|
|
12442
|
+
records: parsed.records,
|
|
12443
|
+
threads: parsed.threads,
|
|
12444
|
+
absent: parsed.absent
|
|
12445
|
+
};
|
|
12446
|
+
}
|
|
12447
|
+
|
|
12429
12448
|
// src/lib/chatStore/vaultOutbox.ts
|
|
12430
12449
|
function patchKey(patch) {
|
|
12431
12450
|
return `${patch.kind}/${patch.id}`;
|
|
@@ -12530,6 +12549,10 @@ async function loadOutbox(storage, slot, decrypt) {
|
|
|
12530
12549
|
|
|
12531
12550
|
// src/lib/chatStore/vaultBackend.ts
|
|
12532
12551
|
var terminalCodes = /* @__PURE__ */ new Set(["key_mismatch", "account_changed", "account_not_found"]);
|
|
12552
|
+
var cacheSaveDelayMs = 500;
|
|
12553
|
+
function cursorRejected(error) {
|
|
12554
|
+
return error instanceof ChatStoreError && (error.status === 400 || error.status === 410);
|
|
12555
|
+
}
|
|
12533
12556
|
function key2(kind, id2) {
|
|
12534
12557
|
return `${kind}/${id2}`;
|
|
12535
12558
|
}
|
|
@@ -12574,7 +12597,7 @@ function defaultActivity() {
|
|
|
12574
12597
|
};
|
|
12575
12598
|
}
|
|
12576
12599
|
function createVaultChatBackend(options) {
|
|
12577
|
-
const {
|
|
12600
|
+
const { cache } = options;
|
|
12578
12601
|
const now = options.now ?? Date.now;
|
|
12579
12602
|
const threadLimit = options.threadCacheSize ?? 30;
|
|
12580
12603
|
const pollIntervalMs = options.pollIntervalMs ?? 6e4;
|
|
@@ -12601,6 +12624,13 @@ function createVaultChatBackend(options) {
|
|
|
12601
12624
|
let persisting = Promise.resolve();
|
|
12602
12625
|
let readyPromise = null;
|
|
12603
12626
|
let adopting = null;
|
|
12627
|
+
let connected = typeof options.store === "function" ? void 0 : options.store;
|
|
12628
|
+
const complete = /* @__PURE__ */ new Set();
|
|
12629
|
+
let fromCache = false;
|
|
12630
|
+
let caching = false;
|
|
12631
|
+
let cacheOff = false;
|
|
12632
|
+
let cacheTimer;
|
|
12633
|
+
let saving = Promise.resolve();
|
|
12604
12634
|
const slot = uuidv73();
|
|
12605
12635
|
const locks = options.outbox?.locks ?? globalThis.navigator?.locks;
|
|
12606
12636
|
let releaseSlot;
|
|
@@ -12637,13 +12667,55 @@ function createVaultChatBackend(options) {
|
|
|
12637
12667
|
}
|
|
12638
12668
|
return out;
|
|
12639
12669
|
};
|
|
12670
|
+
const cacheSnapshot = () => {
|
|
12671
|
+
const kept = [...threads.keys()].filter((id2) => complete.has(id2) && confirmedLive(id2));
|
|
12672
|
+
const keep = new Set(kept);
|
|
12673
|
+
return {
|
|
12674
|
+
account: cache.account,
|
|
12675
|
+
cursor: cursor ?? "",
|
|
12676
|
+
records: [...confirmed.values()].filter(
|
|
12677
|
+
({ record: record2 }) => record2.kind === "conversation" || record2.kind !== "project" && keep.has(record2.conversationId)
|
|
12678
|
+
),
|
|
12679
|
+
threads: kept,
|
|
12680
|
+
absent: [...checked].filter((k) => {
|
|
12681
|
+
const [kind, ...rest] = k.split("/");
|
|
12682
|
+
return (kind === "summary" || kind === "memory_links") && !confirmed.has(k) && keep.has(rest.join("/"));
|
|
12683
|
+
})
|
|
12684
|
+
};
|
|
12685
|
+
};
|
|
12686
|
+
const saveCache = () => {
|
|
12687
|
+
if (!cache || !caching || cacheOff || closed || cacheTimer || cursor === void 0) return;
|
|
12688
|
+
cacheTimer = setTimeout(() => {
|
|
12689
|
+
cacheTimer = void 0;
|
|
12690
|
+
saving = saving.then(
|
|
12691
|
+
() => cacheOff || closed ? void 0 : saveChatCache(cache.storage, cache.seal.encrypt, cacheSnapshot())
|
|
12692
|
+
).catch(() => void 0);
|
|
12693
|
+
}, cacheSaveDelayMs);
|
|
12694
|
+
};
|
|
12695
|
+
const clearCache = async () => {
|
|
12696
|
+
fromCache = false;
|
|
12697
|
+
cacheOff = true;
|
|
12698
|
+
clearTimeout(cacheTimer);
|
|
12699
|
+
cacheTimer = void 0;
|
|
12700
|
+
await saving;
|
|
12701
|
+
if (cache) await cache.storage.set(cache.account, null);
|
|
12702
|
+
};
|
|
12703
|
+
const wipeIfTerminal = (error) => {
|
|
12704
|
+
if (error instanceof ChatStoreError && terminalCodes.has(error.code ?? ""))
|
|
12705
|
+
void clearCache().catch(() => void 0);
|
|
12706
|
+
};
|
|
12640
12707
|
const merge = (snapshot) => {
|
|
12641
12708
|
const k = key2(snapshot.record.kind, snapshot.record.id);
|
|
12642
12709
|
const known = confirmed.get(k);
|
|
12643
12710
|
if (known && known.version >= snapshot.version) return false;
|
|
12644
12711
|
confirmed.set(k, snapshot);
|
|
12712
|
+
saveCache();
|
|
12645
12713
|
return true;
|
|
12646
12714
|
};
|
|
12715
|
+
const remote = async () => {
|
|
12716
|
+
await ready();
|
|
12717
|
+
return connected;
|
|
12718
|
+
};
|
|
12647
12719
|
const persist = () => {
|
|
12648
12720
|
const storage = options.outbox;
|
|
12649
12721
|
if (!storage) return Promise.resolve();
|
|
@@ -12698,7 +12770,7 @@ function createVaultChatBackend(options) {
|
|
|
12698
12770
|
return { kind, id: rest.join("/") };
|
|
12699
12771
|
});
|
|
12700
12772
|
if (refs.length === 0) return;
|
|
12701
|
-
const found = await
|
|
12773
|
+
const found = await (await remote()).getMany(refs);
|
|
12702
12774
|
const seen = new Set(found.map((s) => key2(s.record.kind, s.record.id)));
|
|
12703
12775
|
for (const snapshot of found) merge(snapshot);
|
|
12704
12776
|
for (const ref3 of refs) {
|
|
@@ -12706,6 +12778,7 @@ function createVaultChatBackend(options) {
|
|
|
12706
12778
|
if (!seen.has(k)) confirmed.delete(k);
|
|
12707
12779
|
checked.add(k);
|
|
12708
12780
|
}
|
|
12781
|
+
saveCache();
|
|
12709
12782
|
};
|
|
12710
12783
|
const drop = (patch, reason) => {
|
|
12711
12784
|
inflight.delete(patchKey(patch));
|
|
@@ -12760,7 +12833,7 @@ function createVaultChatBackend(options) {
|
|
|
12760
12833
|
sent.push(patch);
|
|
12761
12834
|
}
|
|
12762
12835
|
if (writes.length === 0) return;
|
|
12763
|
-
const results = await
|
|
12836
|
+
const results = await (await remote()).putMany(writes);
|
|
12764
12837
|
results.forEach((snapshot, i) => {
|
|
12765
12838
|
merge(snapshot);
|
|
12766
12839
|
checked.add(patchKey(sent[i]));
|
|
@@ -12794,6 +12867,7 @@ function createVaultChatBackend(options) {
|
|
|
12794
12867
|
}
|
|
12795
12868
|
if (terminalCodes.has(error.code ?? "")) {
|
|
12796
12869
|
stopped = error.code;
|
|
12870
|
+
wipeIfTerminal(error);
|
|
12797
12871
|
reportOutbox();
|
|
12798
12872
|
return "stop";
|
|
12799
12873
|
}
|
|
@@ -12860,6 +12934,7 @@ function createVaultChatBackend(options) {
|
|
|
12860
12934
|
const forget = (k) => {
|
|
12861
12935
|
confirmed.delete(k);
|
|
12862
12936
|
checked.delete(k);
|
|
12937
|
+
saveCache();
|
|
12863
12938
|
};
|
|
12864
12939
|
const forgetConversation = (conversationId) => {
|
|
12865
12940
|
threads.delete(conversationId);
|
|
@@ -12886,9 +12961,10 @@ function createVaultChatBackend(options) {
|
|
|
12886
12961
|
}
|
|
12887
12962
|
const loading = (async () => {
|
|
12888
12963
|
if (!confirmedLive(conversationId)) return;
|
|
12964
|
+
const source = await remote();
|
|
12889
12965
|
let page;
|
|
12890
12966
|
do {
|
|
12891
|
-
const result = await
|
|
12967
|
+
const result = await source.list({
|
|
12892
12968
|
kind: "message",
|
|
12893
12969
|
conversationId,
|
|
12894
12970
|
limit: 200,
|
|
@@ -12898,7 +12974,15 @@ function createVaultChatBackend(options) {
|
|
|
12898
12974
|
page = result.nextCursor;
|
|
12899
12975
|
} while (page);
|
|
12900
12976
|
})();
|
|
12901
|
-
loading.
|
|
12977
|
+
void loading.then(
|
|
12978
|
+
() => {
|
|
12979
|
+
if (threads.get(conversationId) !== loading) return;
|
|
12980
|
+
complete.add(conversationId);
|
|
12981
|
+
saveCache();
|
|
12982
|
+
},
|
|
12983
|
+
() => threads.delete(conversationId)
|
|
12984
|
+
);
|
|
12985
|
+
complete.delete(conversationId);
|
|
12902
12986
|
threads.set(conversationId, loading);
|
|
12903
12987
|
evict();
|
|
12904
12988
|
return loading;
|
|
@@ -12916,20 +13000,58 @@ function createVaultChatBackend(options) {
|
|
|
12916
13000
|
const relevant2 = threads.has(record2.conversationId) || confirmed.has(k) || checked.has(k) && record2.kind !== "message";
|
|
12917
13001
|
if (relevant2 && merge(snapshot)) announce([record2]);
|
|
12918
13002
|
};
|
|
13003
|
+
const listIndex = async (source) => {
|
|
13004
|
+
const index = [];
|
|
13005
|
+
let page;
|
|
13006
|
+
do {
|
|
13007
|
+
const result = await source.list({
|
|
13008
|
+
kind: "conversation",
|
|
13009
|
+
limit: 200,
|
|
13010
|
+
...page ? { cursor: page } : {}
|
|
13011
|
+
});
|
|
13012
|
+
index.push(...result.items);
|
|
13013
|
+
page = result.nextCursor;
|
|
13014
|
+
} while (page);
|
|
13015
|
+
return index;
|
|
13016
|
+
};
|
|
13017
|
+
const catchUp = async (source) => {
|
|
13018
|
+
let next = cursor ?? "";
|
|
13019
|
+
for (; ; ) {
|
|
13020
|
+
const page = await source.changes(next || void 0, { limit: 200 });
|
|
13021
|
+
page.items.forEach(applyRemote);
|
|
13022
|
+
next = page.nextCursor ?? page.changesCursor;
|
|
13023
|
+
if (!page.nextCursor) break;
|
|
13024
|
+
}
|
|
13025
|
+
cursor = next;
|
|
13026
|
+
};
|
|
13027
|
+
const refetch = async (source) => {
|
|
13028
|
+
const account = await source.account();
|
|
13029
|
+
const index = await listIndex(source);
|
|
13030
|
+
const reopened = [...threads.keys()];
|
|
13031
|
+
confirmed.clear();
|
|
13032
|
+
checked.clear();
|
|
13033
|
+
threads.clear();
|
|
13034
|
+
complete.clear();
|
|
13035
|
+
cursor = account.changesCursor ?? "";
|
|
13036
|
+
index.forEach(merge);
|
|
13037
|
+
emit({ type: "conversations", origin: "remote" });
|
|
13038
|
+
for (const conversationId of reopened)
|
|
13039
|
+
emit({ type: "messages", conversationId, origin: "remote" });
|
|
13040
|
+
};
|
|
12919
13041
|
const poll = () => {
|
|
12920
13042
|
polling ?? (polling = (async () => {
|
|
12921
|
-
await
|
|
12922
|
-
|
|
12923
|
-
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
|
|
12927
|
-
|
|
12928
|
-
}
|
|
12929
|
-
cursor = next;
|
|
13043
|
+
const source = await remote();
|
|
13044
|
+
try {
|
|
13045
|
+
await catchUp(source);
|
|
13046
|
+
} catch (error) {
|
|
13047
|
+
if (!cursorRejected(error)) throw error;
|
|
13048
|
+
await refetch(source);
|
|
13049
|
+
}
|
|
12930
13050
|
pollFailures = 0;
|
|
12931
|
-
|
|
13051
|
+
saveCache();
|
|
13052
|
+
})().catch((error) => {
|
|
12932
13053
|
pollFailures++;
|
|
13054
|
+
wipeIfTerminal(error);
|
|
12933
13055
|
}).finally(() => {
|
|
12934
13056
|
polling = null;
|
|
12935
13057
|
schedulePoll();
|
|
@@ -12945,26 +13067,27 @@ function createVaultChatBackend(options) {
|
|
|
12945
13067
|
};
|
|
12946
13068
|
const ready = () => {
|
|
12947
13069
|
readyPromise ?? (readyPromise = (async () => {
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
12952
|
-
|
|
12953
|
-
|
|
12954
|
-
|
|
12955
|
-
|
|
12956
|
-
});
|
|
12957
|
-
result.items.forEach(merge);
|
|
12958
|
-
page = result.nextCursor;
|
|
12959
|
-
} while (page);
|
|
13070
|
+
await seeding;
|
|
13071
|
+
if (!connected && typeof options.store === "function") connected = await options.store();
|
|
13072
|
+
const source = connected;
|
|
13073
|
+
const account = await source.account();
|
|
13074
|
+
if (!fromCache) {
|
|
13075
|
+
cursor = account.changesCursor ?? "";
|
|
13076
|
+
(await listIndex(source)).forEach(merge);
|
|
13077
|
+
}
|
|
12960
13078
|
await adopt();
|
|
12961
13079
|
schedulePoll();
|
|
12962
13080
|
})());
|
|
12963
|
-
readyPromise.catch(() => {
|
|
13081
|
+
readyPromise.catch((error) => {
|
|
12964
13082
|
readyPromise = null;
|
|
13083
|
+
wipeIfTerminal(error);
|
|
12965
13084
|
});
|
|
12966
13085
|
return readyPromise;
|
|
12967
13086
|
};
|
|
13087
|
+
const available2 = async () => {
|
|
13088
|
+
await seeding;
|
|
13089
|
+
if (!fromCache) await ready();
|
|
13090
|
+
};
|
|
12968
13091
|
const adoptSlot = async (outbox, other) => {
|
|
12969
13092
|
const patches = await loadOutbox(outbox.storage, other, outbox.seal.decrypt);
|
|
12970
13093
|
for (const patch of patches) {
|
|
@@ -13009,20 +13132,20 @@ function createVaultChatBackend(options) {
|
|
|
13009
13132
|
});
|
|
13010
13133
|
if (channel) channel.onmessage = () => void poll();
|
|
13011
13134
|
const conversation = async (conversationId) => {
|
|
13012
|
-
await
|
|
13135
|
+
await available2();
|
|
13013
13136
|
const k = key2("conversation", conversationId);
|
|
13014
13137
|
if (!view(k) && !checked.has(k)) {
|
|
13015
|
-
const found = await
|
|
13138
|
+
const found = await (await remote()).get("conversation", conversationId);
|
|
13016
13139
|
checked.add(k);
|
|
13017
13140
|
if (found) merge(found);
|
|
13018
13141
|
}
|
|
13019
13142
|
return view(k);
|
|
13020
13143
|
};
|
|
13021
13144
|
const message = async (uniqueId) => {
|
|
13022
|
-
await
|
|
13145
|
+
await available2();
|
|
13023
13146
|
const k = key2("message", uniqueId);
|
|
13024
13147
|
if (!view(k) && !checked.has(k)) {
|
|
13025
|
-
const found = await
|
|
13148
|
+
const found = await (await remote()).get("message", uniqueId);
|
|
13026
13149
|
checked.add(k);
|
|
13027
13150
|
if (found) merge(found);
|
|
13028
13151
|
}
|
|
@@ -13030,17 +13153,18 @@ function createVaultChatBackend(options) {
|
|
|
13030
13153
|
return record2 && !record2.isDeleted && conversationLive(record2.conversationId) ? record2 : void 0;
|
|
13031
13154
|
};
|
|
13032
13155
|
const child = async (kind, conversationId) => {
|
|
13033
|
-
await
|
|
13156
|
+
await available2();
|
|
13034
13157
|
const k = key2(kind, conversationId);
|
|
13035
13158
|
if (!view(k) && !checked.has(k) && conversationLive(conversationId)) {
|
|
13036
|
-
const found = await
|
|
13159
|
+
const found = await (await remote()).get(kind, conversationId);
|
|
13037
13160
|
checked.add(k);
|
|
13038
13161
|
if (found) merge(found);
|
|
13162
|
+
saveCache();
|
|
13039
13163
|
}
|
|
13040
13164
|
return view(k);
|
|
13041
13165
|
};
|
|
13042
13166
|
const thread = async (conversationId) => {
|
|
13043
|
-
await
|
|
13167
|
+
await available2();
|
|
13044
13168
|
if (!conversationLive(conversationId)) return [];
|
|
13045
13169
|
await loadThread(conversationId);
|
|
13046
13170
|
return all("message", conversationId).sort(
|
|
@@ -13104,7 +13228,7 @@ function createVaultChatBackend(options) {
|
|
|
13104
13228
|
return record2 && !record2.isDeleted ? toConversation(record2) : null;
|
|
13105
13229
|
},
|
|
13106
13230
|
async getConversations(query) {
|
|
13107
|
-
await
|
|
13231
|
+
await available2();
|
|
13108
13232
|
return all("conversation").map(toConversation).filter(
|
|
13109
13233
|
(c) => query?.projectId === void 0 || (query.projectId === null ? !c.projectId : c.projectId === query.projectId)
|
|
13110
13234
|
).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
@@ -13174,7 +13298,7 @@ function createVaultChatBackend(options) {
|
|
|
13174
13298
|
return toSkeletons(await thread(conversationId));
|
|
13175
13299
|
},
|
|
13176
13300
|
async getMessagesByIds(uniqueIds) {
|
|
13177
|
-
await
|
|
13301
|
+
await available2();
|
|
13178
13302
|
const ids = [...new Set(uniqueIds)];
|
|
13179
13303
|
const unknown = ids.map((id2) => key2("message", id2)).filter((k) => !view(k) && !checked.has(k));
|
|
13180
13304
|
await refresh(unknown);
|
|
@@ -13306,7 +13430,7 @@ function createVaultChatBackend(options) {
|
|
|
13306
13430
|
);
|
|
13307
13431
|
},
|
|
13308
13432
|
async getAllFiles(query) {
|
|
13309
|
-
await
|
|
13433
|
+
await available2();
|
|
13310
13434
|
if (query?.conversationId) await loadThread(query.conversationId);
|
|
13311
13435
|
const files = [];
|
|
13312
13436
|
for (const record2 of all("message", query?.conversationId)) {
|
|
@@ -13331,7 +13455,7 @@ function createVaultChatBackend(options) {
|
|
|
13331
13455
|
const vector2 = acceptedVector(queryVector);
|
|
13332
13456
|
if (!vector2) return [];
|
|
13333
13457
|
await flush();
|
|
13334
|
-
const hits = await
|
|
13458
|
+
const hits = await (await remote()).search(vector2, {
|
|
13335
13459
|
limit: Math.min(50, limit),
|
|
13336
13460
|
kinds: ["message"],
|
|
13337
13461
|
...conversationId ? { conversationId } : {},
|
|
@@ -13438,8 +13562,9 @@ function createVaultChatBackend(options) {
|
|
|
13438
13562
|
let messageCount = 0;
|
|
13439
13563
|
try {
|
|
13440
13564
|
for (const batch of batches(conversations))
|
|
13441
|
-
conversationCount += await
|
|
13442
|
-
for (const batch of batches(messages))
|
|
13565
|
+
conversationCount += await connected.importRecords(batch);
|
|
13566
|
+
for (const batch of batches(messages))
|
|
13567
|
+
messageCount += await connected.importRecords(batch);
|
|
13443
13568
|
} finally {
|
|
13444
13569
|
for (const { record: record2 } of messages) checked.delete(key2("message", record2.id));
|
|
13445
13570
|
await refresh(conversations.map(({ record: record2 }) => key2("conversation", record2.id))).catch(
|
|
@@ -13454,8 +13579,10 @@ function createVaultChatBackend(options) {
|
|
|
13454
13579
|
return { conversations: conversationCount, messages: messageCount };
|
|
13455
13580
|
},
|
|
13456
13581
|
status: () => ({ pending: pending.size + inflight.size, ...stopped ? { stopped } : {} }),
|
|
13582
|
+
clearCache,
|
|
13457
13583
|
close() {
|
|
13458
13584
|
closed = true;
|
|
13585
|
+
clearTimeout(cacheTimer);
|
|
13459
13586
|
clearTimeout(flushTimer);
|
|
13460
13587
|
clearTimeout(retryTimer);
|
|
13461
13588
|
clearTimeout(pollTimer);
|
|
@@ -13472,7 +13599,31 @@ function createVaultChatBackend(options) {
|
|
|
13472
13599
|
emit({ type: "conversations", origin: "local" });
|
|
13473
13600
|
return true;
|
|
13474
13601
|
};
|
|
13602
|
+
const seed = async () => {
|
|
13603
|
+
if (!cache) return;
|
|
13604
|
+
try {
|
|
13605
|
+
const snapshot = await loadChatCache(cache.storage, cache.account, cache.seal.decrypt).catch(
|
|
13606
|
+
() => void 0
|
|
13607
|
+
);
|
|
13608
|
+
if (!snapshot || cacheOff) return;
|
|
13609
|
+
snapshot.records.forEach(merge);
|
|
13610
|
+
for (const conversationId of snapshot.threads) {
|
|
13611
|
+
if (!confirmedLive(conversationId)) continue;
|
|
13612
|
+
threads.set(conversationId, Promise.resolve());
|
|
13613
|
+
complete.add(conversationId);
|
|
13614
|
+
}
|
|
13615
|
+
evict();
|
|
13616
|
+
for (const k of snapshot.absent) checked.add(k);
|
|
13617
|
+
cursor = snapshot.cursor;
|
|
13618
|
+
fromCache = true;
|
|
13619
|
+
await adopt().catch(() => void 0);
|
|
13620
|
+
} finally {
|
|
13621
|
+
caching = true;
|
|
13622
|
+
}
|
|
13623
|
+
};
|
|
13624
|
+
const seeding = seed();
|
|
13475
13625
|
void ready().catch(() => void 0);
|
|
13626
|
+
if (cache) void seeding.then(() => fromCache ? poll() : void 0);
|
|
13476
13627
|
return backend;
|
|
13477
13628
|
}
|
|
13478
13629
|
function vaultChatBackend(backend) {
|
|
@@ -26202,7 +26353,7 @@ function createRemoteMemoryStore(options) {
|
|
|
26202
26353
|
};
|
|
26203
26354
|
const mutate = (id2, change, edit, writeOptions) => serialized(id2, () => mutateLocked(id2, change, edit, writeOptions));
|
|
26204
26355
|
const serializedAll = (ids, task) => [...new Set(ids)].sort().reduceRight((inner, id2) => () => serialized(id2, inner), task)();
|
|
26205
|
-
const mutateMany = async (ids, change, edit, leaseToken, signal) => {
|
|
26356
|
+
const mutateMany = async (ids, change, edit, leaseToken, signal, includeEmbeddings = false) => {
|
|
26206
26357
|
const saved = /* @__PURE__ */ new Map();
|
|
26207
26358
|
const failed = /* @__PURE__ */ new Map();
|
|
26208
26359
|
for (const slice of chunks2([...new Set(ids)], MAX_BATCH)) {
|
|
@@ -26211,7 +26362,7 @@ function createRemoteMemoryStore(options) {
|
|
|
26211
26362
|
const writes = [];
|
|
26212
26363
|
let read;
|
|
26213
26364
|
try {
|
|
26214
|
-
read = await readEveryState(slice, signal);
|
|
26365
|
+
read = await readEveryState(slice, signal, includeEmbeddings);
|
|
26215
26366
|
} catch (error) {
|
|
26216
26367
|
signal?.throwIfAborted();
|
|
26217
26368
|
for (const id2 of slice) failed.set(id2, error);
|
|
@@ -26270,21 +26421,55 @@ function createRemoteMemoryStore(options) {
|
|
|
26270
26421
|
}
|
|
26271
26422
|
return { saved, failed };
|
|
26272
26423
|
};
|
|
26273
|
-
const
|
|
26274
|
-
|
|
26275
|
-
|
|
26276
|
-
|
|
26277
|
-
|
|
26278
|
-
|
|
26279
|
-
const
|
|
26280
|
-
|
|
26281
|
-
|
|
26282
|
-
|
|
26283
|
-
|
|
26284
|
-
|
|
26285
|
-
|
|
26286
|
-
|
|
26287
|
-
|
|
26424
|
+
const pendingEmbeddings = /* @__PURE__ */ new Map();
|
|
26425
|
+
let embeddingActive = false;
|
|
26426
|
+
const drainEmbeddings = async () => {
|
|
26427
|
+
try {
|
|
26428
|
+
while (pendingEmbeddings.size) {
|
|
26429
|
+
const batch = /* @__PURE__ */ new Map();
|
|
26430
|
+
for (const [id2, content] of pendingEmbeddings) {
|
|
26431
|
+
pendingEmbeddings.delete(id2);
|
|
26432
|
+
batch.set(id2, content);
|
|
26433
|
+
if (batch.size === MAX_BATCH) break;
|
|
26434
|
+
}
|
|
26435
|
+
try {
|
|
26436
|
+
const vectors = await generateEmbeddings([...batch.values()], embeddingOptions);
|
|
26437
|
+
const embeddings2 = /* @__PURE__ */ new Map();
|
|
26438
|
+
[...batch.keys()].forEach((id2, i) => {
|
|
26439
|
+
try {
|
|
26440
|
+
embeddings2.set(id2, storedVector(vectors[i]));
|
|
26441
|
+
} catch (error) {
|
|
26442
|
+
getLogger().warn("[memory/remote-store] Failed to embed memory:", error);
|
|
26443
|
+
}
|
|
26444
|
+
});
|
|
26445
|
+
if (!embeddings2.size) continue;
|
|
26446
|
+
const { failed } = await mutateMany(
|
|
26447
|
+
[...embeddings2.keys()],
|
|
26448
|
+
() => "embedding",
|
|
26449
|
+
(memory) => memory.content !== batch.get(memory.memory_id) || memory.embedding?.length ? null : {
|
|
26450
|
+
...memory,
|
|
26451
|
+
embedding: embeddings2.get(memory.memory_id),
|
|
26452
|
+
embedding_model: model
|
|
26453
|
+
},
|
|
26454
|
+
void 0,
|
|
26455
|
+
void 0,
|
|
26456
|
+
true
|
|
26457
|
+
);
|
|
26458
|
+
for (const error of failed.values())
|
|
26459
|
+
getLogger().warn("[memory/remote-store] Failed to embed memory:", error);
|
|
26460
|
+
} catch (error) {
|
|
26461
|
+
getLogger().warn("[memory/remote-store] Failed to embed memories:", error);
|
|
26462
|
+
}
|
|
26463
|
+
}
|
|
26464
|
+
} finally {
|
|
26465
|
+
embeddingActive = false;
|
|
26466
|
+
}
|
|
26467
|
+
};
|
|
26468
|
+
const embedInBackground = (records) => {
|
|
26469
|
+
for (const { memory } of records) pendingEmbeddings.set(memory.memory_id, memory.content);
|
|
26470
|
+
if (embeddingActive || !pendingEmbeddings.size) return;
|
|
26471
|
+
embeddingActive = true;
|
|
26472
|
+
void drainEmbeddings();
|
|
26288
26473
|
};
|
|
26289
26474
|
const newRow = (input) => {
|
|
26290
26475
|
const now = Date.now();
|
|
@@ -26318,9 +26503,7 @@ function createRemoteMemoryStore(options) {
|
|
|
26318
26503
|
};
|
|
26319
26504
|
};
|
|
26320
26505
|
const created = (records, inputs) => {
|
|
26321
|
-
records.
|
|
26322
|
-
if (inputs[i].embedding === void 0) embedInBackground(record2);
|
|
26323
|
-
});
|
|
26506
|
+
embedInBackground(records.filter((_, i) => inputs[i].embedding === void 0));
|
|
26324
26507
|
notify("membership", records);
|
|
26325
26508
|
return records.map((record2) => stored(record2.memory));
|
|
26326
26509
|
};
|
|
@@ -26350,7 +26533,7 @@ function createRemoteMemoryStore(options) {
|
|
|
26350
26533
|
};
|
|
26351
26534
|
};
|
|
26352
26535
|
const withKnownKinds = async (topics) => topics.map(await knownKinds(topics));
|
|
26353
|
-
const readEveryState = async (ids, signal) => {
|
|
26536
|
+
const readEveryState = async (ids, signal, includeEmbeddings = false) => {
|
|
26354
26537
|
const records = /* @__PURE__ */ new Map();
|
|
26355
26538
|
const unreadable = /* @__PURE__ */ new Set();
|
|
26356
26539
|
for (const memory_ids of chunks2(ids, MAX_QUERY_IDS)) {
|
|
@@ -26362,6 +26545,7 @@ function createRemoteMemoryStore(options) {
|
|
|
26362
26545
|
include_archived: true,
|
|
26363
26546
|
include_quarantined: true,
|
|
26364
26547
|
include_superseded: true,
|
|
26548
|
+
...includeEmbeddings && { include_embeddings: true },
|
|
26365
26549
|
limit: 200,
|
|
26366
26550
|
...signal && { signal },
|
|
26367
26551
|
...cursor2 && { cursor: cursor2 }
|
|
@@ -27024,7 +27208,7 @@ function createRemoteMemoryStore(options) {
|
|
|
27024
27208
|
}
|
|
27025
27209
|
return memory;
|
|
27026
27210
|
});
|
|
27027
|
-
if (saved && patch.embedding === void 0) embedInBackground(saved);
|
|
27211
|
+
if (saved && patch.embedding === void 0) embedInBackground([saved]);
|
|
27028
27212
|
return asStored(saved);
|
|
27029
27213
|
},
|
|
27030
27214
|
delete: async (id2) => !!await mutate(id2, "membership", (memory) => ({ ...memory, is_deleted: true })),
|