@anuma/sdk 10.2.1 → 10.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.d.mts +1 -4
- package/dist/client/index.d.ts +1 -4
- 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 +200 -103
- package/dist/expo/index.d.mts +3 -0
- package/dist/expo/index.d.ts +3 -0
- package/dist/expo/index.mjs +168 -79
- 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 +506 -409
- package/dist/react/index.d.mts +3 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.mjs +358 -269
- 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 +7 -0
- package/dist/server/index.d.mts +3 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.mjs +2 -2
- 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);
|
|
@@ -19964,11 +19964,11 @@ function loadVaultCorpus(ctx, options, preparation) {
|
|
|
19964
19964
|
}
|
|
19965
19965
|
return request;
|
|
19966
19966
|
}
|
|
19967
|
-
function rowRequestsFor(
|
|
19968
|
-
let byMask =
|
|
19967
|
+
function rowRequestsFor(registry3, ctx, maskInput) {
|
|
19968
|
+
let byMask = registry3.get(ctx);
|
|
19969
19969
|
if (!byMask) {
|
|
19970
19970
|
byMask = /* @__PURE__ */ new Map();
|
|
19971
|
-
|
|
19971
|
+
registry3.set(ctx, byMask);
|
|
19972
19972
|
}
|
|
19973
19973
|
let requests = byMask.get(maskInput);
|
|
19974
19974
|
if (!requests) {
|
|
@@ -20903,11 +20903,11 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
20903
20903
|
};
|
|
20904
20904
|
}
|
|
20905
20905
|
const limit = searchOptions?.limit ?? 5;
|
|
20906
|
-
const
|
|
20906
|
+
const scopes2 = searchOptions?.scopes;
|
|
20907
20907
|
const folderId = searchOptions?.folderId;
|
|
20908
20908
|
const queryOpts = {};
|
|
20909
20909
|
if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
|
|
20910
|
-
if (
|
|
20910
|
+
if (scopes2?.length) queryOpts.scopes = scopes2;
|
|
20911
20911
|
if (folderId !== void 0) queryOpts.folderId = folderId;
|
|
20912
20912
|
if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
|
|
20913
20913
|
if (searchOptions?.includeArchived) queryOpts.includeArchived = true;
|
|
@@ -21685,7 +21685,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
21685
21685
|
content: m.content,
|
|
21686
21686
|
similarity: m.similarity
|
|
21687
21687
|
}));
|
|
21688
|
-
const { consolidateMemory: doConsolidate } = await import("./consolidate-
|
|
21688
|
+
const { consolidateMemory: doConsolidate } = await import("./consolidate-3RQL75PJ.mjs");
|
|
21689
21689
|
const decision = await doConsolidate(trimmed, candidates, consolidateOptions);
|
|
21690
21690
|
if (decision.action === "create") return decision.fallbackReason ? null : { create: true };
|
|
21691
21691
|
if (decision.action === "supersede" && decision.content) {
|
|
@@ -27190,17 +27190,17 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
27190
27190
|
}
|
|
27191
27191
|
const recallCtx = store ? { embeddingOptions: ctx.embeddingOptions, factSource: store.factSource } : ctx;
|
|
27192
27192
|
const facets = options.facets ?? DEFAULT_PROFILE_FACETS;
|
|
27193
|
-
const
|
|
27193
|
+
const scopes2 = options.scopes ?? DEFAULT_SCOPES;
|
|
27194
27194
|
const config = {
|
|
27195
27195
|
facetKeys: facets.map((f) => f.key).sort(),
|
|
27196
27196
|
facetsSignature: facetsSignature(facets),
|
|
27197
|
-
scopes: [...
|
|
27197
|
+
scopes: [...scopes2].sort(),
|
|
27198
27198
|
redacted: options.redactor !== void 0,
|
|
27199
27199
|
reviewedMemoryIdsSignature: reviewedMemoryIdsSignature(options.reviewedMemoryIds)
|
|
27200
27200
|
};
|
|
27201
27201
|
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 }), []];
|
|
27202
|
+
const listOptions = { scopes: scopes2, includeDeleted: true, includeSuperseded: true };
|
|
27203
|
+
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes: scopes2 }), []];
|
|
27204
27204
|
const watermark = computeVaultWatermark(memories);
|
|
27205
27205
|
const observationTrends = summarizeObservationTrends(
|
|
27206
27206
|
memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
|
|
@@ -27245,7 +27245,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
27245
27245
|
for (const section of previous.sections) {
|
|
27246
27246
|
if (section.sourceMemoryIds.length > 0 && section.sourceMemoryIds.every((id2) => {
|
|
27247
27247
|
const memory = memoriesById.get(id2);
|
|
27248
|
-
return memory && !memory.isDeleted && !memory.supersededBy &&
|
|
27248
|
+
return memory && !memory.isDeleted && !memory.supersededBy && scopes2.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
|
|
27249
27249
|
})) {
|
|
27250
27250
|
fallbackPriors.set(section.key, section);
|
|
27251
27251
|
}
|
|
@@ -27418,7 +27418,7 @@ async function attributeFacts(ctx, candidates, facets) {
|
|
|
27418
27418
|
return keys;
|
|
27419
27419
|
}
|
|
27420
27420
|
async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
|
|
27421
|
-
const
|
|
27421
|
+
const scopes2 = options.scopes ?? DEFAULT_SCOPES;
|
|
27422
27422
|
const limit = options.limit ?? DEFAULT_FACET_RECALL_LIMIT;
|
|
27423
27423
|
const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
|
|
27424
27424
|
const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
|
|
@@ -27435,7 +27435,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
|
|
|
27435
27435
|
}
|
|
27436
27436
|
const recalled = await recall(facet.query, ctx, {
|
|
27437
27437
|
vaultPreparation,
|
|
27438
|
-
scopes,
|
|
27438
|
+
scopes: scopes2,
|
|
27439
27439
|
limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
|
|
27440
27440
|
...hasReviewGate && { memoryIds: [...reviewed] },
|
|
27441
27441
|
types: ["fact"],
|
|
@@ -27462,7 +27462,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
|
|
|
27462
27462
|
llmModel: options.llmModel ?? DEFAULT_SYNTHESIS_MODEL,
|
|
27463
27463
|
baseUrl: options.baseUrl,
|
|
27464
27464
|
fetchFn: options.fetchFn,
|
|
27465
|
-
scopes,
|
|
27465
|
+
scopes: scopes2,
|
|
27466
27466
|
limit,
|
|
27467
27467
|
types: ["fact"],
|
|
27468
27468
|
maxTokens: DEFAULT_FACET_MAX_TOKENS,
|
|
@@ -30372,8 +30372,8 @@ var ZipProcessor = class {
|
|
|
30372
30372
|
* Set the processor registry for handling nested files
|
|
30373
30373
|
* This must be called before processing if you want nested file support
|
|
30374
30374
|
*/
|
|
30375
|
-
setRegistry(
|
|
30376
|
-
this.registry =
|
|
30375
|
+
setRegistry(registry3) {
|
|
30376
|
+
this.registry = registry3;
|
|
30377
30377
|
}
|
|
30378
30378
|
async process(file) {
|
|
30379
30379
|
try {
|
|
@@ -30594,15 +30594,15 @@ function isImageFile(file) {
|
|
|
30594
30594
|
return (file.type ?? "").trim().toLowerCase().startsWith("image/");
|
|
30595
30595
|
}
|
|
30596
30596
|
function createDefaultRegistry() {
|
|
30597
|
-
const
|
|
30598
|
-
|
|
30599
|
-
|
|
30600
|
-
|
|
30601
|
-
|
|
30597
|
+
const registry3 = new ProcessorRegistry();
|
|
30598
|
+
registry3.register(new PdfProcessor());
|
|
30599
|
+
registry3.register(new ExcelProcessor());
|
|
30600
|
+
registry3.register(new WordProcessor());
|
|
30601
|
+
registry3.register(new TextProcessor());
|
|
30602
30602
|
const zipProcessor = new ZipProcessor();
|
|
30603
|
-
zipProcessor.setRegistry(
|
|
30604
|
-
|
|
30605
|
-
return
|
|
30603
|
+
zipProcessor.setRegistry(registry3);
|
|
30604
|
+
registry3.register(zipProcessor);
|
|
30605
|
+
return registry3;
|
|
30606
30606
|
}
|
|
30607
30607
|
var cachedDefaultRegistry = null;
|
|
30608
30608
|
function getDefaultRegistry() {
|
|
@@ -30615,10 +30615,10 @@ function isSupportedFile(file) {
|
|
|
30615
30615
|
return getDefaultRegistry().isSupported(file);
|
|
30616
30616
|
}
|
|
30617
30617
|
function getSupportedFileTypes() {
|
|
30618
|
-
const
|
|
30618
|
+
const registry3 = getDefaultRegistry();
|
|
30619
30619
|
return {
|
|
30620
|
-
mimeTypes:
|
|
30621
|
-
extensions:
|
|
30620
|
+
mimeTypes: registry3.getSupportedMimeTypes(),
|
|
30621
|
+
extensions: registry3.getSupportedExtensions()
|
|
30622
30622
|
};
|
|
30623
30623
|
}
|
|
30624
30624
|
function formatExtractedContent(fileName, content, format) {
|
|
@@ -30673,16 +30673,16 @@ async function preprocessFiles(files, options = {}) {
|
|
|
30673
30673
|
metadata: { processedCount: 0, skippedCount: fileStatuses2.length, errorCount: 0 }
|
|
30674
30674
|
};
|
|
30675
30675
|
}
|
|
30676
|
-
let
|
|
30676
|
+
let registry3;
|
|
30677
30677
|
if (processors === void 0) {
|
|
30678
|
-
|
|
30678
|
+
registry3 = getDefaultRegistry();
|
|
30679
30679
|
} else {
|
|
30680
|
-
|
|
30680
|
+
registry3 = new ProcessorRegistry();
|
|
30681
30681
|
processors.forEach((p) => {
|
|
30682
30682
|
if (p instanceof ZipProcessor) {
|
|
30683
|
-
p.setRegistry(
|
|
30683
|
+
p.setRegistry(registry3);
|
|
30684
30684
|
}
|
|
30685
|
-
|
|
30685
|
+
registry3.register(p);
|
|
30686
30686
|
});
|
|
30687
30687
|
}
|
|
30688
30688
|
const extractedTexts = [];
|
|
@@ -30702,7 +30702,7 @@ async function preprocessFiles(files, options = {}) {
|
|
|
30702
30702
|
fileStatuses.push({ fileId: file.id, fileName: file.name, status: "skipped", reason });
|
|
30703
30703
|
};
|
|
30704
30704
|
onProgress?.(i + 1, files.length, file.name);
|
|
30705
|
-
const processor =
|
|
30705
|
+
const processor = registry3.findProcessor(file);
|
|
30706
30706
|
if (!processor && isImageFile(file)) continue;
|
|
30707
30707
|
if (file.size > maxFileSizeBytes) {
|
|
30708
30708
|
logger.info(
|
|
@@ -33783,7 +33783,7 @@ function useChat(options) {
|
|
|
33783
33783
|
}
|
|
33784
33784
|
|
|
33785
33785
|
// src/react/useChatStorage.ts
|
|
33786
|
-
import { useCallback as
|
|
33786
|
+
import { useCallback as useCallback6, useEffect as useEffect5, useMemo as useMemo4, useRef as useRef4, useState as useState5 } from "react";
|
|
33787
33787
|
import { v7 as uuidv78 } from "uuid";
|
|
33788
33788
|
|
|
33789
33789
|
// src/lib/chat/assembleMessages.ts
|
|
@@ -34347,6 +34347,106 @@ function summaryStore(options) {
|
|
|
34347
34347
|
};
|
|
34348
34348
|
}
|
|
34349
34349
|
|
|
34350
|
+
// src/lib/pii/useConversationRedactors.ts
|
|
34351
|
+
import { useCallback as useCallback4, useEffect as useEffect4, useSyncExternalStore } from "react";
|
|
34352
|
+
var REDACTOR_LIMIT = 50;
|
|
34353
|
+
var registry2 = /* @__PURE__ */ new WeakMap();
|
|
34354
|
+
var compositeKeys = /* @__PURE__ */ new WeakMap();
|
|
34355
|
+
var scopes = /* @__PURE__ */ new Set();
|
|
34356
|
+
var retiredRedactor = new PiiRedactor();
|
|
34357
|
+
retiredRedactor.dispose();
|
|
34358
|
+
function retireScope(scope) {
|
|
34359
|
+
scopes.delete(scope);
|
|
34360
|
+
if (!scope.active) return;
|
|
34361
|
+
scope.active = false;
|
|
34362
|
+
for (const { redactor } of scope.redactors.values()) redactor.dispose();
|
|
34363
|
+
scope.redactors.clear();
|
|
34364
|
+
for (const redactor of scope.evicted) redactor.dispose();
|
|
34365
|
+
scope.evicted = [];
|
|
34366
|
+
for (const notify of scope.subscribers) notify();
|
|
34367
|
+
}
|
|
34368
|
+
function storageKey(storage, secondaryStorage) {
|
|
34369
|
+
if (!secondaryStorage) return storage;
|
|
34370
|
+
let inner = compositeKeys.get(storage);
|
|
34371
|
+
if (!inner) {
|
|
34372
|
+
inner = /* @__PURE__ */ new WeakMap();
|
|
34373
|
+
compositeKeys.set(storage, inner);
|
|
34374
|
+
}
|
|
34375
|
+
let key3 = inner.get(secondaryStorage);
|
|
34376
|
+
if (!key3) {
|
|
34377
|
+
key3 = {};
|
|
34378
|
+
inner.set(secondaryStorage, key3);
|
|
34379
|
+
}
|
|
34380
|
+
return key3;
|
|
34381
|
+
}
|
|
34382
|
+
function getScope(database, storage, account) {
|
|
34383
|
+
let stores = registry2.get(database);
|
|
34384
|
+
if (!stores) {
|
|
34385
|
+
stores = /* @__PURE__ */ new WeakMap();
|
|
34386
|
+
registry2.set(database, stores);
|
|
34387
|
+
}
|
|
34388
|
+
let accounts = stores.get(storage);
|
|
34389
|
+
if (!accounts) {
|
|
34390
|
+
accounts = /* @__PURE__ */ new Map();
|
|
34391
|
+
stores.set(storage, accounts);
|
|
34392
|
+
}
|
|
34393
|
+
let scope = accounts.get(account);
|
|
34394
|
+
if (!scope?.active) {
|
|
34395
|
+
scope = { active: true, users: 0, subscribers: /* @__PURE__ */ new Set(), redactors: /* @__PURE__ */ new Map(), evicted: [] };
|
|
34396
|
+
accounts.set(account, scope);
|
|
34397
|
+
}
|
|
34398
|
+
return scope;
|
|
34399
|
+
}
|
|
34400
|
+
onClearAllEncryptionState(() => {
|
|
34401
|
+
registry2 = /* @__PURE__ */ new WeakMap();
|
|
34402
|
+
for (const scope of [...scopes]) retireScope(scope);
|
|
34403
|
+
});
|
|
34404
|
+
function useConversationRedactors(database, account, storage, secondaryStorage) {
|
|
34405
|
+
const scope = getScope(database, storageKey(storage, secondaryStorage), account);
|
|
34406
|
+
const subscribe = useCallback4(
|
|
34407
|
+
(callback) => {
|
|
34408
|
+
scope.subscribers.add(callback);
|
|
34409
|
+
return () => {
|
|
34410
|
+
scope.subscribers.delete(callback);
|
|
34411
|
+
};
|
|
34412
|
+
},
|
|
34413
|
+
[scope]
|
|
34414
|
+
);
|
|
34415
|
+
const getSnapshot = useCallback4(() => scope.active ? scope : null, [scope]);
|
|
34416
|
+
useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
34417
|
+
useEffect4(() => {
|
|
34418
|
+
if (scope.active) scopes.add(scope);
|
|
34419
|
+
scope.users++;
|
|
34420
|
+
return () => {
|
|
34421
|
+
scope.users--;
|
|
34422
|
+
if (scope.users === 0) retireScope(scope);
|
|
34423
|
+
};
|
|
34424
|
+
}, [scope]);
|
|
34425
|
+
return useCallback4(
|
|
34426
|
+
(conversationId, nerDetector) => {
|
|
34427
|
+
if (!scope.active) return retiredRedactor;
|
|
34428
|
+
const cached = scope.redactors.get(conversationId);
|
|
34429
|
+
if (cached && cached.detector === nerDetector) {
|
|
34430
|
+
scope.redactors.delete(conversationId);
|
|
34431
|
+
scope.redactors.set(conversationId, cached);
|
|
34432
|
+
return cached.redactor;
|
|
34433
|
+
}
|
|
34434
|
+
if (cached) scope.evicted.push(cached.redactor);
|
|
34435
|
+
const redactor = new PiiRedactor({ nerDetector });
|
|
34436
|
+
scope.redactors.set(conversationId, { redactor, detector: nerDetector });
|
|
34437
|
+
if (scope.redactors.size > REDACTOR_LIMIT) {
|
|
34438
|
+
const oldest = scope.redactors.entries().next().value;
|
|
34439
|
+
if (oldest) {
|
|
34440
|
+
scope.evicted.push(oldest[1].redactor);
|
|
34441
|
+
scope.redactors.delete(oldest[0]);
|
|
34442
|
+
}
|
|
34443
|
+
}
|
|
34444
|
+
return redactor;
|
|
34445
|
+
},
|
|
34446
|
+
[scope]
|
|
34447
|
+
);
|
|
34448
|
+
}
|
|
34449
|
+
|
|
34350
34450
|
// src/lib/tools/selection/activeToolSets.ts
|
|
34351
34451
|
function mergeActiveToolSets(current, derived) {
|
|
34352
34452
|
if (derived.length === 0) return current;
|
|
@@ -34407,7 +34507,7 @@ function resetRecentToolSets() {
|
|
|
34407
34507
|
onClearAllEncryptionState(resetRecentToolSets);
|
|
34408
34508
|
|
|
34409
34509
|
// src/react/useChatMedia.ts
|
|
34410
|
-
import { useCallback as
|
|
34510
|
+
import { useCallback as useCallback5 } from "react";
|
|
34411
34511
|
function resolveMediaMeta(extractedKind, urlPath, reportedType) {
|
|
34412
34512
|
const isVideo = extractedKind === "video";
|
|
34413
34513
|
const extension = urlPath.match(/\.([a-zA-Z0-9]+)$/)?.[1] || (isVideo ? "mp4" : "png");
|
|
@@ -34420,7 +34520,7 @@ function resolveMediaMeta(extractedKind, urlPath, reportedType) {
|
|
|
34420
34520
|
}
|
|
34421
34521
|
function useChatMedia(options) {
|
|
34422
34522
|
const { mediaCtx, mcpR2Domain } = options;
|
|
34423
|
-
const getImageDimensions =
|
|
34523
|
+
const getImageDimensions = useCallback5(
|
|
34424
34524
|
async (blob) => {
|
|
34425
34525
|
if (!blob.type.startsWith("image/")) {
|
|
34426
34526
|
return void 0;
|
|
@@ -34447,7 +34547,7 @@ function useChatMedia(options) {
|
|
|
34447
34547
|
},
|
|
34448
34548
|
[]
|
|
34449
34549
|
);
|
|
34450
|
-
const extractAndStoreEncryptedMCPImages =
|
|
34550
|
+
const extractAndStoreEncryptedMCPImages = useCallback5(
|
|
34451
34551
|
async (content, address, conversationId, toolCallEvents) => {
|
|
34452
34552
|
let imageModel;
|
|
34453
34553
|
try {
|
|
@@ -34552,7 +34652,7 @@ function useChatMedia(options) {
|
|
|
34552
34652
|
},
|
|
34553
34653
|
[mediaCtx, getImageDimensions, mcpR2Domain]
|
|
34554
34654
|
);
|
|
34555
|
-
const storeUserFilesInOPFS =
|
|
34655
|
+
const storeUserFilesInOPFS = useCallback5(
|
|
34556
34656
|
async (files, address, conversationId, maxFileSizeBytes) => {
|
|
34557
34657
|
const canUseOPFS = isOPFSSupported() && hasEncryptionKey(address);
|
|
34558
34658
|
let encryptionKey;
|
|
@@ -34914,29 +35014,10 @@ async function storedToLlmapiMessage(stored2, encryptionKey, resolveMediaByIds)
|
|
|
34914
35014
|
}
|
|
34915
35015
|
return messages;
|
|
34916
35016
|
}
|
|
34917
|
-
var CONVERSATION_REDACTOR_LIMIT = 50;
|
|
34918
|
-
var NO_CONVERSATION_KEY = "__no_conversation__";
|
|
34919
35017
|
var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
|
|
34920
35018
|
var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
|
|
34921
35019
|
var MEMORY_STORE_NOT_READY = "Memory store is not ready";
|
|
34922
|
-
var conversationRedactors = /* @__PURE__ */ new Map();
|
|
34923
35020
|
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
35021
|
function resolveCallPii(requestPiiRedaction, hookPiiRedaction, getConversationRedactorFor) {
|
|
34941
35022
|
const effective = requestPiiRedaction === void 0 ? hookPiiRedaction : requestPiiRedaction;
|
|
34942
35023
|
const redactor = effective === true ? getConversationRedactorFor() : isPiiRedactor(effective) ? effective : void 0;
|
|
@@ -34995,11 +35076,17 @@ function useChatStorage(options) {
|
|
|
34995
35076
|
foldToolResultsInHistoryRef.current = foldToolResultsInHistory;
|
|
34996
35077
|
const nerDetectorRef = useRef4(nerDetector);
|
|
34997
35078
|
nerDetectorRef.current = nerDetector;
|
|
35079
|
+
const getConversationRedactor = useConversationRedactors(
|
|
35080
|
+
database,
|
|
35081
|
+
walletAddress,
|
|
35082
|
+
memoryStore ?? chatBackend ?? database,
|
|
35083
|
+
memoryStore && chatBackend ? chatBackend : void 0
|
|
35084
|
+
);
|
|
34998
35085
|
const resolvedPiiRedaction = useMemo4(
|
|
34999
35086
|
() => piiRedaction === true ? getConversationRedactor(currentConversationId, nerDetectorRef.current) : piiRedaction,
|
|
35000
|
-
[piiRedaction, currentConversationId]
|
|
35087
|
+
[piiRedaction, currentConversationId, getConversationRedactor]
|
|
35001
35088
|
);
|
|
35002
|
-
const maskForEmbedding =
|
|
35089
|
+
const maskForEmbedding = useCallback6(
|
|
35003
35090
|
(text16) => isPiiRedactor(resolvedPiiRedaction) ? resolvedPiiRedaction.maskText(text16) : text16,
|
|
35004
35091
|
[resolvedPiiRedaction]
|
|
35005
35092
|
);
|
|
@@ -35013,7 +35100,7 @@ function useChatStorage(options) {
|
|
|
35013
35100
|
);
|
|
35014
35101
|
const storeMaskMissing = memoryStore !== void 0 && memoryStore !== null && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
|
|
35015
35102
|
const blobManagerRef = useRef4(new BlobUrlManager());
|
|
35016
|
-
|
|
35103
|
+
useEffect5(() => {
|
|
35017
35104
|
const manager = blobManagerRef.current;
|
|
35018
35105
|
return () => {
|
|
35019
35106
|
manager.revokeAll();
|
|
@@ -35105,12 +35192,12 @@ function useChatStorage(options) {
|
|
|
35105
35192
|
isFlushing: false,
|
|
35106
35193
|
isPaused: false
|
|
35107
35194
|
});
|
|
35108
|
-
const refreshQueueStatus =
|
|
35195
|
+
const refreshQueueStatus = useCallback6(() => {
|
|
35109
35196
|
if (walletAddress) {
|
|
35110
35197
|
setQueueStatus(queueManager.getStatus(walletAddress));
|
|
35111
35198
|
}
|
|
35112
35199
|
}, [walletAddress]);
|
|
35113
|
-
const executeQueuedOperation =
|
|
35200
|
+
const executeQueuedOperation = useCallback6(
|
|
35114
35201
|
async (operation, encCtx) => {
|
|
35115
35202
|
const queued = queuedBackends.get(operation.payload) ?? backendFactory({
|
|
35116
35203
|
walletAddress: encCtx.walletAddress,
|
|
@@ -35158,7 +35245,7 @@ function useChatStorage(options) {
|
|
|
35158
35245
|
},
|
|
35159
35246
|
[backendFactory, database]
|
|
35160
35247
|
);
|
|
35161
|
-
const flushQueue =
|
|
35248
|
+
const flushQueue = useCallback6(async () => {
|
|
35162
35249
|
if (!walletAddress || !signMessage) {
|
|
35163
35250
|
return { succeeded: [], failed: [], total: 0 };
|
|
35164
35251
|
}
|
|
@@ -35177,31 +35264,31 @@ function useChatStorage(options) {
|
|
|
35177
35264
|
executeQueuedOperation,
|
|
35178
35265
|
refreshQueueStatus
|
|
35179
35266
|
]);
|
|
35180
|
-
const clearQueue =
|
|
35267
|
+
const clearQueue = useCallback6(() => {
|
|
35181
35268
|
if (walletAddress) {
|
|
35182
35269
|
queueManager.clear(walletAddress);
|
|
35183
35270
|
refreshQueueStatus();
|
|
35184
35271
|
}
|
|
35185
35272
|
}, [walletAddress, refreshQueueStatus]);
|
|
35186
|
-
|
|
35273
|
+
useEffect5(() => {
|
|
35187
35274
|
if (!walletAddress) return;
|
|
35188
35275
|
refreshQueueStatus();
|
|
35189
35276
|
return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
|
|
35190
35277
|
}, [walletAddress, refreshQueueStatus]);
|
|
35191
|
-
|
|
35278
|
+
useEffect5(() => {
|
|
35192
35279
|
if (!getWalletAddress || walletAddress) return;
|
|
35193
35280
|
const poller = new WalletPoller();
|
|
35194
35281
|
return poller.startPolling(getWalletAddress, () => {
|
|
35195
35282
|
});
|
|
35196
35283
|
}, [getWalletAddress, walletAddress]);
|
|
35197
|
-
const isEncryptionReady =
|
|
35284
|
+
const isEncryptionReady = useCallback6(() => {
|
|
35198
35285
|
if (!walletAddress || !signMessage) return true;
|
|
35199
35286
|
return hasEncryptionKey(walletAddress);
|
|
35200
35287
|
}, [walletAddress, signMessage]);
|
|
35201
35288
|
const pendingOpsRef = useRef4([]);
|
|
35202
35289
|
const syntheticConvIdsRef = useRef4(/* @__PURE__ */ new Set());
|
|
35203
35290
|
const syntheticConvQueueIdsRef = useRef4(/* @__PURE__ */ new Map());
|
|
35204
|
-
|
|
35291
|
+
useEffect5(() => {
|
|
35205
35292
|
if (!walletAddress || !enableQueue) return;
|
|
35206
35293
|
const pending = pendingOpsRef.current;
|
|
35207
35294
|
if (pending.length === 0) return;
|
|
@@ -35212,7 +35299,7 @@ function useChatStorage(options) {
|
|
|
35212
35299
|
pendingOpsRef.current = [];
|
|
35213
35300
|
refreshQueueStatus();
|
|
35214
35301
|
}, [walletAddress, enableQueue, refreshQueueStatus]);
|
|
35215
|
-
|
|
35302
|
+
useEffect5(() => {
|
|
35216
35303
|
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
35217
35304
|
return onKeyAvailable(walletAddress, () => {
|
|
35218
35305
|
flushQueue().catch((err) => {
|
|
@@ -35220,7 +35307,7 @@ function useChatStorage(options) {
|
|
|
35220
35307
|
});
|
|
35221
35308
|
});
|
|
35222
35309
|
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
35223
|
-
const writeOrQueue =
|
|
35310
|
+
const writeOrQueue = useCallback6(
|
|
35224
35311
|
async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
|
|
35225
35312
|
const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
|
|
35226
35313
|
const currentBackend = storageCtx.walletAddress ? backend : backendRef.current;
|
|
@@ -35258,7 +35345,7 @@ function useChatStorage(options) {
|
|
|
35258
35345
|
},
|
|
35259
35346
|
[storageCtx, backend, enableQueue, signMessage, getWalletAddress]
|
|
35260
35347
|
);
|
|
35261
|
-
const embedMessageAsync =
|
|
35348
|
+
const embedMessageAsync = useCallback6(
|
|
35262
35349
|
async (message, mask = maskForEmbedding) => {
|
|
35263
35350
|
if (!autoEmbedMessages || !getToken) return;
|
|
35264
35351
|
if (message.content.length < minContentLength) return;
|
|
@@ -35297,7 +35384,7 @@ function useChatStorage(options) {
|
|
|
35297
35384
|
maskForEmbedding
|
|
35298
35385
|
]
|
|
35299
35386
|
);
|
|
35300
|
-
const createMemoryEngineTool2 =
|
|
35387
|
+
const createMemoryEngineTool2 = useCallback6(
|
|
35301
35388
|
(searchOptions) => {
|
|
35302
35389
|
if (!getToken) {
|
|
35303
35390
|
throw new Error("getToken is required for memory engine tool");
|
|
@@ -35306,7 +35393,7 @@ function useChatStorage(options) {
|
|
|
35306
35393
|
},
|
|
35307
35394
|
[backend, getToken, vaultEmbeddingOptions]
|
|
35308
35395
|
);
|
|
35309
|
-
const retainVaultMemory =
|
|
35396
|
+
const retainVaultMemory = useCallback6(
|
|
35310
35397
|
async (input) => {
|
|
35311
35398
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35312
35399
|
if (memoryStore) {
|
|
@@ -35338,7 +35425,7 @@ function useChatStorage(options) {
|
|
|
35338
35425
|
},
|
|
35339
35426
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35340
35427
|
);
|
|
35341
|
-
const createMemoryVaultTool2 =
|
|
35428
|
+
const createMemoryVaultTool2 = useCallback6(
|
|
35342
35429
|
(options2) => {
|
|
35343
35430
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35344
35431
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
@@ -35360,7 +35447,7 @@ function useChatStorage(options) {
|
|
|
35360
35447
|
storeMaskMissing
|
|
35361
35448
|
]
|
|
35362
35449
|
);
|
|
35363
|
-
const getVaultMemories =
|
|
35450
|
+
const getVaultMemories = useCallback6(
|
|
35364
35451
|
(options2) => {
|
|
35365
35452
|
if (memoryStore === null) return Promise.resolve([]);
|
|
35366
35453
|
if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
|
|
@@ -35372,7 +35459,7 @@ function useChatStorage(options) {
|
|
|
35372
35459
|
},
|
|
35373
35460
|
[vaultCtx, memoryStore]
|
|
35374
35461
|
);
|
|
35375
|
-
const createVaultMemory =
|
|
35462
|
+
const createVaultMemory = useCallback6(
|
|
35376
35463
|
async (content, scope) => {
|
|
35377
35464
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35378
35465
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
@@ -35394,7 +35481,7 @@ function useChatStorage(options) {
|
|
|
35394
35481
|
},
|
|
35395
35482
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35396
35483
|
);
|
|
35397
|
-
const updateVaultMemory =
|
|
35484
|
+
const updateVaultMemory = useCallback6(
|
|
35398
35485
|
async (id2, content, scope) => {
|
|
35399
35486
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35400
35487
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
@@ -35420,7 +35507,7 @@ function useChatStorage(options) {
|
|
|
35420
35507
|
},
|
|
35421
35508
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35422
35509
|
);
|
|
35423
|
-
const deleteVaultMemory =
|
|
35510
|
+
const deleteVaultMemory = useCallback6(
|
|
35424
35511
|
async (id2) => {
|
|
35425
35512
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35426
35513
|
if (memoryStore) return memoryStore.delete(id2);
|
|
@@ -35435,7 +35522,7 @@ function useChatStorage(options) {
|
|
|
35435
35522
|
);
|
|
35436
35523
|
const chunkVectorCacheRef = useRef4(createChunkVectorCache());
|
|
35437
35524
|
const clientToolEmbeddingsCacheRef = useRef4(/* @__PURE__ */ new Map());
|
|
35438
|
-
|
|
35525
|
+
useEffect5(() => {
|
|
35439
35526
|
if (!getToken || memoryStore !== void 0) return;
|
|
35440
35527
|
void (async () => {
|
|
35441
35528
|
try {
|
|
@@ -35444,13 +35531,13 @@ function useChatStorage(options) {
|
|
|
35444
35531
|
}
|
|
35445
35532
|
})();
|
|
35446
35533
|
}, [vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore]);
|
|
35447
|
-
|
|
35534
|
+
useEffect5(() => {
|
|
35448
35535
|
return onClearAllEncryptionState(() => {
|
|
35449
35536
|
vaultEmbeddingCache.clear();
|
|
35450
35537
|
chunkVectorCacheRef.current.clear();
|
|
35451
35538
|
});
|
|
35452
35539
|
}, [vaultEmbeddingCache]);
|
|
35453
|
-
const createMemoryVaultSearchTool2 =
|
|
35540
|
+
const createMemoryVaultSearchTool2 = useCallback6(
|
|
35454
35541
|
(searchOptions) => {
|
|
35455
35542
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35456
35543
|
if (!getToken && !memoryStore) {
|
|
@@ -35466,7 +35553,7 @@ function useChatStorage(options) {
|
|
|
35466
35553
|
},
|
|
35467
35554
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35468
35555
|
);
|
|
35469
|
-
const createRecallTool2 =
|
|
35556
|
+
const createRecallTool2 = useCallback6(
|
|
35470
35557
|
(toolOptions, callbacks) => {
|
|
35471
35558
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
35472
35559
|
if (!getToken && !memoryStore) {
|
|
@@ -35506,7 +35593,7 @@ function useChatStorage(options) {
|
|
|
35506
35593
|
storeMaskMissing
|
|
35507
35594
|
]
|
|
35508
35595
|
);
|
|
35509
|
-
const searchVaultMemoriesFn =
|
|
35596
|
+
const searchVaultMemoriesFn = useCallback6(
|
|
35510
35597
|
async (query, searchOptions) => {
|
|
35511
35598
|
if (memoryStore === null) return [];
|
|
35512
35599
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
@@ -35522,7 +35609,7 @@ function useChatStorage(options) {
|
|
|
35522
35609
|
},
|
|
35523
35610
|
[vaultCtx, getToken, vaultEmbeddingOptions, vaultEmbeddingCache, memoryStore, storeMaskMissing]
|
|
35524
35611
|
);
|
|
35525
|
-
const recallFn =
|
|
35612
|
+
const recallFn = useCallback6(
|
|
35526
35613
|
async (query, options2) => {
|
|
35527
35614
|
if (memoryStore === null || !getToken && !memoryStore) {
|
|
35528
35615
|
return {
|
|
@@ -35587,7 +35674,7 @@ function useChatStorage(options) {
|
|
|
35587
35674
|
piiRedaction: resolvedPiiRedaction,
|
|
35588
35675
|
onPiiRedacted
|
|
35589
35676
|
});
|
|
35590
|
-
const createConversation =
|
|
35677
|
+
const createConversation = useCallback6(
|
|
35591
35678
|
async (opts) => {
|
|
35592
35679
|
const conversationOpts = {
|
|
35593
35680
|
...opts,
|
|
@@ -35610,16 +35697,16 @@ function useChatStorage(options) {
|
|
|
35610
35697
|
},
|
|
35611
35698
|
[defaultConversationTitle, writeOrQueue]
|
|
35612
35699
|
);
|
|
35613
|
-
const getConversation =
|
|
35700
|
+
const getConversation = useCallback6(
|
|
35614
35701
|
async (id2) => {
|
|
35615
35702
|
return backend.getConversation(id2);
|
|
35616
35703
|
},
|
|
35617
35704
|
[backend]
|
|
35618
35705
|
);
|
|
35619
|
-
const getConversations =
|
|
35706
|
+
const getConversations = useCallback6(async () => {
|
|
35620
35707
|
return backend.getConversations();
|
|
35621
35708
|
}, [backend]);
|
|
35622
|
-
const updateConversationTitle =
|
|
35709
|
+
const updateConversationTitle = useCallback6(
|
|
35623
35710
|
async (id2, title) => {
|
|
35624
35711
|
const { result } = await writeOrQueue(
|
|
35625
35712
|
"updateConversationTitle",
|
|
@@ -35631,7 +35718,7 @@ function useChatStorage(options) {
|
|
|
35631
35718
|
},
|
|
35632
35719
|
[writeOrQueue]
|
|
35633
35720
|
);
|
|
35634
|
-
const updateConversationPinned =
|
|
35721
|
+
const updateConversationPinned = useCallback6(
|
|
35635
35722
|
async (id2, pinned) => {
|
|
35636
35723
|
const { result } = await writeOrQueue(
|
|
35637
35724
|
"updateConversationPinned",
|
|
@@ -35643,7 +35730,7 @@ function useChatStorage(options) {
|
|
|
35643
35730
|
},
|
|
35644
35731
|
[writeOrQueue]
|
|
35645
35732
|
);
|
|
35646
|
-
const deleteConversation =
|
|
35733
|
+
const deleteConversation = useCallback6(
|
|
35647
35734
|
async (id2) => {
|
|
35648
35735
|
const deleted = await backend.deleteConversation(id2);
|
|
35649
35736
|
if (deleted) {
|
|
@@ -35658,7 +35745,7 @@ function useChatStorage(options) {
|
|
|
35658
35745
|
},
|
|
35659
35746
|
[backend, mediaCtx, currentConversationId]
|
|
35660
35747
|
);
|
|
35661
|
-
const resolveMessageFiles =
|
|
35748
|
+
const resolveMessageFiles = useCallback6(
|
|
35662
35749
|
async (messages) => {
|
|
35663
35750
|
if (walletAddress && hasEncryptionKey(walletAddress) && isOPFSSupported()) {
|
|
35664
35751
|
try {
|
|
@@ -35720,33 +35807,33 @@ function useChatStorage(options) {
|
|
|
35720
35807
|
},
|
|
35721
35808
|
[walletAddress]
|
|
35722
35809
|
);
|
|
35723
|
-
const getMessages =
|
|
35810
|
+
const getMessages = useCallback6(
|
|
35724
35811
|
async (convId) => {
|
|
35725
35812
|
const messages = await backend.getMessages(convId);
|
|
35726
35813
|
return resolveMessageFiles(messages);
|
|
35727
35814
|
},
|
|
35728
35815
|
[backend, resolveMessageFiles]
|
|
35729
35816
|
);
|
|
35730
|
-
const getMessagesPage =
|
|
35817
|
+
const getMessagesPage = useCallback6(
|
|
35731
35818
|
async (convId, options2) => {
|
|
35732
35819
|
const messages = await backend.getMessagesPage(convId, options2);
|
|
35733
35820
|
return resolveMessageFiles(messages);
|
|
35734
35821
|
},
|
|
35735
35822
|
[backend, resolveMessageFiles]
|
|
35736
35823
|
);
|
|
35737
|
-
const getMessageSkeletons =
|
|
35824
|
+
const getMessageSkeletons = useCallback6(
|
|
35738
35825
|
(convId) => {
|
|
35739
35826
|
return backend.getMessageSkeletons(convId);
|
|
35740
35827
|
},
|
|
35741
35828
|
[backend]
|
|
35742
35829
|
);
|
|
35743
|
-
const getMessageCount =
|
|
35830
|
+
const getMessageCount = useCallback6(
|
|
35744
35831
|
(convId) => {
|
|
35745
35832
|
return backend.getMessageCount(convId);
|
|
35746
35833
|
},
|
|
35747
35834
|
[backend]
|
|
35748
35835
|
);
|
|
35749
|
-
const ensureConversation =
|
|
35836
|
+
const ensureConversation = useCallback6(async () => {
|
|
35750
35837
|
if (currentConversationId) {
|
|
35751
35838
|
if (syntheticConvIdsRef.current.has(currentConversationId)) {
|
|
35752
35839
|
return currentConversationId;
|
|
@@ -35772,7 +35859,7 @@ function useChatStorage(options) {
|
|
|
35772
35859
|
mediaCtx,
|
|
35773
35860
|
mcpR2Domain
|
|
35774
35861
|
});
|
|
35775
|
-
const sendMessage =
|
|
35862
|
+
const sendMessage = useCallback6(
|
|
35776
35863
|
async (args) => {
|
|
35777
35864
|
const {
|
|
35778
35865
|
messages,
|
|
@@ -36704,6 +36791,8 @@ function useChatStorage(options) {
|
|
|
36704
36791
|
getMessages,
|
|
36705
36792
|
backend,
|
|
36706
36793
|
baseSendMessage,
|
|
36794
|
+
getConversationRedactor,
|
|
36795
|
+
piiRedaction,
|
|
36707
36796
|
walletAddress,
|
|
36708
36797
|
signMessage,
|
|
36709
36798
|
embeddedWalletSigner,
|
|
@@ -36716,7 +36805,7 @@ function useChatStorage(options) {
|
|
|
36716
36805
|
refreshQueueStatus
|
|
36717
36806
|
]
|
|
36718
36807
|
);
|
|
36719
|
-
const getAllFiles =
|
|
36808
|
+
const getAllFiles = useCallback6(
|
|
36720
36809
|
async (options2) => {
|
|
36721
36810
|
return backend.getAllFiles(options2);
|
|
36722
36811
|
},
|
|
@@ -36758,7 +36847,7 @@ function useChatStorage(options) {
|
|
|
36758
36847
|
}
|
|
36759
36848
|
|
|
36760
36849
|
// src/react/useCredits.ts
|
|
36761
|
-
import { useCallback as
|
|
36850
|
+
import { useCallback as useCallback7, useEffect as useEffect6, useRef as useRef5, useState as useState6 } from "react";
|
|
36762
36851
|
function useCredits(options = {}) {
|
|
36763
36852
|
const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
|
|
36764
36853
|
const [balance, setBalance] = useState6(null);
|
|
@@ -36770,12 +36859,12 @@ function useCredits(options = {}) {
|
|
|
36770
36859
|
const baseUrlRef = useRef5(baseUrl);
|
|
36771
36860
|
const onErrorRef = useRef5(onError);
|
|
36772
36861
|
const abortControllerRef = useRef5(null);
|
|
36773
|
-
|
|
36862
|
+
useEffect6(() => {
|
|
36774
36863
|
getTokenRef.current = getToken;
|
|
36775
36864
|
baseUrlRef.current = baseUrl;
|
|
36776
36865
|
onErrorRef.current = onError;
|
|
36777
36866
|
});
|
|
36778
|
-
|
|
36867
|
+
useEffect6(() => {
|
|
36779
36868
|
return () => {
|
|
36780
36869
|
if (abortControllerRef.current) {
|
|
36781
36870
|
abortControllerRef.current.abort();
|
|
@@ -36783,15 +36872,15 @@ function useCredits(options = {}) {
|
|
|
36783
36872
|
}
|
|
36784
36873
|
};
|
|
36785
36874
|
}, []);
|
|
36786
|
-
const startLoading =
|
|
36875
|
+
const startLoading = useCallback7(() => {
|
|
36787
36876
|
loadingCountRef.current++;
|
|
36788
36877
|
setIsLoading(true);
|
|
36789
36878
|
}, []);
|
|
36790
|
-
const stopLoading =
|
|
36879
|
+
const stopLoading = useCallback7(() => {
|
|
36791
36880
|
loadingCountRef.current = Math.max(0, loadingCountRef.current - 1);
|
|
36792
36881
|
setIsLoading(loadingCountRef.current > 0);
|
|
36793
36882
|
}, []);
|
|
36794
|
-
const getHeaders =
|
|
36883
|
+
const getHeaders = useCallback7(async () => {
|
|
36795
36884
|
const headers = {};
|
|
36796
36885
|
if (getTokenRef.current) {
|
|
36797
36886
|
const token = await getTokenRef.current();
|
|
@@ -36801,13 +36890,13 @@ function useCredits(options = {}) {
|
|
|
36801
36890
|
}
|
|
36802
36891
|
return headers;
|
|
36803
36892
|
}, []);
|
|
36804
|
-
const handleError =
|
|
36893
|
+
const handleError = useCallback7((err) => {
|
|
36805
36894
|
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
36806
36895
|
setError(error2);
|
|
36807
36896
|
onErrorRef.current?.(error2);
|
|
36808
36897
|
return error2;
|
|
36809
36898
|
}, []);
|
|
36810
|
-
const fetchBalance =
|
|
36899
|
+
const fetchBalance = useCallback7(async () => {
|
|
36811
36900
|
if (abortControllerRef.current) {
|
|
36812
36901
|
abortControllerRef.current.abort();
|
|
36813
36902
|
}
|
|
@@ -36840,11 +36929,11 @@ function useCredits(options = {}) {
|
|
|
36840
36929
|
}
|
|
36841
36930
|
}
|
|
36842
36931
|
}, [getHeaders, handleError, startLoading, stopLoading]);
|
|
36843
|
-
const refetch =
|
|
36932
|
+
const refetch = useCallback7(async () => {
|
|
36844
36933
|
setBalance(null);
|
|
36845
36934
|
await fetchBalance();
|
|
36846
36935
|
}, [fetchBalance]);
|
|
36847
|
-
const fetchPacks =
|
|
36936
|
+
const fetchPacks = useCallback7(async () => {
|
|
36848
36937
|
startLoading();
|
|
36849
36938
|
setError(null);
|
|
36850
36939
|
try {
|
|
@@ -36864,7 +36953,7 @@ function useCredits(options = {}) {
|
|
|
36864
36953
|
stopLoading();
|
|
36865
36954
|
}
|
|
36866
36955
|
}, [getHeaders, handleError, startLoading, stopLoading]);
|
|
36867
|
-
const purchaseCredits =
|
|
36956
|
+
const purchaseCredits = useCallback7(
|
|
36868
36957
|
async (credits, opts) => {
|
|
36869
36958
|
startLoading();
|
|
36870
36959
|
setError(null);
|
|
@@ -36894,7 +36983,7 @@ function useCredits(options = {}) {
|
|
|
36894
36983
|
[getHeaders, handleError, startLoading, stopLoading]
|
|
36895
36984
|
);
|
|
36896
36985
|
const hasFetchedRef = useRef5(false);
|
|
36897
|
-
|
|
36986
|
+
useEffect6(() => {
|
|
36898
36987
|
if (autoFetch && !hasFetchedRef.current) {
|
|
36899
36988
|
hasFetchedRef.current = true;
|
|
36900
36989
|
void fetchBalance();
|
|
@@ -36921,7 +37010,7 @@ function useDatabaseManager(walletAddress, manager) {
|
|
|
36921
37010
|
}
|
|
36922
37011
|
|
|
36923
37012
|
// src/react/useExportPdf.ts
|
|
36924
|
-
import { useCallback as
|
|
37013
|
+
import { useCallback as useCallback8, useState as useState7 } from "react";
|
|
36925
37014
|
var DEFAULT_FILENAME2 = "document.pdf";
|
|
36926
37015
|
function triggerDownload(blob, filename) {
|
|
36927
37016
|
const url = URL.createObjectURL(blob);
|
|
@@ -36940,7 +37029,7 @@ function useExportPdf() {
|
|
|
36940
37029
|
const [isExporting, setIsExporting] = useState7(false);
|
|
36941
37030
|
const [progress, setProgress] = useState7(null);
|
|
36942
37031
|
const [error, setError] = useState7(null);
|
|
36943
|
-
const wrappedExportElement =
|
|
37032
|
+
const wrappedExportElement = useCallback8(
|
|
36944
37033
|
async (element, options) => {
|
|
36945
37034
|
setIsExporting(true);
|
|
36946
37035
|
setError(null);
|
|
@@ -36960,7 +37049,7 @@ function useExportPdf() {
|
|
|
36960
37049
|
},
|
|
36961
37050
|
[]
|
|
36962
37051
|
);
|
|
36963
|
-
const wrappedExportMarkdown =
|
|
37052
|
+
const wrappedExportMarkdown = useCallback8(
|
|
36964
37053
|
async (markdown, options) => {
|
|
36965
37054
|
setIsExporting(true);
|
|
36966
37055
|
setError(null);
|
|
@@ -36980,21 +37069,21 @@ function useExportPdf() {
|
|
|
36980
37069
|
},
|
|
36981
37070
|
[]
|
|
36982
37071
|
);
|
|
36983
|
-
const downloadElementAsPdf =
|
|
37072
|
+
const downloadElementAsPdf = useCallback8(
|
|
36984
37073
|
async (element, options) => {
|
|
36985
37074
|
const blob = await wrappedExportElement(element, options);
|
|
36986
37075
|
triggerDownload(blob, options?.filename ?? DEFAULT_FILENAME2);
|
|
36987
37076
|
},
|
|
36988
37077
|
[wrappedExportElement]
|
|
36989
37078
|
);
|
|
36990
|
-
const downloadMarkdownAsPdf =
|
|
37079
|
+
const downloadMarkdownAsPdf = useCallback8(
|
|
36991
37080
|
async (markdown, options) => {
|
|
36992
37081
|
const blob = await wrappedExportMarkdown(markdown, options);
|
|
36993
37082
|
triggerDownload(blob, options?.filename ?? DEFAULT_FILENAME2);
|
|
36994
37083
|
},
|
|
36995
37084
|
[wrappedExportMarkdown]
|
|
36996
37085
|
);
|
|
36997
|
-
const wrappedRenderToCanvas =
|
|
37086
|
+
const wrappedRenderToCanvas = useCallback8(
|
|
36998
37087
|
async (element) => {
|
|
36999
37088
|
setIsExporting(true);
|
|
37000
37089
|
setError(null);
|
|
@@ -37026,19 +37115,19 @@ function useExportPdf() {
|
|
|
37026
37115
|
|
|
37027
37116
|
// src/react/useFiles.ts
|
|
37028
37117
|
import { Q as Q19 } from "@nozbe/watermelondb";
|
|
37029
|
-
import { useCallback as
|
|
37118
|
+
import { useCallback as useCallback9, useEffect as useEffect7, useMemo as useMemo6, useState as useState8 } from "react";
|
|
37030
37119
|
function useFiles(options) {
|
|
37031
37120
|
const { database, walletAddress } = options;
|
|
37032
37121
|
const [isLoading, setIsLoading] = useState8(false);
|
|
37033
37122
|
const [isReady, setIsReady] = useState8(false);
|
|
37034
37123
|
const [mediaCollection, setMediaCollection] = useState8(null);
|
|
37035
37124
|
const blobUrlManager = useMemo6(() => new BlobUrlManager(), []);
|
|
37036
|
-
|
|
37125
|
+
useEffect7(() => {
|
|
37037
37126
|
return () => {
|
|
37038
37127
|
blobUrlManager.revokeAll();
|
|
37039
37128
|
};
|
|
37040
37129
|
}, [blobUrlManager]);
|
|
37041
|
-
|
|
37130
|
+
useEffect7(() => {
|
|
37042
37131
|
const initCollection = async () => {
|
|
37043
37132
|
setIsLoading(true);
|
|
37044
37133
|
try {
|
|
@@ -37061,7 +37150,7 @@ function useFiles(options) {
|
|
|
37061
37150
|
}
|
|
37062
37151
|
return { database, walletAddress };
|
|
37063
37152
|
}, [database, mediaCollection, isReady, walletAddress]);
|
|
37064
|
-
const createMedia =
|
|
37153
|
+
const createMedia = useCallback9(
|
|
37065
37154
|
async (createOptions) => {
|
|
37066
37155
|
if (!ctx) {
|
|
37067
37156
|
throw new Error("Files not available. Database may need to be initialized.");
|
|
@@ -37070,7 +37159,7 @@ function useFiles(options) {
|
|
|
37070
37159
|
},
|
|
37071
37160
|
[ctx]
|
|
37072
37161
|
);
|
|
37073
|
-
const createMediaBatch =
|
|
37162
|
+
const createMediaBatch = useCallback9(
|
|
37074
37163
|
async (optionsArray) => {
|
|
37075
37164
|
if (!ctx) {
|
|
37076
37165
|
throw new Error("Files not available. Database may need to be initialized.");
|
|
@@ -37079,7 +37168,7 @@ function useFiles(options) {
|
|
|
37079
37168
|
},
|
|
37080
37169
|
[ctx]
|
|
37081
37170
|
);
|
|
37082
|
-
const getMediaById =
|
|
37171
|
+
const getMediaById = useCallback9(
|
|
37083
37172
|
async (mediaId) => {
|
|
37084
37173
|
if (!ctx) {
|
|
37085
37174
|
return null;
|
|
@@ -37088,7 +37177,7 @@ function useFiles(options) {
|
|
|
37088
37177
|
},
|
|
37089
37178
|
[ctx]
|
|
37090
37179
|
);
|
|
37091
|
-
const getMediaBySourceUrl =
|
|
37180
|
+
const getMediaBySourceUrl = useCallback9(
|
|
37092
37181
|
async (sourceUrl) => {
|
|
37093
37182
|
if (!ctx || !walletAddress) {
|
|
37094
37183
|
return null;
|
|
@@ -37097,7 +37186,7 @@ function useFiles(options) {
|
|
|
37097
37186
|
},
|
|
37098
37187
|
[ctx, walletAddress]
|
|
37099
37188
|
);
|
|
37100
|
-
const getMediaByIds =
|
|
37189
|
+
const getMediaByIds = useCallback9(
|
|
37101
37190
|
async (mediaIds, includeDeleted = false) => {
|
|
37102
37191
|
if (!ctx) {
|
|
37103
37192
|
return [];
|
|
@@ -37106,7 +37195,7 @@ function useFiles(options) {
|
|
|
37106
37195
|
},
|
|
37107
37196
|
[ctx]
|
|
37108
37197
|
);
|
|
37109
|
-
const getMediaByMessage =
|
|
37198
|
+
const getMediaByMessage = useCallback9(
|
|
37110
37199
|
async (messageId) => {
|
|
37111
37200
|
if (!ctx) {
|
|
37112
37201
|
return [];
|
|
@@ -37115,7 +37204,7 @@ function useFiles(options) {
|
|
|
37115
37204
|
},
|
|
37116
37205
|
[ctx]
|
|
37117
37206
|
);
|
|
37118
|
-
const updateMedia =
|
|
37207
|
+
const updateMedia = useCallback9(
|
|
37119
37208
|
async (mediaId, updateOptions) => {
|
|
37120
37209
|
if (!ctx) {
|
|
37121
37210
|
return null;
|
|
@@ -37124,7 +37213,7 @@ function useFiles(options) {
|
|
|
37124
37213
|
},
|
|
37125
37214
|
[ctx]
|
|
37126
37215
|
);
|
|
37127
|
-
const updateMediaMessageIdBatch =
|
|
37216
|
+
const updateMediaMessageIdBatch = useCallback9(
|
|
37128
37217
|
async (mediaIds, messageId) => {
|
|
37129
37218
|
if (!ctx) {
|
|
37130
37219
|
return 0;
|
|
@@ -37133,13 +37222,13 @@ function useFiles(options) {
|
|
|
37133
37222
|
},
|
|
37134
37223
|
[ctx]
|
|
37135
37224
|
);
|
|
37136
|
-
const relinkMisclassifiedVideos =
|
|
37225
|
+
const relinkMisclassifiedVideos = useCallback9(async () => {
|
|
37137
37226
|
if (!ctx || !walletAddress) {
|
|
37138
37227
|
return 0;
|
|
37139
37228
|
}
|
|
37140
37229
|
return relinkMisclassifiedVideosOp(ctx, walletAddress);
|
|
37141
37230
|
}, [ctx, walletAddress]);
|
|
37142
|
-
const deleteMedia =
|
|
37231
|
+
const deleteMedia = useCallback9(
|
|
37143
37232
|
async (mediaId) => {
|
|
37144
37233
|
if (!ctx) {
|
|
37145
37234
|
return false;
|
|
@@ -37150,7 +37239,7 @@ function useFiles(options) {
|
|
|
37150
37239
|
},
|
|
37151
37240
|
[ctx, blobUrlManager]
|
|
37152
37241
|
);
|
|
37153
|
-
const hardDeleteMedia =
|
|
37242
|
+
const hardDeleteMedia = useCallback9(
|
|
37154
37243
|
async (mediaId) => {
|
|
37155
37244
|
if (!ctx) {
|
|
37156
37245
|
return false;
|
|
@@ -37161,7 +37250,7 @@ function useFiles(options) {
|
|
|
37161
37250
|
},
|
|
37162
37251
|
[ctx, blobUrlManager]
|
|
37163
37252
|
);
|
|
37164
|
-
const getMedia =
|
|
37253
|
+
const getMedia = useCallback9(
|
|
37165
37254
|
async (filters) => {
|
|
37166
37255
|
if (!ctx) {
|
|
37167
37256
|
return [];
|
|
@@ -37170,7 +37259,7 @@ function useFiles(options) {
|
|
|
37170
37259
|
},
|
|
37171
37260
|
[ctx]
|
|
37172
37261
|
);
|
|
37173
|
-
const getMediaByType =
|
|
37262
|
+
const getMediaByType = useCallback9(
|
|
37174
37263
|
async (mediaType, limit) => {
|
|
37175
37264
|
if (!ctx || !walletAddress) {
|
|
37176
37265
|
return [];
|
|
@@ -37179,7 +37268,7 @@ function useFiles(options) {
|
|
|
37179
37268
|
},
|
|
37180
37269
|
[ctx, walletAddress]
|
|
37181
37270
|
);
|
|
37182
|
-
const getImages =
|
|
37271
|
+
const getImages = useCallback9(
|
|
37183
37272
|
async (limit) => {
|
|
37184
37273
|
if (!ctx || !walletAddress) {
|
|
37185
37274
|
return [];
|
|
@@ -37188,7 +37277,7 @@ function useFiles(options) {
|
|
|
37188
37277
|
},
|
|
37189
37278
|
[ctx, walletAddress]
|
|
37190
37279
|
);
|
|
37191
|
-
const getVideos =
|
|
37280
|
+
const getVideos = useCallback9(
|
|
37192
37281
|
async (limit) => {
|
|
37193
37282
|
if (!ctx || !walletAddress) {
|
|
37194
37283
|
return [];
|
|
@@ -37197,7 +37286,7 @@ function useFiles(options) {
|
|
|
37197
37286
|
},
|
|
37198
37287
|
[ctx, walletAddress]
|
|
37199
37288
|
);
|
|
37200
|
-
const getAudio =
|
|
37289
|
+
const getAudio = useCallback9(
|
|
37201
37290
|
async (limit) => {
|
|
37202
37291
|
if (!ctx || !walletAddress) {
|
|
37203
37292
|
return [];
|
|
@@ -37206,7 +37295,7 @@ function useFiles(options) {
|
|
|
37206
37295
|
},
|
|
37207
37296
|
[ctx, walletAddress]
|
|
37208
37297
|
);
|
|
37209
|
-
const getDocuments =
|
|
37298
|
+
const getDocuments = useCallback9(
|
|
37210
37299
|
async (limit) => {
|
|
37211
37300
|
if (!ctx || !walletAddress) {
|
|
37212
37301
|
return [];
|
|
@@ -37215,7 +37304,7 @@ function useFiles(options) {
|
|
|
37215
37304
|
},
|
|
37216
37305
|
[ctx, walletAddress]
|
|
37217
37306
|
);
|
|
37218
|
-
const getMediaByConversation =
|
|
37307
|
+
const getMediaByConversation = useCallback9(
|
|
37219
37308
|
async (conversationId, limit) => {
|
|
37220
37309
|
if (!ctx || !walletAddress) {
|
|
37221
37310
|
return [];
|
|
@@ -37224,7 +37313,7 @@ function useFiles(options) {
|
|
|
37224
37313
|
},
|
|
37225
37314
|
[ctx, walletAddress]
|
|
37226
37315
|
);
|
|
37227
|
-
const getMediaByRole =
|
|
37316
|
+
const getMediaByRole = useCallback9(
|
|
37228
37317
|
async (role, limit) => {
|
|
37229
37318
|
if (!ctx || !walletAddress) {
|
|
37230
37319
|
return [];
|
|
@@ -37233,7 +37322,7 @@ function useFiles(options) {
|
|
|
37233
37322
|
},
|
|
37234
37323
|
[ctx, walletAddress]
|
|
37235
37324
|
);
|
|
37236
|
-
const getAIGeneratedMedia =
|
|
37325
|
+
const getAIGeneratedMedia = useCallback9(
|
|
37237
37326
|
async (limit) => {
|
|
37238
37327
|
if (!ctx || !walletAddress) {
|
|
37239
37328
|
return [];
|
|
@@ -37242,7 +37331,7 @@ function useFiles(options) {
|
|
|
37242
37331
|
},
|
|
37243
37332
|
[ctx, walletAddress]
|
|
37244
37333
|
);
|
|
37245
|
-
const getUserUploadedMedia =
|
|
37334
|
+
const getUserUploadedMedia = useCallback9(
|
|
37246
37335
|
async (limit) => {
|
|
37247
37336
|
if (!ctx || !walletAddress) {
|
|
37248
37337
|
return [];
|
|
@@ -37251,7 +37340,7 @@ function useFiles(options) {
|
|
|
37251
37340
|
},
|
|
37252
37341
|
[ctx, walletAddress]
|
|
37253
37342
|
);
|
|
37254
|
-
const getMediaByModel =
|
|
37343
|
+
const getMediaByModel = useCallback9(
|
|
37255
37344
|
async (model, limit) => {
|
|
37256
37345
|
if (!ctx || !walletAddress) {
|
|
37257
37346
|
return [];
|
|
@@ -37260,7 +37349,7 @@ function useFiles(options) {
|
|
|
37260
37349
|
},
|
|
37261
37350
|
[ctx, walletAddress]
|
|
37262
37351
|
);
|
|
37263
|
-
const getRecentMedia =
|
|
37352
|
+
const getRecentMedia = useCallback9(
|
|
37264
37353
|
async (limit = 20) => {
|
|
37265
37354
|
if (!ctx || !walletAddress) {
|
|
37266
37355
|
return [];
|
|
@@ -37269,7 +37358,7 @@ function useFiles(options) {
|
|
|
37269
37358
|
},
|
|
37270
37359
|
[ctx, walletAddress]
|
|
37271
37360
|
);
|
|
37272
|
-
const searchMedia =
|
|
37361
|
+
const searchMedia = useCallback9(
|
|
37273
37362
|
async (query, limit) => {
|
|
37274
37363
|
if (!ctx || !walletAddress) {
|
|
37275
37364
|
return [];
|
|
@@ -37278,7 +37367,7 @@ function useFiles(options) {
|
|
|
37278
37367
|
},
|
|
37279
37368
|
[ctx, walletAddress]
|
|
37280
37369
|
);
|
|
37281
|
-
const getMediaCount =
|
|
37370
|
+
const getMediaCount = useCallback9(
|
|
37282
37371
|
async (mediaType) => {
|
|
37283
37372
|
if (!ctx || !walletAddress) {
|
|
37284
37373
|
return 0;
|
|
@@ -37287,13 +37376,13 @@ function useFiles(options) {
|
|
|
37287
37376
|
},
|
|
37288
37377
|
[ctx, walletAddress]
|
|
37289
37378
|
);
|
|
37290
|
-
const getMediaCountsByType =
|
|
37379
|
+
const getMediaCountsByType = useCallback9(async () => {
|
|
37291
37380
|
if (!ctx || !walletAddress) {
|
|
37292
37381
|
return { image: 0, video: 0, audio: 0, document: 0 };
|
|
37293
37382
|
}
|
|
37294
37383
|
return getMediaCountsByTypeOp(ctx, walletAddress);
|
|
37295
37384
|
}, [ctx, walletAddress]);
|
|
37296
|
-
const deleteMediaByConversation =
|
|
37385
|
+
const deleteMediaByConversation = useCallback9(
|
|
37297
37386
|
async (conversationId) => {
|
|
37298
37387
|
if (!ctx) {
|
|
37299
37388
|
return 0;
|
|
@@ -37302,7 +37391,7 @@ function useFiles(options) {
|
|
|
37302
37391
|
},
|
|
37303
37392
|
[ctx]
|
|
37304
37393
|
);
|
|
37305
|
-
const deleteMediaByMessage =
|
|
37394
|
+
const deleteMediaByMessage = useCallback9(
|
|
37306
37395
|
async (messageId) => {
|
|
37307
37396
|
if (!ctx) {
|
|
37308
37397
|
return 0;
|
|
@@ -37311,7 +37400,7 @@ function useFiles(options) {
|
|
|
37311
37400
|
},
|
|
37312
37401
|
[ctx]
|
|
37313
37402
|
);
|
|
37314
|
-
const readFile =
|
|
37403
|
+
const readFile = useCallback9(
|
|
37315
37404
|
async (mediaId) => {
|
|
37316
37405
|
if (!isOPFSSupported()) {
|
|
37317
37406
|
throw new Error("OPFS is not supported in this browser.");
|
|
@@ -37367,7 +37456,7 @@ function useFiles(options) {
|
|
|
37367
37456
|
},
|
|
37368
37457
|
[walletAddress]
|
|
37369
37458
|
);
|
|
37370
|
-
const createBlobUrl =
|
|
37459
|
+
const createBlobUrl = useCallback9(
|
|
37371
37460
|
async (mediaId) => {
|
|
37372
37461
|
const existingUrl = blobUrlManager.getUrl(mediaId);
|
|
37373
37462
|
if (existingUrl) {
|
|
@@ -37383,16 +37472,16 @@ function useFiles(options) {
|
|
|
37383
37472
|
},
|
|
37384
37473
|
[readFile, blobUrlManager]
|
|
37385
37474
|
);
|
|
37386
|
-
const revokeBlobUrl =
|
|
37475
|
+
const revokeBlobUrl = useCallback9(
|
|
37387
37476
|
(mediaId) => {
|
|
37388
37477
|
blobUrlManager.revokeUrl(mediaId);
|
|
37389
37478
|
},
|
|
37390
37479
|
[blobUrlManager]
|
|
37391
37480
|
);
|
|
37392
|
-
const revokeAllBlobUrls =
|
|
37481
|
+
const revokeAllBlobUrls = useCallback9(() => {
|
|
37393
37482
|
blobUrlManager.revokeAll();
|
|
37394
37483
|
}, [blobUrlManager]);
|
|
37395
|
-
const resolveFilePlaceholders2 =
|
|
37484
|
+
const resolveFilePlaceholders2 = useCallback9(
|
|
37396
37485
|
async (content) => {
|
|
37397
37486
|
if (!walletAddress || !hasEncryptionKey(walletAddress)) {
|
|
37398
37487
|
return content;
|
|
@@ -37450,9 +37539,9 @@ function useFiles(options) {
|
|
|
37450
37539
|
import {
|
|
37451
37540
|
createContext as createContext4,
|
|
37452
37541
|
createElement as createElement3,
|
|
37453
|
-
useCallback as
|
|
37542
|
+
useCallback as useCallback10,
|
|
37454
37543
|
useContext as useContext4,
|
|
37455
|
-
useEffect as
|
|
37544
|
+
useEffect as useEffect8,
|
|
37456
37545
|
useState as useState9
|
|
37457
37546
|
} from "react";
|
|
37458
37547
|
var ICloudAuthContext = createContext4(null);
|
|
@@ -37467,7 +37556,7 @@ function ICloudAuthProvider({
|
|
|
37467
37556
|
const [isAvailable, setIsAvailable] = useState9(false);
|
|
37468
37557
|
const [isConfigured, setIsConfigured] = useState9(false);
|
|
37469
37558
|
const [_isLoading, setIsLoading] = useState9(false);
|
|
37470
|
-
|
|
37559
|
+
useEffect8(() => {
|
|
37471
37560
|
if (!apiToken || typeof window === "undefined") {
|
|
37472
37561
|
return;
|
|
37473
37562
|
}
|
|
@@ -37500,7 +37589,7 @@ function ICloudAuthProvider({
|
|
|
37500
37589
|
};
|
|
37501
37590
|
void initCloudKit();
|
|
37502
37591
|
}, [apiToken, containerIdentifier, environment]);
|
|
37503
|
-
const requestAccess =
|
|
37592
|
+
const requestAccess = useCallback10(async () => {
|
|
37504
37593
|
if (!isConfigured) {
|
|
37505
37594
|
throw new Error("iCloud is not configured");
|
|
37506
37595
|
}
|
|
@@ -37515,7 +37604,7 @@ function ICloudAuthProvider({
|
|
|
37515
37604
|
throw new Error(err instanceof Error ? err.message : "Failed to sign in to iCloud");
|
|
37516
37605
|
}
|
|
37517
37606
|
}, [isAuthenticated, isConfigured]);
|
|
37518
|
-
const logout =
|
|
37607
|
+
const logout = useCallback10(() => {
|
|
37519
37608
|
setIsAuthenticated(false);
|
|
37520
37609
|
setUserRecordName(null);
|
|
37521
37610
|
}, []);
|
|
@@ -37548,7 +37637,7 @@ function clearICloudAuth() {
|
|
|
37548
37637
|
}
|
|
37549
37638
|
|
|
37550
37639
|
// src/react/useICloudBackup.ts
|
|
37551
|
-
import { useCallback as
|
|
37640
|
+
import { useCallback as useCallback11, useMemo as useMemo7 } from "react";
|
|
37552
37641
|
function useICloudBackup(options) {
|
|
37553
37642
|
const { database, userAddress, requestEncryptionKey: requestEncryptionKey2, exportConversation, importConversation } = options;
|
|
37554
37643
|
const { isAuthenticated, isConfigured, isAvailable, requestAccess } = useICloudAuth();
|
|
@@ -37561,7 +37650,7 @@ function useICloudBackup(options) {
|
|
|
37561
37650
|
}),
|
|
37562
37651
|
[requestAccess, requestEncryptionKey2, exportConversation, importConversation]
|
|
37563
37652
|
);
|
|
37564
|
-
const ensureAuthenticated =
|
|
37653
|
+
const ensureAuthenticated = useCallback11(async () => {
|
|
37565
37654
|
if (isAuthenticated) return true;
|
|
37566
37655
|
try {
|
|
37567
37656
|
await requestAccess();
|
|
@@ -37570,7 +37659,7 @@ function useICloudBackup(options) {
|
|
|
37570
37659
|
return false;
|
|
37571
37660
|
}
|
|
37572
37661
|
}, [isAuthenticated, requestAccess]);
|
|
37573
|
-
const backup =
|
|
37662
|
+
const backup = useCallback11(
|
|
37574
37663
|
async (backupOptions) => {
|
|
37575
37664
|
if (!userAddress) {
|
|
37576
37665
|
return { error: "Please sign in to backup to iCloud" };
|
|
@@ -37595,7 +37684,7 @@ function useICloudBackup(options) {
|
|
|
37595
37684
|
},
|
|
37596
37685
|
[database, userAddress, isAvailable, isConfigured, ensureAuthenticated, deps]
|
|
37597
37686
|
);
|
|
37598
|
-
const restore =
|
|
37687
|
+
const restore = useCallback11(
|
|
37599
37688
|
async (restoreOptions) => {
|
|
37600
37689
|
if (!userAddress) {
|
|
37601
37690
|
return { error: "Please sign in to restore from iCloud" };
|
|
@@ -37630,7 +37719,7 @@ function useICloudBackup(options) {
|
|
|
37630
37719
|
}
|
|
37631
37720
|
|
|
37632
37721
|
// src/react/useModels.ts
|
|
37633
|
-
import { useCallback as
|
|
37722
|
+
import { useCallback as useCallback12, useEffect as useEffect9, useRef as useRef6, useState as useState10 } from "react";
|
|
37634
37723
|
var MODELS_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
37635
37724
|
var modelsCache = /* @__PURE__ */ new Map();
|
|
37636
37725
|
var modelsInFlight = /* @__PURE__ */ new Map();
|
|
@@ -37762,12 +37851,12 @@ function useModels(options = {}) {
|
|
|
37762
37851
|
const baseUrlRef = useRef6(baseUrl);
|
|
37763
37852
|
const providerRef = useRef6(provider);
|
|
37764
37853
|
const abortControllerRef = useRef6(null);
|
|
37765
|
-
|
|
37854
|
+
useEffect9(() => {
|
|
37766
37855
|
getTokenRef.current = getToken;
|
|
37767
37856
|
baseUrlRef.current = baseUrl;
|
|
37768
37857
|
providerRef.current = provider;
|
|
37769
37858
|
});
|
|
37770
|
-
|
|
37859
|
+
useEffect9(() => {
|
|
37771
37860
|
return () => {
|
|
37772
37861
|
if (abortControllerRef.current) {
|
|
37773
37862
|
abortControllerRef.current.abort();
|
|
@@ -37775,7 +37864,7 @@ function useModels(options = {}) {
|
|
|
37775
37864
|
}
|
|
37776
37865
|
};
|
|
37777
37866
|
}, []);
|
|
37778
|
-
const fetchModels =
|
|
37867
|
+
const fetchModels = useCallback12(async (force = false) => {
|
|
37779
37868
|
if (abortControllerRef.current) {
|
|
37780
37869
|
abortControllerRef.current.abort();
|
|
37781
37870
|
}
|
|
@@ -37815,12 +37904,12 @@ function useModels(options = {}) {
|
|
|
37815
37904
|
}
|
|
37816
37905
|
}
|
|
37817
37906
|
}, []);
|
|
37818
|
-
const refetch =
|
|
37907
|
+
const refetch = useCallback12(async () => {
|
|
37819
37908
|
setModels([]);
|
|
37820
37909
|
await fetchModels(true);
|
|
37821
37910
|
}, [fetchModels]);
|
|
37822
37911
|
const hasFetchedRef = useRef6(false);
|
|
37823
|
-
|
|
37912
|
+
useEffect9(() => {
|
|
37824
37913
|
if (autoFetch && !hasFetchedRef.current) {
|
|
37825
37914
|
hasFetchedRef.current = true;
|
|
37826
37915
|
void fetchModels();
|
|
@@ -37838,12 +37927,12 @@ function useModels(options = {}) {
|
|
|
37838
37927
|
}
|
|
37839
37928
|
|
|
37840
37929
|
// src/react/useOCR.ts
|
|
37841
|
-
import { useCallback as
|
|
37930
|
+
import { useCallback as useCallback13, useState as useState11 } from "react";
|
|
37842
37931
|
import Tesseract from "tesseract.js";
|
|
37843
37932
|
function useOCR() {
|
|
37844
37933
|
const [isProcessing, setIsProcessing] = useState11(false);
|
|
37845
37934
|
const [error, setError] = useState11(null);
|
|
37846
|
-
const extractOCRContext =
|
|
37935
|
+
const extractOCRContext = useCallback13(async (files) => {
|
|
37847
37936
|
setIsProcessing(true);
|
|
37848
37937
|
setError(null);
|
|
37849
37938
|
try {
|
|
@@ -37921,12 +38010,12 @@ ${text16}`;
|
|
|
37921
38010
|
}
|
|
37922
38011
|
|
|
37923
38012
|
// src/react/usePdf.ts
|
|
37924
|
-
import { useCallback as
|
|
38013
|
+
import { useCallback as useCallback14, useState as useState12 } from "react";
|
|
37925
38014
|
var PDF_MIME_TYPE = "application/pdf";
|
|
37926
38015
|
function usePdf() {
|
|
37927
38016
|
const [isProcessing, setIsProcessing] = useState12(false);
|
|
37928
38017
|
const [error, setError] = useState12(null);
|
|
37929
|
-
const extractPdfContext =
|
|
38018
|
+
const extractPdfContext = useCallback14(async (files) => {
|
|
37930
38019
|
setIsProcessing(true);
|
|
37931
38020
|
setError(null);
|
|
37932
38021
|
try {
|
|
@@ -37970,7 +38059,7 @@ ${text16}`;
|
|
|
37970
38059
|
}
|
|
37971
38060
|
|
|
37972
38061
|
// src/react/usePhoneCalls.ts
|
|
37973
|
-
import { useCallback as
|
|
38062
|
+
import { useCallback as useCallback15, useEffect as useEffect10, useRef as useRef7, useState as useState13 } from "react";
|
|
37974
38063
|
var DEFAULT_POLL_INTERVAL_MS = 5e3;
|
|
37975
38064
|
var DEFAULT_POLL_MAX_ATTEMPTS = 60;
|
|
37976
38065
|
var TERMINAL_SUCCESS_STATUSES = /* @__PURE__ */ new Set(["complete", "completed"]);
|
|
@@ -38013,12 +38102,12 @@ function usePhoneCalls(options = {}) {
|
|
|
38013
38102
|
const requestAbortControllerRef = useRef7(null);
|
|
38014
38103
|
const pollAbortControllerRef = useRef7(null);
|
|
38015
38104
|
const pollRunIdRef = useRef7(0);
|
|
38016
|
-
|
|
38105
|
+
useEffect10(() => {
|
|
38017
38106
|
getTokenRef.current = getToken;
|
|
38018
38107
|
baseUrlRef.current = baseUrl;
|
|
38019
38108
|
onErrorRef.current = onError;
|
|
38020
38109
|
});
|
|
38021
|
-
const stopPolling =
|
|
38110
|
+
const stopPolling = useCallback15(() => {
|
|
38022
38111
|
pollRunIdRef.current += 1;
|
|
38023
38112
|
if (pollAbortControllerRef.current) {
|
|
38024
38113
|
pollAbortControllerRef.current.abort();
|
|
@@ -38026,7 +38115,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38026
38115
|
}
|
|
38027
38116
|
setIsPolling(false);
|
|
38028
38117
|
}, []);
|
|
38029
|
-
|
|
38118
|
+
useEffect10(() => {
|
|
38030
38119
|
return () => {
|
|
38031
38120
|
if (requestAbortControllerRef.current) {
|
|
38032
38121
|
requestAbortControllerRef.current.abort();
|
|
@@ -38039,21 +38128,21 @@ function usePhoneCalls(options = {}) {
|
|
|
38039
38128
|
}
|
|
38040
38129
|
};
|
|
38041
38130
|
}, []);
|
|
38042
|
-
const startLoading =
|
|
38131
|
+
const startLoading = useCallback15(() => {
|
|
38043
38132
|
loadingCountRef.current += 1;
|
|
38044
38133
|
setIsLoading(true);
|
|
38045
38134
|
}, []);
|
|
38046
|
-
const stopLoading =
|
|
38135
|
+
const stopLoading = useCallback15(() => {
|
|
38047
38136
|
loadingCountRef.current = Math.max(0, loadingCountRef.current - 1);
|
|
38048
38137
|
setIsLoading(loadingCountRef.current > 0);
|
|
38049
38138
|
}, []);
|
|
38050
|
-
const handleError =
|
|
38139
|
+
const handleError = useCallback15((err) => {
|
|
38051
38140
|
const nextError = err instanceof Error ? err : new Error(String(err));
|
|
38052
38141
|
setError(nextError);
|
|
38053
38142
|
onErrorRef.current?.(nextError);
|
|
38054
38143
|
return nextError;
|
|
38055
38144
|
}, []);
|
|
38056
|
-
const getHeaders =
|
|
38145
|
+
const getHeaders = useCallback15(async () => {
|
|
38057
38146
|
const headers = {};
|
|
38058
38147
|
if (getTokenRef.current) {
|
|
38059
38148
|
const token = await getTokenRef.current();
|
|
@@ -38063,7 +38152,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38063
38152
|
}
|
|
38064
38153
|
return headers;
|
|
38065
38154
|
}, []);
|
|
38066
|
-
const fetchAvailability =
|
|
38155
|
+
const fetchAvailability = useCallback15(async () => {
|
|
38067
38156
|
if (requestAbortControllerRef.current) {
|
|
38068
38157
|
requestAbortControllerRef.current.abort();
|
|
38069
38158
|
}
|
|
@@ -38101,7 +38190,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38101
38190
|
}
|
|
38102
38191
|
}
|
|
38103
38192
|
}, [getHeaders, handleError, startLoading, stopLoading]);
|
|
38104
|
-
const createPhoneCall =
|
|
38193
|
+
const createPhoneCall = useCallback15(
|
|
38105
38194
|
async (request) => {
|
|
38106
38195
|
startLoading();
|
|
38107
38196
|
setError(null);
|
|
@@ -38128,7 +38217,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38128
38217
|
},
|
|
38129
38218
|
[getHeaders, handleError, startLoading, stopLoading]
|
|
38130
38219
|
);
|
|
38131
|
-
const getPhoneCall =
|
|
38220
|
+
const getPhoneCall = useCallback15(
|
|
38132
38221
|
async (callId) => {
|
|
38133
38222
|
const trimmedCallId = callId.trim();
|
|
38134
38223
|
if (!trimmedCallId) {
|
|
@@ -38177,7 +38266,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38177
38266
|
},
|
|
38178
38267
|
[getHeaders, handleError, startLoading, stopLoading]
|
|
38179
38268
|
);
|
|
38180
|
-
const pollPhoneCall =
|
|
38269
|
+
const pollPhoneCall = useCallback15(
|
|
38181
38270
|
async (callId, pollOptions = {}) => {
|
|
38182
38271
|
const trimmedCallId = callId.trim();
|
|
38183
38272
|
if (!trimmedCallId) {
|
|
@@ -38242,11 +38331,11 @@ function usePhoneCalls(options = {}) {
|
|
|
38242
38331
|
},
|
|
38243
38332
|
[getHeaders, handleError, stopPolling]
|
|
38244
38333
|
);
|
|
38245
|
-
const reset =
|
|
38334
|
+
const reset = useCallback15(() => {
|
|
38246
38335
|
setCurrentCall(null);
|
|
38247
38336
|
setError(null);
|
|
38248
38337
|
}, []);
|
|
38249
|
-
|
|
38338
|
+
useEffect10(() => {
|
|
38250
38339
|
if (!autoFetchAvailability) {
|
|
38251
38340
|
return;
|
|
38252
38341
|
}
|
|
@@ -38269,7 +38358,7 @@ function usePhoneCalls(options = {}) {
|
|
|
38269
38358
|
|
|
38270
38359
|
// src/react/useProjects.ts
|
|
38271
38360
|
import { Q as Q20 } from "@nozbe/watermelondb";
|
|
38272
|
-
import { useCallback as
|
|
38361
|
+
import { useCallback as useCallback16, useEffect as useEffect11, useMemo as useMemo8, useState as useState14 } from "react";
|
|
38273
38362
|
function useProjects(options) {
|
|
38274
38363
|
const { database, initialProjectId } = options;
|
|
38275
38364
|
const [projects, setProjects] = useState14([]);
|
|
@@ -38279,7 +38368,7 @@ function useProjects(options) {
|
|
|
38279
38368
|
const [inboxProjectId, setInboxProjectId] = useState14(null);
|
|
38280
38369
|
const [projectsCollection, setProjectsCollection] = useState14(null);
|
|
38281
38370
|
const [conversationsCollection, setConversationsCollection] = useState14(null);
|
|
38282
|
-
|
|
38371
|
+
useEffect11(() => {
|
|
38283
38372
|
const initCollections = async () => {
|
|
38284
38373
|
getLogger().debug("[useProjects] Initializing collections...");
|
|
38285
38374
|
try {
|
|
@@ -38336,7 +38425,7 @@ function useProjects(options) {
|
|
|
38336
38425
|
return null;
|
|
38337
38426
|
}
|
|
38338
38427
|
}, [database, conversationsCollection, isReady]);
|
|
38339
|
-
const refreshProjects =
|
|
38428
|
+
const refreshProjects = useCallback16(async () => {
|
|
38340
38429
|
if (!projectCtx) {
|
|
38341
38430
|
return;
|
|
38342
38431
|
}
|
|
@@ -38350,12 +38439,12 @@ function useProjects(options) {
|
|
|
38350
38439
|
setIsLoading(false);
|
|
38351
38440
|
}
|
|
38352
38441
|
}, [projectCtx]);
|
|
38353
|
-
|
|
38442
|
+
useEffect11(() => {
|
|
38354
38443
|
if (isReady) {
|
|
38355
38444
|
void refreshProjects();
|
|
38356
38445
|
}
|
|
38357
38446
|
}, [isReady, refreshProjects]);
|
|
38358
|
-
|
|
38447
|
+
useEffect11(() => {
|
|
38359
38448
|
const ensureInboxProject = async () => {
|
|
38360
38449
|
if (!projectCtx || !isReady) return;
|
|
38361
38450
|
try {
|
|
@@ -38373,7 +38462,7 @@ function useProjects(options) {
|
|
|
38373
38462
|
};
|
|
38374
38463
|
void ensureInboxProject();
|
|
38375
38464
|
}, [projectCtx, isReady]);
|
|
38376
|
-
|
|
38465
|
+
useEffect11(() => {
|
|
38377
38466
|
if (!projectsCollection) {
|
|
38378
38467
|
return;
|
|
38379
38468
|
}
|
|
@@ -38382,7 +38471,7 @@ function useProjects(options) {
|
|
|
38382
38471
|
});
|
|
38383
38472
|
return () => subscription.unsubscribe();
|
|
38384
38473
|
}, [projectsCollection]);
|
|
38385
|
-
const createProject =
|
|
38474
|
+
const createProject = useCallback16(
|
|
38386
38475
|
async (opts) => {
|
|
38387
38476
|
if (!projectCtx) {
|
|
38388
38477
|
throw new Error("Projects not available. Database schema may need to be updated.");
|
|
@@ -38392,7 +38481,7 @@ function useProjects(options) {
|
|
|
38392
38481
|
},
|
|
38393
38482
|
[projectCtx]
|
|
38394
38483
|
);
|
|
38395
|
-
const getProject =
|
|
38484
|
+
const getProject = useCallback16(
|
|
38396
38485
|
async (projectId) => {
|
|
38397
38486
|
if (!projectCtx) {
|
|
38398
38487
|
return null;
|
|
@@ -38401,13 +38490,13 @@ function useProjects(options) {
|
|
|
38401
38490
|
},
|
|
38402
38491
|
[projectCtx]
|
|
38403
38492
|
);
|
|
38404
|
-
const getProjects =
|
|
38493
|
+
const getProjects = useCallback16(async () => {
|
|
38405
38494
|
if (!projectCtx) {
|
|
38406
38495
|
return [];
|
|
38407
38496
|
}
|
|
38408
38497
|
return getProjectsOp(projectCtx);
|
|
38409
38498
|
}, [projectCtx]);
|
|
38410
|
-
const updateProjectName =
|
|
38499
|
+
const updateProjectName = useCallback16(
|
|
38411
38500
|
async (projectId, name) => {
|
|
38412
38501
|
if (!projectCtx) {
|
|
38413
38502
|
return false;
|
|
@@ -38416,7 +38505,7 @@ function useProjects(options) {
|
|
|
38416
38505
|
},
|
|
38417
38506
|
[projectCtx]
|
|
38418
38507
|
);
|
|
38419
|
-
const updateProject =
|
|
38508
|
+
const updateProject = useCallback16(
|
|
38420
38509
|
async (projectId, opts) => {
|
|
38421
38510
|
if (!projectCtx) {
|
|
38422
38511
|
return false;
|
|
@@ -38425,7 +38514,7 @@ function useProjects(options) {
|
|
|
38425
38514
|
},
|
|
38426
38515
|
[projectCtx]
|
|
38427
38516
|
);
|
|
38428
|
-
const deleteProject =
|
|
38517
|
+
const deleteProject = useCallback16(
|
|
38429
38518
|
async (projectId) => {
|
|
38430
38519
|
if (!projectCtx) {
|
|
38431
38520
|
return false;
|
|
@@ -38438,7 +38527,7 @@ function useProjects(options) {
|
|
|
38438
38527
|
},
|
|
38439
38528
|
[projectCtx, currentProjectId]
|
|
38440
38529
|
);
|
|
38441
|
-
const getProjectConversations =
|
|
38530
|
+
const getProjectConversations = useCallback16(
|
|
38442
38531
|
async (projectId) => {
|
|
38443
38532
|
if (!projectCtx) {
|
|
38444
38533
|
return [];
|
|
@@ -38447,7 +38536,7 @@ function useProjects(options) {
|
|
|
38447
38536
|
},
|
|
38448
38537
|
[projectCtx]
|
|
38449
38538
|
);
|
|
38450
|
-
const getProjectConversationCount =
|
|
38539
|
+
const getProjectConversationCount = useCallback16(
|
|
38451
38540
|
async (projectId) => {
|
|
38452
38541
|
if (!projectCtx) {
|
|
38453
38542
|
return 0;
|
|
@@ -38456,7 +38545,7 @@ function useProjects(options) {
|
|
|
38456
38545
|
},
|
|
38457
38546
|
[projectCtx]
|
|
38458
38547
|
);
|
|
38459
|
-
const updateConversationProject =
|
|
38548
|
+
const updateConversationProject = useCallback16(
|
|
38460
38549
|
async (conversationId, projectId) => {
|
|
38461
38550
|
if (!storageCtx) {
|
|
38462
38551
|
return false;
|
|
@@ -38465,7 +38554,7 @@ function useProjects(options) {
|
|
|
38465
38554
|
},
|
|
38466
38555
|
[storageCtx]
|
|
38467
38556
|
);
|
|
38468
|
-
const getConversationsByProject =
|
|
38557
|
+
const getConversationsByProject = useCallback16(
|
|
38469
38558
|
async (projectId) => {
|
|
38470
38559
|
if (!storageCtx) {
|
|
38471
38560
|
return [];
|
|
@@ -38496,7 +38585,7 @@ function useProjects(options) {
|
|
|
38496
38585
|
}
|
|
38497
38586
|
|
|
38498
38587
|
// src/react/useSettings.ts
|
|
38499
|
-
import { useCallback as
|
|
38588
|
+
import { useCallback as useCallback17, useMemo as useMemo9, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
38500
38589
|
|
|
38501
38590
|
// src/react/userSettingsStore.ts
|
|
38502
38591
|
import { Q as Q21 } from "@nozbe/watermelondb";
|
|
@@ -38634,15 +38723,15 @@ function patchUserSettingsSnapshot(database, walletAddress, patch) {
|
|
|
38634
38723
|
var DB_NOT_READY = "Database not ready";
|
|
38635
38724
|
function useSettings(options) {
|
|
38636
38725
|
const { database, walletAddress } = options;
|
|
38637
|
-
const subscribe =
|
|
38726
|
+
const subscribe = useCallback17(
|
|
38638
38727
|
(listener) => subscribeUserSettings(database, walletAddress, listener),
|
|
38639
38728
|
[database, walletAddress]
|
|
38640
38729
|
);
|
|
38641
|
-
const getSnapshot =
|
|
38730
|
+
const getSnapshot = useCallback17(
|
|
38642
38731
|
() => getUserSettingsSnapshot(database, walletAddress),
|
|
38643
38732
|
[database, walletAddress]
|
|
38644
38733
|
);
|
|
38645
|
-
const snapshot =
|
|
38734
|
+
const snapshot = useSyncExternalStore2(subscribe, getSnapshot, getSnapshot);
|
|
38646
38735
|
const storageCtx = useMemo9(
|
|
38647
38736
|
() => database ? {
|
|
38648
38737
|
database,
|
|
@@ -38658,7 +38747,7 @@ function useSettings(options) {
|
|
|
38658
38747
|
} : null,
|
|
38659
38748
|
[database]
|
|
38660
38749
|
);
|
|
38661
|
-
const getModelPreference =
|
|
38750
|
+
const getModelPreference = useCallback17(
|
|
38662
38751
|
async (address) => {
|
|
38663
38752
|
try {
|
|
38664
38753
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38671,7 +38760,7 @@ function useSettings(options) {
|
|
|
38671
38760
|
},
|
|
38672
38761
|
[legacyStorageCtx]
|
|
38673
38762
|
);
|
|
38674
|
-
const setModelPreference =
|
|
38763
|
+
const setModelPreference = useCallback17(
|
|
38675
38764
|
async (address, models) => {
|
|
38676
38765
|
try {
|
|
38677
38766
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38687,7 +38776,7 @@ function useSettings(options) {
|
|
|
38687
38776
|
},
|
|
38688
38777
|
[database, legacyStorageCtx, walletAddress]
|
|
38689
38778
|
);
|
|
38690
|
-
const deleteModelPreference =
|
|
38779
|
+
const deleteModelPreference = useCallback17(
|
|
38691
38780
|
async (address) => {
|
|
38692
38781
|
try {
|
|
38693
38782
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38703,7 +38792,7 @@ function useSettings(options) {
|
|
|
38703
38792
|
},
|
|
38704
38793
|
[database, legacyStorageCtx, walletAddress]
|
|
38705
38794
|
);
|
|
38706
|
-
const getUserPreference =
|
|
38795
|
+
const getUserPreference = useCallback17(
|
|
38707
38796
|
async (address) => {
|
|
38708
38797
|
try {
|
|
38709
38798
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38716,7 +38805,7 @@ function useSettings(options) {
|
|
|
38716
38805
|
},
|
|
38717
38806
|
[storageCtx]
|
|
38718
38807
|
);
|
|
38719
|
-
const setUserPreference =
|
|
38808
|
+
const setUserPreference = useCallback17(
|
|
38720
38809
|
async (address, opts) => {
|
|
38721
38810
|
try {
|
|
38722
38811
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38732,7 +38821,7 @@ function useSettings(options) {
|
|
|
38732
38821
|
},
|
|
38733
38822
|
[database, storageCtx, walletAddress]
|
|
38734
38823
|
);
|
|
38735
|
-
const updateProfile =
|
|
38824
|
+
const updateProfile = useCallback17(
|
|
38736
38825
|
async (address, profile) => {
|
|
38737
38826
|
try {
|
|
38738
38827
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38748,7 +38837,7 @@ function useSettings(options) {
|
|
|
38748
38837
|
},
|
|
38749
38838
|
[database, storageCtx, walletAddress]
|
|
38750
38839
|
);
|
|
38751
|
-
const updatePersonality =
|
|
38840
|
+
const updatePersonality = useCallback17(
|
|
38752
38841
|
async (address, personality) => {
|
|
38753
38842
|
try {
|
|
38754
38843
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38764,7 +38853,7 @@ function useSettings(options) {
|
|
|
38764
38853
|
},
|
|
38765
38854
|
[database, storageCtx, walletAddress]
|
|
38766
38855
|
);
|
|
38767
|
-
const updateModels =
|
|
38856
|
+
const updateModels = useCallback17(
|
|
38768
38857
|
async (address, models) => {
|
|
38769
38858
|
try {
|
|
38770
38859
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38780,7 +38869,7 @@ function useSettings(options) {
|
|
|
38780
38869
|
},
|
|
38781
38870
|
[database, storageCtx, walletAddress]
|
|
38782
38871
|
);
|
|
38783
|
-
const deleteUserPreference =
|
|
38872
|
+
const deleteUserPreference = useCallback17(
|
|
38784
38873
|
async (address) => {
|
|
38785
38874
|
try {
|
|
38786
38875
|
if (!address) throw new Error("Wallet address is required");
|
|
@@ -38813,7 +38902,7 @@ function useSettings(options) {
|
|
|
38813
38902
|
}
|
|
38814
38903
|
|
|
38815
38904
|
// src/react/useSubscription.ts
|
|
38816
|
-
import { useCallback as
|
|
38905
|
+
import { useCallback as useCallback18, useEffect as useEffect12, useRef as useRef8, useState as useState15 } from "react";
|
|
38817
38906
|
function useSubscription(options = {}) {
|
|
38818
38907
|
const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
|
|
38819
38908
|
const [status, setStatus] = useState15(null);
|
|
@@ -38823,12 +38912,12 @@ function useSubscription(options = {}) {
|
|
|
38823
38912
|
const baseUrlRef = useRef8(baseUrl);
|
|
38824
38913
|
const onErrorRef = useRef8(onError);
|
|
38825
38914
|
const abortControllerRef = useRef8(null);
|
|
38826
|
-
|
|
38915
|
+
useEffect12(() => {
|
|
38827
38916
|
getTokenRef.current = getToken;
|
|
38828
38917
|
baseUrlRef.current = baseUrl;
|
|
38829
38918
|
onErrorRef.current = onError;
|
|
38830
38919
|
});
|
|
38831
|
-
|
|
38920
|
+
useEffect12(() => {
|
|
38832
38921
|
return () => {
|
|
38833
38922
|
if (abortControllerRef.current) {
|
|
38834
38923
|
abortControllerRef.current.abort();
|
|
@@ -38836,7 +38925,7 @@ function useSubscription(options = {}) {
|
|
|
38836
38925
|
}
|
|
38837
38926
|
};
|
|
38838
38927
|
}, []);
|
|
38839
|
-
const getHeaders =
|
|
38928
|
+
const getHeaders = useCallback18(async () => {
|
|
38840
38929
|
const headers = {};
|
|
38841
38930
|
if (getTokenRef.current) {
|
|
38842
38931
|
const token = await getTokenRef.current();
|
|
@@ -38846,13 +38935,13 @@ function useSubscription(options = {}) {
|
|
|
38846
38935
|
}
|
|
38847
38936
|
return headers;
|
|
38848
38937
|
}, []);
|
|
38849
|
-
const handleError =
|
|
38938
|
+
const handleError = useCallback18((err) => {
|
|
38850
38939
|
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
38851
38940
|
setError(error2);
|
|
38852
38941
|
onErrorRef.current?.(error2);
|
|
38853
38942
|
return error2;
|
|
38854
38943
|
}, []);
|
|
38855
|
-
const fetchStatus =
|
|
38944
|
+
const fetchStatus = useCallback18(async () => {
|
|
38856
38945
|
if (abortControllerRef.current) {
|
|
38857
38946
|
abortControllerRef.current.abort();
|
|
38858
38947
|
}
|
|
@@ -38889,11 +38978,11 @@ function useSubscription(options = {}) {
|
|
|
38889
38978
|
}
|
|
38890
38979
|
}
|
|
38891
38980
|
}, [getHeaders, handleError]);
|
|
38892
|
-
const refetch =
|
|
38981
|
+
const refetch = useCallback18(async () => {
|
|
38893
38982
|
setStatus(null);
|
|
38894
38983
|
await fetchStatus();
|
|
38895
38984
|
}, [fetchStatus]);
|
|
38896
|
-
const createCheckoutSession =
|
|
38985
|
+
const createCheckoutSession = useCallback18(
|
|
38897
38986
|
async (opts) => {
|
|
38898
38987
|
setIsLoading(true);
|
|
38899
38988
|
setError(null);
|
|
@@ -38923,7 +39012,7 @@ function useSubscription(options = {}) {
|
|
|
38923
39012
|
},
|
|
38924
39013
|
[getHeaders, handleError]
|
|
38925
39014
|
);
|
|
38926
|
-
const openCustomerPortal =
|
|
39015
|
+
const openCustomerPortal = useCallback18(
|
|
38927
39016
|
async (opts) => {
|
|
38928
39017
|
setIsLoading(true);
|
|
38929
39018
|
setError(null);
|
|
@@ -38950,7 +39039,7 @@ function useSubscription(options = {}) {
|
|
|
38950
39039
|
},
|
|
38951
39040
|
[getHeaders, handleError]
|
|
38952
39041
|
);
|
|
38953
|
-
const cancelSubscription =
|
|
39042
|
+
const cancelSubscription = useCallback18(async () => {
|
|
38954
39043
|
setIsLoading(true);
|
|
38955
39044
|
setError(null);
|
|
38956
39045
|
try {
|
|
@@ -38972,7 +39061,7 @@ function useSubscription(options = {}) {
|
|
|
38972
39061
|
setIsLoading(false);
|
|
38973
39062
|
}
|
|
38974
39063
|
}, [getHeaders, handleError, fetchStatus]);
|
|
38975
|
-
const renewSubscription =
|
|
39064
|
+
const renewSubscription = useCallback18(async () => {
|
|
38976
39065
|
setIsLoading(true);
|
|
38977
39066
|
setError(null);
|
|
38978
39067
|
try {
|
|
@@ -38995,7 +39084,7 @@ function useSubscription(options = {}) {
|
|
|
38995
39084
|
}
|
|
38996
39085
|
}, [getHeaders, handleError, fetchStatus]);
|
|
38997
39086
|
const hasFetchedRef = useRef8(false);
|
|
38998
|
-
|
|
39087
|
+
useEffect12(() => {
|
|
38999
39088
|
if (autoFetch && !hasFetchedRef.current) {
|
|
39000
39089
|
hasFetchedRef.current = true;
|
|
39001
39090
|
void fetchStatus();
|
|
@@ -39017,7 +39106,7 @@ function useSubscription(options = {}) {
|
|
|
39017
39106
|
}
|
|
39018
39107
|
|
|
39019
39108
|
// src/react/useTools.ts
|
|
39020
|
-
import { useCallback as
|
|
39109
|
+
import { useCallback as useCallback19, useEffect as useEffect13, useMemo as useMemo10, useRef as useRef9, useState as useState16 } from "react";
|
|
39021
39110
|
function useTools(options) {
|
|
39022
39111
|
const { getToken, baseUrl = BASE_URL, includeTools, autoFetch = true } = options;
|
|
39023
39112
|
const [allTools, setAllTools] = useState16([]);
|
|
@@ -39035,11 +39124,11 @@ function useTools(options) {
|
|
|
39035
39124
|
);
|
|
39036
39125
|
const getTokenRef = useRef9(getToken);
|
|
39037
39126
|
const baseUrlRef = useRef9(baseUrl);
|
|
39038
|
-
|
|
39127
|
+
useEffect13(() => {
|
|
39039
39128
|
getTokenRef.current = getToken;
|
|
39040
39129
|
baseUrlRef.current = baseUrl;
|
|
39041
39130
|
});
|
|
39042
|
-
const fetchTools =
|
|
39131
|
+
const fetchTools = useCallback19(async (forceRefresh = false) => {
|
|
39043
39132
|
setIsLoading(true);
|
|
39044
39133
|
setError(null);
|
|
39045
39134
|
try {
|
|
@@ -39056,13 +39145,13 @@ function useTools(options) {
|
|
|
39056
39145
|
setIsLoading(false);
|
|
39057
39146
|
}
|
|
39058
39147
|
}, []);
|
|
39059
|
-
const refresh =
|
|
39148
|
+
const refresh = useCallback19(
|
|
39060
39149
|
async (force = false) => {
|
|
39061
39150
|
await fetchTools(force);
|
|
39062
39151
|
},
|
|
39063
39152
|
[fetchTools]
|
|
39064
39153
|
);
|
|
39065
|
-
const checkForUpdates =
|
|
39154
|
+
const checkForUpdates = useCallback19(
|
|
39066
39155
|
(responseChecksum) => {
|
|
39067
39156
|
if (shouldRefreshTools(responseChecksum)) {
|
|
39068
39157
|
void refresh(true);
|
|
@@ -39073,7 +39162,7 @@ function useTools(options) {
|
|
|
39073
39162
|
[refresh]
|
|
39074
39163
|
);
|
|
39075
39164
|
const hasFetchedRef = useRef9(false);
|
|
39076
|
-
|
|
39165
|
+
useEffect13(() => {
|
|
39077
39166
|
if (autoFetch && !hasFetchedRef.current) {
|
|
39078
39167
|
hasFetchedRef.current = true;
|
|
39079
39168
|
void fetchTools();
|
|
@@ -39096,7 +39185,7 @@ function useTools(options) {
|
|
|
39096
39185
|
import {
|
|
39097
39186
|
createContext as createContext5,
|
|
39098
39187
|
createElement as createElement4,
|
|
39099
|
-
useCallback as
|
|
39188
|
+
useCallback as useCallback20,
|
|
39100
39189
|
useContext as useContext5,
|
|
39101
39190
|
useMemo as useMemo11,
|
|
39102
39191
|
useRef as useRef10,
|
|
@@ -39118,7 +39207,7 @@ function UIInteractionProvider({
|
|
|
39118
39207
|
/* @__PURE__ */ new Map()
|
|
39119
39208
|
);
|
|
39120
39209
|
const timersRef = useRef10(/* @__PURE__ */ new Map());
|
|
39121
|
-
const createInteraction =
|
|
39210
|
+
const createInteraction = useCallback20(
|
|
39122
39211
|
(id2, type, data) => {
|
|
39123
39212
|
return new Promise((resolve, reject) => {
|
|
39124
39213
|
const interaction = {
|
|
@@ -39149,7 +39238,7 @@ function UIInteractionProvider({
|
|
|
39149
39238
|
},
|
|
39150
39239
|
[timeout]
|
|
39151
39240
|
);
|
|
39152
|
-
const createDisplayInteraction =
|
|
39241
|
+
const createDisplayInteraction = useCallback20(
|
|
39153
39242
|
(id2, displayType, data, result, toolVersion, replacesInteractionId) => {
|
|
39154
39243
|
setPendingInteractions((prev) => {
|
|
39155
39244
|
const next = new Map(prev);
|
|
@@ -39181,7 +39270,7 @@ function UIInteractionProvider({
|
|
|
39181
39270
|
},
|
|
39182
39271
|
[]
|
|
39183
39272
|
);
|
|
39184
|
-
const resolveInteraction =
|
|
39273
|
+
const resolveInteraction = useCallback20((id2, result) => {
|
|
39185
39274
|
setPendingInteractions((prev) => {
|
|
39186
39275
|
const interaction = prev.get(id2);
|
|
39187
39276
|
if (!interaction) {
|
|
@@ -39198,7 +39287,7 @@ function UIInteractionProvider({
|
|
|
39198
39287
|
return next;
|
|
39199
39288
|
});
|
|
39200
39289
|
}, []);
|
|
39201
|
-
const clearInteractions =
|
|
39290
|
+
const clearInteractions = useCallback20(() => {
|
|
39202
39291
|
for (const timer of timersRef.current.values()) {
|
|
39203
39292
|
clearTimeout(timer);
|
|
39204
39293
|
}
|
|
@@ -39212,7 +39301,7 @@ function UIInteractionProvider({
|
|
|
39212
39301
|
return /* @__PURE__ */ new Map();
|
|
39213
39302
|
});
|
|
39214
39303
|
}, []);
|
|
39215
|
-
const cancelInteraction =
|
|
39304
|
+
const cancelInteraction = useCallback20((id2) => {
|
|
39216
39305
|
setPendingInteractions((prev) => {
|
|
39217
39306
|
const interaction = prev.get(id2);
|
|
39218
39307
|
if (!interaction) {
|
|
@@ -39229,7 +39318,7 @@ function UIInteractionProvider({
|
|
|
39229
39318
|
return next;
|
|
39230
39319
|
});
|
|
39231
39320
|
}, []);
|
|
39232
|
-
const getInteraction =
|
|
39321
|
+
const getInteraction = useCallback20(
|
|
39233
39322
|
(id2) => {
|
|
39234
39323
|
return pendingInteractions.get(id2);
|
|
39235
39324
|
},
|
|
@@ -39259,7 +39348,7 @@ function UIInteractionProvider({
|
|
|
39259
39348
|
}
|
|
39260
39349
|
|
|
39261
39350
|
// src/react/useVoice.ts
|
|
39262
|
-
import { useCallback as
|
|
39351
|
+
import { useCallback as useCallback21, useMemo as useMemo12, useRef as useRef11, useState as useState18 } from "react";
|
|
39263
39352
|
function getOnDeviceSpeechRecognition() {
|
|
39264
39353
|
if (typeof window === "undefined") return null;
|
|
39265
39354
|
if (!/iPhone|iPad|iPod/.test(navigator.userAgent)) return null;
|
|
@@ -39324,11 +39413,11 @@ function useVoice(options) {
|
|
|
39324
39413
|
const startTimeRef = useRef11(0);
|
|
39325
39414
|
const pipelineRef = useRef11(null);
|
|
39326
39415
|
const modelNameRef = useRef11(null);
|
|
39327
|
-
const getModelName =
|
|
39416
|
+
const getModelName = useCallback21(() => {
|
|
39328
39417
|
const model = options?.model ?? "whisper-tiny";
|
|
39329
39418
|
return `onnx-community/${model}`;
|
|
39330
39419
|
}, [options?.model]);
|
|
39331
|
-
const loadPipeline =
|
|
39420
|
+
const loadPipeline = useCallback21(async () => {
|
|
39332
39421
|
const modelName = getModelName();
|
|
39333
39422
|
if (pipelineRef.current && modelNameRef.current === modelName) {
|
|
39334
39423
|
return pipelineRef.current;
|
|
@@ -39363,10 +39452,10 @@ function useVoice(options) {
|
|
|
39363
39452
|
setIsLoadingModel(false);
|
|
39364
39453
|
}
|
|
39365
39454
|
}, [getModelName, options?.onModelProgress]);
|
|
39366
|
-
const preloadModel =
|
|
39455
|
+
const preloadModel = useCallback21(async () => {
|
|
39367
39456
|
await loadPipeline();
|
|
39368
39457
|
}, [loadPipeline]);
|
|
39369
|
-
const disposeModel =
|
|
39458
|
+
const disposeModel = useCallback21(async () => {
|
|
39370
39459
|
const pipe = pipelineRef.current;
|
|
39371
39460
|
if (pipe?.dispose) {
|
|
39372
39461
|
await pipe.dispose();
|
|
@@ -39375,7 +39464,7 @@ function useVoice(options) {
|
|
|
39375
39464
|
modelNameRef.current = null;
|
|
39376
39465
|
setIsModelLoaded(false);
|
|
39377
39466
|
}, []);
|
|
39378
|
-
const startRecording =
|
|
39467
|
+
const startRecording = useCallback21(async () => {
|
|
39379
39468
|
setError(null);
|
|
39380
39469
|
setRecording(null);
|
|
39381
39470
|
setTranscription(null);
|
|
@@ -39400,7 +39489,7 @@ function useVoice(options) {
|
|
|
39400
39489
|
throw processedError;
|
|
39401
39490
|
}
|
|
39402
39491
|
}, []);
|
|
39403
|
-
const stopRecording =
|
|
39492
|
+
const stopRecording = useCallback21(async () => {
|
|
39404
39493
|
return new Promise((resolve, reject) => {
|
|
39405
39494
|
const recorder = mediaRecorderRef.current;
|
|
39406
39495
|
if (!recorder || recorder.state === "inactive") {
|
|
@@ -39430,7 +39519,7 @@ function useVoice(options) {
|
|
|
39430
39519
|
recorder.stop();
|
|
39431
39520
|
});
|
|
39432
39521
|
}, []);
|
|
39433
|
-
const transcribe =
|
|
39522
|
+
const transcribe = useCallback21(
|
|
39434
39523
|
async (rec) => {
|
|
39435
39524
|
const target = rec ?? recording;
|
|
39436
39525
|
if (!target) {
|
|
@@ -39468,7 +39557,7 @@ function useVoice(options) {
|
|
|
39468
39557
|
const nativeRecognitionRef = useRef11(null);
|
|
39469
39558
|
const nativeTextRef = useRef11("");
|
|
39470
39559
|
const nativeResolveRef = useRef11(null);
|
|
39471
|
-
const startNativeTranscription =
|
|
39560
|
+
const startNativeTranscription = useCallback21(() => {
|
|
39472
39561
|
const SR = getOnDeviceSpeechRecognition();
|
|
39473
39562
|
if (!SR) return;
|
|
39474
39563
|
nativeTextRef.current = "";
|
|
@@ -39505,7 +39594,7 @@ function useVoice(options) {
|
|
|
39505
39594
|
recognition.start();
|
|
39506
39595
|
setIsNativeListening(true);
|
|
39507
39596
|
}, [options?.language]);
|
|
39508
|
-
const stopNativeTranscription =
|
|
39597
|
+
const stopNativeTranscription = useCallback21(() => {
|
|
39509
39598
|
return new Promise((resolve) => {
|
|
39510
39599
|
const recognition = nativeRecognitionRef.current;
|
|
39511
39600
|
if (!recognition) {
|
|
@@ -39516,7 +39605,7 @@ function useVoice(options) {
|
|
|
39516
39605
|
recognition.stop();
|
|
39517
39606
|
});
|
|
39518
39607
|
}, []);
|
|
39519
|
-
const abortNativeTranscription =
|
|
39608
|
+
const abortNativeTranscription = useCallback21(() => {
|
|
39520
39609
|
const recognition = nativeRecognitionRef.current;
|
|
39521
39610
|
if (recognition) {
|
|
39522
39611
|
nativeResolveRef.current = null;
|
|
@@ -39547,7 +39636,7 @@ function useVoice(options) {
|
|
|
39547
39636
|
}
|
|
39548
39637
|
|
|
39549
39638
|
// src/react/useWalletBinding.ts
|
|
39550
|
-
import { useCallback as
|
|
39639
|
+
import { useCallback as useCallback22, useEffect as useEffect14, useRef as useRef12, useState as useState19 } from "react";
|
|
39551
39640
|
function useWalletBinding(options = {}) {
|
|
39552
39641
|
const { getToken, baseUrl = BASE_URL, autoFetch = true, onError } = options;
|
|
39553
39642
|
const [wallets, setWallets] = useState19([]);
|
|
@@ -39558,12 +39647,12 @@ function useWalletBinding(options = {}) {
|
|
|
39558
39647
|
const baseUrlRef = useRef12(baseUrl);
|
|
39559
39648
|
const onErrorRef = useRef12(onError);
|
|
39560
39649
|
const abortControllerRef = useRef12(null);
|
|
39561
|
-
|
|
39650
|
+
useEffect14(() => {
|
|
39562
39651
|
getTokenRef.current = getToken;
|
|
39563
39652
|
baseUrlRef.current = baseUrl;
|
|
39564
39653
|
onErrorRef.current = onError;
|
|
39565
39654
|
});
|
|
39566
|
-
|
|
39655
|
+
useEffect14(() => {
|
|
39567
39656
|
return () => {
|
|
39568
39657
|
if (abortControllerRef.current) {
|
|
39569
39658
|
abortControllerRef.current.abort();
|
|
@@ -39571,7 +39660,7 @@ function useWalletBinding(options = {}) {
|
|
|
39571
39660
|
}
|
|
39572
39661
|
};
|
|
39573
39662
|
}, []);
|
|
39574
|
-
const getHeaders =
|
|
39663
|
+
const getHeaders = useCallback22(async () => {
|
|
39575
39664
|
const headers = {};
|
|
39576
39665
|
if (getTokenRef.current) {
|
|
39577
39666
|
const token = await getTokenRef.current();
|
|
@@ -39581,13 +39670,13 @@ function useWalletBinding(options = {}) {
|
|
|
39581
39670
|
}
|
|
39582
39671
|
return headers;
|
|
39583
39672
|
}, []);
|
|
39584
|
-
const handleError =
|
|
39673
|
+
const handleError = useCallback22((err) => {
|
|
39585
39674
|
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
39586
39675
|
setError(error2);
|
|
39587
39676
|
onErrorRef.current?.(error2);
|
|
39588
39677
|
return error2;
|
|
39589
39678
|
}, []);
|
|
39590
|
-
const fetchBinding =
|
|
39679
|
+
const fetchBinding = useCallback22(async () => {
|
|
39591
39680
|
if (abortControllerRef.current) {
|
|
39592
39681
|
abortControllerRef.current.abort();
|
|
39593
39682
|
}
|
|
@@ -39625,12 +39714,12 @@ function useWalletBinding(options = {}) {
|
|
|
39625
39714
|
}
|
|
39626
39715
|
}
|
|
39627
39716
|
}, [getHeaders, handleError]);
|
|
39628
|
-
const refetch =
|
|
39717
|
+
const refetch = useCallback22(async () => {
|
|
39629
39718
|
setWallets([]);
|
|
39630
39719
|
setTotals(null);
|
|
39631
39720
|
await fetchBinding();
|
|
39632
39721
|
}, [fetchBinding]);
|
|
39633
|
-
const getNonce =
|
|
39722
|
+
const getNonce = useCallback22(async () => {
|
|
39634
39723
|
setIsLoading(true);
|
|
39635
39724
|
setError(null);
|
|
39636
39725
|
try {
|
|
@@ -39651,7 +39740,7 @@ function useWalletBinding(options = {}) {
|
|
|
39651
39740
|
setIsLoading(false);
|
|
39652
39741
|
}
|
|
39653
39742
|
}, [getHeaders, handleError]);
|
|
39654
|
-
const bindWallet =
|
|
39743
|
+
const bindWallet = useCallback22(
|
|
39655
39744
|
async (request) => {
|
|
39656
39745
|
setIsLoading(true);
|
|
39657
39746
|
setError(null);
|
|
@@ -39677,7 +39766,7 @@ function useWalletBinding(options = {}) {
|
|
|
39677
39766
|
},
|
|
39678
39767
|
[getHeaders, handleError, fetchBinding]
|
|
39679
39768
|
);
|
|
39680
|
-
const unbindWallet =
|
|
39769
|
+
const unbindWallet = useCallback22(
|
|
39681
39770
|
async (address) => {
|
|
39682
39771
|
setIsLoading(true);
|
|
39683
39772
|
setError(null);
|
|
@@ -39704,7 +39793,7 @@ function useWalletBinding(options = {}) {
|
|
|
39704
39793
|
[getHeaders, handleError, fetchBinding]
|
|
39705
39794
|
);
|
|
39706
39795
|
const hasFetchedRef = useRef12(false);
|
|
39707
|
-
|
|
39796
|
+
useEffect14(() => {
|
|
39708
39797
|
if (autoFetch && !hasFetchedRef.current) {
|
|
39709
39798
|
hasFetchedRef.current = true;
|
|
39710
39799
|
void fetchBinding();
|