@anuma/sdk 8.0.0 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3515,7 +3515,7 @@ ${appendix}` : appendix;
3515
3515
  }
3516
3516
 
3517
3517
  // src/lib/db/chat/operations.ts
3518
- var import_watermelondb2 = require("@nozbe/watermelondb");
3518
+ var import_watermelondb3 = require("@nozbe/watermelondb");
3519
3519
  var import_uuid2 = require("uuid");
3520
3520
  init_logger();
3521
3521
 
@@ -3964,6 +3964,118 @@ async function assembleDecryptedMessage(message, address) {
3964
3964
  return result;
3965
3965
  }
3966
3966
 
3967
+ // src/lib/db/chat/toolCallEventIndex.ts
3968
+ var import_watermelondb2 = require("@nozbe/watermelondb");
3969
+ function parseEventIds(value) {
3970
+ const ids = /* @__PURE__ */ new Set();
3971
+ let events;
3972
+ try {
3973
+ events = typeof value === "string" ? JSON.parse(value) : value;
3974
+ } catch {
3975
+ return ids;
3976
+ }
3977
+ if (!Array.isArray(events)) return ids;
3978
+ for (const event of events) {
3979
+ if (!event || typeof event !== "object") continue;
3980
+ const id = event.id;
3981
+ if (typeof id === "string" && id) ids.add(id);
3982
+ }
3983
+ return ids;
3984
+ }
3985
+ async function fetchEventRows(collection, conversationId) {
3986
+ try {
3987
+ return await collection.query(
3988
+ import_watermelondb2.Q.unsafeSqlQuery(
3989
+ `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 ('', '[]')`,
3990
+ [conversationId]
3991
+ )
3992
+ ).unsafeFetchRaw();
3993
+ } catch (error) {
3994
+ if (!(error instanceof Error) || !/unsafeSqlQuery.*not supported/.test(error.message)) {
3995
+ throw error;
3996
+ }
3997
+ return await collection.query(
3998
+ import_watermelondb2.Q.where("conversation_id", conversationId),
3999
+ import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notEq(null)),
4000
+ import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notIn(["", "[]"])),
4001
+ import_watermelondb2.Q.unsafeLokiTransform(
4002
+ (rows) => rows.map(({ id, tool_call_events }) => ({ id, tool_call_events }))
4003
+ )
4004
+ ).unsafeFetchRaw();
4005
+ }
4006
+ }
4007
+ var ToolCallEventIndex = class {
4008
+ constructor(collection) {
4009
+ this.collection = collection;
4010
+ this.conversations = /* @__PURE__ */ new Map();
4011
+ this.messages = /* @__PURE__ */ new Map();
4012
+ this.pending = /* @__PURE__ */ new Map();
4013
+ this.resetCount = collection.database._resetCount;
4014
+ collection.experimentalSubscribe((changes) => {
4015
+ for (const { record: record2, type } of changes) {
4016
+ this.replace(
4017
+ record2.id,
4018
+ type === "destroyed" ? void 0 : record2.conversationId,
4019
+ type === "destroyed" ? void 0 : record2._getRaw("tool_call_events")
4020
+ );
4021
+ }
4022
+ });
4023
+ }
4024
+ replace(messageId, conversationId, value) {
4025
+ const previous = this.messages.get(messageId);
4026
+ if (previous) {
4027
+ const counts2 = this.conversations.get(previous.conversationId);
4028
+ for (const id of previous.ids) {
4029
+ const count2 = counts2.get(id) - 1;
4030
+ if (count2 === 0) counts2.delete(id);
4031
+ else counts2.set(id, count2);
4032
+ }
4033
+ this.messages.delete(messageId);
4034
+ }
4035
+ const counts = conversationId === void 0 ? void 0 : this.conversations.get(conversationId);
4036
+ if (!counts || conversationId === void 0) return;
4037
+ const ids = parseEventIds(value);
4038
+ if (ids.size === 0) return;
4039
+ this.messages.set(messageId, { conversationId, ids });
4040
+ for (const id of ids) counts.set(id, (counts.get(id) ?? 0) + 1);
4041
+ }
4042
+ async get(conversationId) {
4043
+ if (this.resetCount !== this.collection.database._resetCount) {
4044
+ this.conversations.clear();
4045
+ this.messages.clear();
4046
+ this.pending.clear();
4047
+ this.resetCount = this.collection.database._resetCount;
4048
+ }
4049
+ if (!this.conversations.has(conversationId)) {
4050
+ let pending = this.pending.get(conversationId);
4051
+ if (!pending) {
4052
+ pending = this.collection.database.read(async () => {
4053
+ const rows = await fetchEventRows(this.collection, conversationId);
4054
+ this.conversations.set(conversationId, /* @__PURE__ */ new Map());
4055
+ for (const row of rows)
4056
+ this.replace(String(row.id), conversationId, row.tool_call_events);
4057
+ });
4058
+ this.pending.set(conversationId, pending);
4059
+ }
4060
+ try {
4061
+ await pending;
4062
+ } finally {
4063
+ this.pending.delete(conversationId);
4064
+ }
4065
+ }
4066
+ return new Set(this.conversations.get(conversationId).keys());
4067
+ }
4068
+ };
4069
+ var indexes = /* @__PURE__ */ new WeakMap();
4070
+ function getToolCallEventIds(collection, conversationId) {
4071
+ let index = indexes.get(collection);
4072
+ if (!index) {
4073
+ index = new ToolCallEventIndex(collection);
4074
+ indexes.set(collection, index);
4075
+ }
4076
+ return index.get(conversationId);
4077
+ }
4078
+
3967
4079
  // src/lib/db/chat/types.ts
3968
4080
  var import_uuid = require("uuid");
3969
4081
 
@@ -4356,7 +4468,7 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
4356
4468
  );
4357
4469
  }
4358
4470
  async function getConversationOp(ctx, id) {
4359
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
4471
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
4360
4472
  return results.length > 0 ? await conversationToStored(
4361
4473
  results[0],
4362
4474
  ctx.walletAddress,
@@ -4365,7 +4477,7 @@ async function getConversationOp(ctx, id) {
4365
4477
  ) : null;
4366
4478
  }
4367
4479
  async function getConversationsOp(ctx) {
4368
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false), import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)).unsafeFetchRaw();
4480
+ 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
4481
  return Promise.all(
4370
4482
  results.map(
4371
4483
  (raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
@@ -4386,33 +4498,33 @@ function conversationRawToLazyStored(raw) {
4386
4498
  };
4387
4499
  }
4388
4500
  async function getConversationsLazyOp(ctx) {
4389
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false), import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)).unsafeFetchRaw();
4501
+ 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
4502
  return results.map(conversationRawToLazyStored);
4391
4503
  }
4392
4504
  async function getConversationsPageOp(ctx, options) {
4393
4505
  const limit = Math.floor(options?.limit ?? 200);
4394
4506
  if (!Number.isFinite(limit) || limit < 1) return [];
4395
4507
  const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
4396
- const clauses = [import_watermelondb2.Q.where("is_deleted", false)];
4508
+ const clauses = [import_watermelondb3.Q.where("is_deleted", false)];
4397
4509
  if (options?.before !== void 0) {
4398
4510
  clauses.push(
4399
- exclude.size > 0 ? import_watermelondb2.Q.where("created_at", import_watermelondb2.Q.lte(options.before)) : import_watermelondb2.Q.where("created_at", import_watermelondb2.Q.lt(options.before))
4511
+ 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
4512
  );
4401
4513
  }
4402
- const fetched = await ctx.conversationsCollection.query(...clauses, import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc), import_watermelondb2.Q.take(limit + exclude.size)).unsafeFetchRaw();
4514
+ 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
4515
  const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
4404
4516
  return results.slice(0, limit).map(conversationRawToLazyStored);
4405
4517
  }
4406
4518
  async function getConversationsByProjectLazyOp(ctx, projectId) {
4407
4519
  const results = await ctx.conversationsCollection.query(
4408
- import_watermelondb2.Q.where("project_id", projectId === null ? "" : projectId),
4409
- import_watermelondb2.Q.where("is_deleted", false),
4410
- import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)
4520
+ import_watermelondb3.Q.where("project_id", projectId === null ? "" : projectId),
4521
+ import_watermelondb3.Q.where("is_deleted", false),
4522
+ import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)
4411
4523
  ).unsafeFetchRaw();
4412
4524
  return results.map(conversationRawToLazyStored);
4413
4525
  }
4414
4526
  async function updateConversationTitleOp(ctx, id, title) {
4415
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
4527
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
4416
4528
  if (results.length > 0) {
4417
4529
  const encryptedOpts = ctx.walletAddress && ctx.signMessage ? await encryptConversationFields(
4418
4530
  { title },
@@ -4431,13 +4543,13 @@ async function updateConversationTitleOp(ctx, id, title) {
4431
4543
  return false;
4432
4544
  }
4433
4545
  async function deleteConversationOp(ctx, id) {
4434
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
4546
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
4435
4547
  if (results.length > 0) {
4436
4548
  await ctx.database.write(async () => {
4437
4549
  await results[0].update((conv) => {
4438
4550
  conv._setRaw("is_deleted", true);
4439
4551
  });
4440
- const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb2.Q.where("conversation_id", id)).fetch() : [];
4552
+ const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", id)).fetch() : [];
4441
4553
  for (const job of jobs) await job.destroyPermanently();
4442
4554
  });
4443
4555
  return true;
@@ -4445,7 +4557,7 @@ async function deleteConversationOp(ctx, id) {
4445
4557
  return false;
4446
4558
  }
4447
4559
  async function updateConversationProjectOp(ctx, id, projectId) {
4448
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
4560
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
4449
4561
  if (results.length > 0) {
4450
4562
  await ctx.database.write(async () => {
4451
4563
  await results[0].update((conv) => {
@@ -4457,7 +4569,7 @@ async function updateConversationProjectOp(ctx, id, projectId) {
4457
4569
  return false;
4458
4570
  }
4459
4571
  async function updateConversationPinnedOp(ctx, id, pinned) {
4460
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
4572
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
4461
4573
  if (results.length > 0) {
4462
4574
  await ctx.database.write(async () => {
4463
4575
  await results[0].update((conv) => {
@@ -4470,9 +4582,9 @@ async function updateConversationPinnedOp(ctx, id, pinned) {
4470
4582
  }
4471
4583
  async function getConversationsByProjectOp(ctx, projectId) {
4472
4584
  const results = await ctx.conversationsCollection.query(
4473
- import_watermelondb2.Q.where("project_id", projectId === null ? "" : projectId),
4474
- import_watermelondb2.Q.where("is_deleted", false),
4475
- import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)
4585
+ import_watermelondb3.Q.where("project_id", projectId === null ? "" : projectId),
4586
+ import_watermelondb3.Q.where("is_deleted", false),
4587
+ import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)
4476
4588
  ).unsafeFetchRaw();
4477
4589
  return Promise.all(
4478
4590
  results.map(
@@ -4481,7 +4593,7 @@ async function getConversationsByProjectOp(ctx, projectId) {
4481
4593
  );
4482
4594
  }
4483
4595
  async function getMessagesOp(ctx, convId, opts) {
4484
- const fetched = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId), import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.asc)).unsafeFetchRaw();
4596
+ 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
4597
  const results = opts?.rawFilter ? fetched.filter(opts.rawFilter) : fetched;
4486
4598
  return Promise.all(
4487
4599
  results.map(
@@ -4490,19 +4602,19 @@ async function getMessagesOp(ctx, convId, opts) {
4490
4602
  );
4491
4603
  }
4492
4604
  async function getMessageCountOp(ctx, convId) {
4493
- return await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId)).fetchCount();
4605
+ return await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetchCount();
4494
4606
  }
4495
4607
  async function getMessagesPageOp(ctx, convId, opts) {
4496
4608
  const limit = Math.floor(opts.limit);
4497
4609
  if (!Number.isFinite(limit) || limit < 1) return [];
4498
4610
  const exclude = new Set(opts.boundaryExcludeUniqueIds ?? []);
4499
- const clauses = [import_watermelondb2.Q.where("conversation_id", convId)];
4611
+ const clauses = [import_watermelondb3.Q.where("conversation_id", convId)];
4500
4612
  if (opts.beforeMessageId !== void 0) {
4501
4613
  clauses.push(
4502
- exclude.size > 0 ? import_watermelondb2.Q.where("message_id", import_watermelondb2.Q.lte(opts.beforeMessageId)) : import_watermelondb2.Q.where("message_id", import_watermelondb2.Q.lt(opts.beforeMessageId))
4614
+ 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
4615
  );
4504
4616
  }
4505
- const fetched = await ctx.messagesCollection.query(...clauses, import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.desc), import_watermelondb2.Q.take(limit + exclude.size)).unsafeFetchRaw();
4617
+ 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
4618
  const results = (exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched).slice(0, limit);
4507
4619
  results.reverse();
4508
4620
  return Promise.all(
@@ -4514,7 +4626,7 @@ async function getMessagesPageOp(ctx, convId, opts) {
4514
4626
  );
4515
4627
  }
4516
4628
  async function getMessageSkeletonsOp(ctx, convId) {
4517
- const results = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId), import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.asc)).unsafeFetchRaw();
4629
+ 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
4630
  const roleById = /* @__PURE__ */ new Map();
4519
4631
  for (const raw of results) {
4520
4632
  roleById.set(raw.id, raw.role);
@@ -4559,32 +4671,12 @@ async function getMessageSkeletonsOp(ctx, convId) {
4559
4671
  return skeletons;
4560
4672
  }
4561
4673
  async function getToolCallEventIdsOp(ctx, convId) {
4562
- const results = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId)).unsafeFetchRaw();
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;
4674
+ return getToolCallEventIds(ctx.messagesCollection, convId);
4583
4675
  }
4584
4676
  async function clearMessagesOp(ctx, convId) {
4585
4677
  await ctx.database.write(async () => {
4586
- const messages = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId)).fetch();
4587
- const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb2.Q.where("conversation_id", convId)).fetch() : [];
4678
+ const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetch();
4679
+ const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", convId)).fetch() : [];
4588
4680
  for (const job of jobs) {
4589
4681
  await job.update((row) => {
4590
4682
  row._setRaw("message_ids", "[]");
@@ -4609,7 +4701,7 @@ async function deleteMessageOp(ctx, uniqueId) {
4609
4701
  return null;
4610
4702
  }
4611
4703
  await ctx.database.write(async () => {
4612
- const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb2.Q.where("conversation_id", message.conversationId)).fetch() : [];
4704
+ 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
4705
  for (const job of jobs) {
4614
4706
  const ids = JSON.parse(String(job._getRaw("message_ids")));
4615
4707
  await job.update((row) => {
@@ -4682,9 +4774,9 @@ async function createMessageOp(ctx, opts) {
4682
4774
  }
4683
4775
  }
4684
4776
  const newest = await ctx.messagesCollection.query(
4685
- import_watermelondb2.Q.where("conversation_id", opts.conversationId),
4686
- import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.desc),
4687
- import_watermelondb2.Q.take(1)
4777
+ import_watermelondb3.Q.where("conversation_id", opts.conversationId),
4778
+ import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.desc),
4779
+ import_watermelondb3.Q.take(1)
4688
4780
  ).fetch();
4689
4781
  const messageId = (newest[0]?.messageId ?? 0) + 1;
4690
4782
  const encryptedOpts = await encryptMessageOptsIfNeeded(ctx, opts);
@@ -4780,13 +4872,13 @@ async function decryptMessageEmbeddingFields(raw, walletAddress) {
4780
4872
  async function sealLegacyMessageEmbeddingsOp(ctx) {
4781
4873
  if (!ctx.walletAddress) return 0;
4782
4874
  const candidateIds = await ctx.messagesCollection.query(
4783
- import_watermelondb2.Q.where("content", import_watermelondb2.Q.like("enc:%")),
4784
- import_watermelondb2.Q.or(
4875
+ import_watermelondb3.Q.where("content", import_watermelondb3.Q.like("enc:%")),
4876
+ import_watermelondb3.Q.or(
4785
4877
  ...["vector", "chunks"].map(
4786
- (column) => import_watermelondb2.Q.and(
4787
- import_watermelondb2.Q.where(column, import_watermelondb2.Q.notEq(null)),
4788
- import_watermelondb2.Q.where(column, import_watermelondb2.Q.notEq("")),
4789
- import_watermelondb2.Q.where(column, import_watermelondb2.Q.notLike("enc:%"))
4878
+ (column) => import_watermelondb3.Q.and(
4879
+ import_watermelondb3.Q.where(column, import_watermelondb3.Q.notEq(null)),
4880
+ import_watermelondb3.Q.where(column, import_watermelondb3.Q.notEq("")),
4881
+ import_watermelondb3.Q.where(column, import_watermelondb3.Q.notLike("enc:%"))
4790
4882
  )
4791
4883
  )
4792
4884
  )
@@ -4796,7 +4888,7 @@ async function sealLegacyMessageEmbeddingsOp(ctx) {
4796
4888
  for (let start = 0; start < candidateIds.length; start += 50) {
4797
4889
  const pageIds = candidateIds.slice(start, start + 50);
4798
4890
  await ctx.database.write(async () => {
4799
- const pageMessages = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(pageIds))).fetch();
4891
+ const pageMessages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).fetch();
4800
4892
  for (const message of pageMessages) {
4801
4893
  if (!isEncrypted(message.content)) continue;
4802
4894
  const content = await decryptFieldDetailed(message.content, ctx.walletAddress);
@@ -4877,15 +4969,15 @@ function chunksWithoutText(raw) {
4877
4969
  });
4878
4970
  }
4879
4971
  async function stripLegacyChunkTextOp(ctx) {
4880
- const candidateIds = await ctx.messagesCollection.query(import_watermelondb2.Q.where("chunks", import_watermelondb2.Q.like(`%${import_watermelondb2.Q.sanitizeLikeString('"text":')}%`))).fetchIds();
4972
+ const candidateIds = await ctx.messagesCollection.query(import_watermelondb3.Q.where("chunks", import_watermelondb3.Q.like(`%${import_watermelondb3.Q.sanitizeLikeString('"text":')}%`))).fetchIds();
4881
4973
  let stripped = 0;
4882
4974
  for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
4883
4975
  const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
4884
- const rows = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(pageIds))).unsafeFetchRaw();
4976
+ const rows = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).unsafeFetchRaw();
4885
4977
  const changedIds = rows.filter((row) => chunksWithoutText(row.chunks) !== null).map((row) => String(row.id));
4886
4978
  if (changedIds.length === 0) continue;
4887
4979
  await ctx.database.write(async () => {
4888
- const messages = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(changedIds))).fetch();
4980
+ const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(changedIds))).fetch();
4889
4981
  const updates = messages.flatMap((message) => {
4890
4982
  const raw = message._raw;
4891
4983
  const chunks3 = chunksWithoutText(raw.chunks);
@@ -4932,13 +5024,13 @@ async function encryptToolCallEventsOp(ctx) {
4932
5024
  return 0;
4933
5025
  }
4934
5026
  const candidateIds = await ctx.messagesCollection.query(
4935
- import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notEq(null)),
4936
- import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notIn(["", "[]"]))
5027
+ import_watermelondb3.Q.where("tool_call_events", import_watermelondb3.Q.notEq(null)),
5028
+ import_watermelondb3.Q.where("tool_call_events", import_watermelondb3.Q.notIn(["", "[]"]))
4937
5029
  ).fetchIds();
4938
5030
  let encrypted = 0;
4939
5031
  for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
4940
5032
  const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
4941
- const rows = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(pageIds))).unsafeFetchRaw();
5033
+ const rows = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).unsafeFetchRaw();
4942
5034
  const repairs = /* @__PURE__ */ new Map();
4943
5035
  for (const row of rows) {
4944
5036
  const column = await encryptedToolCallEventsColumn(
@@ -4951,12 +5043,12 @@ async function encryptToolCallEventsOp(ctx) {
4951
5043
  }
4952
5044
  if (repairs.size === 0) continue;
4953
5045
  await ctx.database.write(async () => {
4954
- const messages = (await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf([...repairs.keys()]))).fetch()).filter(
5046
+ const messages = (await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf([...repairs.keys()]))).fetch()).filter(
4955
5047
  (message) => message._raw.tool_call_events === repairs.get(message.id)?.raw
4956
5048
  );
4957
5049
  if (messages.length === 0) return;
4958
5050
  const conversationIds = [...new Set(messages.map((message) => message.conversationId))];
4959
- const conversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", import_watermelondb2.Q.oneOf(conversationIds))).fetch();
5051
+ const conversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", import_watermelondb3.Q.oneOf(conversationIds))).fetch();
4960
5052
  await ctx.database.batch(
4961
5053
  ...messages.map(
4962
5054
  (message) => message.prepareUpdate((msg) => {
@@ -4983,7 +5075,7 @@ async function savedKeyOpensExistingData(ctx, address, signMessage, embeddedWall
4983
5075
  return refreshEncryptionKeyIfMatches(address, v2Probe, signMessage, embeddedWalletSigner);
4984
5076
  }
4985
5077
  async function findEncryptedContent(ctx, pattern) {
4986
- const [row] = await ctx.messagesCollection.query(import_watermelondb2.Q.where("content", import_watermelondb2.Q.like(pattern)), import_watermelondb2.Q.take(1)).unsafeFetchRaw();
5078
+ const [row] = await ctx.messagesCollection.query(import_watermelondb3.Q.where("content", import_watermelondb3.Q.like(pattern)), import_watermelondb3.Q.take(1)).unsafeFetchRaw();
4987
5079
  return row ? String(row.content) : null;
4988
5080
  }
4989
5081
  async function updateMessageErrorOp(ctx, uniqueId, error) {
@@ -5102,11 +5194,11 @@ async function readRawJsonField(raw, column, walletAddress) {
5102
5194
  }
5103
5195
  async function searchMessagesOp(ctx, queryVector, options) {
5104
5196
  const { limit = 10, minSimilarity = 0.5, conversationId } = options || {};
5105
- const activeConversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false)).fetch();
5197
+ const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
5106
5198
  const activeConversationIds = new Set(
5107
5199
  activeConversations.map((c) => String(c._getRaw("conversation_id")))
5108
5200
  );
5109
- const queryConditions = conversationId ? [import_watermelondb2.Q.where("conversation_id", conversationId)] : [];
5201
+ const queryConditions = conversationId ? [import_watermelondb3.Q.where("conversation_id", conversationId)] : [];
5110
5202
  const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
5111
5203
  const candidates = [];
5112
5204
  for (const message of messages) {
@@ -5145,7 +5237,7 @@ function toChunkCandidateKey(raw) {
5145
5237
  }
5146
5238
  async function fetchRowsByIds(ctx, ids) {
5147
5239
  if (ids.length === 0) return [];
5148
- return await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(ids))).unsafeFetchRaw();
5240
+ return await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))).unsafeFetchRaw();
5149
5241
  }
5150
5242
  async function projectedChunkRowSource(ctx, filter) {
5151
5243
  const clauses = [
@@ -5163,7 +5255,7 @@ async function projectedChunkRowSource(ctx, filter) {
5163
5255
  args.push(filter.excludeConversationId);
5164
5256
  }
5165
5257
  const keyRows = await ctx.messagesCollection.query(
5166
- import_watermelondb2.Q.unsafeSqlQuery(
5258
+ import_watermelondb3.Q.unsafeSqlQuery(
5167
5259
  `select "id", "conversation_id", "updated_at", "embedding_model" from "history" where ${clauses.join(" and ")}`,
5168
5260
  args
5169
5261
  )
@@ -5173,7 +5265,7 @@ async function projectedChunkRowSource(ctx, filter) {
5173
5265
  loadVectorRows: async (ids) => {
5174
5266
  if (ids.length === 0) return [];
5175
5267
  return await ctx.messagesCollection.query(
5176
- import_watermelondb2.Q.unsafeSqlQuery(
5268
+ import_watermelondb3.Q.unsafeSqlQuery(
5177
5269
  `select "id", "updated_at", "chunks", "vector" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
5178
5270
  ids
5179
5271
  )
@@ -5183,11 +5275,11 @@ async function projectedChunkRowSource(ctx, filter) {
5183
5275
  };
5184
5276
  }
5185
5277
  async function fullScanChunkRowSource(ctx, filter) {
5186
- const activeConversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false)).fetch();
5278
+ const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
5187
5279
  const activeConversationIds = new Set(
5188
5280
  activeConversations.map((c) => String(c._getRaw("conversation_id")))
5189
5281
  );
5190
- const queryConditions = filter.conversationId !== void 0 ? [import_watermelondb2.Q.where("conversation_id", filter.conversationId)] : [];
5282
+ const queryConditions = filter.conversationId !== void 0 ? [import_watermelondb3.Q.where("conversation_id", filter.conversationId)] : [];
5191
5283
  const rows = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
5192
5284
  const rowsById = /* @__PURE__ */ new Map();
5193
5285
  for (const row of rows) {
@@ -5394,12 +5486,12 @@ async function searchChunksOp(ctx, queryVector, options) {
5394
5486
  }
5395
5487
  async function getAllFilesOp(ctx, options) {
5396
5488
  const { conversationId, limit } = options || {};
5397
- const activeConversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false)).fetch();
5489
+ const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
5398
5490
  const activeConversationIds = new Set(
5399
5491
  activeConversations.map((c) => String(c._getRaw("conversation_id")))
5400
5492
  );
5401
- const queryConditions = conversationId ? [import_watermelondb2.Q.where("conversation_id", conversationId)] : [];
5402
- const messages = await ctx.messagesCollection.query(...queryConditions, import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)).fetch();
5493
+ const queryConditions = conversationId ? [import_watermelondb3.Q.where("conversation_id", conversationId)] : [];
5494
+ const messages = await ctx.messagesCollection.query(...queryConditions, import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).fetch();
5403
5495
  const filesWithContext = [];
5404
5496
  for (const message of messages) {
5405
5497
  const msgConvId = String(message._getRaw("conversation_id"));
@@ -11796,9 +11888,9 @@ function createWebSearchPreProcessor(options = {}) {
11796
11888
  }
11797
11889
 
11798
11890
  // src/lib/db/appFiles/models.ts
11799
- var import_watermelondb3 = require("@nozbe/watermelondb");
11891
+ var import_watermelondb4 = require("@nozbe/watermelondb");
11800
11892
  var import_decorators = require("@nozbe/watermelondb/decorators");
11801
- var AppFile = class extends import_watermelondb3.Model {
11893
+ var AppFile = class extends import_watermelondb4.Model {
11802
11894
  };
11803
11895
  AppFile.table = "app_files";
11804
11896
  AppFile.associations = {};
@@ -11820,7 +11912,7 @@ __decorateClass([
11820
11912
  ], AppFile.prototype, "updatedAt", 2);
11821
11913
 
11822
11914
  // src/lib/db/appFiles/operations.ts
11823
- var import_watermelondb4 = require("@nozbe/watermelondb");
11915
+ var import_watermelondb5 = require("@nozbe/watermelondb");
11824
11916
 
11825
11917
  // src/utils/paths.ts
11826
11918
  function normalizePath(p) {
@@ -11846,7 +11938,7 @@ async function putAppFileOp(ctx, conversationId, path, content) {
11846
11938
  const normalized = normalizePath(path);
11847
11939
  const now = Date.now();
11848
11940
  const result = await ctx.database.write(async () => {
11849
- const existing = await ctx.appFilesCollection.query(import_watermelondb4.Q.where("conversation_id", conversationId), import_watermelondb4.Q.where("path", normalized)).fetch();
11941
+ const existing = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId), import_watermelondb5.Q.where("path", normalized)).fetch();
11850
11942
  if (existing.length > 0) {
11851
11943
  await existing[0].update((f) => {
11852
11944
  f._setRaw("content", content);
@@ -11866,11 +11958,11 @@ async function putAppFileOp(ctx, conversationId, path, content) {
11866
11958
  }
11867
11959
  async function getAppFileOp(ctx, conversationId, path) {
11868
11960
  const normalized = normalizePath(path);
11869
- const results = await ctx.appFilesCollection.query(import_watermelondb4.Q.where("conversation_id", conversationId), import_watermelondb4.Q.where("path", normalized)).fetch();
11961
+ const results = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId), import_watermelondb5.Q.where("path", normalized)).fetch();
11870
11962
  return results.length > 0 ? appFileToStored(results[0]) : null;
11871
11963
  }
11872
11964
  async function getAppFilesOp(ctx, conversationId) {
11873
- const results = await ctx.appFilesCollection.query(import_watermelondb4.Q.where("conversation_id", conversationId)).fetch();
11965
+ const results = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId)).fetch();
11874
11966
  return results.map(appFileToStored);
11875
11967
  }
11876
11968
  async function getAppFileMapOp(ctx, conversationId) {
@@ -11881,7 +11973,7 @@ async function getAppFileMapOp(ctx, conversationId) {
11881
11973
  }
11882
11974
  async function deleteAppFileOp(ctx, conversationId, path) {
11883
11975
  const normalized = normalizePath(path);
11884
- const results = await ctx.appFilesCollection.query(import_watermelondb4.Q.where("conversation_id", conversationId), import_watermelondb4.Q.where("path", normalized)).fetch();
11976
+ const results = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId), import_watermelondb5.Q.where("path", normalized)).fetch();
11885
11977
  if (results.length === 0) return false;
11886
11978
  await ctx.database.write(async () => {
11887
11979
  await results[0].destroyPermanently();
@@ -11889,7 +11981,7 @@ async function deleteAppFileOp(ctx, conversationId, path) {
11889
11981
  return true;
11890
11982
  }
11891
11983
  async function deleteAllAppFilesOp(ctx, conversationId) {
11892
- const results = await ctx.appFilesCollection.query(import_watermelondb4.Q.where("conversation_id", conversationId)).fetch();
11984
+ const results = await ctx.appFilesCollection.query(import_watermelondb5.Q.where("conversation_id", conversationId)).fetch();
11893
11985
  if (results.length === 0) return;
11894
11986
  await ctx.database.write(async () => {
11895
11987
  const batch = results.map((file) => file.prepareDestroyPermanently());
@@ -11962,9 +12054,9 @@ async function decryptConversationTitle(encryptedTitle, address) {
11962
12054
  }
11963
12055
 
11964
12056
  // src/lib/db/chat/models.ts
11965
- var import_watermelondb5 = require("@nozbe/watermelondb");
12057
+ var import_watermelondb6 = require("@nozbe/watermelondb");
11966
12058
  var import_decorators2 = require("@nozbe/watermelondb/decorators");
11967
- var Message = class extends import_watermelondb5.Model {
12059
+ var Message = class extends import_watermelondb6.Model {
11968
12060
  };
11969
12061
  Message.table = "history";
11970
12062
  Message.associations = {
@@ -12043,7 +12135,7 @@ __decorateClass([
12043
12135
  __decorateClass([
12044
12136
  (0, import_decorators2.text)("origin")
12045
12137
  ], Message.prototype, "origin", 2);
12046
- var Conversation = class extends import_watermelondb5.Model {
12138
+ var Conversation = class extends import_watermelondb6.Model {
12047
12139
  };
12048
12140
  Conversation.table = "conversations";
12049
12141
  Conversation.associations = {
@@ -12071,7 +12163,7 @@ __decorateClass([
12071
12163
  __decorateClass([
12072
12164
  (0, import_decorators2.date)("pinned_at")
12073
12165
  ], Conversation.prototype, "pinnedAt", 2);
12074
- var ConversationSummary = class extends import_watermelondb5.Model {
12166
+ var ConversationSummary = class extends import_watermelondb6.Model {
12075
12167
  };
12076
12168
  ConversationSummary.table = "conversation_summaries";
12077
12169
  ConversationSummary.associations = {
@@ -12097,12 +12189,12 @@ __decorateClass([
12097
12189
  ], ConversationSummary.prototype, "updatedAt", 2);
12098
12190
 
12099
12191
  // src/lib/db/chat/schema.ts
12100
- var import_watermelondb6 = require("@nozbe/watermelondb");
12192
+ var import_watermelondb7 = require("@nozbe/watermelondb");
12101
12193
  var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
12102
- var chatStorageSchema = (0, import_watermelondb6.appSchema)({
12194
+ var chatStorageSchema = (0, import_watermelondb7.appSchema)({
12103
12195
  version: 7,
12104
12196
  tables: [
12105
- (0, import_watermelondb6.tableSchema)({
12197
+ (0, import_watermelondb7.tableSchema)({
12106
12198
  name: "history",
12107
12199
  columns: [
12108
12200
  { name: "message_id", type: "number" },
@@ -12126,7 +12218,7 @@ var chatStorageSchema = (0, import_watermelondb6.appSchema)({
12126
12218
  { name: "thinking", type: "string", isOptional: true }
12127
12219
  ]
12128
12220
  }),
12129
- (0, import_watermelondb6.tableSchema)({
12221
+ (0, import_watermelondb7.tableSchema)({
12130
12222
  name: "conversations",
12131
12223
  columns: [
12132
12224
  { name: "conversation_id", type: "string", isIndexed: true },
@@ -12198,7 +12290,7 @@ var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
12198
12290
  });
12199
12291
 
12200
12292
  // src/lib/db/chat/summaryOperations.ts
12201
- var import_watermelondb7 = require("@nozbe/watermelondb");
12293
+ var import_watermelondb8 = require("@nozbe/watermelondb");
12202
12294
  function createSummaryContext(database) {
12203
12295
  return {
12204
12296
  database,
@@ -12217,14 +12309,14 @@ function modelToStored(record2) {
12217
12309
  };
12218
12310
  }
12219
12311
  async function getConversationSummaryOp(ctx, conversationId) {
12220
- const results = await ctx.summariesCollection.query(import_watermelondb7.Q.where("conversation_id", conversationId)).fetch();
12312
+ const results = await ctx.summariesCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId)).fetch();
12221
12313
  if (results.length === 0) return null;
12222
12314
  return modelToStored(results[0]);
12223
12315
  }
12224
12316
  async function upsertConversationSummaryOp(ctx, conversationId, summary, summarizedUpTo, tokenCount) {
12225
12317
  let record2;
12226
12318
  await ctx.database.write(async () => {
12227
- const existing = await ctx.summariesCollection.query(import_watermelondb7.Q.where("conversation_id", conversationId)).fetch();
12319
+ const existing = await ctx.summariesCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId)).fetch();
12228
12320
  if (existing.length > 0) {
12229
12321
  record2 = await existing[0].update((rec) => {
12230
12322
  rec.summary = summary;
@@ -12244,7 +12336,7 @@ async function upsertConversationSummaryOp(ctx, conversationId, summary, summari
12244
12336
  }
12245
12337
  async function deleteConversationSummaryOp(ctx, conversationId) {
12246
12338
  await ctx.database.write(async () => {
12247
- const existing = await ctx.summariesCollection.query(import_watermelondb7.Q.where("conversation_id", conversationId)).fetch();
12339
+ const existing = await ctx.summariesCollection.query(import_watermelondb8.Q.where("conversation_id", conversationId)).fetch();
12248
12340
  for (const record2 of existing) {
12249
12341
  await record2.destroyPermanently();
12250
12342
  }
@@ -12252,9 +12344,9 @@ async function deleteConversationSummaryOp(ctx, conversationId) {
12252
12344
  }
12253
12345
 
12254
12346
  // src/lib/db/conversationMemory/models.ts
12255
- var import_watermelondb8 = require("@nozbe/watermelondb");
12347
+ var import_watermelondb9 = require("@nozbe/watermelondb");
12256
12348
  var import_decorators3 = require("@nozbe/watermelondb/decorators");
12257
- var ConversationMemory = class extends import_watermelondb8.Model {
12349
+ var ConversationMemory = class extends import_watermelondb9.Model {
12258
12350
  };
12259
12351
  ConversationMemory.table = "conversation_memory";
12260
12352
  ConversationMemory.associations = {};
@@ -12273,7 +12365,7 @@ __decorateClass([
12273
12365
  ], ConversationMemory.prototype, "createdAt", 2);
12274
12366
 
12275
12367
  // src/lib/db/conversationMemory/operations.ts
12276
- var import_watermelondb9 = require("@nozbe/watermelondb");
12368
+ var import_watermelondb10 = require("@nozbe/watermelondb");
12277
12369
  var MAX_PER_CONVERSATION = 200;
12278
12370
  function conversationMemoryToStored(row) {
12279
12371
  return {
@@ -12288,7 +12380,7 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
12288
12380
  if (!conversationId || items.length === 0) return;
12289
12381
  const now = Date.now();
12290
12382
  await ctx.database.write(async () => {
12291
- const existing = await ctx.conversationMemoryCollection.query(import_watermelondb9.Q.where("conversation_id", conversationId), import_watermelondb9.Q.sortBy("created_at", import_watermelondb9.Q.asc)).fetch();
12383
+ 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
12384
  const seen = new Set(existing.map((r) => r.memoryId));
12293
12385
  const batchSeen = /* @__PURE__ */ new Set();
12294
12386
  const deduped = [];
@@ -12318,22 +12410,22 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
12318
12410
  }
12319
12411
  async function getConversationMemoriesOp(ctx, conversationId) {
12320
12412
  if (!conversationId) return [];
12321
- const rows = await ctx.conversationMemoryCollection.query(import_watermelondb9.Q.where("conversation_id", conversationId), import_watermelondb9.Q.sortBy("created_at", import_watermelondb9.Q.asc)).fetch();
12413
+ 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
12414
  return rows.map(conversationMemoryToStored);
12323
12415
  }
12324
12416
  async function clearConversationMemoriesOp(ctx, conversationId) {
12325
12417
  if (!conversationId) return;
12326
12418
  await ctx.database.write(async () => {
12327
- const rows = await ctx.conversationMemoryCollection.query(import_watermelondb9.Q.where("conversation_id", conversationId)).fetch();
12419
+ const rows = await ctx.conversationMemoryCollection.query(import_watermelondb10.Q.where("conversation_id", conversationId)).fetch();
12328
12420
  if (rows.length === 0) return;
12329
12421
  await ctx.database.batch(...rows.map((r) => r.prepareDestroyPermanently()));
12330
12422
  });
12331
12423
  }
12332
12424
 
12333
12425
  // src/lib/db/entities/models.ts
12334
- var import_watermelondb10 = require("@nozbe/watermelondb");
12426
+ var import_watermelondb11 = require("@nozbe/watermelondb");
12335
12427
  var import_decorators4 = require("@nozbe/watermelondb/decorators");
12336
- var Entity = class extends import_watermelondb10.Model {
12428
+ var Entity = class extends import_watermelondb11.Model {
12337
12429
  };
12338
12430
  Entity.table = "entity";
12339
12431
  __decorateClass([
@@ -12349,7 +12441,7 @@ __decorateClass([
12349
12441
  __decorateClass([
12350
12442
  (0, import_decorators4.date)("updated_at")
12351
12443
  ], Entity.prototype, "updatedAt", 2);
12352
- var MemoryEntity = class extends import_watermelondb10.Model {
12444
+ var MemoryEntity = class extends import_watermelondb11.Model {
12353
12445
  };
12354
12446
  MemoryEntity.table = "memory_entity";
12355
12447
  __decorateClass([
@@ -12367,7 +12459,7 @@ __decorateClass([
12367
12459
  ], MemoryEntity.prototype, "createdAt", 2);
12368
12460
 
12369
12461
  // src/lib/db/entities/operations.ts
12370
- var import_watermelondb11 = require("@nozbe/watermelondb");
12462
+ var import_watermelondb12 = require("@nozbe/watermelondb");
12371
12463
 
12372
12464
  // src/lib/db/memoryVault/types.ts
12373
12465
  var MEMORY_KINDS = [
@@ -12516,7 +12608,7 @@ async function upsertEntitiesInWrite(ctx, entities) {
12516
12608
  const unique = Array.from(kindByName.keys());
12517
12609
  const out = /* @__PURE__ */ new Map();
12518
12610
  if (unique.length === 0) return { entities: out, operations: [], kindBackfills: [] };
12519
- const existing = await ctx.entityCollection.query(import_watermelondb11.Q.where("canonical_name", import_watermelondb11.Q.oneOf(unique))).fetch();
12611
+ const existing = await ctx.entityCollection.query(import_watermelondb12.Q.where("canonical_name", import_watermelondb12.Q.oneOf(unique))).fetch();
12520
12612
  const existingNames = new Set(existing.map((e) => e.canonicalName));
12521
12613
  const kindBackfills = existing.filter((e) => {
12522
12614
  const incoming = kindByName.get(e.canonicalName);
@@ -12546,7 +12638,7 @@ function prepareKindBackfills(backfills) {
12546
12638
  }
12547
12639
  async function findVaultRowInWrite(ctx, memoryId) {
12548
12640
  try {
12549
- const rows = await ctx.database.get("memory_vault").query(import_watermelondb11.Q.where("id", memoryId)).fetch();
12641
+ const rows = await ctx.database.get("memory_vault").query(import_watermelondb12.Q.where("id", memoryId)).fetch();
12550
12642
  return rows[0] ?? null;
12551
12643
  } catch {
12552
12644
  return null;
@@ -12648,7 +12740,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
12648
12740
  return;
12649
12741
  }
12650
12742
  if (entities.length === 0) return;
12651
- const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb11.Q.where("memory_id", memoryId)).fetch();
12743
+ const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("memory_id", memoryId)).fetch();
12652
12744
  const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
12653
12745
  const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
12654
12746
  const keptIds = entities.map((e) => e.uniqueId);
@@ -12684,7 +12776,7 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
12684
12776
  }
12685
12777
  async function resolveEntitiesByIds(ctx, entityIds) {
12686
12778
  if (entityIds.length === 0) return [];
12687
- const rows = await ctx.entityCollection.query(import_watermelondb11.Q.where("id", import_watermelondb11.Q.oneOf(Array.from(entityIds)))).fetch();
12779
+ const rows = await ctx.entityCollection.query(import_watermelondb12.Q.where("id", import_watermelondb12.Q.oneOf(Array.from(entityIds)))).fetch();
12688
12780
  return rows.map(entityToStored);
12689
12781
  }
12690
12782
  function autoLinkBlocked(row) {
@@ -12720,7 +12812,7 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
12720
12812
  kindBackfills
12721
12813
  } = await upsertEntitiesInWrite(ctx, normalized);
12722
12814
  entities = Array.from(byName.values());
12723
- const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb11.Q.where("memory_id", memoryId)).fetch();
12815
+ const existingLinks = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("memory_id", memoryId)).fetch();
12724
12816
  const keep = new Set(entities.map((e) => e.uniqueId));
12725
12817
  const existingEntityIds = new Set(existingLinks.map((l) => String(l.entityId)));
12726
12818
  const toCreate = entities.filter((e) => !existingEntityIds.has(e.uniqueId));
@@ -12756,17 +12848,17 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
12756
12848
  async function findOrphanedEntities(ctx, memoryId, toDestroy) {
12757
12849
  const candidateIds = [...new Set(toDestroy.map((l) => String(l.entityId)))];
12758
12850
  if (candidateIds.length === 0) return [];
12759
- const links = await ctx.memoryEntityCollection.query(import_watermelondb11.Q.where("entity_id", import_watermelondb11.Q.oneOf(candidateIds))).fetch();
12851
+ const links = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("entity_id", import_watermelondb12.Q.oneOf(candidateIds))).fetch();
12760
12852
  const stillLinked = new Set(
12761
12853
  links.filter((l) => String(l.memoryId) !== memoryId).map((l) => String(l.entityId))
12762
12854
  );
12763
12855
  const orphanIds = candidateIds.filter((id) => !stillLinked.has(id));
12764
12856
  if (orphanIds.length === 0) return [];
12765
- return await ctx.entityCollection.query(import_watermelondb11.Q.where("id", import_watermelondb11.Q.oneOf(orphanIds))).fetch();
12857
+ return await ctx.entityCollection.query(import_watermelondb12.Q.where("id", import_watermelondb12.Q.oneOf(orphanIds))).fetch();
12766
12858
  }
12767
12859
  async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
12768
12860
  if (memoryIds.length === 0) return;
12769
- const links = await ctx.memoryEntityCollection.query(import_watermelondb11.Q.where("memory_id", import_watermelondb11.Q.oneOf(Array.from(memoryIds)))).fetch();
12861
+ const links = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("memory_id", import_watermelondb12.Q.oneOf(Array.from(memoryIds)))).fetch();
12770
12862
  if (links.length === 0) return;
12771
12863
  await ctx.database.write(async () => {
12772
12864
  await assertCanWrite(ctx);
@@ -12775,7 +12867,7 @@ async function unlinkMemoryEntitiesOp(ctx, memoryIds) {
12775
12867
  }
12776
12868
  async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
12777
12869
  if (!userId) return;
12778
- const links = await ctx.memoryEntityCollection.query(import_watermelondb11.Q.where("user_id", userId)).fetch();
12870
+ const links = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("user_id", userId)).fetch();
12779
12871
  if (links.length === 0) return;
12780
12872
  await ctx.database.write(async () => {
12781
12873
  await assertCanWrite(ctx);
@@ -12783,7 +12875,7 @@ async function unlinkAllMemoryEntitiesForUserOp(ctx, userId) {
12783
12875
  });
12784
12876
  }
12785
12877
  async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
12786
- const unstamped = await ctx.memoryEntityCollection.query(import_watermelondb11.Q.where("user_id", null)).fetch();
12878
+ const unstamped = await ctx.memoryEntityCollection.query(import_watermelondb12.Q.where("user_id", null)).fetch();
12787
12879
  if (unstamped.length === 0) return 0;
12788
12880
  const toUpdate = [];
12789
12881
  for (const link of unstamped) {
@@ -12808,15 +12900,15 @@ async function backfillMemoryEntityUserIdsOp(ctx, vaultMemoryCollection) {
12808
12900
  async function getMemoriesByEntityNamesOp(ctx, entityNames) {
12809
12901
  const unique = Array.from(new Set(entityNames.map(normalizeEntityName).filter((n) => n.length > 0)));
12810
12902
  if (unique.length === 0) return /* @__PURE__ */ new Map();
12811
- const entityRows = await ctx.entityCollection.query(import_watermelondb11.Q.where("canonical_name", import_watermelondb11.Q.oneOf(unique))).fetch();
12903
+ const entityRows = await ctx.entityCollection.query(import_watermelondb12.Q.where("canonical_name", import_watermelondb12.Q.oneOf(unique))).fetch();
12812
12904
  if (entityRows.length === 0) return /* @__PURE__ */ new Map();
12813
12905
  const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
12814
- const linkConditions = [import_watermelondb11.Q.where("entity_id", import_watermelondb11.Q.oneOf(entityRows.map((e) => e.id)))];
12906
+ const linkConditions = [import_watermelondb12.Q.where("entity_id", import_watermelondb12.Q.oneOf(entityRows.map((e) => e.id)))];
12815
12907
  if (ctx.userId !== void 0) {
12816
12908
  if (ctx.allowUnscopedRows) {
12817
- linkConditions.push(import_watermelondb11.Q.or(import_watermelondb11.Q.where("user_id", ctx.userId), import_watermelondb11.Q.where("user_id", null)));
12909
+ linkConditions.push(import_watermelondb12.Q.or(import_watermelondb12.Q.where("user_id", ctx.userId), import_watermelondb12.Q.where("user_id", null)));
12818
12910
  } else {
12819
- linkConditions.push(import_watermelondb11.Q.where("user_id", ctx.userId));
12911
+ linkConditions.push(import_watermelondb12.Q.where("user_id", ctx.userId));
12820
12912
  }
12821
12913
  }
12822
12914
  const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
@@ -12837,18 +12929,18 @@ async function getMemoriesByEntityNamesOp(ctx, entityNames) {
12837
12929
  async function getEntitiesByMemoryIdsOp(ctx, memoryIds) {
12838
12930
  const unique = Array.from(new Set(memoryIds.filter((id) => id.length > 0)));
12839
12931
  if (unique.length === 0) return /* @__PURE__ */ new Map();
12840
- const linkConditions = [import_watermelondb11.Q.where("memory_id", import_watermelondb11.Q.oneOf(unique))];
12932
+ const linkConditions = [import_watermelondb12.Q.where("memory_id", import_watermelondb12.Q.oneOf(unique))];
12841
12933
  if (ctx.userId !== void 0) {
12842
12934
  if (ctx.allowUnscopedRows) {
12843
- linkConditions.push(import_watermelondb11.Q.or(import_watermelondb11.Q.where("user_id", ctx.userId), import_watermelondb11.Q.where("user_id", null)));
12935
+ linkConditions.push(import_watermelondb12.Q.or(import_watermelondb12.Q.where("user_id", ctx.userId), import_watermelondb12.Q.where("user_id", null)));
12844
12936
  } else {
12845
- linkConditions.push(import_watermelondb11.Q.where("user_id", ctx.userId));
12937
+ linkConditions.push(import_watermelondb12.Q.where("user_id", ctx.userId));
12846
12938
  }
12847
12939
  }
12848
12940
  const links = await ctx.memoryEntityCollection.query(...linkConditions).fetch();
12849
12941
  if (links.length === 0) return /* @__PURE__ */ new Map();
12850
12942
  const entityIds = Array.from(new Set(links.map((l) => String(l.entityId))));
12851
- const entityRows = await ctx.entityCollection.query(import_watermelondb11.Q.where("id", import_watermelondb11.Q.oneOf(entityIds))).fetch();
12943
+ const entityRows = await ctx.entityCollection.query(import_watermelondb12.Q.where("id", import_watermelondb12.Q.oneOf(entityIds))).fetch();
12852
12944
  const entityIdToName = new Map(entityRows.map((e) => [e.id, e.canonicalName]));
12853
12945
  const out = /* @__PURE__ */ new Map();
12854
12946
  for (const link of links) {
@@ -12866,16 +12958,16 @@ async function getEntitiesByMemoryIdsOp(ctx, memoryIds) {
12866
12958
  }
12867
12959
 
12868
12960
  // src/lib/db/manager.ts
12869
- var import_watermelondb20 = require("@nozbe/watermelondb");
12961
+ var import_watermelondb21 = require("@nozbe/watermelondb");
12870
12962
 
12871
12963
  // src/lib/db/schema.ts
12872
- var import_watermelondb19 = require("@nozbe/watermelondb");
12964
+ var import_watermelondb20 = require("@nozbe/watermelondb");
12873
12965
  var import_migrations2 = require("@nozbe/watermelondb/Schema/migrations");
12874
12966
 
12875
12967
  // src/lib/db/media/models.ts
12876
- var import_watermelondb12 = require("@nozbe/watermelondb");
12968
+ var import_watermelondb13 = require("@nozbe/watermelondb");
12877
12969
  var import_decorators5 = require("@nozbe/watermelondb/decorators");
12878
- var Media = class extends import_watermelondb12.Model {
12970
+ var Media = class extends import_watermelondb13.Model {
12879
12971
  };
12880
12972
  Media.table = "media";
12881
12973
  Media.associations = {
@@ -12936,9 +13028,9 @@ __decorateClass([
12936
13028
  ], Media.prototype, "isDeleted", 2);
12937
13029
 
12938
13030
  // src/lib/db/memoryVault/models.ts
12939
- var import_watermelondb13 = require("@nozbe/watermelondb");
13031
+ var import_watermelondb14 = require("@nozbe/watermelondb");
12940
13032
  var import_decorators6 = require("@nozbe/watermelondb/decorators");
12941
- var VaultMemory = class extends import_watermelondb13.Model {
13033
+ var VaultMemory = class extends import_watermelondb14.Model {
12942
13034
  };
12943
13035
  VaultMemory.table = "memory_vault";
12944
13036
  __decorateClass([
@@ -13046,9 +13138,9 @@ __decorateClass([
13046
13138
  ], VaultMemory.prototype, "isDeleted", 2);
13047
13139
 
13048
13140
  // src/lib/db/project/models.ts
13049
- var import_watermelondb14 = require("@nozbe/watermelondb");
13141
+ var import_watermelondb15 = require("@nozbe/watermelondb");
13050
13142
  var import_decorators7 = require("@nozbe/watermelondb/decorators");
13051
- var Project = class extends import_watermelondb14.Model {
13143
+ var Project = class extends import_watermelondb15.Model {
13052
13144
  };
13053
13145
  Project.table = "projects";
13054
13146
  Project.associations = {
@@ -13071,10 +13163,10 @@ __decorateClass([
13071
13163
  ], Project.prototype, "isDeleted", 2);
13072
13164
 
13073
13165
  // src/lib/db/savedTools/models.ts
13074
- var import_watermelondb15 = require("@nozbe/watermelondb");
13166
+ var import_watermelondb16 = require("@nozbe/watermelondb");
13075
13167
  var import_decorators8 = require("@nozbe/watermelondb/decorators");
13076
13168
  var sanitizeParameters = (raw) => raw ?? {};
13077
- var SavedTool = class extends import_watermelondb15.Model {
13169
+ var SavedTool = class extends import_watermelondb16.Model {
13078
13170
  };
13079
13171
  SavedTool.table = "saved_tools";
13080
13172
  SavedTool.associations = {};
@@ -13108,9 +13200,9 @@ __decorateClass([
13108
13200
  ], SavedTool.prototype, "isDeleted", 2);
13109
13201
 
13110
13202
  // src/lib/db/settings/models.ts
13111
- var import_watermelondb16 = require("@nozbe/watermelondb");
13203
+ var import_watermelondb17 = require("@nozbe/watermelondb");
13112
13204
  var import_decorators9 = require("@nozbe/watermelondb/decorators");
13113
- var ModelPreference = class extends import_watermelondb16.Model {
13205
+ var ModelPreference = class extends import_watermelondb17.Model {
13114
13206
  };
13115
13207
  ModelPreference.table = "modelPreferences";
13116
13208
  __decorateClass([
@@ -13121,9 +13213,9 @@ __decorateClass([
13121
13213
  ], ModelPreference.prototype, "models", 2);
13122
13214
 
13123
13215
  // src/lib/db/userPreferences/models.ts
13124
- var import_watermelondb17 = require("@nozbe/watermelondb");
13216
+ var import_watermelondb18 = require("@nozbe/watermelondb");
13125
13217
  var import_decorators10 = require("@nozbe/watermelondb/decorators");
13126
- var UserPreference = class extends import_watermelondb17.Model {
13218
+ var UserPreference = class extends import_watermelondb18.Model {
13127
13219
  };
13128
13220
  UserPreference.table = "userPreferences";
13129
13221
  __decorateClass([
@@ -13152,9 +13244,9 @@ __decorateClass([
13152
13244
  ], UserPreference.prototype, "updatedAt", 2);
13153
13245
 
13154
13246
  // src/lib/db/vaultFolders/models.ts
13155
- var import_watermelondb18 = require("@nozbe/watermelondb");
13247
+ var import_watermelondb19 = require("@nozbe/watermelondb");
13156
13248
  var import_decorators11 = require("@nozbe/watermelondb/decorators");
13157
- var VaultFolder = class extends import_watermelondb18.Model {
13249
+ var VaultFolder = class extends import_watermelondb19.Model {
13158
13250
  };
13159
13251
  VaultFolder.table = "vault_folders";
13160
13252
  __decorateClass([
@@ -13182,10 +13274,10 @@ __decorateClass([
13182
13274
 
13183
13275
  // src/lib/db/schema.ts
13184
13276
  var SDK_SCHEMA_VERSION = 48;
13185
- var sdkSchema = (0, import_watermelondb19.appSchema)({
13277
+ var sdkSchema = (0, import_watermelondb20.appSchema)({
13186
13278
  version: SDK_SCHEMA_VERSION,
13187
13279
  tables: [
13188
- (0, import_watermelondb19.tableSchema)({
13280
+ (0, import_watermelondb20.tableSchema)({
13189
13281
  name: "memory_extraction_jobs",
13190
13282
  columns: [
13191
13283
  { name: "owner_key", type: "string", isIndexed: true },
@@ -13200,7 +13292,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13200
13292
  { name: "failed_at", type: "number", isOptional: true }
13201
13293
  ]
13202
13294
  }),
13203
- (0, import_watermelondb19.tableSchema)({
13295
+ (0, import_watermelondb20.tableSchema)({
13204
13296
  name: "history",
13205
13297
  columns: [
13206
13298
  { name: "message_id", type: "number" },
@@ -13229,7 +13321,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13229
13321
  { name: "origin", type: "string", isOptional: true }
13230
13322
  ]
13231
13323
  }),
13232
- (0, import_watermelondb19.tableSchema)({
13324
+ (0, import_watermelondb20.tableSchema)({
13233
13325
  name: "conversations",
13234
13326
  columns: [
13235
13327
  { name: "conversation_id", type: "string", isIndexed: true },
@@ -13241,7 +13333,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13241
13333
  { name: "pinned_at", type: "number", isOptional: true }
13242
13334
  ]
13243
13335
  }),
13244
- (0, import_watermelondb19.tableSchema)({
13336
+ (0, import_watermelondb20.tableSchema)({
13245
13337
  name: "projects",
13246
13338
  columns: [
13247
13339
  { name: "project_id", type: "string", isIndexed: true },
@@ -13251,14 +13343,14 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13251
13343
  { name: "is_deleted", type: "boolean", isIndexed: true }
13252
13344
  ]
13253
13345
  }),
13254
- (0, import_watermelondb19.tableSchema)({
13346
+ (0, import_watermelondb20.tableSchema)({
13255
13347
  name: "modelPreferences",
13256
13348
  columns: [
13257
13349
  { name: "wallet_address", type: "string", isIndexed: true },
13258
13350
  { name: "models", type: "string", isOptional: true }
13259
13351
  ]
13260
13352
  }),
13261
- (0, import_watermelondb19.tableSchema)({
13353
+ (0, import_watermelondb20.tableSchema)({
13262
13354
  name: "userPreferences",
13263
13355
  columns: [
13264
13356
  { name: "wallet_address", type: "string", isIndexed: true },
@@ -13271,7 +13363,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13271
13363
  { name: "updated_at", type: "number" }
13272
13364
  ]
13273
13365
  }),
13274
- (0, import_watermelondb19.tableSchema)({
13366
+ (0, import_watermelondb20.tableSchema)({
13275
13367
  name: "memory_vault",
13276
13368
  columns: [
13277
13369
  { name: "content", type: "string" },
@@ -13310,7 +13402,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13310
13402
  { name: "geohash", type: "string", isOptional: true }
13311
13403
  ]
13312
13404
  }),
13313
- (0, import_watermelondb19.tableSchema)({
13405
+ (0, import_watermelondb20.tableSchema)({
13314
13406
  name: "entity",
13315
13407
  columns: [
13316
13408
  { name: "canonical_name", type: "string", isIndexed: true },
@@ -13319,7 +13411,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13319
13411
  { name: "updated_at", type: "number" }
13320
13412
  ]
13321
13413
  }),
13322
- (0, import_watermelondb19.tableSchema)({
13414
+ (0, import_watermelondb20.tableSchema)({
13323
13415
  name: "memory_entity",
13324
13416
  columns: [
13325
13417
  { name: "memory_id", type: "string", isIndexed: true },
@@ -13328,7 +13420,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13328
13420
  { name: "created_at", type: "number" }
13329
13421
  ]
13330
13422
  }),
13331
- (0, import_watermelondb19.tableSchema)({
13423
+ (0, import_watermelondb20.tableSchema)({
13332
13424
  name: "vault_folders",
13333
13425
  columns: [
13334
13426
  { name: "name", type: "string" },
@@ -13340,7 +13432,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13340
13432
  { name: "context", type: "string", isOptional: true }
13341
13433
  ]
13342
13434
  }),
13343
- (0, import_watermelondb19.tableSchema)({
13435
+ (0, import_watermelondb20.tableSchema)({
13344
13436
  name: "conversation_summaries",
13345
13437
  columns: [
13346
13438
  { name: "conversation_id", type: "string", isIndexed: true },
@@ -13351,7 +13443,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13351
13443
  { name: "updated_at", type: "number" }
13352
13444
  ]
13353
13445
  }),
13354
- (0, import_watermelondb19.tableSchema)({
13446
+ (0, import_watermelondb20.tableSchema)({
13355
13447
  name: "media",
13356
13448
  columns: [
13357
13449
  { name: "media_id", type: "string", isIndexed: true },
@@ -13373,7 +13465,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13373
13465
  { name: "is_deleted", type: "boolean", isIndexed: true }
13374
13466
  ]
13375
13467
  }),
13376
- (0, import_watermelondb19.tableSchema)({
13468
+ (0, import_watermelondb20.tableSchema)({
13377
13469
  name: "app_files",
13378
13470
  columns: [
13379
13471
  { name: "conversation_id", type: "string", isIndexed: true },
@@ -13383,7 +13475,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13383
13475
  { name: "updated_at", type: "number" }
13384
13476
  ]
13385
13477
  }),
13386
- (0, import_watermelondb19.tableSchema)({
13478
+ (0, import_watermelondb20.tableSchema)({
13387
13479
  name: "saved_tools",
13388
13480
  columns: [
13389
13481
  { name: "name", type: "string" },
@@ -13397,7 +13489,7 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
13397
13489
  { name: "is_deleted", type: "boolean", isIndexed: true }
13398
13490
  ]
13399
13491
  }),
13400
- (0, import_watermelondb19.tableSchema)({
13492
+ (0, import_watermelondb20.tableSchema)({
13401
13493
  name: "conversation_memory",
13402
13494
  columns: [
13403
13495
  { name: "conversation_id", type: "string", isIndexed: true },
@@ -14073,7 +14165,7 @@ var DatabaseManager = class {
14073
14165
  walletAddress
14074
14166
  });
14075
14167
  const adapter = this.createAdapter(dbName, sdkSchema, sdkMigrations);
14076
- const database = new import_watermelondb20.Database({
14168
+ const database = new import_watermelondb21.Database({
14077
14169
  adapter,
14078
14170
  modelClasses: sdkModelClasses
14079
14171
  });
@@ -14152,7 +14244,7 @@ var DatabaseManager = class {
14152
14244
  };
14153
14245
 
14154
14246
  // src/lib/db/media/operations.ts
14155
- var import_watermelondb22 = require("@nozbe/watermelondb");
14247
+ var import_watermelondb23 = require("@nozbe/watermelondb");
14156
14248
  init_logger();
14157
14249
 
14158
14250
  // src/lib/storage/opfs.ts
@@ -14420,7 +14512,7 @@ function isR2UrlExpired(sourceUrl, createdAt) {
14420
14512
  }
14421
14513
 
14422
14514
  // src/lib/storage/WatermelonChatStorageAdapter.ts
14423
- var import_watermelondb21 = require("@nozbe/watermelondb");
14515
+ var import_watermelondb22 = require("@nozbe/watermelondb");
14424
14516
  var WatermelonChatStorageAdapter = class {
14425
14517
  constructor(options) {
14426
14518
  this.messages = options.database.get("history");
@@ -14460,10 +14552,10 @@ var WatermelonChatStorageAdapter = class {
14460
14552
  }
14461
14553
  observeConversations(options) {
14462
14554
  const conditions = options?.projectId !== void 0 ? [
14463
- import_watermelondb21.Q.where("project_id", options.projectId === null ? "" : options.projectId),
14464
- import_watermelondb21.Q.where("is_deleted", false),
14465
- import_watermelondb21.Q.sortBy("created_at", import_watermelondb21.Q.desc)
14466
- ] : [import_watermelondb21.Q.where("is_deleted", false), import_watermelondb21.Q.sortBy("created_at", import_watermelondb21.Q.desc)];
14555
+ import_watermelondb22.Q.where("project_id", options.projectId === null ? "" : options.projectId),
14556
+ import_watermelondb22.Q.where("is_deleted", false),
14557
+ import_watermelondb22.Q.sortBy("created_at", import_watermelondb22.Q.desc)
14558
+ ] : [import_watermelondb22.Q.where("is_deleted", false), import_watermelondb22.Q.sortBy("created_at", import_watermelondb22.Q.desc)];
14467
14559
  const rx = this.conversations.query(...conditions).observe();
14468
14560
  return {
14469
14561
  subscribe: (observer) => {
@@ -14510,7 +14602,7 @@ var WatermelonChatStorageAdapter = class {
14510
14602
  return clearMessagesOp(this.ctx, conversationId);
14511
14603
  }
14512
14604
  observeMessages(conversationId) {
14513
- const rx = this.messages.query(import_watermelondb21.Q.where("conversation_id", conversationId), import_watermelondb21.Q.sortBy("message_id", import_watermelondb21.Q.asc)).observe();
14605
+ const rx = this.messages.query(import_watermelondb22.Q.where("conversation_id", conversationId), import_watermelondb22.Q.sortBy("message_id", import_watermelondb22.Q.asc)).observe();
14514
14606
  return {
14515
14607
  subscribe: (observer) => {
14516
14608
  let latestSeq = 0;
@@ -14748,7 +14840,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
14748
14840
  })
14749
14841
  );
14750
14842
  });
14751
- const results = await mediaCollection.query(import_watermelondb22.Q.where("media_id", import_watermelondb22.Q.oneOf(mediaIds))).fetch();
14843
+ const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", import_watermelondb23.Q.oneOf(mediaIds))).fetch();
14752
14844
  return Promise.all(
14753
14845
  results.map(
14754
14846
  (m) => mediaToStored(m, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
@@ -14757,21 +14849,21 @@ async function createMediaBatchOp(ctx, optionsArray) {
14757
14849
  }
14758
14850
  async function getMediaByIdOp(ctx, mediaId) {
14759
14851
  const mediaCollection = ctx.database.get("media");
14760
- const results = await mediaCollection.query(import_watermelondb22.Q.where("media_id", mediaId), import_watermelondb22.Q.where("is_deleted", false)).fetch();
14852
+ const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId), import_watermelondb23.Q.where("is_deleted", false)).fetch();
14761
14853
  return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
14762
14854
  }
14763
14855
  async function getMediaBySourceUrlOp(ctx, sourceUrl, walletAddress) {
14764
14856
  const mediaCollection = ctx.database.get("media");
14765
14857
  const results = await mediaCollection.query(
14766
- import_watermelondb22.Q.where("source_url", sourceUrl),
14767
- import_watermelondb22.Q.where("wallet_address", walletAddress),
14768
- import_watermelondb22.Q.where("is_deleted", false)
14858
+ import_watermelondb23.Q.where("source_url", sourceUrl),
14859
+ import_watermelondb23.Q.where("wallet_address", walletAddress),
14860
+ import_watermelondb23.Q.where("is_deleted", false)
14769
14861
  ).fetch();
14770
14862
  return results.length > 0 ? await mediaToStored(results[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
14771
14863
  }
14772
14864
  async function updateMediaOp(ctx, mediaId, options) {
14773
14865
  const mediaCollection = ctx.database.get("media");
14774
- const results = await mediaCollection.query(import_watermelondb22.Q.where("media_id", mediaId)).fetch();
14866
+ const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId)).fetch();
14775
14867
  if (results.length === 0) {
14776
14868
  return null;
14777
14869
  }
@@ -14791,7 +14883,7 @@ async function updateMediaOp(ctx, mediaId, options) {
14791
14883
  m._setRaw("updated_at", now);
14792
14884
  });
14793
14885
  });
14794
- const updated = await mediaCollection.query(import_watermelondb22.Q.where("media_id", mediaId)).fetch();
14886
+ const updated = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId)).fetch();
14795
14887
  return updated.length > 0 ? await mediaToStored(updated[0], ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : null;
14796
14888
  }
14797
14889
  async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
@@ -14799,7 +14891,7 @@ async function updateMediaMessageIdBatchOp(ctx, mediaIds, messageId) {
14799
14891
  return 0;
14800
14892
  }
14801
14893
  const mediaCollection = ctx.database.get("media");
14802
- const results = await mediaCollection.query(import_watermelondb22.Q.where("media_id", import_watermelondb22.Q.oneOf(mediaIds))).fetch();
14894
+ const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", import_watermelondb23.Q.oneOf(mediaIds))).fetch();
14803
14895
  if (results.length === 0) {
14804
14896
  return 0;
14805
14897
  }
@@ -14821,13 +14913,13 @@ var IMAGE_VIDEO_MIMES = VIDEO_EXTENSIONS.map((ext) => `image/${ext}`);
14821
14913
  async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
14822
14914
  const mediaCollection = ctx.database.get("media");
14823
14915
  const candidates = await mediaCollection.query(
14824
- import_watermelondb22.Q.where("wallet_address", walletAddress),
14825
- import_watermelondb22.Q.where("is_deleted", false),
14826
- import_watermelondb22.Q.where("media_type", "image"),
14827
- import_watermelondb22.Q.or(
14828
- import_watermelondb22.Q.where("mime_type", import_watermelondb22.Q.like("video/%")),
14829
- ...IMAGE_VIDEO_MIMES.map((m) => import_watermelondb22.Q.where("mime_type", m)),
14830
- import_watermelondb22.Q.where("mime_type", "application/octet-stream")
14916
+ import_watermelondb23.Q.where("wallet_address", walletAddress),
14917
+ import_watermelondb23.Q.where("is_deleted", false),
14918
+ import_watermelondb23.Q.where("media_type", "image"),
14919
+ import_watermelondb23.Q.or(
14920
+ import_watermelondb23.Q.where("mime_type", import_watermelondb23.Q.like("video/%")),
14921
+ ...IMAGE_VIDEO_MIMES.map((m) => import_watermelondb23.Q.where("mime_type", m)),
14922
+ import_watermelondb23.Q.where("mime_type", "application/octet-stream")
14831
14923
  )
14832
14924
  ).fetch();
14833
14925
  if (candidates.length === 0) {
@@ -14876,7 +14968,7 @@ async function relinkMisclassifiedVideosOp(ctx, walletAddress) {
14876
14968
  }
14877
14969
  async function deleteMediaOp(ctx, mediaId) {
14878
14970
  const mediaCollection = ctx.database.get("media");
14879
- const results = await mediaCollection.query(import_watermelondb22.Q.where("media_id", mediaId)).fetch();
14971
+ const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId)).fetch();
14880
14972
  if (results.length === 0) {
14881
14973
  return false;
14882
14974
  }
@@ -14894,7 +14986,7 @@ async function deleteMediaOp(ctx, mediaId) {
14894
14986
  }
14895
14987
  async function hardDeleteMediaOp(ctx, mediaId) {
14896
14988
  const mediaCollection = ctx.database.get("media");
14897
- const results = await mediaCollection.query(import_watermelondb22.Q.where("media_id", mediaId)).fetch();
14989
+ const results = await mediaCollection.query(import_watermelondb23.Q.where("media_id", mediaId)).fetch();
14898
14990
  if (results.length === 0) {
14899
14991
  return false;
14900
14992
  }
@@ -14906,28 +14998,28 @@ async function hardDeleteMediaOp(ctx, mediaId) {
14906
14998
  }
14907
14999
  async function getMediaOp(ctx, filters) {
14908
15000
  const mediaCollection = ctx.database.get("media");
14909
- const conditions = [import_watermelondb22.Q.where("wallet_address", filters.walletAddress)];
15001
+ const conditions = [import_watermelondb23.Q.where("wallet_address", filters.walletAddress)];
14910
15002
  if (!filters.includeDeleted) {
14911
- conditions.push(import_watermelondb22.Q.where("is_deleted", false));
15003
+ conditions.push(import_watermelondb23.Q.where("is_deleted", false));
14912
15004
  }
14913
15005
  if (filters.mediaType) {
14914
- conditions.push(import_watermelondb22.Q.where("media_type", filters.mediaType));
15006
+ conditions.push(import_watermelondb23.Q.where("media_type", filters.mediaType));
14915
15007
  }
14916
15008
  if (filters.role) {
14917
- conditions.push(import_watermelondb22.Q.where("role", filters.role));
15009
+ conditions.push(import_watermelondb23.Q.where("role", filters.role));
14918
15010
  }
14919
15011
  if (filters.conversationId) {
14920
- conditions.push(import_watermelondb22.Q.where("conversation_id", filters.conversationId));
15012
+ conditions.push(import_watermelondb23.Q.where("conversation_id", filters.conversationId));
14921
15013
  }
14922
15014
  if (filters.model) {
14923
- conditions.push(import_watermelondb22.Q.where("model", filters.model));
15015
+ conditions.push(import_watermelondb23.Q.where("model", filters.model));
14924
15016
  }
14925
- conditions.push(import_watermelondb22.Q.sortBy("created_at", import_watermelondb22.Q.desc));
15017
+ conditions.push(import_watermelondb23.Q.sortBy("created_at", import_watermelondb23.Q.desc));
14926
15018
  if (filters.limit) {
14927
- conditions.push(import_watermelondb22.Q.take(filters.limit));
15019
+ conditions.push(import_watermelondb23.Q.take(filters.limit));
14928
15020
  }
14929
15021
  if (filters.offset) {
14930
- conditions.push(import_watermelondb22.Q.skip(filters.offset));
15022
+ conditions.push(import_watermelondb23.Q.skip(filters.offset));
14931
15023
  }
14932
15024
  const results = await mediaCollection.query(...conditions).fetch();
14933
15025
  return Promise.all(
@@ -14957,9 +15049,9 @@ async function getMediaByConversationOp(ctx, walletAddress, conversationId, limi
14957
15049
  async function getMediaByMessageOp(ctx, messageId) {
14958
15050
  const mediaCollection = ctx.database.get("media");
14959
15051
  const results = await mediaCollection.query(
14960
- import_watermelondb22.Q.where("message_id", messageId),
14961
- import_watermelondb22.Q.where("is_deleted", false),
14962
- import_watermelondb22.Q.sortBy("created_at", import_watermelondb22.Q.asc)
15052
+ import_watermelondb23.Q.where("message_id", messageId),
15053
+ import_watermelondb23.Q.where("is_deleted", false),
15054
+ import_watermelondb23.Q.sortBy("created_at", import_watermelondb23.Q.asc)
14963
15055
  ).fetch();
14964
15056
  return Promise.all(
14965
15057
  results.map(
@@ -14972,9 +15064,9 @@ async function getMediaByIdsOp(ctx, mediaIds, includeDeleted = false) {
14972
15064
  return [];
14973
15065
  }
14974
15066
  const mediaCollection = ctx.database.get("media");
14975
- const conditions = [import_watermelondb22.Q.where("media_id", import_watermelondb22.Q.oneOf(mediaIds))];
15067
+ const conditions = [import_watermelondb23.Q.where("media_id", import_watermelondb23.Q.oneOf(mediaIds))];
14976
15068
  if (!includeDeleted) {
14977
- conditions.push(import_watermelondb22.Q.where("is_deleted", false));
15069
+ conditions.push(import_watermelondb23.Q.where("is_deleted", false));
14978
15070
  }
14979
15071
  const results = await mediaCollection.query(...conditions).fetch();
14980
15072
  const mediaMap = new Map(results.map((m) => [m.mediaId, m]));
@@ -15011,10 +15103,10 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
15011
15103
  const queryLower = query.toLowerCase();
15012
15104
  const MAX_SEARCH_RECORDS = 500;
15013
15105
  const allResults = await mediaCollection.query(
15014
- import_watermelondb22.Q.where("wallet_address", walletAddress),
15015
- import_watermelondb22.Q.where("is_deleted", false),
15016
- import_watermelondb22.Q.sortBy("created_at", import_watermelondb22.Q.desc),
15017
- import_watermelondb22.Q.take(MAX_SEARCH_RECORDS)
15106
+ import_watermelondb23.Q.where("wallet_address", walletAddress),
15107
+ import_watermelondb23.Q.where("is_deleted", false),
15108
+ import_watermelondb23.Q.sortBy("created_at", import_watermelondb23.Q.desc),
15109
+ import_watermelondb23.Q.take(MAX_SEARCH_RECORDS)
15018
15110
  ).fetch();
15019
15111
  const decrypted = await Promise.all(
15020
15112
  allResults.map(
@@ -15027,11 +15119,11 @@ async function searchMediaOp(ctx, walletAddress, query, limit) {
15027
15119
  async function getMediaCountOp(ctx, walletAddress, mediaType) {
15028
15120
  const mediaCollection = ctx.database.get("media");
15029
15121
  const conditions = [
15030
- import_watermelondb22.Q.where("wallet_address", walletAddress),
15031
- import_watermelondb22.Q.where("is_deleted", false)
15122
+ import_watermelondb23.Q.where("wallet_address", walletAddress),
15123
+ import_watermelondb23.Q.where("is_deleted", false)
15032
15124
  ];
15033
15125
  if (mediaType) {
15034
- conditions.push(import_watermelondb22.Q.where("media_type", mediaType));
15126
+ conditions.push(import_watermelondb23.Q.where("media_type", mediaType));
15035
15127
  }
15036
15128
  return await mediaCollection.query(...conditions).fetchCount();
15037
15129
  }
@@ -15046,7 +15138,7 @@ async function getMediaCountsByTypeOp(ctx, walletAddress) {
15046
15138
  }
15047
15139
  async function deleteMediaByConversationOp(ctx, conversationId) {
15048
15140
  const mediaCollection = ctx.database.get("media");
15049
- const results = await mediaCollection.query(import_watermelondb22.Q.where("conversation_id", conversationId), import_watermelondb22.Q.where("is_deleted", false)).fetch();
15141
+ const results = await mediaCollection.query(import_watermelondb23.Q.where("conversation_id", conversationId), import_watermelondb23.Q.where("is_deleted", false)).fetch();
15050
15142
  if (results.length === 0) {
15051
15143
  return 0;
15052
15144
  }
@@ -15067,7 +15159,7 @@ async function deleteMediaByConversationOp(ctx, conversationId) {
15067
15159
  }
15068
15160
  async function deleteMediaByMessageOp(ctx, messageId) {
15069
15161
  const mediaCollection = ctx.database.get("media");
15070
- const results = await mediaCollection.query(import_watermelondb22.Q.where("message_id", messageId), import_watermelondb22.Q.where("is_deleted", false)).fetch();
15162
+ const results = await mediaCollection.query(import_watermelondb23.Q.where("message_id", messageId), import_watermelondb23.Q.where("is_deleted", false)).fetch();
15071
15163
  if (results.length === 0) {
15072
15164
  return 0;
15073
15165
  }
@@ -15088,7 +15180,7 @@ async function deleteMediaByMessageOp(ctx, messageId) {
15088
15180
  }
15089
15181
 
15090
15182
  // src/lib/db/memoryVault/operations.ts
15091
- var import_watermelondb23 = require("@nozbe/watermelondb");
15183
+ var import_watermelondb24 = require("@nozbe/watermelondb");
15092
15184
  init_logger();
15093
15185
 
15094
15186
  // src/lib/db/memoryVault/encryption.ts
@@ -15139,11 +15231,11 @@ var NON_PRIVATE_VISIBILITIES = ["public"];
15139
15231
  function visibilityConditions(requested) {
15140
15232
  if (!requested?.length) return [];
15141
15233
  if (!requested.includes("private")) {
15142
- return [import_watermelondb23.Q.where("visibility", import_watermelondb23.Q.oneOf([...requested]))];
15234
+ return [import_watermelondb24.Q.where("visibility", import_watermelondb24.Q.oneOf([...requested]))];
15143
15235
  }
15144
15236
  const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
15145
15237
  if (excluded.length === 0) return [];
15146
- return [import_watermelondb23.Q.or(import_watermelondb23.Q.where("visibility", null), import_watermelondb23.Q.where("visibility", import_watermelondb23.Q.notIn(excluded)))];
15238
+ return [import_watermelondb24.Q.or(import_watermelondb24.Q.where("visibility", null), import_watermelondb24.Q.where("visibility", import_watermelondb24.Q.notIn(excluded)))];
15147
15239
  }
15148
15240
  function isKinded(record2) {
15149
15241
  return record2.kind !== null && record2.kind !== void 0;
@@ -15184,17 +15276,17 @@ function levelConditions(requested) {
15184
15276
  const published = ["shared", "public"];
15185
15277
  const wantsMatching = requested.includes("matching");
15186
15278
  const wantsPrivate = requested.includes("private");
15187
- const unresolved = import_watermelondb23.Q.or(import_watermelondb23.Q.where("level", null), import_watermelondb23.Q.where("level", import_watermelondb23.Q.notIn([...MEMORY_LEVELS])));
15188
- const byLevel = import_watermelondb23.Q.where("level", import_watermelondb23.Q.oneOf([...requested]));
15189
- if (wantsMatching && wantsPrivate) return [import_watermelondb23.Q.or(byLevel, unresolved)];
15279
+ const unresolved = import_watermelondb24.Q.or(import_watermelondb24.Q.where("level", null), import_watermelondb24.Q.where("level", import_watermelondb24.Q.notIn([...MEMORY_LEVELS])));
15280
+ const byLevel = import_watermelondb24.Q.where("level", import_watermelondb24.Q.oneOf([...requested]));
15281
+ if (wantsMatching && wantsPrivate) return [import_watermelondb24.Q.or(byLevel, unresolved)];
15190
15282
  if (wantsMatching) {
15191
- return [import_watermelondb23.Q.or(byLevel, import_watermelondb23.Q.and(unresolved, import_watermelondb23.Q.where("scope", import_watermelondb23.Q.oneOf(published))))];
15283
+ return [import_watermelondb24.Q.or(byLevel, import_watermelondb24.Q.and(unresolved, import_watermelondb24.Q.where("scope", import_watermelondb24.Q.oneOf(published))))];
15192
15284
  }
15193
15285
  if (wantsPrivate) {
15194
15286
  return [
15195
- import_watermelondb23.Q.or(
15287
+ import_watermelondb24.Q.or(
15196
15288
  byLevel,
15197
- import_watermelondb23.Q.and(unresolved, import_watermelondb23.Q.or(import_watermelondb23.Q.where("scope", null), import_watermelondb23.Q.where("scope", import_watermelondb23.Q.notIn(published))))
15289
+ 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
15290
  )
15199
15291
  ];
15200
15292
  }
@@ -15205,13 +15297,13 @@ function isOwnedByCtxUser(ctx, record2) {
15205
15297
  }
15206
15298
  function baseVaultConditions(ctx, options) {
15207
15299
  return [
15208
- ...options?.memoryIds !== void 0 ? [import_watermelondb23.Q.where("id", import_watermelondb23.Q.oneOf(options.memoryIds))] : [],
15209
- ...options?.includeDeleted ? [] : [import_watermelondb23.Q.where("is_deleted", false)],
15210
- ...options?.includeArchived ? [] : [import_watermelondb23.Q.where("archived_at", import_watermelondb23.Q.eq(null))],
15211
- ...options?.includeQuarantined ? [] : [import_watermelondb23.Q.where("trust_tier", import_watermelondb23.Q.notEq("quarantined"))],
15212
- ...options?.includeSuperseded ? [] : [import_watermelondb23.Q.where("superseded_by", null)],
15213
- ...ctx.userId !== void 0 ? [import_watermelondb23.Q.where("user_id", ctx.userId)] : [],
15214
- ...options?.since ? [import_watermelondb23.Q.where("updated_at", import_watermelondb23.Q.gt(options.since.getTime()))] : []
15300
+ ...options?.memoryIds !== void 0 ? [import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(options.memoryIds))] : [],
15301
+ ...options?.includeDeleted ? [] : [import_watermelondb24.Q.where("is_deleted", false)],
15302
+ ...options?.includeArchived ? [] : [import_watermelondb24.Q.where("archived_at", import_watermelondb24.Q.eq(null))],
15303
+ ...options?.includeQuarantined ? [] : [import_watermelondb24.Q.where("trust_tier", import_watermelondb24.Q.notEq("quarantined"))],
15304
+ ...options?.includeSuperseded ? [] : [import_watermelondb24.Q.where("superseded_by", null)],
15305
+ ...ctx.userId !== void 0 ? [import_watermelondb24.Q.where("user_id", ctx.userId)] : [],
15306
+ ...options?.since ? [import_watermelondb24.Q.where("updated_at", import_watermelondb24.Q.gt(options.since.getTime()))] : []
15215
15307
  ];
15216
15308
  }
15217
15309
  var KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
@@ -15381,11 +15473,11 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
15381
15473
  async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
15382
15474
  const records = await ctx.vaultMemoryCollection.query(
15383
15475
  ...baseVaultConditions(ctx),
15384
- import_watermelondb23.Q.where("event_time_start", import_watermelondb23.Q.notEq(null)),
15385
- import_watermelondb23.Q.where("event_time_start", import_watermelondb23.Q.lte(windowEnd)),
15386
- import_watermelondb23.Q.or(
15387
- import_watermelondb23.Q.where("event_time_start", import_watermelondb23.Q.gte(windowStart)),
15388
- import_watermelondb23.Q.where("event_time_kind", import_watermelondb23.Q.oneOf(["range", "ongoing"]))
15476
+ import_watermelondb24.Q.where("event_time_start", import_watermelondb24.Q.notEq(null)),
15477
+ import_watermelondb24.Q.where("event_time_start", import_watermelondb24.Q.lte(windowEnd)),
15478
+ import_watermelondb24.Q.or(
15479
+ import_watermelondb24.Q.where("event_time_start", import_watermelondb24.Q.gte(windowStart)),
15480
+ import_watermelondb24.Q.where("event_time_kind", import_watermelondb24.Q.oneOf(["range", "ongoing"]))
15389
15481
  )
15390
15482
  ).fetch();
15391
15483
  const out = [];
@@ -15541,18 +15633,18 @@ async function getAllVaultMemoriesOp(ctx, options) {
15541
15633
  function vaultListConditions(ctx, options) {
15542
15634
  return [
15543
15635
  ...baseVaultConditions(ctx, options),
15544
- ...options?.scopes?.length ? [import_watermelondb23.Q.where("scope", import_watermelondb23.Q.oneOf(options.scopes))] : [],
15636
+ ...options?.scopes?.length ? [import_watermelondb24.Q.where("scope", import_watermelondb24.Q.oneOf(options.scopes))] : [],
15545
15637
  ...visibilityConditions(options?.visibility),
15546
15638
  ...levelConditions(options?.levels),
15547
- ...options?.kinds?.length ? [import_watermelondb23.Q.where("kind", import_watermelondb23.Q.oneOf(options.kinds))] : [],
15548
- ...options?.folderId !== void 0 ? [import_watermelondb23.Q.where("folder_id", options.folderId)] : [],
15549
- ...options?.factTypes?.length ? [import_watermelondb23.Q.where("fact_type", import_watermelondb23.Q.oneOf(options.factTypes))] : []
15639
+ ...options?.kinds?.length ? [import_watermelondb24.Q.where("kind", import_watermelondb24.Q.oneOf(options.kinds))] : [],
15640
+ ...options?.folderId !== void 0 ? [import_watermelondb24.Q.where("folder_id", options.folderId)] : [],
15641
+ ...options?.factTypes?.length ? [import_watermelondb24.Q.where("fact_type", import_watermelondb24.Q.oneOf(options.factTypes))] : []
15550
15642
  ];
15551
15643
  }
15552
15644
  function vaultListOrder(options) {
15553
15645
  return [
15554
- import_watermelondb23.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb23.Q.desc),
15555
- ...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb23.Q.take(options.limit)] : []
15646
+ import_watermelondb24.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb24.Q.desc),
15647
+ ...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb24.Q.take(options.limit)] : []
15556
15648
  ];
15557
15649
  }
15558
15650
  async function getAllVaultMemoryRowsOp(ctx) {
@@ -15591,10 +15683,10 @@ function vaultMemoryRawToRankable(raw) {
15591
15683
  async function getVaultRankingProjectionsOp(ctx, options) {
15592
15684
  const conditions = [
15593
15685
  ...baseVaultConditions(ctx, options),
15594
- ...options?.scopes?.length ? [import_watermelondb23.Q.where("scope", import_watermelondb23.Q.oneOf(options.scopes))] : [],
15595
- ...options?.folderId !== void 0 ? [import_watermelondb23.Q.where("folder_id", options.folderId)] : [],
15596
- import_watermelondb23.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb23.Q.desc),
15597
- ...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb23.Q.take(options.limit)] : []
15686
+ ...options?.scopes?.length ? [import_watermelondb24.Q.where("scope", import_watermelondb24.Q.oneOf(options.scopes))] : [],
15687
+ ...options?.folderId !== void 0 ? [import_watermelondb24.Q.where("folder_id", options.folderId)] : [],
15688
+ import_watermelondb24.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb24.Q.desc),
15689
+ ...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [import_watermelondb24.Q.take(options.limit)] : []
15598
15690
  ];
15599
15691
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
15600
15692
  return results.map(vaultMemoryRawToRankable);
@@ -15645,7 +15737,7 @@ async function getVaultCandidateKeysOp(ctx, options) {
15645
15737
  args.push(...options.factTypes);
15646
15738
  }
15647
15739
  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(import_watermelondb23.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
15740
+ const rows = await ctx.vaultMemoryCollection.query(import_watermelondb24.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
15649
15741
  return rows.map(mapRaw);
15650
15742
  } catch (err) {
15651
15743
  getLogger().debug(
@@ -15656,9 +15748,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
15656
15748
  memoryIds: options?.memoryIds,
15657
15749
  ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
15658
15750
  }),
15659
- ...options?.scopes?.length ? [import_watermelondb23.Q.where("scope", import_watermelondb23.Q.oneOf(options.scopes))] : [],
15660
- ...options?.folderId !== void 0 ? [import_watermelondb23.Q.where("folder_id", options.folderId)] : [],
15661
- ...options?.factTypes?.length ? [import_watermelondb23.Q.where("fact_type", import_watermelondb23.Q.oneOf(options.factTypes))] : []
15751
+ ...options?.scopes?.length ? [import_watermelondb24.Q.where("scope", import_watermelondb24.Q.oneOf(options.scopes))] : [],
15752
+ ...options?.folderId !== void 0 ? [import_watermelondb24.Q.where("folder_id", options.folderId)] : [],
15753
+ ...options?.factTypes?.length ? [import_watermelondb24.Q.where("fact_type", import_watermelondb24.Q.oneOf(options.factTypes))] : []
15662
15754
  ];
15663
15755
  const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
15664
15756
  return rows.map(mapRaw);
@@ -15676,7 +15768,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
15676
15768
  ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
15677
15769
  });
15678
15770
  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(import_watermelondb23.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
15771
+ const rows = await ctx.vaultMemoryCollection.query(import_watermelondb24.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
15680
15772
  return rows.map(mapRaw);
15681
15773
  } catch (err) {
15682
15774
  getLogger().debug(
@@ -15688,7 +15780,7 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
15688
15780
  includeArchived: options.includeArchived
15689
15781
  }
15690
15782
  }),
15691
- import_watermelondb23.Q.where("id", import_watermelondb23.Q.oneOf(ids))
15783
+ import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(ids))
15692
15784
  ).unsafeFetchRaw();
15693
15785
  return rows.map(mapRaw);
15694
15786
  }
@@ -15699,7 +15791,7 @@ async function getVaultMemoriesByIdsOp(ctx, ids, options) {
15699
15791
  ...baseVaultConditions(ctx, {
15700
15792
  ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
15701
15793
  }),
15702
- import_watermelondb23.Q.where("id", import_watermelondb23.Q.oneOf(ids))
15794
+ import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(ids))
15703
15795
  ];
15704
15796
  const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
15705
15797
  return mapInBatches(
@@ -15724,7 +15816,7 @@ async function countActiveVaultMemoriesOp(ctx) {
15724
15816
  }
15725
15817
  async function getActiveVaultMemoryIdsOp(ctx, ids) {
15726
15818
  if (ids.length === 0) return /* @__PURE__ */ new Set();
15727
- const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb23.Q.where("id", import_watermelondb23.Q.oneOf(ids))).unsafeFetchRaw();
15819
+ const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(ids))).unsafeFetchRaw();
15728
15820
  return new Set(rows.map((r) => r.id));
15729
15821
  }
15730
15822
  async function updateVaultMemoryOp(ctx, id, opts) {
@@ -15873,7 +15965,7 @@ async function setMemoryEntitiesOp(ctx, memoryId, entities) {
15873
15965
  () => linkMemoryEntitiesOp(entityCtx, memoryId, entities, { topicsSource: "user" })
15874
15966
  ) : [];
15875
15967
  const keep = new Set(linked.map((e) => e.uniqueId));
15876
- const existing = await entityCtx.memoryEntityCollection.query(import_watermelondb23.Q.where("memory_id", memoryId)).fetch();
15968
+ const existing = await entityCtx.memoryEntityCollection.query(import_watermelondb24.Q.where("memory_id", memoryId)).fetch();
15877
15969
  const staleLinks = existing.filter((l) => !keep.has(String(l.entityId)));
15878
15970
  if (staleLinks.length === 0 && entities.length > 0) return;
15879
15971
  const topicsWrite = await resolveMemoryTopicsWrite(
@@ -16014,9 +16106,9 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
16014
16106
  }
16015
16107
  async function getUnfiledVaultMemoriesOp(ctx) {
16016
16108
  const conditions = [
16017
- import_watermelondb23.Q.where("folder_id", null),
16109
+ import_watermelondb24.Q.where("folder_id", null),
16018
16110
  ...baseVaultConditions(ctx),
16019
- import_watermelondb23.Q.sortBy("created_at", import_watermelondb23.Q.desc)
16111
+ import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)
16020
16112
  ];
16021
16113
  const results = await ctx.vaultMemoryCollection.query(...conditions).fetch();
16022
16114
  return mapInBatches(
@@ -16030,7 +16122,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
16030
16122
  const entityIdByMemory = /* @__PURE__ */ new Map();
16031
16123
  const allEntityIds = /* @__PURE__ */ new Set();
16032
16124
  for (let i = 0; i < memoryIds.length; i += CHUNK) {
16033
- const links = await entityCtx.memoryEntityCollection.query(import_watermelondb23.Q.where("memory_id", import_watermelondb23.Q.oneOf(memoryIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
16125
+ const links = await entityCtx.memoryEntityCollection.query(import_watermelondb24.Q.where("memory_id", import_watermelondb24.Q.oneOf(memoryIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
16034
16126
  for (const link of links) {
16035
16127
  const memoryId = String(link.memory_id);
16036
16128
  const entityId = String(link.entity_id);
@@ -16046,7 +16138,7 @@ async function linkedEntityNamesByMemory(entityCtx, memoryIds) {
16046
16138
  const entityIds = Array.from(allEntityIds);
16047
16139
  const nameById = /* @__PURE__ */ new Map();
16048
16140
  for (let i = 0; i < entityIds.length; i += CHUNK) {
16049
- const entities = await entityCtx.entityCollection.query(import_watermelondb23.Q.where("id", import_watermelondb23.Q.oneOf(entityIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
16141
+ const entities = await entityCtx.entityCollection.query(import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(entityIds.slice(i, i + CHUNK)))).unsafeFetchRaw();
16050
16142
  for (const e of entities) {
16051
16143
  if (typeof e.canonical_name === "string") nameById.set(String(e.id), e.canonical_name);
16052
16144
  }
@@ -16075,7 +16167,7 @@ async function getMemoriesNeedingTopicExtractionOp(ctx, options) {
16075
16167
  if (!entityCtx) {
16076
16168
  throw new Error("getMemoriesNeedingTopicExtractionOp requires ctx.entityCtx");
16077
16169
  }
16078
- const conditions = [...baseVaultConditions(ctx), import_watermelondb23.Q.sortBy("created_at", import_watermelondb23.Q.desc)];
16170
+ const conditions = [...baseVaultConditions(ctx), import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)];
16079
16171
  const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
16080
16172
  const linkedNames = await linkedEntityNamesByMemory(
16081
16173
  entityCtx,
@@ -16231,10 +16323,10 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
16231
16323
  }
16232
16324
  if (record2.isDeleted || !isOwnedByCtxUser(ctx, record2)) continue;
16233
16325
  if (parseTopics(record2.topics) !== null) continue;
16234
- const links = await entityCtx.memoryEntityCollection.query(import_watermelondb23.Q.where("memory_id", id)).unsafeFetchRaw();
16326
+ const links = await entityCtx.memoryEntityCollection.query(import_watermelondb24.Q.where("memory_id", id)).unsafeFetchRaw();
16235
16327
  const entityIds = links.map((l) => String(l.entity_id));
16236
16328
  if (entityIds.length === 0) continue;
16237
- const entities = await entityCtx.entityCollection.query(import_watermelondb23.Q.where("id", import_watermelondb23.Q.oneOf(entityIds))).fetch();
16329
+ const entities = await entityCtx.entityCollection.query(import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf(entityIds))).fetch();
16238
16330
  if (entities.length === 0) continue;
16239
16331
  const source = record2.topicsUserManaged ? "user" : "auto";
16240
16332
  const write = await resolveMemoryTopicsWrite(entityCtx, id, entities, [], source);
@@ -16250,7 +16342,7 @@ async function backfillMemoryTopicsOp(ctx, memoryIds) {
16250
16342
  }
16251
16343
  async function deleteAllVaultMemoriesForUserOp(ctx, userId) {
16252
16344
  if (ctx.userId !== void 0 && ctx.userId !== userId) return 0;
16253
- const records = await ctx.vaultMemoryCollection.query(import_watermelondb23.Q.where("user_id", userId), import_watermelondb23.Q.where("is_deleted", false)).fetch();
16345
+ const records = await ctx.vaultMemoryCollection.query(import_watermelondb24.Q.where("user_id", userId), import_watermelondb24.Q.where("is_deleted", false)).fetch();
16254
16346
  if (records.length === 0) return 0;
16255
16347
  await ctx.database.write(async () => {
16256
16348
  await assertCanWrite2(ctx);
@@ -16287,7 +16379,7 @@ async function getDecayCandidatesRawOp(ctx) {
16287
16379
  assertVaultScopeForSweep(ctx);
16288
16380
  const results = await ctx.vaultMemoryCollection.query(
16289
16381
  ...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
16290
- import_watermelondb23.Q.where("kind", null)
16382
+ import_watermelondb24.Q.where("kind", null)
16291
16383
  ).unsafeFetchRaw();
16292
16384
  return results.map((raw) => ({
16293
16385
  uniqueId: raw.id,
@@ -16417,11 +16509,11 @@ async function findQuarantinedDuplicateOp(ctx, content, sourceIds2, where) {
16417
16509
  const wanted = [...new Set(sourceIds2)].sort().join("\0");
16418
16510
  const target = normalizeForDedupe(content);
16419
16511
  const rows = await ctx.vaultMemoryCollection.query(
16420
- import_watermelondb23.Q.where("trust_tier", "quarantined"),
16421
- import_watermelondb23.Q.where("is_deleted", false),
16422
- import_watermelondb23.Q.where("scope", where.scope),
16423
- import_watermelondb23.Q.where("folder_id", where.folderId),
16424
- ...ctx.userId !== void 0 ? [import_watermelondb23.Q.where("user_id", ctx.userId)] : []
16512
+ import_watermelondb24.Q.where("trust_tier", "quarantined"),
16513
+ import_watermelondb24.Q.where("is_deleted", false),
16514
+ import_watermelondb24.Q.where("scope", where.scope),
16515
+ import_watermelondb24.Q.where("folder_id", where.folderId),
16516
+ ...ctx.userId !== void 0 ? [import_watermelondb24.Q.where("user_id", ctx.userId)] : []
16425
16517
  ).unsafeFetchRaw();
16426
16518
  for (const raw of rows) {
16427
16519
  let ids;
@@ -16578,7 +16670,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
16578
16670
  }
16579
16671
 
16580
16672
  // src/lib/db/project/operations.ts
16581
- var import_watermelondb24 = require("@nozbe/watermelondb");
16673
+ var import_watermelondb25 = require("@nozbe/watermelondb");
16582
16674
 
16583
16675
  // src/lib/db/project/types.ts
16584
16676
  function generateProjectId() {
@@ -16609,15 +16701,15 @@ async function createProjectOp(ctx, opts, defaultName = "New Project") {
16609
16701
  return projectToStored(created);
16610
16702
  }
16611
16703
  async function getProjectOp(ctx, id) {
16612
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
16704
+ const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
16613
16705
  return results.length > 0 ? projectToStored(results[0]) : null;
16614
16706
  }
16615
16707
  async function getProjectsOp(ctx) {
16616
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("is_deleted", false), import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)).fetch();
16708
+ 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
16709
  return results.map(projectToStored);
16618
16710
  }
16619
16711
  async function updateProjectNameOp(ctx, id, name) {
16620
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
16712
+ const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
16621
16713
  if (results.length > 0) {
16622
16714
  await ctx.database.write(async () => {
16623
16715
  await results[0].update((proj) => {
@@ -16629,7 +16721,7 @@ async function updateProjectNameOp(ctx, id, name) {
16629
16721
  return false;
16630
16722
  }
16631
16723
  async function updateProjectOp(ctx, id, opts) {
16632
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
16724
+ const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
16633
16725
  if (results.length > 0) {
16634
16726
  await ctx.database.write(async () => {
16635
16727
  await results[0].update((proj) => {
@@ -16641,7 +16733,7 @@ async function updateProjectOp(ctx, id, opts) {
16641
16733
  return false;
16642
16734
  }
16643
16735
  async function deleteProjectOp(ctx, id) {
16644
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
16736
+ const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
16645
16737
  if (results.length > 0) {
16646
16738
  await ctx.database.write(async () => {
16647
16739
  await results[0].update((proj) => {
@@ -16654,14 +16746,14 @@ async function deleteProjectOp(ctx, id) {
16654
16746
  }
16655
16747
  async function getProjectConversationsOp(ctx, projectId) {
16656
16748
  const results = await ctx.conversationsCollection.query(
16657
- import_watermelondb24.Q.where("project_id", projectId),
16658
- import_watermelondb24.Q.where("is_deleted", false),
16659
- import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)
16749
+ import_watermelondb25.Q.where("project_id", projectId),
16750
+ import_watermelondb25.Q.where("is_deleted", false),
16751
+ import_watermelondb25.Q.sortBy("created_at", import_watermelondb25.Q.desc)
16660
16752
  ).fetch();
16661
16753
  return results.map(conversationToStoredRaw);
16662
16754
  }
16663
16755
  async function getProjectConversationCountOp(ctx, projectId) {
16664
- return await ctx.conversationsCollection.query(import_watermelondb24.Q.where("project_id", projectId), import_watermelondb24.Q.where("is_deleted", false)).fetchCount();
16756
+ return await ctx.conversationsCollection.query(import_watermelondb25.Q.where("project_id", projectId), import_watermelondb25.Q.where("is_deleted", false)).fetchCount();
16665
16757
  }
16666
16758
 
16667
16759
  // src/lib/db/queue/manager.ts
@@ -17005,7 +17097,7 @@ var WalletPoller = class {
17005
17097
  };
17006
17098
 
17007
17099
  // src/lib/db/savedTools/operations.ts
17008
- var import_watermelondb25 = require("@nozbe/watermelondb");
17100
+ var import_watermelondb26 = require("@nozbe/watermelondb");
17009
17101
  function savedToolToStored(tool) {
17010
17102
  return {
17011
17103
  uniqueId: tool.id,
@@ -17038,7 +17130,7 @@ async function createSavedToolOp(ctx, opts) {
17038
17130
  return savedToolToStored(created);
17039
17131
  }
17040
17132
  async function getAllSavedToolsOp(ctx) {
17041
- const results = await ctx.savedToolsCollection.query(import_watermelondb25.Q.where("is_deleted", false), import_watermelondb25.Q.sortBy("created_at", import_watermelondb25.Q.desc)).fetch();
17133
+ 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
17134
  return results.map(savedToolToStored);
17043
17135
  }
17044
17136
  async function getSavedToolByIdOp(ctx, uniqueId) {
@@ -17090,7 +17182,7 @@ async function deleteSavedToolOp(ctx, uniqueId) {
17090
17182
  }
17091
17183
 
17092
17184
  // src/lib/db/settings/operations.ts
17093
- var import_watermelondb26 = require("@nozbe/watermelondb");
17185
+ var import_watermelondb27 = require("@nozbe/watermelondb");
17094
17186
  function modelPreferenceToStored(preference) {
17095
17187
  return {
17096
17188
  uniqueId: preference.id,
@@ -17099,12 +17191,12 @@ function modelPreferenceToStored(preference) {
17099
17191
  };
17100
17192
  }
17101
17193
  async function getModelPreferenceOp(ctx, walletAddress) {
17102
- const results = await ctx.modelPreferencesCollection.query(import_watermelondb26.Q.where("wallet_address", walletAddress)).fetch();
17194
+ const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
17103
17195
  return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
17104
17196
  }
17105
17197
  async function setModelPreferenceOp(ctx, walletAddress, models) {
17106
17198
  const result = await ctx.database.write(async () => {
17107
- const results = await ctx.modelPreferencesCollection.query(import_watermelondb26.Q.where("wallet_address", walletAddress)).fetch();
17199
+ const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
17108
17200
  if (results.length > 0) {
17109
17201
  const preference = results[0];
17110
17202
  await preference.update((pref) => {
@@ -17122,7 +17214,7 @@ async function setModelPreferenceOp(ctx, walletAddress, models) {
17122
17214
  return modelPreferenceToStored(result);
17123
17215
  }
17124
17216
  async function deleteModelPreferenceOp(ctx, walletAddress) {
17125
- const results = await ctx.modelPreferencesCollection.query(import_watermelondb26.Q.where("wallet_address", walletAddress)).fetch();
17217
+ const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
17126
17218
  if (results.length === 0) return false;
17127
17219
  await ctx.database.write(async () => {
17128
17220
  await results[0].destroyPermanently();
@@ -17131,11 +17223,11 @@ async function deleteModelPreferenceOp(ctx, walletAddress) {
17131
17223
  }
17132
17224
 
17133
17225
  // src/lib/db/settings/schema.ts
17134
- var import_watermelondb27 = require("@nozbe/watermelondb");
17135
- var settingsStorageSchema = (0, import_watermelondb27.appSchema)({
17226
+ var import_watermelondb28 = require("@nozbe/watermelondb");
17227
+ var settingsStorageSchema = (0, import_watermelondb28.appSchema)({
17136
17228
  version: 1,
17137
17229
  tables: [
17138
- (0, import_watermelondb27.tableSchema)({
17230
+ (0, import_watermelondb28.tableSchema)({
17139
17231
  name: "modelPreferences",
17140
17232
  columns: [
17141
17233
  { name: "wallet_address", type: "string", isIndexed: true },
@@ -17146,7 +17238,7 @@ var settingsStorageSchema = (0, import_watermelondb27.appSchema)({
17146
17238
  });
17147
17239
 
17148
17240
  // src/lib/db/userPreferences/operations.ts
17149
- var import_watermelondb28 = require("@nozbe/watermelondb");
17241
+ var import_watermelondb29 = require("@nozbe/watermelondb");
17150
17242
  function userPreferenceToStored(preference) {
17151
17243
  return {
17152
17244
  uniqueId: preference.id,
@@ -17161,7 +17253,7 @@ function userPreferenceToStored(preference) {
17161
17253
  };
17162
17254
  }
17163
17255
  async function getUserPreferenceOp(ctx, walletAddress) {
17164
- const results = await ctx.userPreferencesCollection.query(import_watermelondb28.Q.where("wallet_address", walletAddress)).fetch();
17256
+ const results = await ctx.userPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
17165
17257
  return results.length > 0 ? userPreferenceToStored(results[0]) : null;
17166
17258
  }
17167
17259
  async function createUserPreferenceOp(ctx, opts) {
@@ -17181,7 +17273,7 @@ async function createUserPreferenceOp(ctx, opts) {
17181
17273
  return userPreferenceToStored(created);
17182
17274
  }
17183
17275
  async function updateUserPreferenceOp(ctx, walletAddress, opts) {
17184
- const results = await ctx.userPreferencesCollection.query(import_watermelondb28.Q.where("wallet_address", walletAddress)).fetch();
17276
+ const results = await ctx.userPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
17185
17277
  if (results.length === 0) return null;
17186
17278
  const preference = results[0];
17187
17279
  await ctx.database.write(async () => {
@@ -17209,7 +17301,7 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
17209
17301
  async function setUserPreferenceOp(ctx, walletAddress, opts) {
17210
17302
  const now = Date.now();
17211
17303
  const result = await ctx.database.write(async () => {
17212
- const results = await ctx.userPreferencesCollection.query(import_watermelondb28.Q.where("wallet_address", walletAddress)).fetch();
17304
+ const results = await ctx.userPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
17213
17305
  if (results.length > 0) {
17214
17306
  const preference = results[0];
17215
17307
  await preference.update((pref) => {
@@ -17257,7 +17349,7 @@ async function updateModelsOp(ctx, walletAddress, models) {
17257
17349
  return updateUserPreferenceOp(ctx, walletAddress, { models });
17258
17350
  }
17259
17351
  async function deleteUserPreferenceOp(ctx, walletAddress) {
17260
- const results = await ctx.userPreferencesCollection.query(import_watermelondb28.Q.where("wallet_address", walletAddress)).fetch();
17352
+ const results = await ctx.userPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
17261
17353
  if (results.length === 0) return false;
17262
17354
  await ctx.database.write(async () => {
17263
17355
  await results[0].destroyPermanently();
@@ -17272,9 +17364,9 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
17272
17364
  if (existing) {
17273
17365
  return existing;
17274
17366
  }
17275
- const modelResults = await ctx.modelPreferencesCollection.query(import_watermelondb28.Q.where("wallet_address", walletAddress)).fetch();
17367
+ const modelResults = await ctx.modelPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", walletAddress)).fetch();
17276
17368
  const personalityKey = `${walletAddress}_personality_settings`;
17277
- const personalityResults = await ctx.modelPreferencesCollection.query(import_watermelondb28.Q.where("wallet_address", personalityKey)).fetch();
17369
+ const personalityResults = await ctx.modelPreferencesCollection.query(import_watermelondb29.Q.where("wallet_address", personalityKey)).fetch();
17278
17370
  if (modelResults.length === 0 && personalityResults.length === 0) {
17279
17371
  return null;
17280
17372
  }
@@ -17316,11 +17408,11 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
17316
17408
  }
17317
17409
 
17318
17410
  // src/lib/db/userPreferences/schema.ts
17319
- var import_watermelondb29 = require("@nozbe/watermelondb");
17320
- var userPreferencesStorageSchema = (0, import_watermelondb29.appSchema)({
17411
+ var import_watermelondb30 = require("@nozbe/watermelondb");
17412
+ var userPreferencesStorageSchema = (0, import_watermelondb30.appSchema)({
17321
17413
  version: 1,
17322
17414
  tables: [
17323
- (0, import_watermelondb29.tableSchema)({
17415
+ (0, import_watermelondb30.tableSchema)({
17324
17416
  name: "userPreferences",
17325
17417
  columns: [
17326
17418
  { name: "wallet_address", type: "string", isIndexed: true },
@@ -17375,7 +17467,7 @@ var SLIDER_CONFIG = [
17375
17467
  ];
17376
17468
 
17377
17469
  // src/lib/db/vaultFolders/operations.ts
17378
- var import_watermelondb30 = require("@nozbe/watermelondb");
17470
+ var import_watermelondb31 = require("@nozbe/watermelondb");
17379
17471
  function folderToStored(folder) {
17380
17472
  return {
17381
17473
  uniqueId: folder.id,
@@ -17400,7 +17492,7 @@ async function createVaultFolderOp(ctx, opts) {
17400
17492
  return folderToStored(created);
17401
17493
  }
17402
17494
  async function getAllVaultFoldersOp(ctx) {
17403
- const results = await ctx.vaultFolderCollection.query(import_watermelondb30.Q.where("is_deleted", false), import_watermelondb30.Q.sortBy("created_at", import_watermelondb30.Q.desc)).fetch();
17495
+ 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
17496
  return results.map(folderToStored);
17405
17497
  }
17406
17498
  async function updateVaultFolderOp(ctx, id, opts) {
@@ -17409,7 +17501,7 @@ async function updateVaultFolderOp(ctx, id, opts) {
17409
17501
  if (record2.isDeleted) return null;
17410
17502
  const scopeChanged = opts.scope !== void 0 && opts.scope !== record2.scope;
17411
17503
  const updated = await ctx.database.write(async () => {
17412
- const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(import_watermelondb30.Q.where("folder_id", id), import_watermelondb30.Q.where("is_deleted", false)).fetch() : [];
17504
+ const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(import_watermelondb31.Q.where("folder_id", id), import_watermelondb31.Q.where("is_deleted", false)).fetch() : [];
17413
17505
  const updates = [];
17414
17506
  updates.push(
17415
17507
  record2.prepareUpdate((r) => {
@@ -17438,7 +17530,7 @@ async function deleteVaultFolderOp(ctx, id) {
17438
17530
  const record2 = await ctx.vaultFolderCollection.find(id);
17439
17531
  if (record2.isDeleted) return false;
17440
17532
  await ctx.database.write(async () => {
17441
- const memories = await ctx.vaultMemoryCollection.query(import_watermelondb30.Q.where("folder_id", id), import_watermelondb30.Q.where("is_deleted", false)).fetch();
17533
+ const memories = await ctx.vaultMemoryCollection.query(import_watermelondb31.Q.where("folder_id", id), import_watermelondb31.Q.where("is_deleted", false)).fetch();
17442
17534
  const preparedMemories = memories.map(
17443
17535
  (memory) => memory.prepareUpdate((r) => {
17444
17536
  r._setRaw("folder_id", null);
@@ -17509,7 +17601,7 @@ async function updateVaultFolderContextOp(ctx, id, context) {
17509
17601
  }
17510
17602
  }
17511
17603
  async function getVaultFolderMemoryCountOp(ctx, folderId) {
17512
- return await ctx.vaultMemoryCollection.query(import_watermelondb30.Q.where("folder_id", folderId), import_watermelondb30.Q.where("is_deleted", false)).fetchCount();
17604
+ return await ctx.vaultMemoryCollection.query(import_watermelondb31.Q.where("folder_id", folderId), import_watermelondb31.Q.where("is_deleted", false)).fetchCount();
17513
17605
  }
17514
17606
 
17515
17607
  // src/lib/db/vaultFolders/defaults.ts
@@ -17558,7 +17650,7 @@ init_logger();
17558
17650
  init_internalFlowMarker();
17559
17651
 
17560
17652
  // src/lib/memory/autoExtract.ts
17561
- var import_watermelondb31 = require("@nozbe/watermelondb");
17653
+ var import_watermelondb32 = require("@nozbe/watermelondb");
17562
17654
  init_logger();
17563
17655
  init_redactor();
17564
17656
 
@@ -20285,7 +20377,7 @@ async function assertMergeTargetGoneOrThrow(ctx, targetId) {
20285
20377
  // src/lib/memory/autoExtract.ts
20286
20378
  async function isMemoryTopicsUserManaged(ctx, memoryId) {
20287
20379
  try {
20288
- const rows = await ctx.database.get(VaultMemory.table).query(import_watermelondb31.Q.where("id", memoryId)).fetch();
20380
+ const rows = await ctx.database.get(VaultMemory.table).query(import_watermelondb32.Q.where("id", memoryId)).fetch();
20289
20381
  return rows[0]?.topicsUserManaged === true;
20290
20382
  } catch {
20291
20383
  return true;
@@ -22873,7 +22965,7 @@ function parseAnswer(body, base, parseSchema) {
22873
22965
  }
22874
22966
 
22875
22967
  // src/lib/memory/store/local.ts
22876
- var import_watermelondb32 = require("@nozbe/watermelondb");
22968
+ var import_watermelondb33 = require("@nozbe/watermelondb");
22877
22969
  init_logger();
22878
22970
 
22879
22971
  // src/lib/memory/topicExtract.ts
@@ -23156,8 +23248,8 @@ function createLocalMemoryStore(options) {
23156
23248
  writeOptions?.signal?.throwIfAborted();
23157
23249
  };
23158
23250
  const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
23159
- const ownedBy = userId !== void 0 ? [import_watermelondb32.Q.where("user_id", userId)] : [];
23160
- const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [import_watermelondb32.Q.or(import_watermelondb32.Q.where("user_id", userId), import_watermelondb32.Q.where("user_id", null))] : [import_watermelondb32.Q.where("user_id", userId)];
23251
+ const ownedBy = userId !== void 0 ? [import_watermelondb33.Q.where("user_id", userId)] : [];
23252
+ 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
23253
  const watchedColumns = [
23162
23254
  "content",
23163
23255
  "scope",
@@ -23202,7 +23294,7 @@ function createLocalMemoryStore(options) {
23202
23294
  list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
23203
23295
  get: (id) => getVaultMemoryOp(vaultCtx, id),
23204
23296
  listArchived: async () => {
23205
- const ids = await vaultCtx.vaultMemoryCollection.query(import_watermelondb32.Q.where("is_deleted", false), import_watermelondb32.Q.where("archived_at", import_watermelondb32.Q.notEq(null)), ...ownedBy).fetchIds();
23297
+ 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
23298
  if (ids.length === 0) return [];
23207
23299
  const rows = await getAllVaultMemoriesOp(vaultCtx, { memoryIds: ids, includeArchived: true });
23208
23300
  return rows.sort((a, b) => (b.archivedAt ?? 0) - (a.archivedAt ?? 0));
@@ -23218,7 +23310,7 @@ function createLocalMemoryStore(options) {
23218
23310
  set.add(String(link.memory_id));
23219
23311
  members.set(entityId, set);
23220
23312
  }
23221
- const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(import_watermelondb32.Q.where("id", import_watermelondb32.Q.oneOf([...members.keys()]))).unsafeFetchRaw() : [];
23313
+ 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
23314
  const byName = /* @__PURE__ */ new Map();
23223
23315
  for (const entity of entities) {
23224
23316
  const name = String(entity.canonical_name);
@@ -23268,7 +23360,7 @@ function createLocalMemoryStore(options) {
23268
23360
  setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
23269
23361
  addTopics: (memoryId, topics, writeOptions) => database.write(async (writer) => {
23270
23362
  await assertWrite(writeOptions);
23271
- const owned = await vaultCtx.vaultMemoryCollection.query(import_watermelondb32.Q.where("id", memoryId), import_watermelondb32.Q.where("is_deleted", false), ...ownedBy).fetchCount();
23363
+ const owned = await vaultCtx.vaultMemoryCollection.query(import_watermelondb33.Q.where("id", memoryId), import_watermelondb33.Q.where("is_deleted", false), ...ownedBy).fetchCount();
23272
23364
  return owned > 0 ? writer.callWriter(
23273
23365
  () => linkMemoryEntitiesOp(
23274
23366
  {
@@ -23340,7 +23432,7 @@ function createLocalMemoryStore(options) {
23340
23432
  else onChange();
23341
23433
  };
23342
23434
  };
23343
- const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(import_watermelondb32.Q.where("is_deleted", false), ...ownedBy).observeWithColumns(
23435
+ const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(import_watermelondb33.Q.where("is_deleted", false), ...ownedBy).observeWithColumns(
23344
23436
  subscribeOptions?.embeddings ? [...watchedColumns, "embedding", "embedding_model"] : watchedColumns
23345
23437
  );
23346
23438
  const subscriptions = [memories.subscribe(afterFirst())];
@@ -26407,7 +26499,7 @@ async function assembleMemoryContext(options) {
26407
26499
  }
26408
26500
 
26409
26501
  // src/lib/memory/durableExtraction.ts
26410
- var import_watermelondb33 = require("@nozbe/watermelondb");
26502
+ var import_watermelondb34 = require("@nozbe/watermelondb");
26411
26503
  var MAX_JOBS_PER_PASS = 3;
26412
26504
  var MAX_ATTEMPTS = 3;
26413
26505
  var MAX_FAILED_SESSIONS = 3;
@@ -26578,7 +26670,7 @@ function createDurableAutoExtractor(options) {
26578
26670
  const source = options.messageSource?.(conversationId);
26579
26671
  if (source)
26580
26672
  return await fromSource(source.status(conversationId)) === "ready" && (await loadFromSource(source, conversationId, ids)).every(Boolean);
26581
- return await storage.conversationsCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId), import_watermelondb33.Q.where("is_deleted", false)).fetchCount() > 0 && await storage.messagesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId), import_watermelondb33.Q.where("id", import_watermelondb33.Q.oneOf(ids))).fetchCount() === ids.length;
26673
+ 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
26674
  }
26583
26675
  function schedule(delay) {
26584
26676
  if (disposed) return;
@@ -26752,7 +26844,7 @@ function createDurableAutoExtractor(options) {
26752
26844
  let sourceWaiting = false;
26753
26845
  try {
26754
26846
  await writes;
26755
- const pending = await jobs.query(import_watermelondb33.Q.where("owner_key", owner), import_watermelondb33.Q.where("message_ids", import_watermelondb33.Q.notEq("[]"))).fetch();
26847
+ const pending = await jobs.query(import_watermelondb34.Q.where("owner_key", owner), import_watermelondb34.Q.where("message_ids", import_watermelondb34.Q.notEq("[]"))).fetch();
26756
26848
  storeFailures = 0;
26757
26849
  let processed = 0;
26758
26850
  for (const job of pending) {
@@ -26784,7 +26876,7 @@ function createDurableAutoExtractor(options) {
26784
26876
  let ids = [];
26785
26877
  let loaded = [];
26786
26878
  try {
26787
- const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId), import_watermelondb33.Q.where("is_deleted", false)).fetchCount() > 0;
26879
+ 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
26880
  if (!present) {
26789
26881
  await database.write(() => job.destroyPermanently());
26790
26882
  continue;
@@ -26952,7 +27044,7 @@ function createDurableAutoExtractor(options) {
26952
27044
  const scope = currentScope();
26953
27045
  writes = writes.then(
26954
27046
  () => database.write(async () => {
26955
- const existing = await jobs.query(import_watermelondb33.Q.where("owner_key", owner), import_watermelondb33.Q.where("conversation_id", conversationId)).fetch();
27047
+ const existing = await jobs.query(import_watermelondb34.Q.where("owner_key", owner), import_watermelondb34.Q.where("conversation_id", conversationId)).fetch();
26956
27048
  const job = existing.find(
26957
27049
  (candidate) => candidate._getRaw("scope") === scope && (candidate._getRaw("folder_id") ?? null) === folderId
26958
27050
  );
@@ -26965,8 +27057,8 @@ function createDurableAutoExtractor(options) {
26965
27057
  if (watermarks.length) {
26966
27058
  const misplaced = new Set(
26967
27059
  await storage.messagesCollection.query(
26968
- import_watermelondb33.Q.where("id", import_watermelondb33.Q.oneOf(watermarks)),
26969
- import_watermelondb33.Q.where("conversation_id", import_watermelondb33.Q.notEq(conversationId))
27060
+ import_watermelondb34.Q.where("id", import_watermelondb34.Q.oneOf(watermarks)),
27061
+ import_watermelondb34.Q.where("conversation_id", import_watermelondb34.Q.notEq(conversationId))
26970
27062
  ).fetchIds()
26971
27063
  );
26972
27064
  for (const prior of existing)
@@ -26976,7 +27068,7 @@ function createDurableAutoExtractor(options) {
26976
27068
  r._setRaw("watermark_seq", null);
26977
27069
  });
26978
27070
  }
26979
- const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(import_watermelondb33.Q.where("id", import_watermelondb33.Q.oneOf(ids))).fetch();
27071
+ const rows = fromSourceConversation ? [] : await storage.messagesCollection.query(import_watermelondb34.Q.where("id", import_watermelondb34.Q.oneOf(ids))).fetch();
26980
27072
  const foreignRows = new Set(
26981
27073
  rows.filter((row) => row._getRaw("conversation_id") !== conversationId).map((row) => row.id)
26982
27074
  );
@@ -31669,10 +31761,10 @@ var UNREVISIONED_COLUMNS = /* @__PURE__ */ new Set([
31669
31761
  ]);
31670
31762
  async function getBackupRevision(database, conversationId) {
31671
31763
  const serialized = await database.read(async () => {
31672
- const { Q: Q20 } = await import("@nozbe/watermelondb");
31764
+ const { Q: Q21 } = await import("@nozbe/watermelondb");
31673
31765
  const tables = await Promise.all(
31674
31766
  ["conversations", "history"].map(
31675
- (table) => database.get(table).query(Q20.where("conversation_id", conversationId), Q20.sortBy("id", Q20.asc)).unsafeFetchRaw()
31767
+ (table) => database.get(table).query(Q21.where("conversation_id", conversationId), Q21.sortBy("id", Q21.asc)).unsafeFetchRaw()
31676
31768
  )
31677
31769
  );
31678
31770
  return JSON.stringify(
@@ -31715,9 +31807,9 @@ async function pushConversationToICloud(database, conversationId, userAddress, d
31715
31807
  }
31716
31808
  async function performICloudExport(database, userAddress, deps, onProgress) {
31717
31809
  await deps.requestEncryptionKey(userAddress);
31718
- const { Q: Q20 } = await import("@nozbe/watermelondb");
31810
+ const { Q: Q21 } = await import("@nozbe/watermelondb");
31719
31811
  const conversationsCollection = database.get("conversations");
31720
- const records = await conversationsCollection.query(Q20.where("is_deleted", false)).fetch();
31812
+ const records = await conversationsCollection.query(Q21.where("is_deleted", false)).fetch();
31721
31813
  const conversations = records.map(conversationToStoredRaw);
31722
31814
  const total = conversations.length;
31723
31815
  if (total === 0) {
@@ -33469,6 +33561,8 @@ function useChatStorage(options) {
33469
33561
  embeddedWalletSigner
33470
33562
  ]
33471
33563
  );
33564
+ const storageCtxRef = (0, import_react6.useRef)(storageCtx);
33565
+ storageCtxRef.current = storageCtx;
33472
33566
  const mediaCtx = (0, import_react6.useMemo)(
33473
33567
  () => ({
33474
33568
  database,
@@ -33605,14 +33699,6 @@ function useChatStorage(options) {
33605
33699
  refreshQueueStatus();
33606
33700
  return queueManager.onQueueChange(walletAddress, refreshQueueStatus);
33607
33701
  }, [walletAddress, refreshQueueStatus]);
33608
- (0, import_react6.useEffect)(() => {
33609
- if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
33610
- return onKeyAvailable(walletAddress, () => {
33611
- flushQueue().catch((err) => {
33612
- getLogger().warn("[useChatStorage] Auto-flush failed:", err);
33613
- });
33614
- });
33615
- }, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
33616
33702
  (0, import_react6.useEffect)(() => {
33617
33703
  if (!getWalletAddress || walletAddress) return;
33618
33704
  const poller = new WalletPoller();
@@ -33636,34 +33722,49 @@ function useChatStorage(options) {
33636
33722
  pendingOpsRef.current = [];
33637
33723
  refreshQueueStatus();
33638
33724
  }, [walletAddress, enableQueue, refreshQueueStatus]);
33725
+ (0, import_react6.useEffect)(() => {
33726
+ if (!walletAddress || !enableQueue || !autoFlushOnKeyAvailable || !signMessage) return;
33727
+ return onKeyAvailable(walletAddress, () => {
33728
+ flushQueue().catch((err) => {
33729
+ getLogger().warn("[useChatStorage] Auto-flush failed:", err);
33730
+ });
33731
+ });
33732
+ }, [walletAddress, enableQueue, autoFlushOnKeyAvailable, signMessage, flushQueue]);
33639
33733
  const writeOrQueue = (0, import_react6.useCallback)(
33640
33734
  async (opType, payload, directWrite, makeSynthetic, dependencies = []) => {
33641
- if (isEncryptionReady()) {
33642
- const result2 = await directWrite();
33735
+ const currentStorageCtx = storageCtx.walletAddress ? storageCtx : storageCtxRef.current;
33736
+ const currentWalletAddress = currentStorageCtx.walletAddress;
33737
+ if (enableQueue && signMessage && !currentWalletAddress && getWalletAddress) {
33738
+ pendingOpsRef.current.push({ type: opType, payload, dependencies });
33739
+ return { result: makeSynthetic(), queued: true };
33740
+ }
33741
+ if (!currentWalletAddress || !currentStorageCtx.signMessage || hasEncryptionKey(currentWalletAddress)) {
33742
+ const result2 = await directWrite(currentStorageCtx);
33643
33743
  return { result: result2, queued: false };
33644
33744
  }
33645
33745
  if (!enableQueue) {
33646
- const result2 = await directWrite();
33746
+ const result2 = await directWrite(currentStorageCtx);
33647
33747
  return { result: result2, queued: false };
33648
33748
  }
33649
- if (!walletAddress && getWalletAddress) {
33650
- pendingOpsRef.current.push({ type: opType, payload, dependencies });
33651
- return { result: makeSynthetic(), queued: true };
33652
- }
33653
- if (walletAddress) {
33654
- const queueId = queueManager.queueOperation(walletAddress, opType, payload, dependencies);
33749
+ if (currentWalletAddress) {
33750
+ const queueId = queueManager.queueOperation(
33751
+ currentWalletAddress,
33752
+ opType,
33753
+ payload,
33754
+ dependencies
33755
+ );
33655
33756
  if (queueId === null) {
33656
33757
  getLogger().warn("[useChatStorage] Queue full, falling back to direct write");
33657
- const result2 = await directWrite();
33758
+ const result2 = await directWrite(currentStorageCtx);
33658
33759
  return { result: result2, queued: false };
33659
33760
  }
33660
- refreshQueueStatus();
33761
+ setQueueStatus(queueManager.getStatus(currentWalletAddress));
33661
33762
  return { result: makeSynthetic(), queued: true, queueId };
33662
33763
  }
33663
- const result = await directWrite();
33764
+ const result = await directWrite(currentStorageCtx);
33664
33765
  return { result, queued: false };
33665
33766
  },
33666
- [isEncryptionReady, enableQueue, walletAddress, getWalletAddress, refreshQueueStatus]
33767
+ [storageCtx, enableQueue, signMessage, getWalletAddress]
33667
33768
  );
33668
33769
  const embedMessageAsync = (0, import_react6.useCallback)(
33669
33770
  async (message, mask = maskForEmbedding) => {
@@ -34003,7 +34104,7 @@ function useChatStorage(options) {
34003
34104
  const { result, queued, queueId } = await writeOrQueue(
34004
34105
  "createConversation",
34005
34106
  conversationOpts,
34006
- () => createConversationOp(storageCtx, conversationOpts, defaultConversationTitle),
34107
+ (ctx) => createConversationOp(ctx, conversationOpts, defaultConversationTitle),
34007
34108
  () => makeSyntheticStoredConversation(conversationOpts, defaultConversationTitle)
34008
34109
  );
34009
34110
  if (queued) {
@@ -34015,7 +34116,7 @@ function useChatStorage(options) {
34015
34116
  setCurrentConversationId(result.conversationId);
34016
34117
  return result;
34017
34118
  },
34018
- [storageCtx, defaultConversationTitle, writeOrQueue]
34119
+ [defaultConversationTitle, writeOrQueue]
34019
34120
  );
34020
34121
  const getConversation = (0, import_react6.useCallback)(
34021
34122
  async (id) => {
@@ -34031,24 +34132,24 @@ function useChatStorage(options) {
34031
34132
  const { result } = await writeOrQueue(
34032
34133
  "updateConversationTitle",
34033
34134
  { conversationId: id, title },
34034
- () => updateConversationTitleOp(storageCtx, id, title),
34135
+ (ctx) => updateConversationTitleOp(ctx, id, title),
34035
34136
  () => true
34036
34137
  );
34037
34138
  return result;
34038
34139
  },
34039
- [storageCtx, writeOrQueue]
34140
+ [writeOrQueue]
34040
34141
  );
34041
34142
  const updateConversationPinned = (0, import_react6.useCallback)(
34042
34143
  async (id, pinned) => {
34043
34144
  const { result } = await writeOrQueue(
34044
34145
  "updateConversationPinned",
34045
34146
  { conversationId: id, pinned },
34046
- () => updateConversationPinnedOp(storageCtx, id, pinned),
34147
+ (ctx) => updateConversationPinnedOp(ctx, id, pinned),
34047
34148
  () => true
34048
34149
  );
34049
34150
  return result;
34050
34151
  },
34051
- [storageCtx, writeOrQueue]
34152
+ [writeOrQueue]
34052
34153
  );
34053
34154
  const deleteConversation = (0, import_react6.useCallback)(
34054
34155
  async (id) => {
@@ -34707,7 +34808,7 @@ function useChatStorage(options) {
34707
34808
  const userMsgResult = await writeOrQueue(
34708
34809
  "createMessage",
34709
34810
  userMsgOpts,
34710
- () => createMessageOp(storageCtx, userMsgOpts),
34811
+ (ctx) => createMessageOp(ctx, userMsgOpts),
34711
34812
  () => makeSyntheticStoredMessage(userMsgOpts),
34712
34813
  convId && syntheticConvQueueIdsRef.current.has(convId) ? [syntheticConvQueueIdsRef.current.get(convId)] : []
34713
34814
  );
@@ -35028,7 +35129,7 @@ function useChatStorage(options) {
35028
35129
  const assistantMsgResult = await writeOrQueue(
35029
35130
  "createMessage",
35030
35131
  assistantMsgOpts,
35031
- () => createMessageOp(storageCtx, assistantMsgOpts),
35132
+ (ctx) => createMessageOp(ctx, assistantMsgOpts),
35032
35133
  () => makeSyntheticStoredMessage(assistantMsgOpts),
35033
35134
  userMsgQueueId ? [userMsgQueueId] : []
35034
35135
  );
@@ -35079,7 +35180,7 @@ function useChatStorage(options) {
35079
35180
  const toolResultsWrite = await writeOrQueue(
35080
35181
  "createMessage",
35081
35182
  toolResultsOpts,
35082
- () => createMessageOp(storageCtx, toolResultsOpts),
35183
+ (ctx) => createMessageOp(ctx, toolResultsOpts),
35083
35184
  () => makeSyntheticStoredMessage(toolResultsOpts),
35084
35185
  assistantMsgQueueId ? [assistantMsgQueueId] : []
35085
35186
  );
@@ -35438,7 +35539,7 @@ function useExportPdf() {
35438
35539
  }
35439
35540
 
35440
35541
  // src/react/useFiles.ts
35441
- var import_watermelondb34 = require("@nozbe/watermelondb");
35542
+ var import_watermelondb35 = require("@nozbe/watermelondb");
35442
35543
  var import_react10 = require("react");
35443
35544
  init_logger();
35444
35545
  function useFiles(options) {
@@ -35457,7 +35558,7 @@ function useFiles(options) {
35457
35558
  setIsLoading(true);
35458
35559
  try {
35459
35560
  const coll = database.get("media");
35460
- await coll.query(import_watermelondb34.Q.take(1)).fetch();
35561
+ await coll.query(import_watermelondb35.Q.take(1)).fetch();
35461
35562
  setMediaCollection(coll);
35462
35563
  setIsReady(true);
35463
35564
  } catch (error) {
@@ -36679,7 +36780,7 @@ function usePhoneCalls(options = {}) {
36679
36780
  }
36680
36781
 
36681
36782
  // src/react/useProjects.ts
36682
- var import_watermelondb35 = require("@nozbe/watermelondb");
36783
+ var import_watermelondb36 = require("@nozbe/watermelondb");
36683
36784
  var import_react17 = require("react");
36684
36785
  init_logger();
36685
36786
  function useProjects(options) {
@@ -36702,7 +36803,7 @@ function useProjects(options) {
36702
36803
  conversations: convColl?.table
36703
36804
  });
36704
36805
  getLogger().debug("[useProjects] Running test query on projects table...");
36705
- const testResult = await projColl.query(import_watermelondb35.Q.take(1)).fetch();
36806
+ const testResult = await projColl.query(import_watermelondb36.Q.take(1)).fetch();
36706
36807
  getLogger().debug(
36707
36808
  "[useProjects] Test query succeeded, found",
36708
36809
  testResult.length,
@@ -36789,7 +36890,7 @@ function useProjects(options) {
36789
36890
  if (!projectsCollection) {
36790
36891
  return;
36791
36892
  }
36792
- const subscription = projectsCollection.query(import_watermelondb35.Q.where("is_deleted", false)).observe().subscribe((records) => {
36893
+ const subscription = projectsCollection.query(import_watermelondb36.Q.where("is_deleted", false)).observe().subscribe((records) => {
36793
36894
  setProjects(records.map(projectToStored));
36794
36895
  });
36795
36896
  return () => subscription.unsubscribe();
@@ -36911,7 +37012,7 @@ function useProjects(options) {
36911
37012
  var import_react18 = require("react");
36912
37013
 
36913
37014
  // src/react/userSettingsStore.ts
36914
- var import_watermelondb36 = require("@nozbe/watermelondb");
37015
+ var import_watermelondb37 = require("@nozbe/watermelondb");
36915
37016
  var EMPTY_SNAPSHOT = Object.freeze({
36916
37017
  modelPreference: null,
36917
37018
  userPreference: null,
@@ -36963,7 +37064,7 @@ async function startLoad(entry, walletAddress) {
36963
37064
  }
36964
37065
  function startObserve(entry, walletAddress) {
36965
37066
  let isInitialEmission = true;
36966
- entry.observeSub = entry.storageCtx.userPreferencesCollection.query(import_watermelondb36.Q.where("wallet_address", walletAddress)).observeWithColumns([
37067
+ entry.observeSub = entry.storageCtx.userPreferencesCollection.query(import_watermelondb37.Q.where("wallet_address", walletAddress)).observeWithColumns([
36967
37068
  "nickname",
36968
37069
  "occupation",
36969
37070
  "description",