@reverbia/sdk 1.0.0-next.20251202085701 → 1.0.0-next.20251202090922
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/next/index.cjs +73 -0
- package/dist/next/index.d.mts +21 -0
- package/dist/next/index.d.ts +21 -0
- package/dist/next/index.mjs +48 -0
- package/dist/react/chunk-FBCDBTKJ.mjs +55 -0
- package/dist/react/index.cjs +46747 -54
- package/dist/react/index.d.mts +11 -3
- package/dist/react/index.d.ts +11 -3
- package/dist/react/index.mjs +74 -43
- package/dist/react/onnxruntime_binding-5QEF3SUC.node +0 -0
- package/dist/react/onnxruntime_binding-BKPKNEGC.node +0 -0
- package/dist/react/onnxruntime_binding-FMOXGIUT.node +0 -0
- package/dist/react/onnxruntime_binding-OI2KMXC5.node +0 -0
- package/dist/react/onnxruntime_binding-UX44MLAZ.node +0 -0
- package/dist/react/onnxruntime_binding-Y2W7N7WY.node +0 -0
- package/dist/react/transformers.node-BSHUG7OY.mjs +46511 -0
- package/package.json +8 -2
package/dist/react/index.d.mts
CHANGED
|
@@ -339,12 +339,20 @@ type UseMemoryOptions = {
|
|
|
339
339
|
/**
|
|
340
340
|
* The model to use for fact extraction (default: "openai/gpt-4o")
|
|
341
341
|
*/
|
|
342
|
-
|
|
342
|
+
completionsModel?: string;
|
|
343
343
|
/**
|
|
344
|
-
* The model to use for generating embeddings
|
|
345
|
-
*
|
|
344
|
+
* The model to use for generating embeddings
|
|
345
|
+
* For local: default is "Snowflake/snowflake-arctic-embed-xs"
|
|
346
|
+
* For api: default is "openai/text-embedding-3-small"
|
|
347
|
+
* Set to null to disable embedding generation
|
|
346
348
|
*/
|
|
347
349
|
embeddingModel?: string | null;
|
|
350
|
+
/**
|
|
351
|
+
* The provider to use for generating embeddings (default: "local")
|
|
352
|
+
* "local": Uses a local HuggingFace model (in-browser)
|
|
353
|
+
* "api": Uses the backend API
|
|
354
|
+
*/
|
|
355
|
+
embeddingProvider?: "local" | "api";
|
|
348
356
|
/**
|
|
349
357
|
* Whether to automatically generate embeddings for extracted memories (default: true)
|
|
350
358
|
*/
|
package/dist/react/index.d.ts
CHANGED
|
@@ -339,12 +339,20 @@ type UseMemoryOptions = {
|
|
|
339
339
|
/**
|
|
340
340
|
* The model to use for fact extraction (default: "openai/gpt-4o")
|
|
341
341
|
*/
|
|
342
|
-
|
|
342
|
+
completionsModel?: string;
|
|
343
343
|
/**
|
|
344
|
-
* The model to use for generating embeddings
|
|
345
|
-
*
|
|
344
|
+
* The model to use for generating embeddings
|
|
345
|
+
* For local: default is "Snowflake/snowflake-arctic-embed-xs"
|
|
346
|
+
* For api: default is "openai/text-embedding-3-small"
|
|
347
|
+
* Set to null to disable embedding generation
|
|
346
348
|
*/
|
|
347
349
|
embeddingModel?: string | null;
|
|
350
|
+
/**
|
|
351
|
+
* The provider to use for generating embeddings (default: "local")
|
|
352
|
+
* "local": Uses a local HuggingFace model (in-browser)
|
|
353
|
+
* "api": Uses the backend API
|
|
354
|
+
*/
|
|
355
|
+
embeddingProvider?: "local" | "api";
|
|
348
356
|
/**
|
|
349
357
|
* Whether to automatically generate embeddings for extracted memories (default: true)
|
|
350
358
|
*/
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import "./chunk-FBCDBTKJ.mjs";
|
|
2
|
+
|
|
1
3
|
// src/react/useChat.ts
|
|
2
4
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
5
|
|
|
@@ -1372,37 +1374,61 @@ var getApiV1Models = (options) => {
|
|
|
1372
1374
|
});
|
|
1373
1375
|
};
|
|
1374
1376
|
|
|
1377
|
+
// src/lib/memory/constants.ts
|
|
1378
|
+
var DEFAULT_LOCAL_EMBEDDING_MODEL = "Snowflake/snowflake-arctic-embed-xs";
|
|
1379
|
+
var DEFAULT_API_EMBEDDING_MODEL = "openai/text-embedding-3-small";
|
|
1380
|
+
var DEFAULT_COMPLETION_MODEL = "openai/gpt-4o";
|
|
1381
|
+
|
|
1375
1382
|
// src/lib/memory/embeddings.ts
|
|
1383
|
+
var embeddingPipeline = null;
|
|
1376
1384
|
var generateEmbeddingForText = async (text, options = {}) => {
|
|
1377
|
-
const {
|
|
1378
|
-
|
|
1379
|
-
getToken,
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
const token =
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
headers.Authorization = `Bearer ${token}`;
|
|
1385
|
+
const { baseUrl = BASE_URL, provider = "local" } = options;
|
|
1386
|
+
if (provider === "api") {
|
|
1387
|
+
const { getToken, model: model2 } = options;
|
|
1388
|
+
if (!getToken) {
|
|
1389
|
+
throw new Error("getToken is required for API embeddings");
|
|
1390
|
+
}
|
|
1391
|
+
const token = await getToken();
|
|
1392
|
+
if (!token) {
|
|
1393
|
+
throw new Error("No access token available for API embeddings");
|
|
1387
1394
|
}
|
|
1388
1395
|
const response = await postApiV1Embeddings({
|
|
1389
1396
|
baseUrl,
|
|
1390
1397
|
body: {
|
|
1391
1398
|
input: text,
|
|
1392
|
-
model
|
|
1399
|
+
model: model2
|
|
1393
1400
|
},
|
|
1394
|
-
headers
|
|
1401
|
+
headers: {
|
|
1402
|
+
Authorization: `Bearer ${token}`
|
|
1403
|
+
}
|
|
1395
1404
|
});
|
|
1396
|
-
if (
|
|
1405
|
+
if (response.error) {
|
|
1397
1406
|
throw new Error(
|
|
1398
|
-
|
|
1407
|
+
typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
|
|
1399
1408
|
);
|
|
1400
1409
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1410
|
+
if (!response.data?.data?.[0]?.embedding) {
|
|
1411
|
+
throw new Error("No embedding returned from API");
|
|
1412
|
+
}
|
|
1413
|
+
return response.data.data[0].embedding;
|
|
1414
|
+
}
|
|
1415
|
+
let { model } = options;
|
|
1416
|
+
if (!model || model === DEFAULT_API_EMBEDDING_MODEL) {
|
|
1417
|
+
model = DEFAULT_LOCAL_EMBEDDING_MODEL;
|
|
1418
|
+
}
|
|
1419
|
+
try {
|
|
1420
|
+
if (!embeddingPipeline) {
|
|
1421
|
+
const { pipeline } = await import("./transformers.node-BSHUG7OY.mjs");
|
|
1422
|
+
embeddingPipeline = await pipeline("feature-extraction", model);
|
|
1423
|
+
}
|
|
1424
|
+
const output = await embeddingPipeline(text, {
|
|
1425
|
+
pooling: "cls",
|
|
1426
|
+
normalize: true
|
|
1427
|
+
});
|
|
1428
|
+
if (output?.data) {
|
|
1429
|
+
return Array.from(output.data);
|
|
1404
1430
|
}
|
|
1405
|
-
|
|
1431
|
+
throw new Error("Invalid embedding output from transformers.js");
|
|
1406
1432
|
} catch (error) {
|
|
1407
1433
|
console.error("Failed to generate embedding:", error);
|
|
1408
1434
|
throw error;
|
|
@@ -1419,20 +1445,11 @@ var generateEmbeddingForMemory = async (memory, options = {}) => {
|
|
|
1419
1445
|
return generateEmbeddingForText(text, options);
|
|
1420
1446
|
};
|
|
1421
1447
|
var generateEmbeddingsForMemories = async (memories, options = {}) => {
|
|
1422
|
-
const {
|
|
1423
|
-
model = "openai/text-embedding-3-small",
|
|
1424
|
-
getToken,
|
|
1425
|
-
baseUrl = BASE_URL
|
|
1426
|
-
} = options;
|
|
1427
1448
|
const embeddings = /* @__PURE__ */ new Map();
|
|
1428
1449
|
for (const memory of memories) {
|
|
1429
1450
|
const uniqueKey = `${memory.namespace}:${memory.key}:${memory.value}`;
|
|
1430
1451
|
try {
|
|
1431
|
-
const embedding = await generateEmbeddingForMemory(memory,
|
|
1432
|
-
model,
|
|
1433
|
-
getToken,
|
|
1434
|
-
baseUrl
|
|
1435
|
-
});
|
|
1452
|
+
const embedding = await generateEmbeddingForMemory(memory, options);
|
|
1436
1453
|
embeddings.set(uniqueKey, embedding);
|
|
1437
1454
|
} catch (error) {
|
|
1438
1455
|
console.error(
|
|
@@ -1464,29 +1481,42 @@ var updateMemoriesWithEmbeddings = async (embeddings, embeddingModel) => {
|
|
|
1464
1481
|
await Promise.all(updates);
|
|
1465
1482
|
};
|
|
1466
1483
|
var generateAndStoreEmbeddings = async (memories, options = {}) => {
|
|
1467
|
-
|
|
1484
|
+
let { model } = options;
|
|
1485
|
+
const { provider = "local" } = options;
|
|
1486
|
+
if (!model) {
|
|
1487
|
+
if (provider === "local") {
|
|
1488
|
+
model = DEFAULT_LOCAL_EMBEDDING_MODEL;
|
|
1489
|
+
} else {
|
|
1490
|
+
model = DEFAULT_API_EMBEDDING_MODEL;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
if (provider === "local" && model === DEFAULT_API_EMBEDDING_MODEL) {
|
|
1494
|
+
model = DEFAULT_LOCAL_EMBEDDING_MODEL;
|
|
1495
|
+
}
|
|
1468
1496
|
if (memories.length === 0) {
|
|
1469
1497
|
return;
|
|
1470
1498
|
}
|
|
1471
1499
|
console.log(`Generating embeddings for ${memories.length} memories...`);
|
|
1472
|
-
const embeddings = await generateEmbeddingsForMemories(memories,
|
|
1500
|
+
const embeddings = await generateEmbeddingsForMemories(memories, {
|
|
1501
|
+
...options,
|
|
1502
|
+
model
|
|
1503
|
+
});
|
|
1473
1504
|
await updateMemoriesWithEmbeddings(embeddings, model);
|
|
1474
1505
|
console.log(`Generated and stored ${embeddings.size} embeddings`);
|
|
1475
1506
|
};
|
|
1476
|
-
var generateQueryEmbedding = async (query, options = {}) => {
|
|
1477
|
-
return generateEmbeddingForText(query, options);
|
|
1478
|
-
};
|
|
1479
1507
|
|
|
1480
1508
|
// src/react/useMemory.ts
|
|
1481
1509
|
function useMemory(options = {}) {
|
|
1482
1510
|
const {
|
|
1483
|
-
|
|
1484
|
-
embeddingModel
|
|
1511
|
+
completionsModel = DEFAULT_COMPLETION_MODEL,
|
|
1512
|
+
embeddingModel: userEmbeddingModel,
|
|
1513
|
+
embeddingProvider = "local",
|
|
1485
1514
|
generateEmbeddings = true,
|
|
1486
1515
|
onFactsExtracted,
|
|
1487
1516
|
getToken,
|
|
1488
1517
|
baseUrl = BASE_URL
|
|
1489
1518
|
} = options;
|
|
1519
|
+
const embeddingModel = userEmbeddingModel === void 0 ? embeddingProvider === "local" ? DEFAULT_LOCAL_EMBEDDING_MODEL : DEFAULT_API_EMBEDDING_MODEL : userEmbeddingModel;
|
|
1490
1520
|
const extractionInProgressRef = useRef3(false);
|
|
1491
1521
|
const extractMemoriesFromMessage = useCallback2(
|
|
1492
1522
|
async (options2) => {
|
|
@@ -1511,7 +1541,7 @@ function useMemory(options = {}) {
|
|
|
1511
1541
|
},
|
|
1512
1542
|
...messages
|
|
1513
1543
|
],
|
|
1514
|
-
model: model ||
|
|
1544
|
+
model: model || completionsModel
|
|
1515
1545
|
},
|
|
1516
1546
|
headers: {
|
|
1517
1547
|
Authorization: `Bearer ${token}`
|
|
@@ -1626,6 +1656,7 @@ function useMemory(options = {}) {
|
|
|
1626
1656
|
try {
|
|
1627
1657
|
await generateAndStoreEmbeddings(result.items, {
|
|
1628
1658
|
model: embeddingModel,
|
|
1659
|
+
provider: embeddingProvider,
|
|
1629
1660
|
getToken: getToken || void 0,
|
|
1630
1661
|
baseUrl
|
|
1631
1662
|
});
|
|
@@ -1652,8 +1683,9 @@ function useMemory(options = {}) {
|
|
|
1652
1683
|
}
|
|
1653
1684
|
},
|
|
1654
1685
|
[
|
|
1655
|
-
|
|
1686
|
+
completionsModel,
|
|
1656
1687
|
embeddingModel,
|
|
1688
|
+
embeddingProvider,
|
|
1657
1689
|
generateEmbeddings,
|
|
1658
1690
|
getToken,
|
|
1659
1691
|
onFactsExtracted,
|
|
@@ -1662,16 +1694,15 @@ function useMemory(options = {}) {
|
|
|
1662
1694
|
);
|
|
1663
1695
|
const searchMemories = useCallback2(
|
|
1664
1696
|
async (query, limit = 10, minSimilarity = 0.6) => {
|
|
1665
|
-
if (!
|
|
1666
|
-
console.warn(
|
|
1667
|
-
"Cannot search memories: getToken or embeddingModel not provided"
|
|
1668
|
-
);
|
|
1697
|
+
if (!embeddingModel) {
|
|
1698
|
+
console.warn("Cannot search memories: embeddingModel not provided");
|
|
1669
1699
|
return [];
|
|
1670
1700
|
}
|
|
1671
1701
|
try {
|
|
1672
1702
|
console.log(`[Memory Search] Searching for: "${query}"`);
|
|
1673
|
-
const queryEmbedding = await
|
|
1703
|
+
const queryEmbedding = await generateEmbeddingForText(query, {
|
|
1674
1704
|
model: embeddingModel,
|
|
1705
|
+
provider: embeddingProvider,
|
|
1675
1706
|
getToken,
|
|
1676
1707
|
baseUrl
|
|
1677
1708
|
});
|
|
@@ -1698,7 +1729,7 @@ function useMemory(options = {}) {
|
|
|
1698
1729
|
return [];
|
|
1699
1730
|
}
|
|
1700
1731
|
},
|
|
1701
|
-
[embeddingModel, getToken, baseUrl]
|
|
1732
|
+
[embeddingModel, embeddingProvider, getToken, baseUrl]
|
|
1702
1733
|
);
|
|
1703
1734
|
return {
|
|
1704
1735
|
extractMemoriesFromMessage,
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|