@reverbia/sdk 1.0.0-next.20251211090814 → 1.0.0-next.20251212092701
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.d.mts +4 -0
- package/dist/expo/index.d.ts +4 -0
- package/dist/next/index.d.mts +2 -0
- package/dist/next/index.d.ts +2 -0
- package/dist/react/index.cjs +225 -1
- package/dist/react/index.d.mts +62 -0
- package/dist/react/index.d.ts +62 -0
- package/dist/react/index.mjs +225 -1
- package/package.json +2 -2
package/dist/expo/index.d.mts
CHANGED
|
@@ -379,6 +379,8 @@ type UseChatResult = BaseUseChatResult & {
|
|
|
379
379
|
* - `sendMessage`: An async function to send chat messages
|
|
380
380
|
* - `stop`: A function to abort the current request
|
|
381
381
|
*
|
|
382
|
+
* @category Hooks
|
|
383
|
+
*
|
|
382
384
|
* @example
|
|
383
385
|
* ```tsx
|
|
384
386
|
* const { isLoading, sendMessage, stop } = useChat({
|
|
@@ -430,6 +432,7 @@ type UseImageGenerationResult = {
|
|
|
430
432
|
};
|
|
431
433
|
/**
|
|
432
434
|
* React hook for generating images using the LLM API.
|
|
435
|
+
* @category Hooks
|
|
433
436
|
*/
|
|
434
437
|
declare function useImageGeneration(options?: UseImageGenerationOptions): UseImageGenerationResult;
|
|
435
438
|
|
|
@@ -460,6 +463,7 @@ type UseModelsResult = {
|
|
|
460
463
|
/**
|
|
461
464
|
* React hook for fetching available LLM models.
|
|
462
465
|
* Automatically fetches all available models.
|
|
466
|
+
* @category Hooks
|
|
463
467
|
*/
|
|
464
468
|
declare function useModels(options?: UseModelsOptions): UseModelsResult;
|
|
465
469
|
|
package/dist/expo/index.d.ts
CHANGED
|
@@ -379,6 +379,8 @@ type UseChatResult = BaseUseChatResult & {
|
|
|
379
379
|
* - `sendMessage`: An async function to send chat messages
|
|
380
380
|
* - `stop`: A function to abort the current request
|
|
381
381
|
*
|
|
382
|
+
* @category Hooks
|
|
383
|
+
*
|
|
382
384
|
* @example
|
|
383
385
|
* ```tsx
|
|
384
386
|
* const { isLoading, sendMessage, stop } = useChat({
|
|
@@ -430,6 +432,7 @@ type UseImageGenerationResult = {
|
|
|
430
432
|
};
|
|
431
433
|
/**
|
|
432
434
|
* React hook for generating images using the LLM API.
|
|
435
|
+
* @category Hooks
|
|
433
436
|
*/
|
|
434
437
|
declare function useImageGeneration(options?: UseImageGenerationOptions): UseImageGenerationResult;
|
|
435
438
|
|
|
@@ -460,6 +463,7 @@ type UseModelsResult = {
|
|
|
460
463
|
/**
|
|
461
464
|
* React hook for fetching available LLM models.
|
|
462
465
|
* Automatically fetches all available models.
|
|
466
|
+
* @category Hooks
|
|
463
467
|
*/
|
|
464
468
|
declare function useModels(options?: UseModelsOptions): UseModelsResult;
|
|
465
469
|
|
package/dist/next/index.d.mts
CHANGED
package/dist/next/index.d.ts
CHANGED
package/dist/react/index.cjs
CHANGED
|
@@ -1858,9 +1858,69 @@ var saveMemory = async (memory) => {
|
|
|
1858
1858
|
var saveMemories = async (memories) => {
|
|
1859
1859
|
await Promise.all(memories.map((memory) => saveMemory(memory)));
|
|
1860
1860
|
};
|
|
1861
|
+
var updateMemoryById = async (id, updates, existingMemory, embedding, embeddingModel) => {
|
|
1862
|
+
const now = Date.now();
|
|
1863
|
+
const updatedMemory = {
|
|
1864
|
+
...updates,
|
|
1865
|
+
updatedAt: now
|
|
1866
|
+
};
|
|
1867
|
+
if ("namespace" in updates || "key" in updates || "value" in updates) {
|
|
1868
|
+
const namespace = updates.namespace ?? existingMemory.namespace;
|
|
1869
|
+
const key = updates.key ?? existingMemory.key;
|
|
1870
|
+
const value = updates.value ?? existingMemory.value;
|
|
1871
|
+
const newUniqueKey = `${namespace}:${key}:${value}`;
|
|
1872
|
+
if (newUniqueKey !== existingMemory.uniqueKey) {
|
|
1873
|
+
const conflicting = await getMemory(namespace, key, value);
|
|
1874
|
+
if (conflicting) {
|
|
1875
|
+
throw new Error(
|
|
1876
|
+
`A memory with uniqueKey "${newUniqueKey}" already exists (id: ${conflicting.id})`
|
|
1877
|
+
);
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
updatedMemory.compositeKey = `${namespace}:${key}`;
|
|
1881
|
+
updatedMemory.uniqueKey = newUniqueKey;
|
|
1882
|
+
}
|
|
1883
|
+
updatedMemory.embedding = embedding;
|
|
1884
|
+
updatedMemory.embeddingModel = embeddingModel;
|
|
1885
|
+
return await memoryDb.transaction("rw", memoryDb.memories, async () => {
|
|
1886
|
+
await memoryDb.memories.update(id, updatedMemory);
|
|
1887
|
+
return await memoryDb.memories.get(id);
|
|
1888
|
+
});
|
|
1889
|
+
};
|
|
1861
1890
|
var getAllMemories = async () => {
|
|
1862
1891
|
return memoryDb.memories.toArray();
|
|
1863
1892
|
};
|
|
1893
|
+
var getMemoryById = async (id) => {
|
|
1894
|
+
return memoryDb.memories.get(id);
|
|
1895
|
+
};
|
|
1896
|
+
var getMemoriesByNamespace = async (namespace) => {
|
|
1897
|
+
return memoryDb.memories.where("namespace").equals(namespace).toArray();
|
|
1898
|
+
};
|
|
1899
|
+
var getMemories = async (namespace, key) => {
|
|
1900
|
+
const compositeKey = `${namespace}:${key}`;
|
|
1901
|
+
return memoryDb.memories.where("compositeKey").equals(compositeKey).toArray();
|
|
1902
|
+
};
|
|
1903
|
+
var getMemory = async (namespace, key, value) => {
|
|
1904
|
+
const uniqueKey = `${namespace}:${key}:${value}`;
|
|
1905
|
+
return memoryDb.memories.where("uniqueKey").equals(uniqueKey).first();
|
|
1906
|
+
};
|
|
1907
|
+
var deleteMemories = async (namespace, key) => {
|
|
1908
|
+
const compositeKey = `${namespace}:${key}`;
|
|
1909
|
+
await memoryDb.memories.where("compositeKey").equals(compositeKey).delete();
|
|
1910
|
+
};
|
|
1911
|
+
var deleteMemory = async (namespace, key, value) => {
|
|
1912
|
+
const uniqueKey = `${namespace}:${key}:${value}`;
|
|
1913
|
+
const existing = await memoryDb.memories.where("uniqueKey").equals(uniqueKey).first();
|
|
1914
|
+
if (existing?.id) {
|
|
1915
|
+
await memoryDb.memories.delete(existing.id);
|
|
1916
|
+
}
|
|
1917
|
+
};
|
|
1918
|
+
var deleteMemoryById = async (id) => {
|
|
1919
|
+
await memoryDb.memories.delete(id);
|
|
1920
|
+
};
|
|
1921
|
+
var clearAllMemories = async () => {
|
|
1922
|
+
await memoryDb.memories.clear();
|
|
1923
|
+
};
|
|
1864
1924
|
var cosineSimilarity = (a, b) => {
|
|
1865
1925
|
if (a.length !== b.length) {
|
|
1866
1926
|
throw new Error("Vectors must have the same length");
|
|
@@ -2327,9 +2387,173 @@ function useMemory(options = {}) {
|
|
|
2327
2387
|
},
|
|
2328
2388
|
[embeddingModel, embeddingProvider, getToken, baseUrl]
|
|
2329
2389
|
);
|
|
2390
|
+
const fetchAllMemories = (0, import_react2.useCallback)(async () => {
|
|
2391
|
+
try {
|
|
2392
|
+
return await getAllMemories();
|
|
2393
|
+
} catch (error) {
|
|
2394
|
+
throw new Error(
|
|
2395
|
+
"Failed to fetch all memories: " + (error instanceof Error ? error.message : String(error))
|
|
2396
|
+
);
|
|
2397
|
+
}
|
|
2398
|
+
}, []);
|
|
2399
|
+
const fetchMemoriesByNamespace = (0, import_react2.useCallback)(
|
|
2400
|
+
async (namespace) => {
|
|
2401
|
+
if (!namespace) {
|
|
2402
|
+
throw new Error("Missing required field: namespace");
|
|
2403
|
+
}
|
|
2404
|
+
try {
|
|
2405
|
+
return await getMemoriesByNamespace(namespace);
|
|
2406
|
+
} catch (error) {
|
|
2407
|
+
throw new Error(
|
|
2408
|
+
`Failed to fetch memories for namespace "${namespace}": ` + (error instanceof Error ? error.message : String(error))
|
|
2409
|
+
);
|
|
2410
|
+
}
|
|
2411
|
+
},
|
|
2412
|
+
[]
|
|
2413
|
+
);
|
|
2414
|
+
const fetchMemoriesByKey = (0, import_react2.useCallback)(
|
|
2415
|
+
async (namespace, key) => {
|
|
2416
|
+
if (!namespace || !key) {
|
|
2417
|
+
throw new Error("Missing required fields: namespace, key");
|
|
2418
|
+
}
|
|
2419
|
+
try {
|
|
2420
|
+
return await getMemories(namespace, key);
|
|
2421
|
+
} catch (error) {
|
|
2422
|
+
throw new Error(
|
|
2423
|
+
`Failed to fetch memories for "${namespace}:${key}": ` + (error instanceof Error ? error.message : String(error))
|
|
2424
|
+
);
|
|
2425
|
+
}
|
|
2426
|
+
},
|
|
2427
|
+
[]
|
|
2428
|
+
);
|
|
2429
|
+
const updateMemory = (0, import_react2.useCallback)(
|
|
2430
|
+
async (id, updates) => {
|
|
2431
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
2432
|
+
throw new Error("id must be a non-negative integer");
|
|
2433
|
+
}
|
|
2434
|
+
try {
|
|
2435
|
+
const embeddingModelToUse = embeddingProvider === "api" ? embeddingModel ?? DEFAULT_API_EMBEDDING_MODEL : embeddingModel && embeddingModel !== DEFAULT_API_EMBEDDING_MODEL ? embeddingModel : DEFAULT_LOCAL_EMBEDDING_MODEL;
|
|
2436
|
+
const embeddingOptions = {
|
|
2437
|
+
model: embeddingModelToUse,
|
|
2438
|
+
provider: embeddingProvider,
|
|
2439
|
+
getToken: getToken || void 0,
|
|
2440
|
+
baseUrl
|
|
2441
|
+
};
|
|
2442
|
+
if (!updates.type || !updates.namespace || !updates.key || !updates.value || !updates.rawEvidence || updates.confidence === void 0 || updates.confidence === null || updates.pii === void 0 || updates.pii === null) {
|
|
2443
|
+
throw new Error(
|
|
2444
|
+
"Missing required fields: type, namespace, key, value, rawEvidence, confidence, pii"
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
const existingMemory = await getMemoryById(id);
|
|
2448
|
+
if (!existingMemory) {
|
|
2449
|
+
throw new Error(`Memory with id ${id} not found`);
|
|
2450
|
+
}
|
|
2451
|
+
const embeddingFieldsChanged = updates.value !== void 0 && updates.value !== existingMemory.value || updates.rawEvidence !== void 0 && updates.rawEvidence !== existingMemory.rawEvidence || updates.type !== void 0 && updates.type !== existingMemory.type || updates.namespace !== void 0 && updates.namespace !== existingMemory.namespace || updates.key !== void 0 && updates.key !== existingMemory.key;
|
|
2452
|
+
if (!embeddingFieldsChanged) {
|
|
2453
|
+
return existingMemory;
|
|
2454
|
+
}
|
|
2455
|
+
const memory = {
|
|
2456
|
+
type: updates.type,
|
|
2457
|
+
namespace: updates.namespace,
|
|
2458
|
+
key: updates.key,
|
|
2459
|
+
value: updates.value,
|
|
2460
|
+
rawEvidence: updates.rawEvidence,
|
|
2461
|
+
confidence: updates.confidence,
|
|
2462
|
+
pii: updates.pii
|
|
2463
|
+
};
|
|
2464
|
+
let embedding = existingMemory.embedding ?? [];
|
|
2465
|
+
let embeddingModelToStore = existingMemory.embeddingModel ?? "";
|
|
2466
|
+
if (generateEmbeddings && embeddingModelToUse) {
|
|
2467
|
+
try {
|
|
2468
|
+
embedding = await generateEmbeddingForMemory(
|
|
2469
|
+
memory,
|
|
2470
|
+
embeddingOptions
|
|
2471
|
+
);
|
|
2472
|
+
embeddingModelToStore = embeddingModelToUse;
|
|
2473
|
+
} catch (embeddingError) {
|
|
2474
|
+
console.error(
|
|
2475
|
+
"Failed to generate embedding, keeping existing:",
|
|
2476
|
+
embeddingError
|
|
2477
|
+
);
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
return await updateMemoryById(
|
|
2481
|
+
id,
|
|
2482
|
+
updates,
|
|
2483
|
+
existingMemory,
|
|
2484
|
+
embedding,
|
|
2485
|
+
embeddingModelToStore
|
|
2486
|
+
);
|
|
2487
|
+
} catch (error) {
|
|
2488
|
+
throw new Error(
|
|
2489
|
+
`Failed to update memory ${id}: ` + (error instanceof Error ? error.message : String(error))
|
|
2490
|
+
);
|
|
2491
|
+
}
|
|
2492
|
+
},
|
|
2493
|
+
[embeddingModel, embeddingProvider, generateEmbeddings, getToken, baseUrl]
|
|
2494
|
+
);
|
|
2495
|
+
const removeMemory = (0, import_react2.useCallback)(
|
|
2496
|
+
async (namespace, key, value) => {
|
|
2497
|
+
if (!namespace || !key || !value) {
|
|
2498
|
+
throw new Error("Missing required fields: namespace, key, value");
|
|
2499
|
+
}
|
|
2500
|
+
try {
|
|
2501
|
+
await deleteMemory(namespace, key, value);
|
|
2502
|
+
} catch (error) {
|
|
2503
|
+
throw new Error(
|
|
2504
|
+
`Failed to delete memory "${namespace}:${key}:${value}": ` + (error instanceof Error ? error.message : String(error))
|
|
2505
|
+
);
|
|
2506
|
+
}
|
|
2507
|
+
},
|
|
2508
|
+
[]
|
|
2509
|
+
);
|
|
2510
|
+
const removeMemoryById = (0, import_react2.useCallback)(async (id) => {
|
|
2511
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
2512
|
+
throw new Error("id must be a non-negative integer");
|
|
2513
|
+
}
|
|
2514
|
+
try {
|
|
2515
|
+
await deleteMemoryById(id);
|
|
2516
|
+
} catch (error) {
|
|
2517
|
+
throw new Error(
|
|
2518
|
+
`Failed to delete memory with id ${id}: ` + (error instanceof Error ? error.message : String(error))
|
|
2519
|
+
);
|
|
2520
|
+
}
|
|
2521
|
+
}, []);
|
|
2522
|
+
const removeMemories = (0, import_react2.useCallback)(
|
|
2523
|
+
async (namespace, key) => {
|
|
2524
|
+
if (!namespace || !key) {
|
|
2525
|
+
throw new Error("Missing required fields: namespace, key");
|
|
2526
|
+
}
|
|
2527
|
+
try {
|
|
2528
|
+
await deleteMemories(namespace, key);
|
|
2529
|
+
} catch (error) {
|
|
2530
|
+
throw new Error(
|
|
2531
|
+
`Failed to delete memories for "${namespace}:${key}": ` + (error instanceof Error ? error.message : String(error))
|
|
2532
|
+
);
|
|
2533
|
+
}
|
|
2534
|
+
},
|
|
2535
|
+
[]
|
|
2536
|
+
);
|
|
2537
|
+
const clearMemories = (0, import_react2.useCallback)(async () => {
|
|
2538
|
+
try {
|
|
2539
|
+
await clearAllMemories();
|
|
2540
|
+
} catch (error) {
|
|
2541
|
+
throw new Error(
|
|
2542
|
+
"Failed to clear all memories: " + (error instanceof Error ? error.message : String(error))
|
|
2543
|
+
);
|
|
2544
|
+
}
|
|
2545
|
+
}, []);
|
|
2330
2546
|
return {
|
|
2331
2547
|
extractMemoriesFromMessage,
|
|
2332
|
-
searchMemories
|
|
2548
|
+
searchMemories,
|
|
2549
|
+
fetchAllMemories,
|
|
2550
|
+
fetchMemoriesByNamespace,
|
|
2551
|
+
fetchMemoriesByKey,
|
|
2552
|
+
updateMemory,
|
|
2553
|
+
removeMemory,
|
|
2554
|
+
removeMemoryById,
|
|
2555
|
+
removeMemories,
|
|
2556
|
+
clearMemories
|
|
2333
2557
|
};
|
|
2334
2558
|
}
|
|
2335
2559
|
|
package/dist/react/index.d.mts
CHANGED
|
@@ -524,6 +524,8 @@ type UseChatResult = BaseUseChatResult & {
|
|
|
524
524
|
* @param options.toolSelectorModel - The model to use for tool selection.
|
|
525
525
|
* @param options.onToolExecution - Callback function to be called when a tool is executed.
|
|
526
526
|
*
|
|
527
|
+
* @category Hooks
|
|
528
|
+
*
|
|
527
529
|
* @returns An object containing:
|
|
528
530
|
* - `isLoading`: A boolean indicating whether a request is currently in progress
|
|
529
531
|
* - `isSelectingTool`: A boolean indicating whether tool selection is in progress
|
|
@@ -612,6 +614,7 @@ declare function requestEncryptionKey(walletAddress: string, signMessage: SignMe
|
|
|
612
614
|
* Hook that provides on-demand encryption key management.
|
|
613
615
|
* @param signMessage - Function to sign a message (from Privy's useSignMessage)
|
|
614
616
|
* @returns Functions to request encryption keys
|
|
617
|
+
* @category Hooks
|
|
615
618
|
*/
|
|
616
619
|
declare function useEncryption(signMessage: SignMessageFn): {
|
|
617
620
|
requestEncryptionKey: (walletAddress: string) => Promise<void>;
|
|
@@ -698,10 +701,58 @@ type UseMemoryResult = {
|
|
|
698
701
|
searchMemories: (query: string, limit?: number, minSimilarity?: number) => Promise<Array<StoredMemoryItem & {
|
|
699
702
|
similarity: number;
|
|
700
703
|
}>>;
|
|
704
|
+
/**
|
|
705
|
+
* Get all memories stored in IndexedDB
|
|
706
|
+
* @returns Array of all stored memories
|
|
707
|
+
*/
|
|
708
|
+
fetchAllMemories: () => Promise<StoredMemoryItem[]>;
|
|
709
|
+
/**
|
|
710
|
+
* Get memories filtered by namespace
|
|
711
|
+
* @param namespace The namespace to filter by
|
|
712
|
+
* @returns Array of memories in the specified namespace
|
|
713
|
+
*/
|
|
714
|
+
fetchMemoriesByNamespace: (namespace: string) => Promise<StoredMemoryItem[]>;
|
|
715
|
+
/**
|
|
716
|
+
* Get memories by namespace and key
|
|
717
|
+
* @param namespace The namespace
|
|
718
|
+
* @param key The key within the namespace
|
|
719
|
+
* @returns Array of memories matching the namespace and key
|
|
720
|
+
*/
|
|
721
|
+
fetchMemoriesByKey: (namespace: string, key: string) => Promise<StoredMemoryItem[]>;
|
|
722
|
+
/**
|
|
723
|
+
* Update a memory by its ID
|
|
724
|
+
* @param id The memory ID
|
|
725
|
+
* @param updates Partial memory fields to update
|
|
726
|
+
* @returns The updated memory or undefined if not found
|
|
727
|
+
*/
|
|
728
|
+
updateMemory: (id: number, updates: Partial<StoredMemoryItem & MemoryItem>) => Promise<StoredMemoryItem | undefined>;
|
|
729
|
+
/**
|
|
730
|
+
* Delete a specific memory by namespace, key, and value
|
|
731
|
+
* @param namespace The namespace
|
|
732
|
+
* @param key The key
|
|
733
|
+
* @param value The value
|
|
734
|
+
*/
|
|
735
|
+
removeMemory: (namespace: string, key: string, value: string) => Promise<void>;
|
|
736
|
+
/**
|
|
737
|
+
* Delete a memory by its ID
|
|
738
|
+
* @param id The memory ID
|
|
739
|
+
*/
|
|
740
|
+
removeMemoryById: (id: number) => Promise<void>;
|
|
741
|
+
/**
|
|
742
|
+
* Delete all memories by namespace and key
|
|
743
|
+
* @param namespace The namespace
|
|
744
|
+
* @param key The key
|
|
745
|
+
*/
|
|
746
|
+
removeMemories: (namespace: string, key: string) => Promise<void>;
|
|
747
|
+
/**
|
|
748
|
+
* Clear all memories from IndexedDB
|
|
749
|
+
*/
|
|
750
|
+
clearMemories: () => Promise<void>;
|
|
701
751
|
};
|
|
702
752
|
/**
|
|
703
753
|
* Standalone hook for extracting memories from user messages.
|
|
704
754
|
* Can be composed with other hooks like useChat, useFiles, etc.
|
|
755
|
+
* @category Hooks
|
|
705
756
|
*/
|
|
706
757
|
declare function useMemory(options?: UseMemoryOptions): UseMemoryResult;
|
|
707
758
|
|
|
@@ -710,6 +761,10 @@ interface PdfFile {
|
|
|
710
761
|
mediaType?: string;
|
|
711
762
|
filename?: string;
|
|
712
763
|
}
|
|
764
|
+
/**
|
|
765
|
+
* React hook for extracting text from PDF files.
|
|
766
|
+
* @category Hooks
|
|
767
|
+
*/
|
|
713
768
|
declare function usePdf(): {
|
|
714
769
|
extractPdfContext: (files: PdfFile[]) => Promise<string | null>;
|
|
715
770
|
isProcessing: boolean;
|
|
@@ -721,6 +776,10 @@ interface OCRFile {
|
|
|
721
776
|
filename?: string;
|
|
722
777
|
language?: string;
|
|
723
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* React hook for extracting text from images using OCR.
|
|
781
|
+
* @category Hooks
|
|
782
|
+
*/
|
|
724
783
|
declare function useOCR(): {
|
|
725
784
|
extractOCRContext: (files: OCRFile[]) => Promise<string | null>;
|
|
726
785
|
isProcessing: boolean;
|
|
@@ -754,6 +813,7 @@ type UseModelsResult = {
|
|
|
754
813
|
/**
|
|
755
814
|
* React hook for fetching available LLM models.
|
|
756
815
|
* Automatically fetches all available models.
|
|
816
|
+
* @category Hooks
|
|
757
817
|
*/
|
|
758
818
|
declare function useModels(options?: UseModelsOptions): UseModelsResult;
|
|
759
819
|
|
|
@@ -805,6 +865,7 @@ type UseSearchResult = {
|
|
|
805
865
|
*
|
|
806
866
|
* @param options - Configuration options for the search hook
|
|
807
867
|
* @returns Object containing search function, results, loading state, and error
|
|
868
|
+
* @category Hooks
|
|
808
869
|
*
|
|
809
870
|
* @example
|
|
810
871
|
* ```tsx
|
|
@@ -852,6 +913,7 @@ type UseImageGenerationResult = {
|
|
|
852
913
|
};
|
|
853
914
|
/**
|
|
854
915
|
* React hook for generating images using the LLM API.
|
|
916
|
+
* @category Hooks
|
|
855
917
|
*/
|
|
856
918
|
declare function useImageGeneration(options?: UseImageGenerationOptions): UseImageGenerationResult;
|
|
857
919
|
|
package/dist/react/index.d.ts
CHANGED
|
@@ -524,6 +524,8 @@ type UseChatResult = BaseUseChatResult & {
|
|
|
524
524
|
* @param options.toolSelectorModel - The model to use for tool selection.
|
|
525
525
|
* @param options.onToolExecution - Callback function to be called when a tool is executed.
|
|
526
526
|
*
|
|
527
|
+
* @category Hooks
|
|
528
|
+
*
|
|
527
529
|
* @returns An object containing:
|
|
528
530
|
* - `isLoading`: A boolean indicating whether a request is currently in progress
|
|
529
531
|
* - `isSelectingTool`: A boolean indicating whether tool selection is in progress
|
|
@@ -612,6 +614,7 @@ declare function requestEncryptionKey(walletAddress: string, signMessage: SignMe
|
|
|
612
614
|
* Hook that provides on-demand encryption key management.
|
|
613
615
|
* @param signMessage - Function to sign a message (from Privy's useSignMessage)
|
|
614
616
|
* @returns Functions to request encryption keys
|
|
617
|
+
* @category Hooks
|
|
615
618
|
*/
|
|
616
619
|
declare function useEncryption(signMessage: SignMessageFn): {
|
|
617
620
|
requestEncryptionKey: (walletAddress: string) => Promise<void>;
|
|
@@ -698,10 +701,58 @@ type UseMemoryResult = {
|
|
|
698
701
|
searchMemories: (query: string, limit?: number, minSimilarity?: number) => Promise<Array<StoredMemoryItem & {
|
|
699
702
|
similarity: number;
|
|
700
703
|
}>>;
|
|
704
|
+
/**
|
|
705
|
+
* Get all memories stored in IndexedDB
|
|
706
|
+
* @returns Array of all stored memories
|
|
707
|
+
*/
|
|
708
|
+
fetchAllMemories: () => Promise<StoredMemoryItem[]>;
|
|
709
|
+
/**
|
|
710
|
+
* Get memories filtered by namespace
|
|
711
|
+
* @param namespace The namespace to filter by
|
|
712
|
+
* @returns Array of memories in the specified namespace
|
|
713
|
+
*/
|
|
714
|
+
fetchMemoriesByNamespace: (namespace: string) => Promise<StoredMemoryItem[]>;
|
|
715
|
+
/**
|
|
716
|
+
* Get memories by namespace and key
|
|
717
|
+
* @param namespace The namespace
|
|
718
|
+
* @param key The key within the namespace
|
|
719
|
+
* @returns Array of memories matching the namespace and key
|
|
720
|
+
*/
|
|
721
|
+
fetchMemoriesByKey: (namespace: string, key: string) => Promise<StoredMemoryItem[]>;
|
|
722
|
+
/**
|
|
723
|
+
* Update a memory by its ID
|
|
724
|
+
* @param id The memory ID
|
|
725
|
+
* @param updates Partial memory fields to update
|
|
726
|
+
* @returns The updated memory or undefined if not found
|
|
727
|
+
*/
|
|
728
|
+
updateMemory: (id: number, updates: Partial<StoredMemoryItem & MemoryItem>) => Promise<StoredMemoryItem | undefined>;
|
|
729
|
+
/**
|
|
730
|
+
* Delete a specific memory by namespace, key, and value
|
|
731
|
+
* @param namespace The namespace
|
|
732
|
+
* @param key The key
|
|
733
|
+
* @param value The value
|
|
734
|
+
*/
|
|
735
|
+
removeMemory: (namespace: string, key: string, value: string) => Promise<void>;
|
|
736
|
+
/**
|
|
737
|
+
* Delete a memory by its ID
|
|
738
|
+
* @param id The memory ID
|
|
739
|
+
*/
|
|
740
|
+
removeMemoryById: (id: number) => Promise<void>;
|
|
741
|
+
/**
|
|
742
|
+
* Delete all memories by namespace and key
|
|
743
|
+
* @param namespace The namespace
|
|
744
|
+
* @param key The key
|
|
745
|
+
*/
|
|
746
|
+
removeMemories: (namespace: string, key: string) => Promise<void>;
|
|
747
|
+
/**
|
|
748
|
+
* Clear all memories from IndexedDB
|
|
749
|
+
*/
|
|
750
|
+
clearMemories: () => Promise<void>;
|
|
701
751
|
};
|
|
702
752
|
/**
|
|
703
753
|
* Standalone hook for extracting memories from user messages.
|
|
704
754
|
* Can be composed with other hooks like useChat, useFiles, etc.
|
|
755
|
+
* @category Hooks
|
|
705
756
|
*/
|
|
706
757
|
declare function useMemory(options?: UseMemoryOptions): UseMemoryResult;
|
|
707
758
|
|
|
@@ -710,6 +761,10 @@ interface PdfFile {
|
|
|
710
761
|
mediaType?: string;
|
|
711
762
|
filename?: string;
|
|
712
763
|
}
|
|
764
|
+
/**
|
|
765
|
+
* React hook for extracting text from PDF files.
|
|
766
|
+
* @category Hooks
|
|
767
|
+
*/
|
|
713
768
|
declare function usePdf(): {
|
|
714
769
|
extractPdfContext: (files: PdfFile[]) => Promise<string | null>;
|
|
715
770
|
isProcessing: boolean;
|
|
@@ -721,6 +776,10 @@ interface OCRFile {
|
|
|
721
776
|
filename?: string;
|
|
722
777
|
language?: string;
|
|
723
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* React hook for extracting text from images using OCR.
|
|
781
|
+
* @category Hooks
|
|
782
|
+
*/
|
|
724
783
|
declare function useOCR(): {
|
|
725
784
|
extractOCRContext: (files: OCRFile[]) => Promise<string | null>;
|
|
726
785
|
isProcessing: boolean;
|
|
@@ -754,6 +813,7 @@ type UseModelsResult = {
|
|
|
754
813
|
/**
|
|
755
814
|
* React hook for fetching available LLM models.
|
|
756
815
|
* Automatically fetches all available models.
|
|
816
|
+
* @category Hooks
|
|
757
817
|
*/
|
|
758
818
|
declare function useModels(options?: UseModelsOptions): UseModelsResult;
|
|
759
819
|
|
|
@@ -805,6 +865,7 @@ type UseSearchResult = {
|
|
|
805
865
|
*
|
|
806
866
|
* @param options - Configuration options for the search hook
|
|
807
867
|
* @returns Object containing search function, results, loading state, and error
|
|
868
|
+
* @category Hooks
|
|
808
869
|
*
|
|
809
870
|
* @example
|
|
810
871
|
* ```tsx
|
|
@@ -852,6 +913,7 @@ type UseImageGenerationResult = {
|
|
|
852
913
|
};
|
|
853
914
|
/**
|
|
854
915
|
* React hook for generating images using the LLM API.
|
|
916
|
+
* @category Hooks
|
|
855
917
|
*/
|
|
856
918
|
declare function useImageGeneration(options?: UseImageGenerationOptions): UseImageGenerationResult;
|
|
857
919
|
|
package/dist/react/index.mjs
CHANGED
|
@@ -1804,9 +1804,69 @@ var saveMemory = async (memory) => {
|
|
|
1804
1804
|
var saveMemories = async (memories) => {
|
|
1805
1805
|
await Promise.all(memories.map((memory) => saveMemory(memory)));
|
|
1806
1806
|
};
|
|
1807
|
+
var updateMemoryById = async (id, updates, existingMemory, embedding, embeddingModel) => {
|
|
1808
|
+
const now = Date.now();
|
|
1809
|
+
const updatedMemory = {
|
|
1810
|
+
...updates,
|
|
1811
|
+
updatedAt: now
|
|
1812
|
+
};
|
|
1813
|
+
if ("namespace" in updates || "key" in updates || "value" in updates) {
|
|
1814
|
+
const namespace = updates.namespace ?? existingMemory.namespace;
|
|
1815
|
+
const key = updates.key ?? existingMemory.key;
|
|
1816
|
+
const value = updates.value ?? existingMemory.value;
|
|
1817
|
+
const newUniqueKey = `${namespace}:${key}:${value}`;
|
|
1818
|
+
if (newUniqueKey !== existingMemory.uniqueKey) {
|
|
1819
|
+
const conflicting = await getMemory(namespace, key, value);
|
|
1820
|
+
if (conflicting) {
|
|
1821
|
+
throw new Error(
|
|
1822
|
+
`A memory with uniqueKey "${newUniqueKey}" already exists (id: ${conflicting.id})`
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
updatedMemory.compositeKey = `${namespace}:${key}`;
|
|
1827
|
+
updatedMemory.uniqueKey = newUniqueKey;
|
|
1828
|
+
}
|
|
1829
|
+
updatedMemory.embedding = embedding;
|
|
1830
|
+
updatedMemory.embeddingModel = embeddingModel;
|
|
1831
|
+
return await memoryDb.transaction("rw", memoryDb.memories, async () => {
|
|
1832
|
+
await memoryDb.memories.update(id, updatedMemory);
|
|
1833
|
+
return await memoryDb.memories.get(id);
|
|
1834
|
+
});
|
|
1835
|
+
};
|
|
1807
1836
|
var getAllMemories = async () => {
|
|
1808
1837
|
return memoryDb.memories.toArray();
|
|
1809
1838
|
};
|
|
1839
|
+
var getMemoryById = async (id) => {
|
|
1840
|
+
return memoryDb.memories.get(id);
|
|
1841
|
+
};
|
|
1842
|
+
var getMemoriesByNamespace = async (namespace) => {
|
|
1843
|
+
return memoryDb.memories.where("namespace").equals(namespace).toArray();
|
|
1844
|
+
};
|
|
1845
|
+
var getMemories = async (namespace, key) => {
|
|
1846
|
+
const compositeKey = `${namespace}:${key}`;
|
|
1847
|
+
return memoryDb.memories.where("compositeKey").equals(compositeKey).toArray();
|
|
1848
|
+
};
|
|
1849
|
+
var getMemory = async (namespace, key, value) => {
|
|
1850
|
+
const uniqueKey = `${namespace}:${key}:${value}`;
|
|
1851
|
+
return memoryDb.memories.where("uniqueKey").equals(uniqueKey).first();
|
|
1852
|
+
};
|
|
1853
|
+
var deleteMemories = async (namespace, key) => {
|
|
1854
|
+
const compositeKey = `${namespace}:${key}`;
|
|
1855
|
+
await memoryDb.memories.where("compositeKey").equals(compositeKey).delete();
|
|
1856
|
+
};
|
|
1857
|
+
var deleteMemory = async (namespace, key, value) => {
|
|
1858
|
+
const uniqueKey = `${namespace}:${key}:${value}`;
|
|
1859
|
+
const existing = await memoryDb.memories.where("uniqueKey").equals(uniqueKey).first();
|
|
1860
|
+
if (existing?.id) {
|
|
1861
|
+
await memoryDb.memories.delete(existing.id);
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
1864
|
+
var deleteMemoryById = async (id) => {
|
|
1865
|
+
await memoryDb.memories.delete(id);
|
|
1866
|
+
};
|
|
1867
|
+
var clearAllMemories = async () => {
|
|
1868
|
+
await memoryDb.memories.clear();
|
|
1869
|
+
};
|
|
1810
1870
|
var cosineSimilarity = (a, b) => {
|
|
1811
1871
|
if (a.length !== b.length) {
|
|
1812
1872
|
throw new Error("Vectors must have the same length");
|
|
@@ -2273,9 +2333,173 @@ function useMemory(options = {}) {
|
|
|
2273
2333
|
},
|
|
2274
2334
|
[embeddingModel, embeddingProvider, getToken, baseUrl]
|
|
2275
2335
|
);
|
|
2336
|
+
const fetchAllMemories = useCallback2(async () => {
|
|
2337
|
+
try {
|
|
2338
|
+
return await getAllMemories();
|
|
2339
|
+
} catch (error) {
|
|
2340
|
+
throw new Error(
|
|
2341
|
+
"Failed to fetch all memories: " + (error instanceof Error ? error.message : String(error))
|
|
2342
|
+
);
|
|
2343
|
+
}
|
|
2344
|
+
}, []);
|
|
2345
|
+
const fetchMemoriesByNamespace = useCallback2(
|
|
2346
|
+
async (namespace) => {
|
|
2347
|
+
if (!namespace) {
|
|
2348
|
+
throw new Error("Missing required field: namespace");
|
|
2349
|
+
}
|
|
2350
|
+
try {
|
|
2351
|
+
return await getMemoriesByNamespace(namespace);
|
|
2352
|
+
} catch (error) {
|
|
2353
|
+
throw new Error(
|
|
2354
|
+
`Failed to fetch memories for namespace "${namespace}": ` + (error instanceof Error ? error.message : String(error))
|
|
2355
|
+
);
|
|
2356
|
+
}
|
|
2357
|
+
},
|
|
2358
|
+
[]
|
|
2359
|
+
);
|
|
2360
|
+
const fetchMemoriesByKey = useCallback2(
|
|
2361
|
+
async (namespace, key) => {
|
|
2362
|
+
if (!namespace || !key) {
|
|
2363
|
+
throw new Error("Missing required fields: namespace, key");
|
|
2364
|
+
}
|
|
2365
|
+
try {
|
|
2366
|
+
return await getMemories(namespace, key);
|
|
2367
|
+
} catch (error) {
|
|
2368
|
+
throw new Error(
|
|
2369
|
+
`Failed to fetch memories for "${namespace}:${key}": ` + (error instanceof Error ? error.message : String(error))
|
|
2370
|
+
);
|
|
2371
|
+
}
|
|
2372
|
+
},
|
|
2373
|
+
[]
|
|
2374
|
+
);
|
|
2375
|
+
const updateMemory = useCallback2(
|
|
2376
|
+
async (id, updates) => {
|
|
2377
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
2378
|
+
throw new Error("id must be a non-negative integer");
|
|
2379
|
+
}
|
|
2380
|
+
try {
|
|
2381
|
+
const embeddingModelToUse = embeddingProvider === "api" ? embeddingModel ?? DEFAULT_API_EMBEDDING_MODEL : embeddingModel && embeddingModel !== DEFAULT_API_EMBEDDING_MODEL ? embeddingModel : DEFAULT_LOCAL_EMBEDDING_MODEL;
|
|
2382
|
+
const embeddingOptions = {
|
|
2383
|
+
model: embeddingModelToUse,
|
|
2384
|
+
provider: embeddingProvider,
|
|
2385
|
+
getToken: getToken || void 0,
|
|
2386
|
+
baseUrl
|
|
2387
|
+
};
|
|
2388
|
+
if (!updates.type || !updates.namespace || !updates.key || !updates.value || !updates.rawEvidence || updates.confidence === void 0 || updates.confidence === null || updates.pii === void 0 || updates.pii === null) {
|
|
2389
|
+
throw new Error(
|
|
2390
|
+
"Missing required fields: type, namespace, key, value, rawEvidence, confidence, pii"
|
|
2391
|
+
);
|
|
2392
|
+
}
|
|
2393
|
+
const existingMemory = await getMemoryById(id);
|
|
2394
|
+
if (!existingMemory) {
|
|
2395
|
+
throw new Error(`Memory with id ${id} not found`);
|
|
2396
|
+
}
|
|
2397
|
+
const embeddingFieldsChanged = updates.value !== void 0 && updates.value !== existingMemory.value || updates.rawEvidence !== void 0 && updates.rawEvidence !== existingMemory.rawEvidence || updates.type !== void 0 && updates.type !== existingMemory.type || updates.namespace !== void 0 && updates.namespace !== existingMemory.namespace || updates.key !== void 0 && updates.key !== existingMemory.key;
|
|
2398
|
+
if (!embeddingFieldsChanged) {
|
|
2399
|
+
return existingMemory;
|
|
2400
|
+
}
|
|
2401
|
+
const memory = {
|
|
2402
|
+
type: updates.type,
|
|
2403
|
+
namespace: updates.namespace,
|
|
2404
|
+
key: updates.key,
|
|
2405
|
+
value: updates.value,
|
|
2406
|
+
rawEvidence: updates.rawEvidence,
|
|
2407
|
+
confidence: updates.confidence,
|
|
2408
|
+
pii: updates.pii
|
|
2409
|
+
};
|
|
2410
|
+
let embedding = existingMemory.embedding ?? [];
|
|
2411
|
+
let embeddingModelToStore = existingMemory.embeddingModel ?? "";
|
|
2412
|
+
if (generateEmbeddings && embeddingModelToUse) {
|
|
2413
|
+
try {
|
|
2414
|
+
embedding = await generateEmbeddingForMemory(
|
|
2415
|
+
memory,
|
|
2416
|
+
embeddingOptions
|
|
2417
|
+
);
|
|
2418
|
+
embeddingModelToStore = embeddingModelToUse;
|
|
2419
|
+
} catch (embeddingError) {
|
|
2420
|
+
console.error(
|
|
2421
|
+
"Failed to generate embedding, keeping existing:",
|
|
2422
|
+
embeddingError
|
|
2423
|
+
);
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
return await updateMemoryById(
|
|
2427
|
+
id,
|
|
2428
|
+
updates,
|
|
2429
|
+
existingMemory,
|
|
2430
|
+
embedding,
|
|
2431
|
+
embeddingModelToStore
|
|
2432
|
+
);
|
|
2433
|
+
} catch (error) {
|
|
2434
|
+
throw new Error(
|
|
2435
|
+
`Failed to update memory ${id}: ` + (error instanceof Error ? error.message : String(error))
|
|
2436
|
+
);
|
|
2437
|
+
}
|
|
2438
|
+
},
|
|
2439
|
+
[embeddingModel, embeddingProvider, generateEmbeddings, getToken, baseUrl]
|
|
2440
|
+
);
|
|
2441
|
+
const removeMemory = useCallback2(
|
|
2442
|
+
async (namespace, key, value) => {
|
|
2443
|
+
if (!namespace || !key || !value) {
|
|
2444
|
+
throw new Error("Missing required fields: namespace, key, value");
|
|
2445
|
+
}
|
|
2446
|
+
try {
|
|
2447
|
+
await deleteMemory(namespace, key, value);
|
|
2448
|
+
} catch (error) {
|
|
2449
|
+
throw new Error(
|
|
2450
|
+
`Failed to delete memory "${namespace}:${key}:${value}": ` + (error instanceof Error ? error.message : String(error))
|
|
2451
|
+
);
|
|
2452
|
+
}
|
|
2453
|
+
},
|
|
2454
|
+
[]
|
|
2455
|
+
);
|
|
2456
|
+
const removeMemoryById = useCallback2(async (id) => {
|
|
2457
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
2458
|
+
throw new Error("id must be a non-negative integer");
|
|
2459
|
+
}
|
|
2460
|
+
try {
|
|
2461
|
+
await deleteMemoryById(id);
|
|
2462
|
+
} catch (error) {
|
|
2463
|
+
throw new Error(
|
|
2464
|
+
`Failed to delete memory with id ${id}: ` + (error instanceof Error ? error.message : String(error))
|
|
2465
|
+
);
|
|
2466
|
+
}
|
|
2467
|
+
}, []);
|
|
2468
|
+
const removeMemories = useCallback2(
|
|
2469
|
+
async (namespace, key) => {
|
|
2470
|
+
if (!namespace || !key) {
|
|
2471
|
+
throw new Error("Missing required fields: namespace, key");
|
|
2472
|
+
}
|
|
2473
|
+
try {
|
|
2474
|
+
await deleteMemories(namespace, key);
|
|
2475
|
+
} catch (error) {
|
|
2476
|
+
throw new Error(
|
|
2477
|
+
`Failed to delete memories for "${namespace}:${key}": ` + (error instanceof Error ? error.message : String(error))
|
|
2478
|
+
);
|
|
2479
|
+
}
|
|
2480
|
+
},
|
|
2481
|
+
[]
|
|
2482
|
+
);
|
|
2483
|
+
const clearMemories = useCallback2(async () => {
|
|
2484
|
+
try {
|
|
2485
|
+
await clearAllMemories();
|
|
2486
|
+
} catch (error) {
|
|
2487
|
+
throw new Error(
|
|
2488
|
+
"Failed to clear all memories: " + (error instanceof Error ? error.message : String(error))
|
|
2489
|
+
);
|
|
2490
|
+
}
|
|
2491
|
+
}, []);
|
|
2276
2492
|
return {
|
|
2277
2493
|
extractMemoriesFromMessage,
|
|
2278
|
-
searchMemories
|
|
2494
|
+
searchMemories,
|
|
2495
|
+
fetchAllMemories,
|
|
2496
|
+
fetchMemoriesByNamespace,
|
|
2497
|
+
fetchMemoriesByKey,
|
|
2498
|
+
updateMemory,
|
|
2499
|
+
removeMemory,
|
|
2500
|
+
removeMemoryById,
|
|
2501
|
+
removeMemories,
|
|
2502
|
+
clearMemories
|
|
2279
2503
|
};
|
|
2280
2504
|
}
|
|
2281
2505
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reverbia/sdk",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.20251212092701",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"test": "vitest run",
|
|
57
57
|
"build": "tsup",
|
|
58
58
|
"prepublishOnly": "pnpm build",
|
|
59
|
-
"docs": "typedoc
|
|
59
|
+
"docs": "typedoc",
|
|
60
60
|
"generate": "pnpm run spec && pnpm run docs"
|
|
61
61
|
},
|
|
62
62
|
"repository": {
|