@ai-sdk/mistral 4.0.0-beta.21 → 4.0.0-beta.23
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 +30 -0
- package/dist/index.js +170 -147
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/mistral-chat-language-model.ts +20 -3
- package/src/mistral-embedding-model.ts +19 -2
- package/dist/index.d.mts +0 -82
- package/dist/index.mjs +0 -920
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @ai-sdk/mistral
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b3976a2: Add workflow serialization support to all provider models.
|
|
8
|
+
|
|
9
|
+
**`@ai-sdk/provider-utils`:** New `serializeModel()` helper that extracts only serializable properties from a model instance, filtering out functions and objects containing functions. Third-party provider authors can use this to add workflow support to their own models.
|
|
10
|
+
|
|
11
|
+
**All providers:** `headers` is now optional in provider config types. This is non-breaking — existing code that passes `headers` continues to work. Custom provider implementations that construct model configs manually can now omit `headers`, which is useful when models are deserialized from a workflow step boundary where auth is provided separately.
|
|
12
|
+
|
|
13
|
+
All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
|
|
14
|
+
|
|
15
|
+
- ff5eba1: feat: roll `image-*` tool output types into their equivalent `file-*` types
|
|
16
|
+
- Updated dependencies [b3976a2]
|
|
17
|
+
- Updated dependencies [ff5eba1]
|
|
18
|
+
- @ai-sdk/provider-utils@5.0.0-beta.20
|
|
19
|
+
- @ai-sdk/provider@4.0.0-beta.12
|
|
20
|
+
|
|
21
|
+
## 4.0.0-beta.22
|
|
22
|
+
|
|
23
|
+
### Major Changes
|
|
24
|
+
|
|
25
|
+
- ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [ef992f8]
|
|
30
|
+
- @ai-sdk/provider@4.0.0-beta.11
|
|
31
|
+
- @ai-sdk/provider-utils@5.0.0-beta.19
|
|
32
|
+
|
|
3
33
|
## 4.0.0-beta.21
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createMistral: () => createMistral,
|
|
25
|
-
mistral: () => mistral
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/mistral-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadApiKey,
|
|
7
|
+
withoutTrailingSlash,
|
|
8
|
+
withUserAgentSuffix
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
32
10
|
|
|
33
11
|
// src/mistral-chat-language-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
import {
|
|
13
|
+
combineHeaders,
|
|
14
|
+
createEventSourceResponseHandler,
|
|
15
|
+
createJsonResponseHandler,
|
|
16
|
+
generateId,
|
|
17
|
+
injectJsonInstructionIntoMessages,
|
|
18
|
+
isCustomReasoning,
|
|
19
|
+
mapReasoningToProviderEffort,
|
|
20
|
+
parseProviderOptions,
|
|
21
|
+
postJsonToApi,
|
|
22
|
+
serializeModelOptions,
|
|
23
|
+
WORKFLOW_SERIALIZE,
|
|
24
|
+
WORKFLOW_DESERIALIZE
|
|
25
|
+
} from "@ai-sdk/provider-utils";
|
|
26
|
+
import { z as z3 } from "zod/v4";
|
|
36
27
|
|
|
37
28
|
// src/convert-mistral-usage.ts
|
|
38
29
|
function convertMistralUsage(usage) {
|
|
@@ -71,13 +62,15 @@ function convertMistralUsage(usage) {
|
|
|
71
62
|
}
|
|
72
63
|
|
|
73
64
|
// src/convert-to-mistral-chat-messages.ts
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
import {
|
|
66
|
+
UnsupportedFunctionalityError
|
|
67
|
+
} from "@ai-sdk/provider";
|
|
68
|
+
import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
|
|
76
69
|
function formatFileUrl({
|
|
77
70
|
data,
|
|
78
71
|
mediaType
|
|
79
72
|
}) {
|
|
80
|
-
return data instanceof URL ? data.toString() : `data:${mediaType};base64,${
|
|
73
|
+
return data instanceof URL ? data.toString() : `data:${mediaType};base64,${convertToBase64(data)}`;
|
|
81
74
|
}
|
|
82
75
|
function convertToMistralChatMessages(prompt) {
|
|
83
76
|
var _a;
|
|
@@ -99,8 +92,8 @@ function convertToMistralChatMessages(prompt) {
|
|
|
99
92
|
return { type: "text", text: part.text };
|
|
100
93
|
}
|
|
101
94
|
case "file": {
|
|
102
|
-
if (
|
|
103
|
-
throw new
|
|
95
|
+
if (isProviderReference(part.data)) {
|
|
96
|
+
throw new UnsupportedFunctionalityError({
|
|
104
97
|
functionality: "file parts with provider references"
|
|
105
98
|
});
|
|
106
99
|
}
|
|
@@ -119,7 +112,7 @@ function convertToMistralChatMessages(prompt) {
|
|
|
119
112
|
})
|
|
120
113
|
};
|
|
121
114
|
} else {
|
|
122
|
-
throw new
|
|
115
|
+
throw new UnsupportedFunctionalityError({
|
|
123
116
|
functionality: "Only images and PDF file parts are supported"
|
|
124
117
|
});
|
|
125
118
|
}
|
|
@@ -236,61 +229,63 @@ function mapMistralFinishReason(finishReason) {
|
|
|
236
229
|
}
|
|
237
230
|
|
|
238
231
|
// src/mistral-chat-options.ts
|
|
239
|
-
|
|
240
|
-
var mistralLanguageModelOptions =
|
|
232
|
+
import { z } from "zod/v4";
|
|
233
|
+
var mistralLanguageModelOptions = z.object({
|
|
241
234
|
/**
|
|
242
235
|
* Whether to inject a safety prompt before all conversations.
|
|
243
236
|
*
|
|
244
237
|
* Defaults to `false`.
|
|
245
238
|
*/
|
|
246
|
-
safePrompt:
|
|
247
|
-
documentImageLimit:
|
|
248
|
-
documentPageLimit:
|
|
239
|
+
safePrompt: z.boolean().optional(),
|
|
240
|
+
documentImageLimit: z.number().optional(),
|
|
241
|
+
documentPageLimit: z.number().optional(),
|
|
249
242
|
/**
|
|
250
243
|
* Whether to use structured outputs.
|
|
251
244
|
*
|
|
252
245
|
* @default true
|
|
253
246
|
*/
|
|
254
|
-
structuredOutputs:
|
|
247
|
+
structuredOutputs: z.boolean().optional(),
|
|
255
248
|
/**
|
|
256
249
|
* Whether to use strict JSON schema validation.
|
|
257
250
|
*
|
|
258
251
|
* @default false
|
|
259
252
|
*/
|
|
260
|
-
strictJsonSchema:
|
|
253
|
+
strictJsonSchema: z.boolean().optional(),
|
|
261
254
|
/**
|
|
262
255
|
* Whether to enable parallel function calling during tool use.
|
|
263
256
|
* When set to false, the model will use at most one tool per response.
|
|
264
257
|
*
|
|
265
258
|
* @default true
|
|
266
259
|
*/
|
|
267
|
-
parallelToolCalls:
|
|
260
|
+
parallelToolCalls: z.boolean().optional(),
|
|
268
261
|
/**
|
|
269
262
|
* Controls the reasoning effort for models that support adjustable reasoning.
|
|
270
263
|
*
|
|
271
264
|
* - `'high'`: Enable reasoning
|
|
272
265
|
* - `'none'`: Disable reasoning
|
|
273
266
|
*/
|
|
274
|
-
reasoningEffort:
|
|
267
|
+
reasoningEffort: z.enum(["high", "none"]).optional()
|
|
275
268
|
});
|
|
276
269
|
|
|
277
270
|
// src/mistral-error.ts
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
var mistralErrorDataSchema =
|
|
281
|
-
object:
|
|
282
|
-
message:
|
|
283
|
-
type:
|
|
284
|
-
param:
|
|
285
|
-
code:
|
|
271
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
272
|
+
import { z as z2 } from "zod/v4";
|
|
273
|
+
var mistralErrorDataSchema = z2.object({
|
|
274
|
+
object: z2.literal("error"),
|
|
275
|
+
message: z2.string(),
|
|
276
|
+
type: z2.string(),
|
|
277
|
+
param: z2.string().nullable(),
|
|
278
|
+
code: z2.string().nullable()
|
|
286
279
|
});
|
|
287
|
-
var mistralFailedResponseHandler =
|
|
280
|
+
var mistralFailedResponseHandler = createJsonErrorResponseHandler({
|
|
288
281
|
errorSchema: mistralErrorDataSchema,
|
|
289
282
|
errorToMessage: (data) => data.message
|
|
290
283
|
});
|
|
291
284
|
|
|
292
285
|
// src/mistral-prepare-tools.ts
|
|
293
|
-
|
|
286
|
+
import {
|
|
287
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
288
|
+
} from "@ai-sdk/provider";
|
|
294
289
|
function prepareTools({
|
|
295
290
|
tools,
|
|
296
291
|
toolChoice
|
|
@@ -341,7 +336,7 @@ function prepareTools({
|
|
|
341
336
|
};
|
|
342
337
|
default: {
|
|
343
338
|
const _exhaustiveCheck = type;
|
|
344
|
-
throw new
|
|
339
|
+
throw new UnsupportedFunctionalityError2({
|
|
345
340
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
346
341
|
});
|
|
347
342
|
}
|
|
@@ -349,7 +344,7 @@ function prepareTools({
|
|
|
349
344
|
}
|
|
350
345
|
|
|
351
346
|
// src/mistral-chat-language-model.ts
|
|
352
|
-
var MistralChatLanguageModel = class {
|
|
347
|
+
var MistralChatLanguageModel = class _MistralChatLanguageModel {
|
|
353
348
|
constructor(modelId, config) {
|
|
354
349
|
this.specificationVersion = "v4";
|
|
355
350
|
this.supportedUrls = {
|
|
@@ -358,7 +353,16 @@ var MistralChatLanguageModel = class {
|
|
|
358
353
|
var _a;
|
|
359
354
|
this.modelId = modelId;
|
|
360
355
|
this.config = config;
|
|
361
|
-
this.generateId = (_a = config.generateId) != null ? _a :
|
|
356
|
+
this.generateId = (_a = config.generateId) != null ? _a : generateId;
|
|
357
|
+
}
|
|
358
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
359
|
+
return serializeModelOptions({
|
|
360
|
+
modelId: model.modelId,
|
|
361
|
+
config: model.config
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
365
|
+
return new _MistralChatLanguageModel(options.modelId, options.config);
|
|
362
366
|
}
|
|
363
367
|
get provider() {
|
|
364
368
|
return this.config.provider;
|
|
@@ -381,7 +385,7 @@ var MistralChatLanguageModel = class {
|
|
|
381
385
|
}) {
|
|
382
386
|
var _a, _b, _c, _d, _e;
|
|
383
387
|
const warnings = [];
|
|
384
|
-
const options = (_a = await
|
|
388
|
+
const options = (_a = await parseProviderOptions({
|
|
385
389
|
provider: "mistral",
|
|
386
390
|
providerOptions,
|
|
387
391
|
schema: mistralLanguageModelOptions
|
|
@@ -401,7 +405,7 @@ var MistralChatLanguageModel = class {
|
|
|
401
405
|
const supportsReasoningEffort = this.modelId === "mistral-small-latest" || this.modelId === "mistral-small-2603";
|
|
402
406
|
let resolvedReasoningEffort;
|
|
403
407
|
if (supportsReasoningEffort) {
|
|
404
|
-
resolvedReasoningEffort = (_b = options.reasoningEffort) != null ? _b :
|
|
408
|
+
resolvedReasoningEffort = (_b = options.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
|
|
405
409
|
reasoning,
|
|
406
410
|
effortMap: {
|
|
407
411
|
minimal: "high",
|
|
@@ -412,7 +416,7 @@ var MistralChatLanguageModel = class {
|
|
|
412
416
|
},
|
|
413
417
|
warnings
|
|
414
418
|
}) : void 0;
|
|
415
|
-
} else if (
|
|
419
|
+
} else if (isCustomReasoning(reasoning)) {
|
|
416
420
|
warnings.push({
|
|
417
421
|
type: "unsupported",
|
|
418
422
|
feature: "reasoning",
|
|
@@ -422,7 +426,7 @@ var MistralChatLanguageModel = class {
|
|
|
422
426
|
const structuredOutputs = (_c = options.structuredOutputs) != null ? _c : true;
|
|
423
427
|
const strictJsonSchema = (_d = options.strictJsonSchema) != null ? _d : false;
|
|
424
428
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && !(responseFormat == null ? void 0 : responseFormat.schema)) {
|
|
425
|
-
prompt =
|
|
429
|
+
prompt = injectJsonInstructionIntoMessages({
|
|
426
430
|
messages: prompt,
|
|
427
431
|
schema: responseFormat.schema
|
|
428
432
|
});
|
|
@@ -473,18 +477,18 @@ var MistralChatLanguageModel = class {
|
|
|
473
477
|
};
|
|
474
478
|
}
|
|
475
479
|
async doGenerate(options) {
|
|
476
|
-
var _a;
|
|
480
|
+
var _a, _b, _c;
|
|
477
481
|
const { args: body, warnings } = await this.getArgs(options);
|
|
478
482
|
const {
|
|
479
483
|
responseHeaders,
|
|
480
484
|
value: response,
|
|
481
485
|
rawValue: rawResponse
|
|
482
|
-
} = await
|
|
486
|
+
} = await postJsonToApi({
|
|
483
487
|
url: `${this.config.baseURL}/chat/completions`,
|
|
484
|
-
headers: (
|
|
488
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
485
489
|
body,
|
|
486
490
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
487
|
-
successfulResponseHandler:
|
|
491
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
488
492
|
mistralChatResponseSchema
|
|
489
493
|
),
|
|
490
494
|
abortSignal: options.abortSignal,
|
|
@@ -525,7 +529,7 @@ var MistralChatLanguageModel = class {
|
|
|
525
529
|
content,
|
|
526
530
|
finishReason: {
|
|
527
531
|
unified: mapMistralFinishReason(choice.finish_reason),
|
|
528
|
-
raw: (
|
|
532
|
+
raw: (_c = choice.finish_reason) != null ? _c : void 0
|
|
529
533
|
},
|
|
530
534
|
usage: convertMistralUsage(response.usage),
|
|
531
535
|
request: { body },
|
|
@@ -538,14 +542,15 @@ var MistralChatLanguageModel = class {
|
|
|
538
542
|
};
|
|
539
543
|
}
|
|
540
544
|
async doStream(options) {
|
|
545
|
+
var _a, _b;
|
|
541
546
|
const { args, warnings } = await this.getArgs(options);
|
|
542
547
|
const body = { ...args, stream: true };
|
|
543
|
-
const { responseHeaders, value: response } = await
|
|
548
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
544
549
|
url: `${this.config.baseURL}/chat/completions`,
|
|
545
|
-
headers: (
|
|
550
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
546
551
|
body,
|
|
547
552
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
548
|
-
successfulResponseHandler:
|
|
553
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
549
554
|
mistralChatChunkSchema
|
|
550
555
|
),
|
|
551
556
|
abortSignal: options.abortSignal,
|
|
@@ -717,96 +722,105 @@ function extractTextContent(content) {
|
|
|
717
722
|
}
|
|
718
723
|
return textContent.length ? textContent.join("") : void 0;
|
|
719
724
|
}
|
|
720
|
-
var mistralContentSchema =
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
type:
|
|
726
|
-
text:
|
|
725
|
+
var mistralContentSchema = z3.union([
|
|
726
|
+
z3.string(),
|
|
727
|
+
z3.array(
|
|
728
|
+
z3.discriminatedUnion("type", [
|
|
729
|
+
z3.object({
|
|
730
|
+
type: z3.literal("text"),
|
|
731
|
+
text: z3.string()
|
|
727
732
|
}),
|
|
728
|
-
|
|
729
|
-
type:
|
|
730
|
-
image_url:
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
url:
|
|
734
|
-
detail:
|
|
733
|
+
z3.object({
|
|
734
|
+
type: z3.literal("image_url"),
|
|
735
|
+
image_url: z3.union([
|
|
736
|
+
z3.string(),
|
|
737
|
+
z3.object({
|
|
738
|
+
url: z3.string(),
|
|
739
|
+
detail: z3.string().nullable()
|
|
735
740
|
})
|
|
736
741
|
])
|
|
737
742
|
}),
|
|
738
|
-
|
|
739
|
-
type:
|
|
740
|
-
reference_ids:
|
|
743
|
+
z3.object({
|
|
744
|
+
type: z3.literal("reference"),
|
|
745
|
+
reference_ids: z3.array(z3.union([z3.string(), z3.number()]))
|
|
741
746
|
}),
|
|
742
|
-
|
|
743
|
-
type:
|
|
744
|
-
thinking:
|
|
745
|
-
|
|
746
|
-
type:
|
|
747
|
-
text:
|
|
747
|
+
z3.object({
|
|
748
|
+
type: z3.literal("thinking"),
|
|
749
|
+
thinking: z3.array(
|
|
750
|
+
z3.object({
|
|
751
|
+
type: z3.literal("text"),
|
|
752
|
+
text: z3.string()
|
|
748
753
|
})
|
|
749
754
|
)
|
|
750
755
|
})
|
|
751
756
|
])
|
|
752
757
|
)
|
|
753
758
|
]).nullish();
|
|
754
|
-
var mistralUsageSchema =
|
|
755
|
-
prompt_tokens:
|
|
756
|
-
completion_tokens:
|
|
757
|
-
total_tokens:
|
|
759
|
+
var mistralUsageSchema = z3.object({
|
|
760
|
+
prompt_tokens: z3.number(),
|
|
761
|
+
completion_tokens: z3.number(),
|
|
762
|
+
total_tokens: z3.number()
|
|
758
763
|
});
|
|
759
|
-
var mistralChatResponseSchema =
|
|
760
|
-
id:
|
|
761
|
-
created:
|
|
762
|
-
model:
|
|
763
|
-
choices:
|
|
764
|
-
|
|
765
|
-
message:
|
|
766
|
-
role:
|
|
764
|
+
var mistralChatResponseSchema = z3.object({
|
|
765
|
+
id: z3.string().nullish(),
|
|
766
|
+
created: z3.number().nullish(),
|
|
767
|
+
model: z3.string().nullish(),
|
|
768
|
+
choices: z3.array(
|
|
769
|
+
z3.object({
|
|
770
|
+
message: z3.object({
|
|
771
|
+
role: z3.literal("assistant"),
|
|
767
772
|
content: mistralContentSchema,
|
|
768
|
-
tool_calls:
|
|
769
|
-
|
|
770
|
-
id:
|
|
771
|
-
function:
|
|
773
|
+
tool_calls: z3.array(
|
|
774
|
+
z3.object({
|
|
775
|
+
id: z3.string(),
|
|
776
|
+
function: z3.object({ name: z3.string(), arguments: z3.string() })
|
|
772
777
|
})
|
|
773
778
|
).nullish()
|
|
774
779
|
}),
|
|
775
|
-
index:
|
|
776
|
-
finish_reason:
|
|
780
|
+
index: z3.number(),
|
|
781
|
+
finish_reason: z3.string().nullish()
|
|
777
782
|
})
|
|
778
783
|
),
|
|
779
|
-
object:
|
|
784
|
+
object: z3.literal("chat.completion"),
|
|
780
785
|
usage: mistralUsageSchema
|
|
781
786
|
});
|
|
782
|
-
var mistralChatChunkSchema =
|
|
783
|
-
id:
|
|
784
|
-
created:
|
|
785
|
-
model:
|
|
786
|
-
choices:
|
|
787
|
-
|
|
788
|
-
delta:
|
|
789
|
-
role:
|
|
787
|
+
var mistralChatChunkSchema = z3.object({
|
|
788
|
+
id: z3.string().nullish(),
|
|
789
|
+
created: z3.number().nullish(),
|
|
790
|
+
model: z3.string().nullish(),
|
|
791
|
+
choices: z3.array(
|
|
792
|
+
z3.object({
|
|
793
|
+
delta: z3.object({
|
|
794
|
+
role: z3.enum(["assistant"]).optional(),
|
|
790
795
|
content: mistralContentSchema,
|
|
791
|
-
tool_calls:
|
|
792
|
-
|
|
793
|
-
id:
|
|
794
|
-
function:
|
|
796
|
+
tool_calls: z3.array(
|
|
797
|
+
z3.object({
|
|
798
|
+
id: z3.string(),
|
|
799
|
+
function: z3.object({ name: z3.string(), arguments: z3.string() })
|
|
795
800
|
})
|
|
796
801
|
).nullish()
|
|
797
802
|
}),
|
|
798
|
-
finish_reason:
|
|
799
|
-
index:
|
|
803
|
+
finish_reason: z3.string().nullish(),
|
|
804
|
+
index: z3.number()
|
|
800
805
|
})
|
|
801
806
|
),
|
|
802
807
|
usage: mistralUsageSchema.nullish()
|
|
803
808
|
});
|
|
804
809
|
|
|
805
810
|
// src/mistral-embedding-model.ts
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
811
|
+
import {
|
|
812
|
+
TooManyEmbeddingValuesForCallError
|
|
813
|
+
} from "@ai-sdk/provider";
|
|
814
|
+
import {
|
|
815
|
+
combineHeaders as combineHeaders2,
|
|
816
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
817
|
+
postJsonToApi as postJsonToApi2,
|
|
818
|
+
serializeModelOptions as serializeModelOptions2,
|
|
819
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
820
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
821
|
+
} from "@ai-sdk/provider-utils";
|
|
822
|
+
import { z as z4 } from "zod/v4";
|
|
823
|
+
var MistralEmbeddingModel = class _MistralEmbeddingModel {
|
|
810
824
|
constructor(modelId, config) {
|
|
811
825
|
this.specificationVersion = "v4";
|
|
812
826
|
this.maxEmbeddingsPerCall = 32;
|
|
@@ -817,13 +831,23 @@ var MistralEmbeddingModel = class {
|
|
|
817
831
|
get provider() {
|
|
818
832
|
return this.config.provider;
|
|
819
833
|
}
|
|
834
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
835
|
+
return serializeModelOptions2({
|
|
836
|
+
modelId: model.modelId,
|
|
837
|
+
config: model.config
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
841
|
+
return new _MistralEmbeddingModel(options.modelId, options.config);
|
|
842
|
+
}
|
|
820
843
|
async doEmbed({
|
|
821
844
|
values,
|
|
822
845
|
abortSignal,
|
|
823
846
|
headers
|
|
824
847
|
}) {
|
|
848
|
+
var _a, _b;
|
|
825
849
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
826
|
-
throw new
|
|
850
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
827
851
|
provider: this.provider,
|
|
828
852
|
modelId: this.modelId,
|
|
829
853
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -834,16 +858,16 @@ var MistralEmbeddingModel = class {
|
|
|
834
858
|
responseHeaders,
|
|
835
859
|
value: response,
|
|
836
860
|
rawValue
|
|
837
|
-
} = await (
|
|
861
|
+
} = await postJsonToApi2({
|
|
838
862
|
url: `${this.config.baseURL}/embeddings`,
|
|
839
|
-
headers: (
|
|
863
|
+
headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), headers),
|
|
840
864
|
body: {
|
|
841
865
|
model: this.modelId,
|
|
842
866
|
input: values,
|
|
843
867
|
encoding_format: "float"
|
|
844
868
|
},
|
|
845
869
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
846
|
-
successfulResponseHandler: (
|
|
870
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
847
871
|
MistralTextEmbeddingResponseSchema
|
|
848
872
|
),
|
|
849
873
|
abortSignal,
|
|
@@ -857,21 +881,21 @@ var MistralEmbeddingModel = class {
|
|
|
857
881
|
};
|
|
858
882
|
}
|
|
859
883
|
};
|
|
860
|
-
var MistralTextEmbeddingResponseSchema =
|
|
861
|
-
data:
|
|
862
|
-
usage:
|
|
884
|
+
var MistralTextEmbeddingResponseSchema = z4.object({
|
|
885
|
+
data: z4.array(z4.object({ embedding: z4.array(z4.number()) })),
|
|
886
|
+
usage: z4.object({ prompt_tokens: z4.number() }).nullish()
|
|
863
887
|
});
|
|
864
888
|
|
|
865
889
|
// src/version.ts
|
|
866
|
-
var VERSION = true ? "4.0.0-beta.
|
|
890
|
+
var VERSION = true ? "4.0.0-beta.23" : "0.0.0-test";
|
|
867
891
|
|
|
868
892
|
// src/mistral-provider.ts
|
|
869
893
|
function createMistral(options = {}) {
|
|
870
894
|
var _a;
|
|
871
|
-
const baseURL = (_a =
|
|
872
|
-
const getHeaders = () =>
|
|
895
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.mistral.ai/v1";
|
|
896
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
873
897
|
{
|
|
874
|
-
Authorization: `Bearer ${
|
|
898
|
+
Authorization: `Bearer ${loadApiKey({
|
|
875
899
|
apiKey: options.apiKey,
|
|
876
900
|
environmentVariableName: "MISTRAL_API_KEY",
|
|
877
901
|
description: "Mistral"
|
|
@@ -909,15 +933,14 @@ function createMistral(options = {}) {
|
|
|
909
933
|
provider.textEmbedding = createEmbeddingModel;
|
|
910
934
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
911
935
|
provider.imageModel = (modelId) => {
|
|
912
|
-
throw new
|
|
936
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
913
937
|
};
|
|
914
938
|
return provider;
|
|
915
939
|
}
|
|
916
940
|
var mistral = createMistral();
|
|
917
|
-
|
|
918
|
-
0 && (module.exports = {
|
|
941
|
+
export {
|
|
919
942
|
VERSION,
|
|
920
943
|
createMistral,
|
|
921
944
|
mistral
|
|
922
|
-
}
|
|
945
|
+
};
|
|
923
946
|
//# sourceMappingURL=index.js.map
|