@ai-sdk/cohere 3.0.75 → 3.0.76
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 +39 -0
- package/dist/index.js +223 -172
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +223 -172
- package/dist/index.mjs.map +1 -1
- package/docs/25-cohere.mdx +69 -0
- package/package.json +1 -1
- package/src/cohere-chat-language-model.ts +67 -45
- package/src/cohere-citations.ts +77 -0
- package/src/convert-cohere-usage.ts +8 -6
package/dist/index.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
parseJSON,
|
|
21
21
|
postJsonToApi
|
|
22
22
|
} from "@ai-sdk/provider-utils";
|
|
23
|
-
import { z as
|
|
23
|
+
import { z as z4 } from "zod/v4";
|
|
24
24
|
|
|
25
25
|
// src/cohere-chat-options.ts
|
|
26
26
|
import {
|
|
@@ -59,17 +59,67 @@ var cohereImagePartProviderOptions = lazySchema(
|
|
|
59
59
|
)
|
|
60
60
|
);
|
|
61
61
|
|
|
62
|
+
// src/cohere-citations.ts
|
|
63
|
+
import { z as z2 } from "zod/v4";
|
|
64
|
+
var cohereCitationSchema = z2.object({
|
|
65
|
+
start: z2.number().nullish(),
|
|
66
|
+
end: z2.number().nullish(),
|
|
67
|
+
text: z2.string().nullish(),
|
|
68
|
+
sources: z2.array(
|
|
69
|
+
z2.object({
|
|
70
|
+
type: z2.string().nullish(),
|
|
71
|
+
id: z2.string().nullish(),
|
|
72
|
+
// Documents are arbitrary objects; only the fields the provider maps
|
|
73
|
+
// are typed, everything else is passed through as provider metadata.
|
|
74
|
+
document: z2.looseObject({
|
|
75
|
+
id: z2.string().nullish(),
|
|
76
|
+
text: z2.string().nullish(),
|
|
77
|
+
title: z2.string().nullish()
|
|
78
|
+
}).nullish(),
|
|
79
|
+
tool_output: z2.looseObject({}).nullish()
|
|
80
|
+
})
|
|
81
|
+
).nullish(),
|
|
82
|
+
type: z2.string().nullish()
|
|
83
|
+
});
|
|
84
|
+
function mapCohereCitationToSource(citation, generateId2) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const document = (_b = (_a = citation.sources) == null ? void 0 : _a.find(
|
|
87
|
+
(source) => source.document != null
|
|
88
|
+
)) == null ? void 0 : _b.document;
|
|
89
|
+
if (document == null) {
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
type: "source",
|
|
94
|
+
sourceType: "document",
|
|
95
|
+
id: generateId2(),
|
|
96
|
+
mediaType: "text/plain",
|
|
97
|
+
title: document.title || "Document",
|
|
98
|
+
providerMetadata: {
|
|
99
|
+
cohere: {
|
|
100
|
+
...citation.start != null && { start: citation.start },
|
|
101
|
+
...citation.end != null && { end: citation.end },
|
|
102
|
+
...citation.text != null && { text: citation.text },
|
|
103
|
+
...citation.sources != null && {
|
|
104
|
+
sources: citation.sources
|
|
105
|
+
},
|
|
106
|
+
...citation.type != null && { citationType: citation.type }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
62
112
|
// src/cohere-error.ts
|
|
63
113
|
import {
|
|
64
114
|
lazySchema as lazySchema2,
|
|
65
115
|
zodSchema as zodSchema2,
|
|
66
116
|
createJsonErrorResponseHandler
|
|
67
117
|
} from "@ai-sdk/provider-utils";
|
|
68
|
-
import { z as
|
|
118
|
+
import { z as z3 } from "zod/v4";
|
|
69
119
|
var cohereErrorDataSchema = lazySchema2(
|
|
70
120
|
() => zodSchema2(
|
|
71
|
-
|
|
72
|
-
message:
|
|
121
|
+
z3.object({
|
|
122
|
+
message: z3.string()
|
|
73
123
|
})
|
|
74
124
|
)
|
|
75
125
|
);
|
|
@@ -139,6 +189,7 @@ function prepareTools({
|
|
|
139
189
|
|
|
140
190
|
// src/convert-cohere-usage.ts
|
|
141
191
|
function convertCohereUsage(usage) {
|
|
192
|
+
var _a, _b, _c, _d;
|
|
142
193
|
if (usage == null) {
|
|
143
194
|
return {
|
|
144
195
|
inputTokens: {
|
|
@@ -155,9 +206,8 @@ function convertCohereUsage(usage) {
|
|
|
155
206
|
raw: void 0
|
|
156
207
|
};
|
|
157
208
|
}
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
const outputTokens = tokens.output_tokens;
|
|
209
|
+
const inputTokens = (_b = (_a = usage.tokens) == null ? void 0 : _a.input_tokens) != null ? _b : void 0;
|
|
210
|
+
const outputTokens = (_d = (_c = usage.tokens) == null ? void 0 : _c.output_tokens) != null ? _d : void 0;
|
|
161
211
|
return {
|
|
162
212
|
inputTokens: {
|
|
163
213
|
total: inputTokens,
|
|
@@ -445,7 +495,7 @@ var CohereChatLanguageModel = class {
|
|
|
445
495
|
};
|
|
446
496
|
}
|
|
447
497
|
async doGenerate(options) {
|
|
448
|
-
var _a, _b, _c, _d, _e, _f
|
|
498
|
+
var _a, _b, _c, _d, _e, _f;
|
|
449
499
|
const { args, warnings } = await this.getArgs(options);
|
|
450
500
|
const {
|
|
451
501
|
responseHeaders,
|
|
@@ -474,24 +524,15 @@ var CohereChatLanguageModel = class {
|
|
|
474
524
|
}
|
|
475
525
|
}
|
|
476
526
|
for (const citation of (_b = response.message.citations) != null ? _b : []) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
cohere: {
|
|
485
|
-
start: citation.start,
|
|
486
|
-
end: citation.end,
|
|
487
|
-
text: citation.text,
|
|
488
|
-
sources: citation.sources,
|
|
489
|
-
...citation.type && { citationType: citation.type }
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
});
|
|
527
|
+
const source = mapCohereCitationToSource(
|
|
528
|
+
citation,
|
|
529
|
+
() => this.config.generateId()
|
|
530
|
+
);
|
|
531
|
+
if (source != null) {
|
|
532
|
+
content.push(source);
|
|
533
|
+
}
|
|
493
534
|
}
|
|
494
|
-
for (const toolCall of (
|
|
535
|
+
for (const toolCall of (_c = response.message.tool_calls) != null ? _c : []) {
|
|
495
536
|
content.push({
|
|
496
537
|
type: "tool-call",
|
|
497
538
|
toolCallId: toolCall.id,
|
|
@@ -505,13 +546,15 @@ var CohereChatLanguageModel = class {
|
|
|
505
546
|
content,
|
|
506
547
|
finishReason: {
|
|
507
548
|
unified: mapCohereFinishReason(response.finish_reason),
|
|
508
|
-
raw: (
|
|
549
|
+
raw: (_d = response.finish_reason) != null ? _d : void 0
|
|
509
550
|
},
|
|
510
551
|
usage: convertCohereUsage(response.usage),
|
|
511
552
|
request: { body: args },
|
|
512
553
|
response: {
|
|
513
554
|
// TODO timestamp, model id
|
|
514
|
-
|
|
555
|
+
// Cohere v2 returns `id`; `generation_id` is the v1 field, kept only
|
|
556
|
+
// for compatibility with proxies/mocks that still return it.
|
|
557
|
+
id: (_f = (_e = response.id) != null ? _e : response.generation_id) != null ? _f : void 0,
|
|
515
558
|
headers: responseHeaders,
|
|
516
559
|
body: rawResponse
|
|
517
560
|
},
|
|
@@ -538,6 +581,7 @@ var CohereChatLanguageModel = class {
|
|
|
538
581
|
let usage = void 0;
|
|
539
582
|
let pendingToolCall = null;
|
|
540
583
|
let isActiveReasoning = false;
|
|
584
|
+
const generateId2 = this.config.generateId;
|
|
541
585
|
return {
|
|
542
586
|
stream: response.pipeThrough(
|
|
543
587
|
new TransformStream({
|
|
@@ -545,7 +589,7 @@ var CohereChatLanguageModel = class {
|
|
|
545
589
|
controller.enqueue({ type: "stream-start", warnings });
|
|
546
590
|
},
|
|
547
591
|
async transform(chunk, controller) {
|
|
548
|
-
var _a, _b;
|
|
592
|
+
var _a, _b, _c, _d;
|
|
549
593
|
if (options.includeRawChunks) {
|
|
550
594
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
551
595
|
}
|
|
@@ -603,6 +647,22 @@ var CohereChatLanguageModel = class {
|
|
|
603
647
|
});
|
|
604
648
|
return;
|
|
605
649
|
}
|
|
650
|
+
case "citation-start": {
|
|
651
|
+
const citations = (_b = (_a = value.delta) == null ? void 0 : _a.message) == null ? void 0 : _b.citations;
|
|
652
|
+
if (citations == null) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
for (const citation of Array.isArray(citations) ? citations : [citations]) {
|
|
656
|
+
const source = mapCohereCitationToSource(
|
|
657
|
+
citation,
|
|
658
|
+
generateId2
|
|
659
|
+
);
|
|
660
|
+
if (source != null) {
|
|
661
|
+
controller.enqueue(source);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
606
666
|
case "tool-call-start": {
|
|
607
667
|
const toolId = value.delta.message.tool_calls.id;
|
|
608
668
|
const toolName = value.delta.message.tool_calls.function.name;
|
|
@@ -651,7 +711,7 @@ var CohereChatLanguageModel = class {
|
|
|
651
711
|
toolName: pendingToolCall.name,
|
|
652
712
|
input: JSON.stringify(
|
|
653
713
|
await parseJSON({
|
|
654
|
-
text: ((
|
|
714
|
+
text: ((_c = pendingToolCall.arguments) == null ? void 0 : _c.trim()) || "{}"
|
|
655
715
|
})
|
|
656
716
|
)
|
|
657
717
|
});
|
|
@@ -663,7 +723,7 @@ var CohereChatLanguageModel = class {
|
|
|
663
723
|
case "message-start": {
|
|
664
724
|
controller.enqueue({
|
|
665
725
|
type: "response-metadata",
|
|
666
|
-
id: (
|
|
726
|
+
id: (_d = value.id) != null ? _d : void 0
|
|
667
727
|
});
|
|
668
728
|
return;
|
|
669
729
|
}
|
|
@@ -693,148 +753,139 @@ var CohereChatLanguageModel = class {
|
|
|
693
753
|
};
|
|
694
754
|
}
|
|
695
755
|
};
|
|
696
|
-
var cohereUsageSchema = () =>
|
|
697
|
-
billed_units:
|
|
698
|
-
input_tokens:
|
|
699
|
-
output_tokens:
|
|
756
|
+
var cohereUsageSchema = () => z4.looseObject({
|
|
757
|
+
billed_units: z4.looseObject({
|
|
758
|
+
input_tokens: z4.number().nullish(),
|
|
759
|
+
output_tokens: z4.number().nullish()
|
|
760
|
+
}).nullish(),
|
|
761
|
+
tokens: z4.looseObject({
|
|
762
|
+
input_tokens: z4.number().nullish(),
|
|
763
|
+
output_tokens: z4.number().nullish()
|
|
700
764
|
}).nullish(),
|
|
701
|
-
|
|
702
|
-
input_tokens: z3.number(),
|
|
703
|
-
output_tokens: z3.number()
|
|
704
|
-
}),
|
|
705
|
-
cached_tokens: z3.number().nullish()
|
|
765
|
+
cached_tokens: z4.number().nullish()
|
|
706
766
|
});
|
|
707
767
|
var cohereChatResponseSchema = lazySchema3(
|
|
708
768
|
() => zodSchema3(
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
769
|
+
z4.object({
|
|
770
|
+
id: z4.string().nullish(),
|
|
771
|
+
generation_id: z4.string().nullish(),
|
|
772
|
+
message: z4.object({
|
|
773
|
+
role: z4.string(),
|
|
774
|
+
content: z4.array(
|
|
775
|
+
z4.union([
|
|
776
|
+
z4.object({
|
|
777
|
+
type: z4.literal("text"),
|
|
778
|
+
text: z4.string()
|
|
718
779
|
}),
|
|
719
|
-
|
|
720
|
-
type:
|
|
721
|
-
thinking:
|
|
780
|
+
z4.object({
|
|
781
|
+
type: z4.literal("thinking"),
|
|
782
|
+
thinking: z4.string()
|
|
722
783
|
})
|
|
723
784
|
])
|
|
724
785
|
).nullish(),
|
|
725
|
-
tool_plan:
|
|
726
|
-
tool_calls:
|
|
727
|
-
|
|
728
|
-
id:
|
|
729
|
-
type:
|
|
730
|
-
function:
|
|
731
|
-
name:
|
|
732
|
-
arguments:
|
|
786
|
+
tool_plan: z4.string().nullish(),
|
|
787
|
+
tool_calls: z4.array(
|
|
788
|
+
z4.object({
|
|
789
|
+
id: z4.string(),
|
|
790
|
+
type: z4.literal("function"),
|
|
791
|
+
function: z4.object({
|
|
792
|
+
name: z4.string(),
|
|
793
|
+
arguments: z4.string()
|
|
733
794
|
})
|
|
734
795
|
})
|
|
735
796
|
).nullish(),
|
|
736
|
-
citations:
|
|
737
|
-
z3.object({
|
|
738
|
-
start: z3.number(),
|
|
739
|
-
end: z3.number(),
|
|
740
|
-
text: z3.string(),
|
|
741
|
-
sources: z3.array(
|
|
742
|
-
z3.object({
|
|
743
|
-
type: z3.string().optional(),
|
|
744
|
-
id: z3.string().optional(),
|
|
745
|
-
document: z3.object({
|
|
746
|
-
id: z3.string().optional(),
|
|
747
|
-
text: z3.string(),
|
|
748
|
-
title: z3.string()
|
|
749
|
-
})
|
|
750
|
-
})
|
|
751
|
-
),
|
|
752
|
-
type: z3.string().optional()
|
|
753
|
-
})
|
|
754
|
-
).nullish()
|
|
797
|
+
citations: z4.array(cohereCitationSchema).nullish()
|
|
755
798
|
}),
|
|
756
|
-
finish_reason:
|
|
757
|
-
usage: cohereUsageSchema()
|
|
799
|
+
finish_reason: z4.string(),
|
|
800
|
+
usage: cohereUsageSchema().nullish()
|
|
758
801
|
})
|
|
759
802
|
)
|
|
760
803
|
);
|
|
761
804
|
var cohereChatChunkSchema = lazySchema3(
|
|
762
805
|
() => zodSchema3(
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
806
|
+
z4.discriminatedUnion("type", [
|
|
807
|
+
// `citation-start` events can arrive without citations, and a single
|
|
808
|
+
// citation may be sent instead of an array.
|
|
809
|
+
z4.object({
|
|
810
|
+
type: z4.literal("citation-start"),
|
|
811
|
+
index: z4.number().nullish(),
|
|
812
|
+
delta: z4.object({
|
|
813
|
+
message: z4.object({
|
|
814
|
+
citations: z4.union([cohereCitationSchema, z4.array(cohereCitationSchema)]).nullish()
|
|
815
|
+
}).nullish()
|
|
816
|
+
}).nullish()
|
|
766
817
|
}),
|
|
767
|
-
|
|
768
|
-
type:
|
|
818
|
+
z4.object({
|
|
819
|
+
type: z4.literal("citation-end")
|
|
769
820
|
}),
|
|
770
|
-
|
|
771
|
-
type:
|
|
772
|
-
index:
|
|
773
|
-
delta:
|
|
774
|
-
message:
|
|
775
|
-
content:
|
|
776
|
-
|
|
777
|
-
type:
|
|
778
|
-
text:
|
|
821
|
+
z4.object({
|
|
822
|
+
type: z4.literal("content-start"),
|
|
823
|
+
index: z4.number(),
|
|
824
|
+
delta: z4.object({
|
|
825
|
+
message: z4.object({
|
|
826
|
+
content: z4.union([
|
|
827
|
+
z4.object({
|
|
828
|
+
type: z4.literal("text"),
|
|
829
|
+
text: z4.string()
|
|
779
830
|
}),
|
|
780
|
-
|
|
781
|
-
type:
|
|
782
|
-
thinking:
|
|
831
|
+
z4.object({
|
|
832
|
+
type: z4.literal("thinking"),
|
|
833
|
+
thinking: z4.string()
|
|
783
834
|
})
|
|
784
835
|
])
|
|
785
836
|
})
|
|
786
837
|
})
|
|
787
838
|
}),
|
|
788
|
-
|
|
789
|
-
type:
|
|
790
|
-
index:
|
|
791
|
-
delta:
|
|
792
|
-
message:
|
|
793
|
-
content:
|
|
794
|
-
|
|
795
|
-
text:
|
|
839
|
+
z4.object({
|
|
840
|
+
type: z4.literal("content-delta"),
|
|
841
|
+
index: z4.number(),
|
|
842
|
+
delta: z4.object({
|
|
843
|
+
message: z4.object({
|
|
844
|
+
content: z4.union([
|
|
845
|
+
z4.object({
|
|
846
|
+
text: z4.string()
|
|
796
847
|
}),
|
|
797
|
-
|
|
798
|
-
thinking:
|
|
848
|
+
z4.object({
|
|
849
|
+
thinking: z4.string()
|
|
799
850
|
})
|
|
800
851
|
])
|
|
801
852
|
})
|
|
802
853
|
})
|
|
803
854
|
}),
|
|
804
|
-
|
|
805
|
-
type:
|
|
806
|
-
index:
|
|
855
|
+
z4.object({
|
|
856
|
+
type: z4.literal("content-end"),
|
|
857
|
+
index: z4.number()
|
|
807
858
|
}),
|
|
808
|
-
|
|
809
|
-
type:
|
|
810
|
-
id:
|
|
859
|
+
z4.object({
|
|
860
|
+
type: z4.literal("message-start"),
|
|
861
|
+
id: z4.string().nullish()
|
|
811
862
|
}),
|
|
812
|
-
|
|
813
|
-
type:
|
|
814
|
-
delta:
|
|
815
|
-
finish_reason:
|
|
863
|
+
z4.object({
|
|
864
|
+
type: z4.literal("message-end"),
|
|
865
|
+
delta: z4.object({
|
|
866
|
+
finish_reason: z4.string(),
|
|
816
867
|
usage: cohereUsageSchema()
|
|
817
868
|
})
|
|
818
869
|
}),
|
|
819
870
|
// https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
|
|
820
|
-
|
|
821
|
-
type:
|
|
822
|
-
delta:
|
|
823
|
-
message:
|
|
824
|
-
tool_plan:
|
|
871
|
+
z4.object({
|
|
872
|
+
type: z4.literal("tool-plan-delta"),
|
|
873
|
+
delta: z4.object({
|
|
874
|
+
message: z4.object({
|
|
875
|
+
tool_plan: z4.string()
|
|
825
876
|
})
|
|
826
877
|
})
|
|
827
878
|
}),
|
|
828
|
-
|
|
829
|
-
type:
|
|
830
|
-
delta:
|
|
831
|
-
message:
|
|
832
|
-
tool_calls:
|
|
833
|
-
id:
|
|
834
|
-
type:
|
|
835
|
-
function:
|
|
836
|
-
name:
|
|
837
|
-
arguments:
|
|
879
|
+
z4.object({
|
|
880
|
+
type: z4.literal("tool-call-start"),
|
|
881
|
+
delta: z4.object({
|
|
882
|
+
message: z4.object({
|
|
883
|
+
tool_calls: z4.object({
|
|
884
|
+
id: z4.string(),
|
|
885
|
+
type: z4.literal("function"),
|
|
886
|
+
function: z4.object({
|
|
887
|
+
name: z4.string(),
|
|
888
|
+
arguments: z4.string()
|
|
838
889
|
})
|
|
839
890
|
})
|
|
840
891
|
})
|
|
@@ -843,20 +894,20 @@ var cohereChatChunkSchema = lazySchema3(
|
|
|
843
894
|
// A single tool call's `arguments` stream in chunks and must be accumulated
|
|
844
895
|
// in a string and so the full tool object info can only be parsed once we see
|
|
845
896
|
// `tool-call-end`.
|
|
846
|
-
|
|
847
|
-
type:
|
|
848
|
-
delta:
|
|
849
|
-
message:
|
|
850
|
-
tool_calls:
|
|
851
|
-
function:
|
|
852
|
-
arguments:
|
|
897
|
+
z4.object({
|
|
898
|
+
type: z4.literal("tool-call-delta"),
|
|
899
|
+
delta: z4.object({
|
|
900
|
+
message: z4.object({
|
|
901
|
+
tool_calls: z4.object({
|
|
902
|
+
function: z4.object({
|
|
903
|
+
arguments: z4.string()
|
|
853
904
|
})
|
|
854
905
|
})
|
|
855
906
|
})
|
|
856
907
|
})
|
|
857
908
|
}),
|
|
858
|
-
|
|
859
|
-
type:
|
|
909
|
+
z4.object({
|
|
910
|
+
type: z4.literal("tool-call-end")
|
|
860
911
|
})
|
|
861
912
|
])
|
|
862
913
|
)
|
|
@@ -874,17 +925,17 @@ import {
|
|
|
874
925
|
parseProviderOptions as parseProviderOptions3,
|
|
875
926
|
postJsonToApi as postJsonToApi2
|
|
876
927
|
} from "@ai-sdk/provider-utils";
|
|
877
|
-
import { z as
|
|
928
|
+
import { z as z6 } from "zod/v4";
|
|
878
929
|
|
|
879
930
|
// src/cohere-embedding-options.ts
|
|
880
931
|
import {
|
|
881
932
|
lazySchema as lazySchema4,
|
|
882
933
|
zodSchema as zodSchema4
|
|
883
934
|
} from "@ai-sdk/provider-utils";
|
|
884
|
-
import { z as
|
|
935
|
+
import { z as z5 } from "zod/v4";
|
|
885
936
|
var cohereEmbeddingModelOptions = lazySchema4(
|
|
886
937
|
() => zodSchema4(
|
|
887
|
-
|
|
938
|
+
z5.object({
|
|
888
939
|
/**
|
|
889
940
|
* Specifies the type of input passed to the model. Default is `search_query`.
|
|
890
941
|
*
|
|
@@ -893,7 +944,7 @@ var cohereEmbeddingModelOptions = lazySchema4(
|
|
|
893
944
|
* - "classification": Used for embeddings passed through a text classifier.
|
|
894
945
|
* - "clustering": Used for embeddings run through a clustering algorithm.
|
|
895
946
|
*/
|
|
896
|
-
inputType:
|
|
947
|
+
inputType: z5.enum([
|
|
897
948
|
"search_document",
|
|
898
949
|
"search_query",
|
|
899
950
|
"classification",
|
|
@@ -907,7 +958,7 @@ var cohereEmbeddingModelOptions = lazySchema4(
|
|
|
907
958
|
* - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
|
|
908
959
|
* - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
|
|
909
960
|
*/
|
|
910
|
-
truncate:
|
|
961
|
+
truncate: z5.enum(["NONE", "START", "END"]).optional(),
|
|
911
962
|
/**
|
|
912
963
|
* The number of dimensions of the output embedding.
|
|
913
964
|
* Only available for `embed-v4.0` and newer models.
|
|
@@ -915,13 +966,13 @@ var cohereEmbeddingModelOptions = lazySchema4(
|
|
|
915
966
|
* Embed v4.0 supports `256`, `512`, `1024`, and `1536` (default).
|
|
916
967
|
* Embed v5.0 Pro and Fast also support `768` and `2048` (default).
|
|
917
968
|
*/
|
|
918
|
-
outputDimension:
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
969
|
+
outputDimension: z5.union([
|
|
970
|
+
z5.literal(256),
|
|
971
|
+
z5.literal(512),
|
|
972
|
+
z5.literal(768),
|
|
973
|
+
z5.literal(1024),
|
|
974
|
+
z5.literal(1536),
|
|
975
|
+
z5.literal(2048)
|
|
925
976
|
]).optional()
|
|
926
977
|
})
|
|
927
978
|
)
|
|
@@ -994,13 +1045,13 @@ var CohereEmbeddingModel = class {
|
|
|
994
1045
|
};
|
|
995
1046
|
var cohereTextEmbeddingResponseSchema = lazySchema5(
|
|
996
1047
|
() => zodSchema5(
|
|
997
|
-
|
|
998
|
-
embeddings:
|
|
999
|
-
float:
|
|
1048
|
+
z6.object({
|
|
1049
|
+
embeddings: z6.object({
|
|
1050
|
+
float: z6.array(z6.array(z6.number()))
|
|
1000
1051
|
}),
|
|
1001
|
-
meta:
|
|
1002
|
-
billed_units:
|
|
1003
|
-
input_tokens:
|
|
1052
|
+
meta: z6.object({
|
|
1053
|
+
billed_units: z6.object({
|
|
1054
|
+
input_tokens: z6.number()
|
|
1004
1055
|
})
|
|
1005
1056
|
})
|
|
1006
1057
|
})
|
|
@@ -1017,18 +1068,18 @@ import {
|
|
|
1017
1068
|
|
|
1018
1069
|
// src/reranking/cohere-reranking-api.ts
|
|
1019
1070
|
import { lazySchema as lazySchema6, zodSchema as zodSchema6 } from "@ai-sdk/provider-utils";
|
|
1020
|
-
import { z as
|
|
1071
|
+
import { z as z7 } from "zod/v4";
|
|
1021
1072
|
var cohereRerankingResponseSchema = lazySchema6(
|
|
1022
1073
|
() => zodSchema6(
|
|
1023
|
-
|
|
1024
|
-
id:
|
|
1025
|
-
results:
|
|
1026
|
-
|
|
1027
|
-
index:
|
|
1028
|
-
relevance_score:
|
|
1074
|
+
z7.object({
|
|
1075
|
+
id: z7.string().nullish(),
|
|
1076
|
+
results: z7.array(
|
|
1077
|
+
z7.object({
|
|
1078
|
+
index: z7.number(),
|
|
1079
|
+
relevance_score: z7.number()
|
|
1029
1080
|
})
|
|
1030
1081
|
),
|
|
1031
|
-
meta:
|
|
1082
|
+
meta: z7.any()
|
|
1032
1083
|
})
|
|
1033
1084
|
)
|
|
1034
1085
|
);
|
|
@@ -1038,12 +1089,12 @@ import {
|
|
|
1038
1089
|
lazySchema as lazySchema7,
|
|
1039
1090
|
zodSchema as zodSchema7
|
|
1040
1091
|
} from "@ai-sdk/provider-utils";
|
|
1041
|
-
import { z as
|
|
1092
|
+
import { z as z8 } from "zod/v4";
|
|
1042
1093
|
var cohereRerankingModelOptionsSchema = lazySchema7(
|
|
1043
1094
|
() => zodSchema7(
|
|
1044
|
-
|
|
1045
|
-
maxTokensPerDoc:
|
|
1046
|
-
priority:
|
|
1095
|
+
z8.object({
|
|
1096
|
+
maxTokensPerDoc: z8.number().optional(),
|
|
1097
|
+
priority: z8.number().optional()
|
|
1047
1098
|
})
|
|
1048
1099
|
)
|
|
1049
1100
|
);
|
|
@@ -1119,7 +1170,7 @@ var CohereRerankingModel = class {
|
|
|
1119
1170
|
};
|
|
1120
1171
|
|
|
1121
1172
|
// src/version.ts
|
|
1122
|
-
var VERSION = true ? "3.0.
|
|
1173
|
+
var VERSION = true ? "3.0.76" : "0.0.0-test";
|
|
1123
1174
|
|
|
1124
1175
|
// src/cohere-provider.ts
|
|
1125
1176
|
function createCohere(options = {}) {
|