@reverbia/sdk 1.0.0-next.20251217144159 → 1.0.0-next.20251218151654
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 +313 -269
- package/dist/expo/index.d.mts +130 -414
- package/dist/expo/index.d.ts +130 -414
- package/dist/expo/index.mjs +299 -248
- package/dist/index.cjs +46 -2
- package/dist/index.d.mts +175 -2
- package/dist/index.d.ts +175 -2
- package/dist/index.mjs +41 -1
- package/dist/react/index.cjs +424 -331
- package/dist/react/index.d.mts +136 -453
- package/dist/react/index.d.ts +136 -453
- package/dist/react/index.mjs +404 -304
- package/package.json +2 -2
package/dist/expo/index.cjs
CHANGED
|
@@ -16,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
19
27
|
|
|
20
28
|
// src/expo/index.ts
|
|
21
29
|
var index_exports = {};
|
|
@@ -29,6 +37,9 @@ __export(index_exports, {
|
|
|
29
37
|
generateConversationId: () => generateConversationId,
|
|
30
38
|
generateUniqueKey: () => generateUniqueKey,
|
|
31
39
|
memoryStorageSchema: () => memoryStorageSchema,
|
|
40
|
+
sdkMigrations: () => sdkMigrations,
|
|
41
|
+
sdkModelClasses: () => sdkModelClasses,
|
|
42
|
+
sdkSchema: () => sdkSchema,
|
|
32
43
|
useChat: () => useChat,
|
|
33
44
|
useChatStorage: () => useChatStorage,
|
|
34
45
|
useImageGeneration: () => useImageGeneration,
|
|
@@ -322,7 +333,134 @@ function useChat(options) {
|
|
|
322
333
|
// src/expo/useChatStorage.ts
|
|
323
334
|
var import_react2 = require("react");
|
|
324
335
|
|
|
325
|
-
// src/lib/
|
|
336
|
+
// src/lib/db/chat/schema.ts
|
|
337
|
+
var import_watermelondb = require("@nozbe/watermelondb");
|
|
338
|
+
var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
|
|
339
|
+
var chatStorageSchema = (0, import_watermelondb.appSchema)({
|
|
340
|
+
version: 2,
|
|
341
|
+
tables: [
|
|
342
|
+
(0, import_watermelondb.tableSchema)({
|
|
343
|
+
name: "history",
|
|
344
|
+
columns: [
|
|
345
|
+
{ name: "message_id", type: "number" },
|
|
346
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
347
|
+
{ name: "role", type: "string", isIndexed: true },
|
|
348
|
+
{ name: "content", type: "string" },
|
|
349
|
+
{ name: "model", type: "string", isOptional: true },
|
|
350
|
+
{ name: "files", type: "string", isOptional: true },
|
|
351
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
352
|
+
{ name: "updated_at", type: "number" },
|
|
353
|
+
{ name: "vector", type: "string", isOptional: true },
|
|
354
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
355
|
+
{ name: "usage", type: "string", isOptional: true },
|
|
356
|
+
{ name: "sources", type: "string", isOptional: true },
|
|
357
|
+
{ name: "response_duration", type: "number", isOptional: true },
|
|
358
|
+
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
359
|
+
]
|
|
360
|
+
}),
|
|
361
|
+
(0, import_watermelondb.tableSchema)({
|
|
362
|
+
name: "conversations",
|
|
363
|
+
columns: [
|
|
364
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
365
|
+
{ name: "title", type: "string" },
|
|
366
|
+
{ name: "created_at", type: "number" },
|
|
367
|
+
{ name: "updated_at", type: "number" },
|
|
368
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
369
|
+
]
|
|
370
|
+
})
|
|
371
|
+
]
|
|
372
|
+
});
|
|
373
|
+
var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
|
|
374
|
+
migrations: [
|
|
375
|
+
{
|
|
376
|
+
toVersion: 2,
|
|
377
|
+
steps: [
|
|
378
|
+
(0, import_migrations.addColumns)({
|
|
379
|
+
table: "history",
|
|
380
|
+
columns: [{ name: "was_stopped", type: "boolean", isOptional: true }]
|
|
381
|
+
})
|
|
382
|
+
]
|
|
383
|
+
}
|
|
384
|
+
]
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// src/lib/db/chat/models.ts
|
|
388
|
+
var import_watermelondb2 = require("@nozbe/watermelondb");
|
|
389
|
+
var import_decorators = require("@nozbe/watermelondb/decorators");
|
|
390
|
+
var Message = class extends import_watermelondb2.Model {
|
|
391
|
+
};
|
|
392
|
+
Message.table = "history";
|
|
393
|
+
Message.associations = {
|
|
394
|
+
conversations: { type: "belongs_to", key: "conversation_id" }
|
|
395
|
+
};
|
|
396
|
+
__decorateClass([
|
|
397
|
+
(0, import_decorators.field)("message_id")
|
|
398
|
+
], Message.prototype, "messageId", 2);
|
|
399
|
+
__decorateClass([
|
|
400
|
+
(0, import_decorators.text)("conversation_id")
|
|
401
|
+
], Message.prototype, "conversationId", 2);
|
|
402
|
+
__decorateClass([
|
|
403
|
+
(0, import_decorators.text)("role")
|
|
404
|
+
], Message.prototype, "role", 2);
|
|
405
|
+
__decorateClass([
|
|
406
|
+
(0, import_decorators.text)("content")
|
|
407
|
+
], Message.prototype, "content", 2);
|
|
408
|
+
__decorateClass([
|
|
409
|
+
(0, import_decorators.text)("model")
|
|
410
|
+
], Message.prototype, "model", 2);
|
|
411
|
+
__decorateClass([
|
|
412
|
+
(0, import_decorators.json)("files", (json3) => json3)
|
|
413
|
+
], Message.prototype, "files", 2);
|
|
414
|
+
__decorateClass([
|
|
415
|
+
(0, import_decorators.date)("created_at")
|
|
416
|
+
], Message.prototype, "createdAt", 2);
|
|
417
|
+
__decorateClass([
|
|
418
|
+
(0, import_decorators.date)("updated_at")
|
|
419
|
+
], Message.prototype, "updatedAt", 2);
|
|
420
|
+
__decorateClass([
|
|
421
|
+
(0, import_decorators.json)("vector", (json3) => json3)
|
|
422
|
+
], Message.prototype, "vector", 2);
|
|
423
|
+
__decorateClass([
|
|
424
|
+
(0, import_decorators.text)("embedding_model")
|
|
425
|
+
], Message.prototype, "embeddingModel", 2);
|
|
426
|
+
__decorateClass([
|
|
427
|
+
(0, import_decorators.json)("usage", (json3) => json3)
|
|
428
|
+
], Message.prototype, "usage", 2);
|
|
429
|
+
__decorateClass([
|
|
430
|
+
(0, import_decorators.json)("sources", (json3) => json3)
|
|
431
|
+
], Message.prototype, "sources", 2);
|
|
432
|
+
__decorateClass([
|
|
433
|
+
(0, import_decorators.field)("response_duration")
|
|
434
|
+
], Message.prototype, "responseDuration", 2);
|
|
435
|
+
__decorateClass([
|
|
436
|
+
(0, import_decorators.field)("was_stopped")
|
|
437
|
+
], Message.prototype, "wasStopped", 2);
|
|
438
|
+
var Conversation = class extends import_watermelondb2.Model {
|
|
439
|
+
};
|
|
440
|
+
Conversation.table = "conversations";
|
|
441
|
+
Conversation.associations = {
|
|
442
|
+
history: { type: "has_many", foreignKey: "conversation_id" }
|
|
443
|
+
};
|
|
444
|
+
__decorateClass([
|
|
445
|
+
(0, import_decorators.text)("conversation_id")
|
|
446
|
+
], Conversation.prototype, "conversationId", 2);
|
|
447
|
+
__decorateClass([
|
|
448
|
+
(0, import_decorators.text)("title")
|
|
449
|
+
], Conversation.prototype, "title", 2);
|
|
450
|
+
__decorateClass([
|
|
451
|
+
(0, import_decorators.date)("created_at")
|
|
452
|
+
], Conversation.prototype, "createdAt", 2);
|
|
453
|
+
__decorateClass([
|
|
454
|
+
(0, import_decorators.date)("updated_at")
|
|
455
|
+
], Conversation.prototype, "updatedAt", 2);
|
|
456
|
+
__decorateClass([
|
|
457
|
+
(0, import_decorators.field)("is_deleted")
|
|
458
|
+
], Conversation.prototype, "isDeleted", 2);
|
|
459
|
+
|
|
460
|
+
// src/lib/db/chat/types.ts
|
|
461
|
+
function generateConversationId() {
|
|
462
|
+
return `conv_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
463
|
+
}
|
|
326
464
|
function convertUsageToStored(usage) {
|
|
327
465
|
if (!usage) return void 0;
|
|
328
466
|
return {
|
|
@@ -332,12 +470,9 @@ function convertUsageToStored(usage) {
|
|
|
332
470
|
costMicroUsd: usage.cost_micro_usd
|
|
333
471
|
};
|
|
334
472
|
}
|
|
335
|
-
function generateConversationId() {
|
|
336
|
-
return `conv_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
337
|
-
}
|
|
338
473
|
|
|
339
|
-
// src/lib/
|
|
340
|
-
var
|
|
474
|
+
// src/lib/db/chat/operations.ts
|
|
475
|
+
var import_watermelondb3 = require("@nozbe/watermelondb");
|
|
341
476
|
function messageToStored(message) {
|
|
342
477
|
return {
|
|
343
478
|
uniqueId: message.id,
|
|
@@ -380,15 +515,15 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
|
|
|
380
515
|
return conversationToStored(created);
|
|
381
516
|
}
|
|
382
517
|
async function getConversationOp(ctx, id) {
|
|
383
|
-
const results = await ctx.conversationsCollection.query(
|
|
518
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
384
519
|
return results.length > 0 ? conversationToStored(results[0]) : null;
|
|
385
520
|
}
|
|
386
521
|
async function getConversationsOp(ctx) {
|
|
387
|
-
const results = await ctx.conversationsCollection.query(
|
|
522
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false), import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).fetch();
|
|
388
523
|
return results.map(conversationToStored);
|
|
389
524
|
}
|
|
390
525
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
391
|
-
const results = await ctx.conversationsCollection.query(
|
|
526
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
392
527
|
if (results.length > 0) {
|
|
393
528
|
await ctx.database.write(async () => {
|
|
394
529
|
await results[0].update((conv) => {
|
|
@@ -400,7 +535,7 @@ async function updateConversationTitleOp(ctx, id, title) {
|
|
|
400
535
|
return false;
|
|
401
536
|
}
|
|
402
537
|
async function deleteConversationOp(ctx, id) {
|
|
403
|
-
const results = await ctx.conversationsCollection.query(
|
|
538
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
404
539
|
if (results.length > 0) {
|
|
405
540
|
await ctx.database.write(async () => {
|
|
406
541
|
await results[0].update((conv) => {
|
|
@@ -412,14 +547,14 @@ async function deleteConversationOp(ctx, id) {
|
|
|
412
547
|
return false;
|
|
413
548
|
}
|
|
414
549
|
async function getMessagesOp(ctx, convId) {
|
|
415
|
-
const results = await ctx.messagesCollection.query(
|
|
550
|
+
const results = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId), import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.asc)).fetch();
|
|
416
551
|
return results.map(messageToStored);
|
|
417
552
|
}
|
|
418
553
|
async function getMessageCountOp(ctx, convId) {
|
|
419
|
-
return await ctx.messagesCollection.query(
|
|
554
|
+
return await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetchCount();
|
|
420
555
|
}
|
|
421
556
|
async function clearMessagesOp(ctx, convId) {
|
|
422
|
-
const messages = await ctx.messagesCollection.query(
|
|
557
|
+
const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetch();
|
|
423
558
|
await ctx.database.write(async () => {
|
|
424
559
|
for (const message of messages) {
|
|
425
560
|
await message.destroyPermanently();
|
|
@@ -1773,10 +1908,83 @@ function useModels(options = {}) {
|
|
|
1773
1908
|
var import_react5 = require("react");
|
|
1774
1909
|
var import_client4 = require("@reverbia/sdk");
|
|
1775
1910
|
|
|
1776
|
-
// src/lib/
|
|
1777
|
-
var
|
|
1911
|
+
// src/lib/db/memory/schema.ts
|
|
1912
|
+
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
1913
|
+
var memoryStorageSchema = (0, import_watermelondb4.appSchema)({
|
|
1914
|
+
version: 1,
|
|
1915
|
+
tables: [
|
|
1916
|
+
(0, import_watermelondb4.tableSchema)({
|
|
1917
|
+
name: "memories",
|
|
1918
|
+
columns: [
|
|
1919
|
+
{ name: "type", type: "string", isIndexed: true },
|
|
1920
|
+
{ name: "namespace", type: "string", isIndexed: true },
|
|
1921
|
+
{ name: "key", type: "string", isIndexed: true },
|
|
1922
|
+
{ name: "value", type: "string" },
|
|
1923
|
+
{ name: "raw_evidence", type: "string" },
|
|
1924
|
+
{ name: "confidence", type: "number" },
|
|
1925
|
+
{ name: "pii", type: "boolean", isIndexed: true },
|
|
1926
|
+
{ name: "composite_key", type: "string", isIndexed: true },
|
|
1927
|
+
{ name: "unique_key", type: "string", isIndexed: true },
|
|
1928
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
1929
|
+
{ name: "updated_at", type: "number" },
|
|
1930
|
+
{ name: "embedding", type: "string", isOptional: true },
|
|
1931
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
1932
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
1933
|
+
]
|
|
1934
|
+
})
|
|
1935
|
+
]
|
|
1936
|
+
});
|
|
1937
|
+
|
|
1938
|
+
// src/lib/db/memory/models.ts
|
|
1939
|
+
var import_watermelondb5 = require("@nozbe/watermelondb");
|
|
1940
|
+
var import_decorators2 = require("@nozbe/watermelondb/decorators");
|
|
1941
|
+
var Memory = class extends import_watermelondb5.Model {
|
|
1942
|
+
};
|
|
1943
|
+
Memory.table = "memories";
|
|
1944
|
+
__decorateClass([
|
|
1945
|
+
(0, import_decorators2.text)("type")
|
|
1946
|
+
], Memory.prototype, "type", 2);
|
|
1947
|
+
__decorateClass([
|
|
1948
|
+
(0, import_decorators2.text)("namespace")
|
|
1949
|
+
], Memory.prototype, "namespace", 2);
|
|
1950
|
+
__decorateClass([
|
|
1951
|
+
(0, import_decorators2.text)("key")
|
|
1952
|
+
], Memory.prototype, "key", 2);
|
|
1953
|
+
__decorateClass([
|
|
1954
|
+
(0, import_decorators2.text)("value")
|
|
1955
|
+
], Memory.prototype, "value", 2);
|
|
1956
|
+
__decorateClass([
|
|
1957
|
+
(0, import_decorators2.text)("raw_evidence")
|
|
1958
|
+
], Memory.prototype, "rawEvidence", 2);
|
|
1959
|
+
__decorateClass([
|
|
1960
|
+
(0, import_decorators2.field)("confidence")
|
|
1961
|
+
], Memory.prototype, "confidence", 2);
|
|
1962
|
+
__decorateClass([
|
|
1963
|
+
(0, import_decorators2.field)("pii")
|
|
1964
|
+
], Memory.prototype, "pii", 2);
|
|
1965
|
+
__decorateClass([
|
|
1966
|
+
(0, import_decorators2.text)("composite_key")
|
|
1967
|
+
], Memory.prototype, "compositeKey", 2);
|
|
1968
|
+
__decorateClass([
|
|
1969
|
+
(0, import_decorators2.text)("unique_key")
|
|
1970
|
+
], Memory.prototype, "uniqueKey", 2);
|
|
1971
|
+
__decorateClass([
|
|
1972
|
+
(0, import_decorators2.date)("created_at")
|
|
1973
|
+
], Memory.prototype, "createdAt", 2);
|
|
1974
|
+
__decorateClass([
|
|
1975
|
+
(0, import_decorators2.date)("updated_at")
|
|
1976
|
+
], Memory.prototype, "updatedAt", 2);
|
|
1977
|
+
__decorateClass([
|
|
1978
|
+
(0, import_decorators2.json)("embedding", (json3) => json3)
|
|
1979
|
+
], Memory.prototype, "embedding", 2);
|
|
1980
|
+
__decorateClass([
|
|
1981
|
+
(0, import_decorators2.text)("embedding_model")
|
|
1982
|
+
], Memory.prototype, "embeddingModel", 2);
|
|
1983
|
+
__decorateClass([
|
|
1984
|
+
(0, import_decorators2.field)("is_deleted")
|
|
1985
|
+
], Memory.prototype, "isDeleted", 2);
|
|
1778
1986
|
|
|
1779
|
-
// src/lib/
|
|
1987
|
+
// src/lib/db/memory/types.ts
|
|
1780
1988
|
function generateCompositeKey(namespace, key) {
|
|
1781
1989
|
return `${namespace}:${key}`;
|
|
1782
1990
|
}
|
|
@@ -1802,7 +2010,8 @@ function cosineSimilarity(a, b) {
|
|
|
1802
2010
|
return dotProduct / denominator;
|
|
1803
2011
|
}
|
|
1804
2012
|
|
|
1805
|
-
// src/lib/
|
|
2013
|
+
// src/lib/db/memory/operations.ts
|
|
2014
|
+
var import_watermelondb6 = require("@nozbe/watermelondb");
|
|
1806
2015
|
function memoryToStored(memory) {
|
|
1807
2016
|
return {
|
|
1808
2017
|
uniqueId: memory.id,
|
|
@@ -1823,7 +2032,7 @@ function memoryToStored(memory) {
|
|
|
1823
2032
|
};
|
|
1824
2033
|
}
|
|
1825
2034
|
async function getAllMemoriesOp(ctx) {
|
|
1826
|
-
const results = await ctx.memoriesCollection.query(
|
|
2035
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("is_deleted", false), import_watermelondb6.Q.sortBy("created_at", import_watermelondb6.Q.desc)).fetch();
|
|
1827
2036
|
return results.map(memoryToStored);
|
|
1828
2037
|
}
|
|
1829
2038
|
async function getMemoryByIdOp(ctx, id) {
|
|
@@ -1837,18 +2046,18 @@ async function getMemoryByIdOp(ctx, id) {
|
|
|
1837
2046
|
}
|
|
1838
2047
|
async function getMemoriesByNamespaceOp(ctx, namespace) {
|
|
1839
2048
|
const results = await ctx.memoriesCollection.query(
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
2049
|
+
import_watermelondb6.Q.where("namespace", namespace),
|
|
2050
|
+
import_watermelondb6.Q.where("is_deleted", false),
|
|
2051
|
+
import_watermelondb6.Q.sortBy("created_at", import_watermelondb6.Q.desc)
|
|
1843
2052
|
).fetch();
|
|
1844
2053
|
return results.map(memoryToStored);
|
|
1845
2054
|
}
|
|
1846
2055
|
async function getMemoriesByKeyOp(ctx, namespace, key) {
|
|
1847
2056
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
1848
2057
|
const results = await ctx.memoriesCollection.query(
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
2058
|
+
import_watermelondb6.Q.where("composite_key", compositeKey),
|
|
2059
|
+
import_watermelondb6.Q.where("is_deleted", false),
|
|
2060
|
+
import_watermelondb6.Q.sortBy("created_at", import_watermelondb6.Q.desc)
|
|
1852
2061
|
).fetch();
|
|
1853
2062
|
return results.map(memoryToStored);
|
|
1854
2063
|
}
|
|
@@ -1856,7 +2065,7 @@ async function saveMemoryOp(ctx, opts) {
|
|
|
1856
2065
|
const compositeKey = generateCompositeKey(opts.namespace, opts.key);
|
|
1857
2066
|
const uniqueKey = generateUniqueKey(opts.namespace, opts.key, opts.value);
|
|
1858
2067
|
const result = await ctx.database.write(async () => {
|
|
1859
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2068
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("unique_key", uniqueKey)).fetch();
|
|
1860
2069
|
if (existing.length > 0) {
|
|
1861
2070
|
const existingMemory = existing[0];
|
|
1862
2071
|
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;
|
|
@@ -1929,7 +2138,7 @@ async function updateMemoryOp(ctx, id, updates) {
|
|
|
1929
2138
|
const newCompositeKey = generateCompositeKey(newNamespace, newKey);
|
|
1930
2139
|
const newUniqueKey = generateUniqueKey(newNamespace, newKey, newValue);
|
|
1931
2140
|
if (newUniqueKey !== memory.uniqueKey) {
|
|
1932
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2141
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("unique_key", newUniqueKey), import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
1933
2142
|
if (existing.length > 0) {
|
|
1934
2143
|
return { ok: false, reason: "conflict", conflictingKey: newUniqueKey };
|
|
1935
2144
|
}
|
|
@@ -1985,7 +2194,7 @@ async function deleteMemoryByIdOp(ctx, id) {
|
|
|
1985
2194
|
}
|
|
1986
2195
|
async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
1987
2196
|
const uniqueKey = generateUniqueKey(namespace, key, value);
|
|
1988
|
-
const results = await ctx.memoriesCollection.query(
|
|
2197
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("unique_key", uniqueKey)).fetch();
|
|
1989
2198
|
if (results.length > 0) {
|
|
1990
2199
|
await ctx.database.write(async () => {
|
|
1991
2200
|
await results[0].update((mem) => {
|
|
@@ -1996,7 +2205,7 @@ async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
|
1996
2205
|
}
|
|
1997
2206
|
async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
1998
2207
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
1999
|
-
const results = await ctx.memoriesCollection.query(
|
|
2208
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("composite_key", compositeKey), import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2000
2209
|
await ctx.database.write(async () => {
|
|
2001
2210
|
for (const memory of results) {
|
|
2002
2211
|
await memory.update((mem) => {
|
|
@@ -2006,7 +2215,7 @@ async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
|
2006
2215
|
});
|
|
2007
2216
|
}
|
|
2008
2217
|
async function clearAllMemoriesOp(ctx) {
|
|
2009
|
-
const results = await ctx.memoriesCollection.query(
|
|
2218
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2010
2219
|
await ctx.database.write(async () => {
|
|
2011
2220
|
for (const memory of results) {
|
|
2012
2221
|
await memory.update((mem) => {
|
|
@@ -2016,7 +2225,7 @@ async function clearAllMemoriesOp(ctx) {
|
|
|
2016
2225
|
});
|
|
2017
2226
|
}
|
|
2018
2227
|
async function searchSimilarMemoriesOp(ctx, queryEmbedding, limit = 10, minSimilarity = 0.6) {
|
|
2019
|
-
const allMemories = await ctx.memoriesCollection.query(
|
|
2228
|
+
const allMemories = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2020
2229
|
const memoriesWithEmbeddings = allMemories.filter(
|
|
2021
2230
|
(m) => m.embedding && m.embedding.length > 0
|
|
2022
2231
|
);
|
|
@@ -2180,7 +2389,7 @@ var DEFAULT_COMPLETION_MODEL = "openai/gpt-4o";
|
|
|
2180
2389
|
|
|
2181
2390
|
// src/expo/useMemoryStorage.ts
|
|
2182
2391
|
var import_client5 = require("@reverbia/sdk");
|
|
2183
|
-
async function generateEmbeddingForTextApi(
|
|
2392
|
+
async function generateEmbeddingForTextApi(text4, options) {
|
|
2184
2393
|
const token = options.getToken ? await options.getToken() : null;
|
|
2185
2394
|
if (!token) {
|
|
2186
2395
|
throw new Error("No auth token available for embedding generation");
|
|
@@ -2188,7 +2397,7 @@ async function generateEmbeddingForTextApi(text, options) {
|
|
|
2188
2397
|
const response = await (0, import_client5.postApiV1Embeddings)({
|
|
2189
2398
|
baseUrl: options.baseUrl,
|
|
2190
2399
|
body: {
|
|
2191
|
-
input:
|
|
2400
|
+
input: text4,
|
|
2192
2401
|
model: options.model
|
|
2193
2402
|
},
|
|
2194
2403
|
headers: {
|
|
@@ -2205,8 +2414,8 @@ async function generateEmbeddingForTextApi(text, options) {
|
|
|
2205
2414
|
return embedding;
|
|
2206
2415
|
}
|
|
2207
2416
|
async function generateEmbeddingForMemoryApi(memory, options) {
|
|
2208
|
-
const
|
|
2209
|
-
return generateEmbeddingForTextApi(
|
|
2417
|
+
const text4 = `${memory.type}: ${memory.namespace}/${memory.key} = ${memory.value}. Evidence: ${memory.rawEvidence}`;
|
|
2418
|
+
return generateEmbeddingForTextApi(text4, options);
|
|
2210
2419
|
}
|
|
2211
2420
|
function useMemoryStorage(options) {
|
|
2212
2421
|
const {
|
|
@@ -2731,38 +2940,49 @@ function useMemoryStorage(options) {
|
|
|
2731
2940
|
};
|
|
2732
2941
|
}
|
|
2733
2942
|
|
|
2734
|
-
// src/lib/
|
|
2735
|
-
var
|
|
2736
|
-
var
|
|
2737
|
-
|
|
2738
|
-
|
|
2943
|
+
// src/lib/db/schema.ts
|
|
2944
|
+
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
2945
|
+
var import_migrations2 = require("@nozbe/watermelondb/Schema/migrations");
|
|
2946
|
+
|
|
2947
|
+
// src/lib/db/settings/models.ts
|
|
2948
|
+
var import_watermelondb7 = require("@nozbe/watermelondb");
|
|
2949
|
+
var import_decorators3 = require("@nozbe/watermelondb/decorators");
|
|
2950
|
+
var ModelPreference = class extends import_watermelondb7.Model {
|
|
2951
|
+
};
|
|
2952
|
+
ModelPreference.table = "modelPreferences";
|
|
2953
|
+
__decorateClass([
|
|
2954
|
+
(0, import_decorators3.text)("wallet_address")
|
|
2955
|
+
], ModelPreference.prototype, "walletAddress", 2);
|
|
2956
|
+
__decorateClass([
|
|
2957
|
+
(0, import_decorators3.text)("models")
|
|
2958
|
+
], ModelPreference.prototype, "models", 2);
|
|
2959
|
+
|
|
2960
|
+
// src/lib/db/schema.ts
|
|
2961
|
+
var SDK_SCHEMA_VERSION = 4;
|
|
2962
|
+
var sdkSchema = (0, import_watermelondb8.appSchema)({
|
|
2963
|
+
version: SDK_SCHEMA_VERSION,
|
|
2739
2964
|
tables: [
|
|
2740
|
-
|
|
2965
|
+
// Chat storage tables
|
|
2966
|
+
(0, import_watermelondb8.tableSchema)({
|
|
2741
2967
|
name: "history",
|
|
2742
2968
|
columns: [
|
|
2743
2969
|
{ name: "message_id", type: "number" },
|
|
2744
|
-
// Sequential ID within conversation
|
|
2745
2970
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
2746
2971
|
{ name: "role", type: "string", isIndexed: true },
|
|
2747
|
-
// 'user' | 'assistant' | 'system'
|
|
2748
2972
|
{ name: "content", type: "string" },
|
|
2749
2973
|
{ name: "model", type: "string", isOptional: true },
|
|
2750
2974
|
{ name: "files", type: "string", isOptional: true },
|
|
2751
|
-
// JSON stringified FileMetadata[]
|
|
2752
2975
|
{ name: "created_at", type: "number", isIndexed: true },
|
|
2753
2976
|
{ name: "updated_at", type: "number" },
|
|
2754
2977
|
{ name: "vector", type: "string", isOptional: true },
|
|
2755
|
-
// JSON stringified number[]
|
|
2756
2978
|
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2757
2979
|
{ name: "usage", type: "string", isOptional: true },
|
|
2758
|
-
// JSON stringified ChatCompletionUsage
|
|
2759
2980
|
{ name: "sources", type: "string", isOptional: true },
|
|
2760
|
-
// JSON stringified SearchSource[]
|
|
2761
2981
|
{ name: "response_duration", type: "number", isOptional: true },
|
|
2762
2982
|
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
2763
2983
|
]
|
|
2764
2984
|
}),
|
|
2765
|
-
(0,
|
|
2985
|
+
(0, import_watermelondb8.tableSchema)({
|
|
2766
2986
|
name: "conversations",
|
|
2767
2987
|
columns: [
|
|
2768
2988
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -2771,249 +2991,70 @@ var chatStorageSchema = (0, import_watermelondb3.appSchema)({
|
|
|
2771
2991
|
{ name: "updated_at", type: "number" },
|
|
2772
2992
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2773
2993
|
]
|
|
2774
|
-
})
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
|
|
2778
|
-
migrations: [
|
|
2779
|
-
{
|
|
2780
|
-
toVersion: 2,
|
|
2781
|
-
steps: [
|
|
2782
|
-
(0, import_migrations.addColumns)({
|
|
2783
|
-
table: "history",
|
|
2784
|
-
columns: [
|
|
2785
|
-
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
2786
|
-
]
|
|
2787
|
-
})
|
|
2788
|
-
]
|
|
2789
|
-
}
|
|
2790
|
-
]
|
|
2791
|
-
});
|
|
2792
|
-
|
|
2793
|
-
// src/lib/chatStorage/models.ts
|
|
2794
|
-
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
2795
|
-
var Message = class extends import_watermelondb4.Model {
|
|
2796
|
-
/** Sequential message ID within conversation */
|
|
2797
|
-
get messageId() {
|
|
2798
|
-
return this._getRaw("message_id");
|
|
2799
|
-
}
|
|
2800
|
-
/** Links message to its conversation */
|
|
2801
|
-
get conversationId() {
|
|
2802
|
-
return this._getRaw("conversation_id");
|
|
2803
|
-
}
|
|
2804
|
-
/** Who sent the message: 'user' | 'assistant' | 'system' */
|
|
2805
|
-
get role() {
|
|
2806
|
-
return this._getRaw("role");
|
|
2807
|
-
}
|
|
2808
|
-
/** The message text content */
|
|
2809
|
-
get content() {
|
|
2810
|
-
return this._getRaw("content");
|
|
2811
|
-
}
|
|
2812
|
-
/** LLM model used (e.g., GPT-4, Claude) */
|
|
2813
|
-
get model() {
|
|
2814
|
-
const value = this._getRaw("model");
|
|
2815
|
-
return value ? value : void 0;
|
|
2816
|
-
}
|
|
2817
|
-
/** Optional attached files */
|
|
2818
|
-
get files() {
|
|
2819
|
-
const raw = this._getRaw("files");
|
|
2820
|
-
if (!raw) return void 0;
|
|
2821
|
-
try {
|
|
2822
|
-
return JSON.parse(raw);
|
|
2823
|
-
} catch {
|
|
2824
|
-
return void 0;
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
/** Created timestamp */
|
|
2828
|
-
get createdAt() {
|
|
2829
|
-
return new Date(this._getRaw("created_at"));
|
|
2830
|
-
}
|
|
2831
|
-
/** Updated timestamp */
|
|
2832
|
-
get updatedAt() {
|
|
2833
|
-
return new Date(this._getRaw("updated_at"));
|
|
2834
|
-
}
|
|
2835
|
-
/** Embedding vector for semantic search */
|
|
2836
|
-
get vector() {
|
|
2837
|
-
const raw = this._getRaw("vector");
|
|
2838
|
-
if (!raw) return void 0;
|
|
2839
|
-
try {
|
|
2840
|
-
return JSON.parse(raw);
|
|
2841
|
-
} catch {
|
|
2842
|
-
return void 0;
|
|
2843
|
-
}
|
|
2844
|
-
}
|
|
2845
|
-
/** Model used to generate embedding */
|
|
2846
|
-
get embeddingModel() {
|
|
2847
|
-
const value = this._getRaw("embedding_model");
|
|
2848
|
-
return value ? value : void 0;
|
|
2849
|
-
}
|
|
2850
|
-
/** Token counts and cost */
|
|
2851
|
-
get usage() {
|
|
2852
|
-
const raw = this._getRaw("usage");
|
|
2853
|
-
if (!raw) return void 0;
|
|
2854
|
-
try {
|
|
2855
|
-
return JSON.parse(raw);
|
|
2856
|
-
} catch {
|
|
2857
|
-
return void 0;
|
|
2858
|
-
}
|
|
2859
|
-
}
|
|
2860
|
-
/** Web search sources */
|
|
2861
|
-
get sources() {
|
|
2862
|
-
const raw = this._getRaw("sources");
|
|
2863
|
-
if (!raw) return void 0;
|
|
2864
|
-
try {
|
|
2865
|
-
return JSON.parse(raw);
|
|
2866
|
-
} catch {
|
|
2867
|
-
return void 0;
|
|
2868
|
-
}
|
|
2869
|
-
}
|
|
2870
|
-
/** Response time in seconds */
|
|
2871
|
-
get responseDuration() {
|
|
2872
|
-
const value = this._getRaw("response_duration");
|
|
2873
|
-
return value !== null && value !== void 0 ? value : void 0;
|
|
2874
|
-
}
|
|
2875
|
-
/** Whether the message generation was stopped by the user */
|
|
2876
|
-
get wasStopped() {
|
|
2877
|
-
return this._getRaw("was_stopped");
|
|
2878
|
-
}
|
|
2879
|
-
};
|
|
2880
|
-
Message.table = "history";
|
|
2881
|
-
Message.associations = {
|
|
2882
|
-
conversations: { type: "belongs_to", key: "conversation_id" }
|
|
2883
|
-
};
|
|
2884
|
-
var Conversation = class extends import_watermelondb4.Model {
|
|
2885
|
-
/** Unique conversation identifier */
|
|
2886
|
-
get conversationId() {
|
|
2887
|
-
return this._getRaw("conversation_id");
|
|
2888
|
-
}
|
|
2889
|
-
/** Conversation title */
|
|
2890
|
-
get title() {
|
|
2891
|
-
return this._getRaw("title");
|
|
2892
|
-
}
|
|
2893
|
-
/** Created timestamp */
|
|
2894
|
-
get createdAt() {
|
|
2895
|
-
return new Date(this._getRaw("created_at"));
|
|
2896
|
-
}
|
|
2897
|
-
/** Updated timestamp */
|
|
2898
|
-
get updatedAt() {
|
|
2899
|
-
return new Date(this._getRaw("updated_at"));
|
|
2900
|
-
}
|
|
2901
|
-
/** Soft delete flag */
|
|
2902
|
-
get isDeleted() {
|
|
2903
|
-
return this._getRaw("is_deleted");
|
|
2904
|
-
}
|
|
2905
|
-
};
|
|
2906
|
-
Conversation.table = "conversations";
|
|
2907
|
-
Conversation.associations = {
|
|
2908
|
-
history: { type: "has_many", foreignKey: "conversation_id" }
|
|
2909
|
-
};
|
|
2910
|
-
|
|
2911
|
-
// src/lib/memoryStorage/schema.ts
|
|
2912
|
-
var import_watermelondb5 = require("@nozbe/watermelondb");
|
|
2913
|
-
var memoryStorageSchema = (0, import_watermelondb5.appSchema)({
|
|
2914
|
-
version: 1,
|
|
2915
|
-
tables: [
|
|
2916
|
-
(0, import_watermelondb5.tableSchema)({
|
|
2994
|
+
}),
|
|
2995
|
+
// Memory storage tables
|
|
2996
|
+
(0, import_watermelondb8.tableSchema)({
|
|
2917
2997
|
name: "memories",
|
|
2918
2998
|
columns: [
|
|
2919
|
-
// Memory type classification
|
|
2920
2999
|
{ name: "type", type: "string", isIndexed: true },
|
|
2921
|
-
// 'identity' | 'preference' | 'project' | 'skill' | 'constraint'
|
|
2922
|
-
// Hierarchical key structure
|
|
2923
3000
|
{ name: "namespace", type: "string", isIndexed: true },
|
|
2924
3001
|
{ name: "key", type: "string", isIndexed: true },
|
|
2925
3002
|
{ name: "value", type: "string" },
|
|
2926
|
-
// Evidence and confidence
|
|
2927
3003
|
{ name: "raw_evidence", type: "string" },
|
|
2928
3004
|
{ name: "confidence", type: "number" },
|
|
2929
3005
|
{ name: "pii", type: "boolean", isIndexed: true },
|
|
2930
|
-
// Composite keys for efficient lookups
|
|
2931
3006
|
{ name: "composite_key", type: "string", isIndexed: true },
|
|
2932
|
-
// namespace:key
|
|
2933
3007
|
{ name: "unique_key", type: "string", isIndexed: true },
|
|
2934
|
-
// namespace:key:value
|
|
2935
|
-
// Timestamps
|
|
2936
3008
|
{ name: "created_at", type: "number", isIndexed: true },
|
|
2937
3009
|
{ name: "updated_at", type: "number" },
|
|
2938
|
-
// Vector embeddings for semantic search
|
|
2939
3010
|
{ name: "embedding", type: "string", isOptional: true },
|
|
2940
|
-
// JSON stringified number[]
|
|
2941
3011
|
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2942
|
-
// Soft delete flag
|
|
2943
3012
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2944
3013
|
]
|
|
3014
|
+
}),
|
|
3015
|
+
// Settings storage tables
|
|
3016
|
+
(0, import_watermelondb8.tableSchema)({
|
|
3017
|
+
name: "modelPreferences",
|
|
3018
|
+
columns: [
|
|
3019
|
+
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
3020
|
+
{ name: "models", type: "string", isOptional: true }
|
|
3021
|
+
]
|
|
2945
3022
|
})
|
|
2946
3023
|
]
|
|
2947
3024
|
});
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
/** Confidence score (0-1) */
|
|
2973
|
-
get confidence() {
|
|
2974
|
-
return this._getRaw("confidence");
|
|
2975
|
-
}
|
|
2976
|
-
/** Whether this memory contains PII */
|
|
2977
|
-
get pii() {
|
|
2978
|
-
return this._getRaw("pii");
|
|
2979
|
-
}
|
|
2980
|
-
/** Composite key (namespace:key) for efficient lookups */
|
|
2981
|
-
get compositeKey() {
|
|
2982
|
-
return this._getRaw("composite_key");
|
|
2983
|
-
}
|
|
2984
|
-
/** Unique key (namespace:key:value) for deduplication */
|
|
2985
|
-
get uniqueKey() {
|
|
2986
|
-
return this._getRaw("unique_key");
|
|
2987
|
-
}
|
|
2988
|
-
/** Created timestamp */
|
|
2989
|
-
get createdAt() {
|
|
2990
|
-
return new Date(this._getRaw("created_at"));
|
|
2991
|
-
}
|
|
2992
|
-
/** Updated timestamp */
|
|
2993
|
-
get updatedAt() {
|
|
2994
|
-
return new Date(this._getRaw("updated_at"));
|
|
2995
|
-
}
|
|
2996
|
-
/** Embedding vector for semantic search */
|
|
2997
|
-
get embedding() {
|
|
2998
|
-
const raw = this._getRaw("embedding");
|
|
2999
|
-
if (!raw) return void 0;
|
|
3000
|
-
try {
|
|
3001
|
-
return JSON.parse(raw);
|
|
3002
|
-
} catch {
|
|
3003
|
-
return void 0;
|
|
3025
|
+
var sdkMigrations = (0, import_migrations2.schemaMigrations)({
|
|
3026
|
+
migrations: [
|
|
3027
|
+
// v2 -> v3: Added was_stopped column to history
|
|
3028
|
+
{
|
|
3029
|
+
toVersion: 3,
|
|
3030
|
+
steps: [
|
|
3031
|
+
(0, import_migrations2.addColumns)({
|
|
3032
|
+
table: "history",
|
|
3033
|
+
columns: [{ name: "was_stopped", type: "boolean", isOptional: true }]
|
|
3034
|
+
})
|
|
3035
|
+
]
|
|
3036
|
+
},
|
|
3037
|
+
// v3 -> v4: Added settings storage (modelPreferences table)
|
|
3038
|
+
{
|
|
3039
|
+
toVersion: 4,
|
|
3040
|
+
steps: [
|
|
3041
|
+
(0, import_migrations2.createTable)({
|
|
3042
|
+
name: "modelPreferences",
|
|
3043
|
+
columns: [
|
|
3044
|
+
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
3045
|
+
{ name: "models", type: "string", isOptional: true }
|
|
3046
|
+
]
|
|
3047
|
+
})
|
|
3048
|
+
]
|
|
3004
3049
|
}
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
return this._getRaw("is_deleted");
|
|
3014
|
-
}
|
|
3015
|
-
};
|
|
3016
|
-
Memory.table = "memories";
|
|
3050
|
+
]
|
|
3051
|
+
});
|
|
3052
|
+
var sdkModelClasses = [
|
|
3053
|
+
Message,
|
|
3054
|
+
Conversation,
|
|
3055
|
+
Memory,
|
|
3056
|
+
ModelPreference
|
|
3057
|
+
];
|
|
3017
3058
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3018
3059
|
0 && (module.exports = {
|
|
3019
3060
|
ChatConversation,
|
|
@@ -3025,6 +3066,9 @@ Memory.table = "memories";
|
|
|
3025
3066
|
generateConversationId,
|
|
3026
3067
|
generateUniqueKey,
|
|
3027
3068
|
memoryStorageSchema,
|
|
3069
|
+
sdkMigrations,
|
|
3070
|
+
sdkModelClasses,
|
|
3071
|
+
sdkSchema,
|
|
3028
3072
|
useChat,
|
|
3029
3073
|
useChatStorage,
|
|
3030
3074
|
useImageGeneration,
|