@anuma/sdk 8.0.1 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expo/index.cjs +542 -227
- package/dist/expo/index.d.mts +113 -2
- package/dist/expo/index.d.ts +113 -2
- package/dist/expo/index.mjs +490 -179
- package/dist/index.cjs +21 -1
- package/dist/index.mjs +21 -1
- package/dist/react/index.cjs +651 -326
- package/dist/react/index.d.mts +117 -2
- package/dist/react/index.d.ts +117 -2
- package/dist/react/index.mjs +593 -272
- package/dist/server/index.cjs +63 -4
- package/dist/server/index.d.mts +6 -1
- package/dist/server/index.d.ts +6 -1
- package/dist/server/index.mjs +63 -4
- package/dist/tools/index.cjs +142 -0
- package/dist/tools/index.d.mts +91 -1
- package/dist/tools/index.d.ts +91 -1
- package/dist/tools/index.mjs +138 -0
- package/dist/tools/selection/index.cjs +25 -3
- package/dist/tools/selection/index.d.mts +1 -1
- package/dist/tools/selection/index.d.ts +1 -1
- package/dist/tools/selection/index.mjs +25 -3
- 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"));
|
|
@@ -5376,6 +5468,17 @@ function missingConfirmFields(action, parameters) {
|
|
|
5376
5468
|
return requirement.fields.filter((field10) => !shown.has(field10));
|
|
5377
5469
|
}
|
|
5378
5470
|
|
|
5471
|
+
// src/tools/walletPaymentConstants.ts
|
|
5472
|
+
var SELECT_PAYMENT_WALLET_TOOL_NAME = "select_payment_wallet";
|
|
5473
|
+
var WALLET_PAYMENT_TOOL_NAME = "prompt_wallet_payment";
|
|
5474
|
+
var FLIGHT_BOOK_TOOL_SET = "flight-book";
|
|
5475
|
+
var FLIGHT_SERVER_TOOL_NAMES = [
|
|
5476
|
+
"AnumaPaymentsMCP-anuma_search_flights",
|
|
5477
|
+
"AnumaPaymentsMCP-anuma_flight_offer_details",
|
|
5478
|
+
"AnumaPaymentsMCP-anuma_create_flight_intent",
|
|
5479
|
+
"AnumaPaymentsMCP-anuma_get_flight_booking"
|
|
5480
|
+
];
|
|
5481
|
+
|
|
5379
5482
|
// src/lib/storage/mcpImages.ts
|
|
5380
5483
|
var IMAGE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
5381
5484
|
"AnumaMediaMCP-anuma_create_image",
|
|
@@ -6148,7 +6251,8 @@ var BUILT_IN_TOOL_SETS = [
|
|
|
6148
6251
|
"AnumaPaymentsMCP-anuma_cancel_reservation"
|
|
6149
6252
|
],
|
|
6150
6253
|
anchors: []
|
|
6151
|
-
}
|
|
6254
|
+
},
|
|
6255
|
+
{ name: FLIGHT_BOOK_TOOL_SET, members: [...FLIGHT_SERVER_TOOL_NAMES], anchors: [] }
|
|
6152
6256
|
];
|
|
6153
6257
|
var CONFIRMED_ACTION_TOOL_SETS = /* @__PURE__ */ new Map([
|
|
6154
6258
|
["book_restaurant", "restaurant-book"],
|
|
@@ -6280,6 +6384,16 @@ var SERVER_TOOL_DEPENDENCY_SETS = [
|
|
|
6280
6384
|
members: ["AnumaPaymentsMCP-anuma_list_reservations"],
|
|
6281
6385
|
anchors: ["AnumaPaymentsMCP-anuma_cancel_reservation"],
|
|
6282
6386
|
anchorMinSimilarity: 0.5
|
|
6387
|
+
},
|
|
6388
|
+
{
|
|
6389
|
+
name: "flight-book-lookup",
|
|
6390
|
+
members: [
|
|
6391
|
+
"AnumaPaymentsMCP-anuma_flight_offer_details",
|
|
6392
|
+
"AnumaPaymentsMCP-anuma_create_flight_intent",
|
|
6393
|
+
"AnumaPaymentsMCP-anuma_get_flight_booking"
|
|
6394
|
+
],
|
|
6395
|
+
anchors: ["AnumaPaymentsMCP-anuma_search_flights"],
|
|
6396
|
+
anchorMinSimilarity: 0.5
|
|
6283
6397
|
}
|
|
6284
6398
|
];
|
|
6285
6399
|
var defaultServerToolsFilter = createServerToolsFilter({
|
|
@@ -8589,7 +8703,14 @@ function getToolName(tool) {
|
|
|
8589
8703
|
function toolsAfterConfirmation(apiTools, executionResults) {
|
|
8590
8704
|
const members = /* @__PURE__ */ new Set();
|
|
8591
8705
|
let keepConfirm = false;
|
|
8706
|
+
let keepPaymentTools = false;
|
|
8592
8707
|
for (const r of executionResults) {
|
|
8708
|
+
if (r.name === SELECT_PAYMENT_WALLET_TOOL_NAME && r.result?.confirmed === true) {
|
|
8709
|
+
const flightSet = BUILT_IN_TOOL_SETS.find((s) => s.name === FLIGHT_BOOK_TOOL_SET);
|
|
8710
|
+
for (const member of flightSet?.members ?? []) members.add(member);
|
|
8711
|
+
keepPaymentTools = true;
|
|
8712
|
+
continue;
|
|
8713
|
+
}
|
|
8593
8714
|
if (r.name !== CONFIRM_TOOL_NAME) continue;
|
|
8594
8715
|
const answer = r.result;
|
|
8595
8716
|
if (answer?.confirmed !== true || typeof answer.action !== "string") continue;
|
|
@@ -8601,7 +8722,7 @@ function toolsAfterConfirmation(apiTools, executionResults) {
|
|
|
8601
8722
|
if (!apiTools.some((t) => members.has(getToolName(t) ?? ""))) return void 0;
|
|
8602
8723
|
return apiTools.filter((t) => {
|
|
8603
8724
|
const name = getToolName(t) ?? "";
|
|
8604
|
-
return members.has(name) || name === TOOL_SEARCH_TOOL_NAME || keepConfirm && name === CONFIRM_TOOL_NAME;
|
|
8725
|
+
return members.has(name) || name === TOOL_SEARCH_TOOL_NAME || keepConfirm && name === CONFIRM_TOOL_NAME || keepPaymentTools && (name === SELECT_PAYMENT_WALLET_TOOL_NAME || name === WALLET_PAYMENT_TOOL_NAME);
|
|
8605
8726
|
});
|
|
8606
8727
|
}
|
|
8607
8728
|
var STREAM_RESUMABLE_HEADER = "X-Stream-Resumable";
|
|
@@ -9999,7 +10120,7 @@ __decorateClass([
|
|
|
9999
10120
|
], AppFile.prototype, "updatedAt", 2);
|
|
10000
10121
|
|
|
10001
10122
|
// src/lib/db/appFiles/operations.ts
|
|
10002
|
-
import { Q as
|
|
10123
|
+
import { Q as Q3 } from "@nozbe/watermelondb";
|
|
10003
10124
|
|
|
10004
10125
|
// src/utils/paths.ts
|
|
10005
10126
|
function normalizePath(p) {
|
|
@@ -10025,7 +10146,7 @@ async function putAppFileOp(ctx, conversationId, path, content) {
|
|
|
10025
10146
|
const normalized = normalizePath(path);
|
|
10026
10147
|
const now = Date.now();
|
|
10027
10148
|
const result = await ctx.database.write(async () => {
|
|
10028
|
-
const existing = await ctx.appFilesCollection.query(
|
|
10149
|
+
const existing = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId), Q3.where("path", normalized)).fetch();
|
|
10029
10150
|
if (existing.length > 0) {
|
|
10030
10151
|
await existing[0].update((f) => {
|
|
10031
10152
|
f._setRaw("content", content);
|
|
@@ -10045,11 +10166,11 @@ async function putAppFileOp(ctx, conversationId, path, content) {
|
|
|
10045
10166
|
}
|
|
10046
10167
|
async function getAppFileOp(ctx, conversationId, path) {
|
|
10047
10168
|
const normalized = normalizePath(path);
|
|
10048
|
-
const results = await ctx.appFilesCollection.query(
|
|
10169
|
+
const results = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId), Q3.where("path", normalized)).fetch();
|
|
10049
10170
|
return results.length > 0 ? appFileToStored(results[0]) : null;
|
|
10050
10171
|
}
|
|
10051
10172
|
async function getAppFilesOp(ctx, conversationId) {
|
|
10052
|
-
const results = await ctx.appFilesCollection.query(
|
|
10173
|
+
const results = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId)).fetch();
|
|
10053
10174
|
return results.map(appFileToStored);
|
|
10054
10175
|
}
|
|
10055
10176
|
async function getAppFileMapOp(ctx, conversationId) {
|
|
@@ -10060,7 +10181,7 @@ async function getAppFileMapOp(ctx, conversationId) {
|
|
|
10060
10181
|
}
|
|
10061
10182
|
async function deleteAppFileOp(ctx, conversationId, path) {
|
|
10062
10183
|
const normalized = normalizePath(path);
|
|
10063
|
-
const results = await ctx.appFilesCollection.query(
|
|
10184
|
+
const results = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId), Q3.where("path", normalized)).fetch();
|
|
10064
10185
|
if (results.length === 0) return false;
|
|
10065
10186
|
await ctx.database.write(async () => {
|
|
10066
10187
|
await results[0].destroyPermanently();
|
|
@@ -10068,7 +10189,7 @@ async function deleteAppFileOp(ctx, conversationId, path) {
|
|
|
10068
10189
|
return true;
|
|
10069
10190
|
}
|
|
10070
10191
|
async function deleteAllAppFilesOp(ctx, conversationId) {
|
|
10071
|
-
const results = await ctx.appFilesCollection.query(
|
|
10192
|
+
const results = await ctx.appFilesCollection.query(Q3.where("conversation_id", conversationId)).fetch();
|
|
10072
10193
|
if (results.length === 0) return;
|
|
10073
10194
|
await ctx.database.write(async () => {
|
|
10074
10195
|
const batch = results.map((file) => file.prepareDestroyPermanently());
|
|
@@ -10377,7 +10498,7 @@ var chatStorageMigrations = schemaMigrations({
|
|
|
10377
10498
|
});
|
|
10378
10499
|
|
|
10379
10500
|
// src/lib/db/chat/summaryOperations.ts
|
|
10380
|
-
import { Q as
|
|
10501
|
+
import { Q as Q4 } from "@nozbe/watermelondb";
|
|
10381
10502
|
function createSummaryContext(database) {
|
|
10382
10503
|
return {
|
|
10383
10504
|
database,
|
|
@@ -10396,14 +10517,14 @@ function modelToStored(record2) {
|
|
|
10396
10517
|
};
|
|
10397
10518
|
}
|
|
10398
10519
|
async function getConversationSummaryOp(ctx, conversationId) {
|
|
10399
|
-
const results = await ctx.summariesCollection.query(
|
|
10520
|
+
const results = await ctx.summariesCollection.query(Q4.where("conversation_id", conversationId)).fetch();
|
|
10400
10521
|
if (results.length === 0) return null;
|
|
10401
10522
|
return modelToStored(results[0]);
|
|
10402
10523
|
}
|
|
10403
10524
|
async function upsertConversationSummaryOp(ctx, conversationId, summary, summarizedUpTo, tokenCount) {
|
|
10404
10525
|
let record2;
|
|
10405
10526
|
await ctx.database.write(async () => {
|
|
10406
|
-
const existing = await ctx.summariesCollection.query(
|
|
10527
|
+
const existing = await ctx.summariesCollection.query(Q4.where("conversation_id", conversationId)).fetch();
|
|
10407
10528
|
if (existing.length > 0) {
|
|
10408
10529
|
record2 = await existing[0].update((rec) => {
|
|
10409
10530
|
rec.summary = summary;
|
|
@@ -10423,7 +10544,7 @@ async function upsertConversationSummaryOp(ctx, conversationId, summary, summari
|
|
|
10423
10544
|
}
|
|
10424
10545
|
async function deleteConversationSummaryOp(ctx, conversationId) {
|
|
10425
10546
|
await ctx.database.write(async () => {
|
|
10426
|
-
const existing = await ctx.summariesCollection.query(
|
|
10547
|
+
const existing = await ctx.summariesCollection.query(Q4.where("conversation_id", conversationId)).fetch();
|
|
10427
10548
|
for (const record2 of existing) {
|
|
10428
10549
|
await record2.destroyPermanently();
|
|
10429
10550
|
}
|
|
@@ -10452,7 +10573,7 @@ __decorateClass([
|
|
|
10452
10573
|
], ConversationMemory.prototype, "createdAt", 2);
|
|
10453
10574
|
|
|
10454
10575
|
// src/lib/db/conversationMemory/operations.ts
|
|
10455
|
-
import { Q as
|
|
10576
|
+
import { Q as Q5 } from "@nozbe/watermelondb";
|
|
10456
10577
|
var MAX_PER_CONVERSATION = 200;
|
|
10457
10578
|
function conversationMemoryToStored(row) {
|
|
10458
10579
|
return {
|
|
@@ -10467,7 +10588,7 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
10467
10588
|
if (!conversationId || items.length === 0) return;
|
|
10468
10589
|
const now = Date.now();
|
|
10469
10590
|
await ctx.database.write(async () => {
|
|
10470
|
-
const existing = await ctx.conversationMemoryCollection.query(
|
|
10591
|
+
const existing = await ctx.conversationMemoryCollection.query(Q5.where("conversation_id", conversationId), Q5.sortBy("created_at", Q5.asc)).fetch();
|
|
10471
10592
|
const seen = new Set(existing.map((r) => r.memoryId));
|
|
10472
10593
|
const batchSeen = /* @__PURE__ */ new Set();
|
|
10473
10594
|
const deduped = [];
|
|
@@ -10497,13 +10618,13 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
10497
10618
|
}
|
|
10498
10619
|
async function getConversationMemoriesOp(ctx, conversationId) {
|
|
10499
10620
|
if (!conversationId) return [];
|
|
10500
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
10621
|
+
const rows = await ctx.conversationMemoryCollection.query(Q5.where("conversation_id", conversationId), Q5.sortBy("created_at", Q5.asc)).fetch();
|
|
10501
10622
|
return rows.map(conversationMemoryToStored);
|
|
10502
10623
|
}
|
|
10503
10624
|
async function clearConversationMemoriesOp(ctx, conversationId) {
|
|
10504
10625
|
if (!conversationId) return;
|
|
10505
10626
|
await ctx.database.write(async () => {
|
|
10506
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
10627
|
+
const rows = await ctx.conversationMemoryCollection.query(Q5.where("conversation_id", conversationId)).fetch();
|
|
10507
10628
|
if (rows.length === 0) return;
|
|
10508
10629
|
await ctx.database.batch(...rows.map((r) => r.prepareDestroyPermanently()));
|
|
10509
10630
|
});
|
|
@@ -10546,7 +10667,7 @@ __decorateClass([
|
|
|
10546
10667
|
], MemoryEntity.prototype, "createdAt", 2);
|
|
10547
10668
|
|
|
10548
10669
|
// src/lib/db/entities/operations.ts
|
|
10549
|
-
import { Q as
|
|
10670
|
+
import { Q as Q6 } from "@nozbe/watermelondb";
|
|
10550
10671
|
|
|
10551
10672
|
// src/lib/db/memoryVault/types.ts
|
|
10552
10673
|
var MEMORY_KINDS = [
|
|
@@ -10695,7 +10816,7 @@ async function upsertEntitiesInWrite(ctx, entities) {
|
|
|
10695
10816
|
const unique = Array.from(kindByName.keys());
|
|
10696
10817
|
const out = /* @__PURE__ */ new Map();
|
|
10697
10818
|
if (unique.length === 0) return { entities: out, operations: [], kindBackfills: [] };
|
|
10698
|
-
const existing = await ctx.entityCollection.query(
|
|
10819
|
+
const existing = await ctx.entityCollection.query(Q6.where("canonical_name", Q6.oneOf(unique))).fetch();
|
|
10699
10820
|
const existingNames = new Set(existing.map((e) => e.canonicalName));
|
|
10700
10821
|
const kindBackfills = existing.filter((e) => {
|
|
10701
10822
|
const incoming = kindByName.get(e.canonicalName);
|
|
@@ -10725,7 +10846,7 @@ function prepareKindBackfills(backfills) {
|
|
|
10725
10846
|
}
|
|
10726
10847
|
async function findVaultRowInWrite(ctx, memoryId) {
|
|
10727
10848
|
try {
|
|
10728
|
-
const rows = await ctx.database.get("memory_vault").query(
|
|
10849
|
+
const rows = await ctx.database.get("memory_vault").query(Q6.where("id", memoryId)).fetch();
|
|
10729
10850
|
return rows[0] ?? null;
|
|
10730
10851
|
} catch {
|
|
10731
10852
|
return null;
|
|
@@ -10827,7 +10948,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
10827
10948
|
return;
|
|
10828
10949
|
}
|
|
10829
10950
|
if (entities.length === 0) return;
|
|
10830
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
10951
|
+
const existingLinks = await ctx.memoryEntityCollection.query(Q6.where("memory_id", memoryId)).fetch();
|
|
10831
10952
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
10832
10953
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
10833
10954
|
const keptIds = entities.map((e) => e.uniqueId);
|
|
@@ -10863,7 +10984,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
10863
10984
|
}
|
|
10864
10985
|
async function resolveEntitiesByIds(ctx, entityIds) {
|
|
10865
10986
|
if (entityIds.length === 0) return [];
|
|
10866
|
-
const rows = await ctx.entityCollection.query(
|
|
10987
|
+
const rows = await ctx.entityCollection.query(Q6.where("id", Q6.oneOf(Array.from(entityIds)))).fetch();
|
|
10867
10988
|
return rows.map(entityToStored);
|
|
10868
10989
|
}
|
|
10869
10990
|
function autoLinkBlocked(row) {
|
|
@@ -10899,7 +11020,7 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
10899
11020
|
kindBackfills
|
|
10900
11021
|
} = await upsertEntitiesInWrite(ctx, normalized);
|
|
10901
11022
|
entities = Array.from(byName.values());
|
|
10902
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
11023
|
+
const existingLinks = await ctx.memoryEntityCollection.query(Q6.where("memory_id", memoryId)).fetch();
|
|
10903
11024
|
const keep = new Set(entities.map((e) => e.uniqueId));
|
|
10904
11025
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
10905
11026
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
@@ -10935,17 +11056,17 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
10935
11056
|
async function findOrphanedEntities(ctx, memoryId, toDestroy) {
|
|
10936
11057
|
const candidateIds = [...new Set(toDestroy.map((l) => String(l.entityId)))];
|
|
10937
11058
|
if (candidateIds.length === 0) return [];
|
|
10938
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
11059
|
+
const links = await ctx.memoryEntityCollection.query(Q6.where("entity_id", Q6.oneOf(candidateIds))).fetch();
|
|
10939
11060
|
const stillLinked = new Set(
|
|
10940
11061
|
links.filter((l) => String(l.memoryId) !== memoryId).map((l) => String(l.entityId))
|
|
10941
11062
|
);
|
|
10942
11063
|
const orphanIds = candidateIds.filter((id) => !stillLinked.has(id));
|
|
10943
11064
|
if (orphanIds.length === 0) return [];
|
|
10944
|
-
return await ctx.entityCollection.query(
|
|
11065
|
+
return await ctx.entityCollection.query(Q6.where("id", Q6.oneOf(orphanIds))).fetch();
|
|
10945
11066
|
}
|
|
10946
11067
|
async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
10947
11068
|
if (memoryIds.length === 0) return;
|
|
10948
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
11069
|
+
const links = await ctx.memoryEntityCollection.query(Q6.where("memory_id", Q6.oneOf(Array.from(memoryIds)))).fetch();
|
|
10949
11070
|
if (links.length === 0) return;
|
|
10950
11071
|
await ctx.database.write(async () => {
|
|
10951
11072
|
await assertCanWrite(ctx);
|
|
@@ -10954,7 +11075,7 @@ async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
|
10954
11075
|
}
|
|
10955
11076
|
async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
10956
11077
|
if (!userId) return;
|
|
10957
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
11078
|
+
const links = await ctx.memoryEntityCollection.query(Q6.where("user_id", userId)).fetch();
|
|
10958
11079
|
if (links.length === 0) return;
|
|
10959
11080
|
await ctx.database.write(async () => {
|
|
10960
11081
|
await assertCanWrite(ctx);
|
|
@@ -10962,7 +11083,7 @@ async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
|
10962
11083
|
});
|
|
10963
11084
|
}
|
|
10964
11085
|
async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
10965
|
-
const unstamped = await ctx.memoryEntityCollection.query(
|
|
11086
|
+
const unstamped = await ctx.memoryEntityCollection.query(Q6.where("user_id", null)).fetch();
|
|
10966
11087
|
if (unstamped.length === 0) return 0;
|
|
10967
11088
|
const toUpdate = [];
|
|
10968
11089
|
for (const link of unstamped) {
|
|
@@ -10987,15 +11108,15 @@ async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
|
10987
11108
|
async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
10988
11109
|
const unique = Array.from(new Set(entityNames.map(normalizeEntityName).filter((n) => n.length > 0)));
|
|
10989
11110
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
10990
|
-
const entityRows = await ctx.entityCollection.query(
|
|
11111
|
+
const entityRows = await ctx.entityCollection.query(Q6.where("canonical_name", Q6.oneOf(unique))).fetch();
|
|
10991
11112
|
if (entityRows.length === 0) return /* @__PURE__ */ new Map();
|
|
10992
11113
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
10993
|
-
const linkConditions = [
|
|
11114
|
+
const linkConditions = [Q6.where("entity_id", Q6.oneOf(entityRows.map((e) => e.id)))];
|
|
10994
11115
|
if (ctx.userId !== void 0) {
|
|
10995
11116
|
if (ctx.allowUnscopedRows) {
|
|
10996
|
-
linkConditions.push(
|
|
11117
|
+
linkConditions.push(Q6.or(Q6.where("user_id", ctx.userId), Q6.where("user_id", null)));
|
|
10997
11118
|
} else {
|
|
10998
|
-
linkConditions.push(
|
|
11119
|
+
linkConditions.push(Q6.where("user_id", ctx.userId));
|
|
10999
11120
|
}
|
|
11000
11121
|
}
|
|
11001
11122
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
@@ -11016,18 +11137,18 @@ async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
|
11016
11137
|
async function getEntitiesByMemoryIdsOp(ctx, memoryIds) {
|
|
11017
11138
|
const unique = Array.from(new Set(memoryIds.filter((id) => id.length > 0)));
|
|
11018
11139
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
11019
|
-
const linkConditions = [
|
|
11140
|
+
const linkConditions = [Q6.where("memory_id", Q6.oneOf(unique))];
|
|
11020
11141
|
if (ctx.userId !== void 0) {
|
|
11021
11142
|
if (ctx.allowUnscopedRows) {
|
|
11022
|
-
linkConditions.push(
|
|
11143
|
+
linkConditions.push(Q6.or(Q6.where("user_id", ctx.userId), Q6.where("user_id", null)));
|
|
11023
11144
|
} else {
|
|
11024
|
-
linkConditions.push(
|
|
11145
|
+
linkConditions.push(Q6.where("user_id", ctx.userId));
|
|
11025
11146
|
}
|
|
11026
11147
|
}
|
|
11027
11148
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
11028
11149
|
if (links.length === 0) return /* @__PURE__ */ new Map();
|
|
11029
11150
|
const entityIds = Array.from(new Set(links.map((l) => String(l.entityId))));
|
|
11030
|
-
const entityRows = await ctx.entityCollection.query(
|
|
11151
|
+
const entityRows = await ctx.entityCollection.query(Q6.where("id", Q6.oneOf(entityIds))).fetch();
|
|
11031
11152
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
11032
11153
|
const out = /* @__PURE__ */ new Map();
|
|
11033
11154
|
for (const link of links) {
|
|
@@ -11328,6 +11449,9 @@ __decorateClass([
|
|
|
11328
11449
|
__decorateClass([
|
|
11329
11450
|
text11("personality")
|
|
11330
11451
|
], UserPreference.prototype, "personality", 2);
|
|
11452
|
+
__decorateClass([
|
|
11453
|
+
text11("external_wallets")
|
|
11454
|
+
], UserPreference.prototype, "externalWallets", 2);
|
|
11331
11455
|
__decorateClass([
|
|
11332
11456
|
field8("created_at")
|
|
11333
11457
|
], UserPreference.prototype, "createdAt", 2);
|
|
@@ -11365,7 +11489,7 @@ __decorateClass([
|
|
|
11365
11489
|
], VaultFolder.prototype, "context", 2);
|
|
11366
11490
|
|
|
11367
11491
|
// src/lib/db/schema.ts
|
|
11368
|
-
var SDK_SCHEMA_VERSION =
|
|
11492
|
+
var SDK_SCHEMA_VERSION = 49;
|
|
11369
11493
|
var sdkSchema = appSchema2({
|
|
11370
11494
|
version: SDK_SCHEMA_VERSION,
|
|
11371
11495
|
tables: [
|
|
@@ -11451,6 +11575,7 @@ var sdkSchema = appSchema2({
|
|
|
11451
11575
|
{ name: "description", type: "string", isOptional: true },
|
|
11452
11576
|
{ name: "models", type: "string", isOptional: true },
|
|
11453
11577
|
{ name: "personality", type: "string", isOptional: true },
|
|
11578
|
+
{ name: "external_wallets", type: "string", isOptional: true },
|
|
11454
11579
|
{ name: "created_at", type: "number" },
|
|
11455
11580
|
{ name: "updated_at", type: "number" }
|
|
11456
11581
|
]
|
|
@@ -12155,6 +12280,15 @@ var sdkMigrations = schemaMigrations2({
|
|
|
12155
12280
|
"UPDATE memory_vault SET level = CASE WHEN scope IN ('shared', 'public') THEN 'matching' ELSE 'private' END WHERE level IS NULL;"
|
|
12156
12281
|
)
|
|
12157
12282
|
]
|
|
12283
|
+
},
|
|
12284
|
+
{
|
|
12285
|
+
toVersion: 49,
|
|
12286
|
+
steps: [
|
|
12287
|
+
addColumns2({
|
|
12288
|
+
table: "userPreferences",
|
|
12289
|
+
columns: [{ name: "external_wallets", type: "string", isOptional: true }]
|
|
12290
|
+
})
|
|
12291
|
+
]
|
|
12158
12292
|
}
|
|
12159
12293
|
]
|
|
12160
12294
|
});
|
|
@@ -12336,7 +12470,7 @@ var DatabaseManager = class {
|
|
|
12336
12470
|
};
|
|
12337
12471
|
|
|
12338
12472
|
// src/lib/db/media/operations.ts
|
|
12339
|
-
import { Q as
|
|
12473
|
+
import { Q as Q8 } from "@nozbe/watermelondb";
|
|
12340
12474
|
|
|
12341
12475
|
// src/lib/storage/opfs.ts
|
|
12342
12476
|
var FILE_PLACEHOLDER_PREFIX = "__SDKFILE__";
|
|
@@ -12602,7 +12736,7 @@ function isR2UrlExpired(sourceUrl, createdAt) {
|
|
|
12602
12736
|
}
|
|
12603
12737
|
|
|
12604
12738
|
// src/lib/storage/WatermelonChatStorageAdapter.ts
|
|
12605
|
-
import { Q as
|
|
12739
|
+
import { Q as Q7 } from "@nozbe/watermelondb";
|
|
12606
12740
|
var WatermelonChatStorageAdapter = class {
|
|
12607
12741
|
constructor(options) {
|
|
12608
12742
|
this.messages = options.database.get("history");
|
|
@@ -12642,10 +12776,10 @@ var WatermelonChatStorageAdapter = class {
|
|
|
12642
12776
|
}
|
|
12643
12777
|
observeConversations(options) {
|
|
12644
12778
|
const conditions = options?.projectId !== void 0 ? [
|
|
12645
|
-
|
|
12646
|
-
|
|
12647
|
-
|
|
12648
|
-
] : [
|
|
12779
|
+
Q7.where("project_id", options.projectId === null ? "" : options.projectId),
|
|
12780
|
+
Q7.where("is_deleted", false),
|
|
12781
|
+
Q7.sortBy("created_at", Q7.desc)
|
|
12782
|
+
] : [Q7.where("is_deleted", false), Q7.sortBy("created_at", Q7.desc)];
|
|
12649
12783
|
const rx = this.conversations.query(...conditions).observe();
|
|
12650
12784
|
return {
|
|
12651
12785
|
subscribe: (observer) => {
|
|
@@ -12692,7 +12826,7 @@ var WatermelonChatStorageAdapter = class {
|
|
|
12692
12826
|
return clearMessagesOp(this.ctx, conversationId);
|
|
12693
12827
|
}
|
|
12694
12828
|
observeMessages(conversationId) {
|
|
12695
|
-
const rx = this.messages.query(
|
|
12829
|
+
const rx = this.messages.query(Q7.where("conversation_id", conversationId), Q7.sortBy("message_id", Q7.asc)).observe();
|
|
12696
12830
|
return {
|
|
12697
12831
|
subscribe: (observer) => {
|
|
12698
12832
|
let latestSeq = 0;
|
|
@@ -12929,7 +13063,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
12929
13063
|
})
|
|
12930
13064
|
);
|
|
12931
13065
|
});
|
|
12932
|
-
const results = await mediaCollection.query(
|
|
13066
|
+
const results = await mediaCollection.query(Q8.where("media_id", Q8.oneOf(mediaIds))).fetch();
|
|
12933
13067
|
return Promise.all(
|
|
12934
13068
|
results.map(
|
|
12935
13069
|
(m) => mediaToStored(m, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -12938,21 +13072,21 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
12938
13072
|
}
|
|
12939
13073
|
async function getMediaByIdOp(ctx, mediaId) {
|
|
12940
13074
|
const mediaCollection = ctx.database.get("media");
|
|
12941
|
-
const results = await mediaCollection.query(
|
|
13075
|
+
const results = await mediaCollection.query(Q8.where("media_id", mediaId), Q8.where("is_deleted", false)).fetch();
|
|
12942
13076
|
return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
12943
13077
|
}
|
|
12944
13078
|
async function getMediaBySourceUrlOp(ctx, sourceUrl, walletAddress) {
|
|
12945
13079
|
const mediaCollection = ctx.database.get("media");
|
|
12946
13080
|
const results = await mediaCollection.query(
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
13081
|
+
Q8.where("source_url", sourceUrl),
|
|
13082
|
+
Q8.where("wallet_address", walletAddress),
|
|
13083
|
+
Q8.where("is_deleted", false)
|
|
12950
13084
|
).fetch();
|
|
12951
13085
|
return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
12952
13086
|
}
|
|
12953
13087
|
async function updateMediaOp(ctx, mediaId, options) {
|
|
12954
13088
|
const mediaCollection = ctx.database.get("media");
|
|
12955
|
-
const results = await mediaCollection.query(
|
|
13089
|
+
const results = await mediaCollection.query(Q8.where("media_id", mediaId)).fetch();
|
|
12956
13090
|
if (results.length === 0) {
|
|
12957
13091
|
return null;
|
|
12958
13092
|
}
|
|
@@ -12972,7 +13106,7 @@ async function updateMediaOp(ctx, mediaId, options) {
|
|
|
12972
13106
|
m._setRaw("updated_at", now);
|
|
12973
13107
|
});
|
|
12974
13108
|
});
|
|
12975
|
-
const updated = await mediaCollection.query(
|
|
13109
|
+
const updated = await mediaCollection.query(Q8.where("media_id", mediaId)).fetch();
|
|
12976
13110
|
return updated.length > 0 ? await mediaToStored(updated[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
12977
13111
|
}
|
|
12978
13112
|
async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
|
|
@@ -12980,7 +13114,7 @@ async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
|
|
|
12980
13114
|
return 0;
|
|
12981
13115
|
}
|
|
12982
13116
|
const mediaCollection = ctx.database.get("media");
|
|
12983
|
-
const results = await mediaCollection.query(
|
|
13117
|
+
const results = await mediaCollection.query(Q8.where("media_id", Q8.oneOf(mediaIds))).fetch();
|
|
12984
13118
|
if (results.length === 0) {
|
|
12985
13119
|
return 0;
|
|
12986
13120
|
}
|
|
@@ -13002,13 +13136,13 @@ var IMAGE_VIDEO_MIMES = VIDEO_EXTENSIONS.map((ext) => `image/${ext}`);
|
|
|
13002
13136
|
async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
|
|
13003
13137
|
const mediaCollection = ctx.database.get("media");
|
|
13004
13138
|
const candidates = await mediaCollection.query(
|
|
13005
|
-
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
|
|
13009
|
-
|
|
13010
|
-
...IMAGE_VIDEO_MIMES.map((m) =>
|
|
13011
|
-
|
|
13139
|
+
Q8.where("wallet_address", walletAddress),
|
|
13140
|
+
Q8.where("is_deleted", false),
|
|
13141
|
+
Q8.where("media_type", "image"),
|
|
13142
|
+
Q8.or(
|
|
13143
|
+
Q8.where("mime_type", Q8.like("video/%")),
|
|
13144
|
+
...IMAGE_VIDEO_MIMES.map((m) => Q8.where("mime_type", m)),
|
|
13145
|
+
Q8.where("mime_type", "application/octet-stream")
|
|
13012
13146
|
)
|
|
13013
13147
|
).fetch();
|
|
13014
13148
|
if (candidates.length === 0) {
|
|
@@ -13057,7 +13191,7 @@ async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
|
|
|
13057
13191
|
}
|
|
13058
13192
|
async function deleteMediaOp(ctx, mediaId) {
|
|
13059
13193
|
const mediaCollection = ctx.database.get("media");
|
|
13060
|
-
const results = await mediaCollection.query(
|
|
13194
|
+
const results = await mediaCollection.query(Q8.where("media_id", mediaId)).fetch();
|
|
13061
13195
|
if (results.length === 0) {
|
|
13062
13196
|
return false;
|
|
13063
13197
|
}
|
|
@@ -13075,7 +13209,7 @@ async function deleteMediaOp(ctx, mediaId) {
|
|
|
13075
13209
|
}
|
|
13076
13210
|
async function hardDeleteMediaOp(ctx, mediaId) {
|
|
13077
13211
|
const mediaCollection = ctx.database.get("media");
|
|
13078
|
-
const results = await mediaCollection.query(
|
|
13212
|
+
const results = await mediaCollection.query(Q8.where("media_id", mediaId)).fetch();
|
|
13079
13213
|
if (results.length === 0) {
|
|
13080
13214
|
return false;
|
|
13081
13215
|
}
|
|
@@ -13087,28 +13221,28 @@ async function hardDeleteMediaOp(ctx, mediaId) {
|
|
|
13087
13221
|
}
|
|
13088
13222
|
async function getMediaOp(ctx, filters) {
|
|
13089
13223
|
const mediaCollection = ctx.database.get("media");
|
|
13090
|
-
const conditions = [
|
|
13224
|
+
const conditions = [Q8.where("wallet_address", filters.walletAddress)];
|
|
13091
13225
|
if (!filters.includeDeleted) {
|
|
13092
|
-
conditions.push(
|
|
13226
|
+
conditions.push(Q8.where("is_deleted", false));
|
|
13093
13227
|
}
|
|
13094
13228
|
if (filters.mediaType) {
|
|
13095
|
-
conditions.push(
|
|
13229
|
+
conditions.push(Q8.where("media_type", filters.mediaType));
|
|
13096
13230
|
}
|
|
13097
13231
|
if (filters.role) {
|
|
13098
|
-
conditions.push(
|
|
13232
|
+
conditions.push(Q8.where("role", filters.role));
|
|
13099
13233
|
}
|
|
13100
13234
|
if (filters.conversationId) {
|
|
13101
|
-
conditions.push(
|
|
13235
|
+
conditions.push(Q8.where("conversation_id", filters.conversationId));
|
|
13102
13236
|
}
|
|
13103
13237
|
if (filters.model) {
|
|
13104
|
-
conditions.push(
|
|
13238
|
+
conditions.push(Q8.where("model", filters.model));
|
|
13105
13239
|
}
|
|
13106
|
-
conditions.push(
|
|
13240
|
+
conditions.push(Q8.sortBy("created_at", Q8.desc));
|
|
13107
13241
|
if (filters.limit) {
|
|
13108
|
-
conditions.push(
|
|
13242
|
+
conditions.push(Q8.take(filters.limit));
|
|
13109
13243
|
}
|
|
13110
13244
|
if (filters.offset) {
|
|
13111
|
-
conditions.push(
|
|
13245
|
+
conditions.push(Q8.skip(filters.offset));
|
|
13112
13246
|
}
|
|
13113
13247
|
const results = await mediaCollection.query(...conditions).fetch();
|
|
13114
13248
|
return Promise.all(
|
|
@@ -13138,9 +13272,9 @@ async function getMediaByConversationOp(ctx, walletAddress, conversationId, limi
|
|
|
13138
13272
|
async function getMediaByMessageOp(ctx, messageId) {
|
|
13139
13273
|
const mediaCollection = ctx.database.get("media");
|
|
13140
13274
|
const results = await mediaCollection.query(
|
|
13141
|
-
|
|
13142
|
-
|
|
13143
|
-
|
|
13275
|
+
Q8.where("message_id", messageId),
|
|
13276
|
+
Q8.where("is_deleted", false),
|
|
13277
|
+
Q8.sortBy("created_at", Q8.asc)
|
|
13144
13278
|
).fetch();
|
|
13145
13279
|
return Promise.all(
|
|
13146
13280
|
results.map(
|
|
@@ -13153,9 +13287,9 @@ async function getMediaByIdsOp(ctx, mediaIds, includeDeleted = false) {
|
|
|
13153
13287
|
return [];
|
|
13154
13288
|
}
|
|
13155
13289
|
const mediaCollection = ctx.database.get("media");
|
|
13156
|
-
const conditions = [
|
|
13290
|
+
const conditions = [Q8.where("media_id", Q8.oneOf(mediaIds))];
|
|
13157
13291
|
if (!includeDeleted) {
|
|
13158
|
-
conditions.push(
|
|
13292
|
+
conditions.push(Q8.where("is_deleted", false));
|
|
13159
13293
|
}
|
|
13160
13294
|
const results = await mediaCollection.query(...conditions).fetch();
|
|
13161
13295
|
const mediaMap = new Map(results.map((m) => [m.mediaId, m]));
|
|
@@ -13192,10 +13326,10 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
|
|
|
13192
13326
|
const queryLower = query.toLowerCase();
|
|
13193
13327
|
const MAX_SEARCH_RECORDS = 500;
|
|
13194
13328
|
const allResults = await mediaCollection.query(
|
|
13195
|
-
|
|
13196
|
-
|
|
13197
|
-
|
|
13198
|
-
|
|
13329
|
+
Q8.where("wallet_address", walletAddress),
|
|
13330
|
+
Q8.where("is_deleted", false),
|
|
13331
|
+
Q8.sortBy("created_at", Q8.desc),
|
|
13332
|
+
Q8.take(MAX_SEARCH_RECORDS)
|
|
13199
13333
|
).fetch();
|
|
13200
13334
|
const decrypted = await Promise.all(
|
|
13201
13335
|
allResults.map(
|
|
@@ -13208,11 +13342,11 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
|
|
|
13208
13342
|
async function getMediaCountOp(ctx, walletAddress, mediaType) {
|
|
13209
13343
|
const mediaCollection = ctx.database.get("media");
|
|
13210
13344
|
const conditions = [
|
|
13211
|
-
|
|
13212
|
-
|
|
13345
|
+
Q8.where("wallet_address", walletAddress),
|
|
13346
|
+
Q8.where("is_deleted", false)
|
|
13213
13347
|
];
|
|
13214
13348
|
if (mediaType) {
|
|
13215
|
-
conditions.push(
|
|
13349
|
+
conditions.push(Q8.where("media_type", mediaType));
|
|
13216
13350
|
}
|
|
13217
13351
|
return await mediaCollection.query(...conditions).fetchCount();
|
|
13218
13352
|
}
|
|
@@ -13227,7 +13361,7 @@ async function getMediaCountsByTypeOp(ctx, walletAddress) {
|
|
|
13227
13361
|
}
|
|
13228
13362
|
async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
13229
13363
|
const mediaCollection = ctx.database.get("media");
|
|
13230
|
-
const results = await mediaCollection.query(
|
|
13364
|
+
const results = await mediaCollection.query(Q8.where("conversation_id", conversationId), Q8.where("is_deleted", false)).fetch();
|
|
13231
13365
|
if (results.length === 0) {
|
|
13232
13366
|
return 0;
|
|
13233
13367
|
}
|
|
@@ -13248,7 +13382,7 @@ async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
|
13248
13382
|
}
|
|
13249
13383
|
async function deleteMediaByMessageOp(ctx, messageId) {
|
|
13250
13384
|
const mediaCollection = ctx.database.get("media");
|
|
13251
|
-
const results = await mediaCollection.query(
|
|
13385
|
+
const results = await mediaCollection.query(Q8.where("message_id", messageId), Q8.where("is_deleted", false)).fetch();
|
|
13252
13386
|
if (results.length === 0) {
|
|
13253
13387
|
return 0;
|
|
13254
13388
|
}
|
|
@@ -13269,7 +13403,7 @@ async function deleteMediaByMessageOp(ctx, messageId) {
|
|
|
13269
13403
|
}
|
|
13270
13404
|
|
|
13271
13405
|
// src/lib/db/memoryVault/operations.ts
|
|
13272
|
-
import { Q as
|
|
13406
|
+
import { Q as Q9 } from "@nozbe/watermelondb";
|
|
13273
13407
|
|
|
13274
13408
|
// src/lib/db/memoryVault/encryption.ts
|
|
13275
13409
|
async function encryptVaultMemoryContent(content, address, signMessage, embeddedWalletSigner) {
|
|
@@ -13318,11 +13452,11 @@ var NON_PRIVATE_VISIBILITIES = ["public"];
|
|
|
13318
13452
|
function visibilityConditions(requested) {
|
|
13319
13453
|
if (!requested?.length) return [];
|
|
13320
13454
|
if (!requested.includes("private")) {
|
|
13321
|
-
return [
|
|
13455
|
+
return [Q9.where("visibility", Q9.oneOf([...requested]))];
|
|
13322
13456
|
}
|
|
13323
13457
|
const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
|
|
13324
13458
|
if (excluded.length === 0) return [];
|
|
13325
|
-
return [
|
|
13459
|
+
return [Q9.or(Q9.where("visibility", null), Q9.where("visibility", Q9.notIn(excluded)))];
|
|
13326
13460
|
}
|
|
13327
13461
|
function isKinded(record2) {
|
|
13328
13462
|
return record2.kind !== null && record2.kind !== void 0;
|
|
@@ -13363,17 +13497,17 @@ function levelConditions(requested) {
|
|
|
13363
13497
|
const published = ["shared", "public"];
|
|
13364
13498
|
const wantsMatching = requested.includes("matching");
|
|
13365
13499
|
const wantsPrivate = requested.includes("private");
|
|
13366
|
-
const unresolved =
|
|
13367
|
-
const byLevel =
|
|
13368
|
-
if (wantsMatching && wantsPrivate) return [
|
|
13500
|
+
const unresolved = Q9.or(Q9.where("level", null), Q9.where("level", Q9.notIn([...MEMORY_LEVELS])));
|
|
13501
|
+
const byLevel = Q9.where("level", Q9.oneOf([...requested]));
|
|
13502
|
+
if (wantsMatching && wantsPrivate) return [Q9.or(byLevel, unresolved)];
|
|
13369
13503
|
if (wantsMatching) {
|
|
13370
|
-
return [
|
|
13504
|
+
return [Q9.or(byLevel, Q9.and(unresolved, Q9.where("scope", Q9.oneOf(published))))];
|
|
13371
13505
|
}
|
|
13372
13506
|
if (wantsPrivate) {
|
|
13373
13507
|
return [
|
|
13374
|
-
|
|
13508
|
+
Q9.or(
|
|
13375
13509
|
byLevel,
|
|
13376
|
-
|
|
13510
|
+
Q9.and(unresolved, Q9.or(Q9.where("scope", null), Q9.where("scope", Q9.notIn(published))))
|
|
13377
13511
|
)
|
|
13378
13512
|
];
|
|
13379
13513
|
}
|
|
@@ -13384,13 +13518,13 @@ function isOwnedByCtxUser(ctx, record2) {
|
|
|
13384
13518
|
}
|
|
13385
13519
|
function baseVaultConditions(ctx, options) {
|
|
13386
13520
|
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 ? [
|
|
13521
|
+
...options?.memoryIds !== void 0 ? [Q9.where("id", Q9.oneOf(options.memoryIds))] : [],
|
|
13522
|
+
...options?.includeDeleted ? [] : [Q9.where("is_deleted", false)],
|
|
13523
|
+
...options?.includeArchived ? [] : [Q9.where("archived_at", Q9.eq(null))],
|
|
13524
|
+
...options?.includeQuarantined ? [] : [Q9.where("trust_tier", Q9.notEq("quarantined"))],
|
|
13525
|
+
...options?.includeSuperseded ? [] : [Q9.where("superseded_by", null)],
|
|
13526
|
+
...ctx.userId !== void 0 ? [Q9.where("user_id", ctx.userId)] : [],
|
|
13527
|
+
...options?.since ? [Q9.where("updated_at", Q9.gt(options.since.getTime()))] : []
|
|
13394
13528
|
];
|
|
13395
13529
|
}
|
|
13396
13530
|
var KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
|
|
@@ -13560,11 +13694,11 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
13560
13694
|
async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
|
|
13561
13695
|
const records = await ctx.vaultMemoryCollection.query(
|
|
13562
13696
|
...baseVaultConditions(ctx),
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13697
|
+
Q9.where("event_time_start", Q9.notEq(null)),
|
|
13698
|
+
Q9.where("event_time_start", Q9.lte(windowEnd)),
|
|
13699
|
+
Q9.or(
|
|
13700
|
+
Q9.where("event_time_start", Q9.gte(windowStart)),
|
|
13701
|
+
Q9.where("event_time_kind", Q9.oneOf(["range", "ongoing"]))
|
|
13568
13702
|
)
|
|
13569
13703
|
).fetch();
|
|
13570
13704
|
const out = [];
|
|
@@ -13720,18 +13854,18 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
13720
13854
|
function vaultListConditions(ctx, options) {
|
|
13721
13855
|
return [
|
|
13722
13856
|
...baseVaultConditions(ctx, options),
|
|
13723
|
-
...options?.scopes?.length ? [
|
|
13857
|
+
...options?.scopes?.length ? [Q9.where("scope", Q9.oneOf(options.scopes))] : [],
|
|
13724
13858
|
...visibilityConditions(options?.visibility),
|
|
13725
13859
|
...levelConditions(options?.levels),
|
|
13726
|
-
...options?.kinds?.length ? [
|
|
13727
|
-
...options?.folderId !== void 0 ? [
|
|
13728
|
-
...options?.factTypes?.length ? [
|
|
13860
|
+
...options?.kinds?.length ? [Q9.where("kind", Q9.oneOf(options.kinds))] : [],
|
|
13861
|
+
...options?.folderId !== void 0 ? [Q9.where("folder_id", options.folderId)] : [],
|
|
13862
|
+
...options?.factTypes?.length ? [Q9.where("fact_type", Q9.oneOf(options.factTypes))] : []
|
|
13729
13863
|
];
|
|
13730
13864
|
}
|
|
13731
13865
|
function vaultListOrder(options) {
|
|
13732
13866
|
return [
|
|
13733
|
-
|
|
13734
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
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)] : []
|
|
13735
13869
|
];
|
|
13736
13870
|
}
|
|
13737
13871
|
async function getAllVaultMemoryRowsOp(ctx) {
|
|
@@ -13770,10 +13904,10 @@ function vaultMemoryRawToRankable(raw) {
|
|
|
13770
13904
|
async function getVaultRankingProjectionsOp(ctx, options) {
|
|
13771
13905
|
const conditions = [
|
|
13772
13906
|
...baseVaultConditions(ctx, options),
|
|
13773
|
-
...options?.scopes?.length ? [
|
|
13774
|
-
...options?.folderId !== void 0 ? [
|
|
13775
|
-
|
|
13776
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
13907
|
+
...options?.scopes?.length ? [Q9.where("scope", Q9.oneOf(options.scopes))] : [],
|
|
13908
|
+
...options?.folderId !== void 0 ? [Q9.where("folder_id", options.folderId)] : [],
|
|
13909
|
+
Q9.sortBy(options?.since ? "updated_at" : "created_at", Q9.desc),
|
|
13910
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [Q9.take(options.limit)] : []
|
|
13777
13911
|
];
|
|
13778
13912
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
13779
13913
|
return results.map(vaultMemoryRawToRankable);
|
|
@@ -13824,7 +13958,7 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
13824
13958
|
args.push(...options.factTypes);
|
|
13825
13959
|
}
|
|
13826
13960
|
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(
|
|
13961
|
+
const rows = await ctx.vaultMemoryCollection.query(Q9.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
13828
13962
|
return rows.map(mapRaw);
|
|
13829
13963
|
} catch (err) {
|
|
13830
13964
|
getLogger().debug(
|
|
@@ -13835,9 +13969,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
13835
13969
|
memoryIds: options?.memoryIds,
|
|
13836
13970
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
13837
13971
|
}),
|
|
13838
|
-
...options?.scopes?.length ? [
|
|
13839
|
-
...options?.folderId !== void 0 ? [
|
|
13840
|
-
...options?.factTypes?.length ? [
|
|
13972
|
+
...options?.scopes?.length ? [Q9.where("scope", Q9.oneOf(options.scopes))] : [],
|
|
13973
|
+
...options?.folderId !== void 0 ? [Q9.where("folder_id", options.folderId)] : [],
|
|
13974
|
+
...options?.factTypes?.length ? [Q9.where("fact_type", Q9.oneOf(options.factTypes))] : []
|
|
13841
13975
|
];
|
|
13842
13976
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
13843
13977
|
return rows.map(mapRaw);
|
|
@@ -13855,7 +13989,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
13855
13989
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
13856
13990
|
});
|
|
13857
13991
|
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(
|
|
13992
|
+
const rows = await ctx.vaultMemoryCollection.query(Q9.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
13859
13993
|
return rows.map(mapRaw);
|
|
13860
13994
|
} catch (err) {
|
|
13861
13995
|
getLogger().debug(
|
|
@@ -13867,7 +14001,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
13867
14001
|
includeArchived: options.includeArchived
|
|
13868
14002
|
}
|
|
13869
14003
|
}),
|
|
13870
|
-
|
|
14004
|
+
Q9.where("id", Q9.oneOf(ids))
|
|
13871
14005
|
).unsafeFetchRaw();
|
|
13872
14006
|
return rows.map(mapRaw);
|
|
13873
14007
|
}
|
|
@@ -13878,7 +14012,7 @@ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
|
13878
14012
|
...baseVaultConditions(ctx, {
|
|
13879
14013
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
13880
14014
|
}),
|
|
13881
|
-
|
|
14015
|
+
Q9.where("id", Q9.oneOf(ids))
|
|
13882
14016
|
];
|
|
13883
14017
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
13884
14018
|
return mapInBatches(
|
|
@@ -13903,7 +14037,7 @@ async function countActiveVaultMemoriesOp(ctx) {
|
|
|
13903
14037
|
}
|
|
13904
14038
|
async function getActiveVaultMemoryIdsOp(ctx, ids) {
|
|
13905
14039
|
if (ids.length === 0) return /* @__PURE__ */ new Set();
|
|
13906
|
-
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx),
|
|
14040
|
+
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), Q9.where("id", Q9.oneOf(ids))).unsafeFetchRaw();
|
|
13907
14041
|
return new Set(rows.map((r) => r.id));
|
|
13908
14042
|
}
|
|
13909
14043
|
async function updateVaultMemoryOp(ctx, id, opts) {
|
|
@@ -14052,7 +14186,7 @@ async function setMemoryEntitiesOp(ctx, memoryId, entities) {
|
|
|
14052
14186
|
() => linkMemoryEntitiesOp(entityCtx, memoryId, entities, { topicsSource: "user" })
|
|
14053
14187
|
) : [];
|
|
14054
14188
|
const keep = new Set(linked.map((e) => e.uniqueId));
|
|
14055
|
-
const existing = await entityCtx.memoryEntityCollection.query(
|
|
14189
|
+
const existing = await entityCtx.memoryEntityCollection.query(Q9.where("memory_id", memoryId)).fetch();
|
|
14056
14190
|
const staleLinks = existing.filter((l) => !keep.has(String(l.entityId)));
|
|
14057
14191
|
if (staleLinks.length === 0 && entities.length > 0) return;
|
|
14058
14192
|
const topicsWrite = await resolveMemoryTopicsWrite(
|
|
@@ -14193,9 +14327,9 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
14193
14327
|
}
|
|
14194
14328
|
async function getUnfiledVaultMemoriesOp(ctx) {
|
|
14195
14329
|
const conditions = [
|
|
14196
|
-
|
|
14330
|
+
Q9.where("folder_id", null),
|
|
14197
14331
|
...baseVaultConditions(ctx),
|
|
14198
|
-
|
|
14332
|
+
Q9.sortBy("created_at", Q9.desc)
|
|
14199
14333
|
];
|
|
14200
14334
|
const results = await ctx.vaultMemoryCollection.query(...conditions).fetch();
|
|
14201
14335
|
return mapInBatches(
|
|
@@ -14209,7 +14343,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
14209
14343
|
const entityIdByMemory = /* @__PURE__ */ new Map();
|
|
14210
14344
|
const allEntityIds = /* @__PURE__ */ new Set();
|
|
14211
14345
|
for (let i = 0; i < memoryIds.length; i += CHUNK) {
|
|
14212
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
14346
|
+
const links = await entityCtx.memoryEntityCollection.query(Q9.where("memory_id", Q9.oneOf(memoryIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
14213
14347
|
for (const link of links) {
|
|
14214
14348
|
const memoryId = String(link.memory_id);
|
|
14215
14349
|
const entityId = String(link.entity_id);
|
|
@@ -14225,7 +14359,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
14225
14359
|
const entityIds = Array.from(allEntityIds);
|
|
14226
14360
|
const nameById = /* @__PURE__ */ new Map();
|
|
14227
14361
|
for (let i = 0; i < entityIds.length; i += CHUNK) {
|
|
14228
|
-
const entities = await entityCtx.entityCollection.query(
|
|
14362
|
+
const entities = await entityCtx.entityCollection.query(Q9.where("id", Q9.oneOf(entityIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
14229
14363
|
for (const e of entities) {
|
|
14230
14364
|
if (typeof e.canonical_name === "string") nameById.set(String(e.id), e.canonical_name);
|
|
14231
14365
|
}
|
|
@@ -14254,7 +14388,7 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
|
|
|
14254
14388
|
if (!entityCtx) {
|
|
14255
14389
|
throw new Error("getMemoriesNeedingTopicExtractionOp requires ctx.entityCtx");
|
|
14256
14390
|
}
|
|
14257
|
-
const conditions = [...baseVaultConditions(ctx),
|
|
14391
|
+
const conditions = [...baseVaultConditions(ctx), Q9.sortBy("created_at", Q9.desc)];
|
|
14258
14392
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
14259
14393
|
const linkedNames = await linkedEntityNamesByMemory(
|
|
14260
14394
|
entityCtx,
|
|
@@ -14410,10 +14544,10 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
14410
14544
|
}
|
|
14411
14545
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) continue;
|
|
14412
14546
|
if (parseTopics(record2.topics) !== null) continue;
|
|
14413
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
14547
|
+
const links = await entityCtx.memoryEntityCollection.query(Q9.where("memory_id", id)).unsafeFetchRaw();
|
|
14414
14548
|
const entityIds = links.map((l) => String(l.entity_id));
|
|
14415
14549
|
if (entityIds.length === 0) continue;
|
|
14416
|
-
const entities = await entityCtx.entityCollection.query(
|
|
14550
|
+
const entities = await entityCtx.entityCollection.query(Q9.where("id", Q9.oneOf(entityIds))).fetch();
|
|
14417
14551
|
if (entities.length === 0) continue;
|
|
14418
14552
|
const source = record2.topicsUserManaged ? "user" : "auto";
|
|
14419
14553
|
const write = await resolveMemoryTopicsWrite(entityCtx, id, entities, [], source);
|
|
@@ -14429,7 +14563,7 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
14429
14563
|
}
|
|
14430
14564
|
async function deleteAllVaultMemoriesForUserOp(ctx, userId) {
|
|
14431
14565
|
if (ctx.userId !== void 0 && ctx.userId !== userId) return 0;
|
|
14432
|
-
const records = await ctx.vaultMemoryCollection.query(
|
|
14566
|
+
const records = await ctx.vaultMemoryCollection.query(Q9.where("user_id", userId), Q9.where("is_deleted", false)).fetch();
|
|
14433
14567
|
if (records.length === 0) return 0;
|
|
14434
14568
|
await ctx.database.write(async () => {
|
|
14435
14569
|
await assertCanWrite2(ctx);
|
|
@@ -14466,7 +14600,7 @@ async function getDecayCandidatesRawOp(ctx) {
|
|
|
14466
14600
|
assertVaultScopeForSweep(ctx);
|
|
14467
14601
|
const results = await ctx.vaultMemoryCollection.query(
|
|
14468
14602
|
...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
|
|
14469
|
-
|
|
14603
|
+
Q9.where("kind", null)
|
|
14470
14604
|
).unsafeFetchRaw();
|
|
14471
14605
|
return results.map((raw) => ({
|
|
14472
14606
|
uniqueId: raw.id,
|
|
@@ -14596,11 +14730,11 @@ async function findQuarantinedDuplicateOp(ctx, content, sourceIds2, where) {
|
|
|
14596
14730
|
const wanted = [...new Set(sourceIds2)].sort().join("\0");
|
|
14597
14731
|
const target = normalizeForDedupe(content);
|
|
14598
14732
|
const rows = await ctx.vaultMemoryCollection.query(
|
|
14599
|
-
|
|
14600
|
-
|
|
14601
|
-
|
|
14602
|
-
|
|
14603
|
-
...ctx.userId !== void 0 ? [
|
|
14733
|
+
Q9.where("trust_tier", "quarantined"),
|
|
14734
|
+
Q9.where("is_deleted", false),
|
|
14735
|
+
Q9.where("scope", where.scope),
|
|
14736
|
+
Q9.where("folder_id", where.folderId),
|
|
14737
|
+
...ctx.userId !== void 0 ? [Q9.where("user_id", ctx.userId)] : []
|
|
14604
14738
|
).unsafeFetchRaw();
|
|
14605
14739
|
for (const raw of rows) {
|
|
14606
14740
|
let ids;
|
|
@@ -14756,7 +14890,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
|
14756
14890
|
}
|
|
14757
14891
|
|
|
14758
14892
|
// src/lib/db/project/operations.ts
|
|
14759
|
-
import { Q as
|
|
14893
|
+
import { Q as Q10 } from "@nozbe/watermelondb";
|
|
14760
14894
|
|
|
14761
14895
|
// src/lib/db/project/types.ts
|
|
14762
14896
|
function generateProjectId() {
|
|
@@ -14787,15 +14921,15 @@ async function createProjectOp(ctx, opts, defaultName = "New Project") {
|
|
|
14787
14921
|
return projectToStored(created);
|
|
14788
14922
|
}
|
|
14789
14923
|
async function getProjectOp(ctx, id) {
|
|
14790
|
-
const results = await ctx.projectsCollection.query(
|
|
14924
|
+
const results = await ctx.projectsCollection.query(Q10.where("project_id", id), Q10.where("is_deleted", false)).fetch();
|
|
14791
14925
|
return results.length > 0 ? projectToStored(results[0]) : null;
|
|
14792
14926
|
}
|
|
14793
14927
|
async function getProjectsOp(ctx) {
|
|
14794
|
-
const results = await ctx.projectsCollection.query(
|
|
14928
|
+
const results = await ctx.projectsCollection.query(Q10.where("is_deleted", false), Q10.sortBy("created_at", Q10.desc)).fetch();
|
|
14795
14929
|
return results.map(projectToStored);
|
|
14796
14930
|
}
|
|
14797
14931
|
async function updateProjectNameOp(ctx, id, name) {
|
|
14798
|
-
const results = await ctx.projectsCollection.query(
|
|
14932
|
+
const results = await ctx.projectsCollection.query(Q10.where("project_id", id), Q10.where("is_deleted", false)).fetch();
|
|
14799
14933
|
if (results.length > 0) {
|
|
14800
14934
|
await ctx.database.write(async () => {
|
|
14801
14935
|
await results[0].update((proj) => {
|
|
@@ -14807,7 +14941,7 @@ async function updateProjectNameOp(ctx, id, name) {
|
|
|
14807
14941
|
return false;
|
|
14808
14942
|
}
|
|
14809
14943
|
async function updateProjectOp(ctx, id, opts) {
|
|
14810
|
-
const results = await ctx.projectsCollection.query(
|
|
14944
|
+
const results = await ctx.projectsCollection.query(Q10.where("project_id", id), Q10.where("is_deleted", false)).fetch();
|
|
14811
14945
|
if (results.length > 0) {
|
|
14812
14946
|
await ctx.database.write(async () => {
|
|
14813
14947
|
await results[0].update((proj) => {
|
|
@@ -14819,7 +14953,7 @@ async function updateProjectOp(ctx, id, opts) {
|
|
|
14819
14953
|
return false;
|
|
14820
14954
|
}
|
|
14821
14955
|
async function deleteProjectOp(ctx, id) {
|
|
14822
|
-
const results = await ctx.projectsCollection.query(
|
|
14956
|
+
const results = await ctx.projectsCollection.query(Q10.where("project_id", id), Q10.where("is_deleted", false)).fetch();
|
|
14823
14957
|
if (results.length > 0) {
|
|
14824
14958
|
await ctx.database.write(async () => {
|
|
14825
14959
|
await results[0].update((proj) => {
|
|
@@ -14832,14 +14966,14 @@ async function deleteProjectOp(ctx, id) {
|
|
|
14832
14966
|
}
|
|
14833
14967
|
async function getProjectConversationsOp(ctx, projectId) {
|
|
14834
14968
|
const results = await ctx.conversationsCollection.query(
|
|
14835
|
-
|
|
14836
|
-
|
|
14837
|
-
|
|
14969
|
+
Q10.where("project_id", projectId),
|
|
14970
|
+
Q10.where("is_deleted", false),
|
|
14971
|
+
Q10.sortBy("created_at", Q10.desc)
|
|
14838
14972
|
).fetch();
|
|
14839
14973
|
return results.map(conversationToStoredRaw);
|
|
14840
14974
|
}
|
|
14841
14975
|
async function getProjectConversationCountOp(ctx, projectId) {
|
|
14842
|
-
return await ctx.conversationsCollection.query(
|
|
14976
|
+
return await ctx.conversationsCollection.query(Q10.where("project_id", projectId), Q10.where("is_deleted", false)).fetchCount();
|
|
14843
14977
|
}
|
|
14844
14978
|
|
|
14845
14979
|
// src/lib/db/queue/manager.ts
|
|
@@ -15182,7 +15316,7 @@ var WalletPoller = class {
|
|
|
15182
15316
|
};
|
|
15183
15317
|
|
|
15184
15318
|
// src/lib/db/savedTools/operations.ts
|
|
15185
|
-
import { Q as
|
|
15319
|
+
import { Q as Q11 } from "@nozbe/watermelondb";
|
|
15186
15320
|
function savedToolToStored(tool) {
|
|
15187
15321
|
return {
|
|
15188
15322
|
uniqueId: tool.id,
|
|
@@ -15215,7 +15349,7 @@ async function createSavedToolOp(ctx, opts) {
|
|
|
15215
15349
|
return savedToolToStored(created);
|
|
15216
15350
|
}
|
|
15217
15351
|
async function getAllSavedToolsOp(ctx) {
|
|
15218
|
-
const results = await ctx.savedToolsCollection.query(
|
|
15352
|
+
const results = await ctx.savedToolsCollection.query(Q11.where("is_deleted", false), Q11.sortBy("created_at", Q11.desc)).fetch();
|
|
15219
15353
|
return results.map(savedToolToStored);
|
|
15220
15354
|
}
|
|
15221
15355
|
async function getSavedToolByIdOp(ctx, uniqueId) {
|
|
@@ -15267,7 +15401,7 @@ async function deleteSavedToolOp(ctx, uniqueId) {
|
|
|
15267
15401
|
}
|
|
15268
15402
|
|
|
15269
15403
|
// src/lib/db/settings/operations.ts
|
|
15270
|
-
import { Q as
|
|
15404
|
+
import { Q as Q12 } from "@nozbe/watermelondb";
|
|
15271
15405
|
function modelPreferenceToStored(preference) {
|
|
15272
15406
|
return {
|
|
15273
15407
|
uniqueId: preference.id,
|
|
@@ -15276,12 +15410,12 @@ function modelPreferenceToStored(preference) {
|
|
|
15276
15410
|
};
|
|
15277
15411
|
}
|
|
15278
15412
|
async function getModelPreferenceOp(ctx, walletAddress) {
|
|
15279
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
15413
|
+
const results = await ctx.modelPreferencesCollection.query(Q12.where("wallet_address", walletAddress)).fetch();
|
|
15280
15414
|
return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
|
|
15281
15415
|
}
|
|
15282
15416
|
async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
15283
15417
|
const result = await ctx.database.write(async () => {
|
|
15284
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
15418
|
+
const results = await ctx.modelPreferencesCollection.query(Q12.where("wallet_address", walletAddress)).fetch();
|
|
15285
15419
|
if (results.length > 0) {
|
|
15286
15420
|
const preference = results[0];
|
|
15287
15421
|
await preference.update((pref) => {
|
|
@@ -15299,7 +15433,7 @@ async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
|
15299
15433
|
return modelPreferenceToStored(result);
|
|
15300
15434
|
}
|
|
15301
15435
|
async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
15302
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
15436
|
+
const results = await ctx.modelPreferencesCollection.query(Q12.where("wallet_address", walletAddress)).fetch();
|
|
15303
15437
|
if (results.length === 0) return false;
|
|
15304
15438
|
await ctx.database.write(async () => {
|
|
15305
15439
|
await results[0].destroyPermanently();
|
|
@@ -15323,7 +15457,7 @@ var settingsStorageSchema = appSchema3({
|
|
|
15323
15457
|
});
|
|
15324
15458
|
|
|
15325
15459
|
// src/lib/db/userPreferences/operations.ts
|
|
15326
|
-
import { Q as
|
|
15460
|
+
import { Q as Q13 } from "@nozbe/watermelondb";
|
|
15327
15461
|
function userPreferenceToStored(preference) {
|
|
15328
15462
|
return {
|
|
15329
15463
|
uniqueId: preference.id,
|
|
@@ -15333,12 +15467,13 @@ function userPreferenceToStored(preference) {
|
|
|
15333
15467
|
description: preference.description,
|
|
15334
15468
|
models: preference.models,
|
|
15335
15469
|
personality: preference.personality,
|
|
15470
|
+
externalWallets: preference.externalWallets,
|
|
15336
15471
|
createdAt: preference.createdAt,
|
|
15337
15472
|
updatedAt: preference.updatedAt
|
|
15338
15473
|
};
|
|
15339
15474
|
}
|
|
15340
15475
|
async function getUserPreferenceOp(ctx, walletAddress) {
|
|
15341
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
15476
|
+
const results = await ctx.userPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15342
15477
|
return results.length > 0 ? userPreferenceToStored(results[0]) : null;
|
|
15343
15478
|
}
|
|
15344
15479
|
async function createUserPreferenceOp(ctx, opts) {
|
|
@@ -15351,6 +15486,7 @@ async function createUserPreferenceOp(ctx, opts) {
|
|
|
15351
15486
|
if (opts.description) pref._setRaw("description", opts.description);
|
|
15352
15487
|
if (opts.models) pref._setRaw("models", opts.models);
|
|
15353
15488
|
if (opts.personality) pref._setRaw("personality", opts.personality);
|
|
15489
|
+
if (opts.externalWallets) pref._setRaw("external_wallets", opts.externalWallets);
|
|
15354
15490
|
pref._setRaw("created_at", now);
|
|
15355
15491
|
pref._setRaw("updated_at", now);
|
|
15356
15492
|
});
|
|
@@ -15358,7 +15494,7 @@ async function createUserPreferenceOp(ctx, opts) {
|
|
|
15358
15494
|
return userPreferenceToStored(created);
|
|
15359
15495
|
}
|
|
15360
15496
|
async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
15361
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
15497
|
+
const results = await ctx.userPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15362
15498
|
if (results.length === 0) return null;
|
|
15363
15499
|
const preference = results[0];
|
|
15364
15500
|
await ctx.database.write(async () => {
|
|
@@ -15378,6 +15514,9 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
15378
15514
|
if (opts.personality !== void 0) {
|
|
15379
15515
|
pref._setRaw("personality", opts.personality || null);
|
|
15380
15516
|
}
|
|
15517
|
+
if (opts.externalWallets !== void 0) {
|
|
15518
|
+
pref._setRaw("external_wallets", opts.externalWallets || null);
|
|
15519
|
+
}
|
|
15381
15520
|
pref._setRaw("updated_at", Date.now());
|
|
15382
15521
|
});
|
|
15383
15522
|
});
|
|
@@ -15386,7 +15525,7 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
15386
15525
|
async function setUserPreferenceOp(ctx, walletAddress, opts) {
|
|
15387
15526
|
const now = Date.now();
|
|
15388
15527
|
const result = await ctx.database.write(async () => {
|
|
15389
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
15528
|
+
const results = await ctx.userPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15390
15529
|
if (results.length > 0) {
|
|
15391
15530
|
const preference = results[0];
|
|
15392
15531
|
await preference.update((pref) => {
|
|
@@ -15405,6 +15544,9 @@ async function setUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
15405
15544
|
if (opts.personality !== void 0) {
|
|
15406
15545
|
pref._setRaw("personality", opts.personality || null);
|
|
15407
15546
|
}
|
|
15547
|
+
if (opts.externalWallets !== void 0) {
|
|
15548
|
+
pref._setRaw("external_wallets", opts.externalWallets || null);
|
|
15549
|
+
}
|
|
15408
15550
|
pref._setRaw("updated_at", now);
|
|
15409
15551
|
});
|
|
15410
15552
|
return preference;
|
|
@@ -15416,6 +15558,7 @@ async function setUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
15416
15558
|
if (opts.description) pref._setRaw("description", opts.description);
|
|
15417
15559
|
if (opts.models) pref._setRaw("models", opts.models);
|
|
15418
15560
|
if (opts.personality) pref._setRaw("personality", opts.personality);
|
|
15561
|
+
if (opts.externalWallets) pref._setRaw("external_wallets", opts.externalWallets);
|
|
15419
15562
|
pref._setRaw("created_at", now);
|
|
15420
15563
|
pref._setRaw("updated_at", now);
|
|
15421
15564
|
});
|
|
@@ -15434,7 +15577,7 @@ async function updateModelsOp(ctx, walletAddress, models) {
|
|
|
15434
15577
|
return updateUserPreferenceOp(ctx, walletAddress, { models });
|
|
15435
15578
|
}
|
|
15436
15579
|
async function deleteUserPreferenceOp(ctx, walletAddress) {
|
|
15437
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
15580
|
+
const results = await ctx.userPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15438
15581
|
if (results.length === 0) return false;
|
|
15439
15582
|
await ctx.database.write(async () => {
|
|
15440
15583
|
await results[0].destroyPermanently();
|
|
@@ -15449,9 +15592,9 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
|
|
|
15449
15592
|
if (existing) {
|
|
15450
15593
|
return existing;
|
|
15451
15594
|
}
|
|
15452
|
-
const modelResults = await ctx.modelPreferencesCollection.query(
|
|
15595
|
+
const modelResults = await ctx.modelPreferencesCollection.query(Q13.where("wallet_address", walletAddress)).fetch();
|
|
15453
15596
|
const personalityKey = `${walletAddress}_personality_settings`;
|
|
15454
|
-
const personalityResults = await ctx.modelPreferencesCollection.query(
|
|
15597
|
+
const personalityResults = await ctx.modelPreferencesCollection.query(Q13.where("wallet_address", personalityKey)).fetch();
|
|
15455
15598
|
if (modelResults.length === 0 && personalityResults.length === 0) {
|
|
15456
15599
|
return null;
|
|
15457
15600
|
}
|
|
@@ -15506,6 +15649,7 @@ var userPreferencesStorageSchema = appSchema4({
|
|
|
15506
15649
|
{ name: "description", type: "string", isOptional: true },
|
|
15507
15650
|
{ name: "models", type: "string", isOptional: true },
|
|
15508
15651
|
{ name: "personality", type: "string", isOptional: true },
|
|
15652
|
+
{ name: "external_wallets", type: "string", isOptional: true },
|
|
15509
15653
|
{ name: "created_at", type: "number" },
|
|
15510
15654
|
{ name: "updated_at", type: "number" }
|
|
15511
15655
|
]
|
|
@@ -15552,7 +15696,7 @@ var SLIDER_CONFIG = [
|
|
|
15552
15696
|
];
|
|
15553
15697
|
|
|
15554
15698
|
// src/lib/db/vaultFolders/operations.ts
|
|
15555
|
-
import { Q as
|
|
15699
|
+
import { Q as Q14 } from "@nozbe/watermelondb";
|
|
15556
15700
|
function folderToStored(folder) {
|
|
15557
15701
|
return {
|
|
15558
15702
|
uniqueId: folder.id,
|
|
@@ -15577,7 +15721,7 @@ async function createVaultFolderOp(ctx, opts) {
|
|
|
15577
15721
|
return folderToStored(created);
|
|
15578
15722
|
}
|
|
15579
15723
|
async function getAllVaultFoldersOp(ctx) {
|
|
15580
|
-
const results = await ctx.vaultFolderCollection.query(
|
|
15724
|
+
const results = await ctx.vaultFolderCollection.query(Q14.where("is_deleted", false), Q14.sortBy("created_at", Q14.desc)).fetch();
|
|
15581
15725
|
return results.map(folderToStored);
|
|
15582
15726
|
}
|
|
15583
15727
|
async function updateVaultFolderOp(ctx, id, opts) {
|
|
@@ -15586,7 +15730,7 @@ async function updateVaultFolderOp(ctx, id, opts) {
|
|
|
15586
15730
|
if (record2.isDeleted) return null;
|
|
15587
15731
|
const scopeChanged = opts.scope !== void 0 && opts.scope !== record2.scope;
|
|
15588
15732
|
const updated = await ctx.database.write(async () => {
|
|
15589
|
-
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(
|
|
15733
|
+
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(Q14.where("folder_id", id), Q14.where("is_deleted", false)).fetch() : [];
|
|
15590
15734
|
const updates = [];
|
|
15591
15735
|
updates.push(
|
|
15592
15736
|
record2.prepareUpdate((r) => {
|
|
@@ -15615,7 +15759,7 @@ async function deleteVaultFolderOp(ctx, id) {
|
|
|
15615
15759
|
const record2 = await ctx.vaultFolderCollection.find(id);
|
|
15616
15760
|
if (record2.isDeleted) return false;
|
|
15617
15761
|
await ctx.database.write(async () => {
|
|
15618
|
-
const memories = await ctx.vaultMemoryCollection.query(
|
|
15762
|
+
const memories = await ctx.vaultMemoryCollection.query(Q14.where("folder_id", id), Q14.where("is_deleted", false)).fetch();
|
|
15619
15763
|
const preparedMemories = memories.map(
|
|
15620
15764
|
(memory) => memory.prepareUpdate((r) => {
|
|
15621
15765
|
r._setRaw("folder_id", null);
|
|
@@ -15686,7 +15830,7 @@ async function updateVaultFolderContextOp(ctx, id, context) {
|
|
|
15686
15830
|
}
|
|
15687
15831
|
}
|
|
15688
15832
|
async function getVaultFolderMemoryCountOp(ctx, folderId) {
|
|
15689
|
-
return await ctx.vaultMemoryCollection.query(
|
|
15833
|
+
return await ctx.vaultMemoryCollection.query(Q14.where("folder_id", folderId), Q14.where("is_deleted", false)).fetchCount();
|
|
15690
15834
|
}
|
|
15691
15835
|
|
|
15692
15836
|
// src/lib/db/vaultFolders/defaults.ts
|
|
@@ -15729,7 +15873,7 @@ async function _ensureDefaultFoldersImpl(ctx) {
|
|
|
15729
15873
|
}
|
|
15730
15874
|
|
|
15731
15875
|
// src/lib/memory/autoExtract.ts
|
|
15732
|
-
import { Q as
|
|
15876
|
+
import { Q as Q15 } from "@nozbe/watermelondb";
|
|
15733
15877
|
|
|
15734
15878
|
// src/lib/memory/entitySalience.ts
|
|
15735
15879
|
var GENERIC_ENTITY_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -18437,7 +18581,7 @@ async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
|
18437
18581
|
// src/lib/memory/autoExtract.ts
|
|
18438
18582
|
async function isMemoryTopicsUserManaged(ctx, memoryId) {
|
|
18439
18583
|
try {
|
|
18440
|
-
const rows = await ctx.database.get(VaultMemory.table).query(
|
|
18584
|
+
const rows = await ctx.database.get(VaultMemory.table).query(Q15.where("id", memoryId)).fetch();
|
|
18441
18585
|
return rows[0]?.topicsUserManaged === true;
|
|
18442
18586
|
} catch {
|
|
18443
18587
|
return true;
|
|
@@ -21008,7 +21152,7 @@ function parseAnswer(body, base, parseSchema) {
|
|
|
21008
21152
|
}
|
|
21009
21153
|
|
|
21010
21154
|
// src/lib/memory/store/local.ts
|
|
21011
|
-
import { Q as
|
|
21155
|
+
import { Q as Q16 } from "@nozbe/watermelondb";
|
|
21012
21156
|
|
|
21013
21157
|
// src/lib/memory/topicExtract.ts
|
|
21014
21158
|
var TOPIC_EXTRACTION_BATCH_SIZE = 10;
|
|
@@ -21287,8 +21431,8 @@ function createLocalMemoryStore(options) {
|
|
|
21287
21431
|
writeOptions?.signal?.throwIfAborted();
|
|
21288
21432
|
};
|
|
21289
21433
|
const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
|
|
21290
|
-
const ownedBy = userId !== void 0 ? [
|
|
21291
|
-
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [
|
|
21434
|
+
const ownedBy = userId !== void 0 ? [Q16.where("user_id", userId)] : [];
|
|
21435
|
+
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
21436
|
const watchedColumns = [
|
|
21293
21437
|
"content",
|
|
21294
21438
|
"scope",
|
|
@@ -21333,7 +21477,7 @@ function createLocalMemoryStore(options) {
|
|
|
21333
21477
|
list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
|
|
21334
21478
|
get: (id) => getVaultMemoryOp(vaultCtx, id),
|
|
21335
21479
|
listArchived: async () => {
|
|
21336
|
-
const ids = await vaultCtx.vaultMemoryCollection.query(
|
|
21480
|
+
const ids = await vaultCtx.vaultMemoryCollection.query(Q16.where("is_deleted", false), Q16.where("archived_at", Q16.notEq(null)), ...ownedBy).fetchIds();
|
|
21337
21481
|
if (ids.length === 0) return [];
|
|
21338
21482
|
const rows = await getAllVaultMemoriesOp(vaultCtx, { memoryIds: ids, includeArchived: true });
|
|
21339
21483
|
return rows.sort((a, b) => (b.archivedAt ?? 0) - (a.archivedAt ?? 0));
|
|
@@ -21349,7 +21493,7 @@ function createLocalMemoryStore(options) {
|
|
|
21349
21493
|
set.add(String(link.memory_id));
|
|
21350
21494
|
members.set(entityId, set);
|
|
21351
21495
|
}
|
|
21352
|
-
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(
|
|
21496
|
+
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
21497
|
const byName = /* @__PURE__ */ new Map();
|
|
21354
21498
|
for (const entity of entities) {
|
|
21355
21499
|
const name = String(entity.canonical_name);
|
|
@@ -21399,7 +21543,7 @@ function createLocalMemoryStore(options) {
|
|
|
21399
21543
|
setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
|
|
21400
21544
|
addTopics: (memoryId, topics, writeOptions) => database.write(async (writer) => {
|
|
21401
21545
|
await assertWrite(writeOptions);
|
|
21402
|
-
const owned = await vaultCtx.vaultMemoryCollection.query(
|
|
21546
|
+
const owned = await vaultCtx.vaultMemoryCollection.query(Q16.where("id", memoryId), Q16.where("is_deleted", false), ...ownedBy).fetchCount();
|
|
21403
21547
|
return owned > 0 ? writer.callWriter(
|
|
21404
21548
|
() => linkMemoryEntitiesOp(
|
|
21405
21549
|
{
|
|
@@ -21471,7 +21615,7 @@ function createLocalMemoryStore(options) {
|
|
|
21471
21615
|
else onChange();
|
|
21472
21616
|
};
|
|
21473
21617
|
};
|
|
21474
|
-
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(
|
|
21618
|
+
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(Q16.where("is_deleted", false), ...ownedBy).observeWithColumns(
|
|
21475
21619
|
subscribeOptions?.embeddings ? [...watchedColumns, "embedding", "embedding_model"] : watchedColumns
|
|
21476
21620
|
);
|
|
21477
21621
|
const subscriptions = [memories.subscribe(afterFirst())];
|
|
@@ -24530,7 +24674,7 @@ async function assembleMemoryContext(options) {
|
|
|
24530
24674
|
}
|
|
24531
24675
|
|
|
24532
24676
|
// src/lib/memory/durableExtraction.ts
|
|
24533
|
-
import { Q as
|
|
24677
|
+
import { Q as Q17 } from "@nozbe/watermelondb";
|
|
24534
24678
|
var MAX_JOBS_PER_PASS = 3;
|
|
24535
24679
|
var MAX_ATTEMPTS = 3;
|
|
24536
24680
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -24701,7 +24845,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24701
24845
|
const source = options.messageSource?.(conversationId);
|
|
24702
24846
|
if (source)
|
|
24703
24847
|
return await fromSource(source.status(conversationId)) === "ready" && (await loadFromSource(source, conversationId, ids)).every(Boolean);
|
|
24704
|
-
return await storage.conversationsCollection.query(
|
|
24848
|
+
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
24849
|
}
|
|
24706
24850
|
function schedule(delay) {
|
|
24707
24851
|
if (disposed) return;
|
|
@@ -24875,7 +25019,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24875
25019
|
let sourceWaiting = false;
|
|
24876
25020
|
try {
|
|
24877
25021
|
await writes;
|
|
24878
|
-
const pending = await jobs.query(
|
|
25022
|
+
const pending = await jobs.query(Q17.where("owner_key", owner), Q17.where("message_ids", Q17.notEq("[]"))).fetch();
|
|
24879
25023
|
storeFailures = 0;
|
|
24880
25024
|
let processed = 0;
|
|
24881
25025
|
for (const job of pending) {
|
|
@@ -24907,7 +25051,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24907
25051
|
let ids = [];
|
|
24908
25052
|
let loaded = [];
|
|
24909
25053
|
try {
|
|
24910
|
-
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(
|
|
25054
|
+
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(Q17.where("conversation_id", conversationId), Q17.where("is_deleted", false)).fetchCount() > 0;
|
|
24911
25055
|
if (!present) {
|
|
24912
25056
|
await database.write(() => job.destroyPermanently());
|
|
24913
25057
|
continue;
|
|
@@ -25075,7 +25219,7 @@ function createDurableAutoExtractor(options) {
|
|
|
25075
25219
|
const scope = currentScope();
|
|
25076
25220
|
writes = writes.then(
|
|
25077
25221
|
() => database.write(async () => {
|
|
25078
|
-
const existing = await jobs.query(
|
|
25222
|
+
const existing = await jobs.query(Q17.where("owner_key", owner), Q17.where("conversation_id", conversationId)).fetch();
|
|
25079
25223
|
const job = existing.find(
|
|
25080
25224
|
(candidate) => candidate._getRaw("scope") === scope && (candidate._getRaw("folder_id") ?? null) === folderId
|
|
25081
25225
|
);
|
|
@@ -25088,8 +25232,8 @@ function createDurableAutoExtractor(options) {
|
|
|
25088
25232
|
if (watermarks.length) {
|
|
25089
25233
|
const misplaced = new Set(
|
|
25090
25234
|
await storage.messagesCollection.query(
|
|
25091
|
-
|
|
25092
|
-
|
|
25235
|
+
Q17.where("id", Q17.oneOf(watermarks)),
|
|
25236
|
+
Q17.where("conversation_id", Q17.notEq(conversationId))
|
|
25093
25237
|
).fetchIds()
|
|
25094
25238
|
);
|
|
25095
25239
|
for (const prior of existing)
|
|
@@ -25099,7 +25243,7 @@ function createDurableAutoExtractor(options) {
|
|
|
25099
25243
|
r._setRaw("watermark_seq", null);
|
|
25100
25244
|
});
|
|
25101
25245
|
}
|
|
25102
|
-
const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(
|
|
25246
|
+
const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(Q17.where("id", Q17.oneOf(ids))).fetch();
|
|
25103
25247
|
const foreignRows = new Set(
|
|
25104
25248
|
rows.filter((row) => row._getRaw("conversation_id") !== conversationId).map((row) => row.id)
|
|
25105
25249
|
);
|
|
@@ -27555,7 +27699,7 @@ function computeToolGuidance(selectedServerTools, selectedClientTools, extraTool
|
|
|
27555
27699
|
async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embeddingOptions, extraToolSets = [], activeToolSets = [], noEmbeddingsReason = "short-prompt") {
|
|
27556
27700
|
const isAlwaysIncluded = (t) => {
|
|
27557
27701
|
const name = getToolName2(t);
|
|
27558
|
-
return name.startsWith("memory_vault_") || name === RECALL_TOOL_NAME || name === CONFIRM_TOOL_NAME;
|
|
27702
|
+
return name.startsWith("memory_vault_") || name === RECALL_TOOL_NAME || name === CONFIRM_TOOL_NAME || name === SELECT_PAYMENT_WALLET_TOOL_NAME || name === WALLET_PAYMENT_TOOL_NAME;
|
|
27559
27703
|
};
|
|
27560
27704
|
const alwaysInclude = clientTools.filter(isAlwaysIncluded);
|
|
27561
27705
|
const filterCandidates = clientTools.filter((t) => !isAlwaysIncluded(t));
|
|
@@ -27567,7 +27711,7 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
27567
27711
|
}
|
|
27568
27712
|
if (!promptEmbeddings) {
|
|
27569
27713
|
if (activeToolSets.length === 0) {
|
|
27570
|
-
return { tools:
|
|
27714
|
+
return { tools: alwaysInclude, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
27571
27715
|
}
|
|
27572
27716
|
const allSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
27573
27717
|
const activeSets = allSets.filter((s) => activeToolSets.includes(s.name));
|
|
@@ -28651,6 +28795,177 @@ function migrateDisplayResult(result, fromVersion, toVersion, migrations) {
|
|
|
28651
28795
|
}
|
|
28652
28796
|
return current;
|
|
28653
28797
|
}
|
|
28798
|
+
function generateInteractionId(prefix) {
|
|
28799
|
+
return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
|
|
28800
|
+
}
|
|
28801
|
+
function createInteractiveTool(options, config) {
|
|
28802
|
+
return {
|
|
28803
|
+
type: "function",
|
|
28804
|
+
function: {
|
|
28805
|
+
name: config.name,
|
|
28806
|
+
description: config.description,
|
|
28807
|
+
arguments: config.parameters
|
|
28808
|
+
},
|
|
28809
|
+
executor: async (args, signal) => {
|
|
28810
|
+
if (config.validate && !config.validate(args)) {
|
|
28811
|
+
return { cancelled: true };
|
|
28812
|
+
}
|
|
28813
|
+
const context = options.getContext();
|
|
28814
|
+
if (!context) {
|
|
28815
|
+
return { cancelled: true };
|
|
28816
|
+
}
|
|
28817
|
+
const interactionId = generateInteractionId(config.interactionType);
|
|
28818
|
+
const interactionData = config.mapArgs ? config.mapArgs(args) : args;
|
|
28819
|
+
const onAbort = () => context.cancelInteraction?.(interactionId);
|
|
28820
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
28821
|
+
try {
|
|
28822
|
+
const result = await context.createInteraction(interactionId, config.interactionType, {
|
|
28823
|
+
...interactionData,
|
|
28824
|
+
afterMessageId: options.getLastMessageId?.()
|
|
28825
|
+
});
|
|
28826
|
+
if (config.mapResult) {
|
|
28827
|
+
return config.mapResult(result, args);
|
|
28828
|
+
}
|
|
28829
|
+
return result;
|
|
28830
|
+
} catch {
|
|
28831
|
+
return { cancelled: true };
|
|
28832
|
+
} finally {
|
|
28833
|
+
signal?.removeEventListener("abort", onAbort);
|
|
28834
|
+
}
|
|
28835
|
+
},
|
|
28836
|
+
executorTimeout: Infinity
|
|
28837
|
+
};
|
|
28838
|
+
}
|
|
28839
|
+
|
|
28840
|
+
// src/tools/walletPayment.ts
|
|
28841
|
+
var CANCELLED = { cancelled: true };
|
|
28842
|
+
function isNonEmptyString(value) {
|
|
28843
|
+
return typeof value === "string" && value.length > 0;
|
|
28844
|
+
}
|
|
28845
|
+
function hasPassengers(value) {
|
|
28846
|
+
return Array.isArray(value?.passengers);
|
|
28847
|
+
}
|
|
28848
|
+
function createSelectPaymentWalletTool(options) {
|
|
28849
|
+
const tool = createInteractiveTool(options, {
|
|
28850
|
+
name: SELECT_PAYMENT_WALLET_TOOL_NAME,
|
|
28851
|
+
description: "Show the user a card with the flight offer and their wallets, and let them pick the wallet to pay from. Call it after anuma_flight_offer_details, with the exact offer id, price and currency from that result. Returns the chosen wallet, or that the user declined.",
|
|
28852
|
+
parameters: {
|
|
28853
|
+
type: "object",
|
|
28854
|
+
properties: {
|
|
28855
|
+
offer_id: {
|
|
28856
|
+
type: "string",
|
|
28857
|
+
description: "The offer id from anuma_flight_offer_details"
|
|
28858
|
+
},
|
|
28859
|
+
summary: {
|
|
28860
|
+
type: "string",
|
|
28861
|
+
description: "Route, dates and fare of the offer, as shown to the user"
|
|
28862
|
+
},
|
|
28863
|
+
amount: {
|
|
28864
|
+
type: "string",
|
|
28865
|
+
description: "Total price of the offer, e.g. '412.50'"
|
|
28866
|
+
},
|
|
28867
|
+
currency: {
|
|
28868
|
+
type: "string",
|
|
28869
|
+
description: "Currency of the price, e.g. 'USD'"
|
|
28870
|
+
}
|
|
28871
|
+
},
|
|
28872
|
+
required: ["offer_id", "amount", "currency"]
|
|
28873
|
+
},
|
|
28874
|
+
interactionType: "select_payment_wallet",
|
|
28875
|
+
validate: (args) => isNonEmptyString(args.offer_id),
|
|
28876
|
+
mapArgs: ({ offer_id, summary, amount, currency, wallets }) => ({
|
|
28877
|
+
offer_id,
|
|
28878
|
+
summary,
|
|
28879
|
+
amount,
|
|
28880
|
+
currency,
|
|
28881
|
+
wallets
|
|
28882
|
+
}),
|
|
28883
|
+
mapResult: (result, args) => {
|
|
28884
|
+
if (result?.confirmed === true && isNonEmptyString(result.funding_wallet)) {
|
|
28885
|
+
return {
|
|
28886
|
+
confirmed: true,
|
|
28887
|
+
offer_id: args.offer_id,
|
|
28888
|
+
funding_wallet: result.funding_wallet
|
|
28889
|
+
};
|
|
28890
|
+
}
|
|
28891
|
+
if (result?.confirmed === false) return { confirmed: false };
|
|
28892
|
+
return CANCELLED;
|
|
28893
|
+
}
|
|
28894
|
+
});
|
|
28895
|
+
const showCard = tool.executor;
|
|
28896
|
+
return {
|
|
28897
|
+
...tool,
|
|
28898
|
+
executor: async (args, signal) => {
|
|
28899
|
+
if (!isNonEmptyString(args.offer_id)) return CANCELLED;
|
|
28900
|
+
let wallets;
|
|
28901
|
+
try {
|
|
28902
|
+
wallets = await options.listWallets();
|
|
28903
|
+
} catch {
|
|
28904
|
+
return { error_code: "wallets_unavailable", retryable: true };
|
|
28905
|
+
}
|
|
28906
|
+
if (signal?.aborted) return CANCELLED;
|
|
28907
|
+
return showCard?.({ ...args, wallets }, signal);
|
|
28908
|
+
}
|
|
28909
|
+
};
|
|
28910
|
+
}
|
|
28911
|
+
function createWalletPaymentTool(options) {
|
|
28912
|
+
const tool = createInteractiveTool(options, {
|
|
28913
|
+
name: WALLET_PAYMENT_TOOL_NAME,
|
|
28914
|
+
description: "Show the user a card to enter the passengers, then pay the flight booking from the wallet they chose. Call it after anuma_create_flight_intent, with the provider and reference from that result. Returns whether the payment went through.",
|
|
28915
|
+
parameters: {
|
|
28916
|
+
type: "object",
|
|
28917
|
+
properties: {
|
|
28918
|
+
provider: {
|
|
28919
|
+
type: "string",
|
|
28920
|
+
description: "The payment provider from anuma_create_flight_intent"
|
|
28921
|
+
},
|
|
28922
|
+
reference: {
|
|
28923
|
+
type: "string",
|
|
28924
|
+
description: "The payment reference from anuma_create_flight_intent"
|
|
28925
|
+
},
|
|
28926
|
+
passenger_count: {
|
|
28927
|
+
type: "integer",
|
|
28928
|
+
minimum: 1,
|
|
28929
|
+
description: "How many passengers the booking is for"
|
|
28930
|
+
}
|
|
28931
|
+
},
|
|
28932
|
+
required: ["provider", "reference", "passenger_count"]
|
|
28933
|
+
},
|
|
28934
|
+
interactionType: "prompt_wallet_payment",
|
|
28935
|
+
validate: (args) => isNonEmptyString(args.provider) && isNonEmptyString(args.reference) && Number.isInteger(args.passenger_count) && args.passenger_count >= 1,
|
|
28936
|
+
mapArgs: ({ provider, reference, passenger_count }) => ({
|
|
28937
|
+
provider,
|
|
28938
|
+
reference,
|
|
28939
|
+
passenger_count
|
|
28940
|
+
}),
|
|
28941
|
+
mapResult: (result) => hasPassengers(result) ? { passengers: result.passengers } : CANCELLED
|
|
28942
|
+
});
|
|
28943
|
+
const showCard = tool.executor;
|
|
28944
|
+
return {
|
|
28945
|
+
...tool,
|
|
28946
|
+
executor: async (args, signal) => {
|
|
28947
|
+
const answer = await showCard?.(args, signal);
|
|
28948
|
+
if (!hasPassengers(answer) || signal?.aborted) return CANCELLED;
|
|
28949
|
+
const provider = args.provider;
|
|
28950
|
+
const reference = args.reference;
|
|
28951
|
+
let outcome2;
|
|
28952
|
+
try {
|
|
28953
|
+
outcome2 = await options.pay({ provider, reference, passengers: answer.passengers }, signal);
|
|
28954
|
+
} catch {
|
|
28955
|
+
return { paid: false, error_code: "payment_failed", retryable: false };
|
|
28956
|
+
}
|
|
28957
|
+
if (outcome2.paid) {
|
|
28958
|
+
return {
|
|
28959
|
+
paid: true,
|
|
28960
|
+
provider: outcome2.provider,
|
|
28961
|
+
reference: outcome2.reference,
|
|
28962
|
+
status: outcome2.status
|
|
28963
|
+
};
|
|
28964
|
+
}
|
|
28965
|
+
return { paid: false, error_code: outcome2.error_code, retryable: outcome2.retryable };
|
|
28966
|
+
}
|
|
28967
|
+
};
|
|
28968
|
+
}
|
|
28654
28969
|
|
|
28655
28970
|
// src/react/anumaRuntime.tsx
|
|
28656
28971
|
import * as React from "react";
|
|
@@ -29789,10 +30104,10 @@ var UNREVISIONED_COLUMNS = /* @__PURE__ */ new Set([
|
|
|
29789
30104
|
]);
|
|
29790
30105
|
async function getBackupRevision(database, conversationId) {
|
|
29791
30106
|
const serialized = await database.read(async () => {
|
|
29792
|
-
const { Q:
|
|
30107
|
+
const { Q: Q21 } = await import("@nozbe/watermelondb");
|
|
29793
30108
|
const tables = await Promise.all(
|
|
29794
30109
|
["conversations", "history"].map(
|
|
29795
|
-
(table) => database.get(table).query(
|
|
30110
|
+
(table) => database.get(table).query(Q21.where("conversation_id", conversationId), Q21.sortBy("id", Q21.asc)).unsafeFetchRaw()
|
|
29796
30111
|
)
|
|
29797
30112
|
);
|
|
29798
30113
|
return JSON.stringify(
|
|
@@ -29835,9 +30150,9 @@ async function pushConversationToICloud(database, conversationId, userAddress, d
|
|
|
29835
30150
|
}
|
|
29836
30151
|
async function performICloudExport(database, userAddress, deps, onProgress) {
|
|
29837
30152
|
await deps.requestEncryptionKey(userAddress);
|
|
29838
|
-
const { Q:
|
|
30153
|
+
const { Q: Q21 } = await import("@nozbe/watermelondb");
|
|
29839
30154
|
const conversationsCollection = database.get("conversations");
|
|
29840
|
-
const records = await conversationsCollection.query(
|
|
30155
|
+
const records = await conversationsCollection.query(Q21.where("is_deleted", false)).fetch();
|
|
29841
30156
|
const conversations = records.map(conversationToStoredRaw);
|
|
29842
30157
|
const total = conversations.length;
|
|
29843
30158
|
if (total === 0) {
|
|
@@ -33560,7 +33875,7 @@ function useExportPdf() {
|
|
|
33560
33875
|
}
|
|
33561
33876
|
|
|
33562
33877
|
// src/react/useFiles.ts
|
|
33563
|
-
import { Q as
|
|
33878
|
+
import { Q as Q18 } from "@nozbe/watermelondb";
|
|
33564
33879
|
import { useCallback as useCallback8, useEffect as useEffect6, useMemo as useMemo6, useState as useState8 } from "react";
|
|
33565
33880
|
function useFiles(options) {
|
|
33566
33881
|
const { database, walletAddress } = options;
|
|
@@ -33578,7 +33893,7 @@ function useFiles(options) {
|
|
|
33578
33893
|
setIsLoading(true);
|
|
33579
33894
|
try {
|
|
33580
33895
|
const coll = database.get("media");
|
|
33581
|
-
await coll.query(
|
|
33896
|
+
await coll.query(Q18.take(1)).fetch();
|
|
33582
33897
|
setMediaCollection(coll);
|
|
33583
33898
|
setIsReady(true);
|
|
33584
33899
|
} catch (error) {
|
|
@@ -34803,7 +35118,7 @@ function usePhoneCalls(options = {}) {
|
|
|
34803
35118
|
}
|
|
34804
35119
|
|
|
34805
35120
|
// src/react/useProjects.ts
|
|
34806
|
-
import { Q as
|
|
35121
|
+
import { Q as Q19 } from "@nozbe/watermelondb";
|
|
34807
35122
|
import { useCallback as useCallback15, useEffect as useEffect10, useMemo as useMemo8, useState as useState14 } from "react";
|
|
34808
35123
|
function useProjects(options) {
|
|
34809
35124
|
const { database, initialProjectId } = options;
|
|
@@ -34825,7 +35140,7 @@ function useProjects(options) {
|
|
|
34825
35140
|
conversations: convColl?.table
|
|
34826
35141
|
});
|
|
34827
35142
|
getLogger().debug("[useProjects] Running test query on projects table...");
|
|
34828
|
-
const testResult = await projColl.query(
|
|
35143
|
+
const testResult = await projColl.query(Q19.take(1)).fetch();
|
|
34829
35144
|
getLogger().debug(
|
|
34830
35145
|
"[useProjects] Test query succeeded, found",
|
|
34831
35146
|
testResult.length,
|
|
@@ -34912,7 +35227,7 @@ function useProjects(options) {
|
|
|
34912
35227
|
if (!projectsCollection) {
|
|
34913
35228
|
return;
|
|
34914
35229
|
}
|
|
34915
|
-
const subscription = projectsCollection.query(
|
|
35230
|
+
const subscription = projectsCollection.query(Q19.where("is_deleted", false)).observe().subscribe((records) => {
|
|
34916
35231
|
setProjects(records.map(projectToStored));
|
|
34917
35232
|
});
|
|
34918
35233
|
return () => subscription.unsubscribe();
|
|
@@ -35034,7 +35349,7 @@ function useProjects(options) {
|
|
|
35034
35349
|
import { useCallback as useCallback16, useMemo as useMemo9, useSyncExternalStore } from "react";
|
|
35035
35350
|
|
|
35036
35351
|
// src/react/userSettingsStore.ts
|
|
35037
|
-
import { Q as
|
|
35352
|
+
import { Q as Q20 } from "@nozbe/watermelondb";
|
|
35038
35353
|
var EMPTY_SNAPSHOT = Object.freeze({
|
|
35039
35354
|
modelPreference: null,
|
|
35040
35355
|
userPreference: null,
|
|
@@ -35086,12 +35401,13 @@ async function startLoad(entry, walletAddress) {
|
|
|
35086
35401
|
}
|
|
35087
35402
|
function startObserve(entry, walletAddress) {
|
|
35088
35403
|
let isInitialEmission = true;
|
|
35089
|
-
entry.observeSub = entry.storageCtx.userPreferencesCollection.query(
|
|
35404
|
+
entry.observeSub = entry.storageCtx.userPreferencesCollection.query(Q20.where("wallet_address", walletAddress)).observeWithColumns([
|
|
35090
35405
|
"nickname",
|
|
35091
35406
|
"occupation",
|
|
35092
35407
|
"description",
|
|
35093
35408
|
"models",
|
|
35094
35409
|
"personality",
|
|
35410
|
+
"external_wallets",
|
|
35095
35411
|
"updated_at"
|
|
35096
35412
|
]).subscribe({
|
|
35097
35413
|
next: (records) => {
|
|
@@ -35106,6 +35422,7 @@ function startObserve(entry, walletAddress) {
|
|
|
35106
35422
|
description: record2.description,
|
|
35107
35423
|
models: record2.models,
|
|
35108
35424
|
personality: record2.personality,
|
|
35425
|
+
externalWallets: record2.externalWallets,
|
|
35109
35426
|
createdAt: record2.createdAt,
|
|
35110
35427
|
updatedAt: record2.updatedAt
|
|
35111
35428
|
}
|
|
@@ -36330,6 +36647,7 @@ export {
|
|
|
36330
36647
|
RemoteMemoryPartialCreateError,
|
|
36331
36648
|
RerankerUnavailableError,
|
|
36332
36649
|
SDK_SCHEMA_VERSION,
|
|
36650
|
+
SELECT_PAYMENT_WALLET_TOOL_NAME,
|
|
36333
36651
|
SERVER_TOOL_DEPENDENCY_SETS,
|
|
36334
36652
|
SHORT_TTL_MS,
|
|
36335
36653
|
SLIDER_CONFIG,
|
|
@@ -36354,6 +36672,7 @@ export {
|
|
|
36354
36672
|
TextProcessor,
|
|
36355
36673
|
UIInteractionProvider,
|
|
36356
36674
|
VAULT_SIZE_HOP_CAP,
|
|
36675
|
+
WALLET_PAYMENT_TOOL_NAME,
|
|
36357
36676
|
WalletPoller,
|
|
36358
36677
|
WatermelonChatStorageAdapter,
|
|
36359
36678
|
WordProcessor,
|
|
@@ -36420,12 +36739,14 @@ export {
|
|
|
36420
36739
|
createRemoteMemoryPipeline,
|
|
36421
36740
|
createRemoteMemoryStore,
|
|
36422
36741
|
createSavedToolOp,
|
|
36742
|
+
createSelectPaymentWalletTool,
|
|
36423
36743
|
createServerToolsFilter,
|
|
36424
36744
|
createStockPricePreProcessor,
|
|
36425
36745
|
createVaultEmbeddingCache,
|
|
36426
36746
|
createVaultFolderOp,
|
|
36427
36747
|
createVaultMemoriesBatchOp,
|
|
36428
36748
|
createVaultMemoryOp,
|
|
36749
|
+
createWalletPaymentTool,
|
|
36429
36750
|
createWeatherPreProcessor,
|
|
36430
36751
|
createWebSearchPreProcessor,
|
|
36431
36752
|
decodeChunkVector,
|