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

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.
@@ -337,7 +337,7 @@ var import_react2 = require("react");
337
337
  var import_watermelondb = require("@nozbe/watermelondb");
338
338
  var import_migrations = require("@nozbe/watermelondb/Schema/migrations");
339
339
  var chatStorageSchema = (0, import_watermelondb.appSchema)({
340
- version: 2,
340
+ version: 3,
341
341
  tables: [
342
342
  (0, import_watermelondb.tableSchema)({
343
343
  name: "history",
@@ -355,7 +355,8 @@ var chatStorageSchema = (0, import_watermelondb.appSchema)({
355
355
  { name: "usage", type: "string", isOptional: true },
356
356
  { name: "sources", type: "string", isOptional: true },
357
357
  { name: "response_duration", type: "number", isOptional: true },
358
- { name: "was_stopped", type: "boolean", isOptional: true }
358
+ { name: "was_stopped", type: "boolean", isOptional: true },
359
+ { name: "error", type: "string", isOptional: true }
359
360
  ]
360
361
  }),
361
362
  (0, import_watermelondb.tableSchema)({
@@ -380,6 +381,15 @@ var chatStorageMigrations = (0, import_migrations.schemaMigrations)({
380
381
  columns: [{ name: "was_stopped", type: "boolean", isOptional: true }]
381
382
  })
382
383
  ]
384
+ },
385
+ {
386
+ toVersion: 3,
387
+ steps: [
388
+ (0, import_migrations.addColumns)({
389
+ table: "history",
390
+ columns: [{ name: "error", type: "string", isOptional: true }]
391
+ })
392
+ ]
383
393
  }
384
394
  ]
385
395
  });
@@ -435,6 +445,9 @@ __decorateClass([
435
445
  __decorateClass([
436
446
  (0, import_decorators.field)("was_stopped")
437
447
  ], Message.prototype, "wasStopped", 2);
448
+ __decorateClass([
449
+ (0, import_decorators.text)("error")
450
+ ], Message.prototype, "error", 2);
438
451
  var Conversation = class extends import_watermelondb2.Model {
439
452
  };
440
453
  Conversation.table = "conversations";
@@ -489,7 +502,8 @@ function messageToStored(message) {
489
502
  usage: message.usage,
490
503
  sources: message.sources,
491
504
  responseDuration: message.responseDuration,
492
- wasStopped: message.wasStopped
505
+ wasStopped: message.wasStopped,
506
+ error: message.error
493
507
  };
494
508
  }
495
509
  function conversationToStored(conversation) {
@@ -579,10 +593,25 @@ async function createMessageOp(ctx, opts) {
579
593
  if (opts.vector) msg._setRaw("vector", JSON.stringify(opts.vector));
580
594
  if (opts.embeddingModel) msg._setRaw("embedding_model", opts.embeddingModel);
581
595
  if (opts.wasStopped) msg._setRaw("was_stopped", opts.wasStopped);
596
+ if (opts.error) msg._setRaw("error", opts.error);
582
597
  });
583
598
  });
584
599
  return messageToStored(created);
585
600
  }
601
+ async function updateMessageErrorOp(ctx, uniqueId, error) {
602
+ let message;
603
+ try {
604
+ message = await ctx.messagesCollection.find(uniqueId);
605
+ } catch {
606
+ return null;
607
+ }
608
+ await ctx.database.write(async () => {
609
+ await message.update((msg) => {
610
+ msg._setRaw("error", error);
611
+ });
612
+ });
613
+ return messageToStored(message);
614
+ }
586
615
 
587
616
  // src/expo/useChatStorage.ts
588
617
  function storedToLlmapiMessage(stored) {
@@ -748,7 +777,8 @@ function useChatStorage(options) {
748
777
  let messagesToSend = [];
749
778
  if (includeHistory && !providedMessages) {
750
779
  const storedMessages = await getMessages(convId);
751
- const limitedMessages = storedMessages.slice(-maxHistoryMessages);
780
+ const validMessages = storedMessages.filter((msg) => !msg.error);
781
+ const limitedMessages = validMessages.slice(-maxHistoryMessages);
752
782
  messagesToSend = limitedMessages.map(storedToLlmapiMessage);
753
783
  } else if (providedMessages) {
754
784
  messagesToSend = providedMessages;
@@ -838,12 +868,34 @@ function useChatStorage(options) {
838
868
  assistantMessage: storedAssistantMessage2
839
869
  };
840
870
  } catch {
871
+ return {
872
+ data: null,
873
+ error: "Request aborted",
874
+ userMessage: storedUserMessage
875
+ };
841
876
  }
842
877
  }
878
+ const errorMessage = result.error || "No response data received";
879
+ try {
880
+ await updateMessageErrorOp(
881
+ storageCtx,
882
+ storedUserMessage.uniqueId,
883
+ errorMessage
884
+ );
885
+ await createMessageOp(storageCtx, {
886
+ conversationId: convId,
887
+ role: "assistant",
888
+ content: "",
889
+ model: model || "",
890
+ responseDuration,
891
+ error: errorMessage
892
+ });
893
+ } catch {
894
+ }
843
895
  return {
844
896
  data: null,
845
- error: result.error || "No response data received",
846
- userMessage: storedUserMessage
897
+ error: errorMessage,
898
+ userMessage: { ...storedUserMessage, error: errorMessage }
847
899
  };
848
900
  }
849
901
  const responseData = result.data;
@@ -2959,7 +3011,7 @@ __decorateClass([
2959
3011
  ], ModelPreference.prototype, "models", 2);
2960
3012
 
2961
3013
  // src/lib/db/schema.ts
2962
- var SDK_SCHEMA_VERSION = 4;
3014
+ var SDK_SCHEMA_VERSION = 5;
2963
3015
  var sdkSchema = (0, import_watermelondb8.appSchema)({
2964
3016
  version: SDK_SCHEMA_VERSION,
2965
3017
  tables: [
@@ -2980,7 +3032,8 @@ var sdkSchema = (0, import_watermelondb8.appSchema)({
2980
3032
  { name: "usage", type: "string", isOptional: true },
2981
3033
  { name: "sources", type: "string", isOptional: true },
2982
3034
  { name: "response_duration", type: "number", isOptional: true },
2983
- { name: "was_stopped", type: "boolean", isOptional: true }
3035
+ { name: "was_stopped", type: "boolean", isOptional: true },
3036
+ { name: "error", type: "string", isOptional: true }
2984
3037
  ]
2985
3038
  }),
2986
3039
  (0, import_watermelondb8.tableSchema)({
@@ -3047,6 +3100,16 @@ var sdkMigrations = (0, import_migrations2.schemaMigrations)({
3047
3100
  ]
3048
3101
  })
3049
3102
  ]
3103
+ },
3104
+ // v4 -> v5: Added error column to history for error persistence
3105
+ {
3106
+ toVersion: 5,
3107
+ steps: [
3108
+ (0, import_migrations2.addColumns)({
3109
+ table: "history",
3110
+ columns: [{ name: "error", type: "string", isOptional: true }]
3111
+ })
3112
+ ]
3050
3113
  }
3051
3114
  ]
3052
3115
  });
@@ -172,6 +172,10 @@ type LlmapiMessage = {
172
172
  */
173
173
  content?: Array<LlmapiMessageContentPart>;
174
174
  role?: LlmapiRole;
175
+ /**
176
+ * ToolCalls contains tool/function calls made by the assistant (only for assistant role)
177
+ */
178
+ tool_calls?: Array<LlmapiToolCall>;
175
179
  };
176
180
  /**
177
181
  * ImageURL is used when Type=image_url
@@ -298,6 +302,30 @@ type LlmapiModelTopProvider = {
298
302
  * Role is the message role (system, user, assistant)
299
303
  */
300
304
  type LlmapiRole = string;
305
+ type LlmapiToolCall = {
306
+ function?: LlmapiToolCallFunction;
307
+ /**
308
+ * ID is the unique identifier for this tool call
309
+ */
310
+ id?: string;
311
+ /**
312
+ * Type is the type of tool call (always "function" for now)
313
+ */
314
+ type?: string;
315
+ };
316
+ /**
317
+ * Function contains the function call details
318
+ */
319
+ type LlmapiToolCallFunction = {
320
+ /**
321
+ * Arguments is the JSON string of arguments to pass to the function
322
+ */
323
+ arguments?: string;
324
+ /**
325
+ * Name is the name of the function to call
326
+ */
327
+ name?: string;
328
+ };
301
329
 
302
330
  /**
303
331
  * Base arguments for sending a message
@@ -457,6 +485,8 @@ interface StoredMessage {
457
485
  sources?: SearchSource[];
458
486
  responseDuration?: number;
459
487
  wasStopped?: boolean;
488
+ /** If set, indicates the message failed with this error */
489
+ error?: string;
460
490
  }
461
491
  interface StoredConversation {
462
492
  uniqueId: string;
@@ -481,6 +511,8 @@ interface CreateMessageOptions {
481
511
  vector?: number[];
482
512
  embeddingModel?: string;
483
513
  wasStopped?: boolean;
514
+ /** If set, indicates the message failed with this error */
515
+ error?: string;
484
516
  }
485
517
  interface CreateConversationOptions {
486
518
  conversationId?: string;
@@ -555,6 +587,7 @@ declare class Message extends Model {
555
587
  sources?: SearchSource[];
556
588
  responseDuration?: number;
557
589
  wasStopped?: boolean;
590
+ error?: string;
558
591
  }
559
592
  declare class Conversation extends Model {
560
593
  static table: string;
@@ -918,6 +951,7 @@ declare const sdkSchema: Readonly<{
918
951
  * Migration history:
919
952
  * - v2 → v3: Added `was_stopped` column to history table
920
953
  * - v3 → v4: Added `modelPreferences` table for settings storage
954
+ * - v4 → v5: Added `error` column to history table for error persistence
921
955
  */
922
956
  declare const sdkMigrations: Readonly<{
923
957
  validated: true;
@@ -172,6 +172,10 @@ type LlmapiMessage = {
172
172
  */
173
173
  content?: Array<LlmapiMessageContentPart>;
174
174
  role?: LlmapiRole;
175
+ /**
176
+ * ToolCalls contains tool/function calls made by the assistant (only for assistant role)
177
+ */
178
+ tool_calls?: Array<LlmapiToolCall>;
175
179
  };
176
180
  /**
177
181
  * ImageURL is used when Type=image_url
@@ -298,6 +302,30 @@ type LlmapiModelTopProvider = {
298
302
  * Role is the message role (system, user, assistant)
299
303
  */
300
304
  type LlmapiRole = string;
305
+ type LlmapiToolCall = {
306
+ function?: LlmapiToolCallFunction;
307
+ /**
308
+ * ID is the unique identifier for this tool call
309
+ */
310
+ id?: string;
311
+ /**
312
+ * Type is the type of tool call (always "function" for now)
313
+ */
314
+ type?: string;
315
+ };
316
+ /**
317
+ * Function contains the function call details
318
+ */
319
+ type LlmapiToolCallFunction = {
320
+ /**
321
+ * Arguments is the JSON string of arguments to pass to the function
322
+ */
323
+ arguments?: string;
324
+ /**
325
+ * Name is the name of the function to call
326
+ */
327
+ name?: string;
328
+ };
301
329
 
302
330
  /**
303
331
  * Base arguments for sending a message
@@ -457,6 +485,8 @@ interface StoredMessage {
457
485
  sources?: SearchSource[];
458
486
  responseDuration?: number;
459
487
  wasStopped?: boolean;
488
+ /** If set, indicates the message failed with this error */
489
+ error?: string;
460
490
  }
461
491
  interface StoredConversation {
462
492
  uniqueId: string;
@@ -481,6 +511,8 @@ interface CreateMessageOptions {
481
511
  vector?: number[];
482
512
  embeddingModel?: string;
483
513
  wasStopped?: boolean;
514
+ /** If set, indicates the message failed with this error */
515
+ error?: string;
484
516
  }
485
517
  interface CreateConversationOptions {
486
518
  conversationId?: string;
@@ -555,6 +587,7 @@ declare class Message extends Model {
555
587
  sources?: SearchSource[];
556
588
  responseDuration?: number;
557
589
  wasStopped?: boolean;
590
+ error?: string;
558
591
  }
559
592
  declare class Conversation extends Model {
560
593
  static table: string;
@@ -918,6 +951,7 @@ declare const sdkSchema: Readonly<{
918
951
  * Migration history:
919
952
  * - v2 → v3: Added `was_stopped` column to history table
920
953
  * - v3 → v4: Added `modelPreferences` table for settings storage
954
+ * - v4 → v5: Added `error` column to history table for error persistence
921
955
  */
922
956
  declare const sdkMigrations: Readonly<{
923
957
  validated: true;
@@ -301,7 +301,7 @@ import {
301
301
  addColumns
302
302
  } from "@nozbe/watermelondb/Schema/migrations";
303
303
  var chatStorageSchema = appSchema({
304
- version: 2,
304
+ version: 3,
305
305
  tables: [
306
306
  tableSchema({
307
307
  name: "history",
@@ -319,7 +319,8 @@ var chatStorageSchema = appSchema({
319
319
  { name: "usage", type: "string", isOptional: true },
320
320
  { name: "sources", type: "string", isOptional: true },
321
321
  { name: "response_duration", type: "number", isOptional: true },
322
- { name: "was_stopped", type: "boolean", isOptional: true }
322
+ { name: "was_stopped", type: "boolean", isOptional: true },
323
+ { name: "error", type: "string", isOptional: true }
323
324
  ]
324
325
  }),
325
326
  tableSchema({
@@ -344,6 +345,15 @@ var chatStorageMigrations = schemaMigrations({
344
345
  columns: [{ name: "was_stopped", type: "boolean", isOptional: true }]
345
346
  })
346
347
  ]
348
+ },
349
+ {
350
+ toVersion: 3,
351
+ steps: [
352
+ addColumns({
353
+ table: "history",
354
+ columns: [{ name: "error", type: "string", isOptional: true }]
355
+ })
356
+ ]
347
357
  }
348
358
  ]
349
359
  });
@@ -399,6 +409,9 @@ __decorateClass([
399
409
  __decorateClass([
400
410
  field("was_stopped")
401
411
  ], Message.prototype, "wasStopped", 2);
412
+ __decorateClass([
413
+ text("error")
414
+ ], Message.prototype, "error", 2);
402
415
  var Conversation = class extends Model {
403
416
  };
404
417
  Conversation.table = "conversations";
@@ -453,7 +466,8 @@ function messageToStored(message) {
453
466
  usage: message.usage,
454
467
  sources: message.sources,
455
468
  responseDuration: message.responseDuration,
456
- wasStopped: message.wasStopped
469
+ wasStopped: message.wasStopped,
470
+ error: message.error
457
471
  };
458
472
  }
459
473
  function conversationToStored(conversation) {
@@ -543,10 +557,25 @@ async function createMessageOp(ctx, opts) {
543
557
  if (opts.vector) msg._setRaw("vector", JSON.stringify(opts.vector));
544
558
  if (opts.embeddingModel) msg._setRaw("embedding_model", opts.embeddingModel);
545
559
  if (opts.wasStopped) msg._setRaw("was_stopped", opts.wasStopped);
560
+ if (opts.error) msg._setRaw("error", opts.error);
546
561
  });
547
562
  });
548
563
  return messageToStored(created);
549
564
  }
565
+ async function updateMessageErrorOp(ctx, uniqueId, error) {
566
+ let message;
567
+ try {
568
+ message = await ctx.messagesCollection.find(uniqueId);
569
+ } catch {
570
+ return null;
571
+ }
572
+ await ctx.database.write(async () => {
573
+ await message.update((msg) => {
574
+ msg._setRaw("error", error);
575
+ });
576
+ });
577
+ return messageToStored(message);
578
+ }
550
579
 
551
580
  // src/expo/useChatStorage.ts
552
581
  function storedToLlmapiMessage(stored) {
@@ -712,7 +741,8 @@ function useChatStorage(options) {
712
741
  let messagesToSend = [];
713
742
  if (includeHistory && !providedMessages) {
714
743
  const storedMessages = await getMessages(convId);
715
- const limitedMessages = storedMessages.slice(-maxHistoryMessages);
744
+ const validMessages = storedMessages.filter((msg) => !msg.error);
745
+ const limitedMessages = validMessages.slice(-maxHistoryMessages);
716
746
  messagesToSend = limitedMessages.map(storedToLlmapiMessage);
717
747
  } else if (providedMessages) {
718
748
  messagesToSend = providedMessages;
@@ -802,12 +832,34 @@ function useChatStorage(options) {
802
832
  assistantMessage: storedAssistantMessage2
803
833
  };
804
834
  } catch {
835
+ return {
836
+ data: null,
837
+ error: "Request aborted",
838
+ userMessage: storedUserMessage
839
+ };
805
840
  }
806
841
  }
842
+ const errorMessage = result.error || "No response data received";
843
+ try {
844
+ await updateMessageErrorOp(
845
+ storageCtx,
846
+ storedUserMessage.uniqueId,
847
+ errorMessage
848
+ );
849
+ await createMessageOp(storageCtx, {
850
+ conversationId: convId,
851
+ role: "assistant",
852
+ content: "",
853
+ model: model || "",
854
+ responseDuration,
855
+ error: errorMessage
856
+ });
857
+ } catch {
858
+ }
807
859
  return {
808
860
  data: null,
809
- error: result.error || "No response data received",
810
- userMessage: storedUserMessage
861
+ error: errorMessage,
862
+ userMessage: { ...storedUserMessage, error: errorMessage }
811
863
  };
812
864
  }
813
865
  const responseData = result.data;
@@ -2927,7 +2979,7 @@ __decorateClass([
2927
2979
  ], ModelPreference.prototype, "models", 2);
2928
2980
 
2929
2981
  // src/lib/db/schema.ts
2930
- var SDK_SCHEMA_VERSION = 4;
2982
+ var SDK_SCHEMA_VERSION = 5;
2931
2983
  var sdkSchema = appSchema3({
2932
2984
  version: SDK_SCHEMA_VERSION,
2933
2985
  tables: [
@@ -2948,7 +3000,8 @@ var sdkSchema = appSchema3({
2948
3000
  { name: "usage", type: "string", isOptional: true },
2949
3001
  { name: "sources", type: "string", isOptional: true },
2950
3002
  { name: "response_duration", type: "number", isOptional: true },
2951
- { name: "was_stopped", type: "boolean", isOptional: true }
3003
+ { name: "was_stopped", type: "boolean", isOptional: true },
3004
+ { name: "error", type: "string", isOptional: true }
2952
3005
  ]
2953
3006
  }),
2954
3007
  tableSchema3({
@@ -3015,6 +3068,16 @@ var sdkMigrations = schemaMigrations2({
3015
3068
  ]
3016
3069
  })
3017
3070
  ]
3071
+ },
3072
+ // v4 -> v5: Added error column to history for error persistence
3073
+ {
3074
+ toVersion: 5,
3075
+ steps: [
3076
+ addColumns2({
3077
+ table: "history",
3078
+ columns: [{ name: "error", type: "string", isOptional: true }]
3079
+ })
3080
+ ]
3018
3081
  }
3019
3082
  ]
3020
3083
  });
package/dist/index.cjs CHANGED
@@ -26,6 +26,7 @@ __export(index_exports, {
26
26
  postApiV1ChatCompletions: () => postApiV1ChatCompletions,
27
27
  postApiV1Embeddings: () => postApiV1Embeddings,
28
28
  postApiV1ImagesGenerations: () => postApiV1ImagesGenerations,
29
+ postApiV1Responses: () => postApiV1Responses,
29
30
  postApiV1Search: () => postApiV1Search,
30
31
  postAuthOauthByProviderExchange: () => postAuthOauthByProviderExchange,
31
32
  postAuthOauthByProviderRefresh: () => postAuthOauthByProviderRefresh,
@@ -891,6 +892,16 @@ var getApiV1Models = (options) => {
891
892
  ...options
892
893
  });
893
894
  };
895
+ var postApiV1Responses = (options) => {
896
+ return (options.client ?? client).post({
897
+ url: "/api/v1/responses",
898
+ ...options,
899
+ headers: {
900
+ "Content-Type": "application/json",
901
+ ...options.headers
902
+ }
903
+ });
904
+ };
894
905
  var postApiV1Search = (options) => {
895
906
  return (options.client ?? client).post({
896
907
  url: "/api/v1/search",
@@ -945,6 +956,7 @@ var getHealth = (options) => {
945
956
  postApiV1ChatCompletions,
946
957
  postApiV1Embeddings,
947
958
  postApiV1ImagesGenerations,
959
+ postApiV1Responses,
948
960
  postApiV1Search,
949
961
  postAuthOauthByProviderExchange,
950
962
  postAuthOauthByProviderRefresh,