@ai-sdk/cohere 2.0.45 → 2.0.47
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 +16 -0
- package/dist/index.d.mts +9 -12
- package/dist/index.d.ts +9 -12
- package/dist/index.js +258 -223
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +250 -201
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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,
|
|
@@ -20,36 +22,56 @@ import {
|
|
|
20
22
|
import { z as z3 } from "zod/v4";
|
|
21
23
|
|
|
22
24
|
// src/cohere-chat-options.ts
|
|
25
|
+
import {
|
|
26
|
+
lazySchema,
|
|
27
|
+
zodSchema
|
|
28
|
+
} from "@ai-sdk/provider-utils";
|
|
23
29
|
import { z } from "zod/v4";
|
|
24
|
-
var cohereChatModelOptions =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
var cohereChatModelOptions = lazySchema(
|
|
31
|
+
() => zodSchema(
|
|
32
|
+
z.object({
|
|
33
|
+
/**
|
|
34
|
+
* Configuration for reasoning features (optional)
|
|
35
|
+
*
|
|
36
|
+
* Can be set to an object with the two properties `type` and `tokenBudget`. `type` can be set to `'enabled'` or `'disabled'` (defaults to `'enabled'`).
|
|
37
|
+
* `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
|
|
38
|
+
*
|
|
39
|
+
* @see https://docs.cohere.com/reference/chat#request.body.thinking
|
|
40
|
+
*/
|
|
41
|
+
thinking: z.object({
|
|
42
|
+
type: z.enum(["enabled", "disabled"]).optional(),
|
|
43
|
+
tokenBudget: z.number().optional()
|
|
44
|
+
}).optional()
|
|
45
|
+
})
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
var cohereImagePartProviderOptions = lazySchema(
|
|
49
|
+
() => zodSchema(
|
|
50
|
+
z.object({
|
|
51
|
+
/**
|
|
52
|
+
* Image fidelity level passed through as `image_url.detail` on the Cohere chat API.
|
|
53
|
+
*
|
|
54
|
+
* @see https://docs.cohere.com/docs/image-inputs
|
|
55
|
+
*/
|
|
56
|
+
detail: z.enum(["auto", "low", "high"]).optional()
|
|
57
|
+
})
|
|
58
|
+
)
|
|
59
|
+
);
|
|
46
60
|
|
|
47
61
|
// src/cohere-error.ts
|
|
48
|
-
import {
|
|
62
|
+
import {
|
|
63
|
+
lazySchema as lazySchema2,
|
|
64
|
+
zodSchema as zodSchema2,
|
|
65
|
+
createJsonErrorResponseHandler
|
|
66
|
+
} from "@ai-sdk/provider-utils";
|
|
49
67
|
import { z as z2 } from "zod/v4";
|
|
50
|
-
var cohereErrorDataSchema =
|
|
51
|
-
|
|
52
|
-
|
|
68
|
+
var cohereErrorDataSchema = lazySchema2(
|
|
69
|
+
() => zodSchema2(
|
|
70
|
+
z2.object({
|
|
71
|
+
message: z2.string()
|
|
72
|
+
})
|
|
73
|
+
)
|
|
74
|
+
);
|
|
53
75
|
var cohereFailedResponseHandler = createJsonErrorResponseHandler({
|
|
54
76
|
errorSchema: cohereErrorDataSchema,
|
|
55
77
|
errorToMessage: (data) => data.message
|
|
@@ -610,175 +632,185 @@ var CohereChatLanguageModel = class {
|
|
|
610
632
|
};
|
|
611
633
|
}
|
|
612
634
|
};
|
|
613
|
-
var cohereChatResponseSchema =
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
content: z3.array(
|
|
618
|
-
z3.union([
|
|
619
|
-
z3.object({
|
|
620
|
-
type: z3.literal("text"),
|
|
621
|
-
text: z3.string()
|
|
622
|
-
}),
|
|
623
|
-
z3.object({
|
|
624
|
-
type: z3.literal("thinking"),
|
|
625
|
-
thinking: z3.string()
|
|
626
|
-
})
|
|
627
|
-
])
|
|
628
|
-
).nullish(),
|
|
629
|
-
tool_plan: z3.string().nullish(),
|
|
630
|
-
tool_calls: z3.array(
|
|
631
|
-
z3.object({
|
|
632
|
-
id: z3.string(),
|
|
633
|
-
type: z3.literal("function"),
|
|
634
|
-
function: z3.object({
|
|
635
|
-
name: z3.string(),
|
|
636
|
-
arguments: z3.string()
|
|
637
|
-
})
|
|
638
|
-
})
|
|
639
|
-
).nullish(),
|
|
640
|
-
citations: z3.array(
|
|
641
|
-
z3.object({
|
|
642
|
-
start: z3.number(),
|
|
643
|
-
end: z3.number(),
|
|
644
|
-
text: z3.string(),
|
|
645
|
-
sources: z3.array(
|
|
646
|
-
z3.object({
|
|
647
|
-
type: z3.string().optional(),
|
|
648
|
-
id: z3.string().optional(),
|
|
649
|
-
document: z3.object({
|
|
650
|
-
id: z3.string().optional(),
|
|
651
|
-
text: z3.string(),
|
|
652
|
-
title: z3.string()
|
|
653
|
-
})
|
|
654
|
-
})
|
|
655
|
-
),
|
|
656
|
-
type: z3.string().optional()
|
|
657
|
-
})
|
|
658
|
-
).nullish()
|
|
659
|
-
}),
|
|
660
|
-
finish_reason: z3.string(),
|
|
661
|
-
usage: z3.object({
|
|
662
|
-
billed_units: z3.object({
|
|
663
|
-
input_tokens: z3.number(),
|
|
664
|
-
output_tokens: z3.number()
|
|
665
|
-
}),
|
|
666
|
-
tokens: z3.object({
|
|
667
|
-
input_tokens: z3.number(),
|
|
668
|
-
output_tokens: z3.number()
|
|
669
|
-
})
|
|
670
|
-
})
|
|
671
|
-
});
|
|
672
|
-
var cohereChatChunkSchema = z3.discriminatedUnion("type", [
|
|
673
|
-
z3.object({
|
|
674
|
-
type: z3.literal("citation-start")
|
|
675
|
-
}),
|
|
676
|
-
z3.object({
|
|
677
|
-
type: z3.literal("citation-end")
|
|
678
|
-
}),
|
|
679
|
-
z3.object({
|
|
680
|
-
type: z3.literal("content-start"),
|
|
681
|
-
index: z3.number(),
|
|
682
|
-
delta: z3.object({
|
|
635
|
+
var cohereChatResponseSchema = lazySchema3(
|
|
636
|
+
() => zodSchema3(
|
|
637
|
+
z3.object({
|
|
638
|
+
generation_id: z3.string().nullish(),
|
|
683
639
|
message: z3.object({
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
640
|
+
role: z3.string(),
|
|
641
|
+
content: z3.array(
|
|
642
|
+
z3.union([
|
|
643
|
+
z3.object({
|
|
644
|
+
type: z3.literal("text"),
|
|
645
|
+
text: z3.string()
|
|
646
|
+
}),
|
|
647
|
+
z3.object({
|
|
648
|
+
type: z3.literal("thinking"),
|
|
649
|
+
thinking: z3.string()
|
|
650
|
+
})
|
|
651
|
+
])
|
|
652
|
+
).nullish(),
|
|
653
|
+
tool_plan: z3.string().nullish(),
|
|
654
|
+
tool_calls: z3.array(
|
|
689
655
|
z3.object({
|
|
690
|
-
|
|
691
|
-
|
|
656
|
+
id: z3.string(),
|
|
657
|
+
type: z3.literal("function"),
|
|
658
|
+
function: z3.object({
|
|
659
|
+
name: z3.string(),
|
|
660
|
+
arguments: z3.string()
|
|
661
|
+
})
|
|
692
662
|
})
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
})
|
|
696
|
-
}),
|
|
697
|
-
z3.object({
|
|
698
|
-
type: z3.literal("content-delta"),
|
|
699
|
-
index: z3.number(),
|
|
700
|
-
delta: z3.object({
|
|
701
|
-
message: z3.object({
|
|
702
|
-
content: z3.union([
|
|
703
|
-
z3.object({
|
|
704
|
-
text: z3.string()
|
|
705
|
-
}),
|
|
663
|
+
).nullish(),
|
|
664
|
+
citations: z3.array(
|
|
706
665
|
z3.object({
|
|
707
|
-
|
|
666
|
+
start: z3.number(),
|
|
667
|
+
end: z3.number(),
|
|
668
|
+
text: z3.string(),
|
|
669
|
+
sources: z3.array(
|
|
670
|
+
z3.object({
|
|
671
|
+
type: z3.string().optional(),
|
|
672
|
+
id: z3.string().optional(),
|
|
673
|
+
document: z3.object({
|
|
674
|
+
id: z3.string().optional(),
|
|
675
|
+
text: z3.string(),
|
|
676
|
+
title: z3.string()
|
|
677
|
+
})
|
|
678
|
+
})
|
|
679
|
+
),
|
|
680
|
+
type: z3.string().optional()
|
|
708
681
|
})
|
|
709
|
-
|
|
710
|
-
})
|
|
711
|
-
})
|
|
712
|
-
}),
|
|
713
|
-
z3.object({
|
|
714
|
-
type: z3.literal("content-end"),
|
|
715
|
-
index: z3.number()
|
|
716
|
-
}),
|
|
717
|
-
z3.object({
|
|
718
|
-
type: z3.literal("message-start"),
|
|
719
|
-
id: z3.string().nullish()
|
|
720
|
-
}),
|
|
721
|
-
z3.object({
|
|
722
|
-
type: z3.literal("message-end"),
|
|
723
|
-
delta: z3.object({
|
|
682
|
+
).nullish()
|
|
683
|
+
}),
|
|
724
684
|
finish_reason: z3.string(),
|
|
725
685
|
usage: z3.object({
|
|
686
|
+
billed_units: z3.object({
|
|
687
|
+
input_tokens: z3.number(),
|
|
688
|
+
output_tokens: z3.number()
|
|
689
|
+
}),
|
|
726
690
|
tokens: z3.object({
|
|
727
691
|
input_tokens: z3.number(),
|
|
728
692
|
output_tokens: z3.number()
|
|
729
693
|
})
|
|
730
694
|
})
|
|
731
695
|
})
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
})
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
696
|
+
)
|
|
697
|
+
);
|
|
698
|
+
var cohereChatChunkSchema = lazySchema3(
|
|
699
|
+
() => zodSchema3(
|
|
700
|
+
z3.discriminatedUnion("type", [
|
|
701
|
+
z3.object({
|
|
702
|
+
type: z3.literal("citation-start")
|
|
703
|
+
}),
|
|
704
|
+
z3.object({
|
|
705
|
+
type: z3.literal("citation-end")
|
|
706
|
+
}),
|
|
707
|
+
z3.object({
|
|
708
|
+
type: z3.literal("content-start"),
|
|
709
|
+
index: z3.number(),
|
|
710
|
+
delta: z3.object({
|
|
711
|
+
message: z3.object({
|
|
712
|
+
content: z3.union([
|
|
713
|
+
z3.object({
|
|
714
|
+
type: z3.literal("text"),
|
|
715
|
+
text: z3.string()
|
|
716
|
+
}),
|
|
717
|
+
z3.object({
|
|
718
|
+
type: z3.literal("thinking"),
|
|
719
|
+
thinking: z3.string()
|
|
720
|
+
})
|
|
721
|
+
])
|
|
752
722
|
})
|
|
753
723
|
})
|
|
754
|
-
})
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
724
|
+
}),
|
|
725
|
+
z3.object({
|
|
726
|
+
type: z3.literal("content-delta"),
|
|
727
|
+
index: z3.number(),
|
|
728
|
+
delta: z3.object({
|
|
729
|
+
message: z3.object({
|
|
730
|
+
content: z3.union([
|
|
731
|
+
z3.object({
|
|
732
|
+
text: z3.string()
|
|
733
|
+
}),
|
|
734
|
+
z3.object({
|
|
735
|
+
thinking: z3.string()
|
|
736
|
+
})
|
|
737
|
+
])
|
|
738
|
+
})
|
|
739
|
+
})
|
|
740
|
+
}),
|
|
741
|
+
z3.object({
|
|
742
|
+
type: z3.literal("content-end"),
|
|
743
|
+
index: z3.number()
|
|
744
|
+
}),
|
|
745
|
+
z3.object({
|
|
746
|
+
type: z3.literal("message-start"),
|
|
747
|
+
id: z3.string().nullish()
|
|
748
|
+
}),
|
|
749
|
+
z3.object({
|
|
750
|
+
type: z3.literal("message-end"),
|
|
751
|
+
delta: z3.object({
|
|
752
|
+
finish_reason: z3.string(),
|
|
753
|
+
usage: z3.object({
|
|
754
|
+
tokens: z3.object({
|
|
755
|
+
input_tokens: z3.number(),
|
|
756
|
+
output_tokens: z3.number()
|
|
757
|
+
})
|
|
758
|
+
})
|
|
759
|
+
})
|
|
760
|
+
}),
|
|
761
|
+
// https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
|
|
762
|
+
z3.object({
|
|
763
|
+
type: z3.literal("tool-plan-delta"),
|
|
764
|
+
delta: z3.object({
|
|
765
|
+
message: z3.object({
|
|
766
|
+
tool_plan: z3.string()
|
|
767
|
+
})
|
|
768
|
+
})
|
|
769
|
+
}),
|
|
770
|
+
z3.object({
|
|
771
|
+
type: z3.literal("tool-call-start"),
|
|
772
|
+
delta: z3.object({
|
|
773
|
+
message: z3.object({
|
|
774
|
+
tool_calls: z3.object({
|
|
775
|
+
id: z3.string(),
|
|
776
|
+
type: z3.literal("function"),
|
|
777
|
+
function: z3.object({
|
|
778
|
+
name: z3.string(),
|
|
779
|
+
arguments: z3.string()
|
|
780
|
+
})
|
|
781
|
+
})
|
|
782
|
+
})
|
|
783
|
+
})
|
|
784
|
+
}),
|
|
785
|
+
// A single tool call's `arguments` stream in chunks and must be accumulated
|
|
786
|
+
// in a string and so the full tool object info can only be parsed once we see
|
|
787
|
+
// `tool-call-end`.
|
|
788
|
+
z3.object({
|
|
789
|
+
type: z3.literal("tool-call-delta"),
|
|
790
|
+
delta: z3.object({
|
|
791
|
+
message: z3.object({
|
|
792
|
+
tool_calls: z3.object({
|
|
793
|
+
function: z3.object({
|
|
794
|
+
arguments: z3.string()
|
|
795
|
+
})
|
|
796
|
+
})
|
|
767
797
|
})
|
|
768
798
|
})
|
|
799
|
+
}),
|
|
800
|
+
z3.object({
|
|
801
|
+
type: z3.literal("tool-call-end")
|
|
769
802
|
})
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
type: z3.literal("tool-call-end")
|
|
774
|
-
})
|
|
775
|
-
]);
|
|
803
|
+
])
|
|
804
|
+
)
|
|
805
|
+
);
|
|
776
806
|
|
|
777
807
|
// src/cohere-embedding-model.ts
|
|
778
808
|
import {
|
|
779
809
|
TooManyEmbeddingValuesForCallError
|
|
780
810
|
} from "@ai-sdk/provider";
|
|
781
811
|
import {
|
|
812
|
+
lazySchema as lazySchema5,
|
|
813
|
+
zodSchema as zodSchema5,
|
|
782
814
|
combineHeaders as combineHeaders2,
|
|
783
815
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
784
816
|
parseProviderOptions as parseProviderOptions3,
|
|
@@ -787,27 +819,40 @@ import {
|
|
|
787
819
|
import { z as z5 } from "zod/v4";
|
|
788
820
|
|
|
789
821
|
// src/cohere-embedding-options.ts
|
|
822
|
+
import {
|
|
823
|
+
lazySchema as lazySchema4,
|
|
824
|
+
zodSchema as zodSchema4
|
|
825
|
+
} from "@ai-sdk/provider-utils";
|
|
790
826
|
import { z as z4 } from "zod/v4";
|
|
791
|
-
var cohereEmbeddingOptions =
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
827
|
+
var cohereEmbeddingOptions = lazySchema4(
|
|
828
|
+
() => zodSchema4(
|
|
829
|
+
z4.object({
|
|
830
|
+
/**
|
|
831
|
+
* Specifies the type of input passed to the model. Default is `search_query`.
|
|
832
|
+
*
|
|
833
|
+
* - "search_document": Used for embeddings stored in a vector database for search use-cases.
|
|
834
|
+
* - "search_query": Used for embeddings of search queries run against a vector DB to find relevant documents.
|
|
835
|
+
* - "classification": Used for embeddings passed through a text classifier.
|
|
836
|
+
* - "clustering": Used for embeddings run through a clustering algorithm.
|
|
837
|
+
*/
|
|
838
|
+
inputType: z4.enum([
|
|
839
|
+
"search_document",
|
|
840
|
+
"search_query",
|
|
841
|
+
"classification",
|
|
842
|
+
"clustering"
|
|
843
|
+
]).optional(),
|
|
844
|
+
/**
|
|
845
|
+
* Specifies how the API will handle inputs longer than the maximum token length.
|
|
846
|
+
* Default is `END`.
|
|
847
|
+
*
|
|
848
|
+
* - "NONE": If selected, when the input exceeds the maximum input token length will return an error.
|
|
849
|
+
* - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
|
|
850
|
+
* - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
|
|
851
|
+
*/
|
|
852
|
+
truncate: z4.enum(["NONE", "START", "END"]).optional()
|
|
853
|
+
})
|
|
854
|
+
)
|
|
855
|
+
);
|
|
811
856
|
|
|
812
857
|
// src/cohere-embedding-model.ts
|
|
813
858
|
var CohereEmbeddingModel = class {
|
|
@@ -872,19 +917,23 @@ var CohereEmbeddingModel = class {
|
|
|
872
917
|
};
|
|
873
918
|
}
|
|
874
919
|
};
|
|
875
|
-
var cohereTextEmbeddingResponseSchema =
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
920
|
+
var cohereTextEmbeddingResponseSchema = lazySchema5(
|
|
921
|
+
() => zodSchema5(
|
|
922
|
+
z5.object({
|
|
923
|
+
embeddings: z5.object({
|
|
924
|
+
float: z5.array(z5.array(z5.number()))
|
|
925
|
+
}),
|
|
926
|
+
meta: z5.object({
|
|
927
|
+
billed_units: z5.object({
|
|
928
|
+
input_tokens: z5.number()
|
|
929
|
+
})
|
|
930
|
+
})
|
|
882
931
|
})
|
|
883
|
-
|
|
884
|
-
|
|
932
|
+
)
|
|
933
|
+
);
|
|
885
934
|
|
|
886
935
|
// src/version.ts
|
|
887
|
-
var VERSION = true ? "2.0.
|
|
936
|
+
var VERSION = true ? "2.0.47" : "0.0.0-test";
|
|
888
937
|
|
|
889
938
|
// src/cohere-provider.ts
|
|
890
939
|
function createCohere(options = {}) {
|