@ai-sdk/mistral 2.0.0-canary.1 → 2.0.0-canary.11

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/dist/index.js CHANGED
@@ -27,15 +27,14 @@ module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // src/mistral-provider.ts
29
29
  var import_provider4 = require("@ai-sdk/provider");
30
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
30
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/mistral-chat-language-model.ts
33
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
34
- var import_zod2 = require("zod");
33
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
34
+ var import_zod3 = require("zod");
35
35
 
36
36
  // src/convert-to-mistral-chat-messages.ts
37
37
  var import_provider = require("@ai-sdk/provider");
38
- var import_provider_utils = require("@ai-sdk/provider-utils");
39
38
  function convertToMistralChatMessages(prompt) {
40
39
  const messages = [];
41
40
  for (let i = 0; i < prompt.length; i++) {
@@ -50,36 +49,27 @@ function convertToMistralChatMessages(prompt) {
50
49
  messages.push({
51
50
  role: "user",
52
51
  content: content.map((part) => {
53
- var _a;
54
52
  switch (part.type) {
55
53
  case "text": {
56
54
  return { type: "text", text: part.text };
57
55
  }
58
- case "image": {
59
- return {
60
- type: "image_url",
61
- image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils.convertUint8ArrayToBase64)(part.image)}`
62
- };
63
- }
64
56
  case "file": {
65
- if (!(part.data instanceof URL)) {
57
+ if (part.mediaType.startsWith("image/")) {
58
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
59
+ return {
60
+ type: "image_url",
61
+ image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`
62
+ };
63
+ } else if (part.mediaType === "application/pdf") {
64
+ return {
65
+ type: "document_url",
66
+ document_url: part.data.toString()
67
+ };
68
+ } else {
66
69
  throw new import_provider.UnsupportedFunctionalityError({
67
- functionality: "File content parts in user messages"
70
+ functionality: "Only images and PDF file parts are supported"
68
71
  });
69
72
  }
70
- switch (part.mimeType) {
71
- case "application/pdf": {
72
- return {
73
- type: "document_url",
74
- document_url: part.data.toString()
75
- };
76
- }
77
- default: {
78
- throw new import_provider.UnsupportedFunctionalityError({
79
- functionality: "Only PDF files are supported in user messages"
80
- });
81
- }
82
- }
83
73
  }
84
74
  }
85
75
  })
@@ -136,6 +126,19 @@ function convertToMistralChatMessages(prompt) {
136
126
  return messages;
137
127
  }
138
128
 
129
+ // src/get-response-metadata.ts
130
+ function getResponseMetadata({
131
+ id,
132
+ model,
133
+ created
134
+ }) {
135
+ return {
136
+ id: id != null ? id : void 0,
137
+ modelId: model != null ? model : void 0,
138
+ timestamp: created != null ? new Date(created * 1e3) : void 0
139
+ };
140
+ }
141
+
139
142
  // src/map-mistral-finish-reason.ts
140
143
  function mapMistralFinishReason(finishReason) {
141
144
  switch (finishReason) {
@@ -151,42 +154,44 @@ function mapMistralFinishReason(finishReason) {
151
154
  }
152
155
  }
153
156
 
154
- // src/mistral-error.ts
155
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
157
+ // src/mistral-chat-options.ts
156
158
  var import_zod = require("zod");
157
- var mistralErrorDataSchema = import_zod.z.object({
158
- object: import_zod.z.literal("error"),
159
- message: import_zod.z.string(),
160
- type: import_zod.z.string(),
161
- param: import_zod.z.string().nullable(),
162
- code: import_zod.z.string().nullable()
159
+ var mistralProviderOptions = import_zod.z.object({
160
+ /**
161
+ Whether to inject a safety prompt before all conversations.
162
+
163
+ Defaults to `false`.
164
+ */
165
+ safePrompt: import_zod.z.boolean().nullish(),
166
+ documentImageLimit: import_zod.z.number().nullish(),
167
+ documentPageLimit: import_zod.z.number().nullish()
163
168
  });
164
- var mistralFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
169
+
170
+ // src/mistral-error.ts
171
+ var import_provider_utils = require("@ai-sdk/provider-utils");
172
+ var import_zod2 = require("zod");
173
+ var mistralErrorDataSchema = import_zod2.z.object({
174
+ object: import_zod2.z.literal("error"),
175
+ message: import_zod2.z.string(),
176
+ type: import_zod2.z.string(),
177
+ param: import_zod2.z.string().nullable(),
178
+ code: import_zod2.z.string().nullable()
179
+ });
180
+ var mistralFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
165
181
  errorSchema: mistralErrorDataSchema,
166
182
  errorToMessage: (data) => data.message
167
183
  });
168
184
 
169
- // src/get-response-metadata.ts
170
- function getResponseMetadata({
171
- id,
172
- model,
173
- created
174
- }) {
175
- return {
176
- id: id != null ? id : void 0,
177
- modelId: model != null ? model : void 0,
178
- timestamp: created != null ? new Date(created * 1e3) : void 0
179
- };
180
- }
181
-
182
185
  // src/mistral-prepare-tools.ts
183
186
  var import_provider2 = require("@ai-sdk/provider");
184
- function prepareTools(mode) {
185
- var _a;
186
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
187
+ function prepareTools({
188
+ tools,
189
+ toolChoice
190
+ }) {
191
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
187
192
  const toolWarnings = [];
188
193
  if (tools == null) {
189
- return { tools: void 0, tool_choice: void 0, toolWarnings };
194
+ return { tools: void 0, toolChoice: void 0, toolWarnings };
190
195
  }
191
196
  const mistralTools = [];
192
197
  for (const tool of tools) {
@@ -203,29 +208,28 @@ function prepareTools(mode) {
203
208
  });
204
209
  }
205
210
  }
206
- const toolChoice = mode.toolChoice;
207
211
  if (toolChoice == null) {
208
- return { tools: mistralTools, tool_choice: void 0, toolWarnings };
212
+ return { tools: mistralTools, toolChoice: void 0, toolWarnings };
209
213
  }
210
214
  const type = toolChoice.type;
211
215
  switch (type) {
212
216
  case "auto":
213
217
  case "none":
214
- return { tools: mistralTools, tool_choice: type, toolWarnings };
218
+ return { tools: mistralTools, toolChoice: type, toolWarnings };
215
219
  case "required":
216
- return { tools: mistralTools, tool_choice: "any", toolWarnings };
220
+ return { tools: mistralTools, toolChoice: "any", toolWarnings };
217
221
  case "tool":
218
222
  return {
219
223
  tools: mistralTools.filter(
220
224
  (tool) => tool.function.name === toolChoice.toolName
221
225
  ),
222
- tool_choice: "any",
226
+ toolChoice: "any",
223
227
  toolWarnings
224
228
  };
225
229
  default: {
226
230
  const _exhaustiveCheck = type;
227
231
  throw new import_provider2.UnsupportedFunctionalityError({
228
- functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
232
+ functionality: `tool choice type: ${_exhaustiveCheck}`
229
233
  });
230
234
  }
231
235
  }
@@ -233,24 +237,22 @@ function prepareTools(mode) {
233
237
 
234
238
  // src/mistral-chat-language-model.ts
235
239
  var MistralChatLanguageModel = class {
236
- constructor(modelId, settings, config) {
240
+ constructor(modelId, config) {
237
241
  this.specificationVersion = "v2";
238
- this.defaultObjectGenerationMode = "json";
239
- this.supportsImageUrls = false;
240
242
  this.modelId = modelId;
241
- this.settings = settings;
242
243
  this.config = config;
243
244
  }
244
245
  get provider() {
245
246
  return this.config.provider;
246
247
  }
247
- supportsUrl(url) {
248
- return url.protocol === "https:";
248
+ async getSupportedUrls() {
249
+ return {
250
+ "application/pdf": [/^https:\/\/.*$/]
251
+ };
249
252
  }
250
- getArgs({
251
- mode,
253
+ async getArgs({
252
254
  prompt,
253
- maxTokens,
255
+ maxOutputTokens,
254
256
  temperature,
255
257
  topP,
256
258
  topK,
@@ -259,11 +261,17 @@ var MistralChatLanguageModel = class {
259
261
  stopSequences,
260
262
  responseFormat,
261
263
  seed,
262
- providerMetadata
264
+ providerOptions,
265
+ tools,
266
+ toolChoice
263
267
  }) {
264
- var _a, _b;
265
- const type = mode.type;
268
+ var _a;
266
269
  const warnings = [];
270
+ const options = (_a = await (0, import_provider_utils2.parseProviderOptions)({
271
+ provider: "mistral",
272
+ providerOptions,
273
+ schema: mistralProviderOptions
274
+ })) != null ? _a : {};
267
275
  if (topK != null) {
268
276
  warnings.push({
269
277
  type: "unsupported-setting",
@@ -299,126 +307,118 @@ var MistralChatLanguageModel = class {
299
307
  // model id:
300
308
  model: this.modelId,
301
309
  // model specific settings:
302
- safe_prompt: this.settings.safePrompt,
310
+ safe_prompt: options.safePrompt,
303
311
  // standardized settings:
304
- max_tokens: maxTokens,
312
+ max_tokens: maxOutputTokens,
305
313
  temperature,
306
314
  top_p: topP,
307
315
  random_seed: seed,
308
316
  // response format:
309
317
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? { type: "json_object" } : void 0,
310
318
  // mistral-specific provider options:
311
- document_image_limit: (_a = providerMetadata == null ? void 0 : providerMetadata.mistral) == null ? void 0 : _a.documentImageLimit,
312
- document_page_limit: (_b = providerMetadata == null ? void 0 : providerMetadata.mistral) == null ? void 0 : _b.documentPageLimit,
319
+ document_image_limit: options.documentImageLimit,
320
+ document_page_limit: options.documentPageLimit,
313
321
  // messages:
314
322
  messages: convertToMistralChatMessages(prompt)
315
323
  };
316
- switch (type) {
317
- case "regular": {
318
- const { tools, tool_choice, toolWarnings } = prepareTools(mode);
319
- return {
320
- args: { ...baseArgs, tools, tool_choice },
321
- warnings: [...warnings, ...toolWarnings]
322
- };
323
- }
324
- case "object-json": {
325
- return {
326
- args: {
327
- ...baseArgs,
328
- response_format: { type: "json_object" }
329
- },
330
- warnings
331
- };
332
- }
333
- case "object-tool": {
334
- return {
335
- args: {
336
- ...baseArgs,
337
- tool_choice: "any",
338
- tools: [{ type: "function", function: mode.tool }]
339
- },
340
- warnings
341
- };
342
- }
343
- default: {
344
- const _exhaustiveCheck = type;
345
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
346
- }
347
- }
324
+ const {
325
+ tools: mistralTools,
326
+ toolChoice: mistralToolChoice,
327
+ toolWarnings
328
+ } = prepareTools({
329
+ tools,
330
+ toolChoice
331
+ });
332
+ return {
333
+ args: {
334
+ ...baseArgs,
335
+ tools: mistralTools,
336
+ tool_choice: mistralToolChoice
337
+ },
338
+ warnings: [...warnings, ...toolWarnings]
339
+ };
348
340
  }
349
341
  async doGenerate(options) {
350
- var _a;
351
- const { args, warnings } = this.getArgs(options);
342
+ const { args: body, warnings } = await this.getArgs(options);
352
343
  const {
353
344
  responseHeaders,
354
345
  value: response,
355
346
  rawValue: rawResponse
356
- } = await (0, import_provider_utils3.postJsonToApi)({
347
+ } = await (0, import_provider_utils2.postJsonToApi)({
357
348
  url: `${this.config.baseURL}/chat/completions`,
358
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
359
- body: args,
349
+ headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
350
+ body,
360
351
  failedResponseHandler: mistralFailedResponseHandler,
361
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
352
+ successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
362
353
  mistralChatResponseSchema
363
354
  ),
364
355
  abortSignal: options.abortSignal,
365
356
  fetch: this.config.fetch
366
357
  });
367
- const { messages: rawPrompt, ...rawSettings } = args;
368
358
  const choice = response.choices[0];
359
+ const content = [];
369
360
  let text = extractTextContent(choice.message.content);
370
- const lastMessage = rawPrompt[rawPrompt.length - 1];
361
+ const lastMessage = body.messages[body.messages.length - 1];
371
362
  if (lastMessage.role === "assistant" && (text == null ? void 0 : text.startsWith(lastMessage.content))) {
372
363
  text = text.slice(lastMessage.content.length);
373
364
  }
365
+ if (text != null && text.length > 0) {
366
+ content.push({ type: "text", text });
367
+ }
368
+ if (choice.message.tool_calls != null) {
369
+ for (const toolCall of choice.message.tool_calls) {
370
+ content.push({
371
+ type: "tool-call",
372
+ toolCallType: "function",
373
+ toolCallId: toolCall.id,
374
+ toolName: toolCall.function.name,
375
+ args: toolCall.function.arguments
376
+ });
377
+ }
378
+ }
374
379
  return {
375
- text,
376
- toolCalls: (_a = choice.message.tool_calls) == null ? void 0 : _a.map((toolCall) => ({
377
- toolCallType: "function",
378
- toolCallId: toolCall.id,
379
- toolName: toolCall.function.name,
380
- args: toolCall.function.arguments
381
- })),
380
+ content,
382
381
  finishReason: mapMistralFinishReason(choice.finish_reason),
383
382
  usage: {
384
- promptTokens: response.usage.prompt_tokens,
385
- completionTokens: response.usage.completion_tokens
383
+ inputTokens: response.usage.prompt_tokens,
384
+ outputTokens: response.usage.completion_tokens
386
385
  },
387
- rawCall: { rawPrompt, rawSettings },
388
- rawResponse: {
386
+ request: { body },
387
+ response: {
388
+ ...getResponseMetadata(response),
389
389
  headers: responseHeaders,
390
390
  body: rawResponse
391
391
  },
392
- request: { body: JSON.stringify(args) },
393
- response: getResponseMetadata(response),
394
392
  warnings
395
393
  };
396
394
  }
397
395
  async doStream(options) {
398
- const { args, warnings } = this.getArgs(options);
396
+ const { args, warnings } = await this.getArgs(options);
399
397
  const body = { ...args, stream: true };
400
- const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
398
+ const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
401
399
  url: `${this.config.baseURL}/chat/completions`,
402
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
400
+ headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
403
401
  body,
404
402
  failedResponseHandler: mistralFailedResponseHandler,
405
- successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
403
+ successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(
406
404
  mistralChatChunkSchema
407
405
  ),
408
406
  abortSignal: options.abortSignal,
409
407
  fetch: this.config.fetch
410
408
  });
411
- const { messages: rawPrompt, ...rawSettings } = args;
412
409
  let finishReason = "unknown";
413
- let usage = {
414
- promptTokens: Number.NaN,
415
- completionTokens: Number.NaN
410
+ const usage = {
411
+ inputTokens: void 0,
412
+ outputTokens: void 0
416
413
  };
417
414
  let chunkNumber = 0;
418
415
  let trimLeadingSpace = false;
419
416
  return {
420
417
  stream: response.pipeThrough(
421
418
  new TransformStream({
419
+ start(controller) {
420
+ controller.enqueue({ type: "stream-start", warnings });
421
+ },
422
422
  transform(chunk, controller) {
423
423
  if (!chunk.success) {
424
424
  controller.enqueue({ type: "error", error: chunk.error });
@@ -433,10 +433,8 @@ var MistralChatLanguageModel = class {
433
433
  });
434
434
  }
435
435
  if (value.usage != null) {
436
- usage = {
437
- promptTokens: value.usage.prompt_tokens,
438
- completionTokens: value.usage.completion_tokens
439
- };
436
+ usage.inputTokens = value.usage.prompt_tokens;
437
+ usage.outputTokens = value.usage.completion_tokens;
440
438
  }
441
439
  const choice = value.choices[0];
442
440
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
@@ -448,7 +446,7 @@ var MistralChatLanguageModel = class {
448
446
  const delta = choice.delta;
449
447
  const textContent = extractTextContent(delta.content);
450
448
  if (chunkNumber <= 2) {
451
- const lastMessage = rawPrompt[rawPrompt.length - 1];
449
+ const lastMessage = body.messages[body.messages.length - 1];
452
450
  if (lastMessage.role === "assistant" && textContent === lastMessage.content.trimEnd()) {
453
451
  if (textContent.length < lastMessage.content.length) {
454
452
  trimLeadingSpace = true;
@@ -458,8 +456,8 @@ var MistralChatLanguageModel = class {
458
456
  }
459
457
  if (textContent != null) {
460
458
  controller.enqueue({
461
- type: "text-delta",
462
- textDelta: trimLeadingSpace ? textContent.trimStart() : textContent
459
+ type: "text",
460
+ text: trimLeadingSpace ? textContent.trimStart() : textContent
463
461
  });
464
462
  trimLeadingSpace = false;
465
463
  }
@@ -487,10 +485,8 @@ var MistralChatLanguageModel = class {
487
485
  }
488
486
  })
489
487
  ),
490
- rawCall: { rawPrompt, rawSettings },
491
- rawResponse: { headers: responseHeaders },
492
- request: { body: JSON.stringify(body) },
493
- warnings
488
+ request: { body },
489
+ response: { headers: responseHeaders }
494
490
  };
495
491
  }
496
492
  };
@@ -519,90 +515,90 @@ function extractTextContent(content) {
519
515
  }
520
516
  return textContent.length ? textContent.join("") : void 0;
521
517
  }
522
- var mistralContentSchema = import_zod2.z.union([
523
- import_zod2.z.string(),
524
- import_zod2.z.array(
525
- import_zod2.z.discriminatedUnion("type", [
526
- import_zod2.z.object({
527
- type: import_zod2.z.literal("text"),
528
- text: import_zod2.z.string()
518
+ var mistralContentSchema = import_zod3.z.union([
519
+ import_zod3.z.string(),
520
+ import_zod3.z.array(
521
+ import_zod3.z.discriminatedUnion("type", [
522
+ import_zod3.z.object({
523
+ type: import_zod3.z.literal("text"),
524
+ text: import_zod3.z.string()
529
525
  }),
530
- import_zod2.z.object({
531
- type: import_zod2.z.literal("image_url"),
532
- image_url: import_zod2.z.union([
533
- import_zod2.z.string(),
534
- import_zod2.z.object({
535
- url: import_zod2.z.string(),
536
- detail: import_zod2.z.string().nullable()
526
+ import_zod3.z.object({
527
+ type: import_zod3.z.literal("image_url"),
528
+ image_url: import_zod3.z.union([
529
+ import_zod3.z.string(),
530
+ import_zod3.z.object({
531
+ url: import_zod3.z.string(),
532
+ detail: import_zod3.z.string().nullable()
537
533
  })
538
534
  ])
539
535
  }),
540
- import_zod2.z.object({
541
- type: import_zod2.z.literal("reference"),
542
- reference_ids: import_zod2.z.array(import_zod2.z.number())
536
+ import_zod3.z.object({
537
+ type: import_zod3.z.literal("reference"),
538
+ reference_ids: import_zod3.z.array(import_zod3.z.number())
543
539
  })
544
540
  ])
545
541
  )
546
542
  ]).nullish();
547
- var mistralChatResponseSchema = import_zod2.z.object({
548
- id: import_zod2.z.string().nullish(),
549
- created: import_zod2.z.number().nullish(),
550
- model: import_zod2.z.string().nullish(),
551
- choices: import_zod2.z.array(
552
- import_zod2.z.object({
553
- message: import_zod2.z.object({
554
- role: import_zod2.z.literal("assistant"),
543
+ var mistralChatResponseSchema = import_zod3.z.object({
544
+ id: import_zod3.z.string().nullish(),
545
+ created: import_zod3.z.number().nullish(),
546
+ model: import_zod3.z.string().nullish(),
547
+ choices: import_zod3.z.array(
548
+ import_zod3.z.object({
549
+ message: import_zod3.z.object({
550
+ role: import_zod3.z.literal("assistant"),
555
551
  content: mistralContentSchema,
556
- tool_calls: import_zod2.z.array(
557
- import_zod2.z.object({
558
- id: import_zod2.z.string(),
559
- function: import_zod2.z.object({ name: import_zod2.z.string(), arguments: import_zod2.z.string() })
552
+ tool_calls: import_zod3.z.array(
553
+ import_zod3.z.object({
554
+ id: import_zod3.z.string(),
555
+ function: import_zod3.z.object({ name: import_zod3.z.string(), arguments: import_zod3.z.string() })
560
556
  })
561
557
  ).nullish()
562
558
  }),
563
- index: import_zod2.z.number(),
564
- finish_reason: import_zod2.z.string().nullish()
559
+ index: import_zod3.z.number(),
560
+ finish_reason: import_zod3.z.string().nullish()
565
561
  })
566
562
  ),
567
- object: import_zod2.z.literal("chat.completion"),
568
- usage: import_zod2.z.object({
569
- prompt_tokens: import_zod2.z.number(),
570
- completion_tokens: import_zod2.z.number()
563
+ object: import_zod3.z.literal("chat.completion"),
564
+ usage: import_zod3.z.object({
565
+ prompt_tokens: import_zod3.z.number(),
566
+ completion_tokens: import_zod3.z.number()
571
567
  })
572
568
  });
573
- var mistralChatChunkSchema = import_zod2.z.object({
574
- id: import_zod2.z.string().nullish(),
575
- created: import_zod2.z.number().nullish(),
576
- model: import_zod2.z.string().nullish(),
577
- choices: import_zod2.z.array(
578
- import_zod2.z.object({
579
- delta: import_zod2.z.object({
580
- role: import_zod2.z.enum(["assistant"]).optional(),
569
+ var mistralChatChunkSchema = import_zod3.z.object({
570
+ id: import_zod3.z.string().nullish(),
571
+ created: import_zod3.z.number().nullish(),
572
+ model: import_zod3.z.string().nullish(),
573
+ choices: import_zod3.z.array(
574
+ import_zod3.z.object({
575
+ delta: import_zod3.z.object({
576
+ role: import_zod3.z.enum(["assistant"]).optional(),
581
577
  content: mistralContentSchema,
582
- tool_calls: import_zod2.z.array(
583
- import_zod2.z.object({
584
- id: import_zod2.z.string(),
585
- function: import_zod2.z.object({ name: import_zod2.z.string(), arguments: import_zod2.z.string() })
578
+ tool_calls: import_zod3.z.array(
579
+ import_zod3.z.object({
580
+ id: import_zod3.z.string(),
581
+ function: import_zod3.z.object({ name: import_zod3.z.string(), arguments: import_zod3.z.string() })
586
582
  })
587
583
  ).nullish()
588
584
  }),
589
- finish_reason: import_zod2.z.string().nullish(),
590
- index: import_zod2.z.number()
585
+ finish_reason: import_zod3.z.string().nullish(),
586
+ index: import_zod3.z.number()
591
587
  })
592
588
  ),
593
- usage: import_zod2.z.object({
594
- prompt_tokens: import_zod2.z.number(),
595
- completion_tokens: import_zod2.z.number()
589
+ usage: import_zod3.z.object({
590
+ prompt_tokens: import_zod3.z.number(),
591
+ completion_tokens: import_zod3.z.number()
596
592
  }).nullish()
597
593
  });
598
594
 
599
595
  // src/mistral-embedding-model.ts
600
596
  var import_provider3 = require("@ai-sdk/provider");
601
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
602
- var import_zod3 = require("zod");
597
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
598
+ var import_zod4 = require("zod");
603
599
  var MistralEmbeddingModel = class {
604
600
  constructor(modelId, settings, config) {
605
- this.specificationVersion = "v1";
601
+ this.specificationVersion = "v2";
606
602
  this.modelId = modelId;
607
603
  this.settings = settings;
608
604
  this.config = config;
@@ -631,16 +627,20 @@ var MistralEmbeddingModel = class {
631
627
  values
632
628
  });
633
629
  }
634
- const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
630
+ const {
631
+ responseHeaders,
632
+ value: response,
633
+ rawValue
634
+ } = await (0, import_provider_utils3.postJsonToApi)({
635
635
  url: `${this.config.baseURL}/embeddings`,
636
- headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), headers),
636
+ headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), headers),
637
637
  body: {
638
638
  model: this.modelId,
639
639
  input: values,
640
640
  encoding_format: "float"
641
641
  },
642
642
  failedResponseHandler: mistralFailedResponseHandler,
643
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
643
+ successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
644
644
  MistralTextEmbeddingResponseSchema
645
645
  ),
646
646
  abortSignal,
@@ -649,28 +649,28 @@ var MistralEmbeddingModel = class {
649
649
  return {
650
650
  embeddings: response.data.map((item) => item.embedding),
651
651
  usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
652
- rawResponse: { headers: responseHeaders }
652
+ response: { headers: responseHeaders, body: rawValue }
653
653
  };
654
654
  }
655
655
  };
656
- var MistralTextEmbeddingResponseSchema = import_zod3.z.object({
657
- data: import_zod3.z.array(import_zod3.z.object({ embedding: import_zod3.z.array(import_zod3.z.number()) })),
658
- usage: import_zod3.z.object({ prompt_tokens: import_zod3.z.number() }).nullish()
656
+ var MistralTextEmbeddingResponseSchema = import_zod4.z.object({
657
+ data: import_zod4.z.array(import_zod4.z.object({ embedding: import_zod4.z.array(import_zod4.z.number()) })),
658
+ usage: import_zod4.z.object({ prompt_tokens: import_zod4.z.number() }).nullish()
659
659
  });
660
660
 
661
661
  // src/mistral-provider.ts
662
662
  function createMistral(options = {}) {
663
663
  var _a;
664
- const baseURL = (_a = (0, import_provider_utils5.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.mistral.ai/v1";
664
+ const baseURL = (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.mistral.ai/v1";
665
665
  const getHeaders = () => ({
666
- Authorization: `Bearer ${(0, import_provider_utils5.loadApiKey)({
666
+ Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
667
667
  apiKey: options.apiKey,
668
668
  environmentVariableName: "MISTRAL_API_KEY",
669
669
  description: "Mistral"
670
670
  })}`,
671
671
  ...options.headers
672
672
  });
673
- const createChatModel = (modelId, settings = {}) => new MistralChatLanguageModel(modelId, settings, {
673
+ const createChatModel = (modelId) => new MistralChatLanguageModel(modelId, {
674
674
  provider: "mistral.chat",
675
675
  baseURL,
676
676
  headers: getHeaders,
@@ -682,13 +682,13 @@ function createMistral(options = {}) {
682
682
  headers: getHeaders,
683
683
  fetch: options.fetch
684
684
  });
685
- const provider = function(modelId, settings) {
685
+ const provider = function(modelId) {
686
686
  if (new.target) {
687
687
  throw new Error(
688
688
  "The Mistral model function cannot be called with the new keyword."
689
689
  );
690
690
  }
691
- return createChatModel(modelId, settings);
691
+ return createChatModel(modelId);
692
692
  };
693
693
  provider.languageModel = createChatModel;
694
694
  provider.chat = createChatModel;