@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/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 = {};
|
|
@@ -1068,11 +1076,11 @@ async function generateLocalChatCompletion(messages, options = {}) {
|
|
|
1068
1076
|
});
|
|
1069
1077
|
this.cb = cb;
|
|
1070
1078
|
}
|
|
1071
|
-
on_finalized_text(
|
|
1079
|
+
on_finalized_text(text4) {
|
|
1072
1080
|
if (signal?.aborted) {
|
|
1073
1081
|
throw new Error("AbortError");
|
|
1074
1082
|
}
|
|
1075
|
-
this.cb(
|
|
1083
|
+
this.cb(text4);
|
|
1076
1084
|
}
|
|
1077
1085
|
}
|
|
1078
1086
|
const streamer = onToken ? new CallbackStreamer(chatPipeline.tokenizer, onToken) : void 0;
|
|
@@ -1746,7 +1754,134 @@ function useEncryption(signMessage) {
|
|
|
1746
1754
|
// src/react/useChatStorage.ts
|
|
1747
1755
|
var import_react2 = require("react");
|
|
1748
1756
|
|
|
1749
|
-
// src/lib/
|
|
1757
|
+
// src/lib/db/chat/schema.ts
|
|
1758
|
+
var import_watermelondb = require("@nozbe/watermelondb");
|
|
1759
|
+
var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
|
|
1760
|
+
var chatStorageSchema = (0, import_watermelondb.appSchema)({
|
|
1761
|
+
version: 2,
|
|
1762
|
+
tables: [
|
|
1763
|
+
(0, import_watermelondb.tableSchema)({
|
|
1764
|
+
name: "history",
|
|
1765
|
+
columns: [
|
|
1766
|
+
{ name: "message_id", type: "number" },
|
|
1767
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
1768
|
+
{ name: "role", type: "string", isIndexed: true },
|
|
1769
|
+
{ name: "content", type: "string" },
|
|
1770
|
+
{ name: "model", type: "string", isOptional: true },
|
|
1771
|
+
{ name: "files", type: "string", isOptional: true },
|
|
1772
|
+
{ name: "created_at", type: "number", isIndexed: true },
|
|
1773
|
+
{ name: "updated_at", type: "number" },
|
|
1774
|
+
{ name: "vector", type: "string", isOptional: true },
|
|
1775
|
+
{ name: "embedding_model", type: "string", isOptional: true },
|
|
1776
|
+
{ name: "usage", type: "string", isOptional: true },
|
|
1777
|
+
{ name: "sources", type: "string", isOptional: true },
|
|
1778
|
+
{ name: "response_duration", type: "number", isOptional: true },
|
|
1779
|
+
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
1780
|
+
]
|
|
1781
|
+
}),
|
|
1782
|
+
(0, import_watermelondb.tableSchema)({
|
|
1783
|
+
name: "conversations",
|
|
1784
|
+
columns: [
|
|
1785
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
1786
|
+
{ name: "title", type: "string" },
|
|
1787
|
+
{ name: "created_at", type: "number" },
|
|
1788
|
+
{ name: "updated_at", type: "number" },
|
|
1789
|
+
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
1790
|
+
]
|
|
1791
|
+
})
|
|
1792
|
+
]
|
|
1793
|
+
});
|
|
1794
|
+
var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
|
|
1795
|
+
migrations: [
|
|
1796
|
+
{
|
|
1797
|
+
toVersion: 2,
|
|
1798
|
+
steps: [
|
|
1799
|
+
(0, import_migrations.addColumns)({
|
|
1800
|
+
table: "history",
|
|
1801
|
+
columns: [{ name: "was_stopped", type: "boolean", isOptional: true }]
|
|
1802
|
+
})
|
|
1803
|
+
]
|
|
1804
|
+
}
|
|
1805
|
+
]
|
|
1806
|
+
});
|
|
1807
|
+
|
|
1808
|
+
// src/lib/db/chat/models.ts
|
|
1809
|
+
var import_watermelondb2 = require("@nozbe/watermelondb");
|
|
1810
|
+
var import_decorators = require("@nozbe/watermelondb/decorators");
|
|
1811
|
+
var Message = class extends import_watermelondb2.Model {
|
|
1812
|
+
};
|
|
1813
|
+
Message.table = "history";
|
|
1814
|
+
Message.associations = {
|
|
1815
|
+
conversations: { type: "belongs_to", key: "conversation_id" }
|
|
1816
|
+
};
|
|
1817
|
+
__decorateClass([
|
|
1818
|
+
(0, import_decorators.field)("message_id")
|
|
1819
|
+
], Message.prototype, "messageId", 2);
|
|
1820
|
+
__decorateClass([
|
|
1821
|
+
(0, import_decorators.text)("conversation_id")
|
|
1822
|
+
], Message.prototype, "conversationId", 2);
|
|
1823
|
+
__decorateClass([
|
|
1824
|
+
(0, import_decorators.text)("role")
|
|
1825
|
+
], Message.prototype, "role", 2);
|
|
1826
|
+
__decorateClass([
|
|
1827
|
+
(0, import_decorators.text)("content")
|
|
1828
|
+
], Message.prototype, "content", 2);
|
|
1829
|
+
__decorateClass([
|
|
1830
|
+
(0, import_decorators.text)("model")
|
|
1831
|
+
], Message.prototype, "model", 2);
|
|
1832
|
+
__decorateClass([
|
|
1833
|
+
(0, import_decorators.json)("files", (json3) => json3)
|
|
1834
|
+
], Message.prototype, "files", 2);
|
|
1835
|
+
__decorateClass([
|
|
1836
|
+
(0, import_decorators.date)("created_at")
|
|
1837
|
+
], Message.prototype, "createdAt", 2);
|
|
1838
|
+
__decorateClass([
|
|
1839
|
+
(0, import_decorators.date)("updated_at")
|
|
1840
|
+
], Message.prototype, "updatedAt", 2);
|
|
1841
|
+
__decorateClass([
|
|
1842
|
+
(0, import_decorators.json)("vector", (json3) => json3)
|
|
1843
|
+
], Message.prototype, "vector", 2);
|
|
1844
|
+
__decorateClass([
|
|
1845
|
+
(0, import_decorators.text)("embedding_model")
|
|
1846
|
+
], Message.prototype, "embeddingModel", 2);
|
|
1847
|
+
__decorateClass([
|
|
1848
|
+
(0, import_decorators.json)("usage", (json3) => json3)
|
|
1849
|
+
], Message.prototype, "usage", 2);
|
|
1850
|
+
__decorateClass([
|
|
1851
|
+
(0, import_decorators.json)("sources", (json3) => json3)
|
|
1852
|
+
], Message.prototype, "sources", 2);
|
|
1853
|
+
__decorateClass([
|
|
1854
|
+
(0, import_decorators.field)("response_duration")
|
|
1855
|
+
], Message.prototype, "responseDuration", 2);
|
|
1856
|
+
__decorateClass([
|
|
1857
|
+
(0, import_decorators.field)("was_stopped")
|
|
1858
|
+
], Message.prototype, "wasStopped", 2);
|
|
1859
|
+
var Conversation = class extends import_watermelondb2.Model {
|
|
1860
|
+
};
|
|
1861
|
+
Conversation.table = "conversations";
|
|
1862
|
+
Conversation.associations = {
|
|
1863
|
+
history: { type: "has_many", foreignKey: "conversation_id" }
|
|
1864
|
+
};
|
|
1865
|
+
__decorateClass([
|
|
1866
|
+
(0, import_decorators.text)("conversation_id")
|
|
1867
|
+
], Conversation.prototype, "conversationId", 2);
|
|
1868
|
+
__decorateClass([
|
|
1869
|
+
(0, import_decorators.text)("title")
|
|
1870
|
+
], Conversation.prototype, "title", 2);
|
|
1871
|
+
__decorateClass([
|
|
1872
|
+
(0, import_decorators.date)("created_at")
|
|
1873
|
+
], Conversation.prototype, "createdAt", 2);
|
|
1874
|
+
__decorateClass([
|
|
1875
|
+
(0, import_decorators.date)("updated_at")
|
|
1876
|
+
], Conversation.prototype, "updatedAt", 2);
|
|
1877
|
+
__decorateClass([
|
|
1878
|
+
(0, import_decorators.field)("is_deleted")
|
|
1879
|
+
], Conversation.prototype, "isDeleted", 2);
|
|
1880
|
+
|
|
1881
|
+
// src/lib/db/chat/types.ts
|
|
1882
|
+
function generateConversationId() {
|
|
1883
|
+
return `conv_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
1884
|
+
}
|
|
1750
1885
|
function convertUsageToStored(usage) {
|
|
1751
1886
|
if (!usage) return void 0;
|
|
1752
1887
|
return {
|
|
@@ -1756,12 +1891,9 @@ function convertUsageToStored(usage) {
|
|
|
1756
1891
|
costMicroUsd: usage.cost_micro_usd
|
|
1757
1892
|
};
|
|
1758
1893
|
}
|
|
1759
|
-
function generateConversationId() {
|
|
1760
|
-
return `conv_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
1761
|
-
}
|
|
1762
1894
|
|
|
1763
|
-
// src/lib/
|
|
1764
|
-
var
|
|
1895
|
+
// src/lib/db/chat/operations.ts
|
|
1896
|
+
var import_watermelondb3 = require("@nozbe/watermelondb");
|
|
1765
1897
|
function messageToStored(message) {
|
|
1766
1898
|
return {
|
|
1767
1899
|
uniqueId: message.id,
|
|
@@ -1804,15 +1936,15 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
|
|
|
1804
1936
|
return conversationToStored(created);
|
|
1805
1937
|
}
|
|
1806
1938
|
async function getConversationOp(ctx, id) {
|
|
1807
|
-
const results = await ctx.conversationsCollection.query(
|
|
1939
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
1808
1940
|
return results.length > 0 ? conversationToStored(results[0]) : null;
|
|
1809
1941
|
}
|
|
1810
1942
|
async function getConversationsOp(ctx) {
|
|
1811
|
-
const results = await ctx.conversationsCollection.query(
|
|
1943
|
+
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
1944
|
return results.map(conversationToStored);
|
|
1813
1945
|
}
|
|
1814
1946
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
1815
|
-
const results = await ctx.conversationsCollection.query(
|
|
1947
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
1816
1948
|
if (results.length > 0) {
|
|
1817
1949
|
await ctx.database.write(async () => {
|
|
1818
1950
|
await results[0].update((conv) => {
|
|
@@ -1824,7 +1956,7 @@ async function updateConversationTitleOp(ctx, id, title) {
|
|
|
1824
1956
|
return false;
|
|
1825
1957
|
}
|
|
1826
1958
|
async function deleteConversationOp(ctx, id) {
|
|
1827
|
-
const results = await ctx.conversationsCollection.query(
|
|
1959
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
1828
1960
|
if (results.length > 0) {
|
|
1829
1961
|
await ctx.database.write(async () => {
|
|
1830
1962
|
await results[0].update((conv) => {
|
|
@@ -1836,14 +1968,14 @@ async function deleteConversationOp(ctx, id) {
|
|
|
1836
1968
|
return false;
|
|
1837
1969
|
}
|
|
1838
1970
|
async function getMessagesOp(ctx, convId) {
|
|
1839
|
-
const results = await ctx.messagesCollection.query(
|
|
1971
|
+
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
1972
|
return results.map(messageToStored);
|
|
1841
1973
|
}
|
|
1842
1974
|
async function getMessageCountOp(ctx, convId) {
|
|
1843
|
-
return await ctx.messagesCollection.query(
|
|
1975
|
+
return await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetchCount();
|
|
1844
1976
|
}
|
|
1845
1977
|
async function clearMessagesOp(ctx, convId) {
|
|
1846
|
-
const messages = await ctx.messagesCollection.query(
|
|
1978
|
+
const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetch();
|
|
1847
1979
|
await ctx.database.write(async () => {
|
|
1848
1980
|
for (const message of messages) {
|
|
1849
1981
|
await message.destroyPermanently();
|
|
@@ -1902,11 +2034,11 @@ function cosineSimilarity(a, b) {
|
|
|
1902
2034
|
}
|
|
1903
2035
|
async function searchMessagesOp(ctx, queryVector, options) {
|
|
1904
2036
|
const { limit = 10, minSimilarity = 0.5, conversationId } = options || {};
|
|
1905
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
2037
|
+
const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
1906
2038
|
const activeConversationIds = new Set(
|
|
1907
2039
|
activeConversations.map((c) => c.conversationId)
|
|
1908
2040
|
);
|
|
1909
|
-
const queryConditions = conversationId ? [
|
|
2041
|
+
const queryConditions = conversationId ? [import_watermelondb3.Q.where("conversation_id", conversationId)] : [];
|
|
1910
2042
|
const messages = await ctx.messagesCollection.query(...queryConditions).fetch();
|
|
1911
2043
|
const resultsWithSimilarity = [];
|
|
1912
2044
|
for (const message of messages) {
|
|
@@ -2266,191 +2398,87 @@ function useChatStorage(options) {
|
|
|
2266
2398
|
};
|
|
2267
2399
|
}
|
|
2268
2400
|
|
|
2269
|
-
// src/
|
|
2270
|
-
var
|
|
2271
|
-
var
|
|
2272
|
-
|
|
2273
|
-
|
|
2401
|
+
// src/react/useMemoryStorage.ts
|
|
2402
|
+
var import_react3 = require("react");
|
|
2403
|
+
var import_client6 = require("@reverbia/sdk");
|
|
2404
|
+
|
|
2405
|
+
// src/lib/db/memory/schema.ts
|
|
2406
|
+
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
2407
|
+
var memoryStorageSchema = (0, import_watermelondb4.appSchema)({
|
|
2408
|
+
version: 1,
|
|
2274
2409
|
tables: [
|
|
2275
|
-
(0,
|
|
2276
|
-
name: "
|
|
2410
|
+
(0, import_watermelondb4.tableSchema)({
|
|
2411
|
+
name: "memories",
|
|
2277
2412
|
columns: [
|
|
2278
|
-
{ name: "
|
|
2279
|
-
|
|
2280
|
-
{ name: "
|
|
2281
|
-
{ name: "
|
|
2282
|
-
|
|
2283
|
-
{ name: "
|
|
2284
|
-
{ name: "
|
|
2285
|
-
{ name: "
|
|
2286
|
-
|
|
2413
|
+
{ name: "type", type: "string", isIndexed: true },
|
|
2414
|
+
{ name: "namespace", type: "string", isIndexed: true },
|
|
2415
|
+
{ name: "key", type: "string", isIndexed: true },
|
|
2416
|
+
{ name: "value", type: "string" },
|
|
2417
|
+
{ name: "raw_evidence", type: "string" },
|
|
2418
|
+
{ name: "confidence", type: "number" },
|
|
2419
|
+
{ name: "pii", type: "boolean", isIndexed: true },
|
|
2420
|
+
{ name: "composite_key", type: "string", isIndexed: true },
|
|
2421
|
+
{ name: "unique_key", type: "string", isIndexed: true },
|
|
2287
2422
|
{ name: "created_at", type: "number", isIndexed: true },
|
|
2288
2423
|
{ name: "updated_at", type: "number" },
|
|
2289
|
-
{ name: "
|
|
2290
|
-
// JSON stringified number[]
|
|
2424
|
+
{ name: "embedding", type: "string", isOptional: true },
|
|
2291
2425
|
{ name: "embedding_model", type: "string", isOptional: true },
|
|
2292
|
-
{ name: "usage", type: "string", isOptional: true },
|
|
2293
|
-
// JSON stringified ChatCompletionUsage
|
|
2294
|
-
{ name: "sources", type: "string", isOptional: true },
|
|
2295
|
-
// JSON stringified SearchSource[]
|
|
2296
|
-
{ name: "response_duration", type: "number", isOptional: true },
|
|
2297
|
-
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
2298
|
-
]
|
|
2299
|
-
}),
|
|
2300
|
-
(0, import_watermelondb2.tableSchema)({
|
|
2301
|
-
name: "conversations",
|
|
2302
|
-
columns: [
|
|
2303
|
-
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
2304
|
-
{ name: "title", type: "string" },
|
|
2305
|
-
{ name: "created_at", type: "number" },
|
|
2306
|
-
{ name: "updated_at", type: "number" },
|
|
2307
2426
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
2308
2427
|
]
|
|
2309
2428
|
})
|
|
2310
2429
|
]
|
|
2311
2430
|
});
|
|
2312
|
-
var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
|
|
2313
|
-
migrations: [
|
|
2314
|
-
{
|
|
2315
|
-
toVersion: 2,
|
|
2316
|
-
steps: [
|
|
2317
|
-
(0, import_migrations.addColumns)({
|
|
2318
|
-
table: "history",
|
|
2319
|
-
columns: [
|
|
2320
|
-
{ name: "was_stopped", type: "boolean", isOptional: true }
|
|
2321
|
-
]
|
|
2322
|
-
})
|
|
2323
|
-
]
|
|
2324
|
-
}
|
|
2325
|
-
]
|
|
2326
|
-
});
|
|
2327
2431
|
|
|
2328
|
-
// src/lib/
|
|
2329
|
-
var
|
|
2330
|
-
var
|
|
2331
|
-
|
|
2332
|
-
get messageId() {
|
|
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" }
|
|
2432
|
+
// src/lib/db/memory/models.ts
|
|
2433
|
+
var import_watermelondb5 = require("@nozbe/watermelondb");
|
|
2434
|
+
var import_decorators2 = require("@nozbe/watermelondb/decorators");
|
|
2435
|
+
var Memory = class extends import_watermelondb5.Model {
|
|
2444
2436
|
};
|
|
2437
|
+
Memory.table = "memories";
|
|
2438
|
+
__decorateClass([
|
|
2439
|
+
(0, import_decorators2.text)("type")
|
|
2440
|
+
], Memory.prototype, "type", 2);
|
|
2441
|
+
__decorateClass([
|
|
2442
|
+
(0, import_decorators2.text)("namespace")
|
|
2443
|
+
], Memory.prototype, "namespace", 2);
|
|
2444
|
+
__decorateClass([
|
|
2445
|
+
(0, import_decorators2.text)("key")
|
|
2446
|
+
], Memory.prototype, "key", 2);
|
|
2447
|
+
__decorateClass([
|
|
2448
|
+
(0, import_decorators2.text)("value")
|
|
2449
|
+
], Memory.prototype, "value", 2);
|
|
2450
|
+
__decorateClass([
|
|
2451
|
+
(0, import_decorators2.text)("raw_evidence")
|
|
2452
|
+
], Memory.prototype, "rawEvidence", 2);
|
|
2453
|
+
__decorateClass([
|
|
2454
|
+
(0, import_decorators2.field)("confidence")
|
|
2455
|
+
], Memory.prototype, "confidence", 2);
|
|
2456
|
+
__decorateClass([
|
|
2457
|
+
(0, import_decorators2.field)("pii")
|
|
2458
|
+
], Memory.prototype, "pii", 2);
|
|
2459
|
+
__decorateClass([
|
|
2460
|
+
(0, import_decorators2.text)("composite_key")
|
|
2461
|
+
], Memory.prototype, "compositeKey", 2);
|
|
2462
|
+
__decorateClass([
|
|
2463
|
+
(0, import_decorators2.text)("unique_key")
|
|
2464
|
+
], Memory.prototype, "uniqueKey", 2);
|
|
2465
|
+
__decorateClass([
|
|
2466
|
+
(0, import_decorators2.date)("created_at")
|
|
2467
|
+
], Memory.prototype, "createdAt", 2);
|
|
2468
|
+
__decorateClass([
|
|
2469
|
+
(0, import_decorators2.date)("updated_at")
|
|
2470
|
+
], Memory.prototype, "updatedAt", 2);
|
|
2471
|
+
__decorateClass([
|
|
2472
|
+
(0, import_decorators2.json)("embedding", (json3) => json3)
|
|
2473
|
+
], Memory.prototype, "embedding", 2);
|
|
2474
|
+
__decorateClass([
|
|
2475
|
+
(0, import_decorators2.text)("embedding_model")
|
|
2476
|
+
], Memory.prototype, "embeddingModel", 2);
|
|
2477
|
+
__decorateClass([
|
|
2478
|
+
(0, import_decorators2.field)("is_deleted")
|
|
2479
|
+
], Memory.prototype, "isDeleted", 2);
|
|
2445
2480
|
|
|
2446
|
-
// src/
|
|
2447
|
-
var import_react3 = require("react");
|
|
2448
|
-
var import_client6 = require("@reverbia/sdk");
|
|
2449
|
-
|
|
2450
|
-
// src/lib/memoryStorage/operations.ts
|
|
2451
|
-
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
2452
|
-
|
|
2453
|
-
// src/lib/memoryStorage/types.ts
|
|
2481
|
+
// src/lib/db/memory/types.ts
|
|
2454
2482
|
function generateCompositeKey(namespace, key) {
|
|
2455
2483
|
return `${namespace}:${key}`;
|
|
2456
2484
|
}
|
|
@@ -2476,7 +2504,8 @@ function cosineSimilarity2(a, b) {
|
|
|
2476
2504
|
return dotProduct / denominator;
|
|
2477
2505
|
}
|
|
2478
2506
|
|
|
2479
|
-
// src/lib/
|
|
2507
|
+
// src/lib/db/memory/operations.ts
|
|
2508
|
+
var import_watermelondb6 = require("@nozbe/watermelondb");
|
|
2480
2509
|
function memoryToStored(memory) {
|
|
2481
2510
|
return {
|
|
2482
2511
|
uniqueId: memory.id,
|
|
@@ -2497,7 +2526,7 @@ function memoryToStored(memory) {
|
|
|
2497
2526
|
};
|
|
2498
2527
|
}
|
|
2499
2528
|
async function getAllMemoriesOp(ctx) {
|
|
2500
|
-
const results = await ctx.memoriesCollection.query(
|
|
2529
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("is_deleted", false), import_watermelondb6.Q.sortBy("created_at", import_watermelondb6.Q.desc)).fetch();
|
|
2501
2530
|
return results.map(memoryToStored);
|
|
2502
2531
|
}
|
|
2503
2532
|
async function getMemoryByIdOp(ctx, id) {
|
|
@@ -2511,18 +2540,18 @@ async function getMemoryByIdOp(ctx, id) {
|
|
|
2511
2540
|
}
|
|
2512
2541
|
async function getMemoriesByNamespaceOp(ctx, namespace) {
|
|
2513
2542
|
const results = await ctx.memoriesCollection.query(
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2543
|
+
import_watermelondb6.Q.where("namespace", namespace),
|
|
2544
|
+
import_watermelondb6.Q.where("is_deleted", false),
|
|
2545
|
+
import_watermelondb6.Q.sortBy("created_at", import_watermelondb6.Q.desc)
|
|
2517
2546
|
).fetch();
|
|
2518
2547
|
return results.map(memoryToStored);
|
|
2519
2548
|
}
|
|
2520
2549
|
async function getMemoriesByKeyOp(ctx, namespace, key) {
|
|
2521
2550
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
2522
2551
|
const results = await ctx.memoriesCollection.query(
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2552
|
+
import_watermelondb6.Q.where("composite_key", compositeKey),
|
|
2553
|
+
import_watermelondb6.Q.where("is_deleted", false),
|
|
2554
|
+
import_watermelondb6.Q.sortBy("created_at", import_watermelondb6.Q.desc)
|
|
2526
2555
|
).fetch();
|
|
2527
2556
|
return results.map(memoryToStored);
|
|
2528
2557
|
}
|
|
@@ -2530,7 +2559,7 @@ async function saveMemoryOp(ctx, opts) {
|
|
|
2530
2559
|
const compositeKey = generateCompositeKey(opts.namespace, opts.key);
|
|
2531
2560
|
const uniqueKey = generateUniqueKey(opts.namespace, opts.key, opts.value);
|
|
2532
2561
|
const result = await ctx.database.write(async () => {
|
|
2533
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2562
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("unique_key", uniqueKey)).fetch();
|
|
2534
2563
|
if (existing.length > 0) {
|
|
2535
2564
|
const existingMemory = existing[0];
|
|
2536
2565
|
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 +2632,7 @@ async function updateMemoryOp(ctx, id, updates) {
|
|
|
2603
2632
|
const newCompositeKey = generateCompositeKey(newNamespace, newKey);
|
|
2604
2633
|
const newUniqueKey = generateUniqueKey(newNamespace, newKey, newValue);
|
|
2605
2634
|
if (newUniqueKey !== memory.uniqueKey) {
|
|
2606
|
-
const existing = await ctx.memoriesCollection.query(
|
|
2635
|
+
const existing = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("unique_key", newUniqueKey), import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2607
2636
|
if (existing.length > 0) {
|
|
2608
2637
|
return { ok: false, reason: "conflict", conflictingKey: newUniqueKey };
|
|
2609
2638
|
}
|
|
@@ -2659,7 +2688,7 @@ async function deleteMemoryByIdOp(ctx, id) {
|
|
|
2659
2688
|
}
|
|
2660
2689
|
async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
2661
2690
|
const uniqueKey = generateUniqueKey(namespace, key, value);
|
|
2662
|
-
const results = await ctx.memoriesCollection.query(
|
|
2691
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("unique_key", uniqueKey)).fetch();
|
|
2663
2692
|
if (results.length > 0) {
|
|
2664
2693
|
await ctx.database.write(async () => {
|
|
2665
2694
|
await results[0].update((mem) => {
|
|
@@ -2670,7 +2699,7 @@ async function deleteMemoryOp(ctx, namespace, key, value) {
|
|
|
2670
2699
|
}
|
|
2671
2700
|
async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
2672
2701
|
const compositeKey = generateCompositeKey(namespace, key);
|
|
2673
|
-
const results = await ctx.memoriesCollection.query(
|
|
2702
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("composite_key", compositeKey), import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2674
2703
|
await ctx.database.write(async () => {
|
|
2675
2704
|
for (const memory of results) {
|
|
2676
2705
|
await memory.update((mem) => {
|
|
@@ -2680,7 +2709,7 @@ async function deleteMemoriesByKeyOp(ctx, namespace, key) {
|
|
|
2680
2709
|
});
|
|
2681
2710
|
}
|
|
2682
2711
|
async function clearAllMemoriesOp(ctx) {
|
|
2683
|
-
const results = await ctx.memoriesCollection.query(
|
|
2712
|
+
const results = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2684
2713
|
await ctx.database.write(async () => {
|
|
2685
2714
|
for (const memory of results) {
|
|
2686
2715
|
await memory.update((mem) => {
|
|
@@ -2690,7 +2719,7 @@ async function clearAllMemoriesOp(ctx) {
|
|
|
2690
2719
|
});
|
|
2691
2720
|
}
|
|
2692
2721
|
async function searchSimilarMemoriesOp(ctx, queryEmbedding, limit = 10, minSimilarity = 0.6) {
|
|
2693
|
-
const allMemories = await ctx.memoriesCollection.query(
|
|
2722
|
+
const allMemories = await ctx.memoriesCollection.query(import_watermelondb6.Q.where("is_deleted", false)).fetch();
|
|
2694
2723
|
const memoriesWithEmbeddings = allMemories.filter(
|
|
2695
2724
|
(m) => m.embedding && m.embedding.length > 0
|
|
2696
2725
|
);
|
|
@@ -2893,7 +2922,7 @@ var DEFAULT_COMPLETION_MODEL = "openai/gpt-4o";
|
|
|
2893
2922
|
|
|
2894
2923
|
// src/lib/memory/embeddings.ts
|
|
2895
2924
|
var embeddingPipeline = null;
|
|
2896
|
-
var generateEmbeddingForText = async (
|
|
2925
|
+
var generateEmbeddingForText = async (text4, options = {}) => {
|
|
2897
2926
|
const { baseUrl = BASE_URL, provider = "local" } = options;
|
|
2898
2927
|
if (provider === "api") {
|
|
2899
2928
|
const { getToken, model: model2 } = options;
|
|
@@ -2907,7 +2936,7 @@ var generateEmbeddingForText = async (text, options = {}) => {
|
|
|
2907
2936
|
const response = await postApiV1Embeddings({
|
|
2908
2937
|
baseUrl,
|
|
2909
2938
|
body: {
|
|
2910
|
-
input:
|
|
2939
|
+
input: text4,
|
|
2911
2940
|
model: model2 ?? DEFAULT_API_EMBEDDING_MODEL
|
|
2912
2941
|
},
|
|
2913
2942
|
headers: {
|
|
@@ -2933,7 +2962,7 @@ var generateEmbeddingForText = async (text, options = {}) => {
|
|
|
2933
2962
|
const { pipeline } = await import("@huggingface/transformers");
|
|
2934
2963
|
embeddingPipeline = await pipeline("feature-extraction", model);
|
|
2935
2964
|
}
|
|
2936
|
-
const output = await embeddingPipeline(
|
|
2965
|
+
const output = await embeddingPipeline(text4, {
|
|
2937
2966
|
pooling: "cls",
|
|
2938
2967
|
normalize: true
|
|
2939
2968
|
});
|
|
@@ -2947,14 +2976,14 @@ var generateEmbeddingForText = async (text, options = {}) => {
|
|
|
2947
2976
|
}
|
|
2948
2977
|
};
|
|
2949
2978
|
var generateEmbeddingForMemory = async (memory, options = {}) => {
|
|
2950
|
-
const
|
|
2979
|
+
const text4 = [
|
|
2951
2980
|
memory.rawEvidence,
|
|
2952
2981
|
memory.type,
|
|
2953
2982
|
memory.namespace,
|
|
2954
2983
|
memory.key,
|
|
2955
2984
|
memory.value
|
|
2956
2985
|
].filter(Boolean).join(" ");
|
|
2957
|
-
return generateEmbeddingForText(
|
|
2986
|
+
return generateEmbeddingForText(text4, options);
|
|
2958
2987
|
};
|
|
2959
2988
|
|
|
2960
2989
|
// src/react/useMemoryStorage.ts
|
|
@@ -3506,118 +3535,39 @@ function useMemoryStorage(options) {
|
|
|
3506
3535
|
};
|
|
3507
3536
|
}
|
|
3508
3537
|
|
|
3509
|
-
// src/
|
|
3510
|
-
var
|
|
3511
|
-
|
|
3538
|
+
// src/react/useSettings.ts
|
|
3539
|
+
var import_react4 = require("react");
|
|
3540
|
+
|
|
3541
|
+
// src/lib/db/settings/schema.ts
|
|
3542
|
+
var import_watermelondb7 = require("@nozbe/watermelondb");
|
|
3543
|
+
var settingsStorageSchema = (0, import_watermelondb7.appSchema)({
|
|
3512
3544
|
version: 1,
|
|
3513
3545
|
tables: [
|
|
3514
|
-
(0,
|
|
3515
|
-
name: "
|
|
3546
|
+
(0, import_watermelondb7.tableSchema)({
|
|
3547
|
+
name: "modelPreferences",
|
|
3516
3548
|
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 }
|
|
3549
|
+
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
3550
|
+
{ name: "models", type: "string", isOptional: true }
|
|
3542
3551
|
]
|
|
3543
3552
|
})
|
|
3544
3553
|
]
|
|
3545
3554
|
});
|
|
3546
3555
|
|
|
3547
|
-
// src/lib/
|
|
3548
|
-
var
|
|
3549
|
-
var
|
|
3550
|
-
|
|
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
|
-
}
|
|
3556
|
+
// src/lib/db/settings/models.ts
|
|
3557
|
+
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
3558
|
+
var import_decorators3 = require("@nozbe/watermelondb/decorators");
|
|
3559
|
+
var ModelPreference = class extends import_watermelondb8.Model {
|
|
3613
3560
|
};
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3561
|
+
ModelPreference.table = "modelPreferences";
|
|
3562
|
+
__decorateClass([
|
|
3563
|
+
(0, import_decorators3.text)("wallet_address")
|
|
3564
|
+
], ModelPreference.prototype, "walletAddress", 2);
|
|
3565
|
+
__decorateClass([
|
|
3566
|
+
(0, import_decorators3.text)("models")
|
|
3567
|
+
], ModelPreference.prototype, "models", 2);
|
|
3618
3568
|
|
|
3619
|
-
// src/lib/
|
|
3620
|
-
var
|
|
3569
|
+
// src/lib/db/settings/operations.ts
|
|
3570
|
+
var import_watermelondb9 = require("@nozbe/watermelondb");
|
|
3621
3571
|
function modelPreferenceToStored(preference) {
|
|
3622
3572
|
return {
|
|
3623
3573
|
uniqueId: preference.id,
|
|
@@ -3626,12 +3576,12 @@ function modelPreferenceToStored(preference) {
|
|
|
3626
3576
|
};
|
|
3627
3577
|
}
|
|
3628
3578
|
async function getModelPreferenceOp(ctx, walletAddress) {
|
|
3629
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
3579
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb9.Q.where("wallet_address", walletAddress)).fetch();
|
|
3630
3580
|
return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
|
|
3631
3581
|
}
|
|
3632
3582
|
async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
3633
3583
|
const result = await ctx.database.write(async () => {
|
|
3634
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
3584
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb9.Q.where("wallet_address", walletAddress)).fetch();
|
|
3635
3585
|
if (results.length > 0) {
|
|
3636
3586
|
const preference = results[0];
|
|
3637
3587
|
await preference.update((pref) => {
|
|
@@ -3649,7 +3599,7 @@ async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
|
3649
3599
|
return modelPreferenceToStored(result);
|
|
3650
3600
|
}
|
|
3651
3601
|
async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
3652
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
3602
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb9.Q.where("wallet_address", walletAddress)).fetch();
|
|
3653
3603
|
if (results.length === 0) return false;
|
|
3654
3604
|
await ctx.database.write(async () => {
|
|
3655
3605
|
await results[0].destroyPermanently();
|
|
@@ -3754,37 +3704,6 @@ function useSettings(options) {
|
|
|
3754
3704
|
};
|
|
3755
3705
|
}
|
|
3756
3706
|
|
|
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
3707
|
// src/react/usePdf.ts
|
|
3789
3708
|
var import_react5 = require("react");
|
|
3790
3709
|
|
|
@@ -3855,13 +3774,13 @@ function usePdf() {
|
|
|
3855
3774
|
const contexts = await Promise.all(
|
|
3856
3775
|
pdfFiles.map(async (file) => {
|
|
3857
3776
|
try {
|
|
3858
|
-
const
|
|
3859
|
-
if (!
|
|
3777
|
+
const text4 = await extractTextFromPdf(file.url);
|
|
3778
|
+
if (!text4.trim()) {
|
|
3860
3779
|
console.warn(`No text found in PDF ${file.filename}`);
|
|
3861
3780
|
return null;
|
|
3862
3781
|
}
|
|
3863
3782
|
return `[Context from PDF attachment ${file.filename}]:
|
|
3864
|
-
${
|
|
3783
|
+
${text4}`;
|
|
3865
3784
|
} catch (err) {
|
|
3866
3785
|
console.error(`Failed to process PDF ${file.filename}:`, err);
|
|
3867
3786
|
return null;
|
|
@@ -3941,15 +3860,15 @@ function useOCR() {
|
|
|
3941
3860
|
const result = await import_tesseract.default.recognize(image, language);
|
|
3942
3861
|
pageTexts.push(result.data.text);
|
|
3943
3862
|
}
|
|
3944
|
-
const
|
|
3945
|
-
if (!
|
|
3863
|
+
const text4 = pageTexts.join("\n\n");
|
|
3864
|
+
if (!text4.trim()) {
|
|
3946
3865
|
console.warn(
|
|
3947
3866
|
`No text found in OCR source ${filename || "unknown"}`
|
|
3948
3867
|
);
|
|
3949
3868
|
return null;
|
|
3950
3869
|
}
|
|
3951
3870
|
return `[Context from OCR attachment ${filename || "unknown"}]:
|
|
3952
|
-
${
|
|
3871
|
+
${text4}`;
|
|
3953
3872
|
} catch (err) {
|
|
3954
3873
|
console.error(
|
|
3955
3874
|
`Failed to process OCR for ${file.filename || "unknown"}:`,
|
|
@@ -4439,7 +4358,10 @@ async function pushConversationToDropbox(database, conversationId, userAddress,
|
|
|
4439
4358
|
}
|
|
4440
4359
|
}
|
|
4441
4360
|
}
|
|
4442
|
-
const exportResult = await deps.exportConversation(
|
|
4361
|
+
const exportResult = await deps.exportConversation(
|
|
4362
|
+
conversationId,
|
|
4363
|
+
userAddress
|
|
4364
|
+
);
|
|
4443
4365
|
if (!exportResult.success || !exportResult.blob) {
|
|
4444
4366
|
return "failed";
|
|
4445
4367
|
}
|
|
@@ -4449,7 +4371,15 @@ async function pushConversationToDropbox(database, conversationId, userAddress,
|
|
|
4449
4371
|
if (isAuthError(err) && !_retried) {
|
|
4450
4372
|
try {
|
|
4451
4373
|
const newToken = await deps.requestDropboxAccess();
|
|
4452
|
-
return pushConversationToDropbox(
|
|
4374
|
+
return pushConversationToDropbox(
|
|
4375
|
+
database,
|
|
4376
|
+
conversationId,
|
|
4377
|
+
userAddress,
|
|
4378
|
+
newToken,
|
|
4379
|
+
deps,
|
|
4380
|
+
backupFolder,
|
|
4381
|
+
true
|
|
4382
|
+
);
|
|
4453
4383
|
} catch {
|
|
4454
4384
|
return "failed";
|
|
4455
4385
|
}
|
|
@@ -4489,9 +4419,17 @@ async function performDropboxImport(userAddress, token, deps, onProgress, backup
|
|
|
4489
4419
|
await deps.requestEncryptionKey(userAddress);
|
|
4490
4420
|
const remoteFiles = await listDropboxFiles(token, backupFolder);
|
|
4491
4421
|
if (remoteFiles.length === 0) {
|
|
4492
|
-
return {
|
|
4422
|
+
return {
|
|
4423
|
+
success: false,
|
|
4424
|
+
restored: 0,
|
|
4425
|
+
failed: 0,
|
|
4426
|
+
total: 0,
|
|
4427
|
+
noBackupsFound: true
|
|
4428
|
+
};
|
|
4493
4429
|
}
|
|
4494
|
-
const jsonFiles = remoteFiles.filter(
|
|
4430
|
+
const jsonFiles = remoteFiles.filter(
|
|
4431
|
+
(file) => file.name.endsWith(".json")
|
|
4432
|
+
);
|
|
4495
4433
|
const total = jsonFiles.length;
|
|
4496
4434
|
let restored = 0;
|
|
4497
4435
|
let failed = 0;
|
|
@@ -4950,7 +4888,12 @@ async function getConversationsFolder(token, requestDriveAccess, rootFolder, sub
|
|
|
4950
4888
|
async function pushConversationToDrive(database, conversationId, userAddress, token, deps, rootFolder = DEFAULT_ROOT_FOLDER, subfolder = DEFAULT_CONVERSATIONS_FOLDER, _retried = false) {
|
|
4951
4889
|
try {
|
|
4952
4890
|
await deps.requestEncryptionKey(userAddress);
|
|
4953
|
-
const folderResult = await getConversationsFolder(
|
|
4891
|
+
const folderResult = await getConversationsFolder(
|
|
4892
|
+
token,
|
|
4893
|
+
deps.requestDriveAccess,
|
|
4894
|
+
rootFolder,
|
|
4895
|
+
subfolder
|
|
4896
|
+
);
|
|
4954
4897
|
if (!folderResult) return "failed";
|
|
4955
4898
|
const { folderId, token: activeToken } = folderResult;
|
|
4956
4899
|
const filename = `${conversationId}.json`;
|
|
@@ -4968,21 +4911,38 @@ async function pushConversationToDrive(database, conversationId, userAddress, to
|
|
|
4968
4911
|
}
|
|
4969
4912
|
}
|
|
4970
4913
|
}
|
|
4971
|
-
const exportResult = await deps.exportConversation(
|
|
4914
|
+
const exportResult = await deps.exportConversation(
|
|
4915
|
+
conversationId,
|
|
4916
|
+
userAddress
|
|
4917
|
+
);
|
|
4972
4918
|
if (!exportResult.success || !exportResult.blob) {
|
|
4973
4919
|
return "failed";
|
|
4974
4920
|
}
|
|
4975
4921
|
if (existingFile) {
|
|
4976
4922
|
await updateDriveFile(activeToken, existingFile.id, exportResult.blob);
|
|
4977
4923
|
} else {
|
|
4978
|
-
await uploadFileToDrive(
|
|
4924
|
+
await uploadFileToDrive(
|
|
4925
|
+
activeToken,
|
|
4926
|
+
folderId,
|
|
4927
|
+
exportResult.blob,
|
|
4928
|
+
filename
|
|
4929
|
+
);
|
|
4979
4930
|
}
|
|
4980
4931
|
return "uploaded";
|
|
4981
4932
|
} catch (err) {
|
|
4982
4933
|
if (isAuthError2(err) && !_retried) {
|
|
4983
4934
|
try {
|
|
4984
4935
|
const newToken = await deps.requestDriveAccess();
|
|
4985
|
-
return pushConversationToDrive(
|
|
4936
|
+
return pushConversationToDrive(
|
|
4937
|
+
database,
|
|
4938
|
+
conversationId,
|
|
4939
|
+
userAddress,
|
|
4940
|
+
newToken,
|
|
4941
|
+
deps,
|
|
4942
|
+
rootFolder,
|
|
4943
|
+
subfolder,
|
|
4944
|
+
true
|
|
4945
|
+
);
|
|
4986
4946
|
} catch {
|
|
4987
4947
|
return "failed";
|
|
4988
4948
|
}
|
|
@@ -4992,7 +4952,12 @@ async function pushConversationToDrive(database, conversationId, userAddress, to
|
|
|
4992
4952
|
}
|
|
4993
4953
|
async function performGoogleDriveExport(database, userAddress, token, deps, onProgress, rootFolder = DEFAULT_ROOT_FOLDER, subfolder = DEFAULT_CONVERSATIONS_FOLDER) {
|
|
4994
4954
|
await deps.requestEncryptionKey(userAddress);
|
|
4995
|
-
const folderResult = await getConversationsFolder(
|
|
4955
|
+
const folderResult = await getConversationsFolder(
|
|
4956
|
+
token,
|
|
4957
|
+
deps.requestDriveAccess,
|
|
4958
|
+
rootFolder,
|
|
4959
|
+
subfolder
|
|
4960
|
+
);
|
|
4996
4961
|
if (!folderResult) {
|
|
4997
4962
|
return { success: false, uploaded: 0, skipped: 0, total: 0 };
|
|
4998
4963
|
}
|
|
@@ -5026,16 +4991,35 @@ async function performGoogleDriveExport(database, userAddress, token, deps, onPr
|
|
|
5026
4991
|
}
|
|
5027
4992
|
async function performGoogleDriveImport(userAddress, token, deps, onProgress, rootFolder = DEFAULT_ROOT_FOLDER, subfolder = DEFAULT_CONVERSATIONS_FOLDER) {
|
|
5028
4993
|
await deps.requestEncryptionKey(userAddress);
|
|
5029
|
-
const folderResult = await getConversationsFolder(
|
|
4994
|
+
const folderResult = await getConversationsFolder(
|
|
4995
|
+
token,
|
|
4996
|
+
deps.requestDriveAccess,
|
|
4997
|
+
rootFolder,
|
|
4998
|
+
subfolder
|
|
4999
|
+
);
|
|
5030
5000
|
if (!folderResult) {
|
|
5031
|
-
return {
|
|
5001
|
+
return {
|
|
5002
|
+
success: false,
|
|
5003
|
+
restored: 0,
|
|
5004
|
+
failed: 0,
|
|
5005
|
+
total: 0,
|
|
5006
|
+
noBackupsFound: true
|
|
5007
|
+
};
|
|
5032
5008
|
}
|
|
5033
5009
|
const { folderId, token: activeToken } = folderResult;
|
|
5034
5010
|
const remoteFiles = await listDriveFiles(activeToken, folderId);
|
|
5035
5011
|
if (remoteFiles.length === 0) {
|
|
5036
|
-
return {
|
|
5012
|
+
return {
|
|
5013
|
+
success: false,
|
|
5014
|
+
restored: 0,
|
|
5015
|
+
failed: 0,
|
|
5016
|
+
total: 0,
|
|
5017
|
+
noBackupsFound: true
|
|
5018
|
+
};
|
|
5037
5019
|
}
|
|
5038
|
-
const jsonFiles = remoteFiles.filter(
|
|
5020
|
+
const jsonFiles = remoteFiles.filter(
|
|
5021
|
+
(file) => file.name.endsWith(".json")
|
|
5022
|
+
);
|
|
5039
5023
|
const total = jsonFiles.length;
|
|
5040
5024
|
let restored = 0;
|
|
5041
5025
|
let failed = 0;
|