@anuma/sdk 10.2.2 → 10.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expo/{chunk-WRZTH4OS.mjs → chunk-ZIN4E7MR.mjs} +7 -0
- package/dist/expo/{consolidate-HKL5EGZT.mjs → consolidate-4WLZMXOS.mjs} +1 -1
- package/dist/expo/index.cjs +260 -113
- package/dist/expo/index.d.mts +3 -0
- package/dist/expo/index.d.ts +3 -0
- package/dist/expo/index.mjs +228 -89
- package/dist/index.cjs +7 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +7 -0
- package/dist/react/{chunk-RSA3S6OA.mjs → chunk-7JYVPYGQ.mjs} +7 -0
- package/dist/react/{consolidate-WFTPBHDV.mjs → consolidate-3RQL75PJ.mjs} +1 -1
- package/dist/react/index.cjs +566 -419
- package/dist/react/index.d.mts +3 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.mjs +418 -279
- package/dist/server/{chunk-QEROZ4VH.mjs → chunk-QK62YWBH.mjs} +7 -0
- package/dist/server/{consolidate-PYED62LW.mjs → consolidate-NW4UVA6T.mjs} +1 -1
- package/dist/server/index.cjs +67 -10
- package/dist/server/index.d.mts +3 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.mjs +62 -12
- package/package.json +1 -1
package/dist/expo/index.cjs
CHANGED
|
@@ -288,6 +288,7 @@ var init_redactor = __esm({
|
|
|
288
288
|
init_patterns();
|
|
289
289
|
PiiRedactor = class {
|
|
290
290
|
constructor(options = {}) {
|
|
291
|
+
this.disposed = false;
|
|
291
292
|
/** Maps original PII value → placeholder tag. */
|
|
292
293
|
this.valueToPlaceholder = /* @__PURE__ */ new Map();
|
|
293
294
|
/** Maps placeholder tag → original PII value (reverse lookup for de-anonymization). */
|
|
@@ -362,6 +363,7 @@ var init_redactor = __esm({
|
|
|
362
363
|
* The same value always gets the same placeholder within a redactor instance.
|
|
363
364
|
*/
|
|
364
365
|
getPlaceholder(category, value) {
|
|
366
|
+
if (this.disposed) throw new Error("PII redactor session ended");
|
|
365
367
|
const normalizedValue = value.trim();
|
|
366
368
|
const existing = this.valueToPlaceholder.get(normalizedValue);
|
|
367
369
|
if (existing) return existing;
|
|
@@ -737,6 +739,11 @@ var init_redactor = __esm({
|
|
|
737
739
|
this.warnedNonText = false;
|
|
738
740
|
this.warnedNerFailure = false;
|
|
739
741
|
}
|
|
742
|
+
/** Clear the mappings and prevent new reversible mappings. */
|
|
743
|
+
dispose() {
|
|
744
|
+
this.disposed = true;
|
|
745
|
+
this.clear();
|
|
746
|
+
}
|
|
740
747
|
};
|
|
741
748
|
}
|
|
742
749
|
});
|
|
@@ -2680,12 +2687,12 @@ async function persistKeyPair(address, startEpoch) {
|
|
|
2680
2687
|
const combined = new Uint8Array(iv.length + encryptedBytes.length);
|
|
2681
2688
|
combined.set(iv, 0);
|
|
2682
2689
|
combined.set(encryptedBytes, iv.length);
|
|
2683
|
-
const
|
|
2690
|
+
const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
|
|
2684
2691
|
const encryptedHex = bytesToHex(combined);
|
|
2685
2692
|
if (sessionEpoch !== startEpoch) {
|
|
2686
2693
|
return;
|
|
2687
2694
|
}
|
|
2688
|
-
localStorage.setItem(
|
|
2695
|
+
localStorage.setItem(storageKey2, encryptedHex);
|
|
2689
2696
|
} catch (err) {
|
|
2690
2697
|
throw new Error(
|
|
2691
2698
|
`Failed to persist keypair: ${err instanceof Error ? err.message : String(err)}`
|
|
@@ -2696,8 +2703,8 @@ async function loadPersistedKeyPair(address) {
|
|
|
2696
2703
|
if (typeof window === "undefined") {
|
|
2697
2704
|
return null;
|
|
2698
2705
|
}
|
|
2699
|
-
const
|
|
2700
|
-
const encryptedHex = localStorage.getItem(
|
|
2706
|
+
const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
|
|
2707
|
+
const encryptedHex = localStorage.getItem(storageKey2);
|
|
2701
2708
|
if (!encryptedHex) {
|
|
2702
2709
|
return null;
|
|
2703
2710
|
}
|
|
@@ -2748,7 +2755,7 @@ async function loadPersistedKeyPair(address) {
|
|
|
2748
2755
|
publicKey
|
|
2749
2756
|
};
|
|
2750
2757
|
} catch (error) {
|
|
2751
|
-
localStorage.removeItem(
|
|
2758
|
+
localStorage.removeItem(storageKey2);
|
|
2752
2759
|
getLogger().warn(
|
|
2753
2760
|
`Failed to load persisted keypair for ${address}: ${error instanceof Error ? error.message : String(error)}`
|
|
2754
2761
|
);
|
|
@@ -2759,8 +2766,8 @@ function clearPersistedKeyPair(address) {
|
|
|
2759
2766
|
if (typeof window === "undefined") {
|
|
2760
2767
|
return;
|
|
2761
2768
|
}
|
|
2762
|
-
const
|
|
2763
|
-
localStorage.removeItem(
|
|
2769
|
+
const storageKey2 = `${KEYPAIR_STORAGE_PREFIX}${address}`;
|
|
2770
|
+
localStorage.removeItem(storageKey2);
|
|
2764
2771
|
}
|
|
2765
2772
|
async function getKeyPair(address, signMessage, embeddedWalletSigner) {
|
|
2766
2773
|
const existingKeyPair = getStoredKeyPair(address);
|
|
@@ -9602,6 +9609,9 @@ var StreamSmoother = class {
|
|
|
9602
9609
|
this.rampDuration = config.rampDuration ?? 4e3;
|
|
9603
9610
|
}
|
|
9604
9611
|
}
|
|
9612
|
+
get hasPendingOutput() {
|
|
9613
|
+
return this.buffer.length > 0;
|
|
9614
|
+
}
|
|
9605
9615
|
/**
|
|
9606
9616
|
* Add text to the buffer. If smoothing is disabled, passes through immediately.
|
|
9607
9617
|
*/
|
|
@@ -10270,6 +10280,34 @@ async function runToolLoop(options) {
|
|
|
10270
10280
|
toolsChecksum: acc.toolsChecksum
|
|
10271
10281
|
};
|
|
10272
10282
|
};
|
|
10283
|
+
const drainSmoothers = async (acc, smoothers) => {
|
|
10284
|
+
let playbackAborted = false;
|
|
10285
|
+
const stopPlayback = () => {
|
|
10286
|
+
for (const smoother of smoothers) {
|
|
10287
|
+
if (isDetach()) smoother.flush();
|
|
10288
|
+
else smoother.destroy();
|
|
10289
|
+
}
|
|
10290
|
+
};
|
|
10291
|
+
const onAbort = () => {
|
|
10292
|
+
playbackAborted = !isDetach() && smoothers.some((smoother) => smoother.hasPendingOutput);
|
|
10293
|
+
stopPlayback();
|
|
10294
|
+
};
|
|
10295
|
+
combinedSignal?.addEventListener("abort", onAbort, { once: true });
|
|
10296
|
+
try {
|
|
10297
|
+
if (combinedSignal?.aborted) stopPlayback();
|
|
10298
|
+
await Promise.all(smoothers.map((smoother) => smoother.drain()));
|
|
10299
|
+
if (!playbackAborted) return;
|
|
10300
|
+
await fireAfterModelCall(buildModelCallEndPayload(acc, { error: "aborted" }));
|
|
10301
|
+
await fireRunError({ error: "Request aborted", stage: "model" });
|
|
10302
|
+
return {
|
|
10303
|
+
data: buildResponseFinal(acc),
|
|
10304
|
+
error: "Request aborted",
|
|
10305
|
+
toolsChecksum: acc.toolsChecksum
|
|
10306
|
+
};
|
|
10307
|
+
} finally {
|
|
10308
|
+
combinedSignal?.removeEventListener("abort", onAbort);
|
|
10309
|
+
}
|
|
10310
|
+
};
|
|
10273
10311
|
for (let attempt = 0; attempt < STREAM_RETRY_MAX_ATTEMPTS; attempt++) {
|
|
10274
10312
|
sseError = null;
|
|
10275
10313
|
if (combinedSignal?.aborted) {
|
|
@@ -10407,7 +10445,8 @@ async function runToolLoop(options) {
|
|
|
10407
10445
|
contentSmoother.flush();
|
|
10408
10446
|
thinkingSmoother.flush();
|
|
10409
10447
|
} else {
|
|
10410
|
-
await
|
|
10448
|
+
const interrupted = await drainSmoothers(accumulator, [contentSmoother, thinkingSmoother]);
|
|
10449
|
+
if (interrupted) return interrupted;
|
|
10411
10450
|
}
|
|
10412
10451
|
flushDeAnon();
|
|
10413
10452
|
await fireAfterModelCall(buildModelCallEndPayload(accumulator));
|
|
@@ -10926,7 +10965,11 @@ Executing tool: ${toolInfo}
|
|
|
10926
10965
|
contContentSmoother.flush();
|
|
10927
10966
|
contThinkingSmoother.flush();
|
|
10928
10967
|
} else {
|
|
10929
|
-
await
|
|
10968
|
+
const interrupted = await drainSmoothers(currentAccumulator, [
|
|
10969
|
+
contContentSmoother,
|
|
10970
|
+
contThinkingSmoother
|
|
10971
|
+
]);
|
|
10972
|
+
if (interrupted) return interrupted;
|
|
10930
10973
|
}
|
|
10931
10974
|
flushDeAnon();
|
|
10932
10975
|
await fireAfterModelCall(buildModelCallEndPayload(currentAccumulator));
|
|
@@ -11057,6 +11100,8 @@ async function resumeStream(options) {
|
|
|
11057
11100
|
let watchdog;
|
|
11058
11101
|
let idleFired = false;
|
|
11059
11102
|
let callerAborted = false;
|
|
11103
|
+
let playbackAborted = false;
|
|
11104
|
+
let draining = false;
|
|
11060
11105
|
let settled = false;
|
|
11061
11106
|
const idleEnabled = idleTimeoutMs > 0 && idleTimeoutMs !== Infinity && typeof setTimeout === "function";
|
|
11062
11107
|
const armWatchdog = () => {
|
|
@@ -11076,6 +11121,9 @@ async function resumeStream(options) {
|
|
|
11076
11121
|
const abortMessage = () => callerAborted ? "Resume aborted" : idleFired ? "Resume timed out" : "Resume aborted";
|
|
11077
11122
|
const onCallerAbort = () => {
|
|
11078
11123
|
callerAborted = true;
|
|
11124
|
+
playbackAborted = draining && (contentSmoother.hasPendingOutput || thinkingSmoother.hasPendingOutput);
|
|
11125
|
+
contentSmoother.destroy();
|
|
11126
|
+
thinkingSmoother.destroy();
|
|
11079
11127
|
disarmWatchdog();
|
|
11080
11128
|
idleController.abort();
|
|
11081
11129
|
};
|
|
@@ -11159,15 +11207,24 @@ async function resumeStream(options) {
|
|
|
11159
11207
|
statusCode
|
|
11160
11208
|
};
|
|
11161
11209
|
}
|
|
11162
|
-
|
|
11163
|
-
|
|
11164
|
-
|
|
11210
|
+
settled = true;
|
|
11211
|
+
disarmWatchdog();
|
|
11212
|
+
try {
|
|
11213
|
+
if (idleFired) return buildInterrupted(abortMessage());
|
|
11214
|
+
if (accumulator.toolCalls.size > 0) {
|
|
11215
|
+
return buildInterrupted("Stream ended with a pending tool request");
|
|
11216
|
+
}
|
|
11217
|
+
draining = true;
|
|
11218
|
+
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
11219
|
+
if (playbackAborted) return buildInterrupted(abortMessage());
|
|
11220
|
+
const response = strategy.buildFinalResponse(accumulator);
|
|
11221
|
+
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
11222
|
+
if (onFinish && deliveredOutput) onFinish(response);
|
|
11223
|
+
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
11224
|
+
} finally {
|
|
11225
|
+
draining = false;
|
|
11226
|
+
cleanup();
|
|
11165
11227
|
}
|
|
11166
|
-
await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
|
|
11167
|
-
const response = strategy.buildFinalResponse(accumulator);
|
|
11168
|
-
const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
|
|
11169
|
-
if (onFinish && deliveredOutput) onFinish(response);
|
|
11170
|
-
return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
|
|
11171
11228
|
}
|
|
11172
11229
|
|
|
11173
11230
|
// src/lib/chat/stockPriceCentroids.ts
|
|
@@ -19547,11 +19604,11 @@ function loadVaultCorpus(ctx, options, preparation) {
|
|
|
19547
19604
|
}
|
|
19548
19605
|
return request;
|
|
19549
19606
|
}
|
|
19550
|
-
function rowRequestsFor(
|
|
19551
|
-
let byMask =
|
|
19607
|
+
function rowRequestsFor(registry3, ctx, maskInput) {
|
|
19608
|
+
let byMask = registry3.get(ctx);
|
|
19552
19609
|
if (!byMask) {
|
|
19553
19610
|
byMask = /* @__PURE__ */ new Map();
|
|
19554
|
-
|
|
19611
|
+
registry3.set(ctx, byMask);
|
|
19555
19612
|
}
|
|
19556
19613
|
let requests = byMask.get(maskInput);
|
|
19557
19614
|
if (!requests) {
|
|
@@ -20486,11 +20543,11 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
20486
20543
|
};
|
|
20487
20544
|
}
|
|
20488
20545
|
const limit = searchOptions?.limit ?? 5;
|
|
20489
|
-
const
|
|
20546
|
+
const scopes2 = searchOptions?.scopes;
|
|
20490
20547
|
const folderId = searchOptions?.folderId;
|
|
20491
20548
|
const queryOpts = {};
|
|
20492
20549
|
if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
|
|
20493
|
-
if (
|
|
20550
|
+
if (scopes2?.length) queryOpts.scopes = scopes2;
|
|
20494
20551
|
if (folderId !== void 0) queryOpts.folderId = folderId;
|
|
20495
20552
|
if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
|
|
20496
20553
|
if (searchOptions?.includeArchived) queryOpts.includeArchived = true;
|
|
@@ -26776,17 +26833,17 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
26776
26833
|
}
|
|
26777
26834
|
const recallCtx = store ? { embeddingOptions: ctx.embeddingOptions, factSource: store.factSource } : ctx;
|
|
26778
26835
|
const facets = options.facets ?? DEFAULT_PROFILE_FACETS;
|
|
26779
|
-
const
|
|
26836
|
+
const scopes2 = options.scopes ?? DEFAULT_SCOPES;
|
|
26780
26837
|
const config = {
|
|
26781
26838
|
facetKeys: facets.map((f) => f.key).sort(),
|
|
26782
26839
|
facetsSignature: facetsSignature(facets),
|
|
26783
|
-
scopes: [...
|
|
26840
|
+
scopes: [...scopes2].sort(),
|
|
26784
26841
|
redacted: options.redactor !== void 0,
|
|
26785
26842
|
reviewedMemoryIdsSignature: reviewedMemoryIdsSignature(options.reviewedMemoryIds)
|
|
26786
26843
|
};
|
|
26787
26844
|
const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
|
|
26788
|
-
const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
|
|
26789
|
-
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
|
|
26845
|
+
const listOptions = { scopes: scopes2, includeDeleted: true, includeSuperseded: true };
|
|
26846
|
+
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes: scopes2 }), []];
|
|
26790
26847
|
const watermark = computeVaultWatermark(memories);
|
|
26791
26848
|
const observationTrends = summarizeObservationTrends(
|
|
26792
26849
|
memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
|
|
@@ -26831,7 +26888,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
26831
26888
|
for (const section of previous.sections) {
|
|
26832
26889
|
if (section.sourceMemoryIds.length > 0 && section.sourceMemoryIds.every((id2) => {
|
|
26833
26890
|
const memory = memoriesById.get(id2);
|
|
26834
|
-
return memory && !memory.isDeleted && !memory.supersededBy &&
|
|
26891
|
+
return memory && !memory.isDeleted && !memory.supersededBy && scopes2.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id2)) && changeTime(memory) <= previous.vaultWatermark;
|
|
26835
26892
|
})) {
|
|
26836
26893
|
fallbackPriors.set(section.key, section);
|
|
26837
26894
|
}
|
|
@@ -27004,7 +27061,7 @@ async function attributeFacts(ctx, candidates, facets) {
|
|
|
27004
27061
|
return keys;
|
|
27005
27062
|
}
|
|
27006
27063
|
async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
|
|
27007
|
-
const
|
|
27064
|
+
const scopes2 = options.scopes ?? DEFAULT_SCOPES;
|
|
27008
27065
|
const limit = options.limit ?? DEFAULT_FACET_RECALL_LIMIT;
|
|
27009
27066
|
const factTypeWeights = { ...DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, ...options.factTypeWeights };
|
|
27010
27067
|
const proofCountAlpha = options.proofCountAlpha ?? DEFAULT_PROFILE_PROOF_ALPHA;
|
|
@@ -27021,7 +27078,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
|
|
|
27021
27078
|
}
|
|
27022
27079
|
const recalled = await recall(facet.query, ctx, {
|
|
27023
27080
|
vaultPreparation,
|
|
27024
|
-
scopes,
|
|
27081
|
+
scopes: scopes2,
|
|
27025
27082
|
limit: hasReviewGate ? RECALL_MAX_LIMIT : limit,
|
|
27026
27083
|
...hasReviewGate && { memoryIds: [...reviewed] },
|
|
27027
27084
|
types: ["fact"],
|
|
@@ -27048,7 +27105,7 @@ async function synthesizeFacet(facet, ctx, options, prior, vaultPreparation) {
|
|
|
27048
27105
|
llmModel: options.llmModel ?? DEFAULT_SYNTHESIS_MODEL,
|
|
27049
27106
|
baseUrl: options.baseUrl,
|
|
27050
27107
|
fetchFn: options.fetchFn,
|
|
27051
|
-
scopes,
|
|
27108
|
+
scopes: scopes2,
|
|
27052
27109
|
limit,
|
|
27053
27110
|
types: ["fact"],
|
|
27054
27111
|
maxTokens: DEFAULT_FACET_MAX_TOKENS,
|
|
@@ -30819,7 +30876,7 @@ function useChat(options) {
|
|
|
30819
30876
|
}
|
|
30820
30877
|
|
|
30821
30878
|
// src/expo/useChatStorage.ts
|
|
30822
|
-
var
|
|
30879
|
+
var import_react6 = require("react");
|
|
30823
30880
|
var import_uuid8 = require("uuid");
|
|
30824
30881
|
init_clientConfig();
|
|
30825
30882
|
|
|
@@ -31615,6 +31672,107 @@ async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
|
31615
31672
|
init_logger();
|
|
31616
31673
|
init_redactor();
|
|
31617
31674
|
|
|
31675
|
+
// src/lib/pii/useConversationRedactors.ts
|
|
31676
|
+
var import_react5 = require("react");
|
|
31677
|
+
init_redactor();
|
|
31678
|
+
var REDACTOR_LIMIT = 50;
|
|
31679
|
+
var registry2 = /* @__PURE__ */ new WeakMap();
|
|
31680
|
+
var compositeKeys = /* @__PURE__ */ new WeakMap();
|
|
31681
|
+
var scopes = /* @__PURE__ */ new Set();
|
|
31682
|
+
var retiredRedactor = new PiiRedactor();
|
|
31683
|
+
retiredRedactor.dispose();
|
|
31684
|
+
function retireScope(scope) {
|
|
31685
|
+
scopes.delete(scope);
|
|
31686
|
+
if (!scope.active) return;
|
|
31687
|
+
scope.active = false;
|
|
31688
|
+
for (const { redactor } of scope.redactors.values()) redactor.dispose();
|
|
31689
|
+
scope.redactors.clear();
|
|
31690
|
+
for (const redactor of scope.evicted) redactor.dispose();
|
|
31691
|
+
scope.evicted = [];
|
|
31692
|
+
for (const notify of scope.subscribers) notify();
|
|
31693
|
+
}
|
|
31694
|
+
function storageKey(storage, secondaryStorage) {
|
|
31695
|
+
if (!secondaryStorage) return storage;
|
|
31696
|
+
let inner = compositeKeys.get(storage);
|
|
31697
|
+
if (!inner) {
|
|
31698
|
+
inner = /* @__PURE__ */ new WeakMap();
|
|
31699
|
+
compositeKeys.set(storage, inner);
|
|
31700
|
+
}
|
|
31701
|
+
let key3 = inner.get(secondaryStorage);
|
|
31702
|
+
if (!key3) {
|
|
31703
|
+
key3 = {};
|
|
31704
|
+
inner.set(secondaryStorage, key3);
|
|
31705
|
+
}
|
|
31706
|
+
return key3;
|
|
31707
|
+
}
|
|
31708
|
+
function getScope(database, storage, account) {
|
|
31709
|
+
let stores = registry2.get(database);
|
|
31710
|
+
if (!stores) {
|
|
31711
|
+
stores = /* @__PURE__ */ new WeakMap();
|
|
31712
|
+
registry2.set(database, stores);
|
|
31713
|
+
}
|
|
31714
|
+
let accounts = stores.get(storage);
|
|
31715
|
+
if (!accounts) {
|
|
31716
|
+
accounts = /* @__PURE__ */ new Map();
|
|
31717
|
+
stores.set(storage, accounts);
|
|
31718
|
+
}
|
|
31719
|
+
let scope = accounts.get(account);
|
|
31720
|
+
if (!scope?.active) {
|
|
31721
|
+
scope = { active: true, users: 0, subscribers: /* @__PURE__ */ new Set(), redactors: /* @__PURE__ */ new Map(), evicted: [] };
|
|
31722
|
+
accounts.set(account, scope);
|
|
31723
|
+
}
|
|
31724
|
+
return scope;
|
|
31725
|
+
}
|
|
31726
|
+
onClearAllEncryptionState(() => {
|
|
31727
|
+
registry2 = /* @__PURE__ */ new WeakMap();
|
|
31728
|
+
for (const scope of [...scopes]) retireScope(scope);
|
|
31729
|
+
});
|
|
31730
|
+
function useConversationRedactors(database, account, storage, secondaryStorage) {
|
|
31731
|
+
const scope = getScope(database, storageKey(storage, secondaryStorage), account);
|
|
31732
|
+
const subscribe = (0, import_react5.useCallback)(
|
|
31733
|
+
(callback) => {
|
|
31734
|
+
scope.subscribers.add(callback);
|
|
31735
|
+
return () => {
|
|
31736
|
+
scope.subscribers.delete(callback);
|
|
31737
|
+
};
|
|
31738
|
+
},
|
|
31739
|
+
[scope]
|
|
31740
|
+
);
|
|
31741
|
+
const getSnapshot = (0, import_react5.useCallback)(() => scope.active ? scope : null, [scope]);
|
|
31742
|
+
(0, import_react5.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
31743
|
+
(0, import_react5.useEffect)(() => {
|
|
31744
|
+
if (scope.active) scopes.add(scope);
|
|
31745
|
+
scope.users++;
|
|
31746
|
+
return () => {
|
|
31747
|
+
scope.users--;
|
|
31748
|
+
if (scope.users === 0) retireScope(scope);
|
|
31749
|
+
};
|
|
31750
|
+
}, [scope]);
|
|
31751
|
+
return (0, import_react5.useCallback)(
|
|
31752
|
+
(conversationId, nerDetector) => {
|
|
31753
|
+
if (!scope.active) return retiredRedactor;
|
|
31754
|
+
const cached = scope.redactors.get(conversationId);
|
|
31755
|
+
if (cached && cached.detector === nerDetector) {
|
|
31756
|
+
scope.redactors.delete(conversationId);
|
|
31757
|
+
scope.redactors.set(conversationId, cached);
|
|
31758
|
+
return cached.redactor;
|
|
31759
|
+
}
|
|
31760
|
+
if (cached) scope.evicted.push(cached.redactor);
|
|
31761
|
+
const redactor = new PiiRedactor({ nerDetector });
|
|
31762
|
+
scope.redactors.set(conversationId, { redactor, detector: nerDetector });
|
|
31763
|
+
if (scope.redactors.size > REDACTOR_LIMIT) {
|
|
31764
|
+
const oldest = scope.redactors.entries().next().value;
|
|
31765
|
+
if (oldest) {
|
|
31766
|
+
scope.evicted.push(oldest[1].redactor);
|
|
31767
|
+
scope.redactors.delete(oldest[0]);
|
|
31768
|
+
}
|
|
31769
|
+
}
|
|
31770
|
+
return redactor;
|
|
31771
|
+
},
|
|
31772
|
+
[scope]
|
|
31773
|
+
);
|
|
31774
|
+
}
|
|
31775
|
+
|
|
31618
31776
|
// src/lib/tools/selection/activeToolSets.ts
|
|
31619
31777
|
function mergeActiveToolSets(current, derived) {
|
|
31620
31778
|
if (derived.length === 0) return current;
|
|
@@ -31675,30 +31833,11 @@ function resetRecentToolSets() {
|
|
|
31675
31833
|
onClearAllEncryptionState(resetRecentToolSets);
|
|
31676
31834
|
|
|
31677
31835
|
// src/expo/useChatStorage.ts
|
|
31678
|
-
var CONVERSATION_REDACTOR_LIMIT = 50;
|
|
31679
|
-
var NO_CONVERSATION_KEY = "__no_conversation__";
|
|
31680
31836
|
var NO_STORE_FOLDERS = "Folders are not supported with a memoryStore";
|
|
31681
31837
|
var NO_STORE_MASK = "piiRedaction needs a memoryStore built with embeddingOptions.maskInput";
|
|
31682
31838
|
var MEMORY_STORE_NOT_READY = "Memory store is not ready";
|
|
31683
|
-
var conversationRedactors = /* @__PURE__ */ new Map();
|
|
31684
31839
|
var queuedBackends = /* @__PURE__ */ new WeakMap();
|
|
31685
31840
|
var clientToolFilterCache = /* @__PURE__ */ new Map();
|
|
31686
|
-
function getConversationRedactor(conversationId, nerDetector) {
|
|
31687
|
-
const key3 = conversationId ?? NO_CONVERSATION_KEY;
|
|
31688
|
-
const cached = conversationRedactors.get(key3);
|
|
31689
|
-
if (cached && cached.detector === nerDetector) {
|
|
31690
|
-
conversationRedactors.delete(key3);
|
|
31691
|
-
conversationRedactors.set(key3, cached);
|
|
31692
|
-
return cached.redactor;
|
|
31693
|
-
}
|
|
31694
|
-
const redactor = new PiiRedactor({ nerDetector });
|
|
31695
|
-
conversationRedactors.set(key3, { redactor, detector: nerDetector });
|
|
31696
|
-
if (conversationRedactors.size > CONVERSATION_REDACTOR_LIMIT) {
|
|
31697
|
-
const oldest = conversationRedactors.keys().next().value;
|
|
31698
|
-
if (oldest !== void 0) conversationRedactors.delete(oldest);
|
|
31699
|
-
}
|
|
31700
|
-
return redactor;
|
|
31701
|
-
}
|
|
31702
31841
|
function resolveCallPii(requestPiiRedaction, hookPiiRedaction, getConversationRedactorFor) {
|
|
31703
31842
|
const effective = requestPiiRedaction === void 0 ? hookPiiRedaction : requestPiiRedaction;
|
|
31704
31843
|
const redactor = effective === true ? getConversationRedactorFor() : isPiiRedactor(effective) ? effective : void 0;
|
|
@@ -31808,31 +31947,37 @@ function useChatStorage(options) {
|
|
|
31808
31947
|
toolResultsHistoryExclude,
|
|
31809
31948
|
foldToolResultsInHistory
|
|
31810
31949
|
} = options;
|
|
31811
|
-
const [currentConversationId, setCurrentConversationId] = (0,
|
|
31950
|
+
const [currentConversationId, setCurrentConversationId] = (0, import_react6.useState)(
|
|
31812
31951
|
initialConversationId || null
|
|
31813
31952
|
);
|
|
31814
|
-
const toolResultsHistoryExcludeRef = (0,
|
|
31953
|
+
const toolResultsHistoryExcludeRef = (0, import_react6.useRef)(toolResultsHistoryExclude);
|
|
31815
31954
|
toolResultsHistoryExcludeRef.current = toolResultsHistoryExclude;
|
|
31816
|
-
const foldToolResultsInHistoryRef = (0,
|
|
31955
|
+
const foldToolResultsInHistoryRef = (0, import_react6.useRef)(foldToolResultsInHistory);
|
|
31817
31956
|
foldToolResultsInHistoryRef.current = foldToolResultsInHistory;
|
|
31818
|
-
const nerDetectorRef = (0,
|
|
31957
|
+
const nerDetectorRef = (0, import_react6.useRef)(nerDetector);
|
|
31819
31958
|
nerDetectorRef.current = nerDetector;
|
|
31820
|
-
const
|
|
31959
|
+
const getConversationRedactor = useConversationRedactors(
|
|
31960
|
+
database,
|
|
31961
|
+
walletAddress,
|
|
31962
|
+
memoryStore ?? chatBackend ?? database,
|
|
31963
|
+
memoryStore && chatBackend ? chatBackend : void 0
|
|
31964
|
+
);
|
|
31965
|
+
const resolvedPiiRedaction = (0, import_react6.useMemo)(
|
|
31821
31966
|
() => piiRedaction === true ? getConversationRedactor(currentConversationId, nerDetectorRef.current) : piiRedaction,
|
|
31822
|
-
[piiRedaction, currentConversationId]
|
|
31967
|
+
[piiRedaction, currentConversationId, getConversationRedactor]
|
|
31823
31968
|
);
|
|
31824
|
-
const maskForEmbedding = (0,
|
|
31969
|
+
const maskForEmbedding = (0, import_react6.useCallback)(
|
|
31825
31970
|
(text16) => isPiiRedactor(resolvedPiiRedaction) ? resolvedPiiRedaction.maskText(text16) : text16,
|
|
31826
31971
|
[resolvedPiiRedaction]
|
|
31827
31972
|
);
|
|
31828
31973
|
const maskEmbeddingInput = isPiiRedactor(resolvedPiiRedaction) ? maskForEmbedding : void 0;
|
|
31829
31974
|
const storeMaskMissing = memoryStore !== void 0 && memoryStore !== null && maskEmbeddingInput !== void 0 && !memoryStore.masksEmbeddingInput;
|
|
31830
|
-
const messagesCollection = (0,
|
|
31831
|
-
const conversationsCollection = (0,
|
|
31975
|
+
const messagesCollection = (0, import_react6.useMemo)(() => database.get("history"), [database]);
|
|
31976
|
+
const conversationsCollection = (0, import_react6.useMemo)(
|
|
31832
31977
|
() => database.get("conversations"),
|
|
31833
31978
|
[database]
|
|
31834
31979
|
);
|
|
31835
|
-
const storageCtx = (0,
|
|
31980
|
+
const storageCtx = (0, import_react6.useMemo)(
|
|
31836
31981
|
() => ({
|
|
31837
31982
|
database,
|
|
31838
31983
|
messagesCollection,
|
|
@@ -31850,23 +31995,23 @@ function useChatStorage(options) {
|
|
|
31850
31995
|
embeddedWalletSigner
|
|
31851
31996
|
]
|
|
31852
31997
|
);
|
|
31853
|
-
const storageCtxRef = (0,
|
|
31998
|
+
const storageCtxRef = (0, import_react6.useRef)(storageCtx);
|
|
31854
31999
|
storageCtxRef.current = storageCtx;
|
|
31855
|
-
const backendFactory = (0,
|
|
32000
|
+
const backendFactory = (0, import_react6.useMemo)(
|
|
31856
32001
|
() => chatBackend ?? localChatBackend(database),
|
|
31857
32002
|
[chatBackend, database]
|
|
31858
32003
|
);
|
|
31859
|
-
const backend = (0,
|
|
32004
|
+
const backend = (0, import_react6.useMemo)(
|
|
31860
32005
|
() => backendFactory({ walletAddress, signMessage, embeddedWalletSigner }),
|
|
31861
32006
|
[backendFactory, walletAddress, signMessage, embeddedWalletSigner]
|
|
31862
32007
|
);
|
|
31863
|
-
const backendRef = (0,
|
|
32008
|
+
const backendRef = (0, import_react6.useRef)(backend);
|
|
31864
32009
|
backendRef.current = backend;
|
|
31865
|
-
const vaultMemoryCollection = (0,
|
|
32010
|
+
const vaultMemoryCollection = (0, import_react6.useMemo)(
|
|
31866
32011
|
() => database.get("memory_vault"),
|
|
31867
32012
|
[database]
|
|
31868
32013
|
);
|
|
31869
|
-
const vaultCtx = (0,
|
|
32014
|
+
const vaultCtx = (0, import_react6.useMemo)(
|
|
31870
32015
|
() => ({
|
|
31871
32016
|
database,
|
|
31872
32017
|
vaultMemoryCollection,
|
|
@@ -31877,18 +32022,18 @@ function useChatStorage(options) {
|
|
|
31877
32022
|
}),
|
|
31878
32023
|
[database, vaultMemoryCollection, walletAddress, signMessage, embeddedWalletSigner]
|
|
31879
32024
|
);
|
|
31880
|
-
const [queueStatus, setQueueStatus] = (0,
|
|
32025
|
+
const [queueStatus, setQueueStatus] = (0, import_react6.useState)({
|
|
31881
32026
|
pending: 0,
|
|
31882
32027
|
failed: 0,
|
|
31883
32028
|
isFlushing: false,
|
|
31884
32029
|
isPaused: false
|
|
31885
32030
|
});
|
|
31886
|
-
const refreshQueueStatus = (0,
|
|
32031
|
+
const refreshQueueStatus = (0, import_react6.useCallback)(() => {
|
|
31887
32032
|
if (walletAddress) {
|
|
31888
32033
|
setQueueStatus(queueManager.getStatus(walletAddress));
|
|
31889
32034
|
}
|
|
31890
32035
|
}, [walletAddress]);
|
|
31891
|
-
const executeQueuedOperation = (0,
|
|
32036
|
+
const executeQueuedOperation = (0, import_react6.useCallback)(
|
|
31892
32037
|
async (operation, encCtx) => {
|
|
31893
32038
|
const queued = queuedBackends.get(operation.payload) ?? backendFactory({
|
|
31894
32039
|
walletAddress: encCtx.walletAddress,
|
|
@@ -31933,7 +32078,7 @@ function useChatStorage(options) {
|
|
|
31933
32078
|
},
|
|
31934
32079
|
[backendFactory, database]
|
|
31935
32080
|
);
|
|
31936
|
-
const flushQueue = (0,
|
|
32081
|
+
const flushQueue = (0, import_react6.useCallback)(async () => {
|
|
31937
32082
|
if (!walletAddress || !signMessage) {
|
|
31938
32083
|
return { succeeded: [], failed: [], total: 0 };
|
|
31939
32084
|
}
|
|
@@ -31952,26 +32097,26 @@ function useChatStorage(options) {
|
|
|
31952
32097
|
executeQueuedOperation,
|
|
31953
32098
|
refreshQueueStatus
|
|
31954
32099
|
]);
|
|
31955
|
-
const clearQueue = (0,
|
|
32100
|
+
const clearQueue = (0, import_react6.useCallback)(() => {
|
|
31956
32101
|
if (walletAddress) {
|
|
31957
32102
|
queueManager.clear(walletAddress);
|
|
31958
32103
|
refreshQueueStatus();
|
|
31959
32104
|
}
|
|
31960
32105
|
}, [walletAddress, refreshQueueStatus]);
|
|
31961
|
-
(0,
|
|
32106
|
+
(0, import_react6.useEffect)(() => {
|
|
31962
32107
|
if (!walletAddress) return;
|
|
31963
32108
|
refreshQueueStatus();
|
|
31964
32109
|
return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
|
|
31965
32110
|
}, [walletAddress, refreshQueueStatus]);
|
|
31966
|
-
(0,
|
|
32111
|
+
(0, import_react6.useEffect)(() => {
|
|
31967
32112
|
if (!getWalletAddress || walletAddress) return;
|
|
31968
32113
|
const poller = new WalletPoller();
|
|
31969
32114
|
return poller.startPolling(getWalletAddress, () => {
|
|
31970
32115
|
});
|
|
31971
32116
|
}, [getWalletAddress, walletAddress]);
|
|
31972
|
-
const pendingOpsRef = (0,
|
|
31973
|
-
const syntheticConvIdsRef = (0,
|
|
31974
|
-
(0,
|
|
32117
|
+
const pendingOpsRef = (0, import_react6.useRef)([]);
|
|
32118
|
+
const syntheticConvIdsRef = (0, import_react6.useRef)(/* @__PURE__ */ new Set());
|
|
32119
|
+
(0, import_react6.useEffect)(() => {
|
|
31975
32120
|
if (!walletAddress || !enableQueue) return;
|
|
31976
32121
|
const pending = pendingOpsRef.current;
|
|
31977
32122
|
if (pending.length === 0) return;
|
|
@@ -31982,7 +32127,7 @@ function useChatStorage(options) {
|
|
|
31982
32127
|
pendingOpsRef.current = [];
|
|
31983
32128
|
refreshQueueStatus();
|
|
31984
32129
|
}, [walletAddress, enableQueue, refreshQueueStatus]);
|
|
31985
|
-
(0,
|
|
32130
|
+
(0, import_react6.useEffect)(() => {
|
|
31986
32131
|
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
31987
32132
|
return onKeyAvailable(walletAddress, () => {
|
|
31988
32133
|
flushQueue().catch((err) => {
|
|
@@ -31990,7 +32135,7 @@ function useChatStorage(options) {
|
|
|
31990
32135
|
});
|
|
31991
32136
|
});
|
|
31992
32137
|
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
31993
|
-
const writeOrQueue = (0,
|
|
32138
|
+
const writeOrQueue = (0, import_react6.useCallback)(
|
|
31994
32139
|
async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
|
|
31995
32140
|
const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
|
|
31996
32141
|
const currentBackend = storageCtx.walletAddress ? backend : backendRef.current;
|
|
@@ -32028,7 +32173,7 @@ function useChatStorage(options) {
|
|
|
32028
32173
|
},
|
|
32029
32174
|
[storageCtx, backend, enableQueue, signMessage, getWalletAddress]
|
|
32030
32175
|
);
|
|
32031
|
-
const embedMessageAsync = (0,
|
|
32176
|
+
const embedMessageAsync = (0, import_react6.useCallback)(
|
|
32032
32177
|
async (message, mask = maskForEmbedding) => {
|
|
32033
32178
|
if (!autoEmbedMessages || !getToken) return;
|
|
32034
32179
|
if (message.content.length < minContentLength) return;
|
|
@@ -32065,7 +32210,7 @@ function useChatStorage(options) {
|
|
|
32065
32210
|
maskForEmbedding
|
|
32066
32211
|
]
|
|
32067
32212
|
);
|
|
32068
|
-
const createMemoryEngineTool2 = (0,
|
|
32213
|
+
const createMemoryEngineTool2 = (0, import_react6.useCallback)(
|
|
32069
32214
|
(searchOptions) => {
|
|
32070
32215
|
if (!getToken) {
|
|
32071
32216
|
throw new Error("getToken is required for memory engine tool");
|
|
@@ -32078,18 +32223,18 @@ function useChatStorage(options) {
|
|
|
32078
32223
|
},
|
|
32079
32224
|
[backend, getToken, baseUrl, embeddingModel, maskEmbeddingInput]
|
|
32080
32225
|
);
|
|
32081
|
-
const vaultEmbeddingCache = (0,
|
|
32226
|
+
const vaultEmbeddingCache = (0, import_react6.useMemo)(
|
|
32082
32227
|
() => getVaultEmbeddingCache(database, walletAddress, embeddingModel),
|
|
32083
32228
|
[database, walletAddress, embeddingModel]
|
|
32084
32229
|
);
|
|
32085
|
-
const chunkVectorCacheRef = (0,
|
|
32086
|
-
(0,
|
|
32230
|
+
const chunkVectorCacheRef = (0, import_react6.useRef)(createChunkVectorCache());
|
|
32231
|
+
(0, import_react6.useEffect)(() => {
|
|
32087
32232
|
return onClearAllEncryptionState(() => {
|
|
32088
32233
|
vaultEmbeddingCache.clear();
|
|
32089
32234
|
chunkVectorCacheRef.current.clear();
|
|
32090
32235
|
});
|
|
32091
32236
|
}, [vaultEmbeddingCache]);
|
|
32092
|
-
const retainVaultMemory = (0,
|
|
32237
|
+
const retainVaultMemory = (0, import_react6.useCallback)(
|
|
32093
32238
|
async (input) => {
|
|
32094
32239
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
32095
32240
|
if (memoryStore) {
|
|
@@ -32135,7 +32280,7 @@ function useChatStorage(options) {
|
|
|
32135
32280
|
storeMaskMissing
|
|
32136
32281
|
]
|
|
32137
32282
|
);
|
|
32138
|
-
const createMemoryVaultTool2 = (0,
|
|
32283
|
+
const createMemoryVaultTool2 = (0, import_react6.useCallback)(
|
|
32139
32284
|
(options2) => {
|
|
32140
32285
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
32141
32286
|
if (storeMaskMissing) throw new Error(NO_STORE_MASK);
|
|
@@ -32146,7 +32291,7 @@ function useChatStorage(options) {
|
|
|
32146
32291
|
},
|
|
32147
32292
|
[vaultCtx, getToken, retainVaultMemory, memoryStore, storeMaskMissing]
|
|
32148
32293
|
);
|
|
32149
|
-
const createRecallTool2 = (0,
|
|
32294
|
+
const createRecallTool2 = (0, import_react6.useCallback)(
|
|
32150
32295
|
(toolOptions, callbacks) => {
|
|
32151
32296
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
32152
32297
|
if (!getToken && !memoryStore) {
|
|
@@ -32192,7 +32337,7 @@ function useChatStorage(options) {
|
|
|
32192
32337
|
storeMaskMissing
|
|
32193
32338
|
]
|
|
32194
32339
|
);
|
|
32195
|
-
const recallFn = (0,
|
|
32340
|
+
const recallFn = (0, import_react6.useCallback)(
|
|
32196
32341
|
async (query, options2) => {
|
|
32197
32342
|
if (memoryStore === null || !getToken && !memoryStore) {
|
|
32198
32343
|
return {
|
|
@@ -32241,7 +32386,7 @@ function useChatStorage(options) {
|
|
|
32241
32386
|
storeMaskMissing
|
|
32242
32387
|
]
|
|
32243
32388
|
);
|
|
32244
|
-
const getVaultMemories = (0,
|
|
32389
|
+
const getVaultMemories = (0, import_react6.useCallback)(
|
|
32245
32390
|
(options2) => {
|
|
32246
32391
|
if (memoryStore === null) return Promise.resolve([]);
|
|
32247
32392
|
if (!memoryStore) return getAllVaultMemoriesOp(vaultCtx, options2);
|
|
@@ -32253,7 +32398,7 @@ function useChatStorage(options) {
|
|
|
32253
32398
|
},
|
|
32254
32399
|
[vaultCtx, memoryStore]
|
|
32255
32400
|
);
|
|
32256
|
-
const deleteVaultMemory = (0,
|
|
32401
|
+
const deleteVaultMemory = (0, import_react6.useCallback)(
|
|
32257
32402
|
async (id2) => {
|
|
32258
32403
|
if (memoryStore === null) throw new Error(MEMORY_STORE_NOT_READY);
|
|
32259
32404
|
return memoryStore ? memoryStore.delete(id2) : deleteVaultMemoryOp(vaultCtx, id2);
|
|
@@ -32286,12 +32431,12 @@ function useChatStorage(options) {
|
|
|
32286
32431
|
onServerToolCall,
|
|
32287
32432
|
onToolCallArgumentsDelta
|
|
32288
32433
|
});
|
|
32289
|
-
const pendingResumeRef = (0,
|
|
32290
|
-
const isResumingRef = (0,
|
|
32291
|
-
const activeResumeRef = (0,
|
|
32292
|
-
const retirementRef = (0,
|
|
32293
|
-
const retirementStopRequestedRef = (0,
|
|
32294
|
-
const createConversation = (0,
|
|
32434
|
+
const pendingResumeRef = (0, import_react6.useRef)(null);
|
|
32435
|
+
const isResumingRef = (0, import_react6.useRef)(false);
|
|
32436
|
+
const activeResumeRef = (0, import_react6.useRef)(null);
|
|
32437
|
+
const retirementRef = (0, import_react6.useRef)(null);
|
|
32438
|
+
const retirementStopRequestedRef = (0, import_react6.useRef)(false);
|
|
32439
|
+
const createConversation = (0, import_react6.useCallback)(
|
|
32295
32440
|
async (opts) => {
|
|
32296
32441
|
const conversationOpts = {
|
|
32297
32442
|
...opts,
|
|
@@ -32311,16 +32456,16 @@ function useChatStorage(options) {
|
|
|
32311
32456
|
},
|
|
32312
32457
|
[defaultConversationTitle, writeOrQueue]
|
|
32313
32458
|
);
|
|
32314
|
-
const getConversation = (0,
|
|
32459
|
+
const getConversation = (0, import_react6.useCallback)(
|
|
32315
32460
|
async (id2) => {
|
|
32316
32461
|
return backend.getConversation(id2);
|
|
32317
32462
|
},
|
|
32318
32463
|
[backend]
|
|
32319
32464
|
);
|
|
32320
|
-
const getConversations = (0,
|
|
32465
|
+
const getConversations = (0, import_react6.useCallback)(async () => {
|
|
32321
32466
|
return backend.getConversations();
|
|
32322
32467
|
}, [backend]);
|
|
32323
|
-
const updateConversationTitle = (0,
|
|
32468
|
+
const updateConversationTitle = (0, import_react6.useCallback)(
|
|
32324
32469
|
async (id2, title) => {
|
|
32325
32470
|
const { result } = await writeOrQueue(
|
|
32326
32471
|
"updateConversationTitle",
|
|
@@ -32332,7 +32477,7 @@ function useChatStorage(options) {
|
|
|
32332
32477
|
},
|
|
32333
32478
|
[writeOrQueue]
|
|
32334
32479
|
);
|
|
32335
|
-
const updateConversationPinned = (0,
|
|
32480
|
+
const updateConversationPinned = (0, import_react6.useCallback)(
|
|
32336
32481
|
async (id2, pinned) => {
|
|
32337
32482
|
const { result } = await writeOrQueue(
|
|
32338
32483
|
"updateConversationPinned",
|
|
@@ -32344,7 +32489,7 @@ function useChatStorage(options) {
|
|
|
32344
32489
|
},
|
|
32345
32490
|
[writeOrQueue]
|
|
32346
32491
|
);
|
|
32347
|
-
const deleteConversation = (0,
|
|
32492
|
+
const deleteConversation = (0, import_react6.useCallback)(
|
|
32348
32493
|
async (id2) => {
|
|
32349
32494
|
const deleted = await backend.deleteConversation(id2);
|
|
32350
32495
|
if (deleted) {
|
|
@@ -32362,31 +32507,31 @@ function useChatStorage(options) {
|
|
|
32362
32507
|
},
|
|
32363
32508
|
[backend, database, walletAddress, signMessage, embeddedWalletSigner, currentConversationId]
|
|
32364
32509
|
);
|
|
32365
|
-
const getMessages = (0,
|
|
32510
|
+
const getMessages = (0, import_react6.useCallback)(
|
|
32366
32511
|
async (convId) => {
|
|
32367
32512
|
return backend.getMessages(convId);
|
|
32368
32513
|
},
|
|
32369
32514
|
[backend]
|
|
32370
32515
|
);
|
|
32371
|
-
const getMessagesPage = (0,
|
|
32516
|
+
const getMessagesPage = (0, import_react6.useCallback)(
|
|
32372
32517
|
async (convId, options2) => {
|
|
32373
32518
|
return backend.getMessagesPage(convId, options2);
|
|
32374
32519
|
},
|
|
32375
32520
|
[backend]
|
|
32376
32521
|
);
|
|
32377
|
-
const getMessageSkeletons = (0,
|
|
32522
|
+
const getMessageSkeletons = (0, import_react6.useCallback)(
|
|
32378
32523
|
(convId) => {
|
|
32379
32524
|
return backend.getMessageSkeletons(convId);
|
|
32380
32525
|
},
|
|
32381
32526
|
[backend]
|
|
32382
32527
|
);
|
|
32383
|
-
const getMessageCount = (0,
|
|
32528
|
+
const getMessageCount = (0, import_react6.useCallback)(
|
|
32384
32529
|
(convId) => {
|
|
32385
32530
|
return backend.getMessageCount(convId);
|
|
32386
32531
|
},
|
|
32387
32532
|
[backend]
|
|
32388
32533
|
);
|
|
32389
|
-
const extractSourcesFromAssistantMessage = (0,
|
|
32534
|
+
const extractSourcesFromAssistantMessage = (0, import_react6.useCallback)(
|
|
32390
32535
|
(assistantMessage) => {
|
|
32391
32536
|
try {
|
|
32392
32537
|
const extractedSources = [];
|
|
@@ -32468,7 +32613,7 @@ function useChatStorage(options) {
|
|
|
32468
32613
|
},
|
|
32469
32614
|
[]
|
|
32470
32615
|
);
|
|
32471
|
-
const ensureConversation = (0,
|
|
32616
|
+
const ensureConversation = (0, import_react6.useCallback)(async () => {
|
|
32472
32617
|
if (currentConversationId) {
|
|
32473
32618
|
if (syntheticConvIdsRef.current.has(currentConversationId)) {
|
|
32474
32619
|
return currentConversationId;
|
|
@@ -32490,11 +32635,11 @@ function useChatStorage(options) {
|
|
|
32490
32635
|
}
|
|
32491
32636
|
throw new Error("No conversation ID provided and autoCreateConversation is disabled");
|
|
32492
32637
|
}, [currentConversationId, getConversation, autoCreateConversation, createConversation]);
|
|
32493
|
-
const activeToolSetsRef = (0,
|
|
32638
|
+
const activeToolSetsRef = (0, import_react6.useRef)(activeToolSets);
|
|
32494
32639
|
activeToolSetsRef.current = activeToolSets;
|
|
32495
|
-
const getTokenRef = (0,
|
|
32640
|
+
const getTokenRef = (0, import_react6.useRef)(getToken);
|
|
32496
32641
|
getTokenRef.current = getToken;
|
|
32497
|
-
const finalizeResumedRow = (0,
|
|
32642
|
+
const finalizeResumedRow = (0, import_react6.useCallback)(
|
|
32498
32643
|
async (ctx, data, wasStopped, responseDuration, viaQueue = false) => {
|
|
32499
32644
|
const { content, thinking } = extractAssistantText(data);
|
|
32500
32645
|
let parentMessageId = ctx.userMessageUniqueId;
|
|
@@ -32568,7 +32713,7 @@ function useChatStorage(options) {
|
|
|
32568
32713
|
},
|
|
32569
32714
|
[backend, getMessages, writeOrQueue]
|
|
32570
32715
|
);
|
|
32571
|
-
const retirePendingTurn = (0,
|
|
32716
|
+
const retirePendingTurn = (0, import_react6.useCallback)(async () => {
|
|
32572
32717
|
const visible = activeResumeRef.current;
|
|
32573
32718
|
if (visible && !visible.headless) {
|
|
32574
32719
|
baseStop();
|
|
@@ -32631,7 +32776,7 @@ function useChatStorage(options) {
|
|
|
32631
32776
|
}
|
|
32632
32777
|
}
|
|
32633
32778
|
}, [baseCancel, baseStop, finalizeResumedRow, walletAddress, signMessage, embeddedWalletSigner]);
|
|
32634
|
-
const sendMessage = (0,
|
|
32779
|
+
const sendMessage = (0, import_react6.useCallback)(
|
|
32635
32780
|
async (args) => {
|
|
32636
32781
|
const {
|
|
32637
32782
|
messages,
|
|
@@ -33435,6 +33580,8 @@ function useChatStorage(options) {
|
|
|
33435
33580
|
getMessages,
|
|
33436
33581
|
backend,
|
|
33437
33582
|
baseSendMessage,
|
|
33583
|
+
getConversationRedactor,
|
|
33584
|
+
piiRedaction,
|
|
33438
33585
|
retirePendingTurn,
|
|
33439
33586
|
embedMessageAsync,
|
|
33440
33587
|
minContentLength,
|
|
@@ -33449,7 +33596,7 @@ function useChatStorage(options) {
|
|
|
33449
33596
|
onPiiRedacted
|
|
33450
33597
|
]
|
|
33451
33598
|
);
|
|
33452
|
-
const resumeStream2 = (0,
|
|
33599
|
+
const resumeStream2 = (0, import_react6.useCallback)(
|
|
33453
33600
|
async (handleOverride, opts) => {
|
|
33454
33601
|
if (isResumingRef.current || retirementRef.current) {
|
|
33455
33602
|
return { data: null, error: "Resume already in progress", assistantMessage: null };
|
|
@@ -33579,7 +33726,7 @@ function useChatStorage(options) {
|
|
|
33579
33726
|
},
|
|
33580
33727
|
[baseResumeStream, currentConversationId, finalizeResumedRow, embedMessageAsync]
|
|
33581
33728
|
);
|
|
33582
|
-
const stop = (0,
|
|
33729
|
+
const stop = (0, import_react6.useCallback)(() => {
|
|
33583
33730
|
if (retirementRef.current) {
|
|
33584
33731
|
retirementStopRequestedRef.current = true;
|
|
33585
33732
|
return;
|