@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/expo/index.mjs
CHANGED
|
@@ -17084,7 +17084,6 @@ async function recall(query, ctx, options = {}) {
|
|
|
17084
17084
|
}
|
|
17085
17085
|
const needsChunkEmbedding = types.includes("chunk") && ctx.storageCtx;
|
|
17086
17086
|
const wantsTemporal = types.includes("fact") && (ctx.factSource || ctx.vaultCtx);
|
|
17087
|
-
const graphRefiner = flags.traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
|
|
17088
17087
|
const queryEmbedTotalTimeoutMs = options.queryEmbedTotalTimeoutMs ?? DEFAULT_QUERY_EMBED_TOTAL_TIMEOUT_MS;
|
|
17089
17088
|
const prepStart = nowMs2();
|
|
17090
17089
|
let sharedEmbedMs = 0;
|
|
@@ -17113,13 +17112,12 @@ async function recall(query, ctx, options = {}) {
|
|
|
17113
17112
|
safeLane(
|
|
17114
17113
|
"graph",
|
|
17115
17114
|
() => graphLaneFailed = true,
|
|
17116
|
-
() => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(
|
|
17117
|
-
|
|
17118
|
-
|
|
17119
|
-
|
|
17120
|
-
|
|
17121
|
-
|
|
17122
|
-
})
|
|
17115
|
+
() => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(
|
|
17116
|
+
query,
|
|
17117
|
+
ctx,
|
|
17118
|
+
flags.traverse,
|
|
17119
|
+
graphTraversalOptions(options, flags.traverse)
|
|
17120
|
+
)
|
|
17123
17121
|
),
|
|
17124
17122
|
wantsTemporal ? safeLane(
|
|
17125
17123
|
"temporal",
|
|
@@ -17338,6 +17336,16 @@ function toFactMemory(r, now) {
|
|
|
17338
17336
|
updatedAt: r.updatedAt ?? /* @__PURE__ */ new Date(0)
|
|
17339
17337
|
};
|
|
17340
17338
|
}
|
|
17339
|
+
function graphTraversalOptions(options, traverse) {
|
|
17340
|
+
const refineNeighbors = traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
|
|
17341
|
+
return {
|
|
17342
|
+
...options.maxHops !== void 0 && { maxHops: options.maxHops },
|
|
17343
|
+
...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
|
|
17344
|
+
...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
|
|
17345
|
+
...options.rrfK !== void 0 && { rrfK: options.rrfK },
|
|
17346
|
+
...refineNeighbors && { refineNeighbors }
|
|
17347
|
+
};
|
|
17348
|
+
}
|
|
17341
17349
|
async function buildGraphLaneRanking(query, ctx, traverse = false, traversalOptions = {}) {
|
|
17342
17350
|
const entityCtx = ctx.entityCtx ?? ctx.vaultCtx?.entityCtx;
|
|
17343
17351
|
if (!entityCtx) return [];
|
|
@@ -17503,24 +17511,33 @@ function isDumpQuery(query) {
|
|
|
17503
17511
|
return false;
|
|
17504
17512
|
}
|
|
17505
17513
|
async function listRecentFacts(ctx, limit, toolOptions) {
|
|
17514
|
+
const store = toolOptions?.memoryStore;
|
|
17506
17515
|
const vaultCtx = ctx.vaultCtx;
|
|
17507
|
-
if (!vaultCtx) return [];
|
|
17508
|
-
const
|
|
17516
|
+
if (!vaultCtx && !store) return [];
|
|
17517
|
+
const read = (ids) => store ? store.list({ memoryIds: ids }) : getVaultMemoriesByIdsOp(vaultCtx, ids);
|
|
17518
|
+
const filters = {
|
|
17509
17519
|
...toolOptions?.scopes && { scopes: toolOptions.scopes },
|
|
17510
|
-
...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds }
|
|
17520
|
+
...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds }
|
|
17521
|
+
};
|
|
17522
|
+
const project = (size) => store ? store.listProjections({ ...filters, limit: size }) : getVaultRankingProjectionsOp(vaultCtx, {
|
|
17523
|
+
...filters,
|
|
17511
17524
|
...toolOptions?.folderId !== void 0 && { folderId: toolOptions.folderId }
|
|
17512
17525
|
});
|
|
17513
17526
|
const readable = [];
|
|
17514
|
-
|
|
17515
|
-
|
|
17516
|
-
const
|
|
17517
|
-
|
|
17518
|
-
|
|
17519
|
-
|
|
17520
|
-
const
|
|
17521
|
-
|
|
17522
|
-
|
|
17527
|
+
let start = 0;
|
|
17528
|
+
for (let size = limit; readable.length < limit; size *= 2) {
|
|
17529
|
+
const ordered = await project(size);
|
|
17530
|
+
for (let i = start; i < ordered.length && readable.length < limit; i += limit) {
|
|
17531
|
+
const batch = ordered.slice(i, i + limit).map((p) => p.uniqueId);
|
|
17532
|
+
const byId = new Map((await read(batch)).map((m) => [m.uniqueId, m]));
|
|
17533
|
+
for (const id of batch) {
|
|
17534
|
+
const m = byId.get(id);
|
|
17535
|
+
if (m && !isEncrypted(m.content)) readable.push(m);
|
|
17536
|
+
if (readable.length >= limit) break;
|
|
17537
|
+
}
|
|
17523
17538
|
}
|
|
17539
|
+
if (!store || ordered.length < size) break;
|
|
17540
|
+
start = ordered.length;
|
|
17524
17541
|
}
|
|
17525
17542
|
return readable.map((m) => ({
|
|
17526
17543
|
id: m.uniqueId,
|
|
@@ -17537,6 +17554,8 @@ async function listRecentFacts(ctx, limit, toolOptions) {
|
|
|
17537
17554
|
}));
|
|
17538
17555
|
}
|
|
17539
17556
|
function createRecallTool(ctx, toolOptions, callbacks) {
|
|
17557
|
+
if (toolOptions?.memoryStore && toolOptions.folderId !== void 0)
|
|
17558
|
+
throw new Error("Folders are not supported with a memoryStore");
|
|
17540
17559
|
const defaultTypes = toolOptions?.types ?? ["fact", "chunk"];
|
|
17541
17560
|
const defaultLimit = toolOptions?.limit ?? DEFAULT_LIMIT2;
|
|
17542
17561
|
const defaultBudget = toolOptions?.budget ?? DEFAULT_BUDGET2;
|
|
@@ -17608,7 +17627,7 @@ function createRecallTool(ctx, toolOptions, callbacks) {
|
|
|
17608
17627
|
let surfaced = 0;
|
|
17609
17628
|
try {
|
|
17610
17629
|
let recallDegraded = [];
|
|
17611
|
-
const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && ctx.vaultCtx !== void 0;
|
|
17630
|
+
const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && (ctx.vaultCtx !== void 0 || toolOptions?.memoryStore !== void 0);
|
|
17612
17631
|
let result;
|
|
17613
17632
|
if (wantsRecent) {
|
|
17614
17633
|
result = { memories: await listRecentFacts(ctx, effectiveLimit, toolOptions) };
|
|
@@ -18110,6 +18129,7 @@ function createLocalMemoryStore(options) {
|
|
|
18110
18129
|
});
|
|
18111
18130
|
};
|
|
18112
18131
|
return {
|
|
18132
|
+
masksEmbeddingInput: options.embeddingOptions.maskInput !== void 0,
|
|
18113
18133
|
list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
|
|
18114
18134
|
get: (id) => getVaultMemoryOp(vaultCtx, id),
|
|
18115
18135
|
listArchived: async () => {
|
|
@@ -18191,6 +18211,22 @@ function createLocalMemoryStore(options) {
|
|
|
18191
18211
|
{ vaultCtx, embeddingOptions: options.embeddingOptions, vaultCache },
|
|
18192
18212
|
retainOptions
|
|
18193
18213
|
),
|
|
18214
|
+
factSource: {
|
|
18215
|
+
search: (query, searchOptions) => searchVaultMemoriesWithSize(
|
|
18216
|
+
query,
|
|
18217
|
+
vaultCtx,
|
|
18218
|
+
options.embeddingOptions,
|
|
18219
|
+
vaultCache,
|
|
18220
|
+
searchOptions
|
|
18221
|
+
),
|
|
18222
|
+
graphRanking: (query, traverse, recallOptions) => buildGraphLaneRanking(
|
|
18223
|
+
query,
|
|
18224
|
+
{ vaultCtx, entityCtx, embeddingOptions: options.embeddingOptions },
|
|
18225
|
+
traverse,
|
|
18226
|
+
graphTraversalOptions(recallOptions, traverse)
|
|
18227
|
+
),
|
|
18228
|
+
temporalRanking: (query, now) => buildTemporalLaneRanking(query, vaultCtx, now)
|
|
18229
|
+
},
|
|
18194
18230
|
subscribe: (onChange, subscribeOptions) => {
|
|
18195
18231
|
const afterFirst = () => {
|
|
18196
18232
|
let first = true;
|
|
@@ -19077,38 +19113,31 @@ function createRemoteMemoryPipeline(options) {
|
|
|
19077
19113
|
};
|
|
19078
19114
|
return { prepare, port };
|
|
19079
19115
|
};
|
|
19080
|
-
|
|
19081
|
-
|
|
19116
|
+
const factSource = {
|
|
19117
|
+
graphRanking: options.graphRanking,
|
|
19118
|
+
temporalRanking: options.temporalRanking,
|
|
19119
|
+
search: async (text13, searchOptions) => {
|
|
19082
19120
|
const { prepare } = operation("recall");
|
|
19083
|
-
|
|
19084
|
-
|
|
19085
|
-
|
|
19086
|
-
|
|
19087
|
-
|
|
19088
|
-
|
|
19089
|
-
temporalRanking: options.temporalRanking,
|
|
19090
|
-
search: async (text13, searchOptions) => {
|
|
19091
|
-
const prepared = await prepare(text13, searchOptions);
|
|
19092
|
-
const ranked = await rankPreparedVaultCandidates(
|
|
19093
|
-
text13,
|
|
19094
|
-
prepared,
|
|
19095
|
-
embeddingOptions,
|
|
19096
|
-
searchOptions
|
|
19097
|
-
);
|
|
19098
|
-
return {
|
|
19099
|
-
...ranked,
|
|
19100
|
-
rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,
|
|
19101
|
-
decryptLast: true,
|
|
19102
|
-
rowsDecrypted: prepared.rowsDecrypted,
|
|
19103
|
-
queryEmbedMs: prepared.queryEmbedMs,
|
|
19104
|
-
rowsEmbedded: 0
|
|
19105
|
-
};
|
|
19106
|
-
}
|
|
19107
|
-
}
|
|
19108
|
-
},
|
|
19109
|
-
{ ...recallOptions, types: ["fact"] }
|
|
19121
|
+
const prepared = await prepare(text13, searchOptions);
|
|
19122
|
+
const ranked = await rankPreparedVaultCandidates(
|
|
19123
|
+
text13,
|
|
19124
|
+
prepared,
|
|
19125
|
+
embeddingOptions,
|
|
19126
|
+
searchOptions
|
|
19110
19127
|
);
|
|
19111
|
-
|
|
19128
|
+
return {
|
|
19129
|
+
...ranked,
|
|
19130
|
+
rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,
|
|
19131
|
+
decryptLast: true,
|
|
19132
|
+
rowsDecrypted: prepared.rowsDecrypted,
|
|
19133
|
+
queryEmbedMs: prepared.queryEmbedMs,
|
|
19134
|
+
rowsEmbedded: 0
|
|
19135
|
+
};
|
|
19136
|
+
}
|
|
19137
|
+
};
|
|
19138
|
+
return {
|
|
19139
|
+
factSource,
|
|
19140
|
+
recall: async (query, recallOptions = {}) => recall(query, { embeddingOptions, factSource }, { ...recallOptions, types: ["fact"] }),
|
|
19112
19141
|
retain: async (content, retainOptions) => {
|
|
19113
19142
|
const { port } = operation("retain");
|
|
19114
19143
|
return retainWithPersistence(
|
|
@@ -19469,6 +19498,7 @@ function createRemoteMemoryStore(options) {
|
|
|
19469
19498
|
});
|
|
19470
19499
|
};
|
|
19471
19500
|
return {
|
|
19501
|
+
masksEmbeddingInput: embeddingOptions.maskInput !== void 0,
|
|
19472
19502
|
list: async (listOptions = {}) => (await listRows(decrypted, listOptions, listFilters(listOptions), maxOf(listOptions))).map(
|
|
19473
19503
|
(r) => stored(r.memory)
|
|
19474
19504
|
),
|
|
@@ -19664,6 +19694,7 @@ function createRemoteMemoryStore(options) {
|
|
|
19664
19694
|
})
|
|
19665
19695
|
),
|
|
19666
19696
|
recall: (query, recallOptions) => pipeline.recall(query, recallOptions),
|
|
19697
|
+
factSource: pipeline.factSource,
|
|
19667
19698
|
retain: async (content, retainOptions) => {
|
|
19668
19699
|
const result = await pipeline.retain(content, retainOptions);
|
|
19669
19700
|
if (result.action === "create" || result.action === "supersede") notify("membership");
|
|
@@ -21427,19 +21458,20 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
21427
21458
|
const budget = wantsDecompose ? "high" : searchOptions?.rerank ? "mid" : "low";
|
|
21428
21459
|
const folderId = searchOptions?.folderId ?? argFolderId;
|
|
21429
21460
|
if (searchOptions?.useFusion === false) {
|
|
21430
|
-
const
|
|
21461
|
+
const legacyOptions = {
|
|
21462
|
+
limit: requestLimit,
|
|
21463
|
+
minSimilarity,
|
|
21464
|
+
useFusion: false,
|
|
21465
|
+
...tuningForward,
|
|
21466
|
+
...folderId !== void 0 && { folderId },
|
|
21467
|
+
...searchOptions?.scopes && { scopes: searchOptions.scopes }
|
|
21468
|
+
};
|
|
21469
|
+
const { results: legacy, embeddingsUnavailable } = "retain" in vaultCtx ? await vaultCtx.factSource.search(query, legacyOptions) : await searchVaultMemoriesWithSize(
|
|
21431
21470
|
query,
|
|
21432
21471
|
vaultCtx,
|
|
21433
21472
|
embeddingOptions,
|
|
21434
21473
|
cache,
|
|
21435
|
-
|
|
21436
|
-
limit: requestLimit,
|
|
21437
|
-
minSimilarity,
|
|
21438
|
-
useFusion: false,
|
|
21439
|
-
...tuningForward,
|
|
21440
|
-
...folderId !== void 0 && { folderId },
|
|
21441
|
-
...searchOptions?.scopes && { scopes: searchOptions.scopes }
|
|
21442
|
-
}
|
|
21474
|
+
legacyOptions
|
|
21443
21475
|
);
|
|
21444
21476
|
if (legacy.length === 0) {
|
|
21445
21477
|
return embeddingsUnavailable ? EMBEDDINGS_DEGRADED_EMPTY_NO_LEXICAL : "No relevant memories found in the vault.";
|
|
@@ -21458,7 +21490,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
21458
21490
|
let recallDegraded = [];
|
|
21459
21491
|
const result = await recall(
|
|
21460
21492
|
query,
|
|
21461
|
-
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
21493
|
+
"retain" in vaultCtx ? { factSource: vaultCtx.factSource, embeddingOptions } : { vaultCtx, embeddingOptions, vaultCache: cache },
|
|
21462
21494
|
{
|
|
21463
21495
|
onDiagnostics: (d) => {
|
|
21464
21496
|
recallDegraded = d.degraded;
|
|
@@ -21538,8 +21570,10 @@ function describeWriteOutcome(outcome2) {
|
|
|
21538
21570
|
}
|
|
21539
21571
|
}
|
|
21540
21572
|
function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
21573
|
+
const store = "retain" in vaultCtx ? vaultCtx : void 0;
|
|
21574
|
+
const ctx = "retain" in vaultCtx ? void 0 : vaultCtx;
|
|
21541
21575
|
const hasOnSave = !!options?.onSave;
|
|
21542
|
-
const folderNames = options?.folderMap ? Array.from(options.folderMap.keys()) : [];
|
|
21576
|
+
const folderNames = !store && options?.folderMap ? Array.from(options.folderMap.keys()) : [];
|
|
21543
21577
|
return {
|
|
21544
21578
|
type: "function",
|
|
21545
21579
|
function: {
|
|
@@ -21584,7 +21618,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
21584
21618
|
let previousContent;
|
|
21585
21619
|
const scope = options?.scope ?? "private";
|
|
21586
21620
|
if (isUpdate) {
|
|
21587
|
-
const existing = await getVaultMemoryOp(
|
|
21621
|
+
const existing = store ? await store.get(id) : await getVaultMemoryOp(ctx, id);
|
|
21588
21622
|
if (!existing) {
|
|
21589
21623
|
return `Error: Memory with ID "${id}" not found. Creating a new memory instead would require a separate call without an ID.`;
|
|
21590
21624
|
}
|
|
@@ -21605,9 +21639,18 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
21605
21639
|
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.";
|
|
21606
21640
|
}
|
|
21607
21641
|
}
|
|
21608
|
-
if (isUpdate) {
|
|
21642
|
+
if (isUpdate && store) {
|
|
21643
|
+
const updated = await store.update(id, {
|
|
21644
|
+
content,
|
|
21645
|
+
...factType !== void 0 && { factType }
|
|
21646
|
+
});
|
|
21647
|
+
if (!updated) {
|
|
21648
|
+
return `Error: Failed to update memory "${id}".`;
|
|
21649
|
+
}
|
|
21650
|
+
return `Memory updated successfully (ID: ${updated.uniqueId}).`;
|
|
21651
|
+
} else if (isUpdate) {
|
|
21609
21652
|
const folderId = folderName ? options?.folderMap?.get(folderName) : void 0;
|
|
21610
|
-
const updated = await updateVaultMemoryOp(
|
|
21653
|
+
const updated = await updateVaultMemoryOp(ctx, id, {
|
|
21611
21654
|
content,
|
|
21612
21655
|
embedding: null,
|
|
21613
21656
|
folderId,
|
|
@@ -21622,7 +21665,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
21622
21665
|
content,
|
|
21623
21666
|
embeddingOptions,
|
|
21624
21667
|
cache,
|
|
21625
|
-
|
|
21668
|
+
ctx,
|
|
21626
21669
|
id,
|
|
21627
21670
|
updated.updatedAt
|
|
21628
21671
|
).catch(() => {
|
|
@@ -21642,18 +21685,22 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
21642
21685
|
await notifyWritten(options, input, outcome2);
|
|
21643
21686
|
return describeWriteOutcome(outcome2);
|
|
21644
21687
|
}
|
|
21645
|
-
const created = await
|
|
21688
|
+
const created = store ? await store.create({
|
|
21689
|
+
content,
|
|
21690
|
+
scope,
|
|
21691
|
+
...factType !== void 0 && { factType }
|
|
21692
|
+
}) : await createVaultMemoryOp(ctx, {
|
|
21646
21693
|
content,
|
|
21647
21694
|
scope,
|
|
21648
21695
|
folderId,
|
|
21649
21696
|
...factType !== void 0 && { factType }
|
|
21650
21697
|
});
|
|
21651
|
-
if (embeddingOptions && cache) {
|
|
21698
|
+
if (ctx && embeddingOptions && cache) {
|
|
21652
21699
|
eagerEmbedContent(
|
|
21653
21700
|
content,
|
|
21654
21701
|
embeddingOptions,
|
|
21655
21702
|
cache,
|
|
21656
|
-
|
|
21703
|
+
ctx,
|
|
21657
21704
|
created.uniqueId,
|
|
21658
21705
|
created.updatedAt
|
|
21659
21706
|
).catch(() => {
|
|
@@ -23932,6 +23979,8 @@ onClearAllEncryptionState(resetRecentToolSets);
|
|
|
23932
23979
|
// src/expo/useChatStorage.ts
|
|
23933
23980
|
var CONVERSATION_REDACTOR_LIMIT = 50;
|
|
23934
23981
|
var NO_CONVERSATION_KEY = "__no_conversation__";
|
|
23982
|
+
var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
|
|
23983
|
+
var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
|
|
23935
23984
|
var conversationRedactors = /* @__PURE__ */ new Map();
|
|
23936
23985
|
var clientToolFilterCache = /* @__PURE__ */ new Map();
|
|
23937
23986
|
function getConversationRedactor(conversationId, nerDetector) {
|
|
@@ -24033,6 +24082,7 @@ function useChatStorage(options) {
|
|
|
24033
24082
|
signMessage,
|
|
24034
24083
|
embeddedWalletSigner,
|
|
24035
24084
|
getWalletAddress,
|
|
24085
|
+
memoryStore,
|
|
24036
24086
|
enableQueue = true,
|
|
24037
24087
|
autoFlushOnKeyAvailable = true,
|
|
24038
24088
|
extraToolSets,
|
|
@@ -24073,6 +24123,7 @@ function useChatStorage(options) {
|
|
|
24073
24123
|
[resolvedPiiRedaction]
|
|
24074
24124
|
);
|
|
24075
24125
|
const maskEmbeddingInput = isPiiRedactor(resolvedPiiRedaction) ? maskForEmbedding : void 0;
|
|
24126
|
+
const storeMaskMissing = memoryStore !== void 0 && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
|
|
24076
24127
|
const messagesCollection = useMemo(() => database.get("history"), [database]);
|
|
24077
24128
|
const conversationsCollection = useMemo(
|
|
24078
24129
|
() => database.get("conversations"),
|
|
@@ -24321,6 +24372,15 @@ function useChatStorage(options) {
|
|
|
24321
24372
|
}, [vaultEmbeddingCache]);
|
|
24322
24373
|
const retainVaultMemory = useCallback4(
|
|
24323
24374
|
async (input) => {
|
|
24375
|
+
if (memoryStore) {
|
|
24376
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
24377
|
+
if (input.folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
24378
|
+
return memoryStore.retain(input.content, {
|
|
24379
|
+
source: "manual",
|
|
24380
|
+
scope: input.scope,
|
|
24381
|
+
...input.factType !== void 0 && { factType: input.factType }
|
|
24382
|
+
});
|
|
24383
|
+
}
|
|
24324
24384
|
if (!getToken) {
|
|
24325
24385
|
throw new Error("getToken is required to retain a vault memory");
|
|
24326
24386
|
}
|
|
@@ -24344,37 +24404,56 @@ function useChatStorage(options) {
|
|
|
24344
24404
|
}
|
|
24345
24405
|
);
|
|
24346
24406
|
},
|
|
24347
|
-
[
|
|
24407
|
+
[
|
|
24408
|
+
vaultCtx,
|
|
24409
|
+
getToken,
|
|
24410
|
+
baseUrl,
|
|
24411
|
+
embeddingModel,
|
|
24412
|
+
maskEmbeddingInput,
|
|
24413
|
+
vaultEmbeddingCache,
|
|
24414
|
+
memoryStore,
|
|
24415
|
+
storeMaskMissing
|
|
24416
|
+
]
|
|
24348
24417
|
);
|
|
24349
24418
|
const createMemoryVaultTool2 = useCallback4(
|
|
24350
24419
|
(options2) => {
|
|
24420
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
24351
24421
|
return createMemoryVaultTool(
|
|
24352
|
-
vaultCtx,
|
|
24353
|
-
getToken ? { write: retainVaultMemory, ...options2 } : options2
|
|
24422
|
+
memoryStore ?? vaultCtx,
|
|
24423
|
+
getToken || memoryStore ? { write: retainVaultMemory, ...options2 } : options2
|
|
24354
24424
|
);
|
|
24355
24425
|
},
|
|
24356
|
-
[vaultCtx, getToken, retainVaultMemory]
|
|
24426
|
+
[vaultCtx, getToken, retainVaultMemory, memoryStore, storeMaskMissing]
|
|
24357
24427
|
);
|
|
24358
24428
|
const createRecallTool2 = useCallback4(
|
|
24359
24429
|
(toolOptions, callbacks) => {
|
|
24360
|
-
if (!getToken) {
|
|
24430
|
+
if (!getToken && !memoryStore) {
|
|
24361
24431
|
throw new Error("getToken is required for recall tool");
|
|
24362
24432
|
}
|
|
24363
24433
|
const resolvedToolOptions = toolOptions?.excludeConversationId !== void 0 || !currentConversationId ? toolOptions : { ...toolOptions, excludeConversationId: currentConversationId };
|
|
24434
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
24435
|
+
if (memoryStore && resolvedToolOptions?.folderId !== void 0)
|
|
24436
|
+
throw new Error(NO_STORE_FOLDERS);
|
|
24437
|
+
const embeddingOptions = {
|
|
24438
|
+
getToken,
|
|
24439
|
+
baseUrl,
|
|
24440
|
+
model: embeddingModel,
|
|
24441
|
+
maskInput: maskEmbeddingInput
|
|
24442
|
+
};
|
|
24364
24443
|
return createRecallTool(
|
|
24365
|
-
{
|
|
24444
|
+
memoryStore ? {
|
|
24445
|
+
factSource: memoryStore.factSource,
|
|
24446
|
+
...getToken && { storageCtx },
|
|
24447
|
+
embeddingOptions,
|
|
24448
|
+
chunkCache: chunkVectorCacheRef.current
|
|
24449
|
+
} : {
|
|
24366
24450
|
vaultCtx,
|
|
24367
24451
|
storageCtx,
|
|
24368
|
-
embeddingOptions
|
|
24369
|
-
getToken,
|
|
24370
|
-
baseUrl,
|
|
24371
|
-
model: embeddingModel,
|
|
24372
|
-
maskInput: maskEmbeddingInput
|
|
24373
|
-
},
|
|
24452
|
+
embeddingOptions,
|
|
24374
24453
|
vaultCache: vaultEmbeddingCache,
|
|
24375
24454
|
chunkCache: chunkVectorCacheRef.current
|
|
24376
24455
|
},
|
|
24377
|
-
resolvedToolOptions,
|
|
24456
|
+
memoryStore ? { ...resolvedToolOptions, memoryStore } : resolvedToolOptions,
|
|
24378
24457
|
callbacks
|
|
24379
24458
|
);
|
|
24380
24459
|
},
|
|
@@ -24386,12 +24465,14 @@ function useChatStorage(options) {
|
|
|
24386
24465
|
embeddingModel,
|
|
24387
24466
|
currentConversationId,
|
|
24388
24467
|
maskEmbeddingInput,
|
|
24389
|
-
vaultEmbeddingCache
|
|
24468
|
+
vaultEmbeddingCache,
|
|
24469
|
+
memoryStore,
|
|
24470
|
+
storeMaskMissing
|
|
24390
24471
|
]
|
|
24391
24472
|
);
|
|
24392
24473
|
const recallFn = useCallback4(
|
|
24393
24474
|
async (query, options2) => {
|
|
24394
|
-
if (!getToken) {
|
|
24475
|
+
if (!getToken && !memoryStore) {
|
|
24395
24476
|
return {
|
|
24396
24477
|
memories: [],
|
|
24397
24478
|
usedBudget: options2?.budget ?? "low",
|
|
@@ -24400,17 +24481,25 @@ function useChatStorage(options) {
|
|
|
24400
24481
|
};
|
|
24401
24482
|
}
|
|
24402
24483
|
const resolvedOptions = options2?.excludeConversationId !== void 0 || !currentConversationId ? options2 : { ...options2, excludeConversationId: currentConversationId };
|
|
24484
|
+
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
24485
|
+
if (memoryStore && resolvedOptions?.folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
24486
|
+
const embeddingOptions = {
|
|
24487
|
+
getToken,
|
|
24488
|
+
baseUrl,
|
|
24489
|
+
model: embeddingModel,
|
|
24490
|
+
maskInput: maskEmbeddingInput
|
|
24491
|
+
};
|
|
24403
24492
|
return recall(
|
|
24404
24493
|
query,
|
|
24405
|
-
{
|
|
24494
|
+
memoryStore ? {
|
|
24495
|
+
factSource: memoryStore.factSource,
|
|
24496
|
+
...getToken && { storageCtx },
|
|
24497
|
+
embeddingOptions,
|
|
24498
|
+
chunkCache: chunkVectorCacheRef.current
|
|
24499
|
+
} : {
|
|
24406
24500
|
vaultCtx,
|
|
24407
24501
|
storageCtx,
|
|
24408
|
-
embeddingOptions
|
|
24409
|
-
getToken,
|
|
24410
|
-
baseUrl,
|
|
24411
|
-
model: embeddingModel,
|
|
24412
|
-
maskInput: maskEmbeddingInput
|
|
24413
|
-
},
|
|
24502
|
+
embeddingOptions,
|
|
24414
24503
|
vaultCache: vaultEmbeddingCache,
|
|
24415
24504
|
chunkCache: chunkVectorCacheRef.current
|
|
24416
24505
|
},
|
|
@@ -24425,20 +24514,27 @@ function useChatStorage(options) {
|
|
|
24425
24514
|
embeddingModel,
|
|
24426
24515
|
currentConversationId,
|
|
24427
24516
|
maskEmbeddingInput,
|
|
24428
|
-
vaultEmbeddingCache
|
|
24517
|
+
vaultEmbeddingCache,
|
|
24518
|
+
memoryStore,
|
|
24519
|
+
storeMaskMissing
|
|
24429
24520
|
]
|
|
24430
24521
|
);
|
|
24431
24522
|
const getVaultMemories = useCallback4(
|
|
24432
24523
|
(options2) => {
|
|
24433
|
-
return getAllVaultMemoriesOp(vaultCtx, options2);
|
|
24524
|
+
if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
|
|
24525
|
+
const { folderId, levels, kinds, ...listOptions } = options2 ?? {};
|
|
24526
|
+
if (folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
|
|
24527
|
+
if (levels !== void 0 || kinds !== void 0)
|
|
24528
|
+
throw new Error("level and kind filters are not supported with a memoryStore");
|
|
24529
|
+
return memoryStore.list(listOptions);
|
|
24434
24530
|
},
|
|
24435
|
-
[vaultCtx]
|
|
24531
|
+
[vaultCtx, memoryStore]
|
|
24436
24532
|
);
|
|
24437
24533
|
const deleteVaultMemory = useCallback4(
|
|
24438
24534
|
(id) => {
|
|
24439
|
-
return deleteVaultMemoryOp(vaultCtx, id);
|
|
24535
|
+
return memoryStore ? memoryStore.delete(id) : deleteVaultMemoryOp(vaultCtx, id);
|
|
24440
24536
|
},
|
|
24441
|
-
[vaultCtx]
|
|
24537
|
+
[vaultCtx, memoryStore]
|
|
24442
24538
|
);
|
|
24443
24539
|
const {
|
|
24444
24540
|
isLoading,
|