@reverbia/sdk 1.0.0-next.20251205064608 → 1.0.0-next.20251205130522
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/react/index.cjs +74 -95
- package/dist/react/index.d.mts +28 -5
- package/dist/react/index.d.ts +28 -5
- package/dist/react/index.mjs +53 -76
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -47109,6 +47109,8 @@ __export(index_exports, {
|
|
|
47109
47109
|
executeTool: () => executeTool,
|
|
47110
47110
|
extractConversationContext: () => extractConversationContext,
|
|
47111
47111
|
formatMemoriesForChat: () => formatMemoriesForChat,
|
|
47112
|
+
hasEncryptionKey: () => hasEncryptionKey,
|
|
47113
|
+
requestEncryptionKey: () => requestEncryptionKey,
|
|
47112
47114
|
selectTool: () => selectTool,
|
|
47113
47115
|
useChat: () => useChat,
|
|
47114
47116
|
useEncryption: () => useEncryption,
|
|
@@ -48479,10 +48481,11 @@ Please inform the user about this issue and try to help them alternatively.`
|
|
|
48479
48481
|
}
|
|
48480
48482
|
|
|
48481
48483
|
// src/react/useEncryption.ts
|
|
48482
|
-
var import_react2 = require("react");
|
|
48483
|
-
var import_react_auth = require("@privy-io/react-auth");
|
|
48484
48484
|
var SIGN_MESSAGE = "The app is asking you to sign this message to generate a key, which will be used to encrypt data.";
|
|
48485
|
-
var
|
|
48485
|
+
var BASE_SIGNATURE_STORAGE_KEY = "privy_encryption_key";
|
|
48486
|
+
function getStorageKey(address) {
|
|
48487
|
+
return `${BASE_SIGNATURE_STORAGE_KEY}_${address}`;
|
|
48488
|
+
}
|
|
48486
48489
|
function getStorageItem(key) {
|
|
48487
48490
|
if (typeof window === "undefined" || !window.localStorage) {
|
|
48488
48491
|
return null;
|
|
@@ -48524,8 +48527,9 @@ async function deriveKeyFromSignature(signature) {
|
|
|
48524
48527
|
const hashBytes = new Uint8Array(hashBuffer);
|
|
48525
48528
|
return bytesToHex(hashBytes);
|
|
48526
48529
|
}
|
|
48527
|
-
async function getEncryptionKey() {
|
|
48528
|
-
const
|
|
48530
|
+
async function getEncryptionKey(address) {
|
|
48531
|
+
const storageKey = getStorageKey(address);
|
|
48532
|
+
const keyHex = getStorageItem(storageKey);
|
|
48529
48533
|
if (!keyHex) {
|
|
48530
48534
|
throw new Error("Encryption key not found. Please sign in first.");
|
|
48531
48535
|
}
|
|
@@ -48538,8 +48542,8 @@ async function getEncryptionKey() {
|
|
|
48538
48542
|
["encrypt", "decrypt"]
|
|
48539
48543
|
);
|
|
48540
48544
|
}
|
|
48541
|
-
async function encryptData(plaintext) {
|
|
48542
|
-
const key = await getEncryptionKey();
|
|
48545
|
+
async function encryptData(plaintext, address) {
|
|
48546
|
+
const key = await getEncryptionKey(address);
|
|
48543
48547
|
const plaintextBytes = typeof plaintext === "string" ? new TextEncoder().encode(plaintext) : plaintext;
|
|
48544
48548
|
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
48545
48549
|
const encryptedData = await crypto.subtle.encrypt(
|
|
@@ -48556,8 +48560,8 @@ async function encryptData(plaintext) {
|
|
|
48556
48560
|
combined.set(encryptedBytes, iv.length);
|
|
48557
48561
|
return bytesToHex(combined);
|
|
48558
48562
|
}
|
|
48559
|
-
async function decryptData(encryptedHex) {
|
|
48560
|
-
const key = await getEncryptionKey();
|
|
48563
|
+
async function decryptData(encryptedHex, address) {
|
|
48564
|
+
const key = await getEncryptionKey(address);
|
|
48561
48565
|
const combined = hexToBytes(encryptedHex);
|
|
48562
48566
|
const iv = combined.slice(0, 12);
|
|
48563
48567
|
const encryptedData = combined.slice(12);
|
|
@@ -48571,8 +48575,8 @@ async function decryptData(encryptedHex) {
|
|
|
48571
48575
|
);
|
|
48572
48576
|
return new TextDecoder().decode(decryptedData);
|
|
48573
48577
|
}
|
|
48574
|
-
async function decryptDataBytes(encryptedHex) {
|
|
48575
|
-
const key = await getEncryptionKey();
|
|
48578
|
+
async function decryptDataBytes(encryptedHex, address) {
|
|
48579
|
+
const key = await getEncryptionKey(address);
|
|
48576
48580
|
const combined = hexToBytes(encryptedHex);
|
|
48577
48581
|
const iv = combined.slice(0, 12);
|
|
48578
48582
|
const encryptedData = combined.slice(12);
|
|
@@ -48586,58 +48590,31 @@ async function decryptDataBytes(encryptedHex) {
|
|
|
48586
48590
|
);
|
|
48587
48591
|
return new Uint8Array(decryptedData);
|
|
48588
48592
|
}
|
|
48589
|
-
function
|
|
48590
|
-
const
|
|
48591
|
-
|
|
48592
|
-
|
|
48593
|
-
|
|
48594
|
-
|
|
48595
|
-
|
|
48596
|
-
|
|
48597
|
-
|
|
48598
|
-
|
|
48599
|
-
|
|
48600
|
-
|
|
48601
|
-
|
|
48602
|
-
|
|
48603
|
-
|
|
48604
|
-
|
|
48605
|
-
|
|
48606
|
-
|
|
48607
|
-
|
|
48608
|
-
|
|
48609
|
-
|
|
48610
|
-
{ message: SIGN_MESSAGE },
|
|
48611
|
-
{
|
|
48612
|
-
address: wallets[0].address
|
|
48613
|
-
}
|
|
48614
|
-
);
|
|
48615
|
-
const encryptionKey = await deriveKeyFromSignature(signature);
|
|
48616
|
-
const stored = setStorageItem(SIGNATURE_STORAGE_KEY, encryptionKey);
|
|
48617
|
-
if (!stored) {
|
|
48618
|
-
throw new Error("Failed to store encryption key in localStorage");
|
|
48619
|
-
}
|
|
48620
|
-
} catch (error) {
|
|
48621
|
-
hasRequestedSignature.current = false;
|
|
48622
|
-
}
|
|
48623
|
-
}
|
|
48624
|
-
};
|
|
48625
|
-
requestSignature();
|
|
48626
|
-
}, [
|
|
48627
|
-
authenticated,
|
|
48628
|
-
wallets.length > 0 ? wallets[0]?.address : null,
|
|
48629
|
-
signMessage
|
|
48630
|
-
]);
|
|
48631
|
-
(0, import_react2.useEffect)(() => {
|
|
48632
|
-
if (!authenticated) {
|
|
48633
|
-
hasRequestedSignature.current = false;
|
|
48634
|
-
hasCheckedStorage.current = false;
|
|
48635
|
-
}
|
|
48636
|
-
}, [authenticated]);
|
|
48593
|
+
function hasEncryptionKey(address) {
|
|
48594
|
+
const storageKey = getStorageKey(address);
|
|
48595
|
+
return getStorageItem(storageKey) !== null;
|
|
48596
|
+
}
|
|
48597
|
+
async function requestEncryptionKey(walletAddress, signMessage) {
|
|
48598
|
+
const storageKey = getStorageKey(walletAddress);
|
|
48599
|
+
const existingKey = getStorageItem(storageKey);
|
|
48600
|
+
if (existingKey) {
|
|
48601
|
+
return;
|
|
48602
|
+
}
|
|
48603
|
+
const signature = await signMessage(SIGN_MESSAGE);
|
|
48604
|
+
const encryptionKey = await deriveKeyFromSignature(signature);
|
|
48605
|
+
const stored = setStorageItem(storageKey, encryptionKey);
|
|
48606
|
+
if (!stored) {
|
|
48607
|
+
throw new Error("Failed to store encryption key in localStorage");
|
|
48608
|
+
}
|
|
48609
|
+
}
|
|
48610
|
+
function useEncryption(signMessage) {
|
|
48611
|
+
return {
|
|
48612
|
+
requestEncryptionKey: (walletAddress) => requestEncryptionKey(walletAddress, signMessage)
|
|
48613
|
+
};
|
|
48637
48614
|
}
|
|
48638
48615
|
|
|
48639
48616
|
// src/react/useMemory.ts
|
|
48640
|
-
var
|
|
48617
|
+
var import_react2 = require("react");
|
|
48641
48618
|
var import_client6 = require("@reverbia/sdk");
|
|
48642
48619
|
|
|
48643
48620
|
// src/lib/memory/service.ts
|
|
@@ -49035,8 +49012,8 @@ function useMemory(options = {}) {
|
|
|
49035
49012
|
baseUrl = BASE_URL
|
|
49036
49013
|
} = options;
|
|
49037
49014
|
const embeddingModel = userEmbeddingModel === void 0 ? embeddingProvider === "local" ? DEFAULT_LOCAL_EMBEDDING_MODEL : DEFAULT_API_EMBEDDING_MODEL : userEmbeddingModel;
|
|
49038
|
-
const extractionInProgressRef = (0,
|
|
49039
|
-
const extractMemoriesFromMessage = (0,
|
|
49015
|
+
const extractionInProgressRef = (0, import_react2.useRef)(false);
|
|
49016
|
+
const extractMemoriesFromMessage = (0, import_react2.useCallback)(
|
|
49040
49017
|
async (options2) => {
|
|
49041
49018
|
const { messages, model } = options2;
|
|
49042
49019
|
if (!getToken || extractionInProgressRef.current) {
|
|
@@ -49219,7 +49196,7 @@ function useMemory(options = {}) {
|
|
|
49219
49196
|
baseUrl
|
|
49220
49197
|
]
|
|
49221
49198
|
);
|
|
49222
|
-
const searchMemories = (0,
|
|
49199
|
+
const searchMemories = (0, import_react2.useCallback)(
|
|
49223
49200
|
async (query, limit = 10, minSimilarity = 0.6) => {
|
|
49224
49201
|
if (!embeddingModel) {
|
|
49225
49202
|
console.warn("Cannot search memories: embeddingModel not provided");
|
|
@@ -49265,7 +49242,7 @@ function useMemory(options = {}) {
|
|
|
49265
49242
|
}
|
|
49266
49243
|
|
|
49267
49244
|
// src/react/usePdf.ts
|
|
49268
|
-
var
|
|
49245
|
+
var import_react3 = require("react");
|
|
49269
49246
|
|
|
49270
49247
|
// src/lib/pdf.ts
|
|
49271
49248
|
var pdfjs = __toESM(require("pdfjs-dist"));
|
|
@@ -49293,9 +49270,9 @@ async function extractTextFromPdf(pdfDataUrl) {
|
|
|
49293
49270
|
// src/react/usePdf.ts
|
|
49294
49271
|
var PDF_MIME_TYPE = "application/pdf";
|
|
49295
49272
|
function usePdf() {
|
|
49296
|
-
const [isProcessing, setIsProcessing] = (0,
|
|
49297
|
-
const [error, setError] = (0,
|
|
49298
|
-
const extractPdfContext = (0,
|
|
49273
|
+
const [isProcessing, setIsProcessing] = (0, import_react3.useState)(false);
|
|
49274
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
49275
|
+
const extractPdfContext = (0, import_react3.useCallback)(
|
|
49299
49276
|
async (files) => {
|
|
49300
49277
|
setIsProcessing(true);
|
|
49301
49278
|
setError(null);
|
|
@@ -49342,22 +49319,22 @@ ${text}`;
|
|
|
49342
49319
|
}
|
|
49343
49320
|
|
|
49344
49321
|
// src/react/useModels.ts
|
|
49345
|
-
var
|
|
49322
|
+
var import_react4 = require("react");
|
|
49346
49323
|
function useModels(options = {}) {
|
|
49347
49324
|
const { getToken, baseUrl = BASE_URL, provider, autoFetch = true } = options;
|
|
49348
|
-
const [models, setModels] = (0,
|
|
49349
|
-
const [isLoading, setIsLoading] = (0,
|
|
49350
|
-
const [error, setError] = (0,
|
|
49351
|
-
const getTokenRef = (0,
|
|
49352
|
-
const baseUrlRef = (0,
|
|
49353
|
-
const providerRef = (0,
|
|
49354
|
-
const abortControllerRef = (0,
|
|
49355
|
-
(0,
|
|
49325
|
+
const [models, setModels] = (0, import_react4.useState)([]);
|
|
49326
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
49327
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
49328
|
+
const getTokenRef = (0, import_react4.useRef)(getToken);
|
|
49329
|
+
const baseUrlRef = (0, import_react4.useRef)(baseUrl);
|
|
49330
|
+
const providerRef = (0, import_react4.useRef)(provider);
|
|
49331
|
+
const abortControllerRef = (0, import_react4.useRef)(null);
|
|
49332
|
+
(0, import_react4.useEffect)(() => {
|
|
49356
49333
|
getTokenRef.current = getToken;
|
|
49357
49334
|
baseUrlRef.current = baseUrl;
|
|
49358
49335
|
providerRef.current = provider;
|
|
49359
49336
|
});
|
|
49360
|
-
(0,
|
|
49337
|
+
(0, import_react4.useEffect)(() => {
|
|
49361
49338
|
return () => {
|
|
49362
49339
|
if (abortControllerRef.current) {
|
|
49363
49340
|
abortControllerRef.current.abort();
|
|
@@ -49365,7 +49342,7 @@ function useModels(options = {}) {
|
|
|
49365
49342
|
}
|
|
49366
49343
|
};
|
|
49367
49344
|
}, []);
|
|
49368
|
-
const fetchModels = (0,
|
|
49345
|
+
const fetchModels = (0, import_react4.useCallback)(async () => {
|
|
49369
49346
|
if (abortControllerRef.current) {
|
|
49370
49347
|
abortControllerRef.current.abort();
|
|
49371
49348
|
}
|
|
@@ -49423,12 +49400,12 @@ function useModels(options = {}) {
|
|
|
49423
49400
|
}
|
|
49424
49401
|
}
|
|
49425
49402
|
}, []);
|
|
49426
|
-
const refetch = (0,
|
|
49403
|
+
const refetch = (0, import_react4.useCallback)(async () => {
|
|
49427
49404
|
setModels([]);
|
|
49428
49405
|
await fetchModels();
|
|
49429
49406
|
}, [fetchModels]);
|
|
49430
|
-
const hasFetchedRef = (0,
|
|
49431
|
-
(0,
|
|
49407
|
+
const hasFetchedRef = (0, import_react4.useRef)(false);
|
|
49408
|
+
(0, import_react4.useEffect)(() => {
|
|
49432
49409
|
if (autoFetch && !hasFetchedRef.current) {
|
|
49433
49410
|
hasFetchedRef.current = true;
|
|
49434
49411
|
fetchModels();
|
|
@@ -49446,15 +49423,15 @@ function useModels(options = {}) {
|
|
|
49446
49423
|
}
|
|
49447
49424
|
|
|
49448
49425
|
// src/react/useSearch.ts
|
|
49449
|
-
var
|
|
49426
|
+
var import_react5 = require("react");
|
|
49450
49427
|
function useSearch(options = {}) {
|
|
49451
49428
|
const { getToken, baseUrl = BASE_URL, onError } = options;
|
|
49452
|
-
const [isLoading, setIsLoading] = (0,
|
|
49453
|
-
const [results, setResults] = (0,
|
|
49454
|
-
const [response, setResponse] = (0,
|
|
49455
|
-
const [error, setError] = (0,
|
|
49456
|
-
const abortControllerRef = (0,
|
|
49457
|
-
(0,
|
|
49429
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
49430
|
+
const [results, setResults] = (0, import_react5.useState)(null);
|
|
49431
|
+
const [response, setResponse] = (0, import_react5.useState)(null);
|
|
49432
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
49433
|
+
const abortControllerRef = (0, import_react5.useRef)(null);
|
|
49434
|
+
(0, import_react5.useEffect)(() => {
|
|
49458
49435
|
return () => {
|
|
49459
49436
|
if (abortControllerRef.current) {
|
|
49460
49437
|
abortControllerRef.current.abort();
|
|
@@ -49462,7 +49439,7 @@ function useSearch(options = {}) {
|
|
|
49462
49439
|
}
|
|
49463
49440
|
};
|
|
49464
49441
|
}, []);
|
|
49465
|
-
const search = (0,
|
|
49442
|
+
const search = (0, import_react5.useCallback)(
|
|
49466
49443
|
async (query, searchOptions = {}) => {
|
|
49467
49444
|
if (abortControllerRef.current) {
|
|
49468
49445
|
abortControllerRef.current.abort();
|
|
@@ -49530,12 +49507,12 @@ function useSearch(options = {}) {
|
|
|
49530
49507
|
}
|
|
49531
49508
|
|
|
49532
49509
|
// src/react/useImageGeneration.ts
|
|
49533
|
-
var
|
|
49510
|
+
var import_react6 = require("react");
|
|
49534
49511
|
function useImageGeneration(options = {}) {
|
|
49535
49512
|
const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
|
|
49536
|
-
const [isLoading, setIsLoading] = (0,
|
|
49537
|
-
const abortControllerRef = (0,
|
|
49538
|
-
(0,
|
|
49513
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
49514
|
+
const abortControllerRef = (0, import_react6.useRef)(null);
|
|
49515
|
+
(0, import_react6.useEffect)(() => {
|
|
49539
49516
|
return () => {
|
|
49540
49517
|
if (abortControllerRef.current) {
|
|
49541
49518
|
abortControllerRef.current.abort();
|
|
@@ -49543,13 +49520,13 @@ function useImageGeneration(options = {}) {
|
|
|
49543
49520
|
}
|
|
49544
49521
|
};
|
|
49545
49522
|
}, []);
|
|
49546
|
-
const stop = (0,
|
|
49523
|
+
const stop = (0, import_react6.useCallback)(() => {
|
|
49547
49524
|
if (abortControllerRef.current) {
|
|
49548
49525
|
abortControllerRef.current.abort();
|
|
49549
49526
|
abortControllerRef.current = null;
|
|
49550
49527
|
}
|
|
49551
49528
|
}, []);
|
|
49552
|
-
const generateImage = (0,
|
|
49529
|
+
const generateImage = (0, import_react6.useCallback)(
|
|
49553
49530
|
async (args) => {
|
|
49554
49531
|
if (abortControllerRef.current) {
|
|
49555
49532
|
abortControllerRef.current.abort();
|
|
@@ -49675,6 +49652,8 @@ var extractConversationContext = (messages, maxMessages = 3) => {
|
|
|
49675
49652
|
executeTool,
|
|
49676
49653
|
extractConversationContext,
|
|
49677
49654
|
formatMemoriesForChat,
|
|
49655
|
+
hasEncryptionKey,
|
|
49656
|
+
requestEncryptionKey,
|
|
49678
49657
|
selectTool,
|
|
49679
49658
|
useChat,
|
|
49680
49659
|
useEncryption,
|
package/dist/react/index.d.mts
CHANGED
|
@@ -585,20 +585,43 @@ declare function useChat(options?: UseChatOptions): UseChatResult;
|
|
|
585
585
|
* @param plaintext - The data to encrypt (string or Uint8Array)
|
|
586
586
|
* @returns Encrypted data as hex string (IV + ciphertext + auth tag)
|
|
587
587
|
*/
|
|
588
|
-
declare function encryptData(plaintext: string | Uint8Array): Promise<string>;
|
|
588
|
+
declare function encryptData(plaintext: string | Uint8Array, address: string): Promise<string>;
|
|
589
589
|
/**
|
|
590
590
|
* Decrypts data using AES-GCM with the stored encryption key
|
|
591
591
|
* @param encryptedHex - Encrypted data as hex string (IV + ciphertext + auth tag)
|
|
592
592
|
* @returns Decrypted data as string
|
|
593
593
|
*/
|
|
594
|
-
declare function decryptData(encryptedHex: string): Promise<string>;
|
|
594
|
+
declare function decryptData(encryptedHex: string, address: string): Promise<string>;
|
|
595
595
|
/**
|
|
596
596
|
* Decrypts data and returns as Uint8Array (for binary data)
|
|
597
597
|
* @param encryptedHex - Encrypted data as hex string (IV + ciphertext + auth tag)
|
|
598
598
|
* @returns Decrypted data as Uint8Array
|
|
599
599
|
*/
|
|
600
|
-
declare function decryptDataBytes(encryptedHex: string): Promise<Uint8Array>;
|
|
601
|
-
|
|
600
|
+
declare function decryptDataBytes(encryptedHex: string, address: string): Promise<Uint8Array>;
|
|
601
|
+
/**
|
|
602
|
+
* Checks if an encryption key exists for the given wallet address
|
|
603
|
+
*/
|
|
604
|
+
declare function hasEncryptionKey(address: string): boolean;
|
|
605
|
+
/**
|
|
606
|
+
* Type for the signMessage function that client must provide
|
|
607
|
+
*/
|
|
608
|
+
type SignMessageFn = (message: string) => Promise<string>;
|
|
609
|
+
/**
|
|
610
|
+
* Requests the user to sign a message to generate an encryption key.
|
|
611
|
+
* If a key already exists for the given wallet, resolves immediately.
|
|
612
|
+
* @param walletAddress - The wallet address to generate the key for
|
|
613
|
+
* @param signMessage - Function to sign a message (returns signature hex string)
|
|
614
|
+
* @returns Promise that resolves when the key is available
|
|
615
|
+
*/
|
|
616
|
+
declare function requestEncryptionKey(walletAddress: string, signMessage: SignMessageFn): Promise<void>;
|
|
617
|
+
/**
|
|
618
|
+
* Hook that provides on-demand encryption key management.
|
|
619
|
+
* @param signMessage - Function to sign a message (from Privy's useSignMessage)
|
|
620
|
+
* @returns Functions to request encryption keys
|
|
621
|
+
*/
|
|
622
|
+
declare function useEncryption(signMessage: SignMessageFn): {
|
|
623
|
+
requestEncryptionKey: (walletAddress: string) => Promise<void>;
|
|
624
|
+
};
|
|
602
625
|
|
|
603
626
|
interface MemoryItem {
|
|
604
627
|
type: "identity" | "preference" | "project" | "skill" | "constraint";
|
|
@@ -857,4 +880,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
|
|
|
857
880
|
error?: string;
|
|
858
881
|
}>;
|
|
859
882
|
|
|
860
|
-
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type PdfFile, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, usePdf, useSearch };
|
|
883
|
+
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type PdfFile, type SignMessageFn, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, hasEncryptionKey, requestEncryptionKey, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, usePdf, useSearch };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -585,20 +585,43 @@ declare function useChat(options?: UseChatOptions): UseChatResult;
|
|
|
585
585
|
* @param plaintext - The data to encrypt (string or Uint8Array)
|
|
586
586
|
* @returns Encrypted data as hex string (IV + ciphertext + auth tag)
|
|
587
587
|
*/
|
|
588
|
-
declare function encryptData(plaintext: string | Uint8Array): Promise<string>;
|
|
588
|
+
declare function encryptData(plaintext: string | Uint8Array, address: string): Promise<string>;
|
|
589
589
|
/**
|
|
590
590
|
* Decrypts data using AES-GCM with the stored encryption key
|
|
591
591
|
* @param encryptedHex - Encrypted data as hex string (IV + ciphertext + auth tag)
|
|
592
592
|
* @returns Decrypted data as string
|
|
593
593
|
*/
|
|
594
|
-
declare function decryptData(encryptedHex: string): Promise<string>;
|
|
594
|
+
declare function decryptData(encryptedHex: string, address: string): Promise<string>;
|
|
595
595
|
/**
|
|
596
596
|
* Decrypts data and returns as Uint8Array (for binary data)
|
|
597
597
|
* @param encryptedHex - Encrypted data as hex string (IV + ciphertext + auth tag)
|
|
598
598
|
* @returns Decrypted data as Uint8Array
|
|
599
599
|
*/
|
|
600
|
-
declare function decryptDataBytes(encryptedHex: string): Promise<Uint8Array>;
|
|
601
|
-
|
|
600
|
+
declare function decryptDataBytes(encryptedHex: string, address: string): Promise<Uint8Array>;
|
|
601
|
+
/**
|
|
602
|
+
* Checks if an encryption key exists for the given wallet address
|
|
603
|
+
*/
|
|
604
|
+
declare function hasEncryptionKey(address: string): boolean;
|
|
605
|
+
/**
|
|
606
|
+
* Type for the signMessage function that client must provide
|
|
607
|
+
*/
|
|
608
|
+
type SignMessageFn = (message: string) => Promise<string>;
|
|
609
|
+
/**
|
|
610
|
+
* Requests the user to sign a message to generate an encryption key.
|
|
611
|
+
* If a key already exists for the given wallet, resolves immediately.
|
|
612
|
+
* @param walletAddress - The wallet address to generate the key for
|
|
613
|
+
* @param signMessage - Function to sign a message (returns signature hex string)
|
|
614
|
+
* @returns Promise that resolves when the key is available
|
|
615
|
+
*/
|
|
616
|
+
declare function requestEncryptionKey(walletAddress: string, signMessage: SignMessageFn): Promise<void>;
|
|
617
|
+
/**
|
|
618
|
+
* Hook that provides on-demand encryption key management.
|
|
619
|
+
* @param signMessage - Function to sign a message (from Privy's useSignMessage)
|
|
620
|
+
* @returns Functions to request encryption keys
|
|
621
|
+
*/
|
|
622
|
+
declare function useEncryption(signMessage: SignMessageFn): {
|
|
623
|
+
requestEncryptionKey: (walletAddress: string) => Promise<void>;
|
|
624
|
+
};
|
|
602
625
|
|
|
603
626
|
interface MemoryItem {
|
|
604
627
|
type: "identity" | "preference" | "project" | "skill" | "constraint";
|
|
@@ -857,4 +880,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
|
|
|
857
880
|
error?: string;
|
|
858
881
|
}>;
|
|
859
882
|
|
|
860
|
-
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type PdfFile, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, usePdf, useSearch };
|
|
883
|
+
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type PdfFile, type SignMessageFn, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, hasEncryptionKey, requestEncryptionKey, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels, usePdf, useSearch };
|
package/dist/react/index.mjs
CHANGED
|
@@ -1359,10 +1359,11 @@ Please inform the user about this issue and try to help them alternatively.`
|
|
|
1359
1359
|
}
|
|
1360
1360
|
|
|
1361
1361
|
// src/react/useEncryption.ts
|
|
1362
|
-
import { useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
1363
|
-
import { useSignMessage, useWallets } from "@privy-io/react-auth";
|
|
1364
1362
|
var SIGN_MESSAGE = "The app is asking you to sign this message to generate a key, which will be used to encrypt data.";
|
|
1365
|
-
var
|
|
1363
|
+
var BASE_SIGNATURE_STORAGE_KEY = "privy_encryption_key";
|
|
1364
|
+
function getStorageKey(address) {
|
|
1365
|
+
return `${BASE_SIGNATURE_STORAGE_KEY}_${address}`;
|
|
1366
|
+
}
|
|
1366
1367
|
function getStorageItem(key) {
|
|
1367
1368
|
if (typeof window === "undefined" || !window.localStorage) {
|
|
1368
1369
|
return null;
|
|
@@ -1404,8 +1405,9 @@ async function deriveKeyFromSignature(signature) {
|
|
|
1404
1405
|
const hashBytes = new Uint8Array(hashBuffer);
|
|
1405
1406
|
return bytesToHex(hashBytes);
|
|
1406
1407
|
}
|
|
1407
|
-
async function getEncryptionKey() {
|
|
1408
|
-
const
|
|
1408
|
+
async function getEncryptionKey(address) {
|
|
1409
|
+
const storageKey = getStorageKey(address);
|
|
1410
|
+
const keyHex = getStorageItem(storageKey);
|
|
1409
1411
|
if (!keyHex) {
|
|
1410
1412
|
throw new Error("Encryption key not found. Please sign in first.");
|
|
1411
1413
|
}
|
|
@@ -1418,8 +1420,8 @@ async function getEncryptionKey() {
|
|
|
1418
1420
|
["encrypt", "decrypt"]
|
|
1419
1421
|
);
|
|
1420
1422
|
}
|
|
1421
|
-
async function encryptData(plaintext) {
|
|
1422
|
-
const key = await getEncryptionKey();
|
|
1423
|
+
async function encryptData(plaintext, address) {
|
|
1424
|
+
const key = await getEncryptionKey(address);
|
|
1423
1425
|
const plaintextBytes = typeof plaintext === "string" ? new TextEncoder().encode(plaintext) : plaintext;
|
|
1424
1426
|
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
1425
1427
|
const encryptedData = await crypto.subtle.encrypt(
|
|
@@ -1436,8 +1438,8 @@ async function encryptData(plaintext) {
|
|
|
1436
1438
|
combined.set(encryptedBytes, iv.length);
|
|
1437
1439
|
return bytesToHex(combined);
|
|
1438
1440
|
}
|
|
1439
|
-
async function decryptData(encryptedHex) {
|
|
1440
|
-
const key = await getEncryptionKey();
|
|
1441
|
+
async function decryptData(encryptedHex, address) {
|
|
1442
|
+
const key = await getEncryptionKey(address);
|
|
1441
1443
|
const combined = hexToBytes(encryptedHex);
|
|
1442
1444
|
const iv = combined.slice(0, 12);
|
|
1443
1445
|
const encryptedData = combined.slice(12);
|
|
@@ -1451,8 +1453,8 @@ async function decryptData(encryptedHex) {
|
|
|
1451
1453
|
);
|
|
1452
1454
|
return new TextDecoder().decode(decryptedData);
|
|
1453
1455
|
}
|
|
1454
|
-
async function decryptDataBytes(encryptedHex) {
|
|
1455
|
-
const key = await getEncryptionKey();
|
|
1456
|
+
async function decryptDataBytes(encryptedHex, address) {
|
|
1457
|
+
const key = await getEncryptionKey(address);
|
|
1456
1458
|
const combined = hexToBytes(encryptedHex);
|
|
1457
1459
|
const iv = combined.slice(0, 12);
|
|
1458
1460
|
const encryptedData = combined.slice(12);
|
|
@@ -1466,58 +1468,31 @@ async function decryptDataBytes(encryptedHex) {
|
|
|
1466
1468
|
);
|
|
1467
1469
|
return new Uint8Array(decryptedData);
|
|
1468
1470
|
}
|
|
1469
|
-
function
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
{ message: SIGN_MESSAGE },
|
|
1491
|
-
{
|
|
1492
|
-
address: wallets[0].address
|
|
1493
|
-
}
|
|
1494
|
-
);
|
|
1495
|
-
const encryptionKey = await deriveKeyFromSignature(signature);
|
|
1496
|
-
const stored = setStorageItem(SIGNATURE_STORAGE_KEY, encryptionKey);
|
|
1497
|
-
if (!stored) {
|
|
1498
|
-
throw new Error("Failed to store encryption key in localStorage");
|
|
1499
|
-
}
|
|
1500
|
-
} catch (error) {
|
|
1501
|
-
hasRequestedSignature.current = false;
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
};
|
|
1505
|
-
requestSignature();
|
|
1506
|
-
}, [
|
|
1507
|
-
authenticated,
|
|
1508
|
-
wallets.length > 0 ? wallets[0]?.address : null,
|
|
1509
|
-
signMessage
|
|
1510
|
-
]);
|
|
1511
|
-
useEffect2(() => {
|
|
1512
|
-
if (!authenticated) {
|
|
1513
|
-
hasRequestedSignature.current = false;
|
|
1514
|
-
hasCheckedStorage.current = false;
|
|
1515
|
-
}
|
|
1516
|
-
}, [authenticated]);
|
|
1471
|
+
function hasEncryptionKey(address) {
|
|
1472
|
+
const storageKey = getStorageKey(address);
|
|
1473
|
+
return getStorageItem(storageKey) !== null;
|
|
1474
|
+
}
|
|
1475
|
+
async function requestEncryptionKey(walletAddress, signMessage) {
|
|
1476
|
+
const storageKey = getStorageKey(walletAddress);
|
|
1477
|
+
const existingKey = getStorageItem(storageKey);
|
|
1478
|
+
if (existingKey) {
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
const signature = await signMessage(SIGN_MESSAGE);
|
|
1482
|
+
const encryptionKey = await deriveKeyFromSignature(signature);
|
|
1483
|
+
const stored = setStorageItem(storageKey, encryptionKey);
|
|
1484
|
+
if (!stored) {
|
|
1485
|
+
throw new Error("Failed to store encryption key in localStorage");
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
function useEncryption(signMessage) {
|
|
1489
|
+
return {
|
|
1490
|
+
requestEncryptionKey: (walletAddress) => requestEncryptionKey(walletAddress, signMessage)
|
|
1491
|
+
};
|
|
1517
1492
|
}
|
|
1518
1493
|
|
|
1519
1494
|
// src/react/useMemory.ts
|
|
1520
|
-
import { useCallback as useCallback2, useRef as
|
|
1495
|
+
import { useCallback as useCallback2, useRef as useRef2 } from "react";
|
|
1521
1496
|
import { postApiV1ChatCompletions } from "@reverbia/sdk";
|
|
1522
1497
|
|
|
1523
1498
|
// src/lib/memory/service.ts
|
|
@@ -1915,7 +1890,7 @@ function useMemory(options = {}) {
|
|
|
1915
1890
|
baseUrl = BASE_URL
|
|
1916
1891
|
} = options;
|
|
1917
1892
|
const embeddingModel = userEmbeddingModel === void 0 ? embeddingProvider === "local" ? DEFAULT_LOCAL_EMBEDDING_MODEL : DEFAULT_API_EMBEDDING_MODEL : userEmbeddingModel;
|
|
1918
|
-
const extractionInProgressRef =
|
|
1893
|
+
const extractionInProgressRef = useRef2(false);
|
|
1919
1894
|
const extractMemoriesFromMessage = useCallback2(
|
|
1920
1895
|
async (options2) => {
|
|
1921
1896
|
const { messages, model } = options2;
|
|
@@ -2222,22 +2197,22 @@ ${text}`;
|
|
|
2222
2197
|
}
|
|
2223
2198
|
|
|
2224
2199
|
// src/react/useModels.ts
|
|
2225
|
-
import { useCallback as useCallback4, useEffect as
|
|
2200
|
+
import { useCallback as useCallback4, useEffect as useEffect2, useRef as useRef3, useState as useState3 } from "react";
|
|
2226
2201
|
function useModels(options = {}) {
|
|
2227
2202
|
const { getToken, baseUrl = BASE_URL, provider, autoFetch = true } = options;
|
|
2228
2203
|
const [models, setModels] = useState3([]);
|
|
2229
2204
|
const [isLoading, setIsLoading] = useState3(false);
|
|
2230
2205
|
const [error, setError] = useState3(null);
|
|
2231
|
-
const getTokenRef =
|
|
2232
|
-
const baseUrlRef =
|
|
2233
|
-
const providerRef =
|
|
2234
|
-
const abortControllerRef =
|
|
2235
|
-
|
|
2206
|
+
const getTokenRef = useRef3(getToken);
|
|
2207
|
+
const baseUrlRef = useRef3(baseUrl);
|
|
2208
|
+
const providerRef = useRef3(provider);
|
|
2209
|
+
const abortControllerRef = useRef3(null);
|
|
2210
|
+
useEffect2(() => {
|
|
2236
2211
|
getTokenRef.current = getToken;
|
|
2237
2212
|
baseUrlRef.current = baseUrl;
|
|
2238
2213
|
providerRef.current = provider;
|
|
2239
2214
|
});
|
|
2240
|
-
|
|
2215
|
+
useEffect2(() => {
|
|
2241
2216
|
return () => {
|
|
2242
2217
|
if (abortControllerRef.current) {
|
|
2243
2218
|
abortControllerRef.current.abort();
|
|
@@ -2307,8 +2282,8 @@ function useModels(options = {}) {
|
|
|
2307
2282
|
setModels([]);
|
|
2308
2283
|
await fetchModels();
|
|
2309
2284
|
}, [fetchModels]);
|
|
2310
|
-
const hasFetchedRef =
|
|
2311
|
-
|
|
2285
|
+
const hasFetchedRef = useRef3(false);
|
|
2286
|
+
useEffect2(() => {
|
|
2312
2287
|
if (autoFetch && !hasFetchedRef.current) {
|
|
2313
2288
|
hasFetchedRef.current = true;
|
|
2314
2289
|
fetchModels();
|
|
@@ -2326,15 +2301,15 @@ function useModels(options = {}) {
|
|
|
2326
2301
|
}
|
|
2327
2302
|
|
|
2328
2303
|
// src/react/useSearch.ts
|
|
2329
|
-
import { useCallback as useCallback5, useEffect as
|
|
2304
|
+
import { useCallback as useCallback5, useEffect as useEffect3, useRef as useRef4, useState as useState4 } from "react";
|
|
2330
2305
|
function useSearch(options = {}) {
|
|
2331
2306
|
const { getToken, baseUrl = BASE_URL, onError } = options;
|
|
2332
2307
|
const [isLoading, setIsLoading] = useState4(false);
|
|
2333
2308
|
const [results, setResults] = useState4(null);
|
|
2334
2309
|
const [response, setResponse] = useState4(null);
|
|
2335
2310
|
const [error, setError] = useState4(null);
|
|
2336
|
-
const abortControllerRef =
|
|
2337
|
-
|
|
2311
|
+
const abortControllerRef = useRef4(null);
|
|
2312
|
+
useEffect3(() => {
|
|
2338
2313
|
return () => {
|
|
2339
2314
|
if (abortControllerRef.current) {
|
|
2340
2315
|
abortControllerRef.current.abort();
|
|
@@ -2410,12 +2385,12 @@ function useSearch(options = {}) {
|
|
|
2410
2385
|
}
|
|
2411
2386
|
|
|
2412
2387
|
// src/react/useImageGeneration.ts
|
|
2413
|
-
import { useCallback as useCallback6, useEffect as
|
|
2388
|
+
import { useCallback as useCallback6, useEffect as useEffect4, useRef as useRef5, useState as useState5 } from "react";
|
|
2414
2389
|
function useImageGeneration(options = {}) {
|
|
2415
2390
|
const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
|
|
2416
2391
|
const [isLoading, setIsLoading] = useState5(false);
|
|
2417
|
-
const abortControllerRef =
|
|
2418
|
-
|
|
2392
|
+
const abortControllerRef = useRef5(null);
|
|
2393
|
+
useEffect4(() => {
|
|
2419
2394
|
return () => {
|
|
2420
2395
|
if (abortControllerRef.current) {
|
|
2421
2396
|
abortControllerRef.current.abort();
|
|
@@ -2554,6 +2529,8 @@ export {
|
|
|
2554
2529
|
executeTool,
|
|
2555
2530
|
extractConversationContext,
|
|
2556
2531
|
formatMemoriesForChat,
|
|
2532
|
+
hasEncryptionKey,
|
|
2533
|
+
requestEncryptionKey,
|
|
2557
2534
|
selectTool,
|
|
2558
2535
|
useChat,
|
|
2559
2536
|
useEncryption,
|