@anuma/sdk 6.38.0 → 6.39.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/expo/index.cjs +192 -96
- package/dist/expo/index.d.mts +5653 -5644
- package/dist/expo/index.d.ts +5653 -5644
- package/dist/expo/index.mjs +192 -96
- package/dist/index.d.mts +62 -62
- package/dist/index.d.ts +62 -62
- package/dist/react/index.cjs +192 -91
- package/dist/react/index.d.mts +7032 -7023
- package/dist/react/index.d.ts +7032 -7023
- package/dist/react/index.mjs +192 -91
- package/dist/server/index.cjs +91 -39
- package/dist/server/index.d.mts +6173 -6167
- package/dist/server/index.d.ts +6173 -6167
- package/dist/server/index.mjs +91 -39
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -20184,7 +20184,6 @@ async function recall(query, ctx, options = {}) {
|
|
|
20184
20184
|
}
|
|
20185
20185
|
const needsChunkEmbedding = types.includes("chunk") && ctx.storageCtx;
|
|
20186
20186
|
const wantsTemporal = types.includes("fact") && (ctx.factSource || ctx.vaultCtx);
|
|
20187
|
-
const graphRefiner = flags.traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
|
|
20188
20187
|
const queryEmbedTotalTimeoutMs = options.queryEmbedTotalTimeoutMs ?? DEFAULT_QUERY_EMBED_TOTAL_TIMEOUT_MS;
|
|
20189
20188
|
const prepStart = nowMs2();
|
|
20190
20189
|
let sharedEmbedMs = 0;
|
|
@@ -20213,13 +20212,12 @@ async function recall(query, ctx, options = {}) {
|
|
|
20213
20212
|
safeLane(
|
|
20214
20213
|
"graph",
|
|
20215
20214
|
() => graphLaneFailed = true,
|
|
20216
|
-
() => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(
|
|
20217
|
-
|
|
20218
|
-
|
|
20219
|
-
|
|
20220
|
-
|
|
20221
|
-
|
|
20222
|
-
})
|
|
20215
|
+
() => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(
|
|
20216
|
+
query,
|
|
20217
|
+
ctx,
|
|
20218
|
+
flags.traverse,
|
|
20219
|
+
graphTraversalOptions(options, flags.traverse)
|
|
20220
|
+
)
|
|
20223
20221
|
),
|
|
20224
20222
|
wantsTemporal ? safeLane(
|
|
20225
20223
|
"temporal",
|
|
@@ -20438,6 +20436,16 @@ function toFactMemory(r, now) {
|
|
|
20438
20436
|
updatedAt: r.updatedAt ?? /* @__PURE__ */ new Date(0)
|
|
20439
20437
|
};
|
|
20440
20438
|
}
|
|
20439
|
+
function graphTraversalOptions(options, traverse) {
|
|
20440
|
+
const refineNeighbors = traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
|
|
20441
|
+
return {
|
|
20442
|
+
...options.maxHops !== void 0 && { maxHops: options.maxHops },
|
|
20443
|
+
...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
|
|
20444
|
+
...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
|
|
20445
|
+
...options.rrfK !== void 0 && { rrfK: options.rrfK },
|
|
20446
|
+
...refineNeighbors && { refineNeighbors }
|
|
20447
|
+
};
|
|
20448
|
+
}
|
|
20441
20449
|
async function buildGraphLaneRanking(query, ctx, traverse = false, traversalOptions = {}) {
|
|
20442
20450
|
const entityCtx = ctx.entityCtx ?? ctx.vaultCtx?.entityCtx;
|
|
20443
20451
|
if (!entityCtx) return [];
|
|
@@ -20603,24 +20611,33 @@ function isDumpQuery(query) {
|
|
|
20603
20611
|
return false;
|
|
20604
20612
|
}
|
|
20605
20613
|
async function listRecentFacts(ctx, limit, toolOptions) {
|
|
20614
|
+
const store = toolOptions?.memoryStore;
|
|
20606
20615
|
const vaultCtx = ctx.vaultCtx;
|
|
20607
|
-
if (!vaultCtx) return [];
|
|
20608
|
-
const
|
|
20616
|
+
if (!vaultCtx && !store) return [];
|
|
20617
|
+
const read = (ids) => store ? store.list({ memoryIds: ids }) : getVaultMemoriesByIdsOp(vaultCtx, ids);
|
|
20618
|
+
const filters = {
|
|
20609
20619
|
...toolOptions?.scopes && { scopes: toolOptions.scopes },
|
|
20610
|
-
...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds }
|
|
20620
|
+
...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds }
|
|
20621
|
+
};
|
|
20622
|
+
const project = (size) => store ? store.listProjections({ ...filters, limit: size }) : getVaultRankingProjectionsOp(vaultCtx, {
|
|
20623
|
+
...filters,
|
|
20611
20624
|
...toolOptions?.folderId !== void 0 && { folderId: toolOptions.folderId }
|
|
20612
20625
|
});
|
|
20613
20626
|
const readable = [];
|
|
20614
|
-
|
|
20615
|
-
|
|
20616
|
-
const
|
|
20617
|
-
|
|
20618
|
-
|
|
20619
|
-
|
|
20620
|
-
const
|
|
20621
|
-
|
|
20622
|
-
|
|
20627
|
+
let start = 0;
|
|
20628
|
+
for (let size = limit; readable.length < limit; size *= 2) {
|
|
20629
|
+
const ordered = await project(size);
|
|
20630
|
+
for (let i = start; i < ordered.length && readable.length < limit; i += limit) {
|
|
20631
|
+
const batch = ordered.slice(i, i + limit).map((p) => p.uniqueId);
|
|
20632
|
+
const byId = new Map((await read(batch)).map((m) => [m.uniqueId, m]));
|
|
20633
|
+
for (const id of batch) {
|
|
20634
|
+
const m = byId.get(id);
|
|
20635
|
+
if (m && !isEncrypted(m.content)) readable.push(m);
|
|
20636
|
+
if (readable.length >= limit) break;
|
|
20637
|
+
}
|
|
20623
20638
|
}
|
|
20639
|
+
if (!store || ordered.length < size) break;
|
|
20640
|
+
start = ordered.length;
|
|
20624
20641
|
}
|
|
20625
20642
|
return readable.map((m) => ({
|
|
20626
20643
|
id: m.uniqueId,
|
|
@@ -20637,6 +20654,8 @@ async function listRecentFacts(ctx, limit, toolOptions) {
|
|
|
20637
20654
|
}));
|
|
20638
20655
|
}
|
|
20639
20656
|
function createRecallTool(ctx, toolOptions, callbacks) {
|
|
20657
|
+
if (toolOptions?.memoryStore && toolOptions.folderId !== void 0)
|
|
20658
|
+
throw new Error("Folders are not supported with a memoryStore");
|
|
20640
20659
|
const defaultTypes = toolOptions?.types ?? ["fact", "chunk"];
|
|
20641
20660
|
const defaultLimit = toolOptions?.limit ?? DEFAULT_LIMIT2;
|
|
20642
20661
|
const defaultBudget = toolOptions?.budget ?? DEFAULT_BUDGET2;
|
|
@@ -20708,7 +20727,7 @@ function createRecallTool(ctx, toolOptions, callbacks) {
|
|
|
20708
20727
|
let surfaced = 0;
|
|
20709
20728
|
try {
|
|
20710
20729
|
let recallDegraded = [];
|
|
20711
|
-
const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && ctx.vaultCtx !== void 0;
|
|
20730
|
+
const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && (ctx.vaultCtx !== void 0 || toolOptions?.memoryStore !== void 0);
|
|
20712
20731
|
let result;
|
|
20713
20732
|
if (wantsRecent) {
|
|
20714
20733
|
result = { memories: await listRecentFacts(ctx, effectiveLimit, toolOptions) };
|
|
@@ -21210,6 +21229,7 @@ function createLocalMemoryStore(options) {
|
|
|
21210
21229
|
});
|
|
21211
21230
|
};
|
|
21212
21231
|
return {
|
|
21232
|
+
masksEmbeddingInput: options.embeddingOptions.maskInput !== void 0,
|
|
21213
21233
|
list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
|
|
21214
21234
|
get: (id) => getVaultMemoryOp(vaultCtx, id),
|
|
21215
21235
|
listArchived: async () => {
|
|
@@ -21291,6 +21311,22 @@ function createLocalMemoryStore(options) {
|
|
|
21291
21311
|
{ vaultCtx, embeddingOptions: options.embeddingOptions, vaultCache },
|
|
21292
21312
|
retainOptions
|
|
21293
21313
|
),
|
|
21314
|
+
factSource: {
|
|
21315
|
+
search: (query, searchOptions) => searchVaultMemoriesWithSize(
|
|
21316
|
+
query,
|
|
21317
|
+
vaultCtx,
|
|
21318
|
+
options.embeddingOptions,
|
|
21319
|
+
vaultCache,
|
|
21320
|
+
searchOptions
|
|
21321
|
+
),
|
|
21322
|
+
graphRanking: (query, traverse, recallOptions) => buildGraphLaneRanking(
|
|
21323
|
+
query,
|
|
21324
|
+
{ vaultCtx, entityCtx, embeddingOptions: options.embeddingOptions },
|
|
21325
|
+
traverse,
|
|
21326
|
+
graphTraversalOptions(recallOptions, traverse)
|
|
21327
|
+
),
|
|
21328
|
+
temporalRanking: (query, now) => buildTemporalLaneRanking(query, vaultCtx, now)
|
|
21329
|
+
},
|
|
21294
21330
|
subscribe: (onChange, subscribeOptions) => {
|
|
21295
21331
|
const afterFirst = () => {
|
|
21296
21332
|
let first = true;
|
|
@@ -22177,38 +22213,31 @@ function createRemoteMemoryPipeline(options) {
|
|
|
22177
22213
|
};
|
|
22178
22214
|
return { prepare, port };
|
|
22179
22215
|
};
|
|
22180
|
-
|
|
22181
|
-
|
|
22216
|
+
const factSource = {
|
|
22217
|
+
graphRanking: options.graphRanking,
|
|
22218
|
+
temporalRanking: options.temporalRanking,
|
|
22219
|
+
search: async (text13, searchOptions) => {
|
|
22182
22220
|
const { prepare } = operation("recall");
|
|
22183
|
-
|
|
22184
|
-
|
|
22185
|
-
|
|
22186
|
-
|
|
22187
|
-
|
|
22188
|
-
|
|
22189
|
-
temporalRanking: options.temporalRanking,
|
|
22190
|
-
search: async (text13, searchOptions) => {
|
|
22191
|
-
const prepared = await prepare(text13, searchOptions);
|
|
22192
|
-
const ranked = await rankPreparedVaultCandidates(
|
|
22193
|
-
text13,
|
|
22194
|
-
prepared,
|
|
22195
|
-
embeddingOptions,
|
|
22196
|
-
searchOptions
|
|
22197
|
-
);
|
|
22198
|
-
return {
|
|
22199
|
-
...ranked,
|
|
22200
|
-
rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,
|
|
22201
|
-
decryptLast: true,
|
|
22202
|
-
rowsDecrypted: prepared.rowsDecrypted,
|
|
22203
|
-
queryEmbedMs: prepared.queryEmbedMs,
|
|
22204
|
-
rowsEmbedded: 0
|
|
22205
|
-
};
|
|
22206
|
-
}
|
|
22207
|
-
}
|
|
22208
|
-
},
|
|
22209
|
-
{ ...recallOptions, types: ["fact"] }
|
|
22221
|
+
const prepared = await prepare(text13, searchOptions);
|
|
22222
|
+
const ranked = await rankPreparedVaultCandidates(
|
|
22223
|
+
text13,
|
|
22224
|
+
prepared,
|
|
22225
|
+
embeddingOptions,
|
|
22226
|
+
searchOptions
|
|
22210
22227
|
);
|
|
22211
|
-
|
|
22228
|
+
return {
|
|
22229
|
+
...ranked,
|
|
22230
|
+
rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,
|
|
22231
|
+
decryptLast: true,
|
|
22232
|
+
rowsDecrypted: prepared.rowsDecrypted,
|
|
22233
|
+
queryEmbedMs: prepared.queryEmbedMs,
|
|
22234
|
+
rowsEmbedded: 0
|
|
22235
|
+
};
|
|
22236
|
+
}
|
|
22237
|
+
};
|
|
22238
|
+
return {
|
|
22239
|
+
factSource,
|
|
22240
|
+
recall: async (query, recallOptions = {}) => recall(query, { embeddingOptions, factSource }, { ...recallOptions, types: ["fact"] }),
|
|
22212
22241
|
retain: async (content, retainOptions) => {
|
|
22213
22242
|
const { port } = operation("retain");
|
|
22214
22243
|
return retainWithPersistence(
|
|
@@ -22569,6 +22598,7 @@ function createRemoteMemoryStore(options) {
|
|
|
22569
22598
|
});
|
|
22570
22599
|
};
|
|
22571
22600
|
return {
|
|
22601
|
+
masksEmbeddingInput: embeddingOptions.maskInput !== void 0,
|
|
22572
22602
|
list: async (listOptions = {}) => (await listRows(decrypted, listOptions, listFilters(listOptions), maxOf(listOptions))).map(
|
|
22573
22603
|
(r) => stored(r.memory)
|
|
22574
22604
|
),
|
|
@@ -22764,6 +22794,7 @@ function createRemoteMemoryStore(options) {
|
|
|
22764
22794
|
})
|
|
22765
22795
|
),
|
|
22766
22796
|
recall: (query, recallOptions) => pipeline.recall(query, recallOptions),
|
|
22797
|
+
factSource: pipeline.factSource,
|
|
22767
22798
|
retain: async (content, retainOptions) => {
|
|
22768
22799
|
const result = await pipeline.retain(content, retainOptions);
|
|
22769
22800
|
if (result.action === "create" || result.action === "supersede") notify("membership");
|
|
@@ -24527,19 +24558,20 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
24527
24558
|
const budget = wantsDecompose ? "high" : searchOptions?.rerank ? "mid" : "low";
|
|
24528
24559
|
const folderId = searchOptions?.folderId ?? argFolderId;
|
|
24529
24560
|
if (searchOptions?.useFusion === false) {
|
|
24530
|
-
const
|
|
24561
|
+
const legacyOptions = {
|
|
24562
|
+
limit: requestLimit,
|
|
24563
|
+
minSimilarity,
|
|
24564
|
+
useFusion: false,
|
|
24565
|
+
...tuningForward,
|
|
24566
|
+
...folderId !== void 0 && { folderId },
|
|
24567
|
+
...searchOptions?.scopes && { scopes: searchOptions.scopes }
|
|
24568
|
+
};
|
|
24569
|
+
const { results: legacy, embeddingsUnavailable } = "retain" in vaultCtx ? await vaultCtx.factSource.search(query, legacyOptions) : await searchVaultMemoriesWithSize(
|
|
24531
24570
|
query,
|
|
24532
24571
|
vaultCtx,
|
|
24533
24572
|
embeddingOptions,
|
|
24534
24573
|
cache,
|
|
24535
|
-
|
|
24536
|
-
limit: requestLimit,
|
|
24537
|
-
minSimilarity,
|
|
24538
|
-
useFusion: false,
|
|
24539
|
-
...tuningForward,
|
|
24540
|
-
...folderId !== void 0 && { folderId },
|
|
24541
|
-
...searchOptions?.scopes && { scopes: searchOptions.scopes }
|
|
24542
|
-
}
|
|
24574
|
+
legacyOptions
|
|
24543
24575
|
);
|
|
24544
24576
|
if (legacy.length === 0) {
|
|
24545
24577
|
return embeddingsUnavailable ? EMBEDDINGS_DEGRADED_EMPTY_NO_LEXICAL : "No relevant memories found in the vault.";
|
|
@@ -24558,7 +24590,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
24558
24590
|
let recallDegraded = [];
|
|
24559
24591
|
const result = await recall(
|
|
24560
24592
|
query,
|
|
24561
|
-
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
24593
|
+
"retain" in vaultCtx ? { factSource: vaultCtx.factSource, embeddingOptions } : { vaultCtx, embeddingOptions, vaultCache: cache },
|
|
24562
24594
|
{
|
|
24563
24595
|
onDiagnostics: (d) => {
|
|
24564
24596
|
recallDegraded = d.degraded;
|
|
@@ -24638,8 +24670,10 @@ function describeWriteOutcome(outcome2) {
|
|
|
24638
24670
|
}
|
|
24639
24671
|
}
|
|
24640
24672
|
function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
24673
|
+
const store = "retain" in vaultCtx ? vaultCtx : void 0;
|
|
24674
|
+
const ctx = "retain" in vaultCtx ? void 0 : vaultCtx;
|
|
24641
24675
|
const hasOnSave = !!options?.onSave;
|
|
24642
|
-
const folderNames = options?.folderMap ? Array.from(options.folderMap.keys()) : [];
|
|
24676
|
+
const folderNames = !store && options?.folderMap ? Array.from(options.folderMap.keys()) : [];
|
|
24643
24677
|
return {
|
|
24644
24678
|
type: "function",
|
|
24645
24679
|
function: {
|
|
@@ -24684,7 +24718,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
24684
24718
|
let previousContent;
|
|
24685
24719
|
const scope = options?.scope ?? "private";
|
|
24686
24720
|
if (isUpdate) {
|
|
24687
|
-
const existing = await getVaultMemoryOp(
|
|
24721
|
+
const existing = store ? await store.get(id) : await getVaultMemoryOp(ctx, id);
|
|
24688
24722
|
if (!existing) {
|
|
24689
24723
|
return `Error: Memory with ID "${id}" not found. Creating a new memory instead would require a separate call without an ID.`;
|
|
24690
24724
|
}
|
|
@@ -24705,9 +24739,18 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
24705
24739
|
return isUpdate ? `Memory update was cancelled by the user. The memory "${id}" was not modified.` : "Memory save was cancelled by the user. No memory was created.";
|
|
24706
24740
|
}
|
|
24707
24741
|
}
|
|
24708
|
-
if (isUpdate) {
|
|
24742
|
+
if (isUpdate && store) {
|
|
24743
|
+
const updated = await store.update(id, {
|
|
24744
|
+
content,
|
|
24745
|
+
...factType !== void 0 && { factType }
|
|
24746
|
+
});
|
|
24747
|
+
if (!updated) {
|
|
24748
|
+
return `Error: Failed to update memory "${id}".`;
|
|
24749
|
+
}
|
|
24750
|
+
return `Memory updated successfully (ID: ${updated.uniqueId}).`;
|
|
24751
|
+
} else if (isUpdate) {
|
|
24709
24752
|
const folderId = folderName ? options?.folderMap?.get(folderName) : void 0;
|
|
24710
|
-
const updated = await updateVaultMemoryOp(
|
|
24753
|
+
const updated = await updateVaultMemoryOp(ctx, id, {
|
|
24711
24754
|
content,
|
|
24712
24755
|
embedding: null,
|
|
24713
24756
|
folderId,
|
|
@@ -24722,7 +24765,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
24722
24765
|
content,
|
|
24723
24766
|
embeddingOptions,
|
|
24724
24767
|
cache,
|
|
24725
|
-
|
|
24768
|
+
ctx,
|
|
24726
24769
|
id,
|
|
24727
24770
|
updated.updatedAt
|
|
24728
24771
|
).catch(() => {
|
|
@@ -24742,18 +24785,22 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
24742
24785
|
await notifyWritten(options, input, outcome2);
|
|
24743
24786
|
return describeWriteOutcome(outcome2);
|
|
24744
24787
|
}
|
|
24745
|
-
const created = await
|
|
24788
|
+
const created = store ? await store.create({
|
|
24789
|
+
content,
|
|
24790
|
+
scope,
|
|
24791
|
+
...factType !== void 0 && { factType }
|
|
24792
|
+
}) : await createVaultMemoryOp(ctx, {
|
|
24746
24793
|
content,
|
|
24747
24794
|
scope,
|
|
24748
24795
|
folderId,
|
|
24749
24796
|
...factType !== void 0 && { factType }
|
|
24750
24797
|
});
|
|
24751
|
-
if (embeddingOptions && cache) {
|
|
24798
|
+
if (ctx && embeddingOptions && cache) {
|
|
24752
24799
|
eagerEmbedContent(
|
|
24753
24800
|
content,
|
|
24754
24801
|
embeddingOptions,
|
|
24755
24802
|
cache,
|
|
24756
|
-
|
|
24803
|
+
ctx,
|
|
24757
24804
|
created.uniqueId,
|
|
24758
24805
|
created.updatedAt
|
|
24759
24806
|
).catch(() => {
|
|
@@ -31725,6 +31772,8 @@ async function storedToLlmapiMessage(stored2, encryptionKey, resolveMediaByIds)
|
|
|
31725
31772
|
}
|
|
31726
31773
|
var CONVERSATION_REDACTOR_LIMIT = 50;
|
|
31727
31774
|
var NO_CONVERSATION_KEY = "__no_conversation__";
|
|
31775
|
+
var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
|
|
31776
|
+
var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
|
|
31728
31777
|
var conversationRedactors = /* @__PURE__ */ new Map();
|
|
31729
31778
|
function getConversationRedactor(conversationId, nerDetector) {
|
|
31730
31779
|
const key = conversationId ?? NO_CONVERSATION_KEY;
|
|
@@ -31768,6 +31817,7 @@ function useChatStorage(options) {
|
|
|
31768
31817
|
signMessage,
|
|
31769
31818
|
embeddedWalletSigner,
|
|
31770
31819
|
getWalletAddress,
|
|
31820
|
+
memoryStore,
|
|
31771
31821
|
enableQueue = true,
|
|
31772
31822
|
autoFlushOnKeyAvailable = true,
|
|
31773
31823
|
extraToolSets,
|
|
@@ -31813,6 +31863,7 @@ function useChatStorage(options) {
|
|
|
31813
31863
|
() => ({ getToken, baseUrl, model: embeddingModel, maskInput: maskEmbeddingInput }),
|
|
31814
31864
|
[getToken, baseUrl, embeddingModel, maskEmbeddingInput]
|
|
31815
31865
|
);
|
|
31866
|
+
const storeMaskMissing = memoryStore !== void 0 && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
|
|
31816
31867
|
const blobManagerRef = useRef4(new BlobUrlManager());
|
|
31817
31868
|
useEffect4(() => {
|
|
31818
31869
|
const manager = blobManagerRef.current;
|
|
@@ -32089,6 +32140,15 @@ function useChatStorage(options) {
|
|
|
32089
32140
|
);
|
|
32090
32141
|
const retainVaultMemory = useCallback5(
|
|
32091
32142
|
async (input) => {
|
|
32143
|
+
if (memoryStore) {
|
|
32144
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
32145
|
+
if (input.folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
32146
|
+
return memoryStore.retain(input.content, {
|
|
32147
|
+
source: "manual",
|
|
32148
|
+
scope: input.scope,
|
|
32149
|
+
...input.factType !== void 0 && { factType: input.factType }
|
|
32150
|
+
});
|
|
32151
|
+
}
|
|
32092
32152
|
if (!getToken) {
|
|
32093
32153
|
throw new Error("getToken is required to retain a vault memory");
|
|
32094
32154
|
}
|
|
@@ -32107,28 +32167,44 @@ function useChatStorage(options) {
|
|
|
32107
32167
|
}
|
|
32108
32168
|
);
|
|
32109
32169
|
},
|
|
32110
|
-
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
|
|
32170
|
+
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
32111
32171
|
);
|
|
32112
32172
|
const createMemoryVaultTool2 = useCallback5(
|
|
32113
32173
|
(options2) => {
|
|
32174
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
32114
32175
|
const embOpts = getToken ? vaultEmbeddingOptions : void 0;
|
|
32115
32176
|
return createMemoryVaultTool(
|
|
32116
|
-
vaultCtx,
|
|
32117
|
-
embOpts ? { write: retainVaultMemory, ...options2 } : options2,
|
|
32177
|
+
memoryStore ?? vaultCtx,
|
|
32178
|
+
embOpts || memoryStore ? { write: retainVaultMemory, ...options2 } : options2,
|
|
32118
32179
|
embOpts,
|
|
32119
32180
|
embOpts ? vaultEmbeddingCache : void 0
|
|
32120
32181
|
);
|
|
32121
32182
|
},
|
|
32122
|
-
[
|
|
32183
|
+
[
|
|
32184
|
+
vaultCtx,
|
|
32185
|
+
getToken,
|
|
32186
|
+
vaultEmbeddingOptions,
|
|
32187
|
+
vaultEmbeddingCache,
|
|
32188
|
+
retainVaultMemory,
|
|
32189
|
+
memoryStore,
|
|
32190
|
+
storeMaskMissing
|
|
32191
|
+
]
|
|
32123
32192
|
);
|
|
32124
32193
|
const getVaultMemories = useCallback5(
|
|
32125
32194
|
(options2) => {
|
|
32126
|
-
return getAllVaultMemoriesOp(vaultCtx, options2);
|
|
32195
|
+
if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
|
|
32196
|
+
const { folderId, levels, kinds, ...listOptions } = options2 ?? {};
|
|
32197
|
+
if (folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
32198
|
+
if (levels !== void 0 || kinds !== void 0)
|
|
32199
|
+
throw new Error("level and kind filters are not supported with a memoryStore");
|
|
32200
|
+
return memoryStore.list(listOptions);
|
|
32127
32201
|
},
|
|
32128
|
-
[vaultCtx]
|
|
32202
|
+
[vaultCtx, memoryStore]
|
|
32129
32203
|
);
|
|
32130
32204
|
const createVaultMemory = useCallback5(
|
|
32131
32205
|
async (content, scope) => {
|
|
32206
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
32207
|
+
if (memoryStore) return memoryStore.create({ content, scope });
|
|
32132
32208
|
const result = await createVaultMemoryOp(vaultCtx, { content, scope });
|
|
32133
32209
|
if (getToken) {
|
|
32134
32210
|
eagerEmbedContent(
|
|
@@ -32144,10 +32220,12 @@ function useChatStorage(options) {
|
|
|
32144
32220
|
}
|
|
32145
32221
|
return result;
|
|
32146
32222
|
},
|
|
32147
|
-
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
|
|
32223
|
+
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
32148
32224
|
);
|
|
32149
32225
|
const updateVaultMemory = useCallback5(
|
|
32150
32226
|
async (id, content, scope) => {
|
|
32227
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
32228
|
+
if (memoryStore) return memoryStore.update(id, { content, scope });
|
|
32151
32229
|
const existing = await getVaultMemoryOp(vaultCtx, id);
|
|
32152
32230
|
const result = await updateVaultMemoryOp(vaultCtx, id, { content, scope, embedding: null });
|
|
32153
32231
|
if (result && getToken) {
|
|
@@ -32167,10 +32245,11 @@ function useChatStorage(options) {
|
|
|
32167
32245
|
}
|
|
32168
32246
|
return result;
|
|
32169
32247
|
},
|
|
32170
|
-
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
|
|
32248
|
+
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
32171
32249
|
);
|
|
32172
32250
|
const deleteVaultMemory = useCallback5(
|
|
32173
32251
|
async (id) => {
|
|
32252
|
+
if (memoryStore) return memoryStore.delete(id);
|
|
32174
32253
|
const existing = await getVaultMemoryOp(vaultCtx, id);
|
|
32175
32254
|
const result = await deleteVaultMemoryOp(vaultCtx, id);
|
|
32176
32255
|
if (result && existing) {
|
|
@@ -32178,19 +32257,19 @@ function useChatStorage(options) {
|
|
|
32178
32257
|
}
|
|
32179
32258
|
return result;
|
|
32180
32259
|
},
|
|
32181
|
-
[vaultCtx, vaultEmbeddingCache]
|
|
32260
|
+
[vaultCtx, vaultEmbeddingCache, memoryStore]
|
|
32182
32261
|
);
|
|
32183
32262
|
const chunkVectorCacheRef = useRef4(createChunkVectorCache());
|
|
32184
32263
|
const clientToolEmbeddingsCacheRef = useRef4(/* @__PURE__ */ new Map());
|
|
32185
32264
|
useEffect4(() => {
|
|
32186
|
-
if (!getToken) return;
|
|
32265
|
+
if (!getToken || memoryStore) return;
|
|
32187
32266
|
void (async () => {
|
|
32188
32267
|
try {
|
|
32189
32268
|
await preEmbedVaultMemories(vaultCtx, vaultEmbeddingOptions, vaultEmbeddingCache);
|
|
32190
32269
|
} catch {
|
|
32191
32270
|
}
|
|
32192
32271
|
})();
|
|
32193
|
-
}, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]);
|
|
32272
|
+
}, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore]);
|
|
32194
32273
|
useEffect4(() => {
|
|
32195
32274
|
return onClearAllEncryptionState(() => {
|
|
32196
32275
|
vaultEmbeddingCache.clear();
|
|
@@ -32199,26 +32278,35 @@ function useChatStorage(options) {
|
|
|
32199
32278
|
}, [vaultEmbeddingCache]);
|
|
32200
32279
|
const createMemoryVaultSearchTool2 = useCallback5(
|
|
32201
32280
|
(searchOptions) => {
|
|
32202
|
-
if (!getToken) {
|
|
32281
|
+
if (!getToken && !memoryStore) {
|
|
32203
32282
|
throw new Error("getToken is required for memory vault search tool");
|
|
32204
32283
|
}
|
|
32284
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
32205
32285
|
return createMemoryVaultSearchTool(
|
|
32206
|
-
vaultCtx,
|
|
32286
|
+
memoryStore ?? vaultCtx,
|
|
32207
32287
|
vaultEmbeddingOptions,
|
|
32208
32288
|
vaultEmbeddingCache,
|
|
32209
32289
|
searchOptions
|
|
32210
32290
|
);
|
|
32211
32291
|
},
|
|
32212
|
-
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
|
|
32292
|
+
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
32213
32293
|
);
|
|
32214
32294
|
const createRecallTool2 = useCallback5(
|
|
32215
32295
|
(toolOptions, callbacks) => {
|
|
32216
|
-
if (!getToken) {
|
|
32296
|
+
if (!getToken && !memoryStore) {
|
|
32217
32297
|
throw new Error("getToken is required for recall tool");
|
|
32218
32298
|
}
|
|
32299
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
32219
32300
|
const resolvedToolOptions = toolOptions?.excludeConversationId !== void 0 || !currentConversationId ? toolOptions : { ...toolOptions, excludeConversationId: currentConversationId };
|
|
32301
|
+
if (memoryStore && resolvedToolOptions?.folderId !== void 0)
|
|
32302
|
+
throw new Error(NO_STORE_FOLDERS);
|
|
32220
32303
|
return createRecallTool(
|
|
32221
|
-
{
|
|
32304
|
+
memoryStore ? {
|
|
32305
|
+
factSource: memoryStore.factSource,
|
|
32306
|
+
...getToken && { storageCtx },
|
|
32307
|
+
embeddingOptions: vaultEmbeddingOptions,
|
|
32308
|
+
chunkCache: chunkVectorCacheRef.current
|
|
32309
|
+
} : {
|
|
32222
32310
|
vaultCtx,
|
|
32223
32311
|
storageCtx,
|
|
32224
32312
|
embeddingOptions: vaultEmbeddingOptions,
|
|
@@ -32226,7 +32314,7 @@ function useChatStorage(options) {
|
|
|
32226
32314
|
chunkCache: chunkVectorCacheRef.current,
|
|
32227
32315
|
entityCtx
|
|
32228
32316
|
},
|
|
32229
|
-
resolvedToolOptions,
|
|
32317
|
+
memoryStore ? { ...resolvedToolOptions, memoryStore } : resolvedToolOptions,
|
|
32230
32318
|
callbacks
|
|
32231
32319
|
);
|
|
32232
32320
|
},
|
|
@@ -32237,11 +32325,15 @@ function useChatStorage(options) {
|
|
|
32237
32325
|
getToken,
|
|
32238
32326
|
vaultEmbeddingOptions,
|
|
32239
32327
|
vaultEmbeddingCache,
|
|
32240
|
-
currentConversationId
|
|
32328
|
+
currentConversationId,
|
|
32329
|
+
memoryStore,
|
|
32330
|
+
storeMaskMissing
|
|
32241
32331
|
]
|
|
32242
32332
|
);
|
|
32243
32333
|
const searchVaultMemoriesFn = useCallback5(
|
|
32244
32334
|
async (query, searchOptions) => {
|
|
32335
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
32336
|
+
if (memoryStore) return (await memoryStore.factSource.search(query, searchOptions)).results;
|
|
32245
32337
|
if (!getToken) return [];
|
|
32246
32338
|
return searchVaultMemories(
|
|
32247
32339
|
query,
|
|
@@ -32251,11 +32343,11 @@ function useChatStorage(options) {
|
|
|
32251
32343
|
searchOptions
|
|
32252
32344
|
);
|
|
32253
32345
|
},
|
|
32254
|
-
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
|
|
32346
|
+
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
32255
32347
|
);
|
|
32256
32348
|
const recallFn = useCallback5(
|
|
32257
32349
|
async (query, options2) => {
|
|
32258
|
-
if (!getToken) {
|
|
32350
|
+
if (!getToken && !memoryStore) {
|
|
32259
32351
|
return {
|
|
32260
32352
|
memories: [],
|
|
32261
32353
|
usedBudget: options2?.budget ?? "low",
|
|
@@ -32264,9 +32356,16 @@ function useChatStorage(options) {
|
|
|
32264
32356
|
};
|
|
32265
32357
|
}
|
|
32266
32358
|
const resolvedOptions = options2?.excludeConversationId !== void 0 || !currentConversationId ? options2 : { ...options2, excludeConversationId: currentConversationId };
|
|
32359
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
32360
|
+
if (memoryStore && resolvedOptions?.folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
32267
32361
|
return recall(
|
|
32268
32362
|
query,
|
|
32269
|
-
{
|
|
32363
|
+
memoryStore ? {
|
|
32364
|
+
factSource: memoryStore.factSource,
|
|
32365
|
+
...getToken && { storageCtx },
|
|
32366
|
+
embeddingOptions: vaultEmbeddingOptions,
|
|
32367
|
+
chunkCache: chunkVectorCacheRef.current
|
|
32368
|
+
} : {
|
|
32270
32369
|
vaultCtx,
|
|
32271
32370
|
storageCtx,
|
|
32272
32371
|
embeddingOptions: vaultEmbeddingOptions,
|
|
@@ -32284,7 +32383,9 @@ function useChatStorage(options) {
|
|
|
32284
32383
|
getToken,
|
|
32285
32384
|
currentConversationId,
|
|
32286
32385
|
vaultEmbeddingOptions,
|
|
32287
|
-
vaultEmbeddingCache
|
|
32386
|
+
vaultEmbeddingCache,
|
|
32387
|
+
memoryStore,
|
|
32388
|
+
storeMaskMissing
|
|
32288
32389
|
]
|
|
32289
32390
|
);
|
|
32290
32391
|
const {
|