@anuma/sdk 8.0.1 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expo/index.cjs +542 -227
- package/dist/expo/index.d.mts +113 -2
- package/dist/expo/index.d.ts +113 -2
- package/dist/expo/index.mjs +490 -179
- package/dist/index.cjs +21 -1
- package/dist/index.mjs +21 -1
- package/dist/react/index.cjs +651 -326
- package/dist/react/index.d.mts +117 -2
- package/dist/react/index.d.ts +117 -2
- package/dist/react/index.mjs +593 -272
- package/dist/server/index.cjs +63 -4
- package/dist/server/index.d.mts +6 -1
- package/dist/server/index.d.ts +6 -1
- package/dist/server/index.mjs +63 -4
- package/dist/tools/index.cjs +142 -0
- package/dist/tools/index.d.mts +91 -1
- package/dist/tools/index.d.ts +91 -1
- package/dist/tools/index.mjs +138 -0
- package/dist/tools/selection/index.cjs +25 -3
- package/dist/tools/selection/index.d.mts +1 -1
- package/dist/tools/selection/index.d.ts +1 -1
- package/dist/tools/selection/index.mjs +25 -3
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -1459,6 +1459,7 @@ __export(index_exports, {
|
|
|
1459
1459
|
RemoteMemoryPartialCreateError: () => RemoteMemoryPartialCreateError,
|
|
1460
1460
|
RerankerUnavailableError: () => RerankerUnavailableError,
|
|
1461
1461
|
SDK_SCHEMA_VERSION: () => SDK_SCHEMA_VERSION,
|
|
1462
|
+
SELECT_PAYMENT_WALLET_TOOL_NAME: () => SELECT_PAYMENT_WALLET_TOOL_NAME,
|
|
1462
1463
|
SERVER_TOOL_DEPENDENCY_SETS: () => SERVER_TOOL_DEPENDENCY_SETS,
|
|
1463
1464
|
SHORT_TTL_MS: () => SHORT_TTL_MS,
|
|
1464
1465
|
SLIDER_CONFIG: () => SLIDER_CONFIG,
|
|
@@ -1483,6 +1484,7 @@ __export(index_exports, {
|
|
|
1483
1484
|
TextProcessor: () => TextProcessor,
|
|
1484
1485
|
UIInteractionProvider: () => UIInteractionProvider,
|
|
1485
1486
|
VAULT_SIZE_HOP_CAP: () => VAULT_SIZE_HOP_CAP,
|
|
1487
|
+
WALLET_PAYMENT_TOOL_NAME: () => WALLET_PAYMENT_TOOL_NAME,
|
|
1486
1488
|
WalletPoller: () => WalletPoller,
|
|
1487
1489
|
WatermelonChatStorageAdapter: () => WatermelonChatStorageAdapter,
|
|
1488
1490
|
WordProcessor: () => WordProcessor,
|
|
@@ -1549,12 +1551,14 @@ __export(index_exports, {
|
|
|
1549
1551
|
createRemoteMemoryPipeline: () => createRemoteMemoryPipeline,
|
|
1550
1552
|
createRemoteMemoryStore: () => createRemoteMemoryStore,
|
|
1551
1553
|
createSavedToolOp: () => createSavedToolOp,
|
|
1554
|
+
createSelectPaymentWalletTool: () => createSelectPaymentWalletTool,
|
|
1552
1555
|
createServerToolsFilter: () => createServerToolsFilter,
|
|
1553
1556
|
createStockPricePreProcessor: () => createStockPricePreProcessor,
|
|
1554
1557
|
createVaultEmbeddingCache: () => createVaultEmbeddingCache,
|
|
1555
1558
|
createVaultFolderOp: () => createVaultFolderOp,
|
|
1556
1559
|
createVaultMemoriesBatchOp: () => createVaultMemoriesBatchOp,
|
|
1557
1560
|
createVaultMemoryOp: () => createVaultMemoryOp,
|
|
1561
|
+
createWalletPaymentTool: () => createWalletPaymentTool,
|
|
1558
1562
|
createWeatherPreProcessor: () => createWeatherPreProcessor,
|
|
1559
1563
|
createWebSearchPreProcessor: () => createWebSearchPreProcessor,
|
|
1560
1564
|
decodeChunkVector: () => decodeChunkVector,
|
|
@@ -3515,7 +3519,7 @@ ${appendix}` : appendix;
|
|
|
3515
3519
|
}
|
|
3516
3520
|
|
|
3517
3521
|
// src/lib/db/chat/operations.ts
|
|
3518
|
-
var
|
|
3522
|
+
var import_watermelondb3 = require("@nozbe/watermelondb");
|
|
3519
3523
|
var import_uuid2 = require("uuid");
|
|
3520
3524
|
init_logger();
|
|
3521
3525
|
|
|
@@ -3964,6 +3968,118 @@ async function assembleDecryptedMessage(message, address) {
|
|
|
3964
3968
|
return result;
|
|
3965
3969
|
}
|
|
3966
3970
|
|
|
3971
|
+
// src/lib/db/chat/toolCallEventIndex.ts
|
|
3972
|
+
var import_watermelondb2 = require("@nozbe/watermelondb");
|
|
3973
|
+
function parseEventIds(value) {
|
|
3974
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3975
|
+
let events;
|
|
3976
|
+
try {
|
|
3977
|
+
events = typeof value === "string" ? JSON.parse(value) : value;
|
|
3978
|
+
} catch {
|
|
3979
|
+
return ids;
|
|
3980
|
+
}
|
|
3981
|
+
if (!Array.isArray(events)) return ids;
|
|
3982
|
+
for (const event of events) {
|
|
3983
|
+
if (!event || typeof event !== "object") continue;
|
|
3984
|
+
const id = event.id;
|
|
3985
|
+
if (typeof id === "string" && id) ids.add(id);
|
|
3986
|
+
}
|
|
3987
|
+
return ids;
|
|
3988
|
+
}
|
|
3989
|
+
async function fetchEventRows(collection, conversationId) {
|
|
3990
|
+
try {
|
|
3991
|
+
return await collection.query(
|
|
3992
|
+
import_watermelondb2.Q.unsafeSqlQuery(
|
|
3993
|
+
`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 ('', '[]')`,
|
|
3994
|
+
[conversationId]
|
|
3995
|
+
)
|
|
3996
|
+
).unsafeFetchRaw();
|
|
3997
|
+
} catch (error) {
|
|
3998
|
+
if (!(error instanceof Error) || !/unsafeSqlQuery.*not supported/.test(error.message)) {
|
|
3999
|
+
throw error;
|
|
4000
|
+
}
|
|
4001
|
+
return await collection.query(
|
|
4002
|
+
import_watermelondb2.Q.where("conversation_id", conversationId),
|
|
4003
|
+
import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notEq(null)),
|
|
4004
|
+
import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notIn(["", "[]"])),
|
|
4005
|
+
import_watermelondb2.Q.unsafeLokiTransform(
|
|
4006
|
+
(rows) => rows.map(({ id, tool_call_events }) => ({ id, tool_call_events }))
|
|
4007
|
+
)
|
|
4008
|
+
).unsafeFetchRaw();
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
var ToolCallEventIndex = class {
|
|
4012
|
+
constructor(collection) {
|
|
4013
|
+
this.collection = collection;
|
|
4014
|
+
this.conversations = /* @__PURE__ */ new Map();
|
|
4015
|
+
this.messages = /* @__PURE__ */ new Map();
|
|
4016
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
4017
|
+
this.resetCount = collection.database._resetCount;
|
|
4018
|
+
collection.experimentalSubscribe((changes) => {
|
|
4019
|
+
for (const { record: record2, type } of changes) {
|
|
4020
|
+
this.replace(
|
|
4021
|
+
record2.id,
|
|
4022
|
+
type === "destroyed" ? void 0 : record2.conversationId,
|
|
4023
|
+
type === "destroyed" ? void 0 : record2._getRaw("tool_call_events")
|
|
4024
|
+
);
|
|
4025
|
+
}
|
|
4026
|
+
});
|
|
4027
|
+
}
|
|
4028
|
+
replace(messageId, conversationId, value) {
|
|
4029
|
+
const previous = this.messages.get(messageId);
|
|
4030
|
+
if (previous) {
|
|
4031
|
+
const counts2 = this.conversations.get(previous.conversationId);
|
|
4032
|
+
for (const id of previous.ids) {
|
|
4033
|
+
const count2 = counts2.get(id) - 1;
|
|
4034
|
+
if (count2 === 0) counts2.delete(id);
|
|
4035
|
+
else counts2.set(id, count2);
|
|
4036
|
+
}
|
|
4037
|
+
this.messages.delete(messageId);
|
|
4038
|
+
}
|
|
4039
|
+
const counts = conversationId === void 0 ? void 0 : this.conversations.get(conversationId);
|
|
4040
|
+
if (!counts || conversationId === void 0) return;
|
|
4041
|
+
const ids = parseEventIds(value);
|
|
4042
|
+
if (ids.size === 0) return;
|
|
4043
|
+
this.messages.set(messageId, { conversationId, ids });
|
|
4044
|
+
for (const id of ids) counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
4045
|
+
}
|
|
4046
|
+
async get(conversationId) {
|
|
4047
|
+
if (this.resetCount !== this.collection.database._resetCount) {
|
|
4048
|
+
this.conversations.clear();
|
|
4049
|
+
this.messages.clear();
|
|
4050
|
+
this.pending.clear();
|
|
4051
|
+
this.resetCount = this.collection.database._resetCount;
|
|
4052
|
+
}
|
|
4053
|
+
if (!this.conversations.has(conversationId)) {
|
|
4054
|
+
let pending = this.pending.get(conversationId);
|
|
4055
|
+
if (!pending) {
|
|
4056
|
+
pending = this.collection.database.read(async () => {
|
|
4057
|
+
const rows = await fetchEventRows(this.collection, conversationId);
|
|
4058
|
+
this.conversations.set(conversationId, /* @__PURE__ */ new Map());
|
|
4059
|
+
for (const row of rows)
|
|
4060
|
+
this.replace(String(row.id), conversationId, row.tool_call_events);
|
|
4061
|
+
});
|
|
4062
|
+
this.pending.set(conversationId, pending);
|
|
4063
|
+
}
|
|
4064
|
+
try {
|
|
4065
|
+
await pending;
|
|
4066
|
+
} finally {
|
|
4067
|
+
this.pending.delete(conversationId);
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
return new Set(this.conversations.get(conversationId).keys());
|
|
4071
|
+
}
|
|
4072
|
+
};
|
|
4073
|
+
var indexes = /* @__PURE__ */ new WeakMap();
|
|
4074
|
+
function getToolCallEventIds(collection, conversationId) {
|
|
4075
|
+
let index = indexes.get(collection);
|
|
4076
|
+
if (!index) {
|
|
4077
|
+
index = new ToolCallEventIndex(collection);
|
|
4078
|
+
indexes.set(collection, index);
|
|
4079
|
+
}
|
|
4080
|
+
return index.get(conversationId);
|
|
4081
|
+
}
|
|
4082
|
+
|
|
3967
4083
|
// src/lib/db/chat/types.ts
|
|
3968
4084
|
var import_uuid = require("uuid");
|
|
3969
4085
|
|
|
@@ -4356,7 +4472,7 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
|
|
|
4356
4472
|
);
|
|
4357
4473
|
}
|
|
4358
4474
|
async function getConversationOp(ctx, id) {
|
|
4359
|
-
const results = await ctx.conversationsCollection.query(
|
|
4475
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
4360
4476
|
return results.length > 0 ? await conversationToStored(
|
|
4361
4477
|
results[0],
|
|
4362
4478
|
ctx.walletAddress,
|
|
@@ -4365,7 +4481,7 @@ async function getConversationOp(ctx, id) {
|
|
|
4365
4481
|
) : null;
|
|
4366
4482
|
}
|
|
4367
4483
|
async function getConversationsOp(ctx) {
|
|
4368
|
-
const results = await ctx.conversationsCollection.query(
|
|
4484
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false), import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).unsafeFetchRaw();
|
|
4369
4485
|
return Promise.all(
|
|
4370
4486
|
results.map(
|
|
4371
4487
|
(raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -4386,33 +4502,33 @@ function conversationRawToLazyStored(raw) {
|
|
|
4386
4502
|
};
|
|
4387
4503
|
}
|
|
4388
4504
|
async function getConversationsLazyOp(ctx) {
|
|
4389
|
-
const results = await ctx.conversationsCollection.query(
|
|
4505
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false), import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).unsafeFetchRaw();
|
|
4390
4506
|
return results.map(conversationRawToLazyStored);
|
|
4391
4507
|
}
|
|
4392
4508
|
async function getConversationsPageOp(ctx, options) {
|
|
4393
4509
|
const limit = Math.floor(options?.limit ?? 200);
|
|
4394
4510
|
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
4395
4511
|
const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
|
|
4396
|
-
const clauses = [
|
|
4512
|
+
const clauses = [import_watermelondb3.Q.where("is_deleted", false)];
|
|
4397
4513
|
if (options?.before !== void 0) {
|
|
4398
4514
|
clauses.push(
|
|
4399
|
-
exclude.size > 0 ?
|
|
4515
|
+
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))
|
|
4400
4516
|
);
|
|
4401
4517
|
}
|
|
4402
|
-
const fetched = await ctx.conversationsCollection.query(...clauses,
|
|
4518
|
+
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();
|
|
4403
4519
|
const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
|
|
4404
4520
|
return results.slice(0, limit).map(conversationRawToLazyStored);
|
|
4405
4521
|
}
|
|
4406
4522
|
async function getConversationsByProjectLazyOp(ctx, projectId) {
|
|
4407
4523
|
const results = await ctx.conversationsCollection.query(
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4524
|
+
import_watermelondb3.Q.where("project_id", projectId === null ? "" : projectId),
|
|
4525
|
+
import_watermelondb3.Q.where("is_deleted", false),
|
|
4526
|
+
import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)
|
|
4411
4527
|
).unsafeFetchRaw();
|
|
4412
4528
|
return results.map(conversationRawToLazyStored);
|
|
4413
4529
|
}
|
|
4414
4530
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
4415
|
-
const results = await ctx.conversationsCollection.query(
|
|
4531
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
4416
4532
|
if (results.length > 0) {
|
|
4417
4533
|
const encryptedOpts = ctx.walletAddress && ctx.signMessage ? await encryptConversationFields(
|
|
4418
4534
|
{ title },
|
|
@@ -4431,13 +4547,13 @@ async function updateConversationTitleOp(ctx, id, title) {
|
|
|
4431
4547
|
return false;
|
|
4432
4548
|
}
|
|
4433
4549
|
async function deleteConversationOp(ctx, id) {
|
|
4434
|
-
const results = await ctx.conversationsCollection.query(
|
|
4550
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
4435
4551
|
if (results.length > 0) {
|
|
4436
4552
|
await ctx.database.write(async () => {
|
|
4437
4553
|
await results[0].update((conv) => {
|
|
4438
4554
|
conv._setRaw("is_deleted", true);
|
|
4439
4555
|
});
|
|
4440
|
-
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(
|
|
4556
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", id)).fetch() : [];
|
|
4441
4557
|
for (const job of jobs) await job.destroyPermanently();
|
|
4442
4558
|
});
|
|
4443
4559
|
return true;
|
|
@@ -4445,7 +4561,7 @@ async function deleteConversationOp(ctx, id) {
|
|
|
4445
4561
|
return false;
|
|
4446
4562
|
}
|
|
4447
4563
|
async function updateConversationProjectOp(ctx, id, projectId) {
|
|
4448
|
-
const results = await ctx.conversationsCollection.query(
|
|
4564
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
4449
4565
|
if (results.length > 0) {
|
|
4450
4566
|
await ctx.database.write(async () => {
|
|
4451
4567
|
await results[0].update((conv) => {
|
|
@@ -4457,7 +4573,7 @@ async function updateConversationProjectOp(ctx, id, projectId) {
|
|
|
4457
4573
|
return false;
|
|
4458
4574
|
}
|
|
4459
4575
|
async function updateConversationPinnedOp(ctx, id, pinned) {
|
|
4460
|
-
const results = await ctx.conversationsCollection.query(
|
|
4576
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
4461
4577
|
if (results.length > 0) {
|
|
4462
4578
|
await ctx.database.write(async () => {
|
|
4463
4579
|
await results[0].update((conv) => {
|
|
@@ -4470,9 +4586,9 @@ async function updateConversationPinnedOp(ctx, id, pinned) {
|
|
|
4470
4586
|
}
|
|
4471
4587
|
async function getConversationsByProjectOp(ctx, projectId) {
|
|
4472
4588
|
const results = await ctx.conversationsCollection.query(
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4589
|
+
import_watermelondb3.Q.where("project_id", projectId === null ? "" : projectId),
|
|
4590
|
+
import_watermelondb3.Q.where("is_deleted", false),
|
|
4591
|
+
import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)
|
|
4476
4592
|
).unsafeFetchRaw();
|
|
4477
4593
|
return Promise.all(
|
|
4478
4594
|
results.map(
|
|
@@ -4481,7 +4597,7 @@ async function getConversationsByProjectOp(ctx, projectId) {
|
|
|
4481
4597
|
);
|
|
4482
4598
|
}
|
|
4483
4599
|
async function getMessagesOp(ctx, convId, opts) {
|
|
4484
|
-
const fetched = await ctx.messagesCollection.query(
|
|
4600
|
+
const fetched = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId), import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.asc)).unsafeFetchRaw();
|
|
4485
4601
|
const results = opts?.rawFilter ? fetched.filter(opts.rawFilter) : fetched;
|
|
4486
4602
|
return Promise.all(
|
|
4487
4603
|
results.map(
|
|
@@ -4490,19 +4606,19 @@ async function getMessagesOp(ctx, convId, opts) {
|
|
|
4490
4606
|
);
|
|
4491
4607
|
}
|
|
4492
4608
|
async function getMessageCountOp(ctx, convId) {
|
|
4493
|
-
return await ctx.messagesCollection.query(
|
|
4609
|
+
return await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetchCount();
|
|
4494
4610
|
}
|
|
4495
4611
|
async function getMessagesPageOp(ctx, convId, opts) {
|
|
4496
4612
|
const limit = Math.floor(opts.limit);
|
|
4497
4613
|
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
4498
4614
|
const exclude = new Set(opts.boundaryExcludeUniqueIds ?? []);
|
|
4499
|
-
const clauses = [
|
|
4615
|
+
const clauses = [import_watermelondb3.Q.where("conversation_id", convId)];
|
|
4500
4616
|
if (opts.beforeMessageId !== void 0) {
|
|
4501
4617
|
clauses.push(
|
|
4502
|
-
exclude.size > 0 ?
|
|
4618
|
+
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))
|
|
4503
4619
|
);
|
|
4504
4620
|
}
|
|
4505
|
-
const fetched = await ctx.messagesCollection.query(...clauses,
|
|
4621
|
+
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();
|
|
4506
4622
|
const results = (exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched).slice(0, limit);
|
|
4507
4623
|
results.reverse();
|
|
4508
4624
|
return Promise.all(
|
|
@@ -4514,7 +4630,7 @@ async function getMessagesPageOp(ctx, convId, opts) {
|
|
|
4514
4630
|
);
|
|
4515
4631
|
}
|
|
4516
4632
|
async function getMessageSkeletonsOp(ctx, convId) {
|
|
4517
|
-
const results = await ctx.messagesCollection.query(
|
|
4633
|
+
const results = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId), import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.asc)).unsafeFetchRaw();
|
|
4518
4634
|
const roleById = /* @__PURE__ */ new Map();
|
|
4519
4635
|
for (const raw of results) {
|
|
4520
4636
|
roleById.set(raw.id, raw.role);
|
|
@@ -4559,32 +4675,12 @@ async function getMessageSkeletonsOp(ctx, convId) {
|
|
|
4559
4675
|
return skeletons;
|
|
4560
4676
|
}
|
|
4561
4677
|
async function getToolCallEventIdsOp(ctx, convId) {
|
|
4562
|
-
|
|
4563
|
-
const ids = /* @__PURE__ */ new Set();
|
|
4564
|
-
for (const raw of results) {
|
|
4565
|
-
const value = raw.tool_call_events;
|
|
4566
|
-
if (!value) continue;
|
|
4567
|
-
let events;
|
|
4568
|
-
if (typeof value === "string") {
|
|
4569
|
-
try {
|
|
4570
|
-
events = JSON.parse(value);
|
|
4571
|
-
} catch {
|
|
4572
|
-
continue;
|
|
4573
|
-
}
|
|
4574
|
-
} else if (Array.isArray(value)) {
|
|
4575
|
-
events = value;
|
|
4576
|
-
}
|
|
4577
|
-
if (!Array.isArray(events)) continue;
|
|
4578
|
-
for (const evt of events) {
|
|
4579
|
-
if (evt && evt.id) ids.add(evt.id);
|
|
4580
|
-
}
|
|
4581
|
-
}
|
|
4582
|
-
return ids;
|
|
4678
|
+
return getToolCallEventIds(ctx.messagesCollection, convId);
|
|
4583
4679
|
}
|
|
4584
4680
|
async function clearMessagesOp(ctx, convId) {
|
|
4585
4681
|
await ctx.database.write(async () => {
|
|
4586
|
-
const messages = await ctx.messagesCollection.query(
|
|
4587
|
-
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(
|
|
4682
|
+
const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetch();
|
|
4683
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", convId)).fetch() : [];
|
|
4588
4684
|
for (const job of jobs) {
|
|
4589
4685
|
await job.update((row) => {
|
|
4590
4686
|
row._setRaw("message_ids", "[]");
|
|
@@ -4609,7 +4705,7 @@ async function deleteMessageOp(ctx, uniqueId) {
|
|
|
4609
4705
|
return null;
|
|
4610
4706
|
}
|
|
4611
4707
|
await ctx.database.write(async () => {
|
|
4612
|
-
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(
|
|
4708
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", message.conversationId)).fetch() : [];
|
|
4613
4709
|
for (const job of jobs) {
|
|
4614
4710
|
const ids = JSON.parse(String(job._getRaw("message_ids")));
|
|
4615
4711
|
await job.update((row) => {
|
|
@@ -4682,9 +4778,9 @@ async function createMessageOp(ctx, opts) {
|
|
|
4682
4778
|
}
|
|
4683
4779
|
}
|
|
4684
4780
|
const newest = await ctx.messagesCollection.query(
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4781
|
+
import_watermelondb3.Q.where("conversation_id", opts.conversationId),
|
|
4782
|
+
import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.desc),
|
|
4783
|
+
import_watermelondb3.Q.take(1)
|
|
4688
4784
|
).fetch();
|
|
4689
4785
|
const messageId = (newest[0]?.messageId ?? 0) + 1;
|
|
4690
4786
|
const encryptedOpts = await encryptMessageOptsIfNeeded(ctx, opts);
|
|
@@ -4780,13 +4876,13 @@ async function decryptMessageEmbeddingFields(raw, walletAddress) {
|
|
|
4780
4876
|
async function sealLegacyMessageEmbeddingsOp(ctx) {
|
|
4781
4877
|
if (!ctx.walletAddress) return 0;
|
|
4782
4878
|
const candidateIds = await ctx.messagesCollection.query(
|
|
4783
|
-
|
|
4784
|
-
|
|
4879
|
+
import_watermelondb3.Q.where("content", import_watermelondb3.Q.like("enc:%")),
|
|
4880
|
+
import_watermelondb3.Q.or(
|
|
4785
4881
|
...["vector", "chunks"].map(
|
|
4786
|
-
(column) =>
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4882
|
+
(column) => import_watermelondb3.Q.and(
|
|
4883
|
+
import_watermelondb3.Q.where(column, import_watermelondb3.Q.notEq(null)),
|
|
4884
|
+
import_watermelondb3.Q.where(column, import_watermelondb3.Q.notEq("")),
|
|
4885
|
+
import_watermelondb3.Q.where(column, import_watermelondb3.Q.notLike("enc:%"))
|
|
4790
4886
|
)
|
|
4791
4887
|
)
|
|
4792
4888
|
)
|
|
@@ -4796,7 +4892,7 @@ async function sealLegacyMessageEmbeddingsOp(ctx) {
|
|
|
4796
4892
|
for (let start = 0; start < candidateIds.length; start += 50) {
|
|
4797
4893
|
const pageIds = candidateIds.slice(start, start + 50);
|
|
4798
4894
|
await ctx.database.write(async () => {
|
|
4799
|
-
const pageMessages = await ctx.messagesCollection.query(
|
|
4895
|
+
const pageMessages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).fetch();
|
|
4800
4896
|
for (const message of pageMessages) {
|
|
4801
4897
|
if (!isEncrypted(message.content)) continue;
|
|
4802
4898
|
const content = await decryptFieldDetailed(message.content, ctx.walletAddress);
|
|
@@ -4877,15 +4973,15 @@ function chunksWithoutText(raw) {
|
|
|
4877
4973
|
});
|
|
4878
4974
|
}
|
|
4879
4975
|
async function stripLegacyChunkTextOp(ctx) {
|
|
4880
|
-
const candidateIds = await ctx.messagesCollection.query(
|
|
4976
|
+
const candidateIds = await ctx.messagesCollection.query(import_watermelondb3.Q.where("chunks", import_watermelondb3.Q.like(`%${import_watermelondb3.Q.sanitizeLikeString('"text":')}%`))).fetchIds();
|
|
4881
4977
|
let stripped = 0;
|
|
4882
4978
|
for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
|
|
4883
4979
|
const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
|
|
4884
|
-
const rows = await ctx.messagesCollection.query(
|
|
4980
|
+
const rows = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).unsafeFetchRaw();
|
|
4885
4981
|
const changedIds = rows.filter((row) => chunksWithoutText(row.chunks) !== null).map((row) => String(row.id));
|
|
4886
4982
|
if (changedIds.length === 0) continue;
|
|
4887
4983
|
await ctx.database.write(async () => {
|
|
4888
|
-
const messages = await ctx.messagesCollection.query(
|
|
4984
|
+
const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(changedIds))).fetch();
|
|
4889
4985
|
const updates = messages.flatMap((message) => {
|
|
4890
4986
|
const raw = message._raw;
|
|
4891
4987
|
const chunks3 = chunksWithoutText(raw.chunks);
|
|
@@ -4932,13 +5028,13 @@ async function encryptToolCallEventsOp(ctx) {
|
|
|
4932
5028
|
return 0;
|
|
4933
5029
|
}
|
|
4934
5030
|
const candidateIds = await ctx.messagesCollection.query(
|
|
4935
|
-
|
|
4936
|
-
|
|
5031
|
+
import_watermelondb3.Q.where("tool_call_events", import_watermelondb3.Q.notEq(null)),
|
|
5032
|
+
import_watermelondb3.Q.where("tool_call_events", import_watermelondb3.Q.notIn(["", "[]"]))
|
|
4937
5033
|
).fetchIds();
|
|
4938
5034
|
let encrypted = 0;
|
|
4939
5035
|
for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
|
|
4940
5036
|
const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
|
|
4941
|
-
const rows = await ctx.messagesCollection.query(
|
|
5037
|
+
const rows = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).unsafeFetchRaw();
|
|
4942
5038
|
const repairs = /* @__PURE__ */ new Map();
|
|
4943
5039
|
for (const row of rows) {
|
|
4944
5040
|
const column = await encryptedToolCallEventsColumn(
|
|
@@ -4951,12 +5047,12 @@ async function encryptToolCallEventsOp(ctx) {
|
|
|
4951
5047
|
}
|
|
4952
5048
|
if (repairs.size === 0) continue;
|
|
4953
5049
|
await ctx.database.write(async () => {
|
|
4954
|
-
const messages = (await ctx.messagesCollection.query(
|
|
5050
|
+
const messages = (await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf([...repairs.keys()]))).fetch()).filter(
|
|
4955
5051
|
(message) => message._raw.tool_call_events === repairs.get(message.id)?.raw
|
|
4956
5052
|
);
|
|
4957
5053
|
if (messages.length === 0) return;
|
|
4958
5054
|
const conversationIds = [...new Set(messages.map((message) => message.conversationId))];
|
|
4959
|
-
const conversations = await ctx.conversationsCollection.query(
|
|
5055
|
+
const conversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", import_watermelondb3.Q.oneOf(conversationIds))).fetch();
|
|
4960
5056
|
await ctx.database.batch(
|
|
4961
5057
|
...messages.map(
|
|
4962
5058
|
(message) => message.prepareUpdate((msg) => {
|
|
@@ -4983,7 +5079,7 @@ async function savedKeyOpensExistingData(ctx, address, signMessage, embeddedWall
|
|
|
4983
5079
|
return refreshEncryptionKeyIfMatches(address, v2Probe, signMessage, embeddedWalletSigner);
|
|
4984
5080
|
}
|
|
4985
5081
|
async function findEncryptedContent(ctx, pattern) {
|
|
4986
|
-
const [row] = await ctx.messagesCollection.query(
|
|
5082
|
+
const [row] = await ctx.messagesCollection.query(import_watermelondb3.Q.where("content", import_watermelondb3.Q.like(pattern)), import_watermelondb3.Q.take(1)).unsafeFetchRaw();
|
|
4987
5083
|
return row ? String(row.content) : null;
|
|
4988
5084
|
}
|
|
4989
5085
|
async function updateMessageErrorOp(ctx, uniqueId, error) {
|
|
@@ -5102,11 +5198,11 @@ async function readRawJsonField(raw, column, walletAddress) {
|
|
|
5102
5198
|
}
|
|
5103
5199
|
async function searchMessagesOp(ctx, queryVector, options) {
|
|
5104
5200
|
const { limit = 10, minSimilarity = 0.5, conversationId } = options || {};
|
|
5105
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
5201
|
+
const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
5106
5202
|
const activeConversationIds = new Set(
|
|
5107
5203
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
5108
5204
|
);
|
|
5109
|
-
const queryConditions = conversationId ? [
|
|
5205
|
+
const queryConditions = conversationId ? [import_watermelondb3.Q.where("conversation_id", conversationId)] : [];
|
|
5110
5206
|
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
5111
5207
|
const candidates = [];
|
|
5112
5208
|
for (const message of messages) {
|
|
@@ -5145,7 +5241,7 @@ function toChunkCandidateKey(raw) {
|
|
|
5145
5241
|
}
|
|
5146
5242
|
async function fetchRowsByIds(ctx, ids) {
|
|
5147
5243
|
if (ids.length === 0) return [];
|
|
5148
|
-
return await ctx.messagesCollection.query(
|
|
5244
|
+
return await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))).unsafeFetchRaw();
|
|
5149
5245
|
}
|
|
5150
5246
|
async function projectedChunkRowSource(ctx, filter) {
|
|
5151
5247
|
const clauses = [
|
|
@@ -5163,7 +5259,7 @@ async function projectedChunkRowSource(ctx, filter) {
|
|
|
5163
5259
|
args.push(filter.excludeConversationId);
|
|
5164
5260
|
}
|
|
5165
5261
|
const keyRows = await ctx.messagesCollection.query(
|
|
5166
|
-
|
|
5262
|
+
import_watermelondb3.Q.unsafeSqlQuery(
|
|
5167
5263
|
`select "id", "conversation_id", "updated_at", "embedding_model" from "history" where ${clauses.join(" and ")}`,
|
|
5168
5264
|
args
|
|
5169
5265
|
)
|
|
@@ -5173,7 +5269,7 @@ async function projectedChunkRowSource(ctx, filter) {
|
|
|
5173
5269
|
loadVectorRows: async (ids) => {
|
|
5174
5270
|
if (ids.length === 0) return [];
|
|
5175
5271
|
return await ctx.messagesCollection.query(
|
|
5176
|
-
|
|
5272
|
+
import_watermelondb3.Q.unsafeSqlQuery(
|
|
5177
5273
|
`select "id", "updated_at", "chunks", "vector" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
5178
5274
|
ids
|
|
5179
5275
|
)
|
|
@@ -5183,11 +5279,11 @@ async function projectedChunkRowSource(ctx, filter) {
|
|
|
5183
5279
|
};
|
|
5184
5280
|
}
|
|
5185
5281
|
async function fullScanChunkRowSource(ctx, filter) {
|
|
5186
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
5282
|
+
const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
5187
5283
|
const activeConversationIds = new Set(
|
|
5188
5284
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
5189
5285
|
);
|
|
5190
|
-
const queryConditions = filter.conversationId !== void 0 ? [
|
|
5286
|
+
const queryConditions = filter.conversationId !== void 0 ? [import_watermelondb3.Q.where("conversation_id", filter.conversationId)] : [];
|
|
5191
5287
|
const rows = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
5192
5288
|
const rowsById = /* @__PURE__ */ new Map();
|
|
5193
5289
|
for (const row of rows) {
|
|
@@ -5394,12 +5490,12 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
5394
5490
|
}
|
|
5395
5491
|
async function getAllFilesOp(ctx, options) {
|
|
5396
5492
|
const { conversationId, limit } = options || {};
|
|
5397
|
-
const activeConversations = await ctx.conversationsCollection.query(
|
|
5493
|
+
const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
|
|
5398
5494
|
const activeConversationIds = new Set(
|
|
5399
5495
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
5400
5496
|
);
|
|
5401
|
-
const queryConditions = conversationId ? [
|
|
5402
|
-
const messages = await ctx.messagesCollection.query(...queryConditions,
|
|
5497
|
+
const queryConditions = conversationId ? [import_watermelondb3.Q.where("conversation_id", conversationId)] : [];
|
|
5498
|
+
const messages = await ctx.messagesCollection.query(...queryConditions, import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).fetch();
|
|
5403
5499
|
const filesWithContext = [];
|
|
5404
5500
|
for (const message of messages) {
|
|
5405
5501
|
const msgConvId = String(message._getRaw("conversation_id"));
|
|
@@ -7189,6 +7285,17 @@ function missingConfirmFields(action, parameters) {
|
|
|
7189
7285
|
return requirement.fields.filter((field10) => !shown.has(field10));
|
|
7190
7286
|
}
|
|
7191
7287
|
|
|
7288
|
+
// src/tools/walletPaymentConstants.ts
|
|
7289
|
+
var SELECT_PAYMENT_WALLET_TOOL_NAME = "select_payment_wallet";
|
|
7290
|
+
var WALLET_PAYMENT_TOOL_NAME = "prompt_wallet_payment";
|
|
7291
|
+
var FLIGHT_BOOK_TOOL_SET = "flight-book";
|
|
7292
|
+
var FLIGHT_SERVER_TOOL_NAMES = [
|
|
7293
|
+
"AnumaPaymentsMCP-anuma_search_flights",
|
|
7294
|
+
"AnumaPaymentsMCP-anuma_flight_offer_details",
|
|
7295
|
+
"AnumaPaymentsMCP-anuma_create_flight_intent",
|
|
7296
|
+
"AnumaPaymentsMCP-anuma_get_flight_booking"
|
|
7297
|
+
];
|
|
7298
|
+
|
|
7192
7299
|
// src/lib/chat/toolLoop.ts
|
|
7193
7300
|
init_redactor();
|
|
7194
7301
|
|
|
@@ -7965,7 +8072,8 @@ var BUILT_IN_TOOL_SETS = [
|
|
|
7965
8072
|
"AnumaPaymentsMCP-anuma_cancel_reservation"
|
|
7966
8073
|
],
|
|
7967
8074
|
anchors: []
|
|
7968
|
-
}
|
|
8075
|
+
},
|
|
8076
|
+
{ name: FLIGHT_BOOK_TOOL_SET, members: [...FLIGHT_SERVER_TOOL_NAMES], anchors: [] }
|
|
7969
8077
|
];
|
|
7970
8078
|
var CONFIRMED_ACTION_TOOL_SETS = /* @__PURE__ */ new Map([
|
|
7971
8079
|
["book_restaurant", "restaurant-book"],
|
|
@@ -8097,6 +8205,16 @@ var SERVER_TOOL_DEPENDENCY_SETS = [
|
|
|
8097
8205
|
members: ["AnumaPaymentsMCP-anuma_list_reservations"],
|
|
8098
8206
|
anchors: ["AnumaPaymentsMCP-anuma_cancel_reservation"],
|
|
8099
8207
|
anchorMinSimilarity: 0.5
|
|
8208
|
+
},
|
|
8209
|
+
{
|
|
8210
|
+
name: "flight-book-lookup",
|
|
8211
|
+
members: [
|
|
8212
|
+
"AnumaPaymentsMCP-anuma_flight_offer_details",
|
|
8213
|
+
"AnumaPaymentsMCP-anuma_create_flight_intent",
|
|
8214
|
+
"AnumaPaymentsMCP-anuma_get_flight_booking"
|
|
8215
|
+
],
|
|
8216
|
+
anchors: ["AnumaPaymentsMCP-anuma_search_flights"],
|
|
8217
|
+
anchorMinSimilarity: 0.5
|
|
8100
8218
|
}
|
|
8101
8219
|
];
|
|
8102
8220
|
var defaultServerToolsFilter = createServerToolsFilter({
|
|
@@ -10410,7 +10528,14 @@ function getToolName(tool) {
|
|
|
10410
10528
|
function toolsAfterConfirmation(apiTools, executionResults) {
|
|
10411
10529
|
const members = /* @__PURE__ */ new Set();
|
|
10412
10530
|
let keepConfirm = false;
|
|
10531
|
+
let keepPaymentTools = false;
|
|
10413
10532
|
for (const r of executionResults) {
|
|
10533
|
+
if (r.name === SELECT_PAYMENT_WALLET_TOOL_NAME && r.result?.confirmed === true) {
|
|
10534
|
+
const flightSet = BUILT_IN_TOOL_SETS.find((s) => s.name === FLIGHT_BOOK_TOOL_SET);
|
|
10535
|
+
for (const member of flightSet?.members ?? []) members.add(member);
|
|
10536
|
+
keepPaymentTools = true;
|
|
10537
|
+
continue;
|
|
10538
|
+
}
|
|
10414
10539
|
if (r.name !== CONFIRM_TOOL_NAME) continue;
|
|
10415
10540
|
const answer = r.result;
|
|
10416
10541
|
if (answer?.confirmed !== true || typeof answer.action !== "string") continue;
|
|
@@ -10422,7 +10547,7 @@ function toolsAfterConfirmation(apiTools, executionResults) {
|
|
|
10422
10547
|
if (!apiTools.some((t) => members.has(getToolName(t) ?? ""))) return void 0;
|
|
10423
10548
|
return apiTools.filter((t) => {
|
|
10424
10549
|
const name = getToolName(t) ?? "";
|
|
10425
|
-
return members.has(name) || name === TOOL_SEARCH_TOOL_NAME || keepConfirm && name === CONFIRM_TOOL_NAME;
|
|
10550
|
+
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);
|
|
10426
10551
|
});
|
|
10427
10552
|
}
|
|
10428
10553
|
var STREAM_RESUMABLE_HEADER = "X-Stream-Resumable";
|
|
@@ -11796,9 +11921,9 @@ function createWebSearchPreProcessor(options = {}) {
|
|
|
11796
11921
|
}
|
|
11797
11922
|
|
|
11798
11923
|
// src/lib/db/appFiles/models.ts
|
|
11799
|
-
var
|
|
11924
|
+
var import_watermelondb4 = require("@nozbe/watermelondb");
|
|
11800
11925
|
var import_decorators = require("@nozbe/watermelondb/decorators");
|
|
11801
|
-
var AppFile = class extends
|
|
11926
|
+
var AppFile = class extends import_watermelondb4.Model {
|
|
11802
11927
|
};
|
|
11803
11928
|
AppFile.table = "app_files";
|
|
11804
11929
|
AppFile.associations = {};
|
|
@@ -11820,7 +11945,7 @@ __decorateClass([
|
|
|
11820
11945
|
], AppFile.prototype, "updatedAt", 2);
|
|
11821
11946
|
|
|
11822
11947
|
// src/lib/db/appFiles/operations.ts
|
|
11823
|
-
var
|
|
11948
|
+
var import_watermelondb5 = require("@nozbe/watermelondb");
|
|
11824
11949
|
|
|
11825
11950
|
// src/utils/paths.ts
|
|
11826
11951
|
function normalizePath(p) {
|
|
@@ -11846,7 +11971,7 @@ async function putAppFileOp(ctx, conversationId, path, content) {
|
|
|
11846
11971
|
const normalized = normalizePath(path);
|
|
11847
11972
|
const now = Date.now();
|
|
11848
11973
|
const result = await ctx.database.write(async () => {
|
|
11849
|
-
const existing = await ctx.appFilesCollection.query(
|
|
11974
|
+
const existing = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId), import_watermelondb5.Q.where("path", normalized)).fetch();
|
|
11850
11975
|
if (existing.length > 0) {
|
|
11851
11976
|
await existing[0].update((f) => {
|
|
11852
11977
|
f._setRaw("content", content);
|
|
@@ -11866,11 +11991,11 @@ async function putAppFileOp(ctx, conversationId, path, content) {
|
|
|
11866
11991
|
}
|
|
11867
11992
|
async function getAppFileOp(ctx, conversationId, path) {
|
|
11868
11993
|
const normalized = normalizePath(path);
|
|
11869
|
-
const results = await ctx.appFilesCollection.query(
|
|
11994
|
+
const results = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId), import_watermelondb5.Q.where("path", normalized)).fetch();
|
|
11870
11995
|
return results.length > 0 ? appFileToStored(results[0]) : null;
|
|
11871
11996
|
}
|
|
11872
11997
|
async function getAppFilesOp(ctx, conversationId) {
|
|
11873
|
-
const results = await ctx.appFilesCollection.query(
|
|
11998
|
+
const results = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId)).fetch();
|
|
11874
11999
|
return results.map(appFileToStored);
|
|
11875
12000
|
}
|
|
11876
12001
|
async function getAppFileMapOp(ctx, conversationId) {
|
|
@@ -11881,7 +12006,7 @@ async function getAppFileMapOp(ctx, conversationId) {
|
|
|
11881
12006
|
}
|
|
11882
12007
|
async function deleteAppFileOp(ctx, conversationId, path) {
|
|
11883
12008
|
const normalized = normalizePath(path);
|
|
11884
|
-
const results = await ctx.appFilesCollection.query(
|
|
12009
|
+
const results = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId), import_watermelondb5.Q.where("path", normalized)).fetch();
|
|
11885
12010
|
if (results.length === 0) return false;
|
|
11886
12011
|
await ctx.database.write(async () => {
|
|
11887
12012
|
await results[0].destroyPermanently();
|
|
@@ -11889,7 +12014,7 @@ async function deleteAppFileOp(ctx, conversationId, path) {
|
|
|
11889
12014
|
return true;
|
|
11890
12015
|
}
|
|
11891
12016
|
async function deleteAllAppFilesOp(ctx, conversationId) {
|
|
11892
|
-
const results = await ctx.appFilesCollection.query(
|
|
12017
|
+
const results = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId)).fetch();
|
|
11893
12018
|
if (results.length === 0) return;
|
|
11894
12019
|
await ctx.database.write(async () => {
|
|
11895
12020
|
const batch = results.map((file) => file.prepareDestroyPermanently());
|
|
@@ -11962,9 +12087,9 @@ async function decryptConversationTitle(encryptedTitle, address) {
|
|
|
11962
12087
|
}
|
|
11963
12088
|
|
|
11964
12089
|
// src/lib/db/chat/models.ts
|
|
11965
|
-
var
|
|
12090
|
+
var import_watermelondb6 = require("@nozbe/watermelondb");
|
|
11966
12091
|
var import_decorators2 = require("@nozbe/watermelondb/decorators");
|
|
11967
|
-
var Message = class extends
|
|
12092
|
+
var Message = class extends import_watermelondb6.Model {
|
|
11968
12093
|
};
|
|
11969
12094
|
Message.table = "history";
|
|
11970
12095
|
Message.associations = {
|
|
@@ -12043,7 +12168,7 @@ __decorateClass([
|
|
|
12043
12168
|
__decorateClass([
|
|
12044
12169
|
(0, import_decorators2.text)("origin")
|
|
12045
12170
|
], Message.prototype, "origin", 2);
|
|
12046
|
-
var Conversation = class extends
|
|
12171
|
+
var Conversation = class extends import_watermelondb6.Model {
|
|
12047
12172
|
};
|
|
12048
12173
|
Conversation.table = "conversations";
|
|
12049
12174
|
Conversation.associations = {
|
|
@@ -12071,7 +12196,7 @@ __decorateClass([
|
|
|
12071
12196
|
__decorateClass([
|
|
12072
12197
|
(0, import_decorators2.date)("pinned_at")
|
|
12073
12198
|
], Conversation.prototype, "pinnedAt", 2);
|
|
12074
|
-
var ConversationSummary = class extends
|
|
12199
|
+
var ConversationSummary = class extends import_watermelondb6.Model {
|
|
12075
12200
|
};
|
|
12076
12201
|
ConversationSummary.table = "conversation_summaries";
|
|
12077
12202
|
ConversationSummary.associations = {
|
|
@@ -12097,12 +12222,12 @@ __decorateClass([
|
|
|
12097
12222
|
], ConversationSummary.prototype, "updatedAt", 2);
|
|
12098
12223
|
|
|
12099
12224
|
// src/lib/db/chat/schema.ts
|
|
12100
|
-
var
|
|
12225
|
+
var import_watermelondb7 = require("@nozbe/watermelondb");
|
|
12101
12226
|
var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
|
|
12102
|
-
var chatStorageSchema = (0,
|
|
12227
|
+
var chatStorageSchema = (0, import_watermelondb7.appSchema)({
|
|
12103
12228
|
version: 7,
|
|
12104
12229
|
tables: [
|
|
12105
|
-
(0,
|
|
12230
|
+
(0, import_watermelondb7.tableSchema)({
|
|
12106
12231
|
name: "history",
|
|
12107
12232
|
columns: [
|
|
12108
12233
|
{ name: "message_id", type: "number" },
|
|
@@ -12126,7 +12251,7 @@ var chatStorageSchema = (0, import_watermelondb6.appSchema)({
|
|
|
12126
12251
|
{ name: "thinking", type: "string", isOptional: true }
|
|
12127
12252
|
]
|
|
12128
12253
|
}),
|
|
12129
|
-
(0,
|
|
12254
|
+
(0, import_watermelondb7.tableSchema)({
|
|
12130
12255
|
name: "conversations",
|
|
12131
12256
|
columns: [
|
|
12132
12257
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -12198,7 +12323,7 @@ var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
|
|
|
12198
12323
|
});
|
|
12199
12324
|
|
|
12200
12325
|
// src/lib/db/chat/summaryOperations.ts
|
|
12201
|
-
var
|
|
12326
|
+
var import_watermelondb8 = require("@nozbe/watermelondb");
|
|
12202
12327
|
function createSummaryContext(database) {
|
|
12203
12328
|
return {
|
|
12204
12329
|
database,
|
|
@@ -12217,14 +12342,14 @@ function modelToStored(record2) {
|
|
|
12217
12342
|
};
|
|
12218
12343
|
}
|
|
12219
12344
|
async function getConversationSummaryOp(ctx, conversationId) {
|
|
12220
|
-
const results = await ctx.summariesCollection.query(
|
|
12345
|
+
const results = await ctx.summariesCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId)).fetch();
|
|
12221
12346
|
if (results.length === 0) return null;
|
|
12222
12347
|
return modelToStored(results[0]);
|
|
12223
12348
|
}
|
|
12224
12349
|
async function upsertConversationSummaryOp(ctx, conversationId, summary, summarizedUpTo, tokenCount) {
|
|
12225
12350
|
let record2;
|
|
12226
12351
|
await ctx.database.write(async () => {
|
|
12227
|
-
const existing = await ctx.summariesCollection.query(
|
|
12352
|
+
const existing = await ctx.summariesCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId)).fetch();
|
|
12228
12353
|
if (existing.length > 0) {
|
|
12229
12354
|
record2 = await existing[0].update((rec) => {
|
|
12230
12355
|
rec.summary = summary;
|
|
@@ -12244,7 +12369,7 @@ async function upsertConversationSummaryOp(ctx, conversationId, summary, summari
|
|
|
12244
12369
|
}
|
|
12245
12370
|
async function deleteConversationSummaryOp(ctx, conversationId) {
|
|
12246
12371
|
await ctx.database.write(async () => {
|
|
12247
|
-
const existing = await ctx.summariesCollection.query(
|
|
12372
|
+
const existing = await ctx.summariesCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId)).fetch();
|
|
12248
12373
|
for (const record2 of existing) {
|
|
12249
12374
|
await record2.destroyPermanently();
|
|
12250
12375
|
}
|
|
@@ -12252,9 +12377,9 @@ async function deleteConversationSummaryOp(ctx, conversationId) {
|
|
|
12252
12377
|
}
|
|
12253
12378
|
|
|
12254
12379
|
// src/lib/db/conversationMemory/models.ts
|
|
12255
|
-
var
|
|
12380
|
+
var import_watermelondb9 = require("@nozbe/watermelondb");
|
|
12256
12381
|
var import_decorators3 = require("@nozbe/watermelondb/decorators");
|
|
12257
|
-
var ConversationMemory = class extends
|
|
12382
|
+
var ConversationMemory = class extends import_watermelondb9.Model {
|
|
12258
12383
|
};
|
|
12259
12384
|
ConversationMemory.table = "conversation_memory";
|
|
12260
12385
|
ConversationMemory.associations = {};
|
|
@@ -12273,7 +12398,7 @@ __decorateClass([
|
|
|
12273
12398
|
], ConversationMemory.prototype, "createdAt", 2);
|
|
12274
12399
|
|
|
12275
12400
|
// src/lib/db/conversationMemory/operations.ts
|
|
12276
|
-
var
|
|
12401
|
+
var import_watermelondb10 = require("@nozbe/watermelondb");
|
|
12277
12402
|
var MAX_PER_CONVERSATION = 200;
|
|
12278
12403
|
function conversationMemoryToStored(row) {
|
|
12279
12404
|
return {
|
|
@@ -12288,7 +12413,7 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
12288
12413
|
if (!conversationId || items.length === 0) return;
|
|
12289
12414
|
const now = Date.now();
|
|
12290
12415
|
await ctx.database.write(async () => {
|
|
12291
|
-
const existing = await ctx.conversationMemoryCollection.query(
|
|
12416
|
+
const existing = await ctx.conversationMemoryCollection.query(import_watermelondb10.Q.where("conversation_id", conversationId), import_watermelondb10.Q.sortBy("created_at", import_watermelondb10.Q.asc)).fetch();
|
|
12292
12417
|
const seen = new Set(existing.map((r) => r.memoryId));
|
|
12293
12418
|
const batchSeen = /* @__PURE__ */ new Set();
|
|
12294
12419
|
const deduped = [];
|
|
@@ -12318,22 +12443,22 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
|
|
|
12318
12443
|
}
|
|
12319
12444
|
async function getConversationMemoriesOp(ctx, conversationId) {
|
|
12320
12445
|
if (!conversationId) return [];
|
|
12321
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
12446
|
+
const rows = await ctx.conversationMemoryCollection.query(import_watermelondb10.Q.where("conversation_id", conversationId), import_watermelondb10.Q.sortBy("created_at", import_watermelondb10.Q.asc)).fetch();
|
|
12322
12447
|
return rows.map(conversationMemoryToStored);
|
|
12323
12448
|
}
|
|
12324
12449
|
async function clearConversationMemoriesOp(ctx, conversationId) {
|
|
12325
12450
|
if (!conversationId) return;
|
|
12326
12451
|
await ctx.database.write(async () => {
|
|
12327
|
-
const rows = await ctx.conversationMemoryCollection.query(
|
|
12452
|
+
const rows = await ctx.conversationMemoryCollection.query(import_watermelondb10.Q.where("conversation_id", conversationId)).fetch();
|
|
12328
12453
|
if (rows.length === 0) return;
|
|
12329
12454
|
await ctx.database.batch(...rows.map((r) => r.prepareDestroyPermanently()));
|
|
12330
12455
|
});
|
|
12331
12456
|
}
|
|
12332
12457
|
|
|
12333
12458
|
// src/lib/db/entities/models.ts
|
|
12334
|
-
var
|
|
12459
|
+
var import_watermelondb11 = require("@nozbe/watermelondb");
|
|
12335
12460
|
var import_decorators4 = require("@nozbe/watermelondb/decorators");
|
|
12336
|
-
var Entity = class extends
|
|
12461
|
+
var Entity = class extends import_watermelondb11.Model {
|
|
12337
12462
|
};
|
|
12338
12463
|
Entity.table = "entity";
|
|
12339
12464
|
__decorateClass([
|
|
@@ -12349,7 +12474,7 @@ __decorateClass([
|
|
|
12349
12474
|
__decorateClass([
|
|
12350
12475
|
(0, import_decorators4.date)("updated_at")
|
|
12351
12476
|
], Entity.prototype, "updatedAt", 2);
|
|
12352
|
-
var MemoryEntity = class extends
|
|
12477
|
+
var MemoryEntity = class extends import_watermelondb11.Model {
|
|
12353
12478
|
};
|
|
12354
12479
|
MemoryEntity.table = "memory_entity";
|
|
12355
12480
|
__decorateClass([
|
|
@@ -12367,7 +12492,7 @@ __decorateClass([
|
|
|
12367
12492
|
], MemoryEntity.prototype, "createdAt", 2);
|
|
12368
12493
|
|
|
12369
12494
|
// src/lib/db/entities/operations.ts
|
|
12370
|
-
var
|
|
12495
|
+
var import_watermelondb12 = require("@nozbe/watermelondb");
|
|
12371
12496
|
|
|
12372
12497
|
// src/lib/db/memoryVault/types.ts
|
|
12373
12498
|
var MEMORY_KINDS = [
|
|
@@ -12516,7 +12641,7 @@ async function upsertEntitiesInWrite(ctx, entities) {
|
|
|
12516
12641
|
const unique = Array.from(kindByName.keys());
|
|
12517
12642
|
const out = /* @__PURE__ */ new Map();
|
|
12518
12643
|
if (unique.length === 0) return { entities: out, operations: [], kindBackfills: [] };
|
|
12519
|
-
const existing = await ctx.entityCollection.query(
|
|
12644
|
+
const existing = await ctx.entityCollection.query(import_watermelondb12.Q.where("canonical_name", import_watermelondb12.Q.oneOf(unique))).fetch();
|
|
12520
12645
|
const existingNames = new Set(existing.map((e) => e.canonicalName));
|
|
12521
12646
|
const kindBackfills = existing.filter((e) => {
|
|
12522
12647
|
const incoming = kindByName.get(e.canonicalName);
|
|
@@ -12546,7 +12671,7 @@ function prepareKindBackfills(backfills) {
|
|
|
12546
12671
|
}
|
|
12547
12672
|
async function findVaultRowInWrite(ctx, memoryId) {
|
|
12548
12673
|
try {
|
|
12549
|
-
const rows = await ctx.database.get("memory_vault").query(
|
|
12674
|
+
const rows = await ctx.database.get("memory_vault").query(import_watermelondb12.Q.where("id", memoryId)).fetch();
|
|
12550
12675
|
return rows[0] ?? null;
|
|
12551
12676
|
} catch {
|
|
12552
12677
|
return null;
|
|
@@ -12648,7 +12773,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
12648
12773
|
return;
|
|
12649
12774
|
}
|
|
12650
12775
|
if (entities.length === 0) return;
|
|
12651
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
12776
|
+
const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("memory_id", memoryId)).fetch();
|
|
12652
12777
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
12653
12778
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
12654
12779
|
const keptIds = entities.map((e) => e.uniqueId);
|
|
@@ -12684,7 +12809,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
12684
12809
|
}
|
|
12685
12810
|
async function resolveEntitiesByIds(ctx, entityIds) {
|
|
12686
12811
|
if (entityIds.length === 0) return [];
|
|
12687
|
-
const rows = await ctx.entityCollection.query(
|
|
12812
|
+
const rows = await ctx.entityCollection.query(import_watermelondb12.Q.where("id", import_watermelondb12.Q.oneOf(Array.from(entityIds)))).fetch();
|
|
12688
12813
|
return rows.map(entityToStored);
|
|
12689
12814
|
}
|
|
12690
12815
|
function autoLinkBlocked(row) {
|
|
@@ -12720,7 +12845,7 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
12720
12845
|
kindBackfills
|
|
12721
12846
|
} = await upsertEntitiesInWrite(ctx, normalized);
|
|
12722
12847
|
entities = Array.from(byName.values());
|
|
12723
|
-
const existingLinks = await ctx.memoryEntityCollection.query(
|
|
12848
|
+
const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("memory_id", memoryId)).fetch();
|
|
12724
12849
|
const keep = new Set(entities.map((e) => e.uniqueId));
|
|
12725
12850
|
const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
|
|
12726
12851
|
const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
|
|
@@ -12756,17 +12881,17 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
12756
12881
|
async function findOrphanedEntities(ctx, memoryId, toDestroy) {
|
|
12757
12882
|
const candidateIds = [...new Set(toDestroy.map((l) => String(l.entityId)))];
|
|
12758
12883
|
if (candidateIds.length === 0) return [];
|
|
12759
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
12884
|
+
const links = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("entity_id", import_watermelondb12.Q.oneOf(candidateIds))).fetch();
|
|
12760
12885
|
const stillLinked = new Set(
|
|
12761
12886
|
links.filter((l) => String(l.memoryId) !== memoryId).map((l) => String(l.entityId))
|
|
12762
12887
|
);
|
|
12763
12888
|
const orphanIds = candidateIds.filter((id) => !stillLinked.has(id));
|
|
12764
12889
|
if (orphanIds.length === 0) return [];
|
|
12765
|
-
return await ctx.entityCollection.query(
|
|
12890
|
+
return await ctx.entityCollection.query(import_watermelondb12.Q.where("id", import_watermelondb12.Q.oneOf(orphanIds))).fetch();
|
|
12766
12891
|
}
|
|
12767
12892
|
async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
12768
12893
|
if (memoryIds.length === 0) return;
|
|
12769
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
12894
|
+
const links = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("memory_id", import_watermelondb12.Q.oneOf(Array.from(memoryIds)))).fetch();
|
|
12770
12895
|
if (links.length === 0) return;
|
|
12771
12896
|
await ctx.database.write(async () => {
|
|
12772
12897
|
await assertCanWrite(ctx);
|
|
@@ -12775,7 +12900,7 @@ async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
|
|
|
12775
12900
|
}
|
|
12776
12901
|
async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
12777
12902
|
if (!userId) return;
|
|
12778
|
-
const links = await ctx.memoryEntityCollection.query(
|
|
12903
|
+
const links = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("user_id", userId)).fetch();
|
|
12779
12904
|
if (links.length === 0) return;
|
|
12780
12905
|
await ctx.database.write(async () => {
|
|
12781
12906
|
await assertCanWrite(ctx);
|
|
@@ -12783,7 +12908,7 @@ async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
|
|
|
12783
12908
|
});
|
|
12784
12909
|
}
|
|
12785
12910
|
async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
12786
|
-
const unstamped = await ctx.memoryEntityCollection.query(
|
|
12911
|
+
const unstamped = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("user_id", null)).fetch();
|
|
12787
12912
|
if (unstamped.length === 0) return 0;
|
|
12788
12913
|
const toUpdate = [];
|
|
12789
12914
|
for (const link of unstamped) {
|
|
@@ -12808,15 +12933,15 @@ async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
|
|
|
12808
12933
|
async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
12809
12934
|
const unique = Array.from(new Set(entityNames.map(normalizeEntityName).filter((n) => n.length > 0)));
|
|
12810
12935
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
12811
|
-
const entityRows = await ctx.entityCollection.query(
|
|
12936
|
+
const entityRows = await ctx.entityCollection.query(import_watermelondb12.Q.where("canonical_name", import_watermelondb12.Q.oneOf(unique))).fetch();
|
|
12812
12937
|
if (entityRows.length === 0) return /* @__PURE__ */ new Map();
|
|
12813
12938
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
12814
|
-
const linkConditions = [
|
|
12939
|
+
const linkConditions = [import_watermelondb12.Q.where("entity_id", import_watermelondb12.Q.oneOf(entityRows.map((e) => e.id)))];
|
|
12815
12940
|
if (ctx.userId !== void 0) {
|
|
12816
12941
|
if (ctx.allowUnscopedRows) {
|
|
12817
|
-
linkConditions.push(
|
|
12942
|
+
linkConditions.push(import_watermelondb12.Q.or(import_watermelondb12.Q.where("user_id", ctx.userId), import_watermelondb12.Q.where("user_id", null)));
|
|
12818
12943
|
} else {
|
|
12819
|
-
linkConditions.push(
|
|
12944
|
+
linkConditions.push(import_watermelondb12.Q.where("user_id", ctx.userId));
|
|
12820
12945
|
}
|
|
12821
12946
|
}
|
|
12822
12947
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
@@ -12837,18 +12962,18 @@ async function getMemoriesByEntityNamesOp(ctx, entityNames) {
|
|
|
12837
12962
|
async function getEntitiesByMemoryIdsOp(ctx, memoryIds) {
|
|
12838
12963
|
const unique = Array.from(new Set(memoryIds.filter((id) => id.length > 0)));
|
|
12839
12964
|
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
12840
|
-
const linkConditions = [
|
|
12965
|
+
const linkConditions = [import_watermelondb12.Q.where("memory_id", import_watermelondb12.Q.oneOf(unique))];
|
|
12841
12966
|
if (ctx.userId !== void 0) {
|
|
12842
12967
|
if (ctx.allowUnscopedRows) {
|
|
12843
|
-
linkConditions.push(
|
|
12968
|
+
linkConditions.push(import_watermelondb12.Q.or(import_watermelondb12.Q.where("user_id", ctx.userId), import_watermelondb12.Q.where("user_id", null)));
|
|
12844
12969
|
} else {
|
|
12845
|
-
linkConditions.push(
|
|
12970
|
+
linkConditions.push(import_watermelondb12.Q.where("user_id", ctx.userId));
|
|
12846
12971
|
}
|
|
12847
12972
|
}
|
|
12848
12973
|
const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
|
|
12849
12974
|
if (links.length === 0) return /* @__PURE__ */ new Map();
|
|
12850
12975
|
const entityIds = Array.from(new Set(links.map((l) => String(l.entityId))));
|
|
12851
|
-
const entityRows = await ctx.entityCollection.query(
|
|
12976
|
+
const entityRows = await ctx.entityCollection.query(import_watermelondb12.Q.where("id", import_watermelondb12.Q.oneOf(entityIds))).fetch();
|
|
12852
12977
|
const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
|
|
12853
12978
|
const out = /* @__PURE__ */ new Map();
|
|
12854
12979
|
for (const link of links) {
|
|
@@ -12866,16 +12991,16 @@ async function getEntitiesByMemoryIdsOp(ctx, memoryIds) {
|
|
|
12866
12991
|
}
|
|
12867
12992
|
|
|
12868
12993
|
// src/lib/db/manager.ts
|
|
12869
|
-
var
|
|
12994
|
+
var import_watermelondb21 = require("@nozbe/watermelondb");
|
|
12870
12995
|
|
|
12871
12996
|
// src/lib/db/schema.ts
|
|
12872
|
-
var
|
|
12997
|
+
var import_watermelondb20 = require("@nozbe/watermelondb");
|
|
12873
12998
|
var import_migrations2 = require("@nozbe/watermelondb/Schema/migrations");
|
|
12874
12999
|
|
|
12875
13000
|
// src/lib/db/media/models.ts
|
|
12876
|
-
var
|
|
13001
|
+
var import_watermelondb13 = require("@nozbe/watermelondb");
|
|
12877
13002
|
var import_decorators5 = require("@nozbe/watermelondb/decorators");
|
|
12878
|
-
var Media = class extends
|
|
13003
|
+
var Media = class extends import_watermelondb13.Model {
|
|
12879
13004
|
};
|
|
12880
13005
|
Media.table = "media";
|
|
12881
13006
|
Media.associations = {
|
|
@@ -12936,9 +13061,9 @@ __decorateClass([
|
|
|
12936
13061
|
], Media.prototype, "isDeleted", 2);
|
|
12937
13062
|
|
|
12938
13063
|
// src/lib/db/memoryVault/models.ts
|
|
12939
|
-
var
|
|
13064
|
+
var import_watermelondb14 = require("@nozbe/watermelondb");
|
|
12940
13065
|
var import_decorators6 = require("@nozbe/watermelondb/decorators");
|
|
12941
|
-
var VaultMemory = class extends
|
|
13066
|
+
var VaultMemory = class extends import_watermelondb14.Model {
|
|
12942
13067
|
};
|
|
12943
13068
|
VaultMemory.table = "memory_vault";
|
|
12944
13069
|
__decorateClass([
|
|
@@ -13046,9 +13171,9 @@ __decorateClass([
|
|
|
13046
13171
|
], VaultMemory.prototype, "isDeleted", 2);
|
|
13047
13172
|
|
|
13048
13173
|
// src/lib/db/project/models.ts
|
|
13049
|
-
var
|
|
13174
|
+
var import_watermelondb15 = require("@nozbe/watermelondb");
|
|
13050
13175
|
var import_decorators7 = require("@nozbe/watermelondb/decorators");
|
|
13051
|
-
var Project = class extends
|
|
13176
|
+
var Project = class extends import_watermelondb15.Model {
|
|
13052
13177
|
};
|
|
13053
13178
|
Project.table = "projects";
|
|
13054
13179
|
Project.associations = {
|
|
@@ -13071,10 +13196,10 @@ __decorateClass([
|
|
|
13071
13196
|
], Project.prototype, "isDeleted", 2);
|
|
13072
13197
|
|
|
13073
13198
|
// src/lib/db/savedTools/models.ts
|
|
13074
|
-
var
|
|
13199
|
+
var import_watermelondb16 = require("@nozbe/watermelondb");
|
|
13075
13200
|
var import_decorators8 = require("@nozbe/watermelondb/decorators");
|
|
13076
13201
|
var sanitizeParameters = (raw) => raw ?? {};
|
|
13077
|
-
var SavedTool = class extends
|
|
13202
|
+
var SavedTool = class extends import_watermelondb16.Model {
|
|
13078
13203
|
};
|
|
13079
13204
|
SavedTool.table = "saved_tools";
|
|
13080
13205
|
SavedTool.associations = {};
|
|
@@ -13108,9 +13233,9 @@ __decorateClass([
|
|
|
13108
13233
|
], SavedTool.prototype, "isDeleted", 2);
|
|
13109
13234
|
|
|
13110
13235
|
// src/lib/db/settings/models.ts
|
|
13111
|
-
var
|
|
13236
|
+
var import_watermelondb17 = require("@nozbe/watermelondb");
|
|
13112
13237
|
var import_decorators9 = require("@nozbe/watermelondb/decorators");
|
|
13113
|
-
var ModelPreference = class extends
|
|
13238
|
+
var ModelPreference = class extends import_watermelondb17.Model {
|
|
13114
13239
|
};
|
|
13115
13240
|
ModelPreference.table = "modelPreferences";
|
|
13116
13241
|
__decorateClass([
|
|
@@ -13121,9 +13246,9 @@ __decorateClass([
|
|
|
13121
13246
|
], ModelPreference.prototype, "models", 2);
|
|
13122
13247
|
|
|
13123
13248
|
// src/lib/db/userPreferences/models.ts
|
|
13124
|
-
var
|
|
13249
|
+
var import_watermelondb18 = require("@nozbe/watermelondb");
|
|
13125
13250
|
var import_decorators10 = require("@nozbe/watermelondb/decorators");
|
|
13126
|
-
var UserPreference = class extends
|
|
13251
|
+
var UserPreference = class extends import_watermelondb18.Model {
|
|
13127
13252
|
};
|
|
13128
13253
|
UserPreference.table = "userPreferences";
|
|
13129
13254
|
__decorateClass([
|
|
@@ -13144,6 +13269,9 @@ __decorateClass([
|
|
|
13144
13269
|
__decorateClass([
|
|
13145
13270
|
(0, import_decorators10.text)("personality")
|
|
13146
13271
|
], UserPreference.prototype, "personality", 2);
|
|
13272
|
+
__decorateClass([
|
|
13273
|
+
(0, import_decorators10.text)("external_wallets")
|
|
13274
|
+
], UserPreference.prototype, "externalWallets", 2);
|
|
13147
13275
|
__decorateClass([
|
|
13148
13276
|
(0, import_decorators10.field)("created_at")
|
|
13149
13277
|
], UserPreference.prototype, "createdAt", 2);
|
|
@@ -13152,9 +13280,9 @@ __decorateClass([
|
|
|
13152
13280
|
], UserPreference.prototype, "updatedAt", 2);
|
|
13153
13281
|
|
|
13154
13282
|
// src/lib/db/vaultFolders/models.ts
|
|
13155
|
-
var
|
|
13283
|
+
var import_watermelondb19 = require("@nozbe/watermelondb");
|
|
13156
13284
|
var import_decorators11 = require("@nozbe/watermelondb/decorators");
|
|
13157
|
-
var VaultFolder = class extends
|
|
13285
|
+
var VaultFolder = class extends import_watermelondb19.Model {
|
|
13158
13286
|
};
|
|
13159
13287
|
VaultFolder.table = "vault_folders";
|
|
13160
13288
|
__decorateClass([
|
|
@@ -13181,11 +13309,11 @@ __decorateClass([
|
|
|
13181
13309
|
], VaultFolder.prototype, "context", 2);
|
|
13182
13310
|
|
|
13183
13311
|
// src/lib/db/schema.ts
|
|
13184
|
-
var SDK_SCHEMA_VERSION =
|
|
13185
|
-
var sdkSchema = (0,
|
|
13312
|
+
var SDK_SCHEMA_VERSION = 49;
|
|
13313
|
+
var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
13186
13314
|
version: SDK_SCHEMA_VERSION,
|
|
13187
13315
|
tables: [
|
|
13188
|
-
(0,
|
|
13316
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13189
13317
|
name: "memory_extraction_jobs",
|
|
13190
13318
|
columns: [
|
|
13191
13319
|
{ name: "owner_key", type: "string", isIndexed: true },
|
|
@@ -13200,7 +13328,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13200
13328
|
{ name: "failed_at", type: "number", isOptional: true }
|
|
13201
13329
|
]
|
|
13202
13330
|
}),
|
|
13203
|
-
(0,
|
|
13331
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13204
13332
|
name: "history",
|
|
13205
13333
|
columns: [
|
|
13206
13334
|
{ name: "message_id", type: "number" },
|
|
@@ -13229,7 +13357,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13229
13357
|
{ name: "origin", type: "string", isOptional: true }
|
|
13230
13358
|
]
|
|
13231
13359
|
}),
|
|
13232
|
-
(0,
|
|
13360
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13233
13361
|
name: "conversations",
|
|
13234
13362
|
columns: [
|
|
13235
13363
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -13241,7 +13369,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13241
13369
|
{ name: "pinned_at", type: "number", isOptional: true }
|
|
13242
13370
|
]
|
|
13243
13371
|
}),
|
|
13244
|
-
(0,
|
|
13372
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13245
13373
|
name: "projects",
|
|
13246
13374
|
columns: [
|
|
13247
13375
|
{ name: "project_id", type: "string", isIndexed: true },
|
|
@@ -13251,14 +13379,14 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13251
13379
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
13252
13380
|
]
|
|
13253
13381
|
}),
|
|
13254
|
-
(0,
|
|
13382
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13255
13383
|
name: "modelPreferences",
|
|
13256
13384
|
columns: [
|
|
13257
13385
|
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
13258
13386
|
{ name: "models", type: "string", isOptional: true }
|
|
13259
13387
|
]
|
|
13260
13388
|
}),
|
|
13261
|
-
(0,
|
|
13389
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13262
13390
|
name: "userPreferences",
|
|
13263
13391
|
columns: [
|
|
13264
13392
|
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
@@ -13267,11 +13395,12 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13267
13395
|
{ name: "description", type: "string", isOptional: true },
|
|
13268
13396
|
{ name: "models", type: "string", isOptional: true },
|
|
13269
13397
|
{ name: "personality", type: "string", isOptional: true },
|
|
13398
|
+
{ name: "external_wallets", type: "string", isOptional: true },
|
|
13270
13399
|
{ name: "created_at", type: "number" },
|
|
13271
13400
|
{ name: "updated_at", type: "number" }
|
|
13272
13401
|
]
|
|
13273
13402
|
}),
|
|
13274
|
-
(0,
|
|
13403
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13275
13404
|
name: "memory_vault",
|
|
13276
13405
|
columns: [
|
|
13277
13406
|
{ name: "content", type: "string" },
|
|
@@ -13310,7 +13439,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13310
13439
|
{ name: "geohash", type: "string", isOptional: true }
|
|
13311
13440
|
]
|
|
13312
13441
|
}),
|
|
13313
|
-
(0,
|
|
13442
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13314
13443
|
name: "entity",
|
|
13315
13444
|
columns: [
|
|
13316
13445
|
{ name: "canonical_name", type: "string", isIndexed: true },
|
|
@@ -13319,7 +13448,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13319
13448
|
{ name: "updated_at", type: "number" }
|
|
13320
13449
|
]
|
|
13321
13450
|
}),
|
|
13322
|
-
(0,
|
|
13451
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13323
13452
|
name: "memory_entity",
|
|
13324
13453
|
columns: [
|
|
13325
13454
|
{ name: "memory_id", type: "string", isIndexed: true },
|
|
@@ -13328,7 +13457,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13328
13457
|
{ name: "created_at", type: "number" }
|
|
13329
13458
|
]
|
|
13330
13459
|
}),
|
|
13331
|
-
(0,
|
|
13460
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13332
13461
|
name: "vault_folders",
|
|
13333
13462
|
columns: [
|
|
13334
13463
|
{ name: "name", type: "string" },
|
|
@@ -13340,7 +13469,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13340
13469
|
{ name: "context", type: "string", isOptional: true }
|
|
13341
13470
|
]
|
|
13342
13471
|
}),
|
|
13343
|
-
(0,
|
|
13472
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13344
13473
|
name: "conversation_summaries",
|
|
13345
13474
|
columns: [
|
|
13346
13475
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -13351,7 +13480,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13351
13480
|
{ name: "updated_at", type: "number" }
|
|
13352
13481
|
]
|
|
13353
13482
|
}),
|
|
13354
|
-
(0,
|
|
13483
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13355
13484
|
name: "media",
|
|
13356
13485
|
columns: [
|
|
13357
13486
|
{ name: "media_id", type: "string", isIndexed: true },
|
|
@@ -13373,7 +13502,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13373
13502
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
13374
13503
|
]
|
|
13375
13504
|
}),
|
|
13376
|
-
(0,
|
|
13505
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13377
13506
|
name: "app_files",
|
|
13378
13507
|
columns: [
|
|
13379
13508
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -13383,7 +13512,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13383
13512
|
{ name: "updated_at", type: "number" }
|
|
13384
13513
|
]
|
|
13385
13514
|
}),
|
|
13386
|
-
(0,
|
|
13515
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13387
13516
|
name: "saved_tools",
|
|
13388
13517
|
columns: [
|
|
13389
13518
|
{ name: "name", type: "string" },
|
|
@@ -13397,7 +13526,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13397
13526
|
{ name: "is_deleted", type: "boolean", isIndexed: true }
|
|
13398
13527
|
]
|
|
13399
13528
|
}),
|
|
13400
|
-
(0,
|
|
13529
|
+
(0, import_watermelondb20.tableSchema)({
|
|
13401
13530
|
name: "conversation_memory",
|
|
13402
13531
|
columns: [
|
|
13403
13532
|
{ name: "conversation_id", type: "string", isIndexed: true },
|
|
@@ -13971,6 +14100,15 @@ var sdkMigrations = (0, import_migrations2.schemaMigrations)({
|
|
|
13971
14100
|
"UPDATE memory_vault SET level = CASE WHEN scope IN ('shared', 'public') THEN 'matching' ELSE 'private' END WHERE level IS NULL;"
|
|
13972
14101
|
)
|
|
13973
14102
|
]
|
|
14103
|
+
},
|
|
14104
|
+
{
|
|
14105
|
+
toVersion: 49,
|
|
14106
|
+
steps: [
|
|
14107
|
+
(0, import_migrations2.addColumns)({
|
|
14108
|
+
table: "userPreferences",
|
|
14109
|
+
columns: [{ name: "external_wallets", type: "string", isOptional: true }]
|
|
14110
|
+
})
|
|
14111
|
+
]
|
|
13974
14112
|
}
|
|
13975
14113
|
]
|
|
13976
14114
|
});
|
|
@@ -14073,7 +14211,7 @@ var DatabaseManager = class {
|
|
|
14073
14211
|
walletAddress
|
|
14074
14212
|
});
|
|
14075
14213
|
const adapter = this.createAdapter(dbName, sdkSchema, sdkMigrations);
|
|
14076
|
-
const database = new
|
|
14214
|
+
const database = new import_watermelondb21.Database({
|
|
14077
14215
|
adapter,
|
|
14078
14216
|
modelClasses: sdkModelClasses
|
|
14079
14217
|
});
|
|
@@ -14152,7 +14290,7 @@ var DatabaseManager = class {
|
|
|
14152
14290
|
};
|
|
14153
14291
|
|
|
14154
14292
|
// src/lib/db/media/operations.ts
|
|
14155
|
-
var
|
|
14293
|
+
var import_watermelondb23 = require("@nozbe/watermelondb");
|
|
14156
14294
|
init_logger();
|
|
14157
14295
|
|
|
14158
14296
|
// src/lib/storage/opfs.ts
|
|
@@ -14420,7 +14558,7 @@ function isR2UrlExpired(sourceUrl, createdAt) {
|
|
|
14420
14558
|
}
|
|
14421
14559
|
|
|
14422
14560
|
// src/lib/storage/WatermelonChatStorageAdapter.ts
|
|
14423
|
-
var
|
|
14561
|
+
var import_watermelondb22 = require("@nozbe/watermelondb");
|
|
14424
14562
|
var WatermelonChatStorageAdapter = class {
|
|
14425
14563
|
constructor(options) {
|
|
14426
14564
|
this.messages = options.database.get("history");
|
|
@@ -14460,10 +14598,10 @@ var WatermelonChatStorageAdapter = class {
|
|
|
14460
14598
|
}
|
|
14461
14599
|
observeConversations(options) {
|
|
14462
14600
|
const conditions = options?.projectId !== void 0 ? [
|
|
14463
|
-
|
|
14464
|
-
|
|
14465
|
-
|
|
14466
|
-
] : [
|
|
14601
|
+
import_watermelondb22.Q.where("project_id", options.projectId === null ? "" : options.projectId),
|
|
14602
|
+
import_watermelondb22.Q.where("is_deleted", false),
|
|
14603
|
+
import_watermelondb22.Q.sortBy("created_at", import_watermelondb22.Q.desc)
|
|
14604
|
+
] : [import_watermelondb22.Q.where("is_deleted", false), import_watermelondb22.Q.sortBy("created_at", import_watermelondb22.Q.desc)];
|
|
14467
14605
|
const rx = this.conversations.query(...conditions).observe();
|
|
14468
14606
|
return {
|
|
14469
14607
|
subscribe: (observer) => {
|
|
@@ -14510,7 +14648,7 @@ var WatermelonChatStorageAdapter = class {
|
|
|
14510
14648
|
return clearMessagesOp(this.ctx, conversationId);
|
|
14511
14649
|
}
|
|
14512
14650
|
observeMessages(conversationId) {
|
|
14513
|
-
const rx = this.messages.query(
|
|
14651
|
+
const rx = this.messages.query(import_watermelondb22.Q.where("conversation_id", conversationId), import_watermelondb22.Q.sortBy("message_id", import_watermelondb22.Q.asc)).observe();
|
|
14514
14652
|
return {
|
|
14515
14653
|
subscribe: (observer) => {
|
|
14516
14654
|
let latestSeq = 0;
|
|
@@ -14748,7 +14886,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
14748
14886
|
})
|
|
14749
14887
|
);
|
|
14750
14888
|
});
|
|
14751
|
-
const results = await mediaCollection.query(
|
|
14889
|
+
const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", import_watermelondb23.Q.oneOf(mediaIds))).fetch();
|
|
14752
14890
|
return Promise.all(
|
|
14753
14891
|
results.map(
|
|
14754
14892
|
(m) => mediaToStored(m, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -14757,21 +14895,21 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
14757
14895
|
}
|
|
14758
14896
|
async function getMediaByIdOp(ctx, mediaId) {
|
|
14759
14897
|
const mediaCollection = ctx.database.get("media");
|
|
14760
|
-
const results = await mediaCollection.query(
|
|
14898
|
+
const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId), import_watermelondb23.Q.where("is_deleted", false)).fetch();
|
|
14761
14899
|
return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
14762
14900
|
}
|
|
14763
14901
|
async function getMediaBySourceUrlOp(ctx, sourceUrl, walletAddress) {
|
|
14764
14902
|
const mediaCollection = ctx.database.get("media");
|
|
14765
14903
|
const results = await mediaCollection.query(
|
|
14766
|
-
|
|
14767
|
-
|
|
14768
|
-
|
|
14904
|
+
import_watermelondb23.Q.where("source_url", sourceUrl),
|
|
14905
|
+
import_watermelondb23.Q.where("wallet_address", walletAddress),
|
|
14906
|
+
import_watermelondb23.Q.where("is_deleted", false)
|
|
14769
14907
|
).fetch();
|
|
14770
14908
|
return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
14771
14909
|
}
|
|
14772
14910
|
async function updateMediaOp(ctx, mediaId, options) {
|
|
14773
14911
|
const mediaCollection = ctx.database.get("media");
|
|
14774
|
-
const results = await mediaCollection.query(
|
|
14912
|
+
const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId)).fetch();
|
|
14775
14913
|
if (results.length === 0) {
|
|
14776
14914
|
return null;
|
|
14777
14915
|
}
|
|
@@ -14791,7 +14929,7 @@ async function updateMediaOp(ctx, mediaId, options) {
|
|
|
14791
14929
|
m._setRaw("updated_at", now);
|
|
14792
14930
|
});
|
|
14793
14931
|
});
|
|
14794
|
-
const updated = await mediaCollection.query(
|
|
14932
|
+
const updated = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId)).fetch();
|
|
14795
14933
|
return updated.length > 0 ? await mediaToStored(updated[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
|
|
14796
14934
|
}
|
|
14797
14935
|
async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
|
|
@@ -14799,7 +14937,7 @@ async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
|
|
|
14799
14937
|
return 0;
|
|
14800
14938
|
}
|
|
14801
14939
|
const mediaCollection = ctx.database.get("media");
|
|
14802
|
-
const results = await mediaCollection.query(
|
|
14940
|
+
const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", import_watermelondb23.Q.oneOf(mediaIds))).fetch();
|
|
14803
14941
|
if (results.length === 0) {
|
|
14804
14942
|
return 0;
|
|
14805
14943
|
}
|
|
@@ -14821,13 +14959,13 @@ var IMAGE_VIDEO_MIMES = VIDEO_EXTENSIONS.map((ext) => `image/${ext}`);
|
|
|
14821
14959
|
async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
|
|
14822
14960
|
const mediaCollection = ctx.database.get("media");
|
|
14823
14961
|
const candidates = await mediaCollection.query(
|
|
14824
|
-
|
|
14825
|
-
|
|
14826
|
-
|
|
14827
|
-
|
|
14828
|
-
|
|
14829
|
-
...IMAGE_VIDEO_MIMES.map((m) =>
|
|
14830
|
-
|
|
14962
|
+
import_watermelondb23.Q.where("wallet_address", walletAddress),
|
|
14963
|
+
import_watermelondb23.Q.where("is_deleted", false),
|
|
14964
|
+
import_watermelondb23.Q.where("media_type", "image"),
|
|
14965
|
+
import_watermelondb23.Q.or(
|
|
14966
|
+
import_watermelondb23.Q.where("mime_type", import_watermelondb23.Q.like("video/%")),
|
|
14967
|
+
...IMAGE_VIDEO_MIMES.map((m) => import_watermelondb23.Q.where("mime_type", m)),
|
|
14968
|
+
import_watermelondb23.Q.where("mime_type", "application/octet-stream")
|
|
14831
14969
|
)
|
|
14832
14970
|
).fetch();
|
|
14833
14971
|
if (candidates.length === 0) {
|
|
@@ -14876,7 +15014,7 @@ async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
|
|
|
14876
15014
|
}
|
|
14877
15015
|
async function deleteMediaOp(ctx, mediaId) {
|
|
14878
15016
|
const mediaCollection = ctx.database.get("media");
|
|
14879
|
-
const results = await mediaCollection.query(
|
|
15017
|
+
const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId)).fetch();
|
|
14880
15018
|
if (results.length === 0) {
|
|
14881
15019
|
return false;
|
|
14882
15020
|
}
|
|
@@ -14894,7 +15032,7 @@ async function deleteMediaOp(ctx, mediaId) {
|
|
|
14894
15032
|
}
|
|
14895
15033
|
async function hardDeleteMediaOp(ctx, mediaId) {
|
|
14896
15034
|
const mediaCollection = ctx.database.get("media");
|
|
14897
|
-
const results = await mediaCollection.query(
|
|
15035
|
+
const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId)).fetch();
|
|
14898
15036
|
if (results.length === 0) {
|
|
14899
15037
|
return false;
|
|
14900
15038
|
}
|
|
@@ -14906,28 +15044,28 @@ async function hardDeleteMediaOp(ctx, mediaId) {
|
|
|
14906
15044
|
}
|
|
14907
15045
|
async function getMediaOp(ctx, filters) {
|
|
14908
15046
|
const mediaCollection = ctx.database.get("media");
|
|
14909
|
-
const conditions = [
|
|
15047
|
+
const conditions = [import_watermelondb23.Q.where("wallet_address", filters.walletAddress)];
|
|
14910
15048
|
if (!filters.includeDeleted) {
|
|
14911
|
-
conditions.push(
|
|
15049
|
+
conditions.push(import_watermelondb23.Q.where("is_deleted", false));
|
|
14912
15050
|
}
|
|
14913
15051
|
if (filters.mediaType) {
|
|
14914
|
-
conditions.push(
|
|
15052
|
+
conditions.push(import_watermelondb23.Q.where("media_type", filters.mediaType));
|
|
14915
15053
|
}
|
|
14916
15054
|
if (filters.role) {
|
|
14917
|
-
conditions.push(
|
|
15055
|
+
conditions.push(import_watermelondb23.Q.where("role", filters.role));
|
|
14918
15056
|
}
|
|
14919
15057
|
if (filters.conversationId) {
|
|
14920
|
-
conditions.push(
|
|
15058
|
+
conditions.push(import_watermelondb23.Q.where("conversation_id", filters.conversationId));
|
|
14921
15059
|
}
|
|
14922
15060
|
if (filters.model) {
|
|
14923
|
-
conditions.push(
|
|
15061
|
+
conditions.push(import_watermelondb23.Q.where("model", filters.model));
|
|
14924
15062
|
}
|
|
14925
|
-
conditions.push(
|
|
15063
|
+
conditions.push(import_watermelondb23.Q.sortBy("created_at", import_watermelondb23.Q.desc));
|
|
14926
15064
|
if (filters.limit) {
|
|
14927
|
-
conditions.push(
|
|
15065
|
+
conditions.push(import_watermelondb23.Q.take(filters.limit));
|
|
14928
15066
|
}
|
|
14929
15067
|
if (filters.offset) {
|
|
14930
|
-
conditions.push(
|
|
15068
|
+
conditions.push(import_watermelondb23.Q.skip(filters.offset));
|
|
14931
15069
|
}
|
|
14932
15070
|
const results = await mediaCollection.query(...conditions).fetch();
|
|
14933
15071
|
return Promise.all(
|
|
@@ -14957,9 +15095,9 @@ async function getMediaByConversationOp(ctx, walletAddress, conversationId, limi
|
|
|
14957
15095
|
async function getMediaByMessageOp(ctx, messageId) {
|
|
14958
15096
|
const mediaCollection = ctx.database.get("media");
|
|
14959
15097
|
const results = await mediaCollection.query(
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
15098
|
+
import_watermelondb23.Q.where("message_id", messageId),
|
|
15099
|
+
import_watermelondb23.Q.where("is_deleted", false),
|
|
15100
|
+
import_watermelondb23.Q.sortBy("created_at", import_watermelondb23.Q.asc)
|
|
14963
15101
|
).fetch();
|
|
14964
15102
|
return Promise.all(
|
|
14965
15103
|
results.map(
|
|
@@ -14972,9 +15110,9 @@ async function getMediaByIdsOp(ctx, mediaIds, includeDeleted = false) {
|
|
|
14972
15110
|
return [];
|
|
14973
15111
|
}
|
|
14974
15112
|
const mediaCollection = ctx.database.get("media");
|
|
14975
|
-
const conditions = [
|
|
15113
|
+
const conditions = [import_watermelondb23.Q.where("media_id", import_watermelondb23.Q.oneOf(mediaIds))];
|
|
14976
15114
|
if (!includeDeleted) {
|
|
14977
|
-
conditions.push(
|
|
15115
|
+
conditions.push(import_watermelondb23.Q.where("is_deleted", false));
|
|
14978
15116
|
}
|
|
14979
15117
|
const results = await mediaCollection.query(...conditions).fetch();
|
|
14980
15118
|
const mediaMap = new Map(results.map((m) => [m.mediaId, m]));
|
|
@@ -15011,10 +15149,10 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
|
|
|
15011
15149
|
const queryLower = query.toLowerCase();
|
|
15012
15150
|
const MAX_SEARCH_RECORDS = 500;
|
|
15013
15151
|
const allResults = await mediaCollection.query(
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15152
|
+
import_watermelondb23.Q.where("wallet_address", walletAddress),
|
|
15153
|
+
import_watermelondb23.Q.where("is_deleted", false),
|
|
15154
|
+
import_watermelondb23.Q.sortBy("created_at", import_watermelondb23.Q.desc),
|
|
15155
|
+
import_watermelondb23.Q.take(MAX_SEARCH_RECORDS)
|
|
15018
15156
|
).fetch();
|
|
15019
15157
|
const decrypted = await Promise.all(
|
|
15020
15158
|
allResults.map(
|
|
@@ -15027,11 +15165,11 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
|
|
|
15027
15165
|
async function getMediaCountOp(ctx, walletAddress, mediaType) {
|
|
15028
15166
|
const mediaCollection = ctx.database.get("media");
|
|
15029
15167
|
const conditions = [
|
|
15030
|
-
|
|
15031
|
-
|
|
15168
|
+
import_watermelondb23.Q.where("wallet_address", walletAddress),
|
|
15169
|
+
import_watermelondb23.Q.where("is_deleted", false)
|
|
15032
15170
|
];
|
|
15033
15171
|
if (mediaType) {
|
|
15034
|
-
conditions.push(
|
|
15172
|
+
conditions.push(import_watermelondb23.Q.where("media_type", mediaType));
|
|
15035
15173
|
}
|
|
15036
15174
|
return await mediaCollection.query(...conditions).fetchCount();
|
|
15037
15175
|
}
|
|
@@ -15046,7 +15184,7 @@ async function getMediaCountsByTypeOp(ctx, walletAddress) {
|
|
|
15046
15184
|
}
|
|
15047
15185
|
async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
15048
15186
|
const mediaCollection = ctx.database.get("media");
|
|
15049
|
-
const results = await mediaCollection.query(
|
|
15187
|
+
const results = await mediaCollection.query(import_watermelondb23.Q.where("conversation_id", conversationId), import_watermelondb23.Q.where("is_deleted", false)).fetch();
|
|
15050
15188
|
if (results.length === 0) {
|
|
15051
15189
|
return 0;
|
|
15052
15190
|
}
|
|
@@ -15067,7 +15205,7 @@ async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
|
15067
15205
|
}
|
|
15068
15206
|
async function deleteMediaByMessageOp(ctx, messageId) {
|
|
15069
15207
|
const mediaCollection = ctx.database.get("media");
|
|
15070
|
-
const results = await mediaCollection.query(
|
|
15208
|
+
const results = await mediaCollection.query(import_watermelondb23.Q.where("message_id", messageId), import_watermelondb23.Q.where("is_deleted", false)).fetch();
|
|
15071
15209
|
if (results.length === 0) {
|
|
15072
15210
|
return 0;
|
|
15073
15211
|
}
|
|
@@ -15088,7 +15226,7 @@ async function deleteMediaByMessageOp(ctx, messageId) {
|
|
|
15088
15226
|
}
|
|
15089
15227
|
|
|
15090
15228
|
// src/lib/db/memoryVault/operations.ts
|
|
15091
|
-
var
|
|
15229
|
+
var import_watermelondb24 = require("@nozbe/watermelondb");
|
|
15092
15230
|
init_logger();
|
|
15093
15231
|
|
|
15094
15232
|
// src/lib/db/memoryVault/encryption.ts
|
|
@@ -15139,11 +15277,11 @@ var NON_PRIVATE_VISIBILITIES = ["public"];
|
|
|
15139
15277
|
function visibilityConditions(requested) {
|
|
15140
15278
|
if (!requested?.length) return [];
|
|
15141
15279
|
if (!requested.includes("private")) {
|
|
15142
|
-
return [
|
|
15280
|
+
return [import_watermelondb24.Q.where("visibility", import_watermelondb24.Q.oneOf([...requested]))];
|
|
15143
15281
|
}
|
|
15144
15282
|
const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
|
|
15145
15283
|
if (excluded.length === 0) return [];
|
|
15146
|
-
return [
|
|
15284
|
+
return [import_watermelondb24.Q.or(import_watermelondb24.Q.where("visibility", null), import_watermelondb24.Q.where("visibility", import_watermelondb24.Q.notIn(excluded)))];
|
|
15147
15285
|
}
|
|
15148
15286
|
function isKinded(record2) {
|
|
15149
15287
|
return record2.kind !== null && record2.kind !== void 0;
|
|
@@ -15184,17 +15322,17 @@ function levelConditions(requested) {
|
|
|
15184
15322
|
const published = ["shared", "public"];
|
|
15185
15323
|
const wantsMatching = requested.includes("matching");
|
|
15186
15324
|
const wantsPrivate = requested.includes("private");
|
|
15187
|
-
const unresolved =
|
|
15188
|
-
const byLevel =
|
|
15189
|
-
if (wantsMatching && wantsPrivate) return [
|
|
15325
|
+
const unresolved = import_watermelondb24.Q.or(import_watermelondb24.Q.where("level", null), import_watermelondb24.Q.where("level", import_watermelondb24.Q.notIn([...MEMORY_LEVELS])));
|
|
15326
|
+
const byLevel = import_watermelondb24.Q.where("level", import_watermelondb24.Q.oneOf([...requested]));
|
|
15327
|
+
if (wantsMatching && wantsPrivate) return [import_watermelondb24.Q.or(byLevel, unresolved)];
|
|
15190
15328
|
if (wantsMatching) {
|
|
15191
|
-
return [
|
|
15329
|
+
return [import_watermelondb24.Q.or(byLevel, import_watermelondb24.Q.and(unresolved, import_watermelondb24.Q.where("scope", import_watermelondb24.Q.oneOf(published))))];
|
|
15192
15330
|
}
|
|
15193
15331
|
if (wantsPrivate) {
|
|
15194
15332
|
return [
|
|
15195
|
-
|
|
15333
|
+
import_watermelondb24.Q.or(
|
|
15196
15334
|
byLevel,
|
|
15197
|
-
|
|
15335
|
+
import_watermelondb24.Q.and(unresolved, import_watermelondb24.Q.or(import_watermelondb24.Q.where("scope", null), import_watermelondb24.Q.where("scope", import_watermelondb24.Q.notIn(published))))
|
|
15198
15336
|
)
|
|
15199
15337
|
];
|
|
15200
15338
|
}
|
|
@@ -15205,13 +15343,13 @@ function isOwnedByCtxUser(ctx, record2) {
|
|
|
15205
15343
|
}
|
|
15206
15344
|
function baseVaultConditions(ctx, options) {
|
|
15207
15345
|
return [
|
|
15208
|
-
...options?.memoryIds !== void 0 ? [
|
|
15209
|
-
...options?.includeDeleted ? [] : [
|
|
15210
|
-
...options?.includeArchived ? [] : [
|
|
15211
|
-
...options?.includeQuarantined ? [] : [
|
|
15212
|
-
...options?.includeSuperseded ? [] : [
|
|
15213
|
-
...ctx.userId !== void 0 ? [
|
|
15214
|
-
...options?.since ? [
|
|
15346
|
+
...options?.memoryIds !== void 0 ? [import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(options.memoryIds))] : [],
|
|
15347
|
+
...options?.includeDeleted ? [] : [import_watermelondb24.Q.where("is_deleted", false)],
|
|
15348
|
+
...options?.includeArchived ? [] : [import_watermelondb24.Q.where("archived_at", import_watermelondb24.Q.eq(null))],
|
|
15349
|
+
...options?.includeQuarantined ? [] : [import_watermelondb24.Q.where("trust_tier", import_watermelondb24.Q.notEq("quarantined"))],
|
|
15350
|
+
...options?.includeSuperseded ? [] : [import_watermelondb24.Q.where("superseded_by", null)],
|
|
15351
|
+
...ctx.userId !== void 0 ? [import_watermelondb24.Q.where("user_id", ctx.userId)] : [],
|
|
15352
|
+
...options?.since ? [import_watermelondb24.Q.where("updated_at", import_watermelondb24.Q.gt(options.since.getTime()))] : []
|
|
15215
15353
|
];
|
|
15216
15354
|
}
|
|
15217
15355
|
var KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
|
|
@@ -15381,11 +15519,11 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
15381
15519
|
async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
|
|
15382
15520
|
const records = await ctx.vaultMemoryCollection.query(
|
|
15383
15521
|
...baseVaultConditions(ctx),
|
|
15384
|
-
|
|
15385
|
-
|
|
15386
|
-
|
|
15387
|
-
|
|
15388
|
-
|
|
15522
|
+
import_watermelondb24.Q.where("event_time_start", import_watermelondb24.Q.notEq(null)),
|
|
15523
|
+
import_watermelondb24.Q.where("event_time_start", import_watermelondb24.Q.lte(windowEnd)),
|
|
15524
|
+
import_watermelondb24.Q.or(
|
|
15525
|
+
import_watermelondb24.Q.where("event_time_start", import_watermelondb24.Q.gte(windowStart)),
|
|
15526
|
+
import_watermelondb24.Q.where("event_time_kind", import_watermelondb24.Q.oneOf(["range", "ongoing"]))
|
|
15389
15527
|
)
|
|
15390
15528
|
).fetch();
|
|
15391
15529
|
const out = [];
|
|
@@ -15541,18 +15679,18 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
15541
15679
|
function vaultListConditions(ctx, options) {
|
|
15542
15680
|
return [
|
|
15543
15681
|
...baseVaultConditions(ctx, options),
|
|
15544
|
-
...options?.scopes?.length ? [
|
|
15682
|
+
...options?.scopes?.length ? [import_watermelondb24.Q.where("scope", import_watermelondb24.Q.oneOf(options.scopes))] : [],
|
|
15545
15683
|
...visibilityConditions(options?.visibility),
|
|
15546
15684
|
...levelConditions(options?.levels),
|
|
15547
|
-
...options?.kinds?.length ? [
|
|
15548
|
-
...options?.folderId !== void 0 ? [
|
|
15549
|
-
...options?.factTypes?.length ? [
|
|
15685
|
+
...options?.kinds?.length ? [import_watermelondb24.Q.where("kind", import_watermelondb24.Q.oneOf(options.kinds))] : [],
|
|
15686
|
+
...options?.folderId !== void 0 ? [import_watermelondb24.Q.where("folder_id", options.folderId)] : [],
|
|
15687
|
+
...options?.factTypes?.length ? [import_watermelondb24.Q.where("fact_type", import_watermelondb24.Q.oneOf(options.factTypes))] : []
|
|
15550
15688
|
];
|
|
15551
15689
|
}
|
|
15552
15690
|
function vaultListOrder(options) {
|
|
15553
15691
|
return [
|
|
15554
|
-
|
|
15555
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
15692
|
+
import_watermelondb24.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb24.Q.desc),
|
|
15693
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb24.Q.take(options.limit)] : []
|
|
15556
15694
|
];
|
|
15557
15695
|
}
|
|
15558
15696
|
async function getAllVaultMemoryRowsOp(ctx) {
|
|
@@ -15591,10 +15729,10 @@ function vaultMemoryRawToRankable(raw) {
|
|
|
15591
15729
|
async function getVaultRankingProjectionsOp(ctx, options) {
|
|
15592
15730
|
const conditions = [
|
|
15593
15731
|
...baseVaultConditions(ctx, options),
|
|
15594
|
-
...options?.scopes?.length ? [
|
|
15595
|
-
...options?.folderId !== void 0 ? [
|
|
15596
|
-
|
|
15597
|
-
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [
|
|
15732
|
+
...options?.scopes?.length ? [import_watermelondb24.Q.where("scope", import_watermelondb24.Q.oneOf(options.scopes))] : [],
|
|
15733
|
+
...options?.folderId !== void 0 ? [import_watermelondb24.Q.where("folder_id", options.folderId)] : [],
|
|
15734
|
+
import_watermelondb24.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb24.Q.desc),
|
|
15735
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb24.Q.take(options.limit)] : []
|
|
15598
15736
|
];
|
|
15599
15737
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
15600
15738
|
return results.map(vaultMemoryRawToRankable);
|
|
@@ -15645,7 +15783,7 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
15645
15783
|
args.push(...options.factTypes);
|
|
15646
15784
|
}
|
|
15647
15785
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
15648
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
15786
|
+
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb24.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
15649
15787
|
return rows.map(mapRaw);
|
|
15650
15788
|
} catch (err) {
|
|
15651
15789
|
getLogger().debug(
|
|
@@ -15656,9 +15794,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
15656
15794
|
memoryIds: options?.memoryIds,
|
|
15657
15795
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
15658
15796
|
}),
|
|
15659
|
-
...options?.scopes?.length ? [
|
|
15660
|
-
...options?.folderId !== void 0 ? [
|
|
15661
|
-
...options?.factTypes?.length ? [
|
|
15797
|
+
...options?.scopes?.length ? [import_watermelondb24.Q.where("scope", import_watermelondb24.Q.oneOf(options.scopes))] : [],
|
|
15798
|
+
...options?.folderId !== void 0 ? [import_watermelondb24.Q.where("folder_id", options.folderId)] : [],
|
|
15799
|
+
...options?.factTypes?.length ? [import_watermelondb24.Q.where("fact_type", import_watermelondb24.Q.oneOf(options.factTypes))] : []
|
|
15662
15800
|
];
|
|
15663
15801
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
15664
15802
|
return rows.map(mapRaw);
|
|
@@ -15676,7 +15814,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
15676
15814
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
15677
15815
|
});
|
|
15678
15816
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
15679
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
15817
|
+
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb24.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
15680
15818
|
return rows.map(mapRaw);
|
|
15681
15819
|
} catch (err) {
|
|
15682
15820
|
getLogger().debug(
|
|
@@ -15688,7 +15826,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
|
15688
15826
|
includeArchived: options.includeArchived
|
|
15689
15827
|
}
|
|
15690
15828
|
}),
|
|
15691
|
-
|
|
15829
|
+
import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(ids))
|
|
15692
15830
|
).unsafeFetchRaw();
|
|
15693
15831
|
return rows.map(mapRaw);
|
|
15694
15832
|
}
|
|
@@ -15699,7 +15837,7 @@ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
|
15699
15837
|
...baseVaultConditions(ctx, {
|
|
15700
15838
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
15701
15839
|
}),
|
|
15702
|
-
|
|
15840
|
+
import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(ids))
|
|
15703
15841
|
];
|
|
15704
15842
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
15705
15843
|
return mapInBatches(
|
|
@@ -15724,7 +15862,7 @@ async function countActiveVaultMemoriesOp(ctx) {
|
|
|
15724
15862
|
}
|
|
15725
15863
|
async function getActiveVaultMemoryIdsOp(ctx, ids) {
|
|
15726
15864
|
if (ids.length === 0) return /* @__PURE__ */ new Set();
|
|
15727
|
-
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx),
|
|
15865
|
+
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(ids))).unsafeFetchRaw();
|
|
15728
15866
|
return new Set(rows.map((r) => r.id));
|
|
15729
15867
|
}
|
|
15730
15868
|
async function updateVaultMemoryOp(ctx, id, opts) {
|
|
@@ -15873,7 +16011,7 @@ async function setMemoryEntitiesOp(ctx, memoryId, entities) {
|
|
|
15873
16011
|
() => linkMemoryEntitiesOp(entityCtx, memoryId, entities, { topicsSource: "user" })
|
|
15874
16012
|
) : [];
|
|
15875
16013
|
const keep = new Set(linked.map((e) => e.uniqueId));
|
|
15876
|
-
const existing = await entityCtx.memoryEntityCollection.query(
|
|
16014
|
+
const existing = await entityCtx.memoryEntityCollection.query(import_watermelondb24.Q.where("memory_id", memoryId)).fetch();
|
|
15877
16015
|
const staleLinks = existing.filter((l) => !keep.has(String(l.entityId)));
|
|
15878
16016
|
if (staleLinks.length === 0 && entities.length > 0) return;
|
|
15879
16017
|
const topicsWrite = await resolveMemoryTopicsWrite(
|
|
@@ -16014,9 +16152,9 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
16014
16152
|
}
|
|
16015
16153
|
async function getUnfiledVaultMemoriesOp(ctx) {
|
|
16016
16154
|
const conditions = [
|
|
16017
|
-
|
|
16155
|
+
import_watermelondb24.Q.where("folder_id", null),
|
|
16018
16156
|
...baseVaultConditions(ctx),
|
|
16019
|
-
|
|
16157
|
+
import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)
|
|
16020
16158
|
];
|
|
16021
16159
|
const results = await ctx.vaultMemoryCollection.query(...conditions).fetch();
|
|
16022
16160
|
return mapInBatches(
|
|
@@ -16030,7 +16168,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
16030
16168
|
const entityIdByMemory = /* @__PURE__ */ new Map();
|
|
16031
16169
|
const allEntityIds = /* @__PURE__ */ new Set();
|
|
16032
16170
|
for (let i = 0; i < memoryIds.length; i += CHUNK) {
|
|
16033
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
16171
|
+
const links = await entityCtx.memoryEntityCollection.query(import_watermelondb24.Q.where("memory_id", import_watermelondb24.Q.oneOf(memoryIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
16034
16172
|
for (const link of links) {
|
|
16035
16173
|
const memoryId = String(link.memory_id);
|
|
16036
16174
|
const entityId = String(link.entity_id);
|
|
@@ -16046,7 +16184,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
|
|
|
16046
16184
|
const entityIds = Array.from(allEntityIds);
|
|
16047
16185
|
const nameById = /* @__PURE__ */ new Map();
|
|
16048
16186
|
for (let i = 0; i < entityIds.length; i += CHUNK) {
|
|
16049
|
-
const entities = await entityCtx.entityCollection.query(
|
|
16187
|
+
const entities = await entityCtx.entityCollection.query(import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(entityIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
|
|
16050
16188
|
for (const e of entities) {
|
|
16051
16189
|
if (typeof e.canonical_name === "string") nameById.set(String(e.id), e.canonical_name);
|
|
16052
16190
|
}
|
|
@@ -16075,7 +16213,7 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
|
|
|
16075
16213
|
if (!entityCtx) {
|
|
16076
16214
|
throw new Error("getMemoriesNeedingTopicExtractionOp requires ctx.entityCtx");
|
|
16077
16215
|
}
|
|
16078
|
-
const conditions = [...baseVaultConditions(ctx),
|
|
16216
|
+
const conditions = [...baseVaultConditions(ctx), import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)];
|
|
16079
16217
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
16080
16218
|
const linkedNames = await linkedEntityNamesByMemory(
|
|
16081
16219
|
entityCtx,
|
|
@@ -16231,10 +16369,10 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
16231
16369
|
}
|
|
16232
16370
|
if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) continue;
|
|
16233
16371
|
if (parseTopics(record2.topics) !== null) continue;
|
|
16234
|
-
const links = await entityCtx.memoryEntityCollection.query(
|
|
16372
|
+
const links = await entityCtx.memoryEntityCollection.query(import_watermelondb24.Q.where("memory_id", id)).unsafeFetchRaw();
|
|
16235
16373
|
const entityIds = links.map((l) => String(l.entity_id));
|
|
16236
16374
|
if (entityIds.length === 0) continue;
|
|
16237
|
-
const entities = await entityCtx.entityCollection.query(
|
|
16375
|
+
const entities = await entityCtx.entityCollection.query(import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(entityIds))).fetch();
|
|
16238
16376
|
if (entities.length === 0) continue;
|
|
16239
16377
|
const source = record2.topicsUserManaged ? "user" : "auto";
|
|
16240
16378
|
const write = await resolveMemoryTopicsWrite(entityCtx, id, entities, [], source);
|
|
@@ -16250,7 +16388,7 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
|
|
|
16250
16388
|
}
|
|
16251
16389
|
async function deleteAllVaultMemoriesForUserOp(ctx, userId) {
|
|
16252
16390
|
if (ctx.userId !== void 0 && ctx.userId !== userId) return 0;
|
|
16253
|
-
const records = await ctx.vaultMemoryCollection.query(
|
|
16391
|
+
const records = await ctx.vaultMemoryCollection.query(import_watermelondb24.Q.where("user_id", userId), import_watermelondb24.Q.where("is_deleted", false)).fetch();
|
|
16254
16392
|
if (records.length === 0) return 0;
|
|
16255
16393
|
await ctx.database.write(async () => {
|
|
16256
16394
|
await assertCanWrite2(ctx);
|
|
@@ -16287,7 +16425,7 @@ async function getDecayCandidatesRawOp(ctx) {
|
|
|
16287
16425
|
assertVaultScopeForSweep(ctx);
|
|
16288
16426
|
const results = await ctx.vaultMemoryCollection.query(
|
|
16289
16427
|
...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
|
|
16290
|
-
|
|
16428
|
+
import_watermelondb24.Q.where("kind", null)
|
|
16291
16429
|
).unsafeFetchRaw();
|
|
16292
16430
|
return results.map((raw) => ({
|
|
16293
16431
|
uniqueId: raw.id,
|
|
@@ -16417,11 +16555,11 @@ async function findQuarantinedDuplicateOp(ctx, content, sourceIds2, where) {
|
|
|
16417
16555
|
const wanted = [...new Set(sourceIds2)].sort().join("\0");
|
|
16418
16556
|
const target = normalizeForDedupe(content);
|
|
16419
16557
|
const rows = await ctx.vaultMemoryCollection.query(
|
|
16420
|
-
|
|
16421
|
-
|
|
16422
|
-
|
|
16423
|
-
|
|
16424
|
-
...ctx.userId !== void 0 ? [
|
|
16558
|
+
import_watermelondb24.Q.where("trust_tier", "quarantined"),
|
|
16559
|
+
import_watermelondb24.Q.where("is_deleted", false),
|
|
16560
|
+
import_watermelondb24.Q.where("scope", where.scope),
|
|
16561
|
+
import_watermelondb24.Q.where("folder_id", where.folderId),
|
|
16562
|
+
...ctx.userId !== void 0 ? [import_watermelondb24.Q.where("user_id", ctx.userId)] : []
|
|
16425
16563
|
).unsafeFetchRaw();
|
|
16426
16564
|
for (const raw of rows) {
|
|
16427
16565
|
let ids;
|
|
@@ -16578,7 +16716,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
|
16578
16716
|
}
|
|
16579
16717
|
|
|
16580
16718
|
// src/lib/db/project/operations.ts
|
|
16581
|
-
var
|
|
16719
|
+
var import_watermelondb25 = require("@nozbe/watermelondb");
|
|
16582
16720
|
|
|
16583
16721
|
// src/lib/db/project/types.ts
|
|
16584
16722
|
function generateProjectId() {
|
|
@@ -16609,15 +16747,15 @@ async function createProjectOp(ctx, opts, defaultName = "New Project") {
|
|
|
16609
16747
|
return projectToStored(created);
|
|
16610
16748
|
}
|
|
16611
16749
|
async function getProjectOp(ctx, id) {
|
|
16612
|
-
const results = await ctx.projectsCollection.query(
|
|
16750
|
+
const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
|
|
16613
16751
|
return results.length > 0 ? projectToStored(results[0]) : null;
|
|
16614
16752
|
}
|
|
16615
16753
|
async function getProjectsOp(ctx) {
|
|
16616
|
-
const results = await ctx.projectsCollection.query(
|
|
16754
|
+
const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("is_deleted", false), import_watermelondb25.Q.sortBy("created_at", import_watermelondb25.Q.desc)).fetch();
|
|
16617
16755
|
return results.map(projectToStored);
|
|
16618
16756
|
}
|
|
16619
16757
|
async function updateProjectNameOp(ctx, id, name) {
|
|
16620
|
-
const results = await ctx.projectsCollection.query(
|
|
16758
|
+
const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
|
|
16621
16759
|
if (results.length > 0) {
|
|
16622
16760
|
await ctx.database.write(async () => {
|
|
16623
16761
|
await results[0].update((proj) => {
|
|
@@ -16629,7 +16767,7 @@ async function updateProjectNameOp(ctx, id, name) {
|
|
|
16629
16767
|
return false;
|
|
16630
16768
|
}
|
|
16631
16769
|
async function updateProjectOp(ctx, id, opts) {
|
|
16632
|
-
const results = await ctx.projectsCollection.query(
|
|
16770
|
+
const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
|
|
16633
16771
|
if (results.length > 0) {
|
|
16634
16772
|
await ctx.database.write(async () => {
|
|
16635
16773
|
await results[0].update((proj) => {
|
|
@@ -16641,7 +16779,7 @@ async function updateProjectOp(ctx, id, opts) {
|
|
|
16641
16779
|
return false;
|
|
16642
16780
|
}
|
|
16643
16781
|
async function deleteProjectOp(ctx, id) {
|
|
16644
|
-
const results = await ctx.projectsCollection.query(
|
|
16782
|
+
const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
|
|
16645
16783
|
if (results.length > 0) {
|
|
16646
16784
|
await ctx.database.write(async () => {
|
|
16647
16785
|
await results[0].update((proj) => {
|
|
@@ -16654,14 +16792,14 @@ async function deleteProjectOp(ctx, id) {
|
|
|
16654
16792
|
}
|
|
16655
16793
|
async function getProjectConversationsOp(ctx, projectId) {
|
|
16656
16794
|
const results = await ctx.conversationsCollection.query(
|
|
16657
|
-
|
|
16658
|
-
|
|
16659
|
-
|
|
16795
|
+
import_watermelondb25.Q.where("project_id", projectId),
|
|
16796
|
+
import_watermelondb25.Q.where("is_deleted", false),
|
|
16797
|
+
import_watermelondb25.Q.sortBy("created_at", import_watermelondb25.Q.desc)
|
|
16660
16798
|
).fetch();
|
|
16661
16799
|
return results.map(conversationToStoredRaw);
|
|
16662
16800
|
}
|
|
16663
16801
|
async function getProjectConversationCountOp(ctx, projectId) {
|
|
16664
|
-
return await ctx.conversationsCollection.query(
|
|
16802
|
+
return await ctx.conversationsCollection.query(import_watermelondb25.Q.where("project_id", projectId), import_watermelondb25.Q.where("is_deleted", false)).fetchCount();
|
|
16665
16803
|
}
|
|
16666
16804
|
|
|
16667
16805
|
// src/lib/db/queue/manager.ts
|
|
@@ -17005,7 +17143,7 @@ var WalletPoller = class {
|
|
|
17005
17143
|
};
|
|
17006
17144
|
|
|
17007
17145
|
// src/lib/db/savedTools/operations.ts
|
|
17008
|
-
var
|
|
17146
|
+
var import_watermelondb26 = require("@nozbe/watermelondb");
|
|
17009
17147
|
function savedToolToStored(tool) {
|
|
17010
17148
|
return {
|
|
17011
17149
|
uniqueId: tool.id,
|
|
@@ -17038,7 +17176,7 @@ async function createSavedToolOp(ctx, opts) {
|
|
|
17038
17176
|
return savedToolToStored(created);
|
|
17039
17177
|
}
|
|
17040
17178
|
async function getAllSavedToolsOp(ctx) {
|
|
17041
|
-
const results = await ctx.savedToolsCollection.query(
|
|
17179
|
+
const results = await ctx.savedToolsCollection.query(import_watermelondb26.Q.where("is_deleted", false), import_watermelondb26.Q.sortBy("created_at", import_watermelondb26.Q.desc)).fetch();
|
|
17042
17180
|
return results.map(savedToolToStored);
|
|
17043
17181
|
}
|
|
17044
17182
|
async function getSavedToolByIdOp(ctx, uniqueId) {
|
|
@@ -17090,7 +17228,7 @@ async function deleteSavedToolOp(ctx, uniqueId) {
|
|
|
17090
17228
|
}
|
|
17091
17229
|
|
|
17092
17230
|
// src/lib/db/settings/operations.ts
|
|
17093
|
-
var
|
|
17231
|
+
var import_watermelondb27 = require("@nozbe/watermelondb");
|
|
17094
17232
|
function modelPreferenceToStored(preference) {
|
|
17095
17233
|
return {
|
|
17096
17234
|
uniqueId: preference.id,
|
|
@@ -17099,12 +17237,12 @@ function modelPreferenceToStored(preference) {
|
|
|
17099
17237
|
};
|
|
17100
17238
|
}
|
|
17101
17239
|
async function getModelPreferenceOp(ctx, walletAddress) {
|
|
17102
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
17240
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
|
|
17103
17241
|
return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
|
|
17104
17242
|
}
|
|
17105
17243
|
async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
17106
17244
|
const result = await ctx.database.write(async () => {
|
|
17107
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
17245
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
|
|
17108
17246
|
if (results.length > 0) {
|
|
17109
17247
|
const preference = results[0];
|
|
17110
17248
|
await preference.update((pref) => {
|
|
@@ -17122,7 +17260,7 @@ async function setModelPreferenceOp(ctx, walletAddress, models) {
|
|
|
17122
17260
|
return modelPreferenceToStored(result);
|
|
17123
17261
|
}
|
|
17124
17262
|
async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
17125
|
-
const results = await ctx.modelPreferencesCollection.query(
|
|
17263
|
+
const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
|
|
17126
17264
|
if (results.length === 0) return false;
|
|
17127
17265
|
await ctx.database.write(async () => {
|
|
17128
17266
|
await results[0].destroyPermanently();
|
|
@@ -17131,11 +17269,11 @@ async function deleteModelPreferenceOp(ctx, walletAddress) {
|
|
|
17131
17269
|
}
|
|
17132
17270
|
|
|
17133
17271
|
// src/lib/db/settings/schema.ts
|
|
17134
|
-
var
|
|
17135
|
-
var settingsStorageSchema = (0,
|
|
17272
|
+
var import_watermelondb28 = require("@nozbe/watermelondb");
|
|
17273
|
+
var settingsStorageSchema = (0, import_watermelondb28.appSchema)({
|
|
17136
17274
|
version: 1,
|
|
17137
17275
|
tables: [
|
|
17138
|
-
(0,
|
|
17276
|
+
(0, import_watermelondb28.tableSchema)({
|
|
17139
17277
|
name: "modelPreferences",
|
|
17140
17278
|
columns: [
|
|
17141
17279
|
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
@@ -17146,7 +17284,7 @@ var settingsStorageSchema = (0, import_watermelondb27.appSchema)({
|
|
|
17146
17284
|
});
|
|
17147
17285
|
|
|
17148
17286
|
// src/lib/db/userPreferences/operations.ts
|
|
17149
|
-
var
|
|
17287
|
+
var import_watermelondb29 = require("@nozbe/watermelondb");
|
|
17150
17288
|
function userPreferenceToStored(preference) {
|
|
17151
17289
|
return {
|
|
17152
17290
|
uniqueId: preference.id,
|
|
@@ -17156,12 +17294,13 @@ function userPreferenceToStored(preference) {
|
|
|
17156
17294
|
description: preference.description,
|
|
17157
17295
|
models: preference.models,
|
|
17158
17296
|
personality: preference.personality,
|
|
17297
|
+
externalWallets: preference.externalWallets,
|
|
17159
17298
|
createdAt: preference.createdAt,
|
|
17160
17299
|
updatedAt: preference.updatedAt
|
|
17161
17300
|
};
|
|
17162
17301
|
}
|
|
17163
17302
|
async function getUserPreferenceOp(ctx, walletAddress) {
|
|
17164
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
17303
|
+
const results = await ctx.userPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
|
|
17165
17304
|
return results.length > 0 ? userPreferenceToStored(results[0]) : null;
|
|
17166
17305
|
}
|
|
17167
17306
|
async function createUserPreferenceOp(ctx, opts) {
|
|
@@ -17174,6 +17313,7 @@ async function createUserPreferenceOp(ctx, opts) {
|
|
|
17174
17313
|
if (opts.description) pref._setRaw("description", opts.description);
|
|
17175
17314
|
if (opts.models) pref._setRaw("models", opts.models);
|
|
17176
17315
|
if (opts.personality) pref._setRaw("personality", opts.personality);
|
|
17316
|
+
if (opts.externalWallets) pref._setRaw("external_wallets", opts.externalWallets);
|
|
17177
17317
|
pref._setRaw("created_at", now);
|
|
17178
17318
|
pref._setRaw("updated_at", now);
|
|
17179
17319
|
});
|
|
@@ -17181,7 +17321,7 @@ async function createUserPreferenceOp(ctx, opts) {
|
|
|
17181
17321
|
return userPreferenceToStored(created);
|
|
17182
17322
|
}
|
|
17183
17323
|
async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
17184
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
17324
|
+
const results = await ctx.userPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
|
|
17185
17325
|
if (results.length === 0) return null;
|
|
17186
17326
|
const preference = results[0];
|
|
17187
17327
|
await ctx.database.write(async () => {
|
|
@@ -17201,6 +17341,9 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
17201
17341
|
if (opts.personality !== void 0) {
|
|
17202
17342
|
pref._setRaw("personality", opts.personality || null);
|
|
17203
17343
|
}
|
|
17344
|
+
if (opts.externalWallets !== void 0) {
|
|
17345
|
+
pref._setRaw("external_wallets", opts.externalWallets || null);
|
|
17346
|
+
}
|
|
17204
17347
|
pref._setRaw("updated_at", Date.now());
|
|
17205
17348
|
});
|
|
17206
17349
|
});
|
|
@@ -17209,7 +17352,7 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
17209
17352
|
async function setUserPreferenceOp(ctx, walletAddress, opts) {
|
|
17210
17353
|
const now = Date.now();
|
|
17211
17354
|
const result = await ctx.database.write(async () => {
|
|
17212
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
17355
|
+
const results = await ctx.userPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
|
|
17213
17356
|
if (results.length > 0) {
|
|
17214
17357
|
const preference = results[0];
|
|
17215
17358
|
await preference.update((pref) => {
|
|
@@ -17228,6 +17371,9 @@ async function setUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
17228
17371
|
if (opts.personality !== void 0) {
|
|
17229
17372
|
pref._setRaw("personality", opts.personality || null);
|
|
17230
17373
|
}
|
|
17374
|
+
if (opts.externalWallets !== void 0) {
|
|
17375
|
+
pref._setRaw("external_wallets", opts.externalWallets || null);
|
|
17376
|
+
}
|
|
17231
17377
|
pref._setRaw("updated_at", now);
|
|
17232
17378
|
});
|
|
17233
17379
|
return preference;
|
|
@@ -17239,6 +17385,7 @@ async function setUserPreferenceOp(ctx, walletAddress, opts) {
|
|
|
17239
17385
|
if (opts.description) pref._setRaw("description", opts.description);
|
|
17240
17386
|
if (opts.models) pref._setRaw("models", opts.models);
|
|
17241
17387
|
if (opts.personality) pref._setRaw("personality", opts.personality);
|
|
17388
|
+
if (opts.externalWallets) pref._setRaw("external_wallets", opts.externalWallets);
|
|
17242
17389
|
pref._setRaw("created_at", now);
|
|
17243
17390
|
pref._setRaw("updated_at", now);
|
|
17244
17391
|
});
|
|
@@ -17257,7 +17404,7 @@ async function updateModelsOp(ctx, walletAddress, models) {
|
|
|
17257
17404
|
return updateUserPreferenceOp(ctx, walletAddress, { models });
|
|
17258
17405
|
}
|
|
17259
17406
|
async function deleteUserPreferenceOp(ctx, walletAddress) {
|
|
17260
|
-
const results = await ctx.userPreferencesCollection.query(
|
|
17407
|
+
const results = await ctx.userPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
|
|
17261
17408
|
if (results.length === 0) return false;
|
|
17262
17409
|
await ctx.database.write(async () => {
|
|
17263
17410
|
await results[0].destroyPermanently();
|
|
@@ -17272,9 +17419,9 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
|
|
|
17272
17419
|
if (existing) {
|
|
17273
17420
|
return existing;
|
|
17274
17421
|
}
|
|
17275
|
-
const modelResults = await ctx.modelPreferencesCollection.query(
|
|
17422
|
+
const modelResults = await ctx.modelPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
|
|
17276
17423
|
const personalityKey = `${walletAddress}_personality_settings`;
|
|
17277
|
-
const personalityResults = await ctx.modelPreferencesCollection.query(
|
|
17424
|
+
const personalityResults = await ctx.modelPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", personalityKey)).fetch();
|
|
17278
17425
|
if (modelResults.length === 0 && personalityResults.length === 0) {
|
|
17279
17426
|
return null;
|
|
17280
17427
|
}
|
|
@@ -17316,11 +17463,11 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
|
|
|
17316
17463
|
}
|
|
17317
17464
|
|
|
17318
17465
|
// src/lib/db/userPreferences/schema.ts
|
|
17319
|
-
var
|
|
17320
|
-
var userPreferencesStorageSchema = (0,
|
|
17466
|
+
var import_watermelondb30 = require("@nozbe/watermelondb");
|
|
17467
|
+
var userPreferencesStorageSchema = (0, import_watermelondb30.appSchema)({
|
|
17321
17468
|
version: 1,
|
|
17322
17469
|
tables: [
|
|
17323
|
-
(0,
|
|
17470
|
+
(0, import_watermelondb30.tableSchema)({
|
|
17324
17471
|
name: "userPreferences",
|
|
17325
17472
|
columns: [
|
|
17326
17473
|
{ name: "wallet_address", type: "string", isIndexed: true },
|
|
@@ -17329,6 +17476,7 @@ var userPreferencesStorageSchema = (0, import_watermelondb29.appSchema)({
|
|
|
17329
17476
|
{ name: "description", type: "string", isOptional: true },
|
|
17330
17477
|
{ name: "models", type: "string", isOptional: true },
|
|
17331
17478
|
{ name: "personality", type: "string", isOptional: true },
|
|
17479
|
+
{ name: "external_wallets", type: "string", isOptional: true },
|
|
17332
17480
|
{ name: "created_at", type: "number" },
|
|
17333
17481
|
{ name: "updated_at", type: "number" }
|
|
17334
17482
|
]
|
|
@@ -17375,7 +17523,7 @@ var SLIDER_CONFIG = [
|
|
|
17375
17523
|
];
|
|
17376
17524
|
|
|
17377
17525
|
// src/lib/db/vaultFolders/operations.ts
|
|
17378
|
-
var
|
|
17526
|
+
var import_watermelondb31 = require("@nozbe/watermelondb");
|
|
17379
17527
|
function folderToStored(folder) {
|
|
17380
17528
|
return {
|
|
17381
17529
|
uniqueId: folder.id,
|
|
@@ -17400,7 +17548,7 @@ async function createVaultFolderOp(ctx, opts) {
|
|
|
17400
17548
|
return folderToStored(created);
|
|
17401
17549
|
}
|
|
17402
17550
|
async function getAllVaultFoldersOp(ctx) {
|
|
17403
|
-
const results = await ctx.vaultFolderCollection.query(
|
|
17551
|
+
const results = await ctx.vaultFolderCollection.query(import_watermelondb31.Q.where("is_deleted", false), import_watermelondb31.Q.sortBy("created_at", import_watermelondb31.Q.desc)).fetch();
|
|
17404
17552
|
return results.map(folderToStored);
|
|
17405
17553
|
}
|
|
17406
17554
|
async function updateVaultFolderOp(ctx, id, opts) {
|
|
@@ -17409,7 +17557,7 @@ async function updateVaultFolderOp(ctx, id, opts) {
|
|
|
17409
17557
|
if (record2.isDeleted) return null;
|
|
17410
17558
|
const scopeChanged = opts.scope !== void 0 && opts.scope !== record2.scope;
|
|
17411
17559
|
const updated = await ctx.database.write(async () => {
|
|
17412
|
-
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(
|
|
17560
|
+
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(import_watermelondb31.Q.where("folder_id", id), import_watermelondb31.Q.where("is_deleted", false)).fetch() : [];
|
|
17413
17561
|
const updates = [];
|
|
17414
17562
|
updates.push(
|
|
17415
17563
|
record2.prepareUpdate((r) => {
|
|
@@ -17438,7 +17586,7 @@ async function deleteVaultFolderOp(ctx, id) {
|
|
|
17438
17586
|
const record2 = await ctx.vaultFolderCollection.find(id);
|
|
17439
17587
|
if (record2.isDeleted) return false;
|
|
17440
17588
|
await ctx.database.write(async () => {
|
|
17441
|
-
const memories = await ctx.vaultMemoryCollection.query(
|
|
17589
|
+
const memories = await ctx.vaultMemoryCollection.query(import_watermelondb31.Q.where("folder_id", id), import_watermelondb31.Q.where("is_deleted", false)).fetch();
|
|
17442
17590
|
const preparedMemories = memories.map(
|
|
17443
17591
|
(memory) => memory.prepareUpdate((r) => {
|
|
17444
17592
|
r._setRaw("folder_id", null);
|
|
@@ -17509,7 +17657,7 @@ async function updateVaultFolderContextOp(ctx, id, context) {
|
|
|
17509
17657
|
}
|
|
17510
17658
|
}
|
|
17511
17659
|
async function getVaultFolderMemoryCountOp(ctx, folderId) {
|
|
17512
|
-
return await ctx.vaultMemoryCollection.query(
|
|
17660
|
+
return await ctx.vaultMemoryCollection.query(import_watermelondb31.Q.where("folder_id", folderId), import_watermelondb31.Q.where("is_deleted", false)).fetchCount();
|
|
17513
17661
|
}
|
|
17514
17662
|
|
|
17515
17663
|
// src/lib/db/vaultFolders/defaults.ts
|
|
@@ -17558,7 +17706,7 @@ init_logger();
|
|
|
17558
17706
|
init_internalFlowMarker();
|
|
17559
17707
|
|
|
17560
17708
|
// src/lib/memory/autoExtract.ts
|
|
17561
|
-
var
|
|
17709
|
+
var import_watermelondb32 = require("@nozbe/watermelondb");
|
|
17562
17710
|
init_logger();
|
|
17563
17711
|
init_redactor();
|
|
17564
17712
|
|
|
@@ -20285,7 +20433,7 @@ async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
|
20285
20433
|
// src/lib/memory/autoExtract.ts
|
|
20286
20434
|
async function isMemoryTopicsUserManaged(ctx, memoryId) {
|
|
20287
20435
|
try {
|
|
20288
|
-
const rows = await ctx.database.get(VaultMemory.table).query(
|
|
20436
|
+
const rows = await ctx.database.get(VaultMemory.table).query(import_watermelondb32.Q.where("id", memoryId)).fetch();
|
|
20289
20437
|
return rows[0]?.topicsUserManaged === true;
|
|
20290
20438
|
} catch {
|
|
20291
20439
|
return true;
|
|
@@ -22873,7 +23021,7 @@ function parseAnswer(body, base, parseSchema) {
|
|
|
22873
23021
|
}
|
|
22874
23022
|
|
|
22875
23023
|
// src/lib/memory/store/local.ts
|
|
22876
|
-
var
|
|
23024
|
+
var import_watermelondb33 = require("@nozbe/watermelondb");
|
|
22877
23025
|
init_logger();
|
|
22878
23026
|
|
|
22879
23027
|
// src/lib/memory/topicExtract.ts
|
|
@@ -23156,8 +23304,8 @@ function createLocalMemoryStore(options) {
|
|
|
23156
23304
|
writeOptions?.signal?.throwIfAborted();
|
|
23157
23305
|
};
|
|
23158
23306
|
const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
|
|
23159
|
-
const ownedBy = userId !== void 0 ? [
|
|
23160
|
-
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [
|
|
23307
|
+
const ownedBy = userId !== void 0 ? [import_watermelondb33.Q.where("user_id", userId)] : [];
|
|
23308
|
+
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [import_watermelondb33.Q.or(import_watermelondb33.Q.where("user_id", userId), import_watermelondb33.Q.where("user_id", null))] : [import_watermelondb33.Q.where("user_id", userId)];
|
|
23161
23309
|
const watchedColumns = [
|
|
23162
23310
|
"content",
|
|
23163
23311
|
"scope",
|
|
@@ -23202,7 +23350,7 @@ function createLocalMemoryStore(options) {
|
|
|
23202
23350
|
list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
|
|
23203
23351
|
get: (id) => getVaultMemoryOp(vaultCtx, id),
|
|
23204
23352
|
listArchived: async () => {
|
|
23205
|
-
const ids = await vaultCtx.vaultMemoryCollection.query(
|
|
23353
|
+
const ids = await vaultCtx.vaultMemoryCollection.query(import_watermelondb33.Q.where("is_deleted", false), import_watermelondb33.Q.where("archived_at", import_watermelondb33.Q.notEq(null)), ...ownedBy).fetchIds();
|
|
23206
23354
|
if (ids.length === 0) return [];
|
|
23207
23355
|
const rows = await getAllVaultMemoriesOp(vaultCtx, { memoryIds: ids, includeArchived: true });
|
|
23208
23356
|
return rows.sort((a, b) => (b.archivedAt ?? 0) - (a.archivedAt ?? 0));
|
|
@@ -23218,7 +23366,7 @@ function createLocalMemoryStore(options) {
|
|
|
23218
23366
|
set.add(String(link.memory_id));
|
|
23219
23367
|
members.set(entityId, set);
|
|
23220
23368
|
}
|
|
23221
|
-
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(
|
|
23369
|
+
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(import_watermelondb33.Q.where("id", import_watermelondb33.Q.oneOf([...members.keys()]))).unsafeFetchRaw() : [];
|
|
23222
23370
|
const byName = /* @__PURE__ */ new Map();
|
|
23223
23371
|
for (const entity of entities) {
|
|
23224
23372
|
const name = String(entity.canonical_name);
|
|
@@ -23268,7 +23416,7 @@ function createLocalMemoryStore(options) {
|
|
|
23268
23416
|
setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
|
|
23269
23417
|
addTopics: (memoryId, topics, writeOptions) => database.write(async (writer) => {
|
|
23270
23418
|
await assertWrite(writeOptions);
|
|
23271
|
-
const owned = await vaultCtx.vaultMemoryCollection.query(
|
|
23419
|
+
const owned = await vaultCtx.vaultMemoryCollection.query(import_watermelondb33.Q.where("id", memoryId), import_watermelondb33.Q.where("is_deleted", false), ...ownedBy).fetchCount();
|
|
23272
23420
|
return owned > 0 ? writer.callWriter(
|
|
23273
23421
|
() => linkMemoryEntitiesOp(
|
|
23274
23422
|
{
|
|
@@ -23340,7 +23488,7 @@ function createLocalMemoryStore(options) {
|
|
|
23340
23488
|
else onChange();
|
|
23341
23489
|
};
|
|
23342
23490
|
};
|
|
23343
|
-
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(
|
|
23491
|
+
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(import_watermelondb33.Q.where("is_deleted", false), ...ownedBy).observeWithColumns(
|
|
23344
23492
|
subscribeOptions?.embeddings ? [...watchedColumns, "embedding", "embedding_model"] : watchedColumns
|
|
23345
23493
|
);
|
|
23346
23494
|
const subscriptions = [memories.subscribe(afterFirst())];
|
|
@@ -26407,7 +26555,7 @@ async function assembleMemoryContext(options) {
|
|
|
26407
26555
|
}
|
|
26408
26556
|
|
|
26409
26557
|
// src/lib/memory/durableExtraction.ts
|
|
26410
|
-
var
|
|
26558
|
+
var import_watermelondb34 = require("@nozbe/watermelondb");
|
|
26411
26559
|
var MAX_JOBS_PER_PASS = 3;
|
|
26412
26560
|
var MAX_ATTEMPTS = 3;
|
|
26413
26561
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -26578,7 +26726,7 @@ function createDurableAutoExtractor(options) {
|
|
|
26578
26726
|
const source = options.messageSource?.(conversationId);
|
|
26579
26727
|
if (source)
|
|
26580
26728
|
return await fromSource(source.status(conversationId)) === "ready" && (await loadFromSource(source, conversationId, ids)).every(Boolean);
|
|
26581
|
-
return await storage.conversationsCollection.query(
|
|
26729
|
+
return await storage.conversationsCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.where("is_deleted", false)).fetchCount() > 0 && await storage.messagesCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.where("id", import_watermelondb34.Q.oneOf(ids))).fetchCount() === ids.length;
|
|
26582
26730
|
}
|
|
26583
26731
|
function schedule(delay) {
|
|
26584
26732
|
if (disposed) return;
|
|
@@ -26752,7 +26900,7 @@ function createDurableAutoExtractor(options) {
|
|
|
26752
26900
|
let sourceWaiting = false;
|
|
26753
26901
|
try {
|
|
26754
26902
|
await writes;
|
|
26755
|
-
const pending = await jobs.query(
|
|
26903
|
+
const pending = await jobs.query(import_watermelondb34.Q.where("owner_key", owner), import_watermelondb34.Q.where("message_ids", import_watermelondb34.Q.notEq("[]"))).fetch();
|
|
26756
26904
|
storeFailures = 0;
|
|
26757
26905
|
let processed = 0;
|
|
26758
26906
|
for (const job of pending) {
|
|
@@ -26784,7 +26932,7 @@ function createDurableAutoExtractor(options) {
|
|
|
26784
26932
|
let ids = [];
|
|
26785
26933
|
let loaded = [];
|
|
26786
26934
|
try {
|
|
26787
|
-
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(
|
|
26935
|
+
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.where("is_deleted", false)).fetchCount() > 0;
|
|
26788
26936
|
if (!present) {
|
|
26789
26937
|
await database.write(() => job.destroyPermanently());
|
|
26790
26938
|
continue;
|
|
@@ -26952,7 +27100,7 @@ function createDurableAutoExtractor(options) {
|
|
|
26952
27100
|
const scope = currentScope();
|
|
26953
27101
|
writes = writes.then(
|
|
26954
27102
|
() => database.write(async () => {
|
|
26955
|
-
const existing = await jobs.query(
|
|
27103
|
+
const existing = await jobs.query(import_watermelondb34.Q.where("owner_key", owner), import_watermelondb34.Q.where("conversation_id", conversationId)).fetch();
|
|
26956
27104
|
const job = existing.find(
|
|
26957
27105
|
(candidate) => candidate._getRaw("scope") === scope && (candidate._getRaw("folder_id") ?? null) === folderId
|
|
26958
27106
|
);
|
|
@@ -26965,8 +27113,8 @@ function createDurableAutoExtractor(options) {
|
|
|
26965
27113
|
if (watermarks.length) {
|
|
26966
27114
|
const misplaced = new Set(
|
|
26967
27115
|
await storage.messagesCollection.query(
|
|
26968
|
-
|
|
26969
|
-
|
|
27116
|
+
import_watermelondb34.Q.where("id", import_watermelondb34.Q.oneOf(watermarks)),
|
|
27117
|
+
import_watermelondb34.Q.where("conversation_id", import_watermelondb34.Q.notEq(conversationId))
|
|
26970
27118
|
).fetchIds()
|
|
26971
27119
|
);
|
|
26972
27120
|
for (const prior of existing)
|
|
@@ -26976,7 +27124,7 @@ function createDurableAutoExtractor(options) {
|
|
|
26976
27124
|
r._setRaw("watermark_seq", null);
|
|
26977
27125
|
});
|
|
26978
27126
|
}
|
|
26979
|
-
const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(
|
|
27127
|
+
const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(import_watermelondb34.Q.where("id", import_watermelondb34.Q.oneOf(ids))).fetch();
|
|
26980
27128
|
const foreignRows = new Set(
|
|
26981
27129
|
rows.filter((row) => row._getRaw("conversation_id") !== conversationId).map((row) => row.id)
|
|
26982
27130
|
);
|
|
@@ -29445,7 +29593,7 @@ function computeToolGuidance(selectedServerTools, selectedClientTools, extraTool
|
|
|
29445
29593
|
async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embeddingOptions, extraToolSets = [], activeToolSets = [], noEmbeddingsReason = "short-prompt") {
|
|
29446
29594
|
const isAlwaysIncluded = (t) => {
|
|
29447
29595
|
const name = getToolName2(t);
|
|
29448
|
-
return name.startsWith("memory_vault_") || name === RECALL_TOOL_NAME || name === CONFIRM_TOOL_NAME;
|
|
29596
|
+
return name.startsWith("memory_vault_") || name === RECALL_TOOL_NAME || name === CONFIRM_TOOL_NAME || name === SELECT_PAYMENT_WALLET_TOOL_NAME || name === WALLET_PAYMENT_TOOL_NAME;
|
|
29449
29597
|
};
|
|
29450
29598
|
const alwaysInclude = clientTools.filter(isAlwaysIncluded);
|
|
29451
29599
|
const filterCandidates = clientTools.filter((t) => !isAlwaysIncluded(t));
|
|
@@ -29457,7 +29605,7 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
29457
29605
|
}
|
|
29458
29606
|
if (!promptEmbeddings) {
|
|
29459
29607
|
if (activeToolSets.length === 0) {
|
|
29460
|
-
return { tools:
|
|
29608
|
+
return { tools: alwaysInclude, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
29461
29609
|
}
|
|
29462
29610
|
const allSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
29463
29611
|
const activeSets = allSets.filter((s) => activeToolSets.includes(s.name));
|
|
@@ -30542,6 +30690,177 @@ function migrateDisplayResult(result, fromVersion, toVersion, migrations) {
|
|
|
30542
30690
|
}
|
|
30543
30691
|
return current;
|
|
30544
30692
|
}
|
|
30693
|
+
function generateInteractionId(prefix) {
|
|
30694
|
+
return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
|
|
30695
|
+
}
|
|
30696
|
+
function createInteractiveTool(options, config) {
|
|
30697
|
+
return {
|
|
30698
|
+
type: "function",
|
|
30699
|
+
function: {
|
|
30700
|
+
name: config.name,
|
|
30701
|
+
description: config.description,
|
|
30702
|
+
arguments: config.parameters
|
|
30703
|
+
},
|
|
30704
|
+
executor: async (args, signal) => {
|
|
30705
|
+
if (config.validate && !config.validate(args)) {
|
|
30706
|
+
return { cancelled: true };
|
|
30707
|
+
}
|
|
30708
|
+
const context = options.getContext();
|
|
30709
|
+
if (!context) {
|
|
30710
|
+
return { cancelled: true };
|
|
30711
|
+
}
|
|
30712
|
+
const interactionId = generateInteractionId(config.interactionType);
|
|
30713
|
+
const interactionData = config.mapArgs ? config.mapArgs(args) : args;
|
|
30714
|
+
const onAbort = () => context.cancelInteraction?.(interactionId);
|
|
30715
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
30716
|
+
try {
|
|
30717
|
+
const result = await context.createInteraction(interactionId, config.interactionType, {
|
|
30718
|
+
...interactionData,
|
|
30719
|
+
afterMessageId: options.getLastMessageId?.()
|
|
30720
|
+
});
|
|
30721
|
+
if (config.mapResult) {
|
|
30722
|
+
return config.mapResult(result, args);
|
|
30723
|
+
}
|
|
30724
|
+
return result;
|
|
30725
|
+
} catch {
|
|
30726
|
+
return { cancelled: true };
|
|
30727
|
+
} finally {
|
|
30728
|
+
signal?.removeEventListener("abort", onAbort);
|
|
30729
|
+
}
|
|
30730
|
+
},
|
|
30731
|
+
executorTimeout: Infinity
|
|
30732
|
+
};
|
|
30733
|
+
}
|
|
30734
|
+
|
|
30735
|
+
// src/tools/walletPayment.ts
|
|
30736
|
+
var CANCELLED = { cancelled: true };
|
|
30737
|
+
function isNonEmptyString(value) {
|
|
30738
|
+
return typeof value === "string" && value.length > 0;
|
|
30739
|
+
}
|
|
30740
|
+
function hasPassengers(value) {
|
|
30741
|
+
return Array.isArray(value?.passengers);
|
|
30742
|
+
}
|
|
30743
|
+
function createSelectPaymentWalletTool(options) {
|
|
30744
|
+
const tool = createInteractiveTool(options, {
|
|
30745
|
+
name: SELECT_PAYMENT_WALLET_TOOL_NAME,
|
|
30746
|
+
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.",
|
|
30747
|
+
parameters: {
|
|
30748
|
+
type: "object",
|
|
30749
|
+
properties: {
|
|
30750
|
+
offer_id: {
|
|
30751
|
+
type: "string",
|
|
30752
|
+
description: "The offer id from anuma_flight_offer_details"
|
|
30753
|
+
},
|
|
30754
|
+
summary: {
|
|
30755
|
+
type: "string",
|
|
30756
|
+
description: "Route, dates and fare of the offer, as shown to the user"
|
|
30757
|
+
},
|
|
30758
|
+
amount: {
|
|
30759
|
+
type: "string",
|
|
30760
|
+
description: "Total price of the offer, e.g. '412.50'"
|
|
30761
|
+
},
|
|
30762
|
+
currency: {
|
|
30763
|
+
type: "string",
|
|
30764
|
+
description: "Currency of the price, e.g. 'USD'"
|
|
30765
|
+
}
|
|
30766
|
+
},
|
|
30767
|
+
required: ["offer_id", "amount", "currency"]
|
|
30768
|
+
},
|
|
30769
|
+
interactionType: "select_payment_wallet",
|
|
30770
|
+
validate: (args) => isNonEmptyString(args.offer_id),
|
|
30771
|
+
mapArgs: ({ offer_id, summary, amount, currency, wallets }) => ({
|
|
30772
|
+
offer_id,
|
|
30773
|
+
summary,
|
|
30774
|
+
amount,
|
|
30775
|
+
currency,
|
|
30776
|
+
wallets
|
|
30777
|
+
}),
|
|
30778
|
+
mapResult: (result, args) => {
|
|
30779
|
+
if (result?.confirmed === true && isNonEmptyString(result.funding_wallet)) {
|
|
30780
|
+
return {
|
|
30781
|
+
confirmed: true,
|
|
30782
|
+
offer_id: args.offer_id,
|
|
30783
|
+
funding_wallet: result.funding_wallet
|
|
30784
|
+
};
|
|
30785
|
+
}
|
|
30786
|
+
if (result?.confirmed === false) return { confirmed: false };
|
|
30787
|
+
return CANCELLED;
|
|
30788
|
+
}
|
|
30789
|
+
});
|
|
30790
|
+
const showCard = tool.executor;
|
|
30791
|
+
return {
|
|
30792
|
+
...tool,
|
|
30793
|
+
executor: async (args, signal) => {
|
|
30794
|
+
if (!isNonEmptyString(args.offer_id)) return CANCELLED;
|
|
30795
|
+
let wallets;
|
|
30796
|
+
try {
|
|
30797
|
+
wallets = await options.listWallets();
|
|
30798
|
+
} catch {
|
|
30799
|
+
return { error_code: "wallets_unavailable", retryable: true };
|
|
30800
|
+
}
|
|
30801
|
+
if (signal?.aborted) return CANCELLED;
|
|
30802
|
+
return showCard?.({ ...args, wallets }, signal);
|
|
30803
|
+
}
|
|
30804
|
+
};
|
|
30805
|
+
}
|
|
30806
|
+
function createWalletPaymentTool(options) {
|
|
30807
|
+
const tool = createInteractiveTool(options, {
|
|
30808
|
+
name: WALLET_PAYMENT_TOOL_NAME,
|
|
30809
|
+
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.",
|
|
30810
|
+
parameters: {
|
|
30811
|
+
type: "object",
|
|
30812
|
+
properties: {
|
|
30813
|
+
provider: {
|
|
30814
|
+
type: "string",
|
|
30815
|
+
description: "The payment provider from anuma_create_flight_intent"
|
|
30816
|
+
},
|
|
30817
|
+
reference: {
|
|
30818
|
+
type: "string",
|
|
30819
|
+
description: "The payment reference from anuma_create_flight_intent"
|
|
30820
|
+
},
|
|
30821
|
+
passenger_count: {
|
|
30822
|
+
type: "integer",
|
|
30823
|
+
minimum: 1,
|
|
30824
|
+
description: "How many passengers the booking is for"
|
|
30825
|
+
}
|
|
30826
|
+
},
|
|
30827
|
+
required: ["provider", "reference", "passenger_count"]
|
|
30828
|
+
},
|
|
30829
|
+
interactionType: "prompt_wallet_payment",
|
|
30830
|
+
validate: (args) => isNonEmptyString(args.provider) && isNonEmptyString(args.reference) && Number.isInteger(args.passenger_count) && args.passenger_count >= 1,
|
|
30831
|
+
mapArgs: ({ provider, reference, passenger_count }) => ({
|
|
30832
|
+
provider,
|
|
30833
|
+
reference,
|
|
30834
|
+
passenger_count
|
|
30835
|
+
}),
|
|
30836
|
+
mapResult: (result) => hasPassengers(result) ? { passengers: result.passengers } : CANCELLED
|
|
30837
|
+
});
|
|
30838
|
+
const showCard = tool.executor;
|
|
30839
|
+
return {
|
|
30840
|
+
...tool,
|
|
30841
|
+
executor: async (args, signal) => {
|
|
30842
|
+
const answer = await showCard?.(args, signal);
|
|
30843
|
+
if (!hasPassengers(answer) || signal?.aborted) return CANCELLED;
|
|
30844
|
+
const provider = args.provider;
|
|
30845
|
+
const reference = args.reference;
|
|
30846
|
+
let outcome2;
|
|
30847
|
+
try {
|
|
30848
|
+
outcome2 = await options.pay({ provider, reference, passengers: answer.passengers }, signal);
|
|
30849
|
+
} catch {
|
|
30850
|
+
return { paid: false, error_code: "payment_failed", retryable: false };
|
|
30851
|
+
}
|
|
30852
|
+
if (outcome2.paid) {
|
|
30853
|
+
return {
|
|
30854
|
+
paid: true,
|
|
30855
|
+
provider: outcome2.provider,
|
|
30856
|
+
reference: outcome2.reference,
|
|
30857
|
+
status: outcome2.status
|
|
30858
|
+
};
|
|
30859
|
+
}
|
|
30860
|
+
return { paid: false, error_code: outcome2.error_code, retryable: outcome2.retryable };
|
|
30861
|
+
}
|
|
30862
|
+
};
|
|
30863
|
+
}
|
|
30545
30864
|
|
|
30546
30865
|
// src/react/anumaRuntime.tsx
|
|
30547
30866
|
var React = __toESM(require("react"));
|
|
@@ -31669,10 +31988,10 @@ var UNREVISIONED_COLUMNS = /* @__PURE__ */ new Set([
|
|
|
31669
31988
|
]);
|
|
31670
31989
|
async function getBackupRevision(database, conversationId) {
|
|
31671
31990
|
const serialized = await database.read(async () => {
|
|
31672
|
-
const { Q:
|
|
31991
|
+
const { Q: Q21 } = await import("@nozbe/watermelondb");
|
|
31673
31992
|
const tables = await Promise.all(
|
|
31674
31993
|
["conversations", "history"].map(
|
|
31675
|
-
(table) => database.get(table).query(
|
|
31994
|
+
(table) => database.get(table).query(Q21.where("conversation_id", conversationId), Q21.sortBy("id", Q21.asc)).unsafeFetchRaw()
|
|
31676
31995
|
)
|
|
31677
31996
|
);
|
|
31678
31997
|
return JSON.stringify(
|
|
@@ -31715,9 +32034,9 @@ async function pushConversationToICloud(database, conversationId, userAddress, d
|
|
|
31715
32034
|
}
|
|
31716
32035
|
async function performICloudExport(database, userAddress, deps, onProgress) {
|
|
31717
32036
|
await deps.requestEncryptionKey(userAddress);
|
|
31718
|
-
const { Q:
|
|
32037
|
+
const { Q: Q21 } = await import("@nozbe/watermelondb");
|
|
31719
32038
|
const conversationsCollection = database.get("conversations");
|
|
31720
|
-
const records = await conversationsCollection.query(
|
|
32039
|
+
const records = await conversationsCollection.query(Q21.where("is_deleted", false)).fetch();
|
|
31721
32040
|
const conversations = records.map(conversationToStoredRaw);
|
|
31722
32041
|
const total = conversations.length;
|
|
31723
32042
|
if (total === 0) {
|
|
@@ -35447,7 +35766,7 @@ function useExportPdf() {
|
|
|
35447
35766
|
}
|
|
35448
35767
|
|
|
35449
35768
|
// src/react/useFiles.ts
|
|
35450
|
-
var
|
|
35769
|
+
var import_watermelondb35 = require("@nozbe/watermelondb");
|
|
35451
35770
|
var import_react10 = require("react");
|
|
35452
35771
|
init_logger();
|
|
35453
35772
|
function useFiles(options) {
|
|
@@ -35466,7 +35785,7 @@ function useFiles(options) {
|
|
|
35466
35785
|
setIsLoading(true);
|
|
35467
35786
|
try {
|
|
35468
35787
|
const coll = database.get("media");
|
|
35469
|
-
await coll.query(
|
|
35788
|
+
await coll.query(import_watermelondb35.Q.take(1)).fetch();
|
|
35470
35789
|
setMediaCollection(coll);
|
|
35471
35790
|
setIsReady(true);
|
|
35472
35791
|
} catch (error) {
|
|
@@ -36688,7 +37007,7 @@ function usePhoneCalls(options = {}) {
|
|
|
36688
37007
|
}
|
|
36689
37008
|
|
|
36690
37009
|
// src/react/useProjects.ts
|
|
36691
|
-
var
|
|
37010
|
+
var import_watermelondb36 = require("@nozbe/watermelondb");
|
|
36692
37011
|
var import_react17 = require("react");
|
|
36693
37012
|
init_logger();
|
|
36694
37013
|
function useProjects(options) {
|
|
@@ -36711,7 +37030,7 @@ function useProjects(options) {
|
|
|
36711
37030
|
conversations: convColl?.table
|
|
36712
37031
|
});
|
|
36713
37032
|
getLogger().debug("[useProjects] Running test query on projects table...");
|
|
36714
|
-
const testResult = await projColl.query(
|
|
37033
|
+
const testResult = await projColl.query(import_watermelondb36.Q.take(1)).fetch();
|
|
36715
37034
|
getLogger().debug(
|
|
36716
37035
|
"[useProjects] Test query succeeded, found",
|
|
36717
37036
|
testResult.length,
|
|
@@ -36798,7 +37117,7 @@ function useProjects(options) {
|
|
|
36798
37117
|
if (!projectsCollection) {
|
|
36799
37118
|
return;
|
|
36800
37119
|
}
|
|
36801
|
-
const subscription = projectsCollection.query(
|
|
37120
|
+
const subscription = projectsCollection.query(import_watermelondb36.Q.where("is_deleted", false)).observe().subscribe((records) => {
|
|
36802
37121
|
setProjects(records.map(projectToStored));
|
|
36803
37122
|
});
|
|
36804
37123
|
return () => subscription.unsubscribe();
|
|
@@ -36920,7 +37239,7 @@ function useProjects(options) {
|
|
|
36920
37239
|
var import_react18 = require("react");
|
|
36921
37240
|
|
|
36922
37241
|
// src/react/userSettingsStore.ts
|
|
36923
|
-
var
|
|
37242
|
+
var import_watermelondb37 = require("@nozbe/watermelondb");
|
|
36924
37243
|
var EMPTY_SNAPSHOT = Object.freeze({
|
|
36925
37244
|
modelPreference: null,
|
|
36926
37245
|
userPreference: null,
|
|
@@ -36972,12 +37291,13 @@ async function startLoad(entry, walletAddress) {
|
|
|
36972
37291
|
}
|
|
36973
37292
|
function startObserve(entry, walletAddress) {
|
|
36974
37293
|
let isInitialEmission = true;
|
|
36975
|
-
entry.observeSub = entry.storageCtx.userPreferencesCollection.query(
|
|
37294
|
+
entry.observeSub = entry.storageCtx.userPreferencesCollection.query(import_watermelondb37.Q.where("wallet_address", walletAddress)).observeWithColumns([
|
|
36976
37295
|
"nickname",
|
|
36977
37296
|
"occupation",
|
|
36978
37297
|
"description",
|
|
36979
37298
|
"models",
|
|
36980
37299
|
"personality",
|
|
37300
|
+
"external_wallets",
|
|
36981
37301
|
"updated_at"
|
|
36982
37302
|
]).subscribe({
|
|
36983
37303
|
next: (records) => {
|
|
@@ -36992,6 +37312,7 @@ function startObserve(entry, walletAddress) {
|
|
|
36992
37312
|
description: record2.description,
|
|
36993
37313
|
models: record2.models,
|
|
36994
37314
|
personality: record2.personality,
|
|
37315
|
+
externalWallets: record2.externalWallets,
|
|
36995
37316
|
createdAt: record2.createdAt,
|
|
36996
37317
|
updatedAt: record2.updatedAt
|
|
36997
37318
|
}
|
|
@@ -38212,6 +38533,7 @@ function useWalletBinding(options = {}) {
|
|
|
38212
38533
|
RemoteMemoryPartialCreateError,
|
|
38213
38534
|
RerankerUnavailableError,
|
|
38214
38535
|
SDK_SCHEMA_VERSION,
|
|
38536
|
+
SELECT_PAYMENT_WALLET_TOOL_NAME,
|
|
38215
38537
|
SERVER_TOOL_DEPENDENCY_SETS,
|
|
38216
38538
|
SHORT_TTL_MS,
|
|
38217
38539
|
SLIDER_CONFIG,
|
|
@@ -38236,6 +38558,7 @@ function useWalletBinding(options = {}) {
|
|
|
38236
38558
|
TextProcessor,
|
|
38237
38559
|
UIInteractionProvider,
|
|
38238
38560
|
VAULT_SIZE_HOP_CAP,
|
|
38561
|
+
WALLET_PAYMENT_TOOL_NAME,
|
|
38239
38562
|
WalletPoller,
|
|
38240
38563
|
WatermelonChatStorageAdapter,
|
|
38241
38564
|
WordProcessor,
|
|
@@ -38302,12 +38625,14 @@ function useWalletBinding(options = {}) {
|
|
|
38302
38625
|
createRemoteMemoryPipeline,
|
|
38303
38626
|
createRemoteMemoryStore,
|
|
38304
38627
|
createSavedToolOp,
|
|
38628
|
+
createSelectPaymentWalletTool,
|
|
38305
38629
|
createServerToolsFilter,
|
|
38306
38630
|
createStockPricePreProcessor,
|
|
38307
38631
|
createVaultEmbeddingCache,
|
|
38308
38632
|
createVaultFolderOp,
|
|
38309
38633
|
createVaultMemoriesBatchOp,
|
|
38310
38634
|
createVaultMemoryOp,
|
|
38635
|
+
createWalletPaymentTool,
|
|
38311
38636
|
createWeatherPreProcessor,
|
|
38312
38637
|
createWebSearchPreProcessor,
|
|
38313
38638
|
decodeChunkVector,
|