@ai-sdk/cohere 4.0.0-beta.20 → 4.0.0-beta.21
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 +12 -0
- package/dist/index.js +219 -217
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/index.d.mts +0 -117
- package/dist/index.mjs +0 -1108
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,42 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
cohere: () => cohere,
|
|
25
|
-
createCohere: () => createCohere
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/cohere-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
generateId,
|
|
7
|
+
loadApiKey,
|
|
8
|
+
withoutTrailingSlash,
|
|
9
|
+
withUserAgentSuffix
|
|
10
|
+
} from "@ai-sdk/provider-utils";
|
|
32
11
|
|
|
33
12
|
// src/cohere-chat-language-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
import {
|
|
14
|
+
combineHeaders,
|
|
15
|
+
createEventSourceResponseHandler,
|
|
16
|
+
createJsonResponseHandler,
|
|
17
|
+
isCustomReasoning,
|
|
18
|
+
mapReasoningToProviderBudget,
|
|
19
|
+
parseProviderOptions,
|
|
20
|
+
postJsonToApi
|
|
21
|
+
} from "@ai-sdk/provider-utils";
|
|
22
|
+
import { z as z3 } from "zod/v4";
|
|
36
23
|
|
|
37
24
|
// src/cohere-chat-options.ts
|
|
38
|
-
|
|
39
|
-
var cohereLanguageModelOptions =
|
|
25
|
+
import { z } from "zod/v4";
|
|
26
|
+
var cohereLanguageModelOptions = z.object({
|
|
40
27
|
/**
|
|
41
28
|
* Configuration for reasoning features (optional)
|
|
42
29
|
*
|
|
@@ -45,25 +32,27 @@ var cohereLanguageModelOptions = import_v4.z.object({
|
|
|
45
32
|
*
|
|
46
33
|
* @see https://docs.cohere.com/reference/chat#request.body.thinking
|
|
47
34
|
*/
|
|
48
|
-
thinking:
|
|
49
|
-
type:
|
|
50
|
-
tokenBudget:
|
|
35
|
+
thinking: z.object({
|
|
36
|
+
type: z.enum(["enabled", "disabled"]).optional(),
|
|
37
|
+
tokenBudget: z.number().optional()
|
|
51
38
|
}).optional()
|
|
52
39
|
});
|
|
53
40
|
|
|
54
41
|
// src/cohere-error.ts
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var cohereErrorDataSchema =
|
|
58
|
-
message:
|
|
42
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
43
|
+
import { z as z2 } from "zod/v4";
|
|
44
|
+
var cohereErrorDataSchema = z2.object({
|
|
45
|
+
message: z2.string()
|
|
59
46
|
});
|
|
60
|
-
var cohereFailedResponseHandler =
|
|
47
|
+
var cohereFailedResponseHandler = createJsonErrorResponseHandler({
|
|
61
48
|
errorSchema: cohereErrorDataSchema,
|
|
62
49
|
errorToMessage: (data) => data.message
|
|
63
50
|
});
|
|
64
51
|
|
|
65
52
|
// src/cohere-prepare-tools.ts
|
|
66
|
-
|
|
53
|
+
import {
|
|
54
|
+
UnsupportedFunctionalityError
|
|
55
|
+
} from "@ai-sdk/provider";
|
|
67
56
|
function prepareTools({
|
|
68
57
|
tools,
|
|
69
58
|
toolChoice
|
|
@@ -112,7 +101,7 @@ function prepareTools({
|
|
|
112
101
|
};
|
|
113
102
|
default: {
|
|
114
103
|
const _exhaustiveCheck = type;
|
|
115
|
-
throw new
|
|
104
|
+
throw new UnsupportedFunctionalityError({
|
|
116
105
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
117
106
|
});
|
|
118
107
|
}
|
|
@@ -156,8 +145,10 @@ function convertCohereUsage(tokens) {
|
|
|
156
145
|
}
|
|
157
146
|
|
|
158
147
|
// src/convert-to-cohere-chat-prompt.ts
|
|
159
|
-
|
|
160
|
-
|
|
148
|
+
import {
|
|
149
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
150
|
+
} from "@ai-sdk/provider";
|
|
151
|
+
import { isProviderReference } from "@ai-sdk/provider-utils";
|
|
161
152
|
function convertToCohereChatPrompt(prompt) {
|
|
162
153
|
const messages = [];
|
|
163
154
|
const documents = [];
|
|
@@ -178,8 +169,8 @@ function convertToCohereChatPrompt(prompt) {
|
|
|
178
169
|
return part.text;
|
|
179
170
|
}
|
|
180
171
|
case "file": {
|
|
181
|
-
if (
|
|
182
|
-
throw new
|
|
172
|
+
if (isProviderReference(part.data)) {
|
|
173
|
+
throw new UnsupportedFunctionalityError2({
|
|
183
174
|
functionality: "file parts with provider references"
|
|
184
175
|
});
|
|
185
176
|
}
|
|
@@ -188,14 +179,14 @@ function convertToCohereChatPrompt(prompt) {
|
|
|
188
179
|
textContent = part.data;
|
|
189
180
|
} else if (part.data instanceof Uint8Array) {
|
|
190
181
|
if (!(((_a = part.mediaType) == null ? void 0 : _a.startsWith("text/")) || part.mediaType === "application/json")) {
|
|
191
|
-
throw new
|
|
182
|
+
throw new UnsupportedFunctionalityError2({
|
|
192
183
|
functionality: `document media type: ${part.mediaType}`,
|
|
193
184
|
message: `Media type '${part.mediaType}' is not supported. Supported media types are: text/* and application/json.`
|
|
194
185
|
});
|
|
195
186
|
}
|
|
196
187
|
textContent = new TextDecoder().decode(part.data);
|
|
197
188
|
} else {
|
|
198
|
-
throw new
|
|
189
|
+
throw new UnsupportedFunctionalityError2({
|
|
199
190
|
functionality: "File URL data",
|
|
200
191
|
message: "URLs should be downloaded by the AI SDK and not reach this point. This indicates a configuration issue."
|
|
201
192
|
});
|
|
@@ -329,7 +320,7 @@ var CohereChatLanguageModel = class {
|
|
|
329
320
|
}) {
|
|
330
321
|
var _a;
|
|
331
322
|
const warnings = [];
|
|
332
|
-
const cohereOptions = (_a = await
|
|
323
|
+
const cohereOptions = (_a = await parseProviderOptions({
|
|
333
324
|
provider: "cohere",
|
|
334
325
|
providerOptions,
|
|
335
326
|
schema: cohereLanguageModelOptions
|
|
@@ -384,12 +375,12 @@ var CohereChatLanguageModel = class {
|
|
|
384
375
|
responseHeaders,
|
|
385
376
|
value: response,
|
|
386
377
|
rawValue: rawResponse
|
|
387
|
-
} = await
|
|
378
|
+
} = await postJsonToApi({
|
|
388
379
|
url: `${this.config.baseURL}/chat`,
|
|
389
|
-
headers:
|
|
380
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
390
381
|
body: args,
|
|
391
382
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
392
|
-
successfulResponseHandler:
|
|
383
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
393
384
|
cohereChatResponseSchema
|
|
394
385
|
),
|
|
395
386
|
abortSignal: options.abortSignal,
|
|
@@ -453,12 +444,12 @@ var CohereChatLanguageModel = class {
|
|
|
453
444
|
}
|
|
454
445
|
async doStream(options) {
|
|
455
446
|
const { args, warnings } = await this.getArgs(options);
|
|
456
|
-
const { responseHeaders, value: response } = await
|
|
447
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
457
448
|
url: `${this.config.baseURL}/chat`,
|
|
458
|
-
headers:
|
|
449
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
459
450
|
body: { ...args, stream: true },
|
|
460
451
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
461
|
-
successfulResponseHandler:
|
|
452
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
462
453
|
cohereChatChunkSchema
|
|
463
454
|
),
|
|
464
455
|
abortSignal: options.abortSignal,
|
|
@@ -639,13 +630,13 @@ function resolveCohereThinking({
|
|
|
639
630
|
}
|
|
640
631
|
};
|
|
641
632
|
}
|
|
642
|
-
if (!
|
|
633
|
+
if (!isCustomReasoning(reasoning)) {
|
|
643
634
|
return {};
|
|
644
635
|
}
|
|
645
636
|
if (reasoning === "none") {
|
|
646
637
|
return { thinking: { type: "disabled" } };
|
|
647
638
|
}
|
|
648
|
-
const tokenBudget =
|
|
639
|
+
const tokenBudget = mapReasoningToProviderBudget({
|
|
649
640
|
reasoning,
|
|
650
641
|
maxOutputTokens: 32768,
|
|
651
642
|
maxReasoningBudget: 32768,
|
|
@@ -656,145 +647,145 @@ function resolveCohereThinking({
|
|
|
656
647
|
}
|
|
657
648
|
return { thinking: { type: "enabled", token_budget: tokenBudget } };
|
|
658
649
|
}
|
|
659
|
-
var cohereChatResponseSchema =
|
|
660
|
-
generation_id:
|
|
661
|
-
message:
|
|
662
|
-
role:
|
|
663
|
-
content:
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
type:
|
|
667
|
-
text:
|
|
650
|
+
var cohereChatResponseSchema = z3.object({
|
|
651
|
+
generation_id: z3.string().nullish(),
|
|
652
|
+
message: z3.object({
|
|
653
|
+
role: z3.string(),
|
|
654
|
+
content: z3.array(
|
|
655
|
+
z3.union([
|
|
656
|
+
z3.object({
|
|
657
|
+
type: z3.literal("text"),
|
|
658
|
+
text: z3.string()
|
|
668
659
|
}),
|
|
669
|
-
|
|
670
|
-
type:
|
|
671
|
-
thinking:
|
|
660
|
+
z3.object({
|
|
661
|
+
type: z3.literal("thinking"),
|
|
662
|
+
thinking: z3.string()
|
|
672
663
|
})
|
|
673
664
|
])
|
|
674
665
|
).nullish(),
|
|
675
|
-
tool_plan:
|
|
676
|
-
tool_calls:
|
|
677
|
-
|
|
678
|
-
id:
|
|
679
|
-
type:
|
|
680
|
-
function:
|
|
681
|
-
name:
|
|
682
|
-
arguments:
|
|
666
|
+
tool_plan: z3.string().nullish(),
|
|
667
|
+
tool_calls: z3.array(
|
|
668
|
+
z3.object({
|
|
669
|
+
id: z3.string(),
|
|
670
|
+
type: z3.literal("function"),
|
|
671
|
+
function: z3.object({
|
|
672
|
+
name: z3.string(),
|
|
673
|
+
arguments: z3.string()
|
|
683
674
|
})
|
|
684
675
|
})
|
|
685
676
|
).nullish(),
|
|
686
|
-
citations:
|
|
687
|
-
|
|
688
|
-
start:
|
|
689
|
-
end:
|
|
690
|
-
text:
|
|
691
|
-
sources:
|
|
692
|
-
|
|
693
|
-
type:
|
|
694
|
-
id:
|
|
695
|
-
document:
|
|
696
|
-
id:
|
|
697
|
-
text:
|
|
698
|
-
title:
|
|
677
|
+
citations: z3.array(
|
|
678
|
+
z3.object({
|
|
679
|
+
start: z3.number(),
|
|
680
|
+
end: z3.number(),
|
|
681
|
+
text: z3.string(),
|
|
682
|
+
sources: z3.array(
|
|
683
|
+
z3.object({
|
|
684
|
+
type: z3.string().optional(),
|
|
685
|
+
id: z3.string().optional(),
|
|
686
|
+
document: z3.object({
|
|
687
|
+
id: z3.string().optional(),
|
|
688
|
+
text: z3.string(),
|
|
689
|
+
title: z3.string()
|
|
699
690
|
})
|
|
700
691
|
})
|
|
701
692
|
),
|
|
702
|
-
type:
|
|
693
|
+
type: z3.string().optional()
|
|
703
694
|
})
|
|
704
695
|
).nullish()
|
|
705
696
|
}),
|
|
706
|
-
finish_reason:
|
|
707
|
-
usage:
|
|
708
|
-
billed_units:
|
|
709
|
-
input_tokens:
|
|
710
|
-
output_tokens:
|
|
697
|
+
finish_reason: z3.string(),
|
|
698
|
+
usage: z3.object({
|
|
699
|
+
billed_units: z3.object({
|
|
700
|
+
input_tokens: z3.number(),
|
|
701
|
+
output_tokens: z3.number()
|
|
711
702
|
}),
|
|
712
|
-
tokens:
|
|
713
|
-
input_tokens:
|
|
714
|
-
output_tokens:
|
|
703
|
+
tokens: z3.object({
|
|
704
|
+
input_tokens: z3.number(),
|
|
705
|
+
output_tokens: z3.number()
|
|
715
706
|
})
|
|
716
707
|
})
|
|
717
708
|
});
|
|
718
|
-
var cohereChatChunkSchema =
|
|
719
|
-
|
|
720
|
-
type:
|
|
709
|
+
var cohereChatChunkSchema = z3.discriminatedUnion("type", [
|
|
710
|
+
z3.object({
|
|
711
|
+
type: z3.literal("citation-start")
|
|
721
712
|
}),
|
|
722
|
-
|
|
723
|
-
type:
|
|
713
|
+
z3.object({
|
|
714
|
+
type: z3.literal("citation-end")
|
|
724
715
|
}),
|
|
725
|
-
|
|
726
|
-
type:
|
|
727
|
-
index:
|
|
728
|
-
delta:
|
|
729
|
-
message:
|
|
730
|
-
content:
|
|
731
|
-
|
|
732
|
-
type:
|
|
733
|
-
text:
|
|
716
|
+
z3.object({
|
|
717
|
+
type: z3.literal("content-start"),
|
|
718
|
+
index: z3.number(),
|
|
719
|
+
delta: z3.object({
|
|
720
|
+
message: z3.object({
|
|
721
|
+
content: z3.union([
|
|
722
|
+
z3.object({
|
|
723
|
+
type: z3.literal("text"),
|
|
724
|
+
text: z3.string()
|
|
734
725
|
}),
|
|
735
|
-
|
|
736
|
-
type:
|
|
737
|
-
thinking:
|
|
726
|
+
z3.object({
|
|
727
|
+
type: z3.literal("thinking"),
|
|
728
|
+
thinking: z3.string()
|
|
738
729
|
})
|
|
739
730
|
])
|
|
740
731
|
})
|
|
741
732
|
})
|
|
742
733
|
}),
|
|
743
|
-
|
|
744
|
-
type:
|
|
745
|
-
index:
|
|
746
|
-
delta:
|
|
747
|
-
message:
|
|
748
|
-
content:
|
|
749
|
-
|
|
750
|
-
text:
|
|
734
|
+
z3.object({
|
|
735
|
+
type: z3.literal("content-delta"),
|
|
736
|
+
index: z3.number(),
|
|
737
|
+
delta: z3.object({
|
|
738
|
+
message: z3.object({
|
|
739
|
+
content: z3.union([
|
|
740
|
+
z3.object({
|
|
741
|
+
text: z3.string()
|
|
751
742
|
}),
|
|
752
|
-
|
|
753
|
-
thinking:
|
|
743
|
+
z3.object({
|
|
744
|
+
thinking: z3.string()
|
|
754
745
|
})
|
|
755
746
|
])
|
|
756
747
|
})
|
|
757
748
|
})
|
|
758
749
|
}),
|
|
759
|
-
|
|
760
|
-
type:
|
|
761
|
-
index:
|
|
750
|
+
z3.object({
|
|
751
|
+
type: z3.literal("content-end"),
|
|
752
|
+
index: z3.number()
|
|
762
753
|
}),
|
|
763
|
-
|
|
764
|
-
type:
|
|
765
|
-
id:
|
|
754
|
+
z3.object({
|
|
755
|
+
type: z3.literal("message-start"),
|
|
756
|
+
id: z3.string().nullish()
|
|
766
757
|
}),
|
|
767
|
-
|
|
768
|
-
type:
|
|
769
|
-
delta:
|
|
770
|
-
finish_reason:
|
|
771
|
-
usage:
|
|
772
|
-
tokens:
|
|
773
|
-
input_tokens:
|
|
774
|
-
output_tokens:
|
|
758
|
+
z3.object({
|
|
759
|
+
type: z3.literal("message-end"),
|
|
760
|
+
delta: z3.object({
|
|
761
|
+
finish_reason: z3.string(),
|
|
762
|
+
usage: z3.object({
|
|
763
|
+
tokens: z3.object({
|
|
764
|
+
input_tokens: z3.number(),
|
|
765
|
+
output_tokens: z3.number()
|
|
775
766
|
})
|
|
776
767
|
})
|
|
777
768
|
})
|
|
778
769
|
}),
|
|
779
770
|
// https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
|
|
780
|
-
|
|
781
|
-
type:
|
|
782
|
-
delta:
|
|
783
|
-
message:
|
|
784
|
-
tool_plan:
|
|
771
|
+
z3.object({
|
|
772
|
+
type: z3.literal("tool-plan-delta"),
|
|
773
|
+
delta: z3.object({
|
|
774
|
+
message: z3.object({
|
|
775
|
+
tool_plan: z3.string()
|
|
785
776
|
})
|
|
786
777
|
})
|
|
787
778
|
}),
|
|
788
|
-
|
|
789
|
-
type:
|
|
790
|
-
delta:
|
|
791
|
-
message:
|
|
792
|
-
tool_calls:
|
|
793
|
-
id:
|
|
794
|
-
type:
|
|
795
|
-
function:
|
|
796
|
-
name:
|
|
797
|
-
arguments:
|
|
779
|
+
z3.object({
|
|
780
|
+
type: z3.literal("tool-call-start"),
|
|
781
|
+
delta: z3.object({
|
|
782
|
+
message: z3.object({
|
|
783
|
+
tool_calls: z3.object({
|
|
784
|
+
id: z3.string(),
|
|
785
|
+
type: z3.literal("function"),
|
|
786
|
+
function: z3.object({
|
|
787
|
+
name: z3.string(),
|
|
788
|
+
arguments: z3.string()
|
|
798
789
|
})
|
|
799
790
|
})
|
|
800
791
|
})
|
|
@@ -803,31 +794,38 @@ var cohereChatChunkSchema = import_v43.z.discriminatedUnion("type", [
|
|
|
803
794
|
// A single tool call's `arguments` stream in chunks and must be accumulated
|
|
804
795
|
// in a string and so the full tool object info can only be parsed once we see
|
|
805
796
|
// `tool-call-end`.
|
|
806
|
-
|
|
807
|
-
type:
|
|
808
|
-
delta:
|
|
809
|
-
message:
|
|
810
|
-
tool_calls:
|
|
811
|
-
function:
|
|
812
|
-
arguments:
|
|
797
|
+
z3.object({
|
|
798
|
+
type: z3.literal("tool-call-delta"),
|
|
799
|
+
delta: z3.object({
|
|
800
|
+
message: z3.object({
|
|
801
|
+
tool_calls: z3.object({
|
|
802
|
+
function: z3.object({
|
|
803
|
+
arguments: z3.string()
|
|
813
804
|
})
|
|
814
805
|
})
|
|
815
806
|
})
|
|
816
807
|
})
|
|
817
808
|
}),
|
|
818
|
-
|
|
819
|
-
type:
|
|
809
|
+
z3.object({
|
|
810
|
+
type: z3.literal("tool-call-end")
|
|
820
811
|
})
|
|
821
812
|
]);
|
|
822
813
|
|
|
823
814
|
// src/cohere-embedding-model.ts
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
815
|
+
import {
|
|
816
|
+
TooManyEmbeddingValuesForCallError
|
|
817
|
+
} from "@ai-sdk/provider";
|
|
818
|
+
import {
|
|
819
|
+
combineHeaders as combineHeaders2,
|
|
820
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
821
|
+
parseProviderOptions as parseProviderOptions2,
|
|
822
|
+
postJsonToApi as postJsonToApi2
|
|
823
|
+
} from "@ai-sdk/provider-utils";
|
|
824
|
+
import { z as z5 } from "zod/v4";
|
|
827
825
|
|
|
828
826
|
// src/cohere-embedding-options.ts
|
|
829
|
-
|
|
830
|
-
var cohereEmbeddingModelOptions =
|
|
827
|
+
import { z as z4 } from "zod/v4";
|
|
828
|
+
var cohereEmbeddingModelOptions = z4.object({
|
|
831
829
|
/**
|
|
832
830
|
* Specifies the type of input passed to the model. Default is `search_query`.
|
|
833
831
|
*
|
|
@@ -836,7 +834,7 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
|
|
|
836
834
|
* - "classification": Used for embeddings passed through a text classifier.
|
|
837
835
|
* - "clustering": Used for embeddings run through a clustering algorithm.
|
|
838
836
|
*/
|
|
839
|
-
inputType:
|
|
837
|
+
inputType: z4.enum(["search_document", "search_query", "classification", "clustering"]).optional(),
|
|
840
838
|
/**
|
|
841
839
|
* Specifies how the API will handle inputs longer than the maximum token length.
|
|
842
840
|
* Default is `END`.
|
|
@@ -845,7 +843,7 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
|
|
|
845
843
|
* - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
|
|
846
844
|
* - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
|
|
847
845
|
*/
|
|
848
|
-
truncate:
|
|
846
|
+
truncate: z4.enum(["NONE", "START", "END"]).optional(),
|
|
849
847
|
/**
|
|
850
848
|
* The number of dimensions of the output embedding.
|
|
851
849
|
* Only available for `embed-v4.0` and newer models.
|
|
@@ -853,7 +851,7 @@ var cohereEmbeddingModelOptions = import_v44.z.object({
|
|
|
853
851
|
* Possible values are `256`, `512`, `1024`, and `1536`.
|
|
854
852
|
* The default is `1536`.
|
|
855
853
|
*/
|
|
856
|
-
outputDimension:
|
|
854
|
+
outputDimension: z4.union([z4.literal(256), z4.literal(512), z4.literal(1024), z4.literal(1536)]).optional()
|
|
857
855
|
});
|
|
858
856
|
|
|
859
857
|
// src/cohere-embedding-model.ts
|
|
@@ -875,13 +873,13 @@ var CohereEmbeddingModel = class {
|
|
|
875
873
|
providerOptions
|
|
876
874
|
}) {
|
|
877
875
|
var _a;
|
|
878
|
-
const embeddingOptions = await (
|
|
876
|
+
const embeddingOptions = await parseProviderOptions2({
|
|
879
877
|
provider: "cohere",
|
|
880
878
|
providerOptions,
|
|
881
879
|
schema: cohereEmbeddingModelOptions
|
|
882
880
|
});
|
|
883
881
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
884
|
-
throw new
|
|
882
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
885
883
|
provider: this.provider,
|
|
886
884
|
modelId: this.modelId,
|
|
887
885
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -892,9 +890,9 @@ var CohereEmbeddingModel = class {
|
|
|
892
890
|
responseHeaders,
|
|
893
891
|
value: response,
|
|
894
892
|
rawValue
|
|
895
|
-
} = await (
|
|
893
|
+
} = await postJsonToApi2({
|
|
896
894
|
url: `${this.config.baseURL}/embed`,
|
|
897
|
-
headers: (
|
|
895
|
+
headers: combineHeaders2(this.config.headers(), headers),
|
|
898
896
|
body: {
|
|
899
897
|
model: this.modelId,
|
|
900
898
|
// The AI SDK only supports 'float' embeddings. Note that the Cohere API
|
|
@@ -907,7 +905,7 @@ var CohereEmbeddingModel = class {
|
|
|
907
905
|
output_dimension: embeddingOptions == null ? void 0 : embeddingOptions.outputDimension
|
|
908
906
|
},
|
|
909
907
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
910
|
-
successfulResponseHandler: (
|
|
908
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
911
909
|
cohereTextEmbeddingResponseSchema
|
|
912
910
|
),
|
|
913
911
|
abortSignal,
|
|
@@ -921,46 +919,51 @@ var CohereEmbeddingModel = class {
|
|
|
921
919
|
};
|
|
922
920
|
}
|
|
923
921
|
};
|
|
924
|
-
var cohereTextEmbeddingResponseSchema =
|
|
925
|
-
embeddings:
|
|
926
|
-
float:
|
|
922
|
+
var cohereTextEmbeddingResponseSchema = z5.object({
|
|
923
|
+
embeddings: z5.object({
|
|
924
|
+
float: z5.array(z5.array(z5.number()))
|
|
927
925
|
}),
|
|
928
|
-
meta:
|
|
929
|
-
billed_units:
|
|
930
|
-
input_tokens:
|
|
926
|
+
meta: z5.object({
|
|
927
|
+
billed_units: z5.object({
|
|
928
|
+
input_tokens: z5.number()
|
|
931
929
|
})
|
|
932
930
|
})
|
|
933
931
|
});
|
|
934
932
|
|
|
935
933
|
// src/reranking/cohere-reranking-model.ts
|
|
936
|
-
|
|
934
|
+
import {
|
|
935
|
+
combineHeaders as combineHeaders3,
|
|
936
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
937
|
+
parseProviderOptions as parseProviderOptions3,
|
|
938
|
+
postJsonToApi as postJsonToApi3
|
|
939
|
+
} from "@ai-sdk/provider-utils";
|
|
937
940
|
|
|
938
941
|
// src/reranking/cohere-reranking-api.ts
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
var cohereRerankingResponseSchema =
|
|
942
|
-
() =>
|
|
943
|
-
|
|
944
|
-
id:
|
|
945
|
-
results:
|
|
946
|
-
|
|
947
|
-
index:
|
|
948
|
-
relevance_score:
|
|
942
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
943
|
+
import { z as z6 } from "zod/v4";
|
|
944
|
+
var cohereRerankingResponseSchema = lazySchema(
|
|
945
|
+
() => zodSchema(
|
|
946
|
+
z6.object({
|
|
947
|
+
id: z6.string().nullish(),
|
|
948
|
+
results: z6.array(
|
|
949
|
+
z6.object({
|
|
950
|
+
index: z6.number(),
|
|
951
|
+
relevance_score: z6.number()
|
|
949
952
|
})
|
|
950
953
|
),
|
|
951
|
-
meta:
|
|
954
|
+
meta: z6.any()
|
|
952
955
|
})
|
|
953
956
|
)
|
|
954
957
|
);
|
|
955
958
|
|
|
956
959
|
// src/reranking/cohere-reranking-options.ts
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
var cohereRerankingModelOptionsSchema = (
|
|
960
|
-
() => (
|
|
961
|
-
|
|
962
|
-
maxTokensPerDoc:
|
|
963
|
-
priority:
|
|
960
|
+
import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
|
|
961
|
+
import { z as z7 } from "zod/v4";
|
|
962
|
+
var cohereRerankingModelOptionsSchema = lazySchema2(
|
|
963
|
+
() => zodSchema2(
|
|
964
|
+
z7.object({
|
|
965
|
+
maxTokensPerDoc: z7.number().optional(),
|
|
966
|
+
priority: z7.number().optional()
|
|
964
967
|
})
|
|
965
968
|
)
|
|
966
969
|
);
|
|
@@ -985,7 +988,7 @@ var CohereRerankingModel = class {
|
|
|
985
988
|
providerOptions
|
|
986
989
|
}) {
|
|
987
990
|
var _a;
|
|
988
|
-
const rerankingOptions = await (
|
|
991
|
+
const rerankingOptions = await parseProviderOptions3({
|
|
989
992
|
provider: "cohere",
|
|
990
993
|
providerOptions,
|
|
991
994
|
schema: cohereRerankingModelOptionsSchema
|
|
@@ -1002,9 +1005,9 @@ var CohereRerankingModel = class {
|
|
|
1002
1005
|
responseHeaders,
|
|
1003
1006
|
value: response,
|
|
1004
1007
|
rawValue
|
|
1005
|
-
} = await (
|
|
1008
|
+
} = await postJsonToApi3({
|
|
1006
1009
|
url: `${this.config.baseURL}/rerank`,
|
|
1007
|
-
headers: (
|
|
1010
|
+
headers: combineHeaders3(this.config.headers(), headers),
|
|
1008
1011
|
body: {
|
|
1009
1012
|
model: this.modelId,
|
|
1010
1013
|
query,
|
|
@@ -1014,7 +1017,7 @@ var CohereRerankingModel = class {
|
|
|
1014
1017
|
priority: rerankingOptions == null ? void 0 : rerankingOptions.priority
|
|
1015
1018
|
},
|
|
1016
1019
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
1017
|
-
successfulResponseHandler: (
|
|
1020
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
1018
1021
|
cohereRerankingResponseSchema
|
|
1019
1022
|
),
|
|
1020
1023
|
abortSignal,
|
|
@@ -1036,15 +1039,15 @@ var CohereRerankingModel = class {
|
|
|
1036
1039
|
};
|
|
1037
1040
|
|
|
1038
1041
|
// src/version.ts
|
|
1039
|
-
var VERSION = true ? "4.0.0-beta.
|
|
1042
|
+
var VERSION = true ? "4.0.0-beta.21" : "0.0.0-test";
|
|
1040
1043
|
|
|
1041
1044
|
// src/cohere-provider.ts
|
|
1042
1045
|
function createCohere(options = {}) {
|
|
1043
1046
|
var _a;
|
|
1044
|
-
const baseURL = (_a =
|
|
1045
|
-
const getHeaders = () =>
|
|
1047
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.cohere.com/v2";
|
|
1048
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
1046
1049
|
{
|
|
1047
|
-
Authorization: `Bearer ${
|
|
1050
|
+
Authorization: `Bearer ${loadApiKey({
|
|
1048
1051
|
apiKey: options.apiKey,
|
|
1049
1052
|
environmentVariableName: "COHERE_API_KEY",
|
|
1050
1053
|
description: "Cohere"
|
|
@@ -1060,7 +1063,7 @@ function createCohere(options = {}) {
|
|
|
1060
1063
|
baseURL,
|
|
1061
1064
|
headers: getHeaders,
|
|
1062
1065
|
fetch: options.fetch,
|
|
1063
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
1066
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId
|
|
1064
1067
|
});
|
|
1065
1068
|
};
|
|
1066
1069
|
const createEmbeddingModel = (modelId) => new CohereEmbeddingModel(modelId, {
|
|
@@ -1092,15 +1095,14 @@ function createCohere(options = {}) {
|
|
|
1092
1095
|
provider.reranking = createRerankingModel;
|
|
1093
1096
|
provider.rerankingModel = createRerankingModel;
|
|
1094
1097
|
provider.imageModel = (modelId) => {
|
|
1095
|
-
throw new
|
|
1098
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1096
1099
|
};
|
|
1097
1100
|
return provider;
|
|
1098
1101
|
}
|
|
1099
1102
|
var cohere = createCohere();
|
|
1100
|
-
|
|
1101
|
-
0 && (module.exports = {
|
|
1103
|
+
export {
|
|
1102
1104
|
VERSION,
|
|
1103
1105
|
cohere,
|
|
1104
1106
|
createCohere
|
|
1105
|
-
}
|
|
1107
|
+
};
|
|
1106
1108
|
//# sourceMappingURL=index.js.map
|