@ai-sdk/cohere 3.0.72 → 3.0.73
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 +9 -0
- package/dist/index.d.mts +15 -27
- package/dist/index.d.ts +15 -27
- package/dist/index.js +278 -243
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -216
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/cohere-chat-language-model.ts +166 -154
- package/src/cohere-chat-options.ts +39 -26
- package/src/cohere-embedding-model.ts +15 -9
- package/src/cohere-embedding-options.ts +54 -40
- package/src/cohere-error.ts +14 -5
package/dist/index.js
CHANGED
|
@@ -28,44 +28,57 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/cohere-provider.ts
|
|
30
30
|
var import_provider4 = require("@ai-sdk/provider");
|
|
31
|
-
var
|
|
31
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/cohere-chat-language-model.ts
|
|
34
|
-
var
|
|
34
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
35
35
|
var import_v43 = require("zod/v4");
|
|
36
36
|
|
|
37
37
|
// src/cohere-chat-options.ts
|
|
38
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
38
39
|
var import_v4 = require("zod/v4");
|
|
39
|
-
var cohereLanguageModelOptions =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
40
|
+
var cohereLanguageModelOptions = (0, import_provider_utils.lazySchema)(
|
|
41
|
+
() => (0, import_provider_utils.zodSchema)(
|
|
42
|
+
import_v4.z.object({
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for reasoning features (optional)
|
|
45
|
+
*
|
|
46
|
+
* Can be set to an object with the two properties `type` and `tokenBudget`. `type` can be set to `'enabled'` or `'disabled'` (defaults to `'enabled'`).
|
|
47
|
+
* `tokenBudget` is the maximum number of tokens the model can use for thinking, which must be set to a positive integer. The model will stop thinking if it reaches the thinking token budget and will proceed with the response
|
|
48
|
+
*
|
|
49
|
+
* @see https://docs.cohere.com/reference/chat#request.body.thinking
|
|
50
|
+
*/
|
|
51
|
+
thinking: import_v4.z.object({
|
|
52
|
+
type: import_v4.z.enum(["enabled", "disabled"]).optional(),
|
|
53
|
+
tokenBudget: import_v4.z.number().optional()
|
|
54
|
+
}).optional()
|
|
55
|
+
})
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
var cohereImagePartProviderOptions = (0, import_provider_utils.lazySchema)(
|
|
59
|
+
() => (0, import_provider_utils.zodSchema)(
|
|
60
|
+
import_v4.z.object({
|
|
61
|
+
/**
|
|
62
|
+
* Image fidelity level passed through as `image_url.detail` on the Cohere chat API.
|
|
63
|
+
*
|
|
64
|
+
* @see https://docs.cohere.com/docs/image-inputs
|
|
65
|
+
*/
|
|
66
|
+
detail: import_v4.z.enum(["auto", "low", "high"]).optional()
|
|
67
|
+
})
|
|
68
|
+
)
|
|
69
|
+
);
|
|
61
70
|
|
|
62
71
|
// src/cohere-error.ts
|
|
63
|
-
var
|
|
72
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
64
73
|
var import_v42 = require("zod/v4");
|
|
65
|
-
var cohereErrorDataSchema =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
var cohereErrorDataSchema = (0, import_provider_utils2.lazySchema)(
|
|
75
|
+
() => (0, import_provider_utils2.zodSchema)(
|
|
76
|
+
import_v42.z.object({
|
|
77
|
+
message: import_v42.z.string()
|
|
78
|
+
})
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
var cohereFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
|
|
69
82
|
errorSchema: cohereErrorDataSchema,
|
|
70
83
|
errorToMessage: (data) => data.message
|
|
71
84
|
});
|
|
@@ -166,7 +179,7 @@ function convertCohereUsage(usage) {
|
|
|
166
179
|
|
|
167
180
|
// src/convert-to-cohere-chat-prompt.ts
|
|
168
181
|
var import_provider2 = require("@ai-sdk/provider");
|
|
169
|
-
var
|
|
182
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
170
183
|
async function convertToCohereChatPrompt(prompt) {
|
|
171
184
|
var _a, _b;
|
|
172
185
|
const messages = [];
|
|
@@ -193,7 +206,7 @@ async function convertToCohereChatPrompt(prompt) {
|
|
|
193
206
|
if (isImageMediaType(part.mediaType)) {
|
|
194
207
|
hasImage = true;
|
|
195
208
|
const url = buildImageUrl({ part });
|
|
196
|
-
const cohereOptions = (_a = await (0,
|
|
209
|
+
const cohereOptions = (_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
197
210
|
provider: "cohere",
|
|
198
211
|
providerOptions: part.providerOptions,
|
|
199
212
|
schema: cohereImagePartProviderOptions
|
|
@@ -319,7 +332,7 @@ function buildImageUrl({ part }) {
|
|
|
319
332
|
return part.data.toString();
|
|
320
333
|
}
|
|
321
334
|
const mediaType = part.mediaType === "image" || part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
322
|
-
return `data:${mediaType};base64,${(0,
|
|
335
|
+
return `data:${mediaType};base64,${(0, import_provider_utils3.convertToBase64)(part.data)}`;
|
|
323
336
|
}
|
|
324
337
|
|
|
325
338
|
// src/map-cohere-finish-reason.ts
|
|
@@ -368,7 +381,7 @@ var CohereChatLanguageModel = class {
|
|
|
368
381
|
providerOptions
|
|
369
382
|
}) {
|
|
370
383
|
var _a, _b;
|
|
371
|
-
const cohereOptions = (_a = await (0,
|
|
384
|
+
const cohereOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
|
|
372
385
|
provider: "cohere",
|
|
373
386
|
providerOptions,
|
|
374
387
|
schema: cohereLanguageModelOptions
|
|
@@ -423,12 +436,12 @@ var CohereChatLanguageModel = class {
|
|
|
423
436
|
responseHeaders,
|
|
424
437
|
value: response,
|
|
425
438
|
rawValue: rawResponse
|
|
426
|
-
} = await (0,
|
|
439
|
+
} = await (0, import_provider_utils4.postJsonToApi)({
|
|
427
440
|
url: `${this.config.baseURL}/chat`,
|
|
428
|
-
headers: (0,
|
|
441
|
+
headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
|
|
429
442
|
body: args,
|
|
430
443
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
431
|
-
successfulResponseHandler: (0,
|
|
444
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
432
445
|
cohereChatResponseSchema
|
|
433
446
|
),
|
|
434
447
|
abortSignal: options.abortSignal,
|
|
@@ -492,12 +505,12 @@ var CohereChatLanguageModel = class {
|
|
|
492
505
|
}
|
|
493
506
|
async doStream(options) {
|
|
494
507
|
const { args, warnings } = await this.getArgs(options);
|
|
495
|
-
const { responseHeaders, value: response } = await (0,
|
|
508
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
496
509
|
url: `${this.config.baseURL}/chat`,
|
|
497
|
-
headers: (0,
|
|
510
|
+
headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
|
|
498
511
|
body: { ...args, stream: true },
|
|
499
512
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
500
|
-
successfulResponseHandler: (0,
|
|
513
|
+
successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
|
|
501
514
|
cohereChatChunkSchema
|
|
502
515
|
),
|
|
503
516
|
abortSignal: options.abortSignal,
|
|
@@ -622,7 +635,7 @@ var CohereChatLanguageModel = class {
|
|
|
622
635
|
toolCallId: pendingToolCall.id,
|
|
623
636
|
toolName: pendingToolCall.name,
|
|
624
637
|
input: JSON.stringify(
|
|
625
|
-
await (0,
|
|
638
|
+
await (0, import_provider_utils4.parseJSON)({
|
|
626
639
|
text: ((_a = pendingToolCall.arguments) == null ? void 0 : _a.trim()) || "{}"
|
|
627
640
|
})
|
|
628
641
|
)
|
|
@@ -665,7 +678,7 @@ var CohereChatLanguageModel = class {
|
|
|
665
678
|
};
|
|
666
679
|
}
|
|
667
680
|
};
|
|
668
|
-
var cohereUsageSchema = import_v43.z.looseObject({
|
|
681
|
+
var cohereUsageSchema = () => import_v43.z.looseObject({
|
|
669
682
|
billed_units: import_v43.z.looseObject({
|
|
670
683
|
input_tokens: import_v43.z.number(),
|
|
671
684
|
output_tokens: import_v43.z.number()
|
|
@@ -676,198 +689,216 @@ var cohereUsageSchema = import_v43.z.looseObject({
|
|
|
676
689
|
}),
|
|
677
690
|
cached_tokens: import_v43.z.number().nullish()
|
|
678
691
|
});
|
|
679
|
-
var cohereChatResponseSchema =
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
content: import_v43.z.array(
|
|
684
|
-
import_v43.z.union([
|
|
685
|
-
import_v43.z.object({
|
|
686
|
-
type: import_v43.z.literal("text"),
|
|
687
|
-
text: import_v43.z.string()
|
|
688
|
-
}),
|
|
689
|
-
import_v43.z.object({
|
|
690
|
-
type: import_v43.z.literal("thinking"),
|
|
691
|
-
thinking: import_v43.z.string()
|
|
692
|
-
})
|
|
693
|
-
])
|
|
694
|
-
).nullish(),
|
|
695
|
-
tool_plan: import_v43.z.string().nullish(),
|
|
696
|
-
tool_calls: import_v43.z.array(
|
|
697
|
-
import_v43.z.object({
|
|
698
|
-
id: import_v43.z.string(),
|
|
699
|
-
type: import_v43.z.literal("function"),
|
|
700
|
-
function: import_v43.z.object({
|
|
701
|
-
name: import_v43.z.string(),
|
|
702
|
-
arguments: import_v43.z.string()
|
|
703
|
-
})
|
|
704
|
-
})
|
|
705
|
-
).nullish(),
|
|
706
|
-
citations: import_v43.z.array(
|
|
707
|
-
import_v43.z.object({
|
|
708
|
-
start: import_v43.z.number(),
|
|
709
|
-
end: import_v43.z.number(),
|
|
710
|
-
text: import_v43.z.string(),
|
|
711
|
-
sources: import_v43.z.array(
|
|
712
|
-
import_v43.z.object({
|
|
713
|
-
type: import_v43.z.string().optional(),
|
|
714
|
-
id: import_v43.z.string().optional(),
|
|
715
|
-
document: import_v43.z.object({
|
|
716
|
-
id: import_v43.z.string().optional(),
|
|
717
|
-
text: import_v43.z.string(),
|
|
718
|
-
title: import_v43.z.string()
|
|
719
|
-
})
|
|
720
|
-
})
|
|
721
|
-
),
|
|
722
|
-
type: import_v43.z.string().optional()
|
|
723
|
-
})
|
|
724
|
-
).nullish()
|
|
725
|
-
}),
|
|
726
|
-
finish_reason: import_v43.z.string(),
|
|
727
|
-
usage: cohereUsageSchema
|
|
728
|
-
});
|
|
729
|
-
var cohereChatChunkSchema = import_v43.z.discriminatedUnion("type", [
|
|
730
|
-
import_v43.z.object({
|
|
731
|
-
type: import_v43.z.literal("citation-start")
|
|
732
|
-
}),
|
|
733
|
-
import_v43.z.object({
|
|
734
|
-
type: import_v43.z.literal("citation-end")
|
|
735
|
-
}),
|
|
736
|
-
import_v43.z.object({
|
|
737
|
-
type: import_v43.z.literal("content-start"),
|
|
738
|
-
index: import_v43.z.number(),
|
|
739
|
-
delta: import_v43.z.object({
|
|
692
|
+
var cohereChatResponseSchema = (0, import_provider_utils4.lazySchema)(
|
|
693
|
+
() => (0, import_provider_utils4.zodSchema)(
|
|
694
|
+
import_v43.z.object({
|
|
695
|
+
generation_id: import_v43.z.string().nullish(),
|
|
740
696
|
message: import_v43.z.object({
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
697
|
+
role: import_v43.z.string(),
|
|
698
|
+
content: import_v43.z.array(
|
|
699
|
+
import_v43.z.union([
|
|
700
|
+
import_v43.z.object({
|
|
701
|
+
type: import_v43.z.literal("text"),
|
|
702
|
+
text: import_v43.z.string()
|
|
703
|
+
}),
|
|
704
|
+
import_v43.z.object({
|
|
705
|
+
type: import_v43.z.literal("thinking"),
|
|
706
|
+
thinking: import_v43.z.string()
|
|
707
|
+
})
|
|
708
|
+
])
|
|
709
|
+
).nullish(),
|
|
710
|
+
tool_plan: import_v43.z.string().nullish(),
|
|
711
|
+
tool_calls: import_v43.z.array(
|
|
746
712
|
import_v43.z.object({
|
|
747
|
-
|
|
748
|
-
|
|
713
|
+
id: import_v43.z.string(),
|
|
714
|
+
type: import_v43.z.literal("function"),
|
|
715
|
+
function: import_v43.z.object({
|
|
716
|
+
name: import_v43.z.string(),
|
|
717
|
+
arguments: import_v43.z.string()
|
|
718
|
+
})
|
|
749
719
|
})
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
})
|
|
753
|
-
}),
|
|
754
|
-
import_v43.z.object({
|
|
755
|
-
type: import_v43.z.literal("content-delta"),
|
|
756
|
-
index: import_v43.z.number(),
|
|
757
|
-
delta: import_v43.z.object({
|
|
758
|
-
message: import_v43.z.object({
|
|
759
|
-
content: import_v43.z.union([
|
|
760
|
-
import_v43.z.object({
|
|
761
|
-
text: import_v43.z.string()
|
|
762
|
-
}),
|
|
720
|
+
).nullish(),
|
|
721
|
+
citations: import_v43.z.array(
|
|
763
722
|
import_v43.z.object({
|
|
764
|
-
|
|
723
|
+
start: import_v43.z.number(),
|
|
724
|
+
end: import_v43.z.number(),
|
|
725
|
+
text: import_v43.z.string(),
|
|
726
|
+
sources: import_v43.z.array(
|
|
727
|
+
import_v43.z.object({
|
|
728
|
+
type: import_v43.z.string().optional(),
|
|
729
|
+
id: import_v43.z.string().optional(),
|
|
730
|
+
document: import_v43.z.object({
|
|
731
|
+
id: import_v43.z.string().optional(),
|
|
732
|
+
text: import_v43.z.string(),
|
|
733
|
+
title: import_v43.z.string()
|
|
734
|
+
})
|
|
735
|
+
})
|
|
736
|
+
),
|
|
737
|
+
type: import_v43.z.string().optional()
|
|
765
738
|
})
|
|
766
|
-
|
|
767
|
-
})
|
|
768
|
-
})
|
|
769
|
-
}),
|
|
770
|
-
import_v43.z.object({
|
|
771
|
-
type: import_v43.z.literal("content-end"),
|
|
772
|
-
index: import_v43.z.number()
|
|
773
|
-
}),
|
|
774
|
-
import_v43.z.object({
|
|
775
|
-
type: import_v43.z.literal("message-start"),
|
|
776
|
-
id: import_v43.z.string().nullish()
|
|
777
|
-
}),
|
|
778
|
-
import_v43.z.object({
|
|
779
|
-
type: import_v43.z.literal("message-end"),
|
|
780
|
-
delta: import_v43.z.object({
|
|
739
|
+
).nullish()
|
|
740
|
+
}),
|
|
781
741
|
finish_reason: import_v43.z.string(),
|
|
782
|
-
usage: cohereUsageSchema
|
|
742
|
+
usage: cohereUsageSchema()
|
|
783
743
|
})
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
})
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
744
|
+
)
|
|
745
|
+
);
|
|
746
|
+
var cohereChatChunkSchema = (0, import_provider_utils4.lazySchema)(
|
|
747
|
+
() => (0, import_provider_utils4.zodSchema)(
|
|
748
|
+
import_v43.z.discriminatedUnion("type", [
|
|
749
|
+
import_v43.z.object({
|
|
750
|
+
type: import_v43.z.literal("citation-start")
|
|
751
|
+
}),
|
|
752
|
+
import_v43.z.object({
|
|
753
|
+
type: import_v43.z.literal("citation-end")
|
|
754
|
+
}),
|
|
755
|
+
import_v43.z.object({
|
|
756
|
+
type: import_v43.z.literal("content-start"),
|
|
757
|
+
index: import_v43.z.number(),
|
|
758
|
+
delta: import_v43.z.object({
|
|
759
|
+
message: import_v43.z.object({
|
|
760
|
+
content: import_v43.z.union([
|
|
761
|
+
import_v43.z.object({
|
|
762
|
+
type: import_v43.z.literal("text"),
|
|
763
|
+
text: import_v43.z.string()
|
|
764
|
+
}),
|
|
765
|
+
import_v43.z.object({
|
|
766
|
+
type: import_v43.z.literal("thinking"),
|
|
767
|
+
thinking: import_v43.z.string()
|
|
768
|
+
})
|
|
769
|
+
])
|
|
804
770
|
})
|
|
805
771
|
})
|
|
806
|
-
})
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
772
|
+
}),
|
|
773
|
+
import_v43.z.object({
|
|
774
|
+
type: import_v43.z.literal("content-delta"),
|
|
775
|
+
index: import_v43.z.number(),
|
|
776
|
+
delta: import_v43.z.object({
|
|
777
|
+
message: import_v43.z.object({
|
|
778
|
+
content: import_v43.z.union([
|
|
779
|
+
import_v43.z.object({
|
|
780
|
+
text: import_v43.z.string()
|
|
781
|
+
}),
|
|
782
|
+
import_v43.z.object({
|
|
783
|
+
thinking: import_v43.z.string()
|
|
784
|
+
})
|
|
785
|
+
])
|
|
819
786
|
})
|
|
820
787
|
})
|
|
788
|
+
}),
|
|
789
|
+
import_v43.z.object({
|
|
790
|
+
type: import_v43.z.literal("content-end"),
|
|
791
|
+
index: import_v43.z.number()
|
|
792
|
+
}),
|
|
793
|
+
import_v43.z.object({
|
|
794
|
+
type: import_v43.z.literal("message-start"),
|
|
795
|
+
id: import_v43.z.string().nullish()
|
|
796
|
+
}),
|
|
797
|
+
import_v43.z.object({
|
|
798
|
+
type: import_v43.z.literal("message-end"),
|
|
799
|
+
delta: import_v43.z.object({
|
|
800
|
+
finish_reason: import_v43.z.string(),
|
|
801
|
+
usage: cohereUsageSchema()
|
|
802
|
+
})
|
|
803
|
+
}),
|
|
804
|
+
// https://docs.cohere.com/v2/docs/streaming#tool-use-stream-events-for-tool-calling
|
|
805
|
+
import_v43.z.object({
|
|
806
|
+
type: import_v43.z.literal("tool-plan-delta"),
|
|
807
|
+
delta: import_v43.z.object({
|
|
808
|
+
message: import_v43.z.object({
|
|
809
|
+
tool_plan: import_v43.z.string()
|
|
810
|
+
})
|
|
811
|
+
})
|
|
812
|
+
}),
|
|
813
|
+
import_v43.z.object({
|
|
814
|
+
type: import_v43.z.literal("tool-call-start"),
|
|
815
|
+
delta: import_v43.z.object({
|
|
816
|
+
message: import_v43.z.object({
|
|
817
|
+
tool_calls: import_v43.z.object({
|
|
818
|
+
id: import_v43.z.string(),
|
|
819
|
+
type: import_v43.z.literal("function"),
|
|
820
|
+
function: import_v43.z.object({
|
|
821
|
+
name: import_v43.z.string(),
|
|
822
|
+
arguments: import_v43.z.string()
|
|
823
|
+
})
|
|
824
|
+
})
|
|
825
|
+
})
|
|
826
|
+
})
|
|
827
|
+
}),
|
|
828
|
+
// A single tool call's `arguments` stream in chunks and must be accumulated
|
|
829
|
+
// in a string and so the full tool object info can only be parsed once we see
|
|
830
|
+
// `tool-call-end`.
|
|
831
|
+
import_v43.z.object({
|
|
832
|
+
type: import_v43.z.literal("tool-call-delta"),
|
|
833
|
+
delta: import_v43.z.object({
|
|
834
|
+
message: import_v43.z.object({
|
|
835
|
+
tool_calls: import_v43.z.object({
|
|
836
|
+
function: import_v43.z.object({
|
|
837
|
+
arguments: import_v43.z.string()
|
|
838
|
+
})
|
|
839
|
+
})
|
|
840
|
+
})
|
|
841
|
+
})
|
|
842
|
+
}),
|
|
843
|
+
import_v43.z.object({
|
|
844
|
+
type: import_v43.z.literal("tool-call-end")
|
|
821
845
|
})
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
type: import_v43.z.literal("tool-call-end")
|
|
826
|
-
})
|
|
827
|
-
]);
|
|
846
|
+
])
|
|
847
|
+
)
|
|
848
|
+
);
|
|
828
849
|
|
|
829
850
|
// src/cohere-embedding-model.ts
|
|
830
851
|
var import_provider3 = require("@ai-sdk/provider");
|
|
831
|
-
var
|
|
852
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
832
853
|
var import_v45 = require("zod/v4");
|
|
833
854
|
|
|
834
855
|
// src/cohere-embedding-options.ts
|
|
856
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
835
857
|
var import_v44 = require("zod/v4");
|
|
836
|
-
var cohereEmbeddingModelOptions =
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
858
|
+
var cohereEmbeddingModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
859
|
+
() => (0, import_provider_utils5.zodSchema)(
|
|
860
|
+
import_v44.z.object({
|
|
861
|
+
/**
|
|
862
|
+
* Specifies the type of input passed to the model. Default is `search_query`.
|
|
863
|
+
*
|
|
864
|
+
* - "search_document": Used for embeddings stored in a vector database for search use-cases.
|
|
865
|
+
* - "search_query": Used for embeddings of search queries run against a vector DB to find relevant documents.
|
|
866
|
+
* - "classification": Used for embeddings passed through a text classifier.
|
|
867
|
+
* - "clustering": Used for embeddings run through a clustering algorithm.
|
|
868
|
+
*/
|
|
869
|
+
inputType: import_v44.z.enum([
|
|
870
|
+
"search_document",
|
|
871
|
+
"search_query",
|
|
872
|
+
"classification",
|
|
873
|
+
"clustering"
|
|
874
|
+
]).optional(),
|
|
875
|
+
/**
|
|
876
|
+
* Specifies how the API will handle inputs longer than the maximum token length.
|
|
877
|
+
* Default is `END`.
|
|
878
|
+
*
|
|
879
|
+
* - "NONE": If selected, when the input exceeds the maximum input token length will return an error.
|
|
880
|
+
* - "START": Will discard the start of the input until the remaining input is exactly the maximum input token length for the model.
|
|
881
|
+
* - "END": Will discard the end of the input until the remaining input is exactly the maximum input token length for the model.
|
|
882
|
+
*/
|
|
883
|
+
truncate: import_v44.z.enum(["NONE", "START", "END"]).optional(),
|
|
884
|
+
/**
|
|
885
|
+
* The number of dimensions of the output embedding.
|
|
886
|
+
* Only available for `embed-v4.0` and newer models.
|
|
887
|
+
*
|
|
888
|
+
* Embed v4.0 supports `256`, `512`, `1024`, and `1536` (default).
|
|
889
|
+
* Embed v5.0 Pro and Fast also support `768` and `2048` (default).
|
|
890
|
+
*/
|
|
891
|
+
outputDimension: import_v44.z.union([
|
|
892
|
+
import_v44.z.literal(256),
|
|
893
|
+
import_v44.z.literal(512),
|
|
894
|
+
import_v44.z.literal(768),
|
|
895
|
+
import_v44.z.literal(1024),
|
|
896
|
+
import_v44.z.literal(1536),
|
|
897
|
+
import_v44.z.literal(2048)
|
|
898
|
+
]).optional()
|
|
899
|
+
})
|
|
900
|
+
)
|
|
901
|
+
);
|
|
871
902
|
|
|
872
903
|
// src/cohere-embedding-model.ts
|
|
873
904
|
var CohereEmbeddingModel = class {
|
|
@@ -888,7 +919,7 @@ var CohereEmbeddingModel = class {
|
|
|
888
919
|
providerOptions
|
|
889
920
|
}) {
|
|
890
921
|
var _a;
|
|
891
|
-
const embeddingOptions = await (0,
|
|
922
|
+
const embeddingOptions = await (0, import_provider_utils6.parseProviderOptions)({
|
|
892
923
|
provider: "cohere",
|
|
893
924
|
providerOptions,
|
|
894
925
|
schema: cohereEmbeddingModelOptions
|
|
@@ -905,9 +936,9 @@ var CohereEmbeddingModel = class {
|
|
|
905
936
|
responseHeaders,
|
|
906
937
|
value: response,
|
|
907
938
|
rawValue
|
|
908
|
-
} = await (0,
|
|
939
|
+
} = await (0, import_provider_utils6.postJsonToApi)({
|
|
909
940
|
url: `${this.config.baseURL}/embed`,
|
|
910
|
-
headers: (0,
|
|
941
|
+
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), headers),
|
|
911
942
|
body: {
|
|
912
943
|
model: this.modelId,
|
|
913
944
|
// The AI SDK only supports 'float' embeddings. Note that the Cohere API
|
|
@@ -920,7 +951,7 @@ var CohereEmbeddingModel = class {
|
|
|
920
951
|
output_dimension: embeddingOptions == null ? void 0 : embeddingOptions.outputDimension
|
|
921
952
|
},
|
|
922
953
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
923
|
-
successfulResponseHandler: (0,
|
|
954
|
+
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
|
|
924
955
|
cohereTextEmbeddingResponseSchema
|
|
925
956
|
),
|
|
926
957
|
abortSignal,
|
|
@@ -934,25 +965,29 @@ var CohereEmbeddingModel = class {
|
|
|
934
965
|
};
|
|
935
966
|
}
|
|
936
967
|
};
|
|
937
|
-
var cohereTextEmbeddingResponseSchema =
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
968
|
+
var cohereTextEmbeddingResponseSchema = (0, import_provider_utils6.lazySchema)(
|
|
969
|
+
() => (0, import_provider_utils6.zodSchema)(
|
|
970
|
+
import_v45.z.object({
|
|
971
|
+
embeddings: import_v45.z.object({
|
|
972
|
+
float: import_v45.z.array(import_v45.z.array(import_v45.z.number()))
|
|
973
|
+
}),
|
|
974
|
+
meta: import_v45.z.object({
|
|
975
|
+
billed_units: import_v45.z.object({
|
|
976
|
+
input_tokens: import_v45.z.number()
|
|
977
|
+
})
|
|
978
|
+
})
|
|
944
979
|
})
|
|
945
|
-
|
|
946
|
-
|
|
980
|
+
)
|
|
981
|
+
);
|
|
947
982
|
|
|
948
983
|
// src/reranking/cohere-reranking-model.ts
|
|
949
|
-
var
|
|
984
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
950
985
|
|
|
951
986
|
// src/reranking/cohere-reranking-api.ts
|
|
952
|
-
var
|
|
987
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
953
988
|
var import_v46 = require("zod/v4");
|
|
954
|
-
var cohereRerankingResponseSchema = (0,
|
|
955
|
-
() => (0,
|
|
989
|
+
var cohereRerankingResponseSchema = (0, import_provider_utils7.lazySchema)(
|
|
990
|
+
() => (0, import_provider_utils7.zodSchema)(
|
|
956
991
|
import_v46.z.object({
|
|
957
992
|
id: import_v46.z.string().nullish(),
|
|
958
993
|
results: import_v46.z.array(
|
|
@@ -967,10 +1002,10 @@ var cohereRerankingResponseSchema = (0, import_provider_utils5.lazySchema)(
|
|
|
967
1002
|
);
|
|
968
1003
|
|
|
969
1004
|
// src/reranking/cohere-reranking-options.ts
|
|
970
|
-
var
|
|
1005
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
971
1006
|
var import_v47 = require("zod/v4");
|
|
972
|
-
var cohereRerankingModelOptionsSchema = (0,
|
|
973
|
-
() => (0,
|
|
1007
|
+
var cohereRerankingModelOptionsSchema = (0, import_provider_utils8.lazySchema)(
|
|
1008
|
+
() => (0, import_provider_utils8.zodSchema)(
|
|
974
1009
|
import_v47.z.object({
|
|
975
1010
|
maxTokensPerDoc: import_v47.z.number().optional(),
|
|
976
1011
|
priority: import_v47.z.number().optional()
|
|
@@ -998,7 +1033,7 @@ var CohereRerankingModel = class {
|
|
|
998
1033
|
providerOptions
|
|
999
1034
|
}) {
|
|
1000
1035
|
var _a;
|
|
1001
|
-
const rerankingOptions = await (0,
|
|
1036
|
+
const rerankingOptions = await (0, import_provider_utils9.parseProviderOptions)({
|
|
1002
1037
|
provider: "cohere",
|
|
1003
1038
|
providerOptions,
|
|
1004
1039
|
schema: cohereRerankingModelOptionsSchema
|
|
@@ -1015,9 +1050,9 @@ var CohereRerankingModel = class {
|
|
|
1015
1050
|
responseHeaders,
|
|
1016
1051
|
value: response,
|
|
1017
1052
|
rawValue
|
|
1018
|
-
} = await (0,
|
|
1053
|
+
} = await (0, import_provider_utils9.postJsonToApi)({
|
|
1019
1054
|
url: `${this.config.baseURL}/rerank`,
|
|
1020
|
-
headers: (0,
|
|
1055
|
+
headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), headers),
|
|
1021
1056
|
body: {
|
|
1022
1057
|
model: this.modelId,
|
|
1023
1058
|
query,
|
|
@@ -1027,7 +1062,7 @@ var CohereRerankingModel = class {
|
|
|
1027
1062
|
priority: rerankingOptions == null ? void 0 : rerankingOptions.priority
|
|
1028
1063
|
},
|
|
1029
1064
|
failedResponseHandler: cohereFailedResponseHandler,
|
|
1030
|
-
successfulResponseHandler: (0,
|
|
1065
|
+
successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
|
|
1031
1066
|
cohereRerankingResponseSchema
|
|
1032
1067
|
),
|
|
1033
1068
|
abortSignal,
|
|
@@ -1049,15 +1084,15 @@ var CohereRerankingModel = class {
|
|
|
1049
1084
|
};
|
|
1050
1085
|
|
|
1051
1086
|
// src/version.ts
|
|
1052
|
-
var VERSION = true ? "3.0.
|
|
1087
|
+
var VERSION = true ? "3.0.73" : "0.0.0-test";
|
|
1053
1088
|
|
|
1054
1089
|
// src/cohere-provider.ts
|
|
1055
1090
|
function createCohere(options = {}) {
|
|
1056
1091
|
var _a;
|
|
1057
|
-
const baseURL = (_a = (0,
|
|
1058
|
-
const getHeaders = () => (0,
|
|
1092
|
+
const baseURL = (_a = (0, import_provider_utils10.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.cohere.com/v2";
|
|
1093
|
+
const getHeaders = () => (0, import_provider_utils10.withUserAgentSuffix)(
|
|
1059
1094
|
{
|
|
1060
|
-
Authorization: `Bearer ${(0,
|
|
1095
|
+
Authorization: `Bearer ${(0, import_provider_utils10.loadApiKey)({
|
|
1061
1096
|
apiKey: options.apiKey,
|
|
1062
1097
|
environmentVariableName: "COHERE_API_KEY",
|
|
1063
1098
|
description: "Cohere"
|
|
@@ -1073,7 +1108,7 @@ function createCohere(options = {}) {
|
|
|
1073
1108
|
baseURL,
|
|
1074
1109
|
headers: getHeaders,
|
|
1075
1110
|
fetch: options.fetch,
|
|
1076
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
1111
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils10.generateId
|
|
1077
1112
|
});
|
|
1078
1113
|
};
|
|
1079
1114
|
const createEmbeddingModel = (modelId) => new CohereEmbeddingModel(modelId, {
|