@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/react/index.cjs
CHANGED
|
@@ -26,6 +26,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
30
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
31
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
32
|
+
if (decorator = decorators[i])
|
|
33
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
34
|
+
if (kind && result) __defProp(target, key, result);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
29
37
|
|
|
30
38
|
// src/react/index.ts
|
|
31
39
|
var index_exports = {};
|
|
@@ -56,6 +64,9 @@ __export(index_exports, {
|
|
|
56
64
|
hasEncryptionKey: () => hasEncryptionKey,
|
|
57
65
|
memoryStorageSchema: () => memoryStorageSchema,
|
|
58
66
|
requestEncryptionKey: () => requestEncryptionKey,
|
|
67
|
+
sdkMigrations: () => sdkMigrations,
|
|
68
|
+
sdkModelClasses: () => sdkModelClasses,
|
|
69
|
+
sdkSchema: () => sdkSchema,
|
|
59
70
|
selectTool: () => selectTool,
|
|
60
71
|
settingsStorageSchema: () => settingsStorageSchema,
|
|
61
72
|
storeDropboxToken: () => storeToken,
|
|
@@ -1068,11 +1079,11 @@ async function generateLocalChatCompletion(messages, options = {}) {
|
|
|
1068
1079
|
});
|
|
1069
1080
|
this.cb = cb;
|
|
1070
1081
|
}
|
|
1071
|
-
on_finalized_text(
|
|
1082
|
+
on_finalized_text(text4) {
|
|
1072
1083
|
if (signal?.aborted) {
|
|
1073
1084
|
throw new Error("AbortError");
|
|
1074
1085
|
}
|
|
1075
|
-
this.cb(
|
|
1086
|
+
this.cb(text4);
|
|
1076
1087
|
}
|
|
1077
1088
|
}
|
|
1078
1089
|
const streamer = onToken ? new CallbackStreamer(chatPipeline.tokenizer, onToken) : void 0;
|
|
@@ -1746,7 +1757,134 @@ function useEncryption(signMessage) {
|
|
|
1746
1757
|
// src/react/useChatStorage.ts
|
|
1747
1758
|
var import_react2 = require("react");
|
|
1748
1759
|
|
|
1749
|
-
// src/lib/
|
|
1760
|
+
// src/lib/db/chat/schema.ts
|
|
1761
|
+
var import_watermelondb = require("@nozbe/watermelondb");
|
|
1762
|
+
var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
|
|
1763
|
+
var chatStorageSchema = (0, import_watermelondb.appSchema)({
|
|
1764
|
+
version: 2,
|
|
1765
|
+
tables: [
|
|
1766
|
+
(0, import_watermelondb.tableSchema)({
|
|
1767
|
+
name: "history",
|
|
1768
|
+
columns: [
|
|
1769
|
+
{ name: "message_id", type: "number" },
|
|
1770
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
1771
|
+
{ name: "role", type: "string", isIndexed: true },
|
|
1772
|
+
{ name: "content", type: "string" },
|
|
1773
|
+
{ name: "model", type: "string", isOptional: true },
|
|
1774
|
+
{ name: "files", type: "string", isOptional: true },
|
|
1775
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
1776
|
+
{ name: "updated_at", type: "number" },
|
|
1777
|
+
{ name: "vector", type: "string", isOptional: true },
|
|
1778
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
1779
|
+
{ name: "usage", type: "string", isOptional: true },
|
|
1780
|
+
{ name: "sources", type: "string", isOptional: true },
|
|
1781
|
+
{ name: "response_duration", type: "number", isOptional: true },
|
|
1782
|
+
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
1783
|
+
]
|
|
1784
|
+
}),
|
|
1785
|
+
(0, import_watermelondb.tableSchema)({
|
|
1786
|
+
name: "conversations",
|
|
1787
|
+
columns: [
|
|
1788
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
1789
|
+
{ name: "title", type: "string" },
|
|
1790
|
+
{ name: "created_at", type: "number" },
|
|
1791
|
+
{ name: "updated_at", type: "number" },
|
|
1792
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
1793
|
+
]
|
|
1794
|
+
})
|
|
1795
|
+
]
|
|
1796
|
+
});
|
|
1797
|
+
var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
|
|
1798
|
+
migrations: [
|
|
1799
|
+
{
|
|
1800
|
+
toVersion: 2,
|
|
1801
|
+
steps: [
|
|
1802
|
+
(0, import_migrations.addColumns)({
|
|
1803
|
+
table: "history",
|
|
1804
|
+
columns: [{ name: "was_stopped", type: "boolean", isOptional: true }]
|
|
1805
|
+
})
|
|
1806
|
+
]
|
|
1807
|
+
}
|
|
1808
|
+
]
|
|
1809
|
+
});
|
|
1810
|
+
|
|
1811
|
+
// src/lib/db/chat/models.ts
|
|
1812
|
+
var import_watermelondb2 = require("@nozbe/watermelondb");
|
|
1813
|
+
var import_decorators = require("@nozbe/watermelondb/decorators");
|
|
1814
|
+
var Message = class extends import_watermelondb2.Model {
|
|
1815
|
+
};
|
|
1816
|
+
Message.table = "history";
|
|
1817
|
+
Message.associations = {
|
|
1818
|
+
conversations: { type: "belongs_to", key: "conversation_id" }
|
|
1819
|
+
};
|
|
1820
|
+
__decorateClass([
|
|
1821
|
+
(0, import_decorators.field)("message_id")
|
|
1822
|
+
], Message.prototype, "messageId", 2);
|
|
1823
|
+
__decorateClass([
|
|
1824
|
+
(0, import_decorators.text)("conversation_id")
|
|
1825
|
+
], Message.prototype, "conversationId", 2);
|
|
1826
|
+
__decorateClass([
|
|
1827
|
+
(0, import_decorators.text)("role")
|
|
1828
|
+
], Message.prototype, "role", 2);
|
|
1829
|
+
__decorateClass([
|
|
1830
|
+
(0, import_decorators.text)("content")
|
|
1831
|
+
], Message.prototype, "content", 2);
|
|
1832
|
+
__decorateClass([
|
|
1833
|
+
(0, import_decorators.text)("model")
|
|
1834
|
+
], Message.prototype, "model", 2);
|
|
1835
|
+
__decorateClass([
|
|
1836
|
+
(0, import_decorators.json)("files", (json3) => json3)
|
|
1837
|
+
], Message.prototype, "files", 2);
|
|
1838
|
+
__decorateClass([
|
|
1839
|
+
(0, import_decorators.date)("created_at")
|
|
1840
|
+
], Message.prototype, "createdAt", 2);
|
|
1841
|
+
__decorateClass([
|
|
1842
|
+
(0, import_decorators.date)("updated_at")
|
|
1843
|
+
], Message.prototype, "updatedAt", 2);
|
|
1844
|
+
__decorateClass([
|
|
1845
|
+
(0, import_decorators.json)("vector", (json3) => json3)
|
|
1846
|
+
], Message.prototype, "vector", 2);
|
|
1847
|
+
__decorateClass([
|
|
1848
|
+
(0, import_decorators.text)("embedding_model")
|
|
1849
|
+
], Message.prototype, "embeddingModel", 2);
|
|
1850
|
+
__decorateClass([
|
|
1851
|
+
(0, import_decorators.json)("usage", (json3) => json3)
|
|
1852
|
+
], Message.prototype, "usage", 2);
|
|
1853
|
+
__decorateClass([
|
|
1854
|
+
(0, import_decorators.json)("sources", (json3) => json3)
|
|
1855
|
+
], Message.prototype, "sources", 2);
|
|
1856
|
+
__decorateClass([
|
|
1857
|
+
(0, import_decorators.field)("response_duration")
|
|
1858
|
+
], Message.prototype, "responseDuration", 2);
|
|
1859
|
+
__decorateClass([
|
|
1860
|
+
(0, import_decorators.field)("was_stopped")
|
|
1861
|
+
], Message.prototype, "wasStopped", 2);
|
|
1862
|
+
var Conversation = class extends import_watermelondb2.Model {
|
|
1863
|
+
};
|
|
1864
|
+
Conversation.table = "conversations";
|
|
1865
|
+
Conversation.associations = {
|
|
1866
|
+
history: { type: "has_many", foreignKey: "conversation_id" }
|
|
1867
|
+
};
|
|
1868
|
+
__decorateClass([
|
|
1869
|
+
(0, import_decorators.text)("conversation_id")
|
|
1870
|
+
], Conversation.prototype, "conversationId", 2);
|
|
1871
|
+
__decorateClass([
|
|
1872
|
+
(0, import_decorators.text)("title")
|
|
1873
|
+
], Conversation.prototype, "title", 2);
|
|
1874
|
+
__decorateClass([
|
|
1875
|
+
(0, import_decorators.date)("created_at")
|
|
1876
|
+
], Conversation.prototype, "createdAt", 2);
|
|
1877
|
+
__decorateClass([
|
|
1878
|
+
(0, import_decorators.date)("updated_at")
|
|
1879
|
+
], Conversation.prototype, "updatedAt", 2);
|
|
1880
|
+
__decorateClass([
|
|
1881
|
+
(0, import_decorators.field)("is_deleted")
|
|
1882
|
+
], Conversation.prototype, "isDeleted", 2);
|
|
1883
|
+
|
|
1884
|
+
// src/lib/db/chat/types.ts
|
|
1885
|
+
function generateConversationId() {
|
|
1886
|
+
return `conv_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
1887
|
+
}
|
|
1750
1888
|
function convertUsageToStored(usage) {
|
|
1751
1889
|
if (!usage) return void 0;
|
|
1752
1890
|
return {
|
|
@@ -1756,12 +1894,9 @@ function convertUsageToStored(usage) {
|
|
|
1756
1894
|
costMicroUsd: usage.cost_micro_usd
|
|
1757
1895
|
};
|
|
1758
1896
|
}
|
|
1759
|
-
function generateConversationId() {
|
|
1760
|
-
return `conv_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
1761
|
-
}
|
|
1762
1897
|
|
|
1763
|
-
// src/lib/
|
|
1764
|
-
var
|
|
1898
|
+
// src/lib/db/chat/operations.ts
|
|
1899
|
+
var import_watermelondb3 = require("@nozbe/watermelondb");
|
|
1765
1900
|
function messageToStored(message) {
|
|
1766
1901
|
return {
|
|
1767
1902
|
uniqueId: message.id,
|
|
@@ -1804,15 +1939,15 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
|
|
|
1804
1939
|
return conversationToStored(created);
|
|
1805
1940
|
}
|
|
1806
1941
|
async function getConversationOp(ctx, id) {
|
|
1807
|
-
const results = await ctx.conversationsCollection.query(
|
|
1942
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
1808
1943
|
return results.length > 0 ? conversationToStored(results[0]) : null;
|
|
1809
1944
|
}
|
|
1810
1945
|
async function getConversationsOp(ctx) {
|
|
1811
|
-
const results = await ctx.conversationsCollection.query(
|
|
1946
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false), import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).fetch();
|
|
1812
1947
|
return results.map(conversationToStored);
|
|
1813
1948
|
}
|
|
1814
1949
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
1815
|
-
const results = await ctx.conversationsCollection.query(
|
|
1950
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
1816
1951
|
if (results.length > 0) {
|
|
1817
1952
|
await ctx.database.write(async () => {
|
|
1818
1953
|
await results[0].update((conv) => {
|
|
@@ -1824,7 +1959,7 @@ async function updateConversationTitleOp(ctx, id, title) {
|
|
|
1824
1959
|
return false;
|
|
1825
1960
|
}
|
|
1826
1961
|
async function deleteConversationOp(ctx, id) {
|
|
1827
|
-
const results = await ctx.conversationsCollection.query(
|
|
1962
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
1828
1963
|
if (results.length > 0) {
|
|
1829
1964
|
await ctx.database.write(async () => {
|
|
1830
1965
|
await results[0].update((conv) => {
|
|
@@ -1836,14 +1971,14 @@ async function deleteConversationOp(ctx, id) {
|
|
|
1836
1971
|
return false;
|
|
1837
1972
|
}
|
|
1838
1973
|
async function getMessagesOp(ctx, convId) {
|
|
1839
|
-
const results = await ctx.messagesCollection.query(
|
|
1974
|
+
const results = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId), import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.asc)).fetch();
|
|
1840
1975
|
return results.map(messageToStored);
|
|
1841
1976
|
}
|
|
1842
1977
|
async function getMessageCountOp(ctx, convId) {
|
|
1843
|
-
return await ctx.messagesCollection.query(
|
|
1978
|
+
return await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetchCount();
|
|
1844
1979
|
}
|
|
1845
1980
|
async function clearMessagesOp(ctx, convId) {
|
|
1846
|
-
const messages = await ctx.messagesCollection.query(
|
|
1981
|
+
const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetch();
|
|
1847
1982
|
await ctx.database.write(async () => {
|
|
1848
1983
|
for (const message of messages) {
|
|
1849
1984
|
await message.destroyPermanently();
|
|
@@ -1902,11 +2037,11 @@ function cosineSimilarity(a, b) {
|
|
|
1902
2037
|
}
|
|
1903
2038
|
async function searchMessagesOp(ctx, queryVector, options) {
|
|
1904
2039
|
const { limit = 10, minSimilarity = 0.5, conversationId } = options || {};
|
|
1905
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
2040
|
+
const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
1906
2041
|
const activeConversationIds = new Set(
|
|
1907
2042
|
activeConversations.map((c) => c.conversationId)
|
|
1908
2043
|
);
|
|
1909
|
-
const queryConditions = conversationId ? [
|
|
2044
|
+
const queryConditions = conversationId ? [import_watermelondb3.Q.where("conversation_id", conversationId)] : [];
|
|
1910
2045
|
const messages = await ctx.messagesCollection.query(...queryConditions).fetch();
|
|
1911
2046
|
const resultsWithSimilarity = [];
|
|
1912
2047
|
for (const message of messages) {
|
|
@@ -2266,38 +2401,98 @@ function useChatStorage(options) {
|
|
|
2266
2401
|
};
|
|
2267
2402
|
}
|
|
2268
2403
|
|
|
2269
|
-
// src/lib/
|
|
2270
|
-
var
|
|
2271
|
-
var
|
|
2272
|
-
|
|
2273
|
-
|
|
2404
|
+
// src/lib/db/schema.ts
|
|
2405
|
+
var import_watermelondb6 = require("@nozbe/watermelondb");
|
|
2406
|
+
var import_migrations2 = require("@nozbe/watermelondb/Schema/migrations");
|
|
2407
|
+
|
|
2408
|
+
// src/lib/db/memory/models.ts
|
|
2409
|
+
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
2410
|
+
var import_decorators2 = require("@nozbe/watermelondb/decorators");
|
|
2411
|
+
var Memory = class extends import_watermelondb4.Model {
|
|
2412
|
+
};
|
|
2413
|
+
Memory.table = "memories";
|
|
2414
|
+
__decorateClass([
|
|
2415
|
+
(0, import_decorators2.text)("type")
|
|
2416
|
+
], Memory.prototype, "type", 2);
|
|
2417
|
+
__decorateClass([
|
|
2418
|
+
(0, import_decorators2.text)("namespace")
|
|
2419
|
+
], Memory.prototype, "namespace", 2);
|
|
2420
|
+
__decorateClass([
|
|
2421
|
+
(0, import_decorators2.text)("key")
|
|
2422
|
+
], Memory.prototype, "key", 2);
|
|
2423
|
+
__decorateClass([
|
|
2424
|
+
(0, import_decorators2.text)("value")
|
|
2425
|
+
], Memory.prototype, "value", 2);
|
|
2426
|
+
__decorateClass([
|
|
2427
|
+
(0, import_decorators2.text)("raw_evidence")
|
|
2428
|
+
], Memory.prototype, "rawEvidence", 2);
|
|
2429
|
+
__decorateClass([
|
|
2430
|
+
(0, import_decorators2.field)("confidence")
|
|
2431
|
+
], Memory.prototype, "confidence", 2);
|
|
2432
|
+
__decorateClass([
|
|
2433
|
+
(0, import_decorators2.field)("pii")
|
|
2434
|
+
], Memory.prototype, "pii", 2);
|
|
2435
|
+
__decorateClass([
|
|
2436
|
+
(0, import_decorators2.text)("composite_key")
|
|
2437
|
+
], Memory.prototype, "compositeKey", 2);
|
|
2438
|
+
__decorateClass([
|
|
2439
|
+
(0, import_decorators2.text)("unique_key")
|
|
2440
|
+
], Memory.prototype, "uniqueKey", 2);
|
|
2441
|
+
__decorateClass([
|
|
2442
|
+
(0, import_decorators2.date)("created_at")
|
|
2443
|
+
], Memory.prototype, "createdAt", 2);
|
|
2444
|
+
__decorateClass([
|
|
2445
|
+
(0, import_decorators2.date)("updated_at")
|
|
2446
|
+
], Memory.prototype, "updatedAt", 2);
|
|
2447
|
+
__decorateClass([
|
|
2448
|
+
(0, import_decorators2.json)("embedding", (json3) => json3)
|
|
2449
|
+
], Memory.prototype, "embedding", 2);
|
|
2450
|
+
__decorateClass([
|
|
2451
|
+
(0, import_decorators2.text)("embedding_model")
|
|
2452
|
+
], Memory.prototype, "embeddingModel", 2);
|
|
2453
|
+
__decorateClass([
|
|
2454
|
+
(0, import_decorators2.field)("is_deleted")
|
|
2455
|
+
], Memory.prototype, "isDeleted", 2);
|
|
2456
|
+
|
|
2457
|
+
// src/lib/db/settings/models.ts
|
|
2458
|
+
var import_watermelondb5 = require("@nozbe/watermelondb");
|
|
2459
|
+
var import_decorators3 = require("@nozbe/watermelondb/decorators");
|
|
2460
|
+
var ModelPreference = class extends import_watermelondb5.Model {
|
|
2461
|
+
};
|
|
2462
|
+
ModelPreference.table = "modelPreferences";
|
|
2463
|
+
__decorateClass([
|
|
2464
|
+
(0, import_decorators3.text)("wallet_address")
|
|
2465
|
+
], ModelPreference.prototype, "walletAddress", 2);
|
|
2466
|
+
__decorateClass([
|
|
2467
|
+
(0, import_decorators3.text)("models")
|
|
2468
|
+
], ModelPreference.prototype, "models", 2);
|
|
2469
|
+
|
|
2470
|
+
// src/lib/db/schema.ts
|
|
2471
|
+
var SDK_SCHEMA_VERSION = 4;
|
|
2472
|
+
var sdkSchema = (0, import_watermelondb6.appSchema)({
|
|
2473
|
+
version: SDK_SCHEMA_VERSION,
|
|
2274
2474
|
tables: [
|
|
2275
|
-
|
|
2475
|
+
// Chat storage tables
|
|
2476
|
+
(0, import_watermelondb6.tableSchema)({
|
|
2276
2477
|
name: "history",
|
|
2277
2478
|
columns: [
|
|
2278
2479
|
{ name: "message_id", type: "number" },
|
|
2279
|
-
// Sequential ID within conversation
|
|
2280
2480
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
2281
2481
|
{ name: "role", type: "string", isIndexed: true },
|
|
2282
|
-
// 'user' | 'assistant' | 'system'
|
|
2283
2482
|
{ name: "content", type: "string" },
|
|
2284
2483
|
{ name: "model", type: "string", isOptional: true },
|
|
2285
2484
|
{ name: "files", type: "string", isOptional: true },
|
|
2286
|
-
// JSON stringified FileMetadata[]
|
|
2287
2485
|
{ name: "created_at", type: "number", isIndexed: true },
|
|
2288
2486
|
{ name: "updated_at", type: "number" },
|
|
2289
2487
|
{ name: "vector", type: "string", isOptional: true },
|
|
2290
|
-
// JSON stringified number[]
|
|
2291
2488
|
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2292
2489
|
{ name: "usage", type: "string", isOptional: true },
|
|
2293
|
-
// JSON stringified ChatCompletionUsage
|
|
2294
2490
|
{ name: "sources", type: "string", isOptional: true },
|
|
2295
|
-
// JSON stringified SearchSource[]
|
|
2296
2491
|
{ name: "response_duration", type: "number", isOptional: true },
|
|
2297
2492
|
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
2298
2493
|
]
|
|
2299
2494
|
}),
|
|
2300
|
-
(0,
|
|
2495
|
+
(0, import_watermelondb6.tableSchema)({
|
|
2301
2496
|
name: "conversations",
|
|
2302
2497
|
columns: [
|
|
2303
2498
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -2306,151 +2501,103 @@ var chatStorageSchema = (0, import_watermelondb2.appSchema)({
|
|
|
2306
2501
|
{ name: "updated_at", type: "number" },
|
|
2307
2502
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2308
2503
|
]
|
|
2504
|
+
}),
|
|
2505
|
+
// Memory storage tables
|
|
2506
|
+
(0, import_watermelondb6.tableSchema)({
|
|
2507
|
+
name: "memories",
|
|
2508
|
+
columns: [
|
|
2509
|
+
{ name: "type", type: "string", isIndexed: true },
|
|
2510
|
+
{ name: "namespace", type: "string", isIndexed: true },
|
|
2511
|
+
{ name: "key", type: "string", isIndexed: true },
|
|
2512
|
+
{ name: "value", type: "string" },
|
|
2513
|
+
{ name: "raw_evidence", type: "string" },
|
|
2514
|
+
{ name: "confidence", type: "number" },
|
|
2515
|
+
{ name: "pii", type: "boolean", isIndexed: true },
|
|
2516
|
+
{ name: "composite_key", type: "string", isIndexed: true },
|
|
2517
|
+
{ name: "unique_key", type: "string", isIndexed: true },
|
|
2518
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
2519
|
+
{ name: "updated_at", type: "number" },
|
|
2520
|
+
{ name: "embedding", type: "string", isOptional: true },
|
|
2521
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2522
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2523
|
+
]
|
|
2524
|
+
}),
|
|
2525
|
+
// Settings storage tables
|
|
2526
|
+
(0, import_watermelondb6.tableSchema)({
|
|
2527
|
+
name: "modelPreferences",
|
|
2528
|
+
columns: [
|
|
2529
|
+
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
2530
|
+
{ name: "models", type: "string", isOptional: true }
|
|
2531
|
+
]
|
|
2309
2532
|
})
|
|
2310
2533
|
]
|
|
2311
2534
|
});
|
|
2312
|
-
var
|
|
2535
|
+
var sdkMigrations = (0, import_migrations2.schemaMigrations)({
|
|
2313
2536
|
migrations: [
|
|
2537
|
+
// v2 -> v3: Added was_stopped column to history
|
|
2314
2538
|
{
|
|
2315
|
-
toVersion:
|
|
2539
|
+
toVersion: 3,
|
|
2316
2540
|
steps: [
|
|
2317
|
-
(0,
|
|
2541
|
+
(0, import_migrations2.addColumns)({
|
|
2318
2542
|
table: "history",
|
|
2543
|
+
columns: [{ name: "was_stopped", type: "boolean", isOptional: true }]
|
|
2544
|
+
})
|
|
2545
|
+
]
|
|
2546
|
+
},
|
|
2547
|
+
// v3 -> v4: Added settings storage (modelPreferences table)
|
|
2548
|
+
{
|
|
2549
|
+
toVersion: 4,
|
|
2550
|
+
steps: [
|
|
2551
|
+
(0, import_migrations2.createTable)({
|
|
2552
|
+
name: "modelPreferences",
|
|
2319
2553
|
columns: [
|
|
2320
|
-
{ name: "
|
|
2554
|
+
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
2555
|
+
{ name: "models", type: "string", isOptional: true }
|
|
2321
2556
|
]
|
|
2322
2557
|
})
|
|
2323
2558
|
]
|
|
2324
2559
|
}
|
|
2325
2560
|
]
|
|
2326
2561
|
});
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
return this._getRaw("message_id");
|
|
2334
|
-
}
|
|
2335
|
-
/** Links message to its conversation */
|
|
2336
|
-
get conversationId() {
|
|
2337
|
-
return this._getRaw("conversation_id");
|
|
2338
|
-
}
|
|
2339
|
-
/** Who sent the message: 'user' | 'assistant' | 'system' */
|
|
2340
|
-
get role() {
|
|
2341
|
-
return this._getRaw("role");
|
|
2342
|
-
}
|
|
2343
|
-
/** The message text content */
|
|
2344
|
-
get content() {
|
|
2345
|
-
return this._getRaw("content");
|
|
2346
|
-
}
|
|
2347
|
-
/** LLM model used (e.g., GPT-4, Claude) */
|
|
2348
|
-
get model() {
|
|
2349
|
-
const value = this._getRaw("model");
|
|
2350
|
-
return value ? value : void 0;
|
|
2351
|
-
}
|
|
2352
|
-
/** Optional attached files */
|
|
2353
|
-
get files() {
|
|
2354
|
-
const raw = this._getRaw("files");
|
|
2355
|
-
if (!raw) return void 0;
|
|
2356
|
-
try {
|
|
2357
|
-
return JSON.parse(raw);
|
|
2358
|
-
} catch {
|
|
2359
|
-
return void 0;
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
/** Created timestamp */
|
|
2363
|
-
get createdAt() {
|
|
2364
|
-
return new Date(this._getRaw("created_at"));
|
|
2365
|
-
}
|
|
2366
|
-
/** Updated timestamp */
|
|
2367
|
-
get updatedAt() {
|
|
2368
|
-
return new Date(this._getRaw("updated_at"));
|
|
2369
|
-
}
|
|
2370
|
-
/** Embedding vector for semantic search */
|
|
2371
|
-
get vector() {
|
|
2372
|
-
const raw = this._getRaw("vector");
|
|
2373
|
-
if (!raw) return void 0;
|
|
2374
|
-
try {
|
|
2375
|
-
return JSON.parse(raw);
|
|
2376
|
-
} catch {
|
|
2377
|
-
return void 0;
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
/** Model used to generate embedding */
|
|
2381
|
-
get embeddingModel() {
|
|
2382
|
-
const value = this._getRaw("embedding_model");
|
|
2383
|
-
return value ? value : void 0;
|
|
2384
|
-
}
|
|
2385
|
-
/** Token counts and cost */
|
|
2386
|
-
get usage() {
|
|
2387
|
-
const raw = this._getRaw("usage");
|
|
2388
|
-
if (!raw) return void 0;
|
|
2389
|
-
try {
|
|
2390
|
-
return JSON.parse(raw);
|
|
2391
|
-
} catch {
|
|
2392
|
-
return void 0;
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
/** Web search sources */
|
|
2396
|
-
get sources() {
|
|
2397
|
-
const raw = this._getRaw("sources");
|
|
2398
|
-
if (!raw) return void 0;
|
|
2399
|
-
try {
|
|
2400
|
-
return JSON.parse(raw);
|
|
2401
|
-
} catch {
|
|
2402
|
-
return void 0;
|
|
2403
|
-
}
|
|
2404
|
-
}
|
|
2405
|
-
/** Response time in seconds */
|
|
2406
|
-
get responseDuration() {
|
|
2407
|
-
const value = this._getRaw("response_duration");
|
|
2408
|
-
return value !== null && value !== void 0 ? value : void 0;
|
|
2409
|
-
}
|
|
2410
|
-
/** Whether the message generation was stopped by the user */
|
|
2411
|
-
get wasStopped() {
|
|
2412
|
-
return this._getRaw("was_stopped");
|
|
2413
|
-
}
|
|
2414
|
-
};
|
|
2415
|
-
Message.table = "history";
|
|
2416
|
-
Message.associations = {
|
|
2417
|
-
conversations: { type: "belongs_to", key: "conversation_id" }
|
|
2418
|
-
};
|
|
2419
|
-
var Conversation = class extends import_watermelondb3.Model {
|
|
2420
|
-
/** Unique conversation identifier */
|
|
2421
|
-
get conversationId() {
|
|
2422
|
-
return this._getRaw("conversation_id");
|
|
2423
|
-
}
|
|
2424
|
-
/** Conversation title */
|
|
2425
|
-
get title() {
|
|
2426
|
-
return this._getRaw("title");
|
|
2427
|
-
}
|
|
2428
|
-
/** Created timestamp */
|
|
2429
|
-
get createdAt() {
|
|
2430
|
-
return new Date(this._getRaw("created_at"));
|
|
2431
|
-
}
|
|
2432
|
-
/** Updated timestamp */
|
|
2433
|
-
get updatedAt() {
|
|
2434
|
-
return new Date(this._getRaw("updated_at"));
|
|
2435
|
-
}
|
|
2436
|
-
/** Soft delete flag */
|
|
2437
|
-
get isDeleted() {
|
|
2438
|
-
return this._getRaw("is_deleted");
|
|
2439
|
-
}
|
|
2440
|
-
};
|
|
2441
|
-
Conversation.table = "conversations";
|
|
2442
|
-
Conversation.associations = {
|
|
2443
|
-
history: { type: "has_many", foreignKey: "conversation_id" }
|
|
2444
|
-
};
|
|
2562
|
+
var sdkModelClasses = [
|
|
2563
|
+
Message,
|
|
2564
|
+
Conversation,
|
|
2565
|
+
Memory,
|
|
2566
|
+
ModelPreference
|
|
2567
|
+
];
|
|
2445
2568
|
|
|
2446
2569
|
// src/react/useMemoryStorage.ts
|
|
2447
2570
|
var import_react3 = require("react");
|
|
2448
2571
|
var import_client6 = require("@reverbia/sdk");
|
|
2449
2572
|
|
|
2450
|
-
// src/lib/
|
|
2451
|
-
var
|
|
2573
|
+
// src/lib/db/memory/schema.ts
|
|
2574
|
+
var import_watermelondb7 = require("@nozbe/watermelondb");
|
|
2575
|
+
var memoryStorageSchema = (0, import_watermelondb7.appSchema)({
|
|
2576
|
+
version: 1,
|
|
2577
|
+
tables: [
|
|
2578
|
+
(0, import_watermelondb7.tableSchema)({
|
|
2579
|
+
name: "memories",
|
|
2580
|
+
columns: [
|
|
2581
|
+
{ name: "type", type: "string", isIndexed: true },
|
|
2582
|
+
{ name: "namespace", type: "string", isIndexed: true },
|
|
2583
|
+
{ name: "key", type: "string", isIndexed: true },
|
|
2584
|
+
{ name: "value", type: "string" },
|
|
2585
|
+
{ name: "raw_evidence", type: "string" },
|
|
2586
|
+
{ name: "confidence", type: "number" },
|
|
2587
|
+
{ name: "pii", type: "boolean", isIndexed: true },
|
|
2588
|
+
{ name: "composite_key", type: "string", isIndexed: true },
|
|
2589
|
+
{ name: "unique_key", type: "string", isIndexed: true },
|
|
2590
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
2591
|
+
{ name: "updated_at", type: "number" },
|
|
2592
|
+
{ name: "embedding", type: "string", isOptional: true },
|
|
2593
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2594
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2595
|
+
]
|
|
2596
|
+
})
|
|
2597
|
+
]
|
|
2598
|
+
});
|
|
2452
2599
|
|
|
2453
|
-
// src/lib/
|
|
2600
|
+
// src/lib/db/memory/types.ts
|
|
2454
2601
|
function generateCompositeKey(namespace, key) {
|
|
2455
2602
|
return `${namespace}:${key}`;
|
|
2456
2603
|
}
|
|
@@ -2476,7 +2623,8 @@ function cosineSimilarity2(a, b) {
|
|
|
2476
2623
|
return dotProduct / denominator;
|
|
2477
2624
|
}
|
|
2478
2625
|
|
|
2479
|
-
// src/lib/
|
|
2626
|
+
// src/lib/db/memory/operations.ts
|
|
2627
|
+
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
2480
2628
|
function memoryToStored(memory) {
|
|
2481
2629
|
return {
|
|
2482
2630
|
uniqueId: memory.id,
|
|
@@ -2497,7 +2645,7 @@ function memoryToStored(memory) {
|
|
|
2497
2645
|
};
|
|
2498
2646
|
}
|
|
2499
2647
|
async function getAllMemoriesOp(ctx) {
|
|
2500
|
-
const results = await ctx.memoriesCollection.query(
|
|
2648
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("is_deleted", false), import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.desc)).fetch();
|
|
2501
2649
|
return results.map(memoryToStored);
|
|
2502
2650
|
}
|
|
2503
2651
|
async function getMemoryByIdOp(ctx, id) {
|
|
@@ -2511,18 +2659,18 @@ async function getMemoryByIdOp(ctx, id) {
|
|
|
2511
2659
|
}
|
|
2512
2660
|
async function getMemoriesByNamespaceOp(ctx, namespace) {
|
|
2513
2661
|
const results = await ctx.memoriesCollection.query(
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2662
|
+
import_watermelondb8.Q.where("namespace", namespace),
|
|
2663
|
+
import_watermelondb8.Q.where("is_deleted", false),
|
|
2664
|
+
import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.desc)
|
|
2517
2665
|
).fetch();
|
|
2518
2666
|
return results.map(memoryToStored);
|
|
2519
2667
|
}
|
|
2520
2668
|
async function getMemoriesByKeyOp(ctx, namespace, key) {
|
|
2521
2669
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
2522
2670
|
const results = await ctx.memoriesCollection.query(
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2671
|
+
import_watermelondb8.Q.where("composite_key", compositeKey),
|
|
2672
|
+
import_watermelondb8.Q.where("is_deleted", false),
|
|
2673
|
+
import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.desc)
|
|
2526
2674
|
).fetch();
|
|
2527
2675
|
return results.map(memoryToStored);
|
|
2528
2676
|
}
|
|
@@ -2530,7 +2678,7 @@ async function saveMemoryOp(ctx, opts) {
|
|
|
2530
2678
|
const compositeKey = generateCompositeKey(opts.namespace, opts.key);
|
|
2531
2679
|
const uniqueKey = generateUniqueKey(opts.namespace, opts.key, opts.value);
|
|
2532
2680
|
const result = await ctx.database.write(async () => {
|
|
2533
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2681
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("unique_key", uniqueKey)).fetch();
|
|
2534
2682
|
if (existing.length > 0) {
|
|
2535
2683
|
const existingMemory = existing[0];
|
|
2536
2684
|
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;
|
|
@@ -2603,7 +2751,7 @@ async function updateMemoryOp(ctx, id, updates) {
|
|
|
2603
2751
|
const newCompositeKey = generateCompositeKey(newNamespace, newKey);
|
|
2604
2752
|
const newUniqueKey = generateUniqueKey(newNamespace, newKey, newValue);
|
|
2605
2753
|
if (newUniqueKey !== memory.uniqueKey) {
|
|
2606
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2754
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("unique_key", newUniqueKey), import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
2607
2755
|
if (existing.length > 0) {
|
|
2608
2756
|
return { ok: false, reason: "conflict", conflictingKey: newUniqueKey };
|
|
2609
2757
|
}
|
|
@@ -2659,7 +2807,7 @@ async function deleteMemoryByIdOp(ctx, id) {
|
|
|
2659
2807
|
}
|
|
2660
2808
|
async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
2661
2809
|
const uniqueKey = generateUniqueKey(namespace, key, value);
|
|
2662
|
-
const results = await ctx.memoriesCollection.query(
|
|
2810
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("unique_key", uniqueKey)).fetch();
|
|
2663
2811
|
if (results.length > 0) {
|
|
2664
2812
|
await ctx.database.write(async () => {
|
|
2665
2813
|
await results[0].update((mem) => {
|
|
@@ -2670,7 +2818,7 @@ async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
|
2670
2818
|
}
|
|
2671
2819
|
async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
2672
2820
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
2673
|
-
const results = await ctx.memoriesCollection.query(
|
|
2821
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("composite_key", compositeKey), import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
2674
2822
|
await ctx.database.write(async () => {
|
|
2675
2823
|
for (const memory of results) {
|
|
2676
2824
|
await memory.update((mem) => {
|
|
@@ -2680,7 +2828,7 @@ async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
|
2680
2828
|
});
|
|
2681
2829
|
}
|
|
2682
2830
|
async function clearAllMemoriesOp(ctx) {
|
|
2683
|
-
const results = await ctx.memoriesCollection.query(
|
|
2831
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
2684
2832
|
await ctx.database.write(async () => {
|
|
2685
2833
|
for (const memory of results) {
|
|
2686
2834
|
await memory.update((mem) => {
|
|
@@ -2690,7 +2838,7 @@ async function clearAllMemoriesOp(ctx) {
|
|
|
2690
2838
|
});
|
|
2691
2839
|
}
|
|
2692
2840
|
async function searchSimilarMemoriesOp(ctx, queryEmbedding, limit = 10, minSimilarity = 0.6) {
|
|
2693
|
-
const allMemories = await ctx.memoriesCollection.query(
|
|
2841
|
+
const allMemories = await ctx.memoriesCollection.query(import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
2694
2842
|
const memoriesWithEmbeddings = allMemories.filter(
|
|
2695
2843
|
(m) => m.embedding && m.embedding.length > 0
|
|
2696
2844
|
);
|
|
@@ -2893,7 +3041,7 @@ var DEFAULT_COMPLETION_MODEL = "openai/gpt-4o";
|
|
|
2893
3041
|
|
|
2894
3042
|
// src/lib/memory/embeddings.ts
|
|
2895
3043
|
var embeddingPipeline = null;
|
|
2896
|
-
var generateEmbeddingForText = async (
|
|
3044
|
+
var generateEmbeddingForText = async (text4, options = {}) => {
|
|
2897
3045
|
const { baseUrl = BASE_URL, provider = "local" } = options;
|
|
2898
3046
|
if (provider === "api") {
|
|
2899
3047
|
const { getToken, model: model2 } = options;
|
|
@@ -2907,7 +3055,7 @@ var generateEmbeddingForText = async (text, options = {}) => {
|
|
|
2907
3055
|
const response = await postApiV1Embeddings({
|
|
2908
3056
|
baseUrl,
|
|
2909
3057
|
body: {
|
|
2910
|
-
input:
|
|
3058
|
+
input: text4,
|
|
2911
3059
|
model: model2 ?? DEFAULT_API_EMBEDDING_MODEL
|
|
2912
3060
|
},
|
|
2913
3061
|
headers: {
|
|
@@ -2933,7 +3081,7 @@ var generateEmbeddingForText = async (text, options = {}) => {
|
|
|
2933
3081
|
const { pipeline } = await import("@huggingface/transformers");
|
|
2934
3082
|
embeddingPipeline = await pipeline("feature-extraction", model);
|
|
2935
3083
|
}
|
|
2936
|
-
const output = await embeddingPipeline(
|
|
3084
|
+
const output = await embeddingPipeline(text4, {
|
|
2937
3085
|
pooling: "cls",
|
|
2938
3086
|
normalize: true
|
|
2939
3087
|
});
|
|
@@ -2947,14 +3095,14 @@ var generateEmbeddingForText = async (text, options = {}) => {
|
|
|
2947
3095
|
}
|
|
2948
3096
|
};
|
|
2949
3097
|
var generateEmbeddingForMemory = async (memory, options = {}) => {
|
|
2950
|
-
const
|
|
3098
|
+
const text4 = [
|
|
2951
3099
|
memory.rawEvidence,
|
|
2952
3100
|
memory.type,
|
|
2953
3101
|
memory.namespace,
|
|
2954
3102
|
memory.key,
|
|
2955
3103
|
memory.value
|
|
2956
3104
|
].filter(Boolean).join(" ");
|
|
2957
|
-
return generateEmbeddingForText(
|
|
3105
|
+
return generateEmbeddingForText(text4, options);
|
|
2958
3106
|
};
|
|
2959
3107
|
|
|
2960
3108
|
// src/react/useMemoryStorage.ts
|
|
@@ -3506,118 +3654,26 @@ function useMemoryStorage(options) {
|
|
|
3506
3654
|
};
|
|
3507
3655
|
}
|
|
3508
3656
|
|
|
3509
|
-
// src/
|
|
3510
|
-
var
|
|
3511
|
-
|
|
3657
|
+
// src/react/useSettings.ts
|
|
3658
|
+
var import_react4 = require("react");
|
|
3659
|
+
|
|
3660
|
+
// src/lib/db/settings/schema.ts
|
|
3661
|
+
var import_watermelondb9 = require("@nozbe/watermelondb");
|
|
3662
|
+
var settingsStorageSchema = (0, import_watermelondb9.appSchema)({
|
|
3512
3663
|
version: 1,
|
|
3513
3664
|
tables: [
|
|
3514
|
-
(0,
|
|
3515
|
-
name: "
|
|
3665
|
+
(0, import_watermelondb9.tableSchema)({
|
|
3666
|
+
name: "modelPreferences",
|
|
3516
3667
|
columns: [
|
|
3517
|
-
|
|
3518
|
-
{ name: "
|
|
3519
|
-
// 'identity' | 'preference' | 'project' | 'skill' | 'constraint'
|
|
3520
|
-
// Hierarchical key structure
|
|
3521
|
-
{ name: "namespace", type: "string", isIndexed: true },
|
|
3522
|
-
{ name: "key", type: "string", isIndexed: true },
|
|
3523
|
-
{ name: "value", type: "string" },
|
|
3524
|
-
// Evidence and confidence
|
|
3525
|
-
{ name: "raw_evidence", type: "string" },
|
|
3526
|
-
{ name: "confidence", type: "number" },
|
|
3527
|
-
{ name: "pii", type: "boolean", isIndexed: true },
|
|
3528
|
-
// Composite keys for efficient lookups
|
|
3529
|
-
{ name: "composite_key", type: "string", isIndexed: true },
|
|
3530
|
-
// namespace:key
|
|
3531
|
-
{ name: "unique_key", type: "string", isIndexed: true },
|
|
3532
|
-
// namespace:key:value
|
|
3533
|
-
// Timestamps
|
|
3534
|
-
{ name: "created_at", type: "number", isIndexed: true },
|
|
3535
|
-
{ name: "updated_at", type: "number" },
|
|
3536
|
-
// Vector embeddings for semantic search
|
|
3537
|
-
{ name: "embedding", type: "string", isOptional: true },
|
|
3538
|
-
// JSON stringified number[]
|
|
3539
|
-
{ name: "embedding_model", type: "string", isOptional: true },
|
|
3540
|
-
// Soft delete flag
|
|
3541
|
-
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
3668
|
+
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
3669
|
+
{ name: "models", type: "string", isOptional: true }
|
|
3542
3670
|
]
|
|
3543
3671
|
})
|
|
3544
3672
|
]
|
|
3545
3673
|
});
|
|
3546
3674
|
|
|
3547
|
-
// src/lib/
|
|
3548
|
-
var
|
|
3549
|
-
var Memory = class extends import_watermelondb6.Model {
|
|
3550
|
-
/** Memory type classification */
|
|
3551
|
-
get type() {
|
|
3552
|
-
return this._getRaw("type");
|
|
3553
|
-
}
|
|
3554
|
-
/** Namespace for grouping related memories */
|
|
3555
|
-
get namespace() {
|
|
3556
|
-
return this._getRaw("namespace");
|
|
3557
|
-
}
|
|
3558
|
-
/** Key within the namespace */
|
|
3559
|
-
get key() {
|
|
3560
|
-
return this._getRaw("key");
|
|
3561
|
-
}
|
|
3562
|
-
/** The memory value/content */
|
|
3563
|
-
get value() {
|
|
3564
|
-
return this._getRaw("value");
|
|
3565
|
-
}
|
|
3566
|
-
/** Raw evidence from which this memory was extracted */
|
|
3567
|
-
get rawEvidence() {
|
|
3568
|
-
return this._getRaw("raw_evidence");
|
|
3569
|
-
}
|
|
3570
|
-
/** Confidence score (0-1) */
|
|
3571
|
-
get confidence() {
|
|
3572
|
-
return this._getRaw("confidence");
|
|
3573
|
-
}
|
|
3574
|
-
/** Whether this memory contains PII */
|
|
3575
|
-
get pii() {
|
|
3576
|
-
return this._getRaw("pii");
|
|
3577
|
-
}
|
|
3578
|
-
/** Composite key (namespace:key) for efficient lookups */
|
|
3579
|
-
get compositeKey() {
|
|
3580
|
-
return this._getRaw("composite_key");
|
|
3581
|
-
}
|
|
3582
|
-
/** Unique key (namespace:key:value) for deduplication */
|
|
3583
|
-
get uniqueKey() {
|
|
3584
|
-
return this._getRaw("unique_key");
|
|
3585
|
-
}
|
|
3586
|
-
/** Created timestamp */
|
|
3587
|
-
get createdAt() {
|
|
3588
|
-
return new Date(this._getRaw("created_at"));
|
|
3589
|
-
}
|
|
3590
|
-
/** Updated timestamp */
|
|
3591
|
-
get updatedAt() {
|
|
3592
|
-
return new Date(this._getRaw("updated_at"));
|
|
3593
|
-
}
|
|
3594
|
-
/** Embedding vector for semantic search */
|
|
3595
|
-
get embedding() {
|
|
3596
|
-
const raw = this._getRaw("embedding");
|
|
3597
|
-
if (!raw) return void 0;
|
|
3598
|
-
try {
|
|
3599
|
-
return JSON.parse(raw);
|
|
3600
|
-
} catch {
|
|
3601
|
-
return void 0;
|
|
3602
|
-
}
|
|
3603
|
-
}
|
|
3604
|
-
/** Model used to generate embedding */
|
|
3605
|
-
get embeddingModel() {
|
|
3606
|
-
const value = this._getRaw("embedding_model");
|
|
3607
|
-
return value ? value : void 0;
|
|
3608
|
-
}
|
|
3609
|
-
/** Soft delete flag */
|
|
3610
|
-
get isDeleted() {
|
|
3611
|
-
return this._getRaw("is_deleted");
|
|
3612
|
-
}
|
|
3613
|
-
};
|
|
3614
|
-
Memory.table = "memories";
|
|
3615
|
-
|
|
3616
|
-
// src/react/useSettings.ts
|
|
3617
|
-
var import_react4 = require("react");
|
|
3618
|
-
|
|
3619
|
-
// src/lib/settingsStorage/operations.ts
|
|
3620
|
-
var import_watermelondb7 = require("@nozbe/watermelondb");
|
|
3675
|
+
// src/lib/db/settings/operations.ts
|
|
3676
|
+
var import_watermelondb10 = require("@nozbe/watermelondb");
|
|
3621
3677
|
function modelPreferenceToStored(preference) {
|
|
3622
3678
|
return {
|
|
3623
3679
|
uniqueId: preference.id,
|
|
@@ -3626,12 +3682,12 @@ function modelPreferenceToStored(preference) {
|
|
|
3626
3682
|
};
|
|
3627
3683
|
}
|
|
3628
3684
|
async function getModelPreferenceOp(ctx, walletAddress) {
|
|
3629
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
3685
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb10.Q.where("wallet_address", walletAddress)).fetch();
|
|
3630
3686
|
return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
|
|
3631
3687
|
}
|
|
3632
3688
|
async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
3633
3689
|
const result = await ctx.database.write(async () => {
|
|
3634
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
3690
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb10.Q.where("wallet_address", walletAddress)).fetch();
|
|
3635
3691
|
if (results.length > 0) {
|
|
3636
3692
|
const preference = results[0];
|
|
3637
3693
|
await preference.update((pref) => {
|
|
@@ -3649,7 +3705,7 @@ async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
|
3649
3705
|
return modelPreferenceToStored(result);
|
|
3650
3706
|
}
|
|
3651
3707
|
async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
3652
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
3708
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb10.Q.where("wallet_address", walletAddress)).fetch();
|
|
3653
3709
|
if (results.length === 0) return false;
|
|
3654
3710
|
await ctx.database.write(async () => {
|
|
3655
3711
|
await results[0].destroyPermanently();
|
|
@@ -3754,37 +3810,6 @@ function useSettings(options) {
|
|
|
3754
3810
|
};
|
|
3755
3811
|
}
|
|
3756
3812
|
|
|
3757
|
-
// src/lib/settingsStorage/schema.ts
|
|
3758
|
-
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
3759
|
-
var settingsStorageSchema = (0, import_watermelondb8.appSchema)({
|
|
3760
|
-
version: 1,
|
|
3761
|
-
tables: [
|
|
3762
|
-
(0, import_watermelondb8.tableSchema)({
|
|
3763
|
-
name: "modelPreferences",
|
|
3764
|
-
columns: [
|
|
3765
|
-
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
3766
|
-
{ name: "models", type: "string", isOptional: true }
|
|
3767
|
-
// stored as JSON stringified ModelPreference[]
|
|
3768
|
-
]
|
|
3769
|
-
})
|
|
3770
|
-
]
|
|
3771
|
-
});
|
|
3772
|
-
|
|
3773
|
-
// src/lib/settingsStorage/models.ts
|
|
3774
|
-
var import_watermelondb9 = require("@nozbe/watermelondb");
|
|
3775
|
-
var ModelPreference = class extends import_watermelondb9.Model {
|
|
3776
|
-
/** User's wallet address */
|
|
3777
|
-
get walletAddress() {
|
|
3778
|
-
return this._getRaw("wallet_address");
|
|
3779
|
-
}
|
|
3780
|
-
/** Preferred model identifier */
|
|
3781
|
-
get models() {
|
|
3782
|
-
const value = this._getRaw("models");
|
|
3783
|
-
return value ? value : void 0;
|
|
3784
|
-
}
|
|
3785
|
-
};
|
|
3786
|
-
ModelPreference.table = "modelPreferences";
|
|
3787
|
-
|
|
3788
3813
|
// src/react/usePdf.ts
|
|
3789
3814
|
var import_react5 = require("react");
|
|
3790
3815
|
|
|
@@ -3855,13 +3880,13 @@ function usePdf() {
|
|
|
3855
3880
|
const contexts = await Promise.all(
|
|
3856
3881
|
pdfFiles.map(async (file) => {
|
|
3857
3882
|
try {
|
|
3858
|
-
const
|
|
3859
|
-
if (!
|
|
3883
|
+
const text4 = await extractTextFromPdf(file.url);
|
|
3884
|
+
if (!text4.trim()) {
|
|
3860
3885
|
console.warn(`No text found in PDF ${file.filename}`);
|
|
3861
3886
|
return null;
|
|
3862
3887
|
}
|
|
3863
3888
|
return `[Context from PDF attachment ${file.filename}]:
|
|
3864
|
-
${
|
|
3889
|
+
${text4}`;
|
|
3865
3890
|
} catch (err) {
|
|
3866
3891
|
console.error(`Failed to process PDF ${file.filename}:`, err);
|
|
3867
3892
|
return null;
|
|
@@ -3941,15 +3966,15 @@ function useOCR() {
|
|
|
3941
3966
|
const result = await import_tesseract.default.recognize(image, language);
|
|
3942
3967
|
pageTexts.push(result.data.text);
|
|
3943
3968
|
}
|
|
3944
|
-
const
|
|
3945
|
-
if (!
|
|
3969
|
+
const text4 = pageTexts.join("\n\n");
|
|
3970
|
+
if (!text4.trim()) {
|
|
3946
3971
|
console.warn(
|
|
3947
3972
|
`No text found in OCR source ${filename || "unknown"}`
|
|
3948
3973
|
);
|
|
3949
3974
|
return null;
|
|
3950
3975
|
}
|
|
3951
3976
|
return `[Context from OCR attachment ${filename || "unknown"}]:
|
|
3952
|
-
${
|
|
3977
|
+
${text4}`;
|
|
3953
3978
|
} catch (err) {
|
|
3954
3979
|
console.error(
|
|
3955
3980
|
`Failed to process OCR for ${file.filename || "unknown"}:`,
|
|
@@ -4439,7 +4464,10 @@ async function pushConversationToDropbox(database, conversationId, userAddress,
|
|
|
4439
4464
|
}
|
|
4440
4465
|
}
|
|
4441
4466
|
}
|
|
4442
|
-
const exportResult = await deps.exportConversation(
|
|
4467
|
+
const exportResult = await deps.exportConversation(
|
|
4468
|
+
conversationId,
|
|
4469
|
+
userAddress
|
|
4470
|
+
);
|
|
4443
4471
|
if (!exportResult.success || !exportResult.blob) {
|
|
4444
4472
|
return "failed";
|
|
4445
4473
|
}
|
|
@@ -4449,7 +4477,15 @@ async function pushConversationToDropbox(database, conversationId, userAddress,
|
|
|
4449
4477
|
if (isAuthError(err) && !_retried) {
|
|
4450
4478
|
try {
|
|
4451
4479
|
const newToken = await deps.requestDropboxAccess();
|
|
4452
|
-
return pushConversationToDropbox(
|
|
4480
|
+
return pushConversationToDropbox(
|
|
4481
|
+
database,
|
|
4482
|
+
conversationId,
|
|
4483
|
+
userAddress,
|
|
4484
|
+
newToken,
|
|
4485
|
+
deps,
|
|
4486
|
+
backupFolder,
|
|
4487
|
+
true
|
|
4488
|
+
);
|
|
4453
4489
|
} catch {
|
|
4454
4490
|
return "failed";
|
|
4455
4491
|
}
|
|
@@ -4489,9 +4525,17 @@ async function performDropboxImport(userAddress, token, deps, onProgress, backup
|
|
|
4489
4525
|
await deps.requestEncryptionKey(userAddress);
|
|
4490
4526
|
const remoteFiles = await listDropboxFiles(token, backupFolder);
|
|
4491
4527
|
if (remoteFiles.length === 0) {
|
|
4492
|
-
return {
|
|
4528
|
+
return {
|
|
4529
|
+
success: false,
|
|
4530
|
+
restored: 0,
|
|
4531
|
+
failed: 0,
|
|
4532
|
+
total: 0,
|
|
4533
|
+
noBackupsFound: true
|
|
4534
|
+
};
|
|
4493
4535
|
}
|
|
4494
|
-
const jsonFiles = remoteFiles.filter(
|
|
4536
|
+
const jsonFiles = remoteFiles.filter(
|
|
4537
|
+
(file) => file.name.endsWith(".json")
|
|
4538
|
+
);
|
|
4495
4539
|
const total = jsonFiles.length;
|
|
4496
4540
|
let restored = 0;
|
|
4497
4541
|
let failed = 0;
|
|
@@ -4950,7 +4994,12 @@ async function getConversationsFolder(token, requestDriveAccess, rootFolder, sub
|
|
|
4950
4994
|
async function pushConversationToDrive(database, conversationId, userAddress, token, deps, rootFolder = DEFAULT_ROOT_FOLDER, subfolder = DEFAULT_CONVERSATIONS_FOLDER, _retried = false) {
|
|
4951
4995
|
try {
|
|
4952
4996
|
await deps.requestEncryptionKey(userAddress);
|
|
4953
|
-
const folderResult = await getConversationsFolder(
|
|
4997
|
+
const folderResult = await getConversationsFolder(
|
|
4998
|
+
token,
|
|
4999
|
+
deps.requestDriveAccess,
|
|
5000
|
+
rootFolder,
|
|
5001
|
+
subfolder
|
|
5002
|
+
);
|
|
4954
5003
|
if (!folderResult) return "failed";
|
|
4955
5004
|
const { folderId, token: activeToken } = folderResult;
|
|
4956
5005
|
const filename = `${conversationId}.json`;
|
|
@@ -4968,21 +5017,38 @@ async function pushConversationToDrive(database, conversationId, userAddress, to
|
|
|
4968
5017
|
}
|
|
4969
5018
|
}
|
|
4970
5019
|
}
|
|
4971
|
-
const exportResult = await deps.exportConversation(
|
|
5020
|
+
const exportResult = await deps.exportConversation(
|
|
5021
|
+
conversationId,
|
|
5022
|
+
userAddress
|
|
5023
|
+
);
|
|
4972
5024
|
if (!exportResult.success || !exportResult.blob) {
|
|
4973
5025
|
return "failed";
|
|
4974
5026
|
}
|
|
4975
5027
|
if (existingFile) {
|
|
4976
5028
|
await updateDriveFile(activeToken, existingFile.id, exportResult.blob);
|
|
4977
5029
|
} else {
|
|
4978
|
-
await uploadFileToDrive(
|
|
5030
|
+
await uploadFileToDrive(
|
|
5031
|
+
activeToken,
|
|
5032
|
+
folderId,
|
|
5033
|
+
exportResult.blob,
|
|
5034
|
+
filename
|
|
5035
|
+
);
|
|
4979
5036
|
}
|
|
4980
5037
|
return "uploaded";
|
|
4981
5038
|
} catch (err) {
|
|
4982
5039
|
if (isAuthError2(err) && !_retried) {
|
|
4983
5040
|
try {
|
|
4984
5041
|
const newToken = await deps.requestDriveAccess();
|
|
4985
|
-
return pushConversationToDrive(
|
|
5042
|
+
return pushConversationToDrive(
|
|
5043
|
+
database,
|
|
5044
|
+
conversationId,
|
|
5045
|
+
userAddress,
|
|
5046
|
+
newToken,
|
|
5047
|
+
deps,
|
|
5048
|
+
rootFolder,
|
|
5049
|
+
subfolder,
|
|
5050
|
+
true
|
|
5051
|
+
);
|
|
4986
5052
|
} catch {
|
|
4987
5053
|
return "failed";
|
|
4988
5054
|
}
|
|
@@ -4992,7 +5058,12 @@ async function pushConversationToDrive(database, conversationId, userAddress, to
|
|
|
4992
5058
|
}
|
|
4993
5059
|
async function performGoogleDriveExport(database, userAddress, token, deps, onProgress, rootFolder = DEFAULT_ROOT_FOLDER, subfolder = DEFAULT_CONVERSATIONS_FOLDER) {
|
|
4994
5060
|
await deps.requestEncryptionKey(userAddress);
|
|
4995
|
-
const folderResult = await getConversationsFolder(
|
|
5061
|
+
const folderResult = await getConversationsFolder(
|
|
5062
|
+
token,
|
|
5063
|
+
deps.requestDriveAccess,
|
|
5064
|
+
rootFolder,
|
|
5065
|
+
subfolder
|
|
5066
|
+
);
|
|
4996
5067
|
if (!folderResult) {
|
|
4997
5068
|
return { success: false, uploaded: 0, skipped: 0, total: 0 };
|
|
4998
5069
|
}
|
|
@@ -5026,16 +5097,35 @@ async function performGoogleDriveExport(database, userAddress, token, deps, onPr
|
|
|
5026
5097
|
}
|
|
5027
5098
|
async function performGoogleDriveImport(userAddress, token, deps, onProgress, rootFolder = DEFAULT_ROOT_FOLDER, subfolder = DEFAULT_CONVERSATIONS_FOLDER) {
|
|
5028
5099
|
await deps.requestEncryptionKey(userAddress);
|
|
5029
|
-
const folderResult = await getConversationsFolder(
|
|
5100
|
+
const folderResult = await getConversationsFolder(
|
|
5101
|
+
token,
|
|
5102
|
+
deps.requestDriveAccess,
|
|
5103
|
+
rootFolder,
|
|
5104
|
+
subfolder
|
|
5105
|
+
);
|
|
5030
5106
|
if (!folderResult) {
|
|
5031
|
-
return {
|
|
5107
|
+
return {
|
|
5108
|
+
success: false,
|
|
5109
|
+
restored: 0,
|
|
5110
|
+
failed: 0,
|
|
5111
|
+
total: 0,
|
|
5112
|
+
noBackupsFound: true
|
|
5113
|
+
};
|
|
5032
5114
|
}
|
|
5033
5115
|
const { folderId, token: activeToken } = folderResult;
|
|
5034
5116
|
const remoteFiles = await listDriveFiles(activeToken, folderId);
|
|
5035
5117
|
if (remoteFiles.length === 0) {
|
|
5036
|
-
return {
|
|
5118
|
+
return {
|
|
5119
|
+
success: false,
|
|
5120
|
+
restored: 0,
|
|
5121
|
+
failed: 0,
|
|
5122
|
+
total: 0,
|
|
5123
|
+
noBackupsFound: true
|
|
5124
|
+
};
|
|
5037
5125
|
}
|
|
5038
|
-
const jsonFiles = remoteFiles.filter(
|
|
5126
|
+
const jsonFiles = remoteFiles.filter(
|
|
5127
|
+
(file) => file.name.endsWith(".json")
|
|
5128
|
+
);
|
|
5039
5129
|
const total = jsonFiles.length;
|
|
5040
5130
|
let restored = 0;
|
|
5041
5131
|
let failed = 0;
|
|
@@ -5179,6 +5269,9 @@ function useGoogleDriveBackup(options) {
|
|
|
5179
5269
|
hasEncryptionKey,
|
|
5180
5270
|
memoryStorageSchema,
|
|
5181
5271
|
requestEncryptionKey,
|
|
5272
|
+
sdkMigrations,
|
|
5273
|
+
sdkModelClasses,
|
|
5274
|
+
sdkSchema,
|
|
5182
5275
|
selectTool,
|
|
5183
5276
|
settingsStorageSchema,
|
|
5184
5277
|
storeDropboxToken,
|