@reverbia/sdk 1.0.0-next.20251219170400 → 1.0.0-next.20251220010649

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.
@@ -612,6 +612,37 @@ async function updateMessageErrorOp(ctx, uniqueId, error) {
612
612
  });
613
613
  return messageToStored(message);
614
614
  }
615
+ async function updateMessageOp(ctx, uniqueId, opts) {
616
+ let message;
617
+ try {
618
+ message = await ctx.messagesCollection.find(uniqueId);
619
+ } catch {
620
+ return null;
621
+ }
622
+ await ctx.database.write(async () => {
623
+ await message.update((msg) => {
624
+ if (opts.content !== void 0) msg._setRaw("content", opts.content);
625
+ if (opts.model !== void 0) msg._setRaw("model", opts.model);
626
+ if (opts.files !== void 0)
627
+ msg._setRaw("files", JSON.stringify(opts.files));
628
+ if (opts.usage !== void 0)
629
+ msg._setRaw("usage", JSON.stringify(opts.usage));
630
+ if (opts.sources !== void 0)
631
+ msg._setRaw("sources", JSON.stringify(opts.sources));
632
+ if (opts.responseDuration !== void 0)
633
+ msg._setRaw("response_duration", opts.responseDuration);
634
+ if (opts.vector !== void 0)
635
+ msg._setRaw("vector", JSON.stringify(opts.vector));
636
+ if (opts.embeddingModel !== void 0)
637
+ msg._setRaw("embedding_model", opts.embeddingModel);
638
+ if (opts.wasStopped !== void 0)
639
+ msg._setRaw("was_stopped", opts.wasStopped);
640
+ if (opts.error !== void 0)
641
+ msg._setRaw("error", opts.error === null ? "" : opts.error);
642
+ });
643
+ });
644
+ return messageToStored(message);
645
+ }
615
646
 
616
647
  // src/expo/useChatStorage.ts
617
648
  function storedToLlmapiMessage(stored) {
@@ -728,6 +759,12 @@ function useChatStorage(options) {
728
759
  },
729
760
  [storageCtx]
730
761
  );
762
+ const updateMessage = (0, import_react2.useCallback)(
763
+ async (uniqueId, options2) => {
764
+ return updateMessageOp(storageCtx, uniqueId, options2);
765
+ },
766
+ [storageCtx]
767
+ );
731
768
  const ensureConversation = (0, import_react2.useCallback)(async () => {
732
769
  if (currentConversationId) {
733
770
  const existing = await getConversation(currentConversationId);
@@ -939,7 +976,8 @@ function useChatStorage(options) {
939
976
  deleteConversation,
940
977
  getMessages,
941
978
  getMessageCount,
942
- clearMessages
979
+ clearMessages,
980
+ updateMessage
943
981
  };
944
982
  }
945
983
 
@@ -518,6 +518,18 @@ interface CreateConversationOptions {
518
518
  conversationId?: string;
519
519
  title?: string;
520
520
  }
521
+ interface UpdateMessageOptions {
522
+ content?: string;
523
+ model?: string;
524
+ files?: FileMetadata[];
525
+ usage?: ChatCompletionUsage;
526
+ sources?: SearchSource[];
527
+ responseDuration?: number;
528
+ vector?: number[];
529
+ embeddingModel?: string;
530
+ wasStopped?: boolean;
531
+ error?: string | null;
532
+ }
521
533
  interface BaseUseChatStorageOptions {
522
534
  database: Database;
523
535
  conversationId?: string;
@@ -625,6 +637,8 @@ type SendMessageWithStorageResult = BaseSendMessageWithStorageResult;
625
637
  interface UseChatStorageResult extends BaseUseChatStorageResult {
626
638
  /** Send a message and automatically store it (Expo version) */
627
639
  sendMessage: (args: SendMessageWithStorageArgs) => Promise<SendMessageWithStorageResult>;
640
+ /** Update a message's fields (content, embedding, files, etc). Returns updated message or null if not found. */
641
+ updateMessage: (uniqueId: string, options: UpdateMessageOptions) => Promise<StoredMessage | null>;
628
642
  }
629
643
  /**
630
644
  * A React hook that wraps useChat with automatic message persistence using WatermelonDB.
@@ -518,6 +518,18 @@ interface CreateConversationOptions {
518
518
  conversationId?: string;
519
519
  title?: string;
520
520
  }
521
+ interface UpdateMessageOptions {
522
+ content?: string;
523
+ model?: string;
524
+ files?: FileMetadata[];
525
+ usage?: ChatCompletionUsage;
526
+ sources?: SearchSource[];
527
+ responseDuration?: number;
528
+ vector?: number[];
529
+ embeddingModel?: string;
530
+ wasStopped?: boolean;
531
+ error?: string | null;
532
+ }
521
533
  interface BaseUseChatStorageOptions {
522
534
  database: Database;
523
535
  conversationId?: string;
@@ -625,6 +637,8 @@ type SendMessageWithStorageResult = BaseSendMessageWithStorageResult;
625
637
  interface UseChatStorageResult extends BaseUseChatStorageResult {
626
638
  /** Send a message and automatically store it (Expo version) */
627
639
  sendMessage: (args: SendMessageWithStorageArgs) => Promise<SendMessageWithStorageResult>;
640
+ /** Update a message's fields (content, embedding, files, etc). Returns updated message or null if not found. */
641
+ updateMessage: (uniqueId: string, options: UpdateMessageOptions) => Promise<StoredMessage | null>;
628
642
  }
629
643
  /**
630
644
  * A React hook that wraps useChat with automatic message persistence using WatermelonDB.
@@ -576,6 +576,37 @@ async function updateMessageErrorOp(ctx, uniqueId, error) {
576
576
  });
577
577
  return messageToStored(message);
578
578
  }
579
+ async function updateMessageOp(ctx, uniqueId, opts) {
580
+ let message;
581
+ try {
582
+ message = await ctx.messagesCollection.find(uniqueId);
583
+ } catch {
584
+ return null;
585
+ }
586
+ await ctx.database.write(async () => {
587
+ await message.update((msg) => {
588
+ if (opts.content !== void 0) msg._setRaw("content", opts.content);
589
+ if (opts.model !== void 0) msg._setRaw("model", opts.model);
590
+ if (opts.files !== void 0)
591
+ msg._setRaw("files", JSON.stringify(opts.files));
592
+ if (opts.usage !== void 0)
593
+ msg._setRaw("usage", JSON.stringify(opts.usage));
594
+ if (opts.sources !== void 0)
595
+ msg._setRaw("sources", JSON.stringify(opts.sources));
596
+ if (opts.responseDuration !== void 0)
597
+ msg._setRaw("response_duration", opts.responseDuration);
598
+ if (opts.vector !== void 0)
599
+ msg._setRaw("vector", JSON.stringify(opts.vector));
600
+ if (opts.embeddingModel !== void 0)
601
+ msg._setRaw("embedding_model", opts.embeddingModel);
602
+ if (opts.wasStopped !== void 0)
603
+ msg._setRaw("was_stopped", opts.wasStopped);
604
+ if (opts.error !== void 0)
605
+ msg._setRaw("error", opts.error === null ? "" : opts.error);
606
+ });
607
+ });
608
+ return messageToStored(message);
609
+ }
579
610
 
580
611
  // src/expo/useChatStorage.ts
581
612
  function storedToLlmapiMessage(stored) {
@@ -692,6 +723,12 @@ function useChatStorage(options) {
692
723
  },
693
724
  [storageCtx]
694
725
  );
726
+ const updateMessage = useCallback2(
727
+ async (uniqueId, options2) => {
728
+ return updateMessageOp(storageCtx, uniqueId, options2);
729
+ },
730
+ [storageCtx]
731
+ );
695
732
  const ensureConversation = useCallback2(async () => {
696
733
  if (currentConversationId) {
697
734
  const existing = await getConversation(currentConversationId);
@@ -903,7 +940,8 @@ function useChatStorage(options) {
903
940
  deleteConversation,
904
941
  getMessages,
905
942
  getMessageCount,
906
- clearMessages
943
+ clearMessages,
944
+ updateMessage
907
945
  };
908
946
  }
909
947
 
@@ -2085,6 +2085,37 @@ async function updateMessageErrorOp(ctx, uniqueId, error) {
2085
2085
  });
2086
2086
  return messageToStored(message);
2087
2087
  }
2088
+ async function updateMessageOp(ctx, uniqueId, opts) {
2089
+ let message;
2090
+ try {
2091
+ message = await ctx.messagesCollection.find(uniqueId);
2092
+ } catch {
2093
+ return null;
2094
+ }
2095
+ await ctx.database.write(async () => {
2096
+ await message.update((msg) => {
2097
+ if (opts.content !== void 0) msg._setRaw("content", opts.content);
2098
+ if (opts.model !== void 0) msg._setRaw("model", opts.model);
2099
+ if (opts.files !== void 0)
2100
+ msg._setRaw("files", JSON.stringify(opts.files));
2101
+ if (opts.usage !== void 0)
2102
+ msg._setRaw("usage", JSON.stringify(opts.usage));
2103
+ if (opts.sources !== void 0)
2104
+ msg._setRaw("sources", JSON.stringify(opts.sources));
2105
+ if (opts.responseDuration !== void 0)
2106
+ msg._setRaw("response_duration", opts.responseDuration);
2107
+ if (opts.vector !== void 0)
2108
+ msg._setRaw("vector", JSON.stringify(opts.vector));
2109
+ if (opts.embeddingModel !== void 0)
2110
+ msg._setRaw("embedding_model", opts.embeddingModel);
2111
+ if (opts.wasStopped !== void 0)
2112
+ msg._setRaw("was_stopped", opts.wasStopped);
2113
+ if (opts.error !== void 0)
2114
+ msg._setRaw("error", opts.error === null ? "" : opts.error);
2115
+ });
2116
+ });
2117
+ return messageToStored(message);
2118
+ }
2088
2119
  function cosineSimilarity(a, b) {
2089
2120
  if (a.length !== b.length) return 0;
2090
2121
  let dotProduct = 0;
@@ -2483,6 +2514,12 @@ function useChatStorage(options) {
2483
2514
  },
2484
2515
  [storageCtx]
2485
2516
  );
2517
+ const updateMessage = (0, import_react2.useCallback)(
2518
+ async (uniqueId, options2) => {
2519
+ return updateMessageOp(storageCtx, uniqueId, options2);
2520
+ },
2521
+ [storageCtx]
2522
+ );
2486
2523
  return {
2487
2524
  isLoading,
2488
2525
  isSelectingTool,
@@ -2499,7 +2536,8 @@ function useChatStorage(options) {
2499
2536
  getMessageCount,
2500
2537
  clearMessages,
2501
2538
  searchMessages,
2502
- updateMessageEmbedding
2539
+ updateMessageEmbedding,
2540
+ updateMessage
2503
2541
  };
2504
2542
  }
2505
2543
 
@@ -1039,6 +1039,18 @@ interface CreateConversationOptions {
1039
1039
  conversationId?: string;
1040
1040
  title?: string;
1041
1041
  }
1042
+ interface UpdateMessageOptions {
1043
+ content?: string;
1044
+ model?: string;
1045
+ files?: FileMetadata[];
1046
+ usage?: ChatCompletionUsage;
1047
+ sources?: SearchSource[];
1048
+ responseDuration?: number;
1049
+ vector?: number[];
1050
+ embeddingModel?: string;
1051
+ wasStopped?: boolean;
1052
+ error?: string | null;
1053
+ }
1042
1054
  interface BaseUseChatStorageOptions {
1043
1055
  database: Database;
1044
1056
  conversationId?: string;
@@ -1178,6 +1190,8 @@ interface UseChatStorageResult extends BaseUseChatStorageResult {
1178
1190
  searchMessages: (queryVector: number[], options?: SearchMessagesOptions) => Promise<StoredMessageWithSimilarity[]>;
1179
1191
  /** Update a message's embedding vector. Returns updated message or null if not found. */
1180
1192
  updateMessageEmbedding: (uniqueId: string, vector: number[], embeddingModel: string) => Promise<StoredMessage | null>;
1193
+ /** Update a message's fields (content, embedding, files, etc). Returns updated message or null if not found. */
1194
+ updateMessage: (uniqueId: string, options: UpdateMessageOptions) => Promise<StoredMessage | null>;
1181
1195
  }
1182
1196
  /**
1183
1197
  * A React hook that wraps useChat with automatic message persistence using WatermelonDB.
@@ -1039,6 +1039,18 @@ interface CreateConversationOptions {
1039
1039
  conversationId?: string;
1040
1040
  title?: string;
1041
1041
  }
1042
+ interface UpdateMessageOptions {
1043
+ content?: string;
1044
+ model?: string;
1045
+ files?: FileMetadata[];
1046
+ usage?: ChatCompletionUsage;
1047
+ sources?: SearchSource[];
1048
+ responseDuration?: number;
1049
+ vector?: number[];
1050
+ embeddingModel?: string;
1051
+ wasStopped?: boolean;
1052
+ error?: string | null;
1053
+ }
1042
1054
  interface BaseUseChatStorageOptions {
1043
1055
  database: Database;
1044
1056
  conversationId?: string;
@@ -1178,6 +1190,8 @@ interface UseChatStorageResult extends BaseUseChatStorageResult {
1178
1190
  searchMessages: (queryVector: number[], options?: SearchMessagesOptions) => Promise<StoredMessageWithSimilarity[]>;
1179
1191
  /** Update a message's embedding vector. Returns updated message or null if not found. */
1180
1192
  updateMessageEmbedding: (uniqueId: string, vector: number[], embeddingModel: string) => Promise<StoredMessage | null>;
1193
+ /** Update a message's fields (content, embedding, files, etc). Returns updated message or null if not found. */
1194
+ updateMessage: (uniqueId: string, options: UpdateMessageOptions) => Promise<StoredMessage | null>;
1181
1195
  }
1182
1196
  /**
1183
1197
  * A React hook that wraps useChat with automatic message persistence using WatermelonDB.
@@ -1994,6 +1994,37 @@ async function updateMessageErrorOp(ctx, uniqueId, error) {
1994
1994
  });
1995
1995
  return messageToStored(message);
1996
1996
  }
1997
+ async function updateMessageOp(ctx, uniqueId, opts) {
1998
+ let message;
1999
+ try {
2000
+ message = await ctx.messagesCollection.find(uniqueId);
2001
+ } catch {
2002
+ return null;
2003
+ }
2004
+ await ctx.database.write(async () => {
2005
+ await message.update((msg) => {
2006
+ if (opts.content !== void 0) msg._setRaw("content", opts.content);
2007
+ if (opts.model !== void 0) msg._setRaw("model", opts.model);
2008
+ if (opts.files !== void 0)
2009
+ msg._setRaw("files", JSON.stringify(opts.files));
2010
+ if (opts.usage !== void 0)
2011
+ msg._setRaw("usage", JSON.stringify(opts.usage));
2012
+ if (opts.sources !== void 0)
2013
+ msg._setRaw("sources", JSON.stringify(opts.sources));
2014
+ if (opts.responseDuration !== void 0)
2015
+ msg._setRaw("response_duration", opts.responseDuration);
2016
+ if (opts.vector !== void 0)
2017
+ msg._setRaw("vector", JSON.stringify(opts.vector));
2018
+ if (opts.embeddingModel !== void 0)
2019
+ msg._setRaw("embedding_model", opts.embeddingModel);
2020
+ if (opts.wasStopped !== void 0)
2021
+ msg._setRaw("was_stopped", opts.wasStopped);
2022
+ if (opts.error !== void 0)
2023
+ msg._setRaw("error", opts.error === null ? "" : opts.error);
2024
+ });
2025
+ });
2026
+ return messageToStored(message);
2027
+ }
1997
2028
  function cosineSimilarity(a, b) {
1998
2029
  if (a.length !== b.length) return 0;
1999
2030
  let dotProduct = 0;
@@ -2392,6 +2423,12 @@ function useChatStorage(options) {
2392
2423
  },
2393
2424
  [storageCtx]
2394
2425
  );
2426
+ const updateMessage = useCallback2(
2427
+ async (uniqueId, options2) => {
2428
+ return updateMessageOp(storageCtx, uniqueId, options2);
2429
+ },
2430
+ [storageCtx]
2431
+ );
2395
2432
  return {
2396
2433
  isLoading,
2397
2434
  isSelectingTool,
@@ -2408,7 +2445,8 @@ function useChatStorage(options) {
2408
2445
  getMessageCount,
2409
2446
  clearMessages,
2410
2447
  searchMessages,
2411
- updateMessageEmbedding
2448
+ updateMessageEmbedding,
2449
+ updateMessage
2412
2450
  };
2413
2451
  }
2414
2452
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reverbia/sdk",
3
- "version": "1.0.0-next.20251219170400",
3
+ "version": "1.0.0-next.20251220010649",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",