@reverbia/sdk 1.0.0-next.20251217144159 → 1.0.0-next.20251217144909
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 +240 -318
- package/dist/expo/index.d.mts +74 -432
- package/dist/expo/index.d.ts +74 -432
- package/dist/expo/index.mjs +225 -297
- 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 +347 -363
- package/dist/react/index.d.mts +73 -464
- package/dist/react/index.d.ts +73 -464
- package/dist/react/index.mjs +326 -336
- 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 = {};
|
|
@@ -322,7 +330,134 @@ function useChat(options) {
|
|
|
322
330
|
// src/expo/useChatStorage.ts
|
|
323
331
|
var import_react2 = require("react");
|
|
324
332
|
|
|
325
|
-
// src/lib/
|
|
333
|
+
// src/lib/db/chat/schema.ts
|
|
334
|
+
var import_watermelondb = require("@nozbe/watermelondb");
|
|
335
|
+
var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
|
|
336
|
+
var chatStorageSchema = (0, import_watermelondb.appSchema)({
|
|
337
|
+
version: 2,
|
|
338
|
+
tables: [
|
|
339
|
+
(0, import_watermelondb.tableSchema)({
|
|
340
|
+
name: "history",
|
|
341
|
+
columns: [
|
|
342
|
+
{ name: "message_id", type: "number" },
|
|
343
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
344
|
+
{ name: "role", type: "string", isIndexed: true },
|
|
345
|
+
{ name: "content", type: "string" },
|
|
346
|
+
{ name: "model", type: "string", isOptional: true },
|
|
347
|
+
{ name: "files", type: "string", isOptional: true },
|
|
348
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
349
|
+
{ name: "updated_at", type: "number" },
|
|
350
|
+
{ name: "vector", type: "string", isOptional: true },
|
|
351
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
352
|
+
{ name: "usage", type: "string", isOptional: true },
|
|
353
|
+
{ name: "sources", type: "string", isOptional: true },
|
|
354
|
+
{ name: "response_duration", type: "number", isOptional: true },
|
|
355
|
+
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
356
|
+
]
|
|
357
|
+
}),
|
|
358
|
+
(0, import_watermelondb.tableSchema)({
|
|
359
|
+
name: "conversations",
|
|
360
|
+
columns: [
|
|
361
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
362
|
+
{ name: "title", type: "string" },
|
|
363
|
+
{ name: "created_at", type: "number" },
|
|
364
|
+
{ name: "updated_at", type: "number" },
|
|
365
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
366
|
+
]
|
|
367
|
+
})
|
|
368
|
+
]
|
|
369
|
+
});
|
|
370
|
+
var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
|
|
371
|
+
migrations: [
|
|
372
|
+
{
|
|
373
|
+
toVersion: 2,
|
|
374
|
+
steps: [
|
|
375
|
+
(0, import_migrations.addColumns)({
|
|
376
|
+
table: "history",
|
|
377
|
+
columns: [{ name: "was_stopped", type: "boolean", isOptional: true }]
|
|
378
|
+
})
|
|
379
|
+
]
|
|
380
|
+
}
|
|
381
|
+
]
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// src/lib/db/chat/models.ts
|
|
385
|
+
var import_watermelondb2 = require("@nozbe/watermelondb");
|
|
386
|
+
var import_decorators = require("@nozbe/watermelondb/decorators");
|
|
387
|
+
var Message = class extends import_watermelondb2.Model {
|
|
388
|
+
};
|
|
389
|
+
Message.table = "history";
|
|
390
|
+
Message.associations = {
|
|
391
|
+
conversations: { type: "belongs_to", key: "conversation_id" }
|
|
392
|
+
};
|
|
393
|
+
__decorateClass([
|
|
394
|
+
(0, import_decorators.field)("message_id")
|
|
395
|
+
], Message.prototype, "messageId", 2);
|
|
396
|
+
__decorateClass([
|
|
397
|
+
(0, import_decorators.text)("conversation_id")
|
|
398
|
+
], Message.prototype, "conversationId", 2);
|
|
399
|
+
__decorateClass([
|
|
400
|
+
(0, import_decorators.text)("role")
|
|
401
|
+
], Message.prototype, "role", 2);
|
|
402
|
+
__decorateClass([
|
|
403
|
+
(0, import_decorators.text)("content")
|
|
404
|
+
], Message.prototype, "content", 2);
|
|
405
|
+
__decorateClass([
|
|
406
|
+
(0, import_decorators.text)("model")
|
|
407
|
+
], Message.prototype, "model", 2);
|
|
408
|
+
__decorateClass([
|
|
409
|
+
(0, import_decorators.json)("files", (json3) => json3)
|
|
410
|
+
], Message.prototype, "files", 2);
|
|
411
|
+
__decorateClass([
|
|
412
|
+
(0, import_decorators.date)("created_at")
|
|
413
|
+
], Message.prototype, "createdAt", 2);
|
|
414
|
+
__decorateClass([
|
|
415
|
+
(0, import_decorators.date)("updated_at")
|
|
416
|
+
], Message.prototype, "updatedAt", 2);
|
|
417
|
+
__decorateClass([
|
|
418
|
+
(0, import_decorators.json)("vector", (json3) => json3)
|
|
419
|
+
], Message.prototype, "vector", 2);
|
|
420
|
+
__decorateClass([
|
|
421
|
+
(0, import_decorators.text)("embedding_model")
|
|
422
|
+
], Message.prototype, "embeddingModel", 2);
|
|
423
|
+
__decorateClass([
|
|
424
|
+
(0, import_decorators.json)("usage", (json3) => json3)
|
|
425
|
+
], Message.prototype, "usage", 2);
|
|
426
|
+
__decorateClass([
|
|
427
|
+
(0, import_decorators.json)("sources", (json3) => json3)
|
|
428
|
+
], Message.prototype, "sources", 2);
|
|
429
|
+
__decorateClass([
|
|
430
|
+
(0, import_decorators.field)("response_duration")
|
|
431
|
+
], Message.prototype, "responseDuration", 2);
|
|
432
|
+
__decorateClass([
|
|
433
|
+
(0, import_decorators.field)("was_stopped")
|
|
434
|
+
], Message.prototype, "wasStopped", 2);
|
|
435
|
+
var Conversation = class extends import_watermelondb2.Model {
|
|
436
|
+
};
|
|
437
|
+
Conversation.table = "conversations";
|
|
438
|
+
Conversation.associations = {
|
|
439
|
+
history: { type: "has_many", foreignKey: "conversation_id" }
|
|
440
|
+
};
|
|
441
|
+
__decorateClass([
|
|
442
|
+
(0, import_decorators.text)("conversation_id")
|
|
443
|
+
], Conversation.prototype, "conversationId", 2);
|
|
444
|
+
__decorateClass([
|
|
445
|
+
(0, import_decorators.text)("title")
|
|
446
|
+
], Conversation.prototype, "title", 2);
|
|
447
|
+
__decorateClass([
|
|
448
|
+
(0, import_decorators.date)("created_at")
|
|
449
|
+
], Conversation.prototype, "createdAt", 2);
|
|
450
|
+
__decorateClass([
|
|
451
|
+
(0, import_decorators.date)("updated_at")
|
|
452
|
+
], Conversation.prototype, "updatedAt", 2);
|
|
453
|
+
__decorateClass([
|
|
454
|
+
(0, import_decorators.field)("is_deleted")
|
|
455
|
+
], Conversation.prototype, "isDeleted", 2);
|
|
456
|
+
|
|
457
|
+
// src/lib/db/chat/types.ts
|
|
458
|
+
function generateConversationId() {
|
|
459
|
+
return `conv_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
460
|
+
}
|
|
326
461
|
function convertUsageToStored(usage) {
|
|
327
462
|
if (!usage) return void 0;
|
|
328
463
|
return {
|
|
@@ -332,12 +467,9 @@ function convertUsageToStored(usage) {
|
|
|
332
467
|
costMicroUsd: usage.cost_micro_usd
|
|
333
468
|
};
|
|
334
469
|
}
|
|
335
|
-
function generateConversationId() {
|
|
336
|
-
return `conv_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
337
|
-
}
|
|
338
470
|
|
|
339
|
-
// src/lib/
|
|
340
|
-
var
|
|
471
|
+
// src/lib/db/chat/operations.ts
|
|
472
|
+
var import_watermelondb3 = require("@nozbe/watermelondb");
|
|
341
473
|
function messageToStored(message) {
|
|
342
474
|
return {
|
|
343
475
|
uniqueId: message.id,
|
|
@@ -380,15 +512,15 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
|
|
|
380
512
|
return conversationToStored(created);
|
|
381
513
|
}
|
|
382
514
|
async function getConversationOp(ctx, id) {
|
|
383
|
-
const results = await ctx.conversationsCollection.query(
|
|
515
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
384
516
|
return results.length > 0 ? conversationToStored(results[0]) : null;
|
|
385
517
|
}
|
|
386
518
|
async function getConversationsOp(ctx) {
|
|
387
|
-
const results = await ctx.conversationsCollection.query(
|
|
519
|
+
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
520
|
return results.map(conversationToStored);
|
|
389
521
|
}
|
|
390
522
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
391
|
-
const results = await ctx.conversationsCollection.query(
|
|
523
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
392
524
|
if (results.length > 0) {
|
|
393
525
|
await ctx.database.write(async () => {
|
|
394
526
|
await results[0].update((conv) => {
|
|
@@ -400,7 +532,7 @@ async function updateConversationTitleOp(ctx, id, title) {
|
|
|
400
532
|
return false;
|
|
401
533
|
}
|
|
402
534
|
async function deleteConversationOp(ctx, id) {
|
|
403
|
-
const results = await ctx.conversationsCollection.query(
|
|
535
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
404
536
|
if (results.length > 0) {
|
|
405
537
|
await ctx.database.write(async () => {
|
|
406
538
|
await results[0].update((conv) => {
|
|
@@ -412,14 +544,14 @@ async function deleteConversationOp(ctx, id) {
|
|
|
412
544
|
return false;
|
|
413
545
|
}
|
|
414
546
|
async function getMessagesOp(ctx, convId) {
|
|
415
|
-
const results = await ctx.messagesCollection.query(
|
|
547
|
+
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
548
|
return results.map(messageToStored);
|
|
417
549
|
}
|
|
418
550
|
async function getMessageCountOp(ctx, convId) {
|
|
419
|
-
return await ctx.messagesCollection.query(
|
|
551
|
+
return await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetchCount();
|
|
420
552
|
}
|
|
421
553
|
async function clearMessagesOp(ctx, convId) {
|
|
422
|
-
const messages = await ctx.messagesCollection.query(
|
|
554
|
+
const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetch();
|
|
423
555
|
await ctx.database.write(async () => {
|
|
424
556
|
for (const message of messages) {
|
|
425
557
|
await message.destroyPermanently();
|
|
@@ -1773,10 +1905,83 @@ function useModels(options = {}) {
|
|
|
1773
1905
|
var import_react5 = require("react");
|
|
1774
1906
|
var import_client4 = require("@reverbia/sdk");
|
|
1775
1907
|
|
|
1776
|
-
// src/lib/
|
|
1777
|
-
var
|
|
1908
|
+
// src/lib/db/memory/schema.ts
|
|
1909
|
+
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
1910
|
+
var memoryStorageSchema = (0, import_watermelondb4.appSchema)({
|
|
1911
|
+
version: 1,
|
|
1912
|
+
tables: [
|
|
1913
|
+
(0, import_watermelondb4.tableSchema)({
|
|
1914
|
+
name: "memories",
|
|
1915
|
+
columns: [
|
|
1916
|
+
{ name: "type", type: "string", isIndexed: true },
|
|
1917
|
+
{ name: "namespace", type: "string", isIndexed: true },
|
|
1918
|
+
{ name: "key", type: "string", isIndexed: true },
|
|
1919
|
+
{ name: "value", type: "string" },
|
|
1920
|
+
{ name: "raw_evidence", type: "string" },
|
|
1921
|
+
{ name: "confidence", type: "number" },
|
|
1922
|
+
{ name: "pii", type: "boolean", isIndexed: true },
|
|
1923
|
+
{ name: "composite_key", type: "string", isIndexed: true },
|
|
1924
|
+
{ name: "unique_key", type: "string", isIndexed: true },
|
|
1925
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
1926
|
+
{ name: "updated_at", type: "number" },
|
|
1927
|
+
{ name: "embedding", type: "string", isOptional: true },
|
|
1928
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
1929
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
1930
|
+
]
|
|
1931
|
+
})
|
|
1932
|
+
]
|
|
1933
|
+
});
|
|
1934
|
+
|
|
1935
|
+
// src/lib/db/memory/models.ts
|
|
1936
|
+
var import_watermelondb5 = require("@nozbe/watermelondb");
|
|
1937
|
+
var import_decorators2 = require("@nozbe/watermelondb/decorators");
|
|
1938
|
+
var Memory = class extends import_watermelondb5.Model {
|
|
1939
|
+
};
|
|
1940
|
+
Memory.table = "memories";
|
|
1941
|
+
__decorateClass([
|
|
1942
|
+
(0, import_decorators2.text)("type")
|
|
1943
|
+
], Memory.prototype, "type", 2);
|
|
1944
|
+
__decorateClass([
|
|
1945
|
+
(0, import_decorators2.text)("namespace")
|
|
1946
|
+
], Memory.prototype, "namespace", 2);
|
|
1947
|
+
__decorateClass([
|
|
1948
|
+
(0, import_decorators2.text)("key")
|
|
1949
|
+
], Memory.prototype, "key", 2);
|
|
1950
|
+
__decorateClass([
|
|
1951
|
+
(0, import_decorators2.text)("value")
|
|
1952
|
+
], Memory.prototype, "value", 2);
|
|
1953
|
+
__decorateClass([
|
|
1954
|
+
(0, import_decorators2.text)("raw_evidence")
|
|
1955
|
+
], Memory.prototype, "rawEvidence", 2);
|
|
1956
|
+
__decorateClass([
|
|
1957
|
+
(0, import_decorators2.field)("confidence")
|
|
1958
|
+
], Memory.prototype, "confidence", 2);
|
|
1959
|
+
__decorateClass([
|
|
1960
|
+
(0, import_decorators2.field)("pii")
|
|
1961
|
+
], Memory.prototype, "pii", 2);
|
|
1962
|
+
__decorateClass([
|
|
1963
|
+
(0, import_decorators2.text)("composite_key")
|
|
1964
|
+
], Memory.prototype, "compositeKey", 2);
|
|
1965
|
+
__decorateClass([
|
|
1966
|
+
(0, import_decorators2.text)("unique_key")
|
|
1967
|
+
], Memory.prototype, "uniqueKey", 2);
|
|
1968
|
+
__decorateClass([
|
|
1969
|
+
(0, import_decorators2.date)("created_at")
|
|
1970
|
+
], Memory.prototype, "createdAt", 2);
|
|
1971
|
+
__decorateClass([
|
|
1972
|
+
(0, import_decorators2.date)("updated_at")
|
|
1973
|
+
], Memory.prototype, "updatedAt", 2);
|
|
1974
|
+
__decorateClass([
|
|
1975
|
+
(0, import_decorators2.json)("embedding", (json3) => json3)
|
|
1976
|
+
], Memory.prototype, "embedding", 2);
|
|
1977
|
+
__decorateClass([
|
|
1978
|
+
(0, import_decorators2.text)("embedding_model")
|
|
1979
|
+
], Memory.prototype, "embeddingModel", 2);
|
|
1980
|
+
__decorateClass([
|
|
1981
|
+
(0, import_decorators2.field)("is_deleted")
|
|
1982
|
+
], Memory.prototype, "isDeleted", 2);
|
|
1778
1983
|
|
|
1779
|
-
// src/lib/
|
|
1984
|
+
// src/lib/db/memory/types.ts
|
|
1780
1985
|
function generateCompositeKey(namespace, key) {
|
|
1781
1986
|
return `${namespace}:${key}`;
|
|
1782
1987
|
}
|
|
@@ -1802,7 +2007,8 @@ function cosineSimilarity(a, b) {
|
|
|
1802
2007
|
return dotProduct / denominator;
|
|
1803
2008
|
}
|
|
1804
2009
|
|
|
1805
|
-
// src/lib/
|
|
2010
|
+
// src/lib/db/memory/operations.ts
|
|
2011
|
+
var import_watermelondb6 = require("@nozbe/watermelondb");
|
|
1806
2012
|
function memoryToStored(memory) {
|
|
1807
2013
|
return {
|
|
1808
2014
|
uniqueId: memory.id,
|
|
@@ -1823,7 +2029,7 @@ function memoryToStored(memory) {
|
|
|
1823
2029
|
};
|
|
1824
2030
|
}
|
|
1825
2031
|
async function getAllMemoriesOp(ctx) {
|
|
1826
|
-
const results = await ctx.memoriesCollection.query(
|
|
2032
|
+
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
2033
|
return results.map(memoryToStored);
|
|
1828
2034
|
}
|
|
1829
2035
|
async function getMemoryByIdOp(ctx, id) {
|
|
@@ -1837,18 +2043,18 @@ async function getMemoryByIdOp(ctx, id) {
|
|
|
1837
2043
|
}
|
|
1838
2044
|
async function getMemoriesByNamespaceOp(ctx, namespace) {
|
|
1839
2045
|
const results = await ctx.memoriesCollection.query(
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
2046
|
+
import_watermelondb6.Q.where("namespace", namespace),
|
|
2047
|
+
import_watermelondb6.Q.where("is_deleted", false),
|
|
2048
|
+
import_watermelondb6.Q.sortBy("created_at", import_watermelondb6.Q.desc)
|
|
1843
2049
|
).fetch();
|
|
1844
2050
|
return results.map(memoryToStored);
|
|
1845
2051
|
}
|
|
1846
2052
|
async function getMemoriesByKeyOp(ctx, namespace, key) {
|
|
1847
2053
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
1848
2054
|
const results = await ctx.memoriesCollection.query(
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
2055
|
+
import_watermelondb6.Q.where("composite_key", compositeKey),
|
|
2056
|
+
import_watermelondb6.Q.where("is_deleted", false),
|
|
2057
|
+
import_watermelondb6.Q.sortBy("created_at", import_watermelondb6.Q.desc)
|
|
1852
2058
|
).fetch();
|
|
1853
2059
|
return results.map(memoryToStored);
|
|
1854
2060
|
}
|
|
@@ -1856,7 +2062,7 @@ async function saveMemoryOp(ctx, opts) {
|
|
|
1856
2062
|
const compositeKey = generateCompositeKey(opts.namespace, opts.key);
|
|
1857
2063
|
const uniqueKey = generateUniqueKey(opts.namespace, opts.key, opts.value);
|
|
1858
2064
|
const result = await ctx.database.write(async () => {
|
|
1859
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2065
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("unique_key", uniqueKey)).fetch();
|
|
1860
2066
|
if (existing.length > 0) {
|
|
1861
2067
|
const existingMemory = existing[0];
|
|
1862
2068
|
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 +2135,7 @@ async function updateMemoryOp(ctx, id, updates) {
|
|
|
1929
2135
|
const newCompositeKey = generateCompositeKey(newNamespace, newKey);
|
|
1930
2136
|
const newUniqueKey = generateUniqueKey(newNamespace, newKey, newValue);
|
|
1931
2137
|
if (newUniqueKey !== memory.uniqueKey) {
|
|
1932
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2138
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("unique_key", newUniqueKey), import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
1933
2139
|
if (existing.length > 0) {
|
|
1934
2140
|
return { ok: false, reason: "conflict", conflictingKey: newUniqueKey };
|
|
1935
2141
|
}
|
|
@@ -1985,7 +2191,7 @@ async function deleteMemoryByIdOp(ctx, id) {
|
|
|
1985
2191
|
}
|
|
1986
2192
|
async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
1987
2193
|
const uniqueKey = generateUniqueKey(namespace, key, value);
|
|
1988
|
-
const results = await ctx.memoriesCollection.query(
|
|
2194
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("unique_key", uniqueKey)).fetch();
|
|
1989
2195
|
if (results.length > 0) {
|
|
1990
2196
|
await ctx.database.write(async () => {
|
|
1991
2197
|
await results[0].update((mem) => {
|
|
@@ -1996,7 +2202,7 @@ async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
|
1996
2202
|
}
|
|
1997
2203
|
async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
1998
2204
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
1999
|
-
const results = await ctx.memoriesCollection.query(
|
|
2205
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("composite_key", compositeKey), import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2000
2206
|
await ctx.database.write(async () => {
|
|
2001
2207
|
for (const memory of results) {
|
|
2002
2208
|
await memory.update((mem) => {
|
|
@@ -2006,7 +2212,7 @@ async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
|
2006
2212
|
});
|
|
2007
2213
|
}
|
|
2008
2214
|
async function clearAllMemoriesOp(ctx) {
|
|
2009
|
-
const results = await ctx.memoriesCollection.query(
|
|
2215
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2010
2216
|
await ctx.database.write(async () => {
|
|
2011
2217
|
for (const memory of results) {
|
|
2012
2218
|
await memory.update((mem) => {
|
|
@@ -2016,7 +2222,7 @@ async function clearAllMemoriesOp(ctx) {
|
|
|
2016
2222
|
});
|
|
2017
2223
|
}
|
|
2018
2224
|
async function searchSimilarMemoriesOp(ctx, queryEmbedding, limit = 10, minSimilarity = 0.6) {
|
|
2019
|
-
const allMemories = await ctx.memoriesCollection.query(
|
|
2225
|
+
const allMemories = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2020
2226
|
const memoriesWithEmbeddings = allMemories.filter(
|
|
2021
2227
|
(m) => m.embedding && m.embedding.length > 0
|
|
2022
2228
|
);
|
|
@@ -2180,7 +2386,7 @@ var DEFAULT_COMPLETION_MODEL = "openai/gpt-4o";
|
|
|
2180
2386
|
|
|
2181
2387
|
// src/expo/useMemoryStorage.ts
|
|
2182
2388
|
var import_client5 = require("@reverbia/sdk");
|
|
2183
|
-
async function generateEmbeddingForTextApi(
|
|
2389
|
+
async function generateEmbeddingForTextApi(text3, options) {
|
|
2184
2390
|
const token = options.getToken ? await options.getToken() : null;
|
|
2185
2391
|
if (!token) {
|
|
2186
2392
|
throw new Error("No auth token available for embedding generation");
|
|
@@ -2188,7 +2394,7 @@ async function generateEmbeddingForTextApi(text, options) {
|
|
|
2188
2394
|
const response = await (0, import_client5.postApiV1Embeddings)({
|
|
2189
2395
|
baseUrl: options.baseUrl,
|
|
2190
2396
|
body: {
|
|
2191
|
-
input:
|
|
2397
|
+
input: text3,
|
|
2192
2398
|
model: options.model
|
|
2193
2399
|
},
|
|
2194
2400
|
headers: {
|
|
@@ -2205,8 +2411,8 @@ async function generateEmbeddingForTextApi(text, options) {
|
|
|
2205
2411
|
return embedding;
|
|
2206
2412
|
}
|
|
2207
2413
|
async function generateEmbeddingForMemoryApi(memory, options) {
|
|
2208
|
-
const
|
|
2209
|
-
return generateEmbeddingForTextApi(
|
|
2414
|
+
const text3 = `${memory.type}: ${memory.namespace}/${memory.key} = ${memory.value}. Evidence: ${memory.rawEvidence}`;
|
|
2415
|
+
return generateEmbeddingForTextApi(text3, options);
|
|
2210
2416
|
}
|
|
2211
2417
|
function useMemoryStorage(options) {
|
|
2212
2418
|
const {
|
|
@@ -2730,290 +2936,6 @@ function useMemoryStorage(options) {
|
|
|
2730
2936
|
clearMemories
|
|
2731
2937
|
};
|
|
2732
2938
|
}
|
|
2733
|
-
|
|
2734
|
-
// src/lib/chatStorage/schema.ts
|
|
2735
|
-
var import_watermelondb3 = require("@nozbe/watermelondb");
|
|
2736
|
-
var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
|
|
2737
|
-
var chatStorageSchema = (0, import_watermelondb3.appSchema)({
|
|
2738
|
-
version: 2,
|
|
2739
|
-
tables: [
|
|
2740
|
-
(0, import_watermelondb3.tableSchema)({
|
|
2741
|
-
name: "history",
|
|
2742
|
-
columns: [
|
|
2743
|
-
{ name: "message_id", type: "number" },
|
|
2744
|
-
// Sequential ID within conversation
|
|
2745
|
-
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
2746
|
-
{ name: "role", type: "string", isIndexed: true },
|
|
2747
|
-
// 'user' | 'assistant' | 'system'
|
|
2748
|
-
{ name: "content", type: "string" },
|
|
2749
|
-
{ name: "model", type: "string", isOptional: true },
|
|
2750
|
-
{ name: "files", type: "string", isOptional: true },
|
|
2751
|
-
// JSON stringified FileMetadata[]
|
|
2752
|
-
{ name: "created_at", type: "number", isIndexed: true },
|
|
2753
|
-
{ name: "updated_at", type: "number" },
|
|
2754
|
-
{ name: "vector", type: "string", isOptional: true },
|
|
2755
|
-
// JSON stringified number[]
|
|
2756
|
-
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2757
|
-
{ name: "usage", type: "string", isOptional: true },
|
|
2758
|
-
// JSON stringified ChatCompletionUsage
|
|
2759
|
-
{ name: "sources", type: "string", isOptional: true },
|
|
2760
|
-
// JSON stringified SearchSource[]
|
|
2761
|
-
{ name: "response_duration", type: "number", isOptional: true },
|
|
2762
|
-
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
2763
|
-
]
|
|
2764
|
-
}),
|
|
2765
|
-
(0, import_watermelondb3.tableSchema)({
|
|
2766
|
-
name: "conversations",
|
|
2767
|
-
columns: [
|
|
2768
|
-
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
2769
|
-
{ name: "title", type: "string" },
|
|
2770
|
-
{ name: "created_at", type: "number" },
|
|
2771
|
-
{ name: "updated_at", type: "number" },
|
|
2772
|
-
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2773
|
-
]
|
|
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)({
|
|
2917
|
-
name: "memories",
|
|
2918
|
-
columns: [
|
|
2919
|
-
// Memory type classification
|
|
2920
|
-
{ name: "type", type: "string", isIndexed: true },
|
|
2921
|
-
// 'identity' | 'preference' | 'project' | 'skill' | 'constraint'
|
|
2922
|
-
// Hierarchical key structure
|
|
2923
|
-
{ name: "namespace", type: "string", isIndexed: true },
|
|
2924
|
-
{ name: "key", type: "string", isIndexed: true },
|
|
2925
|
-
{ name: "value", type: "string" },
|
|
2926
|
-
// Evidence and confidence
|
|
2927
|
-
{ name: "raw_evidence", type: "string" },
|
|
2928
|
-
{ name: "confidence", type: "number" },
|
|
2929
|
-
{ name: "pii", type: "boolean", isIndexed: true },
|
|
2930
|
-
// Composite keys for efficient lookups
|
|
2931
|
-
{ name: "composite_key", type: "string", isIndexed: true },
|
|
2932
|
-
// namespace:key
|
|
2933
|
-
{ name: "unique_key", type: "string", isIndexed: true },
|
|
2934
|
-
// namespace:key:value
|
|
2935
|
-
// Timestamps
|
|
2936
|
-
{ name: "created_at", type: "number", isIndexed: true },
|
|
2937
|
-
{ name: "updated_at", type: "number" },
|
|
2938
|
-
// Vector embeddings for semantic search
|
|
2939
|
-
{ name: "embedding", type: "string", isOptional: true },
|
|
2940
|
-
// JSON stringified number[]
|
|
2941
|
-
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2942
|
-
// Soft delete flag
|
|
2943
|
-
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2944
|
-
]
|
|
2945
|
-
})
|
|
2946
|
-
]
|
|
2947
|
-
});
|
|
2948
|
-
|
|
2949
|
-
// src/lib/memoryStorage/models.ts
|
|
2950
|
-
var import_watermelondb6 = require("@nozbe/watermelondb");
|
|
2951
|
-
var Memory = class extends import_watermelondb6.Model {
|
|
2952
|
-
/** Memory type classification */
|
|
2953
|
-
get type() {
|
|
2954
|
-
return this._getRaw("type");
|
|
2955
|
-
}
|
|
2956
|
-
/** Namespace for grouping related memories */
|
|
2957
|
-
get namespace() {
|
|
2958
|
-
return this._getRaw("namespace");
|
|
2959
|
-
}
|
|
2960
|
-
/** Key within the namespace */
|
|
2961
|
-
get key() {
|
|
2962
|
-
return this._getRaw("key");
|
|
2963
|
-
}
|
|
2964
|
-
/** The memory value/content */
|
|
2965
|
-
get value() {
|
|
2966
|
-
return this._getRaw("value");
|
|
2967
|
-
}
|
|
2968
|
-
/** Raw evidence from which this memory was extracted */
|
|
2969
|
-
get rawEvidence() {
|
|
2970
|
-
return this._getRaw("raw_evidence");
|
|
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;
|
|
3004
|
-
}
|
|
3005
|
-
}
|
|
3006
|
-
/** Model used to generate embedding */
|
|
3007
|
-
get embeddingModel() {
|
|
3008
|
-
const value = this._getRaw("embedding_model");
|
|
3009
|
-
return value ? value : void 0;
|
|
3010
|
-
}
|
|
3011
|
-
/** Soft delete flag */
|
|
3012
|
-
get isDeleted() {
|
|
3013
|
-
return this._getRaw("is_deleted");
|
|
3014
|
-
}
|
|
3015
|
-
};
|
|
3016
|
-
Memory.table = "memories";
|
|
3017
2939
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3018
2940
|
0 && (module.exports = {
|
|
3019
2941
|
ChatConversation,
|