@broberg/ai-sdk 0.8.0 → 0.9.0

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.
package/dist/index.d.ts CHANGED
@@ -229,6 +229,20 @@ interface TtsRequest {
229
229
  voiceId: string;
230
230
  spec: TierSpec;
231
231
  }
232
+ interface BatchRequestItem {
233
+ customId: string;
234
+ prompt: string;
235
+ }
236
+ interface BatchJob {
237
+ jobId: string;
238
+ status: string;
239
+ total?: number;
240
+ completed?: number;
241
+ }
242
+ interface BatchResultItem {
243
+ customId: string;
244
+ text: string;
245
+ }
232
246
  /** The thin contract every provider implements (F4). A provider need only
233
247
  * support the capabilities it offers — `chat` is the baseline; vision/image/
234
248
  * embedding are optional and absence is a typed capability gap. */
@@ -251,6 +265,19 @@ interface ProviderAdapter {
251
265
  dialogue?(req: DialogueRequest): Promise<PodcastResult>;
252
266
  /** Single-voice TTS (F020.4) → audio. ElevenLabs. */
253
267
  tts?(req: TtsRequest): Promise<PodcastResult>;
268
+ /** Batch (F016.1) — async chat-request processing at 50% cost. Mistral. */
269
+ batchSubmit?(req: {
270
+ items: BatchRequestItem[];
271
+ spec: TierSpec;
272
+ }): Promise<BatchJob>;
273
+ batchStatus?(req: {
274
+ jobId: string;
275
+ spec: TierSpec;
276
+ }): Promise<BatchJob>;
277
+ batchResults?(req: {
278
+ jobId: string;
279
+ spec: TierSpec;
280
+ }): Promise<BatchResultItem[]>;
254
281
  }
255
282
  interface TranslateResult {
256
283
  text: string;
@@ -565,6 +592,7 @@ declare const chatInputSchema: z.ZodObject<{
565
592
  parameters: Record<string, unknown>;
566
593
  }[] | undefined;
567
594
  temperature?: number | undefined;
595
+ purpose?: string | undefined;
568
596
  maxTokens?: number | undefined;
569
597
  responseFormat?: "text" | "json" | undefined;
570
598
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
@@ -578,7 +606,6 @@ declare const chatInputSchema: z.ZodObject<{
578
606
  model: string;
579
607
  transport: "http" | "subprocess";
580
608
  })[] | undefined;
581
- purpose?: string | undefined;
582
609
  labels?: Record<string, string> | undefined;
583
610
  }, {
584
611
  system?: string | undefined;
@@ -606,6 +633,7 @@ declare const chatInputSchema: z.ZodObject<{
606
633
  parameters: Record<string, unknown>;
607
634
  }[] | undefined;
608
635
  temperature?: number | undefined;
636
+ purpose?: string | undefined;
609
637
  maxTokens?: number | undefined;
610
638
  responseFormat?: "text" | "json" | undefined;
611
639
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
@@ -619,7 +647,6 @@ declare const chatInputSchema: z.ZodObject<{
619
647
  model: string;
620
648
  transport: "http" | "subprocess";
621
649
  })[] | undefined;
622
- purpose?: string | undefined;
623
650
  labels?: Record<string, string> | undefined;
624
651
  }>;
625
652
  declare const visionInputSchema: z.ZodObject<{
@@ -659,6 +686,7 @@ declare const visionInputSchema: z.ZodObject<{
659
686
  image: string | Uint8Array<ArrayBuffer>;
660
687
  prompt: string;
661
688
  mimeType?: string | undefined;
689
+ purpose?: string | undefined;
662
690
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
663
691
  override?: {
664
692
  provider?: string | undefined;
@@ -670,12 +698,12 @@ declare const visionInputSchema: z.ZodObject<{
670
698
  model: string;
671
699
  transport: "http" | "subprocess";
672
700
  })[] | undefined;
673
- purpose?: string | undefined;
674
701
  labels?: Record<string, string> | undefined;
675
702
  }, {
676
703
  image: string | Uint8Array<ArrayBuffer>;
677
704
  prompt: string;
678
705
  mimeType?: string | undefined;
706
+ purpose?: string | undefined;
679
707
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
680
708
  override?: {
681
709
  provider?: string | undefined;
@@ -687,7 +715,6 @@ declare const visionInputSchema: z.ZodObject<{
687
715
  model: string;
688
716
  transport: "http" | "subprocess";
689
717
  })[] | undefined;
690
- purpose?: string | undefined;
691
718
  labels?: Record<string, string> | undefined;
692
719
  }>;
693
720
  declare const videoInputSchema: z.ZodObject<{
@@ -727,6 +754,7 @@ declare const videoInputSchema: z.ZodObject<{
727
754
  video: string | Uint8Array<ArrayBuffer>;
728
755
  prompt: string;
729
756
  mimeType?: string | undefined;
757
+ purpose?: string | undefined;
730
758
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
731
759
  override?: {
732
760
  provider?: string | undefined;
@@ -738,12 +766,12 @@ declare const videoInputSchema: z.ZodObject<{
738
766
  model: string;
739
767
  transport: "http" | "subprocess";
740
768
  })[] | undefined;
741
- purpose?: string | undefined;
742
769
  labels?: Record<string, string> | undefined;
743
770
  }, {
744
771
  video: string | Uint8Array<ArrayBuffer>;
745
772
  prompt: string;
746
773
  mimeType?: string | undefined;
774
+ purpose?: string | undefined;
747
775
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
748
776
  override?: {
749
777
  provider?: string | undefined;
@@ -755,7 +783,6 @@ declare const videoInputSchema: z.ZodObject<{
755
783
  model: string;
756
784
  transport: "http" | "subprocess";
757
785
  })[] | undefined;
758
- purpose?: string | undefined;
759
786
  labels?: Record<string, string> | undefined;
760
787
  }>;
761
788
  declare const translateInputSchema: z.ZodObject<{
@@ -794,6 +821,7 @@ declare const translateInputSchema: z.ZodObject<{
794
821
  }, "strip", z.ZodTypeAny, {
795
822
  text: string;
796
823
  to: string;
824
+ purpose?: string | undefined;
797
825
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
798
826
  override?: {
799
827
  provider?: string | undefined;
@@ -805,12 +833,12 @@ declare const translateInputSchema: z.ZodObject<{
805
833
  model: string;
806
834
  transport: "http" | "subprocess";
807
835
  })[] | undefined;
808
- purpose?: string | undefined;
809
836
  labels?: Record<string, string> | undefined;
810
837
  from?: string | undefined;
811
838
  }, {
812
839
  text: string;
813
840
  to: string;
841
+ purpose?: string | undefined;
814
842
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
815
843
  override?: {
816
844
  provider?: string | undefined;
@@ -822,7 +850,6 @@ declare const translateInputSchema: z.ZodObject<{
822
850
  model: string;
823
851
  transport: "http" | "subprocess";
824
852
  })[] | undefined;
825
- purpose?: string | undefined;
826
853
  labels?: Record<string, string> | undefined;
827
854
  from?: string | undefined;
828
855
  }>;
@@ -861,6 +888,7 @@ declare const imageInputSchema: z.ZodObject<{
861
888
  height: z.ZodOptional<z.ZodNumber>;
862
889
  }, "strip", z.ZodTypeAny, {
863
890
  prompt: string;
891
+ purpose?: string | undefined;
864
892
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
865
893
  override?: {
866
894
  provider?: string | undefined;
@@ -872,12 +900,12 @@ declare const imageInputSchema: z.ZodObject<{
872
900
  model: string;
873
901
  transport: "http" | "subprocess";
874
902
  })[] | undefined;
875
- purpose?: string | undefined;
876
903
  labels?: Record<string, string> | undefined;
877
904
  width?: number | undefined;
878
905
  height?: number | undefined;
879
906
  }, {
880
907
  prompt: string;
908
+ purpose?: string | undefined;
881
909
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
882
910
  override?: {
883
911
  provider?: string | undefined;
@@ -889,7 +917,6 @@ declare const imageInputSchema: z.ZodObject<{
889
917
  model: string;
890
918
  transport: "http" | "subprocess";
891
919
  })[] | undefined;
892
- purpose?: string | undefined;
893
920
  labels?: Record<string, string> | undefined;
894
921
  width?: number | undefined;
895
922
  height?: number | undefined;
@@ -927,6 +954,7 @@ declare const embeddingInputSchema: z.ZodObject<{
927
954
  text: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
928
955
  }, "strip", z.ZodTypeAny, {
929
956
  text: string | string[];
957
+ purpose?: string | undefined;
930
958
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
931
959
  override?: {
932
960
  provider?: string | undefined;
@@ -938,10 +966,10 @@ declare const embeddingInputSchema: z.ZodObject<{
938
966
  model: string;
939
967
  transport: "http" | "subprocess";
940
968
  })[] | undefined;
941
- purpose?: string | undefined;
942
969
  labels?: Record<string, string> | undefined;
943
970
  }, {
944
971
  text: string | string[];
972
+ purpose?: string | undefined;
945
973
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
946
974
  override?: {
947
975
  provider?: string | undefined;
@@ -953,7 +981,6 @@ declare const embeddingInputSchema: z.ZodObject<{
953
981
  model: string;
954
982
  transport: "http" | "subprocess";
955
983
  })[] | undefined;
956
- purpose?: string | undefined;
957
984
  labels?: Record<string, string> | undefined;
958
985
  }>;
959
986
  declare const transcribeInputSchema: z.ZodObject<{
@@ -994,6 +1021,7 @@ declare const transcribeInputSchema: z.ZodObject<{
994
1021
  }, "strip", z.ZodTypeAny, {
995
1022
  audio: string | Uint8Array<ArrayBuffer>;
996
1023
  language?: string | undefined;
1024
+ purpose?: string | undefined;
997
1025
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
998
1026
  override?: {
999
1027
  provider?: string | undefined;
@@ -1005,12 +1033,12 @@ declare const transcribeInputSchema: z.ZodObject<{
1005
1033
  model: string;
1006
1034
  transport: "http" | "subprocess";
1007
1035
  })[] | undefined;
1008
- purpose?: string | undefined;
1009
1036
  labels?: Record<string, string> | undefined;
1010
1037
  durationSec?: number | undefined;
1011
1038
  }, {
1012
1039
  audio: string | Uint8Array<ArrayBuffer>;
1013
1040
  language?: string | undefined;
1041
+ purpose?: string | undefined;
1014
1042
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
1015
1043
  override?: {
1016
1044
  provider?: string | undefined;
@@ -1022,7 +1050,6 @@ declare const transcribeInputSchema: z.ZodObject<{
1022
1050
  model: string;
1023
1051
  transport: "http" | "subprocess";
1024
1052
  })[] | undefined;
1025
- purpose?: string | undefined;
1026
1053
  labels?: Record<string, string> | undefined;
1027
1054
  durationSec?: number | undefined;
1028
1055
  }>;
@@ -1063,6 +1090,7 @@ declare const ocrInputSchema: z.ZodObject<{
1063
1090
  }, "strip", z.ZodTypeAny, {
1064
1091
  document: string | Uint8Array<ArrayBuffer>;
1065
1092
  mimeType?: string | undefined;
1093
+ purpose?: string | undefined;
1066
1094
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
1067
1095
  override?: {
1068
1096
  provider?: string | undefined;
@@ -1074,11 +1102,11 @@ declare const ocrInputSchema: z.ZodObject<{
1074
1102
  model: string;
1075
1103
  transport: "http" | "subprocess";
1076
1104
  })[] | undefined;
1077
- purpose?: string | undefined;
1078
1105
  labels?: Record<string, string> | undefined;
1079
1106
  }, {
1080
1107
  document: string | Uint8Array<ArrayBuffer>;
1081
1108
  mimeType?: string | undefined;
1109
+ purpose?: string | undefined;
1082
1110
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
1083
1111
  override?: {
1084
1112
  provider?: string | undefined;
@@ -1090,7 +1118,6 @@ declare const ocrInputSchema: z.ZodObject<{
1090
1118
  model: string;
1091
1119
  transport: "http" | "subprocess";
1092
1120
  })[] | undefined;
1093
- purpose?: string | undefined;
1094
1121
  labels?: Record<string, string> | undefined;
1095
1122
  }>;
1096
1123
  declare const moderationInputSchema: z.ZodObject<{
@@ -1126,6 +1153,7 @@ declare const moderationInputSchema: z.ZodObject<{
1126
1153
  input: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
1127
1154
  }, "strip", z.ZodTypeAny, {
1128
1155
  input: string | string[];
1156
+ purpose?: string | undefined;
1129
1157
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
1130
1158
  override?: {
1131
1159
  provider?: string | undefined;
@@ -1137,10 +1165,10 @@ declare const moderationInputSchema: z.ZodObject<{
1137
1165
  model: string;
1138
1166
  transport: "http" | "subprocess";
1139
1167
  })[] | undefined;
1140
- purpose?: string | undefined;
1141
1168
  labels?: Record<string, string> | undefined;
1142
1169
  }, {
1143
1170
  input: string | string[];
1171
+ purpose?: string | undefined;
1144
1172
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
1145
1173
  override?: {
1146
1174
  provider?: string | undefined;
@@ -1152,7 +1180,6 @@ declare const moderationInputSchema: z.ZodObject<{
1152
1180
  model: string;
1153
1181
  transport: "http" | "subprocess";
1154
1182
  })[] | undefined;
1155
- purpose?: string | undefined;
1156
1183
  labels?: Record<string, string> | undefined;
1157
1184
  }>;
1158
1185
  declare const podcastInputSchema: z.ZodObject<{
@@ -1203,6 +1230,7 @@ declare const podcastInputSchema: z.ZodObject<{
1203
1230
  speaker: string;
1204
1231
  }[];
1205
1232
  voices: Record<string, string>;
1233
+ purpose?: string | undefined;
1206
1234
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
1207
1235
  override?: {
1208
1236
  provider?: string | undefined;
@@ -1214,7 +1242,6 @@ declare const podcastInputSchema: z.ZodObject<{
1214
1242
  model: string;
1215
1243
  transport: "http" | "subprocess";
1216
1244
  })[] | undefined;
1217
- purpose?: string | undefined;
1218
1245
  labels?: Record<string, string> | undefined;
1219
1246
  format?: string | undefined;
1220
1247
  }, {
@@ -1223,6 +1250,7 @@ declare const podcastInputSchema: z.ZodObject<{
1223
1250
  speaker: string;
1224
1251
  }[];
1225
1252
  voices: Record<string, string>;
1253
+ purpose?: string | undefined;
1226
1254
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
1227
1255
  override?: {
1228
1256
  provider?: string | undefined;
@@ -1234,7 +1262,6 @@ declare const podcastInputSchema: z.ZodObject<{
1234
1262
  model: string;
1235
1263
  transport: "http" | "subprocess";
1236
1264
  })[] | undefined;
1237
- purpose?: string | undefined;
1238
1265
  labels?: Record<string, string> | undefined;
1239
1266
  format?: string | undefined;
1240
1267
  }>;
@@ -1273,6 +1300,7 @@ declare const ttsInputSchema: z.ZodObject<{
1273
1300
  }, "strip", z.ZodTypeAny, {
1274
1301
  text: string;
1275
1302
  voice: string;
1303
+ purpose?: string | undefined;
1276
1304
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
1277
1305
  override?: {
1278
1306
  provider?: string | undefined;
@@ -1284,11 +1312,11 @@ declare const ttsInputSchema: z.ZodObject<{
1284
1312
  model: string;
1285
1313
  transport: "http" | "subprocess";
1286
1314
  })[] | undefined;
1287
- purpose?: string | undefined;
1288
1315
  labels?: Record<string, string> | undefined;
1289
1316
  }, {
1290
1317
  text: string;
1291
1318
  voice: string;
1319
+ purpose?: string | undefined;
1292
1320
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
1293
1321
  override?: {
1294
1322
  provider?: string | undefined;
@@ -1300,7 +1328,6 @@ declare const ttsInputSchema: z.ZodObject<{
1300
1328
  model: string;
1301
1329
  transport: "http" | "subprocess";
1302
1330
  })[] | undefined;
1303
- purpose?: string | undefined;
1304
1331
  labels?: Record<string, string> | undefined;
1305
1332
  }>;
1306
1333
  declare const aiConfigSchema: z.ZodObject<{
@@ -1387,6 +1414,15 @@ interface AiClient {
1387
1414
  podcast(input: PodcastInput): Promise<PodcastResult>;
1388
1415
  /** Single-voice TTS (F020.4) — text → audio. `voice` = curated name or voiceId. ElevenLabs. */
1389
1416
  tts(input: TtsInput): Promise<PodcastResult>;
1417
+ /** Batch (F016.1) — submit many chat requests for async (≤24h) processing at 50% cost. Mistral. */
1418
+ batch: {
1419
+ submit(input: {
1420
+ requests: BatchRequestItem[];
1421
+ override?: TierSpec;
1422
+ }): Promise<BatchJob>;
1423
+ status(jobId: string, override?: TierSpec): Promise<BatchJob>;
1424
+ results(jobId: string, override?: TierSpec): Promise<BatchResultItem[]>;
1425
+ };
1390
1426
  /** Prompt-contract capabilities (F5.5) layered on chat/vision. */
1391
1427
  contracts: Contracts;
1392
1428
  }
@@ -1508,8 +1544,8 @@ declare const falStubAdapter: ProviderAdapter;
1508
1544
  * wires the live adapters. */
1509
1545
  declare const stubProviders: Record<string, ProviderAdapter>;
1510
1546
 
1511
- declare const VERSION: "0.8.0";
1512
- declare const SDK_TAG: "@broberg/ai-sdk@0.8.0";
1547
+ declare const VERSION: "0.9.0";
1548
+ declare const SDK_TAG: "@broberg/ai-sdk@0.9.0";
1513
1549
 
1514
1550
  /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
1515
1551
  * per-call override. Model IDs are current at scaffold time; callers pin their
@@ -1702,4 +1738,4 @@ interface StreamTransportRequest extends TransportRequest {
1702
1738
  */
1703
1739
  declare function streamTransport(req: StreamTransportRequest): AsyncIterable<string>;
1704
1740
 
1705
- export { type AiClient, type AiConfig, type BudgetConfig, BudgetExceededError, BudgetGuard, type BudgetStore, type CallOptions, type Capability, type ChatInput, type ChatRequest, type ChatResult, type ChatStreamEvent, type ClassifyInput, type ClassifyResult, type ContentPart, type Contracts, type CostSink, type CostSummary, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DialogueRequest, type DialogueTurn, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, type EmbeddingRequest, type EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type HttpResponse, type ImageInput, type ImageRequest, type ImageResult, type Message, type MockupInput, type MockupResult, type ModerationInput, type ModerationItem, type ModerationRequest, type ModerationResult, type OcrInput, type OcrPage, type OcrRequest, type OcrResult, type OpenAICompatibleConfig, type PodcastInput, type PodcastResult, type PricingEntry, type ProviderAdapter, type RerankInput, type RerankResult, type Role, SDK_TAG, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, type Tier, type TierSpec, type Tool, type ToolCall, type TranscribeInput, type TranscribeRequest, type TranscribeResult, type TranslateInput, type TranslateResult, type Transport, type TransportRequest, type TransportResponse, type TtsInput, type TtsRequest, type UpmetricsSinkConfig, type Usage, VERSION, type VideoInput, type VisionInput, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, chatInputSchema, computeCost, createAI, deepinfraAdapter, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, makeContracts, makeOpenAICompatibleAdapter, messageSchema, mistralAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, resolveTier, resolveVoice, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, upmetricsSink, visionInputSchema };
1741
+ export { type AiClient, type AiConfig, type BatchJob, type BatchRequestItem, type BatchResultItem, type BudgetConfig, BudgetExceededError, BudgetGuard, type BudgetStore, type CallOptions, type Capability, type ChatInput, type ChatRequest, type ChatResult, type ChatStreamEvent, type ClassifyInput, type ClassifyResult, type ContentPart, type Contracts, type CostSink, type CostSummary, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DialogueRequest, type DialogueTurn, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, type EmbeddingRequest, type EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type HttpResponse, type ImageInput, type ImageRequest, type ImageResult, type Message, type MockupInput, type MockupResult, type ModerationInput, type ModerationItem, type ModerationRequest, type ModerationResult, type OcrInput, type OcrPage, type OcrRequest, type OcrResult, type OpenAICompatibleConfig, type PodcastInput, type PodcastResult, type PricingEntry, type ProviderAdapter, type RerankInput, type RerankResult, type Role, SDK_TAG, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, type Tier, type TierSpec, type Tool, type ToolCall, type TranscribeInput, type TranscribeRequest, type TranscribeResult, type TranslateInput, type TranslateResult, type Transport, type TransportRequest, type TransportResponse, type TtsInput, type TtsRequest, type UpmetricsSinkConfig, type Usage, VERSION, type VideoInput, type VisionInput, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, chatInputSchema, computeCost, createAI, deepinfraAdapter, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, makeContracts, makeOpenAICompatibleAdapter, messageSchema, mistralAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, resolveTier, resolveVoice, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, upmetricsSink, visionInputSchema };
package/dist/index.js CHANGED
@@ -280,7 +280,10 @@ var PRICING = {
280
280
  "mistral:codestral-latest": { inputPer1M: 0.3, outputPer1M: 0.9, version: MS },
281
281
  "mistral:open-mistral-nemo": { inputPer1M: 0.15, outputPer1M: 0.15, version: MS },
282
282
  // Moderation (F016.4) — per input token; output 0. (OCR is per-page in the adapter.)
283
- "mistral:mistral-moderation-latest": { inputPer1M: 0.1, outputPer1M: 0, version: MS }
283
+ "mistral:mistral-moderation-latest": { inputPer1M: 0.1, outputPer1M: 0, version: MS },
284
+ // Embeddings (F016.5) — per input token.
285
+ "mistral:mistral-embed": { inputPer1M: 0.1, outputPer1M: 0, version: MS },
286
+ "mistral:codestral-embed": { inputPer1M: 0.15, outputPer1M: 0, version: MS }
284
287
  };
285
288
  function getPrice(provider, model) {
286
289
  const exact = PRICING[`${provider}:${model}`];
@@ -1028,6 +1031,11 @@ function openrouterAdapter(config = {}) {
1028
1031
 
1029
1032
  // src/providers/mistral.ts
1030
1033
  var MISTRAL_OCR_PRICE_PER_PAGE = 2e-3;
1034
+ var VOXTRAL_PRICE_PER_MIN = {
1035
+ "voxtral-mini-latest": 2e-3,
1036
+ "voxtral-mini-2507": 2e-3,
1037
+ "voxtral-mini-2602": 2e-3
1038
+ };
1031
1039
  function mistralAdapter(config = {}) {
1032
1040
  const baseUrl = config.baseUrl ?? "https://api.mistral.ai/v1";
1033
1041
  const base = makeOpenAICompatibleAdapter({ name: "mistral", baseUrl, apiKey: config.apiKey });
@@ -1097,7 +1105,102 @@ function mistralAdapter(config = {}) {
1097
1105
  });
1098
1106
  return { results, usage };
1099
1107
  }
1100
- return { ...base, ocr, moderate };
1108
+ async function embedding(req) {
1109
+ const res = await fetchImpl(`${baseUrl}/embeddings`, {
1110
+ method: "POST",
1111
+ headers: { "content-type": "application/json", authorization: `Bearer ${key()}` },
1112
+ body: JSON.stringify({ model: req.spec.model, input: req.input })
1113
+ });
1114
+ if (!res.ok) {
1115
+ const body = await res.text().catch(() => "");
1116
+ throw new Error(`mistral embeddings ${res.status}: ${body.slice(0, 300)}`);
1117
+ }
1118
+ const data = await res.json();
1119
+ const vectors = (data.data ?? []).map((d) => d.embedding);
1120
+ const usage = freshUsage({
1121
+ provider: "mistral",
1122
+ model: req.spec.model,
1123
+ transport: "http",
1124
+ capability: "embedding",
1125
+ inputTokens: data.usage?.prompt_tokens ?? data.usage?.total_tokens ?? 0,
1126
+ outputTokens: 0
1127
+ });
1128
+ return { vectors, usage };
1129
+ }
1130
+ async function transcribe(req) {
1131
+ const form = new FormData();
1132
+ form.append("file", new Blob([req.audio]), "audio");
1133
+ form.append("model", req.spec.model);
1134
+ if (req.language) form.append("language", req.language);
1135
+ const res = await fetchImpl(`${baseUrl}/audio/transcriptions`, {
1136
+ method: "POST",
1137
+ headers: { authorization: `Bearer ${key()}` },
1138
+ body: form
1139
+ });
1140
+ if (!res.ok) {
1141
+ const body = await res.text().catch(() => "");
1142
+ throw new Error(`mistral transcribe ${res.status}: ${body.slice(0, 300)}`);
1143
+ }
1144
+ const data = await res.json();
1145
+ const usage = freshUsage({
1146
+ provider: "mistral",
1147
+ model: req.spec.model,
1148
+ transport: "http",
1149
+ capability: "transcribe",
1150
+ inputTokens: 0,
1151
+ outputTokens: 0
1152
+ });
1153
+ if (req.durationSec !== void 0) {
1154
+ usage.costUsd = req.durationSec / 60 * (VOXTRAL_PRICE_PER_MIN[req.spec.model] ?? 0);
1155
+ }
1156
+ return { text: data.text ?? "", usage };
1157
+ }
1158
+ async function batchSubmit(req) {
1159
+ const jsonl = req.items.map(
1160
+ (it) => JSON.stringify({
1161
+ custom_id: it.customId,
1162
+ body: { model: req.spec.model, messages: [{ role: "user", content: it.prompt }] }
1163
+ })
1164
+ ).join("\n");
1165
+ const form = new FormData();
1166
+ form.append("purpose", "batch");
1167
+ form.append("file", new Blob([jsonl], { type: "application/jsonl" }), "batch.jsonl");
1168
+ const up = await fetchImpl(`${baseUrl}/files`, {
1169
+ method: "POST",
1170
+ headers: { authorization: `Bearer ${key()}` },
1171
+ body: form
1172
+ });
1173
+ if (!up.ok) throw new Error(`mistral batch upload ${up.status}: ${(await up.text().catch(() => "")).slice(0, 200)}`);
1174
+ const fileId = (await up.json()).id;
1175
+ const job = await fetchImpl(`${baseUrl}/batch/jobs`, {
1176
+ method: "POST",
1177
+ headers: { "content-type": "application/json", authorization: `Bearer ${key()}` },
1178
+ body: JSON.stringify({ input_files: [fileId], model: req.spec.model, endpoint: "/v1/chat/completions" })
1179
+ });
1180
+ if (!job.ok) throw new Error(`mistral batch job ${job.status}: ${(await job.text().catch(() => "")).slice(0, 200)}`);
1181
+ const data = await job.json();
1182
+ return { jobId: data.id ?? "", status: data.status ?? "queued", total: data.total_requests };
1183
+ }
1184
+ async function batchStatus(req) {
1185
+ const res = await fetchImpl(`${baseUrl}/batch/jobs/${req.jobId}`, { headers: { authorization: `Bearer ${key()}` } });
1186
+ if (!res.ok) throw new Error(`mistral batch status ${res.status}`);
1187
+ const d = await res.json();
1188
+ return { jobId: d.id ?? req.jobId, status: d.status ?? "unknown", total: d.total_requests, completed: d.succeeded_requests };
1189
+ }
1190
+ async function batchResults(req) {
1191
+ const job = await fetchImpl(`${baseUrl}/batch/jobs/${req.jobId}`, { headers: { authorization: `Bearer ${key()}` } });
1192
+ if (!job.ok) throw new Error(`mistral batch results ${job.status}`);
1193
+ const outputFile = (await job.json()).output_file;
1194
+ if (!outputFile) throw new Error("mistral batch: job has no output_file yet (not finished)");
1195
+ const content = await fetchImpl(`${baseUrl}/files/${outputFile}/content`, { headers: { authorization: `Bearer ${key()}` } });
1196
+ if (!content.ok) throw new Error(`mistral batch download ${content.status}`);
1197
+ const lines = (await content.text()).trim().split("\n").filter(Boolean);
1198
+ return lines.map((line) => {
1199
+ const row = JSON.parse(line);
1200
+ return { customId: row.custom_id ?? "", text: row.response?.body?.choices?.[0]?.message?.content ?? "" };
1201
+ });
1202
+ }
1203
+ return { ...base, ocr, moderate, embedding, transcribe, batchSubmit, batchStatus, batchResults };
1101
1204
  }
1102
1205
 
1103
1206
  // src/providers/elevenlabs.ts
@@ -1618,6 +1721,7 @@ var DEFAULT_OCR_SPEC = { provider: "mistral", model: "mistral-ocr-latest", trans
1618
1721
  var DEFAULT_MODERATION_SPEC = { provider: "mistral", model: "mistral-moderation-latest", transport: "http" };
1619
1722
  var DEFAULT_PODCAST_SPEC = { provider: "elevenlabs", model: "eleven_v3", transport: "http" };
1620
1723
  var DEFAULT_TTS_SPEC = { provider: "elevenlabs", model: "eleven_multilingual_v2", transport: "http" };
1724
+ var DEFAULT_BATCH_SPEC = { provider: "mistral", model: "mistral-small-latest", transport: "http" };
1621
1725
  function createAI(config = {}) {
1622
1726
  const cfg = aiConfigSchema.parse(config);
1623
1727
  const providers = cfg.providers ?? defaultProviders;
@@ -1977,6 +2081,26 @@ function createAI(config = {}) {
1977
2081
  }
1978
2082
  });
1979
2083
  },
2084
+ batch: {
2085
+ async submit(input) {
2086
+ const spec = { ...DEFAULT_BATCH_SPEC, ...input.override };
2087
+ const adapter = pickProvider(spec.provider);
2088
+ if (!adapter.batchSubmit) throw new Error(`createAI: provider "${spec.provider}" does not support batch`);
2089
+ return adapter.batchSubmit({ items: input.requests, spec });
2090
+ },
2091
+ async status(jobId, override) {
2092
+ const spec = { ...DEFAULT_BATCH_SPEC, ...override };
2093
+ const adapter = pickProvider(spec.provider);
2094
+ if (!adapter.batchStatus) throw new Error(`createAI: provider "${spec.provider}" does not support batch`);
2095
+ return adapter.batchStatus({ jobId, spec });
2096
+ },
2097
+ async results(jobId, override) {
2098
+ const spec = { ...DEFAULT_BATCH_SPEC, ...override };
2099
+ const adapter = pickProvider(spec.provider);
2100
+ if (!adapter.batchResults) throw new Error(`createAI: provider "${spec.provider}" does not support batch`);
2101
+ return adapter.batchResults({ jobId, spec });
2102
+ }
2103
+ },
1980
2104
  // Replaced below with the real prompt-contracts (needs the client itself).
1981
2105
  contracts: void 0
1982
2106
  };
@@ -2065,8 +2189,8 @@ var stubProviders = {
2065
2189
  };
2066
2190
 
2067
2191
  // src/version.ts
2068
- var VERSION = "0.8.0";
2069
- var SDK_TAG = "@broberg/ai-sdk@0.8.0";
2192
+ var VERSION = "0.9.0";
2193
+ var SDK_TAG = "@broberg/ai-sdk@0.9.0";
2070
2194
 
2071
2195
  // src/cost/budget-store.ts
2072
2196
  function sqliteBudgetStore(config) {