@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.
@@ -33957,7 +33957,6 @@ async function recall(query, ctx, options = {}) {
33957
33957
  }
33958
33958
  const needsChunkEmbedding = types.includes("chunk") && ctx.storageCtx;
33959
33959
  const wantsTemporal = types.includes("fact") && (ctx.factSource || ctx.vaultCtx);
33960
- const graphRefiner = flags.traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
33961
33960
  const queryEmbedTotalTimeoutMs = options.queryEmbedTotalTimeoutMs ?? DEFAULT_QUERY_EMBED_TOTAL_TIMEOUT_MS;
33962
33961
  const prepStart = nowMs2();
33963
33962
  let sharedEmbedMs = 0;
@@ -33986,13 +33985,12 @@ async function recall(query, ctx, options = {}) {
33986
33985
  safeLane(
33987
33986
  "graph",
33988
33987
  () => graphLaneFailed = true,
33989
- () => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(query, ctx, flags.traverse, {
33990
- ...options.maxHops !== void 0 && { maxHops: options.maxHops },
33991
- ...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
33992
- ...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
33993
- ...options.rrfK !== void 0 && { rrfK: options.rrfK },
33994
- ...graphRefiner && { refineNeighbors: graphRefiner }
33995
- })
33988
+ () => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(
33989
+ query,
33990
+ ctx,
33991
+ flags.traverse,
33992
+ graphTraversalOptions(options, flags.traverse)
33993
+ )
33996
33994
  ),
33997
33995
  wantsTemporal ? safeLane(
33998
33996
  "temporal",
@@ -34211,6 +34209,16 @@ function toFactMemory(r, now) {
34211
34209
  updatedAt: r.updatedAt ?? /* @__PURE__ */ new Date(0)
34212
34210
  };
34213
34211
  }
34212
+ function graphTraversalOptions(options, traverse) {
34213
+ const refineNeighbors = traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
34214
+ return {
34215
+ ...options.maxHops !== void 0 && { maxHops: options.maxHops },
34216
+ ...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
34217
+ ...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
34218
+ ...options.rrfK !== void 0 && { rrfK: options.rrfK },
34219
+ ...refineNeighbors && { refineNeighbors }
34220
+ };
34221
+ }
34214
34222
  async function buildGraphLaneRanking(query, ctx, traverse = false, traversalOptions = {}) {
34215
34223
  const entityCtx = ctx.entityCtx ?? ctx.vaultCtx?.entityCtx;
34216
34224
  if (!entityCtx) return [];
@@ -34376,24 +34384,33 @@ function isDumpQuery(query) {
34376
34384
  return false;
34377
34385
  }
34378
34386
  async function listRecentFacts(ctx, limit, toolOptions) {
34387
+ const store = toolOptions?.memoryStore;
34379
34388
  const vaultCtx = ctx.vaultCtx;
34380
- if (!vaultCtx) return [];
34381
- const ordered = await getVaultRankingProjectionsOp(vaultCtx, {
34389
+ if (!vaultCtx && !store) return [];
34390
+ const read = (ids) => store ? store.list({ memoryIds: ids }) : getVaultMemoriesByIdsOp(vaultCtx, ids);
34391
+ const filters = {
34382
34392
  ...toolOptions?.scopes && { scopes: toolOptions.scopes },
34383
- ...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds },
34393
+ ...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds }
34394
+ };
34395
+ const project = (size) => store ? store.listProjections({ ...filters, limit: size }) : getVaultRankingProjectionsOp(vaultCtx, {
34396
+ ...filters,
34384
34397
  ...toolOptions?.folderId !== void 0 && { folderId: toolOptions.folderId }
34385
34398
  });
34386
34399
  const readable = [];
34387
- for (let i = 0; i < ordered.length && readable.length < limit; i += limit) {
34388
- const batch = ordered.slice(i, i + limit).map((p) => p.uniqueId);
34389
- const byId = new Map(
34390
- (await getVaultMemoriesByIdsOp(vaultCtx, batch)).map((m) => [m.uniqueId, m])
34391
- );
34392
- for (const id of batch) {
34393
- const m = byId.get(id);
34394
- if (m && !isEncrypted(m.content)) readable.push(m);
34395
- if (readable.length >= limit) break;
34400
+ let start = 0;
34401
+ for (let size = limit; readable.length < limit; size *= 2) {
34402
+ const ordered = await project(size);
34403
+ for (let i = start; i < ordered.length && readable.length < limit; i += limit) {
34404
+ const batch = ordered.slice(i, i + limit).map((p) => p.uniqueId);
34405
+ const byId = new Map((await read(batch)).map((m) => [m.uniqueId, m]));
34406
+ for (const id of batch) {
34407
+ const m = byId.get(id);
34408
+ if (m && !isEncrypted(m.content)) readable.push(m);
34409
+ if (readable.length >= limit) break;
34410
+ }
34396
34411
  }
34412
+ if (!store || ordered.length < size) break;
34413
+ start = ordered.length;
34397
34414
  }
34398
34415
  return readable.map((m) => ({
34399
34416
  id: m.uniqueId,
@@ -34410,6 +34427,8 @@ async function listRecentFacts(ctx, limit, toolOptions) {
34410
34427
  }));
34411
34428
  }
34412
34429
  function createRecallTool(ctx, toolOptions, callbacks) {
34430
+ if (toolOptions?.memoryStore && toolOptions.folderId !== void 0)
34431
+ throw new Error("Folders are not supported with a memoryStore");
34413
34432
  const defaultTypes = toolOptions?.types ?? ["fact", "chunk"];
34414
34433
  const defaultLimit = toolOptions?.limit ?? DEFAULT_LIMIT2;
34415
34434
  const defaultBudget = toolOptions?.budget ?? DEFAULT_BUDGET2;
@@ -34481,7 +34500,7 @@ function createRecallTool(ctx, toolOptions, callbacks) {
34481
34500
  let surfaced = 0;
34482
34501
  try {
34483
34502
  let recallDegraded = [];
34484
- const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && ctx.vaultCtx !== void 0;
34503
+ const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && (ctx.vaultCtx !== void 0 || toolOptions?.memoryStore !== void 0);
34485
34504
  let result;
34486
34505
  if (wantsRecent) {
34487
34506
  result = { memories: await listRecentFacts(ctx, effectiveLimit, toolOptions) };
@@ -34991,6 +35010,7 @@ function createLocalMemoryStore(options) {
34991
35010
  });
34992
35011
  };
34993
35012
  return {
35013
+ masksEmbeddingInput: options.embeddingOptions.maskInput !== void 0,
34994
35014
  list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
34995
35015
  get: (id) => getVaultMemoryOp(vaultCtx, id),
34996
35016
  listArchived: async () => {
@@ -35072,6 +35092,22 @@ function createLocalMemoryStore(options) {
35072
35092
  { vaultCtx, embeddingOptions: options.embeddingOptions, vaultCache },
35073
35093
  retainOptions
35074
35094
  ),
35095
+ factSource: {
35096
+ search: (query, searchOptions) => searchVaultMemoriesWithSize(
35097
+ query,
35098
+ vaultCtx,
35099
+ options.embeddingOptions,
35100
+ vaultCache,
35101
+ searchOptions
35102
+ ),
35103
+ graphRanking: (query, traverse, recallOptions) => buildGraphLaneRanking(
35104
+ query,
35105
+ { vaultCtx, entityCtx, embeddingOptions: options.embeddingOptions },
35106
+ traverse,
35107
+ graphTraversalOptions(recallOptions, traverse)
35108
+ ),
35109
+ temporalRanking: (query, now) => buildTemporalLaneRanking(query, vaultCtx, now)
35110
+ },
35075
35111
  subscribe: (onChange, subscribeOptions) => {
35076
35112
  const afterFirst = () => {
35077
35113
  let first = true;
@@ -36767,19 +36803,20 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
36767
36803
  const budget = wantsDecompose ? "high" : searchOptions?.rerank ? "mid" : "low";
36768
36804
  const folderId = searchOptions?.folderId ?? argFolderId;
36769
36805
  if (searchOptions?.useFusion === false) {
36770
- const { results: legacy, embeddingsUnavailable } = await searchVaultMemoriesWithSize(
36806
+ const legacyOptions = {
36807
+ limit: requestLimit,
36808
+ minSimilarity,
36809
+ useFusion: false,
36810
+ ...tuningForward,
36811
+ ...folderId !== void 0 && { folderId },
36812
+ ...searchOptions?.scopes && { scopes: searchOptions.scopes }
36813
+ };
36814
+ const { results: legacy, embeddingsUnavailable } = "retain" in vaultCtx ? await vaultCtx.factSource.search(query, legacyOptions) : await searchVaultMemoriesWithSize(
36771
36815
  query,
36772
36816
  vaultCtx,
36773
36817
  embeddingOptions,
36774
36818
  cache,
36775
- {
36776
- limit: requestLimit,
36777
- minSimilarity,
36778
- useFusion: false,
36779
- ...tuningForward,
36780
- ...folderId !== void 0 && { folderId },
36781
- ...searchOptions?.scopes && { scopes: searchOptions.scopes }
36782
- }
36819
+ legacyOptions
36783
36820
  );
36784
36821
  if (legacy.length === 0) {
36785
36822
  return embeddingsUnavailable ? EMBEDDINGS_DEGRADED_EMPTY_NO_LEXICAL : "No relevant memories found in the vault.";
@@ -36798,7 +36835,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
36798
36835
  let recallDegraded = [];
36799
36836
  const result = await recall(
36800
36837
  query,
36801
- { vaultCtx, embeddingOptions, vaultCache: cache },
36838
+ "retain" in vaultCtx ? { factSource: vaultCtx.factSource, embeddingOptions } : { vaultCtx, embeddingOptions, vaultCache: cache },
36802
36839
  {
36803
36840
  onDiagnostics: (d) => {
36804
36841
  recallDegraded = d.degraded;
@@ -36878,8 +36915,10 @@ function describeWriteOutcome(outcome) {
36878
36915
  }
36879
36916
  }
36880
36917
  function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
36918
+ const store = "retain" in vaultCtx ? vaultCtx : void 0;
36919
+ const ctx = "retain" in vaultCtx ? void 0 : vaultCtx;
36881
36920
  const hasOnSave = !!options?.onSave;
36882
- const folderNames = options?.folderMap ? Array.from(options.folderMap.keys()) : [];
36921
+ const folderNames = !store && options?.folderMap ? Array.from(options.folderMap.keys()) : [];
36883
36922
  return {
36884
36923
  type: "function",
36885
36924
  function: {
@@ -36924,7 +36963,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
36924
36963
  let previousContent;
36925
36964
  const scope = options?.scope ?? "private";
36926
36965
  if (isUpdate) {
36927
- const existing = await getVaultMemoryOp(vaultCtx, id);
36966
+ const existing = store ? await store.get(id) : await getVaultMemoryOp(ctx, id);
36928
36967
  if (!existing) {
36929
36968
  return `Error: Memory with ID "${id}" not found. Creating a new memory instead would require a separate call without an ID.`;
36930
36969
  }
@@ -36945,9 +36984,18 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
36945
36984
  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.";
36946
36985
  }
36947
36986
  }
36948
- if (isUpdate) {
36987
+ if (isUpdate && store) {
36988
+ const updated = await store.update(id, {
36989
+ content,
36990
+ ...factType !== void 0 && { factType }
36991
+ });
36992
+ if (!updated) {
36993
+ return `Error: Failed to update memory "${id}".`;
36994
+ }
36995
+ return `Memory updated successfully (ID: ${updated.uniqueId}).`;
36996
+ } else if (isUpdate) {
36949
36997
  const folderId = folderName ? options?.folderMap?.get(folderName) : void 0;
36950
- const updated = await updateVaultMemoryOp(vaultCtx, id, {
36998
+ const updated = await updateVaultMemoryOp(ctx, id, {
36951
36999
  content,
36952
37000
  embedding: null,
36953
37001
  folderId,
@@ -36962,7 +37010,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
36962
37010
  content,
36963
37011
  embeddingOptions,
36964
37012
  cache,
36965
- vaultCtx,
37013
+ ctx,
36966
37014
  id,
36967
37015
  updated.updatedAt
36968
37016
  ).catch(() => {
@@ -36982,18 +37030,22 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
36982
37030
  await notifyWritten(options, input, outcome);
36983
37031
  return describeWriteOutcome(outcome);
36984
37032
  }
36985
- const created = await createVaultMemoryOp(vaultCtx, {
37033
+ const created = store ? await store.create({
37034
+ content,
37035
+ scope,
37036
+ ...factType !== void 0 && { factType }
37037
+ }) : await createVaultMemoryOp(ctx, {
36986
37038
  content,
36987
37039
  scope,
36988
37040
  folderId,
36989
37041
  ...factType !== void 0 && { factType }
36990
37042
  });
36991
- if (embeddingOptions && cache) {
37043
+ if (ctx && embeddingOptions && cache) {
36992
37044
  eagerEmbedContent(
36993
37045
  content,
36994
37046
  embeddingOptions,
36995
37047
  cache,
36996
- vaultCtx,
37048
+ ctx,
36997
37049
  created.uniqueId,
36998
37050
  created.updatedAt
36999
37051
  ).catch(() => {