@anuma/sdk 8.0.0 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expo/index.cjs +354 -258
- package/dist/expo/index.mjs +306 -210
- package/dist/react/index.cjs +452 -351
- package/dist/react/index.mjs +398 -297
- package/dist/server/index.cjs +9 -1
- package/dist/server/index.mjs +9 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -1720,7 +1720,7 @@ ${appendix}` : appendix;
|
|
|
1720
1720
|
}
|
|
1721
1721
|
|
|
1722
1722
|
// src/lib/db/chat/operations.ts
|
|
1723
|
-
import { Q } from "@nozbe/watermelondb";
|
|
1723
|
+
import { Q as Q2 } from "@nozbe/watermelondb";
|
|
1724
1724
|
import { v7 as uuidv72 } from "uuid";
|
|
1725
1725
|
|
|
1726
1726
|
// src/lib/memoryEngine/vector.ts
|
|
@@ -2165,6 +2165,118 @@ async function assembleDecryptedMessage(message, address) {
|
|
|
2165
2165
|
return result;
|
|
2166
2166
|
}
|
|
2167
2167
|
|
|
2168
|
+
// src/lib/db/chat/toolCallEventIndex.ts
|
|
2169
|
+
import { Q } from "@nozbe/watermelondb";
|
|
2170
|
+
function parseEventIds(value) {
|
|
2171
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2172
|
+
let events;
|
|
2173
|
+
try {
|
|
2174
|
+
events = typeof value === "string" ? JSON.parse(value) : value;
|
|
2175
|
+
} catch {
|
|
2176
|
+
return ids;
|
|
2177
|
+
}
|
|
2178
|
+
if (!Array.isArray(events)) return ids;
|
|
2179
|
+
for (const event of events) {
|
|
2180
|
+
if (!event || typeof event !== "object") continue;
|
|
2181
|
+
const id = event.id;
|
|
2182
|
+
if (typeof id === "string" && id) ids.add(id);
|
|
2183
|
+
}
|
|
2184
|
+
return ids;
|
|
2185
|
+
}
|
|
2186
|
+
async function fetchEventRows(collection, conversationId) {
|
|
2187
|
+
try {
|
|
2188
|
+
return await collection.query(
|
|
2189
|
+
Q.unsafeSqlQuery(
|
|
2190
|
+
`select "id", "tool_call_events" from "history" where "conversation_id" = ? and "_status" != 'deleted' and "tool_call_events" is not null and "tool_call_events" not in ('', '[]')`,
|
|
2191
|
+
[conversationId]
|
|
2192
|
+
)
|
|
2193
|
+
).unsafeFetchRaw();
|
|
2194
|
+
} catch (error) {
|
|
2195
|
+
if (!(error instanceof Error) || !/unsafeSqlQuery.*not supported/.test(error.message)) {
|
|
2196
|
+
throw error;
|
|
2197
|
+
}
|
|
2198
|
+
return await collection.query(
|
|
2199
|
+
Q.where("conversation_id", conversationId),
|
|
2200
|
+
Q.where("tool_call_events", Q.notEq(null)),
|
|
2201
|
+
Q.where("tool_call_events", Q.notIn(["", "[]"])),
|
|
2202
|
+
Q.unsafeLokiTransform(
|
|
2203
|
+
(rows) => rows.map(({ id, tool_call_events }) => ({ id, tool_call_events }))
|
|
2204
|
+
)
|
|
2205
|
+
).unsafeFetchRaw();
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
var ToolCallEventIndex = class {
|
|
2209
|
+
constructor(collection) {
|
|
2210
|
+
this.collection = collection;
|
|
2211
|
+
this.conversations = /* @__PURE__ */ new Map();
|
|
2212
|
+
this.messages = /* @__PURE__ */ new Map();
|
|
2213
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
2214
|
+
this.resetCount = collection.database._resetCount;
|
|
2215
|
+
collection.experimentalSubscribe((changes) => {
|
|
2216
|
+
for (const { record: record2, type } of changes) {
|
|
2217
|
+
this.replace(
|
|
2218
|
+
record2.id,
|
|
2219
|
+
type === "destroyed" ? void 0 : record2.conversationId,
|
|
2220
|
+
type === "destroyed" ? void 0 : record2._getRaw("tool_call_events")
|
|
2221
|
+
);
|
|
2222
|
+
}
|
|
2223
|
+
});
|
|
2224
|
+
}
|
|
2225
|
+
replace(messageId, conversationId, value) {
|
|
2226
|
+
const previous = this.messages.get(messageId);
|
|
2227
|
+
if (previous) {
|
|
2228
|
+
const counts2 = this.conversations.get(previous.conversationId);
|
|
2229
|
+
for (const id of previous.ids) {
|
|
2230
|
+
const count2 = counts2.get(id) - 1;
|
|
2231
|
+
if (count2 === 0) counts2.delete(id);
|
|
2232
|
+
else counts2.set(id, count2);
|
|
2233
|
+
}
|
|
2234
|
+
this.messages.delete(messageId);
|
|
2235
|
+
}
|
|
2236
|
+
const counts = conversationId === void 0 ? void 0 : this.conversations.get(conversationId);
|
|
2237
|
+
if (!counts || conversationId === void 0) return;
|
|
2238
|
+
const ids = parseEventIds(value);
|
|
2239
|
+
if (ids.size === 0) return;
|
|
2240
|
+
this.messages.set(messageId, { conversationId, ids });
|
|
2241
|
+
for (const id of ids) counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
2242
|
+
}
|
|
2243
|
+
async get(conversationId) {
|
|
2244
|
+
if (this.resetCount !== this.collection.database._resetCount) {
|
|
2245
|
+
this.conversations.clear();
|
|
2246
|
+
this.messages.clear();
|
|
2247
|
+
this.pending.clear();
|
|
2248
|
+
this.resetCount = this.collection.database._resetCount;
|
|
2249
|
+
}
|
|
2250
|
+
if (!this.conversations.has(conversationId)) {
|
|
2251
|
+
let pending = this.pending.get(conversationId);
|
|
2252
|
+
if (!pending) {
|
|
2253
|
+
pending = this.collection.database.read(async () => {
|
|
2254
|
+
const rows = await fetchEventRows(this.collection, conversationId);
|
|
2255
|
+
this.conversations.set(conversationId, /* @__PURE__ */ new Map());
|
|
2256
|
+
for (const row of rows)
|
|
2257
|
+
this.replace(String(row.id), conversationId, row.tool_call_events);
|
|
2258
|
+
});
|
|
2259
|
+
this.pending.set(conversationId, pending);
|
|
2260
|
+
}
|
|
2261
|
+
try {
|
|
2262
|
+
await pending;
|
|
2263
|
+
} finally {
|
|
2264
|
+
this.pending.delete(conversationId);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
return new Set(this.conversations.get(conversationId).keys());
|
|
2268
|
+
}
|
|
2269
|
+
};
|
|
2270
|
+
var indexes = /* @__PURE__ */ new WeakMap();
|
|
2271
|
+
function getToolCallEventIds(collection, conversationId) {
|
|
2272
|
+
let index = indexes.get(collection);
|
|
2273
|
+
if (!index) {
|
|
2274
|
+
index = new ToolCallEventIndex(collection);
|
|
2275
|
+
indexes.set(collection, index);
|
|
2276
|
+
}
|
|
2277
|
+
return index.get(conversationId);
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2168
2280
|
// src/lib/db/chat/types.ts
|
|
2169
2281
|
import { v7 as uuidv7 } from "uuid";
|
|
2170
2282
|
|
|
@@ -2557,7 +2669,7 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
|
|
|
2557
2669
|
);
|
|
2558
2670
|
}
|
|
2559
2671
|
async function getConversationOp(ctx, id) {
|
|
2560
|
-
const results = await ctx.conversationsCollection.query(
|
|
2672
|
+
const results = await ctx.conversationsCollection.query(Q2.where("conversation_id", id), Q2.where("is_deleted", false)).fetch();
|
|
2561
2673
|
return results.length > 0 ? await conversationToStored(
|
|
2562
2674
|
results[0],
|
|
2563
2675
|
ctx.walletAddress,
|
|
@@ -2566,7 +2678,7 @@ async function getConversationOp(ctx, id) {
|
|
|
2566
2678
|
) : null;
|
|
2567
2679
|
}
|
|
2568
2680
|
async function getConversationsOp(ctx) {
|
|
2569
|
-
const results = await ctx.conversationsCollection.query(
|
|
2681
|
+
const results = await ctx.conversationsCollection.query(Q2.where("is_deleted", false), Q2.sortBy("created_at", Q2.desc)).unsafeFetchRaw();
|
|
2570
2682
|
return Promise.all(
|
|
2571
2683
|
results.map(
|
|
2572
2684
|
(raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -2587,33 +2699,33 @@ function conversationRawToLazyStored(raw) {
|
|
|
2587
2699
|
};
|
|
2588
2700
|
}
|
|
2589
2701
|
async function getConversationsLazyOp(ctx) {
|
|
2590
|
-
const results = await ctx.conversationsCollection.query(
|
|
2702
|
+
const results = await ctx.conversationsCollection.query(Q2.where("is_deleted", false), Q2.sortBy("created_at", Q2.desc)).unsafeFetchRaw();
|
|
2591
2703
|
return results.map(conversationRawToLazyStored);
|
|
2592
2704
|
}
|
|
2593
2705
|
async function getConversationsPageOp(ctx, options) {
|
|
2594
2706
|
const limit = Math.floor(options?.limit ?? 200);
|
|
2595
2707
|
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
2596
2708
|
const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
|
|
2597
|
-
const clauses = [
|
|
2709
|
+
const clauses = [Q2.where("is_deleted", false)];
|
|
2598
2710
|
if (options?.before !== void 0) {
|
|
2599
2711
|
clauses.push(
|
|
2600
|
-
exclude.size > 0 ?
|
|
2712
|
+
exclude.size > 0 ? Q2.where("created_at", Q2.lte(options.before)) : Q2.where("created_at", Q2.lt(options.before))
|
|
2601
2713
|
);
|
|
2602
2714
|
}
|
|
2603
|
-
const fetched = await ctx.conversationsCollection.query(...clauses,
|
|
2715
|
+
const fetched = await ctx.conversationsCollection.query(...clauses, Q2.sortBy("created_at", Q2.desc), Q2.take(limit + exclude.size)).unsafeFetchRaw();
|
|
2604
2716
|
const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
|
|
2605
2717
|
return results.slice(0, limit).map(conversationRawToLazyStored);
|
|
2606
2718
|
}
|
|
2607
2719
|
async function getConversationsByProjectLazyOp(ctx, projectId) {
|
|
2608
2720
|
const results = await ctx.conversationsCollection.query(
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2721
|
+
Q2.where("project_id", projectId === null ? "" : projectId),
|
|
2722
|
+
Q2.where("is_deleted", false),
|
|
2723
|
+
Q2.sortBy("created_at", Q2.desc)
|
|
2612
2724
|
).unsafeFetchRaw();
|
|
2613
2725
|
return results.map(conversationRawToLazyStored);
|
|
2614
2726
|
}
|
|
2615
2727
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
2616
|
-
const results = await ctx.conversationsCollection.query(
|
|
2728
|
+
const results = await ctx.conversationsCollection.query(Q2.where("conversation_id", id), Q2.where("is_deleted", false)).fetch();
|
|
2617
2729
|
if (results.length > 0) {
|
|
2618
2730
|
const encryptedOpts = ctx.walletAddress && ctx.signMessage ? await encryptConversationFields(
|
|
2619
2731
|
{ title },
|
|
@@ -2632,13 +2744,13 @@ async function updateConversationTitleOp(ctx, id, title) {
|
|
|
2632
2744
|
return false;
|
|
2633
2745
|
}
|
|
2634
2746
|
async function deleteConversationOp(ctx, id) {
|
|
2635
|
-
const results = await ctx.conversationsCollection.query(
|
|
2747
|
+
const results = await ctx.conversationsCollection.query(Q2.where("conversation_id", id), Q2.where("is_deleted", false)).fetch();
|
|
2636
2748
|
if (results.length > 0) {
|
|
2637
2749
|
await ctx.database.write(async () => {
|
|
2638
2750
|
await results[0].update((conv) => {
|
|
2639
2751
|
conv._setRaw("is_deleted", true);
|
|
2640
2752
|
});
|
|
2641
|
-
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(
|
|
2753
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(Q2.where("conversation_id", id)).fetch() : [];
|
|
2642
2754
|
for (const job of jobs) await job.destroyPermanently();
|
|
2643
2755
|
});
|
|
2644
2756
|
return true;
|
|
@@ -2646,7 +2758,7 @@ async function deleteConversationOp(ctx, id) {
|
|
|
2646
2758
|
return false;
|
|
2647
2759
|
}
|
|
2648
2760
|
async function updateConversationProjectOp(ctx, id, projectId) {
|
|
2649
|
-
const results = await ctx.conversationsCollection.query(
|
|
2761
|
+
const results = await ctx.conversationsCollection.query(Q2.where("conversation_id", id), Q2.where("is_deleted", false)).fetch();
|
|
2650
2762
|
if (results.length > 0) {
|
|
2651
2763
|
await ctx.database.write(async () => {
|
|
2652
2764
|
await results[0].update((conv) => {
|
|
@@ -2658,7 +2770,7 @@ async function updateConversationProjectOp(ctx, id, projectId) {
|
|
|
2658
2770
|
return false;
|
|
2659
2771
|
}
|
|
2660
2772
|
async function updateConversationPinnedOp(ctx, id, pinned) {
|
|
2661
|
-
const results = await ctx.conversationsCollection.query(
|
|
2773
|
+
const results = await ctx.conversationsCollection.query(Q2.where("conversation_id", id), Q2.where("is_deleted", false)).fetch();
|
|
2662
2774
|
if (results.length > 0) {
|
|
2663
2775
|
await ctx.database.write(async () => {
|
|
2664
2776
|
await results[0].update((conv) => {
|
|
@@ -2671,9 +2783,9 @@ async function updateConversationPinnedOp(ctx, id, pinned) {
|
|
|
2671
2783
|
}
|
|
2672
2784
|
async function getConversationsByProjectOp(ctx, projectId) {
|
|
2673
2785
|
const results = await ctx.conversationsCollection.query(
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2786
|
+
Q2.where("project_id", projectId === null ? "" : projectId),
|
|
2787
|
+
Q2.where("is_deleted", false),
|
|
2788
|
+
Q2.sortBy("created_at", Q2.desc)
|
|
2677
2789
|
).unsafeFetchRaw();
|
|
2678
2790
|
return Promise.all(
|
|
2679
2791
|
results.map(
|
|
@@ -2682,7 +2794,7 @@ async function getConversationsByProjectOp(ctx, projectId) {
|
|
|
2682
2794
|
);
|
|
2683
2795
|
}
|
|
2684
2796
|
async function getMessagesOp(ctx, convId, opts) {
|
|
2685
|
-
const fetched = await ctx.messagesCollection.query(
|
|
2797
|
+
const fetched = await ctx.messagesCollection.query(Q2.where("conversation_id", convId), Q2.sortBy("message_id", Q2.asc)).unsafeFetchRaw();
|
|
2686
2798
|
const results = opts?.rawFilter ? fetched.filter(opts.rawFilter) : fetched;
|
|
2687
2799
|
return Promise.all(
|
|
2688
2800
|
results.map(
|
|
@@ -2691,19 +2803,19 @@ async function getMessagesOp(ctx, convId, opts) {
|
|
|
2691
2803
|
);
|
|
2692
2804
|
}
|
|
2693
2805
|
async function getMessageCountOp(ctx, convId) {
|
|
2694
|
-
return await ctx.messagesCollection.query(
|
|
2806
|
+
return await ctx.messagesCollection.query(Q2.where("conversation_id", convId)).fetchCount();
|
|
2695
2807
|
}
|
|
2696
2808
|
async function getMessagesPageOp(ctx, convId, opts) {
|
|
2697
2809
|
const limit = Math.floor(opts.limit);
|
|
2698
2810
|
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
2699
2811
|
const exclude = new Set(opts.boundaryExcludeUniqueIds ?? []);
|
|
2700
|
-
const clauses = [
|
|
2812
|
+
const clauses = [Q2.where("conversation_id", convId)];
|
|
2701
2813
|
if (opts.beforeMessageId !== void 0) {
|
|
2702
2814
|
clauses.push(
|
|
2703
|
-
exclude.size > 0 ?
|
|
2815
|
+
exclude.size > 0 ? Q2.where("message_id", Q2.lte(opts.beforeMessageId)) : Q2.where("message_id", Q2.lt(opts.beforeMessageId))
|
|
2704
2816
|
);
|
|
2705
2817
|
}
|
|
2706
|
-
const fetched = await ctx.messagesCollection.query(...clauses,
|
|
2818
|
+
const fetched = await ctx.messagesCollection.query(...clauses, Q2.sortBy("message_id", Q2.desc), Q2.take(limit + exclude.size)).unsafeFetchRaw();
|
|
2707
2819
|
const results = (exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched).slice(0, limit);
|
|
2708
2820
|
results.reverse();
|
|
2709
2821
|
return Promise.all(
|
|
@@ -2715,7 +2827,7 @@ async function getMessagesPageOp(ctx, convId, opts) {
|
|
|
2715
2827
|
);
|
|
2716
2828
|
}
|
|
2717
2829
|
async function getMessageSkeletonsOp(ctx, convId) {
|
|
2718
|
-
const results = await ctx.messagesCollection.query(
|
|
2830
|
+
const results = await ctx.messagesCollection.query(Q2.where("conversation_id", convId), Q2.sortBy("message_id", Q2.asc)).unsafeFetchRaw();
|
|
2719
2831
|
const roleById = /* @__PURE__ */ new Map();
|
|
2720
2832
|
for (const raw of results) {
|
|
2721
2833
|
roleById.set(raw.id, raw.role);
|
|
@@ -2760,32 +2872,12 @@ async function getMessageSkeletonsOp(ctx, convId) {
|
|
|
2760
2872
|
return skeletons;
|
|
2761
2873
|
}
|
|
2762
2874
|
async function getToolCallEventIdsOp(ctx, convId) {
|
|
2763
|
-
|
|
2764
|
-
const ids = /* @__PURE__ */ new Set();
|
|
2765
|
-
for (const raw of results) {
|
|
2766
|
-
const value = raw.tool_call_events;
|
|
2767
|
-
if (!value) continue;
|
|
2768
|
-
let events;
|
|
2769
|
-
if (typeof value === "string") {
|
|
2770
|
-
try {
|
|
2771
|
-
events = JSON.parse(value);
|
|
2772
|
-
} catch {
|
|
2773
|
-
continue;
|
|
2774
|
-
}
|
|
2775
|
-
} else if (Array.isArray(value)) {
|
|
2776
|
-
events = value;
|
|
2777
|
-
}
|
|
2778
|
-
if (!Array.isArray(events)) continue;
|
|
2779
|
-
for (const evt of events) {
|
|
2780
|
-
if (evt && evt.id) ids.add(evt.id);
|
|
2781
|
-
}
|
|
2782
|
-
}
|
|
2783
|
-
return ids;
|
|
2875
|
+
return getToolCallEventIds(ctx.messagesCollection, convId);
|
|
2784
2876
|
}
|
|
2785
2877
|
async function clearMessagesOp(ctx, convId) {
|
|
2786
2878
|
await ctx.database.write(async () => {
|
|
2787
|
-
const messages = await ctx.messagesCollection.query(
|
|
2788
|
-
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(
|
|
2879
|
+
const messages = await ctx.messagesCollection.query(Q2.where("conversation_id", convId)).fetch();
|
|
2880
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(Q2.where("conversation_id", convId)).fetch() : [];
|
|
2789
2881
|
for (const job of jobs) {
|
|
2790
2882
|
await job.update((row) => {
|
|
2791
2883
|
row._setRaw("message_ids", "[]");
|
|
@@ -2810,7 +2902,7 @@ async function deleteMessageOp(ctx, uniqueId) {
|
|
|
2810
2902
|
return null;
|
|
2811
2903
|
}
|
|
2812
2904
|
await ctx.database.write(async () => {
|
|
2813
|
-
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(
|
|
2905
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(Q2.where("conversation_id", message.conversationId)).fetch() : [];
|
|
2814
2906
|
for (const job of jobs) {
|
|
2815
2907
|
const ids = JSON.parse(String(job._getRaw("message_ids")));
|
|
2816
2908
|
await job.update((row) => {
|
|
@@ -2883,9 +2975,9 @@ async function createMessageOp(ctx, opts) {
|
|
|
2883
2975
|
}
|
|
2884
2976
|
}
|
|
2885
2977
|
const newest = await ctx.messagesCollection.query(
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2978
|
+
Q2.where("conversation_id", opts.conversationId),
|
|
2979
|
+
Q2.sortBy("message_id", Q2.desc),
|
|
2980
|
+
Q2.take(1)
|
|
2889
2981
|
).fetch();
|
|
2890
2982
|
const messageId = (newest[0]?.messageId ?? 0) + 1;
|
|
2891
2983
|
const encryptedOpts = await encryptMessageOptsIfNeeded(ctx, opts);
|
|
@@ -2981,13 +3073,13 @@ async function decryptMessageEmbeddingFields(raw, walletAddress) {
|
|
|
2981
3073
|
async function sealLegacyMessageEmbeddingsOp(ctx) {
|
|
2982
3074
|
if (!ctx.walletAddress) return 0;
|
|
2983
3075
|
const candidateIds = await ctx.messagesCollection.query(
|
|
2984
|
-
|
|
2985
|
-
|
|
3076
|
+
Q2.where("content", Q2.like("enc:%")),
|
|
3077
|
+
Q2.or(
|
|
2986
3078
|
...["vector", "chunks"].map(
|
|
2987
|
-
(column) =>
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
3079
|
+
(column) => Q2.and(
|
|
3080
|
+
Q2.where(column, Q2.notEq(null)),
|
|
3081
|
+
Q2.where(column, Q2.notEq("")),
|
|
3082
|
+
Q2.where(column, Q2.notLike("enc:%"))
|
|
2991
3083
|
)
|
|
2992
3084
|
)
|
|
2993
3085
|
)
|
|
@@ -2997,7 +3089,7 @@ async function sealLegacyMessageEmbeddingsOp(ctx) {
|
|
|
2997
3089
|
for (let start = 0; start < candidateIds.length; start += 50) {
|
|
2998
3090
|
const pageIds = candidateIds.slice(start, start + 50);
|
|
2999
3091
|
await ctx.database.write(async () => {
|
|
3000
|
-
const pageMessages = await ctx.messagesCollection.query(
|
|
3092
|
+
const pageMessages = await ctx.messagesCollection.query(Q2.where("id", Q2.oneOf(pageIds))).fetch();
|
|
3001
3093
|
for (const message of pageMessages) {
|
|
3002
3094
|
if (!isEncrypted(message.content)) continue;
|
|
3003
3095
|
const content = await decryptFieldDetailed(message.content, ctx.walletAddress);
|
|
@@ -3078,15 +3170,15 @@ function chunksWithoutText(raw) {
|
|
|
3078
3170
|
});
|
|
3079
3171
|
}
|
|
3080
3172
|
async function stripLegacyChunkTextOp(ctx) {
|
|
3081
|
-
const candidateIds = await ctx.messagesCollection.query(
|
|
3173
|
+
const candidateIds = await ctx.messagesCollection.query(Q2.where("chunks", Q2.like(`%${Q2.sanitizeLikeString('"text":')}%`))).fetchIds();
|
|
3082
3174
|
let stripped = 0;
|
|
3083
3175
|
for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
|
|
3084
3176
|
const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
|
|
3085
|
-
const rows = await ctx.messagesCollection.query(
|
|
3177
|
+
const rows = await ctx.messagesCollection.query(Q2.where("id", Q2.oneOf(pageIds))).unsafeFetchRaw();
|
|
3086
3178
|
const changedIds = rows.filter((row) => chunksWithoutText(row.chunks) !== null).map((row) => String(row.id));
|
|
3087
3179
|
if (changedIds.length === 0) continue;
|
|
3088
3180
|
await ctx.database.write(async () => {
|
|
3089
|
-
const messages = await ctx.messagesCollection.query(
|
|
3181
|
+
const messages = await ctx.messagesCollection.query(Q2.where("id", Q2.oneOf(changedIds))).fetch();
|
|
3090
3182
|
const updates = messages.flatMap((message) => {
|
|
3091
3183
|
const raw = message._raw;
|
|
3092
3184
|
const chunks3 = chunksWithoutText(raw.chunks);
|
|
@@ -3133,13 +3225,13 @@ async function encryptToolCallEventsOp(ctx) {
|
|
|
3133
3225
|
return 0;
|
|
3134
3226
|
}
|
|
3135
3227
|
const candidateIds = await ctx.messagesCollection.query(
|
|
3136
|
-
|
|
3137
|
-
|
|
3228
|
+
Q2.where("tool_call_events", Q2.notEq(null)),
|
|
3229
|
+
Q2.where("tool_call_events", Q2.notIn(["", "[]"]))
|
|
3138
3230
|
).fetchIds();
|
|
3139
3231
|
let encrypted = 0;
|
|
3140
3232
|
for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
|
|
3141
3233
|
const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
|
|
3142
|
-
const rows = await ctx.messagesCollection.query(
|
|
3234
|
+
const rows = await ctx.messagesCollection.query(Q2.where("id", Q2.oneOf(pageIds))).unsafeFetchRaw();
|
|
3143
3235
|
const repairs = /* @__PURE__ */ new Map();
|
|
3144
3236
|
for (const row of rows) {
|
|
3145
3237
|
const column = await encryptedToolCallEventsColumn(
|
|
@@ -3152,12 +3244,12 @@ async function encryptToolCallEventsOp(ctx) {
|
|
|
3152
3244
|
}
|
|
3153
3245
|
if (repairs.size === 0) continue;
|
|
3154
3246
|
await ctx.database.write(async () => {
|
|
3155
|
-
const messages = (await ctx.messagesCollection.query(
|
|
3247
|
+
const messages = (await ctx.messagesCollection.query(Q2.where("id", Q2.oneOf([...repairs.keys()]))).fetch()).filter(
|
|
3156
3248
|
(message) => message._raw.tool_call_events === repairs.get(message.id)?.raw
|
|
3157
3249
|
);
|
|
3158
3250
|
if (messages.length === 0) return;
|
|
3159
3251
|
const conversationIds = [...new Set(messages.map((message) => message.conversationId))];
|
|
3160
|
-
const conversations = await ctx.conversationsCollection.query(
|
|
3252
|
+
const conversations = await ctx.conversationsCollection.query(Q2.where("conversation_id", Q2.oneOf(conversationIds))).fetch();
|
|
3161
3253
|
await ctx.database.batch(
|
|
3162
3254
|
...messages.map(
|
|
3163
3255
|
(message) => message.prepareUpdate((msg) => {
|
|
@@ -3184,7 +3276,7 @@ async function savedKeyOpensExistingData(ctx, address, signMessage, embeddedWall
|
|
|
3184
3276
|
return refreshEncryptionKeyIfMatches(address, v2Probe, signMessage, embeddedWalletSigner);
|
|
3185
3277
|
}
|
|
3186
3278
|
async function findEncryptedContent(ctx, pattern) {
|
|
3187
|
-
const [row] = await ctx.messagesCollection.query(
|
|
3279
|
+
const [row] = await ctx.messagesCollection.query(Q2.where("content", Q2.like(pattern)), Q2.take(1)).unsafeFetchRaw();
|
|
3188
3280
|
return row ? String(row.content) : null;
|
|
3189
3281
|
}
|
|
3190
3282
|
async function updateMessageErrorOp(ctx, uniqueId, error) {
|
|
@@ -3303,11 +3395,11 @@ async function readRawJsonField(raw, column, walletAddress) {
|
|
|
3303
3395
|
}
|
|
3304
3396
|
async function searchMessagesOp(ctx, queryVector, options) {
|
|
3305
3397
|
const { limit = 10, minSimilarity = 0.5, conversationId } = options || {};
|
|
3306
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
3398
|
+
const activeConversations = await ctx.conversationsCollection.query(Q2.where("is_deleted", false)).fetch();
|
|
3307
3399
|
const activeConversationIds = new Set(
|
|
3308
3400
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
3309
3401
|
);
|
|
3310
|
-
const queryConditions = conversationId ? [
|
|
3402
|
+
const queryConditions = conversationId ? [Q2.where("conversation_id", conversationId)] : [];
|
|
3311
3403
|
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
3312
3404
|
const candidates = [];
|
|
3313
3405
|
for (const message of messages) {
|
|
@@ -3346,7 +3438,7 @@ function toChunkCandidateKey(raw) {
|
|
|
3346
3438
|
}
|
|
3347
3439
|
async function fetchRowsByIds(ctx, ids) {
|
|
3348
3440
|
if (ids.length === 0) return [];
|
|
3349
|
-
return await ctx.messagesCollection.query(
|
|
3441
|
+
return await ctx.messagesCollection.query(Q2.where("id", Q2.oneOf(ids))).unsafeFetchRaw();
|
|
3350
3442
|
}
|
|
3351
3443
|
async function projectedChunkRowSource(ctx, filter) {
|
|
3352
3444
|
const clauses = [
|
|
@@ -3364,7 +3456,7 @@ async function projectedChunkRowSource(ctx, filter) {
|
|
|
3364
3456
|
args.push(filter.excludeConversationId);
|
|
3365
3457
|
}
|
|
3366
3458
|
const keyRows = await ctx.messagesCollection.query(
|
|
3367
|
-
|
|
3459
|
+
Q2.unsafeSqlQuery(
|
|
3368
3460
|
`select "id", "conversation_id", "updated_at", "embedding_model" from "history" where ${clauses.join(" and ")}`,
|
|
3369
3461
|
args
|
|
3370
3462
|
)
|
|
@@ -3374,7 +3466,7 @@ async function projectedChunkRowSource(ctx, filter) {
|
|
|
3374
3466
|
loadVectorRows: async (ids) => {
|
|
3375
3467
|
if (ids.length === 0) return [];
|
|
3376
3468
|
return await ctx.messagesCollection.query(
|
|
3377
|
-
|
|
3469
|
+
Q2.unsafeSqlQuery(
|
|
3378
3470
|
`select "id", "updated_at", "chunks", "vector" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
3379
3471
|
ids
|
|
3380
3472
|
)
|
|
@@ -3384,11 +3476,11 @@ async function projectedChunkRowSource(ctx, filter) {
|
|
|
3384
3476
|
};
|
|
3385
3477
|
}
|
|
3386
3478
|
async function fullScanChunkRowSource(ctx, filter) {
|
|
3387
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
3479
|
+
const activeConversations = await ctx.conversationsCollection.query(Q2.where("is_deleted", false)).fetch();
|
|
3388
3480
|
const activeConversationIds = new Set(
|
|
3389
3481
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
3390
3482
|
);
|
|
3391
|
-
const queryConditions = filter.conversationId !== void 0 ? [
|
|
3483
|
+
const queryConditions = filter.conversationId !== void 0 ? [Q2.where("conversation_id", filter.conversationId)] : [];
|
|
3392
3484
|
const rows = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
3393
3485
|
const rowsById = /* @__PURE__ */ new Map();
|
|
3394
3486
|
for (const row of rows) {
|
|
@@ -3595,12 +3687,12 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
3595
3687
|
}
|
|
3596
3688
|
async function getAllFilesOp(ctx, options) {
|
|
3597
3689
|
const { conversationId, limit } = options || {};
|
|
3598
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
3690
|
+
const activeConversations = await ctx.conversationsCollection.query(Q2.where("is_deleted", false)).fetch();
|
|
3599
3691
|
const activeConversationIds = new Set(
|
|
3600
3692
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
3601
3693
|
);
|
|
3602
|
-
const queryConditions = conversationId ? [
|
|
3603
|
-
const messages = await ctx.messagesCollection.query(...queryConditions,
|
|
3694
|
+
const queryConditions = conversationId ? [Q2.where("conversation_id", conversationId)] : [];
|
|
3695
|
+
const messages = await ctx.messagesCollection.query(...queryConditions, Q2.sortBy("created_at", Q2.desc)).fetch();
|
|
3604
3696
|
const filesWithContext = [];
|
|
3605
3697
|
for (const message of messages) {
|
|
3606
3698
|
const msgConvId = String(message._getRaw("conversation_id"));
|
|
@@ -9999,7 +10091,7 @@ __decorateClass([
|
|
|
9999
10091
|
], AppFile.prototype, "updatedAt", 2);
|
|
10000
10092
|
|
|
10001
10093
|
// src/lib/db/appFiles/operations.ts
|
|
10002
|
-
import { Q as
|
|
10094
|
+
import { Q as Q3 } from "@nozbe/watermelondb";
|
|
10003
10095
|
|
|
10004
10096
|
// src/utils/paths.ts
|
|
10005
10097
|
function normalizePath(p) {
|
|
@@ -10025,7 +10117,7 @@ async function putAppFileOp(ctx, conversationId, path, content) {
|
|
|
10025
10117
|
const normalized = normalizePath(path);
|
|
10026
10118
|
const now = Date.now();
|
|
10027
10119
|
const result = await ctx.database.write(async () => {
|
|
10028
|
-
const existing = await ctx.appFilesCollection.query(
|
|
10120
|
+
const existing = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId), Q3.where("path", normalized)).fetch();
|
|
10029
10121
|
if (existing.length > 0) {
|
|
10030
10122
|
await existing[0].update((f) => {
|
|
10031
10123
|
f._setRaw("content", content);
|
|
@@ -10045,11 +10137,11 @@ async function putAppFileOp(ctx, conversationId, path, content) {
|
|
|
10045
10137
|
}
|
|
10046
10138
|
async function getAppFileOp(ctx, conversationId, path) {
|
|
10047
10139
|
const normalized = normalizePath(path);
|
|
10048
|
-
const results = await ctx.appFilesCollection.query(
|
|
10140
|
+
const results = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId), Q3.where("path", normalized)).fetch();
|
|
10049
10141
|
return results.length > 0 ? appFileToStored(results[0]) : null;
|
|
10050
10142
|
}
|
|
10051
10143
|
async function getAppFilesOp(ctx, conversationId) {
|
|
10052
|
-
const results = await ctx.appFilesCollection.query(
|
|
10144
|
+
const results = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId)).fetch();
|
|
10053
10145
|
return results.map(appFileToStored);
|
|
10054
10146
|
}
|
|
10055
10147
|
async function getAppFileMapOp(ctx, conversationId) {
|
|
@@ -10060,7 +10152,7 @@ async function getAppFileMapOp(ctx, conversationId) {
|
|
|
10060
10152
|
}
|
|
10061
10153
|
async function deleteAppFileOp(ctx, conversationId, path) {
|
|
10062
10154
|
const normalized = normalizePath(path);
|
|
10063
|
-
const results = await ctx.appFilesCollection.query(
|
|
10155
|
+
const results = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId), Q3.where("path", normalized)).fetch();
|
|
10064
10156
|
if (results.length === 0) return false;
|
|
10065
10157
|
await ctx.database.write(async () => {
|
|
10066
10158
|
await results[0].destroyPermanently();
|
|
@@ -10068,7 +10160,7 @@ async function deleteAppFileOp(ctx, conversationId, path) {
|
|
|
10068
10160
|
return true;
|
|
10069
10161
|
}
|
|
10070
10162
|
async function deleteAllAppFilesOp(ctx, conversationId) {
|
|
10071
|
-
const results = await ctx.appFilesCollection.query(
|
|
10163
|
+
const results = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId)).fetch();
|
|
10072
10164
|
if (results.length === 0) return;
|
|
10073
10165
|
await ctx.database.write(async () => {
|
|
10074
10166
|
const batch = results.map((file) => file.prepareDestroyPermanently());
|
|
@@ -10377,7 +10469,7 @@ var chatStorageMigrations = schemaMigrations({
|
|
|
10377
10469
|
});
|
|
10378
10470
|
|
|
10379
10471
|
// src/lib/db/chat/summaryOperations.ts
|
|
10380
|
-
import { Q as
|
|
10472
|
+
import { Q as Q4 } from "@nozbe/watermelondb";
|
|
10381
10473
|
function createSummaryContext(database) {
|
|
10382
10474
|
return {
|
|
10383
10475
|
database,
|
|
@@ -10396,14 +10488,14 @@ function modelToStored(record2) {
|
|
|
10396
10488
|
};
|
|
10397
10489
|
}
|
|
10398
10490
|
async function getConversationSummaryOp(ctx, conversationId) {
|
|
10399
|
-
const results = await ctx.summariesCollection.query(
|
|
10491
|
+
const results = await ctx.summariesCollection.query(Q4.where("conversation_id", conversationId)).fetch();
|
|
10400
10492
|
if (results.length === 0) return null;
|
|
10401
10493
|
return modelToStored(results[0]);
|
|
10402
10494
|
}
|
|
10403
10495
|
async function upsertConversationSummaryOp(ctx, conversationId, summary, summarizedUpTo, tokenCount) {
|
|
10404
10496
|
let record2;
|
|
10405
10497
|
await ctx.database.write(async () => {
|
|
10406
|
-
const existing = await ctx.summariesCollection.query(
|
|
10498
|
+
const existing = await ctx.summariesCollection.query(Q4.where("conversation_id", conversationId)).fetch();
|
|
10407
10499
|
if (existing.length > 0) {
|
|
10408
10500
|
record2 = await existing[0].update((rec) => {
|
|
10409
10501
|
rec.summary = summary;
|
|
@@ -10423,7 +10515,7 @@ async function upsertConversationSummaryOp(ctx, conversationId, summary, summari
|
|
|
10423
10515
|
}
|
|
10424
10516
|
async function deleteConversationSummaryOp(ctx, conversationId) {
|
|
10425
10517
|
await ctx.database.write(async () => {
|
|
10426
|
-
const existing = await ctx.summariesCollection.query(
|
|
10518
|
+
const existing = await ctx.summariesCollection.query(Q4.where("conversation_id", conversationId)).fetch();
|
|
10427
10519
|
for (const record2 of existing) {
|
|
10428
10520
|
await record2.destroyPermanently();
|
|
10429
10521
|
}
|
|
@@ -10452,7 +10544,7 @@ __decorateClass([
|
|
|
10452
10544
|
], ConversationMemory.prototype, "createdAt", 2);
|
|
10453
10545
|
|
|
10454
10546
|
// src/lib/db/conversationMemory/operations.ts
|
|
10455
|
-
import { Q as
|
|
10547
|
+
import { Q as Q5 } from "@nozbe/watermelondb";
|
|
10456
10548
|
var MAX_PER_CONVERSATION = 200;
|
|
10457
10549
|
function conversationMemoryToStored(row) {
|
|
10458
10550
|
return {
|
|
@@ -10467,7 +10559,7 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
10467
10559
|
if (!conversationId || items.length === 0) return;
|
|
10468
10560
|
const now = Date.now();
|
|
10469
10561
|
await ctx.database.write(async () => {
|
|
10470
|
-
const existing = await ctx.conversationMemoryCollection.query(
|
|
10562
|
+
const existing = await ctx.conversationMemoryCollection.query(Q5.where("conversation_id", conversationId), Q5.sortBy("created_at", Q5.asc)).fetch();
|
|
10471
10563
|
const seen = new Set(existing.map((r) => r.memoryId));
|
|
10472
10564
|
const batchSeen = /* @__PURE__ */ new Set();
|
|
10473
10565
|
const deduped = [];
|
|
@@ -10497,13 +10589,13 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
10497
10589
|
}
|
|
10498
10590
|
async function getConversationMemoriesOp(ctx, conversationId) {
|
|
10499
10591
|
if (!conversationId) return [];
|
|
10500
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
10592
|
+
const rows = await ctx.conversationMemoryCollection.query(Q5.where("conversation_id", conversationId), Q5.sortBy("created_at", Q5.asc)).fetch();
|
|
10501
10593
|
return rows.map(conversationMemoryToStored);
|
|
10502
10594
|
}
|
|
10503
10595
|
async function clearConversationMemoriesOp(ctx, conversationId) {
|
|
10504
10596
|
if (!conversationId) return;
|
|
10505
10597
|
await ctx.database.write(async () => {
|
|
10506
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
10598
|
+
const rows = await ctx.conversationMemoryCollection.query(Q5.where("conversation_id", conversationId)).fetch();
|
|
10507
10599
|
if (rows.length === 0) return;
|
|
10508
10600
|
await ctx.database.batch(...rows.map((r) => r.prepareDestroyPermanently()));
|
|
10509
10601
|
});
|
|
@@ -10546,7 +10638,7 @@ __decorateClass([
|
|
|
10546
10638
|
], MemoryEntity.prototype, "createdAt", 2);
|
|
10547
10639
|
|
|
10548
10640
|
// src/lib/db/entities/operations.ts
|
|
10549
|
-
import { Q as
|
|
10641
|
+
import { Q as Q6 } from "@nozbe/watermelondb";
|
|
10550
10642
|
|
|
10551
10643
|
// src/lib/db/memoryVault/types.ts
|
|
10552
10644
|
var MEMORY_KINDS = [
|
|
@@ -10695,7 +10787,7 @@ async function upsertEntitiesInWrite(ctx, entities) {
|
|
|
10695
10787
|
const unique = Array.from(kindByName.keys());
|
|
10696
10788
|
const out = /* @__PURE__ */ new Map();
|
|
10697
10789
|
if (unique.length === 0) return { entities: out, operations: [], kindBackfills: [] };
|
|
10698
|
-
const existing = await ctx.entityCollection.query(
|
|
10790
|
+
const existing = await ctx.entityCollection.query(Q6.where("canonical_name", Q6.oneOf(unique))).fetch();
|
|
10699
10791
|
const existingNames = new Set(existing.map((e) => e.canonicalName));
|
|
10700
10792
|
const kindBackfills = existing.filter((e) => {
|
|
10701
10793
|
const incoming = kindByName.get(e.canonicalName);
|
|
@@ -10725,7 +10817,7 @@ function prepareKindBackfills(backfills) {
|
|
|
10725
10817
|
}
|
|
10726
10818
|
async function findVaultRowInWrite(ctx, memoryId) {
|
|
10727
10819
|
try {
|
|
10728
|
-
const rows = await ctx.database.get("memory_vault").query(
|
|
10820
|
+
const rows = await ctx.database.get("memory_vault").query(Q6.where("id", memoryId)).fetch();
|
|
10729
10821
|
return rows[0] ?? null;
|
|
10730
10822
|
} catch {
|
|
10731
10823
|
return null;
|
|
@@ -10827,7 +10919,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
10827
10919
|
return;
|
|
10828
10920
|
}
|
|
10829
10921
|
if (entities.length === 0) return;
|
|
10830
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
10922
|
+
const existingLinks = await ctx.memoryEntityCollection.query(Q6.where("memory_id", memoryId)).fetch();
|
|
10831
10923
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
10832
10924
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
10833
10925
|
const keptIds = entities.map((e) => e.uniqueId);
|
|
@@ -10863,7 +10955,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
10863
10955
|
}
|
|
10864
10956
|
async function resolveEntitiesByIds(ctx, entityIds) {
|
|
10865
10957
|
if (entityIds.length === 0) return [];
|
|
10866
|
-
const rows = await ctx.entityCollection.query(
|
|
10958
|
+
const rows = await ctx.entityCollection.query(Q6.where("id", Q6.oneOf(Array.from(entityIds)))).fetch();
|
|
10867
10959
|
return rows.map(entityToStored);
|
|
10868
10960
|
}
|
|
10869
10961
|
function autoLinkBlocked(row) {
|
|
@@ -10899,7 +10991,7 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
10899
10991
|
kindBackfills
|
|
10900
10992
|
} = await upsertEntitiesInWrite(ctx, normalized);
|
|
10901
10993
|
entities = Array.from(byName.values());
|
|
10902
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
10994
|
+
const existingLinks = await ctx.memoryEntityCollection.query(Q6.where("memory_id", memoryId)).fetch();
|
|
10903
10995
|
const keep = new Set(entities.map((e) => e.uniqueId));
|
|
10904
10996
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
10905
10997
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
@@ -10935,17 +11027,17 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
10935
11027
|
async function findOrphanedEntities(ctx, memoryId, toDestroy) {
|
|
10936
11028
|
const candidateIds = [...new Set(toDestroy.map((l) => String(l.entityId)))];
|
|
10937
11029
|
if (candidateIds.length === 0) return [];
|
|
10938
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
11030
|
+
const links = await ctx.memoryEntityCollection.query(Q6.where("entity_id", Q6.oneOf(candidateIds))).fetch();
|
|
10939
11031
|
const stillLinked = new Set(
|
|
10940
11032
|
links.filter((l) => String(l.memoryId) !== memoryId).map((l) => String(l.entityId))
|
|
10941
11033
|
);
|
|
10942
11034
|
const orphanIds = candidateIds.filter((id) => !stillLinked.has(id));
|
|
10943
11035
|
if (orphanIds.length === 0) return [];
|
|
10944
|
-
return await ctx.entityCollection.query(
|
|
11036
|
+
return await ctx.entityCollection.query(Q6.where("id", Q6.oneOf(orphanIds))).fetch();
|
|
10945
11037
|
}
|
|
10946
11038
|
async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
10947
11039
|
if (memoryIds.length === 0) return;
|
|
10948
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
11040
|
+
const links = await ctx.memoryEntityCollection.query(Q6.where("memory_id", Q6.oneOf(Array.from(memoryIds)))).fetch();
|
|
10949
11041
|
if (links.length === 0) return;
|
|
10950
11042
|
await ctx.database.write(async () => {
|
|
10951
11043
|
await assertCanWrite(ctx);
|
|
@@ -10954,7 +11046,7 @@ async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
|
10954
11046
|
}
|
|
10955
11047
|
async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
10956
11048
|
if (!userId) return;
|
|
10957
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
11049
|
+
const links = await ctx.memoryEntityCollection.query(Q6.where("user_id", userId)).fetch();
|
|
10958
11050
|
if (links.length === 0) return;
|
|
10959
11051
|
await ctx.database.write(async () => {
|
|
10960
11052
|
await assertCanWrite(ctx);
|
|
@@ -10962,7 +11054,7 @@ async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
|
10962
11054
|
});
|
|
10963
11055
|
}
|
|
10964
11056
|
async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
10965
|
-
const unstamped = await ctx.memoryEntityCollection.query(
|
|
11057
|
+
const unstamped = await ctx.memoryEntityCollection.query(Q6.where("user_id", null)).fetch();
|
|
10966
11058
|
if (unstamped.length === 0) return 0;
|
|
10967
11059
|
const toUpdate = [];
|
|
10968
11060
|
for (const link of unstamped) {
|
|
@@ -10987,15 +11079,15 @@ async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
|
10987
11079
|
async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
10988
11080
|
const unique = Array.from(new Set(entityNames.map(normalizeEntityName).filter((n) => n.length > 0)));
|
|
10989
11081
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
10990
|
-
const entityRows = await ctx.entityCollection.query(
|
|
11082
|
+
const entityRows = await ctx.entityCollection.query(Q6.where("canonical_name", Q6.oneOf(unique))).fetch();
|
|
10991
11083
|
if (entityRows.length === 0) return /* @__PURE__ */ new Map();
|
|
10992
11084
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
10993
|
-
const linkConditions = [
|
|
11085
|
+
const linkConditions = [Q6.where("entity_id", Q6.oneOf(entityRows.map((e) => e.id)))];
|
|
10994
11086
|
if (ctx.userId !== void 0) {
|
|
10995
11087
|
if (ctx.allowUnscopedRows) {
|
|
10996
|
-
linkConditions.push(
|
|
11088
|
+
linkConditions.push(Q6.or(Q6.where("user_id", ctx.userId), Q6.where("user_id", null)));
|
|
10997
11089
|
} else {
|
|
10998
|
-
linkConditions.push(
|
|
11090
|
+
linkConditions.push(Q6.where("user_id", ctx.userId));
|
|
10999
11091
|
}
|
|
11000
11092
|
}
|
|
11001
11093
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
@@ -11016,18 +11108,18 @@ async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
|
11016
11108
|
async function getEntitiesByMemoryIdsOp(ctx, memoryIds) {
|
|
11017
11109
|
const unique = Array.from(new Set(memoryIds.filter((id) => id.length > 0)));
|
|
11018
11110
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
11019
|
-
const linkConditions = [
|
|
11111
|
+
const linkConditions = [Q6.where("memory_id", Q6.oneOf(unique))];
|
|
11020
11112
|
if (ctx.userId !== void 0) {
|
|
11021
11113
|
if (ctx.allowUnscopedRows) {
|
|
11022
|
-
linkConditions.push(
|
|
11114
|
+
linkConditions.push(Q6.or(Q6.where("user_id", ctx.userId), Q6.where("user_id", null)));
|
|
11023
11115
|
} else {
|
|
11024
|
-
linkConditions.push(
|
|
11116
|
+
linkConditions.push(Q6.where("user_id", ctx.userId));
|
|
11025
11117
|
}
|
|
11026
11118
|
}
|
|
11027
11119
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
11028
11120
|
if (links.length === 0) return /* @__PURE__ */ new Map();
|
|
11029
11121
|
const entityIds = Array.from(new Set(links.map((l) => String(l.entityId))));
|
|
11030
|
-
const entityRows = await ctx.entityCollection.query(
|
|
11122
|
+
const entityRows = await ctx.entityCollection.query(Q6.where("id", Q6.oneOf(entityIds))).fetch();
|
|
11031
11123
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
11032
11124
|
const out = /* @__PURE__ */ new Map();
|
|
11033
11125
|
for (const link of links) {
|
|
@@ -12336,7 +12428,7 @@ var DatabaseManager = class {
|
|
|
12336
12428
|
};
|
|
12337
12429
|
|
|
12338
12430
|
// src/lib/db/media/operations.ts
|
|
12339
|
-
import { Q as
|
|
12431
|
+
import { Q as Q8 } from "@nozbe/watermelondb";
|
|
12340
12432
|
|
|
12341
12433
|
// src/lib/storage/opfs.ts
|
|
12342
12434
|
var FILE_PLACEHOLDER_PREFIX = "__SDKFILE__";
|
|
@@ -12602,7 +12694,7 @@ function isR2UrlExpired(sourceUrl, createdAt) {
|
|
|
12602
12694
|
}
|
|
12603
12695
|
|
|
12604
12696
|
// src/lib/storage/WatermelonChatStorageAdapter.ts
|
|
12605
|
-
import { Q as
|
|
12697
|
+
import { Q as Q7 } from "@nozbe/watermelondb";
|
|
12606
12698
|
var WatermelonChatStorageAdapter = class {
|
|
12607
12699
|
constructor(options) {
|
|
12608
12700
|
this.messages = options.database.get("history");
|
|
@@ -12642,10 +12734,10 @@ var WatermelonChatStorageAdapter = class {
|
|
|
12642
12734
|
}
|
|
12643
12735
|
observeConversations(options) {
|
|
12644
12736
|
const conditions = options?.projectId !== void 0 ? [
|
|
12645
|
-
|
|
12646
|
-
|
|
12647
|
-
|
|
12648
|
-
] : [
|
|
12737
|
+
Q7.where("project_id", options.projectId === null ? "" : options.projectId),
|
|
12738
|
+
Q7.where("is_deleted", false),
|
|
12739
|
+
Q7.sortBy("created_at", Q7.desc)
|
|
12740
|
+
] : [Q7.where("is_deleted", false), Q7.sortBy("created_at", Q7.desc)];
|
|
12649
12741
|
const rx = this.conversations.query(...conditions).observe();
|
|
12650
12742
|
return {
|
|
12651
12743
|
subscribe: (observer) => {
|
|
@@ -12692,7 +12784,7 @@ var WatermelonChatStorageAdapter = class {
|
|
|
12692
12784
|
return clearMessagesOp(this.ctx, conversationId);
|
|
12693
12785
|
}
|
|
12694
12786
|
observeMessages(conversationId) {
|
|
12695
|
-
const rx = this.messages.query(
|
|
12787
|
+
const rx = this.messages.query(Q7.where("conversation_id", conversationId), Q7.sortBy("message_id", Q7.asc)).observe();
|
|
12696
12788
|
return {
|
|
12697
12789
|
subscribe: (observer) => {
|
|
12698
12790
|
let latestSeq = 0;
|
|
@@ -12929,7 +13021,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
12929
13021
|
})
|
|
12930
13022
|
);
|
|
12931
13023
|
});
|
|
12932
|
-
const results = await mediaCollection.query(
|
|
13024
|
+
const results = await mediaCollection.query(Q8.where("media_id", Q8.oneOf(mediaIds))).fetch();
|
|
12933
13025
|
return Promise.all(
|
|
12934
13026
|
results.map(
|
|
12935
13027
|
(m) => mediaToStored(m, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -12938,21 +13030,21 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
12938
13030
|
}
|
|
12939
13031
|
async function getMediaByIdOp(ctx, mediaId) {
|
|
12940
13032
|
const mediaCollection = ctx.database.get("media");
|
|
12941
|
-
const results = await mediaCollection.query(
|
|
13033
|
+
const results = await mediaCollection.query(Q8.where("media_id", mediaId), Q8.where("is_deleted", false)).fetch();
|
|
12942
13034
|
return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
12943
13035
|
}
|
|
12944
13036
|
async function getMediaBySourceUrlOp(ctx, sourceUrl, walletAddress) {
|
|
12945
13037
|
const mediaCollection = ctx.database.get("media");
|
|
12946
13038
|
const results = await mediaCollection.query(
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
13039
|
+
Q8.where("source_url", sourceUrl),
|
|
13040
|
+
Q8.where("wallet_address", walletAddress),
|
|
13041
|
+
Q8.where("is_deleted", false)
|
|
12950
13042
|
).fetch();
|
|
12951
13043
|
return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
12952
13044
|
}
|
|
12953
13045
|
async function updateMediaOp(ctx, mediaId, options) {
|
|
12954
13046
|
const mediaCollection = ctx.database.get("media");
|
|
12955
|
-
const results = await mediaCollection.query(
|
|
13047
|
+
const results = await mediaCollection.query(Q8.where("media_id", mediaId)).fetch();
|
|
12956
13048
|
if (results.length === 0) {
|
|
12957
13049
|
return null;
|
|
12958
13050
|
}
|
|
@@ -12972,7 +13064,7 @@ async function updateMediaOp(ctx, mediaId, options) {
|
|
|
12972
13064
|
m._setRaw("updated_at", now);
|
|
12973
13065
|
});
|
|
12974
13066
|
});
|
|
12975
|
-
const updated = await mediaCollection.query(
|
|
13067
|
+
const updated = await mediaCollection.query(Q8.where("media_id", mediaId)).fetch();
|
|
12976
13068
|
return updated.length > 0 ? await mediaToStored(updated[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
12977
13069
|
}
|
|
12978
13070
|
async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
|
|
@@ -12980,7 +13072,7 @@ async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
|
|
|
12980
13072
|
return 0;
|
|
12981
13073
|
}
|
|
12982
13074
|
const mediaCollection = ctx.database.get("media");
|
|
12983
|
-
const results = await mediaCollection.query(
|
|
13075
|
+
const results = await mediaCollection.query(Q8.where("media_id", Q8.oneOf(mediaIds))).fetch();
|
|
12984
13076
|
if (results.length === 0) {
|
|
12985
13077
|
return 0;
|
|
12986
13078
|
}
|
|
@@ -13002,13 +13094,13 @@ var IMAGE_VIDEO_MIMES = VIDEO_EXTENSIONS.map((ext) => `image/${ext}`);
|
|
|
13002
13094
|
async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
|
|
13003
13095
|
const mediaCollection = ctx.database.get("media");
|
|
13004
13096
|
const candidates = await mediaCollection.query(
|
|
13005
|
-
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
|
|
13009
|
-
|
|
13010
|
-
...IMAGE_VIDEO_MIMES.map((m) =>
|
|
13011
|
-
|
|
13097
|
+
Q8.where("wallet_address", walletAddress),
|
|
13098
|
+
Q8.where("is_deleted", false),
|
|
13099
|
+
Q8.where("media_type", "image"),
|
|
13100
|
+
Q8.or(
|
|
13101
|
+
Q8.where("mime_type", Q8.like("video/%")),
|
|
13102
|
+
...IMAGE_VIDEO_MIMES.map((m) => Q8.where("mime_type", m)),
|
|
13103
|
+
Q8.where("mime_type", "application/octet-stream")
|
|
13012
13104
|
)
|
|
13013
13105
|
).fetch();
|
|
13014
13106
|
if (candidates.length === 0) {
|
|
@@ -13057,7 +13149,7 @@ async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
|
|
|
13057
13149
|
}
|
|
13058
13150
|
async function deleteMediaOp(ctx, mediaId) {
|
|
13059
13151
|
const mediaCollection = ctx.database.get("media");
|
|
13060
|
-
const results = await mediaCollection.query(
|
|
13152
|
+
const results = await mediaCollection.query(Q8.where("media_id", mediaId)).fetch();
|
|
13061
13153
|
if (results.length === 0) {
|
|
13062
13154
|
return false;
|
|
13063
13155
|
}
|
|
@@ -13075,7 +13167,7 @@ async function deleteMediaOp(ctx, mediaId) {
|
|
|
13075
13167
|
}
|
|
13076
13168
|
async function hardDeleteMediaOp(ctx, mediaId) {
|
|
13077
13169
|
const mediaCollection = ctx.database.get("media");
|
|
13078
|
-
const results = await mediaCollection.query(
|
|
13170
|
+
const results = await mediaCollection.query(Q8.where("media_id", mediaId)).fetch();
|
|
13079
13171
|
if (results.length === 0) {
|
|
13080
13172
|
return false;
|
|
13081
13173
|
}
|
|
@@ -13087,28 +13179,28 @@ async function hardDeleteMediaOp(ctx, mediaId) {
|
|
|
13087
13179
|
}
|
|
13088
13180
|
async function getMediaOp(ctx, filters) {
|
|
13089
13181
|
const mediaCollection = ctx.database.get("media");
|
|
13090
|
-
const conditions = [
|
|
13182
|
+
const conditions = [Q8.where("wallet_address", filters.walletAddress)];
|
|
13091
13183
|
if (!filters.includeDeleted) {
|
|
13092
|
-
conditions.push(
|
|
13184
|
+
conditions.push(Q8.where("is_deleted", false));
|
|
13093
13185
|
}
|
|
13094
13186
|
if (filters.mediaType) {
|
|
13095
|
-
conditions.push(
|
|
13187
|
+
conditions.push(Q8.where("media_type", filters.mediaType));
|
|
13096
13188
|
}
|
|
13097
13189
|
if (filters.role) {
|
|
13098
|
-
conditions.push(
|
|
13190
|
+
conditions.push(Q8.where("role", filters.role));
|
|
13099
13191
|
}
|
|
13100
13192
|
if (filters.conversationId) {
|
|
13101
|
-
conditions.push(
|
|
13193
|
+
conditions.push(Q8.where("conversation_id", filters.conversationId));
|
|
13102
13194
|
}
|
|
13103
13195
|
if (filters.model) {
|
|
13104
|
-
conditions.push(
|
|
13196
|
+
conditions.push(Q8.where("model", filters.model));
|
|
13105
13197
|
}
|
|
13106
|
-
conditions.push(
|
|
13198
|
+
conditions.push(Q8.sortBy("created_at", Q8.desc));
|
|
13107
13199
|
if (filters.limit) {
|
|
13108
|
-
conditions.push(
|
|
13200
|
+
conditions.push(Q8.take(filters.limit));
|
|
13109
13201
|
}
|
|
13110
13202
|
if (filters.offset) {
|
|
13111
|
-
conditions.push(
|
|
13203
|
+
conditions.push(Q8.skip(filters.offset));
|
|
13112
13204
|
}
|
|
13113
13205
|
const results = await mediaCollection.query(...conditions).fetch();
|
|
13114
13206
|
return Promise.all(
|
|
@@ -13138,9 +13230,9 @@ async function getMediaByConversationOp(ctx, walletAddress, conversationId, limi
|
|
|
13138
13230
|
async function getMediaByMessageOp(ctx, messageId) {
|
|
13139
13231
|
const mediaCollection = ctx.database.get("media");
|
|
13140
13232
|
const results = await mediaCollection.query(
|
|
13141
|
-
|
|
13142
|
-
|
|
13143
|
-
|
|
13233
|
+
Q8.where("message_id", messageId),
|
|
13234
|
+
Q8.where("is_deleted", false),
|
|
13235
|
+
Q8.sortBy("created_at", Q8.asc)
|
|
13144
13236
|
).fetch();
|
|
13145
13237
|
return Promise.all(
|
|
13146
13238
|
results.map(
|
|
@@ -13153,9 +13245,9 @@ async function getMediaByIdsOp(ctx, mediaIds, includeDeleted = false) {
|
|
|
13153
13245
|
return [];
|
|
13154
13246
|
}
|
|
13155
13247
|
const mediaCollection = ctx.database.get("media");
|
|
13156
|
-
const conditions = [
|
|
13248
|
+
const conditions = [Q8.where("media_id", Q8.oneOf(mediaIds))];
|
|
13157
13249
|
if (!includeDeleted) {
|
|
13158
|
-
conditions.push(
|
|
13250
|
+
conditions.push(Q8.where("is_deleted", false));
|
|
13159
13251
|
}
|
|
13160
13252
|
const results = await mediaCollection.query(...conditions).fetch();
|
|
13161
13253
|
const mediaMap = new Map(results.map((m) => [m.mediaId, m]));
|
|
@@ -13192,10 +13284,10 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
|
|
|
13192
13284
|
const queryLower = query.toLowerCase();
|
|
13193
13285
|
const MAX_SEARCH_RECORDS = 500;
|
|
13194
13286
|
const allResults = await mediaCollection.query(
|
|
13195
|
-
|
|
13196
|
-
|
|
13197
|
-
|
|
13198
|
-
|
|
13287
|
+
Q8.where("wallet_address", walletAddress),
|
|
13288
|
+
Q8.where("is_deleted", false),
|
|
13289
|
+
Q8.sortBy("created_at", Q8.desc),
|
|
13290
|
+
Q8.take(MAX_SEARCH_RECORDS)
|
|
13199
13291
|
).fetch();
|
|
13200
13292
|
const decrypted = await Promise.all(
|
|
13201
13293
|
allResults.map(
|
|
@@ -13208,11 +13300,11 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
|
|
|
13208
13300
|
async function getMediaCountOp(ctx, walletAddress, mediaType) {
|
|
13209
13301
|
const mediaCollection = ctx.database.get("media");
|
|
13210
13302
|
const conditions = [
|
|
13211
|
-
|
|
13212
|
-
|
|
13303
|
+
Q8.where("wallet_address", walletAddress),
|
|
13304
|
+
Q8.where("is_deleted", false)
|
|
13213
13305
|
];
|
|
13214
13306
|
if (mediaType) {
|
|
13215
|
-
conditions.push(
|
|
13307
|
+
conditions.push(Q8.where("media_type", mediaType));
|
|
13216
13308
|
}
|
|
13217
13309
|
return await mediaCollection.query(...conditions).fetchCount();
|
|
13218
13310
|
}
|
|
@@ -13227,7 +13319,7 @@ async function getMediaCountsByTypeOp(ctx, walletAddress) {
|
|
|
13227
13319
|
}
|
|
13228
13320
|
async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
13229
13321
|
const mediaCollection = ctx.database.get("media");
|
|
13230
|
-
const results = await mediaCollection.query(
|
|
13322
|
+
const results = await mediaCollection.query(Q8.where("conversation_id", conversationId), Q8.where("is_deleted", false)).fetch();
|
|
13231
13323
|
if (results.length === 0) {
|
|
13232
13324
|
return 0;
|
|
13233
13325
|
}
|
|
@@ -13248,7 +13340,7 @@ async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
|
13248
13340
|
}
|
|
13249
13341
|
async function deleteMediaByMessageOp(ctx, messageId) {
|
|
13250
13342
|
const mediaCollection = ctx.database.get("media");
|
|
13251
|
-
const results = await mediaCollection.query(
|
|
13343
|
+
const results = await mediaCollection.query(Q8.where("message_id", messageId), Q8.where("is_deleted", false)).fetch();
|
|
13252
13344
|
if (results.length === 0) {
|
|
13253
13345
|
return 0;
|
|
13254
13346
|
}
|
|
@@ -13269,7 +13361,7 @@ async function deleteMediaByMessageOp(ctx, messageId) {
|
|
|
13269
13361
|
}
|
|
13270
13362
|
|
|
13271
13363
|
// src/lib/db/memoryVault/operations.ts
|
|
13272
|
-
import { Q as
|
|
13364
|
+
import { Q as Q9 } from "@nozbe/watermelondb";
|
|
13273
13365
|
|
|
13274
13366
|
// src/lib/db/memoryVault/encryption.ts
|
|
13275
13367
|
async function encryptVaultMemoryContent(content, address, signMessage, embeddedWalletSigner) {
|
|
@@ -13318,11 +13410,11 @@ var NON_PRIVATE_VISIBILITIES = ["public"];
|
|
|
13318
13410
|
function visibilityConditions(requested) {
|
|
13319
13411
|
if (!requested?.length) return [];
|
|
13320
13412
|
if (!requested.includes("private")) {
|
|
13321
|
-
return [
|
|
13413
|
+
return [Q9.where("visibility", Q9.oneOf([...requested]))];
|
|
13322
13414
|
}
|
|
13323
13415
|
const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
|
|
13324
13416
|
if (excluded.length === 0) return [];
|
|
13325
|
-
return [
|
|
13417
|
+
return [Q9.or(Q9.where("visibility", null), Q9.where("visibility", Q9.notIn(excluded)))];
|
|
13326
13418
|
}
|
|
13327
13419
|
function isKinded(record2) {
|
|
13328
13420
|
return record2.kind !== null && record2.kind !== void 0;
|
|
@@ -13363,17 +13455,17 @@ function levelConditions(requested) {
|
|
|
13363
13455
|
const published = ["shared", "public"];
|
|
13364
13456
|
const wantsMatching = requested.includes("matching");
|
|
13365
13457
|
const wantsPrivate = requested.includes("private");
|
|
13366
|
-
const unresolved =
|
|
13367
|
-
const byLevel =
|
|
13368
|
-
if (wantsMatching && wantsPrivate) return [
|
|
13458
|
+
const unresolved = Q9.or(Q9.where("level", null), Q9.where("level", Q9.notIn([...MEMORY_LEVELS])));
|
|
13459
|
+
const byLevel = Q9.where("level", Q9.oneOf([...requested]));
|
|
13460
|
+
if (wantsMatching && wantsPrivate) return [Q9.or(byLevel, unresolved)];
|
|
13369
13461
|
if (wantsMatching) {
|
|
13370
|
-
return [
|
|
13462
|
+
return [Q9.or(byLevel, Q9.and(unresolved, Q9.where("scope", Q9.oneOf(published))))];
|
|
13371
13463
|
}
|
|
13372
13464
|
if (wantsPrivate) {
|
|
13373
13465
|
return [
|
|
13374
|
-
|
|
13466
|
+
Q9.or(
|
|
13375
13467
|
byLevel,
|
|
13376
|
-
|
|
13468
|
+
Q9.and(unresolved, Q9.or(Q9.where("scope", null), Q9.where("scope", Q9.notIn(published))))
|
|
13377
13469
|
)
|
|
13378
13470
|
];
|
|
13379
13471
|
}
|
|
@@ -13384,13 +13476,13 @@ function isOwnedByCtxUser(ctx, record2) {
|
|
|
13384
13476
|
}
|
|
13385
13477
|
function baseVaultConditions(ctx, options) {
|
|
13386
13478
|
return [
|
|
13387
|
-
...options?.memoryIds !== void 0 ? [
|
|
13388
|
-
...options?.includeDeleted ? [] : [
|
|
13389
|
-
...options?.includeArchived ? [] : [
|
|
13390
|
-
...options?.includeQuarantined ? [] : [
|
|
13391
|
-
...options?.includeSuperseded ? [] : [
|
|
13392
|
-
...ctx.userId !== void 0 ? [
|
|
13393
|
-
...options?.since ? [
|
|
13479
|
+
...options?.memoryIds !== void 0 ? [Q9.where("id", Q9.oneOf(options.memoryIds))] : [],
|
|
13480
|
+
...options?.includeDeleted ? [] : [Q9.where("is_deleted", false)],
|
|
13481
|
+
...options?.includeArchived ? [] : [Q9.where("archived_at", Q9.eq(null))],
|
|
13482
|
+
...options?.includeQuarantined ? [] : [Q9.where("trust_tier", Q9.notEq("quarantined"))],
|
|
13483
|
+
...options?.includeSuperseded ? [] : [Q9.where("superseded_by", null)],
|
|
13484
|
+
...ctx.userId !== void 0 ? [Q9.where("user_id", ctx.userId)] : [],
|
|
13485
|
+
...options?.since ? [Q9.where("updated_at", Q9.gt(options.since.getTime()))] : []
|
|
13394
13486
|
];
|
|
13395
13487
|
}
|
|
13396
13488
|
var KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
|
|
@@ -13560,11 +13652,11 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
13560
13652
|
async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
|
|
13561
13653
|
const records = await ctx.vaultMemoryCollection.query(
|
|
13562
13654
|
...baseVaultConditions(ctx),
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13655
|
+
Q9.where("event_time_start", Q9.notEq(null)),
|
|
13656
|
+
Q9.where("event_time_start", Q9.lte(windowEnd)),
|
|
13657
|
+
Q9.or(
|
|
13658
|
+
Q9.where("event_time_start", Q9.gte(windowStart)),
|
|
13659
|
+
Q9.where("event_time_kind", Q9.oneOf(["range", "ongoing"]))
|
|
13568
13660
|
)
|
|
13569
13661
|
).fetch();
|
|
13570
13662
|
const out = [];
|
|
@@ -13720,18 +13812,18 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
13720
13812
|
function vaultListConditions(ctx, options) {
|
|
13721
13813
|
return [
|
|
13722
13814
|
...baseVaultConditions(ctx, options),
|
|
13723
|
-
...options?.scopes?.length ? [
|
|
13815
|
+
...options?.scopes?.length ? [Q9.where("scope", Q9.oneOf(options.scopes))] : [],
|
|
13724
13816
|
...visibilityConditions(options?.visibility),
|
|
13725
13817
|
...levelConditions(options?.levels),
|
|
13726
|
-
...options?.kinds?.length ? [
|
|
13727
|
-
...options?.folderId !== void 0 ? [
|
|
13728
|
-
...options?.factTypes?.length ? [
|
|
13818
|
+
...options?.kinds?.length ? [Q9.where("kind", Q9.oneOf(options.kinds))] : [],
|
|
13819
|
+
...options?.folderId !== void 0 ? [Q9.where("folder_id", options.folderId)] : [],
|
|
13820
|
+
...options?.factTypes?.length ? [Q9.where("fact_type", Q9.oneOf(options.factTypes))] : []
|
|
13729
13821
|
];
|
|
13730
13822
|
}
|
|
13731
13823
|
function vaultListOrder(options) {
|
|
13732
13824
|
return [
|
|
13733
|
-
|
|
13734
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
13825
|
+
Q9.sortBy(options?.since ? "updated_at" : "created_at", Q9.desc),
|
|
13826
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [Q9.take(options.limit)] : []
|
|
13735
13827
|
];
|
|
13736
13828
|
}
|
|
13737
13829
|
async function getAllVaultMemoryRowsOp(ctx) {
|
|
@@ -13770,10 +13862,10 @@ function vaultMemoryRawToRankable(raw) {
|
|
|
13770
13862
|
async function getVaultRankingProjectionsOp(ctx, options) {
|
|
13771
13863
|
const conditions = [
|
|
13772
13864
|
...baseVaultConditions(ctx, options),
|
|
13773
|
-
...options?.scopes?.length ? [
|
|
13774
|
-
...options?.folderId !== void 0 ? [
|
|
13775
|
-
|
|
13776
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
13865
|
+
...options?.scopes?.length ? [Q9.where("scope", Q9.oneOf(options.scopes))] : [],
|
|
13866
|
+
...options?.folderId !== void 0 ? [Q9.where("folder_id", options.folderId)] : [],
|
|
13867
|
+
Q9.sortBy(options?.since ? "updated_at" : "created_at", Q9.desc),
|
|
13868
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [Q9.take(options.limit)] : []
|
|
13777
13869
|
];
|
|
13778
13870
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
13779
13871
|
return results.map(vaultMemoryRawToRankable);
|
|
@@ -13824,7 +13916,7 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
13824
13916
|
args.push(...options.factTypes);
|
|
13825
13917
|
}
|
|
13826
13918
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
13827
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
13919
|
+
const rows = await ctx.vaultMemoryCollection.query(Q9.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
13828
13920
|
return rows.map(mapRaw);
|
|
13829
13921
|
} catch (err) {
|
|
13830
13922
|
getLogger().debug(
|
|
@@ -13835,9 +13927,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
13835
13927
|
memoryIds: options?.memoryIds,
|
|
13836
13928
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
13837
13929
|
}),
|
|
13838
|
-
...options?.scopes?.length ? [
|
|
13839
|
-
...options?.folderId !== void 0 ? [
|
|
13840
|
-
...options?.factTypes?.length ? [
|
|
13930
|
+
...options?.scopes?.length ? [Q9.where("scope", Q9.oneOf(options.scopes))] : [],
|
|
13931
|
+
...options?.folderId !== void 0 ? [Q9.where("folder_id", options.folderId)] : [],
|
|
13932
|
+
...options?.factTypes?.length ? [Q9.where("fact_type", Q9.oneOf(options.factTypes))] : []
|
|
13841
13933
|
];
|
|
13842
13934
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
13843
13935
|
return rows.map(mapRaw);
|
|
@@ -13855,7 +13947,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
13855
13947
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
13856
13948
|
});
|
|
13857
13949
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
13858
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
13950
|
+
const rows = await ctx.vaultMemoryCollection.query(Q9.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
13859
13951
|
return rows.map(mapRaw);
|
|
13860
13952
|
} catch (err) {
|
|
13861
13953
|
getLogger().debug(
|
|
@@ -13867,7 +13959,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
13867
13959
|
includeArchived: options.includeArchived
|
|
13868
13960
|
}
|
|
13869
13961
|
}),
|
|
13870
|
-
|
|
13962
|
+
Q9.where("id", Q9.oneOf(ids))
|
|
13871
13963
|
).unsafeFetchRaw();
|
|
13872
13964
|
return rows.map(mapRaw);
|
|
13873
13965
|
}
|
|
@@ -13878,7 +13970,7 @@ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
|
13878
13970
|
...baseVaultConditions(ctx, {
|
|
13879
13971
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
13880
13972
|
}),
|
|
13881
|
-
|
|
13973
|
+
Q9.where("id", Q9.oneOf(ids))
|
|
13882
13974
|
];
|
|
13883
13975
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
13884
13976
|
return mapInBatches(
|
|
@@ -13903,7 +13995,7 @@ async function countActiveVaultMemoriesOp(ctx) {
|
|
|
13903
13995
|
}
|
|
13904
13996
|
async function getActiveVaultMemoryIdsOp(ctx, ids) {
|
|
13905
13997
|
if (ids.length === 0) return /* @__PURE__ */ new Set();
|
|
13906
|
-
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx),
|
|
13998
|
+
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), Q9.where("id", Q9.oneOf(ids))).unsafeFetchRaw();
|
|
13907
13999
|
return new Set(rows.map((r) => r.id));
|
|
13908
14000
|
}
|
|
13909
14001
|
async function updateVaultMemoryOp(ctx, id, opts) {
|
|
@@ -14052,7 +14144,7 @@ async function setMemoryEntitiesOp(ctx, memoryId, entities) {
|
|
|
14052
14144
|
() => linkMemoryEntitiesOp(entityCtx, memoryId, entities, { topicsSource: "user" })
|
|
14053
14145
|
) : [];
|
|
14054
14146
|
const keep = new Set(linked.map((e) => e.uniqueId));
|
|
14055
|
-
const existing = await entityCtx.memoryEntityCollection.query(
|
|
14147
|
+
const existing = await entityCtx.memoryEntityCollection.query(Q9.where("memory_id", memoryId)).fetch();
|
|
14056
14148
|
const staleLinks = existing.filter((l) => !keep.has(String(l.entityId)));
|
|
14057
14149
|
if (staleLinks.length === 0 && entities.length > 0) return;
|
|
14058
14150
|
const topicsWrite = await resolveMemoryTopicsWrite(
|
|
@@ -14193,9 +14285,9 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
14193
14285
|
}
|
|
14194
14286
|
async function getUnfiledVaultMemoriesOp(ctx) {
|
|
14195
14287
|
const conditions = [
|
|
14196
|
-
|
|
14288
|
+
Q9.where("folder_id", null),
|
|
14197
14289
|
...baseVaultConditions(ctx),
|
|
14198
|
-
|
|
14290
|
+
Q9.sortBy("created_at", Q9.desc)
|
|
14199
14291
|
];
|
|
14200
14292
|
const results = await ctx.vaultMemoryCollection.query(...conditions).fetch();
|
|
14201
14293
|
return mapInBatches(
|
|
@@ -14209,7 +14301,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
14209
14301
|
const entityIdByMemory = /* @__PURE__ */ new Map();
|
|
14210
14302
|
const allEntityIds = /* @__PURE__ */ new Set();
|
|
14211
14303
|
for (let i = 0; i < memoryIds.length; i += CHUNK) {
|
|
14212
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
14304
|
+
const links = await entityCtx.memoryEntityCollection.query(Q9.where("memory_id", Q9.oneOf(memoryIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
14213
14305
|
for (const link of links) {
|
|
14214
14306
|
const memoryId = String(link.memory_id);
|
|
14215
14307
|
const entityId = String(link.entity_id);
|
|
@@ -14225,7 +14317,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
14225
14317
|
const entityIds = Array.from(allEntityIds);
|
|
14226
14318
|
const nameById = /* @__PURE__ */ new Map();
|
|
14227
14319
|
for (let i = 0; i < entityIds.length; i += CHUNK) {
|
|
14228
|
-
const entities = await entityCtx.entityCollection.query(
|
|
14320
|
+
const entities = await entityCtx.entityCollection.query(Q9.where("id", Q9.oneOf(entityIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
14229
14321
|
for (const e of entities) {
|
|
14230
14322
|
if (typeof e.canonical_name === "string") nameById.set(String(e.id), e.canonical_name);
|
|
14231
14323
|
}
|
|
@@ -14254,7 +14346,7 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
|
|
|
14254
14346
|
if (!entityCtx) {
|
|
14255
14347
|
throw new Error("getMemoriesNeedingTopicExtractionOp requires ctx.entityCtx");
|
|
14256
14348
|
}
|
|
14257
|
-
const conditions = [...baseVaultConditions(ctx),
|
|
14349
|
+
const conditions = [...baseVaultConditions(ctx), Q9.sortBy("created_at", Q9.desc)];
|
|
14258
14350
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
14259
14351
|
const linkedNames = await linkedEntityNamesByMemory(
|
|
14260
14352
|
entityCtx,
|
|
@@ -14410,10 +14502,10 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
14410
14502
|
}
|
|
14411
14503
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) continue;
|
|
14412
14504
|
if (parseTopics(record2.topics) !== null) continue;
|
|
14413
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
14505
|
+
const links = await entityCtx.memoryEntityCollection.query(Q9.where("memory_id", id)).unsafeFetchRaw();
|
|
14414
14506
|
const entityIds = links.map((l) => String(l.entity_id));
|
|
14415
14507
|
if (entityIds.length === 0) continue;
|
|
14416
|
-
const entities = await entityCtx.entityCollection.query(
|
|
14508
|
+
const entities = await entityCtx.entityCollection.query(Q9.where("id", Q9.oneOf(entityIds))).fetch();
|
|
14417
14509
|
if (entities.length === 0) continue;
|
|
14418
14510
|
const source = record2.topicsUserManaged ? "user" : "auto";
|
|
14419
14511
|
const write = await resolveMemoryTopicsWrite(entityCtx, id, entities, [], source);
|
|
@@ -14429,7 +14521,7 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
14429
14521
|
}
|
|
14430
14522
|
async function deleteAllVaultMemoriesForUserOp(ctx, userId) {
|
|
14431
14523
|
if (ctx.userId !== void 0 && ctx.userId !== userId) return 0;
|
|
14432
|
-
const records = await ctx.vaultMemoryCollection.query(
|
|
14524
|
+
const records = await ctx.vaultMemoryCollection.query(Q9.where("user_id", userId), Q9.where("is_deleted", false)).fetch();
|
|
14433
14525
|
if (records.length === 0) return 0;
|
|
14434
14526
|
await ctx.database.write(async () => {
|
|
14435
14527
|
await assertCanWrite2(ctx);
|
|
@@ -14466,7 +14558,7 @@ async function getDecayCandidatesRawOp(ctx) {
|
|
|
14466
14558
|
assertVaultScopeForSweep(ctx);
|
|
14467
14559
|
const results = await ctx.vaultMemoryCollection.query(
|
|
14468
14560
|
...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
|
|
14469
|
-
|
|
14561
|
+
Q9.where("kind", null)
|
|
14470
14562
|
).unsafeFetchRaw();
|
|
14471
14563
|
return results.map((raw) => ({
|
|
14472
14564
|
uniqueId: raw.id,
|
|
@@ -14596,11 +14688,11 @@ async function findQuarantinedDuplicateOp(ctx, content, sourceIds2, where) {
|
|
|
14596
14688
|
const wanted = [...new Set(sourceIds2)].sort().join("\0");
|
|
14597
14689
|
const target = normalizeForDedupe(content);
|
|
14598
14690
|
const rows = await ctx.vaultMemoryCollection.query(
|
|
14599
|
-
|
|
14600
|
-
|
|
14601
|
-
|
|
14602
|
-
|
|
14603
|
-
...ctx.userId !== void 0 ? [
|
|
14691
|
+
Q9.where("trust_tier", "quarantined"),
|
|
14692
|
+
Q9.where("is_deleted", false),
|
|
14693
|
+
Q9.where("scope", where.scope),
|
|
14694
|
+
Q9.where("folder_id", where.folderId),
|
|
14695
|
+
...ctx.userId !== void 0 ? [Q9.where("user_id", ctx.userId)] : []
|
|
14604
14696
|
).unsafeFetchRaw();
|
|
14605
14697
|
for (const raw of rows) {
|
|
14606
14698
|
let ids;
|
|
@@ -14756,7 +14848,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
|
14756
14848
|
}
|
|
14757
14849
|
|
|
14758
14850
|
// src/lib/db/project/operations.ts
|
|
14759
|
-
import { Q as
|
|
14851
|
+
import { Q as Q10 } from "@nozbe/watermelondb";
|
|
14760
14852
|
|
|
14761
14853
|
// src/lib/db/project/types.ts
|
|
14762
14854
|
function generateProjectId() {
|
|
@@ -14787,15 +14879,15 @@ async function createProjectOp(ctx, opts, defaultName = "New Project") {
|
|
|
14787
14879
|
return projectToStored(created);
|
|
14788
14880
|
}
|
|
14789
14881
|
async function getProjectOp(ctx, id) {
|
|
14790
|
-
const results = await ctx.projectsCollection.query(
|
|
14882
|
+
const results = await ctx.projectsCollection.query(Q10.where("project_id", id), Q10.where("is_deleted", false)).fetch();
|
|
14791
14883
|
return results.length > 0 ? projectToStored(results[0]) : null;
|
|
14792
14884
|
}
|
|
14793
14885
|
async function getProjectsOp(ctx) {
|
|
14794
|
-
const results = await ctx.projectsCollection.query(
|
|
14886
|
+
const results = await ctx.projectsCollection.query(Q10.where("is_deleted", false), Q10.sortBy("created_at", Q10.desc)).fetch();
|
|
14795
14887
|
return results.map(projectToStored);
|
|
14796
14888
|
}
|
|
14797
14889
|
async function updateProjectNameOp(ctx, id, name) {
|
|
14798
|
-
const results = await ctx.projectsCollection.query(
|
|
14890
|
+
const results = await ctx.projectsCollection.query(Q10.where("project_id", id), Q10.where("is_deleted", false)).fetch();
|
|
14799
14891
|
if (results.length > 0) {
|
|
14800
14892
|
await ctx.database.write(async () => {
|
|
14801
14893
|
await results[0].update((proj) => {
|
|
@@ -14807,7 +14899,7 @@ async function updateProjectNameOp(ctx, id, name) {
|
|
|
14807
14899
|
return false;
|
|
14808
14900
|
}
|
|
14809
14901
|
async function updateProjectOp(ctx, id, opts) {
|
|
14810
|
-
const results = await ctx.projectsCollection.query(
|
|
14902
|
+
const results = await ctx.projectsCollection.query(Q10.where("project_id", id), Q10.where("is_deleted", false)).fetch();
|
|
14811
14903
|
if (results.length > 0) {
|
|
14812
14904
|
await ctx.database.write(async () => {
|
|
14813
14905
|
await results[0].update((proj) => {
|
|
@@ -14819,7 +14911,7 @@ async function updateProjectOp(ctx, id, opts) {
|
|
|
14819
14911
|
return false;
|
|
14820
14912
|
}
|
|
14821
14913
|
async function deleteProjectOp(ctx, id) {
|
|
14822
|
-
const results = await ctx.projectsCollection.query(
|
|
14914
|
+
const results = await ctx.projectsCollection.query(Q10.where("project_id", id), Q10.where("is_deleted", false)).fetch();
|
|
14823
14915
|
if (results.length > 0) {
|
|
14824
14916
|
await ctx.database.write(async () => {
|
|
14825
14917
|
await results[0].update((proj) => {
|
|
@@ -14832,14 +14924,14 @@ async function deleteProjectOp(ctx, id) {
|
|
|
14832
14924
|
}
|
|
14833
14925
|
async function getProjectConversationsOp(ctx, projectId) {
|
|
14834
14926
|
const results = await ctx.conversationsCollection.query(
|
|
14835
|
-
|
|
14836
|
-
|
|
14837
|
-
|
|
14927
|
+
Q10.where("project_id", projectId),
|
|
14928
|
+
Q10.where("is_deleted", false),
|
|
14929
|
+
Q10.sortBy("created_at", Q10.desc)
|
|
14838
14930
|
).fetch();
|
|
14839
14931
|
return results.map(conversationToStoredRaw);
|
|
14840
14932
|
}
|
|
14841
14933
|
async function getProjectConversationCountOp(ctx, projectId) {
|
|
14842
|
-
return await ctx.conversationsCollection.query(
|
|
14934
|
+
return await ctx.conversationsCollection.query(Q10.where("project_id", projectId), Q10.where("is_deleted", false)).fetchCount();
|
|
14843
14935
|
}
|
|
14844
14936
|
|
|
14845
14937
|
// src/lib/db/queue/manager.ts
|
|
@@ -15182,7 +15274,7 @@ var WalletPoller = class {
|
|
|
15182
15274
|
};
|
|
15183
15275
|
|
|
15184
15276
|
// src/lib/db/savedTools/operations.ts
|
|
15185
|
-
import { Q as
|
|
15277
|
+
import { Q as Q11 } from "@nozbe/watermelondb";
|
|
15186
15278
|
function savedToolToStored(tool) {
|
|
15187
15279
|
return {
|
|
15188
15280
|
uniqueId: tool.id,
|
|
@@ -15215,7 +15307,7 @@ async function createSavedToolOp(ctx, opts) {
|
|
|
15215
15307
|
return savedToolToStored(created);
|
|
15216
15308
|
}
|
|
15217
15309
|
async function getAllSavedToolsOp(ctx) {
|
|
15218
|
-
const results = await ctx.savedToolsCollection.query(
|
|
15310
|
+
const results = await ctx.savedToolsCollection.query(Q11.where("is_deleted", false), Q11.sortBy("created_at", Q11.desc)).fetch();
|
|
15219
15311
|
return results.map(savedToolToStored);
|
|
15220
15312
|
}
|
|
15221
15313
|
async function getSavedToolByIdOp(ctx, uniqueId) {
|
|
@@ -15267,7 +15359,7 @@ async function deleteSavedToolOp(ctx, uniqueId) {
|
|
|
15267
15359
|
}
|
|
15268
15360
|
|
|
15269
15361
|
// src/lib/db/settings/operations.ts
|
|
15270
|
-
import { Q as
|
|
15362
|
+
import { Q as Q12 } from "@nozbe/watermelondb";
|
|
15271
15363
|
function modelPreferenceToStored(preference) {
|
|
15272
15364
|
return {
|
|
15273
15365
|
uniqueId: preference.id,
|
|
@@ -15276,12 +15368,12 @@ function modelPreferenceToStored(preference) {
|
|
|
15276
15368
|
};
|
|
15277
15369
|
}
|
|
15278
15370
|
async function getModelPreferenceOp(ctx, walletAddress) {
|
|
15279
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
15371
|
+
const results = await ctx.modelPreferencesCollection.query(Q12.where("wallet_address", walletAddress)).fetch();
|
|
15280
15372
|
return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
|
|
15281
15373
|
}
|
|
15282
15374
|
async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
15283
15375
|
const result = await ctx.database.write(async () => {
|
|
15284
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
15376
|
+
const results = await ctx.modelPreferencesCollection.query(Q12.where("wallet_address", walletAddress)).fetch();
|
|
15285
15377
|
if (results.length > 0) {
|
|
15286
15378
|
const preference = results[0];
|
|
15287
15379
|
await preference.update((pref) => {
|
|
@@ -15299,7 +15391,7 @@ async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
|
15299
15391
|
return modelPreferenceToStored(result);
|
|
15300
15392
|
}
|
|
15301
15393
|
async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
15302
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
15394
|
+
const results = await ctx.modelPreferencesCollection.query(Q12.where("wallet_address", walletAddress)).fetch();
|
|
15303
15395
|
if (results.length === 0) return false;
|
|
15304
15396
|
await ctx.database.write(async () => {
|
|
15305
15397
|
await results[0].destroyPermanently();
|
|
@@ -15323,7 +15415,7 @@ var settingsStorageSchema = appSchema3({
|
|
|
15323
15415
|
});
|
|
15324
15416
|
|
|
15325
15417
|
// src/lib/db/userPreferences/operations.ts
|
|
15326
|
-
import { Q as
|
|
15418
|
+
import { Q as Q13 } from "@nozbe/watermelondb";
|
|
15327
15419
|
function userPreferenceToStored(preference) {
|
|
15328
15420
|
return {
|
|
15329
15421
|
uniqueId: preference.id,
|
|
@@ -15338,7 +15430,7 @@ function userPreferenceToStored(preference) {
|
|
|
15338
15430
|
};
|
|
15339
15431
|
}
|
|
15340
15432
|
async function getUserPreferenceOp(ctx, walletAddress) {
|
|
15341
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
15433
|
+
const results = await ctx.userPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15342
15434
|
return results.length > 0 ? userPreferenceToStored(results[0]) : null;
|
|
15343
15435
|
}
|
|
15344
15436
|
async function createUserPreferenceOp(ctx, opts) {
|
|
@@ -15358,7 +15450,7 @@ async function createUserPreferenceOp(ctx, opts) {
|
|
|
15358
15450
|
return userPreferenceToStored(created);
|
|
15359
15451
|
}
|
|
15360
15452
|
async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
15361
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
15453
|
+
const results = await ctx.userPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15362
15454
|
if (results.length === 0) return null;
|
|
15363
15455
|
const preference = results[0];
|
|
15364
15456
|
await ctx.database.write(async () => {
|
|
@@ -15386,7 +15478,7 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
15386
15478
|
async function setUserPreferenceOp(ctx, walletAddress, opts) {
|
|
15387
15479
|
const now = Date.now();
|
|
15388
15480
|
const result = await ctx.database.write(async () => {
|
|
15389
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
15481
|
+
const results = await ctx.userPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15390
15482
|
if (results.length > 0) {
|
|
15391
15483
|
const preference = results[0];
|
|
15392
15484
|
await preference.update((pref) => {
|
|
@@ -15434,7 +15526,7 @@ async function updateModelsOp(ctx, walletAddress, models) {
|
|
|
15434
15526
|
return updateUserPreferenceOp(ctx, walletAddress, { models });
|
|
15435
15527
|
}
|
|
15436
15528
|
async function deleteUserPreferenceOp(ctx, walletAddress) {
|
|
15437
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
15529
|
+
const results = await ctx.userPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15438
15530
|
if (results.length === 0) return false;
|
|
15439
15531
|
await ctx.database.write(async () => {
|
|
15440
15532
|
await results[0].destroyPermanently();
|
|
@@ -15449,9 +15541,9 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
|
|
|
15449
15541
|
if (existing) {
|
|
15450
15542
|
return existing;
|
|
15451
15543
|
}
|
|
15452
|
-
const modelResults = await ctx.modelPreferencesCollection.query(
|
|
15544
|
+
const modelResults = await ctx.modelPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15453
15545
|
const personalityKey = `${walletAddress}_personality_settings`;
|
|
15454
|
-
const personalityResults = await ctx.modelPreferencesCollection.query(
|
|
15546
|
+
const personalityResults = await ctx.modelPreferencesCollection.query(Q13.where("wallet_address", personalityKey)).fetch();
|
|
15455
15547
|
if (modelResults.length === 0 && personalityResults.length === 0) {
|
|
15456
15548
|
return null;
|
|
15457
15549
|
}
|
|
@@ -15552,7 +15644,7 @@ var SLIDER_CONFIG = [
|
|
|
15552
15644
|
];
|
|
15553
15645
|
|
|
15554
15646
|
// src/lib/db/vaultFolders/operations.ts
|
|
15555
|
-
import { Q as
|
|
15647
|
+
import { Q as Q14 } from "@nozbe/watermelondb";
|
|
15556
15648
|
function folderToStored(folder) {
|
|
15557
15649
|
return {
|
|
15558
15650
|
uniqueId: folder.id,
|
|
@@ -15577,7 +15669,7 @@ async function createVaultFolderOp(ctx, opts) {
|
|
|
15577
15669
|
return folderToStored(created);
|
|
15578
15670
|
}
|
|
15579
15671
|
async function getAllVaultFoldersOp(ctx) {
|
|
15580
|
-
const results = await ctx.vaultFolderCollection.query(
|
|
15672
|
+
const results = await ctx.vaultFolderCollection.query(Q14.where("is_deleted", false), Q14.sortBy("created_at", Q14.desc)).fetch();
|
|
15581
15673
|
return results.map(folderToStored);
|
|
15582
15674
|
}
|
|
15583
15675
|
async function updateVaultFolderOp(ctx, id, opts) {
|
|
@@ -15586,7 +15678,7 @@ async function updateVaultFolderOp(ctx, id, opts) {
|
|
|
15586
15678
|
if (record2.isDeleted) return null;
|
|
15587
15679
|
const scopeChanged = opts.scope !== void 0 && opts.scope !== record2.scope;
|
|
15588
15680
|
const updated = await ctx.database.write(async () => {
|
|
15589
|
-
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(
|
|
15681
|
+
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(Q14.where("folder_id", id), Q14.where("is_deleted", false)).fetch() : [];
|
|
15590
15682
|
const updates = [];
|
|
15591
15683
|
updates.push(
|
|
15592
15684
|
record2.prepareUpdate((r) => {
|
|
@@ -15615,7 +15707,7 @@ async function deleteVaultFolderOp(ctx, id) {
|
|
|
15615
15707
|
const record2 = await ctx.vaultFolderCollection.find(id);
|
|
15616
15708
|
if (record2.isDeleted) return false;
|
|
15617
15709
|
await ctx.database.write(async () => {
|
|
15618
|
-
const memories = await ctx.vaultMemoryCollection.query(
|
|
15710
|
+
const memories = await ctx.vaultMemoryCollection.query(Q14.where("folder_id", id), Q14.where("is_deleted", false)).fetch();
|
|
15619
15711
|
const preparedMemories = memories.map(
|
|
15620
15712
|
(memory) => memory.prepareUpdate((r) => {
|
|
15621
15713
|
r._setRaw("folder_id", null);
|
|
@@ -15686,7 +15778,7 @@ async function updateVaultFolderContextOp(ctx, id, context) {
|
|
|
15686
15778
|
}
|
|
15687
15779
|
}
|
|
15688
15780
|
async function getVaultFolderMemoryCountOp(ctx, folderId) {
|
|
15689
|
-
return await ctx.vaultMemoryCollection.query(
|
|
15781
|
+
return await ctx.vaultMemoryCollection.query(Q14.where("folder_id", folderId), Q14.where("is_deleted", false)).fetchCount();
|
|
15690
15782
|
}
|
|
15691
15783
|
|
|
15692
15784
|
// src/lib/db/vaultFolders/defaults.ts
|
|
@@ -15729,7 +15821,7 @@ async function _ensureDefaultFoldersImpl(ctx) {
|
|
|
15729
15821
|
}
|
|
15730
15822
|
|
|
15731
15823
|
// src/lib/memory/autoExtract.ts
|
|
15732
|
-
import { Q as
|
|
15824
|
+
import { Q as Q15 } from "@nozbe/watermelondb";
|
|
15733
15825
|
|
|
15734
15826
|
// src/lib/memory/entitySalience.ts
|
|
15735
15827
|
var GENERIC_ENTITY_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -18437,7 +18529,7 @@ async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
|
18437
18529
|
// src/lib/memory/autoExtract.ts
|
|
18438
18530
|
async function isMemoryTopicsUserManaged(ctx, memoryId) {
|
|
18439
18531
|
try {
|
|
18440
|
-
const rows = await ctx.database.get(VaultMemory.table).query(
|
|
18532
|
+
const rows = await ctx.database.get(VaultMemory.table).query(Q15.where("id", memoryId)).fetch();
|
|
18441
18533
|
return rows[0]?.topicsUserManaged === true;
|
|
18442
18534
|
} catch {
|
|
18443
18535
|
return true;
|
|
@@ -21008,7 +21100,7 @@ function parseAnswer(body, base, parseSchema) {
|
|
|
21008
21100
|
}
|
|
21009
21101
|
|
|
21010
21102
|
// src/lib/memory/store/local.ts
|
|
21011
|
-
import { Q as
|
|
21103
|
+
import { Q as Q16 } from "@nozbe/watermelondb";
|
|
21012
21104
|
|
|
21013
21105
|
// src/lib/memory/topicExtract.ts
|
|
21014
21106
|
var TOPIC_EXTRACTION_BATCH_SIZE = 10;
|
|
@@ -21287,8 +21379,8 @@ function createLocalMemoryStore(options) {
|
|
|
21287
21379
|
writeOptions?.signal?.throwIfAborted();
|
|
21288
21380
|
};
|
|
21289
21381
|
const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
|
|
21290
|
-
const ownedBy = userId !== void 0 ? [
|
|
21291
|
-
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [
|
|
21382
|
+
const ownedBy = userId !== void 0 ? [Q16.where("user_id", userId)] : [];
|
|
21383
|
+
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [Q16.or(Q16.where("user_id", userId), Q16.where("user_id", null))] : [Q16.where("user_id", userId)];
|
|
21292
21384
|
const watchedColumns = [
|
|
21293
21385
|
"content",
|
|
21294
21386
|
"scope",
|
|
@@ -21333,7 +21425,7 @@ function createLocalMemoryStore(options) {
|
|
|
21333
21425
|
list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
|
|
21334
21426
|
get: (id) => getVaultMemoryOp(vaultCtx, id),
|
|
21335
21427
|
listArchived: async () => {
|
|
21336
|
-
const ids = await vaultCtx.vaultMemoryCollection.query(
|
|
21428
|
+
const ids = await vaultCtx.vaultMemoryCollection.query(Q16.where("is_deleted", false), Q16.where("archived_at", Q16.notEq(null)), ...ownedBy).fetchIds();
|
|
21337
21429
|
if (ids.length === 0) return [];
|
|
21338
21430
|
const rows = await getAllVaultMemoriesOp(vaultCtx, { memoryIds: ids, includeArchived: true });
|
|
21339
21431
|
return rows.sort((a, b) => (b.archivedAt ?? 0) - (a.archivedAt ?? 0));
|
|
@@ -21349,7 +21441,7 @@ function createLocalMemoryStore(options) {
|
|
|
21349
21441
|
set.add(String(link.memory_id));
|
|
21350
21442
|
members.set(entityId, set);
|
|
21351
21443
|
}
|
|
21352
|
-
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(
|
|
21444
|
+
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(Q16.where("id", Q16.oneOf([...members.keys()]))).unsafeFetchRaw() : [];
|
|
21353
21445
|
const byName = /* @__PURE__ */ new Map();
|
|
21354
21446
|
for (const entity of entities) {
|
|
21355
21447
|
const name = String(entity.canonical_name);
|
|
@@ -21399,7 +21491,7 @@ function createLocalMemoryStore(options) {
|
|
|
21399
21491
|
setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
|
|
21400
21492
|
addTopics: (memoryId, topics, writeOptions) => database.write(async (writer) => {
|
|
21401
21493
|
await assertWrite(writeOptions);
|
|
21402
|
-
const owned = await vaultCtx.vaultMemoryCollection.query(
|
|
21494
|
+
const owned = await vaultCtx.vaultMemoryCollection.query(Q16.where("id", memoryId), Q16.where("is_deleted", false), ...ownedBy).fetchCount();
|
|
21403
21495
|
return owned > 0 ? writer.callWriter(
|
|
21404
21496
|
() => linkMemoryEntitiesOp(
|
|
21405
21497
|
{
|
|
@@ -21471,7 +21563,7 @@ function createLocalMemoryStore(options) {
|
|
|
21471
21563
|
else onChange();
|
|
21472
21564
|
};
|
|
21473
21565
|
};
|
|
21474
|
-
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(
|
|
21566
|
+
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(Q16.where("is_deleted", false), ...ownedBy).observeWithColumns(
|
|
21475
21567
|
subscribeOptions?.embeddings ? [...watchedColumns, "embedding", "embedding_model"] : watchedColumns
|
|
21476
21568
|
);
|
|
21477
21569
|
const subscriptions = [memories.subscribe(afterFirst())];
|
|
@@ -24530,7 +24622,7 @@ async function assembleMemoryContext(options) {
|
|
|
24530
24622
|
}
|
|
24531
24623
|
|
|
24532
24624
|
// src/lib/memory/durableExtraction.ts
|
|
24533
|
-
import { Q as
|
|
24625
|
+
import { Q as Q17 } from "@nozbe/watermelondb";
|
|
24534
24626
|
var MAX_JOBS_PER_PASS = 3;
|
|
24535
24627
|
var MAX_ATTEMPTS = 3;
|
|
24536
24628
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -24701,7 +24793,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24701
24793
|
const source = options.messageSource?.(conversationId);
|
|
24702
24794
|
if (source)
|
|
24703
24795
|
return await fromSource(source.status(conversationId)) === "ready" && (await loadFromSource(source, conversationId, ids)).every(Boolean);
|
|
24704
|
-
return await storage.conversationsCollection.query(
|
|
24796
|
+
return await storage.conversationsCollection.query(Q17.where("conversation_id", conversationId), Q17.where("is_deleted", false)).fetchCount() > 0 && await storage.messagesCollection.query(Q17.where("conversation_id", conversationId), Q17.where("id", Q17.oneOf(ids))).fetchCount() === ids.length;
|
|
24705
24797
|
}
|
|
24706
24798
|
function schedule(delay) {
|
|
24707
24799
|
if (disposed) return;
|
|
@@ -24875,7 +24967,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24875
24967
|
let sourceWaiting = false;
|
|
24876
24968
|
try {
|
|
24877
24969
|
await writes;
|
|
24878
|
-
const pending = await jobs.query(
|
|
24970
|
+
const pending = await jobs.query(Q17.where("owner_key", owner), Q17.where("message_ids", Q17.notEq("[]"))).fetch();
|
|
24879
24971
|
storeFailures = 0;
|
|
24880
24972
|
let processed = 0;
|
|
24881
24973
|
for (const job of pending) {
|
|
@@ -24907,7 +24999,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24907
24999
|
let ids = [];
|
|
24908
25000
|
let loaded = [];
|
|
24909
25001
|
try {
|
|
24910
|
-
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(
|
|
25002
|
+
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(Q17.where("conversation_id", conversationId), Q17.where("is_deleted", false)).fetchCount() > 0;
|
|
24911
25003
|
if (!present) {
|
|
24912
25004
|
await database.write(() => job.destroyPermanently());
|
|
24913
25005
|
continue;
|
|
@@ -25075,7 +25167,7 @@ function createDurableAutoExtractor(options) {
|
|
|
25075
25167
|
const scope = currentScope();
|
|
25076
25168
|
writes = writes.then(
|
|
25077
25169
|
() => database.write(async () => {
|
|
25078
|
-
const existing = await jobs.query(
|
|
25170
|
+
const existing = await jobs.query(Q17.where("owner_key", owner), Q17.where("conversation_id", conversationId)).fetch();
|
|
25079
25171
|
const job = existing.find(
|
|
25080
25172
|
(candidate) => candidate._getRaw("scope") === scope && (candidate._getRaw("folder_id") ?? null) === folderId
|
|
25081
25173
|
);
|
|
@@ -25088,8 +25180,8 @@ function createDurableAutoExtractor(options) {
|
|
|
25088
25180
|
if (watermarks.length) {
|
|
25089
25181
|
const misplaced = new Set(
|
|
25090
25182
|
await storage.messagesCollection.query(
|
|
25091
|
-
|
|
25092
|
-
|
|
25183
|
+
Q17.where("id", Q17.oneOf(watermarks)),
|
|
25184
|
+
Q17.where("conversation_id", Q17.notEq(conversationId))
|
|
25093
25185
|
).fetchIds()
|
|
25094
25186
|
);
|
|
25095
25187
|
for (const prior of existing)
|
|
@@ -25099,7 +25191,7 @@ function createDurableAutoExtractor(options) {
|
|
|
25099
25191
|
r._setRaw("watermark_seq", null);
|
|
25100
25192
|
});
|
|
25101
25193
|
}
|
|
25102
|
-
const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(
|
|
25194
|
+
const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(Q17.where("id", Q17.oneOf(ids))).fetch();
|
|
25103
25195
|
const foreignRows = new Set(
|
|
25104
25196
|
rows.filter((row) => row._getRaw("conversation_id") !== conversationId).map((row) => row.id)
|
|
25105
25197
|
);
|
|
@@ -29789,10 +29881,10 @@ var UNREVISIONED_COLUMNS = /* @__PURE__ */ new Set([
|
|
|
29789
29881
|
]);
|
|
29790
29882
|
async function getBackupRevision(database, conversationId) {
|
|
29791
29883
|
const serialized = await database.read(async () => {
|
|
29792
|
-
const { Q:
|
|
29884
|
+
const { Q: Q21 } = await import("@nozbe/watermelondb");
|
|
29793
29885
|
const tables = await Promise.all(
|
|
29794
29886
|
["conversations", "history"].map(
|
|
29795
|
-
(table) => database.get(table).query(
|
|
29887
|
+
(table) => database.get(table).query(Q21.where("conversation_id", conversationId), Q21.sortBy("id", Q21.asc)).unsafeFetchRaw()
|
|
29796
29888
|
)
|
|
29797
29889
|
);
|
|
29798
29890
|
return JSON.stringify(
|
|
@@ -29835,9 +29927,9 @@ async function pushConversationToICloud(database, conversationId, userAddress, d
|
|
|
29835
29927
|
}
|
|
29836
29928
|
async function performICloudExport(database, userAddress, deps, onProgress) {
|
|
29837
29929
|
await deps.requestEncryptionKey(userAddress);
|
|
29838
|
-
const { Q:
|
|
29930
|
+
const { Q: Q21 } = await import("@nozbe/watermelondb");
|
|
29839
29931
|
const conversationsCollection = database.get("conversations");
|
|
29840
|
-
const records = await conversationsCollection.query(
|
|
29932
|
+
const records = await conversationsCollection.query(Q21.where("is_deleted", false)).fetch();
|
|
29841
29933
|
const conversations = records.map(conversationToStoredRaw);
|
|
29842
29934
|
const total = conversations.length;
|
|
29843
29935
|
if (total === 0) {
|
|
@@ -31583,6 +31675,8 @@ function useChatStorage(options) {
|
|
|
31583
31675
|
embeddedWalletSigner
|
|
31584
31676
|
]
|
|
31585
31677
|
);
|
|
31678
|
+
const storageCtxRef = useRef4(storageCtx);
|
|
31679
|
+
storageCtxRef.current = storageCtx;
|
|
31586
31680
|
const mediaCtx = useMemo4(
|
|
31587
31681
|
() => ({
|
|
31588
31682
|
database,
|
|
@@ -31719,14 +31813,6 @@ function useChatStorage(options) {
|
|
|
31719
31813
|
refreshQueueStatus();
|
|
31720
31814
|
return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
|
|
31721
31815
|
}, [walletAddress, refreshQueueStatus]);
|
|
31722
|
-
useEffect4(() => {
|
|
31723
|
-
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
31724
|
-
return onKeyAvailable(walletAddress, () => {
|
|
31725
|
-
flushQueue().catch((err) => {
|
|
31726
|
-
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
31727
|
-
});
|
|
31728
|
-
});
|
|
31729
|
-
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
31730
31816
|
useEffect4(() => {
|
|
31731
31817
|
if (!getWalletAddress || walletAddress) return;
|
|
31732
31818
|
const poller = new WalletPoller();
|
|
@@ -31750,34 +31836,49 @@ function useChatStorage(options) {
|
|
|
31750
31836
|
pendingOpsRef.current = [];
|
|
31751
31837
|
refreshQueueStatus();
|
|
31752
31838
|
}, [walletAddress, enableQueue, refreshQueueStatus]);
|
|
31839
|
+
useEffect4(() => {
|
|
31840
|
+
if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
|
|
31841
|
+
return onKeyAvailable(walletAddress, () => {
|
|
31842
|
+
flushQueue().catch((err) => {
|
|
31843
|
+
getLogger().warn("[useChatStorage] Auto-flush failed:", err);
|
|
31844
|
+
});
|
|
31845
|
+
});
|
|
31846
|
+
}, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
|
|
31753
31847
|
const writeOrQueue = useCallback5(
|
|
31754
31848
|
async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
|
|
31755
|
-
|
|
31756
|
-
|
|
31849
|
+
const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
|
|
31850
|
+
const currentWalletAddress = currentStorageCtx.walletAddress;
|
|
31851
|
+
if (enableQueue && signMessage && !currentWalletAddress && getWalletAddress) {
|
|
31852
|
+
pendingOpsRef.current.push({ type: opType, payload, dependencies });
|
|
31853
|
+
return { result: makeSynthetic(), queued: true };
|
|
31854
|
+
}
|
|
31855
|
+
if (!currentWalletAddress || !currentStorageCtx.signMessage || hasEncryptionKey(currentWalletAddress)) {
|
|
31856
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
31757
31857
|
return { result: result2, queued: false };
|
|
31758
31858
|
}
|
|
31759
31859
|
if (!enableQueue) {
|
|
31760
|
-
const result2 = await directWrite();
|
|
31860
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
31761
31861
|
return { result: result2, queued: false };
|
|
31762
31862
|
}
|
|
31763
|
-
if (
|
|
31764
|
-
|
|
31765
|
-
|
|
31766
|
-
|
|
31767
|
-
|
|
31768
|
-
|
|
31863
|
+
if (currentWalletAddress) {
|
|
31864
|
+
const queueId = queueManager.queueOperation(
|
|
31865
|
+
currentWalletAddress,
|
|
31866
|
+
opType,
|
|
31867
|
+
payload,
|
|
31868
|
+
dependencies
|
|
31869
|
+
);
|
|
31769
31870
|
if (queueId === null) {
|
|
31770
31871
|
getLogger().warn("[useChatStorage] Queue full, falling back to direct write");
|
|
31771
|
-
const result2 = await directWrite();
|
|
31872
|
+
const result2 = await directWrite(currentStorageCtx);
|
|
31772
31873
|
return { result: result2, queued: false };
|
|
31773
31874
|
}
|
|
31774
|
-
|
|
31875
|
+
setQueueStatus(queueManager.getStatus(currentWalletAddress));
|
|
31775
31876
|
return { result: makeSynthetic(), queued: true, queueId };
|
|
31776
31877
|
}
|
|
31777
|
-
const result = await directWrite();
|
|
31878
|
+
const result = await directWrite(currentStorageCtx);
|
|
31778
31879
|
return { result, queued: false };
|
|
31779
31880
|
},
|
|
31780
|
-
[
|
|
31881
|
+
[storageCtx, enableQueue, signMessage, getWalletAddress]
|
|
31781
31882
|
);
|
|
31782
31883
|
const embedMessageAsync = useCallback5(
|
|
31783
31884
|
async (message, mask = maskForEmbedding) => {
|
|
@@ -32117,7 +32218,7 @@ function useChatStorage(options) {
|
|
|
32117
32218
|
const { result, queued, queueId } = await writeOrQueue(
|
|
32118
32219
|
"createConversation",
|
|
32119
32220
|
conversationOpts,
|
|
32120
|
-
() => createConversationOp(
|
|
32221
|
+
(ctx) => createConversationOp(ctx, conversationOpts, defaultConversationTitle),
|
|
32121
32222
|
() => makeSyntheticStoredConversation(conversationOpts, defaultConversationTitle)
|
|
32122
32223
|
);
|
|
32123
32224
|
if (queued) {
|
|
@@ -32129,7 +32230,7 @@ function useChatStorage(options) {
|
|
|
32129
32230
|
setCurrentConversationId(result.conversationId);
|
|
32130
32231
|
return result;
|
|
32131
32232
|
},
|
|
32132
|
-
[
|
|
32233
|
+
[defaultConversationTitle, writeOrQueue]
|
|
32133
32234
|
);
|
|
32134
32235
|
const getConversation = useCallback5(
|
|
32135
32236
|
async (id) => {
|
|
@@ -32145,24 +32246,24 @@ function useChatStorage(options) {
|
|
|
32145
32246
|
const { result } = await writeOrQueue(
|
|
32146
32247
|
"updateConversationTitle",
|
|
32147
32248
|
{ conversationId: id, title },
|
|
32148
|
-
() => updateConversationTitleOp(
|
|
32249
|
+
(ctx) => updateConversationTitleOp(ctx, id, title),
|
|
32149
32250
|
() => true
|
|
32150
32251
|
);
|
|
32151
32252
|
return result;
|
|
32152
32253
|
},
|
|
32153
|
-
[
|
|
32254
|
+
[writeOrQueue]
|
|
32154
32255
|
);
|
|
32155
32256
|
const updateConversationPinned = useCallback5(
|
|
32156
32257
|
async (id, pinned) => {
|
|
32157
32258
|
const { result } = await writeOrQueue(
|
|
32158
32259
|
"updateConversationPinned",
|
|
32159
32260
|
{ conversationId: id, pinned },
|
|
32160
|
-
() => updateConversationPinnedOp(
|
|
32261
|
+
(ctx) => updateConversationPinnedOp(ctx, id, pinned),
|
|
32161
32262
|
() => true
|
|
32162
32263
|
);
|
|
32163
32264
|
return result;
|
|
32164
32265
|
},
|
|
32165
|
-
[
|
|
32266
|
+
[writeOrQueue]
|
|
32166
32267
|
);
|
|
32167
32268
|
const deleteConversation = useCallback5(
|
|
32168
32269
|
async (id) => {
|
|
@@ -32821,7 +32922,7 @@ function useChatStorage(options) {
|
|
|
32821
32922
|
const userMsgResult = await writeOrQueue(
|
|
32822
32923
|
"createMessage",
|
|
32823
32924
|
userMsgOpts,
|
|
32824
|
-
() => createMessageOp(
|
|
32925
|
+
(ctx) => createMessageOp(ctx, userMsgOpts),
|
|
32825
32926
|
() => makeSyntheticStoredMessage(userMsgOpts),
|
|
32826
32927
|
convId && syntheticConvQueueIdsRef.current.has(convId) ? [syntheticConvQueueIdsRef.current.get(convId)] : []
|
|
32827
32928
|
);
|
|
@@ -33142,7 +33243,7 @@ function useChatStorage(options) {
|
|
|
33142
33243
|
const assistantMsgResult = await writeOrQueue(
|
|
33143
33244
|
"createMessage",
|
|
33144
33245
|
assistantMsgOpts,
|
|
33145
|
-
() => createMessageOp(
|
|
33246
|
+
(ctx) => createMessageOp(ctx, assistantMsgOpts),
|
|
33146
33247
|
() => makeSyntheticStoredMessage(assistantMsgOpts),
|
|
33147
33248
|
userMsgQueueId ? [userMsgQueueId] : []
|
|
33148
33249
|
);
|
|
@@ -33193,7 +33294,7 @@ function useChatStorage(options) {
|
|
|
33193
33294
|
const toolResultsWrite = await writeOrQueue(
|
|
33194
33295
|
"createMessage",
|
|
33195
33296
|
toolResultsOpts,
|
|
33196
|
-
() => createMessageOp(
|
|
33297
|
+
(ctx) => createMessageOp(ctx, toolResultsOpts),
|
|
33197
33298
|
() => makeSyntheticStoredMessage(toolResultsOpts),
|
|
33198
33299
|
assistantMsgQueueId ? [assistantMsgQueueId] : []
|
|
33199
33300
|
);
|
|
@@ -33551,7 +33652,7 @@ function useExportPdf() {
|
|
|
33551
33652
|
}
|
|
33552
33653
|
|
|
33553
33654
|
// src/react/useFiles.ts
|
|
33554
|
-
import { Q as
|
|
33655
|
+
import { Q as Q18 } from "@nozbe/watermelondb";
|
|
33555
33656
|
import { useCallback as useCallback8, useEffect as useEffect6, useMemo as useMemo6, useState as useState8 } from "react";
|
|
33556
33657
|
function useFiles(options) {
|
|
33557
33658
|
const { database, walletAddress } = options;
|
|
@@ -33569,7 +33670,7 @@ function useFiles(options) {
|
|
|
33569
33670
|
setIsLoading(true);
|
|
33570
33671
|
try {
|
|
33571
33672
|
const coll = database.get("media");
|
|
33572
|
-
await coll.query(
|
|
33673
|
+
await coll.query(Q18.take(1)).fetch();
|
|
33573
33674
|
setMediaCollection(coll);
|
|
33574
33675
|
setIsReady(true);
|
|
33575
33676
|
} catch (error) {
|
|
@@ -34794,7 +34895,7 @@ function usePhoneCalls(options = {}) {
|
|
|
34794
34895
|
}
|
|
34795
34896
|
|
|
34796
34897
|
// src/react/useProjects.ts
|
|
34797
|
-
import { Q as
|
|
34898
|
+
import { Q as Q19 } from "@nozbe/watermelondb";
|
|
34798
34899
|
import { useCallback as useCallback15, useEffect as useEffect10, useMemo as useMemo8, useState as useState14 } from "react";
|
|
34799
34900
|
function useProjects(options) {
|
|
34800
34901
|
const { database, initialProjectId } = options;
|
|
@@ -34816,7 +34917,7 @@ function useProjects(options) {
|
|
|
34816
34917
|
conversations: convColl?.table
|
|
34817
34918
|
});
|
|
34818
34919
|
getLogger().debug("[useProjects] Running test query on projects table...");
|
|
34819
|
-
const testResult = await projColl.query(
|
|
34920
|
+
const testResult = await projColl.query(Q19.take(1)).fetch();
|
|
34820
34921
|
getLogger().debug(
|
|
34821
34922
|
"[useProjects] Test query succeeded, found",
|
|
34822
34923
|
testResult.length,
|
|
@@ -34903,7 +35004,7 @@ function useProjects(options) {
|
|
|
34903
35004
|
if (!projectsCollection) {
|
|
34904
35005
|
return;
|
|
34905
35006
|
}
|
|
34906
|
-
const subscription = projectsCollection.query(
|
|
35007
|
+
const subscription = projectsCollection.query(Q19.where("is_deleted", false)).observe().subscribe((records) => {
|
|
34907
35008
|
setProjects(records.map(projectToStored));
|
|
34908
35009
|
});
|
|
34909
35010
|
return () => subscription.unsubscribe();
|
|
@@ -35025,7 +35126,7 @@ function useProjects(options) {
|
|
|
35025
35126
|
import { useCallback as useCallback16, useMemo as useMemo9, useSyncExternalStore } from "react";
|
|
35026
35127
|
|
|
35027
35128
|
// src/react/userSettingsStore.ts
|
|
35028
|
-
import { Q as
|
|
35129
|
+
import { Q as Q20 } from "@nozbe/watermelondb";
|
|
35029
35130
|
var EMPTY_SNAPSHOT = Object.freeze({
|
|
35030
35131
|
modelPreference: null,
|
|
35031
35132
|
userPreference: null,
|
|
@@ -35077,7 +35178,7 @@ async function startLoad(entry, walletAddress) {
|
|
|
35077
35178
|
}
|
|
35078
35179
|
function startObserve(entry, walletAddress) {
|
|
35079
35180
|
let isInitialEmission = true;
|
|
35080
|
-
entry.observeSub = entry.storageCtx.userPreferencesCollection.query(
|
|
35181
|
+
entry.observeSub = entry.storageCtx.userPreferencesCollection.query(Q20.where("wallet_address", walletAddress)).observeWithColumns([
|
|
35081
35182
|
"nickname",
|
|
35082
35183
|
"occupation",
|
|
35083
35184
|
"description",
|