@ai-sdk/mistral 3.0.74 → 3.0.76

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.
@@ -10,6 +10,9 @@ import {
10
10
  type SharedV3Warning,
11
11
  } from '@ai-sdk/provider';
12
12
  import {
13
+ lazySchema,
14
+ zodSchema,
15
+ type InferSchema,
13
16
  combineHeaders,
14
17
  createEventSourceResponseHandler,
15
18
  createJsonResponseHandler,
@@ -300,7 +303,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
300
303
  return {
301
304
  stream: response.pipeThrough(
302
305
  new TransformStream<
303
- ParseResult<z.infer<typeof mistralChatChunkSchema>>,
306
+ ParseResult<InferSchema<typeof mistralChatChunkSchema>>,
304
307
  LanguageModelV3StreamPart
305
308
  >({
306
309
  start(controller) {
@@ -506,7 +509,9 @@ function extractReasoningContent(
506
509
  .join('');
507
510
  }
508
511
 
509
- function extractTextContent(content: z.infer<typeof mistralContentSchema>) {
512
+ function extractTextContent(
513
+ content: z.infer<ReturnType<typeof mistralContentSchema>>,
514
+ ) {
510
515
  if (typeof content === 'string') {
511
516
  return content;
512
517
  }
@@ -539,98 +544,110 @@ function extractTextContent(content: z.infer<typeof mistralContentSchema>) {
539
544
  return textContent.length ? textContent.join('') : undefined;
540
545
  }
541
546
 
542
- const mistralContentSchema = z
543
- .union([
544
- z.string(),
545
- z.array(
546
- z.discriminatedUnion('type', [
547
- z.object({
548
- type: z.literal('text'),
549
- text: z.string(),
550
- }),
551
- z.object({
552
- type: z.literal('image_url'),
553
- image_url: z.union([
554
- z.string(),
555
- z.object({
556
- url: z.string(),
557
- detail: z.string().nullable(),
558
- }),
559
- ]),
560
- }),
561
- z.object({
562
- type: z.literal('reference'),
563
- reference_ids: z.array(z.union([z.string(), z.number()])),
564
- }),
565
- z.object({
566
- type: z.literal('thinking'),
567
- thinking: z.array(
568
- z.object({
569
- type: z.literal('text'),
570
- text: z.string(),
571
- }),
572
- ),
573
- }),
574
- ]),
575
- ),
576
- ])
577
- .nullish();
547
+ const mistralContentSchema = () =>
548
+ z
549
+ .union([
550
+ z.string(),
551
+ z.array(
552
+ z.discriminatedUnion('type', [
553
+ z.object({
554
+ type: z.literal('text'),
555
+ text: z.string(),
556
+ }),
557
+ z.object({
558
+ type: z.literal('image_url'),
559
+ image_url: z.union([
560
+ z.string(),
561
+ z.object({
562
+ url: z.string(),
563
+ detail: z.string().nullable(),
564
+ }),
565
+ ]),
566
+ }),
567
+ z.object({
568
+ type: z.literal('reference'),
569
+ reference_ids: z.array(z.union([z.string(), z.number()])),
570
+ }),
571
+ z.object({
572
+ type: z.literal('thinking'),
573
+ thinking: z.array(
574
+ z.object({
575
+ type: z.literal('text'),
576
+ text: z.string(),
577
+ }),
578
+ ),
579
+ }),
580
+ ]),
581
+ ),
582
+ ])
583
+ .nullish();
578
584
 
579
585
  // limited version of the schema, focussed on what is needed for the implementation
580
586
  // this approach limits breakages when the API changes and increases efficiency
581
- const mistralChatResponseSchema = z.object({
582
- id: z.string().nullish(),
583
- created: z.number().nullish(),
584
- model: z.string().nullish(),
585
- choices: z.array(
587
+ const mistralChatResponseSchema = lazySchema(() =>
588
+ zodSchema(
586
589
  z.object({
587
- message: z.object({
588
- role: z.literal('assistant'),
589
- content: mistralContentSchema,
590
- tool_calls: z
591
- .array(
592
- z.object({
593
- id: z.string(),
594
- function: z.object({ name: z.string(), arguments: z.string() }),
595
- }),
596
- )
597
- .nullish(),
598
- }),
599
- index: z.number(),
600
- finish_reason: z.string().nullish(),
590
+ id: z.string().nullish(),
591
+ created: z.number().nullish(),
592
+ model: z.string().nullish(),
593
+ choices: z.array(
594
+ z.object({
595
+ message: z.object({
596
+ role: z.literal('assistant'),
597
+ content: mistralContentSchema(),
598
+ tool_calls: z
599
+ .array(
600
+ z.object({
601
+ id: z.string(),
602
+ function: z.object({
603
+ name: z.string(),
604
+ arguments: z.string(),
605
+ }),
606
+ }),
607
+ )
608
+ .nullish(),
609
+ }),
610
+ index: z.number(),
611
+ finish_reason: z.string().nullish(),
612
+ }),
613
+ ),
614
+ object: z.literal('chat.completion'),
615
+ usage: mistralUsageSchema,
601
616
  }),
602
617
  ),
603
- object: z.literal('chat.completion'),
604
- usage: mistralUsageSchema,
605
- });
618
+ );
606
619
 
607
620
  // limited version of the schema, focussed on what is needed for the implementation
608
621
  // this approach limits breakages when the API changes and increases efficiency
609
- const mistralChatChunkSchema = z.object({
610
- id: z.string().nullish(),
611
- created: z.number().nullish(),
612
- model: z.string().nullish(),
613
- choices: z.array(
622
+ const mistralChatChunkSchema = lazySchema(() =>
623
+ zodSchema(
614
624
  z.object({
615
- delta: z.object({
616
- role: z.enum(['assistant']).optional(),
617
- content: mistralContentSchema,
618
- tool_calls: z
619
- .array(
620
- z.object({
621
- index: z.number().nullish(),
622
- id: z.string().nullish(),
623
- function: z.object({
624
- name: z.string().nullish(),
625
- arguments: z.string().nullish(),
626
- }),
627
- }),
628
- )
629
- .nullish(),
630
- }),
631
- finish_reason: z.string().nullish(),
632
- index: z.number(),
625
+ id: z.string().nullish(),
626
+ created: z.number().nullish(),
627
+ model: z.string().nullish(),
628
+ choices: z.array(
629
+ z.object({
630
+ delta: z.object({
631
+ role: z.enum(['assistant']).optional(),
632
+ content: mistralContentSchema(),
633
+ tool_calls: z
634
+ .array(
635
+ z.object({
636
+ index: z.number().nullish(),
637
+ id: z.string().nullish(),
638
+ function: z.object({
639
+ name: z.string().nullish(),
640
+ arguments: z.string().nullish(),
641
+ }),
642
+ }),
643
+ )
644
+ .nullish(),
645
+ }),
646
+ finish_reason: z.string().nullish(),
647
+ index: z.number(),
648
+ }),
649
+ ),
650
+ usage: mistralUsageSchema.nullish(),
633
651
  }),
634
652
  ),
635
- usage: mistralUsageSchema.nullish(),
636
- });
653
+ );
@@ -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
  // https://docs.mistral.ai/getting-started/models/models_overview/
@@ -24,48 +29,52 @@ export type MistralChatModelId =
24
29
  | 'magistral-small-2509'
25
30
  | (string & {});
26
31
 
27
- export const mistralLanguageModelOptions = z.object({
28
- /**
29
- * Whether to inject a safety prompt before all conversations.
30
- *
31
- * Defaults to `false`.
32
- */
33
- safePrompt: z.boolean().optional(),
32
+ export const mistralLanguageModelOptions = lazySchema(() =>
33
+ zodSchema(
34
+ z.object({
35
+ /**
36
+ * Whether to inject a safety prompt before all conversations.
37
+ *
38
+ * Defaults to `false`.
39
+ */
40
+ safePrompt: z.boolean().optional(),
34
41
 
35
- documentImageLimit: z.number().optional(),
36
- documentPageLimit: z.number().optional(),
42
+ documentImageLimit: z.number().optional(),
43
+ documentPageLimit: z.number().optional(),
37
44
 
38
- /**
39
- * Whether to use structured outputs.
40
- *
41
- * @default true
42
- */
43
- structuredOutputs: z.boolean().optional(),
45
+ /**
46
+ * Whether to use structured outputs.
47
+ *
48
+ * @default true
49
+ */
50
+ structuredOutputs: z.boolean().optional(),
44
51
 
45
- /**
46
- * Whether to use strict JSON schema validation.
47
- *
48
- * @default false
49
- */
50
- strictJsonSchema: z.boolean().optional(),
52
+ /**
53
+ * Whether to use strict JSON schema validation.
54
+ *
55
+ * @default false
56
+ */
57
+ strictJsonSchema: z.boolean().optional(),
51
58
 
52
- /**
53
- * Whether to enable parallel function calling during tool use.
54
- * When set to false, the model will use at most one tool per response.
55
- *
56
- * @default true
57
- */
58
- parallelToolCalls: z.boolean().optional(),
59
+ /**
60
+ * Whether to enable parallel function calling during tool use.
61
+ * When set to false, the model will use at most one tool per response.
62
+ *
63
+ * @default true
64
+ */
65
+ parallelToolCalls: z.boolean().optional(),
59
66
 
60
- /**
61
- * Controls the reasoning effort for models that support adjustable reasoning.
62
- *
63
- * - `'high'`: Enable reasoning
64
- * - `'none'`: Disable reasoning
65
- */
66
- reasoningEffort: z.enum(['high', 'none']).optional(),
67
- });
67
+ /**
68
+ * Controls the reasoning effort for models that support adjustable reasoning.
69
+ *
70
+ * - `'high'`: Enable reasoning
71
+ * - `'none'`: Disable reasoning
72
+ */
73
+ reasoningEffort: z.enum(['high', 'none']).optional(),
74
+ }),
75
+ ),
76
+ );
68
77
 
69
- export type MistralLanguageModelOptions = z.infer<
78
+ export type MistralLanguageModelOptions = InferSchema<
70
79
  typeof mistralLanguageModelOptions
71
80
  >;
@@ -3,6 +3,8 @@ import {
3
3
  type EmbeddingModelV3,
4
4
  } from '@ai-sdk/provider';
5
5
  import {
6
+ lazySchema,
7
+ zodSchema,
6
8
  combineHeaders,
7
9
  createJsonResponseHandler,
8
10
  postJsonToApi,
@@ -88,7 +90,11 @@ export class MistralEmbeddingModel implements EmbeddingModelV3 {
88
90
 
89
91
  // minimal version of the schema, focussed on what is needed for the implementation
90
92
  // this approach limits breakages when the API changes and increases efficiency
91
- const MistralTextEmbeddingResponseSchema = z.object({
92
- data: z.array(z.object({ embedding: z.array(z.number()) })),
93
- usage: z.object({ prompt_tokens: z.number() }).nullish(),
94
- });
93
+ const MistralTextEmbeddingResponseSchema = lazySchema(() =>
94
+ zodSchema(
95
+ z.object({
96
+ data: z.array(z.object({ embedding: z.array(z.number()) })),
97
+ usage: z.object({ prompt_tokens: z.number() }).nullish(),
98
+ }),
99
+ ),
100
+ );
@@ -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,16 +1,44 @@
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
- export type MistralSpeechModelId = 'voxtral-mini-tts-2603' | (string & {});
8
+ export type MistralSpeechModelId =
9
+ | 'voxtral-mini-tts-2603'
10
+ | 'voxtral-mini-tts-3-0'
11
+ | 'voxtral-mini-tts-3'
12
+ | 'voxtral-mini-tts-latest'
13
+ | (string & {});
4
14
 
5
- export const mistralSpeechModelOptions = z.object({
6
- /**
7
- * Base64-encoded reference audio for one-off voice cloning.
8
- *
9
- * When provided, this takes precedence over the standard `voice` option.
10
- */
11
- refAudio: z.string().min(1).optional(),
12
- });
15
+ export const mistralSpeechModelOptions = lazySchema(() =>
16
+ zodSchema(
17
+ z.object({
18
+ /**
19
+ * Base64-encoded reference audio for one-off voice cloning.
20
+ *
21
+ * When provided, this takes precedence over the standard `voice` option.
22
+ */
23
+ refAudio: z.string().min(1).optional(),
13
24
 
14
- export type MistralSpeechModelOptions = z.infer<
25
+ /**
26
+ * How expressive the speech is, from 1 to 5. Higher values trade voice
27
+ * similarity and stability for stronger delivery. Supported by Voxtral 3.
28
+ */
29
+ expressiveness: z.number().min(1).max(5).optional(),
30
+
31
+ /**
32
+ * Pronunciation hints mapping words to lists of IPA phonemes.
33
+ * Supported by Voxtral 3.
34
+ */
35
+ phonemeHints: z
36
+ .record(z.string().min(1), z.array(z.string().min(1)).min(1))
37
+ .optional(),
38
+ }),
39
+ ),
40
+ );
41
+
42
+ export type MistralSpeechModelOptions = InferSchema<
15
43
  typeof mistralSpeechModelOptions
16
44
  >;
@@ -1,5 +1,7 @@
1
1
  import type { SharedV3Warning, SpeechModelV3 } from '@ai-sdk/provider';
2
2
  import {
3
+ lazySchema,
4
+ zodSchema,
3
5
  combineHeaders,
4
6
  createJsonResponseHandler,
5
7
  parseProviderOptions,
@@ -99,6 +101,8 @@ export class MistralSpeechModel implements SpeechModelV3 {
99
101
  input: text,
100
102
  voice_id: refAudio == null ? voice : undefined,
101
103
  ref_audio: refAudio,
104
+ expressiveness: mistralOptions?.expressiveness,
105
+ phoneme_hints: mistralOptions?.phonemeHints,
102
106
  response_format: responseFormat,
103
107
  stream: false,
104
108
  };
@@ -157,6 +161,10 @@ export class MistralSpeechModel implements SpeechModelV3 {
157
161
  }
158
162
  }
159
163
 
160
- const mistralSpeechResponseSchema = z.object({
161
- audio_data: z.string(),
162
- });
164
+ const mistralSpeechResponseSchema = lazySchema(() =>
165
+ zodSchema(
166
+ z.object({
167
+ audio_data: z.string(),
168
+ }),
169
+ ),
170
+ );