@anuma/sdk 10.2.2 → 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
  });
@@ -2498,12 +2505,12 @@ async function persistKeyPair(address, startEpoch) {
2498
2505
  const combined = new Uint8Array(iv.length + encryptedBytes.length);
2499
2506
  combined.set(iv, 0);
2500
2507
  combined.set(encryptedBytes, iv.length);
2501
- const storageKey = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2508
+ const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2502
2509
  const encryptedHex = bytesToHex(combined);
2503
2510
  if (sessionEpoch !== startEpoch) {
2504
2511
  return;
2505
2512
  }
2506
- localStorage.setItem(storageKey, encryptedHex);
2513
+ localStorage.setItem(storageKey2, encryptedHex);
2507
2514
  } catch (err) {
2508
2515
  throw new Error(
2509
2516
  `Failed to persist keypair: ${err instanceof Error ? err.message : String(err)}`
@@ -2514,8 +2521,8 @@ async function loadPersistedKeyPair(address) {
2514
2521
  if (typeof window === "undefined") {
2515
2522
  return null;
2516
2523
  }
2517
- const storageKey = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2518
- const encryptedHex = localStorage.getItem(storageKey);
2524
+ const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2525
+ const encryptedHex = localStorage.getItem(storageKey2);
2519
2526
  if (!encryptedHex) {
2520
2527
  return null;
2521
2528
  }
@@ -2566,7 +2573,7 @@ async function loadPersistedKeyPair(address) {
2566
2573
  publicKey
2567
2574
  };
2568
2575
  } catch (error) {
2569
- localStorage.removeItem(storageKey);
2576
+ localStorage.removeItem(storageKey2);
2570
2577
  getLogger().warn(
2571
2578
  `Failed to load persisted keypair for ${address}: ${error instanceof Error ? error.message : String(error)}`
2572
2579
  );
@@ -2577,8 +2584,8 @@ function clearPersistedKeyPair(address) {
2577
2584
  if (typeof window === "undefined") {
2578
2585
  return;
2579
2586
  }
2580
- const storageKey = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2581
- localStorage.removeItem(storageKey);
2587
+ const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
2588
+ localStorage.removeItem(storageKey2);
2582
2589
  }
2583
2590
  async function getKeyPair(address, signMessage, embeddedWalletSigner) {
2584
2591
  const existingKeyPair = getStoredKeyPair(address);
@@ -21851,11 +21858,11 @@ function loadVaultCorpus(ctx, options, preparation) {
21851
21858
  }
21852
21859
  return request;
21853
21860
  }
21854
- function rowRequestsFor(registry2, ctx, maskInput) {
21855
- let byMask = registry2.get(ctx);
21861
+ function rowRequestsFor(registry3, ctx, maskInput) {
21862
+ let byMask = registry3.get(ctx);
21856
21863
  if (!byMask) {
21857
21864
  byMask = /* @__PURE__ */ new Map();
21858
- registry2.set(ctx, byMask);
21865
+ registry3.set(ctx, byMask);
21859
21866
  }
21860
21867
  let requests = byMask.get(maskInput);
21861
21868
  if (!requests) {
@@ -22790,11 +22797,11 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
22790
22797
  };
22791
22798
  }
22792
22799
  const limit = searchOptions?.limit ?? 5;
22793
- const scopes = searchOptions?.scopes;
22800
+ const scopes2 = searchOptions?.scopes;
22794
22801
  const folderId = searchOptions?.folderId;
22795
22802
  const queryOpts = {};
22796
22803
  if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
22797
- if (scopes?.length) queryOpts.scopes = scopes;
22804
+ if (scopes2?.length) queryOpts.scopes = scopes2;
22798
22805
  if (folderId !== void 0) queryOpts.folderId = folderId;
22799
22806
  if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
22800
22807
  if (searchOptions?.includeArchived) queryOpts.includeArchived = true;
@@ -29106,17 +29113,17 @@ async function synthesizeProfile(ctx, options = {}) {
29106
29113
  }
29107
29114
  const recallCtx = store ? { embeddingOptions: ctx.embeddingOptions, factSource: store.factSource } : ctx;
29108
29115
  const facets = options.facets ?? DEFAULT_PROFILE_FACETS;
29109
- const scopes = options.scopes ?? DEFAULT_SCOPES;
29116
+ const scopes2 = options.scopes ?? DEFAULT_SCOPES;
29110
29117
  const config = {
29111
29118
  facetKeys: facets.map((f) => f.key).sort(),
29112
29119
  facetsSignature: facetsSignature(facets),
29113
- scopes: [...scopes].sort(),
29120
+ scopes: [...scopes2].sort(),
29114
29121
  redacted: options.redactor !== void 0,
29115
29122
  reviewedMemoryIdsSignature: reviewedMemoryIdsSignature(options.reviewedMemoryIds)
29116
29123
  };
29117
29124
  const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
29118
- const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
29119
- const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
29125
+ const listOptions = { scopes: scopes2, includeDeleted: true, includeSuperseded: true };
29126
+ const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes: scopes2 }), []];
29120
29127
  const watermark = computeVaultWatermark(memories);
29121
29128
  const observationTrends = summarizeObservationTrends(
29122
29129
  memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
@@ -29161,7 +29168,7 @@ async function synthesizeProfile(ctx, options = {}) {
29161
29168
  for (const section of previous.sections) {
29162
29169
  if (section.sourceMemoryIds.length > 0 && section.sourceMemoryIds.every((id2) => {
29163
29170
  const memory = memoriesById.get(id2);
29164
- return memory && !memory.isDeleted && !memory.supersededBy && scopes.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
29171
+ return memory && !memory.isDeleted && !memory.supersededBy && scopes2.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
29165
29172
  })) {
29166
29173
  fallbackPriors.set(section.key, section);
29167
29174
  }
@@ -29334,7 +29341,7 @@ async function attributeFacts(ctx, candidates, facets) {
29334
29341
  return keys;
29335
29342
  }
29336
29343
  async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
29337
- const scopes = options.scopes ?? DEFAULT_SCOPES;
29344
+ const scopes2 = options.scopes ?? DEFAULT_SCOPES;
29338
29345
  const limit = options.limit ?? DEFAULT_FACET_RECALL_LIMIT;
29339
29346
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
29340
29347
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
@@ -29351,7 +29358,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
29351
29358
  }
29352
29359
  const recalled = await recall(facet.query, ctx, {
29353
29360
  vaultPreparation,
29354
- scopes,
29361
+ scopes: scopes2,
29355
29362
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
29356
29363
  ...hasReviewGate && { memoryIds: [...reviewed] },
29357
29364
  types: ["fact"],
@@ -29378,7 +29385,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
29378
29385
  llmModel: options.llmModel ?? DEFAULT_SYNTHESIS_MODEL,
29379
29386
  baseUrl: options.baseUrl,
29380
29387
  fetchFn: options.fetchFn,
29381
- scopes,
29388
+ scopes: scopes2,
29382
29389
  limit,
29383
29390
  types: ["fact"],
29384
29391
  maxTokens: DEFAULT_FACET_MAX_TOKENS,
@@ -32301,8 +32308,8 @@ var ZipProcessor = class {
32301
32308
  * Set the processor registry for handling nested files
32302
32309
  * This must be called before processing if you want nested file support
32303
32310
  */
32304
- setRegistry(registry2) {
32305
- this.registry = registry2;
32311
+ setRegistry(registry3) {
32312
+ this.registry = registry3;
32306
32313
  }
32307
32314
  async process(file) {
32308
32315
  try {
@@ -32523,15 +32530,15 @@ function isImageFile(file) {
32523
32530
  return (file.type ?? "").trim().toLowerCase().startsWith("image/");
32524
32531
  }
32525
32532
  function createDefaultRegistry() {
32526
- const registry2 = new ProcessorRegistry();
32527
- registry2.register(new PdfProcessor());
32528
- registry2.register(new ExcelProcessor());
32529
- registry2.register(new WordProcessor());
32530
- registry2.register(new TextProcessor());
32533
+ const registry3 = new ProcessorRegistry();
32534
+ registry3.register(new PdfProcessor());
32535
+ registry3.register(new ExcelProcessor());
32536
+ registry3.register(new WordProcessor());
32537
+ registry3.register(new TextProcessor());
32531
32538
  const zipProcessor = new ZipProcessor();
32532
- zipProcessor.setRegistry(registry2);
32533
- registry2.register(zipProcessor);
32534
- return registry2;
32539
+ zipProcessor.setRegistry(registry3);
32540
+ registry3.register(zipProcessor);
32541
+ return registry3;
32535
32542
  }
32536
32543
  var cachedDefaultRegistry = null;
32537
32544
  function getDefaultRegistry() {
@@ -32544,10 +32551,10 @@ function isSupportedFile(file) {
32544
32551
  return getDefaultRegistry().isSupported(file);
32545
32552
  }
32546
32553
  function getSupportedFileTypes() {
32547
- const registry2 = getDefaultRegistry();
32554
+ const registry3 = getDefaultRegistry();
32548
32555
  return {
32549
- mimeTypes: registry2.getSupportedMimeTypes(),
32550
- extensions: registry2.getSupportedExtensions()
32556
+ mimeTypes: registry3.getSupportedMimeTypes(),
32557
+ extensions: registry3.getSupportedExtensions()
32551
32558
  };
32552
32559
  }
32553
32560
  function formatExtractedContent(fileName, content, format) {
@@ -32602,16 +32609,16 @@ async function preprocessFiles(files, options = {}) {
32602
32609
  metadata: { processedCount: 0, skippedCount: fileStatuses2.length, errorCount: 0 }
32603
32610
  };
32604
32611
  }
32605
- let registry2;
32612
+ let registry3;
32606
32613
  if (processors === void 0) {
32607
- registry2 = getDefaultRegistry();
32614
+ registry3 = getDefaultRegistry();
32608
32615
  } else {
32609
- registry2 = new ProcessorRegistry();
32616
+ registry3 = new ProcessorRegistry();
32610
32617
  processors.forEach((p) => {
32611
32618
  if (p instanceof ZipProcessor) {
32612
- p.setRegistry(registry2);
32619
+ p.setRegistry(registry3);
32613
32620
  }
32614
- registry2.register(p);
32621
+ registry3.register(p);
32615
32622
  });
32616
32623
  }
32617
32624
  const extractedTexts = [];
@@ -32631,7 +32638,7 @@ async function preprocessFiles(files, options = {}) {
32631
32638
  fileStatuses.push({ fileId: file.id, fileName: file.name, status: "skipped", reason });
32632
32639
  };
32633
32640
  onProgress?.(i + 1, files.length, file.name);
32634
- const processor = registry2.findProcessor(file);
32641
+ const processor = registry3.findProcessor(file);
32635
32642
  if (!processor && isImageFile(file)) continue;
32636
32643
  if (file.size > maxFileSizeBytes) {
32637
32644
  logger.info(
@@ -35698,7 +35705,7 @@ function useChat(options) {
35698
35705
  }
35699
35706
 
35700
35707
  // src/react/useChatStorage.ts
35701
- var import_react6 = require("react");
35708
+ var import_react7 = require("react");
35702
35709
  var import_uuid8 = require("uuid");
35703
35710
  init_clientConfig();
35704
35711
 
@@ -36271,6 +36278,107 @@ function summaryStore(options) {
36271
36278
  init_logger();
36272
36279
  init_redactor();
36273
36280
 
36281
+ // src/lib/pii/useConversationRedactors.ts
36282
+ var import_react5 = require("react");
36283
+ init_redactor();
36284
+ var REDACTOR_LIMIT = 50;
36285
+ var registry2 = /* @__PURE__ */ new WeakMap();
36286
+ var compositeKeys = /* @__PURE__ */ new WeakMap();
36287
+ var scopes = /* @__PURE__ */ new Set();
36288
+ var retiredRedactor = new PiiRedactor();
36289
+ retiredRedactor.dispose();
36290
+ function retireScope(scope) {
36291
+ scopes.delete(scope);
36292
+ if (!scope.active) return;
36293
+ scope.active = false;
36294
+ for (const { redactor } of scope.redactors.values()) redactor.dispose();
36295
+ scope.redactors.clear();
36296
+ for (const redactor of scope.evicted) redactor.dispose();
36297
+ scope.evicted = [];
36298
+ for (const notify of scope.subscribers) notify();
36299
+ }
36300
+ function storageKey(storage, secondaryStorage) {
36301
+ if (!secondaryStorage) return storage;
36302
+ let inner = compositeKeys.get(storage);
36303
+ if (!inner) {
36304
+ inner = /* @__PURE__ */ new WeakMap();
36305
+ compositeKeys.set(storage, inner);
36306
+ }
36307
+ let key3 = inner.get(secondaryStorage);
36308
+ if (!key3) {
36309
+ key3 = {};
36310
+ inner.set(secondaryStorage, key3);
36311
+ }
36312
+ return key3;
36313
+ }
36314
+ function getScope(database, storage, account) {
36315
+ let stores = registry2.get(database);
36316
+ if (!stores) {
36317
+ stores = /* @__PURE__ */ new WeakMap();
36318
+ registry2.set(database, stores);
36319
+ }
36320
+ let accounts = stores.get(storage);
36321
+ if (!accounts) {
36322
+ accounts = /* @__PURE__ */ new Map();
36323
+ stores.set(storage, accounts);
36324
+ }
36325
+ let scope = accounts.get(account);
36326
+ if (!scope?.active) {
36327
+ scope = { active: true, users: 0, subscribers: /* @__PURE__ */ new Set(), redactors: /* @__PURE__ */ new Map(), evicted: [] };
36328
+ accounts.set(account, scope);
36329
+ }
36330
+ return scope;
36331
+ }
36332
+ onClearAllEncryptionState(() => {
36333
+ registry2 = /* @__PURE__ */ new WeakMap();
36334
+ for (const scope of [...scopes]) retireScope(scope);
36335
+ });
36336
+ function useConversationRedactors(database, account, storage, secondaryStorage) {
36337
+ const scope = getScope(database, storageKey(storage, secondaryStorage), account);
36338
+ const subscribe = (0, import_react5.useCallback)(
36339
+ (callback) => {
36340
+ scope.subscribers.add(callback);
36341
+ return () => {
36342
+ scope.subscribers.delete(callback);
36343
+ };
36344
+ },
36345
+ [scope]
36346
+ );
36347
+ const getSnapshot = (0, import_react5.useCallback)(() => scope.active ? scope : null, [scope]);
36348
+ (0, import_react5.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
36349
+ (0, import_react5.useEffect)(() => {
36350
+ if (scope.active) scopes.add(scope);
36351
+ scope.users++;
36352
+ return () => {
36353
+ scope.users--;
36354
+ if (scope.users === 0) retireScope(scope);
36355
+ };
36356
+ }, [scope]);
36357
+ return (0, import_react5.useCallback)(
36358
+ (conversationId, nerDetector) => {
36359
+ if (!scope.active) return retiredRedactor;
36360
+ const cached = scope.redactors.get(conversationId);
36361
+ if (cached && cached.detector === nerDetector) {
36362
+ scope.redactors.delete(conversationId);
36363
+ scope.redactors.set(conversationId, cached);
36364
+ return cached.redactor;
36365
+ }
36366
+ if (cached) scope.evicted.push(cached.redactor);
36367
+ const redactor = new PiiRedactor({ nerDetector });
36368
+ scope.redactors.set(conversationId, { redactor, detector: nerDetector });
36369
+ if (scope.redactors.size > REDACTOR_LIMIT) {
36370
+ const oldest = scope.redactors.entries().next().value;
36371
+ if (oldest) {
36372
+ scope.evicted.push(oldest[1].redactor);
36373
+ scope.redactors.delete(oldest[0]);
36374
+ }
36375
+ }
36376
+ return redactor;
36377
+ },
36378
+ [scope]
36379
+ );
36380
+ }
36381
+
36274
36382
  // src/lib/tools/selection/activeToolSets.ts
36275
36383
  function mergeActiveToolSets(current, derived) {
36276
36384
  if (derived.length === 0) return current;
@@ -36331,7 +36439,7 @@ function resetRecentToolSets() {
36331
36439
  onClearAllEncryptionState(resetRecentToolSets);
36332
36440
 
36333
36441
  // src/react/useChatMedia.ts
36334
- var import_react5 = require("react");
36442
+ var import_react6 = require("react");
36335
36443
  init_logger();
36336
36444
  function resolveMediaMeta(extractedKind, urlPath, reportedType) {
36337
36445
  const isVideo = extractedKind === "video";
@@ -36345,7 +36453,7 @@ function resolveMediaMeta(extractedKind, urlPath, reportedType) {
36345
36453
  }
36346
36454
  function useChatMedia(options) {
36347
36455
  const { mediaCtx, mcpR2Domain } = options;
36348
- const getImageDimensions = (0, import_react5.useCallback)(
36456
+ const getImageDimensions = (0, import_react6.useCallback)(
36349
36457
  async (blob) => {
36350
36458
  if (!blob.type.startsWith("image/")) {
36351
36459
  return void 0;
@@ -36372,7 +36480,7 @@ function useChatMedia(options) {
36372
36480
  },
36373
36481
  []
36374
36482
  );
36375
- const extractAndStoreEncryptedMCPImages = (0, import_react5.useCallback)(
36483
+ const extractAndStoreEncryptedMCPImages = (0, import_react6.useCallback)(
36376
36484
  async (content, address, conversationId, toolCallEvents) => {
36377
36485
  let imageModel;
36378
36486
  try {
@@ -36477,7 +36585,7 @@ function useChatMedia(options) {
36477
36585
  },
36478
36586
  [mediaCtx, getImageDimensions, mcpR2Domain]
36479
36587
  );
36480
- const storeUserFilesInOPFS = (0, import_react5.useCallback)(
36588
+ const storeUserFilesInOPFS = (0, import_react6.useCallback)(
36481
36589
  async (files, address, conversationId, maxFileSizeBytes) => {
36482
36590
  const canUseOPFS = isOPFSSupported() && hasEncryptionKey(address);
36483
36591
  let encryptionKey;
@@ -36839,29 +36947,10 @@ async function storedToLlmapiMessage(stored2, encryptionKey, resolveMediaByIds)
36839
36947
  }
36840
36948
  return messages;
36841
36949
  }
36842
- var CONVERSATION_REDACTOR_LIMIT = 50;
36843
- var NO_CONVERSATION_KEY = "__no_conversation__";
36844
36950
  var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
36845
36951
  var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
36846
36952
  var MEMORY_STORE_NOT_READY = "Memory store is not ready";
36847
- var conversationRedactors = /* @__PURE__ */ new Map();
36848
36953
  var queuedBackends = /* @__PURE__ */ new WeakMap();
36849
- function getConversationRedactor(conversationId, nerDetector) {
36850
- const key3 = conversationId ?? NO_CONVERSATION_KEY;
36851
- const cached = conversationRedactors.get(key3);
36852
- if (cached && cached.detector === nerDetector) {
36853
- conversationRedactors.delete(key3);
36854
- conversationRedactors.set(key3, cached);
36855
- return cached.redactor;
36856
- }
36857
- const redactor = new PiiRedactor({ nerDetector });
36858
- conversationRedactors.set(key3, { redactor, detector: nerDetector });
36859
- if (conversationRedactors.size > CONVERSATION_REDACTOR_LIMIT) {
36860
- const oldest = conversationRedactors.keys().next().value;
36861
- if (oldest !== void 0) conversationRedactors.delete(oldest);
36862
- }
36863
- return redactor;
36864
- }
36865
36954
  function resolveCallPii(requestPiiRedaction, hookPiiRedaction, getConversationRedactorFor) {
36866
36955
  const effective = requestPiiRedaction === void 0 ? hookPiiRedaction : requestPiiRedaction;
36867
36956
  const redactor = effective === true ? getConversationRedactorFor() : isPiiRedactor(effective) ? effective : void 0;
@@ -36911,45 +37000,51 @@ function useChatStorage(options) {
36911
37000
  toolResultsHistoryExclude,
36912
37001
  foldToolResultsInHistory
36913
37002
  } = options;
36914
- const [currentConversationId, setCurrentConversationId] = (0, import_react6.useState)(
37003
+ const [currentConversationId, setCurrentConversationId] = (0, import_react7.useState)(
36915
37004
  initialConversationId || null
36916
37005
  );
36917
- const toolResultsHistoryExcludeRef = (0, import_react6.useRef)(toolResultsHistoryExclude);
37006
+ const toolResultsHistoryExcludeRef = (0, import_react7.useRef)(toolResultsHistoryExclude);
36918
37007
  toolResultsHistoryExcludeRef.current = toolResultsHistoryExclude;
36919
- const foldToolResultsInHistoryRef = (0, import_react6.useRef)(foldToolResultsInHistory);
37008
+ const foldToolResultsInHistoryRef = (0, import_react7.useRef)(foldToolResultsInHistory);
36920
37009
  foldToolResultsInHistoryRef.current = foldToolResultsInHistory;
36921
- const nerDetectorRef = (0, import_react6.useRef)(nerDetector);
37010
+ const nerDetectorRef = (0, import_react7.useRef)(nerDetector);
36922
37011
  nerDetectorRef.current = nerDetector;
36923
- const resolvedPiiRedaction = (0, import_react6.useMemo)(
37012
+ const getConversationRedactor = useConversationRedactors(
37013
+ database,
37014
+ walletAddress,
37015
+ memoryStore ?? chatBackend ?? database,
37016
+ memoryStore && chatBackend ? chatBackend : void 0
37017
+ );
37018
+ const resolvedPiiRedaction = (0, import_react7.useMemo)(
36924
37019
  () => piiRedaction === true ? getConversationRedactor(currentConversationId, nerDetectorRef.current) : piiRedaction,
36925
- [piiRedaction, currentConversationId]
37020
+ [piiRedaction, currentConversationId, getConversationRedactor]
36926
37021
  );
36927
- const maskForEmbedding = (0, import_react6.useCallback)(
37022
+ const maskForEmbedding = (0, import_react7.useCallback)(
36928
37023
  (text16) => isPiiRedactor(resolvedPiiRedaction) ? resolvedPiiRedaction.maskText(text16) : text16,
36929
37024
  [resolvedPiiRedaction]
36930
37025
  );
36931
- const maskEmbeddingInput = (0, import_react6.useMemo)(
37026
+ const maskEmbeddingInput = (0, import_react7.useMemo)(
36932
37027
  () => isPiiRedactor(resolvedPiiRedaction) ? (text16) => resolvedPiiRedaction.maskText(text16) : void 0,
36933
37028
  [resolvedPiiRedaction]
36934
37029
  );
36935
- const vaultEmbeddingOptions = (0, import_react6.useMemo)(
37030
+ const vaultEmbeddingOptions = (0, import_react7.useMemo)(
36936
37031
  () => ({ getToken, baseUrl, model: embeddingModel, maskInput: maskEmbeddingInput }),
36937
37032
  [getToken, baseUrl, embeddingModel, maskEmbeddingInput]
36938
37033
  );
36939
37034
  const storeMaskMissing = memoryStore !== void 0 && memoryStore !== null && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
36940
- const blobManagerRef = (0, import_react6.useRef)(new BlobUrlManager());
36941
- (0, import_react6.useEffect)(() => {
37035
+ const blobManagerRef = (0, import_react7.useRef)(new BlobUrlManager());
37036
+ (0, import_react7.useEffect)(() => {
36942
37037
  const manager = blobManagerRef.current;
36943
37038
  return () => {
36944
37039
  manager.revokeAll();
36945
37040
  };
36946
37041
  }, []);
36947
- const messagesCollection = (0, import_react6.useMemo)(() => database.get("history"), [database]);
36948
- const conversationsCollection = (0, import_react6.useMemo)(
37042
+ const messagesCollection = (0, import_react7.useMemo)(() => database.get("history"), [database]);
37043
+ const conversationsCollection = (0, import_react7.useMemo)(
36949
37044
  () => database.get("conversations"),
36950
37045
  [database]
36951
37046
  );
36952
- const storageCtx = (0, import_react6.useMemo)(
37047
+ const storageCtx = (0, import_react7.useMemo)(
36953
37048
  () => ({
36954
37049
  database,
36955
37050
  messagesCollection,
@@ -36967,19 +37062,19 @@ function useChatStorage(options) {
36967
37062
  embeddedWalletSigner
36968
37063
  ]
36969
37064
  );
36970
- const storageCtxRef = (0, import_react6.useRef)(storageCtx);
37065
+ const storageCtxRef = (0, import_react7.useRef)(storageCtx);
36971
37066
  storageCtxRef.current = storageCtx;
36972
- const backendFactory = (0, import_react6.useMemo)(
37067
+ const backendFactory = (0, import_react7.useMemo)(
36973
37068
  () => chatBackend ?? localChatBackend(database),
36974
37069
  [chatBackend, database]
36975
37070
  );
36976
- const backend = (0, import_react6.useMemo)(
37071
+ const backend = (0, import_react7.useMemo)(
36977
37072
  () => backendFactory({ walletAddress, signMessage, embeddedWalletSigner }),
36978
37073
  [backendFactory, walletAddress, signMessage, embeddedWalletSigner]
36979
37074
  );
36980
- const backendRef = (0, import_react6.useRef)(backend);
37075
+ const backendRef = (0, import_react7.useRef)(backend);
36981
37076
  backendRef.current = backend;
36982
- const mediaCtx = (0, import_react6.useMemo)(
37077
+ const mediaCtx = (0, import_react7.useMemo)(
36983
37078
  () => ({
36984
37079
  database,
36985
37080
  walletAddress,
@@ -36988,13 +37083,13 @@ function useChatStorage(options) {
36988
37083
  }),
36989
37084
  [database, walletAddress, signMessage, embeddedWalletSigner]
36990
37085
  );
36991
- const activeToolSetsRef = (0, import_react6.useRef)(activeToolSets);
37086
+ const activeToolSetsRef = (0, import_react7.useRef)(activeToolSets);
36992
37087
  activeToolSetsRef.current = activeToolSets;
36993
- const vaultMemoryCollection = (0, import_react6.useMemo)(
37088
+ const vaultMemoryCollection = (0, import_react7.useMemo)(
36994
37089
  () => database.get("memory_vault"),
36995
37090
  [database]
36996
37091
  );
36997
- const vaultCtx = (0, import_react6.useMemo)(
37092
+ const vaultCtx = (0, import_react7.useMemo)(
36998
37093
  () => ({
36999
37094
  database,
37000
37095
  vaultMemoryCollection,
@@ -37005,16 +37100,16 @@ function useChatStorage(options) {
37005
37100
  }),
37006
37101
  [database, vaultMemoryCollection, walletAddress, signMessage, embeddedWalletSigner]
37007
37102
  );
37008
- const vaultEmbeddingCache = (0, import_react6.useMemo)(
37103
+ const vaultEmbeddingCache = (0, import_react7.useMemo)(
37009
37104
  () => getVaultEmbeddingCache(database, walletAddress, embeddingModel),
37010
37105
  [database, walletAddress, embeddingModel]
37011
37106
  );
37012
- const entityCollection = (0, import_react6.useMemo)(() => database.get("entity"), [database]);
37013
- const memoryEntityCollection = (0, import_react6.useMemo)(
37107
+ const entityCollection = (0, import_react7.useMemo)(() => database.get("entity"), [database]);
37108
+ const memoryEntityCollection = (0, import_react7.useMemo)(
37014
37109
  () => database.get("memory_entity"),
37015
37110
  [database]
37016
37111
  );
37017
- const entityCtx = (0, import_react6.useMemo)(
37112
+ const entityCtx = (0, import_react7.useMemo)(
37018
37113
  () => ({
37019
37114
  database,
37020
37115
  entityCollection,
@@ -37024,18 +37119,18 @@ function useChatStorage(options) {
37024
37119
  }),
37025
37120
  [database, entityCollection, memoryEntityCollection, walletAddress]
37026
37121
  );
37027
- const [queueStatus, setQueueStatus] = (0, import_react6.useState)({
37122
+ const [queueStatus, setQueueStatus] = (0, import_react7.useState)({
37028
37123
  pending: 0,
37029
37124
  failed: 0,
37030
37125
  isFlushing: false,
37031
37126
  isPaused: false
37032
37127
  });
37033
- const refreshQueueStatus = (0, import_react6.useCallback)(() => {
37128
+ const refreshQueueStatus = (0, import_react7.useCallback)(() => {
37034
37129
  if (walletAddress) {
37035
37130
  setQueueStatus(queueManager.getStatus(walletAddress));
37036
37131
  }
37037
37132
  }, [walletAddress]);
37038
- const executeQueuedOperation = (0, import_react6.useCallback)(
37133
+ const executeQueuedOperation = (0, import_react7.useCallback)(
37039
37134
  async (operation, encCtx) => {
37040
37135
  const queued = queuedBackends.get(operation.payload) ?? backendFactory({
37041
37136
  walletAddress: encCtx.walletAddress,
@@ -37083,7 +37178,7 @@ function useChatStorage(options) {
37083
37178
  },
37084
37179
  [backendFactory, database]
37085
37180
  );
37086
- const flushQueue = (0, import_react6.useCallback)(async () => {
37181
+ const flushQueue = (0, import_react7.useCallback)(async () => {
37087
37182
  if (!walletAddress || !signMessage) {
37088
37183
  return { succeeded: [], failed: [], total: 0 };
37089
37184
  }
@@ -37102,31 +37197,31 @@ function useChatStorage(options) {
37102
37197
  executeQueuedOperation,
37103
37198
  refreshQueueStatus
37104
37199
  ]);
37105
- const clearQueue = (0, import_react6.useCallback)(() => {
37200
+ const clearQueue = (0, import_react7.useCallback)(() => {
37106
37201
  if (walletAddress) {
37107
37202
  queueManager.clear(walletAddress);
37108
37203
  refreshQueueStatus();
37109
37204
  }
37110
37205
  }, [walletAddress, refreshQueueStatus]);
37111
- (0, import_react6.useEffect)(() => {
37206
+ (0, import_react7.useEffect)(() => {
37112
37207
  if (!walletAddress) return;
37113
37208
  refreshQueueStatus();
37114
37209
  return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
37115
37210
  }, [walletAddress, refreshQueueStatus]);
37116
- (0, import_react6.useEffect)(() => {
37211
+ (0, import_react7.useEffect)(() => {
37117
37212
  if (!getWalletAddress || walletAddress) return;
37118
37213
  const poller = new WalletPoller();
37119
37214
  return poller.startPolling(getWalletAddress, () => {
37120
37215
  });
37121
37216
  }, [getWalletAddress, walletAddress]);
37122
- const isEncryptionReady = (0, import_react6.useCallback)(() => {
37217
+ const isEncryptionReady = (0, import_react7.useCallback)(() => {
37123
37218
  if (!walletAddress || !signMessage) return true;
37124
37219
  return hasEncryptionKey(walletAddress);
37125
37220
  }, [walletAddress, signMessage]);
37126
- const pendingOpsRef = (0, import_react6.useRef)([]);
37127
- const syntheticConvIdsRef = (0, import_react6.useRef)(/* @__PURE__ */ new Set());
37128
- const syntheticConvQueueIdsRef = (0, import_react6.useRef)(/* @__PURE__ */ new Map());
37129
- (0, import_react6.useEffect)(() => {
37221
+ const pendingOpsRef = (0, import_react7.useRef)([]);
37222
+ const syntheticConvIdsRef = (0, import_react7.useRef)(/* @__PURE__ */ new Set());
37223
+ const syntheticConvQueueIdsRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
37224
+ (0, import_react7.useEffect)(() => {
37130
37225
  if (!walletAddress || !enableQueue) return;
37131
37226
  const pending = pendingOpsRef.current;
37132
37227
  if (pending.length === 0) return;
@@ -37137,7 +37232,7 @@ function useChatStorage(options) {
37137
37232
  pendingOpsRef.current = [];
37138
37233
  refreshQueueStatus();
37139
37234
  }, [walletAddress, enableQueue, refreshQueueStatus]);
37140
- (0, import_react6.useEffect)(() => {
37235
+ (0, import_react7.useEffect)(() => {
37141
37236
  if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
37142
37237
  return onKeyAvailable(walletAddress, () => {
37143
37238
  flushQueue().catch((err) => {
@@ -37145,7 +37240,7 @@ function useChatStorage(options) {
37145
37240
  });
37146
37241
  });
37147
37242
  }, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
37148
- const writeOrQueue = (0, import_react6.useCallback)(
37243
+ const writeOrQueue = (0, import_react7.useCallback)(
37149
37244
  async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
37150
37245
  const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
37151
37246
  const currentBackend = storageCtx.walletAddress ? backend : backendRef.current;
@@ -37183,7 +37278,7 @@ function useChatStorage(options) {
37183
37278
  },
37184
37279
  [storageCtx, backend, enableQueue, signMessage, getWalletAddress]
37185
37280
  );
37186
- const embedMessageAsync = (0, import_react6.useCallback)(
37281
+ const embedMessageAsync = (0, import_react7.useCallback)(
37187
37282
  async (message, mask = maskForEmbedding) => {
37188
37283
  if (!autoEmbedMessages || !getToken) return;
37189
37284
  if (message.content.length < minContentLength) return;
@@ -37222,7 +37317,7 @@ function useChatStorage(options) {
37222
37317
  maskForEmbedding
37223
37318
  ]
37224
37319
  );
37225
- const createMemoryEngineTool2 = (0, import_react6.useCallback)(
37320
+ const createMemoryEngineTool2 = (0, import_react7.useCallback)(
37226
37321
  (searchOptions) => {
37227
37322
  if (!getToken) {
37228
37323
  throw new Error("getToken is required for memory engine tool");
@@ -37231,7 +37326,7 @@ function useChatStorage(options) {
37231
37326
  },
37232
37327
  [backend, getToken, vaultEmbeddingOptions]
37233
37328
  );
37234
- const retainVaultMemory = (0, import_react6.useCallback)(
37329
+ const retainVaultMemory = (0, import_react7.useCallback)(
37235
37330
  async (input) => {
37236
37331
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37237
37332
  if (memoryStore) {
@@ -37263,7 +37358,7 @@ function useChatStorage(options) {
37263
37358
  },
37264
37359
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37265
37360
  );
37266
- const createMemoryVaultTool2 = (0, import_react6.useCallback)(
37361
+ const createMemoryVaultTool2 = (0, import_react7.useCallback)(
37267
37362
  (options2) => {
37268
37363
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37269
37364
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -37285,7 +37380,7 @@ function useChatStorage(options) {
37285
37380
  storeMaskMissing
37286
37381
  ]
37287
37382
  );
37288
- const getVaultMemories = (0, import_react6.useCallback)(
37383
+ const getVaultMemories = (0, import_react7.useCallback)(
37289
37384
  (options2) => {
37290
37385
  if (memoryStore === null) return Promise.resolve([]);
37291
37386
  if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
@@ -37297,7 +37392,7 @@ function useChatStorage(options) {
37297
37392
  },
37298
37393
  [vaultCtx, memoryStore]
37299
37394
  );
37300
- const createVaultMemory = (0, import_react6.useCallback)(
37395
+ const createVaultMemory = (0, import_react7.useCallback)(
37301
37396
  async (content, scope) => {
37302
37397
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37303
37398
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -37319,7 +37414,7 @@ function useChatStorage(options) {
37319
37414
  },
37320
37415
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37321
37416
  );
37322
- const updateVaultMemory = (0, import_react6.useCallback)(
37417
+ const updateVaultMemory = (0, import_react7.useCallback)(
37323
37418
  async (id2, content, scope) => {
37324
37419
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37325
37420
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -37345,7 +37440,7 @@ function useChatStorage(options) {
37345
37440
  },
37346
37441
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37347
37442
  );
37348
- const deleteVaultMemory = (0, import_react6.useCallback)(
37443
+ const deleteVaultMemory = (0, import_react7.useCallback)(
37349
37444
  async (id2) => {
37350
37445
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37351
37446
  if (memoryStore) return memoryStore.delete(id2);
@@ -37358,9 +37453,9 @@ function useChatStorage(options) {
37358
37453
  },
37359
37454
  [vaultCtx, vaultEmbeddingCache, memoryStore]
37360
37455
  );
37361
- const chunkVectorCacheRef = (0, import_react6.useRef)(createChunkVectorCache());
37362
- const clientToolEmbeddingsCacheRef = (0, import_react6.useRef)(/* @__PURE__ */ new Map());
37363
- (0, import_react6.useEffect)(() => {
37456
+ const chunkVectorCacheRef = (0, import_react7.useRef)(createChunkVectorCache());
37457
+ const clientToolEmbeddingsCacheRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
37458
+ (0, import_react7.useEffect)(() => {
37364
37459
  if (!getToken || memoryStore !== void 0) return;
37365
37460
  void (async () => {
37366
37461
  try {
@@ -37369,13 +37464,13 @@ function useChatStorage(options) {
37369
37464
  }
37370
37465
  })();
37371
37466
  }, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore]);
37372
- (0, import_react6.useEffect)(() => {
37467
+ (0, import_react7.useEffect)(() => {
37373
37468
  return onClearAllEncryptionState(() => {
37374
37469
  vaultEmbeddingCache.clear();
37375
37470
  chunkVectorCacheRef.current.clear();
37376
37471
  });
37377
37472
  }, [vaultEmbeddingCache]);
37378
- const createMemoryVaultSearchTool2 = (0, import_react6.useCallback)(
37473
+ const createMemoryVaultSearchTool2 = (0, import_react7.useCallback)(
37379
37474
  (searchOptions) => {
37380
37475
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37381
37476
  if (!getToken && !memoryStore) {
@@ -37391,7 +37486,7 @@ function useChatStorage(options) {
37391
37486
  },
37392
37487
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37393
37488
  );
37394
- const createRecallTool2 = (0, import_react6.useCallback)(
37489
+ const createRecallTool2 = (0, import_react7.useCallback)(
37395
37490
  (toolOptions, callbacks) => {
37396
37491
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37397
37492
  if (!getToken && !memoryStore) {
@@ -37431,7 +37526,7 @@ function useChatStorage(options) {
37431
37526
  storeMaskMissing
37432
37527
  ]
37433
37528
  );
37434
- const searchVaultMemoriesFn = (0, import_react6.useCallback)(
37529
+ const searchVaultMemoriesFn = (0, import_react7.useCallback)(
37435
37530
  async (query, searchOptions) => {
37436
37531
  if (memoryStore === null) return [];
37437
37532
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -37447,7 +37542,7 @@ function useChatStorage(options) {
37447
37542
  },
37448
37543
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37449
37544
  );
37450
- const recallFn = (0, import_react6.useCallback)(
37545
+ const recallFn = (0, import_react7.useCallback)(
37451
37546
  async (query, options2) => {
37452
37547
  if (memoryStore === null || !getToken && !memoryStore) {
37453
37548
  return {
@@ -37512,7 +37607,7 @@ function useChatStorage(options) {
37512
37607
  piiRedaction: resolvedPiiRedaction,
37513
37608
  onPiiRedacted
37514
37609
  });
37515
- const createConversation = (0, import_react6.useCallback)(
37610
+ const createConversation = (0, import_react7.useCallback)(
37516
37611
  async (opts) => {
37517
37612
  const conversationOpts = {
37518
37613
  ...opts,
@@ -37535,16 +37630,16 @@ function useChatStorage(options) {
37535
37630
  },
37536
37631
  [defaultConversationTitle, writeOrQueue]
37537
37632
  );
37538
- const getConversation = (0, import_react6.useCallback)(
37633
+ const getConversation = (0, import_react7.useCallback)(
37539
37634
  async (id2) => {
37540
37635
  return backend.getConversation(id2);
37541
37636
  },
37542
37637
  [backend]
37543
37638
  );
37544
- const getConversations = (0, import_react6.useCallback)(async () => {
37639
+ const getConversations = (0, import_react7.useCallback)(async () => {
37545
37640
  return backend.getConversations();
37546
37641
  }, [backend]);
37547
- const updateConversationTitle = (0, import_react6.useCallback)(
37642
+ const updateConversationTitle = (0, import_react7.useCallback)(
37548
37643
  async (id2, title) => {
37549
37644
  const { result } = await writeOrQueue(
37550
37645
  "updateConversationTitle",
@@ -37556,7 +37651,7 @@ function useChatStorage(options) {
37556
37651
  },
37557
37652
  [writeOrQueue]
37558
37653
  );
37559
- const updateConversationPinned = (0, import_react6.useCallback)(
37654
+ const updateConversationPinned = (0, import_react7.useCallback)(
37560
37655
  async (id2, pinned) => {
37561
37656
  const { result } = await writeOrQueue(
37562
37657
  "updateConversationPinned",
@@ -37568,7 +37663,7 @@ function useChatStorage(options) {
37568
37663
  },
37569
37664
  [writeOrQueue]
37570
37665
  );
37571
- const deleteConversation = (0, import_react6.useCallback)(
37666
+ const deleteConversation = (0, import_react7.useCallback)(
37572
37667
  async (id2) => {
37573
37668
  const deleted = await backend.deleteConversation(id2);
37574
37669
  if (deleted) {
@@ -37583,7 +37678,7 @@ function useChatStorage(options) {
37583
37678
  },
37584
37679
  [backend, mediaCtx, currentConversationId]
37585
37680
  );
37586
- const resolveMessageFiles = (0, import_react6.useCallback)(
37681
+ const resolveMessageFiles = (0, import_react7.useCallback)(
37587
37682
  async (messages) => {
37588
37683
  if (walletAddress && hasEncryptionKey(walletAddress) && isOPFSSupported()) {
37589
37684
  try {
@@ -37645,33 +37740,33 @@ function useChatStorage(options) {
37645
37740
  },
37646
37741
  [walletAddress]
37647
37742
  );
37648
- const getMessages = (0, import_react6.useCallback)(
37743
+ const getMessages = (0, import_react7.useCallback)(
37649
37744
  async (convId) => {
37650
37745
  const messages = await backend.getMessages(convId);
37651
37746
  return resolveMessageFiles(messages);
37652
37747
  },
37653
37748
  [backend, resolveMessageFiles]
37654
37749
  );
37655
- const getMessagesPage = (0, import_react6.useCallback)(
37750
+ const getMessagesPage = (0, import_react7.useCallback)(
37656
37751
  async (convId, options2) => {
37657
37752
  const messages = await backend.getMessagesPage(convId, options2);
37658
37753
  return resolveMessageFiles(messages);
37659
37754
  },
37660
37755
  [backend, resolveMessageFiles]
37661
37756
  );
37662
- const getMessageSkeletons = (0, import_react6.useCallback)(
37757
+ const getMessageSkeletons = (0, import_react7.useCallback)(
37663
37758
  (convId) => {
37664
37759
  return backend.getMessageSkeletons(convId);
37665
37760
  },
37666
37761
  [backend]
37667
37762
  );
37668
- const getMessageCount = (0, import_react6.useCallback)(
37763
+ const getMessageCount = (0, import_react7.useCallback)(
37669
37764
  (convId) => {
37670
37765
  return backend.getMessageCount(convId);
37671
37766
  },
37672
37767
  [backend]
37673
37768
  );
37674
- const ensureConversation = (0, import_react6.useCallback)(async () => {
37769
+ const ensureConversation = (0, import_react7.useCallback)(async () => {
37675
37770
  if (currentConversationId) {
37676
37771
  if (syntheticConvIdsRef.current.has(currentConversationId)) {
37677
37772
  return currentConversationId;
@@ -37697,7 +37792,7 @@ function useChatStorage(options) {
37697
37792
  mediaCtx,
37698
37793
  mcpR2Domain
37699
37794
  });
37700
- const sendMessage = (0, import_react6.useCallback)(
37795
+ const sendMessage = (0, import_react7.useCallback)(
37701
37796
  async (args) => {
37702
37797
  const {
37703
37798
  messages,
@@ -38629,6 +38724,8 @@ function useChatStorage(options) {
38629
38724
  getMessages,
38630
38725
  backend,
38631
38726
  baseSendMessage,
38727
+ getConversationRedactor,
38728
+ piiRedaction,
38632
38729
  walletAddress,
38633
38730
  signMessage,
38634
38731
  embeddedWalletSigner,
@@ -38641,7 +38738,7 @@ function useChatStorage(options) {
38641
38738
  refreshQueueStatus
38642
38739
  ]
38643
38740
  );
38644
- const getAllFiles = (0, import_react6.useCallback)(
38741
+ const getAllFiles = (0, import_react7.useCallback)(
38645
38742
  async (options2) => {
38646
38743
  return backend.getAllFiles(options2);
38647
38744
  },
@@ -38683,25 +38780,25 @@ function useChatStorage(options) {
38683
38780
  }
38684
38781
 
38685
38782
  // src/react/useCredits.ts
38686
- var import_react7 = require("react");
38783
+ var import_react8 = require("react");
38687
38784
  init_clientConfig();
38688
38785
  function useCredits(options = {}) {
38689
38786
  const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
38690
- const [balance, setBalance] = (0, import_react7.useState)(null);
38691
- const [packs, setPacks] = (0, import_react7.useState)([]);
38692
- const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
38693
- const [error, setError] = (0, import_react7.useState)(null);
38694
- const loadingCountRef = (0, import_react7.useRef)(0);
38695
- const getTokenRef = (0, import_react7.useRef)(getToken);
38696
- const baseUrlRef = (0, import_react7.useRef)(baseUrl);
38697
- const onErrorRef = (0, import_react7.useRef)(onError);
38698
- const abortControllerRef = (0, import_react7.useRef)(null);
38699
- (0, import_react7.useEffect)(() => {
38787
+ const [balance, setBalance] = (0, import_react8.useState)(null);
38788
+ const [packs, setPacks] = (0, import_react8.useState)([]);
38789
+ const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
38790
+ const [error, setError] = (0, import_react8.useState)(null);
38791
+ const loadingCountRef = (0, import_react8.useRef)(0);
38792
+ const getTokenRef = (0, import_react8.useRef)(getToken);
38793
+ const baseUrlRef = (0, import_react8.useRef)(baseUrl);
38794
+ const onErrorRef = (0, import_react8.useRef)(onError);
38795
+ const abortControllerRef = (0, import_react8.useRef)(null);
38796
+ (0, import_react8.useEffect)(() => {
38700
38797
  getTokenRef.current = getToken;
38701
38798
  baseUrlRef.current = baseUrl;
38702
38799
  onErrorRef.current = onError;
38703
38800
  });
38704
- (0, import_react7.useEffect)(() => {
38801
+ (0, import_react8.useEffect)(() => {
38705
38802
  return () => {
38706
38803
  if (abortControllerRef.current) {
38707
38804
  abortControllerRef.current.abort();
@@ -38709,15 +38806,15 @@ function useCredits(options = {}) {
38709
38806
  }
38710
38807
  };
38711
38808
  }, []);
38712
- const startLoading = (0, import_react7.useCallback)(() => {
38809
+ const startLoading = (0, import_react8.useCallback)(() => {
38713
38810
  loadingCountRef.current++;
38714
38811
  setIsLoading(true);
38715
38812
  }, []);
38716
- const stopLoading = (0, import_react7.useCallback)(() => {
38813
+ const stopLoading = (0, import_react8.useCallback)(() => {
38717
38814
  loadingCountRef.current = Math.max(0, loadingCountRef.current - 1);
38718
38815
  setIsLoading(loadingCountRef.current > 0);
38719
38816
  }, []);
38720
- const getHeaders = (0, import_react7.useCallback)(async () => {
38817
+ const getHeaders = (0, import_react8.useCallback)(async () => {
38721
38818
  const headers = {};
38722
38819
  if (getTokenRef.current) {
38723
38820
  const token = await getTokenRef.current();
@@ -38727,13 +38824,13 @@ function useCredits(options = {}) {
38727
38824
  }
38728
38825
  return headers;
38729
38826
  }, []);
38730
- const handleError = (0, import_react7.useCallback)((err) => {
38827
+ const handleError = (0, import_react8.useCallback)((err) => {
38731
38828
  const error2 = err instanceof Error ? err : new Error(String(err));
38732
38829
  setError(error2);
38733
38830
  onErrorRef.current?.(error2);
38734
38831
  return error2;
38735
38832
  }, []);
38736
- const fetchBalance = (0, import_react7.useCallback)(async () => {
38833
+ const fetchBalance = (0, import_react8.useCallback)(async () => {
38737
38834
  if (abortControllerRef.current) {
38738
38835
  abortControllerRef.current.abort();
38739
38836
  }
@@ -38766,11 +38863,11 @@ function useCredits(options = {}) {
38766
38863
  }
38767
38864
  }
38768
38865
  }, [getHeaders, handleError, startLoading, stopLoading]);
38769
- const refetch = (0, import_react7.useCallback)(async () => {
38866
+ const refetch = (0, import_react8.useCallback)(async () => {
38770
38867
  setBalance(null);
38771
38868
  await fetchBalance();
38772
38869
  }, [fetchBalance]);
38773
- const fetchPacks = (0, import_react7.useCallback)(async () => {
38870
+ const fetchPacks = (0, import_react8.useCallback)(async () => {
38774
38871
  startLoading();
38775
38872
  setError(null);
38776
38873
  try {
@@ -38790,7 +38887,7 @@ function useCredits(options = {}) {
38790
38887
  stopLoading();
38791
38888
  }
38792
38889
  }, [getHeaders, handleError, startLoading, stopLoading]);
38793
- const purchaseCredits = (0, import_react7.useCallback)(
38890
+ const purchaseCredits = (0, import_react8.useCallback)(
38794
38891
  async (credits, opts) => {
38795
38892
  startLoading();
38796
38893
  setError(null);
@@ -38819,8 +38916,8 @@ function useCredits(options = {}) {
38819
38916
  },
38820
38917
  [getHeaders, handleError, startLoading, stopLoading]
38821
38918
  );
38822
- const hasFetchedRef = (0, import_react7.useRef)(false);
38823
- (0, import_react7.useEffect)(() => {
38919
+ const hasFetchedRef = (0, import_react8.useRef)(false);
38920
+ (0, import_react8.useEffect)(() => {
38824
38921
  if (autoFetch && !hasFetchedRef.current) {
38825
38922
  hasFetchedRef.current = true;
38826
38923
  void fetchBalance();
@@ -38841,13 +38938,13 @@ function useCredits(options = {}) {
38841
38938
  }
38842
38939
 
38843
38940
  // src/react/useDatabaseManager.ts
38844
- var import_react8 = require("react");
38941
+ var import_react9 = require("react");
38845
38942
  function useDatabaseManager(walletAddress, manager) {
38846
- return (0, import_react8.useMemo)(() => manager.getDatabase(walletAddress), [walletAddress, manager]);
38943
+ return (0, import_react9.useMemo)(() => manager.getDatabase(walletAddress), [walletAddress, manager]);
38847
38944
  }
38848
38945
 
38849
38946
  // src/react/useExportPdf.ts
38850
- var import_react9 = require("react");
38947
+ var import_react10 = require("react");
38851
38948
  var DEFAULT_FILENAME2 = "document.pdf";
38852
38949
  function triggerDownload(blob, filename) {
38853
38950
  const url = URL.createObjectURL(blob);
@@ -38863,10 +38960,10 @@ function toError(err) {
38863
38960
  return err instanceof Error ? err : new Error(String(err));
38864
38961
  }
38865
38962
  function useExportPdf() {
38866
- const [isExporting, setIsExporting] = (0, import_react9.useState)(false);
38867
- const [progress, setProgress] = (0, import_react9.useState)(null);
38868
- const [error, setError] = (0, import_react9.useState)(null);
38869
- const wrappedExportElement = (0, import_react9.useCallback)(
38963
+ const [isExporting, setIsExporting] = (0, import_react10.useState)(false);
38964
+ const [progress, setProgress] = (0, import_react10.useState)(null);
38965
+ const [error, setError] = (0, import_react10.useState)(null);
38966
+ const wrappedExportElement = (0, import_react10.useCallback)(
38870
38967
  async (element, options) => {
38871
38968
  setIsExporting(true);
38872
38969
  setError(null);
@@ -38886,7 +38983,7 @@ function useExportPdf() {
38886
38983
  },
38887
38984
  []
38888
38985
  );
38889
- const wrappedExportMarkdown = (0, import_react9.useCallback)(
38986
+ const wrappedExportMarkdown = (0, import_react10.useCallback)(
38890
38987
  async (markdown, options) => {
38891
38988
  setIsExporting(true);
38892
38989
  setError(null);
@@ -38906,21 +39003,21 @@ function useExportPdf() {
38906
39003
  },
38907
39004
  []
38908
39005
  );
38909
- const downloadElementAsPdf = (0, import_react9.useCallback)(
39006
+ const downloadElementAsPdf = (0, import_react10.useCallback)(
38910
39007
  async (element, options) => {
38911
39008
  const blob = await wrappedExportElement(element, options);
38912
39009
  triggerDownload(blob, options?.filename ?? DEFAULT_FILENAME2);
38913
39010
  },
38914
39011
  [wrappedExportElement]
38915
39012
  );
38916
- const downloadMarkdownAsPdf = (0, import_react9.useCallback)(
39013
+ const downloadMarkdownAsPdf = (0, import_react10.useCallback)(
38917
39014
  async (markdown, options) => {
38918
39015
  const blob = await wrappedExportMarkdown(markdown, options);
38919
39016
  triggerDownload(blob, options?.filename ?? DEFAULT_FILENAME2);
38920
39017
  },
38921
39018
  [wrappedExportMarkdown]
38922
39019
  );
38923
- const wrappedRenderToCanvas = (0, import_react9.useCallback)(
39020
+ const wrappedRenderToCanvas = (0, import_react10.useCallback)(
38924
39021
  async (element) => {
38925
39022
  setIsExporting(true);
38926
39023
  setError(null);
@@ -38952,20 +39049,20 @@ function useExportPdf() {
38952
39049
 
38953
39050
  // src/react/useFiles.ts
38954
39051
  var import_watermelondb36 = require("@nozbe/watermelondb");
38955
- var import_react10 = require("react");
39052
+ var import_react11 = require("react");
38956
39053
  init_logger();
38957
39054
  function useFiles(options) {
38958
39055
  const { database, walletAddress } = options;
38959
- const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
38960
- const [isReady, setIsReady] = (0, import_react10.useState)(false);
38961
- const [mediaCollection, setMediaCollection] = (0, import_react10.useState)(null);
38962
- const blobUrlManager = (0, import_react10.useMemo)(() => new BlobUrlManager(), []);
38963
- (0, import_react10.useEffect)(() => {
39056
+ const [isLoading, setIsLoading] = (0, import_react11.useState)(false);
39057
+ const [isReady, setIsReady] = (0, import_react11.useState)(false);
39058
+ const [mediaCollection, setMediaCollection] = (0, import_react11.useState)(null);
39059
+ const blobUrlManager = (0, import_react11.useMemo)(() => new BlobUrlManager(), []);
39060
+ (0, import_react11.useEffect)(() => {
38964
39061
  return () => {
38965
39062
  blobUrlManager.revokeAll();
38966
39063
  };
38967
39064
  }, [blobUrlManager]);
38968
- (0, import_react10.useEffect)(() => {
39065
+ (0, import_react11.useEffect)(() => {
38969
39066
  const initCollection = async () => {
38970
39067
  setIsLoading(true);
38971
39068
  try {
@@ -38982,13 +39079,13 @@ function useFiles(options) {
38982
39079
  };
38983
39080
  void initCollection();
38984
39081
  }, [database]);
38985
- const ctx = (0, import_react10.useMemo)(() => {
39082
+ const ctx = (0, import_react11.useMemo)(() => {
38986
39083
  if (!isReady || !mediaCollection) {
38987
39084
  return null;
38988
39085
  }
38989
39086
  return { database, walletAddress };
38990
39087
  }, [database, mediaCollection, isReady, walletAddress]);
38991
- const createMedia = (0, import_react10.useCallback)(
39088
+ const createMedia = (0, import_react11.useCallback)(
38992
39089
  async (createOptions) => {
38993
39090
  if (!ctx) {
38994
39091
  throw new Error("Files not available. Database may need to be initialized.");
@@ -38997,7 +39094,7 @@ function useFiles(options) {
38997
39094
  },
38998
39095
  [ctx]
38999
39096
  );
39000
- const createMediaBatch = (0, import_react10.useCallback)(
39097
+ const createMediaBatch = (0, import_react11.useCallback)(
39001
39098
  async (optionsArray) => {
39002
39099
  if (!ctx) {
39003
39100
  throw new Error("Files not available. Database may need to be initialized.");
@@ -39006,7 +39103,7 @@ function useFiles(options) {
39006
39103
  },
39007
39104
  [ctx]
39008
39105
  );
39009
- const getMediaById = (0, import_react10.useCallback)(
39106
+ const getMediaById = (0, import_react11.useCallback)(
39010
39107
  async (mediaId) => {
39011
39108
  if (!ctx) {
39012
39109
  return null;
@@ -39015,7 +39112,7 @@ function useFiles(options) {
39015
39112
  },
39016
39113
  [ctx]
39017
39114
  );
39018
- const getMediaBySourceUrl = (0, import_react10.useCallback)(
39115
+ const getMediaBySourceUrl = (0, import_react11.useCallback)(
39019
39116
  async (sourceUrl) => {
39020
39117
  if (!ctx || !walletAddress) {
39021
39118
  return null;
@@ -39024,7 +39121,7 @@ function useFiles(options) {
39024
39121
  },
39025
39122
  [ctx, walletAddress]
39026
39123
  );
39027
- const getMediaByIds = (0, import_react10.useCallback)(
39124
+ const getMediaByIds = (0, import_react11.useCallback)(
39028
39125
  async (mediaIds, includeDeleted = false) => {
39029
39126
  if (!ctx) {
39030
39127
  return [];
@@ -39033,7 +39130,7 @@ function useFiles(options) {
39033
39130
  },
39034
39131
  [ctx]
39035
39132
  );
39036
- const getMediaByMessage = (0, import_react10.useCallback)(
39133
+ const getMediaByMessage = (0, import_react11.useCallback)(
39037
39134
  async (messageId) => {
39038
39135
  if (!ctx) {
39039
39136
  return [];
@@ -39042,7 +39139,7 @@ function useFiles(options) {
39042
39139
  },
39043
39140
  [ctx]
39044
39141
  );
39045
- const updateMedia = (0, import_react10.useCallback)(
39142
+ const updateMedia = (0, import_react11.useCallback)(
39046
39143
  async (mediaId, updateOptions) => {
39047
39144
  if (!ctx) {
39048
39145
  return null;
@@ -39051,7 +39148,7 @@ function useFiles(options) {
39051
39148
  },
39052
39149
  [ctx]
39053
39150
  );
39054
- const updateMediaMessageIdBatch = (0, import_react10.useCallback)(
39151
+ const updateMediaMessageIdBatch = (0, import_react11.useCallback)(
39055
39152
  async (mediaIds, messageId) => {
39056
39153
  if (!ctx) {
39057
39154
  return 0;
@@ -39060,13 +39157,13 @@ function useFiles(options) {
39060
39157
  },
39061
39158
  [ctx]
39062
39159
  );
39063
- const relinkMisclassifiedVideos = (0, import_react10.useCallback)(async () => {
39160
+ const relinkMisclassifiedVideos = (0, import_react11.useCallback)(async () => {
39064
39161
  if (!ctx || !walletAddress) {
39065
39162
  return 0;
39066
39163
  }
39067
39164
  return relinkMisclassifiedVideosOp(ctx, walletAddress);
39068
39165
  }, [ctx, walletAddress]);
39069
- const deleteMedia = (0, import_react10.useCallback)(
39166
+ const deleteMedia = (0, import_react11.useCallback)(
39070
39167
  async (mediaId) => {
39071
39168
  if (!ctx) {
39072
39169
  return false;
@@ -39077,7 +39174,7 @@ function useFiles(options) {
39077
39174
  },
39078
39175
  [ctx, blobUrlManager]
39079
39176
  );
39080
- const hardDeleteMedia = (0, import_react10.useCallback)(
39177
+ const hardDeleteMedia = (0, import_react11.useCallback)(
39081
39178
  async (mediaId) => {
39082
39179
  if (!ctx) {
39083
39180
  return false;
@@ -39088,7 +39185,7 @@ function useFiles(options) {
39088
39185
  },
39089
39186
  [ctx, blobUrlManager]
39090
39187
  );
39091
- const getMedia = (0, import_react10.useCallback)(
39188
+ const getMedia = (0, import_react11.useCallback)(
39092
39189
  async (filters) => {
39093
39190
  if (!ctx) {
39094
39191
  return [];
@@ -39097,7 +39194,7 @@ function useFiles(options) {
39097
39194
  },
39098
39195
  [ctx]
39099
39196
  );
39100
- const getMediaByType = (0, import_react10.useCallback)(
39197
+ const getMediaByType = (0, import_react11.useCallback)(
39101
39198
  async (mediaType, limit) => {
39102
39199
  if (!ctx || !walletAddress) {
39103
39200
  return [];
@@ -39106,7 +39203,7 @@ function useFiles(options) {
39106
39203
  },
39107
39204
  [ctx, walletAddress]
39108
39205
  );
39109
- const getImages = (0, import_react10.useCallback)(
39206
+ const getImages = (0, import_react11.useCallback)(
39110
39207
  async (limit) => {
39111
39208
  if (!ctx || !walletAddress) {
39112
39209
  return [];
@@ -39115,7 +39212,7 @@ function useFiles(options) {
39115
39212
  },
39116
39213
  [ctx, walletAddress]
39117
39214
  );
39118
- const getVideos = (0, import_react10.useCallback)(
39215
+ const getVideos = (0, import_react11.useCallback)(
39119
39216
  async (limit) => {
39120
39217
  if (!ctx || !walletAddress) {
39121
39218
  return [];
@@ -39124,7 +39221,7 @@ function useFiles(options) {
39124
39221
  },
39125
39222
  [ctx, walletAddress]
39126
39223
  );
39127
- const getAudio = (0, import_react10.useCallback)(
39224
+ const getAudio = (0, import_react11.useCallback)(
39128
39225
  async (limit) => {
39129
39226
  if (!ctx || !walletAddress) {
39130
39227
  return [];
@@ -39133,7 +39230,7 @@ function useFiles(options) {
39133
39230
  },
39134
39231
  [ctx, walletAddress]
39135
39232
  );
39136
- const getDocuments = (0, import_react10.useCallback)(
39233
+ const getDocuments = (0, import_react11.useCallback)(
39137
39234
  async (limit) => {
39138
39235
  if (!ctx || !walletAddress) {
39139
39236
  return [];
@@ -39142,7 +39239,7 @@ function useFiles(options) {
39142
39239
  },
39143
39240
  [ctx, walletAddress]
39144
39241
  );
39145
- const getMediaByConversation = (0, import_react10.useCallback)(
39242
+ const getMediaByConversation = (0, import_react11.useCallback)(
39146
39243
  async (conversationId, limit) => {
39147
39244
  if (!ctx || !walletAddress) {
39148
39245
  return [];
@@ -39151,7 +39248,7 @@ function useFiles(options) {
39151
39248
  },
39152
39249
  [ctx, walletAddress]
39153
39250
  );
39154
- const getMediaByRole = (0, import_react10.useCallback)(
39251
+ const getMediaByRole = (0, import_react11.useCallback)(
39155
39252
  async (role, limit) => {
39156
39253
  if (!ctx || !walletAddress) {
39157
39254
  return [];
@@ -39160,7 +39257,7 @@ function useFiles(options) {
39160
39257
  },
39161
39258
  [ctx, walletAddress]
39162
39259
  );
39163
- const getAIGeneratedMedia = (0, import_react10.useCallback)(
39260
+ const getAIGeneratedMedia = (0, import_react11.useCallback)(
39164
39261
  async (limit) => {
39165
39262
  if (!ctx || !walletAddress) {
39166
39263
  return [];
@@ -39169,7 +39266,7 @@ function useFiles(options) {
39169
39266
  },
39170
39267
  [ctx, walletAddress]
39171
39268
  );
39172
- const getUserUploadedMedia = (0, import_react10.useCallback)(
39269
+ const getUserUploadedMedia = (0, import_react11.useCallback)(
39173
39270
  async (limit) => {
39174
39271
  if (!ctx || !walletAddress) {
39175
39272
  return [];
@@ -39178,7 +39275,7 @@ function useFiles(options) {
39178
39275
  },
39179
39276
  [ctx, walletAddress]
39180
39277
  );
39181
- const getMediaByModel = (0, import_react10.useCallback)(
39278
+ const getMediaByModel = (0, import_react11.useCallback)(
39182
39279
  async (model, limit) => {
39183
39280
  if (!ctx || !walletAddress) {
39184
39281
  return [];
@@ -39187,7 +39284,7 @@ function useFiles(options) {
39187
39284
  },
39188
39285
  [ctx, walletAddress]
39189
39286
  );
39190
- const getRecentMedia = (0, import_react10.useCallback)(
39287
+ const getRecentMedia = (0, import_react11.useCallback)(
39191
39288
  async (limit = 20) => {
39192
39289
  if (!ctx || !walletAddress) {
39193
39290
  return [];
@@ -39196,7 +39293,7 @@ function useFiles(options) {
39196
39293
  },
39197
39294
  [ctx, walletAddress]
39198
39295
  );
39199
- const searchMedia = (0, import_react10.useCallback)(
39296
+ const searchMedia = (0, import_react11.useCallback)(
39200
39297
  async (query, limit) => {
39201
39298
  if (!ctx || !walletAddress) {
39202
39299
  return [];
@@ -39205,7 +39302,7 @@ function useFiles(options) {
39205
39302
  },
39206
39303
  [ctx, walletAddress]
39207
39304
  );
39208
- const getMediaCount = (0, import_react10.useCallback)(
39305
+ const getMediaCount = (0, import_react11.useCallback)(
39209
39306
  async (mediaType) => {
39210
39307
  if (!ctx || !walletAddress) {
39211
39308
  return 0;
@@ -39214,13 +39311,13 @@ function useFiles(options) {
39214
39311
  },
39215
39312
  [ctx, walletAddress]
39216
39313
  );
39217
- const getMediaCountsByType = (0, import_react10.useCallback)(async () => {
39314
+ const getMediaCountsByType = (0, import_react11.useCallback)(async () => {
39218
39315
  if (!ctx || !walletAddress) {
39219
39316
  return { image: 0, video: 0, audio: 0, document: 0 };
39220
39317
  }
39221
39318
  return getMediaCountsByTypeOp(ctx, walletAddress);
39222
39319
  }, [ctx, walletAddress]);
39223
- const deleteMediaByConversation = (0, import_react10.useCallback)(
39320
+ const deleteMediaByConversation = (0, import_react11.useCallback)(
39224
39321
  async (conversationId) => {
39225
39322
  if (!ctx) {
39226
39323
  return 0;
@@ -39229,7 +39326,7 @@ function useFiles(options) {
39229
39326
  },
39230
39327
  [ctx]
39231
39328
  );
39232
- const deleteMediaByMessage = (0, import_react10.useCallback)(
39329
+ const deleteMediaByMessage = (0, import_react11.useCallback)(
39233
39330
  async (messageId) => {
39234
39331
  if (!ctx) {
39235
39332
  return 0;
@@ -39238,7 +39335,7 @@ function useFiles(options) {
39238
39335
  },
39239
39336
  [ctx]
39240
39337
  );
39241
- const readFile = (0, import_react10.useCallback)(
39338
+ const readFile = (0, import_react11.useCallback)(
39242
39339
  async (mediaId) => {
39243
39340
  if (!isOPFSSupported()) {
39244
39341
  throw new Error("OPFS is not supported in this browser.");
@@ -39294,7 +39391,7 @@ function useFiles(options) {
39294
39391
  },
39295
39392
  [walletAddress]
39296
39393
  );
39297
- const createBlobUrl = (0, import_react10.useCallback)(
39394
+ const createBlobUrl = (0, import_react11.useCallback)(
39298
39395
  async (mediaId) => {
39299
39396
  const existingUrl = blobUrlManager.getUrl(mediaId);
39300
39397
  if (existingUrl) {
@@ -39310,16 +39407,16 @@ function useFiles(options) {
39310
39407
  },
39311
39408
  [readFile, blobUrlManager]
39312
39409
  );
39313
- const revokeBlobUrl = (0, import_react10.useCallback)(
39410
+ const revokeBlobUrl = (0, import_react11.useCallback)(
39314
39411
  (mediaId) => {
39315
39412
  blobUrlManager.revokeUrl(mediaId);
39316
39413
  },
39317
39414
  [blobUrlManager]
39318
39415
  );
39319
- const revokeAllBlobUrls = (0, import_react10.useCallback)(() => {
39416
+ const revokeAllBlobUrls = (0, import_react11.useCallback)(() => {
39320
39417
  blobUrlManager.revokeAll();
39321
39418
  }, [blobUrlManager]);
39322
- const resolveFilePlaceholders2 = (0, import_react10.useCallback)(
39419
+ const resolveFilePlaceholders2 = (0, import_react11.useCallback)(
39323
39420
  async (content) => {
39324
39421
  if (!walletAddress || !hasEncryptionKey(walletAddress)) {
39325
39422
  return content;
@@ -39374,20 +39471,20 @@ function useFiles(options) {
39374
39471
  }
39375
39472
 
39376
39473
  // src/react/useICloudAuth.ts
39377
- var import_react11 = require("react");
39378
- var ICloudAuthContext = (0, import_react11.createContext)(null);
39474
+ var import_react12 = require("react");
39475
+ var ICloudAuthContext = (0, import_react12.createContext)(null);
39379
39476
  function ICloudAuthProvider({
39380
39477
  apiToken,
39381
39478
  containerIdentifier = DEFAULT_CONTAINER_ID,
39382
39479
  environment = "production",
39383
39480
  children
39384
39481
  }) {
39385
- const [isAuthenticated, setIsAuthenticated] = (0, import_react11.useState)(false);
39386
- const [userRecordName, setUserRecordName] = (0, import_react11.useState)(null);
39387
- const [isAvailable, setIsAvailable] = (0, import_react11.useState)(false);
39388
- const [isConfigured, setIsConfigured] = (0, import_react11.useState)(false);
39389
- const [_isLoading, setIsLoading] = (0, import_react11.useState)(false);
39390
- (0, import_react11.useEffect)(() => {
39482
+ const [isAuthenticated, setIsAuthenticated] = (0, import_react12.useState)(false);
39483
+ const [userRecordName, setUserRecordName] = (0, import_react12.useState)(null);
39484
+ const [isAvailable, setIsAvailable] = (0, import_react12.useState)(false);
39485
+ const [isConfigured, setIsConfigured] = (0, import_react12.useState)(false);
39486
+ const [_isLoading, setIsLoading] = (0, import_react12.useState)(false);
39487
+ (0, import_react12.useEffect)(() => {
39391
39488
  if (!apiToken || typeof window === "undefined") {
39392
39489
  return;
39393
39490
  }
@@ -39420,7 +39517,7 @@ function ICloudAuthProvider({
39420
39517
  };
39421
39518
  void initCloudKit();
39422
39519
  }, [apiToken, containerIdentifier, environment]);
39423
- const requestAccess = (0, import_react11.useCallback)(async () => {
39520
+ const requestAccess = (0, import_react12.useCallback)(async () => {
39424
39521
  if (!isConfigured) {
39425
39522
  throw new Error("iCloud is not configured");
39426
39523
  }
@@ -39435,11 +39532,11 @@ function ICloudAuthProvider({
39435
39532
  throw new Error(err instanceof Error ? err.message : "Failed to sign in to iCloud");
39436
39533
  }
39437
39534
  }, [isAuthenticated, isConfigured]);
39438
- const logout = (0, import_react11.useCallback)(() => {
39535
+ const logout = (0, import_react12.useCallback)(() => {
39439
39536
  setIsAuthenticated(false);
39440
39537
  setUserRecordName(null);
39441
39538
  }, []);
39442
- return (0, import_react11.createElement)(
39539
+ return (0, import_react12.createElement)(
39443
39540
  ICloudAuthContext.Provider,
39444
39541
  {
39445
39542
  value: {
@@ -39455,7 +39552,7 @@ function ICloudAuthProvider({
39455
39552
  );
39456
39553
  }
39457
39554
  function useICloudAuth() {
39458
- const context = (0, import_react11.useContext)(ICloudAuthContext);
39555
+ const context = (0, import_react12.useContext)(ICloudAuthContext);
39459
39556
  if (!context) {
39460
39557
  throw new Error("useICloudAuth must be used within ICloudAuthProvider");
39461
39558
  }
@@ -39468,11 +39565,11 @@ function clearICloudAuth() {
39468
39565
  }
39469
39566
 
39470
39567
  // src/react/useICloudBackup.ts
39471
- var import_react12 = require("react");
39568
+ var import_react13 = require("react");
39472
39569
  function useICloudBackup(options) {
39473
39570
  const { database, userAddress, requestEncryptionKey: requestEncryptionKey2, exportConversation, importConversation } = options;
39474
39571
  const { isAuthenticated, isConfigured, isAvailable, requestAccess } = useICloudAuth();
39475
- const deps = (0, import_react12.useMemo)(
39572
+ const deps = (0, import_react13.useMemo)(
39476
39573
  () => ({
39477
39574
  requestICloudAccess: requestAccess,
39478
39575
  requestEncryptionKey: requestEncryptionKey2,
@@ -39481,7 +39578,7 @@ function useICloudBackup(options) {
39481
39578
  }),
39482
39579
  [requestAccess, requestEncryptionKey2, exportConversation, importConversation]
39483
39580
  );
39484
- const ensureAuthenticated = (0, import_react12.useCallback)(async () => {
39581
+ const ensureAuthenticated = (0, import_react13.useCallback)(async () => {
39485
39582
  if (isAuthenticated) return true;
39486
39583
  try {
39487
39584
  await requestAccess();
@@ -39490,7 +39587,7 @@ function useICloudBackup(options) {
39490
39587
  return false;
39491
39588
  }
39492
39589
  }, [isAuthenticated, requestAccess]);
39493
- const backup = (0, import_react12.useCallback)(
39590
+ const backup = (0, import_react13.useCallback)(
39494
39591
  async (backupOptions) => {
39495
39592
  if (!userAddress) {
39496
39593
  return { error: "Please sign in to backup to iCloud" };
@@ -39515,7 +39612,7 @@ function useICloudBackup(options) {
39515
39612
  },
39516
39613
  [database, userAddress, isAvailable, isConfigured, ensureAuthenticated, deps]
39517
39614
  );
39518
- const restore = (0, import_react12.useCallback)(
39615
+ const restore = (0, import_react13.useCallback)(
39519
39616
  async (restoreOptions) => {
39520
39617
  if (!userAddress) {
39521
39618
  return { error: "Please sign in to restore from iCloud" };
@@ -39550,7 +39647,7 @@ function useICloudBackup(options) {
39550
39647
  }
39551
39648
 
39552
39649
  // src/react/useModels.ts
39553
- var import_react13 = require("react");
39650
+ var import_react14 = require("react");
39554
39651
  init_clientConfig();
39555
39652
  var MODELS_CACHE_TTL_MS = 5 * 60 * 1e3;
39556
39653
  var modelsCache = /* @__PURE__ */ new Map();
@@ -39676,19 +39773,19 @@ function waitForSharedRequest(key3, shared, signal) {
39676
39773
  }
39677
39774
  function useModels(options = {}) {
39678
39775
  const { getToken, baseUrl = BASE_URL, provider, autoFetch = true } = options;
39679
- const [models, setModels] = (0, import_react13.useState)([]);
39680
- const [isLoading, setIsLoading] = (0, import_react13.useState)(false);
39681
- const [error, setError] = (0, import_react13.useState)(null);
39682
- const getTokenRef = (0, import_react13.useRef)(getToken);
39683
- const baseUrlRef = (0, import_react13.useRef)(baseUrl);
39684
- const providerRef = (0, import_react13.useRef)(provider);
39685
- const abortControllerRef = (0, import_react13.useRef)(null);
39686
- (0, import_react13.useEffect)(() => {
39776
+ const [models, setModels] = (0, import_react14.useState)([]);
39777
+ const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
39778
+ const [error, setError] = (0, import_react14.useState)(null);
39779
+ const getTokenRef = (0, import_react14.useRef)(getToken);
39780
+ const baseUrlRef = (0, import_react14.useRef)(baseUrl);
39781
+ const providerRef = (0, import_react14.useRef)(provider);
39782
+ const abortControllerRef = (0, import_react14.useRef)(null);
39783
+ (0, import_react14.useEffect)(() => {
39687
39784
  getTokenRef.current = getToken;
39688
39785
  baseUrlRef.current = baseUrl;
39689
39786
  providerRef.current = provider;
39690
39787
  });
39691
- (0, import_react13.useEffect)(() => {
39788
+ (0, import_react14.useEffect)(() => {
39692
39789
  return () => {
39693
39790
  if (abortControllerRef.current) {
39694
39791
  abortControllerRef.current.abort();
@@ -39696,7 +39793,7 @@ function useModels(options = {}) {
39696
39793
  }
39697
39794
  };
39698
39795
  }, []);
39699
- const fetchModels = (0, import_react13.useCallback)(async (force = false) => {
39796
+ const fetchModels = (0, import_react14.useCallback)(async (force = false) => {
39700
39797
  if (abortControllerRef.current) {
39701
39798
  abortControllerRef.current.abort();
39702
39799
  }
@@ -39736,12 +39833,12 @@ function useModels(options = {}) {
39736
39833
  }
39737
39834
  }
39738
39835
  }, []);
39739
- const refetch = (0, import_react13.useCallback)(async () => {
39836
+ const refetch = (0, import_react14.useCallback)(async () => {
39740
39837
  setModels([]);
39741
39838
  await fetchModels(true);
39742
39839
  }, [fetchModels]);
39743
- const hasFetchedRef = (0, import_react13.useRef)(false);
39744
- (0, import_react13.useEffect)(() => {
39840
+ const hasFetchedRef = (0, import_react14.useRef)(false);
39841
+ (0, import_react14.useEffect)(() => {
39745
39842
  if (autoFetch && !hasFetchedRef.current) {
39746
39843
  hasFetchedRef.current = true;
39747
39844
  void fetchModels();
@@ -39759,13 +39856,13 @@ function useModels(options = {}) {
39759
39856
  }
39760
39857
 
39761
39858
  // src/react/useOCR.ts
39762
- var import_react14 = require("react");
39859
+ var import_react15 = require("react");
39763
39860
  var import_tesseract = __toESM(require("tesseract.js"));
39764
39861
  init_logger();
39765
39862
  function useOCR() {
39766
- const [isProcessing, setIsProcessing] = (0, import_react14.useState)(false);
39767
- const [error, setError] = (0, import_react14.useState)(null);
39768
- const extractOCRContext = (0, import_react14.useCallback)(async (files) => {
39863
+ const [isProcessing, setIsProcessing] = (0, import_react15.useState)(false);
39864
+ const [error, setError] = (0, import_react15.useState)(null);
39865
+ const extractOCRContext = (0, import_react15.useCallback)(async (files) => {
39769
39866
  setIsProcessing(true);
39770
39867
  setError(null);
39771
39868
  try {
@@ -39843,13 +39940,13 @@ ${text16}`;
39843
39940
  }
39844
39941
 
39845
39942
  // src/react/usePdf.ts
39846
- var import_react15 = require("react");
39943
+ var import_react16 = require("react");
39847
39944
  init_logger();
39848
39945
  var PDF_MIME_TYPE = "application/pdf";
39849
39946
  function usePdf() {
39850
- const [isProcessing, setIsProcessing] = (0, import_react15.useState)(false);
39851
- const [error, setError] = (0, import_react15.useState)(null);
39852
- const extractPdfContext = (0, import_react15.useCallback)(async (files) => {
39947
+ const [isProcessing, setIsProcessing] = (0, import_react16.useState)(false);
39948
+ const [error, setError] = (0, import_react16.useState)(null);
39949
+ const extractPdfContext = (0, import_react16.useCallback)(async (files) => {
39853
39950
  setIsProcessing(true);
39854
39951
  setError(null);
39855
39952
  try {
@@ -39893,7 +39990,7 @@ ${text16}`;
39893
39990
  }
39894
39991
 
39895
39992
  // src/react/usePhoneCalls.ts
39896
- var import_react16 = require("react");
39993
+ var import_react17 = require("react");
39897
39994
  init_clientConfig();
39898
39995
  var DEFAULT_POLL_INTERVAL_MS = 5e3;
39899
39996
  var DEFAULT_POLL_MAX_ATTEMPTS = 60;
@@ -39925,24 +40022,24 @@ function isTerminalPhoneCall(call) {
39925
40022
  }
39926
40023
  function usePhoneCalls(options = {}) {
39927
40024
  const { getToken, baseUrl = BASE_URL, autoFetchAvailability = true, onError } = options;
39928
- const [isEnabled, setIsEnabled] = (0, import_react16.useState)(null);
39929
- const [currentCall, setCurrentCall] = (0, import_react16.useState)(null);
39930
- const [isLoading, setIsLoading] = (0, import_react16.useState)(false);
39931
- const [isPolling, setIsPolling] = (0, import_react16.useState)(false);
39932
- const [error, setError] = (0, import_react16.useState)(null);
39933
- const getTokenRef = (0, import_react16.useRef)(getToken);
39934
- const baseUrlRef = (0, import_react16.useRef)(baseUrl);
39935
- const onErrorRef = (0, import_react16.useRef)(onError);
39936
- const loadingCountRef = (0, import_react16.useRef)(0);
39937
- const requestAbortControllerRef = (0, import_react16.useRef)(null);
39938
- const pollAbortControllerRef = (0, import_react16.useRef)(null);
39939
- const pollRunIdRef = (0, import_react16.useRef)(0);
39940
- (0, import_react16.useEffect)(() => {
40025
+ const [isEnabled, setIsEnabled] = (0, import_react17.useState)(null);
40026
+ const [currentCall, setCurrentCall] = (0, import_react17.useState)(null);
40027
+ const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
40028
+ const [isPolling, setIsPolling] = (0, import_react17.useState)(false);
40029
+ const [error, setError] = (0, import_react17.useState)(null);
40030
+ const getTokenRef = (0, import_react17.useRef)(getToken);
40031
+ const baseUrlRef = (0, import_react17.useRef)(baseUrl);
40032
+ const onErrorRef = (0, import_react17.useRef)(onError);
40033
+ const loadingCountRef = (0, import_react17.useRef)(0);
40034
+ const requestAbortControllerRef = (0, import_react17.useRef)(null);
40035
+ const pollAbortControllerRef = (0, import_react17.useRef)(null);
40036
+ const pollRunIdRef = (0, import_react17.useRef)(0);
40037
+ (0, import_react17.useEffect)(() => {
39941
40038
  getTokenRef.current = getToken;
39942
40039
  baseUrlRef.current = baseUrl;
39943
40040
  onErrorRef.current = onError;
39944
40041
  });
39945
- const stopPolling = (0, import_react16.useCallback)(() => {
40042
+ const stopPolling = (0, import_react17.useCallback)(() => {
39946
40043
  pollRunIdRef.current += 1;
39947
40044
  if (pollAbortControllerRef.current) {
39948
40045
  pollAbortControllerRef.current.abort();
@@ -39950,7 +40047,7 @@ function usePhoneCalls(options = {}) {
39950
40047
  }
39951
40048
  setIsPolling(false);
39952
40049
  }, []);
39953
- (0, import_react16.useEffect)(() => {
40050
+ (0, import_react17.useEffect)(() => {
39954
40051
  return () => {
39955
40052
  if (requestAbortControllerRef.current) {
39956
40053
  requestAbortControllerRef.current.abort();
@@ -39963,21 +40060,21 @@ function usePhoneCalls(options = {}) {
39963
40060
  }
39964
40061
  };
39965
40062
  }, []);
39966
- const startLoading = (0, import_react16.useCallback)(() => {
40063
+ const startLoading = (0, import_react17.useCallback)(() => {
39967
40064
  loadingCountRef.current += 1;
39968
40065
  setIsLoading(true);
39969
40066
  }, []);
39970
- const stopLoading = (0, import_react16.useCallback)(() => {
40067
+ const stopLoading = (0, import_react17.useCallback)(() => {
39971
40068
  loadingCountRef.current = Math.max(0, loadingCountRef.current - 1);
39972
40069
  setIsLoading(loadingCountRef.current > 0);
39973
40070
  }, []);
39974
- const handleError = (0, import_react16.useCallback)((err) => {
40071
+ const handleError = (0, import_react17.useCallback)((err) => {
39975
40072
  const nextError = err instanceof Error ? err : new Error(String(err));
39976
40073
  setError(nextError);
39977
40074
  onErrorRef.current?.(nextError);
39978
40075
  return nextError;
39979
40076
  }, []);
39980
- const getHeaders = (0, import_react16.useCallback)(async () => {
40077
+ const getHeaders = (0, import_react17.useCallback)(async () => {
39981
40078
  const headers = {};
39982
40079
  if (getTokenRef.current) {
39983
40080
  const token = await getTokenRef.current();
@@ -39987,7 +40084,7 @@ function usePhoneCalls(options = {}) {
39987
40084
  }
39988
40085
  return headers;
39989
40086
  }, []);
39990
- const fetchAvailability = (0, import_react16.useCallback)(async () => {
40087
+ const fetchAvailability = (0, import_react17.useCallback)(async () => {
39991
40088
  if (requestAbortControllerRef.current) {
39992
40089
  requestAbortControllerRef.current.abort();
39993
40090
  }
@@ -40025,7 +40122,7 @@ function usePhoneCalls(options = {}) {
40025
40122
  }
40026
40123
  }
40027
40124
  }, [getHeaders, handleError, startLoading, stopLoading]);
40028
- const createPhoneCall = (0, import_react16.useCallback)(
40125
+ const createPhoneCall = (0, import_react17.useCallback)(
40029
40126
  async (request) => {
40030
40127
  startLoading();
40031
40128
  setError(null);
@@ -40052,7 +40149,7 @@ function usePhoneCalls(options = {}) {
40052
40149
  },
40053
40150
  [getHeaders, handleError, startLoading, stopLoading]
40054
40151
  );
40055
- const getPhoneCall = (0, import_react16.useCallback)(
40152
+ const getPhoneCall = (0, import_react17.useCallback)(
40056
40153
  async (callId) => {
40057
40154
  const trimmedCallId = callId.trim();
40058
40155
  if (!trimmedCallId) {
@@ -40101,7 +40198,7 @@ function usePhoneCalls(options = {}) {
40101
40198
  },
40102
40199
  [getHeaders, handleError, startLoading, stopLoading]
40103
40200
  );
40104
- const pollPhoneCall = (0, import_react16.useCallback)(
40201
+ const pollPhoneCall = (0, import_react17.useCallback)(
40105
40202
  async (callId, pollOptions = {}) => {
40106
40203
  const trimmedCallId = callId.trim();
40107
40204
  if (!trimmedCallId) {
@@ -40166,11 +40263,11 @@ function usePhoneCalls(options = {}) {
40166
40263
  },
40167
40264
  [getHeaders, handleError, stopPolling]
40168
40265
  );
40169
- const reset = (0, import_react16.useCallback)(() => {
40266
+ const reset = (0, import_react17.useCallback)(() => {
40170
40267
  setCurrentCall(null);
40171
40268
  setError(null);
40172
40269
  }, []);
40173
- (0, import_react16.useEffect)(() => {
40270
+ (0, import_react17.useEffect)(() => {
40174
40271
  if (!autoFetchAvailability) {
40175
40272
  return;
40176
40273
  }
@@ -40193,18 +40290,18 @@ function usePhoneCalls(options = {}) {
40193
40290
 
40194
40291
  // src/react/useProjects.ts
40195
40292
  var import_watermelondb37 = require("@nozbe/watermelondb");
40196
- var import_react17 = require("react");
40293
+ var import_react18 = require("react");
40197
40294
  init_logger();
40198
40295
  function useProjects(options) {
40199
40296
  const { database, initialProjectId } = options;
40200
- const [projects, setProjects] = (0, import_react17.useState)([]);
40201
- const [currentProjectId, setCurrentProjectId] = (0, import_react17.useState)(initialProjectId || null);
40202
- const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
40203
- const [isReady, setIsReady] = (0, import_react17.useState)(false);
40204
- const [inboxProjectId, setInboxProjectId] = (0, import_react17.useState)(null);
40205
- const [projectsCollection, setProjectsCollection] = (0, import_react17.useState)(null);
40206
- const [conversationsCollection, setConversationsCollection] = (0, import_react17.useState)(null);
40207
- (0, import_react17.useEffect)(() => {
40297
+ const [projects, setProjects] = (0, import_react18.useState)([]);
40298
+ const [currentProjectId, setCurrentProjectId] = (0, import_react18.useState)(initialProjectId || null);
40299
+ const [isLoading, setIsLoading] = (0, import_react18.useState)(false);
40300
+ const [isReady, setIsReady] = (0, import_react18.useState)(false);
40301
+ const [inboxProjectId, setInboxProjectId] = (0, import_react18.useState)(null);
40302
+ const [projectsCollection, setProjectsCollection] = (0, import_react18.useState)(null);
40303
+ const [conversationsCollection, setConversationsCollection] = (0, import_react18.useState)(null);
40304
+ (0, import_react18.useEffect)(() => {
40208
40305
  const initCollections = async () => {
40209
40306
  getLogger().debug("[useProjects] Initializing collections...");
40210
40307
  try {
@@ -40236,7 +40333,7 @@ function useProjects(options) {
40236
40333
  };
40237
40334
  void initCollections();
40238
40335
  }, [database]);
40239
- const projectCtx = (0, import_react17.useMemo)(() => {
40336
+ const projectCtx = (0, import_react18.useMemo)(() => {
40240
40337
  if (!isReady || !projectsCollection || !conversationsCollection) {
40241
40338
  return null;
40242
40339
  }
@@ -40246,7 +40343,7 @@ function useProjects(options) {
40246
40343
  conversationsCollection
40247
40344
  };
40248
40345
  }, [database, projectsCollection, conversationsCollection, isReady]);
40249
- const storageCtx = (0, import_react17.useMemo)(() => {
40346
+ const storageCtx = (0, import_react18.useMemo)(() => {
40250
40347
  if (!isReady || !conversationsCollection) {
40251
40348
  return null;
40252
40349
  }
@@ -40261,7 +40358,7 @@ function useProjects(options) {
40261
40358
  return null;
40262
40359
  }
40263
40360
  }, [database, conversationsCollection, isReady]);
40264
- const refreshProjects = (0, import_react17.useCallback)(async () => {
40361
+ const refreshProjects = (0, import_react18.useCallback)(async () => {
40265
40362
  if (!projectCtx) {
40266
40363
  return;
40267
40364
  }
@@ -40275,12 +40372,12 @@ function useProjects(options) {
40275
40372
  setIsLoading(false);
40276
40373
  }
40277
40374
  }, [projectCtx]);
40278
- (0, import_react17.useEffect)(() => {
40375
+ (0, import_react18.useEffect)(() => {
40279
40376
  if (isReady) {
40280
40377
  void refreshProjects();
40281
40378
  }
40282
40379
  }, [isReady, refreshProjects]);
40283
- (0, import_react17.useEffect)(() => {
40380
+ (0, import_react18.useEffect)(() => {
40284
40381
  const ensureInboxProject = async () => {
40285
40382
  if (!projectCtx || !isReady) return;
40286
40383
  try {
@@ -40298,7 +40395,7 @@ function useProjects(options) {
40298
40395
  };
40299
40396
  void ensureInboxProject();
40300
40397
  }, [projectCtx, isReady]);
40301
- (0, import_react17.useEffect)(() => {
40398
+ (0, import_react18.useEffect)(() => {
40302
40399
  if (!projectsCollection) {
40303
40400
  return;
40304
40401
  }
@@ -40307,7 +40404,7 @@ function useProjects(options) {
40307
40404
  });
40308
40405
  return () => subscription.unsubscribe();
40309
40406
  }, [projectsCollection]);
40310
- const createProject = (0, import_react17.useCallback)(
40407
+ const createProject = (0, import_react18.useCallback)(
40311
40408
  async (opts) => {
40312
40409
  if (!projectCtx) {
40313
40410
  throw new Error("Projects not available. Database schema may need to be updated.");
@@ -40317,7 +40414,7 @@ function useProjects(options) {
40317
40414
  },
40318
40415
  [projectCtx]
40319
40416
  );
40320
- const getProject = (0, import_react17.useCallback)(
40417
+ const getProject = (0, import_react18.useCallback)(
40321
40418
  async (projectId) => {
40322
40419
  if (!projectCtx) {
40323
40420
  return null;
@@ -40326,13 +40423,13 @@ function useProjects(options) {
40326
40423
  },
40327
40424
  [projectCtx]
40328
40425
  );
40329
- const getProjects = (0, import_react17.useCallback)(async () => {
40426
+ const getProjects = (0, import_react18.useCallback)(async () => {
40330
40427
  if (!projectCtx) {
40331
40428
  return [];
40332
40429
  }
40333
40430
  return getProjectsOp(projectCtx);
40334
40431
  }, [projectCtx]);
40335
- const updateProjectName = (0, import_react17.useCallback)(
40432
+ const updateProjectName = (0, import_react18.useCallback)(
40336
40433
  async (projectId, name) => {
40337
40434
  if (!projectCtx) {
40338
40435
  return false;
@@ -40341,7 +40438,7 @@ function useProjects(options) {
40341
40438
  },
40342
40439
  [projectCtx]
40343
40440
  );
40344
- const updateProject = (0, import_react17.useCallback)(
40441
+ const updateProject = (0, import_react18.useCallback)(
40345
40442
  async (projectId, opts) => {
40346
40443
  if (!projectCtx) {
40347
40444
  return false;
@@ -40350,7 +40447,7 @@ function useProjects(options) {
40350
40447
  },
40351
40448
  [projectCtx]
40352
40449
  );
40353
- const deleteProject = (0, import_react17.useCallback)(
40450
+ const deleteProject = (0, import_react18.useCallback)(
40354
40451
  async (projectId) => {
40355
40452
  if (!projectCtx) {
40356
40453
  return false;
@@ -40363,7 +40460,7 @@ function useProjects(options) {
40363
40460
  },
40364
40461
  [projectCtx, currentProjectId]
40365
40462
  );
40366
- const getProjectConversations = (0, import_react17.useCallback)(
40463
+ const getProjectConversations = (0, import_react18.useCallback)(
40367
40464
  async (projectId) => {
40368
40465
  if (!projectCtx) {
40369
40466
  return [];
@@ -40372,7 +40469,7 @@ function useProjects(options) {
40372
40469
  },
40373
40470
  [projectCtx]
40374
40471
  );
40375
- const getProjectConversationCount = (0, import_react17.useCallback)(
40472
+ const getProjectConversationCount = (0, import_react18.useCallback)(
40376
40473
  async (projectId) => {
40377
40474
  if (!projectCtx) {
40378
40475
  return 0;
@@ -40381,7 +40478,7 @@ function useProjects(options) {
40381
40478
  },
40382
40479
  [projectCtx]
40383
40480
  );
40384
- const updateConversationProject = (0, import_react17.useCallback)(
40481
+ const updateConversationProject = (0, import_react18.useCallback)(
40385
40482
  async (conversationId, projectId) => {
40386
40483
  if (!storageCtx) {
40387
40484
  return false;
@@ -40390,7 +40487,7 @@ function useProjects(options) {
40390
40487
  },
40391
40488
  [storageCtx]
40392
40489
  );
40393
- const getConversationsByProject = (0, import_react17.useCallback)(
40490
+ const getConversationsByProject = (0, import_react18.useCallback)(
40394
40491
  async (projectId) => {
40395
40492
  if (!storageCtx) {
40396
40493
  return [];
@@ -40421,7 +40518,7 @@ function useProjects(options) {
40421
40518
  }
40422
40519
 
40423
40520
  // src/react/useSettings.ts
40424
- var import_react18 = require("react");
40521
+ var import_react19 = require("react");
40425
40522
 
40426
40523
  // src/react/userSettingsStore.ts
40427
40524
  var import_watermelondb38 = require("@nozbe/watermelondb");
@@ -40559,16 +40656,16 @@ function patchUserSettingsSnapshot(database, walletAddress, patch) {
40559
40656
  var DB_NOT_READY = "Database not ready";
40560
40657
  function useSettings(options) {
40561
40658
  const { database, walletAddress } = options;
40562
- const subscribe = (0, import_react18.useCallback)(
40659
+ const subscribe = (0, import_react19.useCallback)(
40563
40660
  (listener) => subscribeUserSettings(database, walletAddress, listener),
40564
40661
  [database, walletAddress]
40565
40662
  );
40566
- const getSnapshot = (0, import_react18.useCallback)(
40663
+ const getSnapshot = (0, import_react19.useCallback)(
40567
40664
  () => getUserSettingsSnapshot(database, walletAddress),
40568
40665
  [database, walletAddress]
40569
40666
  );
40570
- const snapshot = (0, import_react18.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
40571
- const storageCtx = (0, import_react18.useMemo)(
40667
+ const snapshot = (0, import_react19.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
40668
+ const storageCtx = (0, import_react19.useMemo)(
40572
40669
  () => database ? {
40573
40670
  database,
40574
40671
  userPreferencesCollection: database.get("userPreferences"),
@@ -40576,14 +40673,14 @@ function useSettings(options) {
40576
40673
  } : null,
40577
40674
  [database]
40578
40675
  );
40579
- const legacyStorageCtx = (0, import_react18.useMemo)(
40676
+ const legacyStorageCtx = (0, import_react19.useMemo)(
40580
40677
  () => database ? {
40581
40678
  database,
40582
40679
  modelPreferencesCollection: database.get("modelPreferences")
40583
40680
  } : null,
40584
40681
  [database]
40585
40682
  );
40586
- const getModelPreference = (0, import_react18.useCallback)(
40683
+ const getModelPreference = (0, import_react19.useCallback)(
40587
40684
  async (address) => {
40588
40685
  try {
40589
40686
  if (!address) throw new Error("Wallet address is required");
@@ -40596,7 +40693,7 @@ function useSettings(options) {
40596
40693
  },
40597
40694
  [legacyStorageCtx]
40598
40695
  );
40599
- const setModelPreference = (0, import_react18.useCallback)(
40696
+ const setModelPreference = (0, import_react19.useCallback)(
40600
40697
  async (address, models) => {
40601
40698
  try {
40602
40699
  if (!address) throw new Error("Wallet address is required");
@@ -40612,7 +40709,7 @@ function useSettings(options) {
40612
40709
  },
40613
40710
  [database, legacyStorageCtx, walletAddress]
40614
40711
  );
40615
- const deleteModelPreference = (0, import_react18.useCallback)(
40712
+ const deleteModelPreference = (0, import_react19.useCallback)(
40616
40713
  async (address) => {
40617
40714
  try {
40618
40715
  if (!address) throw new Error("Wallet address is required");
@@ -40628,7 +40725,7 @@ function useSettings(options) {
40628
40725
  },
40629
40726
  [database, legacyStorageCtx, walletAddress]
40630
40727
  );
40631
- const getUserPreference = (0, import_react18.useCallback)(
40728
+ const getUserPreference = (0, import_react19.useCallback)(
40632
40729
  async (address) => {
40633
40730
  try {
40634
40731
  if (!address) throw new Error("Wallet address is required");
@@ -40641,7 +40738,7 @@ function useSettings(options) {
40641
40738
  },
40642
40739
  [storageCtx]
40643
40740
  );
40644
- const setUserPreference = (0, import_react18.useCallback)(
40741
+ const setUserPreference = (0, import_react19.useCallback)(
40645
40742
  async (address, opts) => {
40646
40743
  try {
40647
40744
  if (!address) throw new Error("Wallet address is required");
@@ -40657,7 +40754,7 @@ function useSettings(options) {
40657
40754
  },
40658
40755
  [database, storageCtx, walletAddress]
40659
40756
  );
40660
- const updateProfile = (0, import_react18.useCallback)(
40757
+ const updateProfile = (0, import_react19.useCallback)(
40661
40758
  async (address, profile) => {
40662
40759
  try {
40663
40760
  if (!address) throw new Error("Wallet address is required");
@@ -40673,7 +40770,7 @@ function useSettings(options) {
40673
40770
  },
40674
40771
  [database, storageCtx, walletAddress]
40675
40772
  );
40676
- const updatePersonality = (0, import_react18.useCallback)(
40773
+ const updatePersonality = (0, import_react19.useCallback)(
40677
40774
  async (address, personality) => {
40678
40775
  try {
40679
40776
  if (!address) throw new Error("Wallet address is required");
@@ -40689,7 +40786,7 @@ function useSettings(options) {
40689
40786
  },
40690
40787
  [database, storageCtx, walletAddress]
40691
40788
  );
40692
- const updateModels = (0, import_react18.useCallback)(
40789
+ const updateModels = (0, import_react19.useCallback)(
40693
40790
  async (address, models) => {
40694
40791
  try {
40695
40792
  if (!address) throw new Error("Wallet address is required");
@@ -40705,7 +40802,7 @@ function useSettings(options) {
40705
40802
  },
40706
40803
  [database, storageCtx, walletAddress]
40707
40804
  );
40708
- const deleteUserPreference = (0, import_react18.useCallback)(
40805
+ const deleteUserPreference = (0, import_react19.useCallback)(
40709
40806
  async (address) => {
40710
40807
  try {
40711
40808
  if (!address) throw new Error("Wallet address is required");
@@ -40738,23 +40835,23 @@ function useSettings(options) {
40738
40835
  }
40739
40836
 
40740
40837
  // src/react/useSubscription.ts
40741
- var import_react19 = require("react");
40838
+ var import_react20 = require("react");
40742
40839
  init_clientConfig();
40743
40840
  function useSubscription(options = {}) {
40744
40841
  const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
40745
- const [status, setStatus] = (0, import_react19.useState)(null);
40746
- const [isLoading, setIsLoading] = (0, import_react19.useState)(false);
40747
- const [error, setError] = (0, import_react19.useState)(null);
40748
- const getTokenRef = (0, import_react19.useRef)(getToken);
40749
- const baseUrlRef = (0, import_react19.useRef)(baseUrl);
40750
- const onErrorRef = (0, import_react19.useRef)(onError);
40751
- const abortControllerRef = (0, import_react19.useRef)(null);
40752
- (0, import_react19.useEffect)(() => {
40842
+ const [status, setStatus] = (0, import_react20.useState)(null);
40843
+ const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
40844
+ const [error, setError] = (0, import_react20.useState)(null);
40845
+ const getTokenRef = (0, import_react20.useRef)(getToken);
40846
+ const baseUrlRef = (0, import_react20.useRef)(baseUrl);
40847
+ const onErrorRef = (0, import_react20.useRef)(onError);
40848
+ const abortControllerRef = (0, import_react20.useRef)(null);
40849
+ (0, import_react20.useEffect)(() => {
40753
40850
  getTokenRef.current = getToken;
40754
40851
  baseUrlRef.current = baseUrl;
40755
40852
  onErrorRef.current = onError;
40756
40853
  });
40757
- (0, import_react19.useEffect)(() => {
40854
+ (0, import_react20.useEffect)(() => {
40758
40855
  return () => {
40759
40856
  if (abortControllerRef.current) {
40760
40857
  abortControllerRef.current.abort();
@@ -40762,7 +40859,7 @@ function useSubscription(options = {}) {
40762
40859
  }
40763
40860
  };
40764
40861
  }, []);
40765
- const getHeaders = (0, import_react19.useCallback)(async () => {
40862
+ const getHeaders = (0, import_react20.useCallback)(async () => {
40766
40863
  const headers = {};
40767
40864
  if (getTokenRef.current) {
40768
40865
  const token = await getTokenRef.current();
@@ -40772,13 +40869,13 @@ function useSubscription(options = {}) {
40772
40869
  }
40773
40870
  return headers;
40774
40871
  }, []);
40775
- const handleError = (0, import_react19.useCallback)((err) => {
40872
+ const handleError = (0, import_react20.useCallback)((err) => {
40776
40873
  const error2 = err instanceof Error ? err : new Error(String(err));
40777
40874
  setError(error2);
40778
40875
  onErrorRef.current?.(error2);
40779
40876
  return error2;
40780
40877
  }, []);
40781
- const fetchStatus = (0, import_react19.useCallback)(async () => {
40878
+ const fetchStatus = (0, import_react20.useCallback)(async () => {
40782
40879
  if (abortControllerRef.current) {
40783
40880
  abortControllerRef.current.abort();
40784
40881
  }
@@ -40815,11 +40912,11 @@ function useSubscription(options = {}) {
40815
40912
  }
40816
40913
  }
40817
40914
  }, [getHeaders, handleError]);
40818
- const refetch = (0, import_react19.useCallback)(async () => {
40915
+ const refetch = (0, import_react20.useCallback)(async () => {
40819
40916
  setStatus(null);
40820
40917
  await fetchStatus();
40821
40918
  }, [fetchStatus]);
40822
- const createCheckoutSession = (0, import_react19.useCallback)(
40919
+ const createCheckoutSession = (0, import_react20.useCallback)(
40823
40920
  async (opts) => {
40824
40921
  setIsLoading(true);
40825
40922
  setError(null);
@@ -40849,7 +40946,7 @@ function useSubscription(options = {}) {
40849
40946
  },
40850
40947
  [getHeaders, handleError]
40851
40948
  );
40852
- const openCustomerPortal = (0, import_react19.useCallback)(
40949
+ const openCustomerPortal = (0, import_react20.useCallback)(
40853
40950
  async (opts) => {
40854
40951
  setIsLoading(true);
40855
40952
  setError(null);
@@ -40876,7 +40973,7 @@ function useSubscription(options = {}) {
40876
40973
  },
40877
40974
  [getHeaders, handleError]
40878
40975
  );
40879
- const cancelSubscription = (0, import_react19.useCallback)(async () => {
40976
+ const cancelSubscription = (0, import_react20.useCallback)(async () => {
40880
40977
  setIsLoading(true);
40881
40978
  setError(null);
40882
40979
  try {
@@ -40898,7 +40995,7 @@ function useSubscription(options = {}) {
40898
40995
  setIsLoading(false);
40899
40996
  }
40900
40997
  }, [getHeaders, handleError, fetchStatus]);
40901
- const renewSubscription = (0, import_react19.useCallback)(async () => {
40998
+ const renewSubscription = (0, import_react20.useCallback)(async () => {
40902
40999
  setIsLoading(true);
40903
41000
  setError(null);
40904
41001
  try {
@@ -40920,8 +41017,8 @@ function useSubscription(options = {}) {
40920
41017
  setIsLoading(false);
40921
41018
  }
40922
41019
  }, [getHeaders, handleError, fetchStatus]);
40923
- const hasFetchedRef = (0, import_react19.useRef)(false);
40924
- (0, import_react19.useEffect)(() => {
41020
+ const hasFetchedRef = (0, import_react20.useRef)(false);
41021
+ (0, import_react20.useEffect)(() => {
40925
41022
  if (autoFetch && !hasFetchedRef.current) {
40926
41023
  hasFetchedRef.current = true;
40927
41024
  void fetchStatus();
@@ -40943,30 +41040,30 @@ function useSubscription(options = {}) {
40943
41040
  }
40944
41041
 
40945
41042
  // src/react/useTools.ts
40946
- var import_react20 = require("react");
41043
+ var import_react21 = require("react");
40947
41044
  init_clientConfig();
40948
41045
  function useTools(options) {
40949
41046
  const { getToken, baseUrl = BASE_URL, includeTools, autoFetch = true } = options;
40950
- const [allTools, setAllTools] = (0, import_react20.useState)([]);
40951
- const [checksum, setChecksum] = (0, import_react20.useState)(getToolsChecksum2);
40952
- const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
40953
- const [error, setError] = (0, import_react20.useState)(null);
40954
- const includeToolsRef = (0, import_react20.useRef)(includeTools);
41047
+ const [allTools, setAllTools] = (0, import_react21.useState)([]);
41048
+ const [checksum, setChecksum] = (0, import_react21.useState)(getToolsChecksum2);
41049
+ const [isLoading, setIsLoading] = (0, import_react21.useState)(false);
41050
+ const [error, setError] = (0, import_react21.useState)(null);
41051
+ const includeToolsRef = (0, import_react21.useRef)(includeTools);
40955
41052
  if (includeTools !== includeToolsRef.current && (includeTools === void 0 || includeToolsRef.current === void 0 || includeTools.length !== includeToolsRef.current.length || includeTools.some((name, i) => name !== includeToolsRef.current?.[i]))) {
40956
41053
  includeToolsRef.current = includeTools;
40957
41054
  }
40958
41055
  const stableIncludeTools = includeToolsRef.current;
40959
- const tools = (0, import_react20.useMemo)(
41056
+ const tools = (0, import_react21.useMemo)(
40960
41057
  () => filterServerTools(allTools, stableIncludeTools),
40961
41058
  [allTools, stableIncludeTools]
40962
41059
  );
40963
- const getTokenRef = (0, import_react20.useRef)(getToken);
40964
- const baseUrlRef = (0, import_react20.useRef)(baseUrl);
40965
- (0, import_react20.useEffect)(() => {
41060
+ const getTokenRef = (0, import_react21.useRef)(getToken);
41061
+ const baseUrlRef = (0, import_react21.useRef)(baseUrl);
41062
+ (0, import_react21.useEffect)(() => {
40966
41063
  getTokenRef.current = getToken;
40967
41064
  baseUrlRef.current = baseUrl;
40968
41065
  });
40969
- const fetchTools = (0, import_react20.useCallback)(async (forceRefresh = false) => {
41066
+ const fetchTools = (0, import_react21.useCallback)(async (forceRefresh = false) => {
40970
41067
  setIsLoading(true);
40971
41068
  setError(null);
40972
41069
  try {
@@ -40983,13 +41080,13 @@ function useTools(options) {
40983
41080
  setIsLoading(false);
40984
41081
  }
40985
41082
  }, []);
40986
- const refresh = (0, import_react20.useCallback)(
41083
+ const refresh = (0, import_react21.useCallback)(
40987
41084
  async (force = false) => {
40988
41085
  await fetchTools(force);
40989
41086
  },
40990
41087
  [fetchTools]
40991
41088
  );
40992
- const checkForUpdates = (0, import_react20.useCallback)(
41089
+ const checkForUpdates = (0, import_react21.useCallback)(
40993
41090
  (responseChecksum) => {
40994
41091
  if (shouldRefreshTools(responseChecksum)) {
40995
41092
  void refresh(true);
@@ -40999,8 +41096,8 @@ function useTools(options) {
40999
41096
  },
41000
41097
  [refresh]
41001
41098
  );
41002
- const hasFetchedRef = (0, import_react20.useRef)(false);
41003
- (0, import_react20.useEffect)(() => {
41099
+ const hasFetchedRef = (0, import_react21.useRef)(false);
41100
+ (0, import_react21.useEffect)(() => {
41004
41101
  if (autoFetch && !hasFetchedRef.current) {
41005
41102
  hasFetchedRef.current = true;
41006
41103
  void fetchTools();
@@ -41020,10 +41117,10 @@ function useTools(options) {
41020
41117
  }
41021
41118
 
41022
41119
  // src/react/useUIInteraction.ts
41023
- var import_react21 = require("react");
41024
- var UIInteractionContext = (0, import_react21.createContext)(null);
41120
+ var import_react22 = require("react");
41121
+ var UIInteractionContext = (0, import_react22.createContext)(null);
41025
41122
  function useUIInteraction() {
41026
- const context = (0, import_react21.useContext)(UIInteractionContext);
41123
+ const context = (0, import_react22.useContext)(UIInteractionContext);
41027
41124
  if (!context) {
41028
41125
  throw new Error("useUIInteraction must be used within UIInteractionProvider");
41029
41126
  }
@@ -41033,11 +41130,11 @@ function UIInteractionProvider({
41033
41130
  children,
41034
41131
  timeout = 5 * 60 * 1e3
41035
41132
  }) {
41036
- const [pendingInteractions, setPendingInteractions] = (0, import_react21.useState)(
41133
+ const [pendingInteractions, setPendingInteractions] = (0, import_react22.useState)(
41037
41134
  /* @__PURE__ */ new Map()
41038
41135
  );
41039
- const timersRef = (0, import_react21.useRef)(/* @__PURE__ */ new Map());
41040
- const createInteraction = (0, import_react21.useCallback)(
41136
+ const timersRef = (0, import_react22.useRef)(/* @__PURE__ */ new Map());
41137
+ const createInteraction = (0, import_react22.useCallback)(
41041
41138
  (id2, type, data) => {
41042
41139
  return new Promise((resolve, reject) => {
41043
41140
  const interaction = {
@@ -41068,7 +41165,7 @@ function UIInteractionProvider({
41068
41165
  },
41069
41166
  [timeout]
41070
41167
  );
41071
- const createDisplayInteraction = (0, import_react21.useCallback)(
41168
+ const createDisplayInteraction = (0, import_react22.useCallback)(
41072
41169
  (id2, displayType, data, result, toolVersion, replacesInteractionId) => {
41073
41170
  setPendingInteractions((prev) => {
41074
41171
  const next = new Map(prev);
@@ -41100,7 +41197,7 @@ function UIInteractionProvider({
41100
41197
  },
41101
41198
  []
41102
41199
  );
41103
- const resolveInteraction = (0, import_react21.useCallback)((id2, result) => {
41200
+ const resolveInteraction = (0, import_react22.useCallback)((id2, result) => {
41104
41201
  setPendingInteractions((prev) => {
41105
41202
  const interaction = prev.get(id2);
41106
41203
  if (!interaction) {
@@ -41117,7 +41214,7 @@ function UIInteractionProvider({
41117
41214
  return next;
41118
41215
  });
41119
41216
  }, []);
41120
- const clearInteractions = (0, import_react21.useCallback)(() => {
41217
+ const clearInteractions = (0, import_react22.useCallback)(() => {
41121
41218
  for (const timer of timersRef.current.values()) {
41122
41219
  clearTimeout(timer);
41123
41220
  }
@@ -41131,7 +41228,7 @@ function UIInteractionProvider({
41131
41228
  return /* @__PURE__ */ new Map();
41132
41229
  });
41133
41230
  }, []);
41134
- const cancelInteraction = (0, import_react21.useCallback)((id2) => {
41231
+ const cancelInteraction = (0, import_react22.useCallback)((id2) => {
41135
41232
  setPendingInteractions((prev) => {
41136
41233
  const interaction = prev.get(id2);
41137
41234
  if (!interaction) {
@@ -41148,13 +41245,13 @@ function UIInteractionProvider({
41148
41245
  return next;
41149
41246
  });
41150
41247
  }, []);
41151
- const getInteraction = (0, import_react21.useCallback)(
41248
+ const getInteraction = (0, import_react22.useCallback)(
41152
41249
  (id2) => {
41153
41250
  return pendingInteractions.get(id2);
41154
41251
  },
41155
41252
  [pendingInteractions]
41156
41253
  );
41157
- const contextValue = (0, import_react21.useMemo)(
41254
+ const contextValue = (0, import_react22.useMemo)(
41158
41255
  () => ({
41159
41256
  pendingInteractions,
41160
41257
  createInteraction,
@@ -41174,11 +41271,11 @@ function UIInteractionProvider({
41174
41271
  getInteraction
41175
41272
  ]
41176
41273
  );
41177
- return (0, import_react21.createElement)(UIInteractionContext.Provider, { value: contextValue }, children);
41274
+ return (0, import_react22.createElement)(UIInteractionContext.Provider, { value: contextValue }, children);
41178
41275
  }
41179
41276
 
41180
41277
  // src/react/useVoice.ts
41181
- var import_react22 = require("react");
41278
+ var import_react23 = require("react");
41182
41279
  function getOnDeviceSpeechRecognition() {
41183
41280
  if (typeof window === "undefined") return null;
41184
41281
  if (!/iPhone|iPad|iPod/.test(navigator.userAgent)) return null;
@@ -41230,24 +41327,24 @@ async function audioToFloat32(blob) {
41230
41327
  }
41231
41328
  }
41232
41329
  function useVoice(options) {
41233
- const [isRecording, setIsRecording] = (0, import_react22.useState)(false);
41234
- const [isTranscribing, setIsTranscribing] = (0, import_react22.useState)(false);
41235
- const [isModelLoaded, setIsModelLoaded] = (0, import_react22.useState)(false);
41236
- const [isLoadingModel, setIsLoadingModel] = (0, import_react22.useState)(false);
41237
- const [recording, setRecording] = (0, import_react22.useState)(null);
41238
- const [transcription, setTranscription] = (0, import_react22.useState)(null);
41239
- const [error, setError] = (0, import_react22.useState)(null);
41240
- const mediaRecorderRef = (0, import_react22.useRef)(null);
41241
- const mediaStreamRef = (0, import_react22.useRef)(null);
41242
- const chunksRef = (0, import_react22.useRef)([]);
41243
- const startTimeRef = (0, import_react22.useRef)(0);
41244
- const pipelineRef = (0, import_react22.useRef)(null);
41245
- const modelNameRef = (0, import_react22.useRef)(null);
41246
- const getModelName = (0, import_react22.useCallback)(() => {
41330
+ const [isRecording, setIsRecording] = (0, import_react23.useState)(false);
41331
+ const [isTranscribing, setIsTranscribing] = (0, import_react23.useState)(false);
41332
+ const [isModelLoaded, setIsModelLoaded] = (0, import_react23.useState)(false);
41333
+ const [isLoadingModel, setIsLoadingModel] = (0, import_react23.useState)(false);
41334
+ const [recording, setRecording] = (0, import_react23.useState)(null);
41335
+ const [transcription, setTranscription] = (0, import_react23.useState)(null);
41336
+ const [error, setError] = (0, import_react23.useState)(null);
41337
+ const mediaRecorderRef = (0, import_react23.useRef)(null);
41338
+ const mediaStreamRef = (0, import_react23.useRef)(null);
41339
+ const chunksRef = (0, import_react23.useRef)([]);
41340
+ const startTimeRef = (0, import_react23.useRef)(0);
41341
+ const pipelineRef = (0, import_react23.useRef)(null);
41342
+ const modelNameRef = (0, import_react23.useRef)(null);
41343
+ const getModelName = (0, import_react23.useCallback)(() => {
41247
41344
  const model = options?.model ?? "whisper-tiny";
41248
41345
  return `onnx-community/${model}`;
41249
41346
  }, [options?.model]);
41250
- const loadPipeline = (0, import_react22.useCallback)(async () => {
41347
+ const loadPipeline = (0, import_react23.useCallback)(async () => {
41251
41348
  const modelName = getModelName();
41252
41349
  if (pipelineRef.current && modelNameRef.current === modelName) {
41253
41350
  return pipelineRef.current;
@@ -41282,10 +41379,10 @@ function useVoice(options) {
41282
41379
  setIsLoadingModel(false);
41283
41380
  }
41284
41381
  }, [getModelName, options?.onModelProgress]);
41285
- const preloadModel = (0, import_react22.useCallback)(async () => {
41382
+ const preloadModel = (0, import_react23.useCallback)(async () => {
41286
41383
  await loadPipeline();
41287
41384
  }, [loadPipeline]);
41288
- const disposeModel = (0, import_react22.useCallback)(async () => {
41385
+ const disposeModel = (0, import_react23.useCallback)(async () => {
41289
41386
  const pipe = pipelineRef.current;
41290
41387
  if (pipe?.dispose) {
41291
41388
  await pipe.dispose();
@@ -41294,7 +41391,7 @@ function useVoice(options) {
41294
41391
  modelNameRef.current = null;
41295
41392
  setIsModelLoaded(false);
41296
41393
  }, []);
41297
- const startRecording = (0, import_react22.useCallback)(async () => {
41394
+ const startRecording = (0, import_react23.useCallback)(async () => {
41298
41395
  setError(null);
41299
41396
  setRecording(null);
41300
41397
  setTranscription(null);
@@ -41319,7 +41416,7 @@ function useVoice(options) {
41319
41416
  throw processedError;
41320
41417
  }
41321
41418
  }, []);
41322
- const stopRecording = (0, import_react22.useCallback)(async () => {
41419
+ const stopRecording = (0, import_react23.useCallback)(async () => {
41323
41420
  return new Promise((resolve, reject) => {
41324
41421
  const recorder = mediaRecorderRef.current;
41325
41422
  if (!recorder || recorder.state === "inactive") {
@@ -41349,7 +41446,7 @@ function useVoice(options) {
41349
41446
  recorder.stop();
41350
41447
  });
41351
41448
  }, []);
41352
- const transcribe = (0, import_react22.useCallback)(
41449
+ const transcribe = (0, import_react23.useCallback)(
41353
41450
  async (rec) => {
41354
41451
  const target = rec ?? recording;
41355
41452
  if (!target) {
@@ -41382,12 +41479,12 @@ function useVoice(options) {
41382
41479
  },
41383
41480
  [recording, loadPipeline, options?.language]
41384
41481
  );
41385
- const nativeSpeechAvailable = (0, import_react22.useMemo)(() => getOnDeviceSpeechRecognition() !== null, []);
41386
- const [isNativeListening, setIsNativeListening] = (0, import_react22.useState)(false);
41387
- const nativeRecognitionRef = (0, import_react22.useRef)(null);
41388
- const nativeTextRef = (0, import_react22.useRef)("");
41389
- const nativeResolveRef = (0, import_react22.useRef)(null);
41390
- const startNativeTranscription = (0, import_react22.useCallback)(() => {
41482
+ const nativeSpeechAvailable = (0, import_react23.useMemo)(() => getOnDeviceSpeechRecognition() !== null, []);
41483
+ const [isNativeListening, setIsNativeListening] = (0, import_react23.useState)(false);
41484
+ const nativeRecognitionRef = (0, import_react23.useRef)(null);
41485
+ const nativeTextRef = (0, import_react23.useRef)("");
41486
+ const nativeResolveRef = (0, import_react23.useRef)(null);
41487
+ const startNativeTranscription = (0, import_react23.useCallback)(() => {
41391
41488
  const SR = getOnDeviceSpeechRecognition();
41392
41489
  if (!SR) return;
41393
41490
  nativeTextRef.current = "";
@@ -41424,7 +41521,7 @@ function useVoice(options) {
41424
41521
  recognition.start();
41425
41522
  setIsNativeListening(true);
41426
41523
  }, [options?.language]);
41427
- const stopNativeTranscription = (0, import_react22.useCallback)(() => {
41524
+ const stopNativeTranscription = (0, import_react23.useCallback)(() => {
41428
41525
  return new Promise((resolve) => {
41429
41526
  const recognition = nativeRecognitionRef.current;
41430
41527
  if (!recognition) {
@@ -41435,7 +41532,7 @@ function useVoice(options) {
41435
41532
  recognition.stop();
41436
41533
  });
41437
41534
  }, []);
41438
- const abortNativeTranscription = (0, import_react22.useCallback)(() => {
41535
+ const abortNativeTranscription = (0, import_react23.useCallback)(() => {
41439
41536
  const recognition = nativeRecognitionRef.current;
41440
41537
  if (recognition) {
41441
41538
  nativeResolveRef.current = null;
@@ -41466,24 +41563,24 @@ function useVoice(options) {
41466
41563
  }
41467
41564
 
41468
41565
  // src/react/useWalletBinding.ts
41469
- var import_react23 = require("react");
41566
+ var import_react24 = require("react");
41470
41567
  init_clientConfig();
41471
41568
  function useWalletBinding(options = {}) {
41472
41569
  const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
41473
- const [wallets, setWallets] = (0, import_react23.useState)([]);
41474
- const [totals, setTotals] = (0, import_react23.useState)(null);
41475
- const [isLoading, setIsLoading] = (0, import_react23.useState)(false);
41476
- const [error, setError] = (0, import_react23.useState)(null);
41477
- const getTokenRef = (0, import_react23.useRef)(getToken);
41478
- const baseUrlRef = (0, import_react23.useRef)(baseUrl);
41479
- const onErrorRef = (0, import_react23.useRef)(onError);
41480
- const abortControllerRef = (0, import_react23.useRef)(null);
41481
- (0, import_react23.useEffect)(() => {
41570
+ const [wallets, setWallets] = (0, import_react24.useState)([]);
41571
+ const [totals, setTotals] = (0, import_react24.useState)(null);
41572
+ const [isLoading, setIsLoading] = (0, import_react24.useState)(false);
41573
+ const [error, setError] = (0, import_react24.useState)(null);
41574
+ const getTokenRef = (0, import_react24.useRef)(getToken);
41575
+ const baseUrlRef = (0, import_react24.useRef)(baseUrl);
41576
+ const onErrorRef = (0, import_react24.useRef)(onError);
41577
+ const abortControllerRef = (0, import_react24.useRef)(null);
41578
+ (0, import_react24.useEffect)(() => {
41482
41579
  getTokenRef.current = getToken;
41483
41580
  baseUrlRef.current = baseUrl;
41484
41581
  onErrorRef.current = onError;
41485
41582
  });
41486
- (0, import_react23.useEffect)(() => {
41583
+ (0, import_react24.useEffect)(() => {
41487
41584
  return () => {
41488
41585
  if (abortControllerRef.current) {
41489
41586
  abortControllerRef.current.abort();
@@ -41491,7 +41588,7 @@ function useWalletBinding(options = {}) {
41491
41588
  }
41492
41589
  };
41493
41590
  }, []);
41494
- const getHeaders = (0, import_react23.useCallback)(async () => {
41591
+ const getHeaders = (0, import_react24.useCallback)(async () => {
41495
41592
  const headers = {};
41496
41593
  if (getTokenRef.current) {
41497
41594
  const token = await getTokenRef.current();
@@ -41501,13 +41598,13 @@ function useWalletBinding(options = {}) {
41501
41598
  }
41502
41599
  return headers;
41503
41600
  }, []);
41504
- const handleError = (0, import_react23.useCallback)((err) => {
41601
+ const handleError = (0, import_react24.useCallback)((err) => {
41505
41602
  const error2 = err instanceof Error ? err : new Error(String(err));
41506
41603
  setError(error2);
41507
41604
  onErrorRef.current?.(error2);
41508
41605
  return error2;
41509
41606
  }, []);
41510
- const fetchBinding = (0, import_react23.useCallback)(async () => {
41607
+ const fetchBinding = (0, import_react24.useCallback)(async () => {
41511
41608
  if (abortControllerRef.current) {
41512
41609
  abortControllerRef.current.abort();
41513
41610
  }
@@ -41545,12 +41642,12 @@ function useWalletBinding(options = {}) {
41545
41642
  }
41546
41643
  }
41547
41644
  }, [getHeaders, handleError]);
41548
- const refetch = (0, import_react23.useCallback)(async () => {
41645
+ const refetch = (0, import_react24.useCallback)(async () => {
41549
41646
  setWallets([]);
41550
41647
  setTotals(null);
41551
41648
  await fetchBinding();
41552
41649
  }, [fetchBinding]);
41553
- const getNonce = (0, import_react23.useCallback)(async () => {
41650
+ const getNonce = (0, import_react24.useCallback)(async () => {
41554
41651
  setIsLoading(true);
41555
41652
  setError(null);
41556
41653
  try {
@@ -41571,7 +41668,7 @@ function useWalletBinding(options = {}) {
41571
41668
  setIsLoading(false);
41572
41669
  }
41573
41670
  }, [getHeaders, handleError]);
41574
- const bindWallet = (0, import_react23.useCallback)(
41671
+ const bindWallet = (0, import_react24.useCallback)(
41575
41672
  async (request) => {
41576
41673
  setIsLoading(true);
41577
41674
  setError(null);
@@ -41597,7 +41694,7 @@ function useWalletBinding(options = {}) {
41597
41694
  },
41598
41695
  [getHeaders, handleError, fetchBinding]
41599
41696
  );
41600
- const unbindWallet = (0, import_react23.useCallback)(
41697
+ const unbindWallet = (0, import_react24.useCallback)(
41601
41698
  async (address) => {
41602
41699
  setIsLoading(true);
41603
41700
  setError(null);
@@ -41623,8 +41720,8 @@ function useWalletBinding(options = {}) {
41623
41720
  },
41624
41721
  [getHeaders, handleError, fetchBinding]
41625
41722
  );
41626
- const hasFetchedRef = (0, import_react23.useRef)(false);
41627
- (0, import_react23.useEffect)(() => {
41723
+ const hasFetchedRef = (0, import_react24.useRef)(false);
41724
+ (0, import_react24.useEffect)(() => {
41628
41725
  if (autoFetch && !hasFetchedRef.current) {
41629
41726
  hasFetchedRef.current = true;
41630
41727
  void fetchBinding();