@ai-sdk/cohere 3.0.74 → 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 +49 -0
- package/dist/index.js +236 -174
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +242 -175
- package/dist/index.mjs.map +1 -1
- package/docs/25-cohere.mdx +69 -0
- package/package.json +2 -2
- 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/src/convert-to-cohere-chat-prompt.ts +20 -3
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,
|
|
@@ -178,7 +228,23 @@ function convertCohereUsage(usage) {
|
|
|
178
228
|
import {
|
|
179
229
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
180
230
|
} from "@ai-sdk/provider";
|
|
181
|
-
import {
|
|
231
|
+
import {
|
|
232
|
+
secureJsonParse,
|
|
233
|
+
stringifyWithBigIntAndCycles,
|
|
234
|
+
convertToBase64,
|
|
235
|
+
parseProviderOptions
|
|
236
|
+
} from "@ai-sdk/provider-utils";
|
|
237
|
+
function serializeCohereToolCallArguments(input) {
|
|
238
|
+
if (typeof input === "string") {
|
|
239
|
+
try {
|
|
240
|
+
secureJsonParse(input);
|
|
241
|
+
return input;
|
|
242
|
+
} catch (e) {
|
|
243
|
+
return JSON.stringify(input);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return stringifyWithBigIntAndCycles(input);
|
|
247
|
+
}
|
|
182
248
|
async function convertToCohereChatPrompt(prompt) {
|
|
183
249
|
var _a, _b;
|
|
184
250
|
const messages = [];
|
|
@@ -271,7 +337,7 @@ async function convertToCohereChatPrompt(prompt) {
|
|
|
271
337
|
type: "function",
|
|
272
338
|
function: {
|
|
273
339
|
name: part.toolName,
|
|
274
|
-
arguments:
|
|
340
|
+
arguments: serializeCohereToolCallArguments(part.input)
|
|
275
341
|
}
|
|
276
342
|
});
|
|
277
343
|
break;
|
|
@@ -303,7 +369,7 @@ async function convertToCohereChatPrompt(prompt) {
|
|
|
303
369
|
case "content":
|
|
304
370
|
case "json":
|
|
305
371
|
case "error-json":
|
|
306
|
-
contentValue =
|
|
372
|
+
contentValue = stringifyWithBigIntAndCycles(output.value);
|
|
307
373
|
break;
|
|
308
374
|
}
|
|
309
375
|
return {
|
|
@@ -429,7 +495,7 @@ var CohereChatLanguageModel = class {
|
|
|
429
495
|
};
|
|
430
496
|
}
|
|
431
497
|
async doGenerate(options) {
|
|
432
|
-
var _a, _b, _c, _d, _e, _f
|
|
498
|
+
var _a, _b, _c, _d, _e, _f;
|
|
433
499
|
const { args, warnings } = await this.getArgs(options);
|
|
434
500
|
const {
|
|
435
501
|
responseHeaders,
|
|
@@ -458,24 +524,15 @@ var CohereChatLanguageModel = class {
|
|
|
458
524
|
}
|
|
459
525
|
}
|
|
460
526
|
for (const citation of (_b = response.message.citations) != null ? _b : []) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
cohere: {
|
|
469
|
-
start: citation.start,
|
|
470
|
-
end: citation.end,
|
|
471
|
-
text: citation.text,
|
|
472
|
-
sources: citation.sources,
|
|
473
|
-
...citation.type && { citationType: citation.type }
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
});
|
|
527
|
+
const source = mapCohereCitationToSource(
|
|
528
|
+
citation,
|
|
529
|
+
() => this.config.generateId()
|
|
530
|
+
);
|
|
531
|
+
if (source != null) {
|
|
532
|
+
content.push(source);
|
|
533
|
+
}
|
|
477
534
|
}
|
|
478
|
-
for (const toolCall of (
|
|
535
|
+
for (const toolCall of (_c = response.message.tool_calls) != null ? _c : []) {
|
|
479
536
|
content.push({
|
|
480
537
|
type: "tool-call",
|
|
481
538
|
toolCallId: toolCall.id,
|
|
@@ -489,13 +546,15 @@ var CohereChatLanguageModel = class {
|
|
|
489
546
|
content,
|
|
490
547
|
finishReason: {
|
|
491
548
|
unified: mapCohereFinishReason(response.finish_reason),
|
|
492
|
-
raw: (
|
|
549
|
+
raw: (_d = response.finish_reason) != null ? _d : void 0
|
|
493
550
|
},
|
|
494
551
|
usage: convertCohereUsage(response.usage),
|
|
495
552
|
request: { body: args },
|
|
496
553
|
response: {
|
|
497
554
|
// TODO timestamp, model id
|
|
498
|
-
|
|
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,
|
|
499
558
|
headers: responseHeaders,
|
|
500
559
|
body: rawResponse
|
|
501
560
|
},
|
|
@@ -522,6 +581,7 @@ var CohereChatLanguageModel = class {
|
|
|
522
581
|
let usage = void 0;
|
|
523
582
|
let pendingToolCall = null;
|
|
524
583
|
let isActiveReasoning = false;
|
|
584
|
+
const generateId2 = this.config.generateId;
|
|
525
585
|
return {
|
|
526
586
|
stream: response.pipeThrough(
|
|
527
587
|
new TransformStream({
|
|
@@ -529,7 +589,7 @@ var CohereChatLanguageModel = class {
|
|
|
529
589
|
controller.enqueue({ type: "stream-start", warnings });
|
|
530
590
|
},
|
|
531
591
|
async transform(chunk, controller) {
|
|
532
|
-
var _a, _b;
|
|
592
|
+
var _a, _b, _c, _d;
|
|
533
593
|
if (options.includeRawChunks) {
|
|
534
594
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
535
595
|
}
|
|
@@ -587,6 +647,22 @@ var CohereChatLanguageModel = class {
|
|
|
587
647
|
});
|
|
588
648
|
return;
|
|
589
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
|
+
}
|
|
590
666
|
case "tool-call-start": {
|
|
591
667
|
const toolId = value.delta.message.tool_calls.id;
|
|
592
668
|
const toolName = value.delta.message.tool_calls.function.name;
|
|
@@ -635,7 +711,7 @@ var CohereChatLanguageModel = class {
|
|
|
635
711
|
toolName: pendingToolCall.name,
|
|
636
712
|
input: JSON.stringify(
|
|
637
713
|
await parseJSON({
|
|
638
|
-
text: ((
|
|
714
|
+
text: ((_c = pendingToolCall.arguments) == null ? void 0 : _c.trim()) || "{}"
|
|
639
715
|
})
|
|
640
716
|
)
|
|
641
717
|
});
|
|
@@ -647,7 +723,7 @@ var CohereChatLanguageModel = class {
|
|
|
647
723
|
case "message-start": {
|
|
648
724
|
controller.enqueue({
|
|
649
725
|
type: "response-metadata",
|
|
650
|
-
id: (
|
|
726
|
+
id: (_d = value.id) != null ? _d : void 0
|
|
651
727
|
});
|
|
652
728
|
return;
|
|
653
729
|
}
|
|
@@ -677,148 +753,139 @@ var CohereChatLanguageModel = class {
|
|
|
677
753
|
};
|
|
678
754
|
}
|
|
679
755
|
};
|
|
680
|
-
var cohereUsageSchema = () =>
|
|
681
|
-
billed_units:
|
|
682
|
-
input_tokens:
|
|
683
|
-
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()
|
|
684
764
|
}).nullish(),
|
|
685
|
-
|
|
686
|
-
input_tokens: z3.number(),
|
|
687
|
-
output_tokens: z3.number()
|
|
688
|
-
}),
|
|
689
|
-
cached_tokens: z3.number().nullish()
|
|
765
|
+
cached_tokens: z4.number().nullish()
|
|
690
766
|
});
|
|
691
767
|
var cohereChatResponseSchema = lazySchema3(
|
|
692
768
|
() => zodSchema3(
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
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()
|
|
702
779
|
}),
|
|
703
|
-
|
|
704
|
-
type:
|
|
705
|
-
thinking:
|
|
780
|
+
z4.object({
|
|
781
|
+
type: z4.literal("thinking"),
|
|
782
|
+
thinking: z4.string()
|
|
706
783
|
})
|
|
707
784
|
])
|
|
708
785
|
).nullish(),
|
|
709
|
-
tool_plan:
|
|
710
|
-
tool_calls:
|
|
711
|
-
|
|
712
|
-
id:
|
|
713
|
-
type:
|
|
714
|
-
function:
|
|
715
|
-
name:
|
|
716
|
-
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()
|
|
717
794
|
})
|
|
718
795
|
})
|
|
719
796
|
).nullish(),
|
|
720
|
-
citations:
|
|
721
|
-
z3.object({
|
|
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()
|
|
737
|
-
})
|
|
738
|
-
).nullish()
|
|
797
|
+
citations: z4.array(cohereCitationSchema).nullish()
|
|
739
798
|
}),
|
|
740
|
-
finish_reason:
|
|
741
|
-
usage: cohereUsageSchema()
|
|
799
|
+
finish_reason: z4.string(),
|
|
800
|
+
usage: cohereUsageSchema().nullish()
|
|
742
801
|
})
|
|
743
802
|
)
|
|
744
803
|
);
|
|
745
804
|
var cohereChatChunkSchema = lazySchema3(
|
|
746
805
|
() => zodSchema3(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
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()
|
|
750
817
|
}),
|
|
751
|
-
|
|
752
|
-
type:
|
|
818
|
+
z4.object({
|
|
819
|
+
type: z4.literal("citation-end")
|
|
753
820
|
}),
|
|
754
|
-
|
|
755
|
-
type:
|
|
756
|
-
index:
|
|
757
|
-
delta:
|
|
758
|
-
message:
|
|
759
|
-
content:
|
|
760
|
-
|
|
761
|
-
type:
|
|
762
|
-
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()
|
|
763
830
|
}),
|
|
764
|
-
|
|
765
|
-
type:
|
|
766
|
-
thinking:
|
|
831
|
+
z4.object({
|
|
832
|
+
type: z4.literal("thinking"),
|
|
833
|
+
thinking: z4.string()
|
|
767
834
|
})
|
|
768
835
|
])
|
|
769
836
|
})
|
|
770
837
|
})
|
|
771
838
|
}),
|
|
772
|
-
|
|
773
|
-
type:
|
|
774
|
-
index:
|
|
775
|
-
delta:
|
|
776
|
-
message:
|
|
777
|
-
content:
|
|
778
|
-
|
|
779
|
-
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()
|
|
780
847
|
}),
|
|
781
|
-
|
|
782
|
-
thinking:
|
|
848
|
+
z4.object({
|
|
849
|
+
thinking: z4.string()
|
|
783
850
|
})
|
|
784
851
|
])
|
|
785
852
|
})
|
|
786
853
|
})
|
|
787
854
|
}),
|
|
788
|
-
|
|
789
|
-
type:
|
|
790
|
-
index:
|
|
855
|
+
z4.object({
|
|
856
|
+
type: z4.literal("content-end"),
|
|
857
|
+
index: z4.number()
|
|
791
858
|
}),
|
|
792
|
-
|
|
793
|
-
type:
|
|
794
|
-
id:
|
|
859
|
+
z4.object({
|
|
860
|
+
type: z4.literal("message-start"),
|
|
861
|
+
id: z4.string().nullish()
|
|
795
862
|
}),
|
|
796
|
-
|
|
797
|
-
type:
|
|
798
|
-
delta:
|
|
799
|
-
finish_reason:
|
|
863
|
+
z4.object({
|
|
864
|
+
type: z4.literal("message-end"),
|
|
865
|
+
delta: z4.object({
|
|
866
|
+
finish_reason: z4.string(),
|
|
800
867
|
usage: cohereUsageSchema()
|
|
801
868
|
})
|
|
802
869
|
}),
|
|
803
870
|
// https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
|
|
804
|
-
|
|
805
|
-
type:
|
|
806
|
-
delta:
|
|
807
|
-
message:
|
|
808
|
-
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()
|
|
809
876
|
})
|
|
810
877
|
})
|
|
811
878
|
}),
|
|
812
|
-
|
|
813
|
-
type:
|
|
814
|
-
delta:
|
|
815
|
-
message:
|
|
816
|
-
tool_calls:
|
|
817
|
-
id:
|
|
818
|
-
type:
|
|
819
|
-
function:
|
|
820
|
-
name:
|
|
821
|
-
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()
|
|
822
889
|
})
|
|
823
890
|
})
|
|
824
891
|
})
|
|
@@ -827,20 +894,20 @@ var cohereChatChunkSchema = lazySchema3(
|
|
|
827
894
|
// A single tool call's `arguments` stream in chunks and must be accumulated
|
|
828
895
|
// in a string and so the full tool object info can only be parsed once we see
|
|
829
896
|
// `tool-call-end`.
|
|
830
|
-
|
|
831
|
-
type:
|
|
832
|
-
delta:
|
|
833
|
-
message:
|
|
834
|
-
tool_calls:
|
|
835
|
-
function:
|
|
836
|
-
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()
|
|
837
904
|
})
|
|
838
905
|
})
|
|
839
906
|
})
|
|
840
907
|
})
|
|
841
908
|
}),
|
|
842
|
-
|
|
843
|
-
type:
|
|
909
|
+
z4.object({
|
|
910
|
+
type: z4.literal("tool-call-end")
|
|
844
911
|
})
|
|
845
912
|
])
|
|
846
913
|
)
|
|
@@ -858,17 +925,17 @@ import {
|
|
|
858
925
|
parseProviderOptions as parseProviderOptions3,
|
|
859
926
|
postJsonToApi as postJsonToApi2
|
|
860
927
|
} from "@ai-sdk/provider-utils";
|
|
861
|
-
import { z as
|
|
928
|
+
import { z as z6 } from "zod/v4";
|
|
862
929
|
|
|
863
930
|
// src/cohere-embedding-options.ts
|
|
864
931
|
import {
|
|
865
932
|
lazySchema as lazySchema4,
|
|
866
933
|
zodSchema as zodSchema4
|
|
867
934
|
} from "@ai-sdk/provider-utils";
|
|
868
|
-
import { z as
|
|
935
|
+
import { z as z5 } from "zod/v4";
|
|
869
936
|
var cohereEmbeddingModelOptions = lazySchema4(
|
|
870
937
|
() => zodSchema4(
|
|
871
|
-
|
|
938
|
+
z5.object({
|
|
872
939
|
/**
|
|
873
940
|
* Specifies the type of input passed to the model. Default is `search_query`.
|
|
874
941
|
*
|
|
@@ -877,7 +944,7 @@ var cohereEmbeddingModelOptions = lazySchema4(
|
|
|
877
944
|
* - "classification": Used for embeddings passed through a text classifier.
|
|
878
945
|
* - "clustering": Used for embeddings run through a clustering algorithm.
|
|
879
946
|
*/
|
|
880
|
-
inputType:
|
|
947
|
+
inputType: z5.enum([
|
|
881
948
|
"search_document",
|
|
882
949
|
"search_query",
|
|
883
950
|
"classification",
|
|
@@ -891,7 +958,7 @@ var cohereEmbeddingModelOptions = lazySchema4(
|
|
|
891
958
|
* - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
|
|
892
959
|
* - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
|
|
893
960
|
*/
|
|
894
|
-
truncate:
|
|
961
|
+
truncate: z5.enum(["NONE", "START", "END"]).optional(),
|
|
895
962
|
/**
|
|
896
963
|
* The number of dimensions of the output embedding.
|
|
897
964
|
* Only available for `embed-v4.0` and newer models.
|
|
@@ -899,13 +966,13 @@ var cohereEmbeddingModelOptions = lazySchema4(
|
|
|
899
966
|
* Embed v4.0 supports `256`, `512`, `1024`, and `1536` (default).
|
|
900
967
|
* Embed v5.0 Pro and Fast also support `768` and `2048` (default).
|
|
901
968
|
*/
|
|
902
|
-
outputDimension:
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
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)
|
|
909
976
|
]).optional()
|
|
910
977
|
})
|
|
911
978
|
)
|
|
@@ -978,13 +1045,13 @@ var CohereEmbeddingModel = class {
|
|
|
978
1045
|
};
|
|
979
1046
|
var cohereTextEmbeddingResponseSchema = lazySchema5(
|
|
980
1047
|
() => zodSchema5(
|
|
981
|
-
|
|
982
|
-
embeddings:
|
|
983
|
-
float:
|
|
1048
|
+
z6.object({
|
|
1049
|
+
embeddings: z6.object({
|
|
1050
|
+
float: z6.array(z6.array(z6.number()))
|
|
984
1051
|
}),
|
|
985
|
-
meta:
|
|
986
|
-
billed_units:
|
|
987
|
-
input_tokens:
|
|
1052
|
+
meta: z6.object({
|
|
1053
|
+
billed_units: z6.object({
|
|
1054
|
+
input_tokens: z6.number()
|
|
988
1055
|
})
|
|
989
1056
|
})
|
|
990
1057
|
})
|
|
@@ -1001,18 +1068,18 @@ import {
|
|
|
1001
1068
|
|
|
1002
1069
|
// src/reranking/cohere-reranking-api.ts
|
|
1003
1070
|
import { lazySchema as lazySchema6, zodSchema as zodSchema6 } from "@ai-sdk/provider-utils";
|
|
1004
|
-
import { z as
|
|
1071
|
+
import { z as z7 } from "zod/v4";
|
|
1005
1072
|
var cohereRerankingResponseSchema = lazySchema6(
|
|
1006
1073
|
() => zodSchema6(
|
|
1007
|
-
|
|
1008
|
-
id:
|
|
1009
|
-
results:
|
|
1010
|
-
|
|
1011
|
-
index:
|
|
1012
|
-
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()
|
|
1013
1080
|
})
|
|
1014
1081
|
),
|
|
1015
|
-
meta:
|
|
1082
|
+
meta: z7.any()
|
|
1016
1083
|
})
|
|
1017
1084
|
)
|
|
1018
1085
|
);
|
|
@@ -1022,12 +1089,12 @@ import {
|
|
|
1022
1089
|
lazySchema as lazySchema7,
|
|
1023
1090
|
zodSchema as zodSchema7
|
|
1024
1091
|
} from "@ai-sdk/provider-utils";
|
|
1025
|
-
import { z as
|
|
1092
|
+
import { z as z8 } from "zod/v4";
|
|
1026
1093
|
var cohereRerankingModelOptionsSchema = lazySchema7(
|
|
1027
1094
|
() => zodSchema7(
|
|
1028
|
-
|
|
1029
|
-
maxTokensPerDoc:
|
|
1030
|
-
priority:
|
|
1095
|
+
z8.object({
|
|
1096
|
+
maxTokensPerDoc: z8.number().optional(),
|
|
1097
|
+
priority: z8.number().optional()
|
|
1031
1098
|
})
|
|
1032
1099
|
)
|
|
1033
1100
|
);
|
|
@@ -1103,7 +1170,7 @@ var CohereRerankingModel = class {
|
|
|
1103
1170
|
};
|
|
1104
1171
|
|
|
1105
1172
|
// src/version.ts
|
|
1106
|
-
var VERSION = true ? "3.0.
|
|
1173
|
+
var VERSION = true ? "3.0.76" : "0.0.0-test";
|
|
1107
1174
|
|
|
1108
1175
|
// src/cohere-provider.ts
|
|
1109
1176
|
function createCohere(options = {}) {
|