@anuma/sdk 8.0.0 → 8.0.1
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/index.cjs +40 -36
- package/dist/expo/index.mjs +40 -36
- package/dist/react/index.cjs +39 -30
- package/dist/react/index.mjs +39 -30
- package/package.json +1 -1
package/dist/expo/index.cjs
CHANGED
|
@@ -28193,6 +28193,8 @@ function useChatStorage(options) {
|
|
|
28193
28193
|
embeddedWalletSigner
|
|
28194
28194
|
]
|
|
28195
28195
|
);
|
|
28196
|
+
const storageCtxRef = (0, import_react5.useRef)(storageCtx);
|
|
28197
|
+
storageCtxRef.current = storageCtx;
|
|
28196
28198
|
const vaultMemoryCollection = (0, import_react5.useMemo)(
|
|
28197
28199
|
() => database.get("memory_vault"),
|
|
28198
28200
|
[database]
|
|
@@ -28296,24 +28298,12 @@ function useChatStorage(options) {
|
|
|
28296
28298
|
refreshQueueStatus();
|
|
28297
28299
|
return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
|
|
28298
28300
|
}, [walletAddress, refreshQueueStatus]);
|
|
28299
|
-
(0, import_react5.useEffect)(() => {
|
|
28300
|
-
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
28301
|
-
return onKeyAvailable(walletAddress, () => {
|
|
28302
|
-
flushQueue().catch((err) => {
|
|
28303
|
-
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
28304
|
-
});
|
|
28305
|
-
});
|
|
28306
|
-
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
28307
28301
|
(0, import_react5.useEffect)(() => {
|
|
28308
28302
|
if (!getWalletAddress || walletAddress) return;
|
|
28309
28303
|
const poller = new WalletPoller();
|
|
28310
28304
|
return poller.startPolling(getWalletAddress, () => {
|
|
28311
28305
|
});
|
|
28312
28306
|
}, [getWalletAddress, walletAddress]);
|
|
28313
|
-
const isEncryptionReady = (0, import_react5.useCallback)(() => {
|
|
28314
|
-
if (!walletAddress || !signMessage) return true;
|
|
28315
|
-
return hasEncryptionKey(walletAddress);
|
|
28316
|
-
}, [walletAddress, signMessage]);
|
|
28317
28307
|
const pendingOpsRef = (0, import_react5.useRef)([]);
|
|
28318
28308
|
const syntheticConvIdsRef = (0, import_react5.useRef)(/* @__PURE__ */ new Set());
|
|
28319
28309
|
(0, import_react5.useEffect)(() => {
|
|
@@ -28326,34 +28316,49 @@ function useChatStorage(options) {
|
|
|
28326
28316
|
pendingOpsRef.current = [];
|
|
28327
28317
|
refreshQueueStatus();
|
|
28328
28318
|
}, [walletAddress, enableQueue, refreshQueueStatus]);
|
|
28319
|
+
(0, import_react5.useEffect)(() => {
|
|
28320
|
+
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
28321
|
+
return onKeyAvailable(walletAddress, () => {
|
|
28322
|
+
flushQueue().catch((err) => {
|
|
28323
|
+
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
28324
|
+
});
|
|
28325
|
+
});
|
|
28326
|
+
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
28329
28327
|
const writeOrQueue = (0, import_react5.useCallback)(
|
|
28330
28328
|
async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
|
|
28331
|
-
|
|
28332
|
-
|
|
28329
|
+
const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
|
|
28330
|
+
const currentWalletAddress = currentStorageCtx.walletAddress;
|
|
28331
|
+
if (enableQueue && signMessage && !currentWalletAddress && getWalletAddress) {
|
|
28332
|
+
pendingOpsRef.current.push({ type: opType, payload, dependencies });
|
|
28333
|
+
return { result: makeSynthetic(), queued: true };
|
|
28334
|
+
}
|
|
28335
|
+
if (!currentWalletAddress || !currentStorageCtx.signMessage || hasEncryptionKey(currentWalletAddress)) {
|
|
28336
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
28333
28337
|
return { result: result2, queued: false };
|
|
28334
28338
|
}
|
|
28335
28339
|
if (!enableQueue) {
|
|
28336
|
-
const result2 = await directWrite();
|
|
28340
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
28337
28341
|
return { result: result2, queued: false };
|
|
28338
28342
|
}
|
|
28339
|
-
if (
|
|
28340
|
-
|
|
28341
|
-
|
|
28342
|
-
|
|
28343
|
-
|
|
28344
|
-
|
|
28343
|
+
if (currentWalletAddress) {
|
|
28344
|
+
const queueId = queueManager.queueOperation(
|
|
28345
|
+
currentWalletAddress,
|
|
28346
|
+
opType,
|
|
28347
|
+
payload,
|
|
28348
|
+
dependencies
|
|
28349
|
+
);
|
|
28345
28350
|
if (queueId === null) {
|
|
28346
28351
|
getLogger().warn("[useChatStorage] Queue full, falling back to direct write");
|
|
28347
|
-
const result2 = await directWrite();
|
|
28352
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
28348
28353
|
return { result: result2, queued: false };
|
|
28349
28354
|
}
|
|
28350
|
-
|
|
28355
|
+
setQueueStatus(queueManager.getStatus(currentWalletAddress));
|
|
28351
28356
|
return { result: makeSynthetic(), queued: true, queueId };
|
|
28352
28357
|
}
|
|
28353
|
-
const result = await directWrite();
|
|
28358
|
+
const result = await directWrite(currentStorageCtx);
|
|
28354
28359
|
return { result, queued: false };
|
|
28355
28360
|
},
|
|
28356
|
-
[
|
|
28361
|
+
[storageCtx, enableQueue, signMessage, getWalletAddress]
|
|
28357
28362
|
);
|
|
28358
28363
|
const embedMessageAsync = (0, import_react5.useCallback)(
|
|
28359
28364
|
async (message, mask = maskForEmbedding) => {
|
|
@@ -28627,7 +28632,7 @@ function useChatStorage(options) {
|
|
|
28627
28632
|
const { result, queued } = await writeOrQueue(
|
|
28628
28633
|
"createConversation",
|
|
28629
28634
|
conversationOpts,
|
|
28630
|
-
() => createConversationOp(
|
|
28635
|
+
(ctx) => createConversationOp(ctx, conversationOpts, defaultConversationTitle),
|
|
28631
28636
|
() => makeSyntheticStoredConversation(conversationOpts, defaultConversationTitle)
|
|
28632
28637
|
);
|
|
28633
28638
|
if (queued) {
|
|
@@ -28636,7 +28641,7 @@ function useChatStorage(options) {
|
|
|
28636
28641
|
setCurrentConversationId(result.conversationId);
|
|
28637
28642
|
return result;
|
|
28638
28643
|
},
|
|
28639
|
-
[
|
|
28644
|
+
[defaultConversationTitle, writeOrQueue]
|
|
28640
28645
|
);
|
|
28641
28646
|
const getConversation = (0, import_react5.useCallback)(
|
|
28642
28647
|
async (id) => {
|
|
@@ -28652,24 +28657,24 @@ function useChatStorage(options) {
|
|
|
28652
28657
|
const { result } = await writeOrQueue(
|
|
28653
28658
|
"updateConversationTitle",
|
|
28654
28659
|
{ conversationId: id, title },
|
|
28655
|
-
() => updateConversationTitleOp(
|
|
28660
|
+
(ctx) => updateConversationTitleOp(ctx, id, title),
|
|
28656
28661
|
() => true
|
|
28657
28662
|
);
|
|
28658
28663
|
return result;
|
|
28659
28664
|
},
|
|
28660
|
-
[
|
|
28665
|
+
[writeOrQueue]
|
|
28661
28666
|
);
|
|
28662
28667
|
const updateConversationPinned = (0, import_react5.useCallback)(
|
|
28663
28668
|
async (id, pinned) => {
|
|
28664
28669
|
const { result } = await writeOrQueue(
|
|
28665
28670
|
"updateConversationPinned",
|
|
28666
28671
|
{ conversationId: id, pinned },
|
|
28667
|
-
() => updateConversationPinnedOp(
|
|
28672
|
+
(ctx) => updateConversationPinnedOp(ctx, id, pinned),
|
|
28668
28673
|
() => true
|
|
28669
28674
|
);
|
|
28670
28675
|
return result;
|
|
28671
28676
|
},
|
|
28672
|
-
[
|
|
28677
|
+
[writeOrQueue]
|
|
28673
28678
|
);
|
|
28674
28679
|
const deleteConversation = (0, import_react5.useCallback)(
|
|
28675
28680
|
async (id) => {
|
|
@@ -28887,7 +28892,7 @@ function useChatStorage(options) {
|
|
|
28887
28892
|
const { result } = await writeOrQueue(
|
|
28888
28893
|
"createMessage",
|
|
28889
28894
|
rowOpts,
|
|
28890
|
-
() => upsertMessageOp(
|
|
28895
|
+
(currentStorageCtx) => upsertMessageOp(currentStorageCtx, rowOpts),
|
|
28891
28896
|
() => makeSyntheticStoredMessage(rowOpts),
|
|
28892
28897
|
ctx.userMessageQueueId ? [ctx.userMessageQueueId] : []
|
|
28893
28898
|
);
|
|
@@ -29349,7 +29354,7 @@ function useChatStorage(options) {
|
|
|
29349
29354
|
const userMsgResult = await writeOrQueue(
|
|
29350
29355
|
"createMessage",
|
|
29351
29356
|
userMsgOpts,
|
|
29352
|
-
() => createMessageOp(
|
|
29357
|
+
(ctx) => createMessageOp(ctx, userMsgOpts),
|
|
29353
29358
|
() => makeSyntheticStoredMessage(userMsgOpts)
|
|
29354
29359
|
);
|
|
29355
29360
|
storedUserMessage = userMsgResult.result;
|
|
@@ -29698,7 +29703,7 @@ function useChatStorage(options) {
|
|
|
29698
29703
|
const assistantMsgResult = await writeOrQueue(
|
|
29699
29704
|
"createMessage",
|
|
29700
29705
|
assistantMsgOpts,
|
|
29701
|
-
() => createMessageOp(
|
|
29706
|
+
(ctx) => createMessageOp(ctx, assistantMsgOpts),
|
|
29702
29707
|
() => makeSyntheticStoredMessage(assistantMsgOpts),
|
|
29703
29708
|
userMsgQueueId ? [userMsgQueueId] : []
|
|
29704
29709
|
);
|
|
@@ -29730,7 +29735,7 @@ function useChatStorage(options) {
|
|
|
29730
29735
|
const toolResultsWrite = await writeOrQueue(
|
|
29731
29736
|
"createMessage",
|
|
29732
29737
|
toolResultsOpts,
|
|
29733
|
-
() => createMessageOp(
|
|
29738
|
+
(ctx) => createMessageOp(ctx, toolResultsOpts),
|
|
29734
29739
|
() => makeSyntheticStoredMessage(toolResultsOpts),
|
|
29735
29740
|
assistantMsgQueueId ? [assistantMsgQueueId] : []
|
|
29736
29741
|
);
|
|
@@ -29773,7 +29778,6 @@ function useChatStorage(options) {
|
|
|
29773
29778
|
walletAddress,
|
|
29774
29779
|
signMessage,
|
|
29775
29780
|
embeddedWalletSigner,
|
|
29776
|
-
isEncryptionReady,
|
|
29777
29781
|
enableQueue,
|
|
29778
29782
|
getWalletAddress,
|
|
29779
29783
|
refreshQueueStatus,
|
package/dist/expo/index.mjs
CHANGED
|
@@ -26501,6 +26501,8 @@ function useChatStorage(options) {
|
|
|
26501
26501
|
embeddedWalletSigner
|
|
26502
26502
|
]
|
|
26503
26503
|
);
|
|
26504
|
+
const storageCtxRef = useRef4(storageCtx);
|
|
26505
|
+
storageCtxRef.current = storageCtx;
|
|
26504
26506
|
const vaultMemoryCollection = useMemo(
|
|
26505
26507
|
() => database.get("memory_vault"),
|
|
26506
26508
|
[database]
|
|
@@ -26604,24 +26606,12 @@ function useChatStorage(options) {
|
|
|
26604
26606
|
refreshQueueStatus();
|
|
26605
26607
|
return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
|
|
26606
26608
|
}, [walletAddress, refreshQueueStatus]);
|
|
26607
|
-
useEffect4(() => {
|
|
26608
|
-
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
26609
|
-
return onKeyAvailable(walletAddress, () => {
|
|
26610
|
-
flushQueue().catch((err) => {
|
|
26611
|
-
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
26612
|
-
});
|
|
26613
|
-
});
|
|
26614
|
-
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
26615
26609
|
useEffect4(() => {
|
|
26616
26610
|
if (!getWalletAddress || walletAddress) return;
|
|
26617
26611
|
const poller = new WalletPoller();
|
|
26618
26612
|
return poller.startPolling(getWalletAddress, () => {
|
|
26619
26613
|
});
|
|
26620
26614
|
}, [getWalletAddress, walletAddress]);
|
|
26621
|
-
const isEncryptionReady = useCallback4(() => {
|
|
26622
|
-
if (!walletAddress || !signMessage) return true;
|
|
26623
|
-
return hasEncryptionKey(walletAddress);
|
|
26624
|
-
}, [walletAddress, signMessage]);
|
|
26625
26615
|
const pendingOpsRef = useRef4([]);
|
|
26626
26616
|
const syntheticConvIdsRef = useRef4(/* @__PURE__ */ new Set());
|
|
26627
26617
|
useEffect4(() => {
|
|
@@ -26634,34 +26624,49 @@ function useChatStorage(options) {
|
|
|
26634
26624
|
pendingOpsRef.current = [];
|
|
26635
26625
|
refreshQueueStatus();
|
|
26636
26626
|
}, [walletAddress, enableQueue, refreshQueueStatus]);
|
|
26627
|
+
useEffect4(() => {
|
|
26628
|
+
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
26629
|
+
return onKeyAvailable(walletAddress, () => {
|
|
26630
|
+
flushQueue().catch((err) => {
|
|
26631
|
+
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
26632
|
+
});
|
|
26633
|
+
});
|
|
26634
|
+
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
26637
26635
|
const writeOrQueue = useCallback4(
|
|
26638
26636
|
async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
|
|
26639
|
-
|
|
26640
|
-
|
|
26637
|
+
const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
|
|
26638
|
+
const currentWalletAddress = currentStorageCtx.walletAddress;
|
|
26639
|
+
if (enableQueue && signMessage && !currentWalletAddress && getWalletAddress) {
|
|
26640
|
+
pendingOpsRef.current.push({ type: opType, payload, dependencies });
|
|
26641
|
+
return { result: makeSynthetic(), queued: true };
|
|
26642
|
+
}
|
|
26643
|
+
if (!currentWalletAddress || !currentStorageCtx.signMessage || hasEncryptionKey(currentWalletAddress)) {
|
|
26644
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
26641
26645
|
return { result: result2, queued: false };
|
|
26642
26646
|
}
|
|
26643
26647
|
if (!enableQueue) {
|
|
26644
|
-
const result2 = await directWrite();
|
|
26648
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
26645
26649
|
return { result: result2, queued: false };
|
|
26646
26650
|
}
|
|
26647
|
-
if (
|
|
26648
|
-
|
|
26649
|
-
|
|
26650
|
-
|
|
26651
|
-
|
|
26652
|
-
|
|
26651
|
+
if (currentWalletAddress) {
|
|
26652
|
+
const queueId = queueManager.queueOperation(
|
|
26653
|
+
currentWalletAddress,
|
|
26654
|
+
opType,
|
|
26655
|
+
payload,
|
|
26656
|
+
dependencies
|
|
26657
|
+
);
|
|
26653
26658
|
if (queueId === null) {
|
|
26654
26659
|
getLogger().warn("[useChatStorage] Queue full, falling back to direct write");
|
|
26655
|
-
const result2 = await directWrite();
|
|
26660
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
26656
26661
|
return { result: result2, queued: false };
|
|
26657
26662
|
}
|
|
26658
|
-
|
|
26663
|
+
setQueueStatus(queueManager.getStatus(currentWalletAddress));
|
|
26659
26664
|
return { result: makeSynthetic(), queued: true, queueId };
|
|
26660
26665
|
}
|
|
26661
|
-
const result = await directWrite();
|
|
26666
|
+
const result = await directWrite(currentStorageCtx);
|
|
26662
26667
|
return { result, queued: false };
|
|
26663
26668
|
},
|
|
26664
|
-
[
|
|
26669
|
+
[storageCtx, enableQueue, signMessage, getWalletAddress]
|
|
26665
26670
|
);
|
|
26666
26671
|
const embedMessageAsync = useCallback4(
|
|
26667
26672
|
async (message, mask = maskForEmbedding) => {
|
|
@@ -26935,7 +26940,7 @@ function useChatStorage(options) {
|
|
|
26935
26940
|
const { result, queued } = await writeOrQueue(
|
|
26936
26941
|
"createConversation",
|
|
26937
26942
|
conversationOpts,
|
|
26938
|
-
() => createConversationOp(
|
|
26943
|
+
(ctx) => createConversationOp(ctx, conversationOpts, defaultConversationTitle),
|
|
26939
26944
|
() => makeSyntheticStoredConversation(conversationOpts, defaultConversationTitle)
|
|
26940
26945
|
);
|
|
26941
26946
|
if (queued) {
|
|
@@ -26944,7 +26949,7 @@ function useChatStorage(options) {
|
|
|
26944
26949
|
setCurrentConversationId(result.conversationId);
|
|
26945
26950
|
return result;
|
|
26946
26951
|
},
|
|
26947
|
-
[
|
|
26952
|
+
[defaultConversationTitle, writeOrQueue]
|
|
26948
26953
|
);
|
|
26949
26954
|
const getConversation = useCallback4(
|
|
26950
26955
|
async (id) => {
|
|
@@ -26960,24 +26965,24 @@ function useChatStorage(options) {
|
|
|
26960
26965
|
const { result } = await writeOrQueue(
|
|
26961
26966
|
"updateConversationTitle",
|
|
26962
26967
|
{ conversationId: id, title },
|
|
26963
|
-
() => updateConversationTitleOp(
|
|
26968
|
+
(ctx) => updateConversationTitleOp(ctx, id, title),
|
|
26964
26969
|
() => true
|
|
26965
26970
|
);
|
|
26966
26971
|
return result;
|
|
26967
26972
|
},
|
|
26968
|
-
[
|
|
26973
|
+
[writeOrQueue]
|
|
26969
26974
|
);
|
|
26970
26975
|
const updateConversationPinned = useCallback4(
|
|
26971
26976
|
async (id, pinned) => {
|
|
26972
26977
|
const { result } = await writeOrQueue(
|
|
26973
26978
|
"updateConversationPinned",
|
|
26974
26979
|
{ conversationId: id, pinned },
|
|
26975
|
-
() => updateConversationPinnedOp(
|
|
26980
|
+
(ctx) => updateConversationPinnedOp(ctx, id, pinned),
|
|
26976
26981
|
() => true
|
|
26977
26982
|
);
|
|
26978
26983
|
return result;
|
|
26979
26984
|
},
|
|
26980
|
-
[
|
|
26985
|
+
[writeOrQueue]
|
|
26981
26986
|
);
|
|
26982
26987
|
const deleteConversation = useCallback4(
|
|
26983
26988
|
async (id) => {
|
|
@@ -27195,7 +27200,7 @@ function useChatStorage(options) {
|
|
|
27195
27200
|
const { result } = await writeOrQueue(
|
|
27196
27201
|
"createMessage",
|
|
27197
27202
|
rowOpts,
|
|
27198
|
-
() => upsertMessageOp(
|
|
27203
|
+
(currentStorageCtx) => upsertMessageOp(currentStorageCtx, rowOpts),
|
|
27199
27204
|
() => makeSyntheticStoredMessage(rowOpts),
|
|
27200
27205
|
ctx.userMessageQueueId ? [ctx.userMessageQueueId] : []
|
|
27201
27206
|
);
|
|
@@ -27657,7 +27662,7 @@ function useChatStorage(options) {
|
|
|
27657
27662
|
const userMsgResult = await writeOrQueue(
|
|
27658
27663
|
"createMessage",
|
|
27659
27664
|
userMsgOpts,
|
|
27660
|
-
() => createMessageOp(
|
|
27665
|
+
(ctx) => createMessageOp(ctx, userMsgOpts),
|
|
27661
27666
|
() => makeSyntheticStoredMessage(userMsgOpts)
|
|
27662
27667
|
);
|
|
27663
27668
|
storedUserMessage = userMsgResult.result;
|
|
@@ -28006,7 +28011,7 @@ function useChatStorage(options) {
|
|
|
28006
28011
|
const assistantMsgResult = await writeOrQueue(
|
|
28007
28012
|
"createMessage",
|
|
28008
28013
|
assistantMsgOpts,
|
|
28009
|
-
() => createMessageOp(
|
|
28014
|
+
(ctx) => createMessageOp(ctx, assistantMsgOpts),
|
|
28010
28015
|
() => makeSyntheticStoredMessage(assistantMsgOpts),
|
|
28011
28016
|
userMsgQueueId ? [userMsgQueueId] : []
|
|
28012
28017
|
);
|
|
@@ -28038,7 +28043,7 @@ function useChatStorage(options) {
|
|
|
28038
28043
|
const toolResultsWrite = await writeOrQueue(
|
|
28039
28044
|
"createMessage",
|
|
28040
28045
|
toolResultsOpts,
|
|
28041
|
-
() => createMessageOp(
|
|
28046
|
+
(ctx) => createMessageOp(ctx, toolResultsOpts),
|
|
28042
28047
|
() => makeSyntheticStoredMessage(toolResultsOpts),
|
|
28043
28048
|
assistantMsgQueueId ? [assistantMsgQueueId] : []
|
|
28044
28049
|
);
|
|
@@ -28081,7 +28086,6 @@ function useChatStorage(options) {
|
|
|
28081
28086
|
walletAddress,
|
|
28082
28087
|
signMessage,
|
|
28083
28088
|
embeddedWalletSigner,
|
|
28084
|
-
isEncryptionReady,
|
|
28085
28089
|
enableQueue,
|
|
28086
28090
|
getWalletAddress,
|
|
28087
28091
|
refreshQueueStatus,
|
package/dist/react/index.cjs
CHANGED
|
@@ -33469,6 +33469,8 @@ function useChatStorage(options) {
|
|
|
33469
33469
|
embeddedWalletSigner
|
|
33470
33470
|
]
|
|
33471
33471
|
);
|
|
33472
|
+
const storageCtxRef = (0, import_react6.useRef)(storageCtx);
|
|
33473
|
+
storageCtxRef.current = storageCtx;
|
|
33472
33474
|
const mediaCtx = (0, import_react6.useMemo)(
|
|
33473
33475
|
() => ({
|
|
33474
33476
|
database,
|
|
@@ -33605,14 +33607,6 @@ function useChatStorage(options) {
|
|
|
33605
33607
|
refreshQueueStatus();
|
|
33606
33608
|
return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
|
|
33607
33609
|
}, [walletAddress, refreshQueueStatus]);
|
|
33608
|
-
(0, import_react6.useEffect)(() => {
|
|
33609
|
-
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
33610
|
-
return onKeyAvailable(walletAddress, () => {
|
|
33611
|
-
flushQueue().catch((err) => {
|
|
33612
|
-
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
33613
|
-
});
|
|
33614
|
-
});
|
|
33615
|
-
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
33616
33610
|
(0, import_react6.useEffect)(() => {
|
|
33617
33611
|
if (!getWalletAddress || walletAddress) return;
|
|
33618
33612
|
const poller = new WalletPoller();
|
|
@@ -33636,34 +33630,49 @@ function useChatStorage(options) {
|
|
|
33636
33630
|
pendingOpsRef.current = [];
|
|
33637
33631
|
refreshQueueStatus();
|
|
33638
33632
|
}, [walletAddress, enableQueue, refreshQueueStatus]);
|
|
33633
|
+
(0, import_react6.useEffect)(() => {
|
|
33634
|
+
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
33635
|
+
return onKeyAvailable(walletAddress, () => {
|
|
33636
|
+
flushQueue().catch((err) => {
|
|
33637
|
+
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
33638
|
+
});
|
|
33639
|
+
});
|
|
33640
|
+
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
33639
33641
|
const writeOrQueue = (0, import_react6.useCallback)(
|
|
33640
33642
|
async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
|
|
33641
|
-
|
|
33642
|
-
|
|
33643
|
+
const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
|
|
33644
|
+
const currentWalletAddress = currentStorageCtx.walletAddress;
|
|
33645
|
+
if (enableQueue && signMessage && !currentWalletAddress && getWalletAddress) {
|
|
33646
|
+
pendingOpsRef.current.push({ type: opType, payload, dependencies });
|
|
33647
|
+
return { result: makeSynthetic(), queued: true };
|
|
33648
|
+
}
|
|
33649
|
+
if (!currentWalletAddress || !currentStorageCtx.signMessage || hasEncryptionKey(currentWalletAddress)) {
|
|
33650
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
33643
33651
|
return { result: result2, queued: false };
|
|
33644
33652
|
}
|
|
33645
33653
|
if (!enableQueue) {
|
|
33646
|
-
const result2 = await directWrite();
|
|
33654
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
33647
33655
|
return { result: result2, queued: false };
|
|
33648
33656
|
}
|
|
33649
|
-
if (
|
|
33650
|
-
|
|
33651
|
-
|
|
33652
|
-
|
|
33653
|
-
|
|
33654
|
-
|
|
33657
|
+
if (currentWalletAddress) {
|
|
33658
|
+
const queueId = queueManager.queueOperation(
|
|
33659
|
+
currentWalletAddress,
|
|
33660
|
+
opType,
|
|
33661
|
+
payload,
|
|
33662
|
+
dependencies
|
|
33663
|
+
);
|
|
33655
33664
|
if (queueId === null) {
|
|
33656
33665
|
getLogger().warn("[useChatStorage] Queue full, falling back to direct write");
|
|
33657
|
-
const result2 = await directWrite();
|
|
33666
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
33658
33667
|
return { result: result2, queued: false };
|
|
33659
33668
|
}
|
|
33660
|
-
|
|
33669
|
+
setQueueStatus(queueManager.getStatus(currentWalletAddress));
|
|
33661
33670
|
return { result: makeSynthetic(), queued: true, queueId };
|
|
33662
33671
|
}
|
|
33663
|
-
const result = await directWrite();
|
|
33672
|
+
const result = await directWrite(currentStorageCtx);
|
|
33664
33673
|
return { result, queued: false };
|
|
33665
33674
|
},
|
|
33666
|
-
[
|
|
33675
|
+
[storageCtx, enableQueue, signMessage, getWalletAddress]
|
|
33667
33676
|
);
|
|
33668
33677
|
const embedMessageAsync = (0, import_react6.useCallback)(
|
|
33669
33678
|
async (message, mask = maskForEmbedding) => {
|
|
@@ -34003,7 +34012,7 @@ function useChatStorage(options) {
|
|
|
34003
34012
|
const { result, queued, queueId } = await writeOrQueue(
|
|
34004
34013
|
"createConversation",
|
|
34005
34014
|
conversationOpts,
|
|
34006
|
-
() => createConversationOp(
|
|
34015
|
+
(ctx) => createConversationOp(ctx, conversationOpts, defaultConversationTitle),
|
|
34007
34016
|
() => makeSyntheticStoredConversation(conversationOpts, defaultConversationTitle)
|
|
34008
34017
|
);
|
|
34009
34018
|
if (queued) {
|
|
@@ -34015,7 +34024,7 @@ function useChatStorage(options) {
|
|
|
34015
34024
|
setCurrentConversationId(result.conversationId);
|
|
34016
34025
|
return result;
|
|
34017
34026
|
},
|
|
34018
|
-
[
|
|
34027
|
+
[defaultConversationTitle, writeOrQueue]
|
|
34019
34028
|
);
|
|
34020
34029
|
const getConversation = (0, import_react6.useCallback)(
|
|
34021
34030
|
async (id) => {
|
|
@@ -34031,24 +34040,24 @@ function useChatStorage(options) {
|
|
|
34031
34040
|
const { result } = await writeOrQueue(
|
|
34032
34041
|
"updateConversationTitle",
|
|
34033
34042
|
{ conversationId: id, title },
|
|
34034
|
-
() => updateConversationTitleOp(
|
|
34043
|
+
(ctx) => updateConversationTitleOp(ctx, id, title),
|
|
34035
34044
|
() => true
|
|
34036
34045
|
);
|
|
34037
34046
|
return result;
|
|
34038
34047
|
},
|
|
34039
|
-
[
|
|
34048
|
+
[writeOrQueue]
|
|
34040
34049
|
);
|
|
34041
34050
|
const updateConversationPinned = (0, import_react6.useCallback)(
|
|
34042
34051
|
async (id, pinned) => {
|
|
34043
34052
|
const { result } = await writeOrQueue(
|
|
34044
34053
|
"updateConversationPinned",
|
|
34045
34054
|
{ conversationId: id, pinned },
|
|
34046
|
-
() => updateConversationPinnedOp(
|
|
34055
|
+
(ctx) => updateConversationPinnedOp(ctx, id, pinned),
|
|
34047
34056
|
() => true
|
|
34048
34057
|
);
|
|
34049
34058
|
return result;
|
|
34050
34059
|
},
|
|
34051
|
-
[
|
|
34060
|
+
[writeOrQueue]
|
|
34052
34061
|
);
|
|
34053
34062
|
const deleteConversation = (0, import_react6.useCallback)(
|
|
34054
34063
|
async (id) => {
|
|
@@ -34707,7 +34716,7 @@ function useChatStorage(options) {
|
|
|
34707
34716
|
const userMsgResult = await writeOrQueue(
|
|
34708
34717
|
"createMessage",
|
|
34709
34718
|
userMsgOpts,
|
|
34710
|
-
() => createMessageOp(
|
|
34719
|
+
(ctx) => createMessageOp(ctx, userMsgOpts),
|
|
34711
34720
|
() => makeSyntheticStoredMessage(userMsgOpts),
|
|
34712
34721
|
convId && syntheticConvQueueIdsRef.current.has(convId) ? [syntheticConvQueueIdsRef.current.get(convId)] : []
|
|
34713
34722
|
);
|
|
@@ -35028,7 +35037,7 @@ function useChatStorage(options) {
|
|
|
35028
35037
|
const assistantMsgResult = await writeOrQueue(
|
|
35029
35038
|
"createMessage",
|
|
35030
35039
|
assistantMsgOpts,
|
|
35031
|
-
() => createMessageOp(
|
|
35040
|
+
(ctx) => createMessageOp(ctx, assistantMsgOpts),
|
|
35032
35041
|
() => makeSyntheticStoredMessage(assistantMsgOpts),
|
|
35033
35042
|
userMsgQueueId ? [userMsgQueueId] : []
|
|
35034
35043
|
);
|
|
@@ -35079,7 +35088,7 @@ function useChatStorage(options) {
|
|
|
35079
35088
|
const toolResultsWrite = await writeOrQueue(
|
|
35080
35089
|
"createMessage",
|
|
35081
35090
|
toolResultsOpts,
|
|
35082
|
-
() => createMessageOp(
|
|
35091
|
+
(ctx) => createMessageOp(ctx, toolResultsOpts),
|
|
35083
35092
|
() => makeSyntheticStoredMessage(toolResultsOpts),
|
|
35084
35093
|
assistantMsgQueueId ? [assistantMsgQueueId] : []
|
|
35085
35094
|
);
|
package/dist/react/index.mjs
CHANGED
|
@@ -31583,6 +31583,8 @@ function useChatStorage(options) {
|
|
|
31583
31583
|
embeddedWalletSigner
|
|
31584
31584
|
]
|
|
31585
31585
|
);
|
|
31586
|
+
const storageCtxRef = useRef4(storageCtx);
|
|
31587
|
+
storageCtxRef.current = storageCtx;
|
|
31586
31588
|
const mediaCtx = useMemo4(
|
|
31587
31589
|
() => ({
|
|
31588
31590
|
database,
|
|
@@ -31719,14 +31721,6 @@ function useChatStorage(options) {
|
|
|
31719
31721
|
refreshQueueStatus();
|
|
31720
31722
|
return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
|
|
31721
31723
|
}, [walletAddress, refreshQueueStatus]);
|
|
31722
|
-
useEffect4(() => {
|
|
31723
|
-
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
31724
|
-
return onKeyAvailable(walletAddress, () => {
|
|
31725
|
-
flushQueue().catch((err) => {
|
|
31726
|
-
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
31727
|
-
});
|
|
31728
|
-
});
|
|
31729
|
-
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
31730
31724
|
useEffect4(() => {
|
|
31731
31725
|
if (!getWalletAddress || walletAddress) return;
|
|
31732
31726
|
const poller = new WalletPoller();
|
|
@@ -31750,34 +31744,49 @@ function useChatStorage(options) {
|
|
|
31750
31744
|
pendingOpsRef.current = [];
|
|
31751
31745
|
refreshQueueStatus();
|
|
31752
31746
|
}, [walletAddress, enableQueue, refreshQueueStatus]);
|
|
31747
|
+
useEffect4(() => {
|
|
31748
|
+
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
31749
|
+
return onKeyAvailable(walletAddress, () => {
|
|
31750
|
+
flushQueue().catch((err) => {
|
|
31751
|
+
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
31752
|
+
});
|
|
31753
|
+
});
|
|
31754
|
+
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
31753
31755
|
const writeOrQueue = useCallback5(
|
|
31754
31756
|
async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
|
|
31755
|
-
|
|
31756
|
-
|
|
31757
|
+
const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
|
|
31758
|
+
const currentWalletAddress = currentStorageCtx.walletAddress;
|
|
31759
|
+
if (enableQueue && signMessage && !currentWalletAddress && getWalletAddress) {
|
|
31760
|
+
pendingOpsRef.current.push({ type: opType, payload, dependencies });
|
|
31761
|
+
return { result: makeSynthetic(), queued: true };
|
|
31762
|
+
}
|
|
31763
|
+
if (!currentWalletAddress || !currentStorageCtx.signMessage || hasEncryptionKey(currentWalletAddress)) {
|
|
31764
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
31757
31765
|
return { result: result2, queued: false };
|
|
31758
31766
|
}
|
|
31759
31767
|
if (!enableQueue) {
|
|
31760
|
-
const result2 = await directWrite();
|
|
31768
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
31761
31769
|
return { result: result2, queued: false };
|
|
31762
31770
|
}
|
|
31763
|
-
if (
|
|
31764
|
-
|
|
31765
|
-
|
|
31766
|
-
|
|
31767
|
-
|
|
31768
|
-
|
|
31771
|
+
if (currentWalletAddress) {
|
|
31772
|
+
const queueId = queueManager.queueOperation(
|
|
31773
|
+
currentWalletAddress,
|
|
31774
|
+
opType,
|
|
31775
|
+
payload,
|
|
31776
|
+
dependencies
|
|
31777
|
+
);
|
|
31769
31778
|
if (queueId === null) {
|
|
31770
31779
|
getLogger().warn("[useChatStorage] Queue full, falling back to direct write");
|
|
31771
|
-
const result2 = await directWrite();
|
|
31780
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
31772
31781
|
return { result: result2, queued: false };
|
|
31773
31782
|
}
|
|
31774
|
-
|
|
31783
|
+
setQueueStatus(queueManager.getStatus(currentWalletAddress));
|
|
31775
31784
|
return { result: makeSynthetic(), queued: true, queueId };
|
|
31776
31785
|
}
|
|
31777
|
-
const result = await directWrite();
|
|
31786
|
+
const result = await directWrite(currentStorageCtx);
|
|
31778
31787
|
return { result, queued: false };
|
|
31779
31788
|
},
|
|
31780
|
-
[
|
|
31789
|
+
[storageCtx, enableQueue, signMessage, getWalletAddress]
|
|
31781
31790
|
);
|
|
31782
31791
|
const embedMessageAsync = useCallback5(
|
|
31783
31792
|
async (message, mask = maskForEmbedding) => {
|
|
@@ -32117,7 +32126,7 @@ function useChatStorage(options) {
|
|
|
32117
32126
|
const { result, queued, queueId } = await writeOrQueue(
|
|
32118
32127
|
"createConversation",
|
|
32119
32128
|
conversationOpts,
|
|
32120
|
-
() => createConversationOp(
|
|
32129
|
+
(ctx) => createConversationOp(ctx, conversationOpts, defaultConversationTitle),
|
|
32121
32130
|
() => makeSyntheticStoredConversation(conversationOpts, defaultConversationTitle)
|
|
32122
32131
|
);
|
|
32123
32132
|
if (queued) {
|
|
@@ -32129,7 +32138,7 @@ function useChatStorage(options) {
|
|
|
32129
32138
|
setCurrentConversationId(result.conversationId);
|
|
32130
32139
|
return result;
|
|
32131
32140
|
},
|
|
32132
|
-
[
|
|
32141
|
+
[defaultConversationTitle, writeOrQueue]
|
|
32133
32142
|
);
|
|
32134
32143
|
const getConversation = useCallback5(
|
|
32135
32144
|
async (id) => {
|
|
@@ -32145,24 +32154,24 @@ function useChatStorage(options) {
|
|
|
32145
32154
|
const { result } = await writeOrQueue(
|
|
32146
32155
|
"updateConversationTitle",
|
|
32147
32156
|
{ conversationId: id, title },
|
|
32148
|
-
() => updateConversationTitleOp(
|
|
32157
|
+
(ctx) => updateConversationTitleOp(ctx, id, title),
|
|
32149
32158
|
() => true
|
|
32150
32159
|
);
|
|
32151
32160
|
return result;
|
|
32152
32161
|
},
|
|
32153
|
-
[
|
|
32162
|
+
[writeOrQueue]
|
|
32154
32163
|
);
|
|
32155
32164
|
const updateConversationPinned = useCallback5(
|
|
32156
32165
|
async (id, pinned) => {
|
|
32157
32166
|
const { result } = await writeOrQueue(
|
|
32158
32167
|
"updateConversationPinned",
|
|
32159
32168
|
{ conversationId: id, pinned },
|
|
32160
|
-
() => updateConversationPinnedOp(
|
|
32169
|
+
(ctx) => updateConversationPinnedOp(ctx, id, pinned),
|
|
32161
32170
|
() => true
|
|
32162
32171
|
);
|
|
32163
32172
|
return result;
|
|
32164
32173
|
},
|
|
32165
|
-
[
|
|
32174
|
+
[writeOrQueue]
|
|
32166
32175
|
);
|
|
32167
32176
|
const deleteConversation = useCallback5(
|
|
32168
32177
|
async (id) => {
|
|
@@ -32821,7 +32830,7 @@ function useChatStorage(options) {
|
|
|
32821
32830
|
const userMsgResult = await writeOrQueue(
|
|
32822
32831
|
"createMessage",
|
|
32823
32832
|
userMsgOpts,
|
|
32824
|
-
() => createMessageOp(
|
|
32833
|
+
(ctx) => createMessageOp(ctx, userMsgOpts),
|
|
32825
32834
|
() => makeSyntheticStoredMessage(userMsgOpts),
|
|
32826
32835
|
convId && syntheticConvQueueIdsRef.current.has(convId) ? [syntheticConvQueueIdsRef.current.get(convId)] : []
|
|
32827
32836
|
);
|
|
@@ -33142,7 +33151,7 @@ function useChatStorage(options) {
|
|
|
33142
33151
|
const assistantMsgResult = await writeOrQueue(
|
|
33143
33152
|
"createMessage",
|
|
33144
33153
|
assistantMsgOpts,
|
|
33145
|
-
() => createMessageOp(
|
|
33154
|
+
(ctx) => createMessageOp(ctx, assistantMsgOpts),
|
|
33146
33155
|
() => makeSyntheticStoredMessage(assistantMsgOpts),
|
|
33147
33156
|
userMsgQueueId ? [userMsgQueueId] : []
|
|
33148
33157
|
);
|
|
@@ -33193,7 +33202,7 @@ function useChatStorage(options) {
|
|
|
33193
33202
|
const toolResultsWrite = await writeOrQueue(
|
|
33194
33203
|
"createMessage",
|
|
33195
33204
|
toolResultsOpts,
|
|
33196
|
-
() => createMessageOp(
|
|
33205
|
+
(ctx) => createMessageOp(ctx, toolResultsOpts),
|
|
33197
33206
|
() => makeSyntheticStoredMessage(toolResultsOpts),
|
|
33198
33207
|
assistantMsgQueueId ? [assistantMsgQueueId] : []
|
|
33199
33208
|
);
|