@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @ai-sdk/cohere
|
|
2
2
|
|
|
3
|
+
## 3.0.76
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 225154e: fix(cohere): tolerate partial citations and usage in non-streaming responses
|
|
8
|
+
|
|
9
|
+
Cohere citations and usage fields are optional in the API specification, but the
|
|
10
|
+
response schema required `start`, `end`, `text`, every source `document` with
|
|
11
|
+
`text` and `title`, and usage token counts. Responses with untitled documents
|
|
12
|
+
(documents passed without a filename), with tool-sourced citations, or without
|
|
13
|
+
token counts failed with an `AI_TypeValidationError` and discarded the whole
|
|
14
|
+
response.
|
|
15
|
+
|
|
16
|
+
These fields are now validated loosely: citation fields and source `type`/`id`
|
|
17
|
+
are nullish, `document` is a loose object with optional `id`/`text`/`title`, tool
|
|
18
|
+
sources are accepted, and `usage` plus its token counts are nullish. Document
|
|
19
|
+
citations without a title fall back to `"Document"`. Tool-only citations are
|
|
20
|
+
skipped because they have no document to point at; their data stays in the
|
|
21
|
+
response body.
|
|
22
|
+
|
|
23
|
+
`convertCohereUsage` no longer falls back to `billed_units`, which are a
|
|
24
|
+
different measure than `tokens` (e.g. 12 billed vs 507 input tokens in a single
|
|
25
|
+
response) and would go negative when cached tokens are subtracted. A response
|
|
26
|
+
without `tokens` now reports undefined token counts instead of unrelated
|
|
27
|
+
numbers. This usage conversion is shared with streaming.
|
|
28
|
+
|
|
29
|
+
- 024df7d: fix(cohere): read the response id from v2 chat responses
|
|
30
|
+
|
|
31
|
+
The non-streaming response schema read `generation_id`, which Cohere's v2 chat
|
|
32
|
+
response does not return. As a result, `generateText().response.id` was a locally
|
|
33
|
+
generated fallback instead of the provider's id, while `streamText` returned the
|
|
34
|
+
id from the `message-start` event. `doGenerate` now reads `id` and keeps
|
|
35
|
+
`generation_id` (the v1 field) only for compatibility with proxies and mocks that
|
|
36
|
+
still return it.
|
|
37
|
+
|
|
38
|
+
- 225154e: fix(cohere): emit `source` stream parts for citations
|
|
39
|
+
|
|
40
|
+
`streamText` did not produce sources for Cohere RAG responses because `citation-start` stream events were ignored, while `generateText` mapped `message.citations` to document sources. Streaming now maps each cited document to the same `source` part as the non-streaming path. Citations that only reference tool output are not emitted as sources, and `citation-start` events without citations are ignored.
|
|
41
|
+
|
|
3
42
|
## 3.0.75
|
|
4
43
|
|
|
5
44
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
|
32
32
|
|
|
33
33
|
// src/cohere-chat-language-model.ts
|
|
34
34
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
35
|
-
var
|
|
35
|
+
var import_v44 = require("zod/v4");
|
|
36
36
|
|
|
37
37
|
// src/cohere-chat-options.ts
|
|
38
38
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
@@ -68,13 +68,63 @@ var cohereImagePartProviderOptions = (0, import_provider_utils.lazySchema)(
|
|
|
68
68
|
)
|
|
69
69
|
);
|
|
70
70
|
|
|
71
|
+
// src/cohere-citations.ts
|
|
72
|
+
var import_v42 = require("zod/v4");
|
|
73
|
+
var cohereCitationSchema = import_v42.z.object({
|
|
74
|
+
start: import_v42.z.number().nullish(),
|
|
75
|
+
end: import_v42.z.number().nullish(),
|
|
76
|
+
text: import_v42.z.string().nullish(),
|
|
77
|
+
sources: import_v42.z.array(
|
|
78
|
+
import_v42.z.object({
|
|
79
|
+
type: import_v42.z.string().nullish(),
|
|
80
|
+
id: import_v42.z.string().nullish(),
|
|
81
|
+
// Documents are arbitrary objects; only the fields the provider maps
|
|
82
|
+
// are typed, everything else is passed through as provider metadata.
|
|
83
|
+
document: import_v42.z.looseObject({
|
|
84
|
+
id: import_v42.z.string().nullish(),
|
|
85
|
+
text: import_v42.z.string().nullish(),
|
|
86
|
+
title: import_v42.z.string().nullish()
|
|
87
|
+
}).nullish(),
|
|
88
|
+
tool_output: import_v42.z.looseObject({}).nullish()
|
|
89
|
+
})
|
|
90
|
+
).nullish(),
|
|
91
|
+
type: import_v42.z.string().nullish()
|
|
92
|
+
});
|
|
93
|
+
function mapCohereCitationToSource(citation, generateId2) {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
const document = (_b = (_a = citation.sources) == null ? void 0 : _a.find(
|
|
96
|
+
(source) => source.document != null
|
|
97
|
+
)) == null ? void 0 : _b.document;
|
|
98
|
+
if (document == null) {
|
|
99
|
+
return void 0;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
type: "source",
|
|
103
|
+
sourceType: "document",
|
|
104
|
+
id: generateId2(),
|
|
105
|
+
mediaType: "text/plain",
|
|
106
|
+
title: document.title || "Document",
|
|
107
|
+
providerMetadata: {
|
|
108
|
+
cohere: {
|
|
109
|
+
...citation.start != null && { start: citation.start },
|
|
110
|
+
...citation.end != null && { end: citation.end },
|
|
111
|
+
...citation.text != null && { text: citation.text },
|
|
112
|
+
...citation.sources != null && {
|
|
113
|
+
sources: citation.sources
|
|
114
|
+
},
|
|
115
|
+
...citation.type != null && { citationType: citation.type }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
71
121
|
// src/cohere-error.ts
|
|
72
122
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
73
|
-
var
|
|
123
|
+
var import_v43 = require("zod/v4");
|
|
74
124
|
var cohereErrorDataSchema = (0, import_provider_utils2.lazySchema)(
|
|
75
125
|
() => (0, import_provider_utils2.zodSchema)(
|
|
76
|
-
|
|
77
|
-
message:
|
|
126
|
+
import_v43.z.object({
|
|
127
|
+
message: import_v43.z.string()
|
|
78
128
|
})
|
|
79
129
|
)
|
|
80
130
|
);
|
|
@@ -142,6 +192,7 @@ function prepareTools({
|
|
|
142
192
|
|
|
143
193
|
// src/convert-cohere-usage.ts
|
|
144
194
|
function convertCohereUsage(usage) {
|
|
195
|
+
var _a, _b, _c, _d;
|
|
145
196
|
if (usage == null) {
|
|
146
197
|
return {
|
|
147
198
|
inputTokens: {
|
|
@@ -158,9 +209,8 @@ function convertCohereUsage(usage) {
|
|
|
158
209
|
raw: void 0
|
|
159
210
|
};
|
|
160
211
|
}
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
const outputTokens = tokens.output_tokens;
|
|
212
|
+
const inputTokens = (_b = (_a = usage.tokens) == null ? void 0 : _a.input_tokens) != null ? _b : void 0;
|
|
213
|
+
const outputTokens = (_d = (_c = usage.tokens) == null ? void 0 : _c.output_tokens) != null ? _d : void 0;
|
|
164
214
|
return {
|
|
165
215
|
inputTokens: {
|
|
166
216
|
total: inputTokens,
|
|
@@ -441,7 +491,7 @@ var CohereChatLanguageModel = class {
|
|
|
441
491
|
};
|
|
442
492
|
}
|
|
443
493
|
async doGenerate(options) {
|
|
444
|
-
var _a, _b, _c, _d, _e, _f
|
|
494
|
+
var _a, _b, _c, _d, _e, _f;
|
|
445
495
|
const { args, warnings } = await this.getArgs(options);
|
|
446
496
|
const {
|
|
447
497
|
responseHeaders,
|
|
@@ -470,24 +520,15 @@ var CohereChatLanguageModel = class {
|
|
|
470
520
|
}
|
|
471
521
|
}
|
|
472
522
|
for (const citation of (_b = response.message.citations) != null ? _b : []) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
cohere: {
|
|
481
|
-
start: citation.start,
|
|
482
|
-
end: citation.end,
|
|
483
|
-
text: citation.text,
|
|
484
|
-
sources: citation.sources,
|
|
485
|
-
...citation.type && { citationType: citation.type }
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
});
|
|
523
|
+
const source = mapCohereCitationToSource(
|
|
524
|
+
citation,
|
|
525
|
+
() => this.config.generateId()
|
|
526
|
+
);
|
|
527
|
+
if (source != null) {
|
|
528
|
+
content.push(source);
|
|
529
|
+
}
|
|
489
530
|
}
|
|
490
|
-
for (const toolCall of (
|
|
531
|
+
for (const toolCall of (_c = response.message.tool_calls) != null ? _c : []) {
|
|
491
532
|
content.push({
|
|
492
533
|
type: "tool-call",
|
|
493
534
|
toolCallId: toolCall.id,
|
|
@@ -501,13 +542,15 @@ var CohereChatLanguageModel = class {
|
|
|
501
542
|
content,
|
|
502
543
|
finishReason: {
|
|
503
544
|
unified: mapCohereFinishReason(response.finish_reason),
|
|
504
|
-
raw: (
|
|
545
|
+
raw: (_d = response.finish_reason) != null ? _d : void 0
|
|
505
546
|
},
|
|
506
547
|
usage: convertCohereUsage(response.usage),
|
|
507
548
|
request: { body: args },
|
|
508
549
|
response: {
|
|
509
550
|
// TODO timestamp, model id
|
|
510
|
-
|
|
551
|
+
// Cohere v2 returns `id`; `generation_id` is the v1 field, kept only
|
|
552
|
+
// for compatibility with proxies/mocks that still return it.
|
|
553
|
+
id: (_f = (_e = response.id) != null ? _e : response.generation_id) != null ? _f : void 0,
|
|
511
554
|
headers: responseHeaders,
|
|
512
555
|
body: rawResponse
|
|
513
556
|
},
|
|
@@ -534,6 +577,7 @@ var CohereChatLanguageModel = class {
|
|
|
534
577
|
let usage = void 0;
|
|
535
578
|
let pendingToolCall = null;
|
|
536
579
|
let isActiveReasoning = false;
|
|
580
|
+
const generateId2 = this.config.generateId;
|
|
537
581
|
return {
|
|
538
582
|
stream: response.pipeThrough(
|
|
539
583
|
new TransformStream({
|
|
@@ -541,7 +585,7 @@ var CohereChatLanguageModel = class {
|
|
|
541
585
|
controller.enqueue({ type: "stream-start", warnings });
|
|
542
586
|
},
|
|
543
587
|
async transform(chunk, controller) {
|
|
544
|
-
var _a, _b;
|
|
588
|
+
var _a, _b, _c, _d;
|
|
545
589
|
if (options.includeRawChunks) {
|
|
546
590
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
547
591
|
}
|
|
@@ -599,6 +643,22 @@ var CohereChatLanguageModel = class {
|
|
|
599
643
|
});
|
|
600
644
|
return;
|
|
601
645
|
}
|
|
646
|
+
case "citation-start": {
|
|
647
|
+
const citations = (_b = (_a = value.delta) == null ? void 0 : _a.message) == null ? void 0 : _b.citations;
|
|
648
|
+
if (citations == null) {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
for (const citation of Array.isArray(citations) ? citations : [citations]) {
|
|
652
|
+
const source = mapCohereCitationToSource(
|
|
653
|
+
citation,
|
|
654
|
+
generateId2
|
|
655
|
+
);
|
|
656
|
+
if (source != null) {
|
|
657
|
+
controller.enqueue(source);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
602
662
|
case "tool-call-start": {
|
|
603
663
|
const toolId = value.delta.message.tool_calls.id;
|
|
604
664
|
const toolName = value.delta.message.tool_calls.function.name;
|
|
@@ -647,7 +707,7 @@ var CohereChatLanguageModel = class {
|
|
|
647
707
|
toolName: pendingToolCall.name,
|
|
648
708
|
input: JSON.stringify(
|
|
649
709
|
await (0, import_provider_utils4.parseJSON)({
|
|
650
|
-
text: ((
|
|
710
|
+
text: ((_c = pendingToolCall.arguments) == null ? void 0 : _c.trim()) || "{}"
|
|
651
711
|
})
|
|
652
712
|
)
|
|
653
713
|
});
|
|
@@ -659,7 +719,7 @@ var CohereChatLanguageModel = class {
|
|
|
659
719
|
case "message-start": {
|
|
660
720
|
controller.enqueue({
|
|
661
721
|
type: "response-metadata",
|
|
662
|
-
id: (
|
|
722
|
+
id: (_d = value.id) != null ? _d : void 0
|
|
663
723
|
});
|
|
664
724
|
return;
|
|
665
725
|
}
|
|
@@ -689,148 +749,139 @@ var CohereChatLanguageModel = class {
|
|
|
689
749
|
};
|
|
690
750
|
}
|
|
691
751
|
};
|
|
692
|
-
var cohereUsageSchema = () =>
|
|
693
|
-
billed_units:
|
|
694
|
-
input_tokens:
|
|
695
|
-
output_tokens:
|
|
752
|
+
var cohereUsageSchema = () => import_v44.z.looseObject({
|
|
753
|
+
billed_units: import_v44.z.looseObject({
|
|
754
|
+
input_tokens: import_v44.z.number().nullish(),
|
|
755
|
+
output_tokens: import_v44.z.number().nullish()
|
|
756
|
+
}).nullish(),
|
|
757
|
+
tokens: import_v44.z.looseObject({
|
|
758
|
+
input_tokens: import_v44.z.number().nullish(),
|
|
759
|
+
output_tokens: import_v44.z.number().nullish()
|
|
696
760
|
}).nullish(),
|
|
697
|
-
|
|
698
|
-
input_tokens: import_v43.z.number(),
|
|
699
|
-
output_tokens: import_v43.z.number()
|
|
700
|
-
}),
|
|
701
|
-
cached_tokens: import_v43.z.number().nullish()
|
|
761
|
+
cached_tokens: import_v44.z.number().nullish()
|
|
702
762
|
});
|
|
703
763
|
var cohereChatResponseSchema = (0, import_provider_utils4.lazySchema)(
|
|
704
764
|
() => (0, import_provider_utils4.zodSchema)(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
765
|
+
import_v44.z.object({
|
|
766
|
+
id: import_v44.z.string().nullish(),
|
|
767
|
+
generation_id: import_v44.z.string().nullish(),
|
|
768
|
+
message: import_v44.z.object({
|
|
769
|
+
role: import_v44.z.string(),
|
|
770
|
+
content: import_v44.z.array(
|
|
771
|
+
import_v44.z.union([
|
|
772
|
+
import_v44.z.object({
|
|
773
|
+
type: import_v44.z.literal("text"),
|
|
774
|
+
text: import_v44.z.string()
|
|
714
775
|
}),
|
|
715
|
-
|
|
716
|
-
type:
|
|
717
|
-
thinking:
|
|
776
|
+
import_v44.z.object({
|
|
777
|
+
type: import_v44.z.literal("thinking"),
|
|
778
|
+
thinking: import_v44.z.string()
|
|
718
779
|
})
|
|
719
780
|
])
|
|
720
781
|
).nullish(),
|
|
721
|
-
tool_plan:
|
|
722
|
-
tool_calls:
|
|
723
|
-
|
|
724
|
-
id:
|
|
725
|
-
type:
|
|
726
|
-
function:
|
|
727
|
-
name:
|
|
728
|
-
arguments:
|
|
782
|
+
tool_plan: import_v44.z.string().nullish(),
|
|
783
|
+
tool_calls: import_v44.z.array(
|
|
784
|
+
import_v44.z.object({
|
|
785
|
+
id: import_v44.z.string(),
|
|
786
|
+
type: import_v44.z.literal("function"),
|
|
787
|
+
function: import_v44.z.object({
|
|
788
|
+
name: import_v44.z.string(),
|
|
789
|
+
arguments: import_v44.z.string()
|
|
729
790
|
})
|
|
730
791
|
})
|
|
731
792
|
).nullish(),
|
|
732
|
-
citations:
|
|
733
|
-
import_v43.z.object({
|
|
734
|
-
start: import_v43.z.number(),
|
|
735
|
-
end: import_v43.z.number(),
|
|
736
|
-
text: import_v43.z.string(),
|
|
737
|
-
sources: import_v43.z.array(
|
|
738
|
-
import_v43.z.object({
|
|
739
|
-
type: import_v43.z.string().optional(),
|
|
740
|
-
id: import_v43.z.string().optional(),
|
|
741
|
-
document: import_v43.z.object({
|
|
742
|
-
id: import_v43.z.string().optional(),
|
|
743
|
-
text: import_v43.z.string(),
|
|
744
|
-
title: import_v43.z.string()
|
|
745
|
-
})
|
|
746
|
-
})
|
|
747
|
-
),
|
|
748
|
-
type: import_v43.z.string().optional()
|
|
749
|
-
})
|
|
750
|
-
).nullish()
|
|
793
|
+
citations: import_v44.z.array(cohereCitationSchema).nullish()
|
|
751
794
|
}),
|
|
752
|
-
finish_reason:
|
|
753
|
-
usage: cohereUsageSchema()
|
|
795
|
+
finish_reason: import_v44.z.string(),
|
|
796
|
+
usage: cohereUsageSchema().nullish()
|
|
754
797
|
})
|
|
755
798
|
)
|
|
756
799
|
);
|
|
757
800
|
var cohereChatChunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
758
801
|
() => (0, import_provider_utils4.zodSchema)(
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
802
|
+
import_v44.z.discriminatedUnion("type", [
|
|
803
|
+
// `citation-start` events can arrive without citations, and a single
|
|
804
|
+
// citation may be sent instead of an array.
|
|
805
|
+
import_v44.z.object({
|
|
806
|
+
type: import_v44.z.literal("citation-start"),
|
|
807
|
+
index: import_v44.z.number().nullish(),
|
|
808
|
+
delta: import_v44.z.object({
|
|
809
|
+
message: import_v44.z.object({
|
|
810
|
+
citations: import_v44.z.union([cohereCitationSchema, import_v44.z.array(cohereCitationSchema)]).nullish()
|
|
811
|
+
}).nullish()
|
|
812
|
+
}).nullish()
|
|
762
813
|
}),
|
|
763
|
-
|
|
764
|
-
type:
|
|
814
|
+
import_v44.z.object({
|
|
815
|
+
type: import_v44.z.literal("citation-end")
|
|
765
816
|
}),
|
|
766
|
-
|
|
767
|
-
type:
|
|
768
|
-
index:
|
|
769
|
-
delta:
|
|
770
|
-
message:
|
|
771
|
-
content:
|
|
772
|
-
|
|
773
|
-
type:
|
|
774
|
-
text:
|
|
817
|
+
import_v44.z.object({
|
|
818
|
+
type: import_v44.z.literal("content-start"),
|
|
819
|
+
index: import_v44.z.number(),
|
|
820
|
+
delta: import_v44.z.object({
|
|
821
|
+
message: import_v44.z.object({
|
|
822
|
+
content: import_v44.z.union([
|
|
823
|
+
import_v44.z.object({
|
|
824
|
+
type: import_v44.z.literal("text"),
|
|
825
|
+
text: import_v44.z.string()
|
|
775
826
|
}),
|
|
776
|
-
|
|
777
|
-
type:
|
|
778
|
-
thinking:
|
|
827
|
+
import_v44.z.object({
|
|
828
|
+
type: import_v44.z.literal("thinking"),
|
|
829
|
+
thinking: import_v44.z.string()
|
|
779
830
|
})
|
|
780
831
|
])
|
|
781
832
|
})
|
|
782
833
|
})
|
|
783
834
|
}),
|
|
784
|
-
|
|
785
|
-
type:
|
|
786
|
-
index:
|
|
787
|
-
delta:
|
|
788
|
-
message:
|
|
789
|
-
content:
|
|
790
|
-
|
|
791
|
-
text:
|
|
835
|
+
import_v44.z.object({
|
|
836
|
+
type: import_v44.z.literal("content-delta"),
|
|
837
|
+
index: import_v44.z.number(),
|
|
838
|
+
delta: import_v44.z.object({
|
|
839
|
+
message: import_v44.z.object({
|
|
840
|
+
content: import_v44.z.union([
|
|
841
|
+
import_v44.z.object({
|
|
842
|
+
text: import_v44.z.string()
|
|
792
843
|
}),
|
|
793
|
-
|
|
794
|
-
thinking:
|
|
844
|
+
import_v44.z.object({
|
|
845
|
+
thinking: import_v44.z.string()
|
|
795
846
|
})
|
|
796
847
|
])
|
|
797
848
|
})
|
|
798
849
|
})
|
|
799
850
|
}),
|
|
800
|
-
|
|
801
|
-
type:
|
|
802
|
-
index:
|
|
851
|
+
import_v44.z.object({
|
|
852
|
+
type: import_v44.z.literal("content-end"),
|
|
853
|
+
index: import_v44.z.number()
|
|
803
854
|
}),
|
|
804
|
-
|
|
805
|
-
type:
|
|
806
|
-
id:
|
|
855
|
+
import_v44.z.object({
|
|
856
|
+
type: import_v44.z.literal("message-start"),
|
|
857
|
+
id: import_v44.z.string().nullish()
|
|
807
858
|
}),
|
|
808
|
-
|
|
809
|
-
type:
|
|
810
|
-
delta:
|
|
811
|
-
finish_reason:
|
|
859
|
+
import_v44.z.object({
|
|
860
|
+
type: import_v44.z.literal("message-end"),
|
|
861
|
+
delta: import_v44.z.object({
|
|
862
|
+
finish_reason: import_v44.z.string(),
|
|
812
863
|
usage: cohereUsageSchema()
|
|
813
864
|
})
|
|
814
865
|
}),
|
|
815
866
|
// https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
|
|
816
|
-
|
|
817
|
-
type:
|
|
818
|
-
delta:
|
|
819
|
-
message:
|
|
820
|
-
tool_plan:
|
|
867
|
+
import_v44.z.object({
|
|
868
|
+
type: import_v44.z.literal("tool-plan-delta"),
|
|
869
|
+
delta: import_v44.z.object({
|
|
870
|
+
message: import_v44.z.object({
|
|
871
|
+
tool_plan: import_v44.z.string()
|
|
821
872
|
})
|
|
822
873
|
})
|
|
823
874
|
}),
|
|
824
|
-
|
|
825
|
-
type:
|
|
826
|
-
delta:
|
|
827
|
-
message:
|
|
828
|
-
tool_calls:
|
|
829
|
-
id:
|
|
830
|
-
type:
|
|
831
|
-
function:
|
|
832
|
-
name:
|
|
833
|
-
arguments:
|
|
875
|
+
import_v44.z.object({
|
|
876
|
+
type: import_v44.z.literal("tool-call-start"),
|
|
877
|
+
delta: import_v44.z.object({
|
|
878
|
+
message: import_v44.z.object({
|
|
879
|
+
tool_calls: import_v44.z.object({
|
|
880
|
+
id: import_v44.z.string(),
|
|
881
|
+
type: import_v44.z.literal("function"),
|
|
882
|
+
function: import_v44.z.object({
|
|
883
|
+
name: import_v44.z.string(),
|
|
884
|
+
arguments: import_v44.z.string()
|
|
834
885
|
})
|
|
835
886
|
})
|
|
836
887
|
})
|
|
@@ -839,20 +890,20 @@ var cohereChatChunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
839
890
|
// A single tool call's `arguments` stream in chunks and must be accumulated
|
|
840
891
|
// in a string and so the full tool object info can only be parsed once we see
|
|
841
892
|
// `tool-call-end`.
|
|
842
|
-
|
|
843
|
-
type:
|
|
844
|
-
delta:
|
|
845
|
-
message:
|
|
846
|
-
tool_calls:
|
|
847
|
-
function:
|
|
848
|
-
arguments:
|
|
893
|
+
import_v44.z.object({
|
|
894
|
+
type: import_v44.z.literal("tool-call-delta"),
|
|
895
|
+
delta: import_v44.z.object({
|
|
896
|
+
message: import_v44.z.object({
|
|
897
|
+
tool_calls: import_v44.z.object({
|
|
898
|
+
function: import_v44.z.object({
|
|
899
|
+
arguments: import_v44.z.string()
|
|
849
900
|
})
|
|
850
901
|
})
|
|
851
902
|
})
|
|
852
903
|
})
|
|
853
904
|
}),
|
|
854
|
-
|
|
855
|
-
type:
|
|
905
|
+
import_v44.z.object({
|
|
906
|
+
type: import_v44.z.literal("tool-call-end")
|
|
856
907
|
})
|
|
857
908
|
])
|
|
858
909
|
)
|
|
@@ -861,14 +912,14 @@ var cohereChatChunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
|
861
912
|
// src/cohere-embedding-model.ts
|
|
862
913
|
var import_provider3 = require("@ai-sdk/provider");
|
|
863
914
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
864
|
-
var
|
|
915
|
+
var import_v46 = require("zod/v4");
|
|
865
916
|
|
|
866
917
|
// src/cohere-embedding-options.ts
|
|
867
918
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
868
|
-
var
|
|
919
|
+
var import_v45 = require("zod/v4");
|
|
869
920
|
var cohereEmbeddingModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
870
921
|
() => (0, import_provider_utils5.zodSchema)(
|
|
871
|
-
|
|
922
|
+
import_v45.z.object({
|
|
872
923
|
/**
|
|
873
924
|
* Specifies the type of input passed to the model. Default is `search_query`.
|
|
874
925
|
*
|
|
@@ -877,7 +928,7 @@ var cohereEmbeddingModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
877
928
|
* - "classification": Used for embeddings passed through a text classifier.
|
|
878
929
|
* - "clustering": Used for embeddings run through a clustering algorithm.
|
|
879
930
|
*/
|
|
880
|
-
inputType:
|
|
931
|
+
inputType: import_v45.z.enum([
|
|
881
932
|
"search_document",
|
|
882
933
|
"search_query",
|
|
883
934
|
"classification",
|
|
@@ -891,7 +942,7 @@ var cohereEmbeddingModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
891
942
|
* - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
|
|
892
943
|
* - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
|
|
893
944
|
*/
|
|
894
|
-
truncate:
|
|
945
|
+
truncate: import_v45.z.enum(["NONE", "START", "END"]).optional(),
|
|
895
946
|
/**
|
|
896
947
|
* The number of dimensions of the output embedding.
|
|
897
948
|
* Only available for `embed-v4.0` and newer models.
|
|
@@ -899,13 +950,13 @@ var cohereEmbeddingModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
899
950
|
* Embed v4.0 supports `256`, `512`, `1024`, and `1536` (default).
|
|
900
951
|
* Embed v5.0 Pro and Fast also support `768` and `2048` (default).
|
|
901
952
|
*/
|
|
902
|
-
outputDimension:
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
953
|
+
outputDimension: import_v45.z.union([
|
|
954
|
+
import_v45.z.literal(256),
|
|
955
|
+
import_v45.z.literal(512),
|
|
956
|
+
import_v45.z.literal(768),
|
|
957
|
+
import_v45.z.literal(1024),
|
|
958
|
+
import_v45.z.literal(1536),
|
|
959
|
+
import_v45.z.literal(2048)
|
|
909
960
|
]).optional()
|
|
910
961
|
})
|
|
911
962
|
)
|
|
@@ -978,13 +1029,13 @@ var CohereEmbeddingModel = class {
|
|
|
978
1029
|
};
|
|
979
1030
|
var cohereTextEmbeddingResponseSchema = (0, import_provider_utils6.lazySchema)(
|
|
980
1031
|
() => (0, import_provider_utils6.zodSchema)(
|
|
981
|
-
|
|
982
|
-
embeddings:
|
|
983
|
-
float:
|
|
1032
|
+
import_v46.z.object({
|
|
1033
|
+
embeddings: import_v46.z.object({
|
|
1034
|
+
float: import_v46.z.array(import_v46.z.array(import_v46.z.number()))
|
|
984
1035
|
}),
|
|
985
|
-
meta:
|
|
986
|
-
billed_units:
|
|
987
|
-
input_tokens:
|
|
1036
|
+
meta: import_v46.z.object({
|
|
1037
|
+
billed_units: import_v46.z.object({
|
|
1038
|
+
input_tokens: import_v46.z.number()
|
|
988
1039
|
})
|
|
989
1040
|
})
|
|
990
1041
|
})
|
|
@@ -996,30 +1047,30 @@ var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
|
996
1047
|
|
|
997
1048
|
// src/reranking/cohere-reranking-api.ts
|
|
998
1049
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
999
|
-
var
|
|
1050
|
+
var import_v47 = require("zod/v4");
|
|
1000
1051
|
var cohereRerankingResponseSchema = (0, import_provider_utils7.lazySchema)(
|
|
1001
1052
|
() => (0, import_provider_utils7.zodSchema)(
|
|
1002
|
-
|
|
1003
|
-
id:
|
|
1004
|
-
results:
|
|
1005
|
-
|
|
1006
|
-
index:
|
|
1007
|
-
relevance_score:
|
|
1053
|
+
import_v47.z.object({
|
|
1054
|
+
id: import_v47.z.string().nullish(),
|
|
1055
|
+
results: import_v47.z.array(
|
|
1056
|
+
import_v47.z.object({
|
|
1057
|
+
index: import_v47.z.number(),
|
|
1058
|
+
relevance_score: import_v47.z.number()
|
|
1008
1059
|
})
|
|
1009
1060
|
),
|
|
1010
|
-
meta:
|
|
1061
|
+
meta: import_v47.z.any()
|
|
1011
1062
|
})
|
|
1012
1063
|
)
|
|
1013
1064
|
);
|
|
1014
1065
|
|
|
1015
1066
|
// src/reranking/cohere-reranking-options.ts
|
|
1016
1067
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1017
|
-
var
|
|
1068
|
+
var import_v48 = require("zod/v4");
|
|
1018
1069
|
var cohereRerankingModelOptionsSchema = (0, import_provider_utils8.lazySchema)(
|
|
1019
1070
|
() => (0, import_provider_utils8.zodSchema)(
|
|
1020
|
-
|
|
1021
|
-
maxTokensPerDoc:
|
|
1022
|
-
priority:
|
|
1071
|
+
import_v48.z.object({
|
|
1072
|
+
maxTokensPerDoc: import_v48.z.number().optional(),
|
|
1073
|
+
priority: import_v48.z.number().optional()
|
|
1023
1074
|
})
|
|
1024
1075
|
)
|
|
1025
1076
|
);
|
|
@@ -1095,7 +1146,7 @@ var CohereRerankingModel = class {
|
|
|
1095
1146
|
};
|
|
1096
1147
|
|
|
1097
1148
|
// src/version.ts
|
|
1098
|
-
var VERSION = true ? "3.0.
|
|
1149
|
+
var VERSION = true ? "3.0.76" : "0.0.0-test";
|
|
1099
1150
|
|
|
1100
1151
|
// src/cohere-provider.ts
|
|
1101
1152
|
function createCohere(options = {}) {
|