@ai-sdk/cohere 4.0.0-beta.3 → 4.0.0-beta.30

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
@@ -1,42 +1,32 @@
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
- cohere: () => cohere,
25
- createCohere: () => createCohere
26
- });
27
- module.exports = __toCommonJS(index_exports);
28
-
29
1
  // src/cohere-provider.ts
30
- var import_provider4 = require("@ai-sdk/provider");
31
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
2
+ import {
3
+ NoSuchModelError
4
+ } from "@ai-sdk/provider";
5
+ import {
6
+ generateId,
7
+ loadApiKey,
8
+ withoutTrailingSlash,
9
+ withUserAgentSuffix
10
+ } from "@ai-sdk/provider-utils";
32
11
 
33
12
  // src/cohere-chat-language-model.ts
34
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
35
- var import_v43 = require("zod/v4");
13
+ import {
14
+ combineHeaders,
15
+ createEventSourceResponseHandler,
16
+ createJsonResponseHandler,
17
+ isCustomReasoning,
18
+ mapReasoningToProviderBudget,
19
+ parseProviderOptions,
20
+ postJsonToApi,
21
+ serializeModelOptions,
22
+ WORKFLOW_SERIALIZE,
23
+ WORKFLOW_DESERIALIZE
24
+ } from "@ai-sdk/provider-utils";
25
+ import { z as z3 } from "zod/v4";
36
26
 
37
27
  // src/cohere-chat-options.ts
38
- var import_v4 = require("zod/v4");
39
- var cohereLanguageModelOptions = import_v4.z.object({
28
+ import { z } from "zod/v4";
29
+ var cohereLanguageModelOptions = z.object({
40
30
  /**
41
31
  * Configuration for reasoning features (optional)
42
32
  *
@@ -45,25 +35,27 @@ var cohereLanguageModelOptions = import_v4.z.object({
45
35
  *
46
36
  * @see https://docs.cohere.com/reference/chat#request.body.thinking
47
37
  */
48
- thinking: import_v4.z.object({
49
- type: import_v4.z.enum(["enabled", "disabled"]).optional(),
50
- tokenBudget: import_v4.z.number().optional()
38
+ thinking: z.object({
39
+ type: z.enum(["enabled", "disabled"]).optional(),
40
+ tokenBudget: z.number().optional()
51
41
  }).optional()
52
42
  });
53
43
 
54
44
  // src/cohere-error.ts
55
- var import_provider_utils = require("@ai-sdk/provider-utils");
56
- var import_v42 = require("zod/v4");
57
- var cohereErrorDataSchema = import_v42.z.object({
58
- message: import_v42.z.string()
45
+ import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
46
+ import { z as z2 } from "zod/v4";
47
+ var cohereErrorDataSchema = z2.object({
48
+ message: z2.string()
59
49
  });
60
- var cohereFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
50
+ var cohereFailedResponseHandler = createJsonErrorResponseHandler({
61
51
  errorSchema: cohereErrorDataSchema,
62
52
  errorToMessage: (data) => data.message
63
53
  });
64
54
 
65
55
  // src/cohere-prepare-tools.ts
66
- var import_provider = require("@ai-sdk/provider");
56
+ import {
57
+ UnsupportedFunctionalityError
58
+ } from "@ai-sdk/provider";
67
59
  function prepareTools({
68
60
  tools,
69
61
  toolChoice
@@ -112,7 +104,7 @@ function prepareTools({
112
104
  };
113
105
  default: {
114
106
  const _exhaustiveCheck = type;
115
- throw new import_provider.UnsupportedFunctionalityError({
107
+ throw new UnsupportedFunctionalityError({
116
108
  functionality: `tool choice type: ${_exhaustiveCheck}`
117
109
  });
118
110
  }
@@ -156,7 +148,10 @@ function convertCohereUsage(tokens) {
156
148
  }
157
149
 
158
150
  // src/convert-to-cohere-chat-prompt.ts
159
- var import_provider2 = require("@ai-sdk/provider");
151
+ import {
152
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError2
153
+ } from "@ai-sdk/provider";
154
+ import { isProviderReference } from "@ai-sdk/provider-utils";
160
155
  function convertToCohereChatPrompt(prompt) {
161
156
  const messages = [];
162
157
  const documents = [];
@@ -177,19 +172,24 @@ function convertToCohereChatPrompt(prompt) {
177
172
  return part.text;
178
173
  }
179
174
  case "file": {
175
+ if (isProviderReference(part.data)) {
176
+ throw new UnsupportedFunctionalityError2({
177
+ functionality: "file parts with provider references"
178
+ });
179
+ }
180
180
  let textContent;
181
181
  if (typeof part.data === "string") {
182
182
  textContent = part.data;
183
183
  } else if (part.data instanceof Uint8Array) {
184
184
  if (!(((_a = part.mediaType) == null ? void 0 : _a.startsWith("text/")) || part.mediaType === "application/json")) {
185
- throw new import_provider2.UnsupportedFunctionalityError({
185
+ throw new UnsupportedFunctionalityError2({
186
186
  functionality: `document media type: ${part.mediaType}`,
187
187
  message: `Media type '${part.mediaType}' is not supported. Supported media types are: text/* and application/json.`
188
188
  });
189
189
  }
190
190
  textContent = new TextDecoder().decode(part.data);
191
191
  } else {
192
- throw new import_provider2.UnsupportedFunctionalityError({
192
+ throw new UnsupportedFunctionalityError2({
193
193
  functionality: "File URL data",
194
194
  message: "URLs should be downloaded by the AI SDK and not reach this point. This indicates a configuration issue."
195
195
  });
@@ -249,7 +249,7 @@ function convertToCohereChatPrompt(prompt) {
249
249
  contentValue = output.value;
250
250
  break;
251
251
  case "execution-denied":
252
- contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
252
+ contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
253
253
  break;
254
254
  case "content":
255
255
  case "json":
@@ -293,15 +293,24 @@ function mapCohereFinishReason(finishReason) {
293
293
  }
294
294
 
295
295
  // src/cohere-chat-language-model.ts
296
- var CohereChatLanguageModel = class {
296
+ var CohereChatLanguageModel = class _CohereChatLanguageModel {
297
297
  constructor(modelId, config) {
298
- this.specificationVersion = "v3";
298
+ this.specificationVersion = "v4";
299
299
  this.supportedUrls = {
300
300
  // No URLs are supported.
301
301
  };
302
302
  this.modelId = modelId;
303
303
  this.config = config;
304
304
  }
305
+ static [WORKFLOW_SERIALIZE](model) {
306
+ return serializeModelOptions({
307
+ modelId: model.modelId,
308
+ config: model.config
309
+ });
310
+ }
311
+ static [WORKFLOW_DESERIALIZE](options) {
312
+ return new _CohereChatLanguageModel(options.modelId, options.config);
313
+ }
305
314
  get provider() {
306
315
  return this.config.provider;
307
316
  }
@@ -316,12 +325,14 @@ var CohereChatLanguageModel = class {
316
325
  stopSequences,
317
326
  responseFormat,
318
327
  seed,
328
+ reasoning,
319
329
  tools,
320
330
  toolChoice,
321
331
  providerOptions
322
332
  }) {
323
- var _a, _b;
324
- const cohereOptions = (_a = await (0, import_provider_utils2.parseProviderOptions)({
333
+ var _a;
334
+ const warnings = [];
335
+ const cohereOptions = (_a = await parseProviderOptions({
325
336
  provider: "cohere",
326
337
  providerOptions,
327
338
  schema: cohereLanguageModelOptions
@@ -336,6 +347,7 @@ var CohereChatLanguageModel = class {
336
347
  toolChoice: cohereToolChoice,
337
348
  toolWarnings
338
349
  } = prepareTools({ tools, toolChoice });
350
+ warnings.push(...toolWarnings, ...promptWarnings);
339
351
  return {
340
352
  args: {
341
353
  // model id:
@@ -358,37 +370,36 @@ var CohereChatLanguageModel = class {
358
370
  tool_choice: cohereToolChoice,
359
371
  // documents for RAG:
360
372
  ...cohereDocuments.length > 0 && { documents: cohereDocuments },
361
- // reasoning
362
- ...cohereOptions.thinking && {
363
- thinking: {
364
- type: (_b = cohereOptions.thinking.type) != null ? _b : "enabled",
365
- token_budget: cohereOptions.thinking.tokenBudget
366
- }
367
- }
373
+ // reasoning:
374
+ ...resolveCohereThinking({
375
+ reasoning,
376
+ cohereOptions,
377
+ warnings
378
+ })
368
379
  },
369
- warnings: [...toolWarnings, ...promptWarnings]
380
+ warnings
370
381
  };
371
382
  }
372
383
  async doGenerate(options) {
373
- var _a, _b, _c, _d, _e, _f, _g;
384
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
374
385
  const { args, warnings } = await this.getArgs(options);
375
386
  const {
376
387
  responseHeaders,
377
388
  value: response,
378
389
  rawValue: rawResponse
379
- } = await (0, import_provider_utils2.postJsonToApi)({
390
+ } = await postJsonToApi({
380
391
  url: `${this.config.baseURL}/chat`,
381
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
392
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
382
393
  body: args,
383
394
  failedResponseHandler: cohereFailedResponseHandler,
384
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
395
+ successfulResponseHandler: createJsonResponseHandler(
385
396
  cohereChatResponseSchema
386
397
  ),
387
398
  abortSignal: options.abortSignal,
388
399
  fetch: this.config.fetch
389
400
  });
390
401
  const content = [];
391
- for (const item of (_a = response.message.content) != null ? _a : []) {
402
+ for (const item of (_c = response.message.content) != null ? _c : []) {
392
403
  if (item.type === "text" && item.text.length > 0) {
393
404
  content.push({ type: "text", text: item.text });
394
405
  continue;
@@ -398,13 +409,13 @@ var CohereChatLanguageModel = class {
398
409
  continue;
399
410
  }
400
411
  }
401
- for (const citation of (_b = response.message.citations) != null ? _b : []) {
412
+ for (const citation of (_d = response.message.citations) != null ? _d : []) {
402
413
  content.push({
403
414
  type: "source",
404
415
  sourceType: "document",
405
416
  id: this.config.generateId(),
406
417
  mediaType: "text/plain",
407
- title: ((_d = (_c = citation.sources[0]) == null ? void 0 : _c.document) == null ? void 0 : _d.title) || "Document",
418
+ title: ((_f = (_e = citation.sources[0]) == null ? void 0 : _e.document) == null ? void 0 : _f.title) || "Document",
408
419
  providerMetadata: {
409
420
  cohere: {
410
421
  start: citation.start,
@@ -416,7 +427,7 @@ var CohereChatLanguageModel = class {
416
427
  }
417
428
  });
418
429
  }
419
- for (const toolCall of (_e = response.message.tool_calls) != null ? _e : []) {
430
+ for (const toolCall of (_g = response.message.tool_calls) != null ? _g : []) {
420
431
  content.push({
421
432
  type: "tool-call",
422
433
  toolCallId: toolCall.id,
@@ -430,13 +441,13 @@ var CohereChatLanguageModel = class {
430
441
  content,
431
442
  finishReason: {
432
443
  unified: mapCohereFinishReason(response.finish_reason),
433
- raw: (_f = response.finish_reason) != null ? _f : void 0
444
+ raw: (_h = response.finish_reason) != null ? _h : void 0
434
445
  },
435
446
  usage: convertCohereUsage(response.usage.tokens),
436
447
  request: { body: args },
437
448
  response: {
438
449
  // TODO timestamp, model id
439
- id: (_g = response.generation_id) != null ? _g : void 0,
450
+ id: (_i = response.generation_id) != null ? _i : void 0,
440
451
  headers: responseHeaders,
441
452
  body: rawResponse
442
453
  },
@@ -444,13 +455,14 @@ var CohereChatLanguageModel = class {
444
455
  };
445
456
  }
446
457
  async doStream(options) {
458
+ var _a, _b;
447
459
  const { args, warnings } = await this.getArgs(options);
448
- const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
460
+ const { responseHeaders, value: response } = await postJsonToApi({
449
461
  url: `${this.config.baseURL}/chat`,
450
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
462
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
451
463
  body: { ...args, stream: true },
452
464
  failedResponseHandler: cohereFailedResponseHandler,
453
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(
465
+ successfulResponseHandler: createEventSourceResponseHandler(
454
466
  cohereChatChunkSchema
455
467
  ),
456
468
  abortSignal: options.abortSignal,
@@ -470,7 +482,7 @@ var CohereChatLanguageModel = class {
470
482
  controller.enqueue({ type: "stream-start", warnings });
471
483
  },
472
484
  transform(chunk, controller) {
473
- var _a, _b;
485
+ var _a2, _b2;
474
486
  if (options.includeRawChunks) {
475
487
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
476
488
  }
@@ -575,7 +587,7 @@ var CohereChatLanguageModel = class {
575
587
  toolCallId: pendingToolCall.id,
576
588
  toolName: pendingToolCall.name,
577
589
  input: JSON.stringify(
578
- JSON.parse(((_a = pendingToolCall.arguments) == null ? void 0 : _a.trim()) || "{}")
590
+ JSON.parse(((_a2 = pendingToolCall.arguments) == null ? void 0 : _a2.trim()) || "{}")
579
591
  )
580
592
  });
581
593
  pendingToolCall.hasFinished = true;
@@ -586,7 +598,7 @@ var CohereChatLanguageModel = class {
586
598
  case "message-start": {
587
599
  controller.enqueue({
588
600
  type: "response-metadata",
589
- id: (_b = value.id) != null ? _b : void 0
601
+ id: (_b2 = value.id) != null ? _b2 : void 0
590
602
  });
591
603
  return;
592
604
  }
@@ -617,145 +629,176 @@ var CohereChatLanguageModel = class {
617
629
  };
618
630
  }
619
631
  };
620
- var cohereChatResponseSchema = import_v43.z.object({
621
- generation_id: import_v43.z.string().nullish(),
622
- message: import_v43.z.object({
623
- role: import_v43.z.string(),
624
- content: import_v43.z.array(
625
- import_v43.z.union([
626
- import_v43.z.object({
627
- type: import_v43.z.literal("text"),
628
- text: import_v43.z.string()
632
+ function resolveCohereThinking({
633
+ reasoning,
634
+ cohereOptions,
635
+ warnings
636
+ }) {
637
+ var _a;
638
+ if (cohereOptions.thinking) {
639
+ return {
640
+ thinking: {
641
+ type: (_a = cohereOptions.thinking.type) != null ? _a : "enabled",
642
+ token_budget: cohereOptions.thinking.tokenBudget
643
+ }
644
+ };
645
+ }
646
+ if (!isCustomReasoning(reasoning)) {
647
+ return {};
648
+ }
649
+ if (reasoning === "none") {
650
+ return { thinking: { type: "disabled" } };
651
+ }
652
+ const tokenBudget = mapReasoningToProviderBudget({
653
+ reasoning,
654
+ maxOutputTokens: 32768,
655
+ maxReasoningBudget: 32768,
656
+ warnings
657
+ });
658
+ if (tokenBudget == null) {
659
+ return {};
660
+ }
661
+ return { thinking: { type: "enabled", token_budget: tokenBudget } };
662
+ }
663
+ var cohereChatResponseSchema = z3.object({
664
+ generation_id: z3.string().nullish(),
665
+ message: z3.object({
666
+ role: z3.string(),
667
+ content: z3.array(
668
+ z3.union([
669
+ z3.object({
670
+ type: z3.literal("text"),
671
+ text: z3.string()
629
672
  }),
630
- import_v43.z.object({
631
- type: import_v43.z.literal("thinking"),
632
- thinking: import_v43.z.string()
673
+ z3.object({
674
+ type: z3.literal("thinking"),
675
+ thinking: z3.string()
633
676
  })
634
677
  ])
635
678
  ).nullish(),
636
- tool_plan: import_v43.z.string().nullish(),
637
- tool_calls: import_v43.z.array(
638
- import_v43.z.object({
639
- id: import_v43.z.string(),
640
- type: import_v43.z.literal("function"),
641
- function: import_v43.z.object({
642
- name: import_v43.z.string(),
643
- arguments: import_v43.z.string()
679
+ tool_plan: z3.string().nullish(),
680
+ tool_calls: z3.array(
681
+ z3.object({
682
+ id: z3.string(),
683
+ type: z3.literal("function"),
684
+ function: z3.object({
685
+ name: z3.string(),
686
+ arguments: z3.string()
644
687
  })
645
688
  })
646
689
  ).nullish(),
647
- citations: import_v43.z.array(
648
- import_v43.z.object({
649
- start: import_v43.z.number(),
650
- end: import_v43.z.number(),
651
- text: import_v43.z.string(),
652
- sources: import_v43.z.array(
653
- import_v43.z.object({
654
- type: import_v43.z.string().optional(),
655
- id: import_v43.z.string().optional(),
656
- document: import_v43.z.object({
657
- id: import_v43.z.string().optional(),
658
- text: import_v43.z.string(),
659
- title: import_v43.z.string()
690
+ citations: z3.array(
691
+ z3.object({
692
+ start: z3.number(),
693
+ end: z3.number(),
694
+ text: z3.string(),
695
+ sources: z3.array(
696
+ z3.object({
697
+ type: z3.string().optional(),
698
+ id: z3.string().optional(),
699
+ document: z3.object({
700
+ id: z3.string().optional(),
701
+ text: z3.string(),
702
+ title: z3.string()
660
703
  })
661
704
  })
662
705
  ),
663
- type: import_v43.z.string().optional()
706
+ type: z3.string().optional()
664
707
  })
665
708
  ).nullish()
666
709
  }),
667
- finish_reason: import_v43.z.string(),
668
- usage: import_v43.z.object({
669
- billed_units: import_v43.z.object({
670
- input_tokens: import_v43.z.number(),
671
- output_tokens: import_v43.z.number()
710
+ finish_reason: z3.string(),
711
+ usage: z3.object({
712
+ billed_units: z3.object({
713
+ input_tokens: z3.number(),
714
+ output_tokens: z3.number()
672
715
  }),
673
- tokens: import_v43.z.object({
674
- input_tokens: import_v43.z.number(),
675
- output_tokens: import_v43.z.number()
716
+ tokens: z3.object({
717
+ input_tokens: z3.number(),
718
+ output_tokens: z3.number()
676
719
  })
677
720
  })
678
721
  });
679
- var cohereChatChunkSchema = import_v43.z.discriminatedUnion("type", [
680
- import_v43.z.object({
681
- type: import_v43.z.literal("citation-start")
722
+ var cohereChatChunkSchema = z3.discriminatedUnion("type", [
723
+ z3.object({
724
+ type: z3.literal("citation-start")
682
725
  }),
683
- import_v43.z.object({
684
- type: import_v43.z.literal("citation-end")
726
+ z3.object({
727
+ type: z3.literal("citation-end")
685
728
  }),
686
- import_v43.z.object({
687
- type: import_v43.z.literal("content-start"),
688
- index: import_v43.z.number(),
689
- delta: import_v43.z.object({
690
- message: import_v43.z.object({
691
- content: import_v43.z.union([
692
- import_v43.z.object({
693
- type: import_v43.z.literal("text"),
694
- text: import_v43.z.string()
729
+ z3.object({
730
+ type: z3.literal("content-start"),
731
+ index: z3.number(),
732
+ delta: z3.object({
733
+ message: z3.object({
734
+ content: z3.union([
735
+ z3.object({
736
+ type: z3.literal("text"),
737
+ text: z3.string()
695
738
  }),
696
- import_v43.z.object({
697
- type: import_v43.z.literal("thinking"),
698
- thinking: import_v43.z.string()
739
+ z3.object({
740
+ type: z3.literal("thinking"),
741
+ thinking: z3.string()
699
742
  })
700
743
  ])
701
744
  })
702
745
  })
703
746
  }),
704
- import_v43.z.object({
705
- type: import_v43.z.literal("content-delta"),
706
- index: import_v43.z.number(),
707
- delta: import_v43.z.object({
708
- message: import_v43.z.object({
709
- content: import_v43.z.union([
710
- import_v43.z.object({
711
- text: import_v43.z.string()
747
+ z3.object({
748
+ type: z3.literal("content-delta"),
749
+ index: z3.number(),
750
+ delta: z3.object({
751
+ message: z3.object({
752
+ content: z3.union([
753
+ z3.object({
754
+ text: z3.string()
712
755
  }),
713
- import_v43.z.object({
714
- thinking: import_v43.z.string()
756
+ z3.object({
757
+ thinking: z3.string()
715
758
  })
716
759
  ])
717
760
  })
718
761
  })
719
762
  }),
720
- import_v43.z.object({
721
- type: import_v43.z.literal("content-end"),
722
- index: import_v43.z.number()
763
+ z3.object({
764
+ type: z3.literal("content-end"),
765
+ index: z3.number()
723
766
  }),
724
- import_v43.z.object({
725
- type: import_v43.z.literal("message-start"),
726
- id: import_v43.z.string().nullish()
767
+ z3.object({
768
+ type: z3.literal("message-start"),
769
+ id: z3.string().nullish()
727
770
  }),
728
- import_v43.z.object({
729
- type: import_v43.z.literal("message-end"),
730
- delta: import_v43.z.object({
731
- finish_reason: import_v43.z.string(),
732
- usage: import_v43.z.object({
733
- tokens: import_v43.z.object({
734
- input_tokens: import_v43.z.number(),
735
- output_tokens: import_v43.z.number()
771
+ z3.object({
772
+ type: z3.literal("message-end"),
773
+ delta: z3.object({
774
+ finish_reason: z3.string(),
775
+ usage: z3.object({
776
+ tokens: z3.object({
777
+ input_tokens: z3.number(),
778
+ output_tokens: z3.number()
736
779
  })
737
780
  })
738
781
  })
739
782
  }),
740
783
  // https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
741
- import_v43.z.object({
742
- type: import_v43.z.literal("tool-plan-delta"),
743
- delta: import_v43.z.object({
744
- message: import_v43.z.object({
745
- tool_plan: import_v43.z.string()
784
+ z3.object({
785
+ type: z3.literal("tool-plan-delta"),
786
+ delta: z3.object({
787
+ message: z3.object({
788
+ tool_plan: z3.string()
746
789
  })
747
790
  })
748
791
  }),
749
- import_v43.z.object({
750
- type: import_v43.z.literal("tool-call-start"),
751
- delta: import_v43.z.object({
752
- message: import_v43.z.object({
753
- tool_calls: import_v43.z.object({
754
- id: import_v43.z.string(),
755
- type: import_v43.z.literal("function"),
756
- function: import_v43.z.object({
757
- name: import_v43.z.string(),
758
- arguments: import_v43.z.string()
792
+ z3.object({
793
+ type: z3.literal("tool-call-start"),
794
+ delta: z3.object({
795
+ message: z3.object({
796
+ tool_calls: z3.object({
797
+ id: z3.string(),
798
+ type: z3.literal("function"),
799
+ function: z3.object({
800
+ name: z3.string(),
801
+ arguments: z3.string()
759
802
  })
760
803
  })
761
804
  })
@@ -764,31 +807,41 @@ var cohereChatChunkSchema = import_v43.z.discriminatedUnion("type", [
764
807
  // A single tool call's `arguments` stream in chunks and must be accumulated
765
808
  // in a string and so the full tool object info can only be parsed once we see
766
809
  // `tool-call-end`.
767
- import_v43.z.object({
768
- type: import_v43.z.literal("tool-call-delta"),
769
- delta: import_v43.z.object({
770
- message: import_v43.z.object({
771
- tool_calls: import_v43.z.object({
772
- function: import_v43.z.object({
773
- arguments: import_v43.z.string()
810
+ z3.object({
811
+ type: z3.literal("tool-call-delta"),
812
+ delta: z3.object({
813
+ message: z3.object({
814
+ tool_calls: z3.object({
815
+ function: z3.object({
816
+ arguments: z3.string()
774
817
  })
775
818
  })
776
819
  })
777
820
  })
778
821
  }),
779
- import_v43.z.object({
780
- type: import_v43.z.literal("tool-call-end")
822
+ z3.object({
823
+ type: z3.literal("tool-call-end")
781
824
  })
782
825
  ]);
783
826
 
784
827
  // src/cohere-embedding-model.ts
785
- var import_provider3 = require("@ai-sdk/provider");
786
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
787
- var import_v45 = require("zod/v4");
828
+ import {
829
+ TooManyEmbeddingValuesForCallError
830
+ } from "@ai-sdk/provider";
831
+ import {
832
+ combineHeaders as combineHeaders2,
833
+ createJsonResponseHandler as createJsonResponseHandler2,
834
+ parseProviderOptions as parseProviderOptions2,
835
+ postJsonToApi as postJsonToApi2,
836
+ serializeModelOptions as serializeModelOptions2,
837
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
838
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
839
+ } from "@ai-sdk/provider-utils";
840
+ import { z as z5 } from "zod/v4";
788
841
 
789
842
  // src/cohere-embedding-options.ts
790
- var import_v44 = require("zod/v4");
791
- var cohereEmbeddingModelOptions = import_v44.z.object({
843
+ import { z as z4 } from "zod/v4";
844
+ var cohereEmbeddingModelOptions = z4.object({
792
845
  /**
793
846
  * Specifies the type of input passed to the model. Default is `search_query`.
794
847
  *
@@ -797,7 +850,7 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
797
850
  * - "classification": Used for embeddings passed through a text classifier.
798
851
  * - "clustering": Used for embeddings run through a clustering algorithm.
799
852
  */
800
- inputType: import_v44.z.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
853
+ inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
801
854
  /**
802
855
  * Specifies how the API will handle inputs longer than the maximum token length.
803
856
  * Default is `END`.
@@ -806,7 +859,7 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
806
859
  * - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
807
860
  * - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
808
861
  */
809
- truncate: import_v44.z.enum(["NONE", "START", "END"]).optional(),
862
+ truncate: z4.enum(["NONE", "START", "END"]).optional(),
810
863
  /**
811
864
  * The number of dimensions of the output embedding.
812
865
  * Only available for `embed-v4.0` and newer models.
@@ -814,18 +867,27 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
814
867
  * Possible values are `256`, `512`, `1024`, and `1536`.
815
868
  * The default is `1536`.
816
869
  */
817
- outputDimension: import_v44.z.union([import_v44.z.literal(256), import_v44.z.literal(512), import_v44.z.literal(1024), import_v44.z.literal(1536)]).optional()
870
+ outputDimension: z4.union([z4.literal(256), z4.literal(512), z4.literal(1024), z4.literal(1536)]).optional()
818
871
  });
819
872
 
820
873
  // src/cohere-embedding-model.ts
821
- var CohereEmbeddingModel = class {
874
+ var CohereEmbeddingModel = class _CohereEmbeddingModel {
822
875
  constructor(modelId, config) {
823
- this.specificationVersion = "v3";
876
+ this.specificationVersion = "v4";
824
877
  this.maxEmbeddingsPerCall = 96;
825
878
  this.supportsParallelCalls = true;
826
879
  this.modelId = modelId;
827
880
  this.config = config;
828
881
  }
882
+ static [WORKFLOW_SERIALIZE2](model) {
883
+ return serializeModelOptions2({
884
+ modelId: model.modelId,
885
+ config: model.config
886
+ });
887
+ }
888
+ static [WORKFLOW_DESERIALIZE2](options) {
889
+ return new _CohereEmbeddingModel(options.modelId, options.config);
890
+ }
829
891
  get provider() {
830
892
  return this.config.provider;
831
893
  }
@@ -835,14 +897,14 @@ var CohereEmbeddingModel = class {
835
897
  abortSignal,
836
898
  providerOptions
837
899
  }) {
838
- var _a;
839
- const embeddingOptions = await (0, import_provider_utils3.parseProviderOptions)({
900
+ var _a, _b, _c;
901
+ const embeddingOptions = await parseProviderOptions2({
840
902
  provider: "cohere",
841
903
  providerOptions,
842
904
  schema: cohereEmbeddingModelOptions
843
905
  });
844
906
  if (values.length > this.maxEmbeddingsPerCall) {
845
- throw new import_provider3.TooManyEmbeddingValuesForCallError({
907
+ throw new TooManyEmbeddingValuesForCallError({
846
908
  provider: this.provider,
847
909
  modelId: this.modelId,
848
910
  maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
@@ -853,9 +915,9 @@ var CohereEmbeddingModel = class {
853
915
  responseHeaders,
854
916
  value: response,
855
917
  rawValue
856
- } = await (0, import_provider_utils3.postJsonToApi)({
918
+ } = await postJsonToApi2({
857
919
  url: `${this.config.baseURL}/embed`,
858
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), headers),
920
+ headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), headers),
859
921
  body: {
860
922
  model: this.modelId,
861
923
  // The AI SDK only supports 'float' embeddings. Note that the Cohere API
@@ -863,12 +925,12 @@ var CohereEmbeddingModel = class {
863
925
  // https://docs.cohere.com/v2/reference/embed#request.body.embedding_types
864
926
  embedding_types: ["float"],
865
927
  texts: values,
866
- input_type: (_a = embeddingOptions == null ? void 0 : embeddingOptions.inputType) != null ? _a : "search_query",
928
+ input_type: (_c = embeddingOptions == null ? void 0 : embeddingOptions.inputType) != null ? _c : "search_query",
867
929
  truncate: embeddingOptions == null ? void 0 : embeddingOptions.truncate,
868
930
  output_dimension: embeddingOptions == null ? void 0 : embeddingOptions.outputDimension
869
931
  },
870
932
  failedResponseHandler: cohereFailedResponseHandler,
871
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
933
+ successfulResponseHandler: createJsonResponseHandler2(
872
934
  cohereTextEmbeddingResponseSchema
873
935
  ),
874
936
  abortSignal,
@@ -882,46 +944,51 @@ var CohereEmbeddingModel = class {
882
944
  };
883
945
  }
884
946
  };
885
- var cohereTextEmbeddingResponseSchema = import_v45.z.object({
886
- embeddings: import_v45.z.object({
887
- float: import_v45.z.array(import_v45.z.array(import_v45.z.number()))
947
+ var cohereTextEmbeddingResponseSchema = z5.object({
948
+ embeddings: z5.object({
949
+ float: z5.array(z5.array(z5.number()))
888
950
  }),
889
- meta: import_v45.z.object({
890
- billed_units: import_v45.z.object({
891
- input_tokens: import_v45.z.number()
951
+ meta: z5.object({
952
+ billed_units: z5.object({
953
+ input_tokens: z5.number()
892
954
  })
893
955
  })
894
956
  });
895
957
 
896
958
  // src/reranking/cohere-reranking-model.ts
897
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
959
+ import {
960
+ combineHeaders as combineHeaders3,
961
+ createJsonResponseHandler as createJsonResponseHandler3,
962
+ parseProviderOptions as parseProviderOptions3,
963
+ postJsonToApi as postJsonToApi3
964
+ } from "@ai-sdk/provider-utils";
898
965
 
899
966
  // src/reranking/cohere-reranking-api.ts
900
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
901
- var import_v46 = require("zod/v4");
902
- var cohereRerankingResponseSchema = (0, import_provider_utils4.lazySchema)(
903
- () => (0, import_provider_utils4.zodSchema)(
904
- import_v46.z.object({
905
- id: import_v46.z.string().nullish(),
906
- results: import_v46.z.array(
907
- import_v46.z.object({
908
- index: import_v46.z.number(),
909
- relevance_score: import_v46.z.number()
967
+ import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
968
+ import { z as z6 } from "zod/v4";
969
+ var cohereRerankingResponseSchema = lazySchema(
970
+ () => zodSchema(
971
+ z6.object({
972
+ id: z6.string().nullish(),
973
+ results: z6.array(
974
+ z6.object({
975
+ index: z6.number(),
976
+ relevance_score: z6.number()
910
977
  })
911
978
  ),
912
- meta: import_v46.z.any()
979
+ meta: z6.any()
913
980
  })
914
981
  )
915
982
  );
916
983
 
917
984
  // src/reranking/cohere-reranking-options.ts
918
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
919
- var import_v47 = require("zod/v4");
920
- var cohereRerankingModelOptionsSchema = (0, import_provider_utils5.lazySchema)(
921
- () => (0, import_provider_utils5.zodSchema)(
922
- import_v47.z.object({
923
- maxTokensPerDoc: import_v47.z.number().optional(),
924
- priority: import_v47.z.number().optional()
985
+ import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
986
+ import { z as z7 } from "zod/v4";
987
+ var cohereRerankingModelOptionsSchema = lazySchema2(
988
+ () => zodSchema2(
989
+ z7.object({
990
+ maxTokensPerDoc: z7.number().optional(),
991
+ priority: z7.number().optional()
925
992
  })
926
993
  )
927
994
  );
@@ -929,7 +996,7 @@ var cohereRerankingModelOptionsSchema = (0, import_provider_utils5.lazySchema)(
929
996
  // src/reranking/cohere-reranking-model.ts
930
997
  var CohereRerankingModel = class {
931
998
  constructor(modelId, config) {
932
- this.specificationVersion = "v3";
999
+ this.specificationVersion = "v4";
933
1000
  this.modelId = modelId;
934
1001
  this.config = config;
935
1002
  }
@@ -946,7 +1013,7 @@ var CohereRerankingModel = class {
946
1013
  providerOptions
947
1014
  }) {
948
1015
  var _a;
949
- const rerankingOptions = await (0, import_provider_utils6.parseProviderOptions)({
1016
+ const rerankingOptions = await parseProviderOptions3({
950
1017
  provider: "cohere",
951
1018
  providerOptions,
952
1019
  schema: cohereRerankingModelOptionsSchema
@@ -963,9 +1030,9 @@ var CohereRerankingModel = class {
963
1030
  responseHeaders,
964
1031
  value: response,
965
1032
  rawValue
966
- } = await (0, import_provider_utils6.postJsonToApi)({
1033
+ } = await postJsonToApi3({
967
1034
  url: `${this.config.baseURL}/rerank`,
968
- headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), headers),
1035
+ headers: combineHeaders3(this.config.headers(), headers),
969
1036
  body: {
970
1037
  model: this.modelId,
971
1038
  query,
@@ -975,7 +1042,7 @@ var CohereRerankingModel = class {
975
1042
  priority: rerankingOptions == null ? void 0 : rerankingOptions.priority
976
1043
  },
977
1044
  failedResponseHandler: cohereFailedResponseHandler,
978
- successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
1045
+ successfulResponseHandler: createJsonResponseHandler3(
979
1046
  cohereRerankingResponseSchema
980
1047
  ),
981
1048
  abortSignal,
@@ -997,15 +1064,15 @@ var CohereRerankingModel = class {
997
1064
  };
998
1065
 
999
1066
  // src/version.ts
1000
- var VERSION = true ? "4.0.0-beta.3" : "0.0.0-test";
1067
+ var VERSION = true ? "4.0.0-beta.30" : "0.0.0-test";
1001
1068
 
1002
1069
  // src/cohere-provider.ts
1003
1070
  function createCohere(options = {}) {
1004
1071
  var _a;
1005
- const baseURL = (_a = (0, import_provider_utils7.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.cohere.com/v2";
1006
- const getHeaders = () => (0, import_provider_utils7.withUserAgentSuffix)(
1072
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.cohere.com/v2";
1073
+ const getHeaders = () => withUserAgentSuffix(
1007
1074
  {
1008
- Authorization: `Bearer ${(0, import_provider_utils7.loadApiKey)({
1075
+ Authorization: `Bearer ${loadApiKey({
1009
1076
  apiKey: options.apiKey,
1010
1077
  environmentVariableName: "COHERE_API_KEY",
1011
1078
  description: "Cohere"
@@ -1021,7 +1088,7 @@ function createCohere(options = {}) {
1021
1088
  baseURL,
1022
1089
  headers: getHeaders,
1023
1090
  fetch: options.fetch,
1024
- generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils7.generateId
1091
+ generateId: (_a2 = options.generateId) != null ? _a2 : generateId
1025
1092
  });
1026
1093
  };
1027
1094
  const createEmbeddingModel = (modelId) => new CohereEmbeddingModel(modelId, {
@@ -1044,7 +1111,7 @@ function createCohere(options = {}) {
1044
1111
  }
1045
1112
  return createChatModel(modelId);
1046
1113
  };
1047
- provider.specificationVersion = "v3";
1114
+ provider.specificationVersion = "v4";
1048
1115
  provider.languageModel = createChatModel;
1049
1116
  provider.embedding = createEmbeddingModel;
1050
1117
  provider.embeddingModel = createEmbeddingModel;
@@ -1053,15 +1120,14 @@ function createCohere(options = {}) {
1053
1120
  provider.reranking = createRerankingModel;
1054
1121
  provider.rerankingModel = createRerankingModel;
1055
1122
  provider.imageModel = (modelId) => {
1056
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
1123
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1057
1124
  };
1058
1125
  return provider;
1059
1126
  }
1060
1127
  var cohere = createCohere();
1061
- // Annotate the CommonJS export names for ESM import in node:
1062
- 0 && (module.exports = {
1128
+ export {
1063
1129
  VERSION,
1064
1130
  cohere,
1065
1131
  createCohere
1066
- });
1132
+ };
1067
1133
  //# sourceMappingURL=index.js.map