@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.
@@ -22076,7 +22076,6 @@ async function recall(query, ctx, options = {}) {
22076
22076
  }
22077
22077
  const needsChunkEmbedding = types.includes("chunk") && ctx.storageCtx;
22078
22078
  const wantsTemporal = types.includes("fact") && (ctx.factSource || ctx.vaultCtx);
22079
- const graphRefiner = flags.traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
22080
22079
  const queryEmbedTotalTimeoutMs = options.queryEmbedTotalTimeoutMs ?? DEFAULT_QUERY_EMBED_TOTAL_TIMEOUT_MS;
22081
22080
  const prepStart = nowMs2();
22082
22081
  let sharedEmbedMs = 0;
@@ -22105,13 +22104,12 @@ async function recall(query, ctx, options = {}) {
22105
22104
  safeLane(
22106
22105
  "graph",
22107
22106
  () => graphLaneFailed = true,
22108
- () => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(query, ctx, flags.traverse, {
22109
- ...options.maxHops !== void 0 && { maxHops: options.maxHops },
22110
- ...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
22111
- ...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
22112
- ...options.rrfK !== void 0 && { rrfK: options.rrfK },
22113
- ...graphRefiner && { refineNeighbors: graphRefiner }
22114
- })
22107
+ () => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(
22108
+ query,
22109
+ ctx,
22110
+ flags.traverse,
22111
+ graphTraversalOptions(options, flags.traverse)
22112
+ )
22115
22113
  ),
22116
22114
  wantsTemporal ? safeLane(
22117
22115
  "temporal",
@@ -22330,6 +22328,16 @@ function toFactMemory(r, now) {
22330
22328
  updatedAt: r.updatedAt ?? /* @__PURE__ */ new Date(0)
22331
22329
  };
22332
22330
  }
22331
+ function graphTraversalOptions(options, traverse) {
22332
+ const refineNeighbors = traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
22333
+ return {
22334
+ ...options.maxHops !== void 0 && { maxHops: options.maxHops },
22335
+ ...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
22336
+ ...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
22337
+ ...options.rrfK !== void 0 && { rrfK: options.rrfK },
22338
+ ...refineNeighbors && { refineNeighbors }
22339
+ };
22340
+ }
22333
22341
  async function buildGraphLaneRanking(query, ctx, traverse = false, traversalOptions = {}) {
22334
22342
  const entityCtx = ctx.entityCtx ?? ctx.vaultCtx?.entityCtx;
22335
22343
  if (!entityCtx) return [];
@@ -22495,24 +22503,33 @@ function isDumpQuery(query) {
22495
22503
  return false;
22496
22504
  }
22497
22505
  async function listRecentFacts(ctx, limit, toolOptions) {
22506
+ const store = toolOptions?.memoryStore;
22498
22507
  const vaultCtx = ctx.vaultCtx;
22499
- if (!vaultCtx) return [];
22500
- const ordered = await getVaultRankingProjectionsOp(vaultCtx, {
22508
+ if (!vaultCtx && !store) return [];
22509
+ const read = (ids) => store ? store.list({ memoryIds: ids }) : getVaultMemoriesByIdsOp(vaultCtx, ids);
22510
+ const filters = {
22501
22511
  ...toolOptions?.scopes && { scopes: toolOptions.scopes },
22502
- ...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds },
22512
+ ...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds }
22513
+ };
22514
+ const project = (size) => store ? store.listProjections({ ...filters, limit: size }) : getVaultRankingProjectionsOp(vaultCtx, {
22515
+ ...filters,
22503
22516
  ...toolOptions?.folderId !== void 0 && { folderId: toolOptions.folderId }
22504
22517
  });
22505
22518
  const readable = [];
22506
- for (let i = 0; i < ordered.length && readable.length < limit; i += limit) {
22507
- const batch = ordered.slice(i, i + limit).map((p) => p.uniqueId);
22508
- const byId = new Map(
22509
- (await getVaultMemoriesByIdsOp(vaultCtx, batch)).map((m) => [m.uniqueId, m])
22510
- );
22511
- for (const id of batch) {
22512
- const m = byId.get(id);
22513
- if (m && !isEncrypted(m.content)) readable.push(m);
22514
- if (readable.length >= limit) break;
22519
+ let start = 0;
22520
+ for (let size = limit; readable.length < limit; size *= 2) {
22521
+ const ordered = await project(size);
22522
+ for (let i = start; i < ordered.length && readable.length < limit; i += limit) {
22523
+ const batch = ordered.slice(i, i + limit).map((p) => p.uniqueId);
22524
+ const byId = new Map((await read(batch)).map((m) => [m.uniqueId, m]));
22525
+ for (const id of batch) {
22526
+ const m = byId.get(id);
22527
+ if (m && !isEncrypted(m.content)) readable.push(m);
22528
+ if (readable.length >= limit) break;
22529
+ }
22515
22530
  }
22531
+ if (!store || ordered.length < size) break;
22532
+ start = ordered.length;
22516
22533
  }
22517
22534
  return readable.map((m) => ({
22518
22535
  id: m.uniqueId,
@@ -22529,6 +22546,8 @@ async function listRecentFacts(ctx, limit, toolOptions) {
22529
22546
  }));
22530
22547
  }
22531
22548
  function createRecallTool(ctx, toolOptions, callbacks) {
22549
+ if (toolOptions?.memoryStore && toolOptions.folderId !== void 0)
22550
+ throw new Error("Folders are not supported with a memoryStore");
22532
22551
  const defaultTypes = toolOptions?.types ?? ["fact", "chunk"];
22533
22552
  const defaultLimit = toolOptions?.limit ?? DEFAULT_LIMIT2;
22534
22553
  const defaultBudget = toolOptions?.budget ?? DEFAULT_BUDGET2;
@@ -22600,7 +22619,7 @@ function createRecallTool(ctx, toolOptions, callbacks) {
22600
22619
  let surfaced = 0;
22601
22620
  try {
22602
22621
  let recallDegraded = [];
22603
- const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && ctx.vaultCtx !== void 0;
22622
+ const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && (ctx.vaultCtx !== void 0 || toolOptions?.memoryStore !== void 0);
22604
22623
  let result;
22605
22624
  if (wantsRecent) {
22606
22625
  result = { memories: await listRecentFacts(ctx, effectiveLimit, toolOptions) };
@@ -23110,6 +23129,7 @@ function createLocalMemoryStore(options) {
23110
23129
  });
23111
23130
  };
23112
23131
  return {
23132
+ masksEmbeddingInput: options.embeddingOptions.maskInput !== void 0,
23113
23133
  list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
23114
23134
  get: (id) => getVaultMemoryOp(vaultCtx, id),
23115
23135
  listArchived: async () => {
@@ -23191,6 +23211,22 @@ function createLocalMemoryStore(options) {
23191
23211
  { vaultCtx, embeddingOptions: options.embeddingOptions, vaultCache },
23192
23212
  retainOptions
23193
23213
  ),
23214
+ factSource: {
23215
+ search: (query, searchOptions) => searchVaultMemoriesWithSize(
23216
+ query,
23217
+ vaultCtx,
23218
+ options.embeddingOptions,
23219
+ vaultCache,
23220
+ searchOptions
23221
+ ),
23222
+ graphRanking: (query, traverse, recallOptions) => buildGraphLaneRanking(
23223
+ query,
23224
+ { vaultCtx, entityCtx, embeddingOptions: options.embeddingOptions },
23225
+ traverse,
23226
+ graphTraversalOptions(recallOptions, traverse)
23227
+ ),
23228
+ temporalRanking: (query, now) => buildTemporalLaneRanking(query, vaultCtx, now)
23229
+ },
23194
23230
  subscribe: (onChange, subscribeOptions) => {
23195
23231
  const afterFirst = () => {
23196
23232
  let first = true;
@@ -24078,38 +24114,31 @@ function createRemoteMemoryPipeline(options) {
24078
24114
  };
24079
24115
  return { prepare, port };
24080
24116
  };
24081
- return {
24082
- recall: async (query, recallOptions = {}) => {
24117
+ const factSource = {
24118
+ graphRanking: options.graphRanking,
24119
+ temporalRanking: options.temporalRanking,
24120
+ search: async (text13, searchOptions) => {
24083
24121
  const { prepare } = operation("recall");
24084
- return recall(
24085
- query,
24086
- {
24087
- embeddingOptions,
24088
- factSource: {
24089
- graphRanking: options.graphRanking,
24090
- temporalRanking: options.temporalRanking,
24091
- search: async (text13, searchOptions) => {
24092
- const prepared = await prepare(text13, searchOptions);
24093
- const ranked = await rankPreparedVaultCandidates(
24094
- text13,
24095
- prepared,
24096
- embeddingOptions,
24097
- searchOptions
24098
- );
24099
- return {
24100
- ...ranked,
24101
- rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,
24102
- decryptLast: true,
24103
- rowsDecrypted: prepared.rowsDecrypted,
24104
- queryEmbedMs: prepared.queryEmbedMs,
24105
- rowsEmbedded: 0
24106
- };
24107
- }
24108
- }
24109
- },
24110
- { ...recallOptions, types: ["fact"] }
24122
+ const prepared = await prepare(text13, searchOptions);
24123
+ const ranked = await rankPreparedVaultCandidates(
24124
+ text13,
24125
+ prepared,
24126
+ embeddingOptions,
24127
+ searchOptions
24111
24128
  );
24112
- },
24129
+ return {
24130
+ ...ranked,
24131
+ rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,
24132
+ decryptLast: true,
24133
+ rowsDecrypted: prepared.rowsDecrypted,
24134
+ queryEmbedMs: prepared.queryEmbedMs,
24135
+ rowsEmbedded: 0
24136
+ };
24137
+ }
24138
+ };
24139
+ return {
24140
+ factSource,
24141
+ recall: async (query, recallOptions = {}) => recall(query, { embeddingOptions, factSource }, { ...recallOptions, types: ["fact"] }),
24113
24142
  retain: async (content, retainOptions) => {
24114
24143
  const { port } = operation("retain");
24115
24144
  return retainWithPersistence(
@@ -24471,6 +24500,7 @@ function createRemoteMemoryStore(options) {
24471
24500
  });
24472
24501
  };
24473
24502
  return {
24503
+ masksEmbeddingInput: embeddingOptions.maskInput !== void 0,
24474
24504
  list: async (listOptions = {}) => (await listRows(decrypted, listOptions, listFilters(listOptions), maxOf(listOptions))).map(
24475
24505
  (r) => stored(r.memory)
24476
24506
  ),
@@ -24666,6 +24696,7 @@ function createRemoteMemoryStore(options) {
24666
24696
  })
24667
24697
  ),
24668
24698
  recall: (query, recallOptions) => pipeline.recall(query, recallOptions),
24699
+ factSource: pipeline.factSource,
24669
24700
  retain: async (content, retainOptions) => {
24670
24701
  const result = await pipeline.retain(content, retainOptions);
24671
24702
  if (result.action === "create" || result.action === "supersede") notify("membership");
@@ -26434,19 +26465,20 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
26434
26465
  const budget = wantsDecompose ? "high" : searchOptions?.rerank ? "mid" : "low";
26435
26466
  const folderId = searchOptions?.folderId ?? argFolderId;
26436
26467
  if (searchOptions?.useFusion === false) {
26437
- const { results: legacy, embeddingsUnavailable } = await searchVaultMemoriesWithSize(
26468
+ const legacyOptions = {
26469
+ limit: requestLimit,
26470
+ minSimilarity,
26471
+ useFusion: false,
26472
+ ...tuningForward,
26473
+ ...folderId !== void 0 && { folderId },
26474
+ ...searchOptions?.scopes && { scopes: searchOptions.scopes }
26475
+ };
26476
+ const { results: legacy, embeddingsUnavailable } = "retain" in vaultCtx ? await vaultCtx.factSource.search(query, legacyOptions) : await searchVaultMemoriesWithSize(
26438
26477
  query,
26439
26478
  vaultCtx,
26440
26479
  embeddingOptions,
26441
26480
  cache,
26442
- {
26443
- limit: requestLimit,
26444
- minSimilarity,
26445
- useFusion: false,
26446
- ...tuningForward,
26447
- ...folderId !== void 0 && { folderId },
26448
- ...searchOptions?.scopes && { scopes: searchOptions.scopes }
26449
- }
26481
+ legacyOptions
26450
26482
  );
26451
26483
  if (legacy.length === 0) {
26452
26484
  return embeddingsUnavailable ? EMBEDDINGS_DEGRADED_EMPTY_NO_LEXICAL : "No relevant memories found in the vault.";
@@ -26465,7 +26497,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
26465
26497
  let recallDegraded = [];
26466
26498
  const result = await recall(
26467
26499
  query,
26468
- { vaultCtx, embeddingOptions, vaultCache: cache },
26500
+ "retain" in vaultCtx ? { factSource: vaultCtx.factSource, embeddingOptions } : { vaultCtx, embeddingOptions, vaultCache: cache },
26469
26501
  {
26470
26502
  onDiagnostics: (d) => {
26471
26503
  recallDegraded = d.degraded;
@@ -26545,8 +26577,10 @@ function describeWriteOutcome(outcome2) {
26545
26577
  }
26546
26578
  }
26547
26579
  function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
26580
+ const store = "retain" in vaultCtx ? vaultCtx : void 0;
26581
+ const ctx = "retain" in vaultCtx ? void 0 : vaultCtx;
26548
26582
  const hasOnSave = !!options?.onSave;
26549
- const folderNames = options?.folderMap ? Array.from(options.folderMap.keys()) : [];
26583
+ const folderNames = !store && options?.folderMap ? Array.from(options.folderMap.keys()) : [];
26550
26584
  return {
26551
26585
  type: "function",
26552
26586
  function: {
@@ -26591,7 +26625,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
26591
26625
  let previousContent;
26592
26626
  const scope = options?.scope ?? "private";
26593
26627
  if (isUpdate) {
26594
- const existing = await getVaultMemoryOp(vaultCtx, id);
26628
+ const existing = store ? await store.get(id) : await getVaultMemoryOp(ctx, id);
26595
26629
  if (!existing) {
26596
26630
  return `Error: Memory with ID "${id}" not found. Creating a new memory instead would require a separate call without an ID.`;
26597
26631
  }
@@ -26612,9 +26646,18 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
26612
26646
  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.";
26613
26647
  }
26614
26648
  }
26615
- if (isUpdate) {
26649
+ if (isUpdate && store) {
26650
+ const updated = await store.update(id, {
26651
+ content,
26652
+ ...factType !== void 0 && { factType }
26653
+ });
26654
+ if (!updated) {
26655
+ return `Error: Failed to update memory "${id}".`;
26656
+ }
26657
+ return `Memory updated successfully (ID: ${updated.uniqueId}).`;
26658
+ } else if (isUpdate) {
26616
26659
  const folderId = folderName ? options?.folderMap?.get(folderName) : void 0;
26617
- const updated = await updateVaultMemoryOp(vaultCtx, id, {
26660
+ const updated = await updateVaultMemoryOp(ctx, id, {
26618
26661
  content,
26619
26662
  embedding: null,
26620
26663
  folderId,
@@ -26629,7 +26672,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
26629
26672
  content,
26630
26673
  embeddingOptions,
26631
26674
  cache,
26632
- vaultCtx,
26675
+ ctx,
26633
26676
  id,
26634
26677
  updated.updatedAt
26635
26678
  ).catch(() => {
@@ -26649,18 +26692,22 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
26649
26692
  await notifyWritten(options, input, outcome2);
26650
26693
  return describeWriteOutcome(outcome2);
26651
26694
  }
26652
- const created = await createVaultMemoryOp(vaultCtx, {
26695
+ const created = store ? await store.create({
26696
+ content,
26697
+ scope,
26698
+ ...factType !== void 0 && { factType }
26699
+ }) : await createVaultMemoryOp(ctx, {
26653
26700
  content,
26654
26701
  scope,
26655
26702
  folderId,
26656
26703
  ...factType !== void 0 && { factType }
26657
26704
  });
26658
- if (embeddingOptions && cache) {
26705
+ if (ctx && embeddingOptions && cache) {
26659
26706
  eagerEmbedContent(
26660
26707
  content,
26661
26708
  embeddingOptions,
26662
26709
  cache,
26663
- vaultCtx,
26710
+ ctx,
26664
26711
  created.uniqueId,
26665
26712
  created.updatedAt
26666
26713
  ).catch(() => {
@@ -33644,6 +33691,8 @@ async function storedToLlmapiMessage(stored2, encryptionKey, resolveMediaByIds)
33644
33691
  }
33645
33692
  var CONVERSATION_REDACTOR_LIMIT = 50;
33646
33693
  var NO_CONVERSATION_KEY = "__no_conversation__";
33694
+ var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
33695
+ var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
33647
33696
  var conversationRedactors = /* @__PURE__ */ new Map();
33648
33697
  function getConversationRedactor(conversationId, nerDetector) {
33649
33698
  const key = conversationId ?? NO_CONVERSATION_KEY;
@@ -33687,6 +33736,7 @@ function useChatStorage(options) {
33687
33736
  signMessage,
33688
33737
  embeddedWalletSigner,
33689
33738
  getWalletAddress,
33739
+ memoryStore,
33690
33740
  enableQueue = true,
33691
33741
  autoFlushOnKeyAvailable = true,
33692
33742
  extraToolSets,
@@ -33732,6 +33782,7 @@ function useChatStorage(options) {
33732
33782
  () => ({ getToken, baseUrl, model: embeddingModel, maskInput: maskEmbeddingInput }),
33733
33783
  [getToken, baseUrl, embeddingModel, maskEmbeddingInput]
33734
33784
  );
33785
+ const storeMaskMissing = memoryStore !== void 0 && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
33735
33786
  const blobManagerRef = (0, import_react6.useRef)(new BlobUrlManager());
33736
33787
  (0, import_react6.useEffect)(() => {
33737
33788
  const manager = blobManagerRef.current;
@@ -34008,6 +34059,15 @@ function useChatStorage(options) {
34008
34059
  );
34009
34060
  const retainVaultMemory = (0, import_react6.useCallback)(
34010
34061
  async (input) => {
34062
+ if (memoryStore) {
34063
+ if (storeMaskMissing) throw new Error(NO_STORE_MASK);
34064
+ if (input.folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
34065
+ return memoryStore.retain(input.content, {
34066
+ source: "manual",
34067
+ scope: input.scope,
34068
+ ...input.factType !== void 0 && { factType: input.factType }
34069
+ });
34070
+ }
34011
34071
  if (!getToken) {
34012
34072
  throw new Error("getToken is required to retain a vault memory");
34013
34073
  }
@@ -34026,28 +34086,44 @@ function useChatStorage(options) {
34026
34086
  }
34027
34087
  );
34028
34088
  },
34029
- [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
34089
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
34030
34090
  );
34031
34091
  const createMemoryVaultTool2 = (0, import_react6.useCallback)(
34032
34092
  (options2) => {
34093
+ if (storeMaskMissing) throw new Error(NO_STORE_MASK);
34033
34094
  const embOpts = getToken ? vaultEmbeddingOptions : void 0;
34034
34095
  return createMemoryVaultTool(
34035
- vaultCtx,
34036
- embOpts ? { write: retainVaultMemory, ...options2 } : options2,
34096
+ memoryStore ?? vaultCtx,
34097
+ embOpts || memoryStore ? { write: retainVaultMemory, ...options2 } : options2,
34037
34098
  embOpts,
34038
34099
  embOpts ? vaultEmbeddingCache : void 0
34039
34100
  );
34040
34101
  },
34041
- [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, retainVaultMemory]
34102
+ [
34103
+ vaultCtx,
34104
+ getToken,
34105
+ vaultEmbeddingOptions,
34106
+ vaultEmbeddingCache,
34107
+ retainVaultMemory,
34108
+ memoryStore,
34109
+ storeMaskMissing
34110
+ ]
34042
34111
  );
34043
34112
  const getVaultMemories = (0, import_react6.useCallback)(
34044
34113
  (options2) => {
34045
- return getAllVaultMemoriesOp(vaultCtx, options2);
34114
+ if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
34115
+ const { folderId, levels, kinds, ...listOptions } = options2 ?? {};
34116
+ if (folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
34117
+ if (levels !== void 0 || kinds !== void 0)
34118
+ throw new Error("level and kind filters are not supported with a memoryStore");
34119
+ return memoryStore.list(listOptions);
34046
34120
  },
34047
- [vaultCtx]
34121
+ [vaultCtx, memoryStore]
34048
34122
  );
34049
34123
  const createVaultMemory = (0, import_react6.useCallback)(
34050
34124
  async (content, scope) => {
34125
+ if (storeMaskMissing) throw new Error(NO_STORE_MASK);
34126
+ if (memoryStore) return memoryStore.create({ content, scope });
34051
34127
  const result = await createVaultMemoryOp(vaultCtx, { content, scope });
34052
34128
  if (getToken) {
34053
34129
  eagerEmbedContent(
@@ -34063,10 +34139,12 @@ function useChatStorage(options) {
34063
34139
  }
34064
34140
  return result;
34065
34141
  },
34066
- [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
34142
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
34067
34143
  );
34068
34144
  const updateVaultMemory = (0, import_react6.useCallback)(
34069
34145
  async (id, content, scope) => {
34146
+ if (storeMaskMissing) throw new Error(NO_STORE_MASK);
34147
+ if (memoryStore) return memoryStore.update(id, { content, scope });
34070
34148
  const existing = await getVaultMemoryOp(vaultCtx, id);
34071
34149
  const result = await updateVaultMemoryOp(vaultCtx, id, { content, scope, embedding: null });
34072
34150
  if (result && getToken) {
@@ -34086,10 +34164,11 @@ function useChatStorage(options) {
34086
34164
  }
34087
34165
  return result;
34088
34166
  },
34089
- [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
34167
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
34090
34168
  );
34091
34169
  const deleteVaultMemory = (0, import_react6.useCallback)(
34092
34170
  async (id) => {
34171
+ if (memoryStore) return memoryStore.delete(id);
34093
34172
  const existing = await getVaultMemoryOp(vaultCtx, id);
34094
34173
  const result = await deleteVaultMemoryOp(vaultCtx, id);
34095
34174
  if (result && existing) {
@@ -34097,19 +34176,19 @@ function useChatStorage(options) {
34097
34176
  }
34098
34177
  return result;
34099
34178
  },
34100
- [vaultCtx, vaultEmbeddingCache]
34179
+ [vaultCtx, vaultEmbeddingCache, memoryStore]
34101
34180
  );
34102
34181
  const chunkVectorCacheRef = (0, import_react6.useRef)(createChunkVectorCache());
34103
34182
  const clientToolEmbeddingsCacheRef = (0, import_react6.useRef)(/* @__PURE__ */ new Map());
34104
34183
  (0, import_react6.useEffect)(() => {
34105
- if (!getToken) return;
34184
+ if (!getToken || memoryStore) return;
34106
34185
  void (async () => {
34107
34186
  try {
34108
34187
  await preEmbedVaultMemories(vaultCtx, vaultEmbeddingOptions, vaultEmbeddingCache);
34109
34188
  } catch {
34110
34189
  }
34111
34190
  })();
34112
- }, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]);
34191
+ }, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore]);
34113
34192
  (0, import_react6.useEffect)(() => {
34114
34193
  return onClearAllEncryptionState(() => {
34115
34194
  vaultEmbeddingCache.clear();
@@ -34118,26 +34197,35 @@ function useChatStorage(options) {
34118
34197
  }, [vaultEmbeddingCache]);
34119
34198
  const createMemoryVaultSearchTool2 = (0, import_react6.useCallback)(
34120
34199
  (searchOptions) => {
34121
- if (!getToken) {
34200
+ if (!getToken && !memoryStore) {
34122
34201
  throw new Error("getToken is required for memory vault search tool");
34123
34202
  }
34203
+ if (storeMaskMissing) throw new Error(NO_STORE_MASK);
34124
34204
  return createMemoryVaultSearchTool(
34125
- vaultCtx,
34205
+ memoryStore ?? vaultCtx,
34126
34206
  vaultEmbeddingOptions,
34127
34207
  vaultEmbeddingCache,
34128
34208
  searchOptions
34129
34209
  );
34130
34210
  },
34131
- [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
34211
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
34132
34212
  );
34133
34213
  const createRecallTool2 = (0, import_react6.useCallback)(
34134
34214
  (toolOptions, callbacks) => {
34135
- if (!getToken) {
34215
+ if (!getToken && !memoryStore) {
34136
34216
  throw new Error("getToken is required for recall tool");
34137
34217
  }
34218
+ if (storeMaskMissing) throw new Error(NO_STORE_MASK);
34138
34219
  const resolvedToolOptions = toolOptions?.excludeConversationId !== void 0 || !currentConversationId ? toolOptions : { ...toolOptions, excludeConversationId: currentConversationId };
34220
+ if (memoryStore && resolvedToolOptions?.folderId !== void 0)
34221
+ throw new Error(NO_STORE_FOLDERS);
34139
34222
  return createRecallTool(
34140
- {
34223
+ memoryStore ? {
34224
+ factSource: memoryStore.factSource,
34225
+ ...getToken && { storageCtx },
34226
+ embeddingOptions: vaultEmbeddingOptions,
34227
+ chunkCache: chunkVectorCacheRef.current
34228
+ } : {
34141
34229
  vaultCtx,
34142
34230
  storageCtx,
34143
34231
  embeddingOptions: vaultEmbeddingOptions,
@@ -34145,7 +34233,7 @@ function useChatStorage(options) {
34145
34233
  chunkCache: chunkVectorCacheRef.current,
34146
34234
  entityCtx
34147
34235
  },
34148
- resolvedToolOptions,
34236
+ memoryStore ? { ...resolvedToolOptions, memoryStore } : resolvedToolOptions,
34149
34237
  callbacks
34150
34238
  );
34151
34239
  },
@@ -34156,11 +34244,15 @@ function useChatStorage(options) {
34156
34244
  getToken,
34157
34245
  vaultEmbeddingOptions,
34158
34246
  vaultEmbeddingCache,
34159
- currentConversationId
34247
+ currentConversationId,
34248
+ memoryStore,
34249
+ storeMaskMissing
34160
34250
  ]
34161
34251
  );
34162
34252
  const searchVaultMemoriesFn = (0, import_react6.useCallback)(
34163
34253
  async (query, searchOptions) => {
34254
+ if (storeMaskMissing) throw new Error(NO_STORE_MASK);
34255
+ if (memoryStore) return (await memoryStore.factSource.search(query, searchOptions)).results;
34164
34256
  if (!getToken) return [];
34165
34257
  return searchVaultMemories(
34166
34258
  query,
@@ -34170,11 +34262,11 @@ function useChatStorage(options) {
34170
34262
  searchOptions
34171
34263
  );
34172
34264
  },
34173
- [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache]
34265
+ [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
34174
34266
  );
34175
34267
  const recallFn = (0, import_react6.useCallback)(
34176
34268
  async (query, options2) => {
34177
- if (!getToken) {
34269
+ if (!getToken && !memoryStore) {
34178
34270
  return {
34179
34271
  memories: [],
34180
34272
  usedBudget: options2?.budget ?? "low",
@@ -34183,9 +34275,16 @@ function useChatStorage(options) {
34183
34275
  };
34184
34276
  }
34185
34277
  const resolvedOptions = options2?.excludeConversationId !== void 0 || !currentConversationId ? options2 : { ...options2, excludeConversationId: currentConversationId };
34278
+ if (storeMaskMissing) throw new Error(NO_STORE_MASK);
34279
+ if (memoryStore && resolvedOptions?.folderId !== void 0) throw new Error(NO_STORE_FOLDERS);
34186
34280
  return recall(
34187
34281
  query,
34188
- {
34282
+ memoryStore ? {
34283
+ factSource: memoryStore.factSource,
34284
+ ...getToken && { storageCtx },
34285
+ embeddingOptions: vaultEmbeddingOptions,
34286
+ chunkCache: chunkVectorCacheRef.current
34287
+ } : {
34189
34288
  vaultCtx,
34190
34289
  storageCtx,
34191
34290
  embeddingOptions: vaultEmbeddingOptions,
@@ -34203,7 +34302,9 @@ function useChatStorage(options) {
34203
34302
  getToken,
34204
34303
  currentConversationId,
34205
34304
  vaultEmbeddingOptions,
34206
- vaultEmbeddingCache
34305
+ vaultEmbeddingCache,
34306
+ memoryStore,
34307
+ storeMaskMissing
34207
34308
  ]
34208
34309
  );
34209
34310
  const {