@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.
@@ -32242,7 +32242,6 @@ async function recall(query, ctx, options = {}) {
32242
32242
  }
32243
32243
  const needsChunkEmbedding = types.includes("chunk") && ctx.storageCtx;
32244
32244
  const wantsTemporal = types.includes("fact") && (ctx.factSource || ctx.vaultCtx);
32245
- const graphRefiner = flags.traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
32246
32245
  const queryEmbedTotalTimeoutMs = options.queryEmbedTotalTimeoutMs ?? DEFAULT_QUERY_EMBED_TOTAL_TIMEOUT_MS;
32247
32246
  const prepStart = nowMs2();
32248
32247
  let sharedEmbedMs = 0;
@@ -32271,13 +32270,12 @@ async function recall(query, ctx, options = {}) {
32271
32270
  safeLane(
32272
32271
  "graph",
32273
32272
  () => graphLaneFailed = true,
32274
- () => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(query, ctx, flags.traverse, {
32275
- ...options.maxHops !== void 0 && { maxHops: options.maxHops },
32276
- ...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
32277
- ...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
32278
- ...options.rrfK !== void 0 && { rrfK: options.rrfK },
32279
- ...graphRefiner && { refineNeighbors: graphRefiner }
32280
- })
32273
+ () => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(
32274
+ query,
32275
+ ctx,
32276
+ flags.traverse,
32277
+ graphTraversalOptions(options, flags.traverse)
32278
+ )
32281
32279
  ),
32282
32280
  wantsTemporal ? safeLane(
32283
32281
  "temporal",
@@ -32496,6 +32494,16 @@ function toFactMemory(r, now) {
32496
32494
  updatedAt: r.updatedAt ?? /* @__PURE__ */ new Date(0)
32497
32495
  };
32498
32496
  }
32497
+ function graphTraversalOptions(options, traverse) {
32498
+ const refineNeighbors = traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
32499
+ return {
32500
+ ...options.maxHops !== void 0 && { maxHops: options.maxHops },
32501
+ ...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
32502
+ ...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
32503
+ ...options.rrfK !== void 0 && { rrfK: options.rrfK },
32504
+ ...refineNeighbors && { refineNeighbors }
32505
+ };
32506
+ }
32499
32507
  async function buildGraphLaneRanking(query, ctx, traverse = false, traversalOptions = {}) {
32500
32508
  const entityCtx = ctx.entityCtx ?? ctx.vaultCtx?.entityCtx;
32501
32509
  if (!entityCtx) return [];
@@ -32661,24 +32669,33 @@ function isDumpQuery(query) {
32661
32669
  return false;
32662
32670
  }
32663
32671
  async function listRecentFacts(ctx, limit, toolOptions) {
32672
+ const store = toolOptions?.memoryStore;
32664
32673
  const vaultCtx = ctx.vaultCtx;
32665
- if (!vaultCtx) return [];
32666
- const ordered = await getVaultRankingProjectionsOp(vaultCtx, {
32674
+ if (!vaultCtx && !store) return [];
32675
+ const read = (ids) => store ? store.list({ memoryIds: ids }) : getVaultMemoriesByIdsOp(vaultCtx, ids);
32676
+ const filters = {
32667
32677
  ...toolOptions?.scopes && { scopes: toolOptions.scopes },
32668
- ...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds },
32678
+ ...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds }
32679
+ };
32680
+ const project = (size) => store ? store.listProjections({ ...filters, limit: size }) : getVaultRankingProjectionsOp(vaultCtx, {
32681
+ ...filters,
32669
32682
  ...toolOptions?.folderId !== void 0 && { folderId: toolOptions.folderId }
32670
32683
  });
32671
32684
  const readable = [];
32672
- for (let i = 0; i < ordered.length && readable.length < limit; i += limit) {
32673
- const batch = ordered.slice(i, i + limit).map((p) => p.uniqueId);
32674
- const byId = new Map(
32675
- (await getVaultMemoriesByIdsOp(vaultCtx, batch)).map((m) => [m.uniqueId, m])
32676
- );
32677
- for (const id of batch) {
32678
- const m = byId.get(id);
32679
- if (m && !isEncrypted(m.content)) readable.push(m);
32680
- if (readable.length >= limit) break;
32685
+ let start = 0;
32686
+ for (let size = limit; readable.length < limit; size *= 2) {
32687
+ const ordered = await project(size);
32688
+ for (let i = start; i < ordered.length && readable.length < limit; i += limit) {
32689
+ const batch = ordered.slice(i, i + limit).map((p) => p.uniqueId);
32690
+ const byId = new Map((await read(batch)).map((m) => [m.uniqueId, m]));
32691
+ for (const id of batch) {
32692
+ const m = byId.get(id);
32693
+ if (m && !isEncrypted(m.content)) readable.push(m);
32694
+ if (readable.length >= limit) break;
32695
+ }
32681
32696
  }
32697
+ if (!store || ordered.length < size) break;
32698
+ start = ordered.length;
32682
32699
  }
32683
32700
  return readable.map((m) => ({
32684
32701
  id: m.uniqueId,
@@ -32695,6 +32712,8 @@ async function listRecentFacts(ctx, limit, toolOptions) {
32695
32712
  }));
32696
32713
  }
32697
32714
  function createRecallTool(ctx, toolOptions, callbacks) {
32715
+ if (toolOptions?.memoryStore && toolOptions.folderId !== void 0)
32716
+ throw new Error("Folders are not supported with a memoryStore");
32698
32717
  const defaultTypes = toolOptions?.types ?? ["fact", "chunk"];
32699
32718
  const defaultLimit = toolOptions?.limit ?? DEFAULT_LIMIT2;
32700
32719
  const defaultBudget = toolOptions?.budget ?? DEFAULT_BUDGET2;
@@ -32766,7 +32785,7 @@ function createRecallTool(ctx, toolOptions, callbacks) {
32766
32785
  let surfaced = 0;
32767
32786
  try {
32768
32787
  let recallDegraded = [];
32769
- const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && ctx.vaultCtx !== void 0;
32788
+ const wantsRecent = args.sort === "recent" && defaultTypes.includes("fact") && (ctx.vaultCtx !== void 0 || toolOptions?.memoryStore !== void 0);
32770
32789
  let result;
32771
32790
  if (wantsRecent) {
32772
32791
  result = { memories: await listRecentFacts(ctx, effectiveLimit, toolOptions) };
@@ -33268,6 +33287,7 @@ function createLocalMemoryStore(options) {
33268
33287
  });
33269
33288
  };
33270
33289
  return {
33290
+ masksEmbeddingInput: options.embeddingOptions.maskInput !== void 0,
33271
33291
  list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
33272
33292
  get: (id) => getVaultMemoryOp(vaultCtx, id),
33273
33293
  listArchived: async () => {
@@ -33349,6 +33369,22 @@ function createLocalMemoryStore(options) {
33349
33369
  { vaultCtx, embeddingOptions: options.embeddingOptions, vaultCache },
33350
33370
  retainOptions
33351
33371
  ),
33372
+ factSource: {
33373
+ search: (query, searchOptions) => searchVaultMemoriesWithSize(
33374
+ query,
33375
+ vaultCtx,
33376
+ options.embeddingOptions,
33377
+ vaultCache,
33378
+ searchOptions
33379
+ ),
33380
+ graphRanking: (query, traverse, recallOptions) => buildGraphLaneRanking(
33381
+ query,
33382
+ { vaultCtx, entityCtx, embeddingOptions: options.embeddingOptions },
33383
+ traverse,
33384
+ graphTraversalOptions(recallOptions, traverse)
33385
+ ),
33386
+ temporalRanking: (query, now) => buildTemporalLaneRanking(query, vaultCtx, now)
33387
+ },
33352
33388
  subscribe: (onChange, subscribeOptions) => {
33353
33389
  const afterFirst = () => {
33354
33390
  let first = true;
@@ -35039,19 +35075,20 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
35039
35075
  const budget = wantsDecompose ? "high" : searchOptions?.rerank ? "mid" : "low";
35040
35076
  const folderId = searchOptions?.folderId ?? argFolderId;
35041
35077
  if (searchOptions?.useFusion === false) {
35042
- const { results: legacy, embeddingsUnavailable } = await searchVaultMemoriesWithSize(
35078
+ const legacyOptions = {
35079
+ limit: requestLimit,
35080
+ minSimilarity,
35081
+ useFusion: false,
35082
+ ...tuningForward,
35083
+ ...folderId !== void 0 && { folderId },
35084
+ ...searchOptions?.scopes && { scopes: searchOptions.scopes }
35085
+ };
35086
+ const { results: legacy, embeddingsUnavailable } = "retain" in vaultCtx ? await vaultCtx.factSource.search(query, legacyOptions) : await searchVaultMemoriesWithSize(
35043
35087
  query,
35044
35088
  vaultCtx,
35045
35089
  embeddingOptions,
35046
35090
  cache,
35047
- {
35048
- limit: requestLimit,
35049
- minSimilarity,
35050
- useFusion: false,
35051
- ...tuningForward,
35052
- ...folderId !== void 0 && { folderId },
35053
- ...searchOptions?.scopes && { scopes: searchOptions.scopes }
35054
- }
35091
+ legacyOptions
35055
35092
  );
35056
35093
  if (legacy.length === 0) {
35057
35094
  return embeddingsUnavailable ? EMBEDDINGS_DEGRADED_EMPTY_NO_LEXICAL : "No relevant memories found in the vault.";
@@ -35070,7 +35107,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
35070
35107
  let recallDegraded = [];
35071
35108
  const result = await recall(
35072
35109
  query,
35073
- { vaultCtx, embeddingOptions, vaultCache: cache },
35110
+ "retain" in vaultCtx ? { factSource: vaultCtx.factSource, embeddingOptions } : { vaultCtx, embeddingOptions, vaultCache: cache },
35074
35111
  {
35075
35112
  onDiagnostics: (d) => {
35076
35113
  recallDegraded = d.degraded;
@@ -35150,8 +35187,10 @@ function describeWriteOutcome(outcome) {
35150
35187
  }
35151
35188
  }
35152
35189
  function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
35190
+ const store = "retain" in vaultCtx ? vaultCtx : void 0;
35191
+ const ctx = "retain" in vaultCtx ? void 0 : vaultCtx;
35153
35192
  const hasOnSave = !!options?.onSave;
35154
- const folderNames = options?.folderMap ? Array.from(options.folderMap.keys()) : [];
35193
+ const folderNames = !store && options?.folderMap ? Array.from(options.folderMap.keys()) : [];
35155
35194
  return {
35156
35195
  type: "function",
35157
35196
  function: {
@@ -35196,7 +35235,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
35196
35235
  let previousContent;
35197
35236
  const scope = options?.scope ?? "private";
35198
35237
  if (isUpdate) {
35199
- const existing = await getVaultMemoryOp(vaultCtx, id);
35238
+ const existing = store ? await store.get(id) : await getVaultMemoryOp(ctx, id);
35200
35239
  if (!existing) {
35201
35240
  return `Error: Memory with ID "${id}" not found. Creating a new memory instead would require a separate call without an ID.`;
35202
35241
  }
@@ -35217,9 +35256,18 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
35217
35256
  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.";
35218
35257
  }
35219
35258
  }
35220
- if (isUpdate) {
35259
+ if (isUpdate && store) {
35260
+ const updated = await store.update(id, {
35261
+ content,
35262
+ ...factType !== void 0 && { factType }
35263
+ });
35264
+ if (!updated) {
35265
+ return `Error: Failed to update memory "${id}".`;
35266
+ }
35267
+ return `Memory updated successfully (ID: ${updated.uniqueId}).`;
35268
+ } else if (isUpdate) {
35221
35269
  const folderId = folderName ? options?.folderMap?.get(folderName) : void 0;
35222
- const updated = await updateVaultMemoryOp(vaultCtx, id, {
35270
+ const updated = await updateVaultMemoryOp(ctx, id, {
35223
35271
  content,
35224
35272
  embedding: null,
35225
35273
  folderId,
@@ -35234,7 +35282,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
35234
35282
  content,
35235
35283
  embeddingOptions,
35236
35284
  cache,
35237
- vaultCtx,
35285
+ ctx,
35238
35286
  id,
35239
35287
  updated.updatedAt
35240
35288
  ).catch(() => {
@@ -35254,18 +35302,22 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
35254
35302
  await notifyWritten(options, input, outcome);
35255
35303
  return describeWriteOutcome(outcome);
35256
35304
  }
35257
- const created = await createVaultMemoryOp(vaultCtx, {
35305
+ const created = store ? await store.create({
35306
+ content,
35307
+ scope,
35308
+ ...factType !== void 0 && { factType }
35309
+ }) : await createVaultMemoryOp(ctx, {
35258
35310
  content,
35259
35311
  scope,
35260
35312
  folderId,
35261
35313
  ...factType !== void 0 && { factType }
35262
35314
  });
35263
- if (embeddingOptions && cache) {
35315
+ if (ctx && embeddingOptions && cache) {
35264
35316
  eagerEmbedContent(
35265
35317
  content,
35266
35318
  embeddingOptions,
35267
35319
  cache,
35268
- vaultCtx,
35320
+ ctx,
35269
35321
  created.uniqueId,
35270
35322
  created.updatedAt
35271
35323
  ).catch(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "6.38.0",
3
+ "version": "6.39.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",