@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.
- package/CHANGELOG.md +15 -0
- package/dist/index.d.mts +19 -20
- package/dist/index.d.ts +19 -20
- package/dist/index.js +175 -130
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +167 -106
- package/dist/index.mjs.map +1 -1
- package/docs/20-mistral.mdx +36 -5
- package/package.json +4 -4
- package/src/mistral-chat-language-model.ts +102 -85
- package/src/mistral-chat-options.ts +46 -37
- package/src/mistral-embedding-model.ts +10 -4
- package/src/mistral-error.ts +18 -9
- package/src/mistral-speech-model-options.ts +38 -10
- package/src/mistral-speech-model.ts +11 -3
|
@@ -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<
|
|
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(
|
|
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 =
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
z.
|
|
547
|
-
z.
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
z.
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
z.
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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 =
|
|
582
|
-
|
|
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
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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
|
-
|
|
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 =
|
|
610
|
-
|
|
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
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
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
|
-
|
|
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 =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
36
|
-
|
|
42
|
+
documentImageLimit: z.number().optional(),
|
|
43
|
+
documentPageLimit: z.number().optional(),
|
|
37
44
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Whether to use structured outputs.
|
|
47
|
+
*
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
structuredOutputs: z.boolean().optional(),
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Whether to use strict JSON schema validation.
|
|
54
|
+
*
|
|
55
|
+
* @default false
|
|
56
|
+
*/
|
|
57
|
+
strictJsonSchema: z.boolean().optional(),
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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 =
|
|
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 =
|
|
92
|
-
|
|
93
|
-
|
|
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
|
+
);
|
package/src/mistral-error.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import {
|
|
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 =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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 =
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
const mistralSpeechResponseSchema = lazySchema(() =>
|
|
165
|
+
zodSchema(
|
|
166
|
+
z.object({
|
|
167
|
+
audio_data: z.string(),
|
|
168
|
+
}),
|
|
169
|
+
),
|
|
170
|
+
);
|