@ai-sdk/amazon-bedrock 4.0.137 → 4.0.139

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,6 +18,7 @@ import {
18
18
  postJsonToApi,
19
19
  resolve
20
20
  } from "@ai-sdk/provider-utils";
21
+ import { sanitizeJsonSchema } from "@ai-sdk/anthropic/internal";
21
22
  import { z as z4 } from "zod/v4";
22
23
 
23
24
  // src/bedrock-api-types.ts
@@ -417,6 +418,32 @@ function pushCachePoint(content, providerMetadata) {
417
418
  content.push(cachePoint);
418
419
  }
419
420
  }
421
+ function sanitizeToolName(toolName) {
422
+ return toolName.replace(/[^a-zA-Z0-9_-]/g, "") || "_";
423
+ }
424
+ function getBedrockImageSource({
425
+ data,
426
+ functionality
427
+ }) {
428
+ if (data instanceof URL) {
429
+ if (data.protocol !== "s3:") {
430
+ throw new UnsupportedFunctionalityError2({ functionality });
431
+ }
432
+ return {
433
+ s3Location: {
434
+ uri: data.toString()
435
+ }
436
+ };
437
+ }
438
+ return { bytes: convertToBase64(data) };
439
+ }
440
+ function getBedrockImageFormatFromUrl(url) {
441
+ var _a;
442
+ const extension = (_a = url.pathname.split(".").pop()) == null ? void 0 : _a.toLowerCase();
443
+ return getBedrockImageFormat(
444
+ `image/${extension === "jpg" ? "jpeg" : extension}`
445
+ );
446
+ }
420
447
  async function shouldEnableCitations(providerMetadata) {
421
448
  var _a, _b;
422
449
  const bedrockOptions = await parseProviderOptions({
@@ -469,19 +496,22 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
469
496
  break;
470
497
  }
471
498
  case "file": {
472
- if (part.data instanceof URL) {
473
- throw new UnsupportedFunctionalityError2({
474
- functionality: "File URL data"
475
- });
476
- }
477
499
  if (part.mediaType.startsWith("image/")) {
478
500
  bedrockContent.push({
479
501
  image: {
480
502
  format: getBedrockImageFormat(part.mediaType),
481
- source: { bytes: convertToBase64(part.data) }
503
+ source: getBedrockImageSource({
504
+ data: part.data,
505
+ functionality: "File URL data"
506
+ })
482
507
  }
483
508
  });
484
509
  } else {
510
+ if (part.data instanceof URL) {
511
+ throw new UnsupportedFunctionalityError2({
512
+ functionality: "File URL data"
513
+ });
514
+ }
485
515
  if (!part.mediaType) {
486
516
  throw new UnsupportedFunctionalityError2({
487
517
  functionality: "file without mime type",
@@ -535,6 +565,18 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
535
565
  }
536
566
  };
537
567
  }
568
+ case "image-url": {
569
+ const url = new URL(contentPart.url);
570
+ return {
571
+ image: {
572
+ format: getBedrockImageFormatFromUrl(url),
573
+ source: getBedrockImageSource({
574
+ data: url,
575
+ functionality: `tool result image URL "${contentPart.url}"`
576
+ })
577
+ }
578
+ };
579
+ }
538
580
  case "file-data": {
539
581
  if (!contentPart.mediaType.startsWith("image/")) {
540
582
  const enableCitations = await shouldEnableCitations(
@@ -675,7 +717,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
675
717
  bedrockContent.push({
676
718
  toolUse: {
677
719
  toolUseId: normalizeToolCallId(part.toolCallId, isMistral),
678
- name: part.toolName,
720
+ name: sanitizeToolName(part.toolName),
679
721
  input: part.input
680
722
  }
681
723
  });
@@ -799,7 +841,7 @@ var BedrockChatLanguageModel = class {
799
841
  this.specificationVersion = "v3";
800
842
  this.provider = "amazon-bedrock";
801
843
  this.supportedUrls = {
802
- // no supported urls for bedrock
844
+ "image/*": [/^s3:\/\//]
803
845
  };
804
846
  }
805
847
  async getArgs({
@@ -980,7 +1022,7 @@ var BedrockChatLanguageModel = class {
980
1022
  ...(_k = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _k.output_config,
981
1023
  format: {
982
1024
  type: "json_schema",
983
- schema: responseFormat.schema
1025
+ schema: sanitizeJsonSchema(responseFormat.schema)
984
1026
  }
985
1027
  }
986
1028
  };
@@ -1532,8 +1574,7 @@ var BedrockChatLanguageModel = class {
1532
1574
  };
1533
1575
  }
1534
1576
  getUrl(modelId) {
1535
- const encodedModelId = modelId.startsWith("arn:") ? encodeURIComponent(modelId).replace(/%3A/g, ":").replace(/%2F/g, "/") : encodeURIComponent(modelId);
1536
- return `${this.config.baseUrl()}/model/${encodedModelId}`;
1577
+ return `${this.config.baseUrl()}/model/${encodeURIComponent(modelId)}`;
1537
1578
  }
1538
1579
  };
1539
1580
  function bedrockChatModelSupportsStructuredOutput(modelId) {
@@ -2123,7 +2164,7 @@ import {
2123
2164
  import { AwsV4Signer } from "aws4fetch";
2124
2165
 
2125
2166
  // src/version.ts
2126
- var VERSION = true ? "4.0.137" : "0.0.0-test";
2167
+ var VERSION = true ? "4.0.139" : "0.0.0-test";
2127
2168
 
2128
2169
  // src/bedrock-sigv4-fetch.ts
2129
2170
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {