@ai-sdk/amazon-bedrock 3.0.0-canary.7 → 3.0.0-canary.9
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 +21 -0
- package/dist/index.d.mts +1 -13
- package/dist/index.d.ts +1 -13
- package/dist/index.js +84 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -4
package/dist/index.mjs
CHANGED
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
combineHeaders,
|
|
12
12
|
createJsonErrorResponseHandler,
|
|
13
13
|
createJsonResponseHandler,
|
|
14
|
+
parseProviderOptions,
|
|
14
15
|
postJsonToApi,
|
|
15
|
-
resolve
|
|
16
|
-
parseProviderOptions
|
|
16
|
+
resolve
|
|
17
17
|
} from "@ai-sdk/provider-utils";
|
|
18
18
|
import { z as z3 } from "zod";
|
|
19
19
|
|
|
@@ -495,8 +495,6 @@ var BedrockChatLanguageModel = class {
|
|
|
495
495
|
this.config = config;
|
|
496
496
|
this.specificationVersion = "v2";
|
|
497
497
|
this.provider = "amazon-bedrock";
|
|
498
|
-
this.defaultObjectGenerationMode = "tool";
|
|
499
|
-
this.supportsImageUrls = false;
|
|
500
498
|
}
|
|
501
499
|
getArgs({
|
|
502
500
|
prompt,
|
|
@@ -605,8 +603,13 @@ var BedrockChatLanguageModel = class {
|
|
|
605
603
|
warnings: [...warnings, ...toolWarnings]
|
|
606
604
|
};
|
|
607
605
|
}
|
|
606
|
+
async getSupportedUrls() {
|
|
607
|
+
return {
|
|
608
|
+
// no supported urls for bedrock
|
|
609
|
+
};
|
|
610
|
+
}
|
|
608
611
|
async doGenerate(options) {
|
|
609
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m
|
|
612
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
610
613
|
const { command: args, warnings } = this.getArgs(options);
|
|
611
614
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
612
615
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
@@ -629,71 +632,68 @@ var BedrockChatLanguageModel = class {
|
|
|
629
632
|
abortSignal: options.abortSignal,
|
|
630
633
|
fetch: this.config.fetch
|
|
631
634
|
});
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
usage: {
|
|
637
|
-
cacheReadInputTokens: (_b = (_a = response.usage) == null ? void 0 : _a.cacheReadInputTokens) != null ? _b : Number.NaN,
|
|
638
|
-
cacheWriteInputTokens: (_d = (_c = response.usage) == null ? void 0 : _c.cacheWriteInputTokens) != null ? _d : Number.NaN
|
|
639
|
-
}
|
|
640
|
-
}
|
|
635
|
+
const content = [];
|
|
636
|
+
for (const part of response.output.message.content) {
|
|
637
|
+
if (part.text) {
|
|
638
|
+
content.push({ type: "text", text: part.text });
|
|
641
639
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
if (content.reasoningContent) {
|
|
646
|
-
if ("reasoningText" in content.reasoningContent) {
|
|
647
|
-
reasoning.push({
|
|
640
|
+
if (part.reasoningContent) {
|
|
641
|
+
if ("reasoningText" in part.reasoningContent) {
|
|
642
|
+
content.push({
|
|
648
643
|
type: "reasoning",
|
|
649
644
|
reasoningType: "text",
|
|
650
|
-
text:
|
|
645
|
+
text: part.reasoningContent.reasoningText.text
|
|
651
646
|
});
|
|
652
|
-
if (
|
|
653
|
-
|
|
647
|
+
if (part.reasoningContent.reasoningText.signature) {
|
|
648
|
+
content.push({
|
|
654
649
|
type: "reasoning",
|
|
655
650
|
reasoningType: "signature",
|
|
656
|
-
signature:
|
|
651
|
+
signature: part.reasoningContent.reasoningText.signature
|
|
657
652
|
});
|
|
658
653
|
}
|
|
659
|
-
} else if ("redactedReasoning" in
|
|
660
|
-
|
|
654
|
+
} else if ("redactedReasoning" in part.reasoningContent) {
|
|
655
|
+
content.push({
|
|
661
656
|
type: "reasoning",
|
|
662
657
|
reasoningType: "redacted",
|
|
663
|
-
data: (
|
|
658
|
+
data: (_a = part.reasoningContent.redactedReasoning.data) != null ? _a : ""
|
|
664
659
|
});
|
|
665
660
|
}
|
|
666
661
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
var _a2;
|
|
670
|
-
return (_a2 = part.text) != null ? _a2 : "";
|
|
671
|
-
}).join("");
|
|
672
|
-
return {
|
|
673
|
-
text: text != null ? { type: "text", text } : void 0,
|
|
674
|
-
toolCalls: (_l = (_k = (_j = (_i = response.output) == null ? void 0 : _i.message) == null ? void 0 : _j.content) == null ? void 0 : _k.filter((part) => !!part.toolUse)) == null ? void 0 : _l.map((part) => {
|
|
675
|
-
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
676
|
-
return {
|
|
662
|
+
if (part.toolUse) {
|
|
663
|
+
content.push({
|
|
677
664
|
type: "tool-call",
|
|
678
665
|
toolCallType: "function",
|
|
679
|
-
toolCallId: (
|
|
680
|
-
toolName: (
|
|
681
|
-
args: JSON.stringify((
|
|
682
|
-
};
|
|
683
|
-
}
|
|
666
|
+
toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
|
|
667
|
+
toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
|
|
668
|
+
args: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const providerMetadata = response.trace || response.usage ? {
|
|
673
|
+
bedrock: {
|
|
674
|
+
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
675
|
+
...response.usage && {
|
|
676
|
+
usage: {
|
|
677
|
+
cacheReadInputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.cacheReadInputTokens) != null ? _i : Number.NaN,
|
|
678
|
+
cacheWriteInputTokens: (_k = (_j = response.usage) == null ? void 0 : _j.cacheWriteInputTokens) != null ? _k : Number.NaN
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
} : void 0;
|
|
683
|
+
return {
|
|
684
|
+
content,
|
|
684
685
|
finishReason: mapBedrockFinishReason(
|
|
685
686
|
response.stopReason
|
|
686
687
|
),
|
|
687
688
|
usage: {
|
|
688
|
-
inputTokens: (
|
|
689
|
-
outputTokens: (
|
|
689
|
+
inputTokens: (_l = response.usage) == null ? void 0 : _l.inputTokens,
|
|
690
|
+
outputTokens: (_m = response.usage) == null ? void 0 : _m.outputTokens
|
|
690
691
|
},
|
|
691
692
|
response: {
|
|
692
693
|
// TODO add id, timestamp, etc
|
|
693
694
|
headers: responseHeaders
|
|
694
695
|
},
|
|
695
696
|
warnings,
|
|
696
|
-
reasoning: reasoning.length > 0 ? reasoning : void 0,
|
|
697
697
|
...providerMetadata && { providerMetadata }
|
|
698
698
|
};
|
|
699
699
|
}
|
|
@@ -725,6 +725,9 @@ var BedrockChatLanguageModel = class {
|
|
|
725
725
|
return {
|
|
726
726
|
stream: response.pipeThrough(
|
|
727
727
|
new TransformStream({
|
|
728
|
+
start(controller) {
|
|
729
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
730
|
+
},
|
|
728
731
|
transform(chunk, controller) {
|
|
729
732
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
730
733
|
function enqueueError(bedrockError) {
|
|
@@ -854,8 +857,8 @@ var BedrockChatLanguageModel = class {
|
|
|
854
857
|
}
|
|
855
858
|
})
|
|
856
859
|
),
|
|
857
|
-
|
|
858
|
-
|
|
860
|
+
// TODO request?
|
|
861
|
+
response: { headers: responseHeaders }
|
|
859
862
|
};
|
|
860
863
|
}
|
|
861
864
|
getUrl(modelId) {
|
|
@@ -964,14 +967,31 @@ import {
|
|
|
964
967
|
combineHeaders as combineHeaders2,
|
|
965
968
|
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
966
969
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
970
|
+
parseProviderOptions as parseProviderOptions2,
|
|
967
971
|
postJsonToApi as postJsonToApi2,
|
|
968
972
|
resolve as resolve2
|
|
969
973
|
} from "@ai-sdk/provider-utils";
|
|
974
|
+
|
|
975
|
+
// src/bedrock-embedding-options.ts
|
|
970
976
|
import { z as z4 } from "zod";
|
|
977
|
+
var bedrockEmbeddingProviderOptions = z4.object({
|
|
978
|
+
/**
|
|
979
|
+
The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
980
|
+
Only supported in amazon.titan-embed-text-v2:0.
|
|
981
|
+
*/
|
|
982
|
+
dimensions: z4.union([z4.literal(1024), z4.literal(512), z4.literal(256)]).optional(),
|
|
983
|
+
/**
|
|
984
|
+
Flag indicating whether or not to normalize the output embeddings. Defaults to true
|
|
985
|
+
Only supported in amazon.titan-embed-text-v2:0.
|
|
986
|
+
*/
|
|
987
|
+
normalize: z4.boolean().optional()
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
// src/bedrock-embedding-model.ts
|
|
991
|
+
import { z as z5 } from "zod";
|
|
971
992
|
var BedrockEmbeddingModel = class {
|
|
972
|
-
constructor(modelId,
|
|
993
|
+
constructor(modelId, config) {
|
|
973
994
|
this.modelId = modelId;
|
|
974
|
-
this.settings = settings;
|
|
975
995
|
this.config = config;
|
|
976
996
|
this.specificationVersion = "v2";
|
|
977
997
|
this.provider = "amazon-bedrock";
|
|
@@ -985,13 +1005,20 @@ var BedrockEmbeddingModel = class {
|
|
|
985
1005
|
async doEmbed({
|
|
986
1006
|
values,
|
|
987
1007
|
headers,
|
|
988
|
-
abortSignal
|
|
1008
|
+
abortSignal,
|
|
1009
|
+
providerOptions
|
|
989
1010
|
}) {
|
|
1011
|
+
var _a;
|
|
1012
|
+
const bedrockOptions = (_a = parseProviderOptions2({
|
|
1013
|
+
provider: "bedrock",
|
|
1014
|
+
providerOptions,
|
|
1015
|
+
schema: bedrockEmbeddingProviderOptions
|
|
1016
|
+
})) != null ? _a : {};
|
|
990
1017
|
const embedSingleText = async (inputText) => {
|
|
991
1018
|
const args = {
|
|
992
1019
|
inputText,
|
|
993
|
-
dimensions:
|
|
994
|
-
normalize:
|
|
1020
|
+
dimensions: bedrockOptions.dimensions,
|
|
1021
|
+
normalize: bedrockOptions.normalize
|
|
995
1022
|
};
|
|
996
1023
|
const url = this.getUrl(this.modelId);
|
|
997
1024
|
const { value: response } = await postJsonToApi2({
|
|
@@ -1026,9 +1053,9 @@ var BedrockEmbeddingModel = class {
|
|
|
1026
1053
|
);
|
|
1027
1054
|
}
|
|
1028
1055
|
};
|
|
1029
|
-
var BedrockEmbeddingResponseSchema =
|
|
1030
|
-
embedding:
|
|
1031
|
-
inputTextTokenCount:
|
|
1056
|
+
var BedrockEmbeddingResponseSchema = z5.object({
|
|
1057
|
+
embedding: z5.array(z5.number()),
|
|
1058
|
+
inputTextTokenCount: z5.number()
|
|
1032
1059
|
});
|
|
1033
1060
|
|
|
1034
1061
|
// src/bedrock-image-model.ts
|
|
@@ -1046,7 +1073,7 @@ var modelMaxImagesPerCall = {
|
|
|
1046
1073
|
};
|
|
1047
1074
|
|
|
1048
1075
|
// src/bedrock-image-model.ts
|
|
1049
|
-
import { z as
|
|
1076
|
+
import { z as z6 } from "zod";
|
|
1050
1077
|
var BedrockImageModel = class {
|
|
1051
1078
|
constructor(modelId, settings, config) {
|
|
1052
1079
|
this.modelId = modelId;
|
|
@@ -1128,8 +1155,8 @@ var BedrockImageModel = class {
|
|
|
1128
1155
|
};
|
|
1129
1156
|
}
|
|
1130
1157
|
};
|
|
1131
|
-
var bedrockImageResponseSchema =
|
|
1132
|
-
images:
|
|
1158
|
+
var bedrockImageResponseSchema = z6.object({
|
|
1159
|
+
images: z6.array(z6.string())
|
|
1133
1160
|
});
|
|
1134
1161
|
|
|
1135
1162
|
// src/headers-utils.ts
|
|
@@ -1271,9 +1298,9 @@ function createAmazonBedrock(options = {}) {
|
|
|
1271
1298
|
}
|
|
1272
1299
|
return createChatModel(modelId);
|
|
1273
1300
|
};
|
|
1274
|
-
const createEmbeddingModel = (modelId
|
|
1301
|
+
const createEmbeddingModel = (modelId) => {
|
|
1275
1302
|
var _a;
|
|
1276
|
-
return new BedrockEmbeddingModel(modelId,
|
|
1303
|
+
return new BedrockEmbeddingModel(modelId, {
|
|
1277
1304
|
baseUrl: getBaseUrl,
|
|
1278
1305
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1279
1306
|
fetch: sigv4Fetch
|