@ai-sdk/amazon-bedrock 3.0.0-beta.1 → 3.0.0-beta.11
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 +71 -0
- package/README.md +75 -0
- package/dist/index.d.mts +28 -27
- package/dist/index.d.ts +28 -27
- package/dist/index.js +357 -185
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +282 -110
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
postJsonToApi,
|
|
16
16
|
resolve
|
|
17
17
|
} from "@ai-sdk/provider-utils";
|
|
18
|
-
import { z as z3 } from "zod";
|
|
18
|
+
import { z as z3 } from "zod/v4";
|
|
19
19
|
|
|
20
20
|
// src/bedrock-api-types.ts
|
|
21
21
|
var BEDROCK_CACHE_POINT = {
|
|
@@ -33,16 +33,33 @@ var BEDROCK_STOP_REASONS = [
|
|
|
33
33
|
"tool-calls",
|
|
34
34
|
"tool_use"
|
|
35
35
|
];
|
|
36
|
+
var BEDROCK_IMAGE_MIME_TYPES = {
|
|
37
|
+
"image/jpeg": "jpeg",
|
|
38
|
+
"image/png": "png",
|
|
39
|
+
"image/gif": "gif",
|
|
40
|
+
"image/webp": "webp"
|
|
41
|
+
};
|
|
42
|
+
var BEDROCK_DOCUMENT_MIME_TYPES = {
|
|
43
|
+
"application/pdf": "pdf",
|
|
44
|
+
"text/csv": "csv",
|
|
45
|
+
"application/msword": "doc",
|
|
46
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
47
|
+
"application/vnd.ms-excel": "xls",
|
|
48
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
49
|
+
"text/html": "html",
|
|
50
|
+
"text/plain": "txt",
|
|
51
|
+
"text/markdown": "md"
|
|
52
|
+
};
|
|
36
53
|
|
|
37
54
|
// src/bedrock-chat-options.ts
|
|
38
|
-
import { z } from "zod";
|
|
55
|
+
import { z } from "zod/v4";
|
|
39
56
|
var bedrockProviderOptions = z.object({
|
|
40
57
|
/**
|
|
41
58
|
* Additional inference parameters that the model supports,
|
|
42
59
|
* beyond the base set of inference parameters that Converse
|
|
43
60
|
* supports in the inferenceConfig field
|
|
44
61
|
*/
|
|
45
|
-
additionalModelRequestFields: z.record(z.any()).optional(),
|
|
62
|
+
additionalModelRequestFields: z.record(z.string(), z.any()).optional(),
|
|
46
63
|
reasoningConfig: z.object({
|
|
47
64
|
type: z.union([z.literal("enabled"), z.literal("disabled")]).optional(),
|
|
48
65
|
budgetTokens: z.number().optional()
|
|
@@ -50,7 +67,7 @@ var bedrockProviderOptions = z.object({
|
|
|
50
67
|
});
|
|
51
68
|
|
|
52
69
|
// src/bedrock-error.ts
|
|
53
|
-
import { z as z2 } from "zod";
|
|
70
|
+
import { z as z2 } from "zod/v4";
|
|
54
71
|
var BedrockErrorSchema = z2.object({
|
|
55
72
|
message: z2.string(),
|
|
56
73
|
type: z2.string().nullish()
|
|
@@ -135,14 +152,29 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
|
|
|
135
152
|
import {
|
|
136
153
|
UnsupportedFunctionalityError
|
|
137
154
|
} from "@ai-sdk/provider";
|
|
155
|
+
function promptContainsToolContent(prompt) {
|
|
156
|
+
return prompt.some((message) => {
|
|
157
|
+
if ("content" in message && Array.isArray(message.content)) {
|
|
158
|
+
return message.content.some(
|
|
159
|
+
(part) => part.type === "tool-call" || part.type === "tool-result"
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
138
165
|
function prepareTools({
|
|
139
166
|
tools,
|
|
140
|
-
toolChoice
|
|
167
|
+
toolChoice,
|
|
168
|
+
prompt
|
|
141
169
|
}) {
|
|
142
170
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
171
|
+
const hasToolContent = promptContainsToolContent(prompt);
|
|
143
172
|
if (tools == null) {
|
|
144
173
|
return {
|
|
145
|
-
toolConfig: {
|
|
174
|
+
toolConfig: {
|
|
175
|
+
tools: hasToolContent ? [] : void 0,
|
|
176
|
+
toolChoice: void 0
|
|
177
|
+
},
|
|
146
178
|
toolWarnings: []
|
|
147
179
|
};
|
|
148
180
|
}
|
|
@@ -183,7 +215,10 @@ function prepareTools({
|
|
|
183
215
|
};
|
|
184
216
|
case "none":
|
|
185
217
|
return {
|
|
186
|
-
toolConfig: {
|
|
218
|
+
toolConfig: {
|
|
219
|
+
tools: hasToolContent ? [] : void 0,
|
|
220
|
+
toolChoice: void 0
|
|
221
|
+
},
|
|
187
222
|
toolWarnings
|
|
188
223
|
};
|
|
189
224
|
case "tool":
|
|
@@ -213,7 +248,6 @@ function getCachePoint(providerMetadata) {
|
|
|
213
248
|
return (_a = providerMetadata == null ? void 0 : providerMetadata.bedrock) == null ? void 0 : _a.cachePoint;
|
|
214
249
|
}
|
|
215
250
|
async function convertToBedrockChatMessages(prompt) {
|
|
216
|
-
var _a, _b, _c, _d;
|
|
217
251
|
const blocks = groupIntoBlocks(prompt);
|
|
218
252
|
let system = [];
|
|
219
253
|
const messages = [];
|
|
@@ -260,19 +294,22 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
260
294
|
});
|
|
261
295
|
}
|
|
262
296
|
if (part.mediaType.startsWith("image/")) {
|
|
263
|
-
const bedrockImageFormat = part.mediaType === "image/*" ? void 0 : (_b = (_a = part.mediaType) == null ? void 0 : _a.split("/")) == null ? void 0 : _b[1];
|
|
264
297
|
bedrockContent.push({
|
|
265
298
|
image: {
|
|
266
|
-
format:
|
|
299
|
+
format: getBedrockImageFormat(part.mediaType),
|
|
267
300
|
source: { bytes: convertToBase64(part.data) }
|
|
268
301
|
}
|
|
269
302
|
});
|
|
270
303
|
} else {
|
|
304
|
+
if (!part.mediaType) {
|
|
305
|
+
throw new UnsupportedFunctionalityError2({
|
|
306
|
+
functionality: "file without mime type",
|
|
307
|
+
message: "File mime type is required in user message part content"
|
|
308
|
+
});
|
|
309
|
+
}
|
|
271
310
|
bedrockContent.push({
|
|
272
311
|
document: {
|
|
273
|
-
format: (
|
|
274
|
-
"/"
|
|
275
|
-
)) == null ? void 0 : _d[1],
|
|
312
|
+
format: getBedrockDocumentFormat(part.mediaType),
|
|
276
313
|
name: generateDocumentName(),
|
|
277
314
|
source: { bytes: convertToBase64(part.data) }
|
|
278
315
|
}
|
|
@@ -300,12 +337,9 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
300
337
|
functionality: `media type: ${contentPart.mediaType}`
|
|
301
338
|
});
|
|
302
339
|
}
|
|
303
|
-
const format =
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
functionality: `media type: ${contentPart.mediaType}`
|
|
307
|
-
});
|
|
308
|
-
}
|
|
340
|
+
const format = getBedrockImageFormat(
|
|
341
|
+
contentPart.mediaType
|
|
342
|
+
);
|
|
309
343
|
return {
|
|
310
344
|
image: {
|
|
311
345
|
format,
|
|
@@ -438,8 +472,31 @@ async function convertToBedrockChatMessages(prompt) {
|
|
|
438
472
|
}
|
|
439
473
|
return { system, messages };
|
|
440
474
|
}
|
|
441
|
-
function
|
|
442
|
-
|
|
475
|
+
function getBedrockImageFormat(mimeType) {
|
|
476
|
+
if (!mimeType) {
|
|
477
|
+
throw new UnsupportedFunctionalityError2({
|
|
478
|
+
functionality: "image without mime type",
|
|
479
|
+
message: "Image mime type is required in user message part content"
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
const format = BEDROCK_IMAGE_MIME_TYPES[mimeType];
|
|
483
|
+
if (!format) {
|
|
484
|
+
throw new UnsupportedFunctionalityError2({
|
|
485
|
+
functionality: `image mime type: ${mimeType}`,
|
|
486
|
+
message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(", ")}`
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
return format;
|
|
490
|
+
}
|
|
491
|
+
function getBedrockDocumentFormat(mimeType) {
|
|
492
|
+
const format = BEDROCK_DOCUMENT_MIME_TYPES[mimeType];
|
|
493
|
+
if (!format) {
|
|
494
|
+
throw new UnsupportedFunctionalityError2({
|
|
495
|
+
functionality: `file mime type: ${mimeType}`,
|
|
496
|
+
message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(", ")}`
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
return format;
|
|
443
500
|
}
|
|
444
501
|
function trimIfLast(isLastBlock, isLastMessage, isLastContentPart, text) {
|
|
445
502
|
return isLastBlock && isLastMessage && isLastContentPart ? text.trim() : text;
|
|
@@ -535,7 +592,7 @@ var BedrockChatLanguageModel = class {
|
|
|
535
592
|
toolChoice,
|
|
536
593
|
providerOptions
|
|
537
594
|
}) {
|
|
538
|
-
var _a, _b, _c, _d
|
|
595
|
+
var _a, _b, _c, _d;
|
|
539
596
|
const bedrockOptions = (_a = await parseProviderOptions2({
|
|
540
597
|
provider: "bedrock",
|
|
541
598
|
providerOptions,
|
|
@@ -566,13 +623,27 @@ var BedrockChatLanguageModel = class {
|
|
|
566
623
|
setting: "topK"
|
|
567
624
|
});
|
|
568
625
|
}
|
|
569
|
-
if (responseFormat != null && responseFormat.type !== "text") {
|
|
626
|
+
if (responseFormat != null && responseFormat.type !== "text" && responseFormat.type !== "json") {
|
|
570
627
|
warnings.push({
|
|
571
628
|
type: "unsupported-setting",
|
|
572
629
|
setting: "responseFormat",
|
|
573
|
-
details: "
|
|
630
|
+
details: "Only text and json response formats are supported."
|
|
574
631
|
});
|
|
575
632
|
}
|
|
633
|
+
if (tools != null && (responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
634
|
+
if (tools.length > 0) {
|
|
635
|
+
warnings.push({
|
|
636
|
+
type: "other",
|
|
637
|
+
message: "JSON response format does not support tools. The provided tools are ignored."
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
642
|
+
type: "function",
|
|
643
|
+
name: "json",
|
|
644
|
+
description: "Respond with a JSON object.",
|
|
645
|
+
inputSchema: responseFormat.schema
|
|
646
|
+
} : void 0;
|
|
576
647
|
const { system, messages } = await convertToBedrockChatMessages(prompt);
|
|
577
648
|
const isThinking = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled";
|
|
578
649
|
const thinkingBudget = (_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.budgetTokens;
|
|
@@ -590,7 +661,7 @@ var BedrockChatLanguageModel = class {
|
|
|
590
661
|
}
|
|
591
662
|
bedrockOptions.additionalModelRequestFields = {
|
|
592
663
|
...bedrockOptions.additionalModelRequestFields,
|
|
593
|
-
|
|
664
|
+
thinking: {
|
|
594
665
|
type: (_d = bedrockOptions.reasoningConfig) == null ? void 0 : _d.type,
|
|
595
666
|
budget_tokens: thinkingBudget
|
|
596
667
|
}
|
|
@@ -612,7 +683,12 @@ var BedrockChatLanguageModel = class {
|
|
|
612
683
|
details: "topP is not supported when thinking is enabled"
|
|
613
684
|
});
|
|
614
685
|
}
|
|
615
|
-
const { toolConfig, toolWarnings } = prepareTools({
|
|
686
|
+
const { toolConfig, toolWarnings } = prepareTools({
|
|
687
|
+
tools: jsonResponseTool != null ? [jsonResponseTool] : tools != null ? tools : [],
|
|
688
|
+
toolChoice: jsonResponseTool != null ? { type: "tool", toolName: jsonResponseTool.name } : toolChoice,
|
|
689
|
+
prompt
|
|
690
|
+
});
|
|
691
|
+
const { reasoningConfig: _, ...filteredBedrockOptions } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
|
|
616
692
|
return {
|
|
617
693
|
command: {
|
|
618
694
|
system,
|
|
@@ -621,15 +697,20 @@ var BedrockChatLanguageModel = class {
|
|
|
621
697
|
...Object.keys(inferenceConfig).length > 0 && {
|
|
622
698
|
inferenceConfig
|
|
623
699
|
},
|
|
624
|
-
...
|
|
625
|
-
...
|
|
700
|
+
...filteredBedrockOptions,
|
|
701
|
+
...toolConfig.tools !== void 0 ? { toolConfig } : {}
|
|
626
702
|
},
|
|
627
|
-
warnings: [...warnings, ...toolWarnings]
|
|
703
|
+
warnings: [...warnings, ...toolWarnings],
|
|
704
|
+
usesJsonResponseTool: jsonResponseTool != null
|
|
628
705
|
};
|
|
629
706
|
}
|
|
630
707
|
async doGenerate(options) {
|
|
631
708
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
632
|
-
const {
|
|
709
|
+
const {
|
|
710
|
+
command: args,
|
|
711
|
+
warnings,
|
|
712
|
+
usesJsonResponseTool
|
|
713
|
+
} = await this.getArgs(options);
|
|
633
714
|
const url = `${this.getUrl(this.modelId)}/converse`;
|
|
634
715
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
635
716
|
url,
|
|
@@ -654,7 +735,9 @@ var BedrockChatLanguageModel = class {
|
|
|
654
735
|
const content = [];
|
|
655
736
|
for (const part of response.output.message.content) {
|
|
656
737
|
if (part.text) {
|
|
657
|
-
|
|
738
|
+
if (!usesJsonResponseTool) {
|
|
739
|
+
content.push({ type: "text", text: part.text });
|
|
740
|
+
}
|
|
658
741
|
}
|
|
659
742
|
if (part.reasoningContent) {
|
|
660
743
|
if ("reasoningText" in part.reasoningContent) {
|
|
@@ -683,22 +766,29 @@ var BedrockChatLanguageModel = class {
|
|
|
683
766
|
}
|
|
684
767
|
}
|
|
685
768
|
if (part.toolUse) {
|
|
686
|
-
content.push(
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
769
|
+
content.push(
|
|
770
|
+
// when a json response tool is used, the tool call becomes the text:
|
|
771
|
+
usesJsonResponseTool ? {
|
|
772
|
+
type: "text",
|
|
773
|
+
text: JSON.stringify(part.toolUse.input)
|
|
774
|
+
} : {
|
|
775
|
+
type: "tool-call",
|
|
776
|
+
toolCallId: (_c = (_b = part.toolUse) == null ? void 0 : _b.toolUseId) != null ? _c : this.config.generateId(),
|
|
777
|
+
toolName: (_e = (_d = part.toolUse) == null ? void 0 : _d.name) != null ? _e : `tool-${this.config.generateId()}`,
|
|
778
|
+
input: JSON.stringify((_g = (_f = part.toolUse) == null ? void 0 : _f.input) != null ? _g : "")
|
|
779
|
+
}
|
|
780
|
+
);
|
|
692
781
|
}
|
|
693
782
|
}
|
|
694
|
-
const providerMetadata = response.trace || response.usage ? {
|
|
783
|
+
const providerMetadata = response.trace || response.usage || usesJsonResponseTool ? {
|
|
695
784
|
bedrock: {
|
|
696
785
|
...response.trace && typeof response.trace === "object" ? { trace: response.trace } : {},
|
|
697
786
|
...((_h = response.usage) == null ? void 0 : _h.cacheWriteInputTokens) != null && {
|
|
698
787
|
usage: {
|
|
699
788
|
cacheWriteInputTokens: response.usage.cacheWriteInputTokens
|
|
700
789
|
}
|
|
701
|
-
}
|
|
790
|
+
},
|
|
791
|
+
...usesJsonResponseTool && { isJsonResponseFromTool: true }
|
|
702
792
|
}
|
|
703
793
|
} : void 0;
|
|
704
794
|
return {
|
|
@@ -721,7 +811,11 @@ var BedrockChatLanguageModel = class {
|
|
|
721
811
|
};
|
|
722
812
|
}
|
|
723
813
|
async doStream(options) {
|
|
724
|
-
const {
|
|
814
|
+
const {
|
|
815
|
+
command: args,
|
|
816
|
+
warnings,
|
|
817
|
+
usesJsonResponseTool
|
|
818
|
+
} = await this.getArgs(options);
|
|
725
819
|
const url = `${this.getUrl(this.modelId)}/converse-stream`;
|
|
726
820
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
727
821
|
url,
|
|
@@ -800,11 +894,14 @@ var BedrockChatLanguageModel = class {
|
|
|
800
894
|
const trace = value.metadata.trace ? {
|
|
801
895
|
trace: value.metadata.trace
|
|
802
896
|
} : void 0;
|
|
803
|
-
if (cacheUsage || trace) {
|
|
897
|
+
if (cacheUsage || trace || usesJsonResponseTool) {
|
|
804
898
|
providerMetadata = {
|
|
805
899
|
bedrock: {
|
|
806
900
|
...cacheUsage,
|
|
807
|
-
...trace
|
|
901
|
+
...trace,
|
|
902
|
+
...usesJsonResponseTool && {
|
|
903
|
+
isJsonResponseFromTool: true
|
|
904
|
+
}
|
|
808
905
|
}
|
|
809
906
|
};
|
|
810
907
|
}
|
|
@@ -821,16 +918,20 @@ var BedrockChatLanguageModel = class {
|
|
|
821
918
|
const blockIndex = value.contentBlockDelta.contentBlockIndex || 0;
|
|
822
919
|
if (contentBlocks[blockIndex] == null) {
|
|
823
920
|
contentBlocks[blockIndex] = { type: "text" };
|
|
921
|
+
if (!usesJsonResponseTool) {
|
|
922
|
+
controller.enqueue({
|
|
923
|
+
type: "text-start",
|
|
924
|
+
id: String(blockIndex)
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
if (!usesJsonResponseTool) {
|
|
824
929
|
controller.enqueue({
|
|
825
|
-
type: "text-
|
|
826
|
-
id: String(blockIndex)
|
|
930
|
+
type: "text-delta",
|
|
931
|
+
id: String(blockIndex),
|
|
932
|
+
delta: value.contentBlockDelta.delta.text
|
|
827
933
|
});
|
|
828
934
|
}
|
|
829
|
-
controller.enqueue({
|
|
830
|
-
type: "text-delta",
|
|
831
|
-
id: String(blockIndex),
|
|
832
|
-
delta: value.contentBlockDelta.delta.text
|
|
833
|
-
});
|
|
834
935
|
}
|
|
835
936
|
if (((_n = value.contentBlockStop) == null ? void 0 : _n.contentBlockIndex) != null) {
|
|
836
937
|
const blockIndex = value.contentBlockStop.contentBlockIndex;
|
|
@@ -842,21 +943,39 @@ var BedrockChatLanguageModel = class {
|
|
|
842
943
|
id: String(blockIndex)
|
|
843
944
|
});
|
|
844
945
|
} else if (contentBlock.type === "text") {
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
946
|
+
if (!usesJsonResponseTool) {
|
|
947
|
+
controller.enqueue({
|
|
948
|
+
type: "text-end",
|
|
949
|
+
id: String(blockIndex)
|
|
950
|
+
});
|
|
951
|
+
}
|
|
849
952
|
} else if (contentBlock.type === "tool-call") {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
953
|
+
if (usesJsonResponseTool) {
|
|
954
|
+
controller.enqueue({
|
|
955
|
+
type: "text-start",
|
|
956
|
+
id: String(blockIndex)
|
|
957
|
+
});
|
|
958
|
+
controller.enqueue({
|
|
959
|
+
type: "text-delta",
|
|
960
|
+
id: String(blockIndex),
|
|
961
|
+
delta: contentBlock.jsonText
|
|
962
|
+
});
|
|
963
|
+
controller.enqueue({
|
|
964
|
+
type: "text-end",
|
|
965
|
+
id: String(blockIndex)
|
|
966
|
+
});
|
|
967
|
+
} else {
|
|
968
|
+
controller.enqueue({
|
|
969
|
+
type: "tool-input-end",
|
|
970
|
+
id: contentBlock.toolCallId
|
|
971
|
+
});
|
|
972
|
+
controller.enqueue({
|
|
973
|
+
type: "tool-call",
|
|
974
|
+
toolCallId: contentBlock.toolCallId,
|
|
975
|
+
toolName: contentBlock.toolName,
|
|
976
|
+
input: contentBlock.jsonText
|
|
977
|
+
});
|
|
978
|
+
}
|
|
860
979
|
}
|
|
861
980
|
delete contentBlocks[blockIndex];
|
|
862
981
|
}
|
|
@@ -911,11 +1030,13 @@ var BedrockChatLanguageModel = class {
|
|
|
911
1030
|
toolName: toolUse.name,
|
|
912
1031
|
jsonText: ""
|
|
913
1032
|
};
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1033
|
+
if (!usesJsonResponseTool) {
|
|
1034
|
+
controller.enqueue({
|
|
1035
|
+
type: "tool-input-start",
|
|
1036
|
+
id: toolUse.toolUseId,
|
|
1037
|
+
toolName: toolUse.name
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
919
1040
|
}
|
|
920
1041
|
const contentBlockDelta = value.contentBlockDelta;
|
|
921
1042
|
if ((contentBlockDelta == null ? void 0 : contentBlockDelta.delta) && "toolUse" in contentBlockDelta.delta && contentBlockDelta.delta.toolUse) {
|
|
@@ -923,11 +1044,13 @@ var BedrockChatLanguageModel = class {
|
|
|
923
1044
|
const contentBlock = contentBlocks[blockIndex];
|
|
924
1045
|
if ((contentBlock == null ? void 0 : contentBlock.type) === "tool-call") {
|
|
925
1046
|
const delta = (_q = contentBlockDelta.delta.toolUse.input) != null ? _q : "";
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1047
|
+
if (!usesJsonResponseTool) {
|
|
1048
|
+
controller.enqueue({
|
|
1049
|
+
type: "tool-input-delta",
|
|
1050
|
+
id: contentBlock.toolCallId,
|
|
1051
|
+
delta
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
931
1054
|
contentBlock.jsonText += delta;
|
|
932
1055
|
}
|
|
933
1056
|
}
|
|
@@ -1028,9 +1151,9 @@ var BedrockStreamSchema = z3.object({
|
|
|
1028
1151
|
contentBlockStop: z3.object({
|
|
1029
1152
|
contentBlockIndex: z3.number()
|
|
1030
1153
|
}).nullish(),
|
|
1031
|
-
internalServerException: z3.record(z3.unknown()).nullish(),
|
|
1154
|
+
internalServerException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1032
1155
|
messageStop: z3.object({
|
|
1033
|
-
additionalModelResponseFields: z3.record(z3.unknown()).nullish(),
|
|
1156
|
+
additionalModelResponseFields: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1034
1157
|
stopReason: BedrockStopReasonSchema
|
|
1035
1158
|
}).nullish(),
|
|
1036
1159
|
metadata: z3.object({
|
|
@@ -1042,9 +1165,9 @@ var BedrockStreamSchema = z3.object({
|
|
|
1042
1165
|
outputTokens: z3.number()
|
|
1043
1166
|
}).nullish()
|
|
1044
1167
|
}).nullish(),
|
|
1045
|
-
modelStreamErrorException: z3.record(z3.unknown()).nullish(),
|
|
1046
|
-
throttlingException: z3.record(z3.unknown()).nullish(),
|
|
1047
|
-
validationException: z3.record(z3.unknown()).nullish()
|
|
1168
|
+
modelStreamErrorException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1169
|
+
throttlingException: z3.record(z3.string(), z3.unknown()).nullish(),
|
|
1170
|
+
validationException: z3.record(z3.string(), z3.unknown()).nullish()
|
|
1048
1171
|
});
|
|
1049
1172
|
var bedrockReasoningMetadataSchema = z3.object({
|
|
1050
1173
|
signature: z3.string().optional(),
|
|
@@ -1065,7 +1188,7 @@ import {
|
|
|
1065
1188
|
} from "@ai-sdk/provider-utils";
|
|
1066
1189
|
|
|
1067
1190
|
// src/bedrock-embedding-options.ts
|
|
1068
|
-
import { z as z4 } from "zod";
|
|
1191
|
+
import { z as z4 } from "zod/v4";
|
|
1069
1192
|
var bedrockEmbeddingProviderOptions = z4.object({
|
|
1070
1193
|
/**
|
|
1071
1194
|
The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
@@ -1080,7 +1203,7 @@ var bedrockEmbeddingProviderOptions = z4.object({
|
|
|
1080
1203
|
});
|
|
1081
1204
|
|
|
1082
1205
|
// src/bedrock-embedding-model.ts
|
|
1083
|
-
import { z as z5 } from "zod";
|
|
1206
|
+
import { z as z5 } from "zod/v4";
|
|
1084
1207
|
var BedrockEmbeddingModel = class {
|
|
1085
1208
|
constructor(modelId, config) {
|
|
1086
1209
|
this.modelId = modelId;
|
|
@@ -1162,7 +1285,7 @@ var modelMaxImagesPerCall = {
|
|
|
1162
1285
|
};
|
|
1163
1286
|
|
|
1164
1287
|
// src/bedrock-image-model.ts
|
|
1165
|
-
import { z as z6 } from "zod";
|
|
1288
|
+
import { z as z6 } from "zod/v4";
|
|
1166
1289
|
var BedrockImageModel = class {
|
|
1167
1290
|
constructor(modelId, config) {
|
|
1168
1291
|
this.modelId = modelId;
|
|
@@ -1188,7 +1311,7 @@ var BedrockImageModel = class {
|
|
|
1188
1311
|
headers,
|
|
1189
1312
|
abortSignal
|
|
1190
1313
|
}) {
|
|
1191
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1314
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1192
1315
|
const warnings = [];
|
|
1193
1316
|
const [width, height] = size ? size.split("x").map(Number) : [];
|
|
1194
1317
|
const args = {
|
|
@@ -1197,6 +1320,9 @@ var BedrockImageModel = class {
|
|
|
1197
1320
|
text: prompt,
|
|
1198
1321
|
...((_a = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _a.negativeText) ? {
|
|
1199
1322
|
negativeText: providerOptions.bedrock.negativeText
|
|
1323
|
+
} : {},
|
|
1324
|
+
...((_b = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _b.style) ? {
|
|
1325
|
+
style: providerOptions.bedrock.style
|
|
1200
1326
|
} : {}
|
|
1201
1327
|
},
|
|
1202
1328
|
imageGenerationConfig: {
|
|
@@ -1204,8 +1330,8 @@ var BedrockImageModel = class {
|
|
|
1204
1330
|
...height ? { height } : {},
|
|
1205
1331
|
...seed ? { seed } : {},
|
|
1206
1332
|
...n ? { numberOfImages: n } : {},
|
|
1207
|
-
...((
|
|
1208
|
-
...((
|
|
1333
|
+
...((_c = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _c.quality) ? { quality: providerOptions.bedrock.quality } : {},
|
|
1334
|
+
...((_d = providerOptions == null ? void 0 : providerOptions.bedrock) == null ? void 0 : _d.cfgScale) ? { cfgScale: providerOptions.bedrock.cfgScale } : {}
|
|
1209
1335
|
}
|
|
1210
1336
|
};
|
|
1211
1337
|
if (aspectRatio != void 0) {
|
|
@@ -1215,7 +1341,7 @@ var BedrockImageModel = class {
|
|
|
1215
1341
|
details: "This model does not support aspect ratio. Use `size` instead."
|
|
1216
1342
|
});
|
|
1217
1343
|
}
|
|
1218
|
-
const currentDate = (
|
|
1344
|
+
const currentDate = (_g = (_f = (_e = this.config._internal) == null ? void 0 : _e.currentDate) == null ? void 0 : _f.call(_e)) != null ? _g : /* @__PURE__ */ new Date();
|
|
1219
1345
|
const { value: response, responseHeaders } = await postJsonToApi3({
|
|
1220
1346
|
url: this.getUrl(this.modelId),
|
|
1221
1347
|
headers: await resolve3(
|
|
@@ -1318,10 +1444,28 @@ function prepareBodyString(body) {
|
|
|
1318
1444
|
return JSON.stringify(body);
|
|
1319
1445
|
}
|
|
1320
1446
|
}
|
|
1447
|
+
function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
|
|
1448
|
+
return async (input, init) => {
|
|
1449
|
+
const originalHeaders = extractHeaders(init == null ? void 0 : init.headers);
|
|
1450
|
+
return fetch(input, {
|
|
1451
|
+
...init,
|
|
1452
|
+
headers: removeUndefinedEntries(
|
|
1453
|
+
combineHeaders4(originalHeaders, {
|
|
1454
|
+
Authorization: `Bearer ${apiKey}`
|
|
1455
|
+
})
|
|
1456
|
+
)
|
|
1457
|
+
});
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1321
1460
|
|
|
1322
1461
|
// src/bedrock-provider.ts
|
|
1323
1462
|
function createAmazonBedrock(options = {}) {
|
|
1324
|
-
const
|
|
1463
|
+
const rawApiKey = loadOptionalSetting({
|
|
1464
|
+
settingValue: options.apiKey,
|
|
1465
|
+
environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
|
|
1466
|
+
});
|
|
1467
|
+
const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
|
|
1468
|
+
const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
1325
1469
|
const region = loadSetting({
|
|
1326
1470
|
settingValue: options.region,
|
|
1327
1471
|
settingName: "region",
|
|
@@ -1329,30 +1473,58 @@ function createAmazonBedrock(options = {}) {
|
|
|
1329
1473
|
description: "AWS region"
|
|
1330
1474
|
});
|
|
1331
1475
|
if (options.credentialProvider) {
|
|
1476
|
+
try {
|
|
1477
|
+
return {
|
|
1478
|
+
...await options.credentialProvider(),
|
|
1479
|
+
region
|
|
1480
|
+
};
|
|
1481
|
+
} catch (error) {
|
|
1482
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1483
|
+
throw new Error(
|
|
1484
|
+
`AWS credential provider failed: ${errorMessage}. Please ensure your credential provider returns valid AWS credentials with accessKeyId and secretAccessKey properties.`
|
|
1485
|
+
);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
try {
|
|
1332
1489
|
return {
|
|
1333
|
-
|
|
1334
|
-
|
|
1490
|
+
region,
|
|
1491
|
+
accessKeyId: loadSetting({
|
|
1492
|
+
settingValue: options.accessKeyId,
|
|
1493
|
+
settingName: "accessKeyId",
|
|
1494
|
+
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
1495
|
+
description: "AWS access key ID"
|
|
1496
|
+
}),
|
|
1497
|
+
secretAccessKey: loadSetting({
|
|
1498
|
+
settingValue: options.secretAccessKey,
|
|
1499
|
+
settingName: "secretAccessKey",
|
|
1500
|
+
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
1501
|
+
description: "AWS secret access key"
|
|
1502
|
+
}),
|
|
1503
|
+
sessionToken: loadOptionalSetting({
|
|
1504
|
+
settingValue: options.sessionToken,
|
|
1505
|
+
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
1506
|
+
})
|
|
1335
1507
|
};
|
|
1508
|
+
} catch (error) {
|
|
1509
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1510
|
+
if (errorMessage.includes("AWS_ACCESS_KEY_ID") || errorMessage.includes("accessKeyId")) {
|
|
1511
|
+
throw new Error(
|
|
1512
|
+
`AWS SigV4 authentication requires AWS credentials. Please provide either:
|
|
1513
|
+
1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
|
|
1514
|
+
2. Provide accessKeyId and secretAccessKey in options
|
|
1515
|
+
3. Use a credentialProvider function
|
|
1516
|
+
4. Use API key authentication with AWS_BEARER_TOKEN_BEDROCK or apiKey option
|
|
1517
|
+
Original error: ${errorMessage}`
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
if (errorMessage.includes("AWS_SECRET_ACCESS_KEY") || errorMessage.includes("secretAccessKey")) {
|
|
1521
|
+
throw new Error(
|
|
1522
|
+
`AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Please ensure both credentials are provided.
|
|
1523
|
+
Original error: ${errorMessage}`
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
throw error;
|
|
1336
1527
|
}
|
|
1337
|
-
return {
|
|
1338
|
-
region,
|
|
1339
|
-
accessKeyId: loadSetting({
|
|
1340
|
-
settingValue: options.accessKeyId,
|
|
1341
|
-
settingName: "accessKeyId",
|
|
1342
|
-
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
1343
|
-
description: "AWS access key ID"
|
|
1344
|
-
}),
|
|
1345
|
-
secretAccessKey: loadSetting({
|
|
1346
|
-
settingValue: options.secretAccessKey,
|
|
1347
|
-
settingName: "secretAccessKey",
|
|
1348
|
-
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
1349
|
-
description: "AWS secret access key"
|
|
1350
|
-
}),
|
|
1351
|
-
sessionToken: loadOptionalSetting({
|
|
1352
|
-
settingValue: options.sessionToken,
|
|
1353
|
-
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
1354
|
-
})
|
|
1355
|
-
};
|
|
1356
1528
|
}, options.fetch);
|
|
1357
1529
|
const getBaseUrl = () => {
|
|
1358
1530
|
var _a, _b;
|
|
@@ -1370,7 +1542,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1370
1542
|
return new BedrockChatLanguageModel(modelId, {
|
|
1371
1543
|
baseUrl: getBaseUrl,
|
|
1372
1544
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1373
|
-
fetch:
|
|
1545
|
+
fetch: fetchFunction,
|
|
1374
1546
|
generateId
|
|
1375
1547
|
});
|
|
1376
1548
|
};
|
|
@@ -1387,7 +1559,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1387
1559
|
return new BedrockEmbeddingModel(modelId, {
|
|
1388
1560
|
baseUrl: getBaseUrl,
|
|
1389
1561
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1390
|
-
fetch:
|
|
1562
|
+
fetch: fetchFunction
|
|
1391
1563
|
});
|
|
1392
1564
|
};
|
|
1393
1565
|
const createImageModel = (modelId) => {
|
|
@@ -1395,7 +1567,7 @@ function createAmazonBedrock(options = {}) {
|
|
|
1395
1567
|
return new BedrockImageModel(modelId, {
|
|
1396
1568
|
baseUrl: getBaseUrl,
|
|
1397
1569
|
headers: (_a = options.headers) != null ? _a : {},
|
|
1398
|
-
fetch:
|
|
1570
|
+
fetch: fetchFunction
|
|
1399
1571
|
});
|
|
1400
1572
|
};
|
|
1401
1573
|
provider.languageModel = createChatModel;
|