@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/expo/index.cjs
CHANGED
|
@@ -1429,6 +1429,7 @@ __export(index_exports, {
|
|
|
1429
1429
|
RemoteMemoryPartialCreateError: () => RemoteMemoryPartialCreateError,
|
|
1430
1430
|
RerankerUnavailableError: () => RerankerUnavailableError,
|
|
1431
1431
|
SDK_SCHEMA_VERSION: () => SDK_SCHEMA_VERSION,
|
|
1432
|
+
SELECT_PAYMENT_WALLET_TOOL_NAME: () => SELECT_PAYMENT_WALLET_TOOL_NAME,
|
|
1432
1433
|
SHORT_TTL_MS: () => SHORT_TTL_MS,
|
|
1433
1434
|
STREAM_RESUMABLE_HEADER: () => STREAM_RESUMABLE_HEADER,
|
|
1434
1435
|
StoredVaultFolderModel: () => VaultFolder,
|
|
@@ -1441,6 +1442,7 @@ __export(index_exports, {
|
|
|
1441
1442
|
TREND_RECENT_WINDOW_DAYS: () => TREND_RECENT_WINDOW_DAYS,
|
|
1442
1443
|
TREND_STALE_WINDOW_DAYS: () => TREND_STALE_WINDOW_DAYS,
|
|
1443
1444
|
VAULT_SIZE_HOP_CAP: () => VAULT_SIZE_HOP_CAP,
|
|
1445
|
+
WALLET_PAYMENT_TOOL_NAME: () => WALLET_PAYMENT_TOOL_NAME,
|
|
1444
1446
|
WalletPoller: () => WalletPoller,
|
|
1445
1447
|
addConversationMemoriesOp: () => addConversationMemoriesOp,
|
|
1446
1448
|
archiveVaultMemoryOp: () => archiveVaultMemoryOp,
|
|
@@ -1495,12 +1497,14 @@ __export(index_exports, {
|
|
|
1495
1497
|
createRemoteMemoryPersistence: () => createRemoteMemoryPersistence,
|
|
1496
1498
|
createRemoteMemoryPipeline: () => createRemoteMemoryPipeline,
|
|
1497
1499
|
createRemoteMemoryStore: () => createRemoteMemoryStore,
|
|
1500
|
+
createSelectPaymentWalletTool: () => createSelectPaymentWalletTool,
|
|
1498
1501
|
createStockPricePreProcessor: () => createStockPricePreProcessor,
|
|
1499
1502
|
createStreamingDeAnonymizer: () => createStreamingDeAnonymizer,
|
|
1500
1503
|
createVaultEmbeddingCache: () => createVaultEmbeddingCache,
|
|
1501
1504
|
createVaultFolderOp: () => createVaultFolderOp,
|
|
1502
1505
|
createVaultMemoriesBatchOp: () => createVaultMemoriesBatchOp,
|
|
1503
1506
|
createVaultMemoryOp: () => createVaultMemoryOp,
|
|
1507
|
+
createWalletPaymentTool: () => createWalletPaymentTool,
|
|
1504
1508
|
createWeatherPreProcessor: () => createWeatherPreProcessor,
|
|
1505
1509
|
createWebSearchPreProcessor: () => createWebSearchPreProcessor,
|
|
1506
1510
|
decodeChunkVector: () => decodeChunkVector,
|
|
@@ -2048,7 +2052,7 @@ ${appendix}` : appendix;
|
|
|
2048
2052
|
}
|
|
2049
2053
|
|
|
2050
2054
|
// src/lib/db/chat/operations.ts
|
|
2051
|
-
var
|
|
2055
|
+
var import_watermelondb3 = require("@nozbe/watermelondb");
|
|
2052
2056
|
var import_uuid2 = require("uuid");
|
|
2053
2057
|
|
|
2054
2058
|
// src/react/useEncryption.ts
|
|
@@ -3263,6 +3267,118 @@ async function assembleDecryptedMessage(message, address) {
|
|
|
3263
3267
|
return result;
|
|
3264
3268
|
}
|
|
3265
3269
|
|
|
3270
|
+
// src/lib/db/chat/toolCallEventIndex.ts
|
|
3271
|
+
var import_watermelondb2 = require("@nozbe/watermelondb");
|
|
3272
|
+
function parseEventIds(value) {
|
|
3273
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3274
|
+
let events;
|
|
3275
|
+
try {
|
|
3276
|
+
events = typeof value === "string" ? JSON.parse(value) : value;
|
|
3277
|
+
} catch {
|
|
3278
|
+
return ids;
|
|
3279
|
+
}
|
|
3280
|
+
if (!Array.isArray(events)) return ids;
|
|
3281
|
+
for (const event of events) {
|
|
3282
|
+
if (!event || typeof event !== "object") continue;
|
|
3283
|
+
const id = event.id;
|
|
3284
|
+
if (typeof id === "string" && id) ids.add(id);
|
|
3285
|
+
}
|
|
3286
|
+
return ids;
|
|
3287
|
+
}
|
|
3288
|
+
async function fetchEventRows(collection, conversationId) {
|
|
3289
|
+
try {
|
|
3290
|
+
return await collection.query(
|
|
3291
|
+
import_watermelondb2.Q.unsafeSqlQuery(
|
|
3292
|
+
`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 ('', '[]')`,
|
|
3293
|
+
[conversationId]
|
|
3294
|
+
)
|
|
3295
|
+
).unsafeFetchRaw();
|
|
3296
|
+
} catch (error) {
|
|
3297
|
+
if (!(error instanceof Error) || !/unsafeSqlQuery.*not supported/.test(error.message)) {
|
|
3298
|
+
throw error;
|
|
3299
|
+
}
|
|
3300
|
+
return await collection.query(
|
|
3301
|
+
import_watermelondb2.Q.where("conversation_id", conversationId),
|
|
3302
|
+
import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notEq(null)),
|
|
3303
|
+
import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notIn(["", "[]"])),
|
|
3304
|
+
import_watermelondb2.Q.unsafeLokiTransform(
|
|
3305
|
+
(rows) => rows.map(({ id, tool_call_events }) => ({ id, tool_call_events }))
|
|
3306
|
+
)
|
|
3307
|
+
).unsafeFetchRaw();
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
var ToolCallEventIndex = class {
|
|
3311
|
+
constructor(collection) {
|
|
3312
|
+
this.collection = collection;
|
|
3313
|
+
this.conversations = /* @__PURE__ */ new Map();
|
|
3314
|
+
this.messages = /* @__PURE__ */ new Map();
|
|
3315
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
3316
|
+
this.resetCount = collection.database._resetCount;
|
|
3317
|
+
collection.experimentalSubscribe((changes) => {
|
|
3318
|
+
for (const { record: record2, type } of changes) {
|
|
3319
|
+
this.replace(
|
|
3320
|
+
record2.id,
|
|
3321
|
+
type === "destroyed" ? void 0 : record2.conversationId,
|
|
3322
|
+
type === "destroyed" ? void 0 : record2._getRaw("tool_call_events")
|
|
3323
|
+
);
|
|
3324
|
+
}
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3327
|
+
replace(messageId, conversationId, value) {
|
|
3328
|
+
const previous = this.messages.get(messageId);
|
|
3329
|
+
if (previous) {
|
|
3330
|
+
const counts2 = this.conversations.get(previous.conversationId);
|
|
3331
|
+
for (const id of previous.ids) {
|
|
3332
|
+
const count2 = counts2.get(id) - 1;
|
|
3333
|
+
if (count2 === 0) counts2.delete(id);
|
|
3334
|
+
else counts2.set(id, count2);
|
|
3335
|
+
}
|
|
3336
|
+
this.messages.delete(messageId);
|
|
3337
|
+
}
|
|
3338
|
+
const counts = conversationId === void 0 ? void 0 : this.conversations.get(conversationId);
|
|
3339
|
+
if (!counts || conversationId === void 0) return;
|
|
3340
|
+
const ids = parseEventIds(value);
|
|
3341
|
+
if (ids.size === 0) return;
|
|
3342
|
+
this.messages.set(messageId, { conversationId, ids });
|
|
3343
|
+
for (const id of ids) counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
3344
|
+
}
|
|
3345
|
+
async get(conversationId) {
|
|
3346
|
+
if (this.resetCount !== this.collection.database._resetCount) {
|
|
3347
|
+
this.conversations.clear();
|
|
3348
|
+
this.messages.clear();
|
|
3349
|
+
this.pending.clear();
|
|
3350
|
+
this.resetCount = this.collection.database._resetCount;
|
|
3351
|
+
}
|
|
3352
|
+
if (!this.conversations.has(conversationId)) {
|
|
3353
|
+
let pending = this.pending.get(conversationId);
|
|
3354
|
+
if (!pending) {
|
|
3355
|
+
pending = this.collection.database.read(async () => {
|
|
3356
|
+
const rows = await fetchEventRows(this.collection, conversationId);
|
|
3357
|
+
this.conversations.set(conversationId, /* @__PURE__ */ new Map());
|
|
3358
|
+
for (const row of rows)
|
|
3359
|
+
this.replace(String(row.id), conversationId, row.tool_call_events);
|
|
3360
|
+
});
|
|
3361
|
+
this.pending.set(conversationId, pending);
|
|
3362
|
+
}
|
|
3363
|
+
try {
|
|
3364
|
+
await pending;
|
|
3365
|
+
} finally {
|
|
3366
|
+
this.pending.delete(conversationId);
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
return new Set(this.conversations.get(conversationId).keys());
|
|
3370
|
+
}
|
|
3371
|
+
};
|
|
3372
|
+
var indexes = /* @__PURE__ */ new WeakMap();
|
|
3373
|
+
function getToolCallEventIds(collection, conversationId) {
|
|
3374
|
+
let index = indexes.get(collection);
|
|
3375
|
+
if (!index) {
|
|
3376
|
+
index = new ToolCallEventIndex(collection);
|
|
3377
|
+
indexes.set(collection, index);
|
|
3378
|
+
}
|
|
3379
|
+
return index.get(conversationId);
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3266
3382
|
// src/lib/db/chat/types.ts
|
|
3267
3383
|
var import_uuid = require("uuid");
|
|
3268
3384
|
|
|
@@ -3655,7 +3771,7 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
|
|
|
3655
3771
|
);
|
|
3656
3772
|
}
|
|
3657
3773
|
async function getConversationOp(ctx, id) {
|
|
3658
|
-
const results = await ctx.conversationsCollection.query(
|
|
3774
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
3659
3775
|
return results.length > 0 ? await conversationToStored(
|
|
3660
3776
|
results[0],
|
|
3661
3777
|
ctx.walletAddress,
|
|
@@ -3664,7 +3780,7 @@ async function getConversationOp(ctx, id) {
|
|
|
3664
3780
|
) : null;
|
|
3665
3781
|
}
|
|
3666
3782
|
async function getConversationsOp(ctx) {
|
|
3667
|
-
const results = await ctx.conversationsCollection.query(
|
|
3783
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false), import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).unsafeFetchRaw();
|
|
3668
3784
|
return Promise.all(
|
|
3669
3785
|
results.map(
|
|
3670
3786
|
(raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -3685,33 +3801,33 @@ function conversationRawToLazyStored(raw) {
|
|
|
3685
3801
|
};
|
|
3686
3802
|
}
|
|
3687
3803
|
async function getConversationsLazyOp(ctx) {
|
|
3688
|
-
const results = await ctx.conversationsCollection.query(
|
|
3804
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false), import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).unsafeFetchRaw();
|
|
3689
3805
|
return results.map(conversationRawToLazyStored);
|
|
3690
3806
|
}
|
|
3691
3807
|
async function getConversationsPageOp(ctx, options) {
|
|
3692
3808
|
const limit = Math.floor(options?.limit ?? 200);
|
|
3693
3809
|
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
3694
3810
|
const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
|
|
3695
|
-
const clauses = [
|
|
3811
|
+
const clauses = [import_watermelondb3.Q.where("is_deleted", false)];
|
|
3696
3812
|
if (options?.before !== void 0) {
|
|
3697
3813
|
clauses.push(
|
|
3698
|
-
exclude.size > 0 ?
|
|
3814
|
+
exclude.size > 0 ? import_watermelondb3.Q.where("created_at", import_watermelondb3.Q.lte(options.before)) : import_watermelondb3.Q.where("created_at", import_watermelondb3.Q.lt(options.before))
|
|
3699
3815
|
);
|
|
3700
3816
|
}
|
|
3701
|
-
const fetched = await ctx.conversationsCollection.query(...clauses,
|
|
3817
|
+
const fetched = await ctx.conversationsCollection.query(...clauses, import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc), import_watermelondb3.Q.take(limit + exclude.size)).unsafeFetchRaw();
|
|
3702
3818
|
const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
|
|
3703
3819
|
return results.slice(0, limit).map(conversationRawToLazyStored);
|
|
3704
3820
|
}
|
|
3705
3821
|
async function getConversationsByProjectLazyOp(ctx, projectId) {
|
|
3706
3822
|
const results = await ctx.conversationsCollection.query(
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3823
|
+
import_watermelondb3.Q.where("project_id", projectId === null ? "" : projectId),
|
|
3824
|
+
import_watermelondb3.Q.where("is_deleted", false),
|
|
3825
|
+
import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)
|
|
3710
3826
|
).unsafeFetchRaw();
|
|
3711
3827
|
return results.map(conversationRawToLazyStored);
|
|
3712
3828
|
}
|
|
3713
3829
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
3714
|
-
const results = await ctx.conversationsCollection.query(
|
|
3830
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
3715
3831
|
if (results.length > 0) {
|
|
3716
3832
|
const encryptedOpts = ctx.walletAddress && ctx.signMessage ? await encryptConversationFields(
|
|
3717
3833
|
{ title },
|
|
@@ -3730,13 +3846,13 @@ async function updateConversationTitleOp(ctx, id, title) {
|
|
|
3730
3846
|
return false;
|
|
3731
3847
|
}
|
|
3732
3848
|
async function deleteConversationOp(ctx, id) {
|
|
3733
|
-
const results = await ctx.conversationsCollection.query(
|
|
3849
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
3734
3850
|
if (results.length > 0) {
|
|
3735
3851
|
await ctx.database.write(async () => {
|
|
3736
3852
|
await results[0].update((conv) => {
|
|
3737
3853
|
conv._setRaw("is_deleted", true);
|
|
3738
3854
|
});
|
|
3739
|
-
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(
|
|
3855
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", id)).fetch() : [];
|
|
3740
3856
|
for (const job of jobs) await job.destroyPermanently();
|
|
3741
3857
|
});
|
|
3742
3858
|
return true;
|
|
@@ -3744,7 +3860,7 @@ async function deleteConversationOp(ctx, id) {
|
|
|
3744
3860
|
return false;
|
|
3745
3861
|
}
|
|
3746
3862
|
async function updateConversationPinnedOp(ctx, id, pinned) {
|
|
3747
|
-
const results = await ctx.conversationsCollection.query(
|
|
3863
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
3748
3864
|
if (results.length > 0) {
|
|
3749
3865
|
await ctx.database.write(async () => {
|
|
3750
3866
|
await results[0].update((conv) => {
|
|
@@ -3756,7 +3872,7 @@ async function updateConversationPinnedOp(ctx, id, pinned) {
|
|
|
3756
3872
|
return false;
|
|
3757
3873
|
}
|
|
3758
3874
|
async function getMessagesOp(ctx, convId, opts) {
|
|
3759
|
-
const fetched = await ctx.messagesCollection.query(
|
|
3875
|
+
const fetched = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId), import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.asc)).unsafeFetchRaw();
|
|
3760
3876
|
const results = opts?.rawFilter ? fetched.filter(opts.rawFilter) : fetched;
|
|
3761
3877
|
return Promise.all(
|
|
3762
3878
|
results.map(
|
|
@@ -3765,19 +3881,19 @@ async function getMessagesOp(ctx, convId, opts) {
|
|
|
3765
3881
|
);
|
|
3766
3882
|
}
|
|
3767
3883
|
async function getMessageCountOp(ctx, convId) {
|
|
3768
|
-
return await ctx.messagesCollection.query(
|
|
3884
|
+
return await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetchCount();
|
|
3769
3885
|
}
|
|
3770
3886
|
async function getMessagesPageOp(ctx, convId, opts) {
|
|
3771
3887
|
const limit = Math.floor(opts.limit);
|
|
3772
3888
|
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
3773
3889
|
const exclude = new Set(opts.boundaryExcludeUniqueIds ?? []);
|
|
3774
|
-
const clauses = [
|
|
3890
|
+
const clauses = [import_watermelondb3.Q.where("conversation_id", convId)];
|
|
3775
3891
|
if (opts.beforeMessageId !== void 0) {
|
|
3776
3892
|
clauses.push(
|
|
3777
|
-
exclude.size > 0 ?
|
|
3893
|
+
exclude.size > 0 ? import_watermelondb3.Q.where("message_id", import_watermelondb3.Q.lte(opts.beforeMessageId)) : import_watermelondb3.Q.where("message_id", import_watermelondb3.Q.lt(opts.beforeMessageId))
|
|
3778
3894
|
);
|
|
3779
3895
|
}
|
|
3780
|
-
const fetched = await ctx.messagesCollection.query(...clauses,
|
|
3896
|
+
const fetched = await ctx.messagesCollection.query(...clauses, import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.desc), import_watermelondb3.Q.take(limit + exclude.size)).unsafeFetchRaw();
|
|
3781
3897
|
const results = (exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched).slice(0, limit);
|
|
3782
3898
|
results.reverse();
|
|
3783
3899
|
return Promise.all(
|
|
@@ -3789,7 +3905,7 @@ async function getMessagesPageOp(ctx, convId, opts) {
|
|
|
3789
3905
|
);
|
|
3790
3906
|
}
|
|
3791
3907
|
async function getMessageSkeletonsOp(ctx, convId) {
|
|
3792
|
-
const results = await ctx.messagesCollection.query(
|
|
3908
|
+
const results = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId), import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.asc)).unsafeFetchRaw();
|
|
3793
3909
|
const roleById = /* @__PURE__ */ new Map();
|
|
3794
3910
|
for (const raw of results) {
|
|
3795
3911
|
roleById.set(raw.id, raw.role);
|
|
@@ -3834,32 +3950,12 @@ async function getMessageSkeletonsOp(ctx, convId) {
|
|
|
3834
3950
|
return skeletons;
|
|
3835
3951
|
}
|
|
3836
3952
|
async function getToolCallEventIdsOp(ctx, convId) {
|
|
3837
|
-
|
|
3838
|
-
const ids = /* @__PURE__ */ new Set();
|
|
3839
|
-
for (const raw of results) {
|
|
3840
|
-
const value = raw.tool_call_events;
|
|
3841
|
-
if (!value) continue;
|
|
3842
|
-
let events;
|
|
3843
|
-
if (typeof value === "string") {
|
|
3844
|
-
try {
|
|
3845
|
-
events = JSON.parse(value);
|
|
3846
|
-
} catch {
|
|
3847
|
-
continue;
|
|
3848
|
-
}
|
|
3849
|
-
} else if (Array.isArray(value)) {
|
|
3850
|
-
events = value;
|
|
3851
|
-
}
|
|
3852
|
-
if (!Array.isArray(events)) continue;
|
|
3853
|
-
for (const evt of events) {
|
|
3854
|
-
if (evt && evt.id) ids.add(evt.id);
|
|
3855
|
-
}
|
|
3856
|
-
}
|
|
3857
|
-
return ids;
|
|
3953
|
+
return getToolCallEventIds(ctx.messagesCollection, convId);
|
|
3858
3954
|
}
|
|
3859
3955
|
async function clearMessagesOp(ctx, convId) {
|
|
3860
3956
|
await ctx.database.write(async () => {
|
|
3861
|
-
const messages = await ctx.messagesCollection.query(
|
|
3862
|
-
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(
|
|
3957
|
+
const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetch();
|
|
3958
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", convId)).fetch() : [];
|
|
3863
3959
|
for (const job of jobs) {
|
|
3864
3960
|
await job.update((row) => {
|
|
3865
3961
|
row._setRaw("message_ids", "[]");
|
|
@@ -3884,7 +3980,7 @@ async function deleteMessageOp(ctx, uniqueId) {
|
|
|
3884
3980
|
return null;
|
|
3885
3981
|
}
|
|
3886
3982
|
await ctx.database.write(async () => {
|
|
3887
|
-
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(
|
|
3983
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", message.conversationId)).fetch() : [];
|
|
3888
3984
|
for (const job of jobs) {
|
|
3889
3985
|
const ids = JSON.parse(String(job._getRaw("message_ids")));
|
|
3890
3986
|
await job.update((row) => {
|
|
@@ -3957,9 +4053,9 @@ async function createMessageOp(ctx, opts) {
|
|
|
3957
4053
|
}
|
|
3958
4054
|
}
|
|
3959
4055
|
const newest = await ctx.messagesCollection.query(
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
4056
|
+
import_watermelondb3.Q.where("conversation_id", opts.conversationId),
|
|
4057
|
+
import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.desc),
|
|
4058
|
+
import_watermelondb3.Q.take(1)
|
|
3963
4059
|
).fetch();
|
|
3964
4060
|
const messageId = (newest[0]?.messageId ?? 0) + 1;
|
|
3965
4061
|
const encryptedOpts = await encryptMessageOptsIfNeeded(ctx, opts);
|
|
@@ -3973,7 +4069,7 @@ async function createMessageOp(ctx, opts) {
|
|
|
3973
4069
|
return messageToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
3974
4070
|
}
|
|
3975
4071
|
async function upsertMessageOp(ctx, opts) {
|
|
3976
|
-
const results = await ctx.messagesCollection.query(
|
|
4072
|
+
const results = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", opts.uniqueId)).fetch();
|
|
3977
4073
|
const existing = results.length > 0 ? results[0] : null;
|
|
3978
4074
|
if (!existing) {
|
|
3979
4075
|
return createMessageOp(ctx, opts);
|
|
@@ -4081,13 +4177,13 @@ async function decryptMessageEmbeddingFields(raw, walletAddress) {
|
|
|
4081
4177
|
async function sealLegacyMessageEmbeddingsOp(ctx) {
|
|
4082
4178
|
if (!ctx.walletAddress) return 0;
|
|
4083
4179
|
const candidateIds = await ctx.messagesCollection.query(
|
|
4084
|
-
|
|
4085
|
-
|
|
4180
|
+
import_watermelondb3.Q.where("content", import_watermelondb3.Q.like("enc:%")),
|
|
4181
|
+
import_watermelondb3.Q.or(
|
|
4086
4182
|
...["vector", "chunks"].map(
|
|
4087
|
-
(column) =>
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4183
|
+
(column) => import_watermelondb3.Q.and(
|
|
4184
|
+
import_watermelondb3.Q.where(column, import_watermelondb3.Q.notEq(null)),
|
|
4185
|
+
import_watermelondb3.Q.where(column, import_watermelondb3.Q.notEq("")),
|
|
4186
|
+
import_watermelondb3.Q.where(column, import_watermelondb3.Q.notLike("enc:%"))
|
|
4091
4187
|
)
|
|
4092
4188
|
)
|
|
4093
4189
|
)
|
|
@@ -4097,7 +4193,7 @@ async function sealLegacyMessageEmbeddingsOp(ctx) {
|
|
|
4097
4193
|
for (let start = 0; start < candidateIds.length; start += 50) {
|
|
4098
4194
|
const pageIds = candidateIds.slice(start, start + 50);
|
|
4099
4195
|
await ctx.database.write(async () => {
|
|
4100
|
-
const pageMessages = await ctx.messagesCollection.query(
|
|
4196
|
+
const pageMessages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).fetch();
|
|
4101
4197
|
for (const message of pageMessages) {
|
|
4102
4198
|
if (!isEncrypted(message.content)) continue;
|
|
4103
4199
|
const content = await decryptFieldDetailed(message.content, ctx.walletAddress);
|
|
@@ -4178,15 +4274,15 @@ function chunksWithoutText(raw) {
|
|
|
4178
4274
|
});
|
|
4179
4275
|
}
|
|
4180
4276
|
async function stripLegacyChunkTextOp(ctx) {
|
|
4181
|
-
const candidateIds = await ctx.messagesCollection.query(
|
|
4277
|
+
const candidateIds = await ctx.messagesCollection.query(import_watermelondb3.Q.where("chunks", import_watermelondb3.Q.like(`%${import_watermelondb3.Q.sanitizeLikeString('"text":')}%`))).fetchIds();
|
|
4182
4278
|
let stripped = 0;
|
|
4183
4279
|
for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
|
|
4184
4280
|
const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
|
|
4185
|
-
const rows = await ctx.messagesCollection.query(
|
|
4281
|
+
const rows = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).unsafeFetchRaw();
|
|
4186
4282
|
const changedIds = rows.filter((row) => chunksWithoutText(row.chunks) !== null).map((row) => String(row.id));
|
|
4187
4283
|
if (changedIds.length === 0) continue;
|
|
4188
4284
|
await ctx.database.write(async () => {
|
|
4189
|
-
const messages = await ctx.messagesCollection.query(
|
|
4285
|
+
const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(changedIds))).fetch();
|
|
4190
4286
|
const updates = messages.flatMap((message) => {
|
|
4191
4287
|
const raw = message._raw;
|
|
4192
4288
|
const chunks3 = chunksWithoutText(raw.chunks);
|
|
@@ -4233,13 +4329,13 @@ async function encryptToolCallEventsOp(ctx) {
|
|
|
4233
4329
|
return 0;
|
|
4234
4330
|
}
|
|
4235
4331
|
const candidateIds = await ctx.messagesCollection.query(
|
|
4236
|
-
|
|
4237
|
-
|
|
4332
|
+
import_watermelondb3.Q.where("tool_call_events", import_watermelondb3.Q.notEq(null)),
|
|
4333
|
+
import_watermelondb3.Q.where("tool_call_events", import_watermelondb3.Q.notIn(["", "[]"]))
|
|
4238
4334
|
).fetchIds();
|
|
4239
4335
|
let encrypted = 0;
|
|
4240
4336
|
for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
|
|
4241
4337
|
const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
|
|
4242
|
-
const rows = await ctx.messagesCollection.query(
|
|
4338
|
+
const rows = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).unsafeFetchRaw();
|
|
4243
4339
|
const repairs = /* @__PURE__ */ new Map();
|
|
4244
4340
|
for (const row of rows) {
|
|
4245
4341
|
const column = await encryptedToolCallEventsColumn(
|
|
@@ -4252,12 +4348,12 @@ async function encryptToolCallEventsOp(ctx) {
|
|
|
4252
4348
|
}
|
|
4253
4349
|
if (repairs.size === 0) continue;
|
|
4254
4350
|
await ctx.database.write(async () => {
|
|
4255
|
-
const messages = (await ctx.messagesCollection.query(
|
|
4351
|
+
const messages = (await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf([...repairs.keys()]))).fetch()).filter(
|
|
4256
4352
|
(message) => message._raw.tool_call_events === repairs.get(message.id)?.raw
|
|
4257
4353
|
);
|
|
4258
4354
|
if (messages.length === 0) return;
|
|
4259
4355
|
const conversationIds = [...new Set(messages.map((message) => message.conversationId))];
|
|
4260
|
-
const conversations = await ctx.conversationsCollection.query(
|
|
4356
|
+
const conversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", import_watermelondb3.Q.oneOf(conversationIds))).fetch();
|
|
4261
4357
|
await ctx.database.batch(
|
|
4262
4358
|
...messages.map(
|
|
4263
4359
|
(message) => message.prepareUpdate((msg) => {
|
|
@@ -4284,7 +4380,7 @@ async function savedKeyOpensExistingData(ctx, address, signMessage, embeddedWall
|
|
|
4284
4380
|
return refreshEncryptionKeyIfMatches(address, v2Probe, signMessage, embeddedWalletSigner);
|
|
4285
4381
|
}
|
|
4286
4382
|
async function findEncryptedContent(ctx, pattern) {
|
|
4287
|
-
const [row] = await ctx.messagesCollection.query(
|
|
4383
|
+
const [row] = await ctx.messagesCollection.query(import_watermelondb3.Q.where("content", import_watermelondb3.Q.like(pattern)), import_watermelondb3.Q.take(1)).unsafeFetchRaw();
|
|
4288
4384
|
return row ? String(row.content) : null;
|
|
4289
4385
|
}
|
|
4290
4386
|
async function updateMessageErrorOp(ctx, uniqueId, error) {
|
|
@@ -4397,7 +4493,7 @@ function toChunkCandidateKey(raw) {
|
|
|
4397
4493
|
}
|
|
4398
4494
|
async function fetchRowsByIds(ctx, ids) {
|
|
4399
4495
|
if (ids.length === 0) return [];
|
|
4400
|
-
return await ctx.messagesCollection.query(
|
|
4496
|
+
return await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))).unsafeFetchRaw();
|
|
4401
4497
|
}
|
|
4402
4498
|
async function projectedChunkRowSource(ctx, filter) {
|
|
4403
4499
|
const clauses = [
|
|
@@ -4415,7 +4511,7 @@ async function projectedChunkRowSource(ctx, filter) {
|
|
|
4415
4511
|
args.push(filter.excludeConversationId);
|
|
4416
4512
|
}
|
|
4417
4513
|
const keyRows = await ctx.messagesCollection.query(
|
|
4418
|
-
|
|
4514
|
+
import_watermelondb3.Q.unsafeSqlQuery(
|
|
4419
4515
|
`select "id", "conversation_id", "updated_at", "embedding_model" from "history" where ${clauses.join(" and ")}`,
|
|
4420
4516
|
args
|
|
4421
4517
|
)
|
|
@@ -4425,7 +4521,7 @@ async function projectedChunkRowSource(ctx, filter) {
|
|
|
4425
4521
|
loadVectorRows: async (ids) => {
|
|
4426
4522
|
if (ids.length === 0) return [];
|
|
4427
4523
|
return await ctx.messagesCollection.query(
|
|
4428
|
-
|
|
4524
|
+
import_watermelondb3.Q.unsafeSqlQuery(
|
|
4429
4525
|
`select "id", "updated_at", "chunks", "vector" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
4430
4526
|
ids
|
|
4431
4527
|
)
|
|
@@ -4435,11 +4531,11 @@ async function projectedChunkRowSource(ctx, filter) {
|
|
|
4435
4531
|
};
|
|
4436
4532
|
}
|
|
4437
4533
|
async function fullScanChunkRowSource(ctx, filter) {
|
|
4438
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
4534
|
+
const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
4439
4535
|
const activeConversationIds = new Set(
|
|
4440
4536
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
4441
4537
|
);
|
|
4442
|
-
const queryConditions = filter.conversationId !== void 0 ? [
|
|
4538
|
+
const queryConditions = filter.conversationId !== void 0 ? [import_watermelondb3.Q.where("conversation_id", filter.conversationId)] : [];
|
|
4443
4539
|
const rows = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
4444
4540
|
const rowsById = /* @__PURE__ */ new Map();
|
|
4445
4541
|
for (const row of rows) {
|
|
@@ -6366,6 +6462,17 @@ function missingConfirmFields(action, parameters) {
|
|
|
6366
6462
|
return requirement.fields.filter((field10) => !shown.has(field10));
|
|
6367
6463
|
}
|
|
6368
6464
|
|
|
6465
|
+
// src/tools/walletPaymentConstants.ts
|
|
6466
|
+
var SELECT_PAYMENT_WALLET_TOOL_NAME = "select_payment_wallet";
|
|
6467
|
+
var WALLET_PAYMENT_TOOL_NAME = "prompt_wallet_payment";
|
|
6468
|
+
var FLIGHT_BOOK_TOOL_SET = "flight-book";
|
|
6469
|
+
var FLIGHT_SERVER_TOOL_NAMES = [
|
|
6470
|
+
"AnumaPaymentsMCP-anuma_search_flights",
|
|
6471
|
+
"AnumaPaymentsMCP-anuma_flight_offer_details",
|
|
6472
|
+
"AnumaPaymentsMCP-anuma_create_flight_intent",
|
|
6473
|
+
"AnumaPaymentsMCP-anuma_get_flight_booking"
|
|
6474
|
+
];
|
|
6475
|
+
|
|
6369
6476
|
// src/lib/chat/toolLoop.ts
|
|
6370
6477
|
init_redactor();
|
|
6371
6478
|
|
|
@@ -7065,7 +7172,8 @@ var BUILT_IN_TOOL_SETS = [
|
|
|
7065
7172
|
"AnumaPaymentsMCP-anuma_cancel_reservation"
|
|
7066
7173
|
],
|
|
7067
7174
|
anchors: []
|
|
7068
|
-
}
|
|
7175
|
+
},
|
|
7176
|
+
{ name: FLIGHT_BOOK_TOOL_SET, members: [...FLIGHT_SERVER_TOOL_NAMES], anchors: [] }
|
|
7069
7177
|
];
|
|
7070
7178
|
var CONFIRMED_ACTION_TOOL_SETS = /* @__PURE__ */ new Map([
|
|
7071
7179
|
["book_restaurant", "restaurant-book"],
|
|
@@ -7197,6 +7305,16 @@ var SERVER_TOOL_DEPENDENCY_SETS = [
|
|
|
7197
7305
|
members: ["AnumaPaymentsMCP-anuma_list_reservations"],
|
|
7198
7306
|
anchors: ["AnumaPaymentsMCP-anuma_cancel_reservation"],
|
|
7199
7307
|
anchorMinSimilarity: 0.5
|
|
7308
|
+
},
|
|
7309
|
+
{
|
|
7310
|
+
name: "flight-book-lookup",
|
|
7311
|
+
members: [
|
|
7312
|
+
"AnumaPaymentsMCP-anuma_flight_offer_details",
|
|
7313
|
+
"AnumaPaymentsMCP-anuma_create_flight_intent",
|
|
7314
|
+
"AnumaPaymentsMCP-anuma_get_flight_booking"
|
|
7315
|
+
],
|
|
7316
|
+
anchors: ["AnumaPaymentsMCP-anuma_search_flights"],
|
|
7317
|
+
anchorMinSimilarity: 0.5
|
|
7200
7318
|
}
|
|
7201
7319
|
];
|
|
7202
7320
|
var defaultServerToolsFilter = createServerToolsFilter({
|
|
@@ -9462,7 +9580,14 @@ function getToolName(tool) {
|
|
|
9462
9580
|
function toolsAfterConfirmation(apiTools, executionResults) {
|
|
9463
9581
|
const members = /* @__PURE__ */ new Set();
|
|
9464
9582
|
let keepConfirm = false;
|
|
9583
|
+
let keepPaymentTools = false;
|
|
9465
9584
|
for (const r of executionResults) {
|
|
9585
|
+
if (r.name === SELECT_PAYMENT_WALLET_TOOL_NAME && r.result?.confirmed === true) {
|
|
9586
|
+
const flightSet = BUILT_IN_TOOL_SETS.find((s) => s.name === FLIGHT_BOOK_TOOL_SET);
|
|
9587
|
+
for (const member of flightSet?.members ?? []) members.add(member);
|
|
9588
|
+
keepPaymentTools = true;
|
|
9589
|
+
continue;
|
|
9590
|
+
}
|
|
9466
9591
|
if (r.name !== CONFIRM_TOOL_NAME) continue;
|
|
9467
9592
|
const answer = r.result;
|
|
9468
9593
|
if (answer?.confirmed !== true || typeof answer.action !== "string") continue;
|
|
@@ -9474,7 +9599,7 @@ function toolsAfterConfirmation(apiTools, executionResults) {
|
|
|
9474
9599
|
if (!apiTools.some((t) => members.has(getToolName(t) ?? ""))) return void 0;
|
|
9475
9600
|
return apiTools.filter((t) => {
|
|
9476
9601
|
const name = getToolName(t) ?? "";
|
|
9477
|
-
return members.has(name) || name === TOOL_SEARCH_TOOL_NAME || keepConfirm && name === CONFIRM_TOOL_NAME;
|
|
9602
|
+
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);
|
|
9478
9603
|
});
|
|
9479
9604
|
}
|
|
9480
9605
|
var STREAM_RESUMABLE_HEADER = "X-Stream-Resumable";
|
|
@@ -11054,9 +11179,9 @@ async function decryptConversationTitle(encryptedTitle, address) {
|
|
|
11054
11179
|
}
|
|
11055
11180
|
|
|
11056
11181
|
// src/lib/db/chat/models.ts
|
|
11057
|
-
var
|
|
11182
|
+
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
11058
11183
|
var import_decorators = require("@nozbe/watermelondb/decorators");
|
|
11059
|
-
var Message = class extends
|
|
11184
|
+
var Message = class extends import_watermelondb4.Model {
|
|
11060
11185
|
};
|
|
11061
11186
|
Message.table = "history";
|
|
11062
11187
|
Message.associations = {
|
|
@@ -11135,7 +11260,7 @@ __decorateClass([
|
|
|
11135
11260
|
__decorateClass([
|
|
11136
11261
|
(0, import_decorators.text)("origin")
|
|
11137
11262
|
], Message.prototype, "origin", 2);
|
|
11138
|
-
var Conversation = class extends
|
|
11263
|
+
var Conversation = class extends import_watermelondb4.Model {
|
|
11139
11264
|
};
|
|
11140
11265
|
Conversation.table = "conversations";
|
|
11141
11266
|
Conversation.associations = {
|
|
@@ -11163,7 +11288,7 @@ __decorateClass([
|
|
|
11163
11288
|
__decorateClass([
|
|
11164
11289
|
(0, import_decorators.date)("pinned_at")
|
|
11165
11290
|
], Conversation.prototype, "pinnedAt", 2);
|
|
11166
|
-
var ConversationSummary = class extends
|
|
11291
|
+
var ConversationSummary = class extends import_watermelondb4.Model {
|
|
11167
11292
|
};
|
|
11168
11293
|
ConversationSummary.table = "conversation_summaries";
|
|
11169
11294
|
ConversationSummary.associations = {
|
|
@@ -11189,12 +11314,12 @@ __decorateClass([
|
|
|
11189
11314
|
], ConversationSummary.prototype, "updatedAt", 2);
|
|
11190
11315
|
|
|
11191
11316
|
// src/lib/db/chat/schema.ts
|
|
11192
|
-
var
|
|
11317
|
+
var import_watermelondb5 = require("@nozbe/watermelondb");
|
|
11193
11318
|
var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
|
|
11194
|
-
var chatStorageSchema = (0,
|
|
11319
|
+
var chatStorageSchema = (0, import_watermelondb5.appSchema)({
|
|
11195
11320
|
version: 7,
|
|
11196
11321
|
tables: [
|
|
11197
|
-
(0,
|
|
11322
|
+
(0, import_watermelondb5.tableSchema)({
|
|
11198
11323
|
name: "history",
|
|
11199
11324
|
columns: [
|
|
11200
11325
|
{ name: "message_id", type: "number" },
|
|
@@ -11218,7 +11343,7 @@ var chatStorageSchema = (0, import_watermelondb4.appSchema)({
|
|
|
11218
11343
|
{ name: "thinking", type: "string", isOptional: true }
|
|
11219
11344
|
]
|
|
11220
11345
|
}),
|
|
11221
|
-
(0,
|
|
11346
|
+
(0, import_watermelondb5.tableSchema)({
|
|
11222
11347
|
name: "conversations",
|
|
11223
11348
|
columns: [
|
|
11224
11349
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -11290,7 +11415,7 @@ var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
|
|
|
11290
11415
|
});
|
|
11291
11416
|
|
|
11292
11417
|
// src/lib/db/chat/summaryOperations.ts
|
|
11293
|
-
var
|
|
11418
|
+
var import_watermelondb6 = require("@nozbe/watermelondb");
|
|
11294
11419
|
function createSummaryContext(database) {
|
|
11295
11420
|
return {
|
|
11296
11421
|
database,
|
|
@@ -11309,14 +11434,14 @@ function modelToStored(record2) {
|
|
|
11309
11434
|
};
|
|
11310
11435
|
}
|
|
11311
11436
|
async function getConversationSummaryOp(ctx, conversationId) {
|
|
11312
|
-
const results = await ctx.summariesCollection.query(
|
|
11437
|
+
const results = await ctx.summariesCollection.query(import_watermelondb6.Q.where("conversation_id", conversationId)).fetch();
|
|
11313
11438
|
if (results.length === 0) return null;
|
|
11314
11439
|
return modelToStored(results[0]);
|
|
11315
11440
|
}
|
|
11316
11441
|
async function upsertConversationSummaryOp(ctx, conversationId, summary, summarizedUpTo, tokenCount) {
|
|
11317
11442
|
let record2;
|
|
11318
11443
|
await ctx.database.write(async () => {
|
|
11319
|
-
const existing = await ctx.summariesCollection.query(
|
|
11444
|
+
const existing = await ctx.summariesCollection.query(import_watermelondb6.Q.where("conversation_id", conversationId)).fetch();
|
|
11320
11445
|
if (existing.length > 0) {
|
|
11321
11446
|
record2 = await existing[0].update((rec) => {
|
|
11322
11447
|
rec.summary = summary;
|
|
@@ -11336,7 +11461,7 @@ async function upsertConversationSummaryOp(ctx, conversationId, summary, summari
|
|
|
11336
11461
|
}
|
|
11337
11462
|
async function deleteConversationSummaryOp(ctx, conversationId) {
|
|
11338
11463
|
await ctx.database.write(async () => {
|
|
11339
|
-
const existing = await ctx.summariesCollection.query(
|
|
11464
|
+
const existing = await ctx.summariesCollection.query(import_watermelondb6.Q.where("conversation_id", conversationId)).fetch();
|
|
11340
11465
|
for (const record2 of existing) {
|
|
11341
11466
|
await record2.destroyPermanently();
|
|
11342
11467
|
}
|
|
@@ -11370,9 +11495,9 @@ function maskScopedEmbeddingCache(cache, masked) {
|
|
|
11370
11495
|
}
|
|
11371
11496
|
|
|
11372
11497
|
// src/lib/db/conversationMemory/models.ts
|
|
11373
|
-
var
|
|
11498
|
+
var import_watermelondb7 = require("@nozbe/watermelondb");
|
|
11374
11499
|
var import_decorators2 = require("@nozbe/watermelondb/decorators");
|
|
11375
|
-
var ConversationMemory = class extends
|
|
11500
|
+
var ConversationMemory = class extends import_watermelondb7.Model {
|
|
11376
11501
|
};
|
|
11377
11502
|
ConversationMemory.table = "conversation_memory";
|
|
11378
11503
|
ConversationMemory.associations = {};
|
|
@@ -11391,7 +11516,7 @@ __decorateClass([
|
|
|
11391
11516
|
], ConversationMemory.prototype, "createdAt", 2);
|
|
11392
11517
|
|
|
11393
11518
|
// src/lib/db/conversationMemory/operations.ts
|
|
11394
|
-
var
|
|
11519
|
+
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
11395
11520
|
var MAX_PER_CONVERSATION = 200;
|
|
11396
11521
|
function conversationMemoryToStored(row) {
|
|
11397
11522
|
return {
|
|
@@ -11406,7 +11531,7 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
11406
11531
|
if (!conversationId || items.length === 0) return;
|
|
11407
11532
|
const now = Date.now();
|
|
11408
11533
|
await ctx.database.write(async () => {
|
|
11409
|
-
const existing = await ctx.conversationMemoryCollection.query(
|
|
11534
|
+
const existing = await ctx.conversationMemoryCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId), import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.asc)).fetch();
|
|
11410
11535
|
const seen = new Set(existing.map((r) => r.memoryId));
|
|
11411
11536
|
const batchSeen = /* @__PURE__ */ new Set();
|
|
11412
11537
|
const deduped = [];
|
|
@@ -11436,13 +11561,13 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
11436
11561
|
}
|
|
11437
11562
|
async function getConversationMemoriesOp(ctx, conversationId) {
|
|
11438
11563
|
if (!conversationId) return [];
|
|
11439
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
11564
|
+
const rows = await ctx.conversationMemoryCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId), import_watermelondb8.Q.sortBy("created_at", import_watermelondb8.Q.asc)).fetch();
|
|
11440
11565
|
return rows.map(conversationMemoryToStored);
|
|
11441
11566
|
}
|
|
11442
11567
|
async function clearConversationMemoriesOp(ctx, conversationId) {
|
|
11443
11568
|
if (!conversationId) return;
|
|
11444
11569
|
await ctx.database.write(async () => {
|
|
11445
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
11570
|
+
const rows = await ctx.conversationMemoryCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId)).fetch();
|
|
11446
11571
|
if (rows.length === 0) return;
|
|
11447
11572
|
await ctx.database.batch(...rows.map((r) => r.prepareDestroyPermanently()));
|
|
11448
11573
|
});
|
|
@@ -11505,16 +11630,16 @@ function parseTopics(value) {
|
|
|
11505
11630
|
}
|
|
11506
11631
|
|
|
11507
11632
|
// src/lib/db/manager.ts
|
|
11508
|
-
var
|
|
11633
|
+
var import_watermelondb19 = require("@nozbe/watermelondb");
|
|
11509
11634
|
|
|
11510
11635
|
// src/lib/db/schema.ts
|
|
11511
|
-
var
|
|
11636
|
+
var import_watermelondb18 = require("@nozbe/watermelondb");
|
|
11512
11637
|
var import_migrations2 = require("@nozbe/watermelondb/Schema/migrations");
|
|
11513
11638
|
|
|
11514
11639
|
// src/lib/db/appFiles/models.ts
|
|
11515
|
-
var
|
|
11640
|
+
var import_watermelondb9 = require("@nozbe/watermelondb");
|
|
11516
11641
|
var import_decorators3 = require("@nozbe/watermelondb/decorators");
|
|
11517
|
-
var AppFile = class extends
|
|
11642
|
+
var AppFile = class extends import_watermelondb9.Model {
|
|
11518
11643
|
};
|
|
11519
11644
|
AppFile.table = "app_files";
|
|
11520
11645
|
AppFile.associations = {};
|
|
@@ -11536,9 +11661,9 @@ __decorateClass([
|
|
|
11536
11661
|
], AppFile.prototype, "updatedAt", 2);
|
|
11537
11662
|
|
|
11538
11663
|
// src/lib/db/entities/models.ts
|
|
11539
|
-
var
|
|
11664
|
+
var import_watermelondb10 = require("@nozbe/watermelondb");
|
|
11540
11665
|
var import_decorators4 = require("@nozbe/watermelondb/decorators");
|
|
11541
|
-
var Entity = class extends
|
|
11666
|
+
var Entity = class extends import_watermelondb10.Model {
|
|
11542
11667
|
};
|
|
11543
11668
|
Entity.table = "entity";
|
|
11544
11669
|
__decorateClass([
|
|
@@ -11554,7 +11679,7 @@ __decorateClass([
|
|
|
11554
11679
|
__decorateClass([
|
|
11555
11680
|
(0, import_decorators4.date)("updated_at")
|
|
11556
11681
|
], Entity.prototype, "updatedAt", 2);
|
|
11557
|
-
var MemoryEntity = class extends
|
|
11682
|
+
var MemoryEntity = class extends import_watermelondb10.Model {
|
|
11558
11683
|
};
|
|
11559
11684
|
MemoryEntity.table = "memory_entity";
|
|
11560
11685
|
__decorateClass([
|
|
@@ -11572,9 +11697,9 @@ __decorateClass([
|
|
|
11572
11697
|
], MemoryEntity.prototype, "createdAt", 2);
|
|
11573
11698
|
|
|
11574
11699
|
// src/lib/db/media/models.ts
|
|
11575
|
-
var
|
|
11700
|
+
var import_watermelondb11 = require("@nozbe/watermelondb");
|
|
11576
11701
|
var import_decorators5 = require("@nozbe/watermelondb/decorators");
|
|
11577
|
-
var Media = class extends
|
|
11702
|
+
var Media = class extends import_watermelondb11.Model {
|
|
11578
11703
|
};
|
|
11579
11704
|
Media.table = "media";
|
|
11580
11705
|
Media.associations = {
|
|
@@ -11635,9 +11760,9 @@ __decorateClass([
|
|
|
11635
11760
|
], Media.prototype, "isDeleted", 2);
|
|
11636
11761
|
|
|
11637
11762
|
// src/lib/db/memoryVault/models.ts
|
|
11638
|
-
var
|
|
11763
|
+
var import_watermelondb12 = require("@nozbe/watermelondb");
|
|
11639
11764
|
var import_decorators6 = require("@nozbe/watermelondb/decorators");
|
|
11640
|
-
var VaultMemory = class extends
|
|
11765
|
+
var VaultMemory = class extends import_watermelondb12.Model {
|
|
11641
11766
|
};
|
|
11642
11767
|
VaultMemory.table = "memory_vault";
|
|
11643
11768
|
__decorateClass([
|
|
@@ -11745,9 +11870,9 @@ __decorateClass([
|
|
|
11745
11870
|
], VaultMemory.prototype, "isDeleted", 2);
|
|
11746
11871
|
|
|
11747
11872
|
// src/lib/db/project/models.ts
|
|
11748
|
-
var
|
|
11873
|
+
var import_watermelondb13 = require("@nozbe/watermelondb");
|
|
11749
11874
|
var import_decorators7 = require("@nozbe/watermelondb/decorators");
|
|
11750
|
-
var Project = class extends
|
|
11875
|
+
var Project = class extends import_watermelondb13.Model {
|
|
11751
11876
|
};
|
|
11752
11877
|
Project.table = "projects";
|
|
11753
11878
|
Project.associations = {
|
|
@@ -11770,10 +11895,10 @@ __decorateClass([
|
|
|
11770
11895
|
], Project.prototype, "isDeleted", 2);
|
|
11771
11896
|
|
|
11772
11897
|
// src/lib/db/savedTools/models.ts
|
|
11773
|
-
var
|
|
11898
|
+
var import_watermelondb14 = require("@nozbe/watermelondb");
|
|
11774
11899
|
var import_decorators8 = require("@nozbe/watermelondb/decorators");
|
|
11775
11900
|
var sanitizeParameters = (raw) => raw ?? {};
|
|
11776
|
-
var SavedTool = class extends
|
|
11901
|
+
var SavedTool = class extends import_watermelondb14.Model {
|
|
11777
11902
|
};
|
|
11778
11903
|
SavedTool.table = "saved_tools";
|
|
11779
11904
|
SavedTool.associations = {};
|
|
@@ -11807,9 +11932,9 @@ __decorateClass([
|
|
|
11807
11932
|
], SavedTool.prototype, "isDeleted", 2);
|
|
11808
11933
|
|
|
11809
11934
|
// src/lib/db/settings/models.ts
|
|
11810
|
-
var
|
|
11935
|
+
var import_watermelondb15 = require("@nozbe/watermelondb");
|
|
11811
11936
|
var import_decorators9 = require("@nozbe/watermelondb/decorators");
|
|
11812
|
-
var ModelPreference = class extends
|
|
11937
|
+
var ModelPreference = class extends import_watermelondb15.Model {
|
|
11813
11938
|
};
|
|
11814
11939
|
ModelPreference.table = "modelPreferences";
|
|
11815
11940
|
__decorateClass([
|
|
@@ -11820,9 +11945,9 @@ __decorateClass([
|
|
|
11820
11945
|
], ModelPreference.prototype, "models", 2);
|
|
11821
11946
|
|
|
11822
11947
|
// src/lib/db/userPreferences/models.ts
|
|
11823
|
-
var
|
|
11948
|
+
var import_watermelondb16 = require("@nozbe/watermelondb");
|
|
11824
11949
|
var import_decorators10 = require("@nozbe/watermelondb/decorators");
|
|
11825
|
-
var UserPreference = class extends
|
|
11950
|
+
var UserPreference = class extends import_watermelondb16.Model {
|
|
11826
11951
|
};
|
|
11827
11952
|
UserPreference.table = "userPreferences";
|
|
11828
11953
|
__decorateClass([
|
|
@@ -11843,6 +11968,9 @@ __decorateClass([
|
|
|
11843
11968
|
__decorateClass([
|
|
11844
11969
|
(0, import_decorators10.text)("personality")
|
|
11845
11970
|
], UserPreference.prototype, "personality", 2);
|
|
11971
|
+
__decorateClass([
|
|
11972
|
+
(0, import_decorators10.text)("external_wallets")
|
|
11973
|
+
], UserPreference.prototype, "externalWallets", 2);
|
|
11846
11974
|
__decorateClass([
|
|
11847
11975
|
(0, import_decorators10.field)("created_at")
|
|
11848
11976
|
], UserPreference.prototype, "createdAt", 2);
|
|
@@ -11851,9 +11979,9 @@ __decorateClass([
|
|
|
11851
11979
|
], UserPreference.prototype, "updatedAt", 2);
|
|
11852
11980
|
|
|
11853
11981
|
// src/lib/db/vaultFolders/models.ts
|
|
11854
|
-
var
|
|
11982
|
+
var import_watermelondb17 = require("@nozbe/watermelondb");
|
|
11855
11983
|
var import_decorators11 = require("@nozbe/watermelondb/decorators");
|
|
11856
|
-
var VaultFolder = class extends
|
|
11984
|
+
var VaultFolder = class extends import_watermelondb17.Model {
|
|
11857
11985
|
};
|
|
11858
11986
|
VaultFolder.table = "vault_folders";
|
|
11859
11987
|
__decorateClass([
|
|
@@ -11880,11 +12008,11 @@ __decorateClass([
|
|
|
11880
12008
|
], VaultFolder.prototype, "context", 2);
|
|
11881
12009
|
|
|
11882
12010
|
// src/lib/db/schema.ts
|
|
11883
|
-
var SDK_SCHEMA_VERSION =
|
|
11884
|
-
var sdkSchema = (0,
|
|
12011
|
+
var SDK_SCHEMA_VERSION = 49;
|
|
12012
|
+
var sdkSchema = (0, import_watermelondb18.appSchema)({
|
|
11885
12013
|
version: SDK_SCHEMA_VERSION,
|
|
11886
12014
|
tables: [
|
|
11887
|
-
(0,
|
|
12015
|
+
(0, import_watermelondb18.tableSchema)({
|
|
11888
12016
|
name: "memory_extraction_jobs",
|
|
11889
12017
|
columns: [
|
|
11890
12018
|
{ name: "owner_key", type: "string", isIndexed: true },
|
|
@@ -11899,7 +12027,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
11899
12027
|
{ name: "failed_at", type: "number", isOptional: true }
|
|
11900
12028
|
]
|
|
11901
12029
|
}),
|
|
11902
|
-
(0,
|
|
12030
|
+
(0, import_watermelondb18.tableSchema)({
|
|
11903
12031
|
name: "history",
|
|
11904
12032
|
columns: [
|
|
11905
12033
|
{ name: "message_id", type: "number" },
|
|
@@ -11928,7 +12056,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
11928
12056
|
{ name: "origin", type: "string", isOptional: true }
|
|
11929
12057
|
]
|
|
11930
12058
|
}),
|
|
11931
|
-
(0,
|
|
12059
|
+
(0, import_watermelondb18.tableSchema)({
|
|
11932
12060
|
name: "conversations",
|
|
11933
12061
|
columns: [
|
|
11934
12062
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -11940,7 +12068,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
11940
12068
|
{ name: "pinned_at", type: "number", isOptional: true }
|
|
11941
12069
|
]
|
|
11942
12070
|
}),
|
|
11943
|
-
(0,
|
|
12071
|
+
(0, import_watermelondb18.tableSchema)({
|
|
11944
12072
|
name: "projects",
|
|
11945
12073
|
columns: [
|
|
11946
12074
|
{ name: "project_id", type: "string", isIndexed: true },
|
|
@@ -11950,14 +12078,14 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
11950
12078
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
11951
12079
|
]
|
|
11952
12080
|
}),
|
|
11953
|
-
(0,
|
|
12081
|
+
(0, import_watermelondb18.tableSchema)({
|
|
11954
12082
|
name: "modelPreferences",
|
|
11955
12083
|
columns: [
|
|
11956
12084
|
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
11957
12085
|
{ name: "models", type: "string", isOptional: true }
|
|
11958
12086
|
]
|
|
11959
12087
|
}),
|
|
11960
|
-
(0,
|
|
12088
|
+
(0, import_watermelondb18.tableSchema)({
|
|
11961
12089
|
name: "userPreferences",
|
|
11962
12090
|
columns: [
|
|
11963
12091
|
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
@@ -11966,11 +12094,12 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
11966
12094
|
{ name: "description", type: "string", isOptional: true },
|
|
11967
12095
|
{ name: "models", type: "string", isOptional: true },
|
|
11968
12096
|
{ name: "personality", type: "string", isOptional: true },
|
|
12097
|
+
{ name: "external_wallets", type: "string", isOptional: true },
|
|
11969
12098
|
{ name: "created_at", type: "number" },
|
|
11970
12099
|
{ name: "updated_at", type: "number" }
|
|
11971
12100
|
]
|
|
11972
12101
|
}),
|
|
11973
|
-
(0,
|
|
12102
|
+
(0, import_watermelondb18.tableSchema)({
|
|
11974
12103
|
name: "memory_vault",
|
|
11975
12104
|
columns: [
|
|
11976
12105
|
{ name: "content", type: "string" },
|
|
@@ -12009,7 +12138,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
12009
12138
|
{ name: "geohash", type: "string", isOptional: true }
|
|
12010
12139
|
]
|
|
12011
12140
|
}),
|
|
12012
|
-
(0,
|
|
12141
|
+
(0, import_watermelondb18.tableSchema)({
|
|
12013
12142
|
name: "entity",
|
|
12014
12143
|
columns: [
|
|
12015
12144
|
{ name: "canonical_name", type: "string", isIndexed: true },
|
|
@@ -12018,7 +12147,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
12018
12147
|
{ name: "updated_at", type: "number" }
|
|
12019
12148
|
]
|
|
12020
12149
|
}),
|
|
12021
|
-
(0,
|
|
12150
|
+
(0, import_watermelondb18.tableSchema)({
|
|
12022
12151
|
name: "memory_entity",
|
|
12023
12152
|
columns: [
|
|
12024
12153
|
{ name: "memory_id", type: "string", isIndexed: true },
|
|
@@ -12027,7 +12156,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
12027
12156
|
{ name: "created_at", type: "number" }
|
|
12028
12157
|
]
|
|
12029
12158
|
}),
|
|
12030
|
-
(0,
|
|
12159
|
+
(0, import_watermelondb18.tableSchema)({
|
|
12031
12160
|
name: "vault_folders",
|
|
12032
12161
|
columns: [
|
|
12033
12162
|
{ name: "name", type: "string" },
|
|
@@ -12039,7 +12168,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
12039
12168
|
{ name: "context", type: "string", isOptional: true }
|
|
12040
12169
|
]
|
|
12041
12170
|
}),
|
|
12042
|
-
(0,
|
|
12171
|
+
(0, import_watermelondb18.tableSchema)({
|
|
12043
12172
|
name: "conversation_summaries",
|
|
12044
12173
|
columns: [
|
|
12045
12174
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -12050,7 +12179,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
12050
12179
|
{ name: "updated_at", type: "number" }
|
|
12051
12180
|
]
|
|
12052
12181
|
}),
|
|
12053
|
-
(0,
|
|
12182
|
+
(0, import_watermelondb18.tableSchema)({
|
|
12054
12183
|
name: "media",
|
|
12055
12184
|
columns: [
|
|
12056
12185
|
{ name: "media_id", type: "string", isIndexed: true },
|
|
@@ -12072,7 +12201,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
12072
12201
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
12073
12202
|
]
|
|
12074
12203
|
}),
|
|
12075
|
-
(0,
|
|
12204
|
+
(0, import_watermelondb18.tableSchema)({
|
|
12076
12205
|
name: "app_files",
|
|
12077
12206
|
columns: [
|
|
12078
12207
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -12082,7 +12211,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
12082
12211
|
{ name: "updated_at", type: "number" }
|
|
12083
12212
|
]
|
|
12084
12213
|
}),
|
|
12085
|
-
(0,
|
|
12214
|
+
(0, import_watermelondb18.tableSchema)({
|
|
12086
12215
|
name: "saved_tools",
|
|
12087
12216
|
columns: [
|
|
12088
12217
|
{ name: "name", type: "string" },
|
|
@@ -12096,7 +12225,7 @@ var sdkSchema = (0, import_watermelondb17.appSchema)({
|
|
|
12096
12225
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
12097
12226
|
]
|
|
12098
12227
|
}),
|
|
12099
|
-
(0,
|
|
12228
|
+
(0, import_watermelondb18.tableSchema)({
|
|
12100
12229
|
name: "conversation_memory",
|
|
12101
12230
|
columns: [
|
|
12102
12231
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -12670,6 +12799,15 @@ var sdkMigrations = (0, import_migrations2.schemaMigrations)({
|
|
|
12670
12799
|
"UPDATE memory_vault SET level = CASE WHEN scope IN ('shared', 'public') THEN 'matching' ELSE 'private' END WHERE level IS NULL;"
|
|
12671
12800
|
)
|
|
12672
12801
|
]
|
|
12802
|
+
},
|
|
12803
|
+
{
|
|
12804
|
+
toVersion: 49,
|
|
12805
|
+
steps: [
|
|
12806
|
+
(0, import_migrations2.addColumns)({
|
|
12807
|
+
table: "userPreferences",
|
|
12808
|
+
columns: [{ name: "external_wallets", type: "string", isOptional: true }]
|
|
12809
|
+
})
|
|
12810
|
+
]
|
|
12673
12811
|
}
|
|
12674
12812
|
]
|
|
12675
12813
|
});
|
|
@@ -12772,7 +12910,7 @@ var DatabaseManager = class {
|
|
|
12772
12910
|
walletAddress
|
|
12773
12911
|
});
|
|
12774
12912
|
const adapter = this.createAdapter(dbName, sdkSchema, sdkMigrations);
|
|
12775
|
-
const database = new
|
|
12913
|
+
const database = new import_watermelondb19.Database({
|
|
12776
12914
|
adapter,
|
|
12777
12915
|
modelClasses: sdkModelClasses
|
|
12778
12916
|
});
|
|
@@ -12851,11 +12989,11 @@ var DatabaseManager = class {
|
|
|
12851
12989
|
};
|
|
12852
12990
|
|
|
12853
12991
|
// src/lib/db/memoryVault/operations.ts
|
|
12854
|
-
var
|
|
12992
|
+
var import_watermelondb21 = require("@nozbe/watermelondb");
|
|
12855
12993
|
init_logger();
|
|
12856
12994
|
|
|
12857
12995
|
// src/lib/db/entities/operations.ts
|
|
12858
|
-
var
|
|
12996
|
+
var import_watermelondb20 = require("@nozbe/watermelondb");
|
|
12859
12997
|
|
|
12860
12998
|
// src/lib/db/memoryVault/types.ts
|
|
12861
12999
|
var MEMORY_KINDS = [
|
|
@@ -12948,7 +13086,7 @@ async function upsertEntitiesInWrite(ctx, entities) {
|
|
|
12948
13086
|
const unique = Array.from(kindByName.keys());
|
|
12949
13087
|
const out = /* @__PURE__ */ new Map();
|
|
12950
13088
|
if (unique.length === 0) return { entities: out, operations: [], kindBackfills: [] };
|
|
12951
|
-
const existing = await ctx.entityCollection.query(
|
|
13089
|
+
const existing = await ctx.entityCollection.query(import_watermelondb20.Q.where("canonical_name", import_watermelondb20.Q.oneOf(unique))).fetch();
|
|
12952
13090
|
const existingNames = new Set(existing.map((e) => e.canonicalName));
|
|
12953
13091
|
const kindBackfills = existing.filter((e) => {
|
|
12954
13092
|
const incoming = kindByName.get(e.canonicalName);
|
|
@@ -12978,7 +13116,7 @@ function prepareKindBackfills(backfills) {
|
|
|
12978
13116
|
}
|
|
12979
13117
|
async function findVaultRowInWrite(ctx, memoryId) {
|
|
12980
13118
|
try {
|
|
12981
|
-
const rows = await ctx.database.get("memory_vault").query(
|
|
13119
|
+
const rows = await ctx.database.get("memory_vault").query(import_watermelondb20.Q.where("id", memoryId)).fetch();
|
|
12982
13120
|
return rows[0] ?? null;
|
|
12983
13121
|
} catch {
|
|
12984
13122
|
return null;
|
|
@@ -13080,7 +13218,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
13080
13218
|
return;
|
|
13081
13219
|
}
|
|
13082
13220
|
if (entities.length === 0) return;
|
|
13083
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
13221
|
+
const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb20.Q.where("memory_id", memoryId)).fetch();
|
|
13084
13222
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
13085
13223
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
13086
13224
|
const keptIds = entities.map((e) => e.uniqueId);
|
|
@@ -13116,7 +13254,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
13116
13254
|
}
|
|
13117
13255
|
async function resolveEntitiesByIds(ctx, entityIds) {
|
|
13118
13256
|
if (entityIds.length === 0) return [];
|
|
13119
|
-
const rows = await ctx.entityCollection.query(
|
|
13257
|
+
const rows = await ctx.entityCollection.query(import_watermelondb20.Q.where("id", import_watermelondb20.Q.oneOf(Array.from(entityIds)))).fetch();
|
|
13120
13258
|
return rows.map(entityToStored);
|
|
13121
13259
|
}
|
|
13122
13260
|
function autoLinkBlocked(row) {
|
|
@@ -13152,7 +13290,7 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
13152
13290
|
kindBackfills
|
|
13153
13291
|
} = await upsertEntitiesInWrite(ctx, normalized);
|
|
13154
13292
|
entities = Array.from(byName.values());
|
|
13155
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
13293
|
+
const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb20.Q.where("memory_id", memoryId)).fetch();
|
|
13156
13294
|
const keep = new Set(entities.map((e) => e.uniqueId));
|
|
13157
13295
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
13158
13296
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
@@ -13188,17 +13326,17 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
13188
13326
|
async function findOrphanedEntities(ctx, memoryId, toDestroy) {
|
|
13189
13327
|
const candidateIds = [...new Set(toDestroy.map((l) => String(l.entityId)))];
|
|
13190
13328
|
if (candidateIds.length === 0) return [];
|
|
13191
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
13329
|
+
const links = await ctx.memoryEntityCollection.query(import_watermelondb20.Q.where("entity_id", import_watermelondb20.Q.oneOf(candidateIds))).fetch();
|
|
13192
13330
|
const stillLinked = new Set(
|
|
13193
13331
|
links.filter((l) => String(l.memoryId) !== memoryId).map((l) => String(l.entityId))
|
|
13194
13332
|
);
|
|
13195
13333
|
const orphanIds = candidateIds.filter((id) => !stillLinked.has(id));
|
|
13196
13334
|
if (orphanIds.length === 0) return [];
|
|
13197
|
-
return await ctx.entityCollection.query(
|
|
13335
|
+
return await ctx.entityCollection.query(import_watermelondb20.Q.where("id", import_watermelondb20.Q.oneOf(orphanIds))).fetch();
|
|
13198
13336
|
}
|
|
13199
13337
|
async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
13200
13338
|
if (memoryIds.length === 0) return;
|
|
13201
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
13339
|
+
const links = await ctx.memoryEntityCollection.query(import_watermelondb20.Q.where("memory_id", import_watermelondb20.Q.oneOf(Array.from(memoryIds)))).fetch();
|
|
13202
13340
|
if (links.length === 0) return;
|
|
13203
13341
|
await ctx.database.write(async () => {
|
|
13204
13342
|
await assertCanWrite(ctx);
|
|
@@ -13207,7 +13345,7 @@ async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
|
13207
13345
|
}
|
|
13208
13346
|
async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
13209
13347
|
if (!userId) return;
|
|
13210
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
13348
|
+
const links = await ctx.memoryEntityCollection.query(import_watermelondb20.Q.where("user_id", userId)).fetch();
|
|
13211
13349
|
if (links.length === 0) return;
|
|
13212
13350
|
await ctx.database.write(async () => {
|
|
13213
13351
|
await assertCanWrite(ctx);
|
|
@@ -13217,15 +13355,15 @@ async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
|
13217
13355
|
async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
13218
13356
|
const unique = Array.from(new Set(entityNames.map(normalizeEntityName).filter((n) => n.length > 0)));
|
|
13219
13357
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
13220
|
-
const entityRows = await ctx.entityCollection.query(
|
|
13358
|
+
const entityRows = await ctx.entityCollection.query(import_watermelondb20.Q.where("canonical_name", import_watermelondb20.Q.oneOf(unique))).fetch();
|
|
13221
13359
|
if (entityRows.length === 0) return /* @__PURE__ */ new Map();
|
|
13222
13360
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
13223
|
-
const linkConditions = [
|
|
13361
|
+
const linkConditions = [import_watermelondb20.Q.where("entity_id", import_watermelondb20.Q.oneOf(entityRows.map((e) => e.id)))];
|
|
13224
13362
|
if (ctx.userId !== void 0) {
|
|
13225
13363
|
if (ctx.allowUnscopedRows) {
|
|
13226
|
-
linkConditions.push(
|
|
13364
|
+
linkConditions.push(import_watermelondb20.Q.or(import_watermelondb20.Q.where("user_id", ctx.userId), import_watermelondb20.Q.where("user_id", null)));
|
|
13227
13365
|
} else {
|
|
13228
|
-
linkConditions.push(
|
|
13366
|
+
linkConditions.push(import_watermelondb20.Q.where("user_id", ctx.userId));
|
|
13229
13367
|
}
|
|
13230
13368
|
}
|
|
13231
13369
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
@@ -13246,18 +13384,18 @@ async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
|
13246
13384
|
async function getEntitiesByMemoryIdsOp(ctx, memoryIds) {
|
|
13247
13385
|
const unique = Array.from(new Set(memoryIds.filter((id) => id.length > 0)));
|
|
13248
13386
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
13249
|
-
const linkConditions = [
|
|
13387
|
+
const linkConditions = [import_watermelondb20.Q.where("memory_id", import_watermelondb20.Q.oneOf(unique))];
|
|
13250
13388
|
if (ctx.userId !== void 0) {
|
|
13251
13389
|
if (ctx.allowUnscopedRows) {
|
|
13252
|
-
linkConditions.push(
|
|
13390
|
+
linkConditions.push(import_watermelondb20.Q.or(import_watermelondb20.Q.where("user_id", ctx.userId), import_watermelondb20.Q.where("user_id", null)));
|
|
13253
13391
|
} else {
|
|
13254
|
-
linkConditions.push(
|
|
13392
|
+
linkConditions.push(import_watermelondb20.Q.where("user_id", ctx.userId));
|
|
13255
13393
|
}
|
|
13256
13394
|
}
|
|
13257
13395
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
13258
13396
|
if (links.length === 0) return /* @__PURE__ */ new Map();
|
|
13259
13397
|
const entityIds = Array.from(new Set(links.map((l) => String(l.entityId))));
|
|
13260
|
-
const entityRows = await ctx.entityCollection.query(
|
|
13398
|
+
const entityRows = await ctx.entityCollection.query(import_watermelondb20.Q.where("id", import_watermelondb20.Q.oneOf(entityIds))).fetch();
|
|
13261
13399
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
13262
13400
|
const out = /* @__PURE__ */ new Map();
|
|
13263
13401
|
for (const link of links) {
|
|
@@ -13322,11 +13460,11 @@ var NON_PRIVATE_VISIBILITIES = ["public"];
|
|
|
13322
13460
|
function visibilityConditions(requested) {
|
|
13323
13461
|
if (!requested?.length) return [];
|
|
13324
13462
|
if (!requested.includes("private")) {
|
|
13325
|
-
return [
|
|
13463
|
+
return [import_watermelondb21.Q.where("visibility", import_watermelondb21.Q.oneOf([...requested]))];
|
|
13326
13464
|
}
|
|
13327
13465
|
const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
|
|
13328
13466
|
if (excluded.length === 0) return [];
|
|
13329
|
-
return [
|
|
13467
|
+
return [import_watermelondb21.Q.or(import_watermelondb21.Q.where("visibility", null), import_watermelondb21.Q.where("visibility", import_watermelondb21.Q.notIn(excluded)))];
|
|
13330
13468
|
}
|
|
13331
13469
|
function isKinded(record2) {
|
|
13332
13470
|
return record2.kind !== null && record2.kind !== void 0;
|
|
@@ -13367,17 +13505,17 @@ function levelConditions(requested) {
|
|
|
13367
13505
|
const published = ["shared", "public"];
|
|
13368
13506
|
const wantsMatching = requested.includes("matching");
|
|
13369
13507
|
const wantsPrivate = requested.includes("private");
|
|
13370
|
-
const unresolved =
|
|
13371
|
-
const byLevel =
|
|
13372
|
-
if (wantsMatching && wantsPrivate) return [
|
|
13508
|
+
const unresolved = import_watermelondb21.Q.or(import_watermelondb21.Q.where("level", null), import_watermelondb21.Q.where("level", import_watermelondb21.Q.notIn([...MEMORY_LEVELS])));
|
|
13509
|
+
const byLevel = import_watermelondb21.Q.where("level", import_watermelondb21.Q.oneOf([...requested]));
|
|
13510
|
+
if (wantsMatching && wantsPrivate) return [import_watermelondb21.Q.or(byLevel, unresolved)];
|
|
13373
13511
|
if (wantsMatching) {
|
|
13374
|
-
return [
|
|
13512
|
+
return [import_watermelondb21.Q.or(byLevel, import_watermelondb21.Q.and(unresolved, import_watermelondb21.Q.where("scope", import_watermelondb21.Q.oneOf(published))))];
|
|
13375
13513
|
}
|
|
13376
13514
|
if (wantsPrivate) {
|
|
13377
13515
|
return [
|
|
13378
|
-
|
|
13516
|
+
import_watermelondb21.Q.or(
|
|
13379
13517
|
byLevel,
|
|
13380
|
-
|
|
13518
|
+
import_watermelondb21.Q.and(unresolved, import_watermelondb21.Q.or(import_watermelondb21.Q.where("scope", null), import_watermelondb21.Q.where("scope", import_watermelondb21.Q.notIn(published))))
|
|
13381
13519
|
)
|
|
13382
13520
|
];
|
|
13383
13521
|
}
|
|
@@ -13388,13 +13526,13 @@ function isOwnedByCtxUser(ctx, record2) {
|
|
|
13388
13526
|
}
|
|
13389
13527
|
function baseVaultConditions(ctx, options) {
|
|
13390
13528
|
return [
|
|
13391
|
-
...options?.memoryIds !== void 0 ? [
|
|
13392
|
-
...options?.includeDeleted ? [] : [
|
|
13393
|
-
...options?.includeArchived ? [] : [
|
|
13394
|
-
...options?.includeQuarantined ? [] : [
|
|
13395
|
-
...options?.includeSuperseded ? [] : [
|
|
13396
|
-
...ctx.userId !== void 0 ? [
|
|
13397
|
-
...options?.since ? [
|
|
13529
|
+
...options?.memoryIds !== void 0 ? [import_watermelondb21.Q.where("id", import_watermelondb21.Q.oneOf(options.memoryIds))] : [],
|
|
13530
|
+
...options?.includeDeleted ? [] : [import_watermelondb21.Q.where("is_deleted", false)],
|
|
13531
|
+
...options?.includeArchived ? [] : [import_watermelondb21.Q.where("archived_at", import_watermelondb21.Q.eq(null))],
|
|
13532
|
+
...options?.includeQuarantined ? [] : [import_watermelondb21.Q.where("trust_tier", import_watermelondb21.Q.notEq("quarantined"))],
|
|
13533
|
+
...options?.includeSuperseded ? [] : [import_watermelondb21.Q.where("superseded_by", null)],
|
|
13534
|
+
...ctx.userId !== void 0 ? [import_watermelondb21.Q.where("user_id", ctx.userId)] : [],
|
|
13535
|
+
...options?.since ? [import_watermelondb21.Q.where("updated_at", import_watermelondb21.Q.gt(options.since.getTime()))] : []
|
|
13398
13536
|
];
|
|
13399
13537
|
}
|
|
13400
13538
|
var KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
|
|
@@ -13564,11 +13702,11 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
13564
13702
|
async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
|
|
13565
13703
|
const records = await ctx.vaultMemoryCollection.query(
|
|
13566
13704
|
...baseVaultConditions(ctx),
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13705
|
+
import_watermelondb21.Q.where("event_time_start", import_watermelondb21.Q.notEq(null)),
|
|
13706
|
+
import_watermelondb21.Q.where("event_time_start", import_watermelondb21.Q.lte(windowEnd)),
|
|
13707
|
+
import_watermelondb21.Q.or(
|
|
13708
|
+
import_watermelondb21.Q.where("event_time_start", import_watermelondb21.Q.gte(windowStart)),
|
|
13709
|
+
import_watermelondb21.Q.where("event_time_kind", import_watermelondb21.Q.oneOf(["range", "ongoing"]))
|
|
13572
13710
|
)
|
|
13573
13711
|
).fetch();
|
|
13574
13712
|
const out = [];
|
|
@@ -13724,18 +13862,18 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
13724
13862
|
function vaultListConditions(ctx, options) {
|
|
13725
13863
|
return [
|
|
13726
13864
|
...baseVaultConditions(ctx, options),
|
|
13727
|
-
...options?.scopes?.length ? [
|
|
13865
|
+
...options?.scopes?.length ? [import_watermelondb21.Q.where("scope", import_watermelondb21.Q.oneOf(options.scopes))] : [],
|
|
13728
13866
|
...visibilityConditions(options?.visibility),
|
|
13729
13867
|
...levelConditions(options?.levels),
|
|
13730
|
-
...options?.kinds?.length ? [
|
|
13731
|
-
...options?.folderId !== void 0 ? [
|
|
13732
|
-
...options?.factTypes?.length ? [
|
|
13868
|
+
...options?.kinds?.length ? [import_watermelondb21.Q.where("kind", import_watermelondb21.Q.oneOf(options.kinds))] : [],
|
|
13869
|
+
...options?.folderId !== void 0 ? [import_watermelondb21.Q.where("folder_id", options.folderId)] : [],
|
|
13870
|
+
...options?.factTypes?.length ? [import_watermelondb21.Q.where("fact_type", import_watermelondb21.Q.oneOf(options.factTypes))] : []
|
|
13733
13871
|
];
|
|
13734
13872
|
}
|
|
13735
13873
|
function vaultListOrder(options) {
|
|
13736
13874
|
return [
|
|
13737
|
-
|
|
13738
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
13875
|
+
import_watermelondb21.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb21.Q.desc),
|
|
13876
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb21.Q.take(options.limit)] : []
|
|
13739
13877
|
];
|
|
13740
13878
|
}
|
|
13741
13879
|
async function getAllVaultMemoryRowsOp(ctx) {
|
|
@@ -13774,10 +13912,10 @@ function vaultMemoryRawToRankable(raw) {
|
|
|
13774
13912
|
async function getVaultRankingProjectionsOp(ctx, options) {
|
|
13775
13913
|
const conditions = [
|
|
13776
13914
|
...baseVaultConditions(ctx, options),
|
|
13777
|
-
...options?.scopes?.length ? [
|
|
13778
|
-
...options?.folderId !== void 0 ? [
|
|
13779
|
-
|
|
13780
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
13915
|
+
...options?.scopes?.length ? [import_watermelondb21.Q.where("scope", import_watermelondb21.Q.oneOf(options.scopes))] : [],
|
|
13916
|
+
...options?.folderId !== void 0 ? [import_watermelondb21.Q.where("folder_id", options.folderId)] : [],
|
|
13917
|
+
import_watermelondb21.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb21.Q.desc),
|
|
13918
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb21.Q.take(options.limit)] : []
|
|
13781
13919
|
];
|
|
13782
13920
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
13783
13921
|
return results.map(vaultMemoryRawToRankable);
|
|
@@ -13828,7 +13966,7 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
13828
13966
|
args.push(...options.factTypes);
|
|
13829
13967
|
}
|
|
13830
13968
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
13831
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
13969
|
+
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb21.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
13832
13970
|
return rows.map(mapRaw);
|
|
13833
13971
|
} catch (err) {
|
|
13834
13972
|
getLogger().debug(
|
|
@@ -13839,9 +13977,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
13839
13977
|
memoryIds: options?.memoryIds,
|
|
13840
13978
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
13841
13979
|
}),
|
|
13842
|
-
...options?.scopes?.length ? [
|
|
13843
|
-
...options?.folderId !== void 0 ? [
|
|
13844
|
-
...options?.factTypes?.length ? [
|
|
13980
|
+
...options?.scopes?.length ? [import_watermelondb21.Q.where("scope", import_watermelondb21.Q.oneOf(options.scopes))] : [],
|
|
13981
|
+
...options?.folderId !== void 0 ? [import_watermelondb21.Q.where("folder_id", options.folderId)] : [],
|
|
13982
|
+
...options?.factTypes?.length ? [import_watermelondb21.Q.where("fact_type", import_watermelondb21.Q.oneOf(options.factTypes))] : []
|
|
13845
13983
|
];
|
|
13846
13984
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
13847
13985
|
return rows.map(mapRaw);
|
|
@@ -13859,7 +13997,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
13859
13997
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
13860
13998
|
});
|
|
13861
13999
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
13862
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
14000
|
+
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb21.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
13863
14001
|
return rows.map(mapRaw);
|
|
13864
14002
|
} catch (err) {
|
|
13865
14003
|
getLogger().debug(
|
|
@@ -13871,7 +14009,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
13871
14009
|
includeArchived: options.includeArchived
|
|
13872
14010
|
}
|
|
13873
14011
|
}),
|
|
13874
|
-
|
|
14012
|
+
import_watermelondb21.Q.where("id", import_watermelondb21.Q.oneOf(ids))
|
|
13875
14013
|
).unsafeFetchRaw();
|
|
13876
14014
|
return rows.map(mapRaw);
|
|
13877
14015
|
}
|
|
@@ -13882,7 +14020,7 @@ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
|
13882
14020
|
...baseVaultConditions(ctx, {
|
|
13883
14021
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
13884
14022
|
}),
|
|
13885
|
-
|
|
14023
|
+
import_watermelondb21.Q.where("id", import_watermelondb21.Q.oneOf(ids))
|
|
13886
14024
|
];
|
|
13887
14025
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
13888
14026
|
return mapInBatches(
|
|
@@ -13907,7 +14045,7 @@ async function countActiveVaultMemoriesOp(ctx) {
|
|
|
13907
14045
|
}
|
|
13908
14046
|
async function getActiveVaultMemoryIdsOp(ctx, ids) {
|
|
13909
14047
|
if (ids.length === 0) return /* @__PURE__ */ new Set();
|
|
13910
|
-
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx),
|
|
14048
|
+
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb21.Q.where("id", import_watermelondb21.Q.oneOf(ids))).unsafeFetchRaw();
|
|
13911
14049
|
return new Set(rows.map((r) => r.id));
|
|
13912
14050
|
}
|
|
13913
14051
|
async function updateVaultMemoryOp(ctx, id, opts) {
|
|
@@ -14056,7 +14194,7 @@ async function setMemoryEntitiesOp(ctx, memoryId, entities) {
|
|
|
14056
14194
|
() => linkMemoryEntitiesOp(entityCtx, memoryId, entities, { topicsSource: "user" })
|
|
14057
14195
|
) : [];
|
|
14058
14196
|
const keep = new Set(linked.map((e) => e.uniqueId));
|
|
14059
|
-
const existing = await entityCtx.memoryEntityCollection.query(
|
|
14197
|
+
const existing = await entityCtx.memoryEntityCollection.query(import_watermelondb21.Q.where("memory_id", memoryId)).fetch();
|
|
14060
14198
|
const staleLinks = existing.filter((l) => !keep.has(String(l.entityId)));
|
|
14061
14199
|
if (staleLinks.length === 0 && entities.length > 0) return;
|
|
14062
14200
|
const topicsWrite = await resolveMemoryTopicsWrite(
|
|
@@ -14197,9 +14335,9 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
14197
14335
|
}
|
|
14198
14336
|
async function getUnfiledVaultMemoriesOp(ctx) {
|
|
14199
14337
|
const conditions = [
|
|
14200
|
-
|
|
14338
|
+
import_watermelondb21.Q.where("folder_id", null),
|
|
14201
14339
|
...baseVaultConditions(ctx),
|
|
14202
|
-
|
|
14340
|
+
import_watermelondb21.Q.sortBy("created_at", import_watermelondb21.Q.desc)
|
|
14203
14341
|
];
|
|
14204
14342
|
const results = await ctx.vaultMemoryCollection.query(...conditions).fetch();
|
|
14205
14343
|
return mapInBatches(
|
|
@@ -14213,7 +14351,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
14213
14351
|
const entityIdByMemory = /* @__PURE__ */ new Map();
|
|
14214
14352
|
const allEntityIds = /* @__PURE__ */ new Set();
|
|
14215
14353
|
for (let i = 0; i < memoryIds.length; i += CHUNK) {
|
|
14216
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
14354
|
+
const links = await entityCtx.memoryEntityCollection.query(import_watermelondb21.Q.where("memory_id", import_watermelondb21.Q.oneOf(memoryIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
14217
14355
|
for (const link of links) {
|
|
14218
14356
|
const memoryId = String(link.memory_id);
|
|
14219
14357
|
const entityId = String(link.entity_id);
|
|
@@ -14229,7 +14367,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
14229
14367
|
const entityIds = Array.from(allEntityIds);
|
|
14230
14368
|
const nameById = /* @__PURE__ */ new Map();
|
|
14231
14369
|
for (let i = 0; i < entityIds.length; i += CHUNK) {
|
|
14232
|
-
const entities = await entityCtx.entityCollection.query(
|
|
14370
|
+
const entities = await entityCtx.entityCollection.query(import_watermelondb21.Q.where("id", import_watermelondb21.Q.oneOf(entityIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
14233
14371
|
for (const e of entities) {
|
|
14234
14372
|
if (typeof e.canonical_name === "string") nameById.set(String(e.id), e.canonical_name);
|
|
14235
14373
|
}
|
|
@@ -14258,7 +14396,7 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
|
|
|
14258
14396
|
if (!entityCtx) {
|
|
14259
14397
|
throw new Error("getMemoriesNeedingTopicExtractionOp requires ctx.entityCtx");
|
|
14260
14398
|
}
|
|
14261
|
-
const conditions = [...baseVaultConditions(ctx),
|
|
14399
|
+
const conditions = [...baseVaultConditions(ctx), import_watermelondb21.Q.sortBy("created_at", import_watermelondb21.Q.desc)];
|
|
14262
14400
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
14263
14401
|
const linkedNames = await linkedEntityNamesByMemory(
|
|
14264
14402
|
entityCtx,
|
|
@@ -14414,10 +14552,10 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
14414
14552
|
}
|
|
14415
14553
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) continue;
|
|
14416
14554
|
if (parseTopics(record2.topics) !== null) continue;
|
|
14417
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
14555
|
+
const links = await entityCtx.memoryEntityCollection.query(import_watermelondb21.Q.where("memory_id", id)).unsafeFetchRaw();
|
|
14418
14556
|
const entityIds = links.map((l) => String(l.entity_id));
|
|
14419
14557
|
if (entityIds.length === 0) continue;
|
|
14420
|
-
const entities = await entityCtx.entityCollection.query(
|
|
14558
|
+
const entities = await entityCtx.entityCollection.query(import_watermelondb21.Q.where("id", import_watermelondb21.Q.oneOf(entityIds))).fetch();
|
|
14421
14559
|
if (entities.length === 0) continue;
|
|
14422
14560
|
const source = record2.topicsUserManaged ? "user" : "auto";
|
|
14423
14561
|
const write = await resolveMemoryTopicsWrite(entityCtx, id, entities, [], source);
|
|
@@ -14433,7 +14571,7 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
14433
14571
|
}
|
|
14434
14572
|
async function deleteAllVaultMemoriesForUserOp(ctx, userId) {
|
|
14435
14573
|
if (ctx.userId !== void 0 && ctx.userId !== userId) return 0;
|
|
14436
|
-
const records = await ctx.vaultMemoryCollection.query(
|
|
14574
|
+
const records = await ctx.vaultMemoryCollection.query(import_watermelondb21.Q.where("user_id", userId), import_watermelondb21.Q.where("is_deleted", false)).fetch();
|
|
14437
14575
|
if (records.length === 0) return 0;
|
|
14438
14576
|
await ctx.database.write(async () => {
|
|
14439
14577
|
await assertCanWrite2(ctx);
|
|
@@ -14470,7 +14608,7 @@ async function getDecayCandidatesRawOp(ctx) {
|
|
|
14470
14608
|
assertVaultScopeForSweep(ctx);
|
|
14471
14609
|
const results = await ctx.vaultMemoryCollection.query(
|
|
14472
14610
|
...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
|
|
14473
|
-
|
|
14611
|
+
import_watermelondb21.Q.where("kind", null)
|
|
14474
14612
|
).unsafeFetchRaw();
|
|
14475
14613
|
return results.map((raw) => ({
|
|
14476
14614
|
uniqueId: raw.id,
|
|
@@ -14600,11 +14738,11 @@ async function findQuarantinedDuplicateOp(ctx, content, sourceIds2, where) {
|
|
|
14600
14738
|
const wanted = [...new Set(sourceIds2)].sort().join("\0");
|
|
14601
14739
|
const target = normalizeForDedupe(content);
|
|
14602
14740
|
const rows = await ctx.vaultMemoryCollection.query(
|
|
14603
|
-
|
|
14604
|
-
|
|
14605
|
-
|
|
14606
|
-
|
|
14607
|
-
...ctx.userId !== void 0 ? [
|
|
14741
|
+
import_watermelondb21.Q.where("trust_tier", "quarantined"),
|
|
14742
|
+
import_watermelondb21.Q.where("is_deleted", false),
|
|
14743
|
+
import_watermelondb21.Q.where("scope", where.scope),
|
|
14744
|
+
import_watermelondb21.Q.where("folder_id", where.folderId),
|
|
14745
|
+
...ctx.userId !== void 0 ? [import_watermelondb21.Q.where("user_id", ctx.userId)] : []
|
|
14608
14746
|
).unsafeFetchRaw();
|
|
14609
14747
|
for (const raw of rows) {
|
|
14610
14748
|
let ids;
|
|
@@ -15101,7 +15239,7 @@ var WalletPoller = class {
|
|
|
15101
15239
|
};
|
|
15102
15240
|
|
|
15103
15241
|
// src/lib/db/vaultFolders/operations.ts
|
|
15104
|
-
var
|
|
15242
|
+
var import_watermelondb22 = require("@nozbe/watermelondb");
|
|
15105
15243
|
function folderToStored(folder) {
|
|
15106
15244
|
return {
|
|
15107
15245
|
uniqueId: folder.id,
|
|
@@ -15126,7 +15264,7 @@ async function createVaultFolderOp(ctx, opts) {
|
|
|
15126
15264
|
return folderToStored(created);
|
|
15127
15265
|
}
|
|
15128
15266
|
async function getAllVaultFoldersOp(ctx) {
|
|
15129
|
-
const results = await ctx.vaultFolderCollection.query(
|
|
15267
|
+
const results = await ctx.vaultFolderCollection.query(import_watermelondb22.Q.where("is_deleted", false), import_watermelondb22.Q.sortBy("created_at", import_watermelondb22.Q.desc)).fetch();
|
|
15130
15268
|
return results.map(folderToStored);
|
|
15131
15269
|
}
|
|
15132
15270
|
async function updateVaultFolderOp(ctx, id, opts) {
|
|
@@ -15135,7 +15273,7 @@ async function updateVaultFolderOp(ctx, id, opts) {
|
|
|
15135
15273
|
if (record2.isDeleted) return null;
|
|
15136
15274
|
const scopeChanged = opts.scope !== void 0 && opts.scope !== record2.scope;
|
|
15137
15275
|
const updated = await ctx.database.write(async () => {
|
|
15138
|
-
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(
|
|
15276
|
+
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(import_watermelondb22.Q.where("folder_id", id), import_watermelondb22.Q.where("is_deleted", false)).fetch() : [];
|
|
15139
15277
|
const updates = [];
|
|
15140
15278
|
updates.push(
|
|
15141
15279
|
record2.prepareUpdate((r) => {
|
|
@@ -15164,7 +15302,7 @@ async function deleteVaultFolderOp(ctx, id) {
|
|
|
15164
15302
|
const record2 = await ctx.vaultFolderCollection.find(id);
|
|
15165
15303
|
if (record2.isDeleted) return false;
|
|
15166
15304
|
await ctx.database.write(async () => {
|
|
15167
|
-
const memories = await ctx.vaultMemoryCollection.query(
|
|
15305
|
+
const memories = await ctx.vaultMemoryCollection.query(import_watermelondb22.Q.where("folder_id", id), import_watermelondb22.Q.where("is_deleted", false)).fetch();
|
|
15168
15306
|
const preparedMemories = memories.map(
|
|
15169
15307
|
(memory) => memory.prepareUpdate((r) => {
|
|
15170
15308
|
r._setRaw("folder_id", null);
|
|
@@ -15235,7 +15373,7 @@ async function updateVaultFolderContextOp(ctx, id, context) {
|
|
|
15235
15373
|
}
|
|
15236
15374
|
}
|
|
15237
15375
|
async function getVaultFolderMemoryCountOp(ctx, folderId) {
|
|
15238
|
-
return await ctx.vaultMemoryCollection.query(
|
|
15376
|
+
return await ctx.vaultMemoryCollection.query(import_watermelondb22.Q.where("folder_id", folderId), import_watermelondb22.Q.where("is_deleted", false)).fetchCount();
|
|
15239
15377
|
}
|
|
15240
15378
|
|
|
15241
15379
|
// src/lib/db/vaultFolders/defaults.ts
|
|
@@ -15281,7 +15419,7 @@ async function _ensureDefaultFoldersImpl(ctx) {
|
|
|
15281
15419
|
init_logger();
|
|
15282
15420
|
|
|
15283
15421
|
// src/lib/memory/autoExtract.ts
|
|
15284
|
-
var
|
|
15422
|
+
var import_watermelondb23 = require("@nozbe/watermelondb");
|
|
15285
15423
|
init_logger();
|
|
15286
15424
|
init_redactor();
|
|
15287
15425
|
|
|
@@ -18008,7 +18146,7 @@ async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
|
18008
18146
|
// src/lib/memory/autoExtract.ts
|
|
18009
18147
|
async function isMemoryTopicsUserManaged(ctx, memoryId) {
|
|
18010
18148
|
try {
|
|
18011
|
-
const rows = await ctx.database.get(VaultMemory.table).query(
|
|
18149
|
+
const rows = await ctx.database.get(VaultMemory.table).query(import_watermelondb23.Q.where("id", memoryId)).fetch();
|
|
18012
18150
|
return rows[0]?.topicsUserManaged === true;
|
|
18013
18151
|
} catch {
|
|
18014
18152
|
return true;
|
|
@@ -20570,7 +20708,7 @@ function parseAnswer(body, base, parseSchema) {
|
|
|
20570
20708
|
}
|
|
20571
20709
|
|
|
20572
20710
|
// src/lib/memory/store/local.ts
|
|
20573
|
-
var
|
|
20711
|
+
var import_watermelondb24 = require("@nozbe/watermelondb");
|
|
20574
20712
|
init_logger();
|
|
20575
20713
|
|
|
20576
20714
|
// src/lib/memory/topicExtract.ts
|
|
@@ -20853,8 +20991,8 @@ function createLocalMemoryStore(options) {
|
|
|
20853
20991
|
writeOptions?.signal?.throwIfAborted();
|
|
20854
20992
|
};
|
|
20855
20993
|
const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
|
|
20856
|
-
const ownedBy = userId !== void 0 ? [
|
|
20857
|
-
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [
|
|
20994
|
+
const ownedBy = userId !== void 0 ? [import_watermelondb24.Q.where("user_id", userId)] : [];
|
|
20995
|
+
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [import_watermelondb24.Q.or(import_watermelondb24.Q.where("user_id", userId), import_watermelondb24.Q.where("user_id", null))] : [import_watermelondb24.Q.where("user_id", userId)];
|
|
20858
20996
|
const watchedColumns = [
|
|
20859
20997
|
"content",
|
|
20860
20998
|
"scope",
|
|
@@ -20899,7 +21037,7 @@ function createLocalMemoryStore(options) {
|
|
|
20899
21037
|
list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
|
|
20900
21038
|
get: (id) => getVaultMemoryOp(vaultCtx, id),
|
|
20901
21039
|
listArchived: async () => {
|
|
20902
|
-
const ids = await vaultCtx.vaultMemoryCollection.query(
|
|
21040
|
+
const ids = await vaultCtx.vaultMemoryCollection.query(import_watermelondb24.Q.where("is_deleted", false), import_watermelondb24.Q.where("archived_at", import_watermelondb24.Q.notEq(null)), ...ownedBy).fetchIds();
|
|
20903
21041
|
if (ids.length === 0) return [];
|
|
20904
21042
|
const rows = await getAllVaultMemoriesOp(vaultCtx, { memoryIds: ids, includeArchived: true });
|
|
20905
21043
|
return rows.sort((a, b) => (b.archivedAt ?? 0) - (a.archivedAt ?? 0));
|
|
@@ -20915,7 +21053,7 @@ function createLocalMemoryStore(options) {
|
|
|
20915
21053
|
set.add(String(link.memory_id));
|
|
20916
21054
|
members.set(entityId, set);
|
|
20917
21055
|
}
|
|
20918
|
-
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(
|
|
21056
|
+
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf([...members.keys()]))).unsafeFetchRaw() : [];
|
|
20919
21057
|
const byName = /* @__PURE__ */ new Map();
|
|
20920
21058
|
for (const entity of entities) {
|
|
20921
21059
|
const name = String(entity.canonical_name);
|
|
@@ -20965,7 +21103,7 @@ function createLocalMemoryStore(options) {
|
|
|
20965
21103
|
setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
|
|
20966
21104
|
addTopics: (memoryId, topics, writeOptions) => database.write(async (writer) => {
|
|
20967
21105
|
await assertWrite(writeOptions);
|
|
20968
|
-
const owned = await vaultCtx.vaultMemoryCollection.query(
|
|
21106
|
+
const owned = await vaultCtx.vaultMemoryCollection.query(import_watermelondb24.Q.where("id", memoryId), import_watermelondb24.Q.where("is_deleted", false), ...ownedBy).fetchCount();
|
|
20969
21107
|
return owned > 0 ? writer.callWriter(
|
|
20970
21108
|
() => linkMemoryEntitiesOp(
|
|
20971
21109
|
{
|
|
@@ -21037,7 +21175,7 @@ function createLocalMemoryStore(options) {
|
|
|
21037
21175
|
else onChange();
|
|
21038
21176
|
};
|
|
21039
21177
|
};
|
|
21040
|
-
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(
|
|
21178
|
+
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(import_watermelondb24.Q.where("is_deleted", false), ...ownedBy).observeWithColumns(
|
|
21041
21179
|
subscribeOptions?.embeddings ? [...watchedColumns, "embedding", "embedding_model"] : watchedColumns
|
|
21042
21180
|
);
|
|
21043
21181
|
const subscriptions = [memories.subscribe(afterFirst())];
|
|
@@ -24104,7 +24242,7 @@ async function assembleMemoryContext(options) {
|
|
|
24104
24242
|
}
|
|
24105
24243
|
|
|
24106
24244
|
// src/lib/memory/durableExtraction.ts
|
|
24107
|
-
var
|
|
24245
|
+
var import_watermelondb25 = require("@nozbe/watermelondb");
|
|
24108
24246
|
var MAX_JOBS_PER_PASS = 3;
|
|
24109
24247
|
var MAX_ATTEMPTS = 3;
|
|
24110
24248
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -24275,7 +24413,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24275
24413
|
const source = options.messageSource?.(conversationId);
|
|
24276
24414
|
if (source)
|
|
24277
24415
|
return await fromSource(source.status(conversationId)) === "ready" && (await loadFromSource(source, conversationId, ids)).every(Boolean);
|
|
24278
|
-
return await storage.conversationsCollection.query(
|
|
24416
|
+
return await storage.conversationsCollection.query(import_watermelondb25.Q.where("conversation_id", conversationId), import_watermelondb25.Q.where("is_deleted", false)).fetchCount() > 0 && await storage.messagesCollection.query(import_watermelondb25.Q.where("conversation_id", conversationId), import_watermelondb25.Q.where("id", import_watermelondb25.Q.oneOf(ids))).fetchCount() === ids.length;
|
|
24279
24417
|
}
|
|
24280
24418
|
function schedule(delay) {
|
|
24281
24419
|
if (disposed) return;
|
|
@@ -24449,7 +24587,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24449
24587
|
let sourceWaiting = false;
|
|
24450
24588
|
try {
|
|
24451
24589
|
await writes;
|
|
24452
|
-
const pending = await jobs.query(
|
|
24590
|
+
const pending = await jobs.query(import_watermelondb25.Q.where("owner_key", owner), import_watermelondb25.Q.where("message_ids", import_watermelondb25.Q.notEq("[]"))).fetch();
|
|
24453
24591
|
storeFailures = 0;
|
|
24454
24592
|
let processed = 0;
|
|
24455
24593
|
for (const job of pending) {
|
|
@@ -24481,7 +24619,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24481
24619
|
let ids = [];
|
|
24482
24620
|
let loaded = [];
|
|
24483
24621
|
try {
|
|
24484
|
-
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(
|
|
24622
|
+
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(import_watermelondb25.Q.where("conversation_id", conversationId), import_watermelondb25.Q.where("is_deleted", false)).fetchCount() > 0;
|
|
24485
24623
|
if (!present) {
|
|
24486
24624
|
await database.write(() => job.destroyPermanently());
|
|
24487
24625
|
continue;
|
|
@@ -24649,7 +24787,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24649
24787
|
const scope = currentScope();
|
|
24650
24788
|
writes = writes.then(
|
|
24651
24789
|
() => database.write(async () => {
|
|
24652
|
-
const existing = await jobs.query(
|
|
24790
|
+
const existing = await jobs.query(import_watermelondb25.Q.where("owner_key", owner), import_watermelondb25.Q.where("conversation_id", conversationId)).fetch();
|
|
24653
24791
|
const job = existing.find(
|
|
24654
24792
|
(candidate) => candidate._getRaw("scope") === scope && (candidate._getRaw("folder_id") ?? null) === folderId
|
|
24655
24793
|
);
|
|
@@ -24662,8 +24800,8 @@ function createDurableAutoExtractor(options) {
|
|
|
24662
24800
|
if (watermarks.length) {
|
|
24663
24801
|
const misplaced = new Set(
|
|
24664
24802
|
await storage.messagesCollection.query(
|
|
24665
|
-
|
|
24666
|
-
|
|
24803
|
+
import_watermelondb25.Q.where("id", import_watermelondb25.Q.oneOf(watermarks)),
|
|
24804
|
+
import_watermelondb25.Q.where("conversation_id", import_watermelondb25.Q.notEq(conversationId))
|
|
24667
24805
|
).fetchIds()
|
|
24668
24806
|
);
|
|
24669
24807
|
for (const prior of existing)
|
|
@@ -24673,7 +24811,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24673
24811
|
r._setRaw("watermark_seq", null);
|
|
24674
24812
|
});
|
|
24675
24813
|
}
|
|
24676
|
-
const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(
|
|
24814
|
+
const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(import_watermelondb25.Q.where("id", import_watermelondb25.Q.oneOf(ids))).fetch();
|
|
24677
24815
|
const foreignRows = new Set(
|
|
24678
24816
|
rows.filter((row) => row._getRaw("conversation_id") !== conversationId).map((row) => row.id)
|
|
24679
24817
|
);
|
|
@@ -25679,7 +25817,7 @@ function computeToolGuidance(selectedServerTools, selectedClientTools, extraTool
|
|
|
25679
25817
|
async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embeddingOptions, extraToolSets = [], activeToolSets = [], noEmbeddingsReason = "short-prompt") {
|
|
25680
25818
|
const isAlwaysIncluded = (t) => {
|
|
25681
25819
|
const name = getToolName2(t);
|
|
25682
|
-
return name.startsWith("memory_vault_") || name === RECALL_TOOL_NAME || name === CONFIRM_TOOL_NAME;
|
|
25820
|
+
return name.startsWith("memory_vault_") || name === RECALL_TOOL_NAME || name === CONFIRM_TOOL_NAME || name === SELECT_PAYMENT_WALLET_TOOL_NAME || name === WALLET_PAYMENT_TOOL_NAME;
|
|
25683
25821
|
};
|
|
25684
25822
|
const alwaysInclude = clientTools.filter(isAlwaysIncluded);
|
|
25685
25823
|
const filterCandidates = clientTools.filter((t) => !isAlwaysIncluded(t));
|
|
@@ -25691,7 +25829,7 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
25691
25829
|
}
|
|
25692
25830
|
if (!promptEmbeddings) {
|
|
25693
25831
|
if (activeToolSets.length === 0) {
|
|
25694
|
-
return { tools:
|
|
25832
|
+
return { tools: alwaysInclude, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
25695
25833
|
}
|
|
25696
25834
|
const allSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
25697
25835
|
const activeSets = allSets.filter((s) => activeToolSets.includes(s.name));
|
|
@@ -26840,6 +26978,179 @@ function createNotionProxyTools(callMcp) {
|
|
|
26840
26978
|
return NOTION_TOOLS.map((tool) => tool(run));
|
|
26841
26979
|
}
|
|
26842
26980
|
|
|
26981
|
+
// src/tools/uiInteraction.ts
|
|
26982
|
+
function generateInteractionId(prefix) {
|
|
26983
|
+
return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
|
|
26984
|
+
}
|
|
26985
|
+
function createInteractiveTool(options, config) {
|
|
26986
|
+
return {
|
|
26987
|
+
type: "function",
|
|
26988
|
+
function: {
|
|
26989
|
+
name: config.name,
|
|
26990
|
+
description: config.description,
|
|
26991
|
+
arguments: config.parameters
|
|
26992
|
+
},
|
|
26993
|
+
executor: async (args, signal) => {
|
|
26994
|
+
if (config.validate && !config.validate(args)) {
|
|
26995
|
+
return { cancelled: true };
|
|
26996
|
+
}
|
|
26997
|
+
const context = options.getContext();
|
|
26998
|
+
if (!context) {
|
|
26999
|
+
return { cancelled: true };
|
|
27000
|
+
}
|
|
27001
|
+
const interactionId = generateInteractionId(config.interactionType);
|
|
27002
|
+
const interactionData = config.mapArgs ? config.mapArgs(args) : args;
|
|
27003
|
+
const onAbort = () => context.cancelInteraction?.(interactionId);
|
|
27004
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
27005
|
+
try {
|
|
27006
|
+
const result = await context.createInteraction(interactionId, config.interactionType, {
|
|
27007
|
+
...interactionData,
|
|
27008
|
+
afterMessageId: options.getLastMessageId?.()
|
|
27009
|
+
});
|
|
27010
|
+
if (config.mapResult) {
|
|
27011
|
+
return config.mapResult(result, args);
|
|
27012
|
+
}
|
|
27013
|
+
return result;
|
|
27014
|
+
} catch {
|
|
27015
|
+
return { cancelled: true };
|
|
27016
|
+
} finally {
|
|
27017
|
+
signal?.removeEventListener("abort", onAbort);
|
|
27018
|
+
}
|
|
27019
|
+
},
|
|
27020
|
+
executorTimeout: Infinity
|
|
27021
|
+
};
|
|
27022
|
+
}
|
|
27023
|
+
|
|
27024
|
+
// src/tools/walletPayment.ts
|
|
27025
|
+
var CANCELLED = { cancelled: true };
|
|
27026
|
+
function isNonEmptyString(value) {
|
|
27027
|
+
return typeof value === "string" && value.length > 0;
|
|
27028
|
+
}
|
|
27029
|
+
function hasPassengers(value) {
|
|
27030
|
+
return Array.isArray(value?.passengers);
|
|
27031
|
+
}
|
|
27032
|
+
function createSelectPaymentWalletTool(options) {
|
|
27033
|
+
const tool = createInteractiveTool(options, {
|
|
27034
|
+
name: SELECT_PAYMENT_WALLET_TOOL_NAME,
|
|
27035
|
+
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.",
|
|
27036
|
+
parameters: {
|
|
27037
|
+
type: "object",
|
|
27038
|
+
properties: {
|
|
27039
|
+
offer_id: {
|
|
27040
|
+
type: "string",
|
|
27041
|
+
description: "The offer id from anuma_flight_offer_details"
|
|
27042
|
+
},
|
|
27043
|
+
summary: {
|
|
27044
|
+
type: "string",
|
|
27045
|
+
description: "Route, dates and fare of the offer, as shown to the user"
|
|
27046
|
+
},
|
|
27047
|
+
amount: {
|
|
27048
|
+
type: "string",
|
|
27049
|
+
description: "Total price of the offer, e.g. '412.50'"
|
|
27050
|
+
},
|
|
27051
|
+
currency: {
|
|
27052
|
+
type: "string",
|
|
27053
|
+
description: "Currency of the price, e.g. 'USD'"
|
|
27054
|
+
}
|
|
27055
|
+
},
|
|
27056
|
+
required: ["offer_id", "amount", "currency"]
|
|
27057
|
+
},
|
|
27058
|
+
interactionType: "select_payment_wallet",
|
|
27059
|
+
validate: (args) => isNonEmptyString(args.offer_id),
|
|
27060
|
+
mapArgs: ({ offer_id, summary, amount, currency, wallets }) => ({
|
|
27061
|
+
offer_id,
|
|
27062
|
+
summary,
|
|
27063
|
+
amount,
|
|
27064
|
+
currency,
|
|
27065
|
+
wallets
|
|
27066
|
+
}),
|
|
27067
|
+
mapResult: (result, args) => {
|
|
27068
|
+
if (result?.confirmed === true && isNonEmptyString(result.funding_wallet)) {
|
|
27069
|
+
return {
|
|
27070
|
+
confirmed: true,
|
|
27071
|
+
offer_id: args.offer_id,
|
|
27072
|
+
funding_wallet: result.funding_wallet
|
|
27073
|
+
};
|
|
27074
|
+
}
|
|
27075
|
+
if (result?.confirmed === false) return { confirmed: false };
|
|
27076
|
+
return CANCELLED;
|
|
27077
|
+
}
|
|
27078
|
+
});
|
|
27079
|
+
const showCard = tool.executor;
|
|
27080
|
+
return {
|
|
27081
|
+
...tool,
|
|
27082
|
+
executor: async (args, signal) => {
|
|
27083
|
+
if (!isNonEmptyString(args.offer_id)) return CANCELLED;
|
|
27084
|
+
let wallets;
|
|
27085
|
+
try {
|
|
27086
|
+
wallets = await options.listWallets();
|
|
27087
|
+
} catch {
|
|
27088
|
+
return { error_code: "wallets_unavailable", retryable: true };
|
|
27089
|
+
}
|
|
27090
|
+
if (signal?.aborted) return CANCELLED;
|
|
27091
|
+
return showCard?.({ ...args, wallets }, signal);
|
|
27092
|
+
}
|
|
27093
|
+
};
|
|
27094
|
+
}
|
|
27095
|
+
function createWalletPaymentTool(options) {
|
|
27096
|
+
const tool = createInteractiveTool(options, {
|
|
27097
|
+
name: WALLET_PAYMENT_TOOL_NAME,
|
|
27098
|
+
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.",
|
|
27099
|
+
parameters: {
|
|
27100
|
+
type: "object",
|
|
27101
|
+
properties: {
|
|
27102
|
+
provider: {
|
|
27103
|
+
type: "string",
|
|
27104
|
+
description: "The payment provider from anuma_create_flight_intent"
|
|
27105
|
+
},
|
|
27106
|
+
reference: {
|
|
27107
|
+
type: "string",
|
|
27108
|
+
description: "The payment reference from anuma_create_flight_intent"
|
|
27109
|
+
},
|
|
27110
|
+
passenger_count: {
|
|
27111
|
+
type: "integer",
|
|
27112
|
+
minimum: 1,
|
|
27113
|
+
description: "How many passengers the booking is for"
|
|
27114
|
+
}
|
|
27115
|
+
},
|
|
27116
|
+
required: ["provider", "reference", "passenger_count"]
|
|
27117
|
+
},
|
|
27118
|
+
interactionType: "prompt_wallet_payment",
|
|
27119
|
+
validate: (args) => isNonEmptyString(args.provider) && isNonEmptyString(args.reference) && Number.isInteger(args.passenger_count) && args.passenger_count >= 1,
|
|
27120
|
+
mapArgs: ({ provider, reference, passenger_count }) => ({
|
|
27121
|
+
provider,
|
|
27122
|
+
reference,
|
|
27123
|
+
passenger_count
|
|
27124
|
+
}),
|
|
27125
|
+
mapResult: (result) => hasPassengers(result) ? { passengers: result.passengers } : CANCELLED
|
|
27126
|
+
});
|
|
27127
|
+
const showCard = tool.executor;
|
|
27128
|
+
return {
|
|
27129
|
+
...tool,
|
|
27130
|
+
executor: async (args, signal) => {
|
|
27131
|
+
const answer = await showCard?.(args, signal);
|
|
27132
|
+
if (!hasPassengers(answer) || signal?.aborted) return CANCELLED;
|
|
27133
|
+
const provider = args.provider;
|
|
27134
|
+
const reference = args.reference;
|
|
27135
|
+
let outcome2;
|
|
27136
|
+
try {
|
|
27137
|
+
outcome2 = await options.pay({ provider, reference, passengers: answer.passengers }, signal);
|
|
27138
|
+
} catch {
|
|
27139
|
+
return { paid: false, error_code: "payment_failed", retryable: false };
|
|
27140
|
+
}
|
|
27141
|
+
if (outcome2.paid) {
|
|
27142
|
+
return {
|
|
27143
|
+
paid: true,
|
|
27144
|
+
provider: outcome2.provider,
|
|
27145
|
+
reference: outcome2.reference,
|
|
27146
|
+
status: outcome2.status
|
|
27147
|
+
};
|
|
27148
|
+
}
|
|
27149
|
+
return { paid: false, error_code: outcome2.error_code, retryable: outcome2.retryable };
|
|
27150
|
+
}
|
|
27151
|
+
};
|
|
27152
|
+
}
|
|
27153
|
+
|
|
26843
27154
|
// src/expo/useChat.ts
|
|
26844
27155
|
var import_react4 = require("react");
|
|
26845
27156
|
init_clientConfig();
|
|
@@ -27734,7 +28045,7 @@ async function cleanupConversationSummary(database, conversationId) {
|
|
|
27734
28045
|
}
|
|
27735
28046
|
|
|
27736
28047
|
// src/lib/db/media/operations.ts
|
|
27737
|
-
var
|
|
28048
|
+
var import_watermelondb26 = require("@nozbe/watermelondb");
|
|
27738
28049
|
|
|
27739
28050
|
// src/lib/storage/opfs.ts
|
|
27740
28051
|
function isOPFSSupported() {
|
|
@@ -27926,7 +28237,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
27926
28237
|
})
|
|
27927
28238
|
);
|
|
27928
28239
|
});
|
|
27929
|
-
const results = await mediaCollection.query(
|
|
28240
|
+
const results = await mediaCollection.query(import_watermelondb26.Q.where("media_id", import_watermelondb26.Q.oneOf(mediaIds))).fetch();
|
|
27930
28241
|
return Promise.all(
|
|
27931
28242
|
results.map(
|
|
27932
28243
|
(m) => mediaToStored(m, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -27936,7 +28247,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
27936
28247
|
var IMAGE_VIDEO_MIMES = VIDEO_EXTENSIONS.map((ext) => `image/${ext}`);
|
|
27937
28248
|
async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
27938
28249
|
const mediaCollection = ctx.database.get("media");
|
|
27939
|
-
const results = await mediaCollection.query(
|
|
28250
|
+
const results = await mediaCollection.query(import_watermelondb26.Q.where("conversation_id", conversationId), import_watermelondb26.Q.where("is_deleted", false)).fetch();
|
|
27940
28251
|
if (results.length === 0) {
|
|
27941
28252
|
return 0;
|
|
27942
28253
|
}
|
|
@@ -30020,6 +30331,7 @@ function useChatStorage(options) {
|
|
|
30020
30331
|
RemoteMemoryPartialCreateError,
|
|
30021
30332
|
RerankerUnavailableError,
|
|
30022
30333
|
SDK_SCHEMA_VERSION,
|
|
30334
|
+
SELECT_PAYMENT_WALLET_TOOL_NAME,
|
|
30023
30335
|
SHORT_TTL_MS,
|
|
30024
30336
|
STREAM_RESUMABLE_HEADER,
|
|
30025
30337
|
StoredVaultFolderModel,
|
|
@@ -30032,6 +30344,7 @@ function useChatStorage(options) {
|
|
|
30032
30344
|
TREND_RECENT_WINDOW_DAYS,
|
|
30033
30345
|
TREND_STALE_WINDOW_DAYS,
|
|
30034
30346
|
VAULT_SIZE_HOP_CAP,
|
|
30347
|
+
WALLET_PAYMENT_TOOL_NAME,
|
|
30035
30348
|
WalletPoller,
|
|
30036
30349
|
addConversationMemoriesOp,
|
|
30037
30350
|
archiveVaultMemoryOp,
|
|
@@ -30086,12 +30399,14 @@ function useChatStorage(options) {
|
|
|
30086
30399
|
createRemoteMemoryPersistence,
|
|
30087
30400
|
createRemoteMemoryPipeline,
|
|
30088
30401
|
createRemoteMemoryStore,
|
|
30402
|
+
createSelectPaymentWalletTool,
|
|
30089
30403
|
createStockPricePreProcessor,
|
|
30090
30404
|
createStreamingDeAnonymizer,
|
|
30091
30405
|
createVaultEmbeddingCache,
|
|
30092
30406
|
createVaultFolderOp,
|
|
30093
30407
|
createVaultMemoriesBatchOp,
|
|
30094
30408
|
createVaultMemoryOp,
|
|
30409
|
+
createWalletPaymentTool,
|
|
30095
30410
|
createWeatherPreProcessor,
|
|
30096
30411
|
createWebSearchPreProcessor,
|
|
30097
30412
|
decodeChunkVector,
|