@ai-sdk/amazon-bedrock 4.0.174 → 4.0.176

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
@@ -2,9 +2,8 @@
2
2
  import { anthropicTools as anthropicTools2 } from "@ai-sdk/anthropic/internal";
3
3
  import {
4
4
  generateId,
5
- loadOptionalSetting,
5
+ loadOptionalSetting as loadOptionalSetting2,
6
6
  loadSetting,
7
- withoutTrailingSlash,
8
7
  withUserAgentSuffix as withUserAgentSuffix2
9
8
  } from "@ai-sdk/provider-utils";
10
9
 
@@ -2366,7 +2365,7 @@ import {
2366
2365
  import { AwsV4Signer } from "aws4fetch";
2367
2366
 
2368
2367
  // src/version.ts
2369
- var VERSION = true ? "4.0.174" : "0.0.0-test";
2368
+ var VERSION = true ? "4.0.176" : "0.0.0-test";
2370
2369
 
2371
2370
  // src/bedrock-sigv4-fetch.ts
2372
2371
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -2575,9 +2574,47 @@ var BedrockRerankingModel = class {
2575
2574
  }
2576
2575
  };
2577
2576
 
2577
+ // src/resolve-bedrock-base-url.ts
2578
+ import {
2579
+ loadOptionalSetting,
2580
+ withoutTrailingSlash
2581
+ } from "@ai-sdk/provider-utils";
2582
+ var AWS_PARTITION_DNS_SUFFIXES = [
2583
+ { regionPrefix: "cn-", dnsSuffix: "amazonaws.com.cn" },
2584
+ { regionPrefix: "us-iso-", dnsSuffix: "c2s.ic.gov" },
2585
+ { regionPrefix: "us-isob-", dnsSuffix: "sc2s.sgov.gov" },
2586
+ { regionPrefix: "eu-isoe-", dnsSuffix: "cloud.adc-e.uk" },
2587
+ { regionPrefix: "us-isof-", dnsSuffix: "csp.hci.ic.gov" },
2588
+ { regionPrefix: "eusc-", dnsSuffix: "amazonaws.eu" }
2589
+ ];
2590
+ function resolveBedrockBaseURL({
2591
+ baseURL,
2592
+ getRegion,
2593
+ service,
2594
+ serviceEndpointUrlEnvironmentVariableName
2595
+ }) {
2596
+ var _a, _b, _c, _d, _e;
2597
+ const resolvedBaseURL = (_a = baseURL != null ? baseURL : loadOptionalSetting({
2598
+ settingValue: void 0,
2599
+ environmentVariableName: serviceEndpointUrlEnvironmentVariableName
2600
+ })) != null ? _a : loadOptionalSetting({
2601
+ settingValue: void 0,
2602
+ environmentVariableName: "AWS_ENDPOINT_URL"
2603
+ });
2604
+ if (resolvedBaseURL != null) {
2605
+ return (_b = withoutTrailingSlash(resolvedBaseURL)) != null ? _b : resolvedBaseURL;
2606
+ }
2607
+ const region = getRegion();
2608
+ const dnsSuffix = (_d = (_c = AWS_PARTITION_DNS_SUFFIXES.find(
2609
+ ({ regionPrefix }) => region.startsWith(regionPrefix)
2610
+ )) == null ? void 0 : _c.dnsSuffix) != null ? _d : "amazonaws.com";
2611
+ const generatedBaseURL = `https://${service}.${region}.${dnsSuffix}`;
2612
+ return (_e = withoutTrailingSlash(generatedBaseURL)) != null ? _e : generatedBaseURL;
2613
+ }
2614
+
2578
2615
  // src/bedrock-provider.ts
2579
2616
  function createAmazonBedrock(options = {}) {
2580
- const rawApiKey = loadOptionalSetting({
2617
+ const rawApiKey = loadOptionalSetting2({
2581
2618
  settingValue: options.apiKey,
2582
2619
  environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
2583
2620
  });
@@ -2617,7 +2654,7 @@ function createAmazonBedrock(options = {}) {
2617
2654
  environmentVariableName: "AWS_SECRET_ACCESS_KEY",
2618
2655
  description: "AWS secret access key"
2619
2656
  }),
2620
- sessionToken: options.accessKeyId != null && options.secretAccessKey != null ? options.sessionToken : loadOptionalSetting({
2657
+ sessionToken: options.accessKeyId != null && options.secretAccessKey != null ? options.sessionToken : loadOptionalSetting2({
2621
2658
  settingValue: options.sessionToken,
2622
2659
  environmentVariableName: "AWS_SESSION_TOKEN"
2623
2660
  })
@@ -2648,28 +2685,28 @@ Original error: ${errorMessage}`
2648
2685
  const baseHeaders = (_a = options.headers) != null ? _a : {};
2649
2686
  return withUserAgentSuffix2(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
2650
2687
  };
2651
- const getBedrockRuntimeBaseUrl = () => {
2652
- var _a, _b;
2653
- return (_b = withoutTrailingSlash(
2654
- (_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${loadSetting({
2655
- settingValue: options.region,
2656
- settingName: "region",
2657
- environmentVariableName: "AWS_REGION",
2658
- description: "AWS region"
2659
- })}.amazonaws.com`
2660
- )) != null ? _b : `https://bedrock-runtime.us-east-1.amazonaws.com`;
2661
- };
2662
- const getBedrockAgentRuntimeBaseUrl = () => {
2663
- var _a, _b;
2664
- return (_b = withoutTrailingSlash(
2665
- (_a = options.baseURL) != null ? _a : `https://bedrock-agent-runtime.${loadSetting({
2666
- settingValue: options.region,
2667
- settingName: "region",
2668
- environmentVariableName: "AWS_REGION",
2669
- description: "AWS region"
2670
- })}.amazonaws.com`
2671
- )) != null ? _b : `https://bedrock-agent-runtime.us-west-2.amazonaws.com`;
2672
- };
2688
+ const getBedrockRuntimeBaseUrl = () => resolveBedrockBaseURL({
2689
+ baseURL: options.baseURL,
2690
+ getRegion: () => loadSetting({
2691
+ settingValue: options.region,
2692
+ settingName: "region",
2693
+ environmentVariableName: "AWS_REGION",
2694
+ description: "AWS region"
2695
+ }),
2696
+ service: "bedrock-runtime",
2697
+ serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_RUNTIME"
2698
+ });
2699
+ const getBedrockAgentRuntimeBaseUrl = () => resolveBedrockBaseURL({
2700
+ baseURL: options.baseURL,
2701
+ getRegion: () => loadSetting({
2702
+ settingValue: options.region,
2703
+ settingName: "region",
2704
+ environmentVariableName: "AWS_REGION",
2705
+ description: "AWS region"
2706
+ }),
2707
+ service: "bedrock-agent-runtime",
2708
+ serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME"
2709
+ });
2673
2710
  const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
2674
2711
  baseUrl: getBedrockRuntimeBaseUrl,
2675
2712
  headers: getHeaders,