@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.
- package/dist/expo/{chunk-WRZTH4OS.mjs → chunk-ZIN4E7MR.mjs} +7 -0
- package/dist/expo/{consolidate-HKL5EGZT.mjs → consolidate-4WLZMXOS.mjs} +1 -1
- package/dist/expo/index.cjs +260 -113
- package/dist/expo/index.d.mts +3 -0
- package/dist/expo/index.d.ts +3 -0
- package/dist/expo/index.mjs +228 -89
- package/dist/index.cjs +7 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +7 -0
- package/dist/react/{chunk-RSA3S6OA.mjs → chunk-7JYVPYGQ.mjs} +7 -0
- package/dist/react/{consolidate-WFTPBHDV.mjs → consolidate-3RQL75PJ.mjs} +1 -1
- package/dist/react/index.cjs +566 -419
- package/dist/react/index.d.mts +3 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.mjs +418 -279
- package/dist/server/{chunk-QEROZ4VH.mjs → chunk-QK62YWBH.mjs} +7 -0
- package/dist/server/{consolidate-PYED62LW.mjs → consolidate-NW4UVA6T.mjs} +1 -1
- package/dist/server/index.cjs +67 -10
- package/dist/server/index.d.mts +3 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.mjs +62 -12
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
taskTypeHeader,
|
|
20
20
|
validateEndpointOverride,
|
|
21
21
|
withInternalFlowMarker
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-7JYVPYGQ.mjs";
|
|
23
23
|
import {
|
|
24
24
|
BASE_URL,
|
|
25
25
|
MCP_R2_DOMAIN,
|
|
@@ -671,12 +671,12 @@ async function persistKeyPair(address, startEpoch) {
|
|
|
671
671
|
const combined = new Uint8Array(iv.length + encryptedBytes.length);
|
|
672
672
|
combined.set(iv, 0);
|
|
673
673
|
combined.set(encryptedBytes, iv.length);
|
|
674
|
-
const
|
|
674
|
+
const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
|
|
675
675
|
const encryptedHex = bytesToHex(combined);
|
|
676
676
|
if (sessionEpoch !== startEpoch) {
|
|
677
677
|
return;
|
|
678
678
|
}
|
|
679
|
-
localStorage.setItem(
|
|
679
|
+
localStorage.setItem(storageKey2, encryptedHex);
|
|
680
680
|
} catch (err) {
|
|
681
681
|
throw new Error(
|
|
682
682
|
`Failed to persist keypair: ${err instanceof Error ? err.message : String(err)}`
|
|
@@ -687,8 +687,8 @@ async function loadPersistedKeyPair(address) {
|
|
|
687
687
|
if (typeof window === "undefined") {
|
|
688
688
|
return null;
|
|
689
689
|
}
|
|
690
|
-
const
|
|
691
|
-
const encryptedHex = localStorage.getItem(
|
|
690
|
+
const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
|
|
691
|
+
const encryptedHex = localStorage.getItem(storageKey2);
|
|
692
692
|
if (!encryptedHex) {
|
|
693
693
|
return null;
|
|
694
694
|
}
|
|
@@ -739,7 +739,7 @@ async function loadPersistedKeyPair(address) {
|
|
|
739
739
|
publicKey
|
|
740
740
|
};
|
|
741
741
|
} catch (error) {
|
|
742
|
-
localStorage.removeItem(
|
|
742
|
+
localStorage.removeItem(storageKey2);
|
|
743
743
|
getLogger().warn(
|
|
744
744
|
`Failed to load persisted keypair for ${address}: ${error instanceof Error ? error.message : String(error)}`
|
|
745
745
|
);
|
|
@@ -750,8 +750,8 @@ function clearPersistedKeyPair(address) {
|
|
|
750
750
|
if (typeof window === "undefined") {
|
|
751
751
|
return;
|
|
752
752
|
}
|
|
753
|
-
const
|
|
754
|
-
localStorage.removeItem(
|
|
753
|
+
const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
|
|
754
|
+
localStorage.removeItem(storageKey2);
|
|
755
755
|
}
|
|
756
756
|
async function getKeyPair(address, signMessage, embeddedWalletSigner) {
|
|
757
757
|
const existingKeyPair = getStoredKeyPair(address);
|
|
@@ -8658,6 +8658,9 @@ var StreamSmoother = class {
|
|
|
8658
8658
|
this.rampDuration = config.rampDuration ?? 4e3;
|
|
8659
8659
|
}
|
|
8660
8660
|
}
|
|
8661
|
+
get hasPendingOutput() {
|
|
8662
|
+
return this.buffer.length > 0;
|
|
8663
|
+
}
|
|
8661
8664
|
/**
|
|
8662
8665
|
* Add text to the buffer. If smoothing is disabled, passes through immediately.
|
|
8663
8666
|
*/
|
|
@@ -9326,6 +9329,34 @@ async function runToolLoop(options) {
|
|
|
9326
9329
|
toolsChecksum: acc.toolsChecksum
|
|
9327
9330
|
};
|
|
9328
9331
|
};
|
|
9332
|
+
const drainSmoothers = async (acc, smoothers) => {
|
|
9333
|
+
let playbackAborted = false;
|
|
9334
|
+
const stopPlayback = () => {
|
|
9335
|
+
for (const smoother of smoothers) {
|
|
9336
|
+
if (isDetach()) smoother.flush();
|
|
9337
|
+
else smoother.destroy();
|
|
9338
|
+
}
|
|
9339
|
+
};
|
|
9340
|
+
const onAbort = () => {
|
|
9341
|
+
playbackAborted = !isDetach() && smoothers.some((smoother) => smoother.hasPendingOutput);
|
|
9342
|
+
stopPlayback();
|
|
9343
|
+
};
|
|
9344
|
+
combinedSignal?.addEventListener("abort", onAbort, { once: true });
|
|
9345
|
+
try {
|
|
9346
|
+
if (combinedSignal?.aborted) stopPlayback();
|
|
9347
|
+
await Promise.all(smoothers.map((smoother) => smoother.drain()));
|
|
9348
|
+
if (!playbackAborted) return;
|
|
9349
|
+
await fireAfterModelCall(buildModelCallEndPayload(acc, { error: "aborted" }));
|
|
9350
|
+
await fireRunError({ error: "Request aborted", stage: "model" });
|
|
9351
|
+
return {
|
|
9352
|
+
data: buildResponseFinal(acc),
|
|
9353
|
+
error: "Request aborted",
|
|
9354
|
+
toolsChecksum: acc.toolsChecksum
|
|
9355
|
+
};
|
|
9356
|
+
} finally {
|
|
9357
|
+
combinedSignal?.removeEventListener("abort", onAbort);
|
|
9358
|
+
}
|
|
9359
|
+
};
|
|
9329
9360
|
for (let attempt = 0; attempt < STREAM_RETRY_MAX_ATTEMPTS; attempt++) {
|
|
9330
9361
|
sseError = null;
|
|
9331
9362
|
if (combinedSignal?.aborted) {
|
|
@@ -9463,7 +9494,8 @@ async function runToolLoop(options) {
|
|
|
9463
9494
|
contentSmoother.flush();
|
|
9464
9495
|
thinkingSmoother.flush();
|
|
9465
9496
|
} else {
|
|
9466
|
-
await
|
|
9497
|
+
const interrupted = await drainSmoothers(accumulator, [contentSmoother, thinkingSmoother]);
|
|
9498
|
+
if (interrupted) return interrupted;
|
|
9467
9499
|
}
|
|
9468
9500
|
flushDeAnon();
|
|
9469
9501
|
await fireAfterModelCall(buildModelCallEndPayload(accumulator));
|
|
@@ -9982,7 +10014,11 @@ Executing tool: ${toolInfo}
|
|
|
9982
10014
|
contContentSmoother.flush();
|
|
9983
10015
|
contThinkingSmoother.flush();
|
|
9984
10016
|
} else {
|
|
9985
|
-
await
|
|
10017
|
+
const interrupted = await drainSmoothers(currentAccumulator, [
|
|
10018
|
+
contContentSmoother,
|
|
10019
|
+
contThinkingSmoother
|
|
10020
|
+
]);
|
|
10021
|
+
if (interrupted) return interrupted;
|
|
9986
10022
|
}
|
|
9987
10023
|
flushDeAnon();
|
|
9988
10024
|
await fireAfterModelCall(buildModelCallEndPayload(currentAccumulator));
|
|
@@ -10113,6 +10149,8 @@ async function resumeStream(options) {
|
|
|
10113
10149
|
let watchdog;
|
|
10114
10150
|
let idleFired = false;
|
|
10115
10151
|
let callerAborted = false;
|
|
10152
|
+
let playbackAborted = false;
|
|
10153
|
+
let draining = false;
|
|
10116
10154
|
let settled = false;
|
|
10117
10155
|
const idleEnabled = idleTimeoutMs > 0 && idleTimeoutMs !== Infinity && typeof setTimeout === "function";
|
|
10118
10156
|
const armWatchdog = () => {
|
|
@@ -10132,6 +10170,9 @@ async function resumeStream(options) {
|
|
|
10132
10170
|
const abortMessage = () => callerAborted ? "Resume aborted" : idleFired ? "Resume timed out" : "Resume aborted";
|
|
10133
10171
|
const onCallerAbort = () => {
|
|
10134
10172
|
callerAborted = true;
|
|
10173
|
+
playbackAborted = draining && (contentSmoother.hasPendingOutput || thinkingSmoother.hasPendingOutput);
|
|
10174
|
+
contentSmoother.destroy();
|
|
10175
|
+
thinkingSmoother.destroy();
|
|
10135
10176
|
disarmWatchdog();
|
|
10136
10177
|
idleController.abort();
|
|
10137
10178
|
};
|
|
@@ -10215,15 +10256,24 @@ async function resumeStream(options) {
|
|
|
10215
10256
|
statusCode
|
|
10216
10257
|
};
|
|
10217
10258
|
}
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10259
|
+
settled = true;
|
|
10260
|
+
disarmWatchdog();
|
|
10261
|
+
try {
|
|
10262
|
+
if (idleFired) return buildInterrupted(abortMessage());
|
|
10263
|
+
if (accumulator.toolCalls.size > 0) {
|
|
10264
|
+
return buildInterrupted("Stream ended with a pending tool request");
|
|
10265
|
+
}
|
|
10266
|
+
draining = true;
|
|
10267
|
+
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
10268
|
+
if (playbackAborted) return buildInterrupted(abortMessage());
|
|
10269
|
+
const response = strategy.buildFinalResponse(accumulator);
|
|
10270
|
+
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
10271
|
+
if (onFinish && deliveredOutput) onFinish(response);
|
|
10272
|
+
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
10273
|
+
} finally {
|
|
10274
|
+
draining = false;
|
|
10275
|
+
cleanup();
|
|
10221
10276
|
}
|
|
10222
|
-
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
10223
|
-
const response = strategy.buildFinalResponse(accumulator);
|
|
10224
|
-
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
10225
|
-
if (onFinish && deliveredOutput) onFinish(response);
|
|
10226
|
-
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
10227
10277
|
}
|
|
10228
10278
|
|
|
10229
10279
|
// src/lib/chat/stockPriceCentroids.ts
|
|
@@ -19964,11 +20014,11 @@ function loadVaultCorpus(ctx, options, preparation) {
|
|
|
19964
20014
|
}
|
|
19965
20015
|
return request;
|
|
19966
20016
|
}
|
|
19967
|
-
function rowRequestsFor(
|
|
19968
|
-
let byMask =
|
|
20017
|
+
function rowRequestsFor(registry3, ctx, maskInput) {
|
|
20018
|
+
let byMask = registry3.get(ctx);
|
|
19969
20019
|
if (!byMask) {
|
|
19970
20020
|
byMask = /* @__PURE__ */ new Map();
|
|
19971
|
-
|
|
20021
|
+
registry3.set(ctx, byMask);
|
|
19972
20022
|
}
|
|
19973
20023
|
let requests = byMask.get(maskInput);
|
|
19974
20024
|
if (!requests) {
|
|
@@ -20903,11 +20953,11 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
20903
20953
|
};
|
|
20904
20954
|
}
|
|
20905
20955
|
const limit = searchOptions?.limit ?? 5;
|
|
20906
|
-
const
|
|
20956
|
+
const scopes2 = searchOptions?.scopes;
|
|
20907
20957
|
const folderId = searchOptions?.folderId;
|
|
20908
20958
|
const queryOpts = {};
|
|
20909
20959
|
if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
|
|
20910
|
-
if (
|
|
20960
|
+
if (scopes2?.length) queryOpts.scopes = scopes2;
|
|
20911
20961
|
if (folderId !== void 0) queryOpts.folderId = folderId;
|
|
20912
20962
|
if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
|
|
20913
20963
|
if (searchOptions?.includeArchived) queryOpts.includeArchived = true;
|
|
@@ -21685,7 +21735,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
21685
21735
|
content: m.content,
|
|
21686
21736
|
similarity: m.similarity
|
|
21687
21737
|
}));
|
|
21688
|
-
const { consolidateMemory: doConsolidate } = await import("./consolidate-
|
|
21738
|
+
const { consolidateMemory: doConsolidate } = await import("./consolidate-3RQL75PJ.mjs");
|
|
21689
21739
|
const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
|
|
21690
21740
|
if (decision.action === "create") return decision.fallbackReason ? null : { create: true };
|
|
21691
21741
|
if (decision.action === "supersede" && decision.content) {
|
|
@@ -27190,17 +27240,17 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
27190
27240
|
}
|
|
27191
27241
|
const recallCtx = store ? { embeddingOptions: ctx.embeddingOptions, factSource: store.factSource } : ctx;
|
|
27192
27242
|
const facets = options.facets ?? DEFAULT_PROFILE_FACETS;
|
|
27193
|
-
const
|
|
27243
|
+
const scopes2 = options.scopes ?? DEFAULT_SCOPES;
|
|
27194
27244
|
const config = {
|
|
27195
27245
|
facetKeys: facets.map((f) => f.key).sort(),
|
|
27196
27246
|
facetsSignature: facetsSignature(facets),
|
|
27197
|
-
scopes: [...
|
|
27247
|
+
scopes: [...scopes2].sort(),
|
|
27198
27248
|
redacted: options.redactor !== void 0,
|
|
27199
27249
|
reviewedMemoryIdsSignature: reviewedMemoryIdsSignature(options.reviewedMemoryIds)
|
|
27200
27250
|
};
|
|
27201
27251
|
const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
|
|
27202
|
-
const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
|
|
27203
|
-
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
|
|
27252
|
+
const listOptions = { scopes: scopes2, includeDeleted: true, includeSuperseded: true };
|
|
27253
|
+
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes: scopes2 }), []];
|
|
27204
27254
|
const watermark = computeVaultWatermark(memories);
|
|
27205
27255
|
const observationTrends = summarizeObservationTrends(
|
|
27206
27256
|
memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
|
|
@@ -27245,7 +27295,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
27245
27295
|
for (const section of previous.sections) {
|
|
27246
27296
|
if (section.sourceMemoryIds.length > 0 && section.sourceMemoryIds.every((id2) => {
|
|
27247
27297
|
const memory = memoriesById.get(id2);
|
|
27248
|
-
return memory && !memory.isDeleted && !memory.supersededBy &&
|
|
27298
|
+
return memory && !memory.isDeleted && !memory.supersededBy && scopes2.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
|
|
27249
27299
|
})) {
|
|
27250
27300
|
fallbackPriors.set(section.key, section);
|
|
27251
27301
|
}
|
|
@@ -27418,7 +27468,7 @@ async function attributeFacts(ctx, candidates, facets) {
|
|
|
27418
27468
|
return keys;
|
|
27419
27469
|
}
|
|
27420
27470
|
async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
|
|
27421
|
-
const
|
|
27471
|
+
const scopes2 = options.scopes ?? DEFAULT_SCOPES;
|
|
27422
27472
|
const limit = options.limit ?? DEFAULT_FACET_RECALL_LIMIT;
|
|
27423
27473
|
const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
|
|
27424
27474
|
const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
|
|
@@ -27435,7 +27485,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
|
|
|
27435
27485
|
}
|
|
27436
27486
|
const recalled = await recall(facet.query, ctx, {
|
|
27437
27487
|
vaultPreparation,
|
|
27438
|
-
scopes,
|
|
27488
|
+
scopes: scopes2,
|
|
27439
27489
|
limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
|
|
27440
27490
|
...hasReviewGate && { memoryIds: [...reviewed] },
|
|
27441
27491
|
types: ["fact"],
|
|
@@ -27462,7 +27512,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
|
|
|
27462
27512
|
llmModel: options.llmModel ?? DEFAULT_SYNTHESIS_MODEL,
|
|
27463
27513
|
baseUrl: options.baseUrl,
|
|
27464
27514
|
fetchFn: options.fetchFn,
|
|
27465
|
-
scopes,
|
|
27515
|
+
scopes: scopes2,
|
|
27466
27516
|
limit,
|
|
27467
27517
|
types: ["fact"],
|
|
27468
27518
|
maxTokens: DEFAULT_FACET_MAX_TOKENS,
|
|
@@ -30372,8 +30422,8 @@ var ZipProcessor = class {
|
|
|
30372
30422
|
* Set the processor registry for handling nested files
|
|
30373
30423
|
* This must be called before processing if you want nested file support
|
|
30374
30424
|
*/
|
|
30375
|
-
setRegistry(
|
|
30376
|
-
this.registry =
|
|
30425
|
+
setRegistry(registry3) {
|
|
30426
|
+
this.registry = registry3;
|
|
30377
30427
|
}
|
|
30378
30428
|
async process(file) {
|
|
30379
30429
|
try {
|
|
@@ -30594,15 +30644,15 @@ function isImageFile(file) {
|
|
|
30594
30644
|
return (file.type ?? "").trim().toLowerCase().startsWith("image/");
|
|
30595
30645
|
}
|
|
30596
30646
|
function createDefaultRegistry() {
|
|
30597
|
-
const
|
|
30598
|
-
|
|
30599
|
-
|
|
30600
|
-
|
|
30601
|
-
|
|
30647
|
+
const registry3 = new ProcessorRegistry();
|
|
30648
|
+
registry3.register(new PdfProcessor());
|
|
30649
|
+
registry3.register(new ExcelProcessor());
|
|
30650
|
+
registry3.register(new WordProcessor());
|
|
30651
|
+
registry3.register(new TextProcessor());
|
|
30602
30652
|
const zipProcessor = new ZipProcessor();
|
|
30603
|
-
zipProcessor.setRegistry(
|
|
30604
|
-
|
|
30605
|
-
return
|
|
30653
|
+
zipProcessor.setRegistry(registry3);
|
|
30654
|
+
registry3.register(zipProcessor);
|
|
30655
|
+
return registry3;
|
|
30606
30656
|
}
|
|
30607
30657
|
var cachedDefaultRegistry = null;
|
|
30608
30658
|
function getDefaultRegistry() {
|
|
@@ -30615,10 +30665,10 @@ function isSupportedFile(file) {
|
|
|
30615
30665
|
return getDefaultRegistry().isSupported(file);
|
|
30616
30666
|
}
|
|
30617
30667
|
function getSupportedFileTypes() {
|
|
30618
|
-
const
|
|
30668
|
+
const registry3 = getDefaultRegistry();
|
|
30619
30669
|
return {
|
|
30620
|
-
mimeTypes:
|
|
30621
|
-
extensions:
|
|
30670
|
+
mimeTypes: registry3.getSupportedMimeTypes(),
|
|
30671
|
+
extensions: registry3.getSupportedExtensions()
|
|
30622
30672
|
};
|
|
30623
30673
|
}
|
|
30624
30674
|
function formatExtractedContent(fileName, content, format) {
|
|
@@ -30673,16 +30723,16 @@ async function preprocessFiles(files, options = {}) {
|
|
|
30673
30723
|
metadata: { processedCount: 0, skippedCount: fileStatuses2.length, errorCount: 0 }
|
|
30674
30724
|
};
|
|
30675
30725
|
}
|
|
30676
|
-
let
|
|
30726
|
+
let registry3;
|
|
30677
30727
|
if (processors === void 0) {
|
|
30678
|
-
|
|
30728
|
+
registry3 = getDefaultRegistry();
|
|
30679
30729
|
} else {
|
|
30680
|
-
|
|
30730
|
+
registry3 = new ProcessorRegistry();
|
|
30681
30731
|
processors.forEach((p) => {
|
|
30682
30732
|
if (p instanceof ZipProcessor) {
|
|
30683
|
-
p.setRegistry(
|
|
30733
|
+
p.setRegistry(registry3);
|
|
30684
30734
|
}
|
|
30685
|
-
|
|
30735
|
+
registry3.register(p);
|
|
30686
30736
|
});
|
|
30687
30737
|
}
|
|
30688
30738
|
const extractedTexts = [];
|
|
@@ -30702,7 +30752,7 @@ async function preprocessFiles(files, options = {}) {
|
|
|
30702
30752
|
fileStatuses.push({ fileId: file.id, fileName: file.name, status: "skipped", reason });
|
|
30703
30753
|
};
|
|
30704
30754
|
onProgress?.(i + 1, files.length, file.name);
|
|
30705
|
-
const processor =
|
|
30755
|
+
const processor = registry3.findProcessor(file);
|
|
30706
30756
|
if (!processor && isImageFile(file)) continue;
|
|
30707
30757
|
if (file.size > maxFileSizeBytes) {
|
|
30708
30758
|
logger.info(
|
|
@@ -33783,7 +33833,7 @@ function useChat(options) {
|
|
|
33783
33833
|
}
|
|
33784
33834
|
|
|
33785
33835
|
// src/react/useChatStorage.ts
|
|
33786
|
-
import { useCallback as
|
|
33836
|
+
import { useCallback as useCallback6, useEffect as useEffect5, useMemo as useMemo4, useRef as useRef4, useState as useState5 } from "react";
|
|
33787
33837
|
import { v7 as uuidv78 } from "uuid";
|
|
33788
33838
|
|
|
33789
33839
|
// src/lib/chat/assembleMessages.ts
|
|
@@ -34347,6 +34397,106 @@ function summaryStore(options) {
|
|
|
34347
34397
|
};
|
|
34348
34398
|
}
|
|
34349
34399
|
|
|
34400
|
+
// src/lib/pii/useConversationRedactors.ts
|
|
34401
|
+
import { useCallback as useCallback4, useEffect as useEffect4, useSyncExternalStore } from "react";
|
|
34402
|
+
var REDACTOR_LIMIT = 50;
|
|
34403
|
+
var registry2 = /* @__PURE__ */ new WeakMap();
|
|
34404
|
+
var compositeKeys = /* @__PURE__ */ new WeakMap();
|
|
34405
|
+
var scopes = /* @__PURE__ */ new Set();
|
|
34406
|
+
var retiredRedactor = new PiiRedactor();
|
|
34407
|
+
retiredRedactor.dispose();
|
|
34408
|
+
function retireScope(scope) {
|
|
34409
|
+
scopes.delete(scope);
|
|
34410
|
+
if (!scope.active) return;
|
|
34411
|
+
scope.active = false;
|
|
34412
|
+
for (const { redactor } of scope.redactors.values()) redactor.dispose();
|
|
34413
|
+
scope.redactors.clear();
|
|
34414
|
+
for (const redactor of scope.evicted) redactor.dispose();
|
|
34415
|
+
scope.evicted = [];
|
|
34416
|
+
for (const notify of scope.subscribers) notify();
|
|
34417
|
+
}
|
|
34418
|
+
function storageKey(storage, secondaryStorage) {
|
|
34419
|
+
if (!secondaryStorage) return storage;
|
|
34420
|
+
let inner = compositeKeys.get(storage);
|
|
34421
|
+
if (!inner) {
|
|
34422
|
+
inner = /* @__PURE__ */ new WeakMap();
|
|
34423
|
+
compositeKeys.set(storage, inner);
|
|
34424
|
+
}
|
|
34425
|
+
let key3 = inner.get(secondaryStorage);
|
|
34426
|
+
if (!key3) {
|
|
34427
|
+
key3 = {};
|
|
34428
|
+
inner.set(secondaryStorage, key3);
|
|
34429
|
+
}
|
|
34430
|
+
return key3;
|
|
34431
|
+
}
|
|
34432
|
+
function getScope(database, storage, account) {
|
|
34433
|
+
let stores = registry2.get(database);
|
|
34434
|
+
if (!stores) {
|
|
34435
|
+
stores = /* @__PURE__ */ new WeakMap();
|
|
34436
|
+
registry2.set(database, stores);
|
|
34437
|
+
}
|
|
34438
|
+
let accounts = stores.get(storage);
|
|
34439
|
+
if (!accounts) {
|
|
34440
|
+
accounts = /* @__PURE__ */ new Map();
|
|
34441
|
+
stores.set(storage, accounts);
|
|
34442
|
+
}
|
|
34443
|
+
let scope = accounts.get(account);
|
|
34444
|
+
if (!scope?.active) {
|
|
34445
|
+
scope = { active: true, users: 0, subscribers: /* @__PURE__ */ new Set(), redactors: /* @__PURE__ */ new Map(), evicted: [] };
|
|
34446
|
+
accounts.set(account, scope);
|
|
34447
|
+
}
|
|
34448
|
+
return scope;
|
|
34449
|
+
}
|
|
34450
|
+
onClearAllEncryptionState(() => {
|
|
34451
|
+
registry2 = /* @__PURE__ */ new WeakMap();
|
|
34452
|
+
for (const scope of [...scopes]) retireScope(scope);
|
|
34453
|
+
});
|
|
34454
|
+
function useConversationRedactors(database, account, storage, secondaryStorage) {
|
|
34455
|
+
const scope = getScope(database, storageKey(storage, secondaryStorage), account);
|
|
34456
|
+
const subscribe = useCallback4(
|
|
34457
|
+
(callback) => {
|
|
34458
|
+
scope.subscribers.add(callback);
|
|
34459
|
+
return () => {
|
|
34460
|
+
scope.subscribers.delete(callback);
|
|
34461
|
+
};
|
|
34462
|
+
},
|
|
34463
|
+
[scope]
|
|
34464
|
+
);
|
|
34465
|
+
const getSnapshot = useCallback4(() => scope.active ? scope : null, [scope]);
|
|
34466
|
+
useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
34467
|
+
useEffect4(() => {
|
|
34468
|
+
if (scope.active) scopes.add(scope);
|
|
34469
|
+
scope.users++;
|
|
34470
|
+
return () => {
|
|
34471
|
+
scope.users--;
|
|
34472
|
+
if (scope.users === 0) retireScope(scope);
|
|
34473
|
+
};
|
|
34474
|
+
}, [scope]);
|
|
34475
|
+
return useCallback4(
|
|
34476
|
+
(conversationId, nerDetector) => {
|
|
34477
|
+
if (!scope.active) return retiredRedactor;
|
|
34478
|
+
const cached = scope.redactors.get(conversationId);
|
|
34479
|
+
if (cached && cached.detector === nerDetector) {
|
|
34480
|
+
scope.redactors.delete(conversationId);
|
|
34481
|
+
scope.redactors.set(conversationId, cached);
|
|
34482
|
+
return cached.redactor;
|
|
34483
|
+
}
|
|
34484
|
+
if (cached) scope.evicted.push(cached.redactor);
|
|
34485
|
+
const redactor = new PiiRedactor({ nerDetector });
|
|
34486
|
+
scope.redactors.set(conversationId, { redactor, detector: nerDetector });
|
|
34487
|
+
if (scope.redactors.size > REDACTOR_LIMIT) {
|
|
34488
|
+
const oldest = scope.redactors.entries().next().value;
|
|
34489
|
+
if (oldest) {
|
|
34490
|
+
scope.evicted.push(oldest[1].redactor);
|
|
34491
|
+
scope.redactors.delete(oldest[0]);
|
|
34492
|
+
}
|
|
34493
|
+
}
|
|
34494
|
+
return redactor;
|
|
34495
|
+
},
|
|
34496
|
+
[scope]
|
|
34497
|
+
);
|
|
34498
|
+
}
|
|
34499
|
+
|
|
34350
34500
|
// src/lib/tools/selection/activeToolSets.ts
|
|
34351
34501
|
function mergeActiveToolSets(current, derived) {
|
|
34352
34502
|
if (derived.length === 0) return current;
|
|
@@ -34407,7 +34557,7 @@ function resetRecentToolSets() {
|
|
|
34407
34557
|
onClearAllEncryptionState(resetRecentToolSets);
|
|
34408
34558
|
|
|
34409
34559
|
// src/react/useChatMedia.ts
|
|
34410
|
-
import { useCallback as
|
|
34560
|
+
import { useCallback as useCallback5 } from "react";
|
|
34411
34561
|
function resolveMediaMeta(extractedKind, urlPath, reportedType) {
|
|
34412
34562
|
const isVideo = extractedKind === "video";
|
|
34413
34563
|
const extension = urlPath.match(/\.([a-zA-Z0-9]+)$/)?.[1] || (isVideo ? "mp4" : "png");
|
|
@@ -34420,7 +34570,7 @@ function resolveMediaMeta(extractedKind, urlPath, reportedType) {
|
|
|
34420
34570
|
}
|
|
34421
34571
|
function useChatMedia(options) {
|
|
34422
34572
|
const { mediaCtx, mcpR2Domain } = options;
|
|
34423
|
-
const getImageDimensions =
|
|
34573
|
+
const getImageDimensions = useCallback5(
|
|
34424
34574
|
async (blob) => {
|
|
34425
34575
|
if (!blob.type.startsWith("image/")) {
|
|
34426
34576
|
return void 0;
|
|
@@ -34447,7 +34597,7 @@ function useChatMedia(options) {
|
|
|
34447
34597
|
},
|
|
34448
34598
|
[]
|
|
34449
34599
|
);
|
|
34450
|
-
const extractAndStoreEncryptedMCPImages =
|
|
34600
|
+
const extractAndStoreEncryptedMCPImages = useCallback5(
|
|
34451
34601
|
async (content, address, conversationId, toolCallEvents) => {
|
|
34452
34602
|
let imageModel;
|
|
34453
34603
|
try {
|
|
@@ -34552,7 +34702,7 @@ function useChatMedia(options) {
|
|
|
34552
34702
|
},
|
|
34553
34703
|
[mediaCtx, getImageDimensions, mcpR2Domain]
|
|
34554
34704
|
);
|
|
34555
|
-
const storeUserFilesInOPFS =
|
|
34705
|
+
const storeUserFilesInOPFS = useCallback5(
|
|
34556
34706
|
async (files, address, conversationId, maxFileSizeBytes) => {
|
|
34557
34707
|
const canUseOPFS = isOPFSSupported() && hasEncryptionKey(address);
|
|
34558
34708
|
let encryptionKey;
|
|
@@ -34914,29 +35064,10 @@ async function storedToLlmapiMessage(stored2, encryptionKey, resolveMediaByIds)
|
|
|
34914
35064
|
}
|
|
34915
35065
|
return messages;
|
|
34916
35066
|
}
|
|
34917
|
-
var CONVERSATION_REDACTOR_LIMIT = 50;
|
|
34918
|
-
var NO_CONVERSATION_KEY = "__no_conversation__";
|
|
34919
35067
|
var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
|
|
34920
35068
|
var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
|
|
34921
35069
|
var MEMORY_STORE_NOT_READY = "Memory store is not ready";
|
|
34922
|
-
var conversationRedactors = /* @__PURE__ */ new Map();
|
|
34923
35070
|
var queuedBackends = /* @__PURE__ */ new WeakMap();
|
|
34924
|
-
function getConversationRedactor(conversationId, nerDetector) {
|
|
34925
|
-
const key3 = conversationId ?? NO_CONVERSATION_KEY;
|
|
34926
|
-
const cached = conversationRedactors.get(key3);
|
|
34927
|
-
if (cached && cached.detector === nerDetector) {
|
|
34928
|
-
conversationRedactors.delete(key3);
|
|
34929
|
-
conversationRedactors.set(key3, cached);
|
|
34930
|
-
return cached.redactor;
|
|
34931
|
-
}
|
|
34932
|
-
const redactor = new PiiRedactor({ nerDetector });
|
|
34933
|
-
conversationRedactors.set(key3, { redactor, detector: nerDetector });
|
|
34934
|
-
if (conversationRedactors.size > CONVERSATION_REDACTOR_LIMIT) {
|
|
34935
|
-
const oldest = conversationRedactors.keys().next().value;
|
|
34936
|
-
if (oldest !== void 0) conversationRedactors.delete(oldest);
|
|
34937
|
-
}
|
|
34938
|
-
return redactor;
|
|
34939
|
-
}
|
|
34940
35071
|
function resolveCallPii(requestPiiRedaction, hookPiiRedaction, getConversationRedactorFor) {
|
|
34941
35072
|
const effective = requestPiiRedaction === void 0 ? hookPiiRedaction : requestPiiRedaction;
|
|
34942
35073
|
const redactor = effective === true ? getConversationRedactorFor() : isPiiRedactor(effective) ? effective : void 0;
|
|
@@ -34995,11 +35126,17 @@ function useChatStorage(options) {
|
|
|
34995
35126
|
foldToolResultsInHistoryRef.current = foldToolResultsInHistory;
|
|
34996
35127
|
const nerDetectorRef = useRef4(nerDetector);
|
|
34997
35128
|
nerDetectorRef.current = nerDetector;
|
|
35129
|
+
const getConversationRedactor = useConversationRedactors(
|
|
35130
|
+
database,
|
|
35131
|
+
walletAddress,
|
|
35132
|
+
memoryStore ?? chatBackend ?? database,
|
|
35133
|
+
memoryStore && chatBackend ? chatBackend : void 0
|
|
35134
|
+
);
|
|
34998
35135
|
const resolvedPiiRedaction = useMemo4(
|
|
34999
35136
|
() => piiRedaction === true ? getConversationRedactor(currentConversationId, nerDetectorRef.current) : piiRedaction,
|
|
35000
|
-
[piiRedaction, currentConversationId]
|
|
35137
|
+
[piiRedaction, currentConversationId, getConversationRedactor]
|
|
35001
35138
|
);
|
|
35002
|
-
const maskForEmbedding =
|
|
35139
|
+
const maskForEmbedding = useCallback6(
|
|
35003
35140
|
(text16) => isPiiRedactor(resolvedPiiRedaction) ? resolvedPiiRedaction.maskText(text16) : text16,
|
|
35004
35141
|
[resolvedPiiRedaction]
|
|
35005
35142
|
);
|
|
@@ -35013,7 +35150,7 @@ function useChatStorage(options) {
|
|
|
35013
35150
|
);
|
|
35014
35151
|
const storeMaskMissing = memoryStore !== void 0 && memoryStore !== null && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
|
|
35015
35152
|
const blobManagerRef = useRef4(new BlobUrlManager());
|
|
35016
|
-
|
|
35153
|
+
useEffect5(() => {
|
|
35017
35154
|
const manager = blobManagerRef.current;
|
|
35018
35155
|
return () => {
|
|
35019
35156
|
manager.revokeAll();
|
|
@@ -35105,12 +35242,12 @@ function useChatStorage(options) {
|
|
|
35105
35242
|
isFlushing: false,
|
|
35106
35243
|
isPaused: false
|
|
35107
35244
|
});
|
|
35108
|
-
const refreshQueueStatus =
|
|
35245
|
+
const refreshQueueStatus = useCallback6(() => {
|
|
35109
35246
|
if (walletAddress) {
|
|
35110
35247
|
setQueueStatus(queueManager.getStatus(walletAddress));
|
|
35111
35248
|
}
|
|
35112
35249
|
}, [walletAddress]);
|
|
35113
|
-
const executeQueuedOperation =
|
|
35250
|
+
const executeQueuedOperation = useCallback6(
|
|
35114
35251
|
async (operation, encCtx) => {
|
|
35115
35252
|
const queued = queuedBackends.get(operation.payload) ?? backendFactory({
|
|
35116
35253
|
walletAddress: encCtx.walletAddress,
|
|
@@ -35158,7 +35295,7 @@ function useChatStorage(options) {
|
|
|
35158
35295
|
},
|
|
35159
35296
|
[backendFactory, database]
|
|
35160
35297
|
);
|
|
35161
|
-
const flushQueue =
|
|
35298
|
+
const flushQueue = useCallback6(async () => {
|
|
35162
35299
|
if (!walletAddress || !signMessage) {
|
|
35163
35300
|
return { succeeded: [], failed: [], total: 0 };
|
|
35164
35301
|
}
|
|
@@ -35177,31 +35314,31 @@ function useChatStorage(options) {
|
|
|
35177
35314
|
executeQueuedOperation,
|
|
35178
35315
|
refreshQueueStatus
|
|
35179
35316
|
]);
|
|
35180
|
-
const clearQueue =
|
|
35317
|
+
const clearQueue = useCallback6(() => {
|
|
35181
35318
|
if (walletAddress) {
|
|
35182
35319
|
queueManager.clear(walletAddress);
|
|
35183
35320
|
refreshQueueStatus();
|
|
35184
35321
|
}
|
|
35185
35322
|
}, [walletAddress, refreshQueueStatus]);
|
|
35186
|
-
|
|
35323
|
+
useEffect5(() => {
|
|
35187
35324
|
if (!walletAddress) return;
|
|
35188
35325
|
refreshQueueStatus();
|
|
35189
35326
|
return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
|
|
35190
35327
|
}, [walletAddress, refreshQueueStatus]);
|
|
35191
|
-
|
|
35328
|
+
useEffect5(() => {
|
|
35192
35329
|
if (!getWalletAddress || walletAddress) return;
|
|
35193
35330
|
const poller = new WalletPoller();
|
|
35194
35331
|
return poller.startPolling(getWalletAddress, () => {
|
|
35195
35332
|
});
|
|
35196
35333
|
}, [getWalletAddress, walletAddress]);
|
|
35197
|
-
const isEncryptionReady =
|
|
35334
|
+
const isEncryptionReady = useCallback6(() => {
|
|
35198
35335
|
if (!walletAddress || !signMessage) return true;
|
|
35199
35336
|
return hasEncryptionKey(walletAddress);
|
|
35200
35337
|
}, [walletAddress, signMessage]);
|
|
35201
35338
|
const pendingOpsRef = useRef4([]);
|
|
35202
35339
|
const syntheticConvIdsRef = useRef4(/* @__PURE__ */ new Set());
|
|
35203
35340
|
const syntheticConvQueueIdsRef = useRef4(/* @__PURE__ */ new Map());
|
|
35204
|
-
|
|
35341
|
+
useEffect5(() => {
|
|
35205
35342
|
if (!walletAddress || !enableQueue) return;
|
|
35206
35343
|
const pending = pendingOpsRef.current;
|
|
35207
35344
|
if (pending.length === 0) return;
|
|
@@ -35212,7 +35349,7 @@ function useChatStorage(options) {
|
|
|
35212
35349
|
pendingOpsRef.current = [];
|
|
35213
35350
|
refreshQueueStatus();
|
|
35214
35351
|
}, [walletAddress, enableQueue, refreshQueueStatus]);
|
|
35215
|
-
|
|
35352
|
+
useEffect5(() => {
|
|
35216
35353
|
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
35217
35354
|
return onKeyAvailable(walletAddress, () => {
|
|
35218
35355
|
flushQueue().catch((err) => {
|
|
@@ -35220,7 +35357,7 @@ function useChatStorage(options) {
|
|
|
35220
35357
|
});
|
|
35221
35358
|
});
|
|
35222
35359
|
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
35223
|
-
const writeOrQueue =
|
|
35360
|
+
const writeOrQueue = useCallback6(
|
|
35224
35361
|
async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
|
|
35225
35362
|
const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
|
|
35226
35363
|
const currentBackend = storageCtx.walletAddress ? backend : backendRef.current;
|
|
@@ -35258,7 +35395,7 @@ function useChatStorage(options) {
|
|
|
35258
35395
|
},
|
|
35259
35396
|
[storageCtx, backend, enableQueue, signMessage, getWalletAddress]
|
|
35260
35397
|
);
|
|
35261
|
-
const embedMessageAsync =
|
|
35398
|
+
const embedMessageAsync = useCallback6(
|
|
35262
35399
|
async (message, mask = maskForEmbedding) => {
|
|
35263
35400
|
if (!autoEmbedMessages || !getToken) return;
|
|
35264
35401
|
if (message.content.length < minContentLength) return;
|
|
@@ -35297,7 +35434,7 @@ function useChatStorage(options) {
|
|
|
35297
35434
|
maskForEmbedding
|
|
35298
35435
|
]
|
|
35299
35436
|
);
|
|
35300
|
-
const createMemoryEngineTool2 =
|
|
35437
|
+
const createMemoryEngineTool2 = useCallback6(
|
|
35301
35438
|
(searchOptions) => {
|
|
35302
35439
|
if (!getToken) {
|
|
35303
35440
|
throw new Error("getToken is required for memory engine tool");
|
|
@@ -35306,7 +35443,7 @@ function useChatStorage(options) {
|
|
|
35306
35443
|
},
|
|
35307
35444
|
[backend, getToken, vaultEmbeddingOptions]
|
|
35308
35445
|
);
|
|
35309
|
-
const retainVaultMemory =
|
|
35446
|
+
const retainVaultMemory = useCallback6(
|
|
35310
35447
|
async (input) => {
|
|
35311
35448
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35312
35449
|
if (memoryStore) {
|
|
@@ -35338,7 +35475,7 @@ function useChatStorage(options) {
|
|
|
35338
35475
|
},
|
|
35339
35476
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35340
35477
|
);
|
|
35341
|
-
const createMemoryVaultTool2 =
|
|
35478
|
+
const createMemoryVaultTool2 = useCallback6(
|
|
35342
35479
|
(options2) => {
|
|
35343
35480
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35344
35481
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
@@ -35360,7 +35497,7 @@ function useChatStorage(options) {
|
|
|
35360
35497
|
storeMaskMissing
|
|
35361
35498
|
]
|
|
35362
35499
|
);
|
|
35363
|
-
const getVaultMemories =
|
|
35500
|
+
const getVaultMemories = useCallback6(
|
|
35364
35501
|
(options2) => {
|
|
35365
35502
|
if (memoryStore === null) return Promise.resolve([]);
|
|
35366
35503
|
if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
|
|
@@ -35372,7 +35509,7 @@ function useChatStorage(options) {
|
|
|
35372
35509
|
},
|
|
35373
35510
|
[vaultCtx, memoryStore]
|
|
35374
35511
|
);
|
|
35375
|
-
const createVaultMemory =
|
|
35512
|
+
const createVaultMemory = useCallback6(
|
|
35376
35513
|
async (content, scope) => {
|
|
35377
35514
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35378
35515
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
@@ -35394,7 +35531,7 @@ function useChatStorage(options) {
|
|
|
35394
35531
|
},
|
|
35395
35532
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35396
35533
|
);
|
|
35397
|
-
const updateVaultMemory =
|
|
35534
|
+
const updateVaultMemory = useCallback6(
|
|
35398
35535
|
async (id2, content, scope) => {
|
|
35399
35536
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35400
35537
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
@@ -35420,7 +35557,7 @@ function useChatStorage(options) {
|
|
|
35420
35557
|
},
|
|
35421
35558
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35422
35559
|
);
|
|
35423
|
-
const deleteVaultMemory =
|
|
35560
|
+
const deleteVaultMemory = useCallback6(
|
|
35424
35561
|
async (id2) => {
|
|
35425
35562
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35426
35563
|
if (memoryStore) return memoryStore.delete(id2);
|
|
@@ -35435,7 +35572,7 @@ function useChatStorage(options) {
|
|
|
35435
35572
|
);
|
|
35436
35573
|
const chunkVectorCacheRef = useRef4(createChunkVectorCache());
|
|
35437
35574
|
const clientToolEmbeddingsCacheRef = useRef4(/* @__PURE__ */ new Map());
|
|
35438
|
-
|
|
35575
|
+
useEffect5(() => {
|
|
35439
35576
|
if (!getToken || memoryStore !== void 0) return;
|
|
35440
35577
|
void (async () => {
|
|
35441
35578
|
try {
|
|
@@ -35444,13 +35581,13 @@ function useChatStorage(options) {
|
|
|
35444
35581
|
}
|
|
35445
35582
|
})();
|
|
35446
35583
|
}, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore]);
|
|
35447
|
-
|
|
35584
|
+
useEffect5(() => {
|
|
35448
35585
|
return onClearAllEncryptionState(() => {
|
|
35449
35586
|
vaultEmbeddingCache.clear();
|
|
35450
35587
|
chunkVectorCacheRef.current.clear();
|
|
35451
35588
|
});
|
|
35452
35589
|
}, [vaultEmbeddingCache]);
|
|
35453
|
-
const createMemoryVaultSearchTool2 =
|
|
35590
|
+
const createMemoryVaultSearchTool2 = useCallback6(
|
|
35454
35591
|
(searchOptions) => {
|
|
35455
35592
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35456
35593
|
if (!getToken && !memoryStore) {
|
|
@@ -35466,7 +35603,7 @@ function useChatStorage(options) {
|
|
|
35466
35603
|
},
|
|
35467
35604
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35468
35605
|
);
|
|
35469
|
-
const createRecallTool2 =
|
|
35606
|
+
const createRecallTool2 = useCallback6(
|
|
35470
35607
|
(toolOptions, callbacks) => {
|
|
35471
35608
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35472
35609
|
if (!getToken && !memoryStore) {
|
|
@@ -35506,7 +35643,7 @@ function useChatStorage(options) {
|
|
|
35506
35643
|
storeMaskMissing
|
|
35507
35644
|
]
|
|
35508
35645
|
);
|
|
35509
|
-
const searchVaultMemoriesFn =
|
|
35646
|
+
const searchVaultMemoriesFn = useCallback6(
|
|
35510
35647
|
async (query, searchOptions) => {
|
|
35511
35648
|
if (memoryStore === null) return [];
|
|
35512
35649
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
@@ -35522,7 +35659,7 @@ function useChatStorage(options) {
|
|
|
35522
35659
|
},
|
|
35523
35660
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35524
35661
|
);
|
|
35525
|
-
const recallFn =
|
|
35662
|
+
const recallFn = useCallback6(
|
|
35526
35663
|
async (query, options2) => {
|
|
35527
35664
|
if (memoryStore === null || !getToken && !memoryStore) {
|
|
35528
35665
|
return {
|
|
@@ -35587,7 +35724,7 @@ function useChatStorage(options) {
|
|
|
35587
35724
|
piiRedaction: resolvedPiiRedaction,
|
|
35588
35725
|
onPiiRedacted
|
|
35589
35726
|
});
|
|
35590
|
-
const createConversation =
|
|
35727
|
+
const createConversation = useCallback6(
|
|
35591
35728
|
async (opts) => {
|
|
35592
35729
|
const conversationOpts = {
|
|
35593
35730
|
...opts,
|
|
@@ -35610,16 +35747,16 @@ function useChatStorage(options) {
|
|
|
35610
35747
|
},
|
|
35611
35748
|
[defaultConversationTitle, writeOrQueue]
|
|
35612
35749
|
);
|
|
35613
|
-
const getConversation =
|
|
35750
|
+
const getConversation = useCallback6(
|
|
35614
35751
|
async (id2) => {
|
|
35615
35752
|
return backend.getConversation(id2);
|
|
35616
35753
|
},
|
|
35617
35754
|
[backend]
|
|
35618
35755
|
);
|
|
35619
|
-
const getConversations =
|
|
35756
|
+
const getConversations = useCallback6(async () => {
|
|
35620
35757
|
return backend.getConversations();
|
|
35621
35758
|
}, [backend]);
|
|
35622
|
-
const updateConversationTitle =
|
|
35759
|
+
const updateConversationTitle = useCallback6(
|
|
35623
35760
|
async (id2, title) => {
|
|
35624
35761
|
const { result } = await writeOrQueue(
|
|
35625
35762
|
"updateConversationTitle",
|
|
@@ -35631,7 +35768,7 @@ function useChatStorage(options) {
|
|
|
35631
35768
|
},
|
|
35632
35769
|
[writeOrQueue]
|
|
35633
35770
|
);
|
|
35634
|
-
const updateConversationPinned =
|
|
35771
|
+
const updateConversationPinned = useCallback6(
|
|
35635
35772
|
async (id2, pinned) => {
|
|
35636
35773
|
const { result } = await writeOrQueue(
|
|
35637
35774
|
"updateConversationPinned",
|
|
@@ -35643,7 +35780,7 @@ function useChatStorage(options) {
|
|
|
35643
35780
|
},
|
|
35644
35781
|
[writeOrQueue]
|
|
35645
35782
|
);
|
|
35646
|
-
const deleteConversation =
|
|
35783
|
+
const deleteConversation = useCallback6(
|
|
35647
35784
|
async (id2) => {
|
|
35648
35785
|
const deleted = await backend.deleteConversation(id2);
|
|
35649
35786
|
if (deleted) {
|
|
@@ -35658,7 +35795,7 @@ function useChatStorage(options) {
|
|
|
35658
35795
|
},
|
|
35659
35796
|
[backend, mediaCtx, currentConversationId]
|
|
35660
35797
|
);
|
|
35661
|
-
const resolveMessageFiles =
|
|
35798
|
+
const resolveMessageFiles = useCallback6(
|
|
35662
35799
|
async (messages) => {
|
|
35663
35800
|
if (walletAddress && hasEncryptionKey(walletAddress) && isOPFSSupported()) {
|
|
35664
35801
|
try {
|
|
@@ -35720,33 +35857,33 @@ function useChatStorage(options) {
|
|
|
35720
35857
|
},
|
|
35721
35858
|
[walletAddress]
|
|
35722
35859
|
);
|
|
35723
|
-
const getMessages =
|
|
35860
|
+
const getMessages = useCallback6(
|
|
35724
35861
|
async (convId) => {
|
|
35725
35862
|
const messages = await backend.getMessages(convId);
|
|
35726
35863
|
return resolveMessageFiles(messages);
|
|
35727
35864
|
},
|
|
35728
35865
|
[backend, resolveMessageFiles]
|
|
35729
35866
|
);
|
|
35730
|
-
const getMessagesPage =
|
|
35867
|
+
const getMessagesPage = useCallback6(
|
|
35731
35868
|
async (convId, options2) => {
|
|
35732
35869
|
const messages = await backend.getMessagesPage(convId, options2);
|
|
35733
35870
|
return resolveMessageFiles(messages);
|
|
35734
35871
|
},
|
|
35735
35872
|
[backend, resolveMessageFiles]
|
|
35736
35873
|
);
|
|
35737
|
-
const getMessageSkeletons =
|
|
35874
|
+
const getMessageSkeletons = useCallback6(
|
|
35738
35875
|
(convId) => {
|
|
35739
35876
|
return backend.getMessageSkeletons(convId);
|
|
35740
35877
|
},
|
|
35741
35878
|
[backend]
|
|
35742
35879
|
);
|
|
35743
|
-
const getMessageCount =
|
|
35880
|
+
const getMessageCount = useCallback6(
|
|
35744
35881
|
(convId) => {
|
|
35745
35882
|
return backend.getMessageCount(convId);
|
|
35746
35883
|
},
|
|
35747
35884
|
[backend]
|
|
35748
35885
|
);
|
|
35749
|
-
const ensureConversation =
|
|
35886
|
+
const ensureConversation = useCallback6(async () => {
|
|
35750
35887
|
if (currentConversationId) {
|
|
35751
35888
|
if (syntheticConvIdsRef.current.has(currentConversationId)) {
|
|
35752
35889
|
return currentConversationId;
|
|
@@ -35772,7 +35909,7 @@ function useChatStorage(options) {
|
|
|
35772
35909
|
mediaCtx,
|
|
35773
35910
|
mcpR2Domain
|
|
35774
35911
|
});
|
|
35775
|
-
const sendMessage =
|
|
35912
|
+
const sendMessage = useCallback6(
|
|
35776
35913
|
async (args) => {
|
|
35777
35914
|
const {
|
|
35778
35915
|
messages,
|
|
@@ -36704,6 +36841,8 @@ function useChatStorage(options) {
|
|
|
36704
36841
|
getMessages,
|
|
36705
36842
|
backend,
|
|
36706
36843
|
baseSendMessage,
|
|
36844
|
+
getConversationRedactor,
|
|
36845
|
+
piiRedaction,
|
|
36707
36846
|
walletAddress,
|
|
36708
36847
|
signMessage,
|
|
36709
36848
|
embeddedWalletSigner,
|
|
@@ -36716,7 +36855,7 @@ function useChatStorage(options) {
|
|
|
36716
36855
|
refreshQueueStatus
|
|
36717
36856
|
]
|
|
36718
36857
|
);
|
|
36719
|
-
const getAllFiles =
|
|
36858
|
+
const getAllFiles = useCallback6(
|
|
36720
36859
|
async (options2) => {
|
|
36721
36860
|
return backend.getAllFiles(options2);
|
|
36722
36861
|
},
|
|
@@ -36758,7 +36897,7 @@ function useChatStorage(options) {
|
|
|
36758
36897
|
}
|
|
36759
36898
|
|
|
36760
36899
|
// src/react/useCredits.ts
|
|
36761
|
-
import { useCallback as
|
|
36900
|
+
import { useCallback as useCallback7, useEffect as useEffect6, useRef as useRef5, useState as useState6 } from "react";
|
|
36762
36901
|
function useCredits(options = {}) {
|
|
36763
36902
|
const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
|
|
36764
36903
|
const [balance, setBalance] = useState6(null);
|
|
@@ -36770,12 +36909,12 @@ function useCredits(options = {}) {
|
|
|
36770
36909
|
const baseUrlRef = useRef5(baseUrl);
|
|
36771
36910
|
const onErrorRef = useRef5(onError);
|
|
36772
36911
|
const abortControllerRef = useRef5(null);
|
|
36773
|
-
|
|
36912
|
+
useEffect6(() => {
|
|
36774
36913
|
getTokenRef.current = getToken;
|
|
36775
36914
|
baseUrlRef.current = baseUrl;
|
|
36776
36915
|
onErrorRef.current = onError;
|
|
36777
36916
|
});
|
|
36778
|
-
|
|
36917
|
+
useEffect6(() => {
|
|
36779
36918
|
return () => {
|
|
36780
36919
|
if (abortControllerRef.current) {
|
|
36781
36920
|
abortControllerRef.current.abort();
|
|
@@ -36783,15 +36922,15 @@ function useCredits(options = {}) {
|
|
|
36783
36922
|
}
|
|
36784
36923
|
};
|
|
36785
36924
|
}, []);
|
|
36786
|
-
const startLoading =
|
|
36925
|
+
const startLoading = useCallback7(() => {
|
|
36787
36926
|
loadingCountRef.current++;
|
|
36788
36927
|
setIsLoading(true);
|
|
36789
36928
|
}, []);
|
|
36790
|
-
const stopLoading =
|
|
36929
|
+
const stopLoading = useCallback7(() => {
|
|
36791
36930
|
loadingCountRef.current = Math.max(0, loadingCountRef.current - 1);
|
|
36792
36931
|
setIsLoading(loadingCountRef.current > 0);
|
|
36793
36932
|
}, []);
|
|
36794
|
-
const getHeaders =
|
|
36933
|
+
const getHeaders = useCallback7(async () => {
|
|
36795
36934
|
const headers = {};
|
|
36796
36935
|
if (getTokenRef.current) {
|
|
36797
36936
|
const token = await getTokenRef.current();
|
|
@@ -36801,13 +36940,13 @@ function useCredits(options = {}) {
|
|
|
36801
36940
|
}
|
|
36802
36941
|
return headers;
|
|
36803
36942
|
}, []);
|
|
36804
|
-
const handleError =
|
|
36943
|
+
const handleError = useCallback7((err) => {
|
|
36805
36944
|
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
36806
36945
|
setError(error2);
|
|
36807
36946
|
onErrorRef.current?.(error2);
|
|
36808
36947
|
return error2;
|
|
36809
36948
|
}, []);
|
|
36810
|
-
const fetchBalance =
|
|
36949
|
+
const fetchBalance = useCallback7(async () => {
|
|
36811
36950
|
if (abortControllerRef.current) {
|
|
36812
36951
|
abortControllerRef.current.abort();
|
|
36813
36952
|
}
|
|
@@ -36840,11 +36979,11 @@ function useCredits(options = {}) {
|
|
|
36840
36979
|
}
|
|
36841
36980
|
}
|
|
36842
36981
|
}, [getHeaders, handleError, startLoading, stopLoading]);
|
|
36843
|
-
const refetch =
|
|
36982
|
+
const refetch = useCallback7(async () => {
|
|
36844
36983
|
setBalance(null);
|
|
36845
36984
|
await fetchBalance();
|
|
36846
36985
|
}, [fetchBalance]);
|
|
36847
|
-
const fetchPacks =
|
|
36986
|
+
const fetchPacks = useCallback7(async () => {
|
|
36848
36987
|
startLoading();
|
|
36849
36988
|
setError(null);
|
|
36850
36989
|
try {
|
|
@@ -36864,7 +37003,7 @@ function useCredits(options = {}) {
|
|
|
36864
37003
|
stopLoading();
|
|
36865
37004
|
}
|
|
36866
37005
|
}, [getHeaders, handleError, startLoading, stopLoading]);
|
|
36867
|
-
const purchaseCredits =
|
|
37006
|
+
const purchaseCredits = useCallback7(
|
|
36868
37007
|
async (credits, opts) => {
|
|
36869
37008
|
startLoading();
|
|
36870
37009
|
setError(null);
|
|
@@ -36894,7 +37033,7 @@ function useCredits(options = {}) {
|
|
|
36894
37033
|
[getHeaders, handleError, startLoading, stopLoading]
|
|
36895
37034
|
);
|
|
36896
37035
|
const hasFetchedRef = useRef5(false);
|
|
36897
|
-
|
|
37036
|
+
useEffect6(() => {
|
|
36898
37037
|
if (autoFetch && !hasFetchedRef.current) {
|
|
36899
37038
|
hasFetchedRef.current = true;
|
|
36900
37039
|
void fetchBalance();
|
|
@@ -36921,7 +37060,7 @@ function useDatabaseManager(walletAddress, manager) {
|
|
|
36921
37060
|
}
|
|
36922
37061
|
|
|
36923
37062
|
// src/react/useExportPdf.ts
|
|
36924
|
-
import { useCallback as
|
|
37063
|
+
import { useCallback as useCallback8, useState as useState7 } from "react";
|
|
36925
37064
|
var DEFAULT_FILENAME2 = "document.pdf";
|
|
36926
37065
|
function triggerDownload(blob, filename) {
|
|
36927
37066
|
const url = URL.createObjectURL(blob);
|
|
@@ -36940,7 +37079,7 @@ function useExportPdf() {
|
|
|
36940
37079
|
const [isExporting, setIsExporting] = useState7(false);
|
|
36941
37080
|
const [progress, setProgress] = useState7(null);
|
|
36942
37081
|
const [error, setError] = useState7(null);
|
|
36943
|
-
const wrappedExportElement =
|
|
37082
|
+
const wrappedExportElement = useCallback8(
|
|
36944
37083
|
async (element, options) => {
|
|
36945
37084
|
setIsExporting(true);
|
|
36946
37085
|
setError(null);
|
|
@@ -36960,7 +37099,7 @@ function useExportPdf() {
|
|
|
36960
37099
|
},
|
|
36961
37100
|
[]
|
|
36962
37101
|
);
|
|
36963
|
-
const wrappedExportMarkdown =
|
|
37102
|
+
const wrappedExportMarkdown = useCallback8(
|
|
36964
37103
|
async (markdown, options) => {
|
|
36965
37104
|
setIsExporting(true);
|
|
36966
37105
|
setError(null);
|
|
@@ -36980,21 +37119,21 @@ function useExportPdf() {
|
|
|
36980
37119
|
},
|
|
36981
37120
|
[]
|
|
36982
37121
|
);
|
|
36983
|
-
const downloadElementAsPdf =
|
|
37122
|
+
const downloadElementAsPdf = useCallback8(
|
|
36984
37123
|
async (element, options) => {
|
|
36985
37124
|
const blob = await wrappedExportElement(element, options);
|
|
36986
37125
|
triggerDownload(blob, options?.filename ?? DEFAULT_FILENAME2);
|
|
36987
37126
|
},
|
|
36988
37127
|
[wrappedExportElement]
|
|
36989
37128
|
);
|
|
36990
|
-
const downloadMarkdownAsPdf =
|
|
37129
|
+
const downloadMarkdownAsPdf = useCallback8(
|
|
36991
37130
|
async (markdown, options) => {
|
|
36992
37131
|
const blob = await wrappedExportMarkdown(markdown, options);
|
|
36993
37132
|
triggerDownload(blob, options?.filename ?? DEFAULT_FILENAME2);
|
|
36994
37133
|
},
|
|
36995
37134
|
[wrappedExportMarkdown]
|
|
36996
37135
|
);
|
|
36997
|
-
const wrappedRenderToCanvas =
|
|
37136
|
+
const wrappedRenderToCanvas = useCallback8(
|
|
36998
37137
|
async (element) => {
|
|
36999
37138
|
setIsExporting(true);
|
|
37000
37139
|
setError(null);
|
|
@@ -37026,19 +37165,19 @@ function useExportPdf() {
|
|
|
37026
37165
|
|
|
37027
37166
|
// src/react/useFiles.ts
|
|
37028
37167
|
import { Q as Q19 } from "@nozbe/watermelondb";
|
|
37029
|
-
import { useCallback as
|
|
37168
|
+
import { useCallback as useCallback9, useEffect as useEffect7, useMemo as useMemo6, useState as useState8 } from "react";
|
|
37030
37169
|
function useFiles(options) {
|
|
37031
37170
|
const { database, walletAddress } = options;
|
|
37032
37171
|
const [isLoading, setIsLoading] = useState8(false);
|
|
37033
37172
|
const [isReady, setIsReady] = useState8(false);
|
|
37034
37173
|
const [mediaCollection, setMediaCollection] = useState8(null);
|
|
37035
37174
|
const blobUrlManager = useMemo6(() => new BlobUrlManager(), []);
|
|
37036
|
-
|
|
37175
|
+
useEffect7(() => {
|
|
37037
37176
|
return () => {
|
|
37038
37177
|
blobUrlManager.revokeAll();
|
|
37039
37178
|
};
|
|
37040
37179
|
}, [blobUrlManager]);
|
|
37041
|
-
|
|
37180
|
+
useEffect7(() => {
|
|
37042
37181
|
const initCollection = async () => {
|
|
37043
37182
|
setIsLoading(true);
|
|
37044
37183
|
try {
|
|
@@ -37061,7 +37200,7 @@ function useFiles(options) {
|
|
|
37061
37200
|
}
|
|
37062
37201
|
return { database, walletAddress };
|
|
37063
37202
|
}, [database, mediaCollection, isReady, walletAddress]);
|
|
37064
|
-
const createMedia =
|
|
37203
|
+
const createMedia = useCallback9(
|
|
37065
37204
|
async (createOptions) => {
|
|
37066
37205
|
if (!ctx) {
|
|
37067
37206
|
throw new Error("Files not available. Database may need to be initialized.");
|
|
@@ -37070,7 +37209,7 @@ function useFiles(options) {
|
|
|
37070
37209
|
},
|
|
37071
37210
|
[ctx]
|
|
37072
37211
|
);
|
|
37073
|
-
const createMediaBatch =
|
|
37212
|
+
const createMediaBatch = useCallback9(
|
|
37074
37213
|
async (optionsArray) => {
|
|
37075
37214
|
if (!ctx) {
|
|
37076
37215
|
throw new Error("Files not available. Database may need to be initialized.");
|
|
@@ -37079,7 +37218,7 @@ function useFiles(options) {
|
|
|
37079
37218
|
},
|
|
37080
37219
|
[ctx]
|
|
37081
37220
|
);
|
|
37082
|
-
const getMediaById =
|
|
37221
|
+
const getMediaById = useCallback9(
|
|
37083
37222
|
async (mediaId) => {
|
|
37084
37223
|
if (!ctx) {
|
|
37085
37224
|
return null;
|
|
@@ -37088,7 +37227,7 @@ function useFiles(options) {
|
|
|
37088
37227
|
},
|
|
37089
37228
|
[ctx]
|
|
37090
37229
|
);
|
|
37091
|
-
const getMediaBySourceUrl =
|
|
37230
|
+
const getMediaBySourceUrl = useCallback9(
|
|
37092
37231
|
async (sourceUrl) => {
|
|
37093
37232
|
if (!ctx || !walletAddress) {
|
|
37094
37233
|
return null;
|
|
@@ -37097,7 +37236,7 @@ function useFiles(options) {
|
|
|
37097
37236
|
},
|
|
37098
37237
|
[ctx, walletAddress]
|
|
37099
37238
|
);
|
|
37100
|
-
const getMediaByIds =
|
|
37239
|
+
const getMediaByIds = useCallback9(
|
|
37101
37240
|
async (mediaIds, includeDeleted = false) => {
|
|
37102
37241
|
if (!ctx) {
|
|
37103
37242
|
return [];
|
|
@@ -37106,7 +37245,7 @@ function useFiles(options) {
|
|
|
37106
37245
|
},
|
|
37107
37246
|
[ctx]
|
|
37108
37247
|
);
|
|
37109
|
-
const getMediaByMessage =
|
|
37248
|
+
const getMediaByMessage = useCallback9(
|
|
37110
37249
|
async (messageId) => {
|
|
37111
37250
|
if (!ctx) {
|
|
37112
37251
|
return [];
|
|
@@ -37115,7 +37254,7 @@ function useFiles(options) {
|
|
|
37115
37254
|
},
|
|
37116
37255
|
[ctx]
|
|
37117
37256
|
);
|
|
37118
|
-
const updateMedia =
|
|
37257
|
+
const updateMedia = useCallback9(
|
|
37119
37258
|
async (mediaId, updateOptions) => {
|
|
37120
37259
|
if (!ctx) {
|
|
37121
37260
|
return null;
|
|
@@ -37124,7 +37263,7 @@ function useFiles(options) {
|
|
|
37124
37263
|
},
|
|
37125
37264
|
[ctx]
|
|
37126
37265
|
);
|
|
37127
|
-
const updateMediaMessageIdBatch =
|
|
37266
|
+
const updateMediaMessageIdBatch = useCallback9(
|
|
37128
37267
|
async (mediaIds, messageId) => {
|
|
37129
37268
|
if (!ctx) {
|
|
37130
37269
|
return 0;
|
|
@@ -37133,13 +37272,13 @@ function useFiles(options) {
|
|
|
37133
37272
|
},
|
|
37134
37273
|
[ctx]
|
|
37135
37274
|
);
|
|
37136
|
-
const relinkMisclassifiedVideos =
|
|
37275
|
+
const relinkMisclassifiedVideos = useCallback9(async () => {
|
|
37137
37276
|
if (!ctx || !walletAddress) {
|
|
37138
37277
|
return 0;
|
|
37139
37278
|
}
|
|
37140
37279
|
return relinkMisclassifiedVideosOp(ctx, walletAddress);
|
|
37141
37280
|
}, [ctx, walletAddress]);
|
|
37142
|
-
const deleteMedia =
|
|
37281
|
+
const deleteMedia = useCallback9(
|
|
37143
37282
|
async (mediaId) => {
|
|
37144
37283
|
if (!ctx) {
|
|
37145
37284
|
return false;
|
|
@@ -37150,7 +37289,7 @@ function useFiles(options) {
|
|
|
37150
37289
|
},
|
|
37151
37290
|
[ctx, blobUrlManager]
|
|
37152
37291
|
);
|
|
37153
|
-
const hardDeleteMedia =
|
|
37292
|
+
const hardDeleteMedia = useCallback9(
|
|
37154
37293
|
async (mediaId) => {
|
|
37155
37294
|
if (!ctx) {
|
|
37156
37295
|
return false;
|
|
@@ -37161,7 +37300,7 @@ function useFiles(options) {
|
|
|
37161
37300
|
},
|
|
37162
37301
|
[ctx, blobUrlManager]
|
|
37163
37302
|
);
|
|
37164
|
-
const getMedia =
|
|
37303
|
+
const getMedia = useCallback9(
|
|
37165
37304
|
async (filters) => {
|
|
37166
37305
|
if (!ctx) {
|
|
37167
37306
|
return [];
|
|
@@ -37170,7 +37309,7 @@ function useFiles(options) {
|
|
|
37170
37309
|
},
|
|
37171
37310
|
[ctx]
|
|
37172
37311
|
);
|
|
37173
|
-
const getMediaByType =
|
|
37312
|
+
const getMediaByType = useCallback9(
|
|
37174
37313
|
async (mediaType, limit) => {
|
|
37175
37314
|
if (!ctx || !walletAddress) {
|
|
37176
37315
|
return [];
|
|
@@ -37179,7 +37318,7 @@ function useFiles(options) {
|
|
|
37179
37318
|
},
|
|
37180
37319
|
[ctx, walletAddress]
|
|
37181
37320
|
);
|
|
37182
|
-
const getImages =
|
|
37321
|
+
const getImages = useCallback9(
|
|
37183
37322
|
async (limit) => {
|
|
37184
37323
|
if (!ctx || !walletAddress) {
|
|
37185
37324
|
return [];
|
|
@@ -37188,7 +37327,7 @@ function useFiles(options) {
|
|
|
37188
37327
|
},
|
|
37189
37328
|
[ctx, walletAddress]
|
|
37190
37329
|
);
|
|
37191
|
-
const getVideos =
|
|
37330
|
+
const getVideos = useCallback9(
|
|
37192
37331
|
async (limit) => {
|
|
37193
37332
|
if (!ctx || !walletAddress) {
|
|
37194
37333
|
return [];
|
|
@@ -37197,7 +37336,7 @@ function useFiles(options) {
|
|
|
37197
37336
|
},
|
|
37198
37337
|
[ctx, walletAddress]
|
|
37199
37338
|
);
|
|
37200
|
-
const getAudio =
|
|
37339
|
+
const getAudio = useCallback9(
|
|
37201
37340
|
async (limit) => {
|
|
37202
37341
|
if (!ctx || !walletAddress) {
|
|
37203
37342
|
return [];
|
|
@@ -37206,7 +37345,7 @@ function useFiles(options) {
|
|
|
37206
37345
|
},
|
|
37207
37346
|
[ctx, walletAddress]
|
|
37208
37347
|
);
|
|
37209
|
-
const getDocuments =
|
|
37348
|
+
const getDocuments = useCallback9(
|
|
37210
37349
|
async (limit) => {
|
|
37211
37350
|
if (!ctx || !walletAddress) {
|
|
37212
37351
|
return [];
|
|
@@ -37215,7 +37354,7 @@ function useFiles(options) {
|
|
|
37215
37354
|
},
|
|
37216
37355
|
[ctx, walletAddress]
|
|
37217
37356
|
);
|
|
37218
|
-
const getMediaByConversation =
|
|
37357
|
+
const getMediaByConversation = useCallback9(
|
|
37219
37358
|
async (conversationId, limit) => {
|
|
37220
37359
|
if (!ctx || !walletAddress) {
|
|
37221
37360
|
return [];
|
|
@@ -37224,7 +37363,7 @@ function useFiles(options) {
|
|
|
37224
37363
|
},
|
|
37225
37364
|
[ctx, walletAddress]
|
|
37226
37365
|
);
|
|
37227
|
-
const getMediaByRole =
|
|
37366
|
+
const getMediaByRole = useCallback9(
|
|
37228
37367
|
async (role, limit) => {
|
|
37229
37368
|
if (!ctx || !walletAddress) {
|
|
37230
37369
|
return [];
|
|
@@ -37233,7 +37372,7 @@ function useFiles(options) {
|
|
|
37233
37372
|
},
|
|
37234
37373
|
[ctx, walletAddress]
|
|
37235
37374
|
);
|
|
37236
|
-
const getAIGeneratedMedia =
|
|
37375
|
+
const getAIGeneratedMedia = useCallback9(
|
|
37237
37376
|
async (limit) => {
|
|
37238
37377
|
if (!ctx || !walletAddress) {
|
|
37239
37378
|
return [];
|
|
@@ -37242,7 +37381,7 @@ function useFiles(options) {
|
|
|
37242
37381
|
},
|
|
37243
37382
|
[ctx, walletAddress]
|
|
37244
37383
|
);
|
|
37245
|
-
const getUserUploadedMedia =
|
|
37384
|
+
const getUserUploadedMedia = useCallback9(
|
|
37246
37385
|
async (limit) => {
|
|
37247
37386
|
if (!ctx || !walletAddress) {
|
|
37248
37387
|
return [];
|
|
@@ -37251,7 +37390,7 @@ function useFiles(options) {
|
|
|
37251
37390
|
},
|
|
37252
37391
|
[ctx, walletAddress]
|
|
37253
37392
|
);
|
|
37254
|
-
const getMediaByModel =
|
|
37393
|
+
const getMediaByModel = useCallback9(
|
|
37255
37394
|
async (model, limit) => {
|
|
37256
37395
|
if (!ctx || !walletAddress) {
|
|
37257
37396
|
return [];
|
|
@@ -37260,7 +37399,7 @@ function useFiles(options) {
|
|
|
37260
37399
|
},
|
|
37261
37400
|
[ctx, walletAddress]
|
|
37262
37401
|
);
|
|
37263
|
-
const getRecentMedia =
|
|
37402
|
+
const getRecentMedia = useCallback9(
|
|
37264
37403
|
async (limit = 20) => {
|
|
37265
37404
|
if (!ctx || !walletAddress) {
|
|
37266
37405
|
return [];
|
|
@@ -37269,7 +37408,7 @@ function useFiles(options) {
|
|
|
37269
37408
|
},
|
|
37270
37409
|
[ctx, walletAddress]
|
|
37271
37410
|
);
|
|
37272
|
-
const searchMedia =
|
|
37411
|
+
const searchMedia = useCallback9(
|
|
37273
37412
|
async (query, limit) => {
|
|
37274
37413
|
if (!ctx || !walletAddress) {
|
|
37275
37414
|
return [];
|
|
@@ -37278,7 +37417,7 @@ function useFiles(options) {
|
|
|
37278
37417
|
},
|
|
37279
37418
|
[ctx, walletAddress]
|
|
37280
37419
|
);
|
|
37281
|
-
const getMediaCount =
|
|
37420
|
+
const getMediaCount = useCallback9(
|
|
37282
37421
|
async (mediaType) => {
|
|
37283
37422
|
if (!ctx || !walletAddress) {
|
|
37284
37423
|
return 0;
|
|
@@ -37287,13 +37426,13 @@ function useFiles(options) {
|
|
|
37287
37426
|
},
|
|
37288
37427
|
[ctx, walletAddress]
|
|
37289
37428
|
);
|
|
37290
|
-
const getMediaCountsByType =
|
|
37429
|
+
const getMediaCountsByType = useCallback9(async () => {
|
|
37291
37430
|
if (!ctx || !walletAddress) {
|
|
37292
37431
|
return { image: 0, video: 0, audio: 0, document: 0 };
|
|
37293
37432
|
}
|
|
37294
37433
|
return getMediaCountsByTypeOp(ctx, walletAddress);
|
|
37295
37434
|
}, [ctx, walletAddress]);
|
|
37296
|
-
const deleteMediaByConversation =
|
|
37435
|
+
const deleteMediaByConversation = useCallback9(
|
|
37297
37436
|
async (conversationId) => {
|
|
37298
37437
|
if (!ctx) {
|
|
37299
37438
|
return 0;
|
|
@@ -37302,7 +37441,7 @@ function useFiles(options) {
|
|
|
37302
37441
|
},
|
|
37303
37442
|
[ctx]
|
|
37304
37443
|
);
|
|
37305
|
-
const deleteMediaByMessage =
|
|
37444
|
+
const deleteMediaByMessage = useCallback9(
|
|
37306
37445
|
async (messageId) => {
|
|
37307
37446
|
if (!ctx) {
|
|
37308
37447
|
return 0;
|
|
@@ -37311,7 +37450,7 @@ function useFiles(options) {
|
|
|
37311
37450
|
},
|
|
37312
37451
|
[ctx]
|
|
37313
37452
|
);
|
|
37314
|
-
const readFile =
|
|
37453
|
+
const readFile = useCallback9(
|
|
37315
37454
|
async (mediaId) => {
|
|
37316
37455
|
if (!isOPFSSupported()) {
|
|
37317
37456
|
throw new Error("OPFS is not supported in this browser.");
|
|
@@ -37367,7 +37506,7 @@ function useFiles(options) {
|
|
|
37367
37506
|
},
|
|
37368
37507
|
[walletAddress]
|
|
37369
37508
|
);
|
|
37370
|
-
const createBlobUrl =
|
|
37509
|
+
const createBlobUrl = useCallback9(
|
|
37371
37510
|
async (mediaId) => {
|
|
37372
37511
|
const existingUrl = blobUrlManager.getUrl(mediaId);
|
|
37373
37512
|
if (existingUrl) {
|
|
@@ -37383,16 +37522,16 @@ function useFiles(options) {
|
|
|
37383
37522
|
},
|
|
37384
37523
|
[readFile, blobUrlManager]
|
|
37385
37524
|
);
|
|
37386
|
-
const revokeBlobUrl =
|
|
37525
|
+
const revokeBlobUrl = useCallback9(
|
|
37387
37526
|
(mediaId) => {
|
|
37388
37527
|
blobUrlManager.revokeUrl(mediaId);
|
|
37389
37528
|
},
|
|
37390
37529
|
[blobUrlManager]
|
|
37391
37530
|
);
|
|
37392
|
-
const revokeAllBlobUrls =
|
|
37531
|
+
const revokeAllBlobUrls = useCallback9(() => {
|
|
37393
37532
|
blobUrlManager.revokeAll();
|
|
37394
37533
|
}, [blobUrlManager]);
|
|
37395
|
-
const resolveFilePlaceholders2 =
|
|
37534
|
+
const resolveFilePlaceholders2 = useCallback9(
|
|
37396
37535
|
async (content) => {
|
|
37397
37536
|
if (!walletAddress || !hasEncryptionKey(walletAddress)) {
|
|
37398
37537
|
return content;
|
|
@@ -37450,9 +37589,9 @@ function useFiles(options) {
|
|
|
37450
37589
|
import {
|
|
37451
37590
|
createContext as createContext4,
|
|
37452
37591
|
createElement as createElement3,
|
|
37453
|
-
useCallback as
|
|
37592
|
+
useCallback as useCallback10,
|
|
37454
37593
|
useContext as useContext4,
|
|
37455
|
-
useEffect as
|
|
37594
|
+
useEffect as useEffect8,
|
|
37456
37595
|
useState as useState9
|
|
37457
37596
|
} from "react";
|
|
37458
37597
|
var ICloudAuthContext = createContext4(null);
|
|
@@ -37467,7 +37606,7 @@ function ICloudAuthProvider({
|
|
|
37467
37606
|
const [isAvailable, setIsAvailable] = useState9(false);
|
|
37468
37607
|
const [isConfigured, setIsConfigured] = useState9(false);
|
|
37469
37608
|
const [_isLoading, setIsLoading] = useState9(false);
|
|
37470
|
-
|
|
37609
|
+
useEffect8(() => {
|
|
37471
37610
|
if (!apiToken || typeof window === "undefined") {
|
|
37472
37611
|
return;
|
|
37473
37612
|
}
|
|
@@ -37500,7 +37639,7 @@ function ICloudAuthProvider({
|
|
|
37500
37639
|
};
|
|
37501
37640
|
void initCloudKit();
|
|
37502
37641
|
}, [apiToken, containerIdentifier, environment]);
|
|
37503
|
-
const requestAccess =
|
|
37642
|
+
const requestAccess = useCallback10(async () => {
|
|
37504
37643
|
if (!isConfigured) {
|
|
37505
37644
|
throw new Error("iCloud is not configured");
|
|
37506
37645
|
}
|
|
@@ -37515,7 +37654,7 @@ function ICloudAuthProvider({
|
|
|
37515
37654
|
throw new Error(err instanceof Error ? err.message : "Failed to sign in to iCloud");
|
|
37516
37655
|
}
|
|
37517
37656
|
}, [isAuthenticated, isConfigured]);
|
|
37518
|
-
const logout =
|
|
37657
|
+
const logout = useCallback10(() => {
|
|
37519
37658
|
setIsAuthenticated(false);
|
|
37520
37659
|
setUserRecordName(null);
|
|
37521
37660
|
}, []);
|
|
@@ -37548,7 +37687,7 @@ function clearICloudAuth() {
|
|
|
37548
37687
|
}
|
|
37549
37688
|
|
|
37550
37689
|
// src/react/useICloudBackup.ts
|
|
37551
|
-
import { useCallback as
|
|
37690
|
+
import { useCallback as useCallback11, useMemo as useMemo7 } from "react";
|
|
37552
37691
|
function useICloudBackup(options) {
|
|
37553
37692
|
const { database, userAddress, requestEncryptionKey: requestEncryptionKey2, exportConversation, importConversation } = options;
|
|
37554
37693
|
const { isAuthenticated, isConfigured, isAvailable, requestAccess } = useICloudAuth();
|
|
@@ -37561,7 +37700,7 @@ function useICloudBackup(options) {
|
|
|
37561
37700
|
}),
|
|
37562
37701
|
[requestAccess, requestEncryptionKey2, exportConversation, importConversation]
|
|
37563
37702
|
);
|
|
37564
|
-
const ensureAuthenticated =
|
|
37703
|
+
const ensureAuthenticated = useCallback11(async () => {
|
|
37565
37704
|
if (isAuthenticated) return true;
|
|
37566
37705
|
try {
|
|
37567
37706
|
await requestAccess();
|
|
@@ -37570,7 +37709,7 @@ function useICloudBackup(options) {
|
|
|
37570
37709
|
return false;
|
|
37571
37710
|
}
|
|
37572
37711
|
}, [isAuthenticated, requestAccess]);
|
|
37573
|
-
const backup =
|
|
37712
|
+
const backup = useCallback11(
|
|
37574
37713
|
async (backupOptions) => {
|
|
37575
37714
|
if (!userAddress) {
|
|
37576
37715
|
return { error: "Please sign in to backup to iCloud" };
|
|
@@ -37595,7 +37734,7 @@ function useICloudBackup(options) {
|
|
|
37595
37734
|
},
|
|
37596
37735
|
[database, userAddress, isAvailable, isConfigured, ensureAuthenticated, deps]
|
|
37597
37736
|
);
|
|
37598
|
-
const restore =
|
|
37737
|
+
const restore = useCallback11(
|
|
37599
37738
|
async (restoreOptions) => {
|
|
37600
37739
|
if (!userAddress) {
|
|
37601
37740
|
return { error: "Please sign in to restore from iCloud" };
|
|
@@ -37630,7 +37769,7 @@ function useICloudBackup(options) {
|
|
|
37630
37769
|
}
|
|
37631
37770
|
|
|
37632
37771
|
// src/react/useModels.ts
|
|
37633
|
-
import { useCallback as
|
|
37772
|
+
import { useCallback as useCallback12, useEffect as useEffect9, useRef as useRef6, useState as useState10 } from "react";
|
|
37634
37773
|
var MODELS_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
37635
37774
|
var modelsCache = /* @__PURE__ */ new Map();
|
|
37636
37775
|
var modelsInFlight = /* @__PURE__ */ new Map();
|
|
@@ -37762,12 +37901,12 @@ function useModels(options = {}) {
|
|
|
37762
37901
|
const baseUrlRef = useRef6(baseUrl);
|
|
37763
37902
|
const providerRef = useRef6(provider);
|
|
37764
37903
|
const abortControllerRef = useRef6(null);
|
|
37765
|
-
|
|
37904
|
+
useEffect9(() => {
|
|
37766
37905
|
getTokenRef.current = getToken;
|
|
37767
37906
|
baseUrlRef.current = baseUrl;
|
|
37768
37907
|
providerRef.current = provider;
|
|
37769
37908
|
});
|
|
37770
|
-
|
|
37909
|
+
useEffect9(() => {
|
|
37771
37910
|
return () => {
|
|
37772
37911
|
if (abortControllerRef.current) {
|
|
37773
37912
|
abortControllerRef.current.abort();
|
|
@@ -37775,7 +37914,7 @@ function useModels(options = {}) {
|
|
|
37775
37914
|
}
|
|
37776
37915
|
};
|
|
37777
37916
|
}, []);
|
|
37778
|
-
const fetchModels =
|
|
37917
|
+
const fetchModels = useCallback12(async (force = false) => {
|
|
37779
37918
|
if (abortControllerRef.current) {
|
|
37780
37919
|
abortControllerRef.current.abort();
|
|
37781
37920
|
}
|
|
@@ -37815,12 +37954,12 @@ function useModels(options = {}) {
|
|
|
37815
37954
|
}
|
|
37816
37955
|
}
|
|
37817
37956
|
}, []);
|
|
37818
|
-
const refetch =
|
|
37957
|
+
const refetch = useCallback12(async () => {
|
|
37819
37958
|
setModels([]);
|
|
37820
37959
|
await fetchModels(true);
|
|
37821
37960
|
}, [fetchModels]);
|
|
37822
37961
|
const hasFetchedRef = useRef6(false);
|
|
37823
|
-
|
|
37962
|
+
useEffect9(() => {
|
|
37824
37963
|
if (autoFetch && !hasFetchedRef.current) {
|
|
37825
37964
|
hasFetchedRef.current = true;
|
|
37826
37965
|
void fetchModels();
|
|
@@ -37838,12 +37977,12 @@ function useModels(options = {}) {
|
|
|
37838
37977
|
}
|
|
37839
37978
|
|
|
37840
37979
|
// src/react/useOCR.ts
|
|
37841
|
-
import { useCallback as
|
|
37980
|
+
import { useCallback as useCallback13, useState as useState11 } from "react";
|
|
37842
37981
|
import Tesseract from "tesseract.js";
|
|
37843
37982
|
function useOCR() {
|
|
37844
37983
|
const [isProcessing, setIsProcessing] = useState11(false);
|
|
37845
37984
|
const [error, setError] = useState11(null);
|
|
37846
|
-
const extractOCRContext =
|
|
37985
|
+
const extractOCRContext = useCallback13(async (files) => {
|
|
37847
37986
|
setIsProcessing(true);
|
|
37848
37987
|
setError(null);
|
|
37849
37988
|
try {
|
|
@@ -37921,12 +38060,12 @@ ${text16}`;
|
|
|
37921
38060
|
}
|
|
37922
38061
|
|
|
37923
38062
|
// src/react/usePdf.ts
|
|
37924
|
-
import { useCallback as
|
|
38063
|
+
import { useCallback as useCallback14, useState as useState12 } from "react";
|
|
37925
38064
|
var PDF_MIME_TYPE = "application/pdf";
|
|
37926
38065
|
function usePdf() {
|
|
37927
38066
|
const [isProcessing, setIsProcessing] = useState12(false);
|
|
37928
38067
|
const [error, setError] = useState12(null);
|
|
37929
|
-
const extractPdfContext =
|
|
38068
|
+
const extractPdfContext = useCallback14(async (files) => {
|
|
37930
38069
|
setIsProcessing(true);
|
|
37931
38070
|
setError(null);
|
|
37932
38071
|
try {
|
|
@@ -37970,7 +38109,7 @@ ${text16}`;
|
|
|
37970
38109
|
}
|
|
37971
38110
|
|
|
37972
38111
|
// src/react/usePhoneCalls.ts
|
|
37973
|
-
import { useCallback as
|
|
38112
|
+
import { useCallback as useCallback15, useEffect as useEffect10, useRef as useRef7, useState as useState13 } from "react";
|
|
37974
38113
|
var DEFAULT_POLL_INTERVAL_MS = 5e3;
|
|
37975
38114
|
var DEFAULT_POLL_MAX_ATTEMPTS = 60;
|
|
37976
38115
|
var TERMINAL_SUCCESS_STATUSES = /* @__PURE__ */ new Set(["complete", "completed"]);
|
|
@@ -38013,12 +38152,12 @@ function usePhoneCalls(options = {}) {
|
|
|
38013
38152
|
const requestAbortControllerRef = useRef7(null);
|
|
38014
38153
|
const pollAbortControllerRef = useRef7(null);
|
|
38015
38154
|
const pollRunIdRef = useRef7(0);
|
|
38016
|
-
|
|
38155
|
+
useEffect10(() => {
|
|
38017
38156
|
getTokenRef.current = getToken;
|
|
38018
38157
|
baseUrlRef.current = baseUrl;
|
|
38019
38158
|
onErrorRef.current = onError;
|
|
38020
38159
|
});
|
|
38021
|
-
const stopPolling =
|
|
38160
|
+
const stopPolling = useCallback15(() => {
|
|
38022
38161
|
pollRunIdRef.current += 1;
|
|
38023
38162
|
if (pollAbortControllerRef.current) {
|
|
38024
38163
|
pollAbortControllerRef.current.abort();
|
|
@@ -38026,7 +38165,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38026
38165
|
}
|
|
38027
38166
|
setIsPolling(false);
|
|
38028
38167
|
}, []);
|
|
38029
|
-
|
|
38168
|
+
useEffect10(() => {
|
|
38030
38169
|
return () => {
|
|
38031
38170
|
if (requestAbortControllerRef.current) {
|
|
38032
38171
|
requestAbortControllerRef.current.abort();
|
|
@@ -38039,21 +38178,21 @@ function usePhoneCalls(options = {}) {
|
|
|
38039
38178
|
}
|
|
38040
38179
|
};
|
|
38041
38180
|
}, []);
|
|
38042
|
-
const startLoading =
|
|
38181
|
+
const startLoading = useCallback15(() => {
|
|
38043
38182
|
loadingCountRef.current += 1;
|
|
38044
38183
|
setIsLoading(true);
|
|
38045
38184
|
}, []);
|
|
38046
|
-
const stopLoading =
|
|
38185
|
+
const stopLoading = useCallback15(() => {
|
|
38047
38186
|
loadingCountRef.current = Math.max(0, loadingCountRef.current - 1);
|
|
38048
38187
|
setIsLoading(loadingCountRef.current > 0);
|
|
38049
38188
|
}, []);
|
|
38050
|
-
const handleError =
|
|
38189
|
+
const handleError = useCallback15((err) => {
|
|
38051
38190
|
const nextError = err instanceof Error ? err : new Error(String(err));
|
|
38052
38191
|
setError(nextError);
|
|
38053
38192
|
onErrorRef.current?.(nextError);
|
|
38054
38193
|
return nextError;
|
|
38055
38194
|
}, []);
|
|
38056
|
-
const getHeaders =
|
|
38195
|
+
const getHeaders = useCallback15(async () => {
|
|
38057
38196
|
const headers = {};
|
|
38058
38197
|
if (getTokenRef.current) {
|
|
38059
38198
|
const token = await getTokenRef.current();
|
|
@@ -38063,7 +38202,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38063
38202
|
}
|
|
38064
38203
|
return headers;
|
|
38065
38204
|
}, []);
|
|
38066
|
-
const fetchAvailability =
|
|
38205
|
+
const fetchAvailability = useCallback15(async () => {
|
|
38067
38206
|
if (requestAbortControllerRef.current) {
|
|
38068
38207
|
requestAbortControllerRef.current.abort();
|
|
38069
38208
|
}
|
|
@@ -38101,7 +38240,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38101
38240
|
}
|
|
38102
38241
|
}
|
|
38103
38242
|
}, [getHeaders, handleError, startLoading, stopLoading]);
|
|
38104
|
-
const createPhoneCall =
|
|
38243
|
+
const createPhoneCall = useCallback15(
|
|
38105
38244
|
async (request) => {
|
|
38106
38245
|
startLoading();
|
|
38107
38246
|
setError(null);
|
|
@@ -38128,7 +38267,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38128
38267
|
},
|
|
38129
38268
|
[getHeaders, handleError, startLoading, stopLoading]
|
|
38130
38269
|
);
|
|
38131
|
-
const getPhoneCall =
|
|
38270
|
+
const getPhoneCall = useCallback15(
|
|
38132
38271
|
async (callId) => {
|
|
38133
38272
|
const trimmedCallId = callId.trim();
|
|
38134
38273
|
if (!trimmedCallId) {
|
|
@@ -38177,7 +38316,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38177
38316
|
},
|
|
38178
38317
|
[getHeaders, handleError, startLoading, stopLoading]
|
|
38179
38318
|
);
|
|
38180
|
-
const pollPhoneCall =
|
|
38319
|
+
const pollPhoneCall = useCallback15(
|
|
38181
38320
|
async (callId, pollOptions = {}) => {
|
|
38182
38321
|
const trimmedCallId = callId.trim();
|
|
38183
38322
|
if (!trimmedCallId) {
|
|
@@ -38242,11 +38381,11 @@ function usePhoneCalls(options = {}) {
|
|
|
38242
38381
|
},
|
|
38243
38382
|
[getHeaders, handleError, stopPolling]
|
|
38244
38383
|
);
|
|
38245
|
-
const reset =
|
|
38384
|
+
const reset = useCallback15(() => {
|
|
38246
38385
|
setCurrentCall(null);
|
|
38247
38386
|
setError(null);
|
|
38248
38387
|
}, []);
|
|
38249
|
-
|
|
38388
|
+
useEffect10(() => {
|
|
38250
38389
|
if (!autoFetchAvailability) {
|
|
38251
38390
|
return;
|
|
38252
38391
|
}
|
|
@@ -38269,7 +38408,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38269
38408
|
|
|
38270
38409
|
// src/react/useProjects.ts
|
|
38271
38410
|
import { Q as Q20 } from "@nozbe/watermelondb";
|
|
38272
|
-
import { useCallback as
|
|
38411
|
+
import { useCallback as useCallback16, useEffect as useEffect11, useMemo as useMemo8, useState as useState14 } from "react";
|
|
38273
38412
|
function useProjects(options) {
|
|
38274
38413
|
const { database, initialProjectId } = options;
|
|
38275
38414
|
const [projects, setProjects] = useState14([]);
|
|
@@ -38279,7 +38418,7 @@ function useProjects(options) {
|
|
|
38279
38418
|
const [inboxProjectId, setInboxProjectId] = useState14(null);
|
|
38280
38419
|
const [projectsCollection, setProjectsCollection] = useState14(null);
|
|
38281
38420
|
const [conversationsCollection, setConversationsCollection] = useState14(null);
|
|
38282
|
-
|
|
38421
|
+
useEffect11(() => {
|
|
38283
38422
|
const initCollections = async () => {
|
|
38284
38423
|
getLogger().debug("[useProjects] Initializing collections...");
|
|
38285
38424
|
try {
|
|
@@ -38336,7 +38475,7 @@ function useProjects(options) {
|
|
|
38336
38475
|
return null;
|
|
38337
38476
|
}
|
|
38338
38477
|
}, [database, conversationsCollection, isReady]);
|
|
38339
|
-
const refreshProjects =
|
|
38478
|
+
const refreshProjects = useCallback16(async () => {
|
|
38340
38479
|
if (!projectCtx) {
|
|
38341
38480
|
return;
|
|
38342
38481
|
}
|
|
@@ -38350,12 +38489,12 @@ function useProjects(options) {
|
|
|
38350
38489
|
setIsLoading(false);
|
|
38351
38490
|
}
|
|
38352
38491
|
}, [projectCtx]);
|
|
38353
|
-
|
|
38492
|
+
useEffect11(() => {
|
|
38354
38493
|
if (isReady) {
|
|
38355
38494
|
void refreshProjects();
|
|
38356
38495
|
}
|
|
38357
38496
|
}, [isReady, refreshProjects]);
|
|
38358
|
-
|
|
38497
|
+
useEffect11(() => {
|
|
38359
38498
|
const ensureInboxProject = async () => {
|
|
38360
38499
|
if (!projectCtx || !isReady) return;
|
|
38361
38500
|
try {
|
|
@@ -38373,7 +38512,7 @@ function useProjects(options) {
|
|
|
38373
38512
|
};
|
|
38374
38513
|
void ensureInboxProject();
|
|
38375
38514
|
}, [projectCtx, isReady]);
|
|
38376
|
-
|
|
38515
|
+
useEffect11(() => {
|
|
38377
38516
|
if (!projectsCollection) {
|
|
38378
38517
|
return;
|
|
38379
38518
|
}
|
|
@@ -38382,7 +38521,7 @@ function useProjects(options) {
|
|
|
38382
38521
|
});
|
|
38383
38522
|
return () => subscription.unsubscribe();
|
|
38384
38523
|
}, [projectsCollection]);
|
|
38385
|
-
const createProject =
|
|
38524
|
+
const createProject = useCallback16(
|
|
38386
38525
|
async (opts) => {
|
|
38387
38526
|
if (!projectCtx) {
|
|
38388
38527
|
throw new Error("Projects not available. Database schema may need to be updated.");
|
|
@@ -38392,7 +38531,7 @@ function useProjects(options) {
|
|
|
38392
38531
|
},
|
|
38393
38532
|
[projectCtx]
|
|
38394
38533
|
);
|
|
38395
|
-
const getProject =
|
|
38534
|
+
const getProject = useCallback16(
|
|
38396
38535
|
async (projectId) => {
|
|
38397
38536
|
if (!projectCtx) {
|
|
38398
38537
|
return null;
|
|
@@ -38401,13 +38540,13 @@ function useProjects(options) {
|
|
|
38401
38540
|
},
|
|
38402
38541
|
[projectCtx]
|
|
38403
38542
|
);
|
|
38404
|
-
const getProjects =
|
|
38543
|
+
const getProjects = useCallback16(async () => {
|
|
38405
38544
|
if (!projectCtx) {
|
|
38406
38545
|
return [];
|
|
38407
38546
|
}
|
|
38408
38547
|
return getProjectsOp(projectCtx);
|
|
38409
38548
|
}, [projectCtx]);
|
|
38410
|
-
const updateProjectName =
|
|
38549
|
+
const updateProjectName = useCallback16(
|
|
38411
38550
|
async (projectId, name) => {
|
|
38412
38551
|
if (!projectCtx) {
|
|
38413
38552
|
return false;
|
|
@@ -38416,7 +38555,7 @@ function useProjects(options) {
|
|
|
38416
38555
|
},
|
|
38417
38556
|
[projectCtx]
|
|
38418
38557
|
);
|
|
38419
|
-
const updateProject =
|
|
38558
|
+
const updateProject = useCallback16(
|
|
38420
38559
|
async (projectId, opts) => {
|
|
38421
38560
|
if (!projectCtx) {
|
|
38422
38561
|
return false;
|
|
@@ -38425,7 +38564,7 @@ function useProjects(options) {
|
|
|
38425
38564
|
},
|
|
38426
38565
|
[projectCtx]
|
|
38427
38566
|
);
|
|
38428
|
-
const deleteProject =
|
|
38567
|
+
const deleteProject = useCallback16(
|
|
38429
38568
|
async (projectId) => {
|
|
38430
38569
|
if (!projectCtx) {
|
|
38431
38570
|
return false;
|
|
@@ -38438,7 +38577,7 @@ function useProjects(options) {
|
|
|
38438
38577
|
},
|
|
38439
38578
|
[projectCtx, currentProjectId]
|
|
38440
38579
|
);
|
|
38441
|
-
const getProjectConversations =
|
|
38580
|
+
const getProjectConversations = useCallback16(
|
|
38442
38581
|
async (projectId) => {
|
|
38443
38582
|
if (!projectCtx) {
|
|
38444
38583
|
return [];
|
|
@@ -38447,7 +38586,7 @@ function useProjects(options) {
|
|
|
38447
38586
|
},
|
|
38448
38587
|
[projectCtx]
|
|
38449
38588
|
);
|
|
38450
|
-
const getProjectConversationCount =
|
|
38589
|
+
const getProjectConversationCount = useCallback16(
|
|
38451
38590
|
async (projectId) => {
|
|
38452
38591
|
if (!projectCtx) {
|
|
38453
38592
|
return 0;
|
|
@@ -38456,7 +38595,7 @@ function useProjects(options) {
|
|
|
38456
38595
|
},
|
|
38457
38596
|
[projectCtx]
|
|
38458
38597
|
);
|
|
38459
|
-
const updateConversationProject =
|
|
38598
|
+
const updateConversationProject = useCallback16(
|
|
38460
38599
|
async (conversationId, projectId) => {
|
|
38461
38600
|
if (!storageCtx) {
|
|
38462
38601
|
return false;
|
|
@@ -38465,7 +38604,7 @@ function useProjects(options) {
|
|
|
38465
38604
|
},
|
|
38466
38605
|
[storageCtx]
|
|
38467
38606
|
);
|
|
38468
|
-
const getConversationsByProject =
|
|
38607
|
+
const getConversationsByProject = useCallback16(
|
|
38469
38608
|
async (projectId) => {
|
|
38470
38609
|
if (!storageCtx) {
|
|
38471
38610
|
return [];
|
|
@@ -38496,7 +38635,7 @@ function useProjects(options) {
|
|
|
38496
38635
|
}
|
|
38497
38636
|
|
|
38498
38637
|
// src/react/useSettings.ts
|
|
38499
|
-
import { useCallback as
|
|
38638
|
+
import { useCallback as useCallback17, useMemo as useMemo9, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
38500
38639
|
|
|
38501
38640
|
// src/react/userSettingsStore.ts
|
|
38502
38641
|
import { Q as Q21 } from "@nozbe/watermelondb";
|
|
@@ -38634,15 +38773,15 @@ function patchUserSettingsSnapshot(database, walletAddress, patch) {
|
|
|
38634
38773
|
var DB_NOT_READY = "Database not ready";
|
|
38635
38774
|
function useSettings(options) {
|
|
38636
38775
|
const { database, walletAddress } = options;
|
|
38637
|
-
const subscribe =
|
|
38776
|
+
const subscribe = useCallback17(
|
|
38638
38777
|
(listener) => subscribeUserSettings(database, walletAddress, listener),
|
|
38639
38778
|
[database, walletAddress]
|
|
38640
38779
|
);
|
|
38641
|
-
const getSnapshot =
|
|
38780
|
+
const getSnapshot = useCallback17(
|
|
38642
38781
|
() => getUserSettingsSnapshot(database, walletAddress),
|
|
38643
38782
|
[database, walletAddress]
|
|
38644
38783
|
);
|
|
38645
|
-
const snapshot =
|
|
38784
|
+
const snapshot = useSyncExternalStore2(subscribe, getSnapshot, getSnapshot);
|
|
38646
38785
|
const storageCtx = useMemo9(
|
|
38647
38786
|
() => database ? {
|
|
38648
38787
|
database,
|
|
@@ -38658,7 +38797,7 @@ function useSettings(options) {
|
|
|
38658
38797
|
} : null,
|
|
38659
38798
|
[database]
|
|
38660
38799
|
);
|
|
38661
|
-
const getModelPreference =
|
|
38800
|
+
const getModelPreference = useCallback17(
|
|
38662
38801
|
async (address) => {
|
|
38663
38802
|
try {
|
|
38664
38803
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38671,7 +38810,7 @@ function useSettings(options) {
|
|
|
38671
38810
|
},
|
|
38672
38811
|
[legacyStorageCtx]
|
|
38673
38812
|
);
|
|
38674
|
-
const setModelPreference =
|
|
38813
|
+
const setModelPreference = useCallback17(
|
|
38675
38814
|
async (address, models) => {
|
|
38676
38815
|
try {
|
|
38677
38816
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38687,7 +38826,7 @@ function useSettings(options) {
|
|
|
38687
38826
|
},
|
|
38688
38827
|
[database, legacyStorageCtx, walletAddress]
|
|
38689
38828
|
);
|
|
38690
|
-
const deleteModelPreference =
|
|
38829
|
+
const deleteModelPreference = useCallback17(
|
|
38691
38830
|
async (address) => {
|
|
38692
38831
|
try {
|
|
38693
38832
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38703,7 +38842,7 @@ function useSettings(options) {
|
|
|
38703
38842
|
},
|
|
38704
38843
|
[database, legacyStorageCtx, walletAddress]
|
|
38705
38844
|
);
|
|
38706
|
-
const getUserPreference =
|
|
38845
|
+
const getUserPreference = useCallback17(
|
|
38707
38846
|
async (address) => {
|
|
38708
38847
|
try {
|
|
38709
38848
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38716,7 +38855,7 @@ function useSettings(options) {
|
|
|
38716
38855
|
},
|
|
38717
38856
|
[storageCtx]
|
|
38718
38857
|
);
|
|
38719
|
-
const setUserPreference =
|
|
38858
|
+
const setUserPreference = useCallback17(
|
|
38720
38859
|
async (address, opts) => {
|
|
38721
38860
|
try {
|
|
38722
38861
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38732,7 +38871,7 @@ function useSettings(options) {
|
|
|
38732
38871
|
},
|
|
38733
38872
|
[database, storageCtx, walletAddress]
|
|
38734
38873
|
);
|
|
38735
|
-
const updateProfile =
|
|
38874
|
+
const updateProfile = useCallback17(
|
|
38736
38875
|
async (address, profile) => {
|
|
38737
38876
|
try {
|
|
38738
38877
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38748,7 +38887,7 @@ function useSettings(options) {
|
|
|
38748
38887
|
},
|
|
38749
38888
|
[database, storageCtx, walletAddress]
|
|
38750
38889
|
);
|
|
38751
|
-
const updatePersonality =
|
|
38890
|
+
const updatePersonality = useCallback17(
|
|
38752
38891
|
async (address, personality) => {
|
|
38753
38892
|
try {
|
|
38754
38893
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38764,7 +38903,7 @@ function useSettings(options) {
|
|
|
38764
38903
|
},
|
|
38765
38904
|
[database, storageCtx, walletAddress]
|
|
38766
38905
|
);
|
|
38767
|
-
const updateModels =
|
|
38906
|
+
const updateModels = useCallback17(
|
|
38768
38907
|
async (address, models) => {
|
|
38769
38908
|
try {
|
|
38770
38909
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38780,7 +38919,7 @@ function useSettings(options) {
|
|
|
38780
38919
|
},
|
|
38781
38920
|
[database, storageCtx, walletAddress]
|
|
38782
38921
|
);
|
|
38783
|
-
const deleteUserPreference =
|
|
38922
|
+
const deleteUserPreference = useCallback17(
|
|
38784
38923
|
async (address) => {
|
|
38785
38924
|
try {
|
|
38786
38925
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38813,7 +38952,7 @@ function useSettings(options) {
|
|
|
38813
38952
|
}
|
|
38814
38953
|
|
|
38815
38954
|
// src/react/useSubscription.ts
|
|
38816
|
-
import { useCallback as
|
|
38955
|
+
import { useCallback as useCallback18, useEffect as useEffect12, useRef as useRef8, useState as useState15 } from "react";
|
|
38817
38956
|
function useSubscription(options = {}) {
|
|
38818
38957
|
const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
|
|
38819
38958
|
const [status, setStatus] = useState15(null);
|
|
@@ -38823,12 +38962,12 @@ function useSubscription(options = {}) {
|
|
|
38823
38962
|
const baseUrlRef = useRef8(baseUrl);
|
|
38824
38963
|
const onErrorRef = useRef8(onError);
|
|
38825
38964
|
const abortControllerRef = useRef8(null);
|
|
38826
|
-
|
|
38965
|
+
useEffect12(() => {
|
|
38827
38966
|
getTokenRef.current = getToken;
|
|
38828
38967
|
baseUrlRef.current = baseUrl;
|
|
38829
38968
|
onErrorRef.current = onError;
|
|
38830
38969
|
});
|
|
38831
|
-
|
|
38970
|
+
useEffect12(() => {
|
|
38832
38971
|
return () => {
|
|
38833
38972
|
if (abortControllerRef.current) {
|
|
38834
38973
|
abortControllerRef.current.abort();
|
|
@@ -38836,7 +38975,7 @@ function useSubscription(options = {}) {
|
|
|
38836
38975
|
}
|
|
38837
38976
|
};
|
|
38838
38977
|
}, []);
|
|
38839
|
-
const getHeaders =
|
|
38978
|
+
const getHeaders = useCallback18(async () => {
|
|
38840
38979
|
const headers = {};
|
|
38841
38980
|
if (getTokenRef.current) {
|
|
38842
38981
|
const token = await getTokenRef.current();
|
|
@@ -38846,13 +38985,13 @@ function useSubscription(options = {}) {
|
|
|
38846
38985
|
}
|
|
38847
38986
|
return headers;
|
|
38848
38987
|
}, []);
|
|
38849
|
-
const handleError =
|
|
38988
|
+
const handleError = useCallback18((err) => {
|
|
38850
38989
|
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
38851
38990
|
setError(error2);
|
|
38852
38991
|
onErrorRef.current?.(error2);
|
|
38853
38992
|
return error2;
|
|
38854
38993
|
}, []);
|
|
38855
|
-
const fetchStatus =
|
|
38994
|
+
const fetchStatus = useCallback18(async () => {
|
|
38856
38995
|
if (abortControllerRef.current) {
|
|
38857
38996
|
abortControllerRef.current.abort();
|
|
38858
38997
|
}
|
|
@@ -38889,11 +39028,11 @@ function useSubscription(options = {}) {
|
|
|
38889
39028
|
}
|
|
38890
39029
|
}
|
|
38891
39030
|
}, [getHeaders, handleError]);
|
|
38892
|
-
const refetch =
|
|
39031
|
+
const refetch = useCallback18(async () => {
|
|
38893
39032
|
setStatus(null);
|
|
38894
39033
|
await fetchStatus();
|
|
38895
39034
|
}, [fetchStatus]);
|
|
38896
|
-
const createCheckoutSession =
|
|
39035
|
+
const createCheckoutSession = useCallback18(
|
|
38897
39036
|
async (opts) => {
|
|
38898
39037
|
setIsLoading(true);
|
|
38899
39038
|
setError(null);
|
|
@@ -38923,7 +39062,7 @@ function useSubscription(options = {}) {
|
|
|
38923
39062
|
},
|
|
38924
39063
|
[getHeaders, handleError]
|
|
38925
39064
|
);
|
|
38926
|
-
const openCustomerPortal =
|
|
39065
|
+
const openCustomerPortal = useCallback18(
|
|
38927
39066
|
async (opts) => {
|
|
38928
39067
|
setIsLoading(true);
|
|
38929
39068
|
setError(null);
|
|
@@ -38950,7 +39089,7 @@ function useSubscription(options = {}) {
|
|
|
38950
39089
|
},
|
|
38951
39090
|
[getHeaders, handleError]
|
|
38952
39091
|
);
|
|
38953
|
-
const cancelSubscription =
|
|
39092
|
+
const cancelSubscription = useCallback18(async () => {
|
|
38954
39093
|
setIsLoading(true);
|
|
38955
39094
|
setError(null);
|
|
38956
39095
|
try {
|
|
@@ -38972,7 +39111,7 @@ function useSubscription(options = {}) {
|
|
|
38972
39111
|
setIsLoading(false);
|
|
38973
39112
|
}
|
|
38974
39113
|
}, [getHeaders, handleError, fetchStatus]);
|
|
38975
|
-
const renewSubscription =
|
|
39114
|
+
const renewSubscription = useCallback18(async () => {
|
|
38976
39115
|
setIsLoading(true);
|
|
38977
39116
|
setError(null);
|
|
38978
39117
|
try {
|
|
@@ -38995,7 +39134,7 @@ function useSubscription(options = {}) {
|
|
|
38995
39134
|
}
|
|
38996
39135
|
}, [getHeaders, handleError, fetchStatus]);
|
|
38997
39136
|
const hasFetchedRef = useRef8(false);
|
|
38998
|
-
|
|
39137
|
+
useEffect12(() => {
|
|
38999
39138
|
if (autoFetch && !hasFetchedRef.current) {
|
|
39000
39139
|
hasFetchedRef.current = true;
|
|
39001
39140
|
void fetchStatus();
|
|
@@ -39017,7 +39156,7 @@ function useSubscription(options = {}) {
|
|
|
39017
39156
|
}
|
|
39018
39157
|
|
|
39019
39158
|
// src/react/useTools.ts
|
|
39020
|
-
import { useCallback as
|
|
39159
|
+
import { useCallback as useCallback19, useEffect as useEffect13, useMemo as useMemo10, useRef as useRef9, useState as useState16 } from "react";
|
|
39021
39160
|
function useTools(options) {
|
|
39022
39161
|
const { getToken, baseUrl = BASE_URL, includeTools, autoFetch = true } = options;
|
|
39023
39162
|
const [allTools, setAllTools] = useState16([]);
|
|
@@ -39035,11 +39174,11 @@ function useTools(options) {
|
|
|
39035
39174
|
);
|
|
39036
39175
|
const getTokenRef = useRef9(getToken);
|
|
39037
39176
|
const baseUrlRef = useRef9(baseUrl);
|
|
39038
|
-
|
|
39177
|
+
useEffect13(() => {
|
|
39039
39178
|
getTokenRef.current = getToken;
|
|
39040
39179
|
baseUrlRef.current = baseUrl;
|
|
39041
39180
|
});
|
|
39042
|
-
const fetchTools =
|
|
39181
|
+
const fetchTools = useCallback19(async (forceRefresh = false) => {
|
|
39043
39182
|
setIsLoading(true);
|
|
39044
39183
|
setError(null);
|
|
39045
39184
|
try {
|
|
@@ -39056,13 +39195,13 @@ function useTools(options) {
|
|
|
39056
39195
|
setIsLoading(false);
|
|
39057
39196
|
}
|
|
39058
39197
|
}, []);
|
|
39059
|
-
const refresh =
|
|
39198
|
+
const refresh = useCallback19(
|
|
39060
39199
|
async (force = false) => {
|
|
39061
39200
|
await fetchTools(force);
|
|
39062
39201
|
},
|
|
39063
39202
|
[fetchTools]
|
|
39064
39203
|
);
|
|
39065
|
-
const checkForUpdates =
|
|
39204
|
+
const checkForUpdates = useCallback19(
|
|
39066
39205
|
(responseChecksum) => {
|
|
39067
39206
|
if (shouldRefreshTools(responseChecksum)) {
|
|
39068
39207
|
void refresh(true);
|
|
@@ -39073,7 +39212,7 @@ function useTools(options) {
|
|
|
39073
39212
|
[refresh]
|
|
39074
39213
|
);
|
|
39075
39214
|
const hasFetchedRef = useRef9(false);
|
|
39076
|
-
|
|
39215
|
+
useEffect13(() => {
|
|
39077
39216
|
if (autoFetch && !hasFetchedRef.current) {
|
|
39078
39217
|
hasFetchedRef.current = true;
|
|
39079
39218
|
void fetchTools();
|
|
@@ -39096,7 +39235,7 @@ function useTools(options) {
|
|
|
39096
39235
|
import {
|
|
39097
39236
|
createContext as createContext5,
|
|
39098
39237
|
createElement as createElement4,
|
|
39099
|
-
useCallback as
|
|
39238
|
+
useCallback as useCallback20,
|
|
39100
39239
|
useContext as useContext5,
|
|
39101
39240
|
useMemo as useMemo11,
|
|
39102
39241
|
useRef as useRef10,
|
|
@@ -39118,7 +39257,7 @@ function UIInteractionProvider({
|
|
|
39118
39257
|
/* @__PURE__ */ new Map()
|
|
39119
39258
|
);
|
|
39120
39259
|
const timersRef = useRef10(/* @__PURE__ */ new Map());
|
|
39121
|
-
const createInteraction =
|
|
39260
|
+
const createInteraction = useCallback20(
|
|
39122
39261
|
(id2, type, data) => {
|
|
39123
39262
|
return new Promise((resolve, reject) => {
|
|
39124
39263
|
const interaction = {
|
|
@@ -39149,7 +39288,7 @@ function UIInteractionProvider({
|
|
|
39149
39288
|
},
|
|
39150
39289
|
[timeout]
|
|
39151
39290
|
);
|
|
39152
|
-
const createDisplayInteraction =
|
|
39291
|
+
const createDisplayInteraction = useCallback20(
|
|
39153
39292
|
(id2, displayType, data, result, toolVersion, replacesInteractionId) => {
|
|
39154
39293
|
setPendingInteractions((prev) => {
|
|
39155
39294
|
const next = new Map(prev);
|
|
@@ -39181,7 +39320,7 @@ function UIInteractionProvider({
|
|
|
39181
39320
|
},
|
|
39182
39321
|
[]
|
|
39183
39322
|
);
|
|
39184
|
-
const resolveInteraction =
|
|
39323
|
+
const resolveInteraction = useCallback20((id2, result) => {
|
|
39185
39324
|
setPendingInteractions((prev) => {
|
|
39186
39325
|
const interaction = prev.get(id2);
|
|
39187
39326
|
if (!interaction) {
|
|
@@ -39198,7 +39337,7 @@ function UIInteractionProvider({
|
|
|
39198
39337
|
return next;
|
|
39199
39338
|
});
|
|
39200
39339
|
}, []);
|
|
39201
|
-
const clearInteractions =
|
|
39340
|
+
const clearInteractions = useCallback20(() => {
|
|
39202
39341
|
for (const timer of timersRef.current.values()) {
|
|
39203
39342
|
clearTimeout(timer);
|
|
39204
39343
|
}
|
|
@@ -39212,7 +39351,7 @@ function UIInteractionProvider({
|
|
|
39212
39351
|
return /* @__PURE__ */ new Map();
|
|
39213
39352
|
});
|
|
39214
39353
|
}, []);
|
|
39215
|
-
const cancelInteraction =
|
|
39354
|
+
const cancelInteraction = useCallback20((id2) => {
|
|
39216
39355
|
setPendingInteractions((prev) => {
|
|
39217
39356
|
const interaction = prev.get(id2);
|
|
39218
39357
|
if (!interaction) {
|
|
@@ -39229,7 +39368,7 @@ function UIInteractionProvider({
|
|
|
39229
39368
|
return next;
|
|
39230
39369
|
});
|
|
39231
39370
|
}, []);
|
|
39232
|
-
const getInteraction =
|
|
39371
|
+
const getInteraction = useCallback20(
|
|
39233
39372
|
(id2) => {
|
|
39234
39373
|
return pendingInteractions.get(id2);
|
|
39235
39374
|
},
|
|
@@ -39259,7 +39398,7 @@ function UIInteractionProvider({
|
|
|
39259
39398
|
}
|
|
39260
39399
|
|
|
39261
39400
|
// src/react/useVoice.ts
|
|
39262
|
-
import { useCallback as
|
|
39401
|
+
import { useCallback as useCallback21, useMemo as useMemo12, useRef as useRef11, useState as useState18 } from "react";
|
|
39263
39402
|
function getOnDeviceSpeechRecognition() {
|
|
39264
39403
|
if (typeof window === "undefined") return null;
|
|
39265
39404
|
if (!/iPhone|iPad|iPod/.test(navigator.userAgent)) return null;
|
|
@@ -39324,11 +39463,11 @@ function useVoice(options) {
|
|
|
39324
39463
|
const startTimeRef = useRef11(0);
|
|
39325
39464
|
const pipelineRef = useRef11(null);
|
|
39326
39465
|
const modelNameRef = useRef11(null);
|
|
39327
|
-
const getModelName =
|
|
39466
|
+
const getModelName = useCallback21(() => {
|
|
39328
39467
|
const model = options?.model ?? "whisper-tiny";
|
|
39329
39468
|
return `onnx-community/${model}`;
|
|
39330
39469
|
}, [options?.model]);
|
|
39331
|
-
const loadPipeline =
|
|
39470
|
+
const loadPipeline = useCallback21(async () => {
|
|
39332
39471
|
const modelName = getModelName();
|
|
39333
39472
|
if (pipelineRef.current && modelNameRef.current === modelName) {
|
|
39334
39473
|
return pipelineRef.current;
|
|
@@ -39363,10 +39502,10 @@ function useVoice(options) {
|
|
|
39363
39502
|
setIsLoadingModel(false);
|
|
39364
39503
|
}
|
|
39365
39504
|
}, [getModelName, options?.onModelProgress]);
|
|
39366
|
-
const preloadModel =
|
|
39505
|
+
const preloadModel = useCallback21(async () => {
|
|
39367
39506
|
await loadPipeline();
|
|
39368
39507
|
}, [loadPipeline]);
|
|
39369
|
-
const disposeModel =
|
|
39508
|
+
const disposeModel = useCallback21(async () => {
|
|
39370
39509
|
const pipe = pipelineRef.current;
|
|
39371
39510
|
if (pipe?.dispose) {
|
|
39372
39511
|
await pipe.dispose();
|
|
@@ -39375,7 +39514,7 @@ function useVoice(options) {
|
|
|
39375
39514
|
modelNameRef.current = null;
|
|
39376
39515
|
setIsModelLoaded(false);
|
|
39377
39516
|
}, []);
|
|
39378
|
-
const startRecording =
|
|
39517
|
+
const startRecording = useCallback21(async () => {
|
|
39379
39518
|
setError(null);
|
|
39380
39519
|
setRecording(null);
|
|
39381
39520
|
setTranscription(null);
|
|
@@ -39400,7 +39539,7 @@ function useVoice(options) {
|
|
|
39400
39539
|
throw processedError;
|
|
39401
39540
|
}
|
|
39402
39541
|
}, []);
|
|
39403
|
-
const stopRecording =
|
|
39542
|
+
const stopRecording = useCallback21(async () => {
|
|
39404
39543
|
return new Promise((resolve, reject) => {
|
|
39405
39544
|
const recorder = mediaRecorderRef.current;
|
|
39406
39545
|
if (!recorder || recorder.state === "inactive") {
|
|
@@ -39430,7 +39569,7 @@ function useVoice(options) {
|
|
|
39430
39569
|
recorder.stop();
|
|
39431
39570
|
});
|
|
39432
39571
|
}, []);
|
|
39433
|
-
const transcribe =
|
|
39572
|
+
const transcribe = useCallback21(
|
|
39434
39573
|
async (rec) => {
|
|
39435
39574
|
const target = rec ?? recording;
|
|
39436
39575
|
if (!target) {
|
|
@@ -39468,7 +39607,7 @@ function useVoice(options) {
|
|
|
39468
39607
|
const nativeRecognitionRef = useRef11(null);
|
|
39469
39608
|
const nativeTextRef = useRef11("");
|
|
39470
39609
|
const nativeResolveRef = useRef11(null);
|
|
39471
|
-
const startNativeTranscription =
|
|
39610
|
+
const startNativeTranscription = useCallback21(() => {
|
|
39472
39611
|
const SR = getOnDeviceSpeechRecognition();
|
|
39473
39612
|
if (!SR) return;
|
|
39474
39613
|
nativeTextRef.current = "";
|
|
@@ -39505,7 +39644,7 @@ function useVoice(options) {
|
|
|
39505
39644
|
recognition.start();
|
|
39506
39645
|
setIsNativeListening(true);
|
|
39507
39646
|
}, [options?.language]);
|
|
39508
|
-
const stopNativeTranscription =
|
|
39647
|
+
const stopNativeTranscription = useCallback21(() => {
|
|
39509
39648
|
return new Promise((resolve) => {
|
|
39510
39649
|
const recognition = nativeRecognitionRef.current;
|
|
39511
39650
|
if (!recognition) {
|
|
@@ -39516,7 +39655,7 @@ function useVoice(options) {
|
|
|
39516
39655
|
recognition.stop();
|
|
39517
39656
|
});
|
|
39518
39657
|
}, []);
|
|
39519
|
-
const abortNativeTranscription =
|
|
39658
|
+
const abortNativeTranscription = useCallback21(() => {
|
|
39520
39659
|
const recognition = nativeRecognitionRef.current;
|
|
39521
39660
|
if (recognition) {
|
|
39522
39661
|
nativeResolveRef.current = null;
|
|
@@ -39547,7 +39686,7 @@ function useVoice(options) {
|
|
|
39547
39686
|
}
|
|
39548
39687
|
|
|
39549
39688
|
// src/react/useWalletBinding.ts
|
|
39550
|
-
import { useCallback as
|
|
39689
|
+
import { useCallback as useCallback22, useEffect as useEffect14, useRef as useRef12, useState as useState19 } from "react";
|
|
39551
39690
|
function useWalletBinding(options = {}) {
|
|
39552
39691
|
const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
|
|
39553
39692
|
const [wallets, setWallets] = useState19([]);
|
|
@@ -39558,12 +39697,12 @@ function useWalletBinding(options = {}) {
|
|
|
39558
39697
|
const baseUrlRef = useRef12(baseUrl);
|
|
39559
39698
|
const onErrorRef = useRef12(onError);
|
|
39560
39699
|
const abortControllerRef = useRef12(null);
|
|
39561
|
-
|
|
39700
|
+
useEffect14(() => {
|
|
39562
39701
|
getTokenRef.current = getToken;
|
|
39563
39702
|
baseUrlRef.current = baseUrl;
|
|
39564
39703
|
onErrorRef.current = onError;
|
|
39565
39704
|
});
|
|
39566
|
-
|
|
39705
|
+
useEffect14(() => {
|
|
39567
39706
|
return () => {
|
|
39568
39707
|
if (abortControllerRef.current) {
|
|
39569
39708
|
abortControllerRef.current.abort();
|
|
@@ -39571,7 +39710,7 @@ function useWalletBinding(options = {}) {
|
|
|
39571
39710
|
}
|
|
39572
39711
|
};
|
|
39573
39712
|
}, []);
|
|
39574
|
-
const getHeaders =
|
|
39713
|
+
const getHeaders = useCallback22(async () => {
|
|
39575
39714
|
const headers = {};
|
|
39576
39715
|
if (getTokenRef.current) {
|
|
39577
39716
|
const token = await getTokenRef.current();
|
|
@@ -39581,13 +39720,13 @@ function useWalletBinding(options = {}) {
|
|
|
39581
39720
|
}
|
|
39582
39721
|
return headers;
|
|
39583
39722
|
}, []);
|
|
39584
|
-
const handleError =
|
|
39723
|
+
const handleError = useCallback22((err) => {
|
|
39585
39724
|
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
39586
39725
|
setError(error2);
|
|
39587
39726
|
onErrorRef.current?.(error2);
|
|
39588
39727
|
return error2;
|
|
39589
39728
|
}, []);
|
|
39590
|
-
const fetchBinding =
|
|
39729
|
+
const fetchBinding = useCallback22(async () => {
|
|
39591
39730
|
if (abortControllerRef.current) {
|
|
39592
39731
|
abortControllerRef.current.abort();
|
|
39593
39732
|
}
|
|
@@ -39625,12 +39764,12 @@ function useWalletBinding(options = {}) {
|
|
|
39625
39764
|
}
|
|
39626
39765
|
}
|
|
39627
39766
|
}, [getHeaders, handleError]);
|
|
39628
|
-
const refetch =
|
|
39767
|
+
const refetch = useCallback22(async () => {
|
|
39629
39768
|
setWallets([]);
|
|
39630
39769
|
setTotals(null);
|
|
39631
39770
|
await fetchBinding();
|
|
39632
39771
|
}, [fetchBinding]);
|
|
39633
|
-
const getNonce =
|
|
39772
|
+
const getNonce = useCallback22(async () => {
|
|
39634
39773
|
setIsLoading(true);
|
|
39635
39774
|
setError(null);
|
|
39636
39775
|
try {
|
|
@@ -39651,7 +39790,7 @@ function useWalletBinding(options = {}) {
|
|
|
39651
39790
|
setIsLoading(false);
|
|
39652
39791
|
}
|
|
39653
39792
|
}, [getHeaders, handleError]);
|
|
39654
|
-
const bindWallet =
|
|
39793
|
+
const bindWallet = useCallback22(
|
|
39655
39794
|
async (request) => {
|
|
39656
39795
|
setIsLoading(true);
|
|
39657
39796
|
setError(null);
|
|
@@ -39677,7 +39816,7 @@ function useWalletBinding(options = {}) {
|
|
|
39677
39816
|
},
|
|
39678
39817
|
[getHeaders, handleError, fetchBinding]
|
|
39679
39818
|
);
|
|
39680
|
-
const unbindWallet =
|
|
39819
|
+
const unbindWallet = useCallback22(
|
|
39681
39820
|
async (address) => {
|
|
39682
39821
|
setIsLoading(true);
|
|
39683
39822
|
setError(null);
|
|
@@ -39704,7 +39843,7 @@ function useWalletBinding(options = {}) {
|
|
|
39704
39843
|
[getHeaders, handleError, fetchBinding]
|
|
39705
39844
|
);
|
|
39706
39845
|
const hasFetchedRef = useRef12(false);
|
|
39707
|
-
|
|
39846
|
+
useEffect14(() => {
|
|
39708
39847
|
if (autoFetch && !hasFetchedRef.current) {
|
|
39709
39848
|
hasFetchedRef.current = true;
|
|
39710
39849
|
void fetchBinding();
|