@anuma/sdk 6.21.0 → 6.22.0
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/{chunk-CIMZZ7GQ.mjs → chunk-6BULYLRY.mjs} +92 -8
- package/dist/expo/index.cjs +776 -168
- package/dist/expo/index.d.mts +152 -11
- package/dist/expo/index.d.ts +152 -11
- package/dist/expo/index.mjs +531 -20
- package/dist/{react/recall-7Q3V337H.mjs → expo/recall-CUTJWQDQ.mjs} +1 -1
- package/dist/memory/context.cjs +183 -0
- package/dist/memory/context.d.mts +936 -0
- package/dist/memory/context.d.ts +936 -0
- package/dist/memory/context.mjs +157 -0
- package/dist/react/{chunk-AVYB5IXC.mjs → chunk-GPLMMMZN.mjs} +1 -1
- package/dist/react/{chunk-JRVAUZHM.mjs → chunk-K4N52PSK.mjs} +93 -9
- package/dist/react/{consolidate-URHGJT7I.mjs → consolidate-XKS6IZFC.mjs} +2 -2
- package/dist/react/index.cjs +891 -276
- package/dist/react/index.d.mts +210 -11
- package/dist/react/index.d.ts +210 -11
- package/dist/react/index.mjs +584 -71
- package/dist/{expo/recall-FQQGE6A2.mjs → react/recall-LFHIWONV.mjs} +2 -2
- package/dist/server/{chunk-4DSDATYG.mjs → chunk-FEDRFVHD.mjs} +182 -98
- package/dist/server/index.cjs +830 -222
- package/dist/server/index.d.mts +151 -7
- package/dist/server/index.d.ts +151 -7
- package/dist/server/index.mjs +524 -13
- package/dist/server/{recall-HA4UX4BB.mjs → recall-Z2WJGXOL.mjs} +1 -1
- package/dist/telemetry/index.d.mts +7 -1
- package/dist/telemetry/index.d.ts +7 -1
- package/package.json +8 -1
- package/dist/react/{chunk-WUG6GTHO.mjs → chunk-MHZB6KIX.mjs} +8 -8
package/dist/react/index.cjs
CHANGED
|
@@ -1432,6 +1432,18 @@ var init_encryption_utils = __esm({
|
|
|
1432
1432
|
}
|
|
1433
1433
|
});
|
|
1434
1434
|
|
|
1435
|
+
// src/lib/db/extractionJobs/models.ts
|
|
1436
|
+
var import_watermelondb, ExtractionJob;
|
|
1437
|
+
var init_models = __esm({
|
|
1438
|
+
"src/lib/db/extractionJobs/models.ts"() {
|
|
1439
|
+
"use strict";
|
|
1440
|
+
import_watermelondb = require("@nozbe/watermelondb");
|
|
1441
|
+
ExtractionJob = class extends import_watermelondb.Model {
|
|
1442
|
+
};
|
|
1443
|
+
ExtractionJob.table = "memory_extraction_jobs";
|
|
1444
|
+
}
|
|
1445
|
+
});
|
|
1446
|
+
|
|
1435
1447
|
// src/lib/db/chat/conversationEncryption.ts
|
|
1436
1448
|
async function encryptConversationFields(conversation, address, signMessage, embeddedWalletSigner) {
|
|
1437
1449
|
if (!address || !signMessage) {
|
|
@@ -2019,7 +2031,7 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
|
|
|
2019
2031
|
);
|
|
2020
2032
|
}
|
|
2021
2033
|
async function getConversationOp(ctx, id) {
|
|
2022
|
-
const results = await ctx.conversationsCollection.query(
|
|
2034
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
|
|
2023
2035
|
return results.length > 0 ? await conversationToStored(
|
|
2024
2036
|
results[0],
|
|
2025
2037
|
ctx.walletAddress,
|
|
@@ -2028,7 +2040,7 @@ async function getConversationOp(ctx, id) {
|
|
|
2028
2040
|
) : null;
|
|
2029
2041
|
}
|
|
2030
2042
|
async function getConversationsOp(ctx) {
|
|
2031
|
-
const results = await ctx.conversationsCollection.query(
|
|
2043
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false), import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)).unsafeFetchRaw();
|
|
2032
2044
|
return Promise.all(
|
|
2033
2045
|
results.map(
|
|
2034
2046
|
(raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -2049,33 +2061,33 @@ function conversationRawToLazyStored(raw) {
|
|
|
2049
2061
|
};
|
|
2050
2062
|
}
|
|
2051
2063
|
async function getConversationsLazyOp(ctx) {
|
|
2052
|
-
const results = await ctx.conversationsCollection.query(
|
|
2064
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false), import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)).unsafeFetchRaw();
|
|
2053
2065
|
return results.map(conversationRawToLazyStored);
|
|
2054
2066
|
}
|
|
2055
2067
|
async function getConversationsPageOp(ctx, options) {
|
|
2056
2068
|
const limit = Math.floor(options?.limit ?? 200);
|
|
2057
2069
|
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
2058
2070
|
const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
|
|
2059
|
-
const clauses = [
|
|
2071
|
+
const clauses = [import_watermelondb2.Q.where("is_deleted", false)];
|
|
2060
2072
|
if (options?.before !== void 0) {
|
|
2061
2073
|
clauses.push(
|
|
2062
|
-
exclude.size > 0 ?
|
|
2074
|
+
exclude.size > 0 ? import_watermelondb2.Q.where("created_at", import_watermelondb2.Q.lte(options.before)) : import_watermelondb2.Q.where("created_at", import_watermelondb2.Q.lt(options.before))
|
|
2063
2075
|
);
|
|
2064
2076
|
}
|
|
2065
|
-
const fetched = await ctx.conversationsCollection.query(...clauses,
|
|
2077
|
+
const fetched = await ctx.conversationsCollection.query(...clauses, import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc), import_watermelondb2.Q.take(limit + exclude.size)).unsafeFetchRaw();
|
|
2066
2078
|
const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
|
|
2067
2079
|
return results.slice(0, limit).map(conversationRawToLazyStored);
|
|
2068
2080
|
}
|
|
2069
2081
|
async function getConversationsByProjectLazyOp(ctx, projectId) {
|
|
2070
2082
|
const results = await ctx.conversationsCollection.query(
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2083
|
+
import_watermelondb2.Q.where("project_id", projectId === null ? "" : projectId),
|
|
2084
|
+
import_watermelondb2.Q.where("is_deleted", false),
|
|
2085
|
+
import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)
|
|
2074
2086
|
).unsafeFetchRaw();
|
|
2075
2087
|
return results.map(conversationRawToLazyStored);
|
|
2076
2088
|
}
|
|
2077
2089
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
2078
|
-
const results = await ctx.conversationsCollection.query(
|
|
2090
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
|
|
2079
2091
|
if (results.length > 0) {
|
|
2080
2092
|
const encryptedOpts = ctx.walletAddress && ctx.signMessage ? await encryptConversationFields(
|
|
2081
2093
|
{ title },
|
|
@@ -2094,19 +2106,21 @@ async function updateConversationTitleOp(ctx, id, title) {
|
|
|
2094
2106
|
return false;
|
|
2095
2107
|
}
|
|
2096
2108
|
async function deleteConversationOp(ctx, id) {
|
|
2097
|
-
const results = await ctx.conversationsCollection.query(
|
|
2109
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
|
|
2098
2110
|
if (results.length > 0) {
|
|
2099
2111
|
await ctx.database.write(async () => {
|
|
2100
2112
|
await results[0].update((conv) => {
|
|
2101
2113
|
conv._setRaw("is_deleted", true);
|
|
2102
2114
|
});
|
|
2115
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb2.Q.where("conversation_id", id)).fetch() : [];
|
|
2116
|
+
for (const job of jobs) await job.destroyPermanently();
|
|
2103
2117
|
});
|
|
2104
2118
|
return true;
|
|
2105
2119
|
}
|
|
2106
2120
|
return false;
|
|
2107
2121
|
}
|
|
2108
2122
|
async function updateConversationProjectOp(ctx, id, projectId) {
|
|
2109
|
-
const results = await ctx.conversationsCollection.query(
|
|
2123
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
|
|
2110
2124
|
if (results.length > 0) {
|
|
2111
2125
|
await ctx.database.write(async () => {
|
|
2112
2126
|
await results[0].update((conv) => {
|
|
@@ -2118,7 +2132,7 @@ async function updateConversationProjectOp(ctx, id, projectId) {
|
|
|
2118
2132
|
return false;
|
|
2119
2133
|
}
|
|
2120
2134
|
async function updateConversationPinnedOp(ctx, id, pinned) {
|
|
2121
|
-
const results = await ctx.conversationsCollection.query(
|
|
2135
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
|
|
2122
2136
|
if (results.length > 0) {
|
|
2123
2137
|
await ctx.database.write(async () => {
|
|
2124
2138
|
await results[0].update((conv) => {
|
|
@@ -2131,9 +2145,9 @@ async function updateConversationPinnedOp(ctx, id, pinned) {
|
|
|
2131
2145
|
}
|
|
2132
2146
|
async function getConversationsByProjectOp(ctx, projectId) {
|
|
2133
2147
|
const results = await ctx.conversationsCollection.query(
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2148
|
+
import_watermelondb2.Q.where("project_id", projectId === null ? "" : projectId),
|
|
2149
|
+
import_watermelondb2.Q.where("is_deleted", false),
|
|
2150
|
+
import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)
|
|
2137
2151
|
).unsafeFetchRaw();
|
|
2138
2152
|
return Promise.all(
|
|
2139
2153
|
results.map(
|
|
@@ -2142,7 +2156,7 @@ async function getConversationsByProjectOp(ctx, projectId) {
|
|
|
2142
2156
|
);
|
|
2143
2157
|
}
|
|
2144
2158
|
async function getMessagesOp(ctx, convId) {
|
|
2145
|
-
const results = await ctx.messagesCollection.query(
|
|
2159
|
+
const results = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId), import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.asc)).unsafeFetchRaw();
|
|
2146
2160
|
return Promise.all(
|
|
2147
2161
|
results.map(
|
|
2148
2162
|
(raw) => messageRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -2150,19 +2164,19 @@ async function getMessagesOp(ctx, convId) {
|
|
|
2150
2164
|
);
|
|
2151
2165
|
}
|
|
2152
2166
|
async function getMessageCountOp(ctx, convId) {
|
|
2153
|
-
return await ctx.messagesCollection.query(
|
|
2167
|
+
return await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId)).fetchCount();
|
|
2154
2168
|
}
|
|
2155
2169
|
async function getMessagesPageOp(ctx, convId, opts) {
|
|
2156
2170
|
const limit = Math.floor(opts.limit);
|
|
2157
2171
|
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
2158
2172
|
const exclude = new Set(opts.boundaryExcludeUniqueIds ?? []);
|
|
2159
|
-
const clauses = [
|
|
2173
|
+
const clauses = [import_watermelondb2.Q.where("conversation_id", convId)];
|
|
2160
2174
|
if (opts.beforeMessageId !== void 0) {
|
|
2161
2175
|
clauses.push(
|
|
2162
|
-
exclude.size > 0 ?
|
|
2176
|
+
exclude.size > 0 ? import_watermelondb2.Q.where("message_id", import_watermelondb2.Q.lte(opts.beforeMessageId)) : import_watermelondb2.Q.where("message_id", import_watermelondb2.Q.lt(opts.beforeMessageId))
|
|
2163
2177
|
);
|
|
2164
2178
|
}
|
|
2165
|
-
const fetched = await ctx.messagesCollection.query(...clauses,
|
|
2179
|
+
const fetched = await ctx.messagesCollection.query(...clauses, import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.desc), import_watermelondb2.Q.take(limit + exclude.size)).unsafeFetchRaw();
|
|
2166
2180
|
const results = (exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched).slice(0, limit);
|
|
2167
2181
|
results.reverse();
|
|
2168
2182
|
return Promise.all(
|
|
@@ -2174,7 +2188,7 @@ async function getMessagesPageOp(ctx, convId, opts) {
|
|
|
2174
2188
|
);
|
|
2175
2189
|
}
|
|
2176
2190
|
async function getMessageSkeletonsOp(ctx, convId) {
|
|
2177
|
-
const results = await ctx.messagesCollection.query(
|
|
2191
|
+
const results = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId), import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.asc)).unsafeFetchRaw();
|
|
2178
2192
|
const roleById = /* @__PURE__ */ new Map();
|
|
2179
2193
|
for (const raw of results) {
|
|
2180
2194
|
roleById.set(raw.id, raw.role);
|
|
@@ -2221,7 +2235,7 @@ async function getMessageSkeletonsOp(ctx, convId) {
|
|
|
2221
2235
|
return skeletons;
|
|
2222
2236
|
}
|
|
2223
2237
|
async function getToolCallEventIdsOp(ctx, convId) {
|
|
2224
|
-
const results = await ctx.messagesCollection.query(
|
|
2238
|
+
const results = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId)).unsafeFetchRaw();
|
|
2225
2239
|
const ids = /* @__PURE__ */ new Set();
|
|
2226
2240
|
for (const raw of results) {
|
|
2227
2241
|
const value = raw.tool_call_events;
|
|
@@ -2244,8 +2258,16 @@ async function getToolCallEventIdsOp(ctx, convId) {
|
|
|
2244
2258
|
return ids;
|
|
2245
2259
|
}
|
|
2246
2260
|
async function clearMessagesOp(ctx, convId) {
|
|
2247
|
-
const messages = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId)).fetch();
|
|
2248
2261
|
await ctx.database.write(async () => {
|
|
2262
|
+
const messages = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId)).fetch();
|
|
2263
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb2.Q.where("conversation_id", convId)).fetch() : [];
|
|
2264
|
+
for (const job of jobs) {
|
|
2265
|
+
await job.update((row) => {
|
|
2266
|
+
row._setRaw("message_ids", "[]");
|
|
2267
|
+
row._setRaw("watermark", null);
|
|
2268
|
+
row._setRaw("watermark_seq", null);
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2249
2271
|
for (const message of messages) {
|
|
2250
2272
|
await message.update((msg) => {
|
|
2251
2273
|
msg._setRaw("file_ids", null);
|
|
@@ -2255,6 +2277,30 @@ async function clearMessagesOp(ctx, convId) {
|
|
|
2255
2277
|
}
|
|
2256
2278
|
});
|
|
2257
2279
|
}
|
|
2280
|
+
async function deleteMessageOp(ctx, uniqueId) {
|
|
2281
|
+
let message;
|
|
2282
|
+
try {
|
|
2283
|
+
message = await ctx.messagesCollection.find(uniqueId);
|
|
2284
|
+
} catch {
|
|
2285
|
+
return null;
|
|
2286
|
+
}
|
|
2287
|
+
await ctx.database.write(async () => {
|
|
2288
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb2.Q.where("conversation_id", message.conversationId)).fetch() : [];
|
|
2289
|
+
for (const job of jobs) {
|
|
2290
|
+
const ids = JSON.parse(String(job._getRaw("message_ids")));
|
|
2291
|
+
await job.update((row) => {
|
|
2292
|
+
row._setRaw("message_ids", JSON.stringify(ids.filter((id) => id !== uniqueId)));
|
|
2293
|
+
if (row._getRaw("watermark") === uniqueId) row._setRaw("watermark", null);
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
await message.update((msg) => {
|
|
2297
|
+
msg._setRaw("file_ids", null);
|
|
2298
|
+
msg._setRaw("files", null);
|
|
2299
|
+
});
|
|
2300
|
+
await message.destroyPermanently();
|
|
2301
|
+
});
|
|
2302
|
+
return uniqueId;
|
|
2303
|
+
}
|
|
2258
2304
|
async function encryptMessageOptsIfNeeded(ctx, opts) {
|
|
2259
2305
|
return ctx.walletAddress && ctx.signMessage ? await encryptMessageFields(opts, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : opts;
|
|
2260
2306
|
}
|
|
@@ -2312,9 +2358,9 @@ async function createMessageOp(ctx, opts) {
|
|
|
2312
2358
|
}
|
|
2313
2359
|
}
|
|
2314
2360
|
const newest = await ctx.messagesCollection.query(
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2361
|
+
import_watermelondb2.Q.where("conversation_id", opts.conversationId),
|
|
2362
|
+
import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.desc),
|
|
2363
|
+
import_watermelondb2.Q.take(1)
|
|
2318
2364
|
).fetch();
|
|
2319
2365
|
const messageId = (newest[0]?.messageId ?? 0) + 1;
|
|
2320
2366
|
const encryptedOpts = await encryptMessageOptsIfNeeded(ctx, opts);
|
|
@@ -2486,12 +2532,12 @@ async function readRawJsonField(raw, column, walletAddress) {
|
|
|
2486
2532
|
}
|
|
2487
2533
|
async function searchMessagesOp(ctx, queryVector, options) {
|
|
2488
2534
|
const { limit = 10, minSimilarity = 0.5, conversationId } = options || {};
|
|
2489
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
2535
|
+
const activeConversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false)).fetch();
|
|
2490
2536
|
const activeConversationIds = new Set(
|
|
2491
2537
|
// Use _getRaw for reliable raw column access
|
|
2492
2538
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2493
2539
|
);
|
|
2494
|
-
const queryConditions = conversationId ? [
|
|
2540
|
+
const queryConditions = conversationId ? [import_watermelondb2.Q.where("conversation_id", conversationId)] : [];
|
|
2495
2541
|
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
2496
2542
|
const candidates = [];
|
|
2497
2543
|
for (const message of messages) {
|
|
@@ -2525,12 +2571,12 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2525
2571
|
embeddingModel,
|
|
2526
2572
|
chunkCache
|
|
2527
2573
|
} = options || {};
|
|
2528
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
2574
|
+
const activeConversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false)).fetch();
|
|
2529
2575
|
const activeConversationIds = new Set(
|
|
2530
2576
|
// Use _getRaw for reliable raw column access
|
|
2531
2577
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2532
2578
|
);
|
|
2533
|
-
const queryConditions = conversationId ? [
|
|
2579
|
+
const queryConditions = conversationId ? [import_watermelondb2.Q.where("conversation_id", conversationId)] : [];
|
|
2534
2580
|
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
2535
2581
|
const candidates = [];
|
|
2536
2582
|
let staleSkipped = 0;
|
|
@@ -2656,13 +2702,13 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2656
2702
|
}
|
|
2657
2703
|
async function getAllFilesOp(ctx, options) {
|
|
2658
2704
|
const { conversationId, limit } = options || {};
|
|
2659
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
2705
|
+
const activeConversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false)).fetch();
|
|
2660
2706
|
const activeConversationIds = new Set(
|
|
2661
2707
|
// Use _getRaw for reliable raw column access
|
|
2662
2708
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2663
2709
|
);
|
|
2664
|
-
const queryConditions = conversationId ? [
|
|
2665
|
-
const messages = await ctx.messagesCollection.query(...queryConditions,
|
|
2710
|
+
const queryConditions = conversationId ? [import_watermelondb2.Q.where("conversation_id", conversationId)] : [];
|
|
2711
|
+
const messages = await ctx.messagesCollection.query(...queryConditions, import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)).fetch();
|
|
2666
2712
|
const filesWithContext = [];
|
|
2667
2713
|
for (const message of messages) {
|
|
2668
2714
|
const msgConvId = String(message._getRaw("conversation_id"));
|
|
@@ -2723,17 +2769,18 @@ function makeSyntheticStoredConversation(opts, defaultTitle) {
|
|
|
2723
2769
|
isDeleted: false
|
|
2724
2770
|
};
|
|
2725
2771
|
}
|
|
2726
|
-
var
|
|
2772
|
+
var import_watermelondb2, import_uuid2;
|
|
2727
2773
|
var init_operations = __esm({
|
|
2728
2774
|
"src/lib/db/chat/operations.ts"() {
|
|
2729
2775
|
"use strict";
|
|
2730
|
-
|
|
2776
|
+
import_watermelondb2 = require("@nozbe/watermelondb");
|
|
2731
2777
|
import_uuid2 = require("uuid");
|
|
2732
2778
|
init_useEncryption();
|
|
2733
2779
|
init_logger();
|
|
2734
2780
|
init_vector();
|
|
2735
2781
|
init_vectorEncoding();
|
|
2736
2782
|
init_encryption_utils();
|
|
2783
|
+
init_models();
|
|
2737
2784
|
init_conversationEncryption();
|
|
2738
2785
|
init_encryption();
|
|
2739
2786
|
init_types2();
|
|
@@ -4912,7 +4959,7 @@ async function upsertEntitiesInWrite(ctx, entities) {
|
|
|
4912
4959
|
const unique = Array.from(kindByName.keys());
|
|
4913
4960
|
const out = /* @__PURE__ */ new Map();
|
|
4914
4961
|
if (unique.length === 0) return { entities: out, operations: [], kindBackfills: [] };
|
|
4915
|
-
const existing = await ctx.entityCollection.query(
|
|
4962
|
+
const existing = await ctx.entityCollection.query(import_watermelondb10.Q.where("canonical_name", import_watermelondb10.Q.oneOf(unique))).fetch();
|
|
4916
4963
|
const existingNames = new Set(existing.map((e) => e.canonicalName));
|
|
4917
4964
|
const kindBackfills = existing.filter((e) => {
|
|
4918
4965
|
const incoming = kindByName.get(e.canonicalName);
|
|
@@ -4942,7 +4989,7 @@ function prepareKindBackfills(backfills) {
|
|
|
4942
4989
|
}
|
|
4943
4990
|
async function findVaultRowInWrite(ctx, memoryId) {
|
|
4944
4991
|
try {
|
|
4945
|
-
const rows = await ctx.database.get("memory_vault").query(
|
|
4992
|
+
const rows = await ctx.database.get("memory_vault").query(import_watermelondb10.Q.where("id", memoryId)).fetch();
|
|
4946
4993
|
return rows[0] ?? null;
|
|
4947
4994
|
} catch {
|
|
4948
4995
|
return null;
|
|
@@ -5017,7 +5064,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
5017
5064
|
return;
|
|
5018
5065
|
}
|
|
5019
5066
|
if (entities.length === 0) return;
|
|
5020
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
5067
|
+
const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb10.Q.where("memory_id", memoryId)).fetch();
|
|
5021
5068
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
5022
5069
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
5023
5070
|
const keptIds = entities.map((e) => e.uniqueId);
|
|
@@ -5052,7 +5099,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
5052
5099
|
}
|
|
5053
5100
|
async function resolveEntitiesByIds(ctx, entityIds) {
|
|
5054
5101
|
if (entityIds.length === 0) return [];
|
|
5055
|
-
const rows = await ctx.entityCollection.query(
|
|
5102
|
+
const rows = await ctx.entityCollection.query(import_watermelondb10.Q.where("id", import_watermelondb10.Q.oneOf(Array.from(entityIds)))).fetch();
|
|
5056
5103
|
return rows.map(entityToStored);
|
|
5057
5104
|
}
|
|
5058
5105
|
function autoLinkBlocked(row) {
|
|
@@ -5087,7 +5134,7 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
5087
5134
|
kindBackfills
|
|
5088
5135
|
} = await upsertEntitiesInWrite(ctx, normalized);
|
|
5089
5136
|
entities = Array.from(byName.values());
|
|
5090
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
5137
|
+
const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb10.Q.where("memory_id", memoryId)).fetch();
|
|
5091
5138
|
const keep = new Set(entities.map((e) => e.uniqueId));
|
|
5092
5139
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
5093
5140
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
@@ -5122,17 +5169,17 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
5122
5169
|
async function findOrphanedEntities(ctx, memoryId, toDestroy) {
|
|
5123
5170
|
const candidateIds = [...new Set(toDestroy.map((l) => String(l.entityId)))];
|
|
5124
5171
|
if (candidateIds.length === 0) return [];
|
|
5125
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
5172
|
+
const links = await ctx.memoryEntityCollection.query(import_watermelondb10.Q.where("entity_id", import_watermelondb10.Q.oneOf(candidateIds))).fetch();
|
|
5126
5173
|
const stillLinked = new Set(
|
|
5127
5174
|
links.filter((l) => String(l.memoryId) !== memoryId).map((l) => String(l.entityId))
|
|
5128
5175
|
);
|
|
5129
5176
|
const orphanIds = candidateIds.filter((id) => !stillLinked.has(id));
|
|
5130
5177
|
if (orphanIds.length === 0) return [];
|
|
5131
|
-
return await ctx.entityCollection.query(
|
|
5178
|
+
return await ctx.entityCollection.query(import_watermelondb10.Q.where("id", import_watermelondb10.Q.oneOf(orphanIds))).fetch();
|
|
5132
5179
|
}
|
|
5133
5180
|
async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
5134
5181
|
if (memoryIds.length === 0) return;
|
|
5135
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
5182
|
+
const links = await ctx.memoryEntityCollection.query(import_watermelondb10.Q.where("memory_id", import_watermelondb10.Q.oneOf(Array.from(memoryIds)))).fetch();
|
|
5136
5183
|
if (links.length === 0) return;
|
|
5137
5184
|
await ctx.database.write(async () => {
|
|
5138
5185
|
await ctx.database.batch(...links.map((l) => l.prepareDestroyPermanently()));
|
|
@@ -5140,14 +5187,14 @@ async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
|
5140
5187
|
}
|
|
5141
5188
|
async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
5142
5189
|
if (!userId) return;
|
|
5143
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
5190
|
+
const links = await ctx.memoryEntityCollection.query(import_watermelondb10.Q.where("user_id", userId)).fetch();
|
|
5144
5191
|
if (links.length === 0) return;
|
|
5145
5192
|
await ctx.database.write(async () => {
|
|
5146
5193
|
await ctx.database.batch(...links.map((l) => l.prepareDestroyPermanently()));
|
|
5147
5194
|
});
|
|
5148
5195
|
}
|
|
5149
5196
|
async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
5150
|
-
const unstamped = await ctx.memoryEntityCollection.query(
|
|
5197
|
+
const unstamped = await ctx.memoryEntityCollection.query(import_watermelondb10.Q.where("user_id", null)).fetch();
|
|
5151
5198
|
if (unstamped.length === 0) return 0;
|
|
5152
5199
|
const toUpdate = [];
|
|
5153
5200
|
for (const link of unstamped) {
|
|
@@ -5171,15 +5218,15 @@ async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
|
5171
5218
|
async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
5172
5219
|
const unique = Array.from(new Set(entityNames.map(normalizeEntityName).filter((n) => n.length > 0)));
|
|
5173
5220
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
5174
|
-
const entityRows = await ctx.entityCollection.query(
|
|
5221
|
+
const entityRows = await ctx.entityCollection.query(import_watermelondb10.Q.where("canonical_name", import_watermelondb10.Q.oneOf(unique))).fetch();
|
|
5175
5222
|
if (entityRows.length === 0) return /* @__PURE__ */ new Map();
|
|
5176
5223
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
5177
|
-
const linkConditions = [
|
|
5224
|
+
const linkConditions = [import_watermelondb10.Q.where("entity_id", import_watermelondb10.Q.oneOf(entityRows.map((e) => e.id)))];
|
|
5178
5225
|
if (ctx.userId !== void 0) {
|
|
5179
5226
|
if (ctx.allowUnscopedRows) {
|
|
5180
|
-
linkConditions.push(
|
|
5227
|
+
linkConditions.push(import_watermelondb10.Q.or(import_watermelondb10.Q.where("user_id", ctx.userId), import_watermelondb10.Q.where("user_id", null)));
|
|
5181
5228
|
} else {
|
|
5182
|
-
linkConditions.push(
|
|
5229
|
+
linkConditions.push(import_watermelondb10.Q.where("user_id", ctx.userId));
|
|
5183
5230
|
}
|
|
5184
5231
|
}
|
|
5185
5232
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
@@ -5200,18 +5247,18 @@ async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
|
5200
5247
|
async function getEntitiesByMemoryIdsOp(ctx, memoryIds) {
|
|
5201
5248
|
const unique = Array.from(new Set(memoryIds.filter((id) => id.length > 0)));
|
|
5202
5249
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
5203
|
-
const linkConditions = [
|
|
5250
|
+
const linkConditions = [import_watermelondb10.Q.where("memory_id", import_watermelondb10.Q.oneOf(unique))];
|
|
5204
5251
|
if (ctx.userId !== void 0) {
|
|
5205
5252
|
if (ctx.allowUnscopedRows) {
|
|
5206
|
-
linkConditions.push(
|
|
5253
|
+
linkConditions.push(import_watermelondb10.Q.or(import_watermelondb10.Q.where("user_id", ctx.userId), import_watermelondb10.Q.where("user_id", null)));
|
|
5207
5254
|
} else {
|
|
5208
|
-
linkConditions.push(
|
|
5255
|
+
linkConditions.push(import_watermelondb10.Q.where("user_id", ctx.userId));
|
|
5209
5256
|
}
|
|
5210
5257
|
}
|
|
5211
5258
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
5212
5259
|
if (links.length === 0) return /* @__PURE__ */ new Map();
|
|
5213
5260
|
const entityIds = Array.from(new Set(links.map((l) => String(l.entityId))));
|
|
5214
|
-
const entityRows = await ctx.entityCollection.query(
|
|
5261
|
+
const entityRows = await ctx.entityCollection.query(import_watermelondb10.Q.where("id", import_watermelondb10.Q.oneOf(entityIds))).fetch();
|
|
5215
5262
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
5216
5263
|
const out = /* @__PURE__ */ new Map();
|
|
5217
5264
|
for (const link of links) {
|
|
@@ -5227,11 +5274,11 @@ async function getEntitiesByMemoryIdsOp(ctx, memoryIds) {
|
|
|
5227
5274
|
}
|
|
5228
5275
|
return out;
|
|
5229
5276
|
}
|
|
5230
|
-
var
|
|
5277
|
+
var import_watermelondb10;
|
|
5231
5278
|
var init_operations2 = __esm({
|
|
5232
5279
|
"src/lib/db/entities/operations.ts"() {
|
|
5233
5280
|
"use strict";
|
|
5234
|
-
|
|
5281
|
+
import_watermelondb10 = require("@nozbe/watermelondb");
|
|
5235
5282
|
init_types3();
|
|
5236
5283
|
}
|
|
5237
5284
|
});
|
|
@@ -5298,23 +5345,24 @@ function visibilityOrPrivate(value) {
|
|
|
5298
5345
|
function visibilityConditions(requested) {
|
|
5299
5346
|
if (!requested?.length) return [];
|
|
5300
5347
|
if (!requested.includes("private")) {
|
|
5301
|
-
return [
|
|
5348
|
+
return [import_watermelondb11.Q.where("visibility", import_watermelondb11.Q.oneOf([...requested]))];
|
|
5302
5349
|
}
|
|
5303
5350
|
const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
|
|
5304
5351
|
if (excluded.length === 0) return [];
|
|
5305
|
-
return [
|
|
5352
|
+
return [import_watermelondb11.Q.or(import_watermelondb11.Q.where("visibility", null), import_watermelondb11.Q.where("visibility", import_watermelondb11.Q.notIn(excluded)))];
|
|
5306
5353
|
}
|
|
5307
5354
|
function isOwnedByCtxUser(ctx, record) {
|
|
5308
5355
|
return ctx.userId === void 0 || record.userId === ctx.userId;
|
|
5309
5356
|
}
|
|
5310
5357
|
function baseVaultConditions(ctx, options) {
|
|
5311
5358
|
return [
|
|
5312
|
-
...options?.
|
|
5313
|
-
...options?.
|
|
5314
|
-
...options?.
|
|
5315
|
-
...options?.
|
|
5316
|
-
...
|
|
5317
|
-
...
|
|
5359
|
+
...options?.memoryIds !== void 0 ? [import_watermelondb11.Q.where("id", import_watermelondb11.Q.oneOf(options.memoryIds))] : [],
|
|
5360
|
+
...options?.includeDeleted ? [] : [import_watermelondb11.Q.where("is_deleted", false)],
|
|
5361
|
+
...options?.includeArchived ? [] : [import_watermelondb11.Q.where("archived_at", import_watermelondb11.Q.eq(null))],
|
|
5362
|
+
...options?.includeQuarantined ? [] : [import_watermelondb11.Q.where("trust_tier", import_watermelondb11.Q.notEq("quarantined"))],
|
|
5363
|
+
...options?.includeSuperseded ? [] : [import_watermelondb11.Q.where("superseded_by", null)],
|
|
5364
|
+
...ctx.userId !== void 0 ? [import_watermelondb11.Q.where("user_id", ctx.userId)] : [],
|
|
5365
|
+
...options?.since ? [import_watermelondb11.Q.where("updated_at", import_watermelondb11.Q.gt(options.since.getTime()))] : []
|
|
5318
5366
|
];
|
|
5319
5367
|
}
|
|
5320
5368
|
function normalizeTrustTier(value) {
|
|
@@ -5392,6 +5440,8 @@ async function createVaultMemoryOp(ctx, opts) {
|
|
|
5392
5440
|
ctx.embeddedWalletSigner
|
|
5393
5441
|
) : opts.content;
|
|
5394
5442
|
const created = await ctx.database.write(async () => {
|
|
5443
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
5444
|
+
throw new Error("Memory source is no longer eligible");
|
|
5395
5445
|
return ctx.vaultMemoryCollection.create((record) => {
|
|
5396
5446
|
record._setRaw("content", encryptedContent);
|
|
5397
5447
|
record._setRaw("scope", scope);
|
|
@@ -5441,6 +5491,8 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
5441
5491
|
) : opts.content;
|
|
5442
5492
|
let createdRecord = null;
|
|
5443
5493
|
await ctx.database.write(async () => {
|
|
5494
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
5495
|
+
throw new Error("Memory source is no longer eligible");
|
|
5444
5496
|
let target;
|
|
5445
5497
|
try {
|
|
5446
5498
|
target = await ctx.vaultMemoryCollection.find(targetId);
|
|
@@ -5486,11 +5538,11 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
5486
5538
|
async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
|
|
5487
5539
|
const records = await ctx.vaultMemoryCollection.query(
|
|
5488
5540
|
...baseVaultConditions(ctx),
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5541
|
+
import_watermelondb11.Q.where("event_time_start", import_watermelondb11.Q.notEq(null)),
|
|
5542
|
+
import_watermelondb11.Q.where("event_time_start", import_watermelondb11.Q.lte(windowEnd)),
|
|
5543
|
+
import_watermelondb11.Q.or(
|
|
5544
|
+
import_watermelondb11.Q.where("event_time_start", import_watermelondb11.Q.gte(windowStart)),
|
|
5545
|
+
import_watermelondb11.Q.where("event_time_kind", import_watermelondb11.Q.oneOf(["range", "ongoing"]))
|
|
5494
5546
|
)
|
|
5495
5547
|
).fetch();
|
|
5496
5548
|
const out = [];
|
|
@@ -5545,6 +5597,8 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
|
5545
5597
|
})
|
|
5546
5598
|
);
|
|
5547
5599
|
const created = await ctx.database.write(async () => {
|
|
5600
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
5601
|
+
throw new Error("Memory source is no longer eligible");
|
|
5548
5602
|
const prepared = optionsArray.map(
|
|
5549
5603
|
(opts, i) => ctx.vaultMemoryCollection.prepareCreate((record) => {
|
|
5550
5604
|
record._setRaw("content", encryptedContents[i]);
|
|
@@ -5665,12 +5719,12 @@ async function vaultMemoryRawToStored(raw, walletAddress, signMessage, embeddedW
|
|
|
5665
5719
|
async function getAllVaultMemoriesOp(ctx, options) {
|
|
5666
5720
|
const conditions = [
|
|
5667
5721
|
...baseVaultConditions(ctx, options),
|
|
5668
|
-
...options?.scopes?.length ? [
|
|
5722
|
+
...options?.scopes?.length ? [import_watermelondb11.Q.where("scope", import_watermelondb11.Q.oneOf(options.scopes))] : [],
|
|
5669
5723
|
...visibilityConditions(options?.visibility),
|
|
5670
|
-
...options?.folderId !== void 0 ? [
|
|
5671
|
-
...options?.factTypes?.length ? [
|
|
5672
|
-
|
|
5673
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
5724
|
+
...options?.folderId !== void 0 ? [import_watermelondb11.Q.where("folder_id", options.folderId)] : [],
|
|
5725
|
+
...options?.factTypes?.length ? [import_watermelondb11.Q.where("fact_type", import_watermelondb11.Q.oneOf(options.factTypes))] : [],
|
|
5726
|
+
import_watermelondb11.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb11.Q.desc),
|
|
5727
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb11.Q.take(options.limit)] : []
|
|
5674
5728
|
];
|
|
5675
5729
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
5676
5730
|
return mapInBatches(
|
|
@@ -5693,10 +5747,10 @@ function vaultMemoryRawToRankable(raw) {
|
|
|
5693
5747
|
async function getVaultRankingProjectionsOp(ctx, options) {
|
|
5694
5748
|
const conditions = [
|
|
5695
5749
|
...baseVaultConditions(ctx, options),
|
|
5696
|
-
...options?.scopes?.length ? [
|
|
5697
|
-
...options?.folderId !== void 0 ? [
|
|
5698
|
-
|
|
5699
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
5750
|
+
...options?.scopes?.length ? [import_watermelondb11.Q.where("scope", import_watermelondb11.Q.oneOf(options.scopes))] : [],
|
|
5751
|
+
...options?.folderId !== void 0 ? [import_watermelondb11.Q.where("folder_id", options.folderId)] : [],
|
|
5752
|
+
import_watermelondb11.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb11.Q.desc),
|
|
5753
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb11.Q.take(options.limit)] : []
|
|
5700
5754
|
];
|
|
5701
5755
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
5702
5756
|
return results.map(vaultMemoryRawToRankable);
|
|
@@ -5731,6 +5785,11 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
5731
5785
|
});
|
|
5732
5786
|
const clauses = [base.sql];
|
|
5733
5787
|
const args = [...base.args];
|
|
5788
|
+
if (options?.memoryIds !== void 0) {
|
|
5789
|
+
if (options.memoryIds.length === 0) return [];
|
|
5790
|
+
clauses.push(`"id" in (${options.memoryIds.map(() => "?").join(",")})`);
|
|
5791
|
+
args.push(...options.memoryIds);
|
|
5792
|
+
}
|
|
5734
5793
|
if (options?.scopes?.length) {
|
|
5735
5794
|
clauses.push(`"scope" in (${options.scopes.map(() => "?").join(",")})`);
|
|
5736
5795
|
args.push(...options.scopes);
|
|
@@ -5744,7 +5803,7 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
5744
5803
|
args.push(...options.factTypes);
|
|
5745
5804
|
}
|
|
5746
5805
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
5747
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
5806
|
+
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb11.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
5748
5807
|
return rows.map(mapRaw);
|
|
5749
5808
|
} catch (err) {
|
|
5750
5809
|
getLogger().debug(
|
|
@@ -5752,11 +5811,12 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
5752
5811
|
);
|
|
5753
5812
|
const conditions = [
|
|
5754
5813
|
...baseVaultConditions(ctx, {
|
|
5814
|
+
memoryIds: options?.memoryIds,
|
|
5755
5815
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
5756
5816
|
}),
|
|
5757
|
-
...options?.scopes?.length ? [
|
|
5758
|
-
...options?.folderId !== void 0 ? [
|
|
5759
|
-
...options?.factTypes?.length ? [
|
|
5817
|
+
...options?.scopes?.length ? [import_watermelondb11.Q.where("scope", import_watermelondb11.Q.oneOf(options.scopes))] : [],
|
|
5818
|
+
...options?.folderId !== void 0 ? [import_watermelondb11.Q.where("folder_id", options.folderId)] : [],
|
|
5819
|
+
...options?.factTypes?.length ? [import_watermelondb11.Q.where("fact_type", import_watermelondb11.Q.oneOf(options.factTypes))] : []
|
|
5760
5820
|
];
|
|
5761
5821
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
5762
5822
|
return rows.map(mapRaw);
|
|
@@ -5774,7 +5834,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
5774
5834
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
5775
5835
|
});
|
|
5776
5836
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
5777
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
5837
|
+
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb11.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
5778
5838
|
return rows.map(mapRaw);
|
|
5779
5839
|
} catch (err) {
|
|
5780
5840
|
getLogger().debug(
|
|
@@ -5786,7 +5846,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
5786
5846
|
includeArchived: options.includeArchived
|
|
5787
5847
|
}
|
|
5788
5848
|
}),
|
|
5789
|
-
|
|
5849
|
+
import_watermelondb11.Q.where("id", import_watermelondb11.Q.oneOf(ids))
|
|
5790
5850
|
).unsafeFetchRaw();
|
|
5791
5851
|
return rows.map(mapRaw);
|
|
5792
5852
|
}
|
|
@@ -5797,7 +5857,7 @@ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
|
5797
5857
|
...baseVaultConditions(ctx, {
|
|
5798
5858
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
5799
5859
|
}),
|
|
5800
|
-
|
|
5860
|
+
import_watermelondb11.Q.where("id", import_watermelondb11.Q.oneOf(ids))
|
|
5801
5861
|
];
|
|
5802
5862
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
5803
5863
|
return mapInBatches(
|
|
@@ -5822,7 +5882,7 @@ async function countActiveVaultMemoriesOp(ctx) {
|
|
|
5822
5882
|
}
|
|
5823
5883
|
async function getActiveVaultMemoryIdsOp(ctx, ids) {
|
|
5824
5884
|
if (ids.length === 0) return /* @__PURE__ */ new Set();
|
|
5825
|
-
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx),
|
|
5885
|
+
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb11.Q.where("id", import_watermelondb11.Q.oneOf(ids))).unsafeFetchRaw();
|
|
5826
5886
|
return new Set(rows.map((r) => r.id));
|
|
5827
5887
|
}
|
|
5828
5888
|
async function updateVaultMemoryOp(ctx, id, opts) {
|
|
@@ -5839,10 +5899,23 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
5839
5899
|
const record = probe;
|
|
5840
5900
|
const originalUpdatedAt = record.updatedAt.getTime();
|
|
5841
5901
|
await ctx.database.write(async () => {
|
|
5902
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
5903
|
+
throw new Error("Memory source is no longer eligible");
|
|
5842
5904
|
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
|
|
5843
5905
|
stale = true;
|
|
5844
5906
|
return;
|
|
5845
5907
|
}
|
|
5908
|
+
let observedSources = [];
|
|
5909
|
+
let replayedObservation = false;
|
|
5910
|
+
if (opts.observationSourceIds?.length) {
|
|
5911
|
+
try {
|
|
5912
|
+
const parsed = JSON.parse(record.sourceChunkIds ?? "[]");
|
|
5913
|
+
if (Array.isArray(parsed))
|
|
5914
|
+
observedSources = parsed.filter((id2) => typeof id2 === "string");
|
|
5915
|
+
} catch {
|
|
5916
|
+
}
|
|
5917
|
+
replayedObservation = opts.observationSourceIds.every((id2) => observedSources.includes(id2));
|
|
5918
|
+
}
|
|
5846
5919
|
await record.update((r) => {
|
|
5847
5920
|
r._setRaw("content", encryptedContent);
|
|
5848
5921
|
if (opts.scope !== void 0) {
|
|
@@ -5856,9 +5929,15 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
5856
5929
|
r._setRaw("embedding_model", opts.embeddingModel ?? null);
|
|
5857
5930
|
}
|
|
5858
5931
|
if (opts.sourceChunkIds !== void 0) {
|
|
5859
|
-
r._setRaw(
|
|
5932
|
+
r._setRaw(
|
|
5933
|
+
"source_chunk_ids",
|
|
5934
|
+
JSON.stringify(
|
|
5935
|
+
opts.observationSourceIds?.length ? [.../* @__PURE__ */ new Set([...observedSources, ...opts.sourceChunkIds])] : opts.sourceChunkIds
|
|
5936
|
+
)
|
|
5937
|
+
);
|
|
5860
5938
|
}
|
|
5861
|
-
if (
|
|
5939
|
+
if (replayedObservation) {
|
|
5940
|
+
} else if (opts.proofCountIncrement !== void 0) {
|
|
5862
5941
|
const current = r.proofCount ?? 1;
|
|
5863
5942
|
r._setRaw("proof_count", current + opts.proofCountIncrement);
|
|
5864
5943
|
} else if (opts.proofCount !== void 0) {
|
|
@@ -5875,7 +5954,7 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
5875
5954
|
if (opts.topicsUserManaged !== void 0) {
|
|
5876
5955
|
r._setRaw("topics_user_managed", opts.topicsUserManaged);
|
|
5877
5956
|
}
|
|
5878
|
-
if (opts.lastObservedAt !== void 0) {
|
|
5957
|
+
if (opts.lastObservedAt !== void 0 && !replayedObservation) {
|
|
5879
5958
|
r._setRaw("last_observed_at", opts.lastObservedAt);
|
|
5880
5959
|
}
|
|
5881
5960
|
if (opts.factType !== void 0) {
|
|
@@ -5930,7 +6009,7 @@ async function setMemoryEntitiesOp(ctx, memoryId, entities) {
|
|
|
5930
6009
|
() => linkMemoryEntitiesOp(entityCtx, memoryId, entities, { topicsSource: "user" })
|
|
5931
6010
|
) : [];
|
|
5932
6011
|
const keep = new Set(linked.map((e) => e.uniqueId));
|
|
5933
|
-
const existing = await entityCtx.memoryEntityCollection.query(
|
|
6012
|
+
const existing = await entityCtx.memoryEntityCollection.query(import_watermelondb11.Q.where("memory_id", memoryId)).fetch();
|
|
5934
6013
|
const staleLinks = existing.filter((l) => !keep.has(String(l.entityId)));
|
|
5935
6014
|
if (staleLinks.length === 0 && entities.length > 0) return;
|
|
5936
6015
|
const topicsWrite = await resolveMemoryTopicsWrite(
|
|
@@ -6046,6 +6125,8 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
6046
6125
|
}
|
|
6047
6126
|
let stale = false;
|
|
6048
6127
|
await ctx.database.write(async () => {
|
|
6128
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
6129
|
+
throw new Error("Memory source is no longer eligible");
|
|
6049
6130
|
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
|
|
6050
6131
|
stale = true;
|
|
6051
6132
|
return;
|
|
@@ -6066,9 +6147,9 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
6066
6147
|
}
|
|
6067
6148
|
async function getUnfiledVaultMemoriesOp(ctx) {
|
|
6068
6149
|
const conditions = [
|
|
6069
|
-
|
|
6150
|
+
import_watermelondb11.Q.where("folder_id", null),
|
|
6070
6151
|
...baseVaultConditions(ctx),
|
|
6071
|
-
|
|
6152
|
+
import_watermelondb11.Q.sortBy("created_at", import_watermelondb11.Q.desc)
|
|
6072
6153
|
];
|
|
6073
6154
|
const results = await ctx.vaultMemoryCollection.query(...conditions).fetch();
|
|
6074
6155
|
return mapInBatches(
|
|
@@ -6081,7 +6162,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
6081
6162
|
const entityIdByMemory = /* @__PURE__ */ new Map();
|
|
6082
6163
|
const allEntityIds = /* @__PURE__ */ new Set();
|
|
6083
6164
|
for (let i = 0; i < memoryIds.length; i += CHUNK) {
|
|
6084
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
6165
|
+
const links = await entityCtx.memoryEntityCollection.query(import_watermelondb11.Q.where("memory_id", import_watermelondb11.Q.oneOf(memoryIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
6085
6166
|
for (const link of links) {
|
|
6086
6167
|
const memoryId = String(link.memory_id);
|
|
6087
6168
|
const entityId = String(link.entity_id);
|
|
@@ -6097,7 +6178,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
6097
6178
|
const entityIds = Array.from(allEntityIds);
|
|
6098
6179
|
const nameById = /* @__PURE__ */ new Map();
|
|
6099
6180
|
for (let i = 0; i < entityIds.length; i += CHUNK) {
|
|
6100
|
-
const entities = await entityCtx.entityCollection.query(
|
|
6181
|
+
const entities = await entityCtx.entityCollection.query(import_watermelondb11.Q.where("id", import_watermelondb11.Q.oneOf(entityIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
6101
6182
|
for (const e of entities) {
|
|
6102
6183
|
if (typeof e.canonical_name === "string") nameById.set(String(e.id), e.canonical_name);
|
|
6103
6184
|
}
|
|
@@ -6126,7 +6207,7 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
|
|
|
6126
6207
|
if (!entityCtx) {
|
|
6127
6208
|
throw new Error("getMemoriesNeedingTopicExtractionOp requires ctx.entityCtx");
|
|
6128
6209
|
}
|
|
6129
|
-
const conditions = [...baseVaultConditions(ctx),
|
|
6210
|
+
const conditions = [...baseVaultConditions(ctx), import_watermelondb11.Q.sortBy("created_at", import_watermelondb11.Q.desc)];
|
|
6130
6211
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
6131
6212
|
const linkedNames = await linkedEntityNamesByMemory(
|
|
6132
6213
|
entityCtx,
|
|
@@ -6277,10 +6358,10 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
6277
6358
|
}
|
|
6278
6359
|
if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) continue;
|
|
6279
6360
|
if (parseTopics(record.topics) !== null) continue;
|
|
6280
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
6361
|
+
const links = await entityCtx.memoryEntityCollection.query(import_watermelondb11.Q.where("memory_id", id)).unsafeFetchRaw();
|
|
6281
6362
|
const entityIds = links.map((l) => String(l.entity_id));
|
|
6282
6363
|
if (entityIds.length === 0) continue;
|
|
6283
|
-
const entities = await entityCtx.entityCollection.query(
|
|
6364
|
+
const entities = await entityCtx.entityCollection.query(import_watermelondb11.Q.where("id", import_watermelondb11.Q.oneOf(entityIds))).fetch();
|
|
6284
6365
|
if (entities.length === 0) continue;
|
|
6285
6366
|
const source = record.topicsUserManaged ? "user" : "auto";
|
|
6286
6367
|
const write = await resolveMemoryTopicsWrite(entityCtx, id, entities, [], source);
|
|
@@ -6296,7 +6377,7 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
6296
6377
|
}
|
|
6297
6378
|
async function deleteAllVaultMemoriesForUserOp(ctx, userId) {
|
|
6298
6379
|
if (ctx.userId !== void 0 && ctx.userId !== userId) return 0;
|
|
6299
|
-
const records = await ctx.vaultMemoryCollection.query(
|
|
6380
|
+
const records = await ctx.vaultMemoryCollection.query(import_watermelondb11.Q.where("user_id", userId), import_watermelondb11.Q.where("is_deleted", false)).fetch();
|
|
6300
6381
|
if (records.length === 0) return 0;
|
|
6301
6382
|
await ctx.database.write(async () => {
|
|
6302
6383
|
const prepared = records.map(
|
|
@@ -6337,6 +6418,7 @@ async function getDecayCandidatesRawOp(ctx) {
|
|
|
6337
6418
|
eventTimeEnd: raw.event_time_end ?? null,
|
|
6338
6419
|
eventTimeKind: raw.event_time_kind ?? null,
|
|
6339
6420
|
updatedAt: raw.updated_at,
|
|
6421
|
+
lastObservedAt: raw.last_observed_at ?? null,
|
|
6340
6422
|
archivedAt: raw.archived_at ?? null,
|
|
6341
6423
|
source: raw.source ?? null,
|
|
6342
6424
|
trustTier: raw.trust_tier ?? null
|
|
@@ -6353,7 +6435,7 @@ async function archiveVaultMemoryOp(ctx, id, opts) {
|
|
|
6353
6435
|
stale = true;
|
|
6354
6436
|
return;
|
|
6355
6437
|
}
|
|
6356
|
-
if (opts?.expectedUpdatedAt !== void 0 && record.updatedAt.getTime() !== opts.expectedUpdatedAt) {
|
|
6438
|
+
if (opts?.expectedUpdatedAt !== void 0 && record.updatedAt.getTime() !== opts.expectedUpdatedAt || opts?.expectedLastObservedAt !== void 0 && (record.lastObservedAt ?? null) !== opts.expectedLastObservedAt) {
|
|
6357
6439
|
stale = true;
|
|
6358
6440
|
return;
|
|
6359
6441
|
}
|
|
@@ -6428,11 +6510,11 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding, embeddingModel)
|
|
|
6428
6510
|
return false;
|
|
6429
6511
|
}
|
|
6430
6512
|
}
|
|
6431
|
-
var
|
|
6513
|
+
var import_watermelondb11, NON_PRIVATE_VISIBILITIES, KNOWN_TRUST_TIERS, TOPICS_EXTRACTION_VERSION;
|
|
6432
6514
|
var init_operations3 = __esm({
|
|
6433
6515
|
"src/lib/db/memoryVault/operations.ts"() {
|
|
6434
6516
|
"use strict";
|
|
6435
|
-
|
|
6517
|
+
import_watermelondb11 = require("@nozbe/watermelondb");
|
|
6436
6518
|
init_logger();
|
|
6437
6519
|
init_operations2();
|
|
6438
6520
|
init_types3();
|
|
@@ -7938,7 +8020,9 @@ function dedupeBy(items, ...keys) {
|
|
|
7938
8020
|
return out;
|
|
7939
8021
|
}
|
|
7940
8022
|
async function recall(query, ctx, options = {}) {
|
|
7941
|
-
const
|
|
8023
|
+
const requestedTypes = options.types ?? ["fact"];
|
|
8024
|
+
const chunksScopeRestricted = options.memoryIds !== void 0 && requestedTypes.includes("chunk");
|
|
8025
|
+
const types = options.memoryIds !== void 0 ? requestedTypes.filter((kind) => kind === "fact") : requestedTypes;
|
|
7942
8026
|
const limit = options.limit ?? DEFAULT_LIMIT;
|
|
7943
8027
|
const usedBudget = options.budget ?? DEFAULT_BUDGET;
|
|
7944
8028
|
const flags = flagsForBudget(usedBudget);
|
|
@@ -7990,7 +8074,10 @@ async function recall(query, ctx, options = {}) {
|
|
|
7990
8074
|
if (embeddingsUnavailable) degraded.push("embeddings-unavailable");
|
|
7991
8075
|
if (graphLaneFailed) degraded.push("graph-lane-failed");
|
|
7992
8076
|
if (temporalLaneFailed) degraded.push("temporal-lane-failed");
|
|
7993
|
-
|
|
8077
|
+
if (chunksScopeRestricted) degraded.push("chunks-scope-restricted");
|
|
8078
|
+
const laneRan = types.includes("fact") && !!ctx.vaultCtx && !!ctx.vaultCache || types.includes("chunk") && !!ctx.storageCtx || // The chunk lane was wired and deliberately dropped for the scope, which
|
|
8079
|
+
// is not the "requested kinds have no store" wiring bug `no-lanes` means.
|
|
8080
|
+
chunksScopeRestricted && !!ctx.storageCtx;
|
|
7994
8081
|
const scores = admitted.map((m) => m.score);
|
|
7995
8082
|
const minScoreApplied = factResults.length > 0 ? factFloor : chunkResults.length > 0 ? chunkFloor : factFloor >= 0 ? factFloor : chunkFloor;
|
|
7996
8083
|
const diagnostics = {
|
|
@@ -8135,6 +8222,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
8135
8222
|
...options.scopes && { scopes: options.scopes },
|
|
8136
8223
|
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
8137
8224
|
...options.factTypes?.length && { factTypes: options.factTypes },
|
|
8225
|
+
...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
|
|
8138
8226
|
...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
|
|
8139
8227
|
...entityRanking.length > 0 && { entityRanking },
|
|
8140
8228
|
...temporalRanking.length > 0 && { temporalRanking }
|
|
@@ -9138,6 +9226,7 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
9138
9226
|
const scopes = searchOptions?.scopes;
|
|
9139
9227
|
const folderId = searchOptions?.folderId;
|
|
9140
9228
|
const queryOpts = {};
|
|
9229
|
+
if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
|
|
9141
9230
|
if (scopes?.length) queryOpts.scopes = scopes;
|
|
9142
9231
|
if (folderId !== void 0) queryOpts.folderId = folderId;
|
|
9143
9232
|
if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
|
|
@@ -10004,6 +10093,7 @@ __export(index_exports, {
|
|
|
10004
10093
|
HARD_DELETE_WINDOW_MS: () => HARD_DELETE_WINDOW_MS,
|
|
10005
10094
|
ICloudAuthProvider: () => ICloudAuthProvider,
|
|
10006
10095
|
INFERENCE_ID_HEADER: () => INFERENCE_ID_HEADER,
|
|
10096
|
+
INTERNAL_FLOW_MARKER: () => INTERNAL_FLOW_MARKER,
|
|
10007
10097
|
LoggerProvider: () => LoggerProvider,
|
|
10008
10098
|
MAX_HOPS: () => MAX_HOPS,
|
|
10009
10099
|
MEDIUM_TTL_MS: () => MEDIUM_TTL_MS,
|
|
@@ -10052,6 +10142,7 @@ __export(index_exports, {
|
|
|
10052
10142
|
addConversationMemoriesOp: () => addConversationMemoriesOp,
|
|
10053
10143
|
appFileToStored: () => appFileToStored,
|
|
10054
10144
|
archiveVaultMemoryOp: () => archiveVaultMemoryOp,
|
|
10145
|
+
assembleMemoryContext: () => assembleMemoryContext,
|
|
10055
10146
|
backfillMemoryEntityUserIdsOp: () => backfillMemoryEntityUserIdsOp,
|
|
10056
10147
|
backfillMemoryTopicsOp: () => backfillMemoryTopicsOp,
|
|
10057
10148
|
capHopsForDensity: () => capHopsForDensity,
|
|
@@ -10094,6 +10185,7 @@ __export(index_exports, {
|
|
|
10094
10185
|
createChunkVectorCache: () => createChunkVectorCache,
|
|
10095
10186
|
createCryptoPricePreProcessor: () => createCryptoPricePreProcessor,
|
|
10096
10187
|
createDecaySweeper: () => createDecaySweeper,
|
|
10188
|
+
createDurableAutoExtractor: () => createDurableAutoExtractor,
|
|
10097
10189
|
createGitHubTools: () => createGitHubTools,
|
|
10098
10190
|
createLlmDecayClassifier: () => createLlmDecayClassifier,
|
|
10099
10191
|
createLlmNeighborRefiner: () => createLlmNeighborRefiner,
|
|
@@ -10130,6 +10222,7 @@ __export(index_exports, {
|
|
|
10130
10222
|
deleteMediaByConversationOp: () => deleteMediaByConversationOp,
|
|
10131
10223
|
deleteMediaByMessageOp: () => deleteMediaByMessageOp,
|
|
10132
10224
|
deleteMediaOp: () => deleteMediaOp,
|
|
10225
|
+
deleteMessageOp: () => deleteMessageOp,
|
|
10133
10226
|
deleteProjectOp: () => deleteProjectOp,
|
|
10134
10227
|
deleteSavedToolOp: () => deleteSavedToolOp,
|
|
10135
10228
|
deleteVaultFolderOp: () => deleteVaultFolderOp,
|
|
@@ -10334,6 +10427,7 @@ __export(index_exports, {
|
|
|
10334
10427
|
setMemoryVisibilityOp: () => setMemoryVisibilityOp,
|
|
10335
10428
|
settingsStorageSchema: () => settingsStorageSchema,
|
|
10336
10429
|
shouldChunkMessage: () => shouldChunkMessage,
|
|
10430
|
+
shouldRecallMemory: () => shouldRecallMemory,
|
|
10337
10431
|
shouldRefreshTools: () => shouldRefreshTools,
|
|
10338
10432
|
stampTopicsExtractedAtOp: () => stampTopicsExtractedAtOp,
|
|
10339
10433
|
startGithubAuth: () => startGithubAuth,
|
|
@@ -10399,6 +10493,7 @@ __export(index_exports, {
|
|
|
10399
10493
|
verifyMemoriesForPublish: () => verifyMemoriesForPublish,
|
|
10400
10494
|
walk: () => walk,
|
|
10401
10495
|
webPlatformStorage: () => webPlatformStorage,
|
|
10496
|
+
withInternalFlowMarker: () => withInternalFlowMarker,
|
|
10402
10497
|
writeEncryptedFile: () => writeEncryptedFile
|
|
10403
10498
|
});
|
|
10404
10499
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -15130,7 +15225,7 @@ function extractSourcesFromToolCallEvents(toolCallEvents) {
|
|
|
15130
15225
|
init_clientConfig();
|
|
15131
15226
|
|
|
15132
15227
|
// src/lib/db/chat/summaryOperations.ts
|
|
15133
|
-
var
|
|
15228
|
+
var import_watermelondb3 = require("@nozbe/watermelondb");
|
|
15134
15229
|
function createSummaryContext(database) {
|
|
15135
15230
|
return {
|
|
15136
15231
|
database,
|
|
@@ -15149,14 +15244,14 @@ function modelToStored(record) {
|
|
|
15149
15244
|
};
|
|
15150
15245
|
}
|
|
15151
15246
|
async function getConversationSummaryOp(ctx, conversationId) {
|
|
15152
|
-
const results = await ctx.summariesCollection.query(
|
|
15247
|
+
const results = await ctx.summariesCollection.query(import_watermelondb3.Q.where("conversation_id", conversationId)).fetch();
|
|
15153
15248
|
if (results.length === 0) return null;
|
|
15154
15249
|
return modelToStored(results[0]);
|
|
15155
15250
|
}
|
|
15156
15251
|
async function upsertConversationSummaryOp(ctx, conversationId, summary, summarizedUpTo, tokenCount) {
|
|
15157
15252
|
let record;
|
|
15158
15253
|
await ctx.database.write(async () => {
|
|
15159
|
-
const existing = await ctx.summariesCollection.query(
|
|
15254
|
+
const existing = await ctx.summariesCollection.query(import_watermelondb3.Q.where("conversation_id", conversationId)).fetch();
|
|
15160
15255
|
if (existing.length > 0) {
|
|
15161
15256
|
record = await existing[0].update((rec) => {
|
|
15162
15257
|
rec.summary = summary;
|
|
@@ -15176,7 +15271,7 @@ async function upsertConversationSummaryOp(ctx, conversationId, summary, summari
|
|
|
15176
15271
|
}
|
|
15177
15272
|
async function deleteConversationSummaryOp(ctx, conversationId) {
|
|
15178
15273
|
await ctx.database.write(async () => {
|
|
15179
|
-
const existing = await ctx.summariesCollection.query(
|
|
15274
|
+
const existing = await ctx.summariesCollection.query(import_watermelondb3.Q.where("conversation_id", conversationId)).fetch();
|
|
15180
15275
|
for (const record of existing) {
|
|
15181
15276
|
await record.destroyPermanently();
|
|
15182
15277
|
}
|
|
@@ -15668,9 +15763,9 @@ async function decryptConversationTitle(encryptedTitle, address) {
|
|
|
15668
15763
|
}
|
|
15669
15764
|
|
|
15670
15765
|
// src/lib/db/chat/models.ts
|
|
15671
|
-
var
|
|
15766
|
+
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
15672
15767
|
var import_decorators = require("@nozbe/watermelondb/decorators");
|
|
15673
|
-
var Message = class extends
|
|
15768
|
+
var Message = class extends import_watermelondb4.Model {
|
|
15674
15769
|
};
|
|
15675
15770
|
Message.table = "history";
|
|
15676
15771
|
Message.associations = {
|
|
@@ -15749,7 +15844,7 @@ __decorateClass([
|
|
|
15749
15844
|
__decorateClass([
|
|
15750
15845
|
(0, import_decorators.text)("origin")
|
|
15751
15846
|
], Message.prototype, "origin", 2);
|
|
15752
|
-
var Conversation = class extends
|
|
15847
|
+
var Conversation = class extends import_watermelondb4.Model {
|
|
15753
15848
|
};
|
|
15754
15849
|
Conversation.table = "conversations";
|
|
15755
15850
|
Conversation.associations = {
|
|
@@ -15777,7 +15872,7 @@ __decorateClass([
|
|
|
15777
15872
|
__decorateClass([
|
|
15778
15873
|
(0, import_decorators.date)("pinned_at")
|
|
15779
15874
|
], Conversation.prototype, "pinnedAt", 2);
|
|
15780
|
-
var ConversationSummary = class extends
|
|
15875
|
+
var ConversationSummary = class extends import_watermelondb4.Model {
|
|
15781
15876
|
};
|
|
15782
15877
|
ConversationSummary.table = "conversation_summaries";
|
|
15783
15878
|
ConversationSummary.associations = {
|
|
@@ -15806,12 +15901,12 @@ __decorateClass([
|
|
|
15806
15901
|
init_operations();
|
|
15807
15902
|
|
|
15808
15903
|
// src/lib/db/chat/schema.ts
|
|
15809
|
-
var
|
|
15904
|
+
var import_watermelondb5 = require("@nozbe/watermelondb");
|
|
15810
15905
|
var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
|
|
15811
|
-
var chatStorageSchema = (0,
|
|
15906
|
+
var chatStorageSchema = (0, import_watermelondb5.appSchema)({
|
|
15812
15907
|
version: 7,
|
|
15813
15908
|
tables: [
|
|
15814
|
-
(0,
|
|
15909
|
+
(0, import_watermelondb5.tableSchema)({
|
|
15815
15910
|
name: "history",
|
|
15816
15911
|
columns: [
|
|
15817
15912
|
{ name: "message_id", type: "number" },
|
|
@@ -15838,7 +15933,7 @@ var chatStorageSchema = (0, import_watermelondb4.appSchema)({
|
|
|
15838
15933
|
// Reasoning/thinking content
|
|
15839
15934
|
]
|
|
15840
15935
|
}),
|
|
15841
|
-
(0,
|
|
15936
|
+
(0, import_watermelondb5.tableSchema)({
|
|
15842
15937
|
name: "conversations",
|
|
15843
15938
|
columns: [
|
|
15844
15939
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -15935,9 +16030,9 @@ function maskScopedEmbeddingCache(cache, masked) {
|
|
|
15935
16030
|
}
|
|
15936
16031
|
|
|
15937
16032
|
// src/lib/db/media/models.ts
|
|
15938
|
-
var
|
|
16033
|
+
var import_watermelondb6 = require("@nozbe/watermelondb");
|
|
15939
16034
|
var import_decorators2 = require("@nozbe/watermelondb/decorators");
|
|
15940
|
-
var Media = class extends
|
|
16035
|
+
var Media = class extends import_watermelondb6.Model {
|
|
15941
16036
|
};
|
|
15942
16037
|
Media.table = "media";
|
|
15943
16038
|
Media.associations = {
|
|
@@ -16021,7 +16116,7 @@ function isSupportedMediaType(mimeType) {
|
|
|
16021
16116
|
}
|
|
16022
16117
|
|
|
16023
16118
|
// src/lib/db/media/operations.ts
|
|
16024
|
-
var
|
|
16119
|
+
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
16025
16120
|
init_logger();
|
|
16026
16121
|
|
|
16027
16122
|
// src/lib/storage/mcpImages.ts
|
|
@@ -16384,7 +16479,7 @@ function isR2UrlExpired(sourceUrl, createdAt) {
|
|
|
16384
16479
|
}
|
|
16385
16480
|
|
|
16386
16481
|
// src/lib/storage/WatermelonChatStorageAdapter.ts
|
|
16387
|
-
var
|
|
16482
|
+
var import_watermelondb7 = require("@nozbe/watermelondb");
|
|
16388
16483
|
init_operations();
|
|
16389
16484
|
var WatermelonChatStorageAdapter = class {
|
|
16390
16485
|
constructor(options) {
|
|
@@ -16426,10 +16521,10 @@ var WatermelonChatStorageAdapter = class {
|
|
|
16426
16521
|
}
|
|
16427
16522
|
observeConversations(options) {
|
|
16428
16523
|
const conditions = options?.projectId !== void 0 ? [
|
|
16429
|
-
|
|
16430
|
-
|
|
16431
|
-
|
|
16432
|
-
] : [
|
|
16524
|
+
import_watermelondb7.Q.where("project_id", options.projectId === null ? "" : options.projectId),
|
|
16525
|
+
import_watermelondb7.Q.where("is_deleted", false),
|
|
16526
|
+
import_watermelondb7.Q.sortBy("created_at", import_watermelondb7.Q.desc)
|
|
16527
|
+
] : [import_watermelondb7.Q.where("is_deleted", false), import_watermelondb7.Q.sortBy("created_at", import_watermelondb7.Q.desc)];
|
|
16433
16528
|
const rx = this.conversations.query(...conditions).observe();
|
|
16434
16529
|
return {
|
|
16435
16530
|
subscribe: (observer) => {
|
|
@@ -16477,7 +16572,7 @@ var WatermelonChatStorageAdapter = class {
|
|
|
16477
16572
|
return clearMessagesOp(this.ctx, conversationId);
|
|
16478
16573
|
}
|
|
16479
16574
|
observeMessages(conversationId) {
|
|
16480
|
-
const rx = this.messages.query(
|
|
16575
|
+
const rx = this.messages.query(import_watermelondb7.Q.where("conversation_id", conversationId), import_watermelondb7.Q.sortBy("message_id", import_watermelondb7.Q.asc)).observe();
|
|
16481
16576
|
return {
|
|
16482
16577
|
subscribe: (observer) => {
|
|
16483
16578
|
let latestSeq = 0;
|
|
@@ -16696,7 +16791,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
16696
16791
|
})
|
|
16697
16792
|
);
|
|
16698
16793
|
});
|
|
16699
|
-
const results = await mediaCollection.query(
|
|
16794
|
+
const results = await mediaCollection.query(import_watermelondb8.Q.where("media_id", import_watermelondb8.Q.oneOf(mediaIds))).fetch();
|
|
16700
16795
|
return Promise.all(
|
|
16701
16796
|
results.map(
|
|
16702
16797
|
(m) => mediaToStored(m, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -16705,21 +16800,21 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
16705
16800
|
}
|
|
16706
16801
|
async function getMediaByIdOp(ctx, mediaId) {
|
|
16707
16802
|
const mediaCollection = ctx.database.get("media");
|
|
16708
|
-
const results = await mediaCollection.query(
|
|
16803
|
+
const results = await mediaCollection.query(import_watermelondb8.Q.where("media_id", mediaId), import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
16709
16804
|
return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
16710
16805
|
}
|
|
16711
16806
|
async function getMediaBySourceUrlOp(ctx, sourceUrl, walletAddress) {
|
|
16712
16807
|
const mediaCollection = ctx.database.get("media");
|
|
16713
16808
|
const results = await mediaCollection.query(
|
|
16714
|
-
|
|
16715
|
-
|
|
16716
|
-
|
|
16809
|
+
import_watermelondb8.Q.where("source_url", sourceUrl),
|
|
16810
|
+
import_watermelondb8.Q.where("wallet_address", walletAddress),
|
|
16811
|
+
import_watermelondb8.Q.where("is_deleted", false)
|
|
16717
16812
|
).fetch();
|
|
16718
16813
|
return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
16719
16814
|
}
|
|
16720
16815
|
async function updateMediaOp(ctx, mediaId, options) {
|
|
16721
16816
|
const mediaCollection = ctx.database.get("media");
|
|
16722
|
-
const results = await mediaCollection.query(
|
|
16817
|
+
const results = await mediaCollection.query(import_watermelondb8.Q.where("media_id", mediaId)).fetch();
|
|
16723
16818
|
if (results.length === 0) {
|
|
16724
16819
|
return null;
|
|
16725
16820
|
}
|
|
@@ -16739,7 +16834,7 @@ async function updateMediaOp(ctx, mediaId, options) {
|
|
|
16739
16834
|
m._setRaw("updated_at", now);
|
|
16740
16835
|
});
|
|
16741
16836
|
});
|
|
16742
|
-
const updated = await mediaCollection.query(
|
|
16837
|
+
const updated = await mediaCollection.query(import_watermelondb8.Q.where("media_id", mediaId)).fetch();
|
|
16743
16838
|
return updated.length > 0 ? await mediaToStored(updated[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
16744
16839
|
}
|
|
16745
16840
|
async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
|
|
@@ -16747,7 +16842,7 @@ async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
|
|
|
16747
16842
|
return 0;
|
|
16748
16843
|
}
|
|
16749
16844
|
const mediaCollection = ctx.database.get("media");
|
|
16750
|
-
const results = await mediaCollection.query(
|
|
16845
|
+
const results = await mediaCollection.query(import_watermelondb8.Q.where("media_id", import_watermelondb8.Q.oneOf(mediaIds))).fetch();
|
|
16751
16846
|
if (results.length === 0) {
|
|
16752
16847
|
return 0;
|
|
16753
16848
|
}
|
|
@@ -16769,13 +16864,13 @@ var IMAGE_VIDEO_MIMES = VIDEO_EXTENSIONS.map((ext) => `image/${ext}`);
|
|
|
16769
16864
|
async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
|
|
16770
16865
|
const mediaCollection = ctx.database.get("media");
|
|
16771
16866
|
const candidates = await mediaCollection.query(
|
|
16772
|
-
|
|
16773
|
-
|
|
16774
|
-
|
|
16775
|
-
|
|
16776
|
-
|
|
16777
|
-
...IMAGE_VIDEO_MIMES.map((m) =>
|
|
16778
|
-
|
|
16867
|
+
import_watermelondb8.Q.where("wallet_address", walletAddress),
|
|
16868
|
+
import_watermelondb8.Q.where("is_deleted", false),
|
|
16869
|
+
import_watermelondb8.Q.where("media_type", "image"),
|
|
16870
|
+
import_watermelondb8.Q.or(
|
|
16871
|
+
import_watermelondb8.Q.where("mime_type", import_watermelondb8.Q.like("video/%")),
|
|
16872
|
+
...IMAGE_VIDEO_MIMES.map((m) => import_watermelondb8.Q.where("mime_type", m)),
|
|
16873
|
+
import_watermelondb8.Q.where("mime_type", "application/octet-stream")
|
|
16779
16874
|
)
|
|
16780
16875
|
).fetch();
|
|
16781
16876
|
if (candidates.length === 0) {
|
|
@@ -16824,7 +16919,7 @@ async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
|
|
|
16824
16919
|
}
|
|
16825
16920
|
async function deleteMediaOp(ctx, mediaId) {
|
|
16826
16921
|
const mediaCollection = ctx.database.get("media");
|
|
16827
|
-
const results = await mediaCollection.query(
|
|
16922
|
+
const results = await mediaCollection.query(import_watermelondb8.Q.where("media_id", mediaId)).fetch();
|
|
16828
16923
|
if (results.length === 0) {
|
|
16829
16924
|
return false;
|
|
16830
16925
|
}
|
|
@@ -16842,7 +16937,7 @@ async function deleteMediaOp(ctx, mediaId) {
|
|
|
16842
16937
|
}
|
|
16843
16938
|
async function hardDeleteMediaOp(ctx, mediaId) {
|
|
16844
16939
|
const mediaCollection = ctx.database.get("media");
|
|
16845
|
-
const results = await mediaCollection.query(
|
|
16940
|
+
const results = await mediaCollection.query(import_watermelondb8.Q.where("media_id", mediaId)).fetch();
|
|
16846
16941
|
if (results.length === 0) {
|
|
16847
16942
|
return false;
|
|
16848
16943
|
}
|
|
@@ -16854,28 +16949,28 @@ async function hardDeleteMediaOp(ctx, mediaId) {
|
|
|
16854
16949
|
}
|
|
16855
16950
|
async function getMediaOp(ctx, filters) {
|
|
16856
16951
|
const mediaCollection = ctx.database.get("media");
|
|
16857
|
-
const conditions = [
|
|
16952
|
+
const conditions = [import_watermelondb8.Q.where("wallet_address", filters.walletAddress)];
|
|
16858
16953
|
if (!filters.includeDeleted) {
|
|
16859
|
-
conditions.push(
|
|
16954
|
+
conditions.push(import_watermelondb8.Q.where("is_deleted", false));
|
|
16860
16955
|
}
|
|
16861
16956
|
if (filters.mediaType) {
|
|
16862
|
-
conditions.push(
|
|
16957
|
+
conditions.push(import_watermelondb8.Q.where("media_type", filters.mediaType));
|
|
16863
16958
|
}
|
|
16864
16959
|
if (filters.role) {
|
|
16865
|
-
conditions.push(
|
|
16960
|
+
conditions.push(import_watermelondb8.Q.where("role", filters.role));
|
|
16866
16961
|
}
|
|
16867
16962
|
if (filters.conversationId) {
|
|
16868
|
-
conditions.push(
|
|
16963
|
+
conditions.push(import_watermelondb8.Q.where("conversation_id", filters.conversationId));
|
|
16869
16964
|
}
|
|
16870
16965
|
if (filters.model) {
|
|
16871
|
-
conditions.push(
|
|
16966
|
+
conditions.push(import_watermelondb8.Q.where("model", filters.model));
|
|
16872
16967
|
}
|
|
16873
|
-
conditions.push(
|
|
16968
|
+
conditions.push(import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.desc));
|
|
16874
16969
|
if (filters.limit) {
|
|
16875
|
-
conditions.push(
|
|
16970
|
+
conditions.push(import_watermelondb8.Q.take(filters.limit));
|
|
16876
16971
|
}
|
|
16877
16972
|
if (filters.offset) {
|
|
16878
|
-
conditions.push(
|
|
16973
|
+
conditions.push(import_watermelondb8.Q.skip(filters.offset));
|
|
16879
16974
|
}
|
|
16880
16975
|
const results = await mediaCollection.query(...conditions).fetch();
|
|
16881
16976
|
return Promise.all(
|
|
@@ -16905,9 +17000,9 @@ async function getMediaByConversationOp(ctx, walletAddress, conversationId, limi
|
|
|
16905
17000
|
async function getMediaByMessageOp(ctx, messageId) {
|
|
16906
17001
|
const mediaCollection = ctx.database.get("media");
|
|
16907
17002
|
const results = await mediaCollection.query(
|
|
16908
|
-
|
|
16909
|
-
|
|
16910
|
-
|
|
17003
|
+
import_watermelondb8.Q.where("message_id", messageId),
|
|
17004
|
+
import_watermelondb8.Q.where("is_deleted", false),
|
|
17005
|
+
import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.asc)
|
|
16911
17006
|
).fetch();
|
|
16912
17007
|
return Promise.all(
|
|
16913
17008
|
results.map(
|
|
@@ -16920,9 +17015,9 @@ async function getMediaByIdsOp(ctx, mediaIds, includeDeleted = false) {
|
|
|
16920
17015
|
return [];
|
|
16921
17016
|
}
|
|
16922
17017
|
const mediaCollection = ctx.database.get("media");
|
|
16923
|
-
const conditions = [
|
|
17018
|
+
const conditions = [import_watermelondb8.Q.where("media_id", import_watermelondb8.Q.oneOf(mediaIds))];
|
|
16924
17019
|
if (!includeDeleted) {
|
|
16925
|
-
conditions.push(
|
|
17020
|
+
conditions.push(import_watermelondb8.Q.where("is_deleted", false));
|
|
16926
17021
|
}
|
|
16927
17022
|
const results = await mediaCollection.query(...conditions).fetch();
|
|
16928
17023
|
const mediaMap = new Map(results.map((m) => [m.mediaId, m]));
|
|
@@ -16959,10 +17054,10 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
|
|
|
16959
17054
|
const queryLower = query.toLowerCase();
|
|
16960
17055
|
const MAX_SEARCH_RECORDS = 500;
|
|
16961
17056
|
const allResults = await mediaCollection.query(
|
|
16962
|
-
|
|
16963
|
-
|
|
16964
|
-
|
|
16965
|
-
|
|
17057
|
+
import_watermelondb8.Q.where("wallet_address", walletAddress),
|
|
17058
|
+
import_watermelondb8.Q.where("is_deleted", false),
|
|
17059
|
+
import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.desc),
|
|
17060
|
+
import_watermelondb8.Q.take(MAX_SEARCH_RECORDS)
|
|
16966
17061
|
).fetch();
|
|
16967
17062
|
const decrypted = await Promise.all(
|
|
16968
17063
|
allResults.map(
|
|
@@ -16975,11 +17070,11 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
|
|
|
16975
17070
|
async function getMediaCountOp(ctx, walletAddress, mediaType) {
|
|
16976
17071
|
const mediaCollection = ctx.database.get("media");
|
|
16977
17072
|
const conditions = [
|
|
16978
|
-
|
|
16979
|
-
|
|
17073
|
+
import_watermelondb8.Q.where("wallet_address", walletAddress),
|
|
17074
|
+
import_watermelondb8.Q.where("is_deleted", false)
|
|
16980
17075
|
];
|
|
16981
17076
|
if (mediaType) {
|
|
16982
|
-
conditions.push(
|
|
17077
|
+
conditions.push(import_watermelondb8.Q.where("media_type", mediaType));
|
|
16983
17078
|
}
|
|
16984
17079
|
return await mediaCollection.query(...conditions).fetchCount();
|
|
16985
17080
|
}
|
|
@@ -16994,7 +17089,7 @@ async function getMediaCountsByTypeOp(ctx, walletAddress) {
|
|
|
16994
17089
|
}
|
|
16995
17090
|
async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
16996
17091
|
const mediaCollection = ctx.database.get("media");
|
|
16997
|
-
const results = await mediaCollection.query(
|
|
17092
|
+
const results = await mediaCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId), import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
16998
17093
|
if (results.length === 0) {
|
|
16999
17094
|
return 0;
|
|
17000
17095
|
}
|
|
@@ -17015,7 +17110,7 @@ async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
|
17015
17110
|
}
|
|
17016
17111
|
async function deleteMediaByMessageOp(ctx, messageId) {
|
|
17017
17112
|
const mediaCollection = ctx.database.get("media");
|
|
17018
|
-
const results = await mediaCollection.query(
|
|
17113
|
+
const results = await mediaCollection.query(import_watermelondb8.Q.where("message_id", messageId), import_watermelondb8.Q.where("is_deleted", false)).fetch();
|
|
17019
17114
|
if (results.length === 0) {
|
|
17020
17115
|
return 0;
|
|
17021
17116
|
}
|
|
@@ -17036,9 +17131,9 @@ async function deleteMediaByMessageOp(ctx, messageId) {
|
|
|
17036
17131
|
}
|
|
17037
17132
|
|
|
17038
17133
|
// src/lib/db/memoryVault/models.ts
|
|
17039
|
-
var
|
|
17134
|
+
var import_watermelondb9 = require("@nozbe/watermelondb");
|
|
17040
17135
|
var import_decorators3 = require("@nozbe/watermelondb/decorators");
|
|
17041
|
-
var VaultMemory = class extends
|
|
17136
|
+
var VaultMemory = class extends import_watermelondb9.Model {
|
|
17042
17137
|
};
|
|
17043
17138
|
VaultMemory.table = "memory_vault";
|
|
17044
17139
|
__decorateClass([
|
|
@@ -17201,7 +17296,8 @@ function classifyDecay(m, now, policy) {
|
|
|
17201
17296
|
if (m.eventTimeEnd < now - resolved.pastEventGraceMs) return "archive";
|
|
17202
17297
|
if (m.eventTimeEnd >= now) return "keep";
|
|
17203
17298
|
}
|
|
17204
|
-
|
|
17299
|
+
const observedAt = Number.isFinite(m.lastObservedAt) ? m.lastObservedAt : m.updatedAt;
|
|
17300
|
+
if (now - Math.max(m.updatedAt, observedAt) > ttlForType(m.factType, resolved)) return "archive";
|
|
17205
17301
|
return "keep";
|
|
17206
17302
|
}
|
|
17207
17303
|
|
|
@@ -17274,8 +17370,11 @@ init_types4();
|
|
|
17274
17370
|
// src/react/useChatStorage.ts
|
|
17275
17371
|
init_logger();
|
|
17276
17372
|
|
|
17373
|
+
// src/lib/memory/index.ts
|
|
17374
|
+
init_internalFlowMarker();
|
|
17375
|
+
|
|
17277
17376
|
// src/lib/memory/autoExtract.ts
|
|
17278
|
-
var
|
|
17377
|
+
var import_watermelondb12 = require("@nozbe/watermelondb");
|
|
17279
17378
|
init_operations2();
|
|
17280
17379
|
init_types3();
|
|
17281
17380
|
init_logger();
|
|
@@ -17791,6 +17890,7 @@ async function retain(content, ctx, options = {}) {
|
|
|
17791
17890
|
const updated = await updateVaultMemoryOp(ctx.vaultCtx, targetId, {
|
|
17792
17891
|
content: existing.content,
|
|
17793
17892
|
proofCountIncrement: 1,
|
|
17893
|
+
observationSourceIds: options.sourceChunkIds,
|
|
17794
17894
|
sourceChunkIds: mergedSourceIds,
|
|
17795
17895
|
// resurrect encodes the decay gate: ACTIVE target → { preserveUpdatedAt:
|
|
17796
17896
|
// true } (main's normal re-observation path — bump proof_count without
|
|
@@ -18034,6 +18134,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
18034
18134
|
const updated = await updateVaultMemoryOp(ctx.vaultCtx, decision.targetId, {
|
|
18035
18135
|
content: existing.content,
|
|
18036
18136
|
proofCountIncrement: 1,
|
|
18137
|
+
observationSourceIds: options.sourceChunkIds,
|
|
18037
18138
|
sourceChunkIds: mergedSourceIds,
|
|
18038
18139
|
// ACTIVE target → { preserveUpdatedAt: true } (main's normal re-observation
|
|
18039
18140
|
// path); ARCHIVED (non-superseded, non-deleted) → { restore: true } and no
|
|
@@ -18083,6 +18184,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
18083
18184
|
const updated = await updateVaultMemoryOp(ctx.vaultCtx, decision.targetId, {
|
|
18084
18185
|
content: decision.content,
|
|
18085
18186
|
proofCountIncrement: 1,
|
|
18187
|
+
observationSourceIds: options.sourceChunkIds,
|
|
18086
18188
|
sourceChunkIds: mergedSourceIds,
|
|
18087
18189
|
embedding: JSON.stringify(newEmbedding),
|
|
18088
18190
|
embeddingModel: consolidatedModel,
|
|
@@ -18134,7 +18236,7 @@ async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
|
18134
18236
|
// src/lib/memory/autoExtract.ts
|
|
18135
18237
|
async function isMemoryTopicsUserManaged(ctx, memoryId) {
|
|
18136
18238
|
try {
|
|
18137
|
-
const rows = await ctx.database.get(VaultMemory.table).query(
|
|
18239
|
+
const rows = await ctx.database.get(VaultMemory.table).query(import_watermelondb12.Q.where("id", memoryId)).fetch();
|
|
18138
18240
|
return rows[0]?.topicsUserManaged === true;
|
|
18139
18241
|
} catch {
|
|
18140
18242
|
return true;
|
|
@@ -18721,7 +18823,7 @@ function createAutoExtractor(options) {
|
|
|
18721
18823
|
onQuarantined: (info) => options.onMemoryQuarantined?.({ ...info, conversationId })
|
|
18722
18824
|
}
|
|
18723
18825
|
});
|
|
18724
|
-
if (outcome !== "empty-after-retry") {
|
|
18826
|
+
if (outcome !== "empty-after-retry" && failedCount === 0) {
|
|
18725
18827
|
const advancedTo = window2[window2.length - 1].id;
|
|
18726
18828
|
stateFor(conversationId).watermark = advancedTo;
|
|
18727
18829
|
persistCursor(conversationId, messages, advancedTo, contiguous);
|
|
@@ -18882,6 +18984,7 @@ function toDecayInput(c) {
|
|
|
18882
18984
|
eventTimeEnd: c.eventTimeEnd,
|
|
18883
18985
|
eventTimeKind: c.eventTimeKind,
|
|
18884
18986
|
updatedAt: c.updatedAt,
|
|
18987
|
+
lastObservedAt: c.lastObservedAt,
|
|
18885
18988
|
archivedAt: c.archivedAt,
|
|
18886
18989
|
source: c.source,
|
|
18887
18990
|
trustTier: c.trustTier
|
|
@@ -18963,7 +19066,8 @@ function createDecaySweeper(options) {
|
|
|
18963
19066
|
for (const c of toArchive) {
|
|
18964
19067
|
const ok = await archiveVaultMemoryOp(vaultCtx, c.uniqueId, {
|
|
18965
19068
|
now,
|
|
18966
|
-
expectedUpdatedAt: c.updatedAt
|
|
19069
|
+
expectedUpdatedAt: c.updatedAt,
|
|
19070
|
+
expectedLastObservedAt: c.lastObservedAt ?? null
|
|
18967
19071
|
});
|
|
18968
19072
|
if (ok) archived++;
|
|
18969
19073
|
}
|
|
@@ -19219,6 +19323,7 @@ function createRecallTool(ctx, toolOptions, callbacks) {
|
|
|
19219
19323
|
budget: defaultBudget,
|
|
19220
19324
|
...toolOptions?.minScore !== void 0 && { minScore: toolOptions.minScore },
|
|
19221
19325
|
...toolOptions?.scopes && { scopes: toolOptions.scopes },
|
|
19326
|
+
...toolOptions?.memoryIds !== void 0 && { memoryIds: toolOptions.memoryIds },
|
|
19222
19327
|
...toolOptions?.folderId !== void 0 && { folderId: toolOptions.folderId },
|
|
19223
19328
|
...toolOptions?.excludeConversationId && {
|
|
19224
19329
|
excludeConversationId: toolOptions.excludeConversationId
|
|
@@ -19640,13 +19745,25 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
19640
19745
|
watermark,
|
|
19641
19746
|
options.reviewedMemoryIds
|
|
19642
19747
|
);
|
|
19748
|
+
const memoriesById = new Map(memories.map((memory) => [memory.uniqueId, memory]));
|
|
19749
|
+
const fallbackPriors = /* @__PURE__ */ new Map();
|
|
19750
|
+
if (previous) {
|
|
19751
|
+
for (const section of previous.sections) {
|
|
19752
|
+
if (section.sourceMemoryIds.length > 0 && section.sourceMemoryIds.every((id) => {
|
|
19753
|
+
const memory = memoriesById.get(id);
|
|
19754
|
+
return memory && !memory.isDeleted && !memory.supersededBy && scopes.includes(memory.scope) && (options.reviewedMemoryIds === void 0 || options.reviewedMemoryIds.includes(id)) && changeTime(memory) <= previous.vaultWatermark;
|
|
19755
|
+
})) {
|
|
19756
|
+
fallbackPriors.set(section.key, section);
|
|
19757
|
+
}
|
|
19758
|
+
}
|
|
19759
|
+
}
|
|
19643
19760
|
const settled = await Promise.allSettled(
|
|
19644
19761
|
facets.map(async (facet) => {
|
|
19645
19762
|
const prior = previous?.sections.find((s) => s.key === facet.key);
|
|
19646
19763
|
if (prior && !staleKeys.has(facet.key)) {
|
|
19647
19764
|
return prior;
|
|
19648
19765
|
}
|
|
19649
|
-
return synthesizeFacet(facet, ctx, options,
|
|
19766
|
+
return synthesizeFacet(facet, ctx, options, fallbackPriors.get(facet.key));
|
|
19650
19767
|
})
|
|
19651
19768
|
);
|
|
19652
19769
|
const sections = settled.map((r, i) => {
|
|
@@ -19659,10 +19776,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
19659
19776
|
error: r.reason instanceof Error ? r.reason.message : String(r.reason)
|
|
19660
19777
|
}
|
|
19661
19778
|
);
|
|
19662
|
-
return fallbackSection(
|
|
19663
|
-
facet,
|
|
19664
|
-
previous?.sections.find((s) => s.key === facet.key)
|
|
19665
|
-
);
|
|
19779
|
+
return fallbackSection(facet, fallbackPriors.get(facet.key));
|
|
19666
19780
|
});
|
|
19667
19781
|
return {
|
|
19668
19782
|
version: PROFILE_DOC_VERSION,
|
|
@@ -19850,7 +19964,7 @@ async function synthesizeFacet(facet, ctx, options, prior) {
|
|
|
19850
19964
|
const { text: text12, legitimateEmpty } = extractFacetText(result.structuredOutput);
|
|
19851
19965
|
if (!text12 && !legitimateEmpty && !noEvidence) {
|
|
19852
19966
|
getLogger().warn(
|
|
19853
|
-
"[memory/synthesizeProfile] facet synthesis returned degraded-empty;
|
|
19967
|
+
"[memory/synthesizeProfile] facet synthesis returned degraded-empty; using fallback section",
|
|
19854
19968
|
{ facet: facet.key, recalledCount: result.basedOn.memoryIds.length }
|
|
19855
19969
|
);
|
|
19856
19970
|
return fallbackSection(facet, prior);
|
|
@@ -20425,6 +20539,465 @@ function createMessageSourceResolver(ctx) {
|
|
|
20425
20539
|
};
|
|
20426
20540
|
}
|
|
20427
20541
|
|
|
20542
|
+
// src/lib/memory/context.ts
|
|
20543
|
+
function shouldRecallMemory(query) {
|
|
20544
|
+
const normalized = query.trim().toLowerCase().replace(/[.!?。!?¡¿]+$/u, "").replace(/^[¡¿]+/u, "");
|
|
20545
|
+
return normalized.length > 0 && !/^(hi|hi there|hello|hey|yes|no|yep|nope|sure|k|ok|okay|thanks|thank you|thank you very much|thanks a lot|cool|great|got it|sounds good|hola|buenos días|buenas|sí|si|gracias|muchas gracias|vale|bonjour|salut|oui|non|merci|merci beaucoup|d'accord|hallo|guten tag|ja|nein|danke|danke schön|alles klar|olá|obrigado|obrigada|ciao|grazie|sì|你好|谢谢|好的|こんにちは|ありがとう|안녕하세요|감사합니다)$/u.test(
|
|
20546
|
+
normalized
|
|
20547
|
+
);
|
|
20548
|
+
}
|
|
20549
|
+
async function assembleMemoryContext(options) {
|
|
20550
|
+
const { query, recall: recall2, loadFacts, loadSessionRefs } = options;
|
|
20551
|
+
const memoryIds = options.memoryIds ?? options.recallOptions?.memoryIds;
|
|
20552
|
+
const ranked = shouldRecallMemory(query);
|
|
20553
|
+
const degraded = [];
|
|
20554
|
+
const guard = async (lane, run, fallback) => {
|
|
20555
|
+
try {
|
|
20556
|
+
return await run();
|
|
20557
|
+
} catch (error) {
|
|
20558
|
+
degraded.push(lane);
|
|
20559
|
+
try {
|
|
20560
|
+
options.onDegraded?.(lane, error);
|
|
20561
|
+
} catch {
|
|
20562
|
+
}
|
|
20563
|
+
return fallback;
|
|
20564
|
+
}
|
|
20565
|
+
};
|
|
20566
|
+
const scoped = memoryIds !== void 0 || options.recallOptions?.scopes !== void 0 || options.recallOptions?.folderId !== void 0;
|
|
20567
|
+
const allowed = memoryIds !== void 0 ? new Set(memoryIds) : void 0;
|
|
20568
|
+
const filters = {
|
|
20569
|
+
...options.recallOptions?.scopes && { scopes: options.recallOptions.scopes },
|
|
20570
|
+
...options.recallOptions?.folderId !== void 0 && {
|
|
20571
|
+
folderId: options.recallOptions.folderId
|
|
20572
|
+
}
|
|
20573
|
+
};
|
|
20574
|
+
const active = (m) => !m.isDeleted && !m.archivedAt && !m.supersededBy && m.trustTier !== "quarantined" && (!allowed || allowed.has(m.uniqueId));
|
|
20575
|
+
const asItem = (m, lane, score = 1) => ({
|
|
20576
|
+
id: m.uniqueId,
|
|
20577
|
+
content: m.content,
|
|
20578
|
+
score,
|
|
20579
|
+
lane,
|
|
20580
|
+
sourceIds: m.sourceChunkIds ?? []
|
|
20581
|
+
});
|
|
20582
|
+
const empty = {
|
|
20583
|
+
memories: [],
|
|
20584
|
+
usedBudget: options.recallOptions?.budget ?? "low",
|
|
20585
|
+
reranked: false,
|
|
20586
|
+
candidateCount: 0
|
|
20587
|
+
};
|
|
20588
|
+
const [facts, episodes, profile, session] = await Promise.all([
|
|
20589
|
+
ranked ? guard(
|
|
20590
|
+
"fact",
|
|
20591
|
+
() => recall2(query, { ...options.recallOptions, types: ["fact"], limit: 20, memoryIds }),
|
|
20592
|
+
empty
|
|
20593
|
+
) : empty,
|
|
20594
|
+
ranked && !scoped && options.includeEpisodes !== false ? guard(
|
|
20595
|
+
"episode",
|
|
20596
|
+
() => recall2(query, {
|
|
20597
|
+
...options.recallOptions,
|
|
20598
|
+
types: ["chunk"],
|
|
20599
|
+
limit: 4,
|
|
20600
|
+
minScore: 0.5,
|
|
20601
|
+
onDiagnostics: void 0
|
|
20602
|
+
}),
|
|
20603
|
+
empty
|
|
20604
|
+
) : empty,
|
|
20605
|
+
loadFacts ? guard(
|
|
20606
|
+
"profile",
|
|
20607
|
+
async () => {
|
|
20608
|
+
const stable = await loadFacts({
|
|
20609
|
+
...filters,
|
|
20610
|
+
memoryIds,
|
|
20611
|
+
factTypes: ["identity", "preference", "constraint", "relationship"],
|
|
20612
|
+
limit: 8
|
|
20613
|
+
});
|
|
20614
|
+
const dynamic = await loadFacts({
|
|
20615
|
+
...filters,
|
|
20616
|
+
memoryIds,
|
|
20617
|
+
factTypes: ["ongoing_context", "plan"],
|
|
20618
|
+
limit: 4
|
|
20619
|
+
});
|
|
20620
|
+
return [...stable, ...dynamic].filter(active).map((m) => asItem(m, "profile"));
|
|
20621
|
+
},
|
|
20622
|
+
[]
|
|
20623
|
+
) : [],
|
|
20624
|
+
loadFacts && loadSessionRefs ? guard(
|
|
20625
|
+
"session",
|
|
20626
|
+
async () => {
|
|
20627
|
+
const refs = (await loadSessionRefs()).filter((r) => !allowed || allowed.has(r.memoryId)).sort((a, b) => b.score - a.score).slice(0, 10);
|
|
20628
|
+
if (!refs.length) return [];
|
|
20629
|
+
const rows = await loadFacts({ ...filters, memoryIds: refs.map((r) => r.memoryId) });
|
|
20630
|
+
const byId = new Map(rows.filter(active).map((m) => [m.uniqueId, m]));
|
|
20631
|
+
return refs.flatMap((ref) => {
|
|
20632
|
+
const m = byId.get(ref.memoryId);
|
|
20633
|
+
return m ? [asItem(m, "session", ref.score)] : [];
|
|
20634
|
+
});
|
|
20635
|
+
},
|
|
20636
|
+
[]
|
|
20637
|
+
) : []
|
|
20638
|
+
]);
|
|
20639
|
+
const toItems = (result, lane) => result.memories.filter((m) => !allowed || allowed.has(m.id)).map((m) => ({
|
|
20640
|
+
id: m.id,
|
|
20641
|
+
content: m.content,
|
|
20642
|
+
score: m.score,
|
|
20643
|
+
lane,
|
|
20644
|
+
...lane === "fact" && { recalled: true },
|
|
20645
|
+
sourceIds: m.sourceChunkIds ?? (m.messageId ? [m.messageId] : [])
|
|
20646
|
+
}));
|
|
20647
|
+
const recalledFacts = toItems(facts, "fact");
|
|
20648
|
+
const recalledScores = /* @__PURE__ */ new Map();
|
|
20649
|
+
const recalledContentScores = /* @__PURE__ */ new Map();
|
|
20650
|
+
for (const item of recalledFacts) {
|
|
20651
|
+
recalledScores.set(item.id, Math.max(recalledScores.get(item.id) ?? -Infinity, item.score));
|
|
20652
|
+
const content = item.content.trim();
|
|
20653
|
+
recalledContentScores.set(
|
|
20654
|
+
content,
|
|
20655
|
+
Math.max(recalledContentScores.get(content) ?? -Infinity, item.score)
|
|
20656
|
+
);
|
|
20657
|
+
}
|
|
20658
|
+
const rankedProfile = profile.map((item) => {
|
|
20659
|
+
const score = Math.max(
|
|
20660
|
+
recalledScores.get(item.id) ?? -Infinity,
|
|
20661
|
+
recalledContentScores.get(item.content.trim()) ?? -Infinity
|
|
20662
|
+
);
|
|
20663
|
+
return score === -Infinity ? item : { ...item, score, recalled: true };
|
|
20664
|
+
});
|
|
20665
|
+
const lanes = [
|
|
20666
|
+
[rankedProfile, 2e3],
|
|
20667
|
+
[recalledFacts, 6e3],
|
|
20668
|
+
[toItems(episodes, "episode"), 3e3],
|
|
20669
|
+
[session, 1e3]
|
|
20670
|
+
];
|
|
20671
|
+
const items = [];
|
|
20672
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
20673
|
+
const seenContent = /* @__PURE__ */ new Set();
|
|
20674
|
+
let remaining = Math.max(0, options.maxChars ?? 12e3);
|
|
20675
|
+
let truncated = false;
|
|
20676
|
+
for (const [candidates, laneBudget] of lanes) {
|
|
20677
|
+
let laneRemaining = Math.min(laneBudget, remaining);
|
|
20678
|
+
for (const item of candidates) {
|
|
20679
|
+
const content = item.content?.trim();
|
|
20680
|
+
const key = `${item.lane === "episode" ? "episode" : "fact"}:${item.id}`;
|
|
20681
|
+
if (!content || seenIds.has(key) || seenContent.has(content)) continue;
|
|
20682
|
+
if (content.length > laneRemaining) {
|
|
20683
|
+
truncated = true;
|
|
20684
|
+
continue;
|
|
20685
|
+
}
|
|
20686
|
+
items.push({ ...item, content });
|
|
20687
|
+
seenIds.add(key);
|
|
20688
|
+
seenContent.add(content);
|
|
20689
|
+
remaining -= content.length;
|
|
20690
|
+
laneRemaining -= content.length;
|
|
20691
|
+
}
|
|
20692
|
+
}
|
|
20693
|
+
return { items, ranked, rankedCount: recalledFacts.length, degraded, truncated };
|
|
20694
|
+
}
|
|
20695
|
+
|
|
20696
|
+
// src/lib/memory/durableExtraction.ts
|
|
20697
|
+
var import_watermelondb13 = require("@nozbe/watermelondb");
|
|
20698
|
+
init_encryption();
|
|
20699
|
+
init_operations();
|
|
20700
|
+
init_models();
|
|
20701
|
+
var MAX_JOBS_PER_PASS = 3;
|
|
20702
|
+
var MAX_ATTEMPTS = 3;
|
|
20703
|
+
function idsOf(job) {
|
|
20704
|
+
return JSON.parse(String(job._getRaw("message_ids")));
|
|
20705
|
+
}
|
|
20706
|
+
function seqOf(job) {
|
|
20707
|
+
const raw = job._getRaw("watermark_seq");
|
|
20708
|
+
return typeof raw === "number" && raw > 0 ? raw : void 0;
|
|
20709
|
+
}
|
|
20710
|
+
function createDurableAutoExtractor(options) {
|
|
20711
|
+
const vault = options.retainCtx.vaultCtx;
|
|
20712
|
+
const database = vault.database;
|
|
20713
|
+
const owner = vault.userId ?? vault.walletAddress;
|
|
20714
|
+
if (!owner) throw new Error("Durable extraction requires a user or wallet owner");
|
|
20715
|
+
const jobs = database.get(ExtractionJob.table);
|
|
20716
|
+
const storage = {
|
|
20717
|
+
database,
|
|
20718
|
+
messagesCollection: database.get("history"),
|
|
20719
|
+
conversationsCollection: database.get("conversations"),
|
|
20720
|
+
walletAddress: vault.walletAddress,
|
|
20721
|
+
signMessage: vault.signMessage,
|
|
20722
|
+
embeddedWalletSigner: vault.embeddedWalletSigner
|
|
20723
|
+
};
|
|
20724
|
+
const folderId = options.folderId ?? null;
|
|
20725
|
+
let disposed = false;
|
|
20726
|
+
let running = false;
|
|
20727
|
+
let wakeRequested = false;
|
|
20728
|
+
let timer;
|
|
20729
|
+
let writes = Promise.resolve();
|
|
20730
|
+
let storeFailures = 0;
|
|
20731
|
+
const attempts = /* @__PURE__ */ new Map();
|
|
20732
|
+
const reportError = (error, conversationId) => {
|
|
20733
|
+
try {
|
|
20734
|
+
options.onError?.(error instanceof Error ? error : new Error(String(error)), conversationId);
|
|
20735
|
+
} catch {
|
|
20736
|
+
}
|
|
20737
|
+
};
|
|
20738
|
+
const currentScope = () => {
|
|
20739
|
+
try {
|
|
20740
|
+
const value = typeof options.scope === "function" ? options.scope() : options.scope;
|
|
20741
|
+
return value ?? "private";
|
|
20742
|
+
} catch (error) {
|
|
20743
|
+
reportError(error);
|
|
20744
|
+
return "private";
|
|
20745
|
+
}
|
|
20746
|
+
};
|
|
20747
|
+
function schedule(delay) {
|
|
20748
|
+
if (disposed) return;
|
|
20749
|
+
if (running || timer !== void 0) {
|
|
20750
|
+
if (running) wakeRequested = true;
|
|
20751
|
+
return;
|
|
20752
|
+
}
|
|
20753
|
+
timer = setTimeout(() => {
|
|
20754
|
+
timer = void 0;
|
|
20755
|
+
void drain();
|
|
20756
|
+
}, delay);
|
|
20757
|
+
}
|
|
20758
|
+
async function extractBatch(messages, conversationId, ids, jobScope, jobFolderId) {
|
|
20759
|
+
let watchdog;
|
|
20760
|
+
try {
|
|
20761
|
+
return await Promise.race([
|
|
20762
|
+
new Promise((resolve, reject) => {
|
|
20763
|
+
const worker = createAutoExtractor({
|
|
20764
|
+
...options,
|
|
20765
|
+
retainCtx: {
|
|
20766
|
+
...options.retainCtx,
|
|
20767
|
+
vaultCtx: {
|
|
20768
|
+
...vault,
|
|
20769
|
+
canWrite: async () => !disposed && await storage.conversationsCollection.query(import_watermelondb13.Q.where("conversation_id", conversationId), import_watermelondb13.Q.where("is_deleted", false)).fetchCount() > 0 && await storage.messagesCollection.query(import_watermelondb13.Q.where("conversation_id", conversationId), import_watermelondb13.Q.where("id", import_watermelondb13.Q.oneOf(ids))).fetchCount() === ids.length && (!vault.canWrite || await vault.canWrite()) && !disposed
|
|
20770
|
+
}
|
|
20771
|
+
},
|
|
20772
|
+
// Never publish a private queued observation after a mode flip.
|
|
20773
|
+
scope: jobScope,
|
|
20774
|
+
folderId: jobFolderId,
|
|
20775
|
+
cursorStore: void 0,
|
|
20776
|
+
windowSize: 20,
|
|
20777
|
+
maxWindowSize: 20,
|
|
20778
|
+
onTurnComplete: resolve,
|
|
20779
|
+
onError: reject
|
|
20780
|
+
});
|
|
20781
|
+
worker.processTurn(messages, conversationId);
|
|
20782
|
+
worker.dispose();
|
|
20783
|
+
}),
|
|
20784
|
+
new Promise((_resolve, reject) => {
|
|
20785
|
+
watchdog = setTimeout(
|
|
20786
|
+
() => reject(new Error("Extraction did not settle in time; retained for retry")),
|
|
20787
|
+
options.batchTimeoutMs ?? 18e4
|
|
20788
|
+
);
|
|
20789
|
+
})
|
|
20790
|
+
]);
|
|
20791
|
+
} finally {
|
|
20792
|
+
if (watchdog !== void 0) clearTimeout(watchdog);
|
|
20793
|
+
}
|
|
20794
|
+
}
|
|
20795
|
+
async function drain() {
|
|
20796
|
+
if (disposed || running) return;
|
|
20797
|
+
running = true;
|
|
20798
|
+
wakeRequested = false;
|
|
20799
|
+
let retry = false;
|
|
20800
|
+
let scheduleAfterSuccess = false;
|
|
20801
|
+
try {
|
|
20802
|
+
await writes;
|
|
20803
|
+
const pending = await jobs.query(import_watermelondb13.Q.where("owner_key", owner), import_watermelondb13.Q.where("message_ids", import_watermelondb13.Q.notEq("[]"))).fetch();
|
|
20804
|
+
storeFailures = 0;
|
|
20805
|
+
let processed = 0;
|
|
20806
|
+
for (const job of pending) {
|
|
20807
|
+
if (disposed) break;
|
|
20808
|
+
const attempted = attempts.get(job.id) ?? 0;
|
|
20809
|
+
if (attempted >= MAX_ATTEMPTS) continue;
|
|
20810
|
+
if (processed >= MAX_JOBS_PER_PASS) {
|
|
20811
|
+
scheduleAfterSuccess = true;
|
|
20812
|
+
break;
|
|
20813
|
+
}
|
|
20814
|
+
processed++;
|
|
20815
|
+
const conversationId = String(job._getRaw("conversation_id"));
|
|
20816
|
+
try {
|
|
20817
|
+
const conversations = await storage.conversationsCollection.query(import_watermelondb13.Q.where("conversation_id", conversationId), import_watermelondb13.Q.where("is_deleted", false)).fetchCount();
|
|
20818
|
+
if (!conversations) {
|
|
20819
|
+
await database.write(() => job.destroyPermanently());
|
|
20820
|
+
continue;
|
|
20821
|
+
}
|
|
20822
|
+
const ids = idsOf(job).slice(0, 20);
|
|
20823
|
+
const loaded = await Promise.all(ids.map((id) => getMessageOp(storage, id)));
|
|
20824
|
+
const missing = ids.filter((_id, index) => loaded[index] === null);
|
|
20825
|
+
if (missing.length) {
|
|
20826
|
+
if (attempted < MAX_ATTEMPTS - 1)
|
|
20827
|
+
throw new Error("Source messages not yet available; retained for retry");
|
|
20828
|
+
const dropped = new Set(missing);
|
|
20829
|
+
await database.write(
|
|
20830
|
+
() => job.update(
|
|
20831
|
+
(r) => r._setRaw(
|
|
20832
|
+
"message_ids",
|
|
20833
|
+
JSON.stringify(idsOf(job).filter((id) => !dropped.has(id)))
|
|
20834
|
+
)
|
|
20835
|
+
)
|
|
20836
|
+
);
|
|
20837
|
+
attempts.delete(job.id);
|
|
20838
|
+
scheduleAfterSuccess = true;
|
|
20839
|
+
reportError(
|
|
20840
|
+
new Error(
|
|
20841
|
+
`Dropped ${missing.length} unresolvable source id(s) to unblock extraction`
|
|
20842
|
+
),
|
|
20843
|
+
conversationId
|
|
20844
|
+
);
|
|
20845
|
+
continue;
|
|
20846
|
+
}
|
|
20847
|
+
if (loaded.some(
|
|
20848
|
+
(message) => message && (message.decryptionStatus || isEncrypted(message.content))
|
|
20849
|
+
)) {
|
|
20850
|
+
throw new Error("Source messages are locked; retained for retry");
|
|
20851
|
+
}
|
|
20852
|
+
const messages = loaded.flatMap(
|
|
20853
|
+
(m) => m && m.conversationId === conversationId && (m.role === "user" || m.role === "assistant") ? [{ id: m.uniqueId, role: m.role, content: m.content }] : []
|
|
20854
|
+
);
|
|
20855
|
+
let success = messages.length === 0;
|
|
20856
|
+
if (messages.length) {
|
|
20857
|
+
const result = await extractBatch(
|
|
20858
|
+
messages,
|
|
20859
|
+
conversationId,
|
|
20860
|
+
ids,
|
|
20861
|
+
currentScope() === "private" ? "private" : String(job._getRaw("scope")),
|
|
20862
|
+
job._getRaw("folder_id") ?? null
|
|
20863
|
+
);
|
|
20864
|
+
success = result.failedCount === 0 && result.outcome !== "empty-after-retry";
|
|
20865
|
+
options.onTurnComplete?.(result);
|
|
20866
|
+
}
|
|
20867
|
+
if (!success) throw new Error("Extraction batch incomplete; retained for retry");
|
|
20868
|
+
attempts.delete(job.id);
|
|
20869
|
+
const sequences = /* @__PURE__ */ new Map();
|
|
20870
|
+
for (const message of loaded)
|
|
20871
|
+
if (message && message.messageId > 0)
|
|
20872
|
+
sequences.set(message.uniqueId, message.messageId);
|
|
20873
|
+
await database.write(async () => {
|
|
20874
|
+
const current = idsOf(job);
|
|
20875
|
+
const acknowledged = ids.filter((id) => current.includes(id));
|
|
20876
|
+
if (!acknowledged.length) return;
|
|
20877
|
+
const done = new Set(acknowledged);
|
|
20878
|
+
const remaining = current.filter((id) => !done.has(id));
|
|
20879
|
+
if (remaining.length) {
|
|
20880
|
+
await job.update(
|
|
20881
|
+
(r) => r._setRaw("message_ids", JSON.stringify([...acknowledged.slice(-2), ...remaining]))
|
|
20882
|
+
);
|
|
20883
|
+
} else await job.update((r) => r._setRaw("message_ids", "[]"));
|
|
20884
|
+
const newest = acknowledged[acknowledged.length - 1];
|
|
20885
|
+
await job.update((r) => {
|
|
20886
|
+
r._setRaw("watermark", newest);
|
|
20887
|
+
const sequence = sequences.get(newest);
|
|
20888
|
+
if (sequence !== void 0) {
|
|
20889
|
+
const prior = seqOf(job);
|
|
20890
|
+
r._setRaw(
|
|
20891
|
+
"watermark_seq",
|
|
20892
|
+
prior === void 0 ? sequence : Math.max(prior, sequence)
|
|
20893
|
+
);
|
|
20894
|
+
}
|
|
20895
|
+
});
|
|
20896
|
+
});
|
|
20897
|
+
scheduleAfterSuccess = true;
|
|
20898
|
+
} catch (error) {
|
|
20899
|
+
attempts.set(job.id, attempted + 1);
|
|
20900
|
+
retry = true;
|
|
20901
|
+
reportError(error, conversationId);
|
|
20902
|
+
}
|
|
20903
|
+
}
|
|
20904
|
+
} catch (error) {
|
|
20905
|
+
retry = ++storeFailures < 3;
|
|
20906
|
+
reportError(error);
|
|
20907
|
+
} finally {
|
|
20908
|
+
running = false;
|
|
20909
|
+
const woken = wakeRequested;
|
|
20910
|
+
wakeRequested = false;
|
|
20911
|
+
if (retry || scheduleAfterSuccess || woken)
|
|
20912
|
+
schedule(retry ? options.retryDelayMs ?? 3e4 : 0);
|
|
20913
|
+
}
|
|
20914
|
+
}
|
|
20915
|
+
schedule(0);
|
|
20916
|
+
return {
|
|
20917
|
+
processTurn(messages, conversationId) {
|
|
20918
|
+
if (disposed || !conversationId || !messages.length) return false;
|
|
20919
|
+
const ids = messages.map((m) => m.id);
|
|
20920
|
+
const scope = currentScope();
|
|
20921
|
+
writes = writes.then(
|
|
20922
|
+
() => database.write(async () => {
|
|
20923
|
+
const existing = await jobs.query(import_watermelondb13.Q.where("owner_key", owner), import_watermelondb13.Q.where("conversation_id", conversationId)).fetch();
|
|
20924
|
+
const job = existing.find(
|
|
20925
|
+
(candidate) => candidate._getRaw("scope") === scope && (candidate._getRaw("folder_id") ?? null) === folderId
|
|
20926
|
+
);
|
|
20927
|
+
const positions = new Map(ids.map((id, index) => [id, index]));
|
|
20928
|
+
const rows = await storage.messagesCollection.query(import_watermelondb13.Q.where("id", import_watermelondb13.Q.oneOf(ids))).fetch();
|
|
20929
|
+
const sequences = /* @__PURE__ */ new Map();
|
|
20930
|
+
for (const row of rows) {
|
|
20931
|
+
const sequence = Number(row._getRaw("message_id"));
|
|
20932
|
+
if (Number.isFinite(sequence) && sequence > 0) sequences.set(row.id, sequence);
|
|
20933
|
+
}
|
|
20934
|
+
let boundary = -1;
|
|
20935
|
+
let observedSeq = 0;
|
|
20936
|
+
const foreignSources = /* @__PURE__ */ new Set();
|
|
20937
|
+
for (const prior of existing) {
|
|
20938
|
+
const sources = [...idsOf(prior), String(prior._getRaw("watermark") ?? "")];
|
|
20939
|
+
for (const id of sources) {
|
|
20940
|
+
boundary = Math.max(boundary, positions.get(id) ?? -1);
|
|
20941
|
+
if (prior !== job) foreignSources.add(id);
|
|
20942
|
+
}
|
|
20943
|
+
observedSeq = Math.max(observedSeq, seqOf(prior) ?? 0);
|
|
20944
|
+
for (const id of idsOf(prior))
|
|
20945
|
+
observedSeq = Math.max(observedSeq, sequences.get(id) ?? 0);
|
|
20946
|
+
}
|
|
20947
|
+
if (observedSeq > 0)
|
|
20948
|
+
ids.forEach((id, index) => {
|
|
20949
|
+
const sequence = sequences.get(id);
|
|
20950
|
+
if (sequence !== void 0 && sequence <= observedSeq)
|
|
20951
|
+
boundary = Math.max(boundary, index);
|
|
20952
|
+
});
|
|
20953
|
+
if (!existing.length && options.cursorStore) {
|
|
20954
|
+
try {
|
|
20955
|
+
const cursor = options.cursorStore.get(conversationId);
|
|
20956
|
+
if (cursor) boundary = Math.max(boundary, positions.get(cursor) ?? -1);
|
|
20957
|
+
} catch (error) {
|
|
20958
|
+
reportError(error, conversationId);
|
|
20959
|
+
}
|
|
20960
|
+
}
|
|
20961
|
+
if (boundary < 0 && existing.some((prior) => idsOf(prior).length > 0 || seqOf(prior) !== void 0)) {
|
|
20962
|
+
reportError(
|
|
20963
|
+
new Error("Extraction boundary unresolved; skipped rather than re-observing"),
|
|
20964
|
+
conversationId
|
|
20965
|
+
);
|
|
20966
|
+
return;
|
|
20967
|
+
}
|
|
20968
|
+
const start = boundary >= 0 ? boundary + 1 : Math.max(0, ids.length - Math.max(1, options.windowSize ?? 6));
|
|
20969
|
+
if (start >= ids.length) return;
|
|
20970
|
+
const ownWatermark = job?._getRaw("watermark");
|
|
20971
|
+
const atOwnWatermark = !!job && boundary >= 0 && (ids[boundary] === ownWatermark || sequences.get(ids[boundary]) !== void 0 && sequences.get(ids[boundary]) === seqOf(job));
|
|
20972
|
+
const overlapStart = atOwnWatermark ? Math.max(0, boundary - 1) : start;
|
|
20973
|
+
const fresh = ids.slice(overlapStart).filter((id) => !foreignSources.has(id));
|
|
20974
|
+
if (!fresh.length) return;
|
|
20975
|
+
if (job) {
|
|
20976
|
+
await job.update(
|
|
20977
|
+
(r) => r._setRaw("message_ids", JSON.stringify([.../* @__PURE__ */ new Set([...idsOf(job), ...fresh])]))
|
|
20978
|
+
);
|
|
20979
|
+
attempts.delete(job.id);
|
|
20980
|
+
} else {
|
|
20981
|
+
await jobs.create((r) => {
|
|
20982
|
+
r._setRaw("owner_key", owner);
|
|
20983
|
+
r._setRaw("conversation_id", conversationId);
|
|
20984
|
+
r._setRaw("scope", scope);
|
|
20985
|
+
r._setRaw("folder_id", folderId);
|
|
20986
|
+
r._setRaw("message_ids", JSON.stringify([...new Set(fresh)]));
|
|
20987
|
+
});
|
|
20988
|
+
}
|
|
20989
|
+
})
|
|
20990
|
+
).then(() => schedule(options.debounceMs ?? 2e4)).catch((error) => reportError(error, conversationId));
|
|
20991
|
+
return true;
|
|
20992
|
+
},
|
|
20993
|
+
isProcessing: () => running,
|
|
20994
|
+
dispose() {
|
|
20995
|
+
disposed = true;
|
|
20996
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
20997
|
+
}
|
|
20998
|
+
};
|
|
20999
|
+
}
|
|
21000
|
+
|
|
20428
21001
|
// src/lib/memoryEngine/index.ts
|
|
20429
21002
|
init_chunking();
|
|
20430
21003
|
init_embeddings();
|
|
@@ -24820,13 +25393,13 @@ function useChatStorage(options) {
|
|
|
24820
25393
|
}
|
|
24821
25394
|
|
|
24822
25395
|
// src/lib/db/schema.ts
|
|
24823
|
-
var
|
|
25396
|
+
var import_watermelondb22 = require("@nozbe/watermelondb");
|
|
24824
25397
|
var import_migrations2 = require("@nozbe/watermelondb/Schema/migrations");
|
|
24825
25398
|
|
|
24826
25399
|
// src/lib/db/appFiles/models.ts
|
|
24827
|
-
var
|
|
25400
|
+
var import_watermelondb14 = require("@nozbe/watermelondb");
|
|
24828
25401
|
var import_decorators4 = require("@nozbe/watermelondb/decorators");
|
|
24829
|
-
var AppFile = class extends
|
|
25402
|
+
var AppFile = class extends import_watermelondb14.Model {
|
|
24830
25403
|
};
|
|
24831
25404
|
AppFile.table = "app_files";
|
|
24832
25405
|
AppFile.associations = {};
|
|
@@ -24848,9 +25421,9 @@ __decorateClass([
|
|
|
24848
25421
|
], AppFile.prototype, "updatedAt", 2);
|
|
24849
25422
|
|
|
24850
25423
|
// src/lib/db/conversationMemory/models.ts
|
|
24851
|
-
var
|
|
25424
|
+
var import_watermelondb15 = require("@nozbe/watermelondb");
|
|
24852
25425
|
var import_decorators5 = require("@nozbe/watermelondb/decorators");
|
|
24853
|
-
var ConversationMemory = class extends
|
|
25426
|
+
var ConversationMemory = class extends import_watermelondb15.Model {
|
|
24854
25427
|
};
|
|
24855
25428
|
ConversationMemory.table = "conversation_memory";
|
|
24856
25429
|
ConversationMemory.associations = {};
|
|
@@ -24869,9 +25442,9 @@ __decorateClass([
|
|
|
24869
25442
|
], ConversationMemory.prototype, "createdAt", 2);
|
|
24870
25443
|
|
|
24871
25444
|
// src/lib/db/entities/models.ts
|
|
24872
|
-
var
|
|
25445
|
+
var import_watermelondb16 = require("@nozbe/watermelondb");
|
|
24873
25446
|
var import_decorators6 = require("@nozbe/watermelondb/decorators");
|
|
24874
|
-
var Entity = class extends
|
|
25447
|
+
var Entity = class extends import_watermelondb16.Model {
|
|
24875
25448
|
};
|
|
24876
25449
|
Entity.table = "entity";
|
|
24877
25450
|
__decorateClass([
|
|
@@ -24887,7 +25460,7 @@ __decorateClass([
|
|
|
24887
25460
|
__decorateClass([
|
|
24888
25461
|
(0, import_decorators6.date)("updated_at")
|
|
24889
25462
|
], Entity.prototype, "updatedAt", 2);
|
|
24890
|
-
var MemoryEntity = class extends
|
|
25463
|
+
var MemoryEntity = class extends import_watermelondb16.Model {
|
|
24891
25464
|
};
|
|
24892
25465
|
MemoryEntity.table = "memory_entity";
|
|
24893
25466
|
__decorateClass([
|
|
@@ -24904,10 +25477,13 @@ __decorateClass([
|
|
|
24904
25477
|
(0, import_decorators6.date)("created_at")
|
|
24905
25478
|
], MemoryEntity.prototype, "createdAt", 2);
|
|
24906
25479
|
|
|
25480
|
+
// src/lib/db/schema.ts
|
|
25481
|
+
init_models();
|
|
25482
|
+
|
|
24907
25483
|
// src/lib/db/project/models.ts
|
|
24908
|
-
var
|
|
25484
|
+
var import_watermelondb17 = require("@nozbe/watermelondb");
|
|
24909
25485
|
var import_decorators7 = require("@nozbe/watermelondb/decorators");
|
|
24910
|
-
var Project = class extends
|
|
25486
|
+
var Project = class extends import_watermelondb17.Model {
|
|
24911
25487
|
};
|
|
24912
25488
|
Project.table = "projects";
|
|
24913
25489
|
Project.associations = {
|
|
@@ -24930,10 +25506,10 @@ __decorateClass([
|
|
|
24930
25506
|
], Project.prototype, "isDeleted", 2);
|
|
24931
25507
|
|
|
24932
25508
|
// src/lib/db/savedTools/models.ts
|
|
24933
|
-
var
|
|
25509
|
+
var import_watermelondb18 = require("@nozbe/watermelondb");
|
|
24934
25510
|
var import_decorators8 = require("@nozbe/watermelondb/decorators");
|
|
24935
25511
|
var sanitizeParameters = (raw) => raw ?? {};
|
|
24936
|
-
var SavedTool = class extends
|
|
25512
|
+
var SavedTool = class extends import_watermelondb18.Model {
|
|
24937
25513
|
};
|
|
24938
25514
|
SavedTool.table = "saved_tools";
|
|
24939
25515
|
SavedTool.associations = {};
|
|
@@ -24967,9 +25543,9 @@ __decorateClass([
|
|
|
24967
25543
|
], SavedTool.prototype, "isDeleted", 2);
|
|
24968
25544
|
|
|
24969
25545
|
// src/lib/db/settings/models.ts
|
|
24970
|
-
var
|
|
25546
|
+
var import_watermelondb19 = require("@nozbe/watermelondb");
|
|
24971
25547
|
var import_decorators9 = require("@nozbe/watermelondb/decorators");
|
|
24972
|
-
var ModelPreference = class extends
|
|
25548
|
+
var ModelPreference = class extends import_watermelondb19.Model {
|
|
24973
25549
|
};
|
|
24974
25550
|
ModelPreference.table = "modelPreferences";
|
|
24975
25551
|
__decorateClass([
|
|
@@ -24980,9 +25556,9 @@ __decorateClass([
|
|
|
24980
25556
|
], ModelPreference.prototype, "models", 2);
|
|
24981
25557
|
|
|
24982
25558
|
// src/lib/db/userPreferences/models.ts
|
|
24983
|
-
var
|
|
25559
|
+
var import_watermelondb20 = require("@nozbe/watermelondb");
|
|
24984
25560
|
var import_decorators10 = require("@nozbe/watermelondb/decorators");
|
|
24985
|
-
var UserPreference = class extends
|
|
25561
|
+
var UserPreference = class extends import_watermelondb20.Model {
|
|
24986
25562
|
};
|
|
24987
25563
|
UserPreference.table = "userPreferences";
|
|
24988
25564
|
__decorateClass([
|
|
@@ -25011,9 +25587,9 @@ __decorateClass([
|
|
|
25011
25587
|
], UserPreference.prototype, "updatedAt", 2);
|
|
25012
25588
|
|
|
25013
25589
|
// src/lib/db/vaultFolders/models.ts
|
|
25014
|
-
var
|
|
25590
|
+
var import_watermelondb21 = require("@nozbe/watermelondb");
|
|
25015
25591
|
var import_decorators11 = require("@nozbe/watermelondb/decorators");
|
|
25016
|
-
var VaultFolder = class extends
|
|
25592
|
+
var VaultFolder = class extends import_watermelondb21.Model {
|
|
25017
25593
|
};
|
|
25018
25594
|
VaultFolder.table = "vault_folders";
|
|
25019
25595
|
__decorateClass([
|
|
@@ -25040,12 +25616,27 @@ __decorateClass([
|
|
|
25040
25616
|
], VaultFolder.prototype, "context", 2);
|
|
25041
25617
|
|
|
25042
25618
|
// src/lib/db/schema.ts
|
|
25043
|
-
var SDK_SCHEMA_VERSION =
|
|
25044
|
-
var sdkSchema = (0,
|
|
25619
|
+
var SDK_SCHEMA_VERSION = 46;
|
|
25620
|
+
var sdkSchema = (0, import_watermelondb22.appSchema)({
|
|
25045
25621
|
version: SDK_SCHEMA_VERSION,
|
|
25046
25622
|
tables: [
|
|
25623
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25624
|
+
name: "memory_extraction_jobs",
|
|
25625
|
+
columns: [
|
|
25626
|
+
{ name: "owner_key", type: "string", isIndexed: true },
|
|
25627
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
25628
|
+
{ name: "scope", type: "string" },
|
|
25629
|
+
{ name: "message_ids", type: "string" },
|
|
25630
|
+
{ name: "watermark", type: "string", isOptional: true },
|
|
25631
|
+
// Deletion-proof anchor: history.message_id of the newest acknowledged
|
|
25632
|
+
// source. `watermark` alone is an id, and deleting that message erased
|
|
25633
|
+
// the anchor — see the column note in extractionJobs/models.ts.
|
|
25634
|
+
{ name: "watermark_seq", type: "number", isOptional: true },
|
|
25635
|
+
{ name: "folder_id", type: "string", isOptional: true }
|
|
25636
|
+
]
|
|
25637
|
+
}),
|
|
25047
25638
|
// Chat storage tables
|
|
25048
|
-
(0,
|
|
25639
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25049
25640
|
name: "history",
|
|
25050
25641
|
columns: [
|
|
25051
25642
|
{ name: "message_id", type: "number" },
|
|
@@ -25084,7 +25675,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25084
25675
|
// MessageOrigin — provenance, NOT encrypted (see v44)
|
|
25085
25676
|
]
|
|
25086
25677
|
}),
|
|
25087
|
-
(0,
|
|
25678
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25088
25679
|
name: "conversations",
|
|
25089
25680
|
columns: [
|
|
25090
25681
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -25106,7 +25697,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25106
25697
|
]
|
|
25107
25698
|
}),
|
|
25108
25699
|
// Project storage table
|
|
25109
|
-
(0,
|
|
25700
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25110
25701
|
name: "projects",
|
|
25111
25702
|
columns: [
|
|
25112
25703
|
{ name: "project_id", type: "string", isIndexed: true },
|
|
@@ -25117,7 +25708,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25117
25708
|
]
|
|
25118
25709
|
}),
|
|
25119
25710
|
// Settings storage tables (deprecated - use userPreferences)
|
|
25120
|
-
(0,
|
|
25711
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25121
25712
|
name: "modelPreferences",
|
|
25122
25713
|
columns: [
|
|
25123
25714
|
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
@@ -25125,7 +25716,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25125
25716
|
]
|
|
25126
25717
|
}),
|
|
25127
25718
|
// Unified user preferences storage
|
|
25128
|
-
(0,
|
|
25719
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25129
25720
|
name: "userPreferences",
|
|
25130
25721
|
columns: [
|
|
25131
25722
|
// Identity
|
|
@@ -25144,7 +25735,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25144
25735
|
]
|
|
25145
25736
|
}),
|
|
25146
25737
|
// Memory vault storage
|
|
25147
|
-
(0,
|
|
25738
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25148
25739
|
name: "memory_vault",
|
|
25149
25740
|
columns: [
|
|
25150
25741
|
{ name: "content", type: "string" },
|
|
@@ -25272,7 +25863,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25272
25863
|
]
|
|
25273
25864
|
}),
|
|
25274
25865
|
// Entity table — canonical names extracted from auto-extraction (W5).
|
|
25275
|
-
(0,
|
|
25866
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25276
25867
|
name: "entity",
|
|
25277
25868
|
columns: [
|
|
25278
25869
|
{ name: "canonical_name", type: "string", isIndexed: true },
|
|
@@ -25282,7 +25873,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25282
25873
|
]
|
|
25283
25874
|
}),
|
|
25284
25875
|
// Many-to-many join: which memories reference which entities.
|
|
25285
|
-
(0,
|
|
25876
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25286
25877
|
name: "memory_entity",
|
|
25287
25878
|
columns: [
|
|
25288
25879
|
{ name: "memory_id", type: "string", isIndexed: true },
|
|
@@ -25292,7 +25883,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25292
25883
|
]
|
|
25293
25884
|
}),
|
|
25294
25885
|
// Vault folder organization
|
|
25295
|
-
(0,
|
|
25886
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25296
25887
|
name: "vault_folders",
|
|
25297
25888
|
columns: [
|
|
25298
25889
|
{ name: "name", type: "string" },
|
|
@@ -25305,7 +25896,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25305
25896
|
]
|
|
25306
25897
|
}),
|
|
25307
25898
|
// Conversation summary cache for progressive history summarization
|
|
25308
|
-
(0,
|
|
25899
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25309
25900
|
name: "conversation_summaries",
|
|
25310
25901
|
columns: [
|
|
25311
25902
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -25318,7 +25909,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25318
25909
|
]
|
|
25319
25910
|
}),
|
|
25320
25911
|
// Media library storage (images, videos, audio, documents)
|
|
25321
|
-
(0,
|
|
25912
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25322
25913
|
name: "media",
|
|
25323
25914
|
columns: [
|
|
25324
25915
|
// Identity
|
|
@@ -25354,7 +25945,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25354
25945
|
]
|
|
25355
25946
|
}),
|
|
25356
25947
|
// ── App files ─────────────────────────────────────────────────────────
|
|
25357
|
-
(0,
|
|
25948
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25358
25949
|
name: "app_files",
|
|
25359
25950
|
columns: [
|
|
25360
25951
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -25365,7 +25956,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25365
25956
|
]
|
|
25366
25957
|
}),
|
|
25367
25958
|
// ── Saved tools ──────────────────────────────────────────────────────
|
|
25368
|
-
(0,
|
|
25959
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25369
25960
|
name: "saved_tools",
|
|
25370
25961
|
columns: [
|
|
25371
25962
|
{ name: "name", type: "string" },
|
|
@@ -25381,7 +25972,7 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
25381
25972
|
]
|
|
25382
25973
|
}),
|
|
25383
25974
|
// ── Conversation memories (panel persistence) ────────────────────────
|
|
25384
|
-
(0,
|
|
25975
|
+
(0, import_watermelondb22.tableSchema)({
|
|
25385
25976
|
name: "conversation_memory",
|
|
25386
25977
|
columns: [
|
|
25387
25978
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -26048,10 +26639,28 @@ var sdkMigrations = (0, import_migrations2.schemaMigrations)({
|
|
|
26048
26639
|
columns: [{ name: "media", type: "string", isOptional: true }]
|
|
26049
26640
|
})
|
|
26050
26641
|
]
|
|
26642
|
+
},
|
|
26643
|
+
{
|
|
26644
|
+
toVersion: 46,
|
|
26645
|
+
steps: [
|
|
26646
|
+
(0, import_migrations2.createTable)({
|
|
26647
|
+
name: "memory_extraction_jobs",
|
|
26648
|
+
columns: [
|
|
26649
|
+
{ name: "owner_key", type: "string", isIndexed: true },
|
|
26650
|
+
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
26651
|
+
{ name: "scope", type: "string" },
|
|
26652
|
+
{ name: "message_ids", type: "string" },
|
|
26653
|
+
{ name: "watermark", type: "string", isOptional: true },
|
|
26654
|
+
{ name: "watermark_seq", type: "number", isOptional: true },
|
|
26655
|
+
{ name: "folder_id", type: "string", isOptional: true }
|
|
26656
|
+
]
|
|
26657
|
+
})
|
|
26658
|
+
]
|
|
26051
26659
|
}
|
|
26052
26660
|
]
|
|
26053
26661
|
});
|
|
26054
26662
|
var sdkModelClasses = [
|
|
26663
|
+
ExtractionJob,
|
|
26055
26664
|
Message,
|
|
26056
26665
|
Conversation,
|
|
26057
26666
|
ConversationSummary,
|
|
@@ -26069,7 +26678,7 @@ var sdkModelClasses = [
|
|
|
26069
26678
|
];
|
|
26070
26679
|
|
|
26071
26680
|
// src/lib/db/manager.ts
|
|
26072
|
-
var
|
|
26681
|
+
var import_watermelondb23 = require("@nozbe/watermelondb");
|
|
26073
26682
|
var DESTRUCTIVE_MIGRATION_VERSION = 8;
|
|
26074
26683
|
var webPlatformStorage = {
|
|
26075
26684
|
getItem: (key) => localStorage.getItem(key),
|
|
@@ -26150,7 +26759,7 @@ var DatabaseManager = class {
|
|
|
26150
26759
|
walletAddress
|
|
26151
26760
|
});
|
|
26152
26761
|
const adapter = this.createAdapter(dbName, sdkSchema, sdkMigrations);
|
|
26153
|
-
const database = new
|
|
26762
|
+
const database = new import_watermelondb23.Database({
|
|
26154
26763
|
adapter,
|
|
26155
26764
|
modelClasses: sdkModelClasses
|
|
26156
26765
|
});
|
|
@@ -26235,7 +26844,7 @@ function useDatabaseManager(walletAddress, manager) {
|
|
|
26235
26844
|
}
|
|
26236
26845
|
|
|
26237
26846
|
// src/lib/db/project/operations.ts
|
|
26238
|
-
var
|
|
26847
|
+
var import_watermelondb24 = require("@nozbe/watermelondb");
|
|
26239
26848
|
init_operations();
|
|
26240
26849
|
|
|
26241
26850
|
// src/lib/db/project/types.ts
|
|
@@ -26267,15 +26876,15 @@ async function createProjectOp(ctx, opts, defaultName = "New Project") {
|
|
|
26267
26876
|
return projectToStored(created);
|
|
26268
26877
|
}
|
|
26269
26878
|
async function getProjectOp(ctx, id) {
|
|
26270
|
-
const results = await ctx.projectsCollection.query(
|
|
26879
|
+
const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
|
|
26271
26880
|
return results.length > 0 ? projectToStored(results[0]) : null;
|
|
26272
26881
|
}
|
|
26273
26882
|
async function getProjectsOp(ctx) {
|
|
26274
|
-
const results = await ctx.projectsCollection.query(
|
|
26883
|
+
const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("is_deleted", false), import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)).fetch();
|
|
26275
26884
|
return results.map(projectToStored);
|
|
26276
26885
|
}
|
|
26277
26886
|
async function updateProjectNameOp(ctx, id, name) {
|
|
26278
|
-
const results = await ctx.projectsCollection.query(
|
|
26887
|
+
const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
|
|
26279
26888
|
if (results.length > 0) {
|
|
26280
26889
|
await ctx.database.write(async () => {
|
|
26281
26890
|
await results[0].update((proj) => {
|
|
@@ -26287,7 +26896,7 @@ async function updateProjectNameOp(ctx, id, name) {
|
|
|
26287
26896
|
return false;
|
|
26288
26897
|
}
|
|
26289
26898
|
async function updateProjectOp(ctx, id, opts) {
|
|
26290
|
-
const results = await ctx.projectsCollection.query(
|
|
26899
|
+
const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
|
|
26291
26900
|
if (results.length > 0) {
|
|
26292
26901
|
await ctx.database.write(async () => {
|
|
26293
26902
|
await results[0].update((proj) => {
|
|
@@ -26299,7 +26908,7 @@ async function updateProjectOp(ctx, id, opts) {
|
|
|
26299
26908
|
return false;
|
|
26300
26909
|
}
|
|
26301
26910
|
async function deleteProjectOp(ctx, id) {
|
|
26302
|
-
const results = await ctx.projectsCollection.query(
|
|
26911
|
+
const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
|
|
26303
26912
|
if (results.length > 0) {
|
|
26304
26913
|
await ctx.database.write(async () => {
|
|
26305
26914
|
await results[0].update((proj) => {
|
|
@@ -26312,18 +26921,18 @@ async function deleteProjectOp(ctx, id) {
|
|
|
26312
26921
|
}
|
|
26313
26922
|
async function getProjectConversationsOp(ctx, projectId) {
|
|
26314
26923
|
const results = await ctx.conversationsCollection.query(
|
|
26315
|
-
|
|
26316
|
-
|
|
26317
|
-
|
|
26924
|
+
import_watermelondb24.Q.where("project_id", projectId),
|
|
26925
|
+
import_watermelondb24.Q.where("is_deleted", false),
|
|
26926
|
+
import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)
|
|
26318
26927
|
).fetch();
|
|
26319
26928
|
return results.map(conversationToStoredRaw);
|
|
26320
26929
|
}
|
|
26321
26930
|
async function getProjectConversationCountOp(ctx, projectId) {
|
|
26322
|
-
return await ctx.conversationsCollection.query(
|
|
26931
|
+
return await ctx.conversationsCollection.query(import_watermelondb24.Q.where("project_id", projectId), import_watermelondb24.Q.where("is_deleted", false)).fetchCount();
|
|
26323
26932
|
}
|
|
26324
26933
|
|
|
26325
26934
|
// src/react/useFiles.ts
|
|
26326
|
-
var
|
|
26935
|
+
var import_watermelondb25 = require("@nozbe/watermelondb");
|
|
26327
26936
|
var import_react7 = require("react");
|
|
26328
26937
|
init_logger();
|
|
26329
26938
|
init_useEncryption();
|
|
@@ -26343,7 +26952,7 @@ function useFiles(options) {
|
|
|
26343
26952
|
setIsLoading(true);
|
|
26344
26953
|
try {
|
|
26345
26954
|
const coll = database.get("media");
|
|
26346
|
-
await coll.query(
|
|
26955
|
+
await coll.query(import_watermelondb25.Q.take(1)).fetch();
|
|
26347
26956
|
setMediaCollection(coll);
|
|
26348
26957
|
setIsReady(true);
|
|
26349
26958
|
} catch (error) {
|
|
@@ -26751,7 +27360,7 @@ function useFiles(options) {
|
|
|
26751
27360
|
}
|
|
26752
27361
|
|
|
26753
27362
|
// src/react/useProjects.ts
|
|
26754
|
-
var
|
|
27363
|
+
var import_watermelondb26 = require("@nozbe/watermelondb");
|
|
26755
27364
|
var import_react8 = require("react");
|
|
26756
27365
|
init_logger();
|
|
26757
27366
|
function useProjects(options) {
|
|
@@ -26774,7 +27383,7 @@ function useProjects(options) {
|
|
|
26774
27383
|
conversations: convColl?.table
|
|
26775
27384
|
});
|
|
26776
27385
|
getLogger().debug("[useProjects] Running test query on projects table...");
|
|
26777
|
-
const testResult = await projColl.query(
|
|
27386
|
+
const testResult = await projColl.query(import_watermelondb26.Q.take(1)).fetch();
|
|
26778
27387
|
getLogger().debug(
|
|
26779
27388
|
"[useProjects] Test query succeeded, found",
|
|
26780
27389
|
testResult.length,
|
|
@@ -26861,7 +27470,7 @@ function useProjects(options) {
|
|
|
26861
27470
|
if (!projectsCollection) {
|
|
26862
27471
|
return;
|
|
26863
27472
|
}
|
|
26864
|
-
const subscription = projectsCollection.query(
|
|
27473
|
+
const subscription = projectsCollection.query(import_watermelondb26.Q.where("is_deleted", false)).observe().subscribe((records) => {
|
|
26865
27474
|
setProjects(records.map(projectToStored));
|
|
26866
27475
|
});
|
|
26867
27476
|
return () => subscription.unsubscribe();
|
|
@@ -26984,7 +27593,7 @@ function useProjects(options) {
|
|
|
26984
27593
|
}
|
|
26985
27594
|
|
|
26986
27595
|
// src/lib/db/settings/operations.ts
|
|
26987
|
-
var
|
|
27596
|
+
var import_watermelondb27 = require("@nozbe/watermelondb");
|
|
26988
27597
|
function modelPreferenceToStored(preference) {
|
|
26989
27598
|
return {
|
|
26990
27599
|
uniqueId: preference.id,
|
|
@@ -26993,12 +27602,12 @@ function modelPreferenceToStored(preference) {
|
|
|
26993
27602
|
};
|
|
26994
27603
|
}
|
|
26995
27604
|
async function getModelPreferenceOp(ctx, walletAddress) {
|
|
26996
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
27605
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
|
|
26997
27606
|
return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
|
|
26998
27607
|
}
|
|
26999
27608
|
async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
27000
27609
|
const result = await ctx.database.write(async () => {
|
|
27001
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
27610
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
|
|
27002
27611
|
if (results.length > 0) {
|
|
27003
27612
|
const preference = results[0];
|
|
27004
27613
|
await preference.update((pref) => {
|
|
@@ -27016,7 +27625,7 @@ async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
|
27016
27625
|
return modelPreferenceToStored(result);
|
|
27017
27626
|
}
|
|
27018
27627
|
async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
27019
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
27628
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
|
|
27020
27629
|
if (results.length === 0) return false;
|
|
27021
27630
|
await ctx.database.write(async () => {
|
|
27022
27631
|
await results[0].destroyPermanently();
|
|
@@ -27025,11 +27634,11 @@ async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
|
27025
27634
|
}
|
|
27026
27635
|
|
|
27027
27636
|
// src/lib/db/settings/schema.ts
|
|
27028
|
-
var
|
|
27029
|
-
var settingsStorageSchema = (0,
|
|
27637
|
+
var import_watermelondb28 = require("@nozbe/watermelondb");
|
|
27638
|
+
var settingsStorageSchema = (0, import_watermelondb28.appSchema)({
|
|
27030
27639
|
version: 1,
|
|
27031
27640
|
tables: [
|
|
27032
|
-
(0,
|
|
27641
|
+
(0, import_watermelondb28.tableSchema)({
|
|
27033
27642
|
name: "modelPreferences",
|
|
27034
27643
|
columns: [
|
|
27035
27644
|
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
@@ -27040,7 +27649,7 @@ var settingsStorageSchema = (0, import_watermelondb26.appSchema)({
|
|
|
27040
27649
|
});
|
|
27041
27650
|
|
|
27042
27651
|
// src/lib/db/vaultFolders/operations.ts
|
|
27043
|
-
var
|
|
27652
|
+
var import_watermelondb29 = require("@nozbe/watermelondb");
|
|
27044
27653
|
function folderToStored(folder) {
|
|
27045
27654
|
return {
|
|
27046
27655
|
uniqueId: folder.id,
|
|
@@ -27065,7 +27674,7 @@ async function createVaultFolderOp(ctx, opts) {
|
|
|
27065
27674
|
return folderToStored(created);
|
|
27066
27675
|
}
|
|
27067
27676
|
async function getAllVaultFoldersOp(ctx) {
|
|
27068
|
-
const results = await ctx.vaultFolderCollection.query(
|
|
27677
|
+
const results = await ctx.vaultFolderCollection.query(import_watermelondb29.Q.where("is_deleted", false), import_watermelondb29.Q.sortBy("created_at", import_watermelondb29.Q.desc)).fetch();
|
|
27069
27678
|
return results.map(folderToStored);
|
|
27070
27679
|
}
|
|
27071
27680
|
async function updateVaultFolderOp(ctx, id, opts) {
|
|
@@ -27074,7 +27683,7 @@ async function updateVaultFolderOp(ctx, id, opts) {
|
|
|
27074
27683
|
if (record.isDeleted) return null;
|
|
27075
27684
|
const scopeChanged = opts.scope !== void 0 && opts.scope !== record.scope;
|
|
27076
27685
|
const updated = await ctx.database.write(async () => {
|
|
27077
|
-
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(
|
|
27686
|
+
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(import_watermelondb29.Q.where("folder_id", id), import_watermelondb29.Q.where("is_deleted", false)).fetch() : [];
|
|
27078
27687
|
const updates = [];
|
|
27079
27688
|
updates.push(
|
|
27080
27689
|
record.prepareUpdate((r) => {
|
|
@@ -27102,7 +27711,7 @@ async function deleteVaultFolderOp(ctx, id) {
|
|
|
27102
27711
|
const record = await ctx.vaultFolderCollection.find(id);
|
|
27103
27712
|
if (record.isDeleted) return false;
|
|
27104
27713
|
await ctx.database.write(async () => {
|
|
27105
|
-
const memories = await ctx.vaultMemoryCollection.query(
|
|
27714
|
+
const memories = await ctx.vaultMemoryCollection.query(import_watermelondb29.Q.where("folder_id", id), import_watermelondb29.Q.where("is_deleted", false)).fetch();
|
|
27106
27715
|
const preparedMemories = memories.map(
|
|
27107
27716
|
(memory) => memory.prepareUpdate((r) => {
|
|
27108
27717
|
r._setRaw("folder_id", null);
|
|
@@ -27171,7 +27780,7 @@ async function updateVaultFolderContextOp(ctx, id, context) {
|
|
|
27171
27780
|
}
|
|
27172
27781
|
}
|
|
27173
27782
|
async function getVaultFolderMemoryCountOp(ctx, folderId) {
|
|
27174
|
-
return await ctx.vaultMemoryCollection.query(
|
|
27783
|
+
return await ctx.vaultMemoryCollection.query(import_watermelondb29.Q.where("folder_id", folderId), import_watermelondb29.Q.where("is_deleted", false)).fetchCount();
|
|
27175
27784
|
}
|
|
27176
27785
|
|
|
27177
27786
|
// src/lib/db/vaultFolders/defaults.ts
|
|
@@ -27221,7 +27830,7 @@ init_types3();
|
|
|
27221
27830
|
var import_react9 = require("react");
|
|
27222
27831
|
|
|
27223
27832
|
// src/lib/db/userPreferences/operations.ts
|
|
27224
|
-
var
|
|
27833
|
+
var import_watermelondb30 = require("@nozbe/watermelondb");
|
|
27225
27834
|
function userPreferenceToStored(preference) {
|
|
27226
27835
|
return {
|
|
27227
27836
|
uniqueId: preference.id,
|
|
@@ -27236,7 +27845,7 @@ function userPreferenceToStored(preference) {
|
|
|
27236
27845
|
};
|
|
27237
27846
|
}
|
|
27238
27847
|
async function getUserPreferenceOp(ctx, walletAddress) {
|
|
27239
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
27848
|
+
const results = await ctx.userPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
|
|
27240
27849
|
return results.length > 0 ? userPreferenceToStored(results[0]) : null;
|
|
27241
27850
|
}
|
|
27242
27851
|
async function createUserPreferenceOp(ctx, opts) {
|
|
@@ -27256,7 +27865,7 @@ async function createUserPreferenceOp(ctx, opts) {
|
|
|
27256
27865
|
return userPreferenceToStored(created);
|
|
27257
27866
|
}
|
|
27258
27867
|
async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
27259
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
27868
|
+
const results = await ctx.userPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
|
|
27260
27869
|
if (results.length === 0) return null;
|
|
27261
27870
|
const preference = results[0];
|
|
27262
27871
|
await ctx.database.write(async () => {
|
|
@@ -27284,7 +27893,7 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
27284
27893
|
async function setUserPreferenceOp(ctx, walletAddress, opts) {
|
|
27285
27894
|
const now = Date.now();
|
|
27286
27895
|
const result = await ctx.database.write(async () => {
|
|
27287
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
27896
|
+
const results = await ctx.userPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
|
|
27288
27897
|
if (results.length > 0) {
|
|
27289
27898
|
const preference = results[0];
|
|
27290
27899
|
await preference.update((pref) => {
|
|
@@ -27332,7 +27941,7 @@ async function updateModelsOp(ctx, walletAddress, models) {
|
|
|
27332
27941
|
return updateUserPreferenceOp(ctx, walletAddress, { models });
|
|
27333
27942
|
}
|
|
27334
27943
|
async function deleteUserPreferenceOp(ctx, walletAddress) {
|
|
27335
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
27944
|
+
const results = await ctx.userPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
|
|
27336
27945
|
if (results.length === 0) return false;
|
|
27337
27946
|
await ctx.database.write(async () => {
|
|
27338
27947
|
await results[0].destroyPermanently();
|
|
@@ -27347,9 +27956,9 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
|
|
|
27347
27956
|
if (existing) {
|
|
27348
27957
|
return existing;
|
|
27349
27958
|
}
|
|
27350
|
-
const modelResults = await ctx.modelPreferencesCollection.query(
|
|
27959
|
+
const modelResults = await ctx.modelPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
|
|
27351
27960
|
const personalityKey = `${walletAddress}_personality_settings`;
|
|
27352
|
-
const personalityResults = await ctx.modelPreferencesCollection.query(
|
|
27961
|
+
const personalityResults = await ctx.modelPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", personalityKey)).fetch();
|
|
27353
27962
|
if (modelResults.length === 0 && personalityResults.length === 0) {
|
|
27354
27963
|
return null;
|
|
27355
27964
|
}
|
|
@@ -27391,11 +28000,11 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
|
|
|
27391
28000
|
}
|
|
27392
28001
|
|
|
27393
28002
|
// src/lib/db/userPreferences/schema.ts
|
|
27394
|
-
var
|
|
27395
|
-
var userPreferencesStorageSchema = (0,
|
|
28003
|
+
var import_watermelondb31 = require("@nozbe/watermelondb");
|
|
28004
|
+
var userPreferencesStorageSchema = (0, import_watermelondb31.appSchema)({
|
|
27396
28005
|
version: 1,
|
|
27397
28006
|
tables: [
|
|
27398
|
-
(0,
|
|
28007
|
+
(0, import_watermelondb31.tableSchema)({
|
|
27399
28008
|
name: "userPreferences",
|
|
27400
28009
|
columns: [
|
|
27401
28010
|
// Identity
|
|
@@ -27455,7 +28064,7 @@ var SLIDER_CONFIG = [
|
|
|
27455
28064
|
];
|
|
27456
28065
|
|
|
27457
28066
|
// src/react/userSettingsStore.ts
|
|
27458
|
-
var
|
|
28067
|
+
var import_watermelondb32 = require("@nozbe/watermelondb");
|
|
27459
28068
|
var EMPTY_SNAPSHOT = Object.freeze({
|
|
27460
28069
|
modelPreference: null,
|
|
27461
28070
|
userPreference: null,
|
|
@@ -27517,7 +28126,7 @@ async function startLoad(entry, walletAddress) {
|
|
|
27517
28126
|
}
|
|
27518
28127
|
function startObserve(entry, walletAddress) {
|
|
27519
28128
|
let isInitialEmission = true;
|
|
27520
|
-
entry.observeSub = entry.storageCtx.userPreferencesCollection.query(
|
|
28129
|
+
entry.observeSub = entry.storageCtx.userPreferencesCollection.query(import_watermelondb32.Q.where("wallet_address", walletAddress)).observeWithColumns([
|
|
27521
28130
|
"nickname",
|
|
27522
28131
|
"occupation",
|
|
27523
28132
|
"description",
|
|
@@ -27781,7 +28390,7 @@ function useSettings(options) {
|
|
|
27781
28390
|
}
|
|
27782
28391
|
|
|
27783
28392
|
// src/lib/db/appFiles/operations.ts
|
|
27784
|
-
var
|
|
28393
|
+
var import_watermelondb33 = require("@nozbe/watermelondb");
|
|
27785
28394
|
|
|
27786
28395
|
// src/utils/paths.ts
|
|
27787
28396
|
function normalizePath(p) {
|
|
@@ -27807,7 +28416,7 @@ async function putAppFileOp(ctx, conversationId, path, content) {
|
|
|
27807
28416
|
const normalized = normalizePath(path);
|
|
27808
28417
|
const now = Date.now();
|
|
27809
28418
|
const result = await ctx.database.write(async () => {
|
|
27810
|
-
const existing = await ctx.appFilesCollection.query(
|
|
28419
|
+
const existing = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId), import_watermelondb33.Q.where("path", normalized)).fetch();
|
|
27811
28420
|
if (existing.length > 0) {
|
|
27812
28421
|
await existing[0].update((f) => {
|
|
27813
28422
|
f._setRaw("content", content);
|
|
@@ -27827,11 +28436,11 @@ async function putAppFileOp(ctx, conversationId, path, content) {
|
|
|
27827
28436
|
}
|
|
27828
28437
|
async function getAppFileOp(ctx, conversationId, path) {
|
|
27829
28438
|
const normalized = normalizePath(path);
|
|
27830
|
-
const results = await ctx.appFilesCollection.query(
|
|
28439
|
+
const results = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId), import_watermelondb33.Q.where("path", normalized)).fetch();
|
|
27831
28440
|
return results.length > 0 ? appFileToStored(results[0]) : null;
|
|
27832
28441
|
}
|
|
27833
28442
|
async function getAppFilesOp(ctx, conversationId) {
|
|
27834
|
-
const results = await ctx.appFilesCollection.query(
|
|
28443
|
+
const results = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId)).fetch();
|
|
27835
28444
|
return results.map(appFileToStored);
|
|
27836
28445
|
}
|
|
27837
28446
|
async function getAppFileMapOp(ctx, conversationId) {
|
|
@@ -27842,7 +28451,7 @@ async function getAppFileMapOp(ctx, conversationId) {
|
|
|
27842
28451
|
}
|
|
27843
28452
|
async function deleteAppFileOp(ctx, conversationId, path) {
|
|
27844
28453
|
const normalized = normalizePath(path);
|
|
27845
|
-
const results = await ctx.appFilesCollection.query(
|
|
28454
|
+
const results = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId), import_watermelondb33.Q.where("path", normalized)).fetch();
|
|
27846
28455
|
if (results.length === 0) return false;
|
|
27847
28456
|
await ctx.database.write(async () => {
|
|
27848
28457
|
await results[0].destroyPermanently();
|
|
@@ -27850,7 +28459,7 @@ async function deleteAppFileOp(ctx, conversationId, path) {
|
|
|
27850
28459
|
return true;
|
|
27851
28460
|
}
|
|
27852
28461
|
async function deleteAllAppFilesOp(ctx, conversationId) {
|
|
27853
|
-
const results = await ctx.appFilesCollection.query(
|
|
28462
|
+
const results = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId)).fetch();
|
|
27854
28463
|
if (results.length === 0) return;
|
|
27855
28464
|
await ctx.database.write(async () => {
|
|
27856
28465
|
const batch = results.map((file) => file.prepareDestroyPermanently());
|
|
@@ -27859,7 +28468,7 @@ async function deleteAllAppFilesOp(ctx, conversationId) {
|
|
|
27859
28468
|
}
|
|
27860
28469
|
|
|
27861
28470
|
// src/lib/db/conversationMemory/operations.ts
|
|
27862
|
-
var
|
|
28471
|
+
var import_watermelondb34 = require("@nozbe/watermelondb");
|
|
27863
28472
|
var MAX_PER_CONVERSATION = 200;
|
|
27864
28473
|
function conversationMemoryToStored(row) {
|
|
27865
28474
|
return {
|
|
@@ -27874,7 +28483,7 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
27874
28483
|
if (!conversationId || items.length === 0) return;
|
|
27875
28484
|
const now = Date.now();
|
|
27876
28485
|
await ctx.database.write(async () => {
|
|
27877
|
-
const existing = await ctx.conversationMemoryCollection.query(
|
|
28486
|
+
const existing = await ctx.conversationMemoryCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.sortBy("created_at", import_watermelondb34.Q.asc)).fetch();
|
|
27878
28487
|
const seen = new Set(existing.map((r) => r.memoryId));
|
|
27879
28488
|
const batchSeen = /* @__PURE__ */ new Set();
|
|
27880
28489
|
const deduped = [];
|
|
@@ -27909,20 +28518,20 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
27909
28518
|
}
|
|
27910
28519
|
async function getConversationMemoriesOp(ctx, conversationId) {
|
|
27911
28520
|
if (!conversationId) return [];
|
|
27912
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
28521
|
+
const rows = await ctx.conversationMemoryCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.sortBy("created_at", import_watermelondb34.Q.asc)).fetch();
|
|
27913
28522
|
return rows.map(conversationMemoryToStored);
|
|
27914
28523
|
}
|
|
27915
28524
|
async function clearConversationMemoriesOp(ctx, conversationId) {
|
|
27916
28525
|
if (!conversationId) return;
|
|
27917
28526
|
await ctx.database.write(async () => {
|
|
27918
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
28527
|
+
const rows = await ctx.conversationMemoryCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId)).fetch();
|
|
27919
28528
|
if (rows.length === 0) return;
|
|
27920
28529
|
await ctx.database.batch(...rows.map((r) => r.prepareDestroyPermanently()));
|
|
27921
28530
|
});
|
|
27922
28531
|
}
|
|
27923
28532
|
|
|
27924
28533
|
// src/lib/db/savedTools/operations.ts
|
|
27925
|
-
var
|
|
28534
|
+
var import_watermelondb35 = require("@nozbe/watermelondb");
|
|
27926
28535
|
function savedToolToStored(tool) {
|
|
27927
28536
|
return {
|
|
27928
28537
|
uniqueId: tool.id,
|
|
@@ -27955,7 +28564,7 @@ async function createSavedToolOp(ctx, opts) {
|
|
|
27955
28564
|
return savedToolToStored(created);
|
|
27956
28565
|
}
|
|
27957
28566
|
async function getAllSavedToolsOp(ctx) {
|
|
27958
|
-
const results = await ctx.savedToolsCollection.query(
|
|
28567
|
+
const results = await ctx.savedToolsCollection.query(import_watermelondb35.Q.where("is_deleted", false), import_watermelondb35.Q.sortBy("created_at", import_watermelondb35.Q.desc)).fetch();
|
|
27959
28568
|
return results.map(savedToolToStored);
|
|
27960
28569
|
}
|
|
27961
28570
|
async function getSavedToolByIdOp(ctx, uniqueId) {
|
|
@@ -30496,9 +31105,9 @@ async function pushConversationToDropbox(database, conversationId, userAddress,
|
|
|
30496
31105
|
const filename = `${conversationId}.json`;
|
|
30497
31106
|
const existingFile = await findDropboxFile(token, filename, backupFolder);
|
|
30498
31107
|
if (existingFile) {
|
|
30499
|
-
const { Q:
|
|
31108
|
+
const { Q: Q19 } = await import("@nozbe/watermelondb");
|
|
30500
31109
|
const conversationsCollection = database.get("conversations");
|
|
30501
|
-
const records = await conversationsCollection.query(
|
|
31110
|
+
const records = await conversationsCollection.query(Q19.where("conversation_id", conversationId)).fetch();
|
|
30502
31111
|
if (records.length > 0) {
|
|
30503
31112
|
const conversation = conversationToStoredRaw(records[0]);
|
|
30504
31113
|
const localUpdated = conversation.updatedAt.getTime();
|
|
@@ -30536,9 +31145,9 @@ async function pushConversationToDropbox(database, conversationId, userAddress,
|
|
|
30536
31145
|
}
|
|
30537
31146
|
async function performDropboxExport(database, userAddress, token, deps, onProgress, backupFolder = DEFAULT_BACKUP_FOLDER) {
|
|
30538
31147
|
await deps.requestEncryptionKey(userAddress);
|
|
30539
|
-
const { Q:
|
|
31148
|
+
const { Q: Q19 } = await import("@nozbe/watermelondb");
|
|
30540
31149
|
const conversationsCollection = database.get("conversations");
|
|
30541
|
-
const records = await conversationsCollection.query(
|
|
31150
|
+
const records = await conversationsCollection.query(Q19.where("is_deleted", false)).fetch();
|
|
30542
31151
|
const conversations = records.map(conversationToStoredRaw);
|
|
30543
31152
|
const total = conversations.length;
|
|
30544
31153
|
if (total === 0) {
|
|
@@ -31179,9 +31788,9 @@ async function pushConversationToDrive(database, conversationId, userAddress, to
|
|
|
31179
31788
|
const filename = `${conversationId}.json`;
|
|
31180
31789
|
const existingFile = await findDriveFile(activeToken, folderId, filename);
|
|
31181
31790
|
if (existingFile) {
|
|
31182
|
-
const { Q:
|
|
31791
|
+
const { Q: Q19 } = await import("@nozbe/watermelondb");
|
|
31183
31792
|
const conversationsCollection = database.get("conversations");
|
|
31184
|
-
const records = await conversationsCollection.query(
|
|
31793
|
+
const records = await conversationsCollection.query(Q19.where("conversation_id", conversationId)).fetch();
|
|
31185
31794
|
if (records.length > 0) {
|
|
31186
31795
|
const conversation = conversationToStoredRaw(records[0]);
|
|
31187
31796
|
const localUpdated = conversation.updatedAt.getTime();
|
|
@@ -31234,9 +31843,9 @@ async function performGoogleDriveExport(database, userAddress, token, deps, onPr
|
|
|
31234
31843
|
return { success: false, uploaded: 0, skipped: 0, total: 0 };
|
|
31235
31844
|
}
|
|
31236
31845
|
const { token: activeToken } = folderResult;
|
|
31237
|
-
const { Q:
|
|
31846
|
+
const { Q: Q19 } = await import("@nozbe/watermelondb");
|
|
31238
31847
|
const conversationsCollection = database.get("conversations");
|
|
31239
|
-
const records = await conversationsCollection.query(
|
|
31848
|
+
const records = await conversationsCollection.query(Q19.where("is_deleted", false)).fetch();
|
|
31240
31849
|
const conversations = records.map(conversationToStoredRaw);
|
|
31241
31850
|
const total = conversations.length;
|
|
31242
31851
|
if (total === 0) {
|
|
@@ -31818,9 +32427,9 @@ async function pushConversationToICloud(database, conversationId, userAddress, d
|
|
|
31818
32427
|
const filename = `${conversationId}.json`;
|
|
31819
32428
|
const existingFile = await findICloudFile(filename);
|
|
31820
32429
|
if (existingFile) {
|
|
31821
|
-
const { Q:
|
|
32430
|
+
const { Q: Q19 } = await import("@nozbe/watermelondb");
|
|
31822
32431
|
const conversationsCollection = database.get("conversations");
|
|
31823
|
-
const records = await conversationsCollection.query(
|
|
32432
|
+
const records = await conversationsCollection.query(Q19.where("conversation_id", conversationId)).fetch();
|
|
31824
32433
|
if (records.length > 0) {
|
|
31825
32434
|
const conversation = conversationToStoredRaw(records[0]);
|
|
31826
32435
|
const localUpdated = conversation.updatedAt.getTime();
|
|
@@ -31850,9 +32459,9 @@ async function pushConversationToICloud(database, conversationId, userAddress, d
|
|
|
31850
32459
|
}
|
|
31851
32460
|
async function performICloudExport(database, userAddress, deps, onProgress) {
|
|
31852
32461
|
await deps.requestEncryptionKey(userAddress);
|
|
31853
|
-
const { Q:
|
|
32462
|
+
const { Q: Q19 } = await import("@nozbe/watermelondb");
|
|
31854
32463
|
const conversationsCollection = database.get("conversations");
|
|
31855
|
-
const records = await conversationsCollection.query(
|
|
32464
|
+
const records = await conversationsCollection.query(Q19.where("is_deleted", false)).fetch();
|
|
31856
32465
|
const conversations = records.map(conversationToStoredRaw);
|
|
31857
32466
|
const total = conversations.length;
|
|
31858
32467
|
if (total === 0) {
|
|
@@ -35710,6 +36319,7 @@ function renderAnumaJsx(jsx3) {
|
|
|
35710
36319
|
HARD_DELETE_WINDOW_MS,
|
|
35711
36320
|
ICloudAuthProvider,
|
|
35712
36321
|
INFERENCE_ID_HEADER,
|
|
36322
|
+
INTERNAL_FLOW_MARKER,
|
|
35713
36323
|
LoggerProvider,
|
|
35714
36324
|
MAX_HOPS,
|
|
35715
36325
|
MEDIUM_TTL_MS,
|
|
@@ -35758,6 +36368,7 @@ function renderAnumaJsx(jsx3) {
|
|
|
35758
36368
|
addConversationMemoriesOp,
|
|
35759
36369
|
appFileToStored,
|
|
35760
36370
|
archiveVaultMemoryOp,
|
|
36371
|
+
assembleMemoryContext,
|
|
35761
36372
|
backfillMemoryEntityUserIdsOp,
|
|
35762
36373
|
backfillMemoryTopicsOp,
|
|
35763
36374
|
capHopsForDensity,
|
|
@@ -35800,6 +36411,7 @@ function renderAnumaJsx(jsx3) {
|
|
|
35800
36411
|
createChunkVectorCache,
|
|
35801
36412
|
createCryptoPricePreProcessor,
|
|
35802
36413
|
createDecaySweeper,
|
|
36414
|
+
createDurableAutoExtractor,
|
|
35803
36415
|
createGitHubTools,
|
|
35804
36416
|
createLlmDecayClassifier,
|
|
35805
36417
|
createLlmNeighborRefiner,
|
|
@@ -35836,6 +36448,7 @@ function renderAnumaJsx(jsx3) {
|
|
|
35836
36448
|
deleteMediaByConversationOp,
|
|
35837
36449
|
deleteMediaByMessageOp,
|
|
35838
36450
|
deleteMediaOp,
|
|
36451
|
+
deleteMessageOp,
|
|
35839
36452
|
deleteProjectOp,
|
|
35840
36453
|
deleteSavedToolOp,
|
|
35841
36454
|
deleteVaultFolderOp,
|
|
@@ -36040,6 +36653,7 @@ function renderAnumaJsx(jsx3) {
|
|
|
36040
36653
|
setMemoryVisibilityOp,
|
|
36041
36654
|
settingsStorageSchema,
|
|
36042
36655
|
shouldChunkMessage,
|
|
36656
|
+
shouldRecallMemory,
|
|
36043
36657
|
shouldRefreshTools,
|
|
36044
36658
|
stampTopicsExtractedAtOp,
|
|
36045
36659
|
startGithubAuth,
|
|
@@ -36105,5 +36719,6 @@ function renderAnumaJsx(jsx3) {
|
|
|
36105
36719
|
verifyMemoriesForPublish,
|
|
36106
36720
|
walk,
|
|
36107
36721
|
webPlatformStorage,
|
|
36722
|
+
withInternalFlowMarker,
|
|
36108
36723
|
writeEncryptedFile
|
|
36109
36724
|
});
|