@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.
@@ -288,6 +288,7 @@ var init_redactor = __esm({
288
288
  init_patterns();
289
289
  PiiRedactor = class {
290
290
  constructor(options = {}) {
291
+ this.disposed = false;
291
292
  /** Maps original PII value → placeholder tag. */
292
293
  this.valueToPlaceholder = /* @__PURE__ */ new Map();
293
294
  /** Maps placeholder tag → original PII value (reverse lookup for de-anonymization). */
@@ -362,6 +363,7 @@ var init_redactor = __esm({
362
363
  * The same value always gets the same placeholder within a redactor instance.
363
364
  */
364
365
  getPlaceholder(category, value) {
366
+ if (this.disposed) throw new Error("PII redactor session ended");
365
367
  const normalizedValue = value.trim();
366
368
  const existing = this.valueToPlaceholder.get(normalizedValue);
367
369
  if (existing) return existing;
@@ -737,6 +739,11 @@ var init_redactor = __esm({
737
739
  this.warnedNonText = false;
738
740
  this.warnedNerFailure = false;
739
741
  }
742
+ /** Clear the mappings and prevent new reversible mappings. */
743
+ dispose() {
744
+ this.disposed = true;
745
+ this.clear();
746
+ }
740
747
  };
741
748
  }
742
749
  });
@@ -2680,12 +2687,12 @@ async function persistKeyPair(address, startEpoch) {
2680
2687
  const combined = new Uint8Array(iv.length + encryptedBytes.length);
2681
2688
  combined.set(iv, 0);
2682
2689
  combined.set(encryptedBytes, iv.length);
2683
- const storageKey = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2690
+ const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2684
2691
  const encryptedHex = bytesToHex(combined);
2685
2692
  if (sessionEpoch !== startEpoch) {
2686
2693
  return;
2687
2694
  }
2688
- localStorage.setItem(storageKey, encryptedHex);
2695
+ localStorage.setItem(storageKey2, encryptedHex);
2689
2696
  } catch (err) {
2690
2697
  throw new Error(
2691
2698
  `Failed to persist keypair: ${err instanceof Error ? err.message : String(err)}`
@@ -2696,8 +2703,8 @@ async function loadPersistedKeyPair(address) {
2696
2703
  if (typeof window === "undefined") {
2697
2704
  return null;
2698
2705
  }
2699
- const storageKey = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2700
- const encryptedHex = localStorage.getItem(storageKey);
2706
+ const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2707
+ const encryptedHex = localStorage.getItem(storageKey2);
2701
2708
  if (!encryptedHex) {
2702
2709
  return null;
2703
2710
  }
@@ -2748,7 +2755,7 @@ async function loadPersistedKeyPair(address) {
2748
2755
  publicKey
2749
2756
  };
2750
2757
  } catch (error) {
2751
- localStorage.removeItem(storageKey);
2758
+ localStorage.removeItem(storageKey2);
2752
2759
  getLogger().warn(
2753
2760
  `Failed to load persisted keypair for ${address}: ${error instanceof Error ? error.message : String(error)}`
2754
2761
  );
@@ -2759,8 +2766,8 @@ function clearPersistedKeyPair(address) {
2759
2766
  if (typeof window === "undefined") {
2760
2767
  return;
2761
2768
  }
2762
- const storageKey = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2763
- localStorage.removeItem(storageKey);
2769
+ const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2770
+ localStorage.removeItem(storageKey2);
2764
2771
  }
2765
2772
  async function getKeyPair(address, signMessage, embeddedWalletSigner) {
2766
2773
  const existingKeyPair = getStoredKeyPair(address);
@@ -19547,11 +19554,11 @@ function loadVaultCorpus(ctx, options, preparation) {
19547
19554
  }
19548
19555
  return request;
19549
19556
  }
19550
- function rowRequestsFor(registry2, ctx, maskInput) {
19551
- let byMask = registry2.get(ctx);
19557
+ function rowRequestsFor(registry3, ctx, maskInput) {
19558
+ let byMask = registry3.get(ctx);
19552
19559
  if (!byMask) {
19553
19560
  byMask = /* @__PURE__ */ new Map();
19554
- registry2.set(ctx, byMask);
19561
+ registry3.set(ctx, byMask);
19555
19562
  }
19556
19563
  let requests = byMask.get(maskInput);
19557
19564
  if (!requests) {
@@ -20486,11 +20493,11 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
20486
20493
  };
20487
20494
  }
20488
20495
  const limit = searchOptions?.limit ?? 5;
20489
- const scopes = searchOptions?.scopes;
20496
+ const scopes2 = searchOptions?.scopes;
20490
20497
  const folderId = searchOptions?.folderId;
20491
20498
  const queryOpts = {};
20492
20499
  if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
20493
- if (scopes?.length) queryOpts.scopes = scopes;
20500
+ if (scopes2?.length) queryOpts.scopes = scopes2;
20494
20501
  if (folderId !== void 0) queryOpts.folderId = folderId;
20495
20502
  if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
20496
20503
  if (searchOptions?.includeArchived) queryOpts.includeArchived = true;
@@ -26776,17 +26783,17 @@ async function synthesizeProfile(ctx, options = {}) {
26776
26783
  }
26777
26784
  const recallCtx = store ? { embeddingOptions: ctx.embeddingOptions, factSource: store.factSource } : ctx;
26778
26785
  const facets = options.facets ?? DEFAULT_PROFILE_FACETS;
26779
- const scopes = options.scopes ?? DEFAULT_SCOPES;
26786
+ const scopes2 = options.scopes ?? DEFAULT_SCOPES;
26780
26787
  const config = {
26781
26788
  facetKeys: facets.map((f) => f.key).sort(),
26782
26789
  facetsSignature: facetsSignature(facets),
26783
- scopes: [...scopes].sort(),
26790
+ scopes: [...scopes2].sort(),
26784
26791
  redacted: options.redactor !== void 0,
26785
26792
  reviewedMemoryIdsSignature: reviewedMemoryIdsSignature(options.reviewedMemoryIds)
26786
26793
  };
26787
26794
  const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
26788
- const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
26789
- const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
26795
+ const listOptions = { scopes: scopes2, includeDeleted: true, includeSuperseded: true };
26796
+ const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes: scopes2 }), []];
26790
26797
  const watermark = computeVaultWatermark(memories);
26791
26798
  const observationTrends = summarizeObservationTrends(
26792
26799
  memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
@@ -26831,7 +26838,7 @@ async function synthesizeProfile(ctx, options = {}) {
26831
26838
  for (const section of previous.sections) {
26832
26839
  if (section.sourceMemoryIds.length > 0 && section.sourceMemoryIds.every((id2) => {
26833
26840
  const memory = memoriesById.get(id2);
26834
- return memory && !memory.isDeleted && !memory.supersededBy && scopes.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
26841
+ return memory && !memory.isDeleted && !memory.supersededBy && scopes2.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
26835
26842
  })) {
26836
26843
  fallbackPriors.set(section.key, section);
26837
26844
  }
@@ -27004,7 +27011,7 @@ async function attributeFacts(ctx, candidates, facets) {
27004
27011
  return keys;
27005
27012
  }
27006
27013
  async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
27007
- const scopes = options.scopes ?? DEFAULT_SCOPES;
27014
+ const scopes2 = options.scopes ?? DEFAULT_SCOPES;
27008
27015
  const limit = options.limit ?? DEFAULT_FACET_RECALL_LIMIT;
27009
27016
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
27010
27017
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
@@ -27021,7 +27028,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
27021
27028
  }
27022
27029
  const recalled = await recall(facet.query, ctx, {
27023
27030
  vaultPreparation,
27024
- scopes,
27031
+ scopes: scopes2,
27025
27032
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
27026
27033
  ...hasReviewGate && { memoryIds: [...reviewed] },
27027
27034
  types: ["fact"],
@@ -27048,7 +27055,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
27048
27055
  llmModel: options.llmModel ?? DEFAULT_SYNTHESIS_MODEL,
27049
27056
  baseUrl: options.baseUrl,
27050
27057
  fetchFn: options.fetchFn,
27051
- scopes,
27058
+ scopes: scopes2,
27052
27059
  limit,
27053
27060
  types: ["fact"],
27054
27061
  maxTokens: DEFAULT_FACET_MAX_TOKENS,
@@ -30819,7 +30826,7 @@ function useChat(options) {
30819
30826
  }
30820
30827
 
30821
30828
  // src/expo/useChatStorage.ts
30822
- var import_react5 = require("react");
30829
+ var import_react6 = require("react");
30823
30830
  var import_uuid8 = require("uuid");
30824
30831
  init_clientConfig();
30825
30832
 
@@ -31615,6 +31622,107 @@ async function deleteMediaByConversationOp(ctx, conversationId) {
31615
31622
  init_logger();
31616
31623
  init_redactor();
31617
31624
 
31625
+ // src/lib/pii/useConversationRedactors.ts
31626
+ var import_react5 = require("react");
31627
+ init_redactor();
31628
+ var REDACTOR_LIMIT = 50;
31629
+ var registry2 = /* @__PURE__ */ new WeakMap();
31630
+ var compositeKeys = /* @__PURE__ */ new WeakMap();
31631
+ var scopes = /* @__PURE__ */ new Set();
31632
+ var retiredRedactor = new PiiRedactor();
31633
+ retiredRedactor.dispose();
31634
+ function retireScope(scope) {
31635
+ scopes.delete(scope);
31636
+ if (!scope.active) return;
31637
+ scope.active = false;
31638
+ for (const { redactor } of scope.redactors.values()) redactor.dispose();
31639
+ scope.redactors.clear();
31640
+ for (const redactor of scope.evicted) redactor.dispose();
31641
+ scope.evicted = [];
31642
+ for (const notify of scope.subscribers) notify();
31643
+ }
31644
+ function storageKey(storage, secondaryStorage) {
31645
+ if (!secondaryStorage) return storage;
31646
+ let inner = compositeKeys.get(storage);
31647
+ if (!inner) {
31648
+ inner = /* @__PURE__ */ new WeakMap();
31649
+ compositeKeys.set(storage, inner);
31650
+ }
31651
+ let key3 = inner.get(secondaryStorage);
31652
+ if (!key3) {
31653
+ key3 = {};
31654
+ inner.set(secondaryStorage, key3);
31655
+ }
31656
+ return key3;
31657
+ }
31658
+ function getScope(database, storage, account) {
31659
+ let stores = registry2.get(database);
31660
+ if (!stores) {
31661
+ stores = /* @__PURE__ */ new WeakMap();
31662
+ registry2.set(database, stores);
31663
+ }
31664
+ let accounts = stores.get(storage);
31665
+ if (!accounts) {
31666
+ accounts = /* @__PURE__ */ new Map();
31667
+ stores.set(storage, accounts);
31668
+ }
31669
+ let scope = accounts.get(account);
31670
+ if (!scope?.active) {
31671
+ scope = { active: true, users: 0, subscribers: /* @__PURE__ */ new Set(), redactors: /* @__PURE__ */ new Map(), evicted: [] };
31672
+ accounts.set(account, scope);
31673
+ }
31674
+ return scope;
31675
+ }
31676
+ onClearAllEncryptionState(() => {
31677
+ registry2 = /* @__PURE__ */ new WeakMap();
31678
+ for (const scope of [...scopes]) retireScope(scope);
31679
+ });
31680
+ function useConversationRedactors(database, account, storage, secondaryStorage) {
31681
+ const scope = getScope(database, storageKey(storage, secondaryStorage), account);
31682
+ const subscribe = (0, import_react5.useCallback)(
31683
+ (callback) => {
31684
+ scope.subscribers.add(callback);
31685
+ return () => {
31686
+ scope.subscribers.delete(callback);
31687
+ };
31688
+ },
31689
+ [scope]
31690
+ );
31691
+ const getSnapshot = (0, import_react5.useCallback)(() => scope.active ? scope : null, [scope]);
31692
+ (0, import_react5.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
31693
+ (0, import_react5.useEffect)(() => {
31694
+ if (scope.active) scopes.add(scope);
31695
+ scope.users++;
31696
+ return () => {
31697
+ scope.users--;
31698
+ if (scope.users === 0) retireScope(scope);
31699
+ };
31700
+ }, [scope]);
31701
+ return (0, import_react5.useCallback)(
31702
+ (conversationId, nerDetector) => {
31703
+ if (!scope.active) return retiredRedactor;
31704
+ const cached = scope.redactors.get(conversationId);
31705
+ if (cached && cached.detector === nerDetector) {
31706
+ scope.redactors.delete(conversationId);
31707
+ scope.redactors.set(conversationId, cached);
31708
+ return cached.redactor;
31709
+ }
31710
+ if (cached) scope.evicted.push(cached.redactor);
31711
+ const redactor = new PiiRedactor({ nerDetector });
31712
+ scope.redactors.set(conversationId, { redactor, detector: nerDetector });
31713
+ if (scope.redactors.size > REDACTOR_LIMIT) {
31714
+ const oldest = scope.redactors.entries().next().value;
31715
+ if (oldest) {
31716
+ scope.evicted.push(oldest[1].redactor);
31717
+ scope.redactors.delete(oldest[0]);
31718
+ }
31719
+ }
31720
+ return redactor;
31721
+ },
31722
+ [scope]
31723
+ );
31724
+ }
31725
+
31618
31726
  // src/lib/tools/selection/activeToolSets.ts
31619
31727
  function mergeActiveToolSets(current, derived) {
31620
31728
  if (derived.length === 0) return current;
@@ -31675,30 +31783,11 @@ function resetRecentToolSets() {
31675
31783
  onClearAllEncryptionState(resetRecentToolSets);
31676
31784
 
31677
31785
  // src/expo/useChatStorage.ts
31678
- var CONVERSATION_REDACTOR_LIMIT = 50;
31679
- var NO_CONVERSATION_KEY = "__no_conversation__";
31680
31786
  var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
31681
31787
  var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
31682
31788
  var MEMORY_STORE_NOT_READY = "Memory store is not ready";
31683
- var conversationRedactors = /* @__PURE__ */ new Map();
31684
31789
  var queuedBackends = /* @__PURE__ */ new WeakMap();
31685
31790
  var clientToolFilterCache = /* @__PURE__ */ new Map();
31686
- function getConversationRedactor(conversationId, nerDetector) {
31687
- const key3 = conversationId ?? NO_CONVERSATION_KEY;
31688
- const cached = conversationRedactors.get(key3);
31689
- if (cached && cached.detector === nerDetector) {
31690
- conversationRedactors.delete(key3);
31691
- conversationRedactors.set(key3, cached);
31692
- return cached.redactor;
31693
- }
31694
- const redactor = new PiiRedactor({ nerDetector });
31695
- conversationRedactors.set(key3, { redactor, detector: nerDetector });
31696
- if (conversationRedactors.size > CONVERSATION_REDACTOR_LIMIT) {
31697
- const oldest = conversationRedactors.keys().next().value;
31698
- if (oldest !== void 0) conversationRedactors.delete(oldest);
31699
- }
31700
- return redactor;
31701
- }
31702
31791
  function resolveCallPii(requestPiiRedaction, hookPiiRedaction, getConversationRedactorFor) {
31703
31792
  const effective = requestPiiRedaction === void 0 ? hookPiiRedaction : requestPiiRedaction;
31704
31793
  const redactor = effective === true ? getConversationRedactorFor() : isPiiRedactor(effective) ? effective : void 0;
@@ -31808,31 +31897,37 @@ function useChatStorage(options) {
31808
31897
  toolResultsHistoryExclude,
31809
31898
  foldToolResultsInHistory
31810
31899
  } = options;
31811
- const [currentConversationId, setCurrentConversationId] = (0, import_react5.useState)(
31900
+ const [currentConversationId, setCurrentConversationId] = (0, import_react6.useState)(
31812
31901
  initialConversationId || null
31813
31902
  );
31814
- const toolResultsHistoryExcludeRef = (0, import_react5.useRef)(toolResultsHistoryExclude);
31903
+ const toolResultsHistoryExcludeRef = (0, import_react6.useRef)(toolResultsHistoryExclude);
31815
31904
  toolResultsHistoryExcludeRef.current = toolResultsHistoryExclude;
31816
- const foldToolResultsInHistoryRef = (0, import_react5.useRef)(foldToolResultsInHistory);
31905
+ const foldToolResultsInHistoryRef = (0, import_react6.useRef)(foldToolResultsInHistory);
31817
31906
  foldToolResultsInHistoryRef.current = foldToolResultsInHistory;
31818
- const nerDetectorRef = (0, import_react5.useRef)(nerDetector);
31907
+ const nerDetectorRef = (0, import_react6.useRef)(nerDetector);
31819
31908
  nerDetectorRef.current = nerDetector;
31820
- const resolvedPiiRedaction = (0, import_react5.useMemo)(
31909
+ const getConversationRedactor = useConversationRedactors(
31910
+ database,
31911
+ walletAddress,
31912
+ memoryStore ?? chatBackend ?? database,
31913
+ memoryStore && chatBackend ? chatBackend : void 0
31914
+ );
31915
+ const resolvedPiiRedaction = (0, import_react6.useMemo)(
31821
31916
  () => piiRedaction === true ? getConversationRedactor(currentConversationId, nerDetectorRef.current) : piiRedaction,
31822
- [piiRedaction, currentConversationId]
31917
+ [piiRedaction, currentConversationId, getConversationRedactor]
31823
31918
  );
31824
- const maskForEmbedding = (0, import_react5.useCallback)(
31919
+ const maskForEmbedding = (0, import_react6.useCallback)(
31825
31920
  (text16) => isPiiRedactor(resolvedPiiRedaction) ? resolvedPiiRedaction.maskText(text16) : text16,
31826
31921
  [resolvedPiiRedaction]
31827
31922
  );
31828
31923
  const maskEmbeddingInput = isPiiRedactor(resolvedPiiRedaction) ? maskForEmbedding : void 0;
31829
31924
  const storeMaskMissing = memoryStore !== void 0 && memoryStore !== null && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
31830
- const messagesCollection = (0, import_react5.useMemo)(() => database.get("history"), [database]);
31831
- const conversationsCollection = (0, import_react5.useMemo)(
31925
+ const messagesCollection = (0, import_react6.useMemo)(() => database.get("history"), [database]);
31926
+ const conversationsCollection = (0, import_react6.useMemo)(
31832
31927
  () => database.get("conversations"),
31833
31928
  [database]
31834
31929
  );
31835
- const storageCtx = (0, import_react5.useMemo)(
31930
+ const storageCtx = (0, import_react6.useMemo)(
31836
31931
  () => ({
31837
31932
  database,
31838
31933
  messagesCollection,
@@ -31850,23 +31945,23 @@ function useChatStorage(options) {
31850
31945
  embeddedWalletSigner
31851
31946
  ]
31852
31947
  );
31853
- const storageCtxRef = (0, import_react5.useRef)(storageCtx);
31948
+ const storageCtxRef = (0, import_react6.useRef)(storageCtx);
31854
31949
  storageCtxRef.current = storageCtx;
31855
- const backendFactory = (0, import_react5.useMemo)(
31950
+ const backendFactory = (0, import_react6.useMemo)(
31856
31951
  () => chatBackend ?? localChatBackend(database),
31857
31952
  [chatBackend, database]
31858
31953
  );
31859
- const backend = (0, import_react5.useMemo)(
31954
+ const backend = (0, import_react6.useMemo)(
31860
31955
  () => backendFactory({ walletAddress, signMessage, embeddedWalletSigner }),
31861
31956
  [backendFactory, walletAddress, signMessage, embeddedWalletSigner]
31862
31957
  );
31863
- const backendRef = (0, import_react5.useRef)(backend);
31958
+ const backendRef = (0, import_react6.useRef)(backend);
31864
31959
  backendRef.current = backend;
31865
- const vaultMemoryCollection = (0, import_react5.useMemo)(
31960
+ const vaultMemoryCollection = (0, import_react6.useMemo)(
31866
31961
  () => database.get("memory_vault"),
31867
31962
  [database]
31868
31963
  );
31869
- const vaultCtx = (0, import_react5.useMemo)(
31964
+ const vaultCtx = (0, import_react6.useMemo)(
31870
31965
  () => ({
31871
31966
  database,
31872
31967
  vaultMemoryCollection,
@@ -31877,18 +31972,18 @@ function useChatStorage(options) {
31877
31972
  }),
31878
31973
  [database, vaultMemoryCollection, walletAddress, signMessage, embeddedWalletSigner]
31879
31974
  );
31880
- const [queueStatus, setQueueStatus] = (0, import_react5.useState)({
31975
+ const [queueStatus, setQueueStatus] = (0, import_react6.useState)({
31881
31976
  pending: 0,
31882
31977
  failed: 0,
31883
31978
  isFlushing: false,
31884
31979
  isPaused: false
31885
31980
  });
31886
- const refreshQueueStatus = (0, import_react5.useCallback)(() => {
31981
+ const refreshQueueStatus = (0, import_react6.useCallback)(() => {
31887
31982
  if (walletAddress) {
31888
31983
  setQueueStatus(queueManager.getStatus(walletAddress));
31889
31984
  }
31890
31985
  }, [walletAddress]);
31891
- const executeQueuedOperation = (0, import_react5.useCallback)(
31986
+ const executeQueuedOperation = (0, import_react6.useCallback)(
31892
31987
  async (operation, encCtx) => {
31893
31988
  const queued = queuedBackends.get(operation.payload) ?? backendFactory({
31894
31989
  walletAddress: encCtx.walletAddress,
@@ -31933,7 +32028,7 @@ function useChatStorage(options) {
31933
32028
  },
31934
32029
  [backendFactory, database]
31935
32030
  );
31936
- const flushQueue = (0, import_react5.useCallback)(async () => {
32031
+ const flushQueue = (0, import_react6.useCallback)(async () => {
31937
32032
  if (!walletAddress || !signMessage) {
31938
32033
  return { succeeded: [], failed: [], total: 0 };
31939
32034
  }
@@ -31952,26 +32047,26 @@ function useChatStorage(options) {
31952
32047
  executeQueuedOperation,
31953
32048
  refreshQueueStatus
31954
32049
  ]);
31955
- const clearQueue = (0, import_react5.useCallback)(() => {
32050
+ const clearQueue = (0, import_react6.useCallback)(() => {
31956
32051
  if (walletAddress) {
31957
32052
  queueManager.clear(walletAddress);
31958
32053
  refreshQueueStatus();
31959
32054
  }
31960
32055
  }, [walletAddress, refreshQueueStatus]);
31961
- (0, import_react5.useEffect)(() => {
32056
+ (0, import_react6.useEffect)(() => {
31962
32057
  if (!walletAddress) return;
31963
32058
  refreshQueueStatus();
31964
32059
  return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
31965
32060
  }, [walletAddress, refreshQueueStatus]);
31966
- (0, import_react5.useEffect)(() => {
32061
+ (0, import_react6.useEffect)(() => {
31967
32062
  if (!getWalletAddress || walletAddress) return;
31968
32063
  const poller = new WalletPoller();
31969
32064
  return poller.startPolling(getWalletAddress, () => {
31970
32065
  });
31971
32066
  }, [getWalletAddress, walletAddress]);
31972
- const pendingOpsRef = (0, import_react5.useRef)([]);
31973
- const syntheticConvIdsRef = (0, import_react5.useRef)(/* @__PURE__ */ new Set());
31974
- (0, import_react5.useEffect)(() => {
32067
+ const pendingOpsRef = (0, import_react6.useRef)([]);
32068
+ const syntheticConvIdsRef = (0, import_react6.useRef)(/* @__PURE__ */ new Set());
32069
+ (0, import_react6.useEffect)(() => {
31975
32070
  if (!walletAddress || !enableQueue) return;
31976
32071
  const pending = pendingOpsRef.current;
31977
32072
  if (pending.length === 0) return;
@@ -31982,7 +32077,7 @@ function useChatStorage(options) {
31982
32077
  pendingOpsRef.current = [];
31983
32078
  refreshQueueStatus();
31984
32079
  }, [walletAddress, enableQueue, refreshQueueStatus]);
31985
- (0, import_react5.useEffect)(() => {
32080
+ (0, import_react6.useEffect)(() => {
31986
32081
  if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
31987
32082
  return onKeyAvailable(walletAddress, () => {
31988
32083
  flushQueue().catch((err) => {
@@ -31990,7 +32085,7 @@ function useChatStorage(options) {
31990
32085
  });
31991
32086
  });
31992
32087
  }, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
31993
- const writeOrQueue = (0, import_react5.useCallback)(
32088
+ const writeOrQueue = (0, import_react6.useCallback)(
31994
32089
  async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
31995
32090
  const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
31996
32091
  const currentBackend = storageCtx.walletAddress ? backend : backendRef.current;
@@ -32028,7 +32123,7 @@ function useChatStorage(options) {
32028
32123
  },
32029
32124
  [storageCtx, backend, enableQueue, signMessage, getWalletAddress]
32030
32125
  );
32031
- const embedMessageAsync = (0, import_react5.useCallback)(
32126
+ const embedMessageAsync = (0, import_react6.useCallback)(
32032
32127
  async (message, mask = maskForEmbedding) => {
32033
32128
  if (!autoEmbedMessages || !getToken) return;
32034
32129
  if (message.content.length < minContentLength) return;
@@ -32065,7 +32160,7 @@ function useChatStorage(options) {
32065
32160
  maskForEmbedding
32066
32161
  ]
32067
32162
  );
32068
- const createMemoryEngineTool2 = (0, import_react5.useCallback)(
32163
+ const createMemoryEngineTool2 = (0, import_react6.useCallback)(
32069
32164
  (searchOptions) => {
32070
32165
  if (!getToken) {
32071
32166
  throw new Error("getToken is required for memory engine tool");
@@ -32078,18 +32173,18 @@ function useChatStorage(options) {
32078
32173
  },
32079
32174
  [backend, getToken, baseUrl, embeddingModel, maskEmbeddingInput]
32080
32175
  );
32081
- const vaultEmbeddingCache = (0, import_react5.useMemo)(
32176
+ const vaultEmbeddingCache = (0, import_react6.useMemo)(
32082
32177
  () => getVaultEmbeddingCache(database, walletAddress, embeddingModel),
32083
32178
  [database, walletAddress, embeddingModel]
32084
32179
  );
32085
- const chunkVectorCacheRef = (0, import_react5.useRef)(createChunkVectorCache());
32086
- (0, import_react5.useEffect)(() => {
32180
+ const chunkVectorCacheRef = (0, import_react6.useRef)(createChunkVectorCache());
32181
+ (0, import_react6.useEffect)(() => {
32087
32182
  return onClearAllEncryptionState(() => {
32088
32183
  vaultEmbeddingCache.clear();
32089
32184
  chunkVectorCacheRef.current.clear();
32090
32185
  });
32091
32186
  }, [vaultEmbeddingCache]);
32092
- const retainVaultMemory = (0, import_react5.useCallback)(
32187
+ const retainVaultMemory = (0, import_react6.useCallback)(
32093
32188
  async (input) => {
32094
32189
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
32095
32190
  if (memoryStore) {
@@ -32135,7 +32230,7 @@ function useChatStorage(options) {
32135
32230
  storeMaskMissing
32136
32231
  ]
32137
32232
  );
32138
- const createMemoryVaultTool2 = (0, import_react5.useCallback)(
32233
+ const createMemoryVaultTool2 = (0, import_react6.useCallback)(
32139
32234
  (options2) => {
32140
32235
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
32141
32236
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -32146,7 +32241,7 @@ function useChatStorage(options) {
32146
32241
  },
32147
32242
  [vaultCtx, getToken, retainVaultMemory, memoryStore, storeMaskMissing]
32148
32243
  );
32149
- const createRecallTool2 = (0, import_react5.useCallback)(
32244
+ const createRecallTool2 = (0, import_react6.useCallback)(
32150
32245
  (toolOptions, callbacks) => {
32151
32246
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
32152
32247
  if (!getToken && !memoryStore) {
@@ -32192,7 +32287,7 @@ function useChatStorage(options) {
32192
32287
  storeMaskMissing
32193
32288
  ]
32194
32289
  );
32195
- const recallFn = (0, import_react5.useCallback)(
32290
+ const recallFn = (0, import_react6.useCallback)(
32196
32291
  async (query, options2) => {
32197
32292
  if (memoryStore === null || !getToken && !memoryStore) {
32198
32293
  return {
@@ -32241,7 +32336,7 @@ function useChatStorage(options) {
32241
32336
  storeMaskMissing
32242
32337
  ]
32243
32338
  );
32244
- const getVaultMemories = (0, import_react5.useCallback)(
32339
+ const getVaultMemories = (0, import_react6.useCallback)(
32245
32340
  (options2) => {
32246
32341
  if (memoryStore === null) return Promise.resolve([]);
32247
32342
  if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
@@ -32253,7 +32348,7 @@ function useChatStorage(options) {
32253
32348
  },
32254
32349
  [vaultCtx, memoryStore]
32255
32350
  );
32256
- const deleteVaultMemory = (0, import_react5.useCallback)(
32351
+ const deleteVaultMemory = (0, import_react6.useCallback)(
32257
32352
  async (id2) => {
32258
32353
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
32259
32354
  return memoryStore ? memoryStore.delete(id2) : deleteVaultMemoryOp(vaultCtx, id2);
@@ -32286,12 +32381,12 @@ function useChatStorage(options) {
32286
32381
  onServerToolCall,
32287
32382
  onToolCallArgumentsDelta
32288
32383
  });
32289
- const pendingResumeRef = (0, import_react5.useRef)(null);
32290
- const isResumingRef = (0, import_react5.useRef)(false);
32291
- const activeResumeRef = (0, import_react5.useRef)(null);
32292
- const retirementRef = (0, import_react5.useRef)(null);
32293
- const retirementStopRequestedRef = (0, import_react5.useRef)(false);
32294
- const createConversation = (0, import_react5.useCallback)(
32384
+ const pendingResumeRef = (0, import_react6.useRef)(null);
32385
+ const isResumingRef = (0, import_react6.useRef)(false);
32386
+ const activeResumeRef = (0, import_react6.useRef)(null);
32387
+ const retirementRef = (0, import_react6.useRef)(null);
32388
+ const retirementStopRequestedRef = (0, import_react6.useRef)(false);
32389
+ const createConversation = (0, import_react6.useCallback)(
32295
32390
  async (opts) => {
32296
32391
  const conversationOpts = {
32297
32392
  ...opts,
@@ -32311,16 +32406,16 @@ function useChatStorage(options) {
32311
32406
  },
32312
32407
  [defaultConversationTitle, writeOrQueue]
32313
32408
  );
32314
- const getConversation = (0, import_react5.useCallback)(
32409
+ const getConversation = (0, import_react6.useCallback)(
32315
32410
  async (id2) => {
32316
32411
  return backend.getConversation(id2);
32317
32412
  },
32318
32413
  [backend]
32319
32414
  );
32320
- const getConversations = (0, import_react5.useCallback)(async () => {
32415
+ const getConversations = (0, import_react6.useCallback)(async () => {
32321
32416
  return backend.getConversations();
32322
32417
  }, [backend]);
32323
- const updateConversationTitle = (0, import_react5.useCallback)(
32418
+ const updateConversationTitle = (0, import_react6.useCallback)(
32324
32419
  async (id2, title) => {
32325
32420
  const { result } = await writeOrQueue(
32326
32421
  "updateConversationTitle",
@@ -32332,7 +32427,7 @@ function useChatStorage(options) {
32332
32427
  },
32333
32428
  [writeOrQueue]
32334
32429
  );
32335
- const updateConversationPinned = (0, import_react5.useCallback)(
32430
+ const updateConversationPinned = (0, import_react6.useCallback)(
32336
32431
  async (id2, pinned) => {
32337
32432
  const { result } = await writeOrQueue(
32338
32433
  "updateConversationPinned",
@@ -32344,7 +32439,7 @@ function useChatStorage(options) {
32344
32439
  },
32345
32440
  [writeOrQueue]
32346
32441
  );
32347
- const deleteConversation = (0, import_react5.useCallback)(
32442
+ const deleteConversation = (0, import_react6.useCallback)(
32348
32443
  async (id2) => {
32349
32444
  const deleted = await backend.deleteConversation(id2);
32350
32445
  if (deleted) {
@@ -32362,31 +32457,31 @@ function useChatStorage(options) {
32362
32457
  },
32363
32458
  [backend, database, walletAddress, signMessage, embeddedWalletSigner, currentConversationId]
32364
32459
  );
32365
- const getMessages = (0, import_react5.useCallback)(
32460
+ const getMessages = (0, import_react6.useCallback)(
32366
32461
  async (convId) => {
32367
32462
  return backend.getMessages(convId);
32368
32463
  },
32369
32464
  [backend]
32370
32465
  );
32371
- const getMessagesPage = (0, import_react5.useCallback)(
32466
+ const getMessagesPage = (0, import_react6.useCallback)(
32372
32467
  async (convId, options2) => {
32373
32468
  return backend.getMessagesPage(convId, options2);
32374
32469
  },
32375
32470
  [backend]
32376
32471
  );
32377
- const getMessageSkeletons = (0, import_react5.useCallback)(
32472
+ const getMessageSkeletons = (0, import_react6.useCallback)(
32378
32473
  (convId) => {
32379
32474
  return backend.getMessageSkeletons(convId);
32380
32475
  },
32381
32476
  [backend]
32382
32477
  );
32383
- const getMessageCount = (0, import_react5.useCallback)(
32478
+ const getMessageCount = (0, import_react6.useCallback)(
32384
32479
  (convId) => {
32385
32480
  return backend.getMessageCount(convId);
32386
32481
  },
32387
32482
  [backend]
32388
32483
  );
32389
- const extractSourcesFromAssistantMessage = (0, import_react5.useCallback)(
32484
+ const extractSourcesFromAssistantMessage = (0, import_react6.useCallback)(
32390
32485
  (assistantMessage) => {
32391
32486
  try {
32392
32487
  const extractedSources = [];
@@ -32468,7 +32563,7 @@ function useChatStorage(options) {
32468
32563
  },
32469
32564
  []
32470
32565
  );
32471
- const ensureConversation = (0, import_react5.useCallback)(async () => {
32566
+ const ensureConversation = (0, import_react6.useCallback)(async () => {
32472
32567
  if (currentConversationId) {
32473
32568
  if (syntheticConvIdsRef.current.has(currentConversationId)) {
32474
32569
  return currentConversationId;
@@ -32490,11 +32585,11 @@ function useChatStorage(options) {
32490
32585
  }
32491
32586
  throw new Error("No conversation ID provided and autoCreateConversation is disabled");
32492
32587
  }, [currentConversationId, getConversation, autoCreateConversation, createConversation]);
32493
- const activeToolSetsRef = (0, import_react5.useRef)(activeToolSets);
32588
+ const activeToolSetsRef = (0, import_react6.useRef)(activeToolSets);
32494
32589
  activeToolSetsRef.current = activeToolSets;
32495
- const getTokenRef = (0, import_react5.useRef)(getToken);
32590
+ const getTokenRef = (0, import_react6.useRef)(getToken);
32496
32591
  getTokenRef.current = getToken;
32497
- const finalizeResumedRow = (0, import_react5.useCallback)(
32592
+ const finalizeResumedRow = (0, import_react6.useCallback)(
32498
32593
  async (ctx, data, wasStopped, responseDuration, viaQueue = false) => {
32499
32594
  const { content, thinking } = extractAssistantText(data);
32500
32595
  let parentMessageId = ctx.userMessageUniqueId;
@@ -32568,7 +32663,7 @@ function useChatStorage(options) {
32568
32663
  },
32569
32664
  [backend, getMessages, writeOrQueue]
32570
32665
  );
32571
- const retirePendingTurn = (0, import_react5.useCallback)(async () => {
32666
+ const retirePendingTurn = (0, import_react6.useCallback)(async () => {
32572
32667
  const visible = activeResumeRef.current;
32573
32668
  if (visible && !visible.headless) {
32574
32669
  baseStop();
@@ -32631,7 +32726,7 @@ function useChatStorage(options) {
32631
32726
  }
32632
32727
  }
32633
32728
  }, [baseCancel, baseStop, finalizeResumedRow, walletAddress, signMessage, embeddedWalletSigner]);
32634
- const sendMessage = (0, import_react5.useCallback)(
32729
+ const sendMessage = (0, import_react6.useCallback)(
32635
32730
  async (args) => {
32636
32731
  const {
32637
32732
  messages,
@@ -33435,6 +33530,8 @@ function useChatStorage(options) {
33435
33530
  getMessages,
33436
33531
  backend,
33437
33532
  baseSendMessage,
33533
+ getConversationRedactor,
33534
+ piiRedaction,
33438
33535
  retirePendingTurn,
33439
33536
  embedMessageAsync,
33440
33537
  minContentLength,
@@ -33449,7 +33546,7 @@ function useChatStorage(options) {
33449
33546
  onPiiRedacted
33450
33547
  ]
33451
33548
  );
33452
- const resumeStream2 = (0, import_react5.useCallback)(
33549
+ const resumeStream2 = (0, import_react6.useCallback)(
33453
33550
  async (handleOverride, opts) => {
33454
33551
  if (isResumingRef.current || retirementRef.current) {
33455
33552
  return { data: null, error: "Resume already in progress", assistantMessage: null };
@@ -33579,7 +33676,7 @@ function useChatStorage(options) {
33579
33676
  },
33580
33677
  [baseResumeStream, currentConversationId, finalizeResumedRow, embedMessageAsync]
33581
33678
  );
33582
- const stop = (0, import_react5.useCallback)(() => {
33679
+ const stop = (0, import_react6.useCallback)(() => {
33583
33680
  if (retirementRef.current) {
33584
33681
  retirementStopRequestedRef.current = true;
33585
33682
  return;