@ai-sdk/amazon-bedrock 5.0.26 → 5.0.28

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,21 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 5.0.28
4
+
5
+ ### Patch Changes
6
+
7
+ - 1f92bdb: Pass through `s3://` image URLs to Amazon Bedrock Converse as S3 image sources instead of downloading them.
8
+ - 8fcb72c: Sanitize invalid characters in replayed tool call names before sending conversation history to Amazon Bedrock.
9
+ - Updated dependencies [bc43dc2]
10
+ - @ai-sdk/openai@4.0.18
11
+
12
+ ## 5.0.27
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [97de198]
17
+ - @ai-sdk/anthropic@4.0.18
18
+
3
19
  ## 5.0.26
4
20
 
5
21
  ### 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.26" : "0.0.0-test";
27
+ var VERSION = true ? "5.0.28" : "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
@@ -430,6 +430,27 @@ function pushCachePoint(content, providerMetadata) {
430
430
  content.push(cachePoint);
431
431
  }
432
432
  }
433
+ function sanitizeToolName(toolName) {
434
+ return toolName.replace(/[^a-zA-Z0-9_-]/g, "") || "_";
435
+ }
436
+ function getAmazonBedrockImageSource({
437
+ data,
438
+ functionality
439
+ }) {
440
+ switch (data.type) {
441
+ case "data":
442
+ return { bytes: convertToBase64(data.data) };
443
+ case "url":
444
+ if (data.url.protocol !== "s3:") {
445
+ throw new UnsupportedFunctionalityError2({ functionality });
446
+ }
447
+ return {
448
+ s3Location: {
449
+ uri: data.url.toString()
450
+ }
451
+ };
452
+ }
453
+ }
433
454
  async function shouldEnableCitations(providerMetadata) {
434
455
  var _a, _b, _c;
435
456
  const amazonBedrockOptions = (_a = await parseProviderOptions({
@@ -493,9 +514,27 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
493
514
  });
494
515
  }
495
516
  case "url": {
496
- throw new UnsupportedFunctionalityError2({
497
- functionality: "File URL data"
517
+ if (part.data.url.protocol !== "s3:") {
518
+ throw new UnsupportedFunctionalityError2({
519
+ functionality: "File URL data"
520
+ });
521
+ }
522
+ const fullMediaType = resolveFullMediaType({ part });
523
+ if (getTopLevelMediaType(fullMediaType) !== "image") {
524
+ throw new UnsupportedFunctionalityError2({
525
+ functionality: "File URL data"
526
+ });
527
+ }
528
+ amazonBedrockContent.push({
529
+ image: {
530
+ format: getAmazonBedrockImageFormat(fullMediaType),
531
+ source: getAmazonBedrockImageSource({
532
+ data: part.data,
533
+ functionality: "File URL data"
534
+ })
535
+ }
498
536
  });
537
+ break;
499
538
  }
500
539
  case "text": {
501
540
  const textMediaType = isFullMediaType(part.mediaType) ? part.mediaType : "text/plain";
@@ -524,9 +563,10 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
524
563
  amazonBedrockContent.push({
525
564
  image: {
526
565
  format: getAmazonBedrockImageFormat(fullMediaType),
527
- source: {
528
- bytes: convertToBase64(part.data.data)
529
- }
566
+ source: getAmazonBedrockImageSource({
567
+ data: part.data,
568
+ functionality: "File URL data"
569
+ })
530
570
  }
531
571
  });
532
572
  } else {
@@ -571,7 +611,7 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
571
611
  case "text":
572
612
  return { text: contentPart.text };
573
613
  case "file": {
574
- if (contentPart.data.type !== "data") {
614
+ if (contentPart.data.type !== "data" && (contentPart.data.type !== "url" || contentPart.data.url.protocol !== "s3:")) {
575
615
  throw new UnsupportedFunctionalityError2({
576
616
  functionality: `tool result file data of type "${contentPart.data.type}"`
577
617
  });
@@ -580,6 +620,11 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
580
620
  part: contentPart
581
621
  });
582
622
  if (getTopLevelMediaType(fullMediaType) !== "image") {
623
+ if (contentPart.data.type !== "data") {
624
+ throw new UnsupportedFunctionalityError2({
625
+ functionality: `tool result file data of type "${contentPart.data.type}"`
626
+ });
627
+ }
583
628
  const enableCitations = await shouldEnableCitations(
584
629
  contentPart.providerOptions
585
630
  );
@@ -603,9 +648,10 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
603
648
  return {
604
649
  image: {
605
650
  format: getAmazonBedrockImageFormat(fullMediaType),
606
- source: {
607
- bytes: convertToBase64(contentPart.data.data)
608
- }
651
+ source: getAmazonBedrockImageSource({
652
+ data: contentPart.data,
653
+ functionality: `tool result file data of type "${contentPart.data.type}"`
654
+ })
609
655
  }
610
656
  };
611
657
  }
@@ -722,7 +768,7 @@ async function convertToAmazonBedrockChatMessages(prompt, isMistral = false) {
722
768
  amazonBedrockContent.push({
723
769
  toolUse: {
724
770
  toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
725
- name: part.toolName,
771
+ name: sanitizeToolName(part.toolName),
726
772
  input: toBedrockToolInput(part.input)
727
773
  }
728
774
  });
@@ -843,7 +889,7 @@ var AmazonBedrockChatLanguageModel = class _AmazonBedrockChatLanguageModel {
843
889
  this.specificationVersion = "v4";
844
890
  this.provider = "amazon-bedrock";
845
891
  this.supportedUrls = {
846
- // no supported urls for bedrock
892
+ "image/*": [/^s3:\/\//]
847
893
  };
848
894
  }
849
895
  static [WORKFLOW_SERIALIZE](model) {
@@ -2346,7 +2392,7 @@ import {
2346
2392
  import { AwsV4Signer } from "aws4fetch";
2347
2393
 
2348
2394
  // src/version.ts
2349
- var VERSION = true ? "5.0.26" : "0.0.0-test";
2395
+ var VERSION = true ? "5.0.28" : "0.0.0-test";
2350
2396
 
2351
2397
  // src/amazon-bedrock-sigv4-fetch.ts
2352
2398
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {