@reverbia/sdk 1.0.0-next.20251217144909 → 1.0.0-next.20251218162622
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 +126 -4
- package/dist/expo/index.d.mts +78 -2
- package/dist/expo/index.d.ts +78 -2
- package/dist/expo/index.mjs +127 -4
- package/dist/react/index.cjs +218 -79
- package/dist/react/index.d.mts +83 -2
- package/dist/react/index.d.ts +83 -2
- package/dist/react/index.mjs +198 -58
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -64,6 +64,9 @@ __export(index_exports, {
|
|
|
64
64
|
hasEncryptionKey: () => hasEncryptionKey,
|
|
65
65
|
memoryStorageSchema: () => memoryStorageSchema,
|
|
66
66
|
requestEncryptionKey: () => requestEncryptionKey,
|
|
67
|
+
sdkMigrations: () => sdkMigrations,
|
|
68
|
+
sdkModelClasses: () => sdkModelClasses,
|
|
69
|
+
sdkSchema: () => sdkSchema,
|
|
67
70
|
selectTool: () => selectTool,
|
|
68
71
|
settingsStorageSchema: () => settingsStorageSchema,
|
|
69
72
|
storeDropboxToken: () => storeToken,
|
|
@@ -1312,7 +1315,8 @@ function useChat(options) {
|
|
|
1312
1315
|
onData,
|
|
1313
1316
|
runTools = true,
|
|
1314
1317
|
headers,
|
|
1315
|
-
memoryContext
|
|
1318
|
+
memoryContext,
|
|
1319
|
+
searchContext
|
|
1316
1320
|
}) => {
|
|
1317
1321
|
const messagesValidation = validateMessages(messages);
|
|
1318
1322
|
if (!messagesValidation.valid) {
|
|
@@ -1338,6 +1342,22 @@ function useChat(options) {
|
|
|
1338
1342
|
};
|
|
1339
1343
|
messagesWithContext = [memorySystemMessage, ...messages];
|
|
1340
1344
|
}
|
|
1345
|
+
if (searchContext) {
|
|
1346
|
+
const searchSystemMessage = {
|
|
1347
|
+
role: "system",
|
|
1348
|
+
content: [
|
|
1349
|
+
{
|
|
1350
|
+
type: "text",
|
|
1351
|
+
text: "Here are the search results for the user's query. Use this information to respond to the user's request:"
|
|
1352
|
+
},
|
|
1353
|
+
{
|
|
1354
|
+
type: "text",
|
|
1355
|
+
text: searchContext
|
|
1356
|
+
}
|
|
1357
|
+
]
|
|
1358
|
+
};
|
|
1359
|
+
messagesWithContext = [searchSystemMessage, ...messagesWithContext];
|
|
1360
|
+
}
|
|
1341
1361
|
let messagesWithToolContext = messagesWithContext;
|
|
1342
1362
|
const shouldRunTools = runTools && tools && tools.length > 0;
|
|
1343
1363
|
if (shouldRunTools) {
|
|
@@ -2220,7 +2240,9 @@ function useChatStorage(options) {
|
|
|
2220
2240
|
onData: perRequestOnData,
|
|
2221
2241
|
runTools,
|
|
2222
2242
|
headers,
|
|
2223
|
-
memoryContext
|
|
2243
|
+
memoryContext,
|
|
2244
|
+
searchContext,
|
|
2245
|
+
sources
|
|
2224
2246
|
} = args;
|
|
2225
2247
|
let convId;
|
|
2226
2248
|
try {
|
|
@@ -2286,7 +2308,8 @@ function useChatStorage(options) {
|
|
|
2286
2308
|
onData: perRequestOnData,
|
|
2287
2309
|
runTools,
|
|
2288
2310
|
headers,
|
|
2289
|
-
memoryContext
|
|
2311
|
+
memoryContext,
|
|
2312
|
+
searchContext
|
|
2290
2313
|
});
|
|
2291
2314
|
const responseDuration = (Date.now() - startTime) / 1e3;
|
|
2292
2315
|
if (result.error || !result.data) {
|
|
@@ -2303,19 +2326,24 @@ function useChatStorage(options) {
|
|
|
2303
2326
|
model: responseModel,
|
|
2304
2327
|
usage: convertUsageToStored(abortedResult.data?.usage),
|
|
2305
2328
|
responseDuration,
|
|
2306
|
-
wasStopped: true
|
|
2329
|
+
wasStopped: true,
|
|
2330
|
+
sources
|
|
2307
2331
|
});
|
|
2308
2332
|
const completionData = abortedResult.data || {
|
|
2309
2333
|
id: `aborted-${Date.now()}`,
|
|
2310
2334
|
model: responseModel,
|
|
2311
|
-
choices: [
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2335
|
+
choices: [
|
|
2336
|
+
{
|
|
2337
|
+
index: 0,
|
|
2338
|
+
message: {
|
|
2339
|
+
role: "assistant",
|
|
2340
|
+
content: [
|
|
2341
|
+
{ type: "text", text: assistantContent2 }
|
|
2342
|
+
]
|
|
2343
|
+
},
|
|
2344
|
+
finish_reason: "stop"
|
|
2345
|
+
}
|
|
2346
|
+
],
|
|
2319
2347
|
usage: void 0
|
|
2320
2348
|
};
|
|
2321
2349
|
return {
|
|
@@ -2374,7 +2402,12 @@ function useChatStorage(options) {
|
|
|
2374
2402
|
);
|
|
2375
2403
|
const updateMessageEmbedding = (0, import_react2.useCallback)(
|
|
2376
2404
|
async (uniqueId, vector, embeddingModel) => {
|
|
2377
|
-
return updateMessageEmbeddingOp(
|
|
2405
|
+
return updateMessageEmbeddingOp(
|
|
2406
|
+
storageCtx,
|
|
2407
|
+
uniqueId,
|
|
2408
|
+
vector,
|
|
2409
|
+
embeddingModel
|
|
2410
|
+
);
|
|
2378
2411
|
},
|
|
2379
2412
|
[storageCtx]
|
|
2380
2413
|
);
|
|
@@ -2398,41 +2431,14 @@ function useChatStorage(options) {
|
|
|
2398
2431
|
};
|
|
2399
2432
|
}
|
|
2400
2433
|
|
|
2401
|
-
// src/
|
|
2402
|
-
var
|
|
2403
|
-
var
|
|
2404
|
-
|
|
2405
|
-
// src/lib/db/memory/schema.ts
|
|
2406
|
-
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
2407
|
-
var memoryStorageSchema = (0, import_watermelondb4.appSchema)({
|
|
2408
|
-
version: 1,
|
|
2409
|
-
tables: [
|
|
2410
|
-
(0, import_watermelondb4.tableSchema)({
|
|
2411
|
-
name: "memories",
|
|
2412
|
-
columns: [
|
|
2413
|
-
{ name: "type", type: "string", isIndexed: true },
|
|
2414
|
-
{ name: "namespace", type: "string", isIndexed: true },
|
|
2415
|
-
{ name: "key", type: "string", isIndexed: true },
|
|
2416
|
-
{ name: "value", type: "string" },
|
|
2417
|
-
{ name: "raw_evidence", type: "string" },
|
|
2418
|
-
{ name: "confidence", type: "number" },
|
|
2419
|
-
{ name: "pii", type: "boolean", isIndexed: true },
|
|
2420
|
-
{ name: "composite_key", type: "string", isIndexed: true },
|
|
2421
|
-
{ name: "unique_key", type: "string", isIndexed: true },
|
|
2422
|
-
{ name: "created_at", type: "number", isIndexed: true },
|
|
2423
|
-
{ name: "updated_at", type: "number" },
|
|
2424
|
-
{ name: "embedding", type: "string", isOptional: true },
|
|
2425
|
-
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2426
|
-
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2427
|
-
]
|
|
2428
|
-
})
|
|
2429
|
-
]
|
|
2430
|
-
});
|
|
2434
|
+
// src/lib/db/schema.ts
|
|
2435
|
+
var import_watermelondb6 = require("@nozbe/watermelondb");
|
|
2436
|
+
var import_migrations2 = require("@nozbe/watermelondb/Schema/migrations");
|
|
2431
2437
|
|
|
2432
2438
|
// src/lib/db/memory/models.ts
|
|
2433
|
-
var
|
|
2439
|
+
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
2434
2440
|
var import_decorators2 = require("@nozbe/watermelondb/decorators");
|
|
2435
|
-
var Memory = class extends
|
|
2441
|
+
var Memory = class extends import_watermelondb4.Model {
|
|
2436
2442
|
};
|
|
2437
2443
|
Memory.table = "memories";
|
|
2438
2444
|
__decorateClass([
|
|
@@ -2478,6 +2484,149 @@ __decorateClass([
|
|
|
2478
2484
|
(0, import_decorators2.field)("is_deleted")
|
|
2479
2485
|
], Memory.prototype, "isDeleted", 2);
|
|
2480
2486
|
|
|
2487
|
+
// src/lib/db/settings/models.ts
|
|
2488
|
+
var import_watermelondb5 = require("@nozbe/watermelondb");
|
|
2489
|
+
var import_decorators3 = require("@nozbe/watermelondb/decorators");
|
|
2490
|
+
var ModelPreference = class extends import_watermelondb5.Model {
|
|
2491
|
+
};
|
|
2492
|
+
ModelPreference.table = "modelPreferences";
|
|
2493
|
+
__decorateClass([
|
|
2494
|
+
(0, import_decorators3.text)("wallet_address")
|
|
2495
|
+
], ModelPreference.prototype, "walletAddress", 2);
|
|
2496
|
+
__decorateClass([
|
|
2497
|
+
(0, import_decorators3.text)("models")
|
|
2498
|
+
], ModelPreference.prototype, "models", 2);
|
|
2499
|
+
|
|
2500
|
+
// src/lib/db/schema.ts
|
|
2501
|
+
var SDK_SCHEMA_VERSION = 4;
|
|
2502
|
+
var sdkSchema = (0, import_watermelondb6.appSchema)({
|
|
2503
|
+
version: SDK_SCHEMA_VERSION,
|
|
2504
|
+
tables: [
|
|
2505
|
+
// Chat storage tables
|
|
2506
|
+
(0, import_watermelondb6.tableSchema)({
|
|
2507
|
+
name: "history",
|
|
2508
|
+
columns: [
|
|
2509
|
+
{ name: "message_id", type: "number" },
|
|
2510
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
2511
|
+
{ name: "role", type: "string", isIndexed: true },
|
|
2512
|
+
{ name: "content", type: "string" },
|
|
2513
|
+
{ name: "model", type: "string", isOptional: true },
|
|
2514
|
+
{ name: "files", type: "string", isOptional: true },
|
|
2515
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
2516
|
+
{ name: "updated_at", type: "number" },
|
|
2517
|
+
{ name: "vector", type: "string", isOptional: true },
|
|
2518
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2519
|
+
{ name: "usage", type: "string", isOptional: true },
|
|
2520
|
+
{ name: "sources", type: "string", isOptional: true },
|
|
2521
|
+
{ name: "response_duration", type: "number", isOptional: true },
|
|
2522
|
+
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
2523
|
+
]
|
|
2524
|
+
}),
|
|
2525
|
+
(0, import_watermelondb6.tableSchema)({
|
|
2526
|
+
name: "conversations",
|
|
2527
|
+
columns: [
|
|
2528
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
2529
|
+
{ name: "title", type: "string" },
|
|
2530
|
+
{ name: "created_at", type: "number" },
|
|
2531
|
+
{ name: "updated_at", type: "number" },
|
|
2532
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2533
|
+
]
|
|
2534
|
+
}),
|
|
2535
|
+
// Memory storage tables
|
|
2536
|
+
(0, import_watermelondb6.tableSchema)({
|
|
2537
|
+
name: "memories",
|
|
2538
|
+
columns: [
|
|
2539
|
+
{ name: "type", type: "string", isIndexed: true },
|
|
2540
|
+
{ name: "namespace", type: "string", isIndexed: true },
|
|
2541
|
+
{ name: "key", type: "string", isIndexed: true },
|
|
2542
|
+
{ name: "value", type: "string" },
|
|
2543
|
+
{ name: "raw_evidence", type: "string" },
|
|
2544
|
+
{ name: "confidence", type: "number" },
|
|
2545
|
+
{ name: "pii", type: "boolean", isIndexed: true },
|
|
2546
|
+
{ name: "composite_key", type: "string", isIndexed: true },
|
|
2547
|
+
{ name: "unique_key", type: "string", isIndexed: true },
|
|
2548
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
2549
|
+
{ name: "updated_at", type: "number" },
|
|
2550
|
+
{ name: "embedding", type: "string", isOptional: true },
|
|
2551
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2552
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2553
|
+
]
|
|
2554
|
+
}),
|
|
2555
|
+
// Settings storage tables
|
|
2556
|
+
(0, import_watermelondb6.tableSchema)({
|
|
2557
|
+
name: "modelPreferences",
|
|
2558
|
+
columns: [
|
|
2559
|
+
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
2560
|
+
{ name: "models", type: "string", isOptional: true }
|
|
2561
|
+
]
|
|
2562
|
+
})
|
|
2563
|
+
]
|
|
2564
|
+
});
|
|
2565
|
+
var sdkMigrations = (0, import_migrations2.schemaMigrations)({
|
|
2566
|
+
migrations: [
|
|
2567
|
+
// v2 -> v3: Added was_stopped column to history
|
|
2568
|
+
{
|
|
2569
|
+
toVersion: 3,
|
|
2570
|
+
steps: [
|
|
2571
|
+
(0, import_migrations2.addColumns)({
|
|
2572
|
+
table: "history",
|
|
2573
|
+
columns: [{ name: "was_stopped", type: "boolean", isOptional: true }]
|
|
2574
|
+
})
|
|
2575
|
+
]
|
|
2576
|
+
},
|
|
2577
|
+
// v3 -> v4: Added settings storage (modelPreferences table)
|
|
2578
|
+
{
|
|
2579
|
+
toVersion: 4,
|
|
2580
|
+
steps: [
|
|
2581
|
+
(0, import_migrations2.createTable)({
|
|
2582
|
+
name: "modelPreferences",
|
|
2583
|
+
columns: [
|
|
2584
|
+
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
2585
|
+
{ name: "models", type: "string", isOptional: true }
|
|
2586
|
+
]
|
|
2587
|
+
})
|
|
2588
|
+
]
|
|
2589
|
+
}
|
|
2590
|
+
]
|
|
2591
|
+
});
|
|
2592
|
+
var sdkModelClasses = [
|
|
2593
|
+
Message,
|
|
2594
|
+
Conversation,
|
|
2595
|
+
Memory,
|
|
2596
|
+
ModelPreference
|
|
2597
|
+
];
|
|
2598
|
+
|
|
2599
|
+
// src/react/useMemoryStorage.ts
|
|
2600
|
+
var import_react3 = require("react");
|
|
2601
|
+
var import_client6 = require("@reverbia/sdk");
|
|
2602
|
+
|
|
2603
|
+
// src/lib/db/memory/schema.ts
|
|
2604
|
+
var import_watermelondb7 = require("@nozbe/watermelondb");
|
|
2605
|
+
var memoryStorageSchema = (0, import_watermelondb7.appSchema)({
|
|
2606
|
+
version: 1,
|
|
2607
|
+
tables: [
|
|
2608
|
+
(0, import_watermelondb7.tableSchema)({
|
|
2609
|
+
name: "memories",
|
|
2610
|
+
columns: [
|
|
2611
|
+
{ name: "type", type: "string", isIndexed: true },
|
|
2612
|
+
{ name: "namespace", type: "string", isIndexed: true },
|
|
2613
|
+
{ name: "key", type: "string", isIndexed: true },
|
|
2614
|
+
{ name: "value", type: "string" },
|
|
2615
|
+
{ name: "raw_evidence", type: "string" },
|
|
2616
|
+
{ name: "confidence", type: "number" },
|
|
2617
|
+
{ name: "pii", type: "boolean", isIndexed: true },
|
|
2618
|
+
{ name: "composite_key", type: "string", isIndexed: true },
|
|
2619
|
+
{ name: "unique_key", type: "string", isIndexed: true },
|
|
2620
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
2621
|
+
{ name: "updated_at", type: "number" },
|
|
2622
|
+
{ name: "embedding", type: "string", isOptional: true },
|
|
2623
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2624
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2625
|
+
]
|
|
2626
|
+
})
|
|
2627
|
+
]
|
|
2628
|
+
});
|
|
2629
|
+
|
|
2481
2630
|
// src/lib/db/memory/types.ts
|
|
2482
2631
|
function generateCompositeKey(namespace, key) {
|
|
2483
2632
|
return `${namespace}:${key}`;
|
|
@@ -2505,7 +2654,7 @@ function cosineSimilarity2(a, b) {
|
|
|
2505
2654
|
}
|
|
2506
2655
|
|
|
2507
2656
|
// src/lib/db/memory/operations.ts
|
|
2508
|
-
var
|
|
2657
|
+
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
2509
2658
|
function memoryToStored(memory) {
|
|
2510
2659
|
return {
|
|
2511
2660
|
uniqueId: memory.id,
|
|
@@ -2526,7 +2675,7 @@ function memoryToStored(memory) {
|
|
|
2526
2675
|
};
|
|
2527
2676
|
}
|
|
2528
2677
|
async function getAllMemoriesOp(ctx) {
|
|
2529
|
-
const results = await ctx.memoriesCollection.query(
|
|
2678
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("is_deleted", false), import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.desc)).fetch();
|
|
2530
2679
|
return results.map(memoryToStored);
|
|
2531
2680
|
}
|
|
2532
2681
|
async function getMemoryByIdOp(ctx, id) {
|
|
@@ -2540,18 +2689,18 @@ async function getMemoryByIdOp(ctx, id) {
|
|
|
2540
2689
|
}
|
|
2541
2690
|
async function getMemoriesByNamespaceOp(ctx, namespace) {
|
|
2542
2691
|
const results = await ctx.memoriesCollection.query(
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2692
|
+
import_watermelondb8.Q.where("namespace", namespace),
|
|
2693
|
+
import_watermelondb8.Q.where("is_deleted", false),
|
|
2694
|
+
import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.desc)
|
|
2546
2695
|
).fetch();
|
|
2547
2696
|
return results.map(memoryToStored);
|
|
2548
2697
|
}
|
|
2549
2698
|
async function getMemoriesByKeyOp(ctx, namespace, key) {
|
|
2550
2699
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
2551
2700
|
const results = await ctx.memoriesCollection.query(
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2701
|
+
import_watermelondb8.Q.where("composite_key", compositeKey),
|
|
2702
|
+
import_watermelondb8.Q.where("is_deleted", false),
|
|
2703
|
+
import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.desc)
|
|
2555
2704
|
).fetch();
|
|
2556
2705
|
return results.map(memoryToStored);
|
|
2557
2706
|
}
|
|
@@ -2559,7 +2708,7 @@ async function saveMemoryOp(ctx, opts) {
|
|
|
2559
2708
|
const compositeKey = generateCompositeKey(opts.namespace, opts.key);
|
|
2560
2709
|
const uniqueKey = generateUniqueKey(opts.namespace, opts.key, opts.value);
|
|
2561
2710
|
const result = await ctx.database.write(async () => {
|
|
2562
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2711
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("unique_key", uniqueKey)).fetch();
|
|
2563
2712
|
if (existing.length > 0) {
|
|
2564
2713
|
const existingMemory = existing[0];
|
|
2565
2714
|
const shouldPreserveEmbedding = existingMemory.value === opts.value && existingMemory.rawEvidence === opts.rawEvidence && existingMemory.type === opts.type && existingMemory.namespace === opts.namespace && existingMemory.key === opts.key && existingMemory.embedding !== void 0 && existingMemory.embedding.length > 0 && !opts.embedding;
|
|
@@ -2632,7 +2781,7 @@ async function updateMemoryOp(ctx, id, updates) {
|
|
|
2632
2781
|
const newCompositeKey = generateCompositeKey(newNamespace, newKey);
|
|
2633
2782
|
const newUniqueKey = generateUniqueKey(newNamespace, newKey, newValue);
|
|
2634
2783
|
if (newUniqueKey !== memory.uniqueKey) {
|
|
2635
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2784
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("unique_key", newUniqueKey), import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
2636
2785
|
if (existing.length > 0) {
|
|
2637
2786
|
return { ok: false, reason: "conflict", conflictingKey: newUniqueKey };
|
|
2638
2787
|
}
|
|
@@ -2688,7 +2837,7 @@ async function deleteMemoryByIdOp(ctx, id) {
|
|
|
2688
2837
|
}
|
|
2689
2838
|
async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
2690
2839
|
const uniqueKey = generateUniqueKey(namespace, key, value);
|
|
2691
|
-
const results = await ctx.memoriesCollection.query(
|
|
2840
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("unique_key", uniqueKey)).fetch();
|
|
2692
2841
|
if (results.length > 0) {
|
|
2693
2842
|
await ctx.database.write(async () => {
|
|
2694
2843
|
await results[0].update((mem) => {
|
|
@@ -2699,7 +2848,7 @@ async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
|
2699
2848
|
}
|
|
2700
2849
|
async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
2701
2850
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
2702
|
-
const results = await ctx.memoriesCollection.query(
|
|
2851
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("composite_key", compositeKey), import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
2703
2852
|
await ctx.database.write(async () => {
|
|
2704
2853
|
for (const memory of results) {
|
|
2705
2854
|
await memory.update((mem) => {
|
|
@@ -2709,7 +2858,7 @@ async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
|
2709
2858
|
});
|
|
2710
2859
|
}
|
|
2711
2860
|
async function clearAllMemoriesOp(ctx) {
|
|
2712
|
-
const results = await ctx.memoriesCollection.query(
|
|
2861
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
2713
2862
|
await ctx.database.write(async () => {
|
|
2714
2863
|
for (const memory of results) {
|
|
2715
2864
|
await memory.update((mem) => {
|
|
@@ -2719,7 +2868,7 @@ async function clearAllMemoriesOp(ctx) {
|
|
|
2719
2868
|
});
|
|
2720
2869
|
}
|
|
2721
2870
|
async function searchSimilarMemoriesOp(ctx, queryEmbedding, limit = 10, minSimilarity = 0.6) {
|
|
2722
|
-
const allMemories = await ctx.memoriesCollection.query(
|
|
2871
|
+
const allMemories = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
2723
2872
|
const memoriesWithEmbeddings = allMemories.filter(
|
|
2724
2873
|
(m) => m.embedding && m.embedding.length > 0
|
|
2725
2874
|
);
|
|
@@ -3539,11 +3688,11 @@ function useMemoryStorage(options) {
|
|
|
3539
3688
|
var import_react4 = require("react");
|
|
3540
3689
|
|
|
3541
3690
|
// src/lib/db/settings/schema.ts
|
|
3542
|
-
var
|
|
3543
|
-
var settingsStorageSchema = (0,
|
|
3691
|
+
var import_watermelondb9 = require("@nozbe/watermelondb");
|
|
3692
|
+
var settingsStorageSchema = (0, import_watermelondb9.appSchema)({
|
|
3544
3693
|
version: 1,
|
|
3545
3694
|
tables: [
|
|
3546
|
-
(0,
|
|
3695
|
+
(0, import_watermelondb9.tableSchema)({
|
|
3547
3696
|
name: "modelPreferences",
|
|
3548
3697
|
columns: [
|
|
3549
3698
|
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
@@ -3553,21 +3702,8 @@ var settingsStorageSchema = (0, import_watermelondb7.appSchema)({
|
|
|
3553
3702
|
]
|
|
3554
3703
|
});
|
|
3555
3704
|
|
|
3556
|
-
// src/lib/db/settings/models.ts
|
|
3557
|
-
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
3558
|
-
var import_decorators3 = require("@nozbe/watermelondb/decorators");
|
|
3559
|
-
var ModelPreference = class extends import_watermelondb8.Model {
|
|
3560
|
-
};
|
|
3561
|
-
ModelPreference.table = "modelPreferences";
|
|
3562
|
-
__decorateClass([
|
|
3563
|
-
(0, import_decorators3.text)("wallet_address")
|
|
3564
|
-
], ModelPreference.prototype, "walletAddress", 2);
|
|
3565
|
-
__decorateClass([
|
|
3566
|
-
(0, import_decorators3.text)("models")
|
|
3567
|
-
], ModelPreference.prototype, "models", 2);
|
|
3568
|
-
|
|
3569
3705
|
// src/lib/db/settings/operations.ts
|
|
3570
|
-
var
|
|
3706
|
+
var import_watermelondb10 = require("@nozbe/watermelondb");
|
|
3571
3707
|
function modelPreferenceToStored(preference) {
|
|
3572
3708
|
return {
|
|
3573
3709
|
uniqueId: preference.id,
|
|
@@ -3576,12 +3712,12 @@ function modelPreferenceToStored(preference) {
|
|
|
3576
3712
|
};
|
|
3577
3713
|
}
|
|
3578
3714
|
async function getModelPreferenceOp(ctx, walletAddress) {
|
|
3579
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
3715
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb10.Q.where("wallet_address", walletAddress)).fetch();
|
|
3580
3716
|
return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
|
|
3581
3717
|
}
|
|
3582
3718
|
async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
3583
3719
|
const result = await ctx.database.write(async () => {
|
|
3584
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
3720
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb10.Q.where("wallet_address", walletAddress)).fetch();
|
|
3585
3721
|
if (results.length > 0) {
|
|
3586
3722
|
const preference = results[0];
|
|
3587
3723
|
await preference.update((pref) => {
|
|
@@ -3599,7 +3735,7 @@ async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
|
3599
3735
|
return modelPreferenceToStored(result);
|
|
3600
3736
|
}
|
|
3601
3737
|
async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
3602
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
3738
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb10.Q.where("wallet_address", walletAddress)).fetch();
|
|
3603
3739
|
if (results.length === 0) return false;
|
|
3604
3740
|
await ctx.database.write(async () => {
|
|
3605
3741
|
await results[0].destroyPermanently();
|
|
@@ -5163,6 +5299,9 @@ function useGoogleDriveBackup(options) {
|
|
|
5163
5299
|
hasEncryptionKey,
|
|
5164
5300
|
memoryStorageSchema,
|
|
5165
5301
|
requestEncryptionKey,
|
|
5302
|
+
sdkMigrations,
|
|
5303
|
+
sdkModelClasses,
|
|
5304
|
+
sdkSchema,
|
|
5166
5305
|
selectTool,
|
|
5167
5306
|
settingsStorageSchema,
|
|
5168
5307
|
storeDropboxToken,
|
package/dist/react/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Database, Model } from '@nozbe/watermelondb';
|
|
2
2
|
import * as _nozbe_watermelondb_Schema_migrations from '@nozbe/watermelondb/Schema/migrations';
|
|
3
3
|
import * as _nozbe_watermelondb_Schema from '@nozbe/watermelondb/Schema';
|
|
4
|
-
import { Associations } from '@nozbe/watermelondb/Model';
|
|
4
|
+
import Model$1, { Associations } from '@nozbe/watermelondb/Model';
|
|
5
|
+
import { Class } from '@nozbe/watermelondb/types';
|
|
5
6
|
import { ReactNode, JSX } from 'react';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -475,6 +476,11 @@ type SendMessageArgs = BaseSendMessageArgs & {
|
|
|
475
476
|
* This is typically formatted memories from useMemoryStorage.
|
|
476
477
|
*/
|
|
477
478
|
memoryContext?: string;
|
|
479
|
+
/**
|
|
480
|
+
* Search context to inject as a system message.
|
|
481
|
+
* This is typically formatted search results from useSearch.
|
|
482
|
+
*/
|
|
483
|
+
searchContext?: string;
|
|
478
484
|
};
|
|
479
485
|
type SendMessageResult = {
|
|
480
486
|
data: LlmapiChatCompletionResponse;
|
|
@@ -732,6 +738,8 @@ interface BaseSendMessageWithStorageArgs {
|
|
|
732
738
|
files?: FileMetadata[];
|
|
733
739
|
onData?: (chunk: string) => void;
|
|
734
740
|
memoryContext?: string;
|
|
741
|
+
searchContext?: string;
|
|
742
|
+
sources?: SearchSource[];
|
|
735
743
|
}
|
|
736
744
|
interface BaseUseChatStorageResult {
|
|
737
745
|
isLoading: boolean;
|
|
@@ -904,6 +912,79 @@ interface UseChatStorageResult extends BaseUseChatStorageResult {
|
|
|
904
912
|
*/
|
|
905
913
|
declare function useChatStorage(options: UseChatStorageOptions): UseChatStorageResult;
|
|
906
914
|
|
|
915
|
+
/**
|
|
916
|
+
* Combined WatermelonDB schema for all SDK storage modules.
|
|
917
|
+
*
|
|
918
|
+
* This unified schema includes all tables needed by the SDK:
|
|
919
|
+
* - `history`: Chat message storage with embeddings and metadata
|
|
920
|
+
* - `conversations`: Conversation metadata and organization
|
|
921
|
+
* - `memories`: Persistent memory storage with semantic search
|
|
922
|
+
* - `modelPreferences`: User model preferences and settings
|
|
923
|
+
*
|
|
924
|
+
* @example
|
|
925
|
+
* ```typescript
|
|
926
|
+
* import { Database } from '@nozbe/watermelondb';
|
|
927
|
+
* import LokiJSAdapter from '@nozbe/watermelondb/adapters/lokijs';
|
|
928
|
+
* import { sdkSchema, sdkMigrations, sdkModelClasses } from '@reverbia/sdk/react';
|
|
929
|
+
*
|
|
930
|
+
* const adapter = new LokiJSAdapter({
|
|
931
|
+
* schema: sdkSchema,
|
|
932
|
+
* migrations: sdkMigrations,
|
|
933
|
+
* dbName: 'my-app-db',
|
|
934
|
+
* useWebWorker: false,
|
|
935
|
+
* useIncrementalIndexedDB: true,
|
|
936
|
+
* });
|
|
937
|
+
*
|
|
938
|
+
* const database = new Database({
|
|
939
|
+
* adapter,
|
|
940
|
+
* modelClasses: sdkModelClasses,
|
|
941
|
+
* });
|
|
942
|
+
* ```
|
|
943
|
+
*/
|
|
944
|
+
declare const sdkSchema: Readonly<{
|
|
945
|
+
version: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
946
|
+
tables: _nozbe_watermelondb_Schema.TableMap;
|
|
947
|
+
unsafeSql?: (_: string, __: _nozbe_watermelondb_Schema.AppSchemaUnsafeSqlKind) => string;
|
|
948
|
+
}>;
|
|
949
|
+
/**
|
|
950
|
+
* Combined migrations for all SDK storage modules.
|
|
951
|
+
*
|
|
952
|
+
* These migrations handle database schema upgrades from any previous version
|
|
953
|
+
* to the current version. The SDK manages all migration logic internally,
|
|
954
|
+
* so consumer apps don't need to handle version arithmetic or migration merging.
|
|
955
|
+
*
|
|
956
|
+
* **Minimum supported version: v2**
|
|
957
|
+
* Migrations from v1 are not supported. Databases at v1 require a fresh install.
|
|
958
|
+
*
|
|
959
|
+
* Migration history:
|
|
960
|
+
* - v2 → v3: Added `was_stopped` column to history table
|
|
961
|
+
* - v3 → v4: Added `modelPreferences` table for settings storage
|
|
962
|
+
*/
|
|
963
|
+
declare const sdkMigrations: Readonly<{
|
|
964
|
+
validated: true;
|
|
965
|
+
minVersion: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
966
|
+
maxVersion: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
967
|
+
sortedMigrations: _nozbe_watermelondb_Schema_migrations.Migration[];
|
|
968
|
+
}>;
|
|
969
|
+
/**
|
|
970
|
+
* Model classes to register with the WatermelonDB database.
|
|
971
|
+
*
|
|
972
|
+
* Pass this array directly to the `modelClasses` option when creating
|
|
973
|
+
* your Database instance.
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* ```typescript
|
|
977
|
+
* import { Database } from '@nozbe/watermelondb';
|
|
978
|
+
* import { sdkSchema, sdkMigrations, sdkModelClasses } from '@reverbia/sdk/react';
|
|
979
|
+
*
|
|
980
|
+
* const database = new Database({
|
|
981
|
+
* adapter,
|
|
982
|
+
* modelClasses: sdkModelClasses,
|
|
983
|
+
* });
|
|
984
|
+
* ```
|
|
985
|
+
*/
|
|
986
|
+
declare const sdkModelClasses: Class<Model$1>[];
|
|
987
|
+
|
|
907
988
|
declare const memoryStorageSchema: Readonly<{
|
|
908
989
|
version: _nozbe_watermelondb_Schema.SchemaVersion;
|
|
909
990
|
tables: _nozbe_watermelondb_Schema.TableMap;
|
|
@@ -1715,4 +1796,4 @@ interface UseGoogleDriveBackupResult {
|
|
|
1715
1796
|
*/
|
|
1716
1797
|
declare function useGoogleDriveBackup(options: UseGoogleDriveBackupOptions): UseGoogleDriveBackupResult;
|
|
1717
1798
|
|
|
1718
|
-
export { Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type ClientTool, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_TOOL_SELECTOR_MODEL, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveExportResult, type GoogleDriveImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearToken as clearDropboxToken, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getStoredToken as getDropboxToken, hasEncryptionKey, memoryStorageSchema, requestEncryptionKey, selectTool, settingsStorageSchema, storeToken as storeDropboxToken, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };
|
|
1799
|
+
export { Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type ClientTool, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_TOOL_SELECTOR_MODEL, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveExportResult, type GoogleDriveImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearToken as clearDropboxToken, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getStoredToken as getDropboxToken, hasEncryptionKey, memoryStorageSchema, requestEncryptionKey, sdkMigrations, sdkModelClasses, sdkSchema, selectTool, settingsStorageSchema, storeToken as storeDropboxToken, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };
|