@ai-sdk/mistral 2.0.0-canary.6 → 2.0.0-canary.8

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 CHANGED
@@ -1,5 +1,39 @@
1
1
  # @ai-sdk/mistral
2
2
 
3
+ ## 2.0.0-canary.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [5d142ab]
8
+ - Updated dependencies [b6b43c7]
9
+ - Updated dependencies [8aa9e20]
10
+ - Updated dependencies [3795467]
11
+ - @ai-sdk/provider-utils@3.0.0-canary.8
12
+ - @ai-sdk/provider@2.0.0-canary.7
13
+
14
+ ## 2.0.0-canary.7
15
+
16
+ ### Patch Changes
17
+
18
+ - 1251401: chore(providers/mistral): convert to providerOptions
19
+ - 26735b5: chore(embedding-model): add v2 interface
20
+ - 443d8ec: feat(embedding-model-v2): add response body field
21
+ - fd65bc6: chore(embedding-model-v2): rename rawResponse to response
22
+ - Updated dependencies [26735b5]
23
+ - Updated dependencies [443d8ec]
24
+ - Updated dependencies [14c9410]
25
+ - Updated dependencies [d9c98f4]
26
+ - Updated dependencies [c4a2fec]
27
+ - Updated dependencies [0054544]
28
+ - Updated dependencies [9e9c809]
29
+ - Updated dependencies [32831c6]
30
+ - Updated dependencies [d0f9495]
31
+ - Updated dependencies [fd65bc6]
32
+ - Updated dependencies [393138b]
33
+ - Updated dependencies [7182d14]
34
+ - @ai-sdk/provider@2.0.0-canary.6
35
+ - @ai-sdk/provider-utils@3.0.0-canary.7
36
+
3
37
  ## 2.0.0-canary.6
4
38
 
5
39
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,15 +1,7 @@
1
- import { ProviderV2, LanguageModelV2, EmbeddingModelV1 } from '@ai-sdk/provider';
1
+ import { ProviderV2, LanguageModelV2, EmbeddingModelV2 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
3
 
4
4
  type MistralChatModelId = 'ministral-3b-latest' | 'ministral-8b-latest' | 'mistral-large-latest' | 'mistral-small-latest' | 'pixtral-large-latest' | 'pixtral-12b-2409' | 'open-mistral-7b' | 'open-mixtral-8x7b' | 'open-mixtral-8x22b' | (string & {});
5
- interface MistralChatSettings {
6
- /**
7
- Whether to inject a safety prompt before all conversations.
8
-
9
- Defaults to `false`.
10
- */
11
- safePrompt?: boolean;
12
- }
13
5
 
14
6
  type MistralEmbeddingModelId = 'mistral-embed' | (string & {});
15
7
  interface MistralEmbeddingSettings {
@@ -24,24 +16,24 @@ interface MistralEmbeddingSettings {
24
16
  }
25
17
 
26
18
  interface MistralProvider extends ProviderV2 {
27
- (modelId: MistralChatModelId, settings?: MistralChatSettings): LanguageModelV2;
19
+ (modelId: MistralChatModelId): LanguageModelV2;
28
20
  /**
29
21
  Creates a model for text generation.
30
22
  */
31
- languageModel(modelId: MistralChatModelId, settings?: MistralChatSettings): LanguageModelV2;
23
+ languageModel(modelId: MistralChatModelId): LanguageModelV2;
32
24
  /**
33
25
  Creates a model for text generation.
34
26
  */
35
- chat(modelId: MistralChatModelId, settings?: MistralChatSettings): LanguageModelV2;
27
+ chat(modelId: MistralChatModelId): LanguageModelV2;
36
28
  /**
37
29
  @deprecated Use `textEmbeddingModel()` instead.
38
30
  */
39
- embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV1<string>;
31
+ embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV2<string>;
40
32
  /**
41
33
  @deprecated Use `textEmbeddingModel()` instead.
42
34
  */
43
- textEmbedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV1<string>;
44
- textEmbeddingModel: (modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings) => EmbeddingModelV1<string>;
35
+ textEmbedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV2<string>;
36
+ textEmbeddingModel: (modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings) => EmbeddingModelV2<string>;
45
37
  }
46
38
  interface MistralProviderSettings {
47
39
  /**
package/dist/index.d.ts CHANGED
@@ -1,15 +1,7 @@
1
- import { ProviderV2, LanguageModelV2, EmbeddingModelV1 } from '@ai-sdk/provider';
1
+ import { ProviderV2, LanguageModelV2, EmbeddingModelV2 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
3
 
4
4
  type MistralChatModelId = 'ministral-3b-latest' | 'ministral-8b-latest' | 'mistral-large-latest' | 'mistral-small-latest' | 'pixtral-large-latest' | 'pixtral-12b-2409' | 'open-mistral-7b' | 'open-mixtral-8x7b' | 'open-mixtral-8x22b' | (string & {});
5
- interface MistralChatSettings {
6
- /**
7
- Whether to inject a safety prompt before all conversations.
8
-
9
- Defaults to `false`.
10
- */
11
- safePrompt?: boolean;
12
- }
13
5
 
14
6
  type MistralEmbeddingModelId = 'mistral-embed' | (string & {});
15
7
  interface MistralEmbeddingSettings {
@@ -24,24 +16,24 @@ interface MistralEmbeddingSettings {
24
16
  }
25
17
 
26
18
  interface MistralProvider extends ProviderV2 {
27
- (modelId: MistralChatModelId, settings?: MistralChatSettings): LanguageModelV2;
19
+ (modelId: MistralChatModelId): LanguageModelV2;
28
20
  /**
29
21
  Creates a model for text generation.
30
22
  */
31
- languageModel(modelId: MistralChatModelId, settings?: MistralChatSettings): LanguageModelV2;
23
+ languageModel(modelId: MistralChatModelId): LanguageModelV2;
32
24
  /**
33
25
  Creates a model for text generation.
34
26
  */
35
- chat(modelId: MistralChatModelId, settings?: MistralChatSettings): LanguageModelV2;
27
+ chat(modelId: MistralChatModelId): LanguageModelV2;
36
28
  /**
37
29
  @deprecated Use `textEmbeddingModel()` instead.
38
30
  */
39
- embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV1<string>;
31
+ embedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV2<string>;
40
32
  /**
41
33
  @deprecated Use `textEmbeddingModel()` instead.
42
34
  */
43
- textEmbedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV1<string>;
44
- textEmbeddingModel: (modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings) => EmbeddingModelV1<string>;
35
+ textEmbedding(modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings): EmbeddingModelV2<string>;
36
+ textEmbeddingModel: (modelId: MistralEmbeddingModelId, settings?: MistralEmbeddingSettings) => EmbeddingModelV2<string>;
45
37
  }
46
38
  interface MistralProviderSettings {
47
39
  /**
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider_utils4 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/mistral-chat-language-model.ts
33
33
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
34
- var import_zod2 = require("zod");
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");
@@ -154,15 +154,28 @@ function mapMistralFinishReason(finishReason) {
154
154
  }
155
155
  }
156
156
 
157
+ // src/mistral-chat-options.ts
158
+ var import_zod = require("zod");
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()
168
+ });
169
+
157
170
  // src/mistral-error.ts
158
171
  var import_provider_utils = require("@ai-sdk/provider-utils");
159
- var import_zod = require("zod");
160
- var mistralErrorDataSchema = import_zod.z.object({
161
- object: import_zod.z.literal("error"),
162
- message: import_zod.z.string(),
163
- type: import_zod.z.string(),
164
- param: import_zod.z.string().nullable(),
165
- code: import_zod.z.string().nullable()
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()
166
179
  });
167
180
  var mistralFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
168
181
  errorSchema: mistralErrorDataSchema,
@@ -224,12 +237,11 @@ function prepareTools({
224
237
 
225
238
  // src/mistral-chat-language-model.ts
226
239
  var MistralChatLanguageModel = class {
227
- constructor(modelId, settings, config) {
240
+ constructor(modelId, config) {
228
241
  this.specificationVersion = "v2";
229
242
  this.defaultObjectGenerationMode = "json";
230
243
  this.supportsImageUrls = false;
231
244
  this.modelId = modelId;
232
- this.settings = settings;
233
245
  this.config = config;
234
246
  }
235
247
  get provider() {
@@ -253,8 +265,13 @@ var MistralChatLanguageModel = class {
253
265
  tools,
254
266
  toolChoice
255
267
  }) {
256
- var _a, _b;
268
+ var _a;
257
269
  const warnings = [];
270
+ const options = (_a = (0, import_provider_utils2.parseProviderOptions)({
271
+ provider: "mistral",
272
+ providerOptions,
273
+ schema: mistralProviderOptions
274
+ })) != null ? _a : {};
258
275
  if (topK != null) {
259
276
  warnings.push({
260
277
  type: "unsupported-setting",
@@ -290,7 +307,7 @@ var MistralChatLanguageModel = class {
290
307
  // model id:
291
308
  model: this.modelId,
292
309
  // model specific settings:
293
- safe_prompt: this.settings.safePrompt,
310
+ safe_prompt: options.safePrompt,
294
311
  // standardized settings:
295
312
  max_tokens: maxOutputTokens,
296
313
  temperature,
@@ -299,8 +316,8 @@ var MistralChatLanguageModel = class {
299
316
  // response format:
300
317
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? { type: "json_object" } : void 0,
301
318
  // mistral-specific provider options:
302
- document_image_limit: (_a = providerOptions == null ? void 0 : providerOptions.mistral) == null ? void 0 : _a.documentImageLimit,
303
- document_page_limit: (_b = providerOptions == null ? void 0 : providerOptions.mistral) == null ? void 0 : _b.documentPageLimit,
319
+ document_image_limit: options.documentImageLimit,
320
+ document_page_limit: options.documentPageLimit,
304
321
  // messages:
305
322
  messages: convertToMistralChatMessages(prompt)
306
323
  };
@@ -322,7 +339,6 @@ var MistralChatLanguageModel = class {
322
339
  };
323
340
  }
324
341
  async doGenerate(options) {
325
- var _a;
326
342
  const { args: body, warnings } = this.getArgs(options);
327
343
  const {
328
344
  responseHeaders,
@@ -340,19 +356,28 @@ var MistralChatLanguageModel = class {
340
356
  fetch: this.config.fetch
341
357
  });
342
358
  const choice = response.choices[0];
359
+ const content = [];
343
360
  let text = extractTextContent(choice.message.content);
344
361
  const lastMessage = body.messages[body.messages.length - 1];
345
362
  if (lastMessage.role === "assistant" && (text == null ? void 0 : text.startsWith(lastMessage.content))) {
346
363
  text = text.slice(lastMessage.content.length);
347
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
+ }
348
379
  return {
349
- text,
350
- toolCalls: (_a = choice.message.tool_calls) == null ? void 0 : _a.map((toolCall) => ({
351
- toolCallType: "function",
352
- toolCallId: toolCall.id,
353
- toolName: toolCall.function.name,
354
- args: toolCall.function.arguments
355
- })),
380
+ content,
356
381
  finishReason: mapMistralFinishReason(choice.finish_reason),
357
382
  usage: {
358
383
  inputTokens: response.usage.prompt_tokens,
@@ -391,6 +416,9 @@ var MistralChatLanguageModel = class {
391
416
  return {
392
417
  stream: response.pipeThrough(
393
418
  new TransformStream({
419
+ start(controller) {
420
+ controller.enqueue({ type: "stream-start", warnings });
421
+ },
394
422
  transform(chunk, controller) {
395
423
  if (!chunk.success) {
396
424
  controller.enqueue({ type: "error", error: chunk.error });
@@ -428,8 +456,8 @@ var MistralChatLanguageModel = class {
428
456
  }
429
457
  if (textContent != null) {
430
458
  controller.enqueue({
431
- type: "text-delta",
432
- textDelta: trimLeadingSpace ? textContent.trimStart() : textContent
459
+ type: "text",
460
+ text: trimLeadingSpace ? textContent.trimStart() : textContent
433
461
  });
434
462
  trimLeadingSpace = false;
435
463
  }
@@ -458,8 +486,7 @@ var MistralChatLanguageModel = class {
458
486
  })
459
487
  ),
460
488
  request: { body },
461
- response: { headers: responseHeaders },
462
- warnings
489
+ response: { headers: responseHeaders }
463
490
  };
464
491
  }
465
492
  };
@@ -488,90 +515,90 @@ function extractTextContent(content) {
488
515
  }
489
516
  return textContent.length ? textContent.join("") : void 0;
490
517
  }
491
- var mistralContentSchema = import_zod2.z.union([
492
- import_zod2.z.string(),
493
- import_zod2.z.array(
494
- import_zod2.z.discriminatedUnion("type", [
495
- import_zod2.z.object({
496
- type: import_zod2.z.literal("text"),
497
- 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()
498
525
  }),
499
- import_zod2.z.object({
500
- type: import_zod2.z.literal("image_url"),
501
- image_url: import_zod2.z.union([
502
- import_zod2.z.string(),
503
- import_zod2.z.object({
504
- url: import_zod2.z.string(),
505
- 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()
506
533
  })
507
534
  ])
508
535
  }),
509
- import_zod2.z.object({
510
- type: import_zod2.z.literal("reference"),
511
- 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())
512
539
  })
513
540
  ])
514
541
  )
515
542
  ]).nullish();
516
- var mistralChatResponseSchema = import_zod2.z.object({
517
- id: import_zod2.z.string().nullish(),
518
- created: import_zod2.z.number().nullish(),
519
- model: import_zod2.z.string().nullish(),
520
- choices: import_zod2.z.array(
521
- import_zod2.z.object({
522
- message: import_zod2.z.object({
523
- 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"),
524
551
  content: mistralContentSchema,
525
- tool_calls: import_zod2.z.array(
526
- import_zod2.z.object({
527
- id: import_zod2.z.string(),
528
- 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() })
529
556
  })
530
557
  ).nullish()
531
558
  }),
532
- index: import_zod2.z.number(),
533
- finish_reason: import_zod2.z.string().nullish()
559
+ index: import_zod3.z.number(),
560
+ finish_reason: import_zod3.z.string().nullish()
534
561
  })
535
562
  ),
536
- object: import_zod2.z.literal("chat.completion"),
537
- usage: import_zod2.z.object({
538
- prompt_tokens: import_zod2.z.number(),
539
- 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()
540
567
  })
541
568
  });
542
- var mistralChatChunkSchema = import_zod2.z.object({
543
- id: import_zod2.z.string().nullish(),
544
- created: import_zod2.z.number().nullish(),
545
- model: import_zod2.z.string().nullish(),
546
- choices: import_zod2.z.array(
547
- import_zod2.z.object({
548
- delta: import_zod2.z.object({
549
- 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(),
550
577
  content: mistralContentSchema,
551
- tool_calls: import_zod2.z.array(
552
- import_zod2.z.object({
553
- id: import_zod2.z.string(),
554
- 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() })
555
582
  })
556
583
  ).nullish()
557
584
  }),
558
- finish_reason: import_zod2.z.string().nullish(),
559
- index: import_zod2.z.number()
585
+ finish_reason: import_zod3.z.string().nullish(),
586
+ index: import_zod3.z.number()
560
587
  })
561
588
  ),
562
- usage: import_zod2.z.object({
563
- prompt_tokens: import_zod2.z.number(),
564
- 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()
565
592
  }).nullish()
566
593
  });
567
594
 
568
595
  // src/mistral-embedding-model.ts
569
596
  var import_provider3 = require("@ai-sdk/provider");
570
597
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
571
- var import_zod3 = require("zod");
598
+ var import_zod4 = require("zod");
572
599
  var MistralEmbeddingModel = class {
573
600
  constructor(modelId, settings, config) {
574
- this.specificationVersion = "v1";
601
+ this.specificationVersion = "v2";
575
602
  this.modelId = modelId;
576
603
  this.settings = settings;
577
604
  this.config = config;
@@ -600,7 +627,11 @@ var MistralEmbeddingModel = class {
600
627
  values
601
628
  });
602
629
  }
603
- const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
630
+ const {
631
+ responseHeaders,
632
+ value: response,
633
+ rawValue
634
+ } = await (0, import_provider_utils3.postJsonToApi)({
604
635
  url: `${this.config.baseURL}/embeddings`,
605
636
  headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), headers),
606
637
  body: {
@@ -618,13 +649,13 @@ var MistralEmbeddingModel = class {
618
649
  return {
619
650
  embeddings: response.data.map((item) => item.embedding),
620
651
  usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
621
- rawResponse: { headers: responseHeaders }
652
+ response: { headers: responseHeaders, body: rawValue }
622
653
  };
623
654
  }
624
655
  };
625
- var MistralTextEmbeddingResponseSchema = import_zod3.z.object({
626
- data: import_zod3.z.array(import_zod3.z.object({ embedding: import_zod3.z.array(import_zod3.z.number()) })),
627
- 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()
628
659
  });
629
660
 
630
661
  // src/mistral-provider.ts
@@ -639,7 +670,7 @@ function createMistral(options = {}) {
639
670
  })}`,
640
671
  ...options.headers
641
672
  });
642
- const createChatModel = (modelId, settings = {}) => new MistralChatLanguageModel(modelId, settings, {
673
+ const createChatModel = (modelId) => new MistralChatLanguageModel(modelId, {
643
674
  provider: "mistral.chat",
644
675
  baseURL,
645
676
  headers: getHeaders,
@@ -651,13 +682,13 @@ function createMistral(options = {}) {
651
682
  headers: getHeaders,
652
683
  fetch: options.fetch
653
684
  });
654
- const provider = function(modelId, settings) {
685
+ const provider = function(modelId) {
655
686
  if (new.target) {
656
687
  throw new Error(
657
688
  "The Mistral model function cannot be called with the new keyword."
658
689
  );
659
690
  }
660
- return createChatModel(modelId, settings);
691
+ return createChatModel(modelId);
661
692
  };
662
693
  provider.languageModel = createChatModel;
663
694
  provider.chat = createChatModel;