@ai-sdk/mistral 4.0.68 → 4.0.69

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.
@@ -13,6 +13,9 @@ import type {
13
13
  SharedV4Warning,
14
14
  } from '@ai-sdk/provider';
15
15
  import {
16
+ lazySchema,
17
+ zodSchema,
18
+ type InferSchema,
16
19
  combineHeaders,
17
20
  createEventSourceResponseHandler,
18
21
  createJsonResponseHandler,
@@ -389,7 +392,7 @@ export class MistralConversationLanguageModel implements LanguageModelV4 {
389
392
  return {
390
393
  stream: response.pipeThrough(
391
394
  new TransformStream<
392
- ParseResult<z.infer<typeof mistralConversationChunkSchema>>,
395
+ ParseResult<InferSchema<typeof mistralConversationChunkSchema>>,
393
396
  LanguageModelV4StreamPart
394
397
  >({
395
398
  start(controller) {
@@ -573,7 +576,7 @@ function createContentConverter({
573
576
  return {
574
577
  toolNameMapping,
575
578
  convertChunk(
576
- chunk: z.infer<typeof mistralConversationContentSchema>,
579
+ chunk: z.infer<ReturnType<typeof mistralConversationContentSchema>>,
577
580
  ): Array<
578
581
  LanguageModelV4Text | LanguageModelV4Reasoning | LanguageModelV4Source
579
582
  > {
@@ -604,7 +607,9 @@ function createContentConverter({
604
607
  }
605
608
  },
606
609
  convertTool(
607
- output: z.infer<typeof mistralConversationToolExecutionSchema>,
610
+ output: z.infer<
611
+ ReturnType<typeof mistralConversationToolExecutionSchema>
612
+ >,
608
613
  ): [LanguageModelV4ToolCall, LanguageModelV4ToolResult] {
609
614
  const toolName = toolNameMapping.toCustomToolName(output.name);
610
615
  return [
@@ -633,98 +638,110 @@ function createContentConverter({
633
638
  };
634
639
  }
635
640
 
636
- const mistralConversationContentSchema = z.discriminatedUnion('type', [
637
- z.object({ type: z.literal('text'), text: z.string() }),
641
+ const mistralConversationContentSchema = () =>
642
+ z.discriminatedUnion('type', [
643
+ z.object({ type: z.literal('text'), text: z.string() }),
644
+ z.object({
645
+ type: z.literal('thinking'),
646
+ thinking: z.array(
647
+ z.object({ type: z.literal('text'), text: z.string() }),
648
+ ),
649
+ }),
650
+ z.object({
651
+ type: z.literal('tool_reference'),
652
+ tool: z.string().nullish(),
653
+ title: z.string().nullish(),
654
+ url: z.string().nullish(),
655
+ }),
656
+ ]);
657
+ const mistralConversationMessageContentSchema = () =>
658
+ z.union([z.string(), z.array(mistralConversationContentSchema())]);
659
+ const mistralConversationToolExecutionSchema = () =>
638
660
  z.object({
639
- type: z.literal('thinking'),
640
- thinking: z.array(z.object({ type: z.literal('text'), text: z.string() })),
641
- }),
661
+ type: z.literal('tool.execution'),
662
+ id: z.string(),
663
+ name: z.string(),
664
+ arguments: z.string(),
665
+ function: z.string().nullish(),
666
+ info: z.record(z.string(), z.json()).nullish(),
667
+ });
668
+ const mistralConversationFunctionCallSchema = () =>
642
669
  z.object({
643
- type: z.literal('tool_reference'),
644
- tool: z.string().nullish(),
645
- title: z.string().nullish(),
646
- url: z.string().nullish(),
647
- }),
648
- ]);
649
- const mistralConversationMessageContentSchema = z.union([
650
- z.string(),
651
- z.array(mistralConversationContentSchema),
652
- ]);
653
- const mistralConversationToolExecutionSchema = z.object({
654
- type: z.literal('tool.execution'),
655
- id: z.string(),
656
- name: z.string(),
657
- arguments: z.string(),
658
- function: z.string().nullish(),
659
- info: z.record(z.string(), z.json()).nullish(),
660
- });
661
- const mistralConversationFunctionCallSchema = z.object({
662
- type: z.literal('function.call'),
663
- tool_call_id: z.string(),
664
- name: z.string(),
665
- arguments: z.union([z.string(), z.record(z.string(), z.json())]),
666
- });
667
- const mistralConversationUsageSchema = mistralUsageSchema.extend({
668
- prompt_tokens: z.number().default(0),
669
- completion_tokens: z.number().default(0),
670
- total_tokens: z.number().default(0),
671
- });
672
- const mistralConversationResponseSchema = z.object({
673
- conversation_id: z.string(),
674
- outputs: z.array(
670
+ type: z.literal('function.call'),
671
+ tool_call_id: z.string(),
672
+ name: z.string(),
673
+ arguments: z.union([z.string(), z.record(z.string(), z.json())]),
674
+ });
675
+ const mistralConversationUsageSchema = () =>
676
+ mistralUsageSchema.extend({
677
+ prompt_tokens: z.number().default(0),
678
+ completion_tokens: z.number().default(0),
679
+ total_tokens: z.number().default(0),
680
+ });
681
+ const mistralConversationResponseSchema = lazySchema(() =>
682
+ zodSchema(
683
+ z.object({
684
+ conversation_id: z.string(),
685
+ outputs: z.array(
686
+ z.discriminatedUnion('type', [
687
+ mistralConversationToolExecutionSchema(),
688
+ mistralConversationFunctionCallSchema(),
689
+ z.object({
690
+ type: z.literal('message.output'),
691
+ content: mistralConversationMessageContentSchema(),
692
+ model: z.string().nullish(),
693
+ }),
694
+ ]),
695
+ ),
696
+ usage: mistralConversationUsageSchema().nullish(),
697
+ }),
698
+ ),
699
+ );
700
+ const mistralConversationChunkSchema = lazySchema(() =>
701
+ zodSchema(
675
702
  z.discriminatedUnion('type', [
676
- mistralConversationToolExecutionSchema,
677
- mistralConversationFunctionCallSchema,
678
703
  z.object({
679
- type: z.literal('message.output'),
680
- content: mistralConversationMessageContentSchema,
704
+ type: z.literal('conversation.response.started'),
705
+ conversation_id: z.string(),
706
+ created_at: z.string().nullish(),
707
+ }),
708
+ z.object({
709
+ type: z.literal('conversation.response.done'),
710
+ usage: mistralConversationUsageSchema().nullish(),
711
+ }),
712
+ z.object({
713
+ type: z.literal('conversation.response.error'),
714
+ message: z.string(),
715
+ code: z.number(),
716
+ }),
717
+ z.object({
718
+ type: z.literal('message.output.delta'),
719
+ id: z.string(),
720
+ content_index: z.number().nullish(),
721
+ content: z.union([z.string(), mistralConversationContentSchema()]),
681
722
  model: z.string().nullish(),
682
723
  }),
724
+ z.object({
725
+ type: z.literal('function.call.delta'),
726
+ tool_call_id: z.string(),
727
+ name: z.string(),
728
+ arguments: z.string(),
729
+ output_index: z.number().nullish(),
730
+ }),
731
+ z.object({
732
+ type: z.enum(['tool.execution.started', 'tool.execution.delta']),
733
+ id: z.string(),
734
+ name: z.string(),
735
+ arguments: z.string(),
736
+ function: z.string().nullish(),
737
+ }),
738
+ z.object({
739
+ type: z.literal('tool.execution.done'),
740
+ id: z.string(),
741
+ name: z.string(),
742
+ function: z.string().nullish(),
743
+ info: z.record(z.string(), z.json()).nullish(),
744
+ }),
683
745
  ]),
684
746
  ),
685
- usage: mistralConversationUsageSchema.nullish(),
686
- });
687
- const mistralConversationChunkSchema = z.discriminatedUnion('type', [
688
- z.object({
689
- type: z.literal('conversation.response.started'),
690
- conversation_id: z.string(),
691
- created_at: z.string().nullish(),
692
- }),
693
- z.object({
694
- type: z.literal('conversation.response.done'),
695
- usage: mistralConversationUsageSchema.nullish(),
696
- }),
697
- z.object({
698
- type: z.literal('conversation.response.error'),
699
- message: z.string(),
700
- code: z.number(),
701
- }),
702
- z.object({
703
- type: z.literal('message.output.delta'),
704
- id: z.string(),
705
- content_index: z.number().nullish(),
706
- content: z.union([z.string(), mistralConversationContentSchema]),
707
- model: z.string().nullish(),
708
- }),
709
- z.object({
710
- type: z.literal('function.call.delta'),
711
- tool_call_id: z.string(),
712
- name: z.string(),
713
- arguments: z.string(),
714
- output_index: z.number().nullish(),
715
- }),
716
- z.object({
717
- type: z.enum(['tool.execution.started', 'tool.execution.delta']),
718
- id: z.string(),
719
- name: z.string(),
720
- arguments: z.string(),
721
- function: z.string().nullish(),
722
- }),
723
- z.object({
724
- type: z.literal('tool.execution.done'),
725
- id: z.string(),
726
- name: z.string(),
727
- function: z.string().nullish(),
728
- info: z.record(z.string(), z.json()).nullish(),
729
- }),
730
- ]);
747
+ );
@@ -3,6 +3,8 @@ import {
3
3
  type EmbeddingModelV4,
4
4
  } from '@ai-sdk/provider';
5
5
  import {
6
+ lazySchema,
7
+ zodSchema,
6
8
  combineHeaders,
7
9
  createJsonResponseHandler,
8
10
  parseProviderOptions,
@@ -121,7 +123,11 @@ export class MistralEmbeddingModel implements EmbeddingModelV4 {
121
123
 
122
124
  // minimal version of the schema, focussed on what is needed for the implementation
123
125
  // this approach limits breakages when the API changes and increases efficiency
124
- const MistralTextEmbeddingResponseSchema = z.object({
125
- data: z.array(z.object({ embedding: z.array(z.number()) })),
126
- usage: z.object({ prompt_tokens: z.number() }).nullish(),
127
- });
126
+ const MistralTextEmbeddingResponseSchema = lazySchema(() =>
127
+ zodSchema(
128
+ z.object({
129
+ data: z.array(z.object({ embedding: z.array(z.number()) })),
130
+ usage: z.object({ prompt_tokens: z.number() }).nullish(),
131
+ }),
132
+ ),
133
+ );
@@ -1,15 +1,24 @@
1
- import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ createJsonErrorResponseHandler,
6
+ } from '@ai-sdk/provider-utils';
2
7
  import { z } from 'zod/v4';
3
8
 
4
- const mistralErrorDataSchema = z.object({
5
- object: z.literal('error'),
6
- message: z.string(),
7
- type: z.string(),
8
- param: z.string().nullable(),
9
- code: z.string().nullable(),
10
- });
9
+ const mistralErrorDataSchema = lazySchema(() =>
10
+ zodSchema(
11
+ z.object({
12
+ object: z.literal('error'),
13
+ message: z.string(),
14
+ type: z.string(),
15
+ param: z.string().nullable(),
16
+ code: z.string().nullable(),
17
+ }),
18
+ ),
19
+ );
11
20
 
12
- export type MistralErrorData = z.infer<typeof mistralErrorDataSchema>;
21
+ export type MistralErrorData = InferSchema<typeof mistralErrorDataSchema>;
13
22
 
14
23
  export const mistralFailedResponseHandler = createJsonErrorResponseHandler({
15
24
  errorSchema: mistralErrorDataSchema,
@@ -1,3 +1,8 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
1
6
  import { z } from 'zod/v4';
2
7
 
3
8
  export type MistralSpeechModelId =
@@ -5,15 +10,19 @@ export type MistralSpeechModelId =
5
10
  | 'voxtral-mini-tts-latest'
6
11
  | (string & {});
7
12
 
8
- export const mistralSpeechModelOptions = z.object({
9
- /**
10
- * Base64-encoded reference audio for one-off voice cloning.
11
- *
12
- * When provided, this takes precedence over the standard `voice` option.
13
- */
14
- refAudio: z.string().min(1).optional(),
15
- });
13
+ export const mistralSpeechModelOptions = lazySchema(() =>
14
+ zodSchema(
15
+ z.object({
16
+ /**
17
+ * Base64-encoded reference audio for one-off voice cloning.
18
+ *
19
+ * When provided, this takes precedence over the standard `voice` option.
20
+ */
21
+ refAudio: z.string().min(1).optional(),
22
+ }),
23
+ ),
24
+ );
16
25
 
17
- export type MistralSpeechModelOptions = z.infer<
26
+ export type MistralSpeechModelOptions = InferSchema<
18
27
  typeof mistralSpeechModelOptions
19
28
  >;
@@ -1,5 +1,7 @@
1
1
  import type { SharedV4Warning, SpeechModelV4 } from '@ai-sdk/provider';
2
2
  import {
3
+ lazySchema,
4
+ zodSchema,
3
5
  combineHeaders,
4
6
  createJsonResponseHandler,
5
7
  parseProviderOptions,
@@ -174,6 +176,10 @@ export class MistralSpeechModel implements SpeechModelV4 {
174
176
  }
175
177
  }
176
178
 
177
- const mistralSpeechResponseSchema = z.object({
178
- audio_data: z.string(),
179
- });
179
+ const mistralSpeechResponseSchema = lazySchema(() =>
180
+ zodSchema(
181
+ z.object({
182
+ audio_data: z.string(),
183
+ }),
184
+ ),
185
+ );
@@ -5,6 +5,8 @@ import {
5
5
  type TranscriptionModelV4,
6
6
  } from '@ai-sdk/provider';
7
7
  import {
8
+ lazySchema,
9
+ zodSchema,
8
10
  combineHeaders,
9
11
  convertBase64ToUint8Array,
10
12
  createJsonResponseHandler,
@@ -229,29 +231,33 @@ function appendFormValue(
229
231
  formData.append(key, String(value));
230
232
  }
231
233
 
232
- const mistralTranscriptionResponseSchema = z.object({
233
- model: z.string(),
234
- text: z.string(),
235
- language: z.string().nullish(),
236
- segments: z
237
- .array(
238
- z.object({
239
- type: z.literal('transcription_segment').nullish(),
240
- text: z.string(),
241
- start: z.number(),
242
- end: z.number(),
243
- score: z.number().nullish(),
244
- speaker_id: z.string().nullish(),
245
- }),
246
- )
247
- .nullish(),
248
- usage: z
249
- .object({
250
- prompt_tokens: z.number().nullish(),
251
- completion_tokens: z.number().nullish(),
252
- total_tokens: z.number().nullish(),
253
- prompt_audio_seconds: z.number().nullish(),
254
- request_count: z.number().nullish(),
255
- })
256
- .nullish(),
257
- });
234
+ const mistralTranscriptionResponseSchema = lazySchema(() =>
235
+ zodSchema(
236
+ z.object({
237
+ model: z.string(),
238
+ text: z.string(),
239
+ language: z.string().nullish(),
240
+ segments: z
241
+ .array(
242
+ z.object({
243
+ type: z.literal('transcription_segment').nullish(),
244
+ text: z.string(),
245
+ start: z.number(),
246
+ end: z.number(),
247
+ score: z.number().nullish(),
248
+ speaker_id: z.string().nullish(),
249
+ }),
250
+ )
251
+ .nullish(),
252
+ usage: z
253
+ .object({
254
+ prompt_tokens: z.number().nullish(),
255
+ completion_tokens: z.number().nullish(),
256
+ total_tokens: z.number().nullish(),
257
+ prompt_audio_seconds: z.number().nullish(),
258
+ request_count: z.number().nullish(),
259
+ })
260
+ .nullish(),
261
+ }),
262
+ ),
263
+ );