@ai-sdk/amazon-bedrock 4.0.138 → 4.0.140

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,26 @@
1
1
  # @ai-sdk/amazon-bedrock
2
2
 
3
+ ## 4.0.140
4
+
5
+ ### Patch Changes
6
+
7
+ - 0608dca: fix (provider/anthropic): use current-generation capability defaults for unrecognized Claude model IDs while retaining conservative defaults for legacy Claude and non-Claude models.
8
+ - Updated dependencies [8100830]
9
+ - Updated dependencies [0608dca]
10
+ - @ai-sdk/openai@3.0.88
11
+ - @ai-sdk/anthropic@3.0.101
12
+
13
+ ## 4.0.139
14
+
15
+ ### Patch Changes
16
+
17
+ - 7d821cf: Pass through `s3://` image URLs to Amazon Bedrock Converse as S3 image sources instead of downloading them.
18
+ - b52ca46: Sanitize invalid characters in replayed tool call names before sending conversation history to Amazon Bedrock.
19
+ - Updated dependencies [2f11af1]
20
+ - Updated dependencies [b7afc80]
21
+ - @ai-sdk/openai@3.0.87
22
+ - @ai-sdk/anthropic@3.0.100
23
+
3
24
  ## 4.0.138
4
25
 
5
26
  ### Patch Changes
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
35
35
  var import_aws4fetch = require("aws4fetch");
36
36
 
37
37
  // src/version.ts
38
- var VERSION = true ? "4.0.138" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.140" : "0.0.0-test";
39
39
 
40
40
  // src/bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -24,7 +24,7 @@ import {
24
24
  import { AwsV4Signer } from "aws4fetch";
25
25
 
26
26
  // src/version.ts
27
- var VERSION = true ? "4.0.138" : "0.0.0-test";
27
+ var VERSION = true ? "4.0.140" : "0.0.0-test";
28
28
 
29
29
  // src/bedrock-sigv4-fetch.ts
30
30
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
package/dist/index.js CHANGED
@@ -417,6 +417,32 @@ function pushCachePoint(content, providerMetadata) {
417
417
  content.push(cachePoint);
418
418
  }
419
419
  }
420
+ function sanitizeToolName(toolName) {
421
+ return toolName.replace(/[^a-zA-Z0-9_-]/g, "") || "_";
422
+ }
423
+ function getBedrockImageSource({
424
+ data,
425
+ functionality
426
+ }) {
427
+ if (data instanceof URL) {
428
+ if (data.protocol !== "s3:") {
429
+ throw new import_provider3.UnsupportedFunctionalityError({ functionality });
430
+ }
431
+ return {
432
+ s3Location: {
433
+ uri: data.toString()
434
+ }
435
+ };
436
+ }
437
+ return { bytes: (0, import_provider_utils3.convertToBase64)(data) };
438
+ }
439
+ function getBedrockImageFormatFromUrl(url) {
440
+ var _a;
441
+ const extension = (_a = url.pathname.split(".").pop()) == null ? void 0 : _a.toLowerCase();
442
+ return getBedrockImageFormat(
443
+ `image/${extension === "jpg" ? "jpeg" : extension}`
444
+ );
445
+ }
420
446
  async function shouldEnableCitations(providerMetadata) {
421
447
  var _a, _b;
422
448
  const bedrockOptions = await (0, import_provider_utils3.parseProviderOptions)({
@@ -469,19 +495,22 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
469
495
  break;
470
496
  }
471
497
  case "file": {
472
- if (part.data instanceof URL) {
473
- throw new import_provider3.UnsupportedFunctionalityError({
474
- functionality: "File URL data"
475
- });
476
- }
477
498
  if (part.mediaType.startsWith("image/")) {
478
499
  bedrockContent.push({
479
500
  image: {
480
501
  format: getBedrockImageFormat(part.mediaType),
481
- source: { bytes: (0, import_provider_utils3.convertToBase64)(part.data) }
502
+ source: getBedrockImageSource({
503
+ data: part.data,
504
+ functionality: "File URL data"
505
+ })
482
506
  }
483
507
  });
484
508
  } else {
509
+ if (part.data instanceof URL) {
510
+ throw new import_provider3.UnsupportedFunctionalityError({
511
+ functionality: "File URL data"
512
+ });
513
+ }
485
514
  if (!part.mediaType) {
486
515
  throw new import_provider3.UnsupportedFunctionalityError({
487
516
  functionality: "file without mime type",
@@ -535,6 +564,18 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
535
564
  }
536
565
  };
537
566
  }
567
+ case "image-url": {
568
+ const url = new URL(contentPart.url);
569
+ return {
570
+ image: {
571
+ format: getBedrockImageFormatFromUrl(url),
572
+ source: getBedrockImageSource({
573
+ data: url,
574
+ functionality: `tool result image URL "${contentPart.url}"`
575
+ })
576
+ }
577
+ };
578
+ }
538
579
  case "file-data": {
539
580
  if (!contentPart.mediaType.startsWith("image/")) {
540
581
  const enableCitations = await shouldEnableCitations(
@@ -675,7 +716,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
675
716
  bedrockContent.push({
676
717
  toolUse: {
677
718
  toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
678
- name: part.toolName,
719
+ name: sanitizeToolName(part.toolName),
679
720
  input: part.input
680
721
  }
681
722
  });
@@ -799,7 +840,7 @@ var BedrockChatLanguageModel = class {
799
840
  this.specificationVersion = "v3";
800
841
  this.provider = "amazon-bedrock";
801
842
  this.supportedUrls = {
802
- // no supported urls for bedrock
843
+ "image/*": [/^s3:\/\//]
803
844
  };
804
845
  }
805
846
  async getArgs({
@@ -867,7 +908,7 @@ var BedrockChatLanguageModel = class {
867
908
  const isAnthropicModel = this.modelId.includes("anthropic");
868
909
  const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
869
910
  const modelRejectsNativeStructuredOutput = this.modelId.includes("claude-opus-4-7") || this.modelId.includes("claude-opus-4-8") || this.modelId.includes("claude-fable-5") || this.modelId.includes("claude-sonnet-5");
870
- const modelSupportsStructuredOutput = bedrockChatModelSupportsStructuredOutput(this.modelId);
911
+ const { supportsStructuredOutput: modelSupportsStructuredOutput } = (0, import_internal2.getModelCapabilities)(this.modelId);
871
912
  const useNativeStructuredOutput = isAnthropicModel && !modelRejectsNativeStructuredOutput && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
872
913
  const useJsonInstructionForStructuredOutput = isAnthropicModel && (this.modelId.includes("claude-opus-4-7") || this.modelId.includes("claude-opus-4-8")) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
873
914
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
@@ -1535,9 +1576,6 @@ var BedrockChatLanguageModel = class {
1535
1576
  return `${this.config.baseUrl()}/model/${encodeURIComponent(modelId)}`;
1536
1577
  }
1537
1578
  };
1538
- function bedrockChatModelSupportsStructuredOutput(modelId) {
1539
- return modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5") || modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6") || modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5") || modelId.includes("claude-opus-4-1");
1540
- }
1541
1579
  var JsonObjectTextExtractor = class {
1542
1580
  constructor() {
1543
1581
  this.started = false;
@@ -2101,7 +2139,7 @@ var import_provider_utils7 = require("@ai-sdk/provider-utils");
2101
2139
  var import_aws4fetch = require("aws4fetch");
2102
2140
 
2103
2141
  // src/version.ts
2104
- var VERSION = true ? "4.0.138" : "0.0.0-test";
2142
+ var VERSION = true ? "4.0.140" : "0.0.0-test";
2105
2143
 
2106
2144
  // src/bedrock-sigv4-fetch.ts
2107
2145
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {