@ai-sdk/amazon-bedrock 5.0.36 → 5.0.38
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 +18 -0
- package/dist/anthropic/index.js +1 -1
- package/dist/index.js +154 -72
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +1 -1
- package/dist/mantle/index.js +1 -1
- package/package.json +5 -5
- package/src/amazon-bedrock-api-types.ts +37 -0
- package/src/amazon-bedrock-chat-language-model.ts +6 -3
- package/src/amazon-bedrock-prepare-tools.ts +8 -0
- package/src/convert-to-amazon-bedrock-chat-messages.ts +161 -88
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ai-sdk/amazon-bedrock
|
|
2
2
|
|
|
3
|
+
## 5.0.38
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 52e22a7: feat(bedrock): support video inputs in Converse messages
|
|
8
|
+
|
|
9
|
+
## 5.0.37
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ebd31b8: fix(amazon-bedrock): warn when unsupported strict tools are omitted and align structured output fallback routing
|
|
14
|
+
- Updated dependencies [d8210b6]
|
|
15
|
+
- Updated dependencies [beaecb3]
|
|
16
|
+
- Updated dependencies [b192878]
|
|
17
|
+
- @ai-sdk/provider-utils@5.0.16
|
|
18
|
+
- @ai-sdk/anthropic@4.0.25
|
|
19
|
+
- @ai-sdk/openai@4.0.25
|
|
20
|
+
|
|
3
21
|
## 5.0.36
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/anthropic/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import { AwsV4Signer } from "aws4fetch";
|
|
25
25
|
|
|
26
26
|
// src/version.ts
|
|
27
|
-
var VERSION = true ? "5.0.
|
|
27
|
+
var VERSION = true ? "5.0.38" : "0.0.0-test";
|
|
28
28
|
|
|
29
29
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
30
30
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,18 @@ var BEDROCK_DOCUMENT_MIME_TYPES = {
|
|
|
60
60
|
"text/plain": "txt",
|
|
61
61
|
"text/markdown": "md"
|
|
62
62
|
};
|
|
63
|
+
var BEDROCK_VIDEO_MIME_TYPES = {
|
|
64
|
+
"video/x-matroska": "mkv",
|
|
65
|
+
"video/quicktime": "mov",
|
|
66
|
+
"video/mp4": "mp4",
|
|
67
|
+
"video/webm": "webm",
|
|
68
|
+
"video/x-flv": "flv",
|
|
69
|
+
"video/mpeg": "mpeg",
|
|
70
|
+
"video/mpg": "mpg",
|
|
71
|
+
"video/wmv": "wmv",
|
|
72
|
+
"video/x-ms-wmv": "wmv",
|
|
73
|
+
"video/3gpp": "three_gp"
|
|
74
|
+
};
|
|
63
75
|
|
|
64
76
|
// src/amazon-bedrock-chat-language-model-options.ts
|
|
65
77
|
import { z } from "zod/v4";
|
|
@@ -319,6 +331,13 @@ async function prepareTools({
|
|
|
319
331
|
const filteredFunctionTools = (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? functionTools.filter((t) => t.name === toolChoice.toolName) : functionTools;
|
|
320
332
|
const supportsStrictOnTools = supportsStrictTools(modelId);
|
|
321
333
|
for (const tool of filteredFunctionTools) {
|
|
334
|
+
if (!supportsStrictOnTools && tool.strict != null) {
|
|
335
|
+
toolWarnings.push({
|
|
336
|
+
type: "unsupported",
|
|
337
|
+
feature: "strict",
|
|
338
|
+
details: `Tool '${tool.name}' has strict: ${tool.strict}, but strict mode is not supported by this model on Amazon Bedrock. The strict property will be ignored.`
|
|
339
|
+
});
|
|
340
|
+
}
|
|
322
341
|
amazonBedrockTools.push({
|
|
323
342
|
toolSpec: {
|
|
324
343
|
name: tool.name,
|
|
@@ -453,7 +472,7 @@ function pushCachePoint(content, providerMetadata) {
|
|
|
453
472
|
function sanitizeToolName(toolName) {
|
|
454
473
|
return toolName.replace(/[^a-zA-Z0-9_-]/g, "") || "_";
|
|
455
474
|
}
|
|
456
|
-
function
|
|
475
|
+
function getAmazonBedrockMediaSource({
|
|
457
476
|
data,
|
|
458
477
|
functionality
|
|
459
478
|
}) {
|
|
@@ -540,20 +559,37 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
540
559
|
});
|
|
541
560
|
}
|
|
542
561
|
const fullMediaType = resolveFullMediaType({ part });
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
562
|
+
switch (getTopLevelMediaType(fullMediaType)) {
|
|
563
|
+
case "image": {
|
|
564
|
+
amazonBedrockContent.push({
|
|
565
|
+
image: {
|
|
566
|
+
format: getAmazonBedrockImageFormat(fullMediaType),
|
|
567
|
+
source: getAmazonBedrockMediaSource({
|
|
568
|
+
data: part.data,
|
|
569
|
+
functionality: "File URL data"
|
|
570
|
+
})
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
case "video": {
|
|
576
|
+
amazonBedrockContent.push({
|
|
577
|
+
video: {
|
|
578
|
+
format: getAmazonBedrockVideoFormat(fullMediaType),
|
|
579
|
+
source: getAmazonBedrockMediaSource({
|
|
580
|
+
data: part.data,
|
|
581
|
+
functionality: "File URL data"
|
|
582
|
+
})
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
default: {
|
|
588
|
+
throw new UnsupportedFunctionalityError2({
|
|
553
589
|
functionality: "File URL data"
|
|
554
|
-
})
|
|
590
|
+
});
|
|
555
591
|
}
|
|
556
|
-
}
|
|
592
|
+
}
|
|
557
593
|
break;
|
|
558
594
|
}
|
|
559
595
|
case "text": {
|
|
@@ -579,32 +615,48 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
579
615
|
}
|
|
580
616
|
case "data": {
|
|
581
617
|
const fullMediaType = resolveFullMediaType({ part });
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
});
|
|
592
|
-
} else {
|
|
593
|
-
const enableCitations = await shouldEnableCitations(
|
|
594
|
-
part.providerOptions
|
|
595
|
-
);
|
|
596
|
-
amazonBedrockContent.push({
|
|
597
|
-
document: {
|
|
598
|
-
format: getAmazonBedrockDocumentFormat(fullMediaType),
|
|
599
|
-
name: part.filename ? stripFileExtension(part.filename) : generateDocumentName(),
|
|
600
|
-
source: {
|
|
601
|
-
bytes: convertToBase64(part.data.data)
|
|
602
|
-
},
|
|
603
|
-
...enableCitations && {
|
|
604
|
-
citations: { enabled: true }
|
|
618
|
+
switch (getTopLevelMediaType(fullMediaType)) {
|
|
619
|
+
case "image": {
|
|
620
|
+
amazonBedrockContent.push({
|
|
621
|
+
image: {
|
|
622
|
+
format: getAmazonBedrockImageFormat(fullMediaType),
|
|
623
|
+
source: getAmazonBedrockMediaSource({
|
|
624
|
+
data: part.data,
|
|
625
|
+
functionality: "File URL data"
|
|
626
|
+
})
|
|
605
627
|
}
|
|
606
|
-
}
|
|
607
|
-
|
|
628
|
+
});
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
case "video": {
|
|
632
|
+
amazonBedrockContent.push({
|
|
633
|
+
video: {
|
|
634
|
+
format: getAmazonBedrockVideoFormat(fullMediaType),
|
|
635
|
+
source: getAmazonBedrockMediaSource({
|
|
636
|
+
data: part.data,
|
|
637
|
+
functionality: "File URL data"
|
|
638
|
+
})
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
default: {
|
|
644
|
+
const enableCitations = await shouldEnableCitations(
|
|
645
|
+
part.providerOptions
|
|
646
|
+
);
|
|
647
|
+
amazonBedrockContent.push({
|
|
648
|
+
document: {
|
|
649
|
+
format: getAmazonBedrockDocumentFormat(fullMediaType),
|
|
650
|
+
name: part.filename ? stripFileExtension(part.filename) : generateDocumentName(),
|
|
651
|
+
source: {
|
|
652
|
+
bytes: convertToBase64(part.data.data)
|
|
653
|
+
},
|
|
654
|
+
...enableCitations && {
|
|
655
|
+
citations: { enabled: true }
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
}
|
|
608
660
|
}
|
|
609
661
|
break;
|
|
610
662
|
}
|
|
@@ -639,41 +691,60 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
|
|
|
639
691
|
const fullMediaType = resolveFullMediaType({
|
|
640
692
|
part: contentPart
|
|
641
693
|
});
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
694
|
+
switch (getTopLevelMediaType(fullMediaType)) {
|
|
695
|
+
case "image": {
|
|
696
|
+
return {
|
|
697
|
+
image: {
|
|
698
|
+
format: getAmazonBedrockImageFormat(
|
|
699
|
+
fullMediaType
|
|
700
|
+
),
|
|
701
|
+
source: getAmazonBedrockMediaSource({
|
|
702
|
+
data: contentPart.data,
|
|
703
|
+
functionality: `tool result file data of type "${contentPart.data.type}"`
|
|
704
|
+
})
|
|
705
|
+
}
|
|
706
|
+
};
|
|
647
707
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
bytes: convertToBase64(
|
|
659
|
-
contentPart.data.data
|
|
660
|
-
)
|
|
661
|
-
},
|
|
662
|
-
...enableCitations && {
|
|
663
|
-
citations: { enabled: true }
|
|
708
|
+
case "video": {
|
|
709
|
+
return {
|
|
710
|
+
video: {
|
|
711
|
+
format: getAmazonBedrockVideoFormat(
|
|
712
|
+
fullMediaType
|
|
713
|
+
),
|
|
714
|
+
source: getAmazonBedrockMediaSource({
|
|
715
|
+
data: contentPart.data,
|
|
716
|
+
functionality: `tool result file data of type "${contentPart.data.type}"`
|
|
717
|
+
})
|
|
664
718
|
}
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
default: {
|
|
722
|
+
if (contentPart.data.type !== "data") {
|
|
723
|
+
throw new UnsupportedFunctionalityError2({
|
|
724
|
+
functionality: `tool result file data of type "${contentPart.data.type}"`
|
|
725
|
+
});
|
|
665
726
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
727
|
+
const enableCitations = await shouldEnableCitations(
|
|
728
|
+
contentPart.providerOptions
|
|
729
|
+
);
|
|
730
|
+
return {
|
|
731
|
+
document: {
|
|
732
|
+
format: getAmazonBedrockDocumentFormat(
|
|
733
|
+
fullMediaType
|
|
734
|
+
),
|
|
735
|
+
name: contentPart.filename ? stripFileExtension(contentPart.filename) : generateDocumentName(),
|
|
736
|
+
source: {
|
|
737
|
+
bytes: convertToBase64(
|
|
738
|
+
contentPart.data.data
|
|
739
|
+
)
|
|
740
|
+
},
|
|
741
|
+
...enableCitations && {
|
|
742
|
+
citations: { enabled: true }
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
};
|
|
675
746
|
}
|
|
676
|
-
}
|
|
747
|
+
}
|
|
677
748
|
}
|
|
678
749
|
default: {
|
|
679
750
|
throw new UnsupportedFunctionalityError2({
|
|
@@ -833,6 +904,16 @@ function getAmazonBedrockDocumentFormat(mimeType) {
|
|
|
833
904
|
}
|
|
834
905
|
return format;
|
|
835
906
|
}
|
|
907
|
+
function getAmazonBedrockVideoFormat(mimeType) {
|
|
908
|
+
const format = BEDROCK_VIDEO_MIME_TYPES[mimeType];
|
|
909
|
+
if (!format) {
|
|
910
|
+
throw new UnsupportedFunctionalityError2({
|
|
911
|
+
functionality: `video mime type: ${mimeType}`,
|
|
912
|
+
message: `Unsupported video mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_VIDEO_MIME_TYPES).join(", ")}`
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
return format;
|
|
916
|
+
}
|
|
836
917
|
function trimIfLast(isLastBlock, isLastMessage, isLastContentPart, text) {
|
|
837
918
|
return isLastBlock && isLastMessage && isLastContentPart ? text.trim() : text;
|
|
838
919
|
}
|
|
@@ -909,7 +990,8 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
909
990
|
this.specificationVersion = "v4";
|
|
910
991
|
this.provider = "amazon-bedrock";
|
|
911
992
|
this.supportedUrls = {
|
|
912
|
-
"image/*": [/^s3:\/\//]
|
|
993
|
+
"image/*": [/^s3:\/\//],
|
|
994
|
+
"video/*": [/^s3:\/\//]
|
|
913
995
|
};
|
|
914
996
|
}
|
|
915
997
|
static [WORKFLOW_SERIALIZE](model) {
|
|
@@ -1000,7 +1082,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
|
|
|
1000
1082
|
const isThinkingEnabled = ((_c = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "enabled" || ((_d = amazonBedrockOptions.reasoningConfig) == null ? void 0 : _d.type) === "adaptive";
|
|
1001
1083
|
const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
|
|
1002
1084
|
const useNativeStructuredOutput = isAnthropicModel && supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
|
|
1003
|
-
const useJsonInstructionForStructuredOutput = isAnthropicModel && (this.modelId
|
|
1085
|
+
const useJsonInstructionForStructuredOutput = isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
|
|
1004
1086
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
|
|
1005
1087
|
type: "function",
|
|
1006
1088
|
name: "json",
|
|
@@ -2411,7 +2493,7 @@ import {
|
|
|
2411
2493
|
import { AwsV4Signer } from "aws4fetch";
|
|
2412
2494
|
|
|
2413
2495
|
// src/version.ts
|
|
2414
|
-
var VERSION = true ? "5.0.
|
|
2496
|
+
var VERSION = true ? "5.0.38" : "0.0.0-test";
|
|
2415
2497
|
|
|
2416
2498
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
2417
2499
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|