@ai-sdk/mistral 4.0.0-beta.4 → 4.0.0-beta.55
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 +421 -8
- package/README.md +2 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +259 -174
- package/dist/index.js.map +1 -1
- package/docs/20-mistral.mdx +30 -7
- package/package.json +14 -14
- package/src/convert-mistral-usage.ts +12 -3
- package/src/convert-to-mistral-chat-messages.ts +64 -39
- package/src/index.ts +5 -1
- package/src/map-mistral-finish-reason.ts +1 -1
- package/src/{mistral-chat-options.ts → mistral-chat-language-model-options.ts} +23 -15
- package/src/mistral-chat-language-model.ts +74 -13
- package/src/mistral-embedding-model.ts +22 -5
- package/src/mistral-prepare-tools.ts +3 -3
- package/src/mistral-provider.ts +6 -6
- package/dist/index.d.mts +0 -78
- package/dist/index.mjs +0 -883
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,41 +1,33 @@
|
|
|
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) {
|
|
30
|
+
var _a, _b, _c, _d, _e;
|
|
39
31
|
if (usage == null) {
|
|
40
32
|
return {
|
|
41
33
|
inputTokens: {
|
|
@@ -54,11 +46,12 @@ function convertMistralUsage(usage) {
|
|
|
54
46
|
}
|
|
55
47
|
const promptTokens = usage.prompt_tokens;
|
|
56
48
|
const completionTokens = usage.completion_tokens;
|
|
49
|
+
const cacheReadTokens = (_e = (_d = (_b = usage.num_cached_tokens) != null ? _b : (_a = usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _d : (_c = usage.prompt_token_details) == null ? void 0 : _c.cached_tokens) != null ? _e : 0;
|
|
57
50
|
return {
|
|
58
51
|
inputTokens: {
|
|
59
52
|
total: promptTokens,
|
|
60
|
-
noCache: promptTokens,
|
|
61
|
-
cacheRead: void 0,
|
|
53
|
+
noCache: promptTokens - cacheReadTokens,
|
|
54
|
+
cacheRead: cacheReadTokens || void 0,
|
|
62
55
|
cacheWrite: void 0
|
|
63
56
|
},
|
|
64
57
|
outputTokens: {
|
|
@@ -71,13 +64,24 @@ function convertMistralUsage(usage) {
|
|
|
71
64
|
}
|
|
72
65
|
|
|
73
66
|
// src/convert-to-mistral-chat-messages.ts
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
import {
|
|
68
|
+
UnsupportedFunctionalityError
|
|
69
|
+
} from "@ai-sdk/provider";
|
|
70
|
+
import {
|
|
71
|
+
convertToBase64,
|
|
72
|
+
getTopLevelMediaType,
|
|
73
|
+
resolveFullMediaType
|
|
74
|
+
} from "@ai-sdk/provider-utils";
|
|
75
|
+
function formatFileUrl({ part }) {
|
|
76
|
+
if (part.data.type === "url") {
|
|
77
|
+
return part.data.url.toString();
|
|
78
|
+
}
|
|
79
|
+
if (part.data.type === "data") {
|
|
80
|
+
return `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`;
|
|
81
|
+
}
|
|
82
|
+
throw new UnsupportedFunctionalityError({
|
|
83
|
+
functionality: `file part data type ${part.data.type}`
|
|
84
|
+
});
|
|
81
85
|
}
|
|
82
86
|
function convertToMistralChatMessages(prompt) {
|
|
83
87
|
var _a;
|
|
@@ -99,24 +103,44 @@ function convertToMistralChatMessages(prompt) {
|
|
|
99
103
|
return { type: "text", text: part.text };
|
|
100
104
|
}
|
|
101
105
|
case "file": {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
106
|
+
switch (part.data.type) {
|
|
107
|
+
case "reference": {
|
|
108
|
+
throw new UnsupportedFunctionalityError({
|
|
109
|
+
functionality: "file parts with provider references"
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
case "text": {
|
|
113
|
+
throw new UnsupportedFunctionalityError({
|
|
114
|
+
functionality: "text file parts"
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
case "url":
|
|
118
|
+
case "data": {
|
|
119
|
+
const topLevel = getTopLevelMediaType(part.mediaType);
|
|
120
|
+
if (topLevel === "image") {
|
|
121
|
+
return {
|
|
122
|
+
type: "image_url",
|
|
123
|
+
image_url: formatFileUrl({ part })
|
|
124
|
+
};
|
|
125
|
+
} else {
|
|
126
|
+
if (part.data.type === "data") {
|
|
127
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
128
|
+
if (fullMediaType !== "application/pdf") {
|
|
129
|
+
throw new UnsupportedFunctionalityError({
|
|
130
|
+
functionality: "Only images and PDF file parts are supported"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
} else if (part.mediaType !== "application/pdf") {
|
|
134
|
+
throw new UnsupportedFunctionalityError({
|
|
135
|
+
functionality: "Only images and PDF file parts are supported"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
type: "document_url",
|
|
140
|
+
document_url: formatFileUrl({ part })
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
120
144
|
}
|
|
121
145
|
}
|
|
122
146
|
}
|
|
@@ -176,7 +200,7 @@ function convertToMistralChatMessages(prompt) {
|
|
|
176
200
|
contentValue = output.value;
|
|
177
201
|
break;
|
|
178
202
|
case "execution-denied":
|
|
179
|
-
contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
|
|
203
|
+
contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
|
|
180
204
|
break;
|
|
181
205
|
case "content":
|
|
182
206
|
case "json":
|
|
@@ -230,55 +254,64 @@ function mapMistralFinishReason(finishReason) {
|
|
|
230
254
|
}
|
|
231
255
|
}
|
|
232
256
|
|
|
233
|
-
// src/mistral-chat-options.ts
|
|
234
|
-
|
|
235
|
-
var
|
|
257
|
+
// src/mistral-chat-language-model-options.ts
|
|
258
|
+
import { z } from "zod/v4";
|
|
259
|
+
var mistralLanguageModelChatOptions = z.object({
|
|
236
260
|
/**
|
|
237
261
|
* Whether to inject a safety prompt before all conversations.
|
|
238
262
|
*
|
|
239
263
|
* Defaults to `false`.
|
|
240
264
|
*/
|
|
241
|
-
safePrompt:
|
|
242
|
-
documentImageLimit:
|
|
243
|
-
documentPageLimit:
|
|
265
|
+
safePrompt: z.boolean().optional(),
|
|
266
|
+
documentImageLimit: z.number().optional(),
|
|
267
|
+
documentPageLimit: z.number().optional(),
|
|
244
268
|
/**
|
|
245
269
|
* Whether to use structured outputs.
|
|
246
270
|
*
|
|
247
271
|
* @default true
|
|
248
272
|
*/
|
|
249
|
-
structuredOutputs:
|
|
273
|
+
structuredOutputs: z.boolean().optional(),
|
|
250
274
|
/**
|
|
251
275
|
* Whether to use strict JSON schema validation.
|
|
252
276
|
*
|
|
253
277
|
* @default false
|
|
254
278
|
*/
|
|
255
|
-
strictJsonSchema:
|
|
279
|
+
strictJsonSchema: z.boolean().optional(),
|
|
256
280
|
/**
|
|
257
281
|
* Whether to enable parallel function calling during tool use.
|
|
258
282
|
* When set to false, the model will use at most one tool per response.
|
|
259
283
|
*
|
|
260
284
|
* @default true
|
|
261
285
|
*/
|
|
262
|
-
parallelToolCalls:
|
|
286
|
+
parallelToolCalls: z.boolean().optional(),
|
|
287
|
+
/**
|
|
288
|
+
* Controls the reasoning effort for models that support adjustable reasoning.
|
|
289
|
+
*
|
|
290
|
+
* - `'high'`: Enable reasoning
|
|
291
|
+
* - `'none'`: Disable reasoning
|
|
292
|
+
*/
|
|
293
|
+
reasoningEffort: z.enum(["high", "none"]).optional()
|
|
263
294
|
});
|
|
264
295
|
|
|
265
296
|
// src/mistral-error.ts
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
var mistralErrorDataSchema =
|
|
269
|
-
object:
|
|
270
|
-
message:
|
|
271
|
-
type:
|
|
272
|
-
param:
|
|
273
|
-
code:
|
|
297
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
298
|
+
import { z as z2 } from "zod/v4";
|
|
299
|
+
var mistralErrorDataSchema = z2.object({
|
|
300
|
+
object: z2.literal("error"),
|
|
301
|
+
message: z2.string(),
|
|
302
|
+
type: z2.string(),
|
|
303
|
+
param: z2.string().nullable(),
|
|
304
|
+
code: z2.string().nullable()
|
|
274
305
|
});
|
|
275
|
-
var mistralFailedResponseHandler =
|
|
306
|
+
var mistralFailedResponseHandler = createJsonErrorResponseHandler({
|
|
276
307
|
errorSchema: mistralErrorDataSchema,
|
|
277
308
|
errorToMessage: (data) => data.message
|
|
278
309
|
});
|
|
279
310
|
|
|
280
311
|
// src/mistral-prepare-tools.ts
|
|
281
|
-
|
|
312
|
+
import {
|
|
313
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
314
|
+
} from "@ai-sdk/provider";
|
|
282
315
|
function prepareTools({
|
|
283
316
|
tools,
|
|
284
317
|
toolChoice
|
|
@@ -329,7 +362,7 @@ function prepareTools({
|
|
|
329
362
|
};
|
|
330
363
|
default: {
|
|
331
364
|
const _exhaustiveCheck = type;
|
|
332
|
-
throw new
|
|
365
|
+
throw new UnsupportedFunctionalityError2({
|
|
333
366
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
334
367
|
});
|
|
335
368
|
}
|
|
@@ -337,7 +370,7 @@ function prepareTools({
|
|
|
337
370
|
}
|
|
338
371
|
|
|
339
372
|
// src/mistral-chat-language-model.ts
|
|
340
|
-
var MistralChatLanguageModel = class {
|
|
373
|
+
var MistralChatLanguageModel = class _MistralChatLanguageModel {
|
|
341
374
|
constructor(modelId, config) {
|
|
342
375
|
this.specificationVersion = "v4";
|
|
343
376
|
this.supportedUrls = {
|
|
@@ -346,7 +379,16 @@ var MistralChatLanguageModel = class {
|
|
|
346
379
|
var _a;
|
|
347
380
|
this.modelId = modelId;
|
|
348
381
|
this.config = config;
|
|
349
|
-
this.generateId = (_a = config.generateId) != null ? _a :
|
|
382
|
+
this.generateId = (_a = config.generateId) != null ? _a : generateId;
|
|
383
|
+
}
|
|
384
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
385
|
+
return serializeModelOptions({
|
|
386
|
+
modelId: model.modelId,
|
|
387
|
+
config: model.config
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
391
|
+
return new _MistralChatLanguageModel(options.modelId, options.config);
|
|
350
392
|
}
|
|
351
393
|
get provider() {
|
|
352
394
|
return this.config.provider;
|
|
@@ -359,6 +401,7 @@ var MistralChatLanguageModel = class {
|
|
|
359
401
|
topK,
|
|
360
402
|
frequencyPenalty,
|
|
361
403
|
presencePenalty,
|
|
404
|
+
reasoning,
|
|
362
405
|
stopSequences,
|
|
363
406
|
responseFormat,
|
|
364
407
|
seed,
|
|
@@ -366,12 +409,12 @@ var MistralChatLanguageModel = class {
|
|
|
366
409
|
tools,
|
|
367
410
|
toolChoice
|
|
368
411
|
}) {
|
|
369
|
-
var _a, _b, _c, _d;
|
|
412
|
+
var _a, _b, _c, _d, _e;
|
|
370
413
|
const warnings = [];
|
|
371
|
-
const options = (_a = await
|
|
414
|
+
const options = (_a = await parseProviderOptions({
|
|
372
415
|
provider: "mistral",
|
|
373
416
|
providerOptions,
|
|
374
|
-
schema:
|
|
417
|
+
schema: mistralLanguageModelChatOptions
|
|
375
418
|
})) != null ? _a : {};
|
|
376
419
|
if (topK != null) {
|
|
377
420
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
@@ -382,13 +425,31 @@ var MistralChatLanguageModel = class {
|
|
|
382
425
|
if (presencePenalty != null) {
|
|
383
426
|
warnings.push({ type: "unsupported", feature: "presencePenalty" });
|
|
384
427
|
}
|
|
385
|
-
|
|
386
|
-
|
|
428
|
+
const supportsReasoningEffort = this.modelId === "mistral-small-latest" || this.modelId === "mistral-small-2603" || this.modelId === "mistral-medium-3" || this.modelId === "mistral-medium-3.5";
|
|
429
|
+
let resolvedReasoningEffort;
|
|
430
|
+
if (supportsReasoningEffort) {
|
|
431
|
+
resolvedReasoningEffort = (_b = options.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
|
|
432
|
+
reasoning,
|
|
433
|
+
effortMap: {
|
|
434
|
+
minimal: "high",
|
|
435
|
+
low: "high",
|
|
436
|
+
medium: "high",
|
|
437
|
+
high: "high",
|
|
438
|
+
xhigh: "high"
|
|
439
|
+
},
|
|
440
|
+
warnings
|
|
441
|
+
}) : void 0;
|
|
442
|
+
} else if (isCustomReasoning(reasoning)) {
|
|
443
|
+
warnings.push({
|
|
444
|
+
type: "unsupported",
|
|
445
|
+
feature: "reasoning",
|
|
446
|
+
details: "This model does not support reasoning configuration."
|
|
447
|
+
});
|
|
387
448
|
}
|
|
388
|
-
const structuredOutputs = (
|
|
389
|
-
const strictJsonSchema = (
|
|
449
|
+
const structuredOutputs = (_c = options.structuredOutputs) != null ? _c : true;
|
|
450
|
+
const strictJsonSchema = (_d = options.strictJsonSchema) != null ? _d : false;
|
|
390
451
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && !(responseFormat == null ? void 0 : responseFormat.schema)) {
|
|
391
|
-
prompt =
|
|
452
|
+
prompt = injectJsonInstructionIntoMessages({
|
|
392
453
|
messages: prompt,
|
|
393
454
|
schema: responseFormat.schema
|
|
394
455
|
});
|
|
@@ -402,14 +463,16 @@ var MistralChatLanguageModel = class {
|
|
|
402
463
|
max_tokens: maxOutputTokens,
|
|
403
464
|
temperature,
|
|
404
465
|
top_p: topP,
|
|
466
|
+
stop: stopSequences,
|
|
405
467
|
random_seed: seed,
|
|
468
|
+
reasoning_effort: resolvedReasoningEffort,
|
|
406
469
|
// response format:
|
|
407
470
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && (responseFormat == null ? void 0 : responseFormat.schema) != null ? {
|
|
408
471
|
type: "json_schema",
|
|
409
472
|
json_schema: {
|
|
410
473
|
schema: responseFormat.schema,
|
|
411
474
|
strict: strictJsonSchema,
|
|
412
|
-
name: (
|
|
475
|
+
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
413
476
|
description: responseFormat.description
|
|
414
477
|
}
|
|
415
478
|
} : { type: "json_object" } : void 0,
|
|
@@ -438,18 +501,18 @@ var MistralChatLanguageModel = class {
|
|
|
438
501
|
};
|
|
439
502
|
}
|
|
440
503
|
async doGenerate(options) {
|
|
441
|
-
var _a;
|
|
504
|
+
var _a, _b, _c;
|
|
442
505
|
const { args: body, warnings } = await this.getArgs(options);
|
|
443
506
|
const {
|
|
444
507
|
responseHeaders,
|
|
445
508
|
value: response,
|
|
446
509
|
rawValue: rawResponse
|
|
447
|
-
} = await
|
|
510
|
+
} = await postJsonToApi({
|
|
448
511
|
url: `${this.config.baseURL}/chat/completions`,
|
|
449
|
-
headers: (
|
|
512
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
450
513
|
body,
|
|
451
514
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
452
|
-
successfulResponseHandler:
|
|
515
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
453
516
|
mistralChatResponseSchema
|
|
454
517
|
),
|
|
455
518
|
abortSignal: options.abortSignal,
|
|
@@ -490,7 +553,7 @@ var MistralChatLanguageModel = class {
|
|
|
490
553
|
content,
|
|
491
554
|
finishReason: {
|
|
492
555
|
unified: mapMistralFinishReason(choice.finish_reason),
|
|
493
|
-
raw: (
|
|
556
|
+
raw: (_c = choice.finish_reason) != null ? _c : void 0
|
|
494
557
|
},
|
|
495
558
|
usage: convertMistralUsage(response.usage),
|
|
496
559
|
request: { body },
|
|
@@ -503,14 +566,15 @@ var MistralChatLanguageModel = class {
|
|
|
503
566
|
};
|
|
504
567
|
}
|
|
505
568
|
async doStream(options) {
|
|
569
|
+
var _a, _b;
|
|
506
570
|
const { args, warnings } = await this.getArgs(options);
|
|
507
571
|
const body = { ...args, stream: true };
|
|
508
|
-
const { responseHeaders, value: response } = await
|
|
572
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
509
573
|
url: `${this.config.baseURL}/chat/completions`,
|
|
510
|
-
headers: (
|
|
574
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
511
575
|
body,
|
|
512
576
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
513
|
-
successfulResponseHandler:
|
|
577
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
514
578
|
mistralChatChunkSchema
|
|
515
579
|
),
|
|
516
580
|
abortSignal: options.abortSignal,
|
|
@@ -682,96 +746,108 @@ function extractTextContent(content) {
|
|
|
682
746
|
}
|
|
683
747
|
return textContent.length ? textContent.join("") : void 0;
|
|
684
748
|
}
|
|
685
|
-
var mistralContentSchema =
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
type:
|
|
691
|
-
text:
|
|
749
|
+
var mistralContentSchema = z3.union([
|
|
750
|
+
z3.string(),
|
|
751
|
+
z3.array(
|
|
752
|
+
z3.discriminatedUnion("type", [
|
|
753
|
+
z3.object({
|
|
754
|
+
type: z3.literal("text"),
|
|
755
|
+
text: z3.string()
|
|
692
756
|
}),
|
|
693
|
-
|
|
694
|
-
type:
|
|
695
|
-
image_url:
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
url:
|
|
699
|
-
detail:
|
|
757
|
+
z3.object({
|
|
758
|
+
type: z3.literal("image_url"),
|
|
759
|
+
image_url: z3.union([
|
|
760
|
+
z3.string(),
|
|
761
|
+
z3.object({
|
|
762
|
+
url: z3.string(),
|
|
763
|
+
detail: z3.string().nullable()
|
|
700
764
|
})
|
|
701
765
|
])
|
|
702
766
|
}),
|
|
703
|
-
|
|
704
|
-
type:
|
|
705
|
-
reference_ids:
|
|
767
|
+
z3.object({
|
|
768
|
+
type: z3.literal("reference"),
|
|
769
|
+
reference_ids: z3.array(z3.union([z3.string(), z3.number()]))
|
|
706
770
|
}),
|
|
707
|
-
|
|
708
|
-
type:
|
|
709
|
-
thinking:
|
|
710
|
-
|
|
711
|
-
type:
|
|
712
|
-
text:
|
|
771
|
+
z3.object({
|
|
772
|
+
type: z3.literal("thinking"),
|
|
773
|
+
thinking: z3.array(
|
|
774
|
+
z3.object({
|
|
775
|
+
type: z3.literal("text"),
|
|
776
|
+
text: z3.string()
|
|
713
777
|
})
|
|
714
778
|
)
|
|
715
779
|
})
|
|
716
780
|
])
|
|
717
781
|
)
|
|
718
782
|
]).nullish();
|
|
719
|
-
var mistralUsageSchema =
|
|
720
|
-
prompt_tokens:
|
|
721
|
-
completion_tokens:
|
|
722
|
-
total_tokens:
|
|
783
|
+
var mistralUsageSchema = z3.object({
|
|
784
|
+
prompt_tokens: z3.number(),
|
|
785
|
+
completion_tokens: z3.number(),
|
|
786
|
+
total_tokens: z3.number(),
|
|
787
|
+
num_cached_tokens: z3.number().nullish(),
|
|
788
|
+
prompt_tokens_details: z3.object({ cached_tokens: z3.number().nullish() }).nullish(),
|
|
789
|
+
prompt_token_details: z3.object({ cached_tokens: z3.number().nullish() }).nullish()
|
|
723
790
|
});
|
|
724
|
-
var mistralChatResponseSchema =
|
|
725
|
-
id:
|
|
726
|
-
created:
|
|
727
|
-
model:
|
|
728
|
-
choices:
|
|
729
|
-
|
|
730
|
-
message:
|
|
731
|
-
role:
|
|
791
|
+
var mistralChatResponseSchema = z3.object({
|
|
792
|
+
id: z3.string().nullish(),
|
|
793
|
+
created: z3.number().nullish(),
|
|
794
|
+
model: z3.string().nullish(),
|
|
795
|
+
choices: z3.array(
|
|
796
|
+
z3.object({
|
|
797
|
+
message: z3.object({
|
|
798
|
+
role: z3.literal("assistant"),
|
|
732
799
|
content: mistralContentSchema,
|
|
733
|
-
tool_calls:
|
|
734
|
-
|
|
735
|
-
id:
|
|
736
|
-
function:
|
|
800
|
+
tool_calls: z3.array(
|
|
801
|
+
z3.object({
|
|
802
|
+
id: z3.string(),
|
|
803
|
+
function: z3.object({ name: z3.string(), arguments: z3.string() })
|
|
737
804
|
})
|
|
738
805
|
).nullish()
|
|
739
806
|
}),
|
|
740
|
-
index:
|
|
741
|
-
finish_reason:
|
|
807
|
+
index: z3.number(),
|
|
808
|
+
finish_reason: z3.string().nullish()
|
|
742
809
|
})
|
|
743
810
|
),
|
|
744
|
-
object:
|
|
811
|
+
object: z3.literal("chat.completion"),
|
|
745
812
|
usage: mistralUsageSchema
|
|
746
813
|
});
|
|
747
|
-
var mistralChatChunkSchema =
|
|
748
|
-
id:
|
|
749
|
-
created:
|
|
750
|
-
model:
|
|
751
|
-
choices:
|
|
752
|
-
|
|
753
|
-
delta:
|
|
754
|
-
role:
|
|
814
|
+
var mistralChatChunkSchema = z3.object({
|
|
815
|
+
id: z3.string().nullish(),
|
|
816
|
+
created: z3.number().nullish(),
|
|
817
|
+
model: z3.string().nullish(),
|
|
818
|
+
choices: z3.array(
|
|
819
|
+
z3.object({
|
|
820
|
+
delta: z3.object({
|
|
821
|
+
role: z3.enum(["assistant"]).optional(),
|
|
755
822
|
content: mistralContentSchema,
|
|
756
|
-
tool_calls:
|
|
757
|
-
|
|
758
|
-
id:
|
|
759
|
-
function:
|
|
823
|
+
tool_calls: z3.array(
|
|
824
|
+
z3.object({
|
|
825
|
+
id: z3.string(),
|
|
826
|
+
function: z3.object({ name: z3.string(), arguments: z3.string() })
|
|
760
827
|
})
|
|
761
828
|
).nullish()
|
|
762
829
|
}),
|
|
763
|
-
finish_reason:
|
|
764
|
-
index:
|
|
830
|
+
finish_reason: z3.string().nullish(),
|
|
831
|
+
index: z3.number()
|
|
765
832
|
})
|
|
766
833
|
),
|
|
767
834
|
usage: mistralUsageSchema.nullish()
|
|
768
835
|
});
|
|
769
836
|
|
|
770
837
|
// src/mistral-embedding-model.ts
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
838
|
+
import {
|
|
839
|
+
TooManyEmbeddingValuesForCallError
|
|
840
|
+
} from "@ai-sdk/provider";
|
|
841
|
+
import {
|
|
842
|
+
combineHeaders as combineHeaders2,
|
|
843
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
844
|
+
postJsonToApi as postJsonToApi2,
|
|
845
|
+
serializeModelOptions as serializeModelOptions2,
|
|
846
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
847
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
848
|
+
} from "@ai-sdk/provider-utils";
|
|
849
|
+
import { z as z4 } from "zod/v4";
|
|
850
|
+
var MistralEmbeddingModel = class _MistralEmbeddingModel {
|
|
775
851
|
constructor(modelId, config) {
|
|
776
852
|
this.specificationVersion = "v4";
|
|
777
853
|
this.maxEmbeddingsPerCall = 32;
|
|
@@ -782,13 +858,23 @@ var MistralEmbeddingModel = class {
|
|
|
782
858
|
get provider() {
|
|
783
859
|
return this.config.provider;
|
|
784
860
|
}
|
|
861
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
862
|
+
return serializeModelOptions2({
|
|
863
|
+
modelId: model.modelId,
|
|
864
|
+
config: model.config
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
868
|
+
return new _MistralEmbeddingModel(options.modelId, options.config);
|
|
869
|
+
}
|
|
785
870
|
async doEmbed({
|
|
786
871
|
values,
|
|
787
872
|
abortSignal,
|
|
788
873
|
headers
|
|
789
874
|
}) {
|
|
875
|
+
var _a, _b;
|
|
790
876
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
791
|
-
throw new
|
|
877
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
792
878
|
provider: this.provider,
|
|
793
879
|
modelId: this.modelId,
|
|
794
880
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -799,16 +885,16 @@ var MistralEmbeddingModel = class {
|
|
|
799
885
|
responseHeaders,
|
|
800
886
|
value: response,
|
|
801
887
|
rawValue
|
|
802
|
-
} = await (
|
|
888
|
+
} = await postJsonToApi2({
|
|
803
889
|
url: `${this.config.baseURL}/embeddings`,
|
|
804
|
-
headers: (
|
|
890
|
+
headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), headers),
|
|
805
891
|
body: {
|
|
806
892
|
model: this.modelId,
|
|
807
893
|
input: values,
|
|
808
894
|
encoding_format: "float"
|
|
809
895
|
},
|
|
810
896
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
811
|
-
successfulResponseHandler: (
|
|
897
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
812
898
|
MistralTextEmbeddingResponseSchema
|
|
813
899
|
),
|
|
814
900
|
abortSignal,
|
|
@@ -822,21 +908,21 @@ var MistralEmbeddingModel = class {
|
|
|
822
908
|
};
|
|
823
909
|
}
|
|
824
910
|
};
|
|
825
|
-
var MistralTextEmbeddingResponseSchema =
|
|
826
|
-
data:
|
|
827
|
-
usage:
|
|
911
|
+
var MistralTextEmbeddingResponseSchema = z4.object({
|
|
912
|
+
data: z4.array(z4.object({ embedding: z4.array(z4.number()) })),
|
|
913
|
+
usage: z4.object({ prompt_tokens: z4.number() }).nullish()
|
|
828
914
|
});
|
|
829
915
|
|
|
830
916
|
// src/version.ts
|
|
831
|
-
var VERSION = true ? "4.0.0-beta.
|
|
917
|
+
var VERSION = true ? "4.0.0-beta.55" : "0.0.0-test";
|
|
832
918
|
|
|
833
919
|
// src/mistral-provider.ts
|
|
834
920
|
function createMistral(options = {}) {
|
|
835
921
|
var _a;
|
|
836
|
-
const baseURL = (_a =
|
|
837
|
-
const getHeaders = () =>
|
|
922
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.mistral.ai/v1";
|
|
923
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
838
924
|
{
|
|
839
|
-
Authorization: `Bearer ${
|
|
925
|
+
Authorization: `Bearer ${loadApiKey({
|
|
840
926
|
apiKey: options.apiKey,
|
|
841
927
|
environmentVariableName: "MISTRAL_API_KEY",
|
|
842
928
|
description: "Mistral"
|
|
@@ -874,15 +960,14 @@ function createMistral(options = {}) {
|
|
|
874
960
|
provider.textEmbedding = createEmbeddingModel;
|
|
875
961
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
876
962
|
provider.imageModel = (modelId) => {
|
|
877
|
-
throw new
|
|
963
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
878
964
|
};
|
|
879
965
|
return provider;
|
|
880
966
|
}
|
|
881
967
|
var mistral = createMistral();
|
|
882
|
-
|
|
883
|
-
0 && (module.exports = {
|
|
968
|
+
export {
|
|
884
969
|
VERSION,
|
|
885
970
|
createMistral,
|
|
886
971
|
mistral
|
|
887
|
-
}
|
|
972
|
+
};
|
|
888
973
|
//# sourceMappingURL=index.js.map
|