@ai-sdk/amazon-bedrock 5.0.37 → 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 CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 5.0.37
4
10
 
5
11
  ### Patch Changes
@@ -24,7 +24,7 @@ import {
24
24
  import { AwsV4Signer } from "aws4fetch";
25
25
 
26
26
  // src/version.ts
27
- var VERSION = true ? "5.0.37" : "0.0.0-test";
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";
@@ -460,7 +472,7 @@ function pushCachePoint(content, providerMetadata) {
460
472
  function sanitizeToolName(toolName) {
461
473
  return toolName.replace(/[^a-zA-Z0-9_-]/g, "") || "_";
462
474
  }
463
- function getAmazonBedrockImageSource({
475
+ function getAmazonBedrockMediaSource({
464
476
  data,
465
477
  functionality
466
478
  }) {
@@ -547,20 +559,37 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
547
559
  });
548
560
  }
549
561
  const fullMediaType = resolveFullMediaType({ part });
550
- if (getTopLevelMediaType(fullMediaType) !== "image") {
551
- throw new UnsupportedFunctionalityError2({
552
- functionality: "File URL data"
553
- });
554
- }
555
- amazonBedrockContent.push({
556
- image: {
557
- format: getAmazonBedrockImageFormat(fullMediaType),
558
- source: getAmazonBedrockImageSource({
559
- data: part.data,
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({
560
589
  functionality: "File URL data"
561
- })
590
+ });
562
591
  }
563
- });
592
+ }
564
593
  break;
565
594
  }
566
595
  case "text": {
@@ -586,32 +615,48 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
586
615
  }
587
616
  case "data": {
588
617
  const fullMediaType = resolveFullMediaType({ part });
589
- if (getTopLevelMediaType(fullMediaType) === "image") {
590
- amazonBedrockContent.push({
591
- image: {
592
- format: getAmazonBedrockImageFormat(fullMediaType),
593
- source: getAmazonBedrockImageSource({
594
- data: part.data,
595
- functionality: "File URL data"
596
- })
597
- }
598
- });
599
- } else {
600
- const enableCitations = await shouldEnableCitations(
601
- part.providerOptions
602
- );
603
- amazonBedrockContent.push({
604
- document: {
605
- format: getAmazonBedrockDocumentFormat(fullMediaType),
606
- name: part.filename ? stripFileExtension(part.filename) : generateDocumentName(),
607
- source: {
608
- bytes: convertToBase64(part.data.data)
609
- },
610
- ...enableCitations && {
611
- 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
+ })
612
627
  }
613
- }
614
- });
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
+ }
615
660
  }
616
661
  break;
617
662
  }
@@ -646,41 +691,60 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
646
691
  const fullMediaType = resolveFullMediaType({
647
692
  part: contentPart
648
693
  });
649
- if (getTopLevelMediaType(fullMediaType) !== "image") {
650
- if (contentPart.data.type !== "data") {
651
- throw new UnsupportedFunctionalityError2({
652
- functionality: `tool result file data of type "${contentPart.data.type}"`
653
- });
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
+ };
654
707
  }
655
- const enableCitations = await shouldEnableCitations(
656
- contentPart.providerOptions
657
- );
658
- return {
659
- document: {
660
- format: getAmazonBedrockDocumentFormat(
661
- fullMediaType
662
- ),
663
- name: contentPart.filename ? stripFileExtension(contentPart.filename) : generateDocumentName(),
664
- source: {
665
- bytes: convertToBase64(
666
- contentPart.data.data
667
- )
668
- },
669
- ...enableCitations && {
670
- 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
+ })
671
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
+ });
672
726
  }
673
- };
674
- }
675
- return {
676
- image: {
677
- format: getAmazonBedrockImageFormat(fullMediaType),
678
- source: getAmazonBedrockImageSource({
679
- data: contentPart.data,
680
- functionality: `tool result file data of type "${contentPart.data.type}"`
681
- })
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
+ };
682
746
  }
683
- };
747
+ }
684
748
  }
685
749
  default: {
686
750
  throw new UnsupportedFunctionalityError2({
@@ -840,6 +904,16 @@ function getAmazonBedrockDocumentFormat(mimeType) {
840
904
  }
841
905
  return format;
842
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
+ }
843
917
  function trimIfLast(isLastBlock, isLastMessage, isLastContentPart, text) {
844
918
  return isLastBlock && isLastMessage && isLastContentPart ? text.trim() : text;
845
919
  }
@@ -916,7 +990,8 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
916
990
  this.specificationVersion = "v4";
917
991
  this.provider = "amazon-bedrock";
918
992
  this.supportedUrls = {
919
- "image/*": [/^s3:\/\//]
993
+ "image/*": [/^s3:\/\//],
994
+ "video/*": [/^s3:\/\//]
920
995
  };
921
996
  }
922
997
  static [WORKFLOW_SERIALIZE](model) {
@@ -2418,7 +2493,7 @@ import {
2418
2493
  import { AwsV4Signer } from "aws4fetch";
2419
2494
 
2420
2495
  // src/version.ts
2421
- var VERSION = true ? "5.0.37" : "0.0.0-test";
2496
+ var VERSION = true ? "5.0.38" : "0.0.0-test";
2422
2497
 
2423
2498
  // src/amazon-bedrock-sigv4-fetch.ts
2424
2499
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {