@anuma/sdk 10.2.2 → 10.2.4

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);
@@ -10514,6 +10521,9 @@ var StreamSmoother = class {
10514
10521
  this.rampDuration = config.rampDuration ?? 4e3;
10515
10522
  }
10516
10523
  }
10524
+ get hasPendingOutput() {
10525
+ return this.buffer.length > 0;
10526
+ }
10517
10527
  /**
10518
10528
  * Add text to the buffer. If smoothing is disabled, passes through immediately.
10519
10529
  */
@@ -11182,6 +11192,34 @@ async function runToolLoop(options) {
11182
11192
  toolsChecksum: acc.toolsChecksum
11183
11193
  };
11184
11194
  };
11195
+ const drainSmoothers = async (acc, smoothers) => {
11196
+ let playbackAborted = false;
11197
+ const stopPlayback = () => {
11198
+ for (const smoother of smoothers) {
11199
+ if (isDetach()) smoother.flush();
11200
+ else smoother.destroy();
11201
+ }
11202
+ };
11203
+ const onAbort = () => {
11204
+ playbackAborted = !isDetach() && smoothers.some((smoother) => smoother.hasPendingOutput);
11205
+ stopPlayback();
11206
+ };
11207
+ combinedSignal?.addEventListener("abort", onAbort, { once: true });
11208
+ try {
11209
+ if (combinedSignal?.aborted) stopPlayback();
11210
+ await Promise.all(smoothers.map((smoother) => smoother.drain()));
11211
+ if (!playbackAborted) return;
11212
+ await fireAfterModelCall(buildModelCallEndPayload(acc, { error: "aborted" }));
11213
+ await fireRunError({ error: "Request aborted", stage: "model" });
11214
+ return {
11215
+ data: buildResponseFinal(acc),
11216
+ error: "Request aborted",
11217
+ toolsChecksum: acc.toolsChecksum
11218
+ };
11219
+ } finally {
11220
+ combinedSignal?.removeEventListener("abort", onAbort);
11221
+ }
11222
+ };
11185
11223
  for (let attempt = 0; attempt < STREAM_RETRY_MAX_ATTEMPTS; attempt++) {
11186
11224
  sseError = null;
11187
11225
  if (combinedSignal?.aborted) {
@@ -11319,7 +11357,8 @@ async function runToolLoop(options) {
11319
11357
  contentSmoother.flush();
11320
11358
  thinkingSmoother.flush();
11321
11359
  } else {
11322
- await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
11360
+ const interrupted = await drainSmoothers(accumulator, [contentSmoother, thinkingSmoother]);
11361
+ if (interrupted) return interrupted;
11323
11362
  }
11324
11363
  flushDeAnon();
11325
11364
  await fireAfterModelCall(buildModelCallEndPayload(accumulator));
@@ -11838,7 +11877,11 @@ Executing tool: ${toolInfo}
11838
11877
  contContentSmoother.flush();
11839
11878
  contThinkingSmoother.flush();
11840
11879
  } else {
11841
- await Promise.all([contContentSmoother.drain(), contThinkingSmoother.drain()]);
11880
+ const interrupted = await drainSmoothers(currentAccumulator, [
11881
+ contContentSmoother,
11882
+ contThinkingSmoother
11883
+ ]);
11884
+ if (interrupted) return interrupted;
11842
11885
  }
11843
11886
  flushDeAnon();
11844
11887
  await fireAfterModelCall(buildModelCallEndPayload(currentAccumulator));
@@ -11969,6 +12012,8 @@ async function resumeStream(options) {
11969
12012
  let watchdog;
11970
12013
  let idleFired = false;
11971
12014
  let callerAborted = false;
12015
+ let playbackAborted = false;
12016
+ let draining = false;
11972
12017
  let settled = false;
11973
12018
  const idleEnabled = idleTimeoutMs > 0 && idleTimeoutMs !== Infinity && typeof setTimeout === "function";
11974
12019
  const armWatchdog = () => {
@@ -11988,6 +12033,9 @@ async function resumeStream(options) {
11988
12033
  const abortMessage = () => callerAborted ? "Resume aborted" : idleFired ? "Resume timed out" : "Resume aborted";
11989
12034
  const onCallerAbort = () => {
11990
12035
  callerAborted = true;
12036
+ playbackAborted = draining && (contentSmoother.hasPendingOutput || thinkingSmoother.hasPendingOutput);
12037
+ contentSmoother.destroy();
12038
+ thinkingSmoother.destroy();
11991
12039
  disarmWatchdog();
11992
12040
  idleController.abort();
11993
12041
  };
@@ -12071,15 +12119,24 @@ async function resumeStream(options) {
12071
12119
  statusCode
12072
12120
  };
12073
12121
  }
12074
- cleanup();
12075
- if (accumulator.toolCalls.size > 0) {
12076
- return buildInterrupted("Stream ended with a pending tool request");
12122
+ settled = true;
12123
+ disarmWatchdog();
12124
+ try {
12125
+ if (idleFired) return buildInterrupted(abortMessage());
12126
+ if (accumulator.toolCalls.size > 0) {
12127
+ return buildInterrupted("Stream ended with a pending tool request");
12128
+ }
12129
+ draining = true;
12130
+ await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
12131
+ if (playbackAborted) return buildInterrupted(abortMessage());
12132
+ const response = strategy.buildFinalResponse(accumulator);
12133
+ const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
12134
+ if (onFinish && deliveredOutput) onFinish(response);
12135
+ return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
12136
+ } finally {
12137
+ draining = false;
12138
+ cleanup();
12077
12139
  }
12078
- await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
12079
- const response = strategy.buildFinalResponse(accumulator);
12080
- const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
12081
- if (onFinish && deliveredOutput) onFinish(response);
12082
- return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
12083
12140
  }
12084
12141
 
12085
12142
  // src/lib/chat/stockPriceCentroids.ts
@@ -21851,11 +21908,11 @@ function loadVaultCorpus(ctx, options, preparation) {
21851
21908
  }
21852
21909
  return request;
21853
21910
  }
21854
- function rowRequestsFor(registry2, ctx, maskInput) {
21855
- let byMask = registry2.get(ctx);
21911
+ function rowRequestsFor(registry3, ctx, maskInput) {
21912
+ let byMask = registry3.get(ctx);
21856
21913
  if (!byMask) {
21857
21914
  byMask = /* @__PURE__ */ new Map();
21858
- registry2.set(ctx, byMask);
21915
+ registry3.set(ctx, byMask);
21859
21916
  }
21860
21917
  let requests = byMask.get(maskInput);
21861
21918
  if (!requests) {
@@ -22790,11 +22847,11 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
22790
22847
  };
22791
22848
  }
22792
22849
  const limit = searchOptions?.limit ?? 5;
22793
- const scopes = searchOptions?.scopes;
22850
+ const scopes2 = searchOptions?.scopes;
22794
22851
  const folderId = searchOptions?.folderId;
22795
22852
  const queryOpts = {};
22796
22853
  if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
22797
- if (scopes?.length) queryOpts.scopes = scopes;
22854
+ if (scopes2?.length) queryOpts.scopes = scopes2;
22798
22855
  if (folderId !== void 0) queryOpts.folderId = folderId;
22799
22856
  if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
22800
22857
  if (searchOptions?.includeArchived) queryOpts.includeArchived = true;
@@ -29106,17 +29163,17 @@ async function synthesizeProfile(ctx, options = {}) {
29106
29163
  }
29107
29164
  const recallCtx = store ? { embeddingOptions: ctx.embeddingOptions, factSource: store.factSource } : ctx;
29108
29165
  const facets = options.facets ?? DEFAULT_PROFILE_FACETS;
29109
- const scopes = options.scopes ?? DEFAULT_SCOPES;
29166
+ const scopes2 = options.scopes ?? DEFAULT_SCOPES;
29110
29167
  const config = {
29111
29168
  facetKeys: facets.map((f) => f.key).sort(),
29112
29169
  facetsSignature: facetsSignature(facets),
29113
- scopes: [...scopes].sort(),
29170
+ scopes: [...scopes2].sort(),
29114
29171
  redacted: options.redactor !== void 0,
29115
29172
  reviewedMemoryIdsSignature: reviewedMemoryIdsSignature(options.reviewedMemoryIds)
29116
29173
  };
29117
29174
  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 }), []];
29175
+ const listOptions = { scopes: scopes2, includeDeleted: true, includeSuperseded: true };
29176
+ const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes: scopes2 }), []];
29120
29177
  const watermark = computeVaultWatermark(memories);
29121
29178
  const observationTrends = summarizeObservationTrends(
29122
29179
  memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
@@ -29161,7 +29218,7 @@ async function synthesizeProfile(ctx, options = {}) {
29161
29218
  for (const section of previous.sections) {
29162
29219
  if (section.sourceMemoryIds.length > 0 && section.sourceMemoryIds.every((id2) => {
29163
29220
  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;
29221
+ return memory && !memory.isDeleted && !memory.supersededBy && scopes2.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
29165
29222
  })) {
29166
29223
  fallbackPriors.set(section.key, section);
29167
29224
  }
@@ -29334,7 +29391,7 @@ async function attributeFacts(ctx, candidates, facets) {
29334
29391
  return keys;
29335
29392
  }
29336
29393
  async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
29337
- const scopes = options.scopes ?? DEFAULT_SCOPES;
29394
+ const scopes2 = options.scopes ?? DEFAULT_SCOPES;
29338
29395
  const limit = options.limit ?? DEFAULT_FACET_RECALL_LIMIT;
29339
29396
  const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
29340
29397
  const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
@@ -29351,7 +29408,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
29351
29408
  }
29352
29409
  const recalled = await recall(facet.query, ctx, {
29353
29410
  vaultPreparation,
29354
- scopes,
29411
+ scopes: scopes2,
29355
29412
  limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
29356
29413
  ...hasReviewGate && { memoryIds: [...reviewed] },
29357
29414
  types: ["fact"],
@@ -29378,7 +29435,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
29378
29435
  llmModel: options.llmModel ?? DEFAULT_SYNTHESIS_MODEL,
29379
29436
  baseUrl: options.baseUrl,
29380
29437
  fetchFn: options.fetchFn,
29381
- scopes,
29438
+ scopes: scopes2,
29382
29439
  limit,
29383
29440
  types: ["fact"],
29384
29441
  maxTokens: DEFAULT_FACET_MAX_TOKENS,
@@ -32301,8 +32358,8 @@ var ZipProcessor = class {
32301
32358
  * Set the processor registry for handling nested files
32302
32359
  * This must be called before processing if you want nested file support
32303
32360
  */
32304
- setRegistry(registry2) {
32305
- this.registry = registry2;
32361
+ setRegistry(registry3) {
32362
+ this.registry = registry3;
32306
32363
  }
32307
32364
  async process(file) {
32308
32365
  try {
@@ -32523,15 +32580,15 @@ function isImageFile(file) {
32523
32580
  return (file.type ?? "").trim().toLowerCase().startsWith("image/");
32524
32581
  }
32525
32582
  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());
32583
+ const registry3 = new ProcessorRegistry();
32584
+ registry3.register(new PdfProcessor());
32585
+ registry3.register(new ExcelProcessor());
32586
+ registry3.register(new WordProcessor());
32587
+ registry3.register(new TextProcessor());
32531
32588
  const zipProcessor = new ZipProcessor();
32532
- zipProcessor.setRegistry(registry2);
32533
- registry2.register(zipProcessor);
32534
- return registry2;
32589
+ zipProcessor.setRegistry(registry3);
32590
+ registry3.register(zipProcessor);
32591
+ return registry3;
32535
32592
  }
32536
32593
  var cachedDefaultRegistry = null;
32537
32594
  function getDefaultRegistry() {
@@ -32544,10 +32601,10 @@ function isSupportedFile(file) {
32544
32601
  return getDefaultRegistry().isSupported(file);
32545
32602
  }
32546
32603
  function getSupportedFileTypes() {
32547
- const registry2 = getDefaultRegistry();
32604
+ const registry3 = getDefaultRegistry();
32548
32605
  return {
32549
- mimeTypes: registry2.getSupportedMimeTypes(),
32550
- extensions: registry2.getSupportedExtensions()
32606
+ mimeTypes: registry3.getSupportedMimeTypes(),
32607
+ extensions: registry3.getSupportedExtensions()
32551
32608
  };
32552
32609
  }
32553
32610
  function formatExtractedContent(fileName, content, format) {
@@ -32602,16 +32659,16 @@ async function preprocessFiles(files, options = {}) {
32602
32659
  metadata: { processedCount: 0, skippedCount: fileStatuses2.length, errorCount: 0 }
32603
32660
  };
32604
32661
  }
32605
- let registry2;
32662
+ let registry3;
32606
32663
  if (processors === void 0) {
32607
- registry2 = getDefaultRegistry();
32664
+ registry3 = getDefaultRegistry();
32608
32665
  } else {
32609
- registry2 = new ProcessorRegistry();
32666
+ registry3 = new ProcessorRegistry();
32610
32667
  processors.forEach((p) => {
32611
32668
  if (p instanceof ZipProcessor) {
32612
- p.setRegistry(registry2);
32669
+ p.setRegistry(registry3);
32613
32670
  }
32614
- registry2.register(p);
32671
+ registry3.register(p);
32615
32672
  });
32616
32673
  }
32617
32674
  const extractedTexts = [];
@@ -32631,7 +32688,7 @@ async function preprocessFiles(files, options = {}) {
32631
32688
  fileStatuses.push({ fileId: file.id, fileName: file.name, status: "skipped", reason });
32632
32689
  };
32633
32690
  onProgress?.(i + 1, files.length, file.name);
32634
- const processor = registry2.findProcessor(file);
32691
+ const processor = registry3.findProcessor(file);
32635
32692
  if (!processor && isImageFile(file)) continue;
32636
32693
  if (file.size > maxFileSizeBytes) {
32637
32694
  logger.info(
@@ -35698,7 +35755,7 @@ function useChat(options) {
35698
35755
  }
35699
35756
 
35700
35757
  // src/react/useChatStorage.ts
35701
- var import_react6 = require("react");
35758
+ var import_react7 = require("react");
35702
35759
  var import_uuid8 = require("uuid");
35703
35760
  init_clientConfig();
35704
35761
 
@@ -36271,6 +36328,107 @@ function summaryStore(options) {
36271
36328
  init_logger();
36272
36329
  init_redactor();
36273
36330
 
36331
+ // src/lib/pii/useConversationRedactors.ts
36332
+ var import_react5 = require("react");
36333
+ init_redactor();
36334
+ var REDACTOR_LIMIT = 50;
36335
+ var registry2 = /* @__PURE__ */ new WeakMap();
36336
+ var compositeKeys = /* @__PURE__ */ new WeakMap();
36337
+ var scopes = /* @__PURE__ */ new Set();
36338
+ var retiredRedactor = new PiiRedactor();
36339
+ retiredRedactor.dispose();
36340
+ function retireScope(scope) {
36341
+ scopes.delete(scope);
36342
+ if (!scope.active) return;
36343
+ scope.active = false;
36344
+ for (const { redactor } of scope.redactors.values()) redactor.dispose();
36345
+ scope.redactors.clear();
36346
+ for (const redactor of scope.evicted) redactor.dispose();
36347
+ scope.evicted = [];
36348
+ for (const notify of scope.subscribers) notify();
36349
+ }
36350
+ function storageKey(storage, secondaryStorage) {
36351
+ if (!secondaryStorage) return storage;
36352
+ let inner = compositeKeys.get(storage);
36353
+ if (!inner) {
36354
+ inner = /* @__PURE__ */ new WeakMap();
36355
+ compositeKeys.set(storage, inner);
36356
+ }
36357
+ let key3 = inner.get(secondaryStorage);
36358
+ if (!key3) {
36359
+ key3 = {};
36360
+ inner.set(secondaryStorage, key3);
36361
+ }
36362
+ return key3;
36363
+ }
36364
+ function getScope(database, storage, account) {
36365
+ let stores = registry2.get(database);
36366
+ if (!stores) {
36367
+ stores = /* @__PURE__ */ new WeakMap();
36368
+ registry2.set(database, stores);
36369
+ }
36370
+ let accounts = stores.get(storage);
36371
+ if (!accounts) {
36372
+ accounts = /* @__PURE__ */ new Map();
36373
+ stores.set(storage, accounts);
36374
+ }
36375
+ let scope = accounts.get(account);
36376
+ if (!scope?.active) {
36377
+ scope = { active: true, users: 0, subscribers: /* @__PURE__ */ new Set(), redactors: /* @__PURE__ */ new Map(), evicted: [] };
36378
+ accounts.set(account, scope);
36379
+ }
36380
+ return scope;
36381
+ }
36382
+ onClearAllEncryptionState(() => {
36383
+ registry2 = /* @__PURE__ */ new WeakMap();
36384
+ for (const scope of [...scopes]) retireScope(scope);
36385
+ });
36386
+ function useConversationRedactors(database, account, storage, secondaryStorage) {
36387
+ const scope = getScope(database, storageKey(storage, secondaryStorage), account);
36388
+ const subscribe = (0, import_react5.useCallback)(
36389
+ (callback) => {
36390
+ scope.subscribers.add(callback);
36391
+ return () => {
36392
+ scope.subscribers.delete(callback);
36393
+ };
36394
+ },
36395
+ [scope]
36396
+ );
36397
+ const getSnapshot = (0, import_react5.useCallback)(() => scope.active ? scope : null, [scope]);
36398
+ (0, import_react5.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
36399
+ (0, import_react5.useEffect)(() => {
36400
+ if (scope.active) scopes.add(scope);
36401
+ scope.users++;
36402
+ return () => {
36403
+ scope.users--;
36404
+ if (scope.users === 0) retireScope(scope);
36405
+ };
36406
+ }, [scope]);
36407
+ return (0, import_react5.useCallback)(
36408
+ (conversationId, nerDetector) => {
36409
+ if (!scope.active) return retiredRedactor;
36410
+ const cached = scope.redactors.get(conversationId);
36411
+ if (cached && cached.detector === nerDetector) {
36412
+ scope.redactors.delete(conversationId);
36413
+ scope.redactors.set(conversationId, cached);
36414
+ return cached.redactor;
36415
+ }
36416
+ if (cached) scope.evicted.push(cached.redactor);
36417
+ const redactor = new PiiRedactor({ nerDetector });
36418
+ scope.redactors.set(conversationId, { redactor, detector: nerDetector });
36419
+ if (scope.redactors.size > REDACTOR_LIMIT) {
36420
+ const oldest = scope.redactors.entries().next().value;
36421
+ if (oldest) {
36422
+ scope.evicted.push(oldest[1].redactor);
36423
+ scope.redactors.delete(oldest[0]);
36424
+ }
36425
+ }
36426
+ return redactor;
36427
+ },
36428
+ [scope]
36429
+ );
36430
+ }
36431
+
36274
36432
  // src/lib/tools/selection/activeToolSets.ts
36275
36433
  function mergeActiveToolSets(current, derived) {
36276
36434
  if (derived.length === 0) return current;
@@ -36331,7 +36489,7 @@ function resetRecentToolSets() {
36331
36489
  onClearAllEncryptionState(resetRecentToolSets);
36332
36490
 
36333
36491
  // src/react/useChatMedia.ts
36334
- var import_react5 = require("react");
36492
+ var import_react6 = require("react");
36335
36493
  init_logger();
36336
36494
  function resolveMediaMeta(extractedKind, urlPath, reportedType) {
36337
36495
  const isVideo = extractedKind === "video";
@@ -36345,7 +36503,7 @@ function resolveMediaMeta(extractedKind, urlPath, reportedType) {
36345
36503
  }
36346
36504
  function useChatMedia(options) {
36347
36505
  const { mediaCtx, mcpR2Domain } = options;
36348
- const getImageDimensions = (0, import_react5.useCallback)(
36506
+ const getImageDimensions = (0, import_react6.useCallback)(
36349
36507
  async (blob) => {
36350
36508
  if (!blob.type.startsWith("image/")) {
36351
36509
  return void 0;
@@ -36372,7 +36530,7 @@ function useChatMedia(options) {
36372
36530
  },
36373
36531
  []
36374
36532
  );
36375
- const extractAndStoreEncryptedMCPImages = (0, import_react5.useCallback)(
36533
+ const extractAndStoreEncryptedMCPImages = (0, import_react6.useCallback)(
36376
36534
  async (content, address, conversationId, toolCallEvents) => {
36377
36535
  let imageModel;
36378
36536
  try {
@@ -36477,7 +36635,7 @@ function useChatMedia(options) {
36477
36635
  },
36478
36636
  [mediaCtx, getImageDimensions, mcpR2Domain]
36479
36637
  );
36480
- const storeUserFilesInOPFS = (0, import_react5.useCallback)(
36638
+ const storeUserFilesInOPFS = (0, import_react6.useCallback)(
36481
36639
  async (files, address, conversationId, maxFileSizeBytes) => {
36482
36640
  const canUseOPFS = isOPFSSupported() && hasEncryptionKey(address);
36483
36641
  let encryptionKey;
@@ -36839,29 +36997,10 @@ async function storedToLlmapiMessage(stored2, encryptionKey, resolveMediaByIds)
36839
36997
  }
36840
36998
  return messages;
36841
36999
  }
36842
- var CONVERSATION_REDACTOR_LIMIT = 50;
36843
- var NO_CONVERSATION_KEY = "__no_conversation__";
36844
37000
  var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
36845
37001
  var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
36846
37002
  var MEMORY_STORE_NOT_READY = "Memory store is not ready";
36847
- var conversationRedactors = /* @__PURE__ */ new Map();
36848
37003
  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
37004
  function resolveCallPii(requestPiiRedaction, hookPiiRedaction, getConversationRedactorFor) {
36866
37005
  const effective = requestPiiRedaction === void 0 ? hookPiiRedaction : requestPiiRedaction;
36867
37006
  const redactor = effective === true ? getConversationRedactorFor() : isPiiRedactor(effective) ? effective : void 0;
@@ -36911,45 +37050,51 @@ function useChatStorage(options) {
36911
37050
  toolResultsHistoryExclude,
36912
37051
  foldToolResultsInHistory
36913
37052
  } = options;
36914
- const [currentConversationId, setCurrentConversationId] = (0, import_react6.useState)(
37053
+ const [currentConversationId, setCurrentConversationId] = (0, import_react7.useState)(
36915
37054
  initialConversationId || null
36916
37055
  );
36917
- const toolResultsHistoryExcludeRef = (0, import_react6.useRef)(toolResultsHistoryExclude);
37056
+ const toolResultsHistoryExcludeRef = (0, import_react7.useRef)(toolResultsHistoryExclude);
36918
37057
  toolResultsHistoryExcludeRef.current = toolResultsHistoryExclude;
36919
- const foldToolResultsInHistoryRef = (0, import_react6.useRef)(foldToolResultsInHistory);
37058
+ const foldToolResultsInHistoryRef = (0, import_react7.useRef)(foldToolResultsInHistory);
36920
37059
  foldToolResultsInHistoryRef.current = foldToolResultsInHistory;
36921
- const nerDetectorRef = (0, import_react6.useRef)(nerDetector);
37060
+ const nerDetectorRef = (0, import_react7.useRef)(nerDetector);
36922
37061
  nerDetectorRef.current = nerDetector;
36923
- const resolvedPiiRedaction = (0, import_react6.useMemo)(
37062
+ const getConversationRedactor = useConversationRedactors(
37063
+ database,
37064
+ walletAddress,
37065
+ memoryStore ?? chatBackend ?? database,
37066
+ memoryStore && chatBackend ? chatBackend : void 0
37067
+ );
37068
+ const resolvedPiiRedaction = (0, import_react7.useMemo)(
36924
37069
  () => piiRedaction === true ? getConversationRedactor(currentConversationId, nerDetectorRef.current) : piiRedaction,
36925
- [piiRedaction, currentConversationId]
37070
+ [piiRedaction, currentConversationId, getConversationRedactor]
36926
37071
  );
36927
- const maskForEmbedding = (0, import_react6.useCallback)(
37072
+ const maskForEmbedding = (0, import_react7.useCallback)(
36928
37073
  (text16) => isPiiRedactor(resolvedPiiRedaction) ? resolvedPiiRedaction.maskText(text16) : text16,
36929
37074
  [resolvedPiiRedaction]
36930
37075
  );
36931
- const maskEmbeddingInput = (0, import_react6.useMemo)(
37076
+ const maskEmbeddingInput = (0, import_react7.useMemo)(
36932
37077
  () => isPiiRedactor(resolvedPiiRedaction) ? (text16) => resolvedPiiRedaction.maskText(text16) : void 0,
36933
37078
  [resolvedPiiRedaction]
36934
37079
  );
36935
- const vaultEmbeddingOptions = (0, import_react6.useMemo)(
37080
+ const vaultEmbeddingOptions = (0, import_react7.useMemo)(
36936
37081
  () => ({ getToken, baseUrl, model: embeddingModel, maskInput: maskEmbeddingInput }),
36937
37082
  [getToken, baseUrl, embeddingModel, maskEmbeddingInput]
36938
37083
  );
36939
37084
  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)(() => {
37085
+ const blobManagerRef = (0, import_react7.useRef)(new BlobUrlManager());
37086
+ (0, import_react7.useEffect)(() => {
36942
37087
  const manager = blobManagerRef.current;
36943
37088
  return () => {
36944
37089
  manager.revokeAll();
36945
37090
  };
36946
37091
  }, []);
36947
- const messagesCollection = (0, import_react6.useMemo)(() => database.get("history"), [database]);
36948
- const conversationsCollection = (0, import_react6.useMemo)(
37092
+ const messagesCollection = (0, import_react7.useMemo)(() => database.get("history"), [database]);
37093
+ const conversationsCollection = (0, import_react7.useMemo)(
36949
37094
  () => database.get("conversations"),
36950
37095
  [database]
36951
37096
  );
36952
- const storageCtx = (0, import_react6.useMemo)(
37097
+ const storageCtx = (0, import_react7.useMemo)(
36953
37098
  () => ({
36954
37099
  database,
36955
37100
  messagesCollection,
@@ -36967,19 +37112,19 @@ function useChatStorage(options) {
36967
37112
  embeddedWalletSigner
36968
37113
  ]
36969
37114
  );
36970
- const storageCtxRef = (0, import_react6.useRef)(storageCtx);
37115
+ const storageCtxRef = (0, import_react7.useRef)(storageCtx);
36971
37116
  storageCtxRef.current = storageCtx;
36972
- const backendFactory = (0, import_react6.useMemo)(
37117
+ const backendFactory = (0, import_react7.useMemo)(
36973
37118
  () => chatBackend ?? localChatBackend(database),
36974
37119
  [chatBackend, database]
36975
37120
  );
36976
- const backend = (0, import_react6.useMemo)(
37121
+ const backend = (0, import_react7.useMemo)(
36977
37122
  () => backendFactory({ walletAddress, signMessage, embeddedWalletSigner }),
36978
37123
  [backendFactory, walletAddress, signMessage, embeddedWalletSigner]
36979
37124
  );
36980
- const backendRef = (0, import_react6.useRef)(backend);
37125
+ const backendRef = (0, import_react7.useRef)(backend);
36981
37126
  backendRef.current = backend;
36982
- const mediaCtx = (0, import_react6.useMemo)(
37127
+ const mediaCtx = (0, import_react7.useMemo)(
36983
37128
  () => ({
36984
37129
  database,
36985
37130
  walletAddress,
@@ -36988,13 +37133,13 @@ function useChatStorage(options) {
36988
37133
  }),
36989
37134
  [database, walletAddress, signMessage, embeddedWalletSigner]
36990
37135
  );
36991
- const activeToolSetsRef = (0, import_react6.useRef)(activeToolSets);
37136
+ const activeToolSetsRef = (0, import_react7.useRef)(activeToolSets);
36992
37137
  activeToolSetsRef.current = activeToolSets;
36993
- const vaultMemoryCollection = (0, import_react6.useMemo)(
37138
+ const vaultMemoryCollection = (0, import_react7.useMemo)(
36994
37139
  () => database.get("memory_vault"),
36995
37140
  [database]
36996
37141
  );
36997
- const vaultCtx = (0, import_react6.useMemo)(
37142
+ const vaultCtx = (0, import_react7.useMemo)(
36998
37143
  () => ({
36999
37144
  database,
37000
37145
  vaultMemoryCollection,
@@ -37005,16 +37150,16 @@ function useChatStorage(options) {
37005
37150
  }),
37006
37151
  [database, vaultMemoryCollection, walletAddress, signMessage, embeddedWalletSigner]
37007
37152
  );
37008
- const vaultEmbeddingCache = (0, import_react6.useMemo)(
37153
+ const vaultEmbeddingCache = (0, import_react7.useMemo)(
37009
37154
  () => getVaultEmbeddingCache(database, walletAddress, embeddingModel),
37010
37155
  [database, walletAddress, embeddingModel]
37011
37156
  );
37012
- const entityCollection = (0, import_react6.useMemo)(() => database.get("entity"), [database]);
37013
- const memoryEntityCollection = (0, import_react6.useMemo)(
37157
+ const entityCollection = (0, import_react7.useMemo)(() => database.get("entity"), [database]);
37158
+ const memoryEntityCollection = (0, import_react7.useMemo)(
37014
37159
  () => database.get("memory_entity"),
37015
37160
  [database]
37016
37161
  );
37017
- const entityCtx = (0, import_react6.useMemo)(
37162
+ const entityCtx = (0, import_react7.useMemo)(
37018
37163
  () => ({
37019
37164
  database,
37020
37165
  entityCollection,
@@ -37024,18 +37169,18 @@ function useChatStorage(options) {
37024
37169
  }),
37025
37170
  [database, entityCollection, memoryEntityCollection, walletAddress]
37026
37171
  );
37027
- const [queueStatus, setQueueStatus] = (0, import_react6.useState)({
37172
+ const [queueStatus, setQueueStatus] = (0, import_react7.useState)({
37028
37173
  pending: 0,
37029
37174
  failed: 0,
37030
37175
  isFlushing: false,
37031
37176
  isPaused: false
37032
37177
  });
37033
- const refreshQueueStatus = (0, import_react6.useCallback)(() => {
37178
+ const refreshQueueStatus = (0, import_react7.useCallback)(() => {
37034
37179
  if (walletAddress) {
37035
37180
  setQueueStatus(queueManager.getStatus(walletAddress));
37036
37181
  }
37037
37182
  }, [walletAddress]);
37038
- const executeQueuedOperation = (0, import_react6.useCallback)(
37183
+ const executeQueuedOperation = (0, import_react7.useCallback)(
37039
37184
  async (operation, encCtx) => {
37040
37185
  const queued = queuedBackends.get(operation.payload) ?? backendFactory({
37041
37186
  walletAddress: encCtx.walletAddress,
@@ -37083,7 +37228,7 @@ function useChatStorage(options) {
37083
37228
  },
37084
37229
  [backendFactory, database]
37085
37230
  );
37086
- const flushQueue = (0, import_react6.useCallback)(async () => {
37231
+ const flushQueue = (0, import_react7.useCallback)(async () => {
37087
37232
  if (!walletAddress || !signMessage) {
37088
37233
  return { succeeded: [], failed: [], total: 0 };
37089
37234
  }
@@ -37102,31 +37247,31 @@ function useChatStorage(options) {
37102
37247
  executeQueuedOperation,
37103
37248
  refreshQueueStatus
37104
37249
  ]);
37105
- const clearQueue = (0, import_react6.useCallback)(() => {
37250
+ const clearQueue = (0, import_react7.useCallback)(() => {
37106
37251
  if (walletAddress) {
37107
37252
  queueManager.clear(walletAddress);
37108
37253
  refreshQueueStatus();
37109
37254
  }
37110
37255
  }, [walletAddress, refreshQueueStatus]);
37111
- (0, import_react6.useEffect)(() => {
37256
+ (0, import_react7.useEffect)(() => {
37112
37257
  if (!walletAddress) return;
37113
37258
  refreshQueueStatus();
37114
37259
  return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
37115
37260
  }, [walletAddress, refreshQueueStatus]);
37116
- (0, import_react6.useEffect)(() => {
37261
+ (0, import_react7.useEffect)(() => {
37117
37262
  if (!getWalletAddress || walletAddress) return;
37118
37263
  const poller = new WalletPoller();
37119
37264
  return poller.startPolling(getWalletAddress, () => {
37120
37265
  });
37121
37266
  }, [getWalletAddress, walletAddress]);
37122
- const isEncryptionReady = (0, import_react6.useCallback)(() => {
37267
+ const isEncryptionReady = (0, import_react7.useCallback)(() => {
37123
37268
  if (!walletAddress || !signMessage) return true;
37124
37269
  return hasEncryptionKey(walletAddress);
37125
37270
  }, [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)(() => {
37271
+ const pendingOpsRef = (0, import_react7.useRef)([]);
37272
+ const syntheticConvIdsRef = (0, import_react7.useRef)(/* @__PURE__ */ new Set());
37273
+ const syntheticConvQueueIdsRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
37274
+ (0, import_react7.useEffect)(() => {
37130
37275
  if (!walletAddress || !enableQueue) return;
37131
37276
  const pending = pendingOpsRef.current;
37132
37277
  if (pending.length === 0) return;
@@ -37137,7 +37282,7 @@ function useChatStorage(options) {
37137
37282
  pendingOpsRef.current = [];
37138
37283
  refreshQueueStatus();
37139
37284
  }, [walletAddress, enableQueue, refreshQueueStatus]);
37140
- (0, import_react6.useEffect)(() => {
37285
+ (0, import_react7.useEffect)(() => {
37141
37286
  if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
37142
37287
  return onKeyAvailable(walletAddress, () => {
37143
37288
  flushQueue().catch((err) => {
@@ -37145,7 +37290,7 @@ function useChatStorage(options) {
37145
37290
  });
37146
37291
  });
37147
37292
  }, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
37148
- const writeOrQueue = (0, import_react6.useCallback)(
37293
+ const writeOrQueue = (0, import_react7.useCallback)(
37149
37294
  async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
37150
37295
  const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
37151
37296
  const currentBackend = storageCtx.walletAddress ? backend : backendRef.current;
@@ -37183,7 +37328,7 @@ function useChatStorage(options) {
37183
37328
  },
37184
37329
  [storageCtx, backend, enableQueue, signMessage, getWalletAddress]
37185
37330
  );
37186
- const embedMessageAsync = (0, import_react6.useCallback)(
37331
+ const embedMessageAsync = (0, import_react7.useCallback)(
37187
37332
  async (message, mask = maskForEmbedding) => {
37188
37333
  if (!autoEmbedMessages || !getToken) return;
37189
37334
  if (message.content.length < minContentLength) return;
@@ -37222,7 +37367,7 @@ function useChatStorage(options) {
37222
37367
  maskForEmbedding
37223
37368
  ]
37224
37369
  );
37225
- const createMemoryEngineTool2 = (0, import_react6.useCallback)(
37370
+ const createMemoryEngineTool2 = (0, import_react7.useCallback)(
37226
37371
  (searchOptions) => {
37227
37372
  if (!getToken) {
37228
37373
  throw new Error("getToken is required for memory engine tool");
@@ -37231,7 +37376,7 @@ function useChatStorage(options) {
37231
37376
  },
37232
37377
  [backend, getToken, vaultEmbeddingOptions]
37233
37378
  );
37234
- const retainVaultMemory = (0, import_react6.useCallback)(
37379
+ const retainVaultMemory = (0, import_react7.useCallback)(
37235
37380
  async (input) => {
37236
37381
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37237
37382
  if (memoryStore) {
@@ -37263,7 +37408,7 @@ function useChatStorage(options) {
37263
37408
  },
37264
37409
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37265
37410
  );
37266
- const createMemoryVaultTool2 = (0, import_react6.useCallback)(
37411
+ const createMemoryVaultTool2 = (0, import_react7.useCallback)(
37267
37412
  (options2) => {
37268
37413
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37269
37414
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -37285,7 +37430,7 @@ function useChatStorage(options) {
37285
37430
  storeMaskMissing
37286
37431
  ]
37287
37432
  );
37288
- const getVaultMemories = (0, import_react6.useCallback)(
37433
+ const getVaultMemories = (0, import_react7.useCallback)(
37289
37434
  (options2) => {
37290
37435
  if (memoryStore === null) return Promise.resolve([]);
37291
37436
  if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
@@ -37297,7 +37442,7 @@ function useChatStorage(options) {
37297
37442
  },
37298
37443
  [vaultCtx, memoryStore]
37299
37444
  );
37300
- const createVaultMemory = (0, import_react6.useCallback)(
37445
+ const createVaultMemory = (0, import_react7.useCallback)(
37301
37446
  async (content, scope) => {
37302
37447
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37303
37448
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -37319,7 +37464,7 @@ function useChatStorage(options) {
37319
37464
  },
37320
37465
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37321
37466
  );
37322
- const updateVaultMemory = (0, import_react6.useCallback)(
37467
+ const updateVaultMemory = (0, import_react7.useCallback)(
37323
37468
  async (id2, content, scope) => {
37324
37469
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37325
37470
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -37345,7 +37490,7 @@ function useChatStorage(options) {
37345
37490
  },
37346
37491
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37347
37492
  );
37348
- const deleteVaultMemory = (0, import_react6.useCallback)(
37493
+ const deleteVaultMemory = (0, import_react7.useCallback)(
37349
37494
  async (id2) => {
37350
37495
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37351
37496
  if (memoryStore) return memoryStore.delete(id2);
@@ -37358,9 +37503,9 @@ function useChatStorage(options) {
37358
37503
  },
37359
37504
  [vaultCtx, vaultEmbeddingCache, memoryStore]
37360
37505
  );
37361
- const chunkVectorCacheRef = (0, import_react6.useRef)(createChunkVectorCache());
37362
- const clientToolEmbeddingsCacheRef = (0, import_react6.useRef)(/* @__PURE__ */ new Map());
37363
- (0, import_react6.useEffect)(() => {
37506
+ const chunkVectorCacheRef = (0, import_react7.useRef)(createChunkVectorCache());
37507
+ const clientToolEmbeddingsCacheRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
37508
+ (0, import_react7.useEffect)(() => {
37364
37509
  if (!getToken || memoryStore !== void 0) return;
37365
37510
  void (async () => {
37366
37511
  try {
@@ -37369,13 +37514,13 @@ function useChatStorage(options) {
37369
37514
  }
37370
37515
  })();
37371
37516
  }, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore]);
37372
- (0, import_react6.useEffect)(() => {
37517
+ (0, import_react7.useEffect)(() => {
37373
37518
  return onClearAllEncryptionState(() => {
37374
37519
  vaultEmbeddingCache.clear();
37375
37520
  chunkVectorCacheRef.current.clear();
37376
37521
  });
37377
37522
  }, [vaultEmbeddingCache]);
37378
- const createMemoryVaultSearchTool2 = (0, import_react6.useCallback)(
37523
+ const createMemoryVaultSearchTool2 = (0, import_react7.useCallback)(
37379
37524
  (searchOptions) => {
37380
37525
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37381
37526
  if (!getToken && !memoryStore) {
@@ -37391,7 +37536,7 @@ function useChatStorage(options) {
37391
37536
  },
37392
37537
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37393
37538
  );
37394
- const createRecallTool2 = (0, import_react6.useCallback)(
37539
+ const createRecallTool2 = (0, import_react7.useCallback)(
37395
37540
  (toolOptions, callbacks) => {
37396
37541
  if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
37397
37542
  if (!getToken && !memoryStore) {
@@ -37431,7 +37576,7 @@ function useChatStorage(options) {
37431
37576
  storeMaskMissing
37432
37577
  ]
37433
37578
  );
37434
- const searchVaultMemoriesFn = (0, import_react6.useCallback)(
37579
+ const searchVaultMemoriesFn = (0, import_react7.useCallback)(
37435
37580
  async (query, searchOptions) => {
37436
37581
  if (memoryStore === null) return [];
37437
37582
  if (storeMaskMissing) throw new Error(NO_STORE_MASK);
@@ -37447,7 +37592,7 @@ function useChatStorage(options) {
37447
37592
  },
37448
37593
  [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
37449
37594
  );
37450
- const recallFn = (0, import_react6.useCallback)(
37595
+ const recallFn = (0, import_react7.useCallback)(
37451
37596
  async (query, options2) => {
37452
37597
  if (memoryStore === null || !getToken && !memoryStore) {
37453
37598
  return {
@@ -37512,7 +37657,7 @@ function useChatStorage(options) {
37512
37657
  piiRedaction: resolvedPiiRedaction,
37513
37658
  onPiiRedacted
37514
37659
  });
37515
- const createConversation = (0, import_react6.useCallback)(
37660
+ const createConversation = (0, import_react7.useCallback)(
37516
37661
  async (opts) => {
37517
37662
  const conversationOpts = {
37518
37663
  ...opts,
@@ -37535,16 +37680,16 @@ function useChatStorage(options) {
37535
37680
  },
37536
37681
  [defaultConversationTitle, writeOrQueue]
37537
37682
  );
37538
- const getConversation = (0, import_react6.useCallback)(
37683
+ const getConversation = (0, import_react7.useCallback)(
37539
37684
  async (id2) => {
37540
37685
  return backend.getConversation(id2);
37541
37686
  },
37542
37687
  [backend]
37543
37688
  );
37544
- const getConversations = (0, import_react6.useCallback)(async () => {
37689
+ const getConversations = (0, import_react7.useCallback)(async () => {
37545
37690
  return backend.getConversations();
37546
37691
  }, [backend]);
37547
- const updateConversationTitle = (0, import_react6.useCallback)(
37692
+ const updateConversationTitle = (0, import_react7.useCallback)(
37548
37693
  async (id2, title) => {
37549
37694
  const { result } = await writeOrQueue(
37550
37695
  "updateConversationTitle",
@@ -37556,7 +37701,7 @@ function useChatStorage(options) {
37556
37701
  },
37557
37702
  [writeOrQueue]
37558
37703
  );
37559
- const updateConversationPinned = (0, import_react6.useCallback)(
37704
+ const updateConversationPinned = (0, import_react7.useCallback)(
37560
37705
  async (id2, pinned) => {
37561
37706
  const { result } = await writeOrQueue(
37562
37707
  "updateConversationPinned",
@@ -37568,7 +37713,7 @@ function useChatStorage(options) {
37568
37713
  },
37569
37714
  [writeOrQueue]
37570
37715
  );
37571
- const deleteConversation = (0, import_react6.useCallback)(
37716
+ const deleteConversation = (0, import_react7.useCallback)(
37572
37717
  async (id2) => {
37573
37718
  const deleted = await backend.deleteConversation(id2);
37574
37719
  if (deleted) {
@@ -37583,7 +37728,7 @@ function useChatStorage(options) {
37583
37728
  },
37584
37729
  [backend, mediaCtx, currentConversationId]
37585
37730
  );
37586
- const resolveMessageFiles = (0, import_react6.useCallback)(
37731
+ const resolveMessageFiles = (0, import_react7.useCallback)(
37587
37732
  async (messages) => {
37588
37733
  if (walletAddress && hasEncryptionKey(walletAddress) && isOPFSSupported()) {
37589
37734
  try {
@@ -37645,33 +37790,33 @@ function useChatStorage(options) {
37645
37790
  },
37646
37791
  [walletAddress]
37647
37792
  );
37648
- const getMessages = (0, import_react6.useCallback)(
37793
+ const getMessages = (0, import_react7.useCallback)(
37649
37794
  async (convId) => {
37650
37795
  const messages = await backend.getMessages(convId);
37651
37796
  return resolveMessageFiles(messages);
37652
37797
  },
37653
37798
  [backend, resolveMessageFiles]
37654
37799
  );
37655
- const getMessagesPage = (0, import_react6.useCallback)(
37800
+ const getMessagesPage = (0, import_react7.useCallback)(
37656
37801
  async (convId, options2) => {
37657
37802
  const messages = await backend.getMessagesPage(convId, options2);
37658
37803
  return resolveMessageFiles(messages);
37659
37804
  },
37660
37805
  [backend, resolveMessageFiles]
37661
37806
  );
37662
- const getMessageSkeletons = (0, import_react6.useCallback)(
37807
+ const getMessageSkeletons = (0, import_react7.useCallback)(
37663
37808
  (convId) => {
37664
37809
  return backend.getMessageSkeletons(convId);
37665
37810
  },
37666
37811
  [backend]
37667
37812
  );
37668
- const getMessageCount = (0, import_react6.useCallback)(
37813
+ const getMessageCount = (0, import_react7.useCallback)(
37669
37814
  (convId) => {
37670
37815
  return backend.getMessageCount(convId);
37671
37816
  },
37672
37817
  [backend]
37673
37818
  );
37674
- const ensureConversation = (0, import_react6.useCallback)(async () => {
37819
+ const ensureConversation = (0, import_react7.useCallback)(async () => {
37675
37820
  if (currentConversationId) {
37676
37821
  if (syntheticConvIdsRef.current.has(currentConversationId)) {
37677
37822
  return currentConversationId;
@@ -37697,7 +37842,7 @@ function useChatStorage(options) {
37697
37842
  mediaCtx,
37698
37843
  mcpR2Domain
37699
37844
  });
37700
- const sendMessage = (0, import_react6.useCallback)(
37845
+ const sendMessage = (0, import_react7.useCallback)(
37701
37846
  async (args) => {
37702
37847
  const {
37703
37848
  messages,
@@ -38629,6 +38774,8 @@ function useChatStorage(options) {
38629
38774
  getMessages,
38630
38775
  backend,
38631
38776
  baseSendMessage,
38777
+ getConversationRedactor,
38778
+ piiRedaction,
38632
38779
  walletAddress,
38633
38780
  signMessage,
38634
38781
  embeddedWalletSigner,
@@ -38641,7 +38788,7 @@ function useChatStorage(options) {
38641
38788
  refreshQueueStatus
38642
38789
  ]
38643
38790
  );
38644
- const getAllFiles = (0, import_react6.useCallback)(
38791
+ const getAllFiles = (0, import_react7.useCallback)(
38645
38792
  async (options2) => {
38646
38793
  return backend.getAllFiles(options2);
38647
38794
  },
@@ -38683,25 +38830,25 @@ function useChatStorage(options) {
38683
38830
  }
38684
38831
 
38685
38832
  // src/react/useCredits.ts
38686
- var import_react7 = require("react");
38833
+ var import_react8 = require("react");
38687
38834
  init_clientConfig();
38688
38835
  function useCredits(options = {}) {
38689
38836
  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)(() => {
38837
+ const [balance, setBalance] = (0, import_react8.useState)(null);
38838
+ const [packs, setPacks] = (0, import_react8.useState)([]);
38839
+ const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
38840
+ const [error, setError] = (0, import_react8.useState)(null);
38841
+ const loadingCountRef = (0, import_react8.useRef)(0);
38842
+ const getTokenRef = (0, import_react8.useRef)(getToken);
38843
+ const baseUrlRef = (0, import_react8.useRef)(baseUrl);
38844
+ const onErrorRef = (0, import_react8.useRef)(onError);
38845
+ const abortControllerRef = (0, import_react8.useRef)(null);
38846
+ (0, import_react8.useEffect)(() => {
38700
38847
  getTokenRef.current = getToken;
38701
38848
  baseUrlRef.current = baseUrl;
38702
38849
  onErrorRef.current = onError;
38703
38850
  });
38704
- (0, import_react7.useEffect)(() => {
38851
+ (0, import_react8.useEffect)(() => {
38705
38852
  return () => {
38706
38853
  if (abortControllerRef.current) {
38707
38854
  abortControllerRef.current.abort();
@@ -38709,15 +38856,15 @@ function useCredits(options = {}) {
38709
38856
  }
38710
38857
  };
38711
38858
  }, []);
38712
- const startLoading = (0, import_react7.useCallback)(() => {
38859
+ const startLoading = (0, import_react8.useCallback)(() => {
38713
38860
  loadingCountRef.current++;
38714
38861
  setIsLoading(true);
38715
38862
  }, []);
38716
- const stopLoading = (0, import_react7.useCallback)(() => {
38863
+ const stopLoading = (0, import_react8.useCallback)(() => {
38717
38864
  loadingCountRef.current = Math.max(0, loadingCountRef.current - 1);
38718
38865
  setIsLoading(loadingCountRef.current > 0);
38719
38866
  }, []);
38720
- const getHeaders = (0, import_react7.useCallback)(async () => {
38867
+ const getHeaders = (0, import_react8.useCallback)(async () => {
38721
38868
  const headers = {};
38722
38869
  if (getTokenRef.current) {
38723
38870
  const token = await getTokenRef.current();
@@ -38727,13 +38874,13 @@ function useCredits(options = {}) {
38727
38874
  }
38728
38875
  return headers;
38729
38876
  }, []);
38730
- const handleError = (0, import_react7.useCallback)((err) => {
38877
+ const handleError = (0, import_react8.useCallback)((err) => {
38731
38878
  const error2 = err instanceof Error ? err : new Error(String(err));
38732
38879
  setError(error2);
38733
38880
  onErrorRef.current?.(error2);
38734
38881
  return error2;
38735
38882
  }, []);
38736
- const fetchBalance = (0, import_react7.useCallback)(async () => {
38883
+ const fetchBalance = (0, import_react8.useCallback)(async () => {
38737
38884
  if (abortControllerRef.current) {
38738
38885
  abortControllerRef.current.abort();
38739
38886
  }
@@ -38766,11 +38913,11 @@ function useCredits(options = {}) {
38766
38913
  }
38767
38914
  }
38768
38915
  }, [getHeaders, handleError, startLoading, stopLoading]);
38769
- const refetch = (0, import_react7.useCallback)(async () => {
38916
+ const refetch = (0, import_react8.useCallback)(async () => {
38770
38917
  setBalance(null);
38771
38918
  await fetchBalance();
38772
38919
  }, [fetchBalance]);
38773
- const fetchPacks = (0, import_react7.useCallback)(async () => {
38920
+ const fetchPacks = (0, import_react8.useCallback)(async () => {
38774
38921
  startLoading();
38775
38922
  setError(null);
38776
38923
  try {
@@ -38790,7 +38937,7 @@ function useCredits(options = {}) {
38790
38937
  stopLoading();
38791
38938
  }
38792
38939
  }, [getHeaders, handleError, startLoading, stopLoading]);
38793
- const purchaseCredits = (0, import_react7.useCallback)(
38940
+ const purchaseCredits = (0, import_react8.useCallback)(
38794
38941
  async (credits, opts) => {
38795
38942
  startLoading();
38796
38943
  setError(null);
@@ -38819,8 +38966,8 @@ function useCredits(options = {}) {
38819
38966
  },
38820
38967
  [getHeaders, handleError, startLoading, stopLoading]
38821
38968
  );
38822
- const hasFetchedRef = (0, import_react7.useRef)(false);
38823
- (0, import_react7.useEffect)(() => {
38969
+ const hasFetchedRef = (0, import_react8.useRef)(false);
38970
+ (0, import_react8.useEffect)(() => {
38824
38971
  if (autoFetch && !hasFetchedRef.current) {
38825
38972
  hasFetchedRef.current = true;
38826
38973
  void fetchBalance();
@@ -38841,13 +38988,13 @@ function useCredits(options = {}) {
38841
38988
  }
38842
38989
 
38843
38990
  // src/react/useDatabaseManager.ts
38844
- var import_react8 = require("react");
38991
+ var import_react9 = require("react");
38845
38992
  function useDatabaseManager(walletAddress, manager) {
38846
- return (0, import_react8.useMemo)(() => manager.getDatabase(walletAddress), [walletAddress, manager]);
38993
+ return (0, import_react9.useMemo)(() => manager.getDatabase(walletAddress), [walletAddress, manager]);
38847
38994
  }
38848
38995
 
38849
38996
  // src/react/useExportPdf.ts
38850
- var import_react9 = require("react");
38997
+ var import_react10 = require("react");
38851
38998
  var DEFAULT_FILENAME2 = "document.pdf";
38852
38999
  function triggerDownload(blob, filename) {
38853
39000
  const url = URL.createObjectURL(blob);
@@ -38863,10 +39010,10 @@ function toError(err) {
38863
39010
  return err instanceof Error ? err : new Error(String(err));
38864
39011
  }
38865
39012
  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)(
39013
+ const [isExporting, setIsExporting] = (0, import_react10.useState)(false);
39014
+ const [progress, setProgress] = (0, import_react10.useState)(null);
39015
+ const [error, setError] = (0, import_react10.useState)(null);
39016
+ const wrappedExportElement = (0, import_react10.useCallback)(
38870
39017
  async (element, options) => {
38871
39018
  setIsExporting(true);
38872
39019
  setError(null);
@@ -38886,7 +39033,7 @@ function useExportPdf() {
38886
39033
  },
38887
39034
  []
38888
39035
  );
38889
- const wrappedExportMarkdown = (0, import_react9.useCallback)(
39036
+ const wrappedExportMarkdown = (0, import_react10.useCallback)(
38890
39037
  async (markdown, options) => {
38891
39038
  setIsExporting(true);
38892
39039
  setError(null);
@@ -38906,21 +39053,21 @@ function useExportPdf() {
38906
39053
  },
38907
39054
  []
38908
39055
  );
38909
- const downloadElementAsPdf = (0, import_react9.useCallback)(
39056
+ const downloadElementAsPdf = (0, import_react10.useCallback)(
38910
39057
  async (element, options) => {
38911
39058
  const blob = await wrappedExportElement(element, options);
38912
39059
  triggerDownload(blob, options?.filename ?? DEFAULT_FILENAME2);
38913
39060
  },
38914
39061
  [wrappedExportElement]
38915
39062
  );
38916
- const downloadMarkdownAsPdf = (0, import_react9.useCallback)(
39063
+ const downloadMarkdownAsPdf = (0, import_react10.useCallback)(
38917
39064
  async (markdown, options) => {
38918
39065
  const blob = await wrappedExportMarkdown(markdown, options);
38919
39066
  triggerDownload(blob, options?.filename ?? DEFAULT_FILENAME2);
38920
39067
  },
38921
39068
  [wrappedExportMarkdown]
38922
39069
  );
38923
- const wrappedRenderToCanvas = (0, import_react9.useCallback)(
39070
+ const wrappedRenderToCanvas = (0, import_react10.useCallback)(
38924
39071
  async (element) => {
38925
39072
  setIsExporting(true);
38926
39073
  setError(null);
@@ -38952,20 +39099,20 @@ function useExportPdf() {
38952
39099
 
38953
39100
  // src/react/useFiles.ts
38954
39101
  var import_watermelondb36 = require("@nozbe/watermelondb");
38955
- var import_react10 = require("react");
39102
+ var import_react11 = require("react");
38956
39103
  init_logger();
38957
39104
  function useFiles(options) {
38958
39105
  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)(() => {
39106
+ const [isLoading, setIsLoading] = (0, import_react11.useState)(false);
39107
+ const [isReady, setIsReady] = (0, import_react11.useState)(false);
39108
+ const [mediaCollection, setMediaCollection] = (0, import_react11.useState)(null);
39109
+ const blobUrlManager = (0, import_react11.useMemo)(() => new BlobUrlManager(), []);
39110
+ (0, import_react11.useEffect)(() => {
38964
39111
  return () => {
38965
39112
  blobUrlManager.revokeAll();
38966
39113
  };
38967
39114
  }, [blobUrlManager]);
38968
- (0, import_react10.useEffect)(() => {
39115
+ (0, import_react11.useEffect)(() => {
38969
39116
  const initCollection = async () => {
38970
39117
  setIsLoading(true);
38971
39118
  try {
@@ -38982,13 +39129,13 @@ function useFiles(options) {
38982
39129
  };
38983
39130
  void initCollection();
38984
39131
  }, [database]);
38985
- const ctx = (0, import_react10.useMemo)(() => {
39132
+ const ctx = (0, import_react11.useMemo)(() => {
38986
39133
  if (!isReady || !mediaCollection) {
38987
39134
  return null;
38988
39135
  }
38989
39136
  return { database, walletAddress };
38990
39137
  }, [database, mediaCollection, isReady, walletAddress]);
38991
- const createMedia = (0, import_react10.useCallback)(
39138
+ const createMedia = (0, import_react11.useCallback)(
38992
39139
  async (createOptions) => {
38993
39140
  if (!ctx) {
38994
39141
  throw new Error("Files not available. Database may need to be initialized.");
@@ -38997,7 +39144,7 @@ function useFiles(options) {
38997
39144
  },
38998
39145
  [ctx]
38999
39146
  );
39000
- const createMediaBatch = (0, import_react10.useCallback)(
39147
+ const createMediaBatch = (0, import_react11.useCallback)(
39001
39148
  async (optionsArray) => {
39002
39149
  if (!ctx) {
39003
39150
  throw new Error("Files not available. Database may need to be initialized.");
@@ -39006,7 +39153,7 @@ function useFiles(options) {
39006
39153
  },
39007
39154
  [ctx]
39008
39155
  );
39009
- const getMediaById = (0, import_react10.useCallback)(
39156
+ const getMediaById = (0, import_react11.useCallback)(
39010
39157
  async (mediaId) => {
39011
39158
  if (!ctx) {
39012
39159
  return null;
@@ -39015,7 +39162,7 @@ function useFiles(options) {
39015
39162
  },
39016
39163
  [ctx]
39017
39164
  );
39018
- const getMediaBySourceUrl = (0, import_react10.useCallback)(
39165
+ const getMediaBySourceUrl = (0, import_react11.useCallback)(
39019
39166
  async (sourceUrl) => {
39020
39167
  if (!ctx || !walletAddress) {
39021
39168
  return null;
@@ -39024,7 +39171,7 @@ function useFiles(options) {
39024
39171
  },
39025
39172
  [ctx, walletAddress]
39026
39173
  );
39027
- const getMediaByIds = (0, import_react10.useCallback)(
39174
+ const getMediaByIds = (0, import_react11.useCallback)(
39028
39175
  async (mediaIds, includeDeleted = false) => {
39029
39176
  if (!ctx) {
39030
39177
  return [];
@@ -39033,7 +39180,7 @@ function useFiles(options) {
39033
39180
  },
39034
39181
  [ctx]
39035
39182
  );
39036
- const getMediaByMessage = (0, import_react10.useCallback)(
39183
+ const getMediaByMessage = (0, import_react11.useCallback)(
39037
39184
  async (messageId) => {
39038
39185
  if (!ctx) {
39039
39186
  return [];
@@ -39042,7 +39189,7 @@ function useFiles(options) {
39042
39189
  },
39043
39190
  [ctx]
39044
39191
  );
39045
- const updateMedia = (0, import_react10.useCallback)(
39192
+ const updateMedia = (0, import_react11.useCallback)(
39046
39193
  async (mediaId, updateOptions) => {
39047
39194
  if (!ctx) {
39048
39195
  return null;
@@ -39051,7 +39198,7 @@ function useFiles(options) {
39051
39198
  },
39052
39199
  [ctx]
39053
39200
  );
39054
- const updateMediaMessageIdBatch = (0, import_react10.useCallback)(
39201
+ const updateMediaMessageIdBatch = (0, import_react11.useCallback)(
39055
39202
  async (mediaIds, messageId) => {
39056
39203
  if (!ctx) {
39057
39204
  return 0;
@@ -39060,13 +39207,13 @@ function useFiles(options) {
39060
39207
  },
39061
39208
  [ctx]
39062
39209
  );
39063
- const relinkMisclassifiedVideos = (0, import_react10.useCallback)(async () => {
39210
+ const relinkMisclassifiedVideos = (0, import_react11.useCallback)(async () => {
39064
39211
  if (!ctx || !walletAddress) {
39065
39212
  return 0;
39066
39213
  }
39067
39214
  return relinkMisclassifiedVideosOp(ctx, walletAddress);
39068
39215
  }, [ctx, walletAddress]);
39069
- const deleteMedia = (0, import_react10.useCallback)(
39216
+ const deleteMedia = (0, import_react11.useCallback)(
39070
39217
  async (mediaId) => {
39071
39218
  if (!ctx) {
39072
39219
  return false;
@@ -39077,7 +39224,7 @@ function useFiles(options) {
39077
39224
  },
39078
39225
  [ctx, blobUrlManager]
39079
39226
  );
39080
- const hardDeleteMedia = (0, import_react10.useCallback)(
39227
+ const hardDeleteMedia = (0, import_react11.useCallback)(
39081
39228
  async (mediaId) => {
39082
39229
  if (!ctx) {
39083
39230
  return false;
@@ -39088,7 +39235,7 @@ function useFiles(options) {
39088
39235
  },
39089
39236
  [ctx, blobUrlManager]
39090
39237
  );
39091
- const getMedia = (0, import_react10.useCallback)(
39238
+ const getMedia = (0, import_react11.useCallback)(
39092
39239
  async (filters) => {
39093
39240
  if (!ctx) {
39094
39241
  return [];
@@ -39097,7 +39244,7 @@ function useFiles(options) {
39097
39244
  },
39098
39245
  [ctx]
39099
39246
  );
39100
- const getMediaByType = (0, import_react10.useCallback)(
39247
+ const getMediaByType = (0, import_react11.useCallback)(
39101
39248
  async (mediaType, limit) => {
39102
39249
  if (!ctx || !walletAddress) {
39103
39250
  return [];
@@ -39106,7 +39253,7 @@ function useFiles(options) {
39106
39253
  },
39107
39254
  [ctx, walletAddress]
39108
39255
  );
39109
- const getImages = (0, import_react10.useCallback)(
39256
+ const getImages = (0, import_react11.useCallback)(
39110
39257
  async (limit) => {
39111
39258
  if (!ctx || !walletAddress) {
39112
39259
  return [];
@@ -39115,7 +39262,7 @@ function useFiles(options) {
39115
39262
  },
39116
39263
  [ctx, walletAddress]
39117
39264
  );
39118
- const getVideos = (0, import_react10.useCallback)(
39265
+ const getVideos = (0, import_react11.useCallback)(
39119
39266
  async (limit) => {
39120
39267
  if (!ctx || !walletAddress) {
39121
39268
  return [];
@@ -39124,7 +39271,7 @@ function useFiles(options) {
39124
39271
  },
39125
39272
  [ctx, walletAddress]
39126
39273
  );
39127
- const getAudio = (0, import_react10.useCallback)(
39274
+ const getAudio = (0, import_react11.useCallback)(
39128
39275
  async (limit) => {
39129
39276
  if (!ctx || !walletAddress) {
39130
39277
  return [];
@@ -39133,7 +39280,7 @@ function useFiles(options) {
39133
39280
  },
39134
39281
  [ctx, walletAddress]
39135
39282
  );
39136
- const getDocuments = (0, import_react10.useCallback)(
39283
+ const getDocuments = (0, import_react11.useCallback)(
39137
39284
  async (limit) => {
39138
39285
  if (!ctx || !walletAddress) {
39139
39286
  return [];
@@ -39142,7 +39289,7 @@ function useFiles(options) {
39142
39289
  },
39143
39290
  [ctx, walletAddress]
39144
39291
  );
39145
- const getMediaByConversation = (0, import_react10.useCallback)(
39292
+ const getMediaByConversation = (0, import_react11.useCallback)(
39146
39293
  async (conversationId, limit) => {
39147
39294
  if (!ctx || !walletAddress) {
39148
39295
  return [];
@@ -39151,7 +39298,7 @@ function useFiles(options) {
39151
39298
  },
39152
39299
  [ctx, walletAddress]
39153
39300
  );
39154
- const getMediaByRole = (0, import_react10.useCallback)(
39301
+ const getMediaByRole = (0, import_react11.useCallback)(
39155
39302
  async (role, limit) => {
39156
39303
  if (!ctx || !walletAddress) {
39157
39304
  return [];
@@ -39160,7 +39307,7 @@ function useFiles(options) {
39160
39307
  },
39161
39308
  [ctx, walletAddress]
39162
39309
  );
39163
- const getAIGeneratedMedia = (0, import_react10.useCallback)(
39310
+ const getAIGeneratedMedia = (0, import_react11.useCallback)(
39164
39311
  async (limit) => {
39165
39312
  if (!ctx || !walletAddress) {
39166
39313
  return [];
@@ -39169,7 +39316,7 @@ function useFiles(options) {
39169
39316
  },
39170
39317
  [ctx, walletAddress]
39171
39318
  );
39172
- const getUserUploadedMedia = (0, import_react10.useCallback)(
39319
+ const getUserUploadedMedia = (0, import_react11.useCallback)(
39173
39320
  async (limit) => {
39174
39321
  if (!ctx || !walletAddress) {
39175
39322
  return [];
@@ -39178,7 +39325,7 @@ function useFiles(options) {
39178
39325
  },
39179
39326
  [ctx, walletAddress]
39180
39327
  );
39181
- const getMediaByModel = (0, import_react10.useCallback)(
39328
+ const getMediaByModel = (0, import_react11.useCallback)(
39182
39329
  async (model, limit) => {
39183
39330
  if (!ctx || !walletAddress) {
39184
39331
  return [];
@@ -39187,7 +39334,7 @@ function useFiles(options) {
39187
39334
  },
39188
39335
  [ctx, walletAddress]
39189
39336
  );
39190
- const getRecentMedia = (0, import_react10.useCallback)(
39337
+ const getRecentMedia = (0, import_react11.useCallback)(
39191
39338
  async (limit = 20) => {
39192
39339
  if (!ctx || !walletAddress) {
39193
39340
  return [];
@@ -39196,7 +39343,7 @@ function useFiles(options) {
39196
39343
  },
39197
39344
  [ctx, walletAddress]
39198
39345
  );
39199
- const searchMedia = (0, import_react10.useCallback)(
39346
+ const searchMedia = (0, import_react11.useCallback)(
39200
39347
  async (query, limit) => {
39201
39348
  if (!ctx || !walletAddress) {
39202
39349
  return [];
@@ -39205,7 +39352,7 @@ function useFiles(options) {
39205
39352
  },
39206
39353
  [ctx, walletAddress]
39207
39354
  );
39208
- const getMediaCount = (0, import_react10.useCallback)(
39355
+ const getMediaCount = (0, import_react11.useCallback)(
39209
39356
  async (mediaType) => {
39210
39357
  if (!ctx || !walletAddress) {
39211
39358
  return 0;
@@ -39214,13 +39361,13 @@ function useFiles(options) {
39214
39361
  },
39215
39362
  [ctx, walletAddress]
39216
39363
  );
39217
- const getMediaCountsByType = (0, import_react10.useCallback)(async () => {
39364
+ const getMediaCountsByType = (0, import_react11.useCallback)(async () => {
39218
39365
  if (!ctx || !walletAddress) {
39219
39366
  return { image: 0, video: 0, audio: 0, document: 0 };
39220
39367
  }
39221
39368
  return getMediaCountsByTypeOp(ctx, walletAddress);
39222
39369
  }, [ctx, walletAddress]);
39223
- const deleteMediaByConversation = (0, import_react10.useCallback)(
39370
+ const deleteMediaByConversation = (0, import_react11.useCallback)(
39224
39371
  async (conversationId) => {
39225
39372
  if (!ctx) {
39226
39373
  return 0;
@@ -39229,7 +39376,7 @@ function useFiles(options) {
39229
39376
  },
39230
39377
  [ctx]
39231
39378
  );
39232
- const deleteMediaByMessage = (0, import_react10.useCallback)(
39379
+ const deleteMediaByMessage = (0, import_react11.useCallback)(
39233
39380
  async (messageId) => {
39234
39381
  if (!ctx) {
39235
39382
  return 0;
@@ -39238,7 +39385,7 @@ function useFiles(options) {
39238
39385
  },
39239
39386
  [ctx]
39240
39387
  );
39241
- const readFile = (0, import_react10.useCallback)(
39388
+ const readFile = (0, import_react11.useCallback)(
39242
39389
  async (mediaId) => {
39243
39390
  if (!isOPFSSupported()) {
39244
39391
  throw new Error("OPFS is not supported in this browser.");
@@ -39294,7 +39441,7 @@ function useFiles(options) {
39294
39441
  },
39295
39442
  [walletAddress]
39296
39443
  );
39297
- const createBlobUrl = (0, import_react10.useCallback)(
39444
+ const createBlobUrl = (0, import_react11.useCallback)(
39298
39445
  async (mediaId) => {
39299
39446
  const existingUrl = blobUrlManager.getUrl(mediaId);
39300
39447
  if (existingUrl) {
@@ -39310,16 +39457,16 @@ function useFiles(options) {
39310
39457
  },
39311
39458
  [readFile, blobUrlManager]
39312
39459
  );
39313
- const revokeBlobUrl = (0, import_react10.useCallback)(
39460
+ const revokeBlobUrl = (0, import_react11.useCallback)(
39314
39461
  (mediaId) => {
39315
39462
  blobUrlManager.revokeUrl(mediaId);
39316
39463
  },
39317
39464
  [blobUrlManager]
39318
39465
  );
39319
- const revokeAllBlobUrls = (0, import_react10.useCallback)(() => {
39466
+ const revokeAllBlobUrls = (0, import_react11.useCallback)(() => {
39320
39467
  blobUrlManager.revokeAll();
39321
39468
  }, [blobUrlManager]);
39322
- const resolveFilePlaceholders2 = (0, import_react10.useCallback)(
39469
+ const resolveFilePlaceholders2 = (0, import_react11.useCallback)(
39323
39470
  async (content) => {
39324
39471
  if (!walletAddress || !hasEncryptionKey(walletAddress)) {
39325
39472
  return content;
@@ -39374,20 +39521,20 @@ function useFiles(options) {
39374
39521
  }
39375
39522
 
39376
39523
  // src/react/useICloudAuth.ts
39377
- var import_react11 = require("react");
39378
- var ICloudAuthContext = (0, import_react11.createContext)(null);
39524
+ var import_react12 = require("react");
39525
+ var ICloudAuthContext = (0, import_react12.createContext)(null);
39379
39526
  function ICloudAuthProvider({
39380
39527
  apiToken,
39381
39528
  containerIdentifier = DEFAULT_CONTAINER_ID,
39382
39529
  environment = "production",
39383
39530
  children
39384
39531
  }) {
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)(() => {
39532
+ const [isAuthenticated, setIsAuthenticated] = (0, import_react12.useState)(false);
39533
+ const [userRecordName, setUserRecordName] = (0, import_react12.useState)(null);
39534
+ const [isAvailable, setIsAvailable] = (0, import_react12.useState)(false);
39535
+ const [isConfigured, setIsConfigured] = (0, import_react12.useState)(false);
39536
+ const [_isLoading, setIsLoading] = (0, import_react12.useState)(false);
39537
+ (0, import_react12.useEffect)(() => {
39391
39538
  if (!apiToken || typeof window === "undefined") {
39392
39539
  return;
39393
39540
  }
@@ -39420,7 +39567,7 @@ function ICloudAuthProvider({
39420
39567
  };
39421
39568
  void initCloudKit();
39422
39569
  }, [apiToken, containerIdentifier, environment]);
39423
- const requestAccess = (0, import_react11.useCallback)(async () => {
39570
+ const requestAccess = (0, import_react12.useCallback)(async () => {
39424
39571
  if (!isConfigured) {
39425
39572
  throw new Error("iCloud is not configured");
39426
39573
  }
@@ -39435,11 +39582,11 @@ function ICloudAuthProvider({
39435
39582
  throw new Error(err instanceof Error ? err.message : "Failed to sign in to iCloud");
39436
39583
  }
39437
39584
  }, [isAuthenticated, isConfigured]);
39438
- const logout = (0, import_react11.useCallback)(() => {
39585
+ const logout = (0, import_react12.useCallback)(() => {
39439
39586
  setIsAuthenticated(false);
39440
39587
  setUserRecordName(null);
39441
39588
  }, []);
39442
- return (0, import_react11.createElement)(
39589
+ return (0, import_react12.createElement)(
39443
39590
  ICloudAuthContext.Provider,
39444
39591
  {
39445
39592
  value: {
@@ -39455,7 +39602,7 @@ function ICloudAuthProvider({
39455
39602
  );
39456
39603
  }
39457
39604
  function useICloudAuth() {
39458
- const context = (0, import_react11.useContext)(ICloudAuthContext);
39605
+ const context = (0, import_react12.useContext)(ICloudAuthContext);
39459
39606
  if (!context) {
39460
39607
  throw new Error("useICloudAuth must be used within ICloudAuthProvider");
39461
39608
  }
@@ -39468,11 +39615,11 @@ function clearICloudAuth() {
39468
39615
  }
39469
39616
 
39470
39617
  // src/react/useICloudBackup.ts
39471
- var import_react12 = require("react");
39618
+ var import_react13 = require("react");
39472
39619
  function useICloudBackup(options) {
39473
39620
  const { database, userAddress, requestEncryptionKey: requestEncryptionKey2, exportConversation, importConversation } = options;
39474
39621
  const { isAuthenticated, isConfigured, isAvailable, requestAccess } = useICloudAuth();
39475
- const deps = (0, import_react12.useMemo)(
39622
+ const deps = (0, import_react13.useMemo)(
39476
39623
  () => ({
39477
39624
  requestICloudAccess: requestAccess,
39478
39625
  requestEncryptionKey: requestEncryptionKey2,
@@ -39481,7 +39628,7 @@ function useICloudBackup(options) {
39481
39628
  }),
39482
39629
  [requestAccess, requestEncryptionKey2, exportConversation, importConversation]
39483
39630
  );
39484
- const ensureAuthenticated = (0, import_react12.useCallback)(async () => {
39631
+ const ensureAuthenticated = (0, import_react13.useCallback)(async () => {
39485
39632
  if (isAuthenticated) return true;
39486
39633
  try {
39487
39634
  await requestAccess();
@@ -39490,7 +39637,7 @@ function useICloudBackup(options) {
39490
39637
  return false;
39491
39638
  }
39492
39639
  }, [isAuthenticated, requestAccess]);
39493
- const backup = (0, import_react12.useCallback)(
39640
+ const backup = (0, import_react13.useCallback)(
39494
39641
  async (backupOptions) => {
39495
39642
  if (!userAddress) {
39496
39643
  return { error: "Please sign in to backup to iCloud" };
@@ -39515,7 +39662,7 @@ function useICloudBackup(options) {
39515
39662
  },
39516
39663
  [database, userAddress, isAvailable, isConfigured, ensureAuthenticated, deps]
39517
39664
  );
39518
- const restore = (0, import_react12.useCallback)(
39665
+ const restore = (0, import_react13.useCallback)(
39519
39666
  async (restoreOptions) => {
39520
39667
  if (!userAddress) {
39521
39668
  return { error: "Please sign in to restore from iCloud" };
@@ -39550,7 +39697,7 @@ function useICloudBackup(options) {
39550
39697
  }
39551
39698
 
39552
39699
  // src/react/useModels.ts
39553
- var import_react13 = require("react");
39700
+ var import_react14 = require("react");
39554
39701
  init_clientConfig();
39555
39702
  var MODELS_CACHE_TTL_MS = 5 * 60 * 1e3;
39556
39703
  var modelsCache = /* @__PURE__ */ new Map();
@@ -39676,19 +39823,19 @@ function waitForSharedRequest(key3, shared, signal) {
39676
39823
  }
39677
39824
  function useModels(options = {}) {
39678
39825
  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)(() => {
39826
+ const [models, setModels] = (0, import_react14.useState)([]);
39827
+ const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
39828
+ const [error, setError] = (0, import_react14.useState)(null);
39829
+ const getTokenRef = (0, import_react14.useRef)(getToken);
39830
+ const baseUrlRef = (0, import_react14.useRef)(baseUrl);
39831
+ const providerRef = (0, import_react14.useRef)(provider);
39832
+ const abortControllerRef = (0, import_react14.useRef)(null);
39833
+ (0, import_react14.useEffect)(() => {
39687
39834
  getTokenRef.current = getToken;
39688
39835
  baseUrlRef.current = baseUrl;
39689
39836
  providerRef.current = provider;
39690
39837
  });
39691
- (0, import_react13.useEffect)(() => {
39838
+ (0, import_react14.useEffect)(() => {
39692
39839
  return () => {
39693
39840
  if (abortControllerRef.current) {
39694
39841
  abortControllerRef.current.abort();
@@ -39696,7 +39843,7 @@ function useModels(options = {}) {
39696
39843
  }
39697
39844
  };
39698
39845
  }, []);
39699
- const fetchModels = (0, import_react13.useCallback)(async (force = false) => {
39846
+ const fetchModels = (0, import_react14.useCallback)(async (force = false) => {
39700
39847
  if (abortControllerRef.current) {
39701
39848
  abortControllerRef.current.abort();
39702
39849
  }
@@ -39736,12 +39883,12 @@ function useModels(options = {}) {
39736
39883
  }
39737
39884
  }
39738
39885
  }, []);
39739
- const refetch = (0, import_react13.useCallback)(async () => {
39886
+ const refetch = (0, import_react14.useCallback)(async () => {
39740
39887
  setModels([]);
39741
39888
  await fetchModels(true);
39742
39889
  }, [fetchModels]);
39743
- const hasFetchedRef = (0, import_react13.useRef)(false);
39744
- (0, import_react13.useEffect)(() => {
39890
+ const hasFetchedRef = (0, import_react14.useRef)(false);
39891
+ (0, import_react14.useEffect)(() => {
39745
39892
  if (autoFetch && !hasFetchedRef.current) {
39746
39893
  hasFetchedRef.current = true;
39747
39894
  void fetchModels();
@@ -39759,13 +39906,13 @@ function useModels(options = {}) {
39759
39906
  }
39760
39907
 
39761
39908
  // src/react/useOCR.ts
39762
- var import_react14 = require("react");
39909
+ var import_react15 = require("react");
39763
39910
  var import_tesseract = __toESM(require("tesseract.js"));
39764
39911
  init_logger();
39765
39912
  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) => {
39913
+ const [isProcessing, setIsProcessing] = (0, import_react15.useState)(false);
39914
+ const [error, setError] = (0, import_react15.useState)(null);
39915
+ const extractOCRContext = (0, import_react15.useCallback)(async (files) => {
39769
39916
  setIsProcessing(true);
39770
39917
  setError(null);
39771
39918
  try {
@@ -39843,13 +39990,13 @@ ${text16}`;
39843
39990
  }
39844
39991
 
39845
39992
  // src/react/usePdf.ts
39846
- var import_react15 = require("react");
39993
+ var import_react16 = require("react");
39847
39994
  init_logger();
39848
39995
  var PDF_MIME_TYPE = "application/pdf";
39849
39996
  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) => {
39997
+ const [isProcessing, setIsProcessing] = (0, import_react16.useState)(false);
39998
+ const [error, setError] = (0, import_react16.useState)(null);
39999
+ const extractPdfContext = (0, import_react16.useCallback)(async (files) => {
39853
40000
  setIsProcessing(true);
39854
40001
  setError(null);
39855
40002
  try {
@@ -39893,7 +40040,7 @@ ${text16}`;
39893
40040
  }
39894
40041
 
39895
40042
  // src/react/usePhoneCalls.ts
39896
- var import_react16 = require("react");
40043
+ var import_react17 = require("react");
39897
40044
  init_clientConfig();
39898
40045
  var DEFAULT_POLL_INTERVAL_MS = 5e3;
39899
40046
  var DEFAULT_POLL_MAX_ATTEMPTS = 60;
@@ -39925,24 +40072,24 @@ function isTerminalPhoneCall(call) {
39925
40072
  }
39926
40073
  function usePhoneCalls(options = {}) {
39927
40074
  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)(() => {
40075
+ const [isEnabled, setIsEnabled] = (0, import_react17.useState)(null);
40076
+ const [currentCall, setCurrentCall] = (0, import_react17.useState)(null);
40077
+ const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
40078
+ const [isPolling, setIsPolling] = (0, import_react17.useState)(false);
40079
+ const [error, setError] = (0, import_react17.useState)(null);
40080
+ const getTokenRef = (0, import_react17.useRef)(getToken);
40081
+ const baseUrlRef = (0, import_react17.useRef)(baseUrl);
40082
+ const onErrorRef = (0, import_react17.useRef)(onError);
40083
+ const loadingCountRef = (0, import_react17.useRef)(0);
40084
+ const requestAbortControllerRef = (0, import_react17.useRef)(null);
40085
+ const pollAbortControllerRef = (0, import_react17.useRef)(null);
40086
+ const pollRunIdRef = (0, import_react17.useRef)(0);
40087
+ (0, import_react17.useEffect)(() => {
39941
40088
  getTokenRef.current = getToken;
39942
40089
  baseUrlRef.current = baseUrl;
39943
40090
  onErrorRef.current = onError;
39944
40091
  });
39945
- const stopPolling = (0, import_react16.useCallback)(() => {
40092
+ const stopPolling = (0, import_react17.useCallback)(() => {
39946
40093
  pollRunIdRef.current += 1;
39947
40094
  if (pollAbortControllerRef.current) {
39948
40095
  pollAbortControllerRef.current.abort();
@@ -39950,7 +40097,7 @@ function usePhoneCalls(options = {}) {
39950
40097
  }
39951
40098
  setIsPolling(false);
39952
40099
  }, []);
39953
- (0, import_react16.useEffect)(() => {
40100
+ (0, import_react17.useEffect)(() => {
39954
40101
  return () => {
39955
40102
  if (requestAbortControllerRef.current) {
39956
40103
  requestAbortControllerRef.current.abort();
@@ -39963,21 +40110,21 @@ function usePhoneCalls(options = {}) {
39963
40110
  }
39964
40111
  };
39965
40112
  }, []);
39966
- const startLoading = (0, import_react16.useCallback)(() => {
40113
+ const startLoading = (0, import_react17.useCallback)(() => {
39967
40114
  loadingCountRef.current += 1;
39968
40115
  setIsLoading(true);
39969
40116
  }, []);
39970
- const stopLoading = (0, import_react16.useCallback)(() => {
40117
+ const stopLoading = (0, import_react17.useCallback)(() => {
39971
40118
  loadingCountRef.current = Math.max(0, loadingCountRef.current - 1);
39972
40119
  setIsLoading(loadingCountRef.current > 0);
39973
40120
  }, []);
39974
- const handleError = (0, import_react16.useCallback)((err) => {
40121
+ const handleError = (0, import_react17.useCallback)((err) => {
39975
40122
  const nextError = err instanceof Error ? err : new Error(String(err));
39976
40123
  setError(nextError);
39977
40124
  onErrorRef.current?.(nextError);
39978
40125
  return nextError;
39979
40126
  }, []);
39980
- const getHeaders = (0, import_react16.useCallback)(async () => {
40127
+ const getHeaders = (0, import_react17.useCallback)(async () => {
39981
40128
  const headers = {};
39982
40129
  if (getTokenRef.current) {
39983
40130
  const token = await getTokenRef.current();
@@ -39987,7 +40134,7 @@ function usePhoneCalls(options = {}) {
39987
40134
  }
39988
40135
  return headers;
39989
40136
  }, []);
39990
- const fetchAvailability = (0, import_react16.useCallback)(async () => {
40137
+ const fetchAvailability = (0, import_react17.useCallback)(async () => {
39991
40138
  if (requestAbortControllerRef.current) {
39992
40139
  requestAbortControllerRef.current.abort();
39993
40140
  }
@@ -40025,7 +40172,7 @@ function usePhoneCalls(options = {}) {
40025
40172
  }
40026
40173
  }
40027
40174
  }, [getHeaders, handleError, startLoading, stopLoading]);
40028
- const createPhoneCall = (0, import_react16.useCallback)(
40175
+ const createPhoneCall = (0, import_react17.useCallback)(
40029
40176
  async (request) => {
40030
40177
  startLoading();
40031
40178
  setError(null);
@@ -40052,7 +40199,7 @@ function usePhoneCalls(options = {}) {
40052
40199
  },
40053
40200
  [getHeaders, handleError, startLoading, stopLoading]
40054
40201
  );
40055
- const getPhoneCall = (0, import_react16.useCallback)(
40202
+ const getPhoneCall = (0, import_react17.useCallback)(
40056
40203
  async (callId) => {
40057
40204
  const trimmedCallId = callId.trim();
40058
40205
  if (!trimmedCallId) {
@@ -40101,7 +40248,7 @@ function usePhoneCalls(options = {}) {
40101
40248
  },
40102
40249
  [getHeaders, handleError, startLoading, stopLoading]
40103
40250
  );
40104
- const pollPhoneCall = (0, import_react16.useCallback)(
40251
+ const pollPhoneCall = (0, import_react17.useCallback)(
40105
40252
  async (callId, pollOptions = {}) => {
40106
40253
  const trimmedCallId = callId.trim();
40107
40254
  if (!trimmedCallId) {
@@ -40166,11 +40313,11 @@ function usePhoneCalls(options = {}) {
40166
40313
  },
40167
40314
  [getHeaders, handleError, stopPolling]
40168
40315
  );
40169
- const reset = (0, import_react16.useCallback)(() => {
40316
+ const reset = (0, import_react17.useCallback)(() => {
40170
40317
  setCurrentCall(null);
40171
40318
  setError(null);
40172
40319
  }, []);
40173
- (0, import_react16.useEffect)(() => {
40320
+ (0, import_react17.useEffect)(() => {
40174
40321
  if (!autoFetchAvailability) {
40175
40322
  return;
40176
40323
  }
@@ -40193,18 +40340,18 @@ function usePhoneCalls(options = {}) {
40193
40340
 
40194
40341
  // src/react/useProjects.ts
40195
40342
  var import_watermelondb37 = require("@nozbe/watermelondb");
40196
- var import_react17 = require("react");
40343
+ var import_react18 = require("react");
40197
40344
  init_logger();
40198
40345
  function useProjects(options) {
40199
40346
  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)(() => {
40347
+ const [projects, setProjects] = (0, import_react18.useState)([]);
40348
+ const [currentProjectId, setCurrentProjectId] = (0, import_react18.useState)(initialProjectId || null);
40349
+ const [isLoading, setIsLoading] = (0, import_react18.useState)(false);
40350
+ const [isReady, setIsReady] = (0, import_react18.useState)(false);
40351
+ const [inboxProjectId, setInboxProjectId] = (0, import_react18.useState)(null);
40352
+ const [projectsCollection, setProjectsCollection] = (0, import_react18.useState)(null);
40353
+ const [conversationsCollection, setConversationsCollection] = (0, import_react18.useState)(null);
40354
+ (0, import_react18.useEffect)(() => {
40208
40355
  const initCollections = async () => {
40209
40356
  getLogger().debug("[useProjects] Initializing collections...");
40210
40357
  try {
@@ -40236,7 +40383,7 @@ function useProjects(options) {
40236
40383
  };
40237
40384
  void initCollections();
40238
40385
  }, [database]);
40239
- const projectCtx = (0, import_react17.useMemo)(() => {
40386
+ const projectCtx = (0, import_react18.useMemo)(() => {
40240
40387
  if (!isReady || !projectsCollection || !conversationsCollection) {
40241
40388
  return null;
40242
40389
  }
@@ -40246,7 +40393,7 @@ function useProjects(options) {
40246
40393
  conversationsCollection
40247
40394
  };
40248
40395
  }, [database, projectsCollection, conversationsCollection, isReady]);
40249
- const storageCtx = (0, import_react17.useMemo)(() => {
40396
+ const storageCtx = (0, import_react18.useMemo)(() => {
40250
40397
  if (!isReady || !conversationsCollection) {
40251
40398
  return null;
40252
40399
  }
@@ -40261,7 +40408,7 @@ function useProjects(options) {
40261
40408
  return null;
40262
40409
  }
40263
40410
  }, [database, conversationsCollection, isReady]);
40264
- const refreshProjects = (0, import_react17.useCallback)(async () => {
40411
+ const refreshProjects = (0, import_react18.useCallback)(async () => {
40265
40412
  if (!projectCtx) {
40266
40413
  return;
40267
40414
  }
@@ -40275,12 +40422,12 @@ function useProjects(options) {
40275
40422
  setIsLoading(false);
40276
40423
  }
40277
40424
  }, [projectCtx]);
40278
- (0, import_react17.useEffect)(() => {
40425
+ (0, import_react18.useEffect)(() => {
40279
40426
  if (isReady) {
40280
40427
  void refreshProjects();
40281
40428
  }
40282
40429
  }, [isReady, refreshProjects]);
40283
- (0, import_react17.useEffect)(() => {
40430
+ (0, import_react18.useEffect)(() => {
40284
40431
  const ensureInboxProject = async () => {
40285
40432
  if (!projectCtx || !isReady) return;
40286
40433
  try {
@@ -40298,7 +40445,7 @@ function useProjects(options) {
40298
40445
  };
40299
40446
  void ensureInboxProject();
40300
40447
  }, [projectCtx, isReady]);
40301
- (0, import_react17.useEffect)(() => {
40448
+ (0, import_react18.useEffect)(() => {
40302
40449
  if (!projectsCollection) {
40303
40450
  return;
40304
40451
  }
@@ -40307,7 +40454,7 @@ function useProjects(options) {
40307
40454
  });
40308
40455
  return () => subscription.unsubscribe();
40309
40456
  }, [projectsCollection]);
40310
- const createProject = (0, import_react17.useCallback)(
40457
+ const createProject = (0, import_react18.useCallback)(
40311
40458
  async (opts) => {
40312
40459
  if (!projectCtx) {
40313
40460
  throw new Error("Projects not available. Database schema may need to be updated.");
@@ -40317,7 +40464,7 @@ function useProjects(options) {
40317
40464
  },
40318
40465
  [projectCtx]
40319
40466
  );
40320
- const getProject = (0, import_react17.useCallback)(
40467
+ const getProject = (0, import_react18.useCallback)(
40321
40468
  async (projectId) => {
40322
40469
  if (!projectCtx) {
40323
40470
  return null;
@@ -40326,13 +40473,13 @@ function useProjects(options) {
40326
40473
  },
40327
40474
  [projectCtx]
40328
40475
  );
40329
- const getProjects = (0, import_react17.useCallback)(async () => {
40476
+ const getProjects = (0, import_react18.useCallback)(async () => {
40330
40477
  if (!projectCtx) {
40331
40478
  return [];
40332
40479
  }
40333
40480
  return getProjectsOp(projectCtx);
40334
40481
  }, [projectCtx]);
40335
- const updateProjectName = (0, import_react17.useCallback)(
40482
+ const updateProjectName = (0, import_react18.useCallback)(
40336
40483
  async (projectId, name) => {
40337
40484
  if (!projectCtx) {
40338
40485
  return false;
@@ -40341,7 +40488,7 @@ function useProjects(options) {
40341
40488
  },
40342
40489
  [projectCtx]
40343
40490
  );
40344
- const updateProject = (0, import_react17.useCallback)(
40491
+ const updateProject = (0, import_react18.useCallback)(
40345
40492
  async (projectId, opts) => {
40346
40493
  if (!projectCtx) {
40347
40494
  return false;
@@ -40350,7 +40497,7 @@ function useProjects(options) {
40350
40497
  },
40351
40498
  [projectCtx]
40352
40499
  );
40353
- const deleteProject = (0, import_react17.useCallback)(
40500
+ const deleteProject = (0, import_react18.useCallback)(
40354
40501
  async (projectId) => {
40355
40502
  if (!projectCtx) {
40356
40503
  return false;
@@ -40363,7 +40510,7 @@ function useProjects(options) {
40363
40510
  },
40364
40511
  [projectCtx, currentProjectId]
40365
40512
  );
40366
- const getProjectConversations = (0, import_react17.useCallback)(
40513
+ const getProjectConversations = (0, import_react18.useCallback)(
40367
40514
  async (projectId) => {
40368
40515
  if (!projectCtx) {
40369
40516
  return [];
@@ -40372,7 +40519,7 @@ function useProjects(options) {
40372
40519
  },
40373
40520
  [projectCtx]
40374
40521
  );
40375
- const getProjectConversationCount = (0, import_react17.useCallback)(
40522
+ const getProjectConversationCount = (0, import_react18.useCallback)(
40376
40523
  async (projectId) => {
40377
40524
  if (!projectCtx) {
40378
40525
  return 0;
@@ -40381,7 +40528,7 @@ function useProjects(options) {
40381
40528
  },
40382
40529
  [projectCtx]
40383
40530
  );
40384
- const updateConversationProject = (0, import_react17.useCallback)(
40531
+ const updateConversationProject = (0, import_react18.useCallback)(
40385
40532
  async (conversationId, projectId) => {
40386
40533
  if (!storageCtx) {
40387
40534
  return false;
@@ -40390,7 +40537,7 @@ function useProjects(options) {
40390
40537
  },
40391
40538
  [storageCtx]
40392
40539
  );
40393
- const getConversationsByProject = (0, import_react17.useCallback)(
40540
+ const getConversationsByProject = (0, import_react18.useCallback)(
40394
40541
  async (projectId) => {
40395
40542
  if (!storageCtx) {
40396
40543
  return [];
@@ -40421,7 +40568,7 @@ function useProjects(options) {
40421
40568
  }
40422
40569
 
40423
40570
  // src/react/useSettings.ts
40424
- var import_react18 = require("react");
40571
+ var import_react19 = require("react");
40425
40572
 
40426
40573
  // src/react/userSettingsStore.ts
40427
40574
  var import_watermelondb38 = require("@nozbe/watermelondb");
@@ -40559,16 +40706,16 @@ function patchUserSettingsSnapshot(database, walletAddress, patch) {
40559
40706
  var DB_NOT_READY = "Database not ready";
40560
40707
  function useSettings(options) {
40561
40708
  const { database, walletAddress } = options;
40562
- const subscribe = (0, import_react18.useCallback)(
40709
+ const subscribe = (0, import_react19.useCallback)(
40563
40710
  (listener) => subscribeUserSettings(database, walletAddress, listener),
40564
40711
  [database, walletAddress]
40565
40712
  );
40566
- const getSnapshot = (0, import_react18.useCallback)(
40713
+ const getSnapshot = (0, import_react19.useCallback)(
40567
40714
  () => getUserSettingsSnapshot(database, walletAddress),
40568
40715
  [database, walletAddress]
40569
40716
  );
40570
- const snapshot = (0, import_react18.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
40571
- const storageCtx = (0, import_react18.useMemo)(
40717
+ const snapshot = (0, import_react19.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
40718
+ const storageCtx = (0, import_react19.useMemo)(
40572
40719
  () => database ? {
40573
40720
  database,
40574
40721
  userPreferencesCollection: database.get("userPreferences"),
@@ -40576,14 +40723,14 @@ function useSettings(options) {
40576
40723
  } : null,
40577
40724
  [database]
40578
40725
  );
40579
- const legacyStorageCtx = (0, import_react18.useMemo)(
40726
+ const legacyStorageCtx = (0, import_react19.useMemo)(
40580
40727
  () => database ? {
40581
40728
  database,
40582
40729
  modelPreferencesCollection: database.get("modelPreferences")
40583
40730
  } : null,
40584
40731
  [database]
40585
40732
  );
40586
- const getModelPreference = (0, import_react18.useCallback)(
40733
+ const getModelPreference = (0, import_react19.useCallback)(
40587
40734
  async (address) => {
40588
40735
  try {
40589
40736
  if (!address) throw new Error("Wallet address is required");
@@ -40596,7 +40743,7 @@ function useSettings(options) {
40596
40743
  },
40597
40744
  [legacyStorageCtx]
40598
40745
  );
40599
- const setModelPreference = (0, import_react18.useCallback)(
40746
+ const setModelPreference = (0, import_react19.useCallback)(
40600
40747
  async (address, models) => {
40601
40748
  try {
40602
40749
  if (!address) throw new Error("Wallet address is required");
@@ -40612,7 +40759,7 @@ function useSettings(options) {
40612
40759
  },
40613
40760
  [database, legacyStorageCtx, walletAddress]
40614
40761
  );
40615
- const deleteModelPreference = (0, import_react18.useCallback)(
40762
+ const deleteModelPreference = (0, import_react19.useCallback)(
40616
40763
  async (address) => {
40617
40764
  try {
40618
40765
  if (!address) throw new Error("Wallet address is required");
@@ -40628,7 +40775,7 @@ function useSettings(options) {
40628
40775
  },
40629
40776
  [database, legacyStorageCtx, walletAddress]
40630
40777
  );
40631
- const getUserPreference = (0, import_react18.useCallback)(
40778
+ const getUserPreference = (0, import_react19.useCallback)(
40632
40779
  async (address) => {
40633
40780
  try {
40634
40781
  if (!address) throw new Error("Wallet address is required");
@@ -40641,7 +40788,7 @@ function useSettings(options) {
40641
40788
  },
40642
40789
  [storageCtx]
40643
40790
  );
40644
- const setUserPreference = (0, import_react18.useCallback)(
40791
+ const setUserPreference = (0, import_react19.useCallback)(
40645
40792
  async (address, opts) => {
40646
40793
  try {
40647
40794
  if (!address) throw new Error("Wallet address is required");
@@ -40657,7 +40804,7 @@ function useSettings(options) {
40657
40804
  },
40658
40805
  [database, storageCtx, walletAddress]
40659
40806
  );
40660
- const updateProfile = (0, import_react18.useCallback)(
40807
+ const updateProfile = (0, import_react19.useCallback)(
40661
40808
  async (address, profile) => {
40662
40809
  try {
40663
40810
  if (!address) throw new Error("Wallet address is required");
@@ -40673,7 +40820,7 @@ function useSettings(options) {
40673
40820
  },
40674
40821
  [database, storageCtx, walletAddress]
40675
40822
  );
40676
- const updatePersonality = (0, import_react18.useCallback)(
40823
+ const updatePersonality = (0, import_react19.useCallback)(
40677
40824
  async (address, personality) => {
40678
40825
  try {
40679
40826
  if (!address) throw new Error("Wallet address is required");
@@ -40689,7 +40836,7 @@ function useSettings(options) {
40689
40836
  },
40690
40837
  [database, storageCtx, walletAddress]
40691
40838
  );
40692
- const updateModels = (0, import_react18.useCallback)(
40839
+ const updateModels = (0, import_react19.useCallback)(
40693
40840
  async (address, models) => {
40694
40841
  try {
40695
40842
  if (!address) throw new Error("Wallet address is required");
@@ -40705,7 +40852,7 @@ function useSettings(options) {
40705
40852
  },
40706
40853
  [database, storageCtx, walletAddress]
40707
40854
  );
40708
- const deleteUserPreference = (0, import_react18.useCallback)(
40855
+ const deleteUserPreference = (0, import_react19.useCallback)(
40709
40856
  async (address) => {
40710
40857
  try {
40711
40858
  if (!address) throw new Error("Wallet address is required");
@@ -40738,23 +40885,23 @@ function useSettings(options) {
40738
40885
  }
40739
40886
 
40740
40887
  // src/react/useSubscription.ts
40741
- var import_react19 = require("react");
40888
+ var import_react20 = require("react");
40742
40889
  init_clientConfig();
40743
40890
  function useSubscription(options = {}) {
40744
40891
  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)(() => {
40892
+ const [status, setStatus] = (0, import_react20.useState)(null);
40893
+ const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
40894
+ const [error, setError] = (0, import_react20.useState)(null);
40895
+ const getTokenRef = (0, import_react20.useRef)(getToken);
40896
+ const baseUrlRef = (0, import_react20.useRef)(baseUrl);
40897
+ const onErrorRef = (0, import_react20.useRef)(onError);
40898
+ const abortControllerRef = (0, import_react20.useRef)(null);
40899
+ (0, import_react20.useEffect)(() => {
40753
40900
  getTokenRef.current = getToken;
40754
40901
  baseUrlRef.current = baseUrl;
40755
40902
  onErrorRef.current = onError;
40756
40903
  });
40757
- (0, import_react19.useEffect)(() => {
40904
+ (0, import_react20.useEffect)(() => {
40758
40905
  return () => {
40759
40906
  if (abortControllerRef.current) {
40760
40907
  abortControllerRef.current.abort();
@@ -40762,7 +40909,7 @@ function useSubscription(options = {}) {
40762
40909
  }
40763
40910
  };
40764
40911
  }, []);
40765
- const getHeaders = (0, import_react19.useCallback)(async () => {
40912
+ const getHeaders = (0, import_react20.useCallback)(async () => {
40766
40913
  const headers = {};
40767
40914
  if (getTokenRef.current) {
40768
40915
  const token = await getTokenRef.current();
@@ -40772,13 +40919,13 @@ function useSubscription(options = {}) {
40772
40919
  }
40773
40920
  return headers;
40774
40921
  }, []);
40775
- const handleError = (0, import_react19.useCallback)((err) => {
40922
+ const handleError = (0, import_react20.useCallback)((err) => {
40776
40923
  const error2 = err instanceof Error ? err : new Error(String(err));
40777
40924
  setError(error2);
40778
40925
  onErrorRef.current?.(error2);
40779
40926
  return error2;
40780
40927
  }, []);
40781
- const fetchStatus = (0, import_react19.useCallback)(async () => {
40928
+ const fetchStatus = (0, import_react20.useCallback)(async () => {
40782
40929
  if (abortControllerRef.current) {
40783
40930
  abortControllerRef.current.abort();
40784
40931
  }
@@ -40815,11 +40962,11 @@ function useSubscription(options = {}) {
40815
40962
  }
40816
40963
  }
40817
40964
  }, [getHeaders, handleError]);
40818
- const refetch = (0, import_react19.useCallback)(async () => {
40965
+ const refetch = (0, import_react20.useCallback)(async () => {
40819
40966
  setStatus(null);
40820
40967
  await fetchStatus();
40821
40968
  }, [fetchStatus]);
40822
- const createCheckoutSession = (0, import_react19.useCallback)(
40969
+ const createCheckoutSession = (0, import_react20.useCallback)(
40823
40970
  async (opts) => {
40824
40971
  setIsLoading(true);
40825
40972
  setError(null);
@@ -40849,7 +40996,7 @@ function useSubscription(options = {}) {
40849
40996
  },
40850
40997
  [getHeaders, handleError]
40851
40998
  );
40852
- const openCustomerPortal = (0, import_react19.useCallback)(
40999
+ const openCustomerPortal = (0, import_react20.useCallback)(
40853
41000
  async (opts) => {
40854
41001
  setIsLoading(true);
40855
41002
  setError(null);
@@ -40876,7 +41023,7 @@ function useSubscription(options = {}) {
40876
41023
  },
40877
41024
  [getHeaders, handleError]
40878
41025
  );
40879
- const cancelSubscription = (0, import_react19.useCallback)(async () => {
41026
+ const cancelSubscription = (0, import_react20.useCallback)(async () => {
40880
41027
  setIsLoading(true);
40881
41028
  setError(null);
40882
41029
  try {
@@ -40898,7 +41045,7 @@ function useSubscription(options = {}) {
40898
41045
  setIsLoading(false);
40899
41046
  }
40900
41047
  }, [getHeaders, handleError, fetchStatus]);
40901
- const renewSubscription = (0, import_react19.useCallback)(async () => {
41048
+ const renewSubscription = (0, import_react20.useCallback)(async () => {
40902
41049
  setIsLoading(true);
40903
41050
  setError(null);
40904
41051
  try {
@@ -40920,8 +41067,8 @@ function useSubscription(options = {}) {
40920
41067
  setIsLoading(false);
40921
41068
  }
40922
41069
  }, [getHeaders, handleError, fetchStatus]);
40923
- const hasFetchedRef = (0, import_react19.useRef)(false);
40924
- (0, import_react19.useEffect)(() => {
41070
+ const hasFetchedRef = (0, import_react20.useRef)(false);
41071
+ (0, import_react20.useEffect)(() => {
40925
41072
  if (autoFetch && !hasFetchedRef.current) {
40926
41073
  hasFetchedRef.current = true;
40927
41074
  void fetchStatus();
@@ -40943,30 +41090,30 @@ function useSubscription(options = {}) {
40943
41090
  }
40944
41091
 
40945
41092
  // src/react/useTools.ts
40946
- var import_react20 = require("react");
41093
+ var import_react21 = require("react");
40947
41094
  init_clientConfig();
40948
41095
  function useTools(options) {
40949
41096
  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);
41097
+ const [allTools, setAllTools] = (0, import_react21.useState)([]);
41098
+ const [checksum, setChecksum] = (0, import_react21.useState)(getToolsChecksum2);
41099
+ const [isLoading, setIsLoading] = (0, import_react21.useState)(false);
41100
+ const [error, setError] = (0, import_react21.useState)(null);
41101
+ const includeToolsRef = (0, import_react21.useRef)(includeTools);
40955
41102
  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
41103
  includeToolsRef.current = includeTools;
40957
41104
  }
40958
41105
  const stableIncludeTools = includeToolsRef.current;
40959
- const tools = (0, import_react20.useMemo)(
41106
+ const tools = (0, import_react21.useMemo)(
40960
41107
  () => filterServerTools(allTools, stableIncludeTools),
40961
41108
  [allTools, stableIncludeTools]
40962
41109
  );
40963
- const getTokenRef = (0, import_react20.useRef)(getToken);
40964
- const baseUrlRef = (0, import_react20.useRef)(baseUrl);
40965
- (0, import_react20.useEffect)(() => {
41110
+ const getTokenRef = (0, import_react21.useRef)(getToken);
41111
+ const baseUrlRef = (0, import_react21.useRef)(baseUrl);
41112
+ (0, import_react21.useEffect)(() => {
40966
41113
  getTokenRef.current = getToken;
40967
41114
  baseUrlRef.current = baseUrl;
40968
41115
  });
40969
- const fetchTools = (0, import_react20.useCallback)(async (forceRefresh = false) => {
41116
+ const fetchTools = (0, import_react21.useCallback)(async (forceRefresh = false) => {
40970
41117
  setIsLoading(true);
40971
41118
  setError(null);
40972
41119
  try {
@@ -40983,13 +41130,13 @@ function useTools(options) {
40983
41130
  setIsLoading(false);
40984
41131
  }
40985
41132
  }, []);
40986
- const refresh = (0, import_react20.useCallback)(
41133
+ const refresh = (0, import_react21.useCallback)(
40987
41134
  async (force = false) => {
40988
41135
  await fetchTools(force);
40989
41136
  },
40990
41137
  [fetchTools]
40991
41138
  );
40992
- const checkForUpdates = (0, import_react20.useCallback)(
41139
+ const checkForUpdates = (0, import_react21.useCallback)(
40993
41140
  (responseChecksum) => {
40994
41141
  if (shouldRefreshTools(responseChecksum)) {
40995
41142
  void refresh(true);
@@ -40999,8 +41146,8 @@ function useTools(options) {
40999
41146
  },
41000
41147
  [refresh]
41001
41148
  );
41002
- const hasFetchedRef = (0, import_react20.useRef)(false);
41003
- (0, import_react20.useEffect)(() => {
41149
+ const hasFetchedRef = (0, import_react21.useRef)(false);
41150
+ (0, import_react21.useEffect)(() => {
41004
41151
  if (autoFetch && !hasFetchedRef.current) {
41005
41152
  hasFetchedRef.current = true;
41006
41153
  void fetchTools();
@@ -41020,10 +41167,10 @@ function useTools(options) {
41020
41167
  }
41021
41168
 
41022
41169
  // src/react/useUIInteraction.ts
41023
- var import_react21 = require("react");
41024
- var UIInteractionContext = (0, import_react21.createContext)(null);
41170
+ var import_react22 = require("react");
41171
+ var UIInteractionContext = (0, import_react22.createContext)(null);
41025
41172
  function useUIInteraction() {
41026
- const context = (0, import_react21.useContext)(UIInteractionContext);
41173
+ const context = (0, import_react22.useContext)(UIInteractionContext);
41027
41174
  if (!context) {
41028
41175
  throw new Error("useUIInteraction must be used within UIInteractionProvider");
41029
41176
  }
@@ -41033,11 +41180,11 @@ function UIInteractionProvider({
41033
41180
  children,
41034
41181
  timeout = 5 * 60 * 1e3
41035
41182
  }) {
41036
- const [pendingInteractions, setPendingInteractions] = (0, import_react21.useState)(
41183
+ const [pendingInteractions, setPendingInteractions] = (0, import_react22.useState)(
41037
41184
  /* @__PURE__ */ new Map()
41038
41185
  );
41039
- const timersRef = (0, import_react21.useRef)(/* @__PURE__ */ new Map());
41040
- const createInteraction = (0, import_react21.useCallback)(
41186
+ const timersRef = (0, import_react22.useRef)(/* @__PURE__ */ new Map());
41187
+ const createInteraction = (0, import_react22.useCallback)(
41041
41188
  (id2, type, data) => {
41042
41189
  return new Promise((resolve, reject) => {
41043
41190
  const interaction = {
@@ -41068,7 +41215,7 @@ function UIInteractionProvider({
41068
41215
  },
41069
41216
  [timeout]
41070
41217
  );
41071
- const createDisplayInteraction = (0, import_react21.useCallback)(
41218
+ const createDisplayInteraction = (0, import_react22.useCallback)(
41072
41219
  (id2, displayType, data, result, toolVersion, replacesInteractionId) => {
41073
41220
  setPendingInteractions((prev) => {
41074
41221
  const next = new Map(prev);
@@ -41100,7 +41247,7 @@ function UIInteractionProvider({
41100
41247
  },
41101
41248
  []
41102
41249
  );
41103
- const resolveInteraction = (0, import_react21.useCallback)((id2, result) => {
41250
+ const resolveInteraction = (0, import_react22.useCallback)((id2, result) => {
41104
41251
  setPendingInteractions((prev) => {
41105
41252
  const interaction = prev.get(id2);
41106
41253
  if (!interaction) {
@@ -41117,7 +41264,7 @@ function UIInteractionProvider({
41117
41264
  return next;
41118
41265
  });
41119
41266
  }, []);
41120
- const clearInteractions = (0, import_react21.useCallback)(() => {
41267
+ const clearInteractions = (0, import_react22.useCallback)(() => {
41121
41268
  for (const timer of timersRef.current.values()) {
41122
41269
  clearTimeout(timer);
41123
41270
  }
@@ -41131,7 +41278,7 @@ function UIInteractionProvider({
41131
41278
  return /* @__PURE__ */ new Map();
41132
41279
  });
41133
41280
  }, []);
41134
- const cancelInteraction = (0, import_react21.useCallback)((id2) => {
41281
+ const cancelInteraction = (0, import_react22.useCallback)((id2) => {
41135
41282
  setPendingInteractions((prev) => {
41136
41283
  const interaction = prev.get(id2);
41137
41284
  if (!interaction) {
@@ -41148,13 +41295,13 @@ function UIInteractionProvider({
41148
41295
  return next;
41149
41296
  });
41150
41297
  }, []);
41151
- const getInteraction = (0, import_react21.useCallback)(
41298
+ const getInteraction = (0, import_react22.useCallback)(
41152
41299
  (id2) => {
41153
41300
  return pendingInteractions.get(id2);
41154
41301
  },
41155
41302
  [pendingInteractions]
41156
41303
  );
41157
- const contextValue = (0, import_react21.useMemo)(
41304
+ const contextValue = (0, import_react22.useMemo)(
41158
41305
  () => ({
41159
41306
  pendingInteractions,
41160
41307
  createInteraction,
@@ -41174,11 +41321,11 @@ function UIInteractionProvider({
41174
41321
  getInteraction
41175
41322
  ]
41176
41323
  );
41177
- return (0, import_react21.createElement)(UIInteractionContext.Provider, { value: contextValue }, children);
41324
+ return (0, import_react22.createElement)(UIInteractionContext.Provider, { value: contextValue }, children);
41178
41325
  }
41179
41326
 
41180
41327
  // src/react/useVoice.ts
41181
- var import_react22 = require("react");
41328
+ var import_react23 = require("react");
41182
41329
  function getOnDeviceSpeechRecognition() {
41183
41330
  if (typeof window === "undefined") return null;
41184
41331
  if (!/iPhone|iPad|iPod/.test(navigator.userAgent)) return null;
@@ -41230,24 +41377,24 @@ async function audioToFloat32(blob) {
41230
41377
  }
41231
41378
  }
41232
41379
  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)(() => {
41380
+ const [isRecording, setIsRecording] = (0, import_react23.useState)(false);
41381
+ const [isTranscribing, setIsTranscribing] = (0, import_react23.useState)(false);
41382
+ const [isModelLoaded, setIsModelLoaded] = (0, import_react23.useState)(false);
41383
+ const [isLoadingModel, setIsLoadingModel] = (0, import_react23.useState)(false);
41384
+ const [recording, setRecording] = (0, import_react23.useState)(null);
41385
+ const [transcription, setTranscription] = (0, import_react23.useState)(null);
41386
+ const [error, setError] = (0, import_react23.useState)(null);
41387
+ const mediaRecorderRef = (0, import_react23.useRef)(null);
41388
+ const mediaStreamRef = (0, import_react23.useRef)(null);
41389
+ const chunksRef = (0, import_react23.useRef)([]);
41390
+ const startTimeRef = (0, import_react23.useRef)(0);
41391
+ const pipelineRef = (0, import_react23.useRef)(null);
41392
+ const modelNameRef = (0, import_react23.useRef)(null);
41393
+ const getModelName = (0, import_react23.useCallback)(() => {
41247
41394
  const model = options?.model ?? "whisper-tiny";
41248
41395
  return `onnx-community/${model}`;
41249
41396
  }, [options?.model]);
41250
- const loadPipeline = (0, import_react22.useCallback)(async () => {
41397
+ const loadPipeline = (0, import_react23.useCallback)(async () => {
41251
41398
  const modelName = getModelName();
41252
41399
  if (pipelineRef.current && modelNameRef.current === modelName) {
41253
41400
  return pipelineRef.current;
@@ -41282,10 +41429,10 @@ function useVoice(options) {
41282
41429
  setIsLoadingModel(false);
41283
41430
  }
41284
41431
  }, [getModelName, options?.onModelProgress]);
41285
- const preloadModel = (0, import_react22.useCallback)(async () => {
41432
+ const preloadModel = (0, import_react23.useCallback)(async () => {
41286
41433
  await loadPipeline();
41287
41434
  }, [loadPipeline]);
41288
- const disposeModel = (0, import_react22.useCallback)(async () => {
41435
+ const disposeModel = (0, import_react23.useCallback)(async () => {
41289
41436
  const pipe = pipelineRef.current;
41290
41437
  if (pipe?.dispose) {
41291
41438
  await pipe.dispose();
@@ -41294,7 +41441,7 @@ function useVoice(options) {
41294
41441
  modelNameRef.current = null;
41295
41442
  setIsModelLoaded(false);
41296
41443
  }, []);
41297
- const startRecording = (0, import_react22.useCallback)(async () => {
41444
+ const startRecording = (0, import_react23.useCallback)(async () => {
41298
41445
  setError(null);
41299
41446
  setRecording(null);
41300
41447
  setTranscription(null);
@@ -41319,7 +41466,7 @@ function useVoice(options) {
41319
41466
  throw processedError;
41320
41467
  }
41321
41468
  }, []);
41322
- const stopRecording = (0, import_react22.useCallback)(async () => {
41469
+ const stopRecording = (0, import_react23.useCallback)(async () => {
41323
41470
  return new Promise((resolve, reject) => {
41324
41471
  const recorder = mediaRecorderRef.current;
41325
41472
  if (!recorder || recorder.state === "inactive") {
@@ -41349,7 +41496,7 @@ function useVoice(options) {
41349
41496
  recorder.stop();
41350
41497
  });
41351
41498
  }, []);
41352
- const transcribe = (0, import_react22.useCallback)(
41499
+ const transcribe = (0, import_react23.useCallback)(
41353
41500
  async (rec) => {
41354
41501
  const target = rec ?? recording;
41355
41502
  if (!target) {
@@ -41382,12 +41529,12 @@ function useVoice(options) {
41382
41529
  },
41383
41530
  [recording, loadPipeline, options?.language]
41384
41531
  );
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)(() => {
41532
+ const nativeSpeechAvailable = (0, import_react23.useMemo)(() => getOnDeviceSpeechRecognition() !== null, []);
41533
+ const [isNativeListening, setIsNativeListening] = (0, import_react23.useState)(false);
41534
+ const nativeRecognitionRef = (0, import_react23.useRef)(null);
41535
+ const nativeTextRef = (0, import_react23.useRef)("");
41536
+ const nativeResolveRef = (0, import_react23.useRef)(null);
41537
+ const startNativeTranscription = (0, import_react23.useCallback)(() => {
41391
41538
  const SR = getOnDeviceSpeechRecognition();
41392
41539
  if (!SR) return;
41393
41540
  nativeTextRef.current = "";
@@ -41424,7 +41571,7 @@ function useVoice(options) {
41424
41571
  recognition.start();
41425
41572
  setIsNativeListening(true);
41426
41573
  }, [options?.language]);
41427
- const stopNativeTranscription = (0, import_react22.useCallback)(() => {
41574
+ const stopNativeTranscription = (0, import_react23.useCallback)(() => {
41428
41575
  return new Promise((resolve) => {
41429
41576
  const recognition = nativeRecognitionRef.current;
41430
41577
  if (!recognition) {
@@ -41435,7 +41582,7 @@ function useVoice(options) {
41435
41582
  recognition.stop();
41436
41583
  });
41437
41584
  }, []);
41438
- const abortNativeTranscription = (0, import_react22.useCallback)(() => {
41585
+ const abortNativeTranscription = (0, import_react23.useCallback)(() => {
41439
41586
  const recognition = nativeRecognitionRef.current;
41440
41587
  if (recognition) {
41441
41588
  nativeResolveRef.current = null;
@@ -41466,24 +41613,24 @@ function useVoice(options) {
41466
41613
  }
41467
41614
 
41468
41615
  // src/react/useWalletBinding.ts
41469
- var import_react23 = require("react");
41616
+ var import_react24 = require("react");
41470
41617
  init_clientConfig();
41471
41618
  function useWalletBinding(options = {}) {
41472
41619
  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)(() => {
41620
+ const [wallets, setWallets] = (0, import_react24.useState)([]);
41621
+ const [totals, setTotals] = (0, import_react24.useState)(null);
41622
+ const [isLoading, setIsLoading] = (0, import_react24.useState)(false);
41623
+ const [error, setError] = (0, import_react24.useState)(null);
41624
+ const getTokenRef = (0, import_react24.useRef)(getToken);
41625
+ const baseUrlRef = (0, import_react24.useRef)(baseUrl);
41626
+ const onErrorRef = (0, import_react24.useRef)(onError);
41627
+ const abortControllerRef = (0, import_react24.useRef)(null);
41628
+ (0, import_react24.useEffect)(() => {
41482
41629
  getTokenRef.current = getToken;
41483
41630
  baseUrlRef.current = baseUrl;
41484
41631
  onErrorRef.current = onError;
41485
41632
  });
41486
- (0, import_react23.useEffect)(() => {
41633
+ (0, import_react24.useEffect)(() => {
41487
41634
  return () => {
41488
41635
  if (abortControllerRef.current) {
41489
41636
  abortControllerRef.current.abort();
@@ -41491,7 +41638,7 @@ function useWalletBinding(options = {}) {
41491
41638
  }
41492
41639
  };
41493
41640
  }, []);
41494
- const getHeaders = (0, import_react23.useCallback)(async () => {
41641
+ const getHeaders = (0, import_react24.useCallback)(async () => {
41495
41642
  const headers = {};
41496
41643
  if (getTokenRef.current) {
41497
41644
  const token = await getTokenRef.current();
@@ -41501,13 +41648,13 @@ function useWalletBinding(options = {}) {
41501
41648
  }
41502
41649
  return headers;
41503
41650
  }, []);
41504
- const handleError = (0, import_react23.useCallback)((err) => {
41651
+ const handleError = (0, import_react24.useCallback)((err) => {
41505
41652
  const error2 = err instanceof Error ? err : new Error(String(err));
41506
41653
  setError(error2);
41507
41654
  onErrorRef.current?.(error2);
41508
41655
  return error2;
41509
41656
  }, []);
41510
- const fetchBinding = (0, import_react23.useCallback)(async () => {
41657
+ const fetchBinding = (0, import_react24.useCallback)(async () => {
41511
41658
  if (abortControllerRef.current) {
41512
41659
  abortControllerRef.current.abort();
41513
41660
  }
@@ -41545,12 +41692,12 @@ function useWalletBinding(options = {}) {
41545
41692
  }
41546
41693
  }
41547
41694
  }, [getHeaders, handleError]);
41548
- const refetch = (0, import_react23.useCallback)(async () => {
41695
+ const refetch = (0, import_react24.useCallback)(async () => {
41549
41696
  setWallets([]);
41550
41697
  setTotals(null);
41551
41698
  await fetchBinding();
41552
41699
  }, [fetchBinding]);
41553
- const getNonce = (0, import_react23.useCallback)(async () => {
41700
+ const getNonce = (0, import_react24.useCallback)(async () => {
41554
41701
  setIsLoading(true);
41555
41702
  setError(null);
41556
41703
  try {
@@ -41571,7 +41718,7 @@ function useWalletBinding(options = {}) {
41571
41718
  setIsLoading(false);
41572
41719
  }
41573
41720
  }, [getHeaders, handleError]);
41574
- const bindWallet = (0, import_react23.useCallback)(
41721
+ const bindWallet = (0, import_react24.useCallback)(
41575
41722
  async (request) => {
41576
41723
  setIsLoading(true);
41577
41724
  setError(null);
@@ -41597,7 +41744,7 @@ function useWalletBinding(options = {}) {
41597
41744
  },
41598
41745
  [getHeaders, handleError, fetchBinding]
41599
41746
  );
41600
- const unbindWallet = (0, import_react23.useCallback)(
41747
+ const unbindWallet = (0, import_react24.useCallback)(
41601
41748
  async (address) => {
41602
41749
  setIsLoading(true);
41603
41750
  setError(null);
@@ -41623,8 +41770,8 @@ function useWalletBinding(options = {}) {
41623
41770
  },
41624
41771
  [getHeaders, handleError, fetchBinding]
41625
41772
  );
41626
- const hasFetchedRef = (0, import_react23.useRef)(false);
41627
- (0, import_react23.useEffect)(() => {
41773
+ const hasFetchedRef = (0, import_react24.useRef)(false);
41774
+ (0, import_react24.useEffect)(() => {
41628
41775
  if (autoFetch && !hasFetchedRef.current) {
41629
41776
  hasFetchedRef.current = true;
41630
41777
  void fetchBinding();