@anuma/sdk 4.2.0 → 5.0.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.
@@ -8,6 +8,7 @@ import {
8
8
  EMBEDDINGS_DEGRADED_EMPTY,
9
9
  ENTITY_FANOUT,
10
10
  ENTITY_KINDS,
11
+ EncryptionKeyMissingError,
11
12
  LRUCache,
12
13
  MAX_HOPS,
13
14
  NODE_BUDGET,
@@ -41,6 +42,7 @@ import {
41
42
  createVaultEmbeddingCache,
42
43
  createVaultMemoriesBatchOp,
43
44
  createVaultMemoryOp,
45
+ decomposeQuery,
44
46
  decryptField,
45
47
  decryptJsonField,
46
48
  deleteAllVaultMemoriesForUserOp,
@@ -92,6 +94,7 @@ import {
92
94
  prepareVaultCandidates,
93
95
  rankPreparedVaultCandidates,
94
96
  recall,
97
+ refreshEncryptionKeyIfMatches,
95
98
  relinkMemoryTopicsOp,
96
99
  replaceMemoryEntitiesGuardedOp,
97
100
  requestEncryptionKey,
@@ -99,6 +102,7 @@ import {
99
102
  restoreVaultMemoryOp,
100
103
  searchChunksOp,
101
104
  searchVaultMemories,
105
+ seedEncryptionKeys,
102
106
  setMemoryVisibilityOp,
103
107
  shouldChunkMessage,
104
108
  stampTopicsExtractedAtOp,
@@ -116,7 +120,7 @@ import {
116
120
  upsertMessageOp,
117
121
  useEncryption,
118
122
  vaultMemoryToStored
119
- } from "./chunk-VBO6KSNQ.mjs";
123
+ } from "./chunk-SIMGZQ4P.mjs";
120
124
  import {
121
125
  PII_PATTERNS,
122
126
  PiiRedactor,
@@ -7811,7 +7815,7 @@ function createRecallTool(ctx, toolOptions, callbacks) {
7811
7815
  type: "function",
7812
7816
  function: {
7813
7817
  name: RECALL_TOOL_NAME,
7814
- description: "Search the user's memory across stored facts/preferences and past conversation excerpts. Returns a unified ranked list \u2014 facts carry an `id` you can reference; conversation excerpts carry a date and role. Use this whenever the user's question may relate to anything previously discussed or saved (preferences, prior decisions, past topics). Phrase the query naturally.",
7818
+ description: `Search the user's memory across stored facts/preferences and past conversation excerpts. Returns a unified ranked list \u2014 facts carry an \`id\` you can reference; conversation excerpts carry a date and role. Use this whenever the user's question may relate to anything previously discussed or saved (preferences, prior decisions, past topics). Phrase the query naturally. For multi-faceted / overview questions ("tell me about the user", "what's my tech stack"), prefer several targeted searches \u2014 one facet each (e.g. name, work, hobbies) \u2014 over a single broad query; fuse the results yourself.`,
7815
7819
  arguments: {
7816
7820
  type: "object",
7817
7821
  properties: {
@@ -7866,6 +7870,13 @@ function createRecallTool(ctx, toolOptions, callbacks) {
7866
7870
  let surfaced = 0;
7867
7871
  try {
7868
7872
  let recallDegraded = [];
7873
+ let subQueries;
7874
+ if (defaultBudget === "high" && toolOptions?.decomposeOptions) {
7875
+ const decomp = await decomposeQuery(query, toolOptions.decomposeOptions);
7876
+ if (decomp.mode === "composite" && decomp.subQueries.length >= 2) {
7877
+ subQueries = decomp.subQueries;
7878
+ }
7879
+ }
7869
7880
  const recallOpts = {
7870
7881
  onDiagnostics: (d) => {
7871
7882
  recallDegraded = d.degraded;
@@ -7879,10 +7890,12 @@ function createRecallTool(ctx, toolOptions, callbacks) {
7879
7890
  ...toolOptions?.excludeConversationId && {
7880
7891
  excludeConversationId: toolOptions.excludeConversationId
7881
7892
  },
7882
- ...toolOptions?.decomposeOptions && {
7883
- decomposeOptions: toolOptions.decomposeOptions
7884
- },
7885
- ...toolOptions?.now !== void 0 && { now: toolOptions.now }
7893
+ // Do NOT forward decomposeOptions into recall() — rewrite already
7894
+ // ran above, and forwarding would falsely trip `decompose-moved`
7895
+ // on every specific-mode high-budget call. graphRefine auth can
7896
+ // be threaded later when the tool opts into that path.
7897
+ ...toolOptions?.now !== void 0 && { now: toolOptions.now },
7898
+ ...subQueries && { subQueries }
7886
7899
  };
7887
7900
  const result = await recall(query, ctx, recallOpts);
7888
7901
  if (callbacks?.onChunksRetrieved) {
@@ -14232,6 +14245,7 @@ export {
14232
14245
  DEFAULT_VAULT_CACHE_SIZE,
14233
14246
  DatabaseManager,
14234
14247
  ENTITY_FANOUT,
14248
+ EncryptionKeyMissingError,
14235
14249
  HARD_DELETE_WINDOW_MS,
14236
14250
  INFERENCE_ID_HEADER,
14237
14251
  LoggerProvider,
@@ -14358,6 +14372,7 @@ export {
14358
14372
  rankProfileCandidates,
14359
14373
  recall,
14360
14374
  reflect,
14375
+ refreshEncryptionKeyIfMatches,
14361
14376
  refreshNotionAccessToken,
14362
14377
  registerNotionClient,
14363
14378
  relinkMemoryTopicsOp,
@@ -14372,6 +14387,7 @@ export {
14372
14387
  sdkModelClasses,
14373
14388
  sdkSchema,
14374
14389
  searchVaultMemories,
14390
+ seedEncryptionKeys,
14375
14391
  setLogger,
14376
14392
  setMemoryVisibilityOp,
14377
14393
  shouldChunkMessage,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-VBO6KSNQ.mjs";
3
+ } from "./chunk-SIMGZQ4P.mjs";
4
4
  import "./chunk-ILAWDQDE.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
package/dist/index.cjs CHANGED
@@ -2830,6 +2830,16 @@ function buildSystemPrompt(ctx, options) {
2830
2830
  }
2831
2831
 
2832
2832
  // src/react/useEncryption.ts
2833
+ var EncryptionKeyMissingError = class extends Error {
2834
+ constructor(address, version) {
2835
+ super(
2836
+ `Encryption key (${version}) not found for ${address}. Please sign a message to generate your encryption key.`
2837
+ );
2838
+ this.name = "EncryptionKeyMissingError";
2839
+ this.address = address;
2840
+ this.version = version;
2841
+ }
2842
+ };
2833
2843
  var encryptionKeyStore = /* @__PURE__ */ new Map();
2834
2844
  var cryptoKeyCache = /* @__PURE__ */ new Map();
2835
2845
  var clearAllEncryptionStateCallbacks = /* @__PURE__ */ new Set();
@@ -2839,14 +2849,11 @@ function onClearAllEncryptionState(callback) {
2839
2849
  clearAllEncryptionStateCallbacks.delete(callback);
2840
2850
  };
2841
2851
  }
2842
- function getStoredKey(address) {
2843
- const keys = encryptionKeyStore.get(address);
2844
- return keys?.current ?? null;
2845
- }
2846
2852
  function getStoredKeyByVersion(address, version) {
2847
2853
  const keys = encryptionKeyStore.get(address);
2848
2854
  if (!keys) return null;
2849
- return version === "v2" ? keys.legacy : keys.current;
2855
+ const value = version === "v2" ? keys.legacy : keys.current;
2856
+ return value ?? null;
2850
2857
  }
2851
2858
  function hexToBytes(hex) {
2852
2859
  const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
@@ -2866,9 +2873,7 @@ async function getEncryptionKey(address, version = "v3") {
2866
2873
  }
2867
2874
  const keyHex = getStoredKeyByVersion(address, version);
2868
2875
  if (!keyHex) {
2869
- throw new Error(
2870
- "Encryption key not found. Please sign a message to generate your encryption key."
2871
- );
2876
+ throw new EncryptionKeyMissingError(address, version);
2872
2877
  }
2873
2878
  const keyBytes = hexToBytes(keyHex);
2874
2879
  const cryptoKey = await crypto.subtle.importKey(
@@ -2885,8 +2890,8 @@ async function decryptData(encryptedHex, address, version = "v3") {
2885
2890
  const key = await getEncryptionKey(address, version);
2886
2891
  return decryptDataWithKey(encryptedHex, key);
2887
2892
  }
2888
- function hasEncryptionKey(address) {
2889
- return getStoredKey(address) !== null;
2893
+ function hasEncryptionKey(address, version) {
2894
+ return getStoredKeyByVersion(address, version ?? "v3") !== null;
2890
2895
  }
2891
2896
  async function decryptDataWithKey(encryptedHex, key) {
2892
2897
  const combined = hexToBytes(encryptedHex);
@@ -2919,20 +2924,29 @@ function detectEncryptionVersion(value) {
2919
2924
  }
2920
2925
  return null;
2921
2926
  }
2922
- async function decryptField(value, address) {
2923
- if (!value) return value;
2927
+ async function decryptFieldDetailed(value, address) {
2928
+ if (!value) return { status: "plaintext", value };
2924
2929
  const detected = detectEncryptionVersion(value);
2925
- if (!detected) return value;
2930
+ if (!detected) return { status: "plaintext", value };
2926
2931
  if (detected.encryptedData.length < 56 || !/^[0-9a-f]+$/i.test(detected.encryptedData)) {
2927
- return value;
2932
+ return { status: "invalid_payload", value, version: detected.version };
2928
2933
  }
2929
2934
  try {
2930
- return await decryptData(detected.encryptedData, address, detected.version);
2935
+ const plaintext = await decryptData(detected.encryptedData, address, detected.version);
2936
+ return { status: "ok", value: plaintext, version: detected.version };
2931
2937
  } catch (error) {
2932
- getLogger().warn("Failed to decrypt field, returning as-is:", error);
2933
- return value;
2938
+ if (error instanceof EncryptionKeyMissingError) {
2939
+ getLogger().warn("Failed to decrypt field (key missing for version):", error.message);
2940
+ return { status: "key_missing", value, version: detected.version };
2941
+ }
2942
+ getLogger().warn("Failed to decrypt field (auth mismatch or crypto error):", error);
2943
+ return { status: "auth_mismatch", value, version: detected.version };
2934
2944
  }
2935
2945
  }
2946
+ async function decryptField(value, address) {
2947
+ const result = await decryptFieldDetailed(value, address);
2948
+ return result.value;
2949
+ }
2936
2950
 
2937
2951
  // src/lib/chat/useChat/strategies/types.ts
2938
2952
  function isChatCompletionResponse(r) {
package/dist/index.mjs CHANGED
@@ -2634,6 +2634,16 @@ function buildSystemPrompt(ctx, options) {
2634
2634
  }
2635
2635
 
2636
2636
  // src/react/useEncryption.ts
2637
+ var EncryptionKeyMissingError = class extends Error {
2638
+ constructor(address, version) {
2639
+ super(
2640
+ `Encryption key (${version}) not found for ${address}. Please sign a message to generate your encryption key.`
2641
+ );
2642
+ this.name = "EncryptionKeyMissingError";
2643
+ this.address = address;
2644
+ this.version = version;
2645
+ }
2646
+ };
2637
2647
  var encryptionKeyStore = /* @__PURE__ */ new Map();
2638
2648
  var cryptoKeyCache = /* @__PURE__ */ new Map();
2639
2649
  var clearAllEncryptionStateCallbacks = /* @__PURE__ */ new Set();
@@ -2643,14 +2653,11 @@ function onClearAllEncryptionState(callback) {
2643
2653
  clearAllEncryptionStateCallbacks.delete(callback);
2644
2654
  };
2645
2655
  }
2646
- function getStoredKey(address) {
2647
- const keys = encryptionKeyStore.get(address);
2648
- return keys?.current ?? null;
2649
- }
2650
2656
  function getStoredKeyByVersion(address, version) {
2651
2657
  const keys = encryptionKeyStore.get(address);
2652
2658
  if (!keys) return null;
2653
- return version === "v2" ? keys.legacy : keys.current;
2659
+ const value = version === "v2" ? keys.legacy : keys.current;
2660
+ return value ?? null;
2654
2661
  }
2655
2662
  function hexToBytes(hex) {
2656
2663
  const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
@@ -2670,9 +2677,7 @@ async function getEncryptionKey(address, version = "v3") {
2670
2677
  }
2671
2678
  const keyHex = getStoredKeyByVersion(address, version);
2672
2679
  if (!keyHex) {
2673
- throw new Error(
2674
- "Encryption key not found. Please sign a message to generate your encryption key."
2675
- );
2680
+ throw new EncryptionKeyMissingError(address, version);
2676
2681
  }
2677
2682
  const keyBytes = hexToBytes(keyHex);
2678
2683
  const cryptoKey = await crypto.subtle.importKey(
@@ -2689,8 +2694,8 @@ async function decryptData(encryptedHex, address, version = "v3") {
2689
2694
  const key = await getEncryptionKey(address, version);
2690
2695
  return decryptDataWithKey(encryptedHex, key);
2691
2696
  }
2692
- function hasEncryptionKey(address) {
2693
- return getStoredKey(address) !== null;
2697
+ function hasEncryptionKey(address, version) {
2698
+ return getStoredKeyByVersion(address, version ?? "v3") !== null;
2694
2699
  }
2695
2700
  async function decryptDataWithKey(encryptedHex, key) {
2696
2701
  const combined = hexToBytes(encryptedHex);
@@ -2723,20 +2728,29 @@ function detectEncryptionVersion(value) {
2723
2728
  }
2724
2729
  return null;
2725
2730
  }
2726
- async function decryptField(value, address) {
2727
- if (!value) return value;
2731
+ async function decryptFieldDetailed(value, address) {
2732
+ if (!value) return { status: "plaintext", value };
2728
2733
  const detected = detectEncryptionVersion(value);
2729
- if (!detected) return value;
2734
+ if (!detected) return { status: "plaintext", value };
2730
2735
  if (detected.encryptedData.length < 56 || !/^[0-9a-f]+$/i.test(detected.encryptedData)) {
2731
- return value;
2736
+ return { status: "invalid_payload", value, version: detected.version };
2732
2737
  }
2733
2738
  try {
2734
- return await decryptData(detected.encryptedData, address, detected.version);
2739
+ const plaintext = await decryptData(detected.encryptedData, address, detected.version);
2740
+ return { status: "ok", value: plaintext, version: detected.version };
2735
2741
  } catch (error) {
2736
- getLogger().warn("Failed to decrypt field, returning as-is:", error);
2737
- return value;
2742
+ if (error instanceof EncryptionKeyMissingError) {
2743
+ getLogger().warn("Failed to decrypt field (key missing for version):", error.message);
2744
+ return { status: "key_missing", value, version: detected.version };
2745
+ }
2746
+ getLogger().warn("Failed to decrypt field (auth mismatch or crypto error):", error);
2747
+ return { status: "auth_mismatch", value, version: detected.version };
2738
2748
  }
2739
2749
  }
2750
+ async function decryptField(value, address) {
2751
+ const result = await decryptFieldDetailed(value, address);
2752
+ return result.value;
2753
+ }
2740
2754
 
2741
2755
  // src/lib/chat/useChat/strategies/types.ts
2742
2756
  function isChatCompletionResponse(r) {