@ai-sdk/cohere 3.0.72 → 3.0.74

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.mjs CHANGED
@@ -11,6 +11,8 @@ import {
11
11
 
12
12
  // src/cohere-chat-language-model.ts
13
13
  import {
14
+ lazySchema as lazySchema3,
15
+ zodSchema as zodSchema3,
14
16
  combineHeaders,
15
17
  createEventSourceResponseHandler,
16
18
  createJsonResponseHandler,
@@ -21,36 +23,56 @@ import {
21
23
  import { z as z3 } from "zod/v4";
22
24
 
23
25
  // src/cohere-chat-options.ts
26
+ import {
27
+ lazySchema,
28
+ zodSchema
29
+ } from "@ai-sdk/provider-utils";
24
30
  import { z } from "zod/v4";
25
- var cohereLanguageModelOptions = z.object({
26
- /**
27
- * Configuration for reasoning features (optional)
28
- *
29
- * Can be set to an object with the two properties `type` and `tokenBudget`. `type` can be set to `'enabled'` or `'disabled'` (defaults to `'enabled'`).
30
- * `tokenBudget` is the maximum number of tokens the model can use for thinking, which must be set to a positive integer. The model will stop thinking if it reaches the thinking token budget and will proceed with the response
31
- *
32
- * @see https://docs.cohere.com/reference/chat#request.body.thinking
33
- */
34
- thinking: z.object({
35
- type: z.enum(["enabled", "disabled"]).optional(),
36
- tokenBudget: z.number().optional()
37
- }).optional()
38
- });
39
- var cohereImagePartProviderOptions = z.object({
40
- /**
41
- * Image fidelity level passed through as `image_url.detail` on the Cohere chat API.
42
- *
43
- * @see https://docs.cohere.com/docs/image-inputs
44
- */
45
- detail: z.enum(["auto", "low", "high"]).optional()
46
- });
31
+ var cohereLanguageModelOptions = lazySchema(
32
+ () => zodSchema(
33
+ z.object({
34
+ /**
35
+ * Configuration for reasoning features (optional)
36
+ *
37
+ * Can be set to an object with the two properties `type` and `tokenBudget`. `type` can be set to `'enabled'` or `'disabled'` (defaults to `'enabled'`).
38
+ * `tokenBudget` is the maximum number of tokens the model can use for thinking, which must be set to a positive integer. The model will stop thinking if it reaches the thinking token budget and will proceed with the response
39
+ *
40
+ * @see https://docs.cohere.com/reference/chat#request.body.thinking
41
+ */
42
+ thinking: z.object({
43
+ type: z.enum(["enabled", "disabled"]).optional(),
44
+ tokenBudget: z.number().optional()
45
+ }).optional()
46
+ })
47
+ )
48
+ );
49
+ var cohereImagePartProviderOptions = lazySchema(
50
+ () => zodSchema(
51
+ z.object({
52
+ /**
53
+ * Image fidelity level passed through as `image_url.detail` on the Cohere chat API.
54
+ *
55
+ * @see https://docs.cohere.com/docs/image-inputs
56
+ */
57
+ detail: z.enum(["auto", "low", "high"]).optional()
58
+ })
59
+ )
60
+ );
47
61
 
48
62
  // src/cohere-error.ts
49
- import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
63
+ import {
64
+ lazySchema as lazySchema2,
65
+ zodSchema as zodSchema2,
66
+ createJsonErrorResponseHandler
67
+ } from "@ai-sdk/provider-utils";
50
68
  import { z as z2 } from "zod/v4";
51
- var cohereErrorDataSchema = z2.object({
52
- message: z2.string()
53
- });
69
+ var cohereErrorDataSchema = lazySchema2(
70
+ () => zodSchema2(
71
+ z2.object({
72
+ message: z2.string()
73
+ })
74
+ )
75
+ );
54
76
  var cohereFailedResponseHandler = createJsonErrorResponseHandler({
55
77
  errorSchema: cohereErrorDataSchema,
56
78
  errorToMessage: (data) => data.message
@@ -655,7 +677,7 @@ var CohereChatLanguageModel = class {
655
677
  };
656
678
  }
657
679
  };
658
- var cohereUsageSchema = z3.looseObject({
680
+ var cohereUsageSchema = () => z3.looseObject({
659
681
  billed_units: z3.looseObject({
660
682
  input_tokens: z3.number(),
661
683
  output_tokens: z3.number()
@@ -666,161 +688,171 @@ var cohereUsageSchema = z3.looseObject({
666
688
  }),
667
689
  cached_tokens: z3.number().nullish()
668
690
  });
669
- var cohereChatResponseSchema = z3.object({
670
- generation_id: z3.string().nullish(),
671
- message: z3.object({
672
- role: z3.string(),
673
- content: z3.array(
674
- z3.union([
675
- z3.object({
676
- type: z3.literal("text"),
677
- text: z3.string()
678
- }),
679
- z3.object({
680
- type: z3.literal("thinking"),
681
- thinking: z3.string()
682
- })
683
- ])
684
- ).nullish(),
685
- tool_plan: z3.string().nullish(),
686
- tool_calls: z3.array(
687
- z3.object({
688
- id: z3.string(),
689
- type: z3.literal("function"),
690
- function: z3.object({
691
- name: z3.string(),
692
- arguments: z3.string()
693
- })
694
- })
695
- ).nullish(),
696
- citations: z3.array(
697
- z3.object({
698
- start: z3.number(),
699
- end: z3.number(),
700
- text: z3.string(),
701
- sources: z3.array(
702
- z3.object({
703
- type: z3.string().optional(),
704
- id: z3.string().optional(),
705
- document: z3.object({
706
- id: z3.string().optional(),
707
- text: z3.string(),
708
- title: z3.string()
709
- })
710
- })
711
- ),
712
- type: z3.string().optional()
713
- })
714
- ).nullish()
715
- }),
716
- finish_reason: z3.string(),
717
- usage: cohereUsageSchema
718
- });
719
- var cohereChatChunkSchema = z3.discriminatedUnion("type", [
720
- z3.object({
721
- type: z3.literal("citation-start")
722
- }),
723
- z3.object({
724
- type: z3.literal("citation-end")
725
- }),
726
- z3.object({
727
- type: z3.literal("content-start"),
728
- index: z3.number(),
729
- delta: z3.object({
691
+ var cohereChatResponseSchema = lazySchema3(
692
+ () => zodSchema3(
693
+ z3.object({
694
+ generation_id: z3.string().nullish(),
730
695
  message: z3.object({
731
- content: z3.union([
732
- z3.object({
733
- type: z3.literal("text"),
734
- text: z3.string()
735
- }),
696
+ role: z3.string(),
697
+ content: z3.array(
698
+ z3.union([
699
+ z3.object({
700
+ type: z3.literal("text"),
701
+ text: z3.string()
702
+ }),
703
+ z3.object({
704
+ type: z3.literal("thinking"),
705
+ thinking: z3.string()
706
+ })
707
+ ])
708
+ ).nullish(),
709
+ tool_plan: z3.string().nullish(),
710
+ tool_calls: z3.array(
736
711
  z3.object({
737
- type: z3.literal("thinking"),
738
- thinking: z3.string()
712
+ id: z3.string(),
713
+ type: z3.literal("function"),
714
+ function: z3.object({
715
+ name: z3.string(),
716
+ arguments: z3.string()
717
+ })
739
718
  })
740
- ])
741
- })
742
- })
743
- }),
744
- z3.object({
745
- type: z3.literal("content-delta"),
746
- index: z3.number(),
747
- delta: z3.object({
748
- message: z3.object({
749
- content: z3.union([
750
- z3.object({
751
- text: z3.string()
752
- }),
719
+ ).nullish(),
720
+ citations: z3.array(
753
721
  z3.object({
754
- thinking: z3.string()
722
+ start: z3.number(),
723
+ end: z3.number(),
724
+ text: z3.string(),
725
+ sources: z3.array(
726
+ z3.object({
727
+ type: z3.string().optional(),
728
+ id: z3.string().optional(),
729
+ document: z3.object({
730
+ id: z3.string().optional(),
731
+ text: z3.string(),
732
+ title: z3.string()
733
+ })
734
+ })
735
+ ),
736
+ type: z3.string().optional()
755
737
  })
756
- ])
757
- })
758
- })
759
- }),
760
- z3.object({
761
- type: z3.literal("content-end"),
762
- index: z3.number()
763
- }),
764
- z3.object({
765
- type: z3.literal("message-start"),
766
- id: z3.string().nullish()
767
- }),
768
- z3.object({
769
- type: z3.literal("message-end"),
770
- delta: z3.object({
738
+ ).nullish()
739
+ }),
771
740
  finish_reason: z3.string(),
772
- usage: cohereUsageSchema
773
- })
774
- }),
775
- // https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
776
- z3.object({
777
- type: z3.literal("tool-plan-delta"),
778
- delta: z3.object({
779
- message: z3.object({
780
- tool_plan: z3.string()
781
- })
741
+ usage: cohereUsageSchema()
782
742
  })
783
- }),
784
- z3.object({
785
- type: z3.literal("tool-call-start"),
786
- delta: z3.object({
787
- message: z3.object({
788
- tool_calls: z3.object({
789
- id: z3.string(),
790
- type: z3.literal("function"),
791
- function: z3.object({
792
- name: z3.string(),
793
- arguments: z3.string()
743
+ )
744
+ );
745
+ var cohereChatChunkSchema = lazySchema3(
746
+ () => zodSchema3(
747
+ z3.discriminatedUnion("type", [
748
+ z3.object({
749
+ type: z3.literal("citation-start")
750
+ }),
751
+ z3.object({
752
+ type: z3.literal("citation-end")
753
+ }),
754
+ z3.object({
755
+ type: z3.literal("content-start"),
756
+ index: z3.number(),
757
+ delta: z3.object({
758
+ message: z3.object({
759
+ content: z3.union([
760
+ z3.object({
761
+ type: z3.literal("text"),
762
+ text: z3.string()
763
+ }),
764
+ z3.object({
765
+ type: z3.literal("thinking"),
766
+ thinking: z3.string()
767
+ })
768
+ ])
794
769
  })
795
770
  })
796
- })
797
- })
798
- }),
799
- // A single tool call's `arguments` stream in chunks and must be accumulated
800
- // in a string and so the full tool object info can only be parsed once we see
801
- // `tool-call-end`.
802
- z3.object({
803
- type: z3.literal("tool-call-delta"),
804
- delta: z3.object({
805
- message: z3.object({
806
- tool_calls: z3.object({
807
- function: z3.object({
808
- arguments: z3.string()
771
+ }),
772
+ z3.object({
773
+ type: z3.literal("content-delta"),
774
+ index: z3.number(),
775
+ delta: z3.object({
776
+ message: z3.object({
777
+ content: z3.union([
778
+ z3.object({
779
+ text: z3.string()
780
+ }),
781
+ z3.object({
782
+ thinking: z3.string()
783
+ })
784
+ ])
785
+ })
786
+ })
787
+ }),
788
+ z3.object({
789
+ type: z3.literal("content-end"),
790
+ index: z3.number()
791
+ }),
792
+ z3.object({
793
+ type: z3.literal("message-start"),
794
+ id: z3.string().nullish()
795
+ }),
796
+ z3.object({
797
+ type: z3.literal("message-end"),
798
+ delta: z3.object({
799
+ finish_reason: z3.string(),
800
+ usage: cohereUsageSchema()
801
+ })
802
+ }),
803
+ // https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
804
+ z3.object({
805
+ type: z3.literal("tool-plan-delta"),
806
+ delta: z3.object({
807
+ message: z3.object({
808
+ tool_plan: z3.string()
809
+ })
810
+ })
811
+ }),
812
+ z3.object({
813
+ type: z3.literal("tool-call-start"),
814
+ delta: z3.object({
815
+ message: z3.object({
816
+ tool_calls: z3.object({
817
+ id: z3.string(),
818
+ type: z3.literal("function"),
819
+ function: z3.object({
820
+ name: z3.string(),
821
+ arguments: z3.string()
822
+ })
823
+ })
809
824
  })
810
825
  })
826
+ }),
827
+ // A single tool call's `arguments` stream in chunks and must be accumulated
828
+ // in a string and so the full tool object info can only be parsed once we see
829
+ // `tool-call-end`.
830
+ z3.object({
831
+ type: z3.literal("tool-call-delta"),
832
+ delta: z3.object({
833
+ message: z3.object({
834
+ tool_calls: z3.object({
835
+ function: z3.object({
836
+ arguments: z3.string()
837
+ })
838
+ })
839
+ })
840
+ })
841
+ }),
842
+ z3.object({
843
+ type: z3.literal("tool-call-end")
811
844
  })
812
- })
813
- }),
814
- z3.object({
815
- type: z3.literal("tool-call-end")
816
- })
817
- ]);
845
+ ])
846
+ )
847
+ );
818
848
 
819
849
  // src/cohere-embedding-model.ts
820
850
  import {
821
851
  TooManyEmbeddingValuesForCallError
822
852
  } from "@ai-sdk/provider";
823
853
  import {
854
+ lazySchema as lazySchema5,
855
+ zodSchema as zodSchema5,
824
856
  combineHeaders as combineHeaders2,
825
857
  createJsonResponseHandler as createJsonResponseHandler2,
826
858
  parseProviderOptions as parseProviderOptions3,
@@ -829,42 +861,55 @@ import {
829
861
  import { z as z5 } from "zod/v4";
830
862
 
831
863
  // src/cohere-embedding-options.ts
864
+ import {
865
+ lazySchema as lazySchema4,
866
+ zodSchema as zodSchema4
867
+ } from "@ai-sdk/provider-utils";
832
868
  import { z as z4 } from "zod/v4";
833
- var cohereEmbeddingModelOptions = z4.object({
834
- /**
835
- * Specifies the type of input passed to the model. Default is `search_query`.
836
- *
837
- * - "search_document": Used for embeddings stored in a vector database for search use-cases.
838
- * - "search_query": Used for embeddings of search queries run against a vector DB to find relevant documents.
839
- * - "classification": Used for embeddings passed through a text classifier.
840
- * - "clustering": Used for embeddings run through a clustering algorithm.
841
- */
842
- inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
843
- /**
844
- * Specifies how the API will handle inputs longer than the maximum token length.
845
- * Default is `END`.
846
- *
847
- * - "NONE": If selected, when the input exceeds the maximum input token length will return an error.
848
- * - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
849
- * - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
850
- */
851
- truncate: z4.enum(["NONE", "START", "END"]).optional(),
852
- /**
853
- * The number of dimensions of the output embedding.
854
- * Only available for `embed-v4.0` and newer models.
855
- *
856
- * Embed v4.0 supports `256`, `512`, `1024`, and `1536` (default).
857
- * Embed v5.0 Pro and Fast also support `768` and `2048` (default).
858
- */
859
- outputDimension: z4.union([
860
- z4.literal(256),
861
- z4.literal(512),
862
- z4.literal(768),
863
- z4.literal(1024),
864
- z4.literal(1536),
865
- z4.literal(2048)
866
- ]).optional()
867
- });
869
+ var cohereEmbeddingModelOptions = lazySchema4(
870
+ () => zodSchema4(
871
+ z4.object({
872
+ /**
873
+ * Specifies the type of input passed to the model. Default is `search_query`.
874
+ *
875
+ * - "search_document": Used for embeddings stored in a vector database for search use-cases.
876
+ * - "search_query": Used for embeddings of search queries run against a vector DB to find relevant documents.
877
+ * - "classification": Used for embeddings passed through a text classifier.
878
+ * - "clustering": Used for embeddings run through a clustering algorithm.
879
+ */
880
+ inputType: z4.enum([
881
+ "search_document",
882
+ "search_query",
883
+ "classification",
884
+ "clustering"
885
+ ]).optional(),
886
+ /**
887
+ * Specifies how the API will handle inputs longer than the maximum token length.
888
+ * Default is `END`.
889
+ *
890
+ * - "NONE": If selected, when the input exceeds the maximum input token length will return an error.
891
+ * - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
892
+ * - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
893
+ */
894
+ truncate: z4.enum(["NONE", "START", "END"]).optional(),
895
+ /**
896
+ * The number of dimensions of the output embedding.
897
+ * Only available for `embed-v4.0` and newer models.
898
+ *
899
+ * Embed v4.0 supports `256`, `512`, `1024`, and `1536` (default).
900
+ * Embed v5.0 Pro and Fast also support `768` and `2048` (default).
901
+ */
902
+ outputDimension: z4.union([
903
+ z4.literal(256),
904
+ z4.literal(512),
905
+ z4.literal(768),
906
+ z4.literal(1024),
907
+ z4.literal(1536),
908
+ z4.literal(2048)
909
+ ]).optional()
910
+ })
911
+ )
912
+ );
868
913
 
869
914
  // src/cohere-embedding-model.ts
870
915
  var CohereEmbeddingModel = class {
@@ -931,16 +976,20 @@ var CohereEmbeddingModel = class {
931
976
  };
932
977
  }
933
978
  };
934
- var cohereTextEmbeddingResponseSchema = z5.object({
935
- embeddings: z5.object({
936
- float: z5.array(z5.array(z5.number()))
937
- }),
938
- meta: z5.object({
939
- billed_units: z5.object({
940
- input_tokens: z5.number()
979
+ var cohereTextEmbeddingResponseSchema = lazySchema5(
980
+ () => zodSchema5(
981
+ z5.object({
982
+ embeddings: z5.object({
983
+ float: z5.array(z5.array(z5.number()))
984
+ }),
985
+ meta: z5.object({
986
+ billed_units: z5.object({
987
+ input_tokens: z5.number()
988
+ })
989
+ })
941
990
  })
942
- })
943
- });
991
+ )
992
+ );
944
993
 
945
994
  // src/reranking/cohere-reranking-model.ts
946
995
  import {
@@ -951,10 +1000,10 @@ import {
951
1000
  } from "@ai-sdk/provider-utils";
952
1001
 
953
1002
  // src/reranking/cohere-reranking-api.ts
954
- import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
1003
+ import { lazySchema as lazySchema6, zodSchema as zodSchema6 } from "@ai-sdk/provider-utils";
955
1004
  import { z as z6 } from "zod/v4";
956
- var cohereRerankingResponseSchema = lazySchema(
957
- () => zodSchema(
1005
+ var cohereRerankingResponseSchema = lazySchema6(
1006
+ () => zodSchema6(
958
1007
  z6.object({
959
1008
  id: z6.string().nullish(),
960
1009
  results: z6.array(
@@ -970,12 +1019,12 @@ var cohereRerankingResponseSchema = lazySchema(
970
1019
 
971
1020
  // src/reranking/cohere-reranking-options.ts
972
1021
  import {
973
- lazySchema as lazySchema2,
974
- zodSchema as zodSchema2
1022
+ lazySchema as lazySchema7,
1023
+ zodSchema as zodSchema7
975
1024
  } from "@ai-sdk/provider-utils";
976
1025
  import { z as z7 } from "zod/v4";
977
- var cohereRerankingModelOptionsSchema = lazySchema2(
978
- () => zodSchema2(
1026
+ var cohereRerankingModelOptionsSchema = lazySchema7(
1027
+ () => zodSchema7(
979
1028
  z7.object({
980
1029
  maxTokensPerDoc: z7.number().optional(),
981
1030
  priority: z7.number().optional()
@@ -1054,7 +1103,7 @@ var CohereRerankingModel = class {
1054
1103
  };
1055
1104
 
1056
1105
  // src/version.ts
1057
- var VERSION = true ? "3.0.72" : "0.0.0-test";
1106
+ var VERSION = true ? "3.0.74" : "0.0.0-test";
1058
1107
 
1059
1108
  // src/cohere-provider.ts
1060
1109
  function createCohere(options = {}) {