@reverbia/sdk 1.0.0-next.20251215193957 → 1.0.0-next.20251217134403

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.
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  ChatConversation: () => Conversation,
24
24
  ChatMessage: () => Message,
25
25
  StoredMemoryModel: () => Memory,
26
+ chatStorageMigrations: () => chatStorageMigrations,
26
27
  chatStorageSchema: () => chatStorageSchema,
27
28
  generateCompositeKey: () => generateCompositeKey,
28
29
  generateConversationId: () => generateConversationId,
@@ -352,7 +353,8 @@ function messageToStored(message) {
352
353
  embeddingModel: message.embeddingModel,
353
354
  usage: message.usage,
354
355
  sources: message.sources,
355
- responseDuration: message.responseDuration
356
+ responseDuration: message.responseDuration,
357
+ wasStopped: message.wasStopped
356
358
  };
357
359
  }
358
360
  function conversationToStored(conversation) {
@@ -441,6 +443,7 @@ async function createMessageOp(ctx, opts) {
441
443
  msg._setRaw("response_duration", opts.responseDuration);
442
444
  if (opts.vector) msg._setRaw("vector", JSON.stringify(opts.vector));
443
445
  if (opts.embeddingModel) msg._setRaw("embedding_model", opts.embeddingModel);
446
+ if (opts.wasStopped) msg._setRaw("was_stopped", opts.wasStopped);
444
447
  });
445
448
  });
446
449
  return messageToStored(created);
@@ -663,6 +666,44 @@ function useChatStorage(options) {
663
666
  });
664
667
  const responseDuration = (Date.now() - startTime) / 1e3;
665
668
  if (result.error || !result.data) {
669
+ const abortedResult = result;
670
+ if (abortedResult.error === "Request aborted") {
671
+ const assistantContent2 = abortedResult.data?.choices?.[0]?.message?.content?.map((part) => part.text || "").join("") || "";
672
+ const responseModel = abortedResult.data?.model || model || "";
673
+ let storedAssistantMessage2;
674
+ try {
675
+ storedAssistantMessage2 = await createMessageOp(storageCtx, {
676
+ conversationId: convId,
677
+ role: "assistant",
678
+ content: assistantContent2,
679
+ model: responseModel,
680
+ usage: convertUsageToStored(abortedResult.data?.usage),
681
+ responseDuration,
682
+ wasStopped: true
683
+ });
684
+ const completionData = abortedResult.data || {
685
+ id: `aborted-${Date.now()}`,
686
+ model: responseModel,
687
+ choices: [{
688
+ index: 0,
689
+ message: {
690
+ role: "assistant",
691
+ content: [{ type: "text", text: assistantContent2 }]
692
+ },
693
+ finish_reason: "stop"
694
+ }],
695
+ usage: void 0
696
+ };
697
+ return {
698
+ data: completionData,
699
+ error: null,
700
+ // Treat as success to the caller
701
+ userMessage: storedUserMessage,
702
+ assistantMessage: storedAssistantMessage2
703
+ };
704
+ } catch {
705
+ }
706
+ }
666
707
  return {
667
708
  data: null,
668
709
  error: result.error || "No response data received",
@@ -2692,8 +2733,9 @@ function useMemoryStorage(options) {
2692
2733
 
2693
2734
  // src/lib/chatStorage/schema.ts
2694
2735
  var import_watermelondb3 = require("@nozbe/watermelondb");
2736
+ var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
2695
2737
  var chatStorageSchema = (0, import_watermelondb3.appSchema)({
2696
- version: 1,
2738
+ version: 2,
2697
2739
  tables: [
2698
2740
  (0, import_watermelondb3.tableSchema)({
2699
2741
  name: "history",
@@ -2716,7 +2758,8 @@ var chatStorageSchema = (0, import_watermelondb3.appSchema)({
2716
2758
  // JSON stringified ChatCompletionUsage
2717
2759
  { name: "sources", type: "string", isOptional: true },
2718
2760
  // JSON stringified SearchSource[]
2719
- { name: "response_duration", type: "number", isOptional: true }
2761
+ { name: "response_duration", type: "number", isOptional: true },
2762
+ { name: "was_stopped", type: "boolean", isOptional: true }
2720
2763
  ]
2721
2764
  }),
2722
2765
  (0, import_watermelondb3.tableSchema)({
@@ -2731,6 +2774,21 @@ var chatStorageSchema = (0, import_watermelondb3.appSchema)({
2731
2774
  })
2732
2775
  ]
2733
2776
  });
2777
+ var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
2778
+ migrations: [
2779
+ {
2780
+ toVersion: 2,
2781
+ steps: [
2782
+ (0, import_migrations.addColumns)({
2783
+ table: "history",
2784
+ columns: [
2785
+ { name: "was_stopped", type: "boolean", isOptional: true }
2786
+ ]
2787
+ })
2788
+ ]
2789
+ }
2790
+ ]
2791
+ });
2734
2792
 
2735
2793
  // src/lib/chatStorage/models.ts
2736
2794
  var import_watermelondb4 = require("@nozbe/watermelondb");
@@ -2814,6 +2872,10 @@ var Message = class extends import_watermelondb4.Model {
2814
2872
  const value = this._getRaw("response_duration");
2815
2873
  return value !== null && value !== void 0 ? value : void 0;
2816
2874
  }
2875
+ /** Whether the message generation was stopped by the user */
2876
+ get wasStopped() {
2877
+ return this._getRaw("was_stopped");
2878
+ }
2817
2879
  };
2818
2880
  Message.table = "history";
2819
2881
  Message.associations = {
@@ -2957,6 +3019,7 @@ Memory.table = "memories";
2957
3019
  ChatConversation,
2958
3020
  ChatMessage,
2959
3021
  StoredMemoryModel,
3022
+ chatStorageMigrations,
2960
3023
  chatStorageSchema,
2961
3024
  generateCompositeKey,
2962
3025
  generateConversationId,
@@ -1,4 +1,5 @@
1
1
  import { Database, Model } from '@nozbe/watermelondb';
2
+ import * as _nozbe_watermelondb_Schema_migrations from '@nozbe/watermelondb/Schema/migrations';
2
3
  import * as _nozbe_watermelondb_Schema from '@nozbe/watermelondb/Schema';
3
4
  import { Associations } from '@nozbe/watermelondb/Model';
4
5
 
@@ -480,6 +481,8 @@ interface StoredMessage {
480
481
  sources?: SearchSource[];
481
482
  /** Response time in seconds */
482
483
  responseDuration?: number;
484
+ /** Whether the message generation was stopped by the user */
485
+ wasStopped?: boolean;
483
486
  }
484
487
  /**
485
488
  * Stored conversation record
@@ -529,6 +532,8 @@ interface CreateMessageOptions {
529
532
  vector?: number[];
530
533
  /** Model used to generate the embedding */
531
534
  embeddingModel?: string;
535
+ /** Whether the message generation was stopped by the user */
536
+ wasStopped?: boolean;
532
537
  }
533
538
  /**
534
539
  * Options for creating a new conversation
@@ -1105,6 +1110,15 @@ declare const chatStorageSchema: Readonly<{
1105
1110
  tables: _nozbe_watermelondb_Schema.TableMap;
1106
1111
  unsafeSql?: (_: string, __: _nozbe_watermelondb_Schema.AppSchemaUnsafeSqlKind) => string;
1107
1112
  }>;
1113
+ /**
1114
+ * Schema migrations
1115
+ */
1116
+ declare const chatStorageMigrations: Readonly<{
1117
+ validated: true;
1118
+ minVersion: _nozbe_watermelondb_Schema.SchemaVersion;
1119
+ maxVersion: _nozbe_watermelondb_Schema.SchemaVersion;
1120
+ sortedMigrations: _nozbe_watermelondb_Schema_migrations.Migration[];
1121
+ }>;
1108
1122
 
1109
1123
  /**
1110
1124
  * Message model representing a single chat message
@@ -1141,6 +1155,8 @@ declare class Message extends Model {
1141
1155
  get sources(): SearchSource[] | undefined;
1142
1156
  /** Response time in seconds */
1143
1157
  get responseDuration(): number | undefined;
1158
+ /** Whether the message generation was stopped by the user */
1159
+ get wasStopped(): boolean;
1144
1160
  }
1145
1161
  /**
1146
1162
  * Conversation model representing conversation metadata
@@ -1210,4 +1226,4 @@ declare class Memory extends Model {
1210
1226
  get isDeleted(): boolean;
1211
1227
  }
1212
1228
 
1213
- export { Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type FileMetadata, type MemoryItem, type MemoryType, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type UpdateMemoryOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseModelsOptions, type UseModelsResult, chatStorageSchema, generateCompositeKey, generateConversationId, generateUniqueKey, memoryStorageSchema, useChat, useChatStorage, useImageGeneration, useMemoryStorage, useModels };
1229
+ export { Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type FileMetadata, type MemoryItem, type MemoryType, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type UpdateMemoryOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseModelsOptions, type UseModelsResult, chatStorageMigrations, chatStorageSchema, generateCompositeKey, generateConversationId, generateUniqueKey, memoryStorageSchema, useChat, useChatStorage, useImageGeneration, useMemoryStorage, useModels };
@@ -1,4 +1,5 @@
1
1
  import { Database, Model } from '@nozbe/watermelondb';
2
+ import * as _nozbe_watermelondb_Schema_migrations from '@nozbe/watermelondb/Schema/migrations';
2
3
  import * as _nozbe_watermelondb_Schema from '@nozbe/watermelondb/Schema';
3
4
  import { Associations } from '@nozbe/watermelondb/Model';
4
5
 
@@ -480,6 +481,8 @@ interface StoredMessage {
480
481
  sources?: SearchSource[];
481
482
  /** Response time in seconds */
482
483
  responseDuration?: number;
484
+ /** Whether the message generation was stopped by the user */
485
+ wasStopped?: boolean;
483
486
  }
484
487
  /**
485
488
  * Stored conversation record
@@ -529,6 +532,8 @@ interface CreateMessageOptions {
529
532
  vector?: number[];
530
533
  /** Model used to generate the embedding */
531
534
  embeddingModel?: string;
535
+ /** Whether the message generation was stopped by the user */
536
+ wasStopped?: boolean;
532
537
  }
533
538
  /**
534
539
  * Options for creating a new conversation
@@ -1105,6 +1110,15 @@ declare const chatStorageSchema: Readonly<{
1105
1110
  tables: _nozbe_watermelondb_Schema.TableMap;
1106
1111
  unsafeSql?: (_: string, __: _nozbe_watermelondb_Schema.AppSchemaUnsafeSqlKind) => string;
1107
1112
  }>;
1113
+ /**
1114
+ * Schema migrations
1115
+ */
1116
+ declare const chatStorageMigrations: Readonly<{
1117
+ validated: true;
1118
+ minVersion: _nozbe_watermelondb_Schema.SchemaVersion;
1119
+ maxVersion: _nozbe_watermelondb_Schema.SchemaVersion;
1120
+ sortedMigrations: _nozbe_watermelondb_Schema_migrations.Migration[];
1121
+ }>;
1108
1122
 
1109
1123
  /**
1110
1124
  * Message model representing a single chat message
@@ -1141,6 +1155,8 @@ declare class Message extends Model {
1141
1155
  get sources(): SearchSource[] | undefined;
1142
1156
  /** Response time in seconds */
1143
1157
  get responseDuration(): number | undefined;
1158
+ /** Whether the message generation was stopped by the user */
1159
+ get wasStopped(): boolean;
1144
1160
  }
1145
1161
  /**
1146
1162
  * Conversation model representing conversation metadata
@@ -1210,4 +1226,4 @@ declare class Memory extends Model {
1210
1226
  get isDeleted(): boolean;
1211
1227
  }
1212
1228
 
1213
- export { Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type FileMetadata, type MemoryItem, type MemoryType, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type UpdateMemoryOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseModelsOptions, type UseModelsResult, chatStorageSchema, generateCompositeKey, generateConversationId, generateUniqueKey, memoryStorageSchema, useChat, useChatStorage, useImageGeneration, useMemoryStorage, useModels };
1229
+ export { Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type FileMetadata, type MemoryItem, type MemoryType, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type UpdateMemoryOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseModelsOptions, type UseModelsResult, chatStorageMigrations, chatStorageSchema, generateCompositeKey, generateConversationId, generateUniqueKey, memoryStorageSchema, useChat, useChatStorage, useImageGeneration, useMemoryStorage, useModels };
@@ -314,7 +314,8 @@ function messageToStored(message) {
314
314
  embeddingModel: message.embeddingModel,
315
315
  usage: message.usage,
316
316
  sources: message.sources,
317
- responseDuration: message.responseDuration
317
+ responseDuration: message.responseDuration,
318
+ wasStopped: message.wasStopped
318
319
  };
319
320
  }
320
321
  function conversationToStored(conversation) {
@@ -403,6 +404,7 @@ async function createMessageOp(ctx, opts) {
403
404
  msg._setRaw("response_duration", opts.responseDuration);
404
405
  if (opts.vector) msg._setRaw("vector", JSON.stringify(opts.vector));
405
406
  if (opts.embeddingModel) msg._setRaw("embedding_model", opts.embeddingModel);
407
+ if (opts.wasStopped) msg._setRaw("was_stopped", opts.wasStopped);
406
408
  });
407
409
  });
408
410
  return messageToStored(created);
@@ -625,6 +627,44 @@ function useChatStorage(options) {
625
627
  });
626
628
  const responseDuration = (Date.now() - startTime) / 1e3;
627
629
  if (result.error || !result.data) {
630
+ const abortedResult = result;
631
+ if (abortedResult.error === "Request aborted") {
632
+ const assistantContent2 = abortedResult.data?.choices?.[0]?.message?.content?.map((part) => part.text || "").join("") || "";
633
+ const responseModel = abortedResult.data?.model || model || "";
634
+ let storedAssistantMessage2;
635
+ try {
636
+ storedAssistantMessage2 = await createMessageOp(storageCtx, {
637
+ conversationId: convId,
638
+ role: "assistant",
639
+ content: assistantContent2,
640
+ model: responseModel,
641
+ usage: convertUsageToStored(abortedResult.data?.usage),
642
+ responseDuration,
643
+ wasStopped: true
644
+ });
645
+ const completionData = abortedResult.data || {
646
+ id: `aborted-${Date.now()}`,
647
+ model: responseModel,
648
+ choices: [{
649
+ index: 0,
650
+ message: {
651
+ role: "assistant",
652
+ content: [{ type: "text", text: assistantContent2 }]
653
+ },
654
+ finish_reason: "stop"
655
+ }],
656
+ usage: void 0
657
+ };
658
+ return {
659
+ data: completionData,
660
+ error: null,
661
+ // Treat as success to the caller
662
+ userMessage: storedUserMessage,
663
+ assistantMessage: storedAssistantMessage2
664
+ };
665
+ } catch {
666
+ }
667
+ }
628
668
  return {
629
669
  data: null,
630
670
  error: result.error || "No response data received",
@@ -2654,8 +2694,9 @@ function useMemoryStorage(options) {
2654
2694
 
2655
2695
  // src/lib/chatStorage/schema.ts
2656
2696
  import { appSchema, tableSchema } from "@nozbe/watermelondb";
2697
+ import { schemaMigrations, addColumns } from "@nozbe/watermelondb/Schema/migrations";
2657
2698
  var chatStorageSchema = appSchema({
2658
- version: 1,
2699
+ version: 2,
2659
2700
  tables: [
2660
2701
  tableSchema({
2661
2702
  name: "history",
@@ -2678,7 +2719,8 @@ var chatStorageSchema = appSchema({
2678
2719
  // JSON stringified ChatCompletionUsage
2679
2720
  { name: "sources", type: "string", isOptional: true },
2680
2721
  // JSON stringified SearchSource[]
2681
- { name: "response_duration", type: "number", isOptional: true }
2722
+ { name: "response_duration", type: "number", isOptional: true },
2723
+ { name: "was_stopped", type: "boolean", isOptional: true }
2682
2724
  ]
2683
2725
  }),
2684
2726
  tableSchema({
@@ -2693,6 +2735,21 @@ var chatStorageSchema = appSchema({
2693
2735
  })
2694
2736
  ]
2695
2737
  });
2738
+ var chatStorageMigrations = schemaMigrations({
2739
+ migrations: [
2740
+ {
2741
+ toVersion: 2,
2742
+ steps: [
2743
+ addColumns({
2744
+ table: "history",
2745
+ columns: [
2746
+ { name: "was_stopped", type: "boolean", isOptional: true }
2747
+ ]
2748
+ })
2749
+ ]
2750
+ }
2751
+ ]
2752
+ });
2696
2753
 
2697
2754
  // src/lib/chatStorage/models.ts
2698
2755
  import { Model } from "@nozbe/watermelondb";
@@ -2776,6 +2833,10 @@ var Message = class extends Model {
2776
2833
  const value = this._getRaw("response_duration");
2777
2834
  return value !== null && value !== void 0 ? value : void 0;
2778
2835
  }
2836
+ /** Whether the message generation was stopped by the user */
2837
+ get wasStopped() {
2838
+ return this._getRaw("was_stopped");
2839
+ }
2779
2840
  };
2780
2841
  Message.table = "history";
2781
2842
  Message.associations = {
@@ -2918,6 +2979,7 @@ export {
2918
2979
  Conversation as ChatConversation,
2919
2980
  Message as ChatMessage,
2920
2981
  Memory as StoredMemoryModel,
2982
+ chatStorageMigrations,
2921
2983
  chatStorageSchema,
2922
2984
  generateCompositeKey,
2923
2985
  generateConversationId,