@ai-sdk/mistral 2.0.0-canary.0 → 2.0.0-canary.10

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