@anuma/sdk 10.0.1 → 10.0.3

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.
@@ -15136,7 +15136,7 @@ ${line}`;
15136
15136
  }
15137
15137
 
15138
15138
  // src/lib/db/chat/operations.ts
15139
- var import_watermelondb2 = __toESM(require_watermelondb());
15139
+ var import_watermelondb3 = __toESM(require_watermelondb());
15140
15140
  import { v7 as uuidv72 } from "uuid";
15141
15141
 
15142
15142
  // src/react/useEncryption.ts
@@ -16410,6 +16410,160 @@ async function assembleDecryptedMessage(message, address) {
16410
16410
  return result;
16411
16411
  }
16412
16412
 
16413
+ // src/lib/db/chat/models.ts
16414
+ var import_watermelondb2 = __toESM(require_watermelondb());
16415
+ var import_decorators = __toESM(require_decorators());
16416
+ var Message = class extends import_watermelondb2.Model {
16417
+ };
16418
+ Message.table = "history";
16419
+ Message.associations = {
16420
+ conversations: { type: "belongs_to", key: "conversation_id" },
16421
+ media: { type: "has_many", foreignKey: "message_id" }
16422
+ };
16423
+ __decorateClass([
16424
+ (0, import_decorators.field)("message_id")
16425
+ ], Message.prototype, "messageId", 2);
16426
+ __decorateClass([
16427
+ (0, import_decorators.text)("conversation_id")
16428
+ ], Message.prototype, "conversationId", 2);
16429
+ __decorateClass([
16430
+ (0, import_decorators.text)("role")
16431
+ ], Message.prototype, "role", 2);
16432
+ __decorateClass([
16433
+ (0, import_decorators.text)("content")
16434
+ ], Message.prototype, "content", 2);
16435
+ __decorateClass([
16436
+ (0, import_decorators.text)("model")
16437
+ ], Message.prototype, "model", 2);
16438
+ __decorateClass([
16439
+ (0, import_decorators.text)("image_model")
16440
+ ], Message.prototype, "imageModel", 2);
16441
+ __decorateClass([
16442
+ (0, import_decorators.json)("files", (raw) => raw)
16443
+ ], Message.prototype, "files", 2);
16444
+ __decorateClass([
16445
+ (0, import_decorators.json)("file_ids", (raw) => raw)
16446
+ ], Message.prototype, "fileIds", 2);
16447
+ __decorateClass([
16448
+ (0, import_decorators.date)("created_at")
16449
+ ], Message.prototype, "createdAt", 2);
16450
+ __decorateClass([
16451
+ (0, import_decorators.date)("updated_at")
16452
+ ], Message.prototype, "updatedAt", 2);
16453
+ __decorateClass([
16454
+ (0, import_decorators.json)("vector", (raw) => raw)
16455
+ ], Message.prototype, "vector", 2);
16456
+ __decorateClass([
16457
+ (0, import_decorators.text)("embedding_model")
16458
+ ], Message.prototype, "embeddingModel", 2);
16459
+ __decorateClass([
16460
+ (0, import_decorators.json)("chunks", (raw) => raw)
16461
+ ], Message.prototype, "chunks", 2);
16462
+ __decorateClass([
16463
+ (0, import_decorators.json)("usage", (raw) => raw)
16464
+ ], Message.prototype, "usage", 2);
16465
+ __decorateClass([
16466
+ (0, import_decorators.json)("sources", (raw) => raw)
16467
+ ], Message.prototype, "sources", 2);
16468
+ __decorateClass([
16469
+ (0, import_decorators.field)("response_duration")
16470
+ ], Message.prototype, "responseDuration", 2);
16471
+ __decorateClass([
16472
+ (0, import_decorators.field)("was_stopped")
16473
+ ], Message.prototype, "wasStopped", 2);
16474
+ __decorateClass([
16475
+ (0, import_decorators.text)("error")
16476
+ ], Message.prototype, "error", 2);
16477
+ __decorateClass([
16478
+ (0, import_decorators.json)("thought_process", (raw) => raw)
16479
+ ], Message.prototype, "thoughtProcess", 2);
16480
+ __decorateClass([
16481
+ (0, import_decorators.text)("thinking")
16482
+ ], Message.prototype, "thinking", 2);
16483
+ __decorateClass([
16484
+ (0, import_decorators.text)("parent_message_id")
16485
+ ], Message.prototype, "parentMessageId", 2);
16486
+ __decorateClass([
16487
+ (0, import_decorators.text)("feedback")
16488
+ ], Message.prototype, "feedback", 2);
16489
+ __decorateClass([
16490
+ (0, import_decorators.json)("tool_call_events", (raw) => raw)
16491
+ ], Message.prototype, "toolCallEvents", 2);
16492
+ __decorateClass([
16493
+ (0, import_decorators.text)("origin")
16494
+ ], Message.prototype, "origin", 2);
16495
+ var Conversation = class extends import_watermelondb2.Model {
16496
+ };
16497
+ Conversation.table = "conversations";
16498
+ Conversation.associations = {
16499
+ history: { type: "has_many", foreignKey: "conversation_id" },
16500
+ projects: { type: "belongs_to", key: "project_id" }
16501
+ };
16502
+ __decorateClass([
16503
+ (0, import_decorators.text)("conversation_id")
16504
+ ], Conversation.prototype, "conversationId", 2);
16505
+ __decorateClass([
16506
+ (0, import_decorators.text)("title")
16507
+ ], Conversation.prototype, "title", 2);
16508
+ __decorateClass([
16509
+ (0, import_decorators.text)("project_id")
16510
+ ], Conversation.prototype, "projectId", 2);
16511
+ __decorateClass([
16512
+ (0, import_decorators.date)("created_at")
16513
+ ], Conversation.prototype, "createdAt", 2);
16514
+ __decorateClass([
16515
+ (0, import_decorators.date)("updated_at")
16516
+ ], Conversation.prototype, "updatedAt", 2);
16517
+ __decorateClass([
16518
+ (0, import_decorators.field)("is_deleted")
16519
+ ], Conversation.prototype, "isDeleted", 2);
16520
+ __decorateClass([
16521
+ (0, import_decorators.date)("pinned_at")
16522
+ ], Conversation.prototype, "pinnedAt", 2);
16523
+ var ConversationSummary = class extends import_watermelondb2.Model {
16524
+ };
16525
+ ConversationSummary.table = "conversation_summaries";
16526
+ ConversationSummary.associations = {
16527
+ conversations: { type: "belongs_to", key: "conversation_id" }
16528
+ };
16529
+ __decorateClass([
16530
+ (0, import_decorators.text)("conversation_id")
16531
+ ], ConversationSummary.prototype, "conversationId", 2);
16532
+ __decorateClass([
16533
+ (0, import_decorators.text)("summary")
16534
+ ], ConversationSummary.prototype, "summary", 2);
16535
+ __decorateClass([
16536
+ (0, import_decorators.text)("summarized_up_to")
16537
+ ], ConversationSummary.prototype, "summarizedUpTo", 2);
16538
+ __decorateClass([
16539
+ (0, import_decorators.field)("token_count")
16540
+ ], ConversationSummary.prototype, "tokenCount", 2);
16541
+ __decorateClass([
16542
+ (0, import_decorators.date)("created_at")
16543
+ ], ConversationSummary.prototype, "createdAt", 2);
16544
+ __decorateClass([
16545
+ (0, import_decorators.date)("updated_at")
16546
+ ], ConversationSummary.prototype, "updatedAt", 2);
16547
+
16548
+ // src/lib/db/chat/summaryRevision.ts
16549
+ var conversationRevisions = /* @__PURE__ */ new WeakMap();
16550
+ function getConversationRevision(database, conversationId) {
16551
+ return conversationRevisions.get(database)?.get(conversationId) ?? 0;
16552
+ }
16553
+ function advanceConversationRevision(database, conversationId) {
16554
+ let revisions = conversationRevisions.get(database);
16555
+ if (!revisions) {
16556
+ revisions = /* @__PURE__ */ new Map();
16557
+ conversationRevisions.set(database, revisions);
16558
+ }
16559
+ revisions.set(conversationId, getConversationRevision(database, conversationId) + 1);
16560
+ }
16561
+ function assertConversationRevision(database, conversationId, revision) {
16562
+ if (getConversationRevision(database, conversationId) !== revision) {
16563
+ throw new Error("The conversation changed during summarization. Retry the request.");
16564
+ }
16565
+ }
16566
+
16413
16567
  // src/lib/db/chat/types.ts
16414
16568
  import { v7 as uuidv7 } from "uuid";
16415
16569
 
@@ -16652,7 +16806,7 @@ async function createConversationOp(ctx, opts, defaultTitle = "New Conversation"
16652
16806
  );
16653
16807
  }
16654
16808
  async function getConversationOp(ctx, id) {
16655
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
16809
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
16656
16810
  return results.length > 0 ? await conversationToStored(
16657
16811
  results[0],
16658
16812
  ctx.walletAddress,
@@ -16661,7 +16815,7 @@ async function getConversationOp(ctx, id) {
16661
16815
  ) : null;
16662
16816
  }
16663
16817
  async function getConversationsOp(ctx) {
16664
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false), import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)).unsafeFetchRaw();
16818
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false), import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).unsafeFetchRaw();
16665
16819
  return Promise.all(
16666
16820
  results.map(
16667
16821
  (raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
@@ -16682,33 +16836,33 @@ function conversationRawToLazyStored(raw) {
16682
16836
  };
16683
16837
  }
16684
16838
  async function getConversationsLazyOp(ctx) {
16685
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false), import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)).unsafeFetchRaw();
16839
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false), import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).unsafeFetchRaw();
16686
16840
  return results.map(conversationRawToLazyStored);
16687
16841
  }
16688
16842
  async function getConversationsPageOp(ctx, options) {
16689
16843
  const limit = Math.floor(options?.limit ?? 200);
16690
16844
  if (!Number.isFinite(limit) || limit < 1) return [];
16691
16845
  const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
16692
- const clauses = [import_watermelondb2.Q.where("is_deleted", false)];
16846
+ const clauses = [import_watermelondb3.Q.where("is_deleted", false)];
16693
16847
  if (options?.before !== void 0) {
16694
16848
  clauses.push(
16695
- 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))
16849
+ 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))
16696
16850
  );
16697
16851
  }
16698
- 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();
16852
+ 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();
16699
16853
  const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
16700
16854
  return results.slice(0, limit).map(conversationRawToLazyStored);
16701
16855
  }
16702
16856
  async function getConversationsByProjectLazyOp(ctx, projectId) {
16703
16857
  const results = await ctx.conversationsCollection.query(
16704
- import_watermelondb2.Q.where("project_id", projectId === null ? "" : projectId),
16705
- import_watermelondb2.Q.where("is_deleted", false),
16706
- import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)
16858
+ import_watermelondb3.Q.where("project_id", projectId === null ? "" : projectId),
16859
+ import_watermelondb3.Q.where("is_deleted", false),
16860
+ import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)
16707
16861
  ).unsafeFetchRaw();
16708
16862
  return results.map(conversationRawToLazyStored);
16709
16863
  }
16710
16864
  async function updateConversationTitleOp(ctx, id, title) {
16711
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
16865
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
16712
16866
  if (results.length > 0) {
16713
16867
  const encryptedOpts = ctx.walletAddress && ctx.signMessage ? await encryptConversationFields(
16714
16868
  { title },
@@ -16727,13 +16881,13 @@ async function updateConversationTitleOp(ctx, id, title) {
16727
16881
  return false;
16728
16882
  }
16729
16883
  async function deleteConversationOp(ctx, id) {
16730
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
16884
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
16731
16885
  if (results.length > 0) {
16732
16886
  await ctx.database.write(async () => {
16733
16887
  await results[0].update((conv) => {
16734
16888
  conv._setRaw("is_deleted", true);
16735
16889
  });
16736
- const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb2.Q.where("conversation_id", id)).fetch() : [];
16890
+ const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", id)).fetch() : [];
16737
16891
  for (const job of jobs) await job.destroyPermanently();
16738
16892
  });
16739
16893
  return true;
@@ -16741,7 +16895,7 @@ async function deleteConversationOp(ctx, id) {
16741
16895
  return false;
16742
16896
  }
16743
16897
  async function updateConversationProjectOp(ctx, id, projectId) {
16744
- const results = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", id), import_watermelondb2.Q.where("is_deleted", false)).fetch();
16898
+ const results = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", id), import_watermelondb3.Q.where("is_deleted", false)).fetch();
16745
16899
  if (results.length > 0) {
16746
16900
  await ctx.database.write(async () => {
16747
16901
  await results[0].update((conv) => {
@@ -16754,9 +16908,9 @@ async function updateConversationProjectOp(ctx, id, projectId) {
16754
16908
  }
16755
16909
  async function getConversationsByProjectOp(ctx, projectId) {
16756
16910
  const results = await ctx.conversationsCollection.query(
16757
- import_watermelondb2.Q.where("project_id", projectId === null ? "" : projectId),
16758
- import_watermelondb2.Q.where("is_deleted", false),
16759
- import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)
16911
+ import_watermelondb3.Q.where("project_id", projectId === null ? "" : projectId),
16912
+ import_watermelondb3.Q.where("is_deleted", false),
16913
+ import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)
16760
16914
  ).unsafeFetchRaw();
16761
16915
  return Promise.all(
16762
16916
  results.map(
@@ -16765,7 +16919,7 @@ async function getConversationsByProjectOp(ctx, projectId) {
16765
16919
  );
16766
16920
  }
16767
16921
  async function getMessagesOp(ctx, convId, opts) {
16768
- const fetched = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId), import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.asc)).unsafeFetchRaw();
16922
+ const fetched = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId), import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.asc)).unsafeFetchRaw();
16769
16923
  const results = opts?.rawFilter ? fetched.filter(opts.rawFilter) : fetched;
16770
16924
  return Promise.all(
16771
16925
  results.map(
@@ -16773,10 +16927,22 @@ async function getMessagesOp(ctx, convId, opts) {
16773
16927
  )
16774
16928
  );
16775
16929
  }
16930
+ async function invalidateConversationSummary(ctx, conversationId, changedMessageId) {
16931
+ if (!ctx.database.schema?.tables[ConversationSummary.table]) return;
16932
+ const summaries = await ctx.database.get(ConversationSummary.table).query(import_watermelondb3.Q.where("conversation_id", conversationId)).fetch();
16933
+ for (const summary of summaries) {
16934
+ if (changedMessageId !== void 0) {
16935
+ const [boundary] = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", summary.summarizedUpTo), import_watermelondb3.Q.where("conversation_id", conversationId)).fetch();
16936
+ if (boundary && changedMessageId > boundary.messageId) continue;
16937
+ }
16938
+ await summary.destroyPermanently();
16939
+ }
16940
+ }
16776
16941
  async function clearMessagesOp(ctx, convId) {
16777
16942
  await ctx.database.write(async () => {
16778
- const messages = await ctx.messagesCollection.query(import_watermelondb2.Q.where("conversation_id", convId)).fetch();
16779
- const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb2.Q.where("conversation_id", convId)).fetch() : [];
16943
+ await invalidateConversationSummary(ctx, convId);
16944
+ const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("conversation_id", convId)).fetch();
16945
+ const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", convId)).fetch() : [];
16780
16946
  for (const job of jobs) {
16781
16947
  await job.update((row) => {
16782
16948
  row._setRaw("message_ids", "[]");
@@ -16786,11 +16952,12 @@ async function clearMessagesOp(ctx, convId) {
16786
16952
  }
16787
16953
  for (const message of messages) {
16788
16954
  await message.update((msg) => {
16789
- msg._setRaw("file_ids", null);
16955
+ if (ctx.messagesCollection.schema.columns.file_ids) msg._setRaw("file_ids", null);
16790
16956
  msg._setRaw("files", null);
16791
16957
  });
16792
16958
  await message.destroyPermanently();
16793
16959
  }
16960
+ advanceConversationRevision(ctx.database, convId);
16794
16961
  });
16795
16962
  }
16796
16963
  async function deleteMessageOp(ctx, uniqueId) {
@@ -16801,7 +16968,8 @@ async function deleteMessageOp(ctx, uniqueId) {
16801
16968
  return null;
16802
16969
  }
16803
16970
  await ctx.database.write(async () => {
16804
- const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb2.Q.where("conversation_id", message.conversationId)).fetch() : [];
16971
+ await invalidateConversationSummary(ctx, message.conversationId, message.messageId);
16972
+ const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(import_watermelondb3.Q.where("conversation_id", message.conversationId)).fetch() : [];
16805
16973
  for (const job of jobs) {
16806
16974
  const ids = JSON.parse(String(job._getRaw("message_ids")));
16807
16975
  await job.update((row) => {
@@ -16810,10 +16978,11 @@ async function deleteMessageOp(ctx, uniqueId) {
16810
16978
  });
16811
16979
  }
16812
16980
  await message.update((msg) => {
16813
- msg._setRaw("file_ids", null);
16981
+ if (ctx.messagesCollection.schema.columns.file_ids) msg._setRaw("file_ids", null);
16814
16982
  msg._setRaw("files", null);
16815
16983
  });
16816
16984
  await message.destroyPermanently();
16985
+ advanceConversationRevision(ctx.database, message.conversationId);
16817
16986
  });
16818
16987
  return uniqueId;
16819
16988
  }
@@ -16874,9 +17043,9 @@ async function createMessageOp(ctx, opts) {
16874
17043
  }
16875
17044
  }
16876
17045
  const newest = await ctx.messagesCollection.query(
16877
- import_watermelondb2.Q.where("conversation_id", opts.conversationId),
16878
- import_watermelondb2.Q.sortBy("message_id", import_watermelondb2.Q.desc),
16879
- import_watermelondb2.Q.take(1)
17046
+ import_watermelondb3.Q.where("conversation_id", opts.conversationId),
17047
+ import_watermelondb3.Q.sortBy("message_id", import_watermelondb3.Q.desc),
17048
+ import_watermelondb3.Q.take(1)
16880
17049
  ).fetch();
16881
17050
  const messageId = (newest[0]?.messageId ?? 0) + 1;
16882
17051
  const encryptedOpts = await encryptMessageOptsIfNeeded(ctx, opts);
@@ -16890,7 +17059,7 @@ async function createMessageOp(ctx, opts) {
16890
17059
  return messageToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
16891
17060
  }
16892
17061
  async function upsertMessageOp(ctx, opts) {
16893
- const results = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", opts.uniqueId)).fetch();
17062
+ const results = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", opts.uniqueId)).fetch();
16894
17063
  const existing = results.length > 0 ? results[0] : null;
16895
17064
  if (!existing) {
16896
17065
  return createMessageOp(ctx, opts);
@@ -16998,13 +17167,13 @@ async function decryptMessageEmbeddingFields(raw, walletAddress) {
16998
17167
  async function sealLegacyMessageEmbeddingsOp(ctx) {
16999
17168
  if (!ctx.walletAddress) return 0;
17000
17169
  const candidateIds = await ctx.messagesCollection.query(
17001
- import_watermelondb2.Q.where("content", import_watermelondb2.Q.like("enc:%")),
17002
- import_watermelondb2.Q.or(
17170
+ import_watermelondb3.Q.where("content", import_watermelondb3.Q.like("enc:%")),
17171
+ import_watermelondb3.Q.or(
17003
17172
  ...["vector", "chunks"].map(
17004
- (column) => import_watermelondb2.Q.and(
17005
- import_watermelondb2.Q.where(column, import_watermelondb2.Q.notEq(null)),
17006
- import_watermelondb2.Q.where(column, import_watermelondb2.Q.notEq("")),
17007
- import_watermelondb2.Q.where(column, import_watermelondb2.Q.notLike("enc:%"))
17173
+ (column) => import_watermelondb3.Q.and(
17174
+ import_watermelondb3.Q.where(column, import_watermelondb3.Q.notEq(null)),
17175
+ import_watermelondb3.Q.where(column, import_watermelondb3.Q.notEq("")),
17176
+ import_watermelondb3.Q.where(column, import_watermelondb3.Q.notLike("enc:%"))
17008
17177
  )
17009
17178
  )
17010
17179
  )
@@ -17014,7 +17183,7 @@ async function sealLegacyMessageEmbeddingsOp(ctx) {
17014
17183
  for (let start = 0; start < candidateIds.length; start += 50) {
17015
17184
  const pageIds = candidateIds.slice(start, start + 50);
17016
17185
  await ctx.database.write(async () => {
17017
- const pageMessages = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(pageIds))).fetch();
17186
+ const pageMessages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).fetch();
17018
17187
  for (const message of pageMessages) {
17019
17188
  if (!isEncrypted(message.content)) continue;
17020
17189
  const content = await decryptFieldDetailed(message.content, ctx.walletAddress);
@@ -17095,15 +17264,15 @@ function chunksWithoutText(raw) {
17095
17264
  });
17096
17265
  }
17097
17266
  async function stripLegacyChunkTextOp(ctx) {
17098
- const candidateIds = await ctx.messagesCollection.query(import_watermelondb2.Q.where("chunks", import_watermelondb2.Q.like(`%${import_watermelondb2.Q.sanitizeLikeString('"text":')}%`))).fetchIds();
17267
+ const candidateIds = await ctx.messagesCollection.query(import_watermelondb3.Q.where("chunks", import_watermelondb3.Q.like(`%${import_watermelondb3.Q.sanitizeLikeString('"text":')}%`))).fetchIds();
17099
17268
  let stripped = 0;
17100
17269
  for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
17101
17270
  const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
17102
- const rows = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(pageIds))).unsafeFetchRaw();
17271
+ const rows = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).unsafeFetchRaw();
17103
17272
  const changedIds = rows.filter((row) => chunksWithoutText(row.chunks) !== null).map((row) => String(row.id));
17104
17273
  if (changedIds.length === 0) continue;
17105
17274
  await ctx.database.write(async () => {
17106
- const messages = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(changedIds))).fetch();
17275
+ const messages = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(changedIds))).fetch();
17107
17276
  const updates = messages.flatMap((message) => {
17108
17277
  const raw = message._raw;
17109
17278
  const chunks = chunksWithoutText(raw.chunks);
@@ -17150,13 +17319,13 @@ async function encryptToolCallEventsOp(ctx) {
17150
17319
  return 0;
17151
17320
  }
17152
17321
  const candidateIds = await ctx.messagesCollection.query(
17153
- import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notEq(null)),
17154
- import_watermelondb2.Q.where("tool_call_events", import_watermelondb2.Q.notIn(["", "[]"]))
17322
+ import_watermelondb3.Q.where("tool_call_events", import_watermelondb3.Q.notEq(null)),
17323
+ import_watermelondb3.Q.where("tool_call_events", import_watermelondb3.Q.notIn(["", "[]"]))
17155
17324
  ).fetchIds();
17156
17325
  let encrypted = 0;
17157
17326
  for (let start = 0; start < candidateIds.length; start += RAW_REPAIR_PAGE_SIZE) {
17158
17327
  const pageIds = candidateIds.slice(start, start + RAW_REPAIR_PAGE_SIZE);
17159
- const rows = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(pageIds))).unsafeFetchRaw();
17328
+ const rows = await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(pageIds))).unsafeFetchRaw();
17160
17329
  const repairs = /* @__PURE__ */ new Map();
17161
17330
  for (const row of rows) {
17162
17331
  const column = await encryptedToolCallEventsColumn(
@@ -17169,12 +17338,12 @@ async function encryptToolCallEventsOp(ctx) {
17169
17338
  }
17170
17339
  if (repairs.size === 0) continue;
17171
17340
  await ctx.database.write(async () => {
17172
- const messages = (await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf([...repairs.keys()]))).fetch()).filter(
17341
+ const messages = (await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf([...repairs.keys()]))).fetch()).filter(
17173
17342
  (message) => message._raw.tool_call_events === repairs.get(message.id)?.raw
17174
17343
  );
17175
17344
  if (messages.length === 0) return;
17176
17345
  const conversationIds = [...new Set(messages.map((message) => message.conversationId))];
17177
- const conversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("conversation_id", import_watermelondb2.Q.oneOf(conversationIds))).fetch();
17346
+ const conversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("conversation_id", import_watermelondb3.Q.oneOf(conversationIds))).fetch();
17178
17347
  await ctx.database.batch(
17179
17348
  ...messages.map(
17180
17349
  (message) => message.prepareUpdate((msg) => {
@@ -17201,7 +17370,7 @@ async function savedKeyOpensExistingData(ctx, address, signMessage, embeddedWall
17201
17370
  return refreshEncryptionKeyIfMatches(address, v2Probe, signMessage, embeddedWalletSigner);
17202
17371
  }
17203
17372
  async function findEncryptedContent(ctx, pattern) {
17204
- const [row] = await ctx.messagesCollection.query(import_watermelondb2.Q.where("content", import_watermelondb2.Q.like(pattern)), import_watermelondb2.Q.take(1)).unsafeFetchRaw();
17373
+ const [row] = await ctx.messagesCollection.query(import_watermelondb3.Q.where("content", import_watermelondb3.Q.like(pattern)), import_watermelondb3.Q.take(1)).unsafeFetchRaw();
17205
17374
  return row ? String(row.content) : null;
17206
17375
  }
17207
17376
  async function updateMessageErrorOp(ctx, uniqueId, error) {
@@ -17246,6 +17415,14 @@ async function _updateMessageOp(ctx, uniqueId, opts) {
17246
17415
  ctx.embeddedWalletSigner
17247
17416
  ) : opts;
17248
17417
  await ctx.database.write(async () => {
17418
+ let contentChanged = false;
17419
+ if (opts.content !== void 0) {
17420
+ const originalContent = ctx.walletAddress ? await decryptField(message.content, ctx.walletAddress) : message.content;
17421
+ contentChanged = opts.content !== originalContent;
17422
+ if (contentChanged) {
17423
+ await invalidateConversationSummary(ctx, message.conversationId, message.messageId);
17424
+ }
17425
+ }
17249
17426
  await message.update((msg) => {
17250
17427
  if (encryptedOpts.content !== void 0)
17251
17428
  msg._setRaw("content", encryptedOpts.content);
@@ -17290,6 +17467,7 @@ async function _updateMessageOp(ctx, uniqueId, opts) {
17290
17467
  msg._setRaw("tool_call_events", tceValue);
17291
17468
  }
17292
17469
  });
17470
+ if (contentChanged) advanceConversationRevision(ctx.database, message.conversationId);
17293
17471
  });
17294
17472
  return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
17295
17473
  }
@@ -17317,11 +17495,11 @@ async function readRawJsonField(raw, column, walletAddress) {
17317
17495
  }
17318
17496
  async function searchMessagesOp(ctx, queryVector, options) {
17319
17497
  const { limit = 10, minSimilarity = 0.5, conversationId } = options || {};
17320
- const activeConversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false)).fetch();
17498
+ const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
17321
17499
  const activeConversationIds = new Set(
17322
17500
  activeConversations.map((c) => String(c._getRaw("conversation_id")))
17323
17501
  );
17324
- const queryConditions = conversationId ? [import_watermelondb2.Q.where("conversation_id", conversationId)] : [];
17502
+ const queryConditions = conversationId ? [import_watermelondb3.Q.where("conversation_id", conversationId)] : [];
17325
17503
  const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
17326
17504
  const candidates = [];
17327
17505
  for (const message of messages) {
@@ -17360,7 +17538,7 @@ function toChunkCandidateKey(raw) {
17360
17538
  }
17361
17539
  async function fetchRowsByIds(ctx, ids) {
17362
17540
  if (ids.length === 0) return [];
17363
- return await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(ids))).unsafeFetchRaw();
17541
+ return await ctx.messagesCollection.query(import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))).unsafeFetchRaw();
17364
17542
  }
17365
17543
  async function projectedChunkRowSource(ctx, filter) {
17366
17544
  const clauses = [
@@ -17378,7 +17556,7 @@ async function projectedChunkRowSource(ctx, filter) {
17378
17556
  args.push(filter.excludeConversationId);
17379
17557
  }
17380
17558
  const keyRows = await ctx.messagesCollection.query(
17381
- import_watermelondb2.Q.unsafeSqlQuery(
17559
+ import_watermelondb3.Q.unsafeSqlQuery(
17382
17560
  `select "id", "conversation_id", "updated_at", "embedding_model" from "history" where ${clauses.join(" and ")}`,
17383
17561
  args
17384
17562
  )
@@ -17388,7 +17566,7 @@ async function projectedChunkRowSource(ctx, filter) {
17388
17566
  loadVectorRows: async (ids) => {
17389
17567
  if (ids.length === 0) return [];
17390
17568
  return await ctx.messagesCollection.query(
17391
- import_watermelondb2.Q.unsafeSqlQuery(
17569
+ import_watermelondb3.Q.unsafeSqlQuery(
17392
17570
  `select "id", "updated_at", "chunks", "vector" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
17393
17571
  ids
17394
17572
  )
@@ -17398,11 +17576,11 @@ async function projectedChunkRowSource(ctx, filter) {
17398
17576
  };
17399
17577
  }
17400
17578
  async function fullScanChunkRowSource(ctx, filter) {
17401
- const activeConversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false)).fetch();
17579
+ const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
17402
17580
  const activeConversationIds = new Set(
17403
17581
  activeConversations.map((c) => String(c._getRaw("conversation_id")))
17404
17582
  );
17405
- const queryConditions = filter.conversationId !== void 0 ? [import_watermelondb2.Q.where("conversation_id", filter.conversationId)] : [];
17583
+ const queryConditions = filter.conversationId !== void 0 ? [import_watermelondb3.Q.where("conversation_id", filter.conversationId)] : [];
17406
17584
  const rows = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
17407
17585
  const rowsById = /* @__PURE__ */ new Map();
17408
17586
  for (const row of rows) {
@@ -17609,12 +17787,12 @@ async function searchChunksOp(ctx, queryVector, options) {
17609
17787
  }
17610
17788
  async function getAllFilesOp(ctx, options) {
17611
17789
  const { conversationId, limit } = options || {};
17612
- const activeConversations = await ctx.conversationsCollection.query(import_watermelondb2.Q.where("is_deleted", false)).fetch();
17790
+ const activeConversations = await ctx.conversationsCollection.query(import_watermelondb3.Q.where("is_deleted", false)).fetch();
17613
17791
  const activeConversationIds = new Set(
17614
17792
  activeConversations.map((c) => String(c._getRaw("conversation_id")))
17615
17793
  );
17616
- const queryConditions = conversationId ? [import_watermelondb2.Q.where("conversation_id", conversationId)] : [];
17617
- const messages = await ctx.messagesCollection.query(...queryConditions, import_watermelondb2.Q.sortBy("created_at", import_watermelondb2.Q.desc)).fetch();
17794
+ const queryConditions = conversationId ? [import_watermelondb3.Q.where("conversation_id", conversationId)] : [];
17795
+ const messages = await ctx.messagesCollection.query(...queryConditions, import_watermelondb3.Q.sortBy("created_at", import_watermelondb3.Q.desc)).fetch();
17618
17796
  const filesWithContext = [];
17619
17797
  for (const message of messages) {
17620
17798
  const msgConvId = String(message._getRaw("conversation_id"));
@@ -23574,7 +23752,7 @@ function createStockPricePreProcessor(options = {}) {
23574
23752
  }
23575
23753
 
23576
23754
  // src/lib/db/chat/summaryOperations.ts
23577
- var import_watermelondb3 = __toESM(require_watermelondb());
23755
+ var import_watermelondb4 = __toESM(require_watermelondb());
23578
23756
  function createSummaryContext(database) {
23579
23757
  return {
23580
23758
  database,
@@ -23593,14 +23771,14 @@ function modelToStored(record) {
23593
23771
  };
23594
23772
  }
23595
23773
  async function getConversationSummaryOp(ctx, conversationId) {
23596
- const results = await ctx.summariesCollection.query(import_watermelondb3.Q.where("conversation_id", conversationId)).fetch();
23774
+ const results = await ctx.summariesCollection.query(import_watermelondb4.Q.where("conversation_id", conversationId)).fetch();
23597
23775
  if (results.length === 0) return null;
23598
23776
  return modelToStored(results[0]);
23599
23777
  }
23600
23778
  async function upsertConversationSummaryOp(ctx, conversationId, summary, summarizedUpTo, tokenCount) {
23601
23779
  let record;
23602
23780
  await ctx.database.write(async () => {
23603
- const existing = await ctx.summariesCollection.query(import_watermelondb3.Q.where("conversation_id", conversationId)).fetch();
23781
+ const existing = await ctx.summariesCollection.query(import_watermelondb4.Q.where("conversation_id", conversationId)).fetch();
23604
23782
  if (existing.length > 0) {
23605
23783
  record = await existing[0].update((rec) => {
23606
23784
  rec.summary = summary;
@@ -23620,7 +23798,7 @@ async function upsertConversationSummaryOp(ctx, conversationId, summary, summari
23620
23798
  }
23621
23799
  async function deleteConversationSummaryOp(ctx, conversationId) {
23622
23800
  await ctx.database.write(async () => {
23623
- const existing = await ctx.summariesCollection.query(import_watermelondb3.Q.where("conversation_id", conversationId)).fetch();
23801
+ const existing = await ctx.summariesCollection.query(import_watermelondb4.Q.where("conversation_id", conversationId)).fetch();
23624
23802
  for (const record of existing) {
23625
23803
  await record.destroyPermanently();
23626
23804
  }
@@ -23861,6 +24039,13 @@ var lastCompactionTime = /* @__PURE__ */ new Map();
23861
24039
  var COMPACTION_COOLDOWN_MS = 6e4;
23862
24040
  var MAX_SUMMARY_TOKEN_RATIO = 0.8;
23863
24041
  async function maybeSummarizeHistory(options) {
24042
+ const { database, conversationId } = options;
24043
+ const revision = getConversationRevision(database, conversationId);
24044
+ const result = await summarizeHistoryAtRevision(options, revision);
24045
+ assertConversationRevision(database, conversationId, revision);
24046
+ return result;
24047
+ }
24048
+ async function summarizeHistoryAtRevision(options, revision) {
23864
24049
  const { database, conversationId, messages, summarizeHistory, summaryMinWindowMessages, token } = options;
23865
24050
  if (!summarizeHistory) {
23866
24051
  return { messagesToConvert: messages, summarySystemMessage: null };
@@ -23901,7 +24086,7 @@ async function maybeSummarizeHistory(options) {
23901
24086
  clearTimeout(staleGuardTimerId);
23902
24087
  }
23903
24088
  }
23904
- const promise = doSummarizeHistory(options);
24089
+ const promise = doSummarizeHistory(options, revision);
23905
24090
  summarizationLocks.set(conversationId, promise);
23906
24091
  try {
23907
24092
  return await promise;
@@ -23915,7 +24100,7 @@ Summary to condense:
23915
24100
  {summary}
23916
24101
 
23917
24102
  Condensed summary:`;
23918
- async function doSummarizeHistory(options) {
24103
+ async function doSummarizeHistory(options, revision) {
23919
24104
  const {
23920
24105
  database,
23921
24106
  conversationId,
@@ -23930,7 +24115,20 @@ async function doSummarizeHistory(options) {
23930
24115
  } = options;
23931
24116
  try {
23932
24117
  const summaryCtx = createSummaryContext(database);
24118
+ const persistSummary = (summary, summarizedUpTo, tokenCount) => database.write(async (writer) => {
24119
+ assertConversationRevision(database, conversationId, revision);
24120
+ await writer.callWriter(
24121
+ () => upsertConversationSummaryOp(
24122
+ summaryCtx,
24123
+ conversationId,
24124
+ summary,
24125
+ summarizedUpTo,
24126
+ tokenCount
24127
+ )
24128
+ );
24129
+ });
23933
24130
  let cachedSummary = await getConversationSummaryOp(summaryCtx, conversationId);
24131
+ assertConversationRevision(database, conversationId, revision);
23934
24132
  const lastCompacted = lastCompactionTime.get(conversationId) ?? 0;
23935
24133
  const compactionCooledDown = Date.now() - lastCompacted > COMPACTION_COOLDOWN_MS;
23936
24134
  if (cachedSummary && cachedSummary.tokenCount > summaryTokenThreshold * MAX_SUMMARY_TOKEN_RATIO && compactionCooledDown) {
@@ -23946,13 +24144,7 @@ async function doSummarizeHistory(options) {
23946
24144
  );
23947
24145
  const compactedSummary = redactor ? redactor.deAnonymize(rawCompacted) : rawCompacted;
23948
24146
  const compactedTokens = estimateTokens(compactedSummary);
23949
- await upsertConversationSummaryOp(
23950
- summaryCtx,
23951
- conversationId,
23952
- compactedSummary,
23953
- cachedSummary.summarizedUpTo,
23954
- compactedTokens
23955
- );
24147
+ await persistSummary(compactedSummary, cachedSummary.summarizedUpTo, compactedTokens);
23956
24148
  cachedSummary = {
23957
24149
  ...cachedSummary,
23958
24150
  summary: compactedSummary,
@@ -23960,6 +24152,7 @@ async function doSummarizeHistory(options) {
23960
24152
  };
23961
24153
  lastCompactionTime.set(conversationId, Date.now());
23962
24154
  } catch {
24155
+ assertConversationRevision(database, conversationId, revision);
23963
24156
  lastCompactionTime.set(conversationId, Date.now());
23964
24157
  getLogger().warn(
23965
24158
  "[summarize] Summary compaction failed, proceeding with oversized summary"
@@ -23991,10 +24184,9 @@ async function doSummarizeHistory(options) {
23991
24184
  redactor,
23992
24185
  onPiiRedacted
23993
24186
  });
24187
+ assertConversationRevision(database, conversationId, revision);
23994
24188
  if (summarizeResult.didSummarize && summarizeResult.summary && summarizeResult.summarizedUpTo) {
23995
- await upsertConversationSummaryOp(
23996
- summaryCtx,
23997
- conversationId,
24189
+ await persistSummary(
23998
24190
  summarizeResult.summary,
23999
24191
  summarizeResult.summarizedUpTo,
24000
24192
  summarizeResult.summaryTokenCount
@@ -24013,6 +24205,7 @@ async function doSummarizeHistory(options) {
24013
24205
  summarySystemMessage: summarizeResult.summary ? summaryToSystemMessage(summarizeResult.summary) : null
24014
24206
  };
24015
24207
  } catch (err) {
24208
+ assertConversationRevision(database, conversationId, revision);
24016
24209
  getLogger().warn("[summarize] Summarization failed, falling back to verbatim:", err);
24017
24210
  return { messagesToConvert: messages, summarySystemMessage: null };
24018
24211
  }
@@ -24171,141 +24364,6 @@ async function decryptConversationTitle(encryptedTitle, address) {
24171
24364
  }
24172
24365
  }
24173
24366
 
24174
- // src/lib/db/chat/models.ts
24175
- var import_watermelondb4 = __toESM(require_watermelondb());
24176
- var import_decorators = __toESM(require_decorators());
24177
- var Message = class extends import_watermelondb4.Model {
24178
- };
24179
- Message.table = "history";
24180
- Message.associations = {
24181
- conversations: { type: "belongs_to", key: "conversation_id" },
24182
- media: { type: "has_many", foreignKey: "message_id" }
24183
- };
24184
- __decorateClass([
24185
- (0, import_decorators.field)("message_id")
24186
- ], Message.prototype, "messageId", 2);
24187
- __decorateClass([
24188
- (0, import_decorators.text)("conversation_id")
24189
- ], Message.prototype, "conversationId", 2);
24190
- __decorateClass([
24191
- (0, import_decorators.text)("role")
24192
- ], Message.prototype, "role", 2);
24193
- __decorateClass([
24194
- (0, import_decorators.text)("content")
24195
- ], Message.prototype, "content", 2);
24196
- __decorateClass([
24197
- (0, import_decorators.text)("model")
24198
- ], Message.prototype, "model", 2);
24199
- __decorateClass([
24200
- (0, import_decorators.text)("image_model")
24201
- ], Message.prototype, "imageModel", 2);
24202
- __decorateClass([
24203
- (0, import_decorators.json)("files", (raw) => raw)
24204
- ], Message.prototype, "files", 2);
24205
- __decorateClass([
24206
- (0, import_decorators.json)("file_ids", (raw) => raw)
24207
- ], Message.prototype, "fileIds", 2);
24208
- __decorateClass([
24209
- (0, import_decorators.date)("created_at")
24210
- ], Message.prototype, "createdAt", 2);
24211
- __decorateClass([
24212
- (0, import_decorators.date)("updated_at")
24213
- ], Message.prototype, "updatedAt", 2);
24214
- __decorateClass([
24215
- (0, import_decorators.json)("vector", (raw) => raw)
24216
- ], Message.prototype, "vector", 2);
24217
- __decorateClass([
24218
- (0, import_decorators.text)("embedding_model")
24219
- ], Message.prototype, "embeddingModel", 2);
24220
- __decorateClass([
24221
- (0, import_decorators.json)("chunks", (raw) => raw)
24222
- ], Message.prototype, "chunks", 2);
24223
- __decorateClass([
24224
- (0, import_decorators.json)("usage", (raw) => raw)
24225
- ], Message.prototype, "usage", 2);
24226
- __decorateClass([
24227
- (0, import_decorators.json)("sources", (raw) => raw)
24228
- ], Message.prototype, "sources", 2);
24229
- __decorateClass([
24230
- (0, import_decorators.field)("response_duration")
24231
- ], Message.prototype, "responseDuration", 2);
24232
- __decorateClass([
24233
- (0, import_decorators.field)("was_stopped")
24234
- ], Message.prototype, "wasStopped", 2);
24235
- __decorateClass([
24236
- (0, import_decorators.text)("error")
24237
- ], Message.prototype, "error", 2);
24238
- __decorateClass([
24239
- (0, import_decorators.json)("thought_process", (raw) => raw)
24240
- ], Message.prototype, "thoughtProcess", 2);
24241
- __decorateClass([
24242
- (0, import_decorators.text)("thinking")
24243
- ], Message.prototype, "thinking", 2);
24244
- __decorateClass([
24245
- (0, import_decorators.text)("parent_message_id")
24246
- ], Message.prototype, "parentMessageId", 2);
24247
- __decorateClass([
24248
- (0, import_decorators.text)("feedback")
24249
- ], Message.prototype, "feedback", 2);
24250
- __decorateClass([
24251
- (0, import_decorators.json)("tool_call_events", (raw) => raw)
24252
- ], Message.prototype, "toolCallEvents", 2);
24253
- __decorateClass([
24254
- (0, import_decorators.text)("origin")
24255
- ], Message.prototype, "origin", 2);
24256
- var Conversation = class extends import_watermelondb4.Model {
24257
- };
24258
- Conversation.table = "conversations";
24259
- Conversation.associations = {
24260
- history: { type: "has_many", foreignKey: "conversation_id" },
24261
- projects: { type: "belongs_to", key: "project_id" }
24262
- };
24263
- __decorateClass([
24264
- (0, import_decorators.text)("conversation_id")
24265
- ], Conversation.prototype, "conversationId", 2);
24266
- __decorateClass([
24267
- (0, import_decorators.text)("title")
24268
- ], Conversation.prototype, "title", 2);
24269
- __decorateClass([
24270
- (0, import_decorators.text)("project_id")
24271
- ], Conversation.prototype, "projectId", 2);
24272
- __decorateClass([
24273
- (0, import_decorators.date)("created_at")
24274
- ], Conversation.prototype, "createdAt", 2);
24275
- __decorateClass([
24276
- (0, import_decorators.date)("updated_at")
24277
- ], Conversation.prototype, "updatedAt", 2);
24278
- __decorateClass([
24279
- (0, import_decorators.field)("is_deleted")
24280
- ], Conversation.prototype, "isDeleted", 2);
24281
- __decorateClass([
24282
- (0, import_decorators.date)("pinned_at")
24283
- ], Conversation.prototype, "pinnedAt", 2);
24284
- var ConversationSummary = class extends import_watermelondb4.Model {
24285
- };
24286
- ConversationSummary.table = "conversation_summaries";
24287
- ConversationSummary.associations = {
24288
- conversations: { type: "belongs_to", key: "conversation_id" }
24289
- };
24290
- __decorateClass([
24291
- (0, import_decorators.text)("conversation_id")
24292
- ], ConversationSummary.prototype, "conversationId", 2);
24293
- __decorateClass([
24294
- (0, import_decorators.text)("summary")
24295
- ], ConversationSummary.prototype, "summary", 2);
24296
- __decorateClass([
24297
- (0, import_decorators.text)("summarized_up_to")
24298
- ], ConversationSummary.prototype, "summarizedUpTo", 2);
24299
- __decorateClass([
24300
- (0, import_decorators.field)("token_count")
24301
- ], ConversationSummary.prototype, "tokenCount", 2);
24302
- __decorateClass([
24303
- (0, import_decorators.date)("created_at")
24304
- ], ConversationSummary.prototype, "createdAt", 2);
24305
- __decorateClass([
24306
- (0, import_decorators.date)("updated_at")
24307
- ], ConversationSummary.prototype, "updatedAt", 2);
24308
-
24309
24367
  // src/lib/db/manager.ts
24310
24368
  var import_watermelondb16 = __toESM(require_watermelondb());
24311
24369