@anuma/sdk 10.2.1 → 10.2.3

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.
@@ -1818,6 +1818,7 @@ interface MessageRedactionResult {
1818
1818
  * same email address throughout the conversation.
1819
1819
  */
1820
1820
  declare class PiiRedactor {
1821
+ private disposed;
1821
1822
  /** Maps original PII value → placeholder tag. */
1822
1823
  private valueToPlaceholder;
1823
1824
  /** Maps placeholder tag → original PII value (reverse lookup for de-anonymization). */
@@ -2017,6 +2018,8 @@ declare class PiiRedactor {
2017
2018
  * Reset all state. Useful for testing or when starting a fresh conversation.
2018
2019
  */
2019
2020
  clear(): void;
2021
+ /** Clear the mappings and prevent new reversible mappings. */
2022
+ dispose(): void;
2020
2023
  }
2021
2024
  /**
2022
2025
  * Structural (duck-typed) check for a {@link PiiRedactor}. Used instead of
@@ -1818,6 +1818,7 @@ interface MessageRedactionResult {
1818
1818
  * same email address throughout the conversation.
1819
1819
  */
1820
1820
  declare class PiiRedactor {
1821
+ private disposed;
1821
1822
  /** Maps original PII value → placeholder tag. */
1822
1823
  private valueToPlaceholder;
1823
1824
  /** Maps placeholder tag → original PII value (reverse lookup for de-anonymization). */
@@ -2017,6 +2018,8 @@ declare class PiiRedactor {
2017
2018
  * Reset all state. Useful for testing or when starting a fresh conversation.
2018
2019
  */
2019
2020
  clear(): void;
2021
+ /** Clear the mappings and prevent new reversible mappings. */
2022
+ dispose(): void;
2020
2023
  }
2021
2024
  /**
2022
2025
  * Structural (duck-typed) check for a {@link PiiRedactor}. Used instead of
@@ -20,7 +20,7 @@ import {
20
20
  taskTypeHeader,
21
21
  validateEndpointOverride,
22
22
  withInternalFlowMarker
23
- } from "./chunk-WRZTH4OS.mjs";
23
+ } from "./chunk-ZIN4E7MR.mjs";
24
24
  import {
25
25
  BASE_URL,
26
26
  MCP_R2_DOMAIN,
@@ -1054,12 +1054,12 @@ async function persistKeyPair(address, startEpoch) {
1054
1054
  const combined = new Uint8Array(iv.length + encryptedBytes.length);
1055
1055
  combined.set(iv, 0);
1056
1056
  combined.set(encryptedBytes, iv.length);
1057
- const storageKey = `${KEYPAIR_STORAGE_PREFIX}${address}`;
1057
+ const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
1058
1058
  const encryptedHex = bytesToHex(combined);
1059
1059
  if (sessionEpoch !== startEpoch) {
1060
1060
  return;
1061
1061
  }
1062
- localStorage.setItem(storageKey, encryptedHex);
1062
+ localStorage.setItem(storageKey2, encryptedHex);
1063
1063
  } catch (err) {
1064
1064
  throw new Error(
1065
1065
  `Failed to persist keypair: ${err instanceof Error ? err.message : String(err)}`
@@ -1070,8 +1070,8 @@ async function loadPersistedKeyPair(address) {
1070
1070
  if (typeof window === "undefined") {
1071
1071
  return null;
1072
1072
  }
1073
- const storageKey = `${KEYPAIR_STORAGE_PREFIX}${address}`;
1074
- const encryptedHex = localStorage.getItem(storageKey);
1073
+ const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
1074
+ const encryptedHex = localStorage.getItem(storageKey2);
1075
1075
  if (!encryptedHex) {
1076
1076
  return null;
1077
1077
  }
@@ -1122,7 +1122,7 @@ async function loadPersistedKeyPair(address) {
1122
1122
  publicKey
1123
1123
  };
1124
1124
  } catch (error) {
1125
- localStorage.removeItem(storageKey);
1125
+ localStorage.removeItem(storageKey2);
1126
1126
  getLogger().warn(
1127
1127
  `Failed to load persisted keypair for ${address}: ${error instanceof Error ? error.message : String(error)}`
1128
1128
  );
@@ -1133,8 +1133,8 @@ function clearPersistedKeyPair(address) {
1133
1133
  if (typeof window === "undefined") {
1134
1134
  return;
1135
1135
  }
1136
- const storageKey = `${KEYPAIR_STORAGE_PREFIX}${address}`;
1137
- localStorage.removeItem(storageKey);
1136
+ const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
1137
+ localStorage.removeItem(storageKey2);
1138
1138
  }
1139
1139
  async function getKeyPair(address, signMessage, embeddedWalletSigner) {
1140
1140
  const existingKeyPair = getStoredKeyPair(address);
@@ -17868,11 +17868,11 @@ function loadVaultCorpus(ctx, options, preparation) {
17868
17868
  }
17869
17869
  return request;
17870
17870
  }
17871
- function rowRequestsFor(registry2, ctx, maskInput) {
17872
- let byMask = registry2.get(ctx);
17871
+ function rowRequestsFor(registry3, ctx, maskInput) {
17872
+ let byMask = registry3.get(ctx);
17873
17873
  if (!byMask) {
17874
17874
  byMask = /* @__PURE__ */ new Map();
17875
- registry2.set(ctx, byMask);
17875
+ registry3.set(ctx, byMask);
17876
17876
  }
17877
17877
  let requests = byMask.get(maskInput);
17878
17878
  if (!requests) {
@@ -18807,11 +18807,11 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
18807
18807
  };
18808
18808
  }
18809
18809
  const limit = searchOptions?.limit ?? 5;
18810
- const scopes = searchOptions?.scopes;
18810
+ const scopes2 = searchOptions?.scopes;
18811
18811
  const folderId = searchOptions?.folderId;
18812
18812
  const queryOpts = {};
18813
18813
  if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
18814
- if (scopes?.length) queryOpts.scopes = scopes;
18814
+ if (scopes2?.length) queryOpts.scopes = scopes2;
18815
18815
  if (folderId !== void 0) queryOpts.folderId = folderId;
18816
18816
  if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
18817
18817
  if (searchOptions?.includeArchived) queryOpts.includeArchived = true;
@@ -19589,7 +19589,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
19589
19589
  content: m.content,
19590
19590
  similarity: m.similarity
19591
19591
  }));
19592
- const { consolidateMemory: doConsolidate } = await import("./consolidate-HKL5EGZT.mjs");
19592
+ const { consolidateMemory: doConsolidate } = await import("./consolidate-4WLZMXOS.mjs");
19593
19593
  const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
19594
19594
  if (decision.action === "create") return decision.fallbackReason ? null : { create: true };
19595
19595
  if (decision.action === "supersede" && decision.content) {
@@ -25068,17 +25068,17 @@ async function synthesizeProfile(ctx, options = {}) {
25068
25068
  }
25069
25069
  const recallCtx = store ? { embeddingOptions: ctx.embeddingOptions, factSource: store.factSource } : ctx;
25070
25070
  const facets = options.facets ?? DEFAULT_PROFILE_FACETS;
25071
- const scopes = options.scopes ?? DEFAULT_SCOPES;
25071
+ const scopes2 = options.scopes ?? DEFAULT_SCOPES;
25072
25072
  const config = {
25073
25073
  facetKeys: facets.map((f) => f.key).sort(),
25074
25074
  facetsSignature: facetsSignature(facets),
25075
- scopes: [...scopes].sort(),
25075
+ scopes: [...scopes2].sort(),
25076
25076
  redacted: options.redactor !== void 0,
25077
25077
  reviewedMemoryIdsSignature: reviewedMemoryIdsSignature(options.reviewedMemoryIds)
25078
25078
  };
25079
25079
  const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
25080
- const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
25081
- const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
25080
+ const listOptions = { scopes: scopes2, includeDeleted: true, includeSuperseded: true };
25081
+ const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes: scopes2 }), []];
25082
25082
  const watermark = computeVaultWatermark(memories);
25083
25083
  const observationTrends = summarizeObservationTrends(
25084
25084
  memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
@@ -25123,7 +25123,7 @@ async function synthesizeProfile(ctx, options = {}) {
25123
25123
  for (const section of previous.sections) {
25124
25124
  if (section.sourceMemoryIds.length > 0 && section.sourceMemoryIds.every((id2) => {
25125
25125
  const memory = memoriesById.get(id2);
25126
- return memory && !memory.isDeleted && !memory.supersededBy && scopes.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
25126
+ return memory && !memory.isDeleted && !memory.supersededBy && scopes2.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
25127
25127
  })) {
25128
25128
  fallbackPriors.set(section.key, section);
25129
25129
  }
@@ -25296,7 +25296,7 @@ async function attributeFacts(ctx, candidates, facets) {
25296
25296
  return keys;
25297
25297
  }
25298
25298
  async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
25299
- const scopes = options.scopes ?? DEFAULT_SCOPES;
25299
+ const scopes2 = options.scopes ?? DEFAULT_SCOPES;
25300
25300
  const limit = options.limit ?? DEFAULT_FACET_RECALL_LIMIT;
25301
25301
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
25302
25302
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
@@ -25313,7 +25313,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
25313
25313
  }
25314
25314
  const recalled = await recall(facet.query, ctx, {
25315
25315
  vaultPreparation,
25316
- scopes,
25316
+ scopes: scopes2,
25317
25317
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
25318
25318
  ...hasReviewGate && { memoryIds: [...reviewed] },
25319
25319
  types: ["fact"],
@@ -25340,7 +25340,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
25340
25340
  llmModel: options.llmModel ?? DEFAULT_SYNTHESIS_MODEL,
25341
25341
  baseUrl: options.baseUrl,
25342
25342
  fetchFn: options.fetchFn,
25343
- scopes,
25343
+ scopes: scopes2,
25344
25344
  limit,
25345
25345
  types: ["fact"],
25346
25346
  maxTokens: DEFAULT_FACET_MAX_TOKENS,
@@ -29098,7 +29098,7 @@ function useChat(options) {
29098
29098
  }
29099
29099
 
29100
29100
  // src/expo/useChatStorage.ts
29101
- import { useCallback as useCallback4, useEffect as useEffect4, useMemo, useRef as useRef4, useState as useState4 } from "react";
29101
+ import { useCallback as useCallback5, useEffect as useEffect5, useMemo, useRef as useRef4, useState as useState4 } from "react";
29102
29102
  import { v7 as uuidv78 } from "uuid";
29103
29103
 
29104
29104
  // src/lib/chat/assembleMessages.ts
@@ -29884,6 +29884,106 @@ async function deleteMediaByConversationOp(ctx, conversationId) {
29884
29884
  return results.length;
29885
29885
  }
29886
29886
 
29887
+ // src/lib/pii/useConversationRedactors.ts
29888
+ import { useCallback as useCallback4, useEffect as useEffect4, useSyncExternalStore } from "react";
29889
+ var REDACTOR_LIMIT = 50;
29890
+ var registry2 = /* @__PURE__ */ new WeakMap();
29891
+ var compositeKeys = /* @__PURE__ */ new WeakMap();
29892
+ var scopes = /* @__PURE__ */ new Set();
29893
+ var retiredRedactor = new PiiRedactor();
29894
+ retiredRedactor.dispose();
29895
+ function retireScope(scope) {
29896
+ scopes.delete(scope);
29897
+ if (!scope.active) return;
29898
+ scope.active = false;
29899
+ for (const { redactor } of scope.redactors.values()) redactor.dispose();
29900
+ scope.redactors.clear();
29901
+ for (const redactor of scope.evicted) redactor.dispose();
29902
+ scope.evicted = [];
29903
+ for (const notify of scope.subscribers) notify();
29904
+ }
29905
+ function storageKey(storage, secondaryStorage) {
29906
+ if (!secondaryStorage) return storage;
29907
+ let inner = compositeKeys.get(storage);
29908
+ if (!inner) {
29909
+ inner = /* @__PURE__ */ new WeakMap();
29910
+ compositeKeys.set(storage, inner);
29911
+ }
29912
+ let key3 = inner.get(secondaryStorage);
29913
+ if (!key3) {
29914
+ key3 = {};
29915
+ inner.set(secondaryStorage, key3);
29916
+ }
29917
+ return key3;
29918
+ }
29919
+ function getScope(database, storage, account) {
29920
+ let stores = registry2.get(database);
29921
+ if (!stores) {
29922
+ stores = /* @__PURE__ */ new WeakMap();
29923
+ registry2.set(database, stores);
29924
+ }
29925
+ let accounts = stores.get(storage);
29926
+ if (!accounts) {
29927
+ accounts = /* @__PURE__ */ new Map();
29928
+ stores.set(storage, accounts);
29929
+ }
29930
+ let scope = accounts.get(account);
29931
+ if (!scope?.active) {
29932
+ scope = { active: true, users: 0, subscribers: /* @__PURE__ */ new Set(), redactors: /* @__PURE__ */ new Map(), evicted: [] };
29933
+ accounts.set(account, scope);
29934
+ }
29935
+ return scope;
29936
+ }
29937
+ onClearAllEncryptionState(() => {
29938
+ registry2 = /* @__PURE__ */ new WeakMap();
29939
+ for (const scope of [...scopes]) retireScope(scope);
29940
+ });
29941
+ function useConversationRedactors(database, account, storage, secondaryStorage) {
29942
+ const scope = getScope(database, storageKey(storage, secondaryStorage), account);
29943
+ const subscribe = useCallback4(
29944
+ (callback) => {
29945
+ scope.subscribers.add(callback);
29946
+ return () => {
29947
+ scope.subscribers.delete(callback);
29948
+ };
29949
+ },
29950
+ [scope]
29951
+ );
29952
+ const getSnapshot = useCallback4(() => scope.active ? scope : null, [scope]);
29953
+ useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
29954
+ useEffect4(() => {
29955
+ if (scope.active) scopes.add(scope);
29956
+ scope.users++;
29957
+ return () => {
29958
+ scope.users--;
29959
+ if (scope.users === 0) retireScope(scope);
29960
+ };
29961
+ }, [scope]);
29962
+ return useCallback4(
29963
+ (conversationId, nerDetector) => {
29964
+ if (!scope.active) return retiredRedactor;
29965
+ const cached = scope.redactors.get(conversationId);
29966
+ if (cached && cached.detector === nerDetector) {
29967
+ scope.redactors.delete(conversationId);
29968
+ scope.redactors.set(conversationId, cached);
29969
+ return cached.redactor;
29970
+ }
29971
+ if (cached) scope.evicted.push(cached.redactor);
29972
+ const redactor = new PiiRedactor({ nerDetector });
29973
+ scope.redactors.set(conversationId, { redactor, detector: nerDetector });
29974
+ if (scope.redactors.size > REDACTOR_LIMIT) {
29975
+ const oldest = scope.redactors.entries().next().value;
29976
+ if (oldest) {
29977
+ scope.evicted.push(oldest[1].redactor);
29978
+ scope.redactors.delete(oldest[0]);
29979
+ }
29980
+ }
29981
+ return redactor;
29982
+ },
29983
+ [scope]
29984
+ );
29985
+ }
29986
+
29887
29987
  // src/lib/tools/selection/activeToolSets.ts
29888
29988
  function mergeActiveToolSets(current, derived) {
29889
29989
  if (derived.length === 0) return current;
@@ -29944,30 +30044,11 @@ function resetRecentToolSets() {
29944
30044
  onClearAllEncryptionState(resetRecentToolSets);
29945
30045
 
29946
30046
  // src/expo/useChatStorage.ts
29947
- var CONVERSATION_REDACTOR_LIMIT = 50;
29948
- var NO_CONVERSATION_KEY = "__no_conversation__";
29949
30047
  var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
29950
30048
  var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
29951
30049
  var MEMORY_STORE_NOT_READY = "Memory store is not ready";
29952
- var conversationRedactors = /* @__PURE__ */ new Map();
29953
30050
  var queuedBackends = /* @__PURE__ */ new WeakMap();
29954
30051
  var clientToolFilterCache = /* @__PURE__ */ new Map();
29955
- function getConversationRedactor(conversationId, nerDetector) {
29956
- const key3 = conversationId ?? NO_CONVERSATION_KEY;
29957
- const cached = conversationRedactors.get(key3);
29958
- if (cached && cached.detector === nerDetector) {
29959
- conversationRedactors.delete(key3);
29960
- conversationRedactors.set(key3, cached);
29961
- return cached.redactor;
29962
- }
29963
- const redactor = new PiiRedactor({ nerDetector });
29964
- conversationRedactors.set(key3, { redactor, detector: nerDetector });
29965
- if (conversationRedactors.size > CONVERSATION_REDACTOR_LIMIT) {
29966
- const oldest = conversationRedactors.keys().next().value;
29967
- if (oldest !== void 0) conversationRedactors.delete(oldest);
29968
- }
29969
- return redactor;
29970
- }
29971
30052
  function resolveCallPii(requestPiiRedaction, hookPiiRedaction, getConversationRedactorFor) {
29972
30053
  const effective = requestPiiRedaction === void 0 ? hookPiiRedaction : requestPiiRedaction;
29973
30054
  const redactor = effective === true ? getConversationRedactorFor() : isPiiRedactor(effective) ? effective : void 0;
@@ -30086,11 +30167,17 @@ function useChatStorage(options) {
30086
30167
  foldToolResultsInHistoryRef.current = foldToolResultsInHistory;
30087
30168
  const nerDetectorRef = useRef4(nerDetector);
30088
30169
  nerDetectorRef.current = nerDetector;
30170
+ const getConversationRedactor = useConversationRedactors(
30171
+ database,
30172
+ walletAddress,
30173
+ memoryStore ?? chatBackend ?? database,
30174
+ memoryStore && chatBackend ? chatBackend : void 0
30175
+ );
30089
30176
  const resolvedPiiRedaction = useMemo(
30090
30177
  () => piiRedaction === true ? getConversationRedactor(currentConversationId, nerDetectorRef.current) : piiRedaction,
30091
- [piiRedaction, currentConversationId]
30178
+ [piiRedaction, currentConversationId, getConversationRedactor]
30092
30179
  );
30093
- const maskForEmbedding = useCallback4(
30180
+ const maskForEmbedding = useCallback5(
30094
30181
  (text16) => isPiiRedactor(resolvedPiiRedaction) ? resolvedPiiRedaction.maskText(text16) : text16,
30095
30182
  [resolvedPiiRedaction]
30096
30183
  );
@@ -30152,12 +30239,12 @@ function useChatStorage(options) {
30152
30239
  isFlushing: false,
30153
30240
  isPaused: false
30154
30241
  });
30155
- const refreshQueueStatus = useCallback4(() => {
30242
+ const refreshQueueStatus = useCallback5(() => {
30156
30243
  if (walletAddress) {
30157
30244
  setQueueStatus(queueManager.getStatus(walletAddress));
30158
30245
  }
30159
30246
  }, [walletAddress]);
30160
- const executeQueuedOperation = useCallback4(
30247
+ const executeQueuedOperation = useCallback5(
30161
30248
  async (operation, encCtx) => {
30162
30249
  const queued = queuedBackends.get(operation.payload) ?? backendFactory({
30163
30250
  walletAddress: encCtx.walletAddress,
@@ -30202,7 +30289,7 @@ function useChatStorage(options) {
30202
30289
  },
30203
30290
  [backendFactory, database]
30204
30291
  );
30205
- const flushQueue = useCallback4(async () => {
30292
+ const flushQueue = useCallback5(async () => {
30206
30293
  if (!walletAddress || !signMessage) {
30207
30294
  return { succeeded: [], failed: [], total: 0 };
30208
30295
  }
@@ -30221,18 +30308,18 @@ function useChatStorage(options) {
30221
30308
  executeQueuedOperation,
30222
30309
  refreshQueueStatus
30223
30310
  ]);
30224
- const clearQueue = useCallback4(() => {
30311
+ const clearQueue = useCallback5(() => {
30225
30312
  if (walletAddress) {
30226
30313
  queueManager.clear(walletAddress);
30227
30314
  refreshQueueStatus();
30228
30315
  }
30229
30316
  }, [walletAddress, refreshQueueStatus]);
30230
- useEffect4(() => {
30317
+ useEffect5(() => {
30231
30318
  if (!walletAddress) return;
30232
30319
  refreshQueueStatus();
30233
30320
  return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
30234
30321
  }, [walletAddress, refreshQueueStatus]);
30235
- useEffect4(() => {
30322
+ useEffect5(() => {
30236
30323
  if (!getWalletAddress || walletAddress) return;
30237
30324
  const poller = new WalletPoller();
30238
30325
  return poller.startPolling(getWalletAddress, () => {
@@ -30240,7 +30327,7 @@ function useChatStorage(options) {
30240
30327
  }, [getWalletAddress, walletAddress]);
30241
30328
  const pendingOpsRef = useRef4([]);
30242
30329
  const syntheticConvIdsRef = useRef4(/* @__PURE__ */ new Set());
30243
- useEffect4(() => {
30330
+ useEffect5(() => {
30244
30331
  if (!walletAddress || !enableQueue) return;
30245
30332
  const pending = pendingOpsRef.current;
30246
30333
  if (pending.length === 0) return;
@@ -30251,7 +30338,7 @@ function useChatStorage(options) {
30251
30338
  pendingOpsRef.current = [];
30252
30339
  refreshQueueStatus();
30253
30340
  }, [walletAddress, enableQueue, refreshQueueStatus]);
30254
- useEffect4(() => {
30341
+ useEffect5(() => {
30255
30342
  if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
30256
30343
  return onKeyAvailable(walletAddress, () => {
30257
30344
  flushQueue().catch((err) => {
@@ -30259,7 +30346,7 @@ function useChatStorage(options) {
30259
30346
  });
30260
30347
  });
30261
30348
  }, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
30262
- const writeOrQueue = useCallback4(
30349
+ const writeOrQueue = useCallback5(
30263
30350
  async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
30264
30351
  const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
30265
30352
  const currentBackend = storageCtx.walletAddress ? backend : backendRef.current;
@@ -30297,7 +30384,7 @@ function useChatStorage(options) {
30297
30384
  },
30298
30385
  [storageCtx, backend, enableQueue, signMessage, getWalletAddress]
30299
30386
  );
30300
- const embedMessageAsync = useCallback4(
30387
+ const embedMessageAsync = useCallback5(
30301
30388
  async (message, mask = maskForEmbedding) => {
30302
30389
  if (!autoEmbedMessages || !getToken) return;
30303
30390
  if (message.content.length < minContentLength) return;
@@ -30334,7 +30421,7 @@ function useChatStorage(options) {
30334
30421
  maskForEmbedding
30335
30422
  ]
30336
30423
  );
30337
- const createMemoryEngineTool2 = useCallback4(
30424
+ const createMemoryEngineTool2 = useCallback5(
30338
30425
  (searchOptions) => {
30339
30426
  if (!getToken) {
30340
30427
  throw new Error("getToken is required for memory engine tool");
@@ -30352,13 +30439,13 @@ function useChatStorage(options) {
30352
30439
  [database, walletAddress, embeddingModel]
30353
30440
  );
30354
30441
  const chunkVectorCacheRef = useRef4(createChunkVectorCache());
30355
- useEffect4(() => {
30442
+ useEffect5(() => {
30356
30443
  return onClearAllEncryptionState(() => {
30357
30444
  vaultEmbeddingCache.clear();
30358
30445
  chunkVectorCacheRef.current.clear();
30359
30446
  });
30360
30447
  }, [vaultEmbeddingCache]);
30361
- const retainVaultMemory = useCallback4(
30448
+ const retainVaultMemory = useCallback5(
30362
30449
  async (input) => {
30363
30450
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
30364
30451
  if (memoryStore) {
@@ -30404,7 +30491,7 @@ function useChatStorage(options) {
30404
30491
  storeMaskMissing
30405
30492
  ]
30406
30493
  );
30407
- const createMemoryVaultTool2 = useCallback4(
30494
+ const createMemoryVaultTool2 = useCallback5(
30408
30495
  (options2) => {
30409
30496
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
30410
30497
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -30415,7 +30502,7 @@ function useChatStorage(options) {
30415
30502
  },
30416
30503
  [vaultCtx, getToken, retainVaultMemory, memoryStore, storeMaskMissing]
30417
30504
  );
30418
- const createRecallTool2 = useCallback4(
30505
+ const createRecallTool2 = useCallback5(
30419
30506
  (toolOptions, callbacks) => {
30420
30507
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
30421
30508
  if (!getToken && !memoryStore) {
@@ -30461,7 +30548,7 @@ function useChatStorage(options) {
30461
30548
  storeMaskMissing
30462
30549
  ]
30463
30550
  );
30464
- const recallFn = useCallback4(
30551
+ const recallFn = useCallback5(
30465
30552
  async (query, options2) => {
30466
30553
  if (memoryStore === null || !getToken && !memoryStore) {
30467
30554
  return {
@@ -30510,7 +30597,7 @@ function useChatStorage(options) {
30510
30597
  storeMaskMissing
30511
30598
  ]
30512
30599
  );
30513
- const getVaultMemories = useCallback4(
30600
+ const getVaultMemories = useCallback5(
30514
30601
  (options2) => {
30515
30602
  if (memoryStore === null) return Promise.resolve([]);
30516
30603
  if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
@@ -30522,7 +30609,7 @@ function useChatStorage(options) {
30522
30609
  },
30523
30610
  [vaultCtx, memoryStore]
30524
30611
  );
30525
- const deleteVaultMemory = useCallback4(
30612
+ const deleteVaultMemory = useCallback5(
30526
30613
  async (id2) => {
30527
30614
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
30528
30615
  return memoryStore ? memoryStore.delete(id2) : deleteVaultMemoryOp(vaultCtx, id2);
@@ -30560,7 +30647,7 @@ function useChatStorage(options) {
30560
30647
  const activeResumeRef = useRef4(null);
30561
30648
  const retirementRef = useRef4(null);
30562
30649
  const retirementStopRequestedRef = useRef4(false);
30563
- const createConversation = useCallback4(
30650
+ const createConversation = useCallback5(
30564
30651
  async (opts) => {
30565
30652
  const conversationOpts = {
30566
30653
  ...opts,
@@ -30580,16 +30667,16 @@ function useChatStorage(options) {
30580
30667
  },
30581
30668
  [defaultConversationTitle, writeOrQueue]
30582
30669
  );
30583
- const getConversation = useCallback4(
30670
+ const getConversation = useCallback5(
30584
30671
  async (id2) => {
30585
30672
  return backend.getConversation(id2);
30586
30673
  },
30587
30674
  [backend]
30588
30675
  );
30589
- const getConversations = useCallback4(async () => {
30676
+ const getConversations = useCallback5(async () => {
30590
30677
  return backend.getConversations();
30591
30678
  }, [backend]);
30592
- const updateConversationTitle = useCallback4(
30679
+ const updateConversationTitle = useCallback5(
30593
30680
  async (id2, title) => {
30594
30681
  const { result } = await writeOrQueue(
30595
30682
  "updateConversationTitle",
@@ -30601,7 +30688,7 @@ function useChatStorage(options) {
30601
30688
  },
30602
30689
  [writeOrQueue]
30603
30690
  );
30604
- const updateConversationPinned = useCallback4(
30691
+ const updateConversationPinned = useCallback5(
30605
30692
  async (id2, pinned) => {
30606
30693
  const { result } = await writeOrQueue(
30607
30694
  "updateConversationPinned",
@@ -30613,7 +30700,7 @@ function useChatStorage(options) {
30613
30700
  },
30614
30701
  [writeOrQueue]
30615
30702
  );
30616
- const deleteConversation = useCallback4(
30703
+ const deleteConversation = useCallback5(
30617
30704
  async (id2) => {
30618
30705
  const deleted = await backend.deleteConversation(id2);
30619
30706
  if (deleted) {
@@ -30631,31 +30718,31 @@ function useChatStorage(options) {
30631
30718
  },
30632
30719
  [backend, database, walletAddress, signMessage, embeddedWalletSigner, currentConversationId]
30633
30720
  );
30634
- const getMessages = useCallback4(
30721
+ const getMessages = useCallback5(
30635
30722
  async (convId) => {
30636
30723
  return backend.getMessages(convId);
30637
30724
  },
30638
30725
  [backend]
30639
30726
  );
30640
- const getMessagesPage = useCallback4(
30727
+ const getMessagesPage = useCallback5(
30641
30728
  async (convId, options2) => {
30642
30729
  return backend.getMessagesPage(convId, options2);
30643
30730
  },
30644
30731
  [backend]
30645
30732
  );
30646
- const getMessageSkeletons = useCallback4(
30733
+ const getMessageSkeletons = useCallback5(
30647
30734
  (convId) => {
30648
30735
  return backend.getMessageSkeletons(convId);
30649
30736
  },
30650
30737
  [backend]
30651
30738
  );
30652
- const getMessageCount = useCallback4(
30739
+ const getMessageCount = useCallback5(
30653
30740
  (convId) => {
30654
30741
  return backend.getMessageCount(convId);
30655
30742
  },
30656
30743
  [backend]
30657
30744
  );
30658
- const extractSourcesFromAssistantMessage = useCallback4(
30745
+ const extractSourcesFromAssistantMessage = useCallback5(
30659
30746
  (assistantMessage) => {
30660
30747
  try {
30661
30748
  const extractedSources = [];
@@ -30737,7 +30824,7 @@ function useChatStorage(options) {
30737
30824
  },
30738
30825
  []
30739
30826
  );
30740
- const ensureConversation = useCallback4(async () => {
30827
+ const ensureConversation = useCallback5(async () => {
30741
30828
  if (currentConversationId) {
30742
30829
  if (syntheticConvIdsRef.current.has(currentConversationId)) {
30743
30830
  return currentConversationId;
@@ -30763,7 +30850,7 @@ function useChatStorage(options) {
30763
30850
  activeToolSetsRef.current = activeToolSets;
30764
30851
  const getTokenRef = useRef4(getToken);
30765
30852
  getTokenRef.current = getToken;
30766
- const finalizeResumedRow = useCallback4(
30853
+ const finalizeResumedRow = useCallback5(
30767
30854
  async (ctx, data, wasStopped, responseDuration, viaQueue = false) => {
30768
30855
  const { content, thinking } = extractAssistantText(data);
30769
30856
  let parentMessageId = ctx.userMessageUniqueId;
@@ -30837,7 +30924,7 @@ function useChatStorage(options) {
30837
30924
  },
30838
30925
  [backend, getMessages, writeOrQueue]
30839
30926
  );
30840
- const retirePendingTurn = useCallback4(async () => {
30927
+ const retirePendingTurn = useCallback5(async () => {
30841
30928
  const visible = activeResumeRef.current;
30842
30929
  if (visible && !visible.headless) {
30843
30930
  baseStop();
@@ -30900,7 +30987,7 @@ function useChatStorage(options) {
30900
30987
  }
30901
30988
  }
30902
30989
  }, [baseCancel, baseStop, finalizeResumedRow, walletAddress, signMessage, embeddedWalletSigner]);
30903
- const sendMessage = useCallback4(
30990
+ const sendMessage = useCallback5(
30904
30991
  async (args) => {
30905
30992
  const {
30906
30993
  messages,
@@ -31704,6 +31791,8 @@ function useChatStorage(options) {
31704
31791
  getMessages,
31705
31792
  backend,
31706
31793
  baseSendMessage,
31794
+ getConversationRedactor,
31795
+ piiRedaction,
31707
31796
  retirePendingTurn,
31708
31797
  embedMessageAsync,
31709
31798
  minContentLength,
@@ -31718,7 +31807,7 @@ function useChatStorage(options) {
31718
31807
  onPiiRedacted
31719
31808
  ]
31720
31809
  );
31721
- const resumeStream2 = useCallback4(
31810
+ const resumeStream2 = useCallback5(
31722
31811
  async (handleOverride, opts) => {
31723
31812
  if (isResumingRef.current || retirementRef.current) {
31724
31813
  return { data: null, error: "Resume already in progress", assistantMessage: null };
@@ -31848,7 +31937,7 @@ function useChatStorage(options) {
31848
31937
  },
31849
31938
  [baseResumeStream, currentConversationId, finalizeResumedRow, embedMessageAsync]
31850
31939
  );
31851
- const stop = useCallback4(() => {
31940
+ const stop = useCallback5(() => {
31852
31941
  if (retirementRef.current) {
31853
31942
  retirementStopRequestedRef.current = true;
31854
31943
  return;
package/dist/index.cjs CHANGED
@@ -3415,6 +3415,7 @@ function isWordChar(ch) {
3415
3415
  }
3416
3416
  var PiiRedactor = class {
3417
3417
  constructor(options = {}) {
3418
+ this.disposed = false;
3418
3419
  /** Maps original PII value → placeholder tag. */
3419
3420
  this.valueToPlaceholder = /* @__PURE__ */ new Map();
3420
3421
  /** Maps placeholder tag → original PII value (reverse lookup for de-anonymization). */
@@ -3489,6 +3490,7 @@ var PiiRedactor = class {
3489
3490
  * The same value always gets the same placeholder within a redactor instance.
3490
3491
  */
3491
3492
  getPlaceholder(category, value) {
3493
+ if (this.disposed) throw new Error("PII redactor session ended");
3492
3494
  const normalizedValue = value.trim();
3493
3495
  const existing = this.valueToPlaceholder.get(normalizedValue);
3494
3496
  if (existing) return existing;
@@ -3864,6 +3866,11 @@ var PiiRedactor = class {
3864
3866
  this.warnedNonText = false;
3865
3867
  this.warnedNerFailure = false;
3866
3868
  }
3869
+ /** Clear the mappings and prevent new reversible mappings. */
3870
+ dispose() {
3871
+ this.disposed = true;
3872
+ this.clear();
3873
+ }
3867
3874
  };
3868
3875
  function isPiiRedactor(value) {
3869
3876
  return typeof value === "object" && value !== null && typeof value.redactMessages === "function" && typeof value.deAnonymize === "function";
package/dist/index.d.mts CHANGED
@@ -7543,6 +7543,7 @@ interface MessageRedactionResult {
7543
7543
  * same email address throughout the conversation.
7544
7544
  */
7545
7545
  declare class PiiRedactor {
7546
+ private disposed;
7546
7547
  /** Maps original PII value → placeholder tag. */
7547
7548
  private valueToPlaceholder;
7548
7549
  /** Maps placeholder tag → original PII value (reverse lookup for de-anonymization). */
@@ -7742,6 +7743,8 @@ declare class PiiRedactor {
7742
7743
  * Reset all state. Useful for testing or when starting a fresh conversation.
7743
7744
  */
7744
7745
  clear(): void;
7746
+ /** Clear the mappings and prevent new reversible mappings. */
7747
+ dispose(): void;
7745
7748
  }
7746
7749
  /**
7747
7750
  * Structural (duck-typed) check for a {@link PiiRedactor}. Used instead of