@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/dist/index.mjs CHANGED
@@ -18,7 +18,10 @@ import {
18
18
  postJsonToApi,
19
19
  resolve
20
20
  } from "@ai-sdk/provider-utils";
21
- import { sanitizeJsonSchema } from "@ai-sdk/anthropic/internal";
21
+ import {
22
+ getModelCapabilities,
23
+ sanitizeJsonSchema
24
+ } from "@ai-sdk/anthropic/internal";
22
25
  import { z as z4 } from "zod/v4";
23
26
 
24
27
  // src/bedrock-api-types.ts
@@ -418,6 +421,32 @@ function pushCachePoint(content, providerMetadata) {
418
421
  content.push(cachePoint);
419
422
  }
420
423
  }
424
+ function sanitizeToolName(toolName) {
425
+ return toolName.replace(/[^a-zA-Z0-9_-]/g, "") || "_";
426
+ }
427
+ function getBedrockImageSource({
428
+ data,
429
+ functionality
430
+ }) {
431
+ if (data instanceof URL) {
432
+ if (data.protocol !== "s3:") {
433
+ throw new UnsupportedFunctionalityError2({ functionality });
434
+ }
435
+ return {
436
+ s3Location: {
437
+ uri: data.toString()
438
+ }
439
+ };
440
+ }
441
+ return { bytes: convertToBase64(data) };
442
+ }
443
+ function getBedrockImageFormatFromUrl(url) {
444
+ var _a;
445
+ const extension = (_a = url.pathname.split(".").pop()) == null ? void 0 : _a.toLowerCase();
446
+ return getBedrockImageFormat(
447
+ `image/${extension === "jpg" ? "jpeg" : extension}`
448
+ );
449
+ }
421
450
  async function shouldEnableCitations(providerMetadata) {
422
451
  var _a, _b;
423
452
  const bedrockOptions = await parseProviderOptions({
@@ -470,19 +499,22 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
470
499
  break;
471
500
  }
472
501
  case "file": {
473
- if (part.data instanceof URL) {
474
- throw new UnsupportedFunctionalityError2({
475
- functionality: "File URL data"
476
- });
477
- }
478
502
  if (part.mediaType.startsWith("image/")) {
479
503
  bedrockContent.push({
480
504
  image: {
481
505
  format: getBedrockImageFormat(part.mediaType),
482
- source: { bytes: convertToBase64(part.data) }
506
+ source: getBedrockImageSource({
507
+ data: part.data,
508
+ functionality: "File URL data"
509
+ })
483
510
  }
484
511
  });
485
512
  } else {
513
+ if (part.data instanceof URL) {
514
+ throw new UnsupportedFunctionalityError2({
515
+ functionality: "File URL data"
516
+ });
517
+ }
486
518
  if (!part.mediaType) {
487
519
  throw new UnsupportedFunctionalityError2({
488
520
  functionality: "file without mime type",
@@ -536,6 +568,18 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
536
568
  }
537
569
  };
538
570
  }
571
+ case "image-url": {
572
+ const url = new URL(contentPart.url);
573
+ return {
574
+ image: {
575
+ format: getBedrockImageFormatFromUrl(url),
576
+ source: getBedrockImageSource({
577
+ data: url,
578
+ functionality: `tool result image URL "${contentPart.url}"`
579
+ })
580
+ }
581
+ };
582
+ }
539
583
  case "file-data": {
540
584
  if (!contentPart.mediaType.startsWith("image/")) {
541
585
  const enableCitations = await shouldEnableCitations(
@@ -676,7 +720,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
676
720
  bedrockContent.push({
677
721
  toolUse: {
678
722
  toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
679
- name: part.toolName,
723
+ name: sanitizeToolName(part.toolName),
680
724
  input: part.input
681
725
  }
682
726
  });
@@ -800,7 +844,7 @@ var BedrockChatLanguageModel = class {
800
844
  this.specificationVersion = "v3";
801
845
  this.provider = "amazon-bedrock";
802
846
  this.supportedUrls = {
803
- // no supported urls for bedrock
847
+ "image/*": [/^s3:\/\//]
804
848
  };
805
849
  }
806
850
  async getArgs({
@@ -868,7 +912,7 @@ var BedrockChatLanguageModel = class {
868
912
  const isAnthropicModel = this.modelId.includes("anthropic");
869
913
  const isThinkingEnabled = ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.type) === "enabled" || ((_c = bedrockOptions.reasoningConfig) == null ? void 0 : _c.type) === "adaptive";
870
914
  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");
871
- const modelSupportsStructuredOutput = bedrockChatModelSupportsStructuredOutput(this.modelId);
915
+ const { supportsStructuredOutput: modelSupportsStructuredOutput } = getModelCapabilities(this.modelId);
872
916
  const useNativeStructuredOutput = isAnthropicModel && !modelRejectsNativeStructuredOutput && (modelSupportsStructuredOutput || isThinkingEnabled) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null;
873
917
  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;
874
918
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
@@ -1536,9 +1580,6 @@ var BedrockChatLanguageModel = class {
1536
1580
  return `${this.config.baseUrl()}/model/${encodeURIComponent(modelId)}`;
1537
1581
  }
1538
1582
  };
1539
- function bedrockChatModelSupportsStructuredOutput(modelId) {
1540
- 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");
1541
- }
1542
1583
  var JsonObjectTextExtractor = class {
1543
1584
  constructor() {
1544
1585
  this.started = false;
@@ -2123,7 +2164,7 @@ import {
2123
2164
  import { AwsV4Signer } from "aws4fetch";
2124
2165
 
2125
2166
  // src/version.ts
2126
- var VERSION = true ? "4.0.138" : "0.0.0-test";
2167
+ var VERSION = true ? "4.0.140" : "0.0.0-test";
2127
2168
 
2128
2169
  // src/bedrock-sigv4-fetch.ts
2129
2170
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {