@ai-sdk/amazon-bedrock 3.0.130 → 3.0.131

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.d.mts CHANGED
@@ -93,7 +93,9 @@ interface AmazonBedrockProviderSettings {
93
93
  */
94
94
  sessionToken?: string;
95
95
  /**
96
- Base URL for the Bedrock API calls.
96
+ Base URL for the Bedrock API calls. When omitted, the provider uses
97
+ `AWS_ENDPOINT_URL_BEDROCK_RUNTIME`, then `AWS_ENDPOINT_URL`, before generating
98
+ an endpoint from the AWS region.
97
99
  */
98
100
  baseURL?: string;
99
101
  /**
package/dist/index.d.ts CHANGED
@@ -93,7 +93,9 @@ interface AmazonBedrockProviderSettings {
93
93
  */
94
94
  sessionToken?: string;
95
95
  /**
96
- Base URL for the Bedrock API calls.
96
+ Base URL for the Bedrock API calls. When omitted, the provider uses
97
+ `AWS_ENDPOINT_URL_BEDROCK_RUNTIME`, then `AWS_ENDPOINT_URL`, before generating
98
+ an endpoint from the AWS region.
97
99
  */
98
100
  baseURL?: string;
99
101
  /**
package/dist/index.js CHANGED
@@ -27,10 +27,10 @@ __export(index_exports, {
27
27
  module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/bedrock-provider.ts
30
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
30
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "3.0.130" : "0.0.0-test";
33
+ var VERSION = true ? "3.0.131" : "0.0.0-test";
34
34
 
35
35
  // src/bedrock-provider.ts
36
36
  var import_internal3 = require("@ai-sdk/anthropic/internal");
@@ -1928,15 +1928,50 @@ function createApiKeyFetchFunction(apiKey, fetch = globalThis.fetch) {
1928
1928
  };
1929
1929
  }
1930
1930
 
1931
+ // src/resolve-bedrock-base-url.ts
1932
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
1933
+ var AWS_PARTITION_DNS_SUFFIXES = [
1934
+ { regionPrefix: "cn-", dnsSuffix: "amazonaws.com.cn" },
1935
+ { regionPrefix: "us-iso-", dnsSuffix: "c2s.ic.gov" },
1936
+ { regionPrefix: "us-isob-", dnsSuffix: "sc2s.sgov.gov" },
1937
+ { regionPrefix: "eu-isoe-", dnsSuffix: "cloud.adc-e.uk" },
1938
+ { regionPrefix: "us-isof-", dnsSuffix: "csp.hci.ic.gov" },
1939
+ { regionPrefix: "eusc-", dnsSuffix: "amazonaws.eu" }
1940
+ ];
1941
+ function resolveBedrockBaseURL({
1942
+ baseURL,
1943
+ getRegion,
1944
+ service,
1945
+ serviceEndpointUrlEnvironmentVariableName
1946
+ }) {
1947
+ var _a, _b, _c, _d, _e;
1948
+ const resolvedBaseURL = (_a = baseURL != null ? baseURL : (0, import_provider_utils8.loadOptionalSetting)({
1949
+ settingValue: void 0,
1950
+ environmentVariableName: serviceEndpointUrlEnvironmentVariableName
1951
+ })) != null ? _a : (0, import_provider_utils8.loadOptionalSetting)({
1952
+ settingValue: void 0,
1953
+ environmentVariableName: "AWS_ENDPOINT_URL"
1954
+ });
1955
+ if (resolvedBaseURL != null) {
1956
+ return (_b = (0, import_provider_utils8.withoutTrailingSlash)(resolvedBaseURL)) != null ? _b : resolvedBaseURL;
1957
+ }
1958
+ const region = getRegion();
1959
+ const dnsSuffix = (_d = (_c = AWS_PARTITION_DNS_SUFFIXES.find(
1960
+ ({ regionPrefix }) => region.startsWith(regionPrefix)
1961
+ )) == null ? void 0 : _c.dnsSuffix) != null ? _d : "amazonaws.com";
1962
+ const generatedBaseURL = `https://${service}.${region}.${dnsSuffix}`;
1963
+ return (_e = (0, import_provider_utils8.withoutTrailingSlash)(generatedBaseURL)) != null ? _e : generatedBaseURL;
1964
+ }
1965
+
1931
1966
  // src/bedrock-provider.ts
1932
1967
  function createAmazonBedrock(options = {}) {
1933
- const rawApiKey = (0, import_provider_utils8.loadOptionalSetting)({
1968
+ const rawApiKey = (0, import_provider_utils9.loadOptionalSetting)({
1934
1969
  settingValue: options.apiKey,
1935
1970
  environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
1936
1971
  });
1937
1972
  const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
1938
1973
  const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
1939
- const region = (0, import_provider_utils8.loadSetting)({
1974
+ const region = (0, import_provider_utils9.loadSetting)({
1940
1975
  settingValue: options.region,
1941
1976
  settingName: "region",
1942
1977
  environmentVariableName: "AWS_REGION",
@@ -1958,19 +1993,19 @@ function createAmazonBedrock(options = {}) {
1958
1993
  try {
1959
1994
  return {
1960
1995
  region,
1961
- accessKeyId: (0, import_provider_utils8.loadSetting)({
1996
+ accessKeyId: (0, import_provider_utils9.loadSetting)({
1962
1997
  settingValue: options.accessKeyId,
1963
1998
  settingName: "accessKeyId",
1964
1999
  environmentVariableName: "AWS_ACCESS_KEY_ID",
1965
2000
  description: "AWS access key ID"
1966
2001
  }),
1967
- secretAccessKey: (0, import_provider_utils8.loadSetting)({
2002
+ secretAccessKey: (0, import_provider_utils9.loadSetting)({
1968
2003
  settingValue: options.secretAccessKey,
1969
2004
  settingName: "secretAccessKey",
1970
2005
  environmentVariableName: "AWS_SECRET_ACCESS_KEY",
1971
2006
  description: "AWS secret access key"
1972
2007
  }),
1973
- sessionToken: (0, import_provider_utils8.loadOptionalSetting)({
2008
+ sessionToken: (0, import_provider_utils9.loadOptionalSetting)({
1974
2009
  settingValue: options.sessionToken,
1975
2010
  environmentVariableName: "AWS_SESSION_TOKEN"
1976
2011
  })
@@ -1996,27 +2031,27 @@ Original error: ${errorMessage}`
1996
2031
  throw error;
1997
2032
  }
1998
2033
  }, options.fetch);
1999
- const getBaseUrl = () => {
2000
- var _a, _b;
2001
- return (_b = (0, import_provider_utils8.withoutTrailingSlash)(
2002
- (_a = options.baseURL) != null ? _a : `https://bedrock-runtime.${(0, import_provider_utils8.loadSetting)({
2003
- settingValue: options.region,
2004
- settingName: "region",
2005
- environmentVariableName: "AWS_REGION",
2006
- description: "AWS region"
2007
- })}.amazonaws.com`
2008
- )) != null ? _b : `https://bedrock-runtime.us-east-1.amazonaws.com`;
2009
- };
2034
+ const getBaseUrl = () => resolveBedrockBaseURL({
2035
+ baseURL: options.baseURL,
2036
+ getRegion: () => (0, import_provider_utils9.loadSetting)({
2037
+ settingValue: options.region,
2038
+ settingName: "region",
2039
+ environmentVariableName: "AWS_REGION",
2040
+ description: "AWS region"
2041
+ }),
2042
+ service: "bedrock-runtime",
2043
+ serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_RUNTIME"
2044
+ });
2010
2045
  const getHeaders = () => {
2011
2046
  var _a;
2012
2047
  const baseHeaders = (_a = options.headers) != null ? _a : {};
2013
- return (0, import_provider_utils8.withUserAgentSuffix)(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
2048
+ return (0, import_provider_utils9.withUserAgentSuffix)(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
2014
2049
  };
2015
2050
  const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
2016
2051
  baseUrl: getBaseUrl,
2017
2052
  headers: getHeaders,
2018
2053
  fetch: fetchFunction,
2019
- generateId: import_provider_utils8.generateId
2054
+ generateId: import_provider_utils9.generateId
2020
2055
  });
2021
2056
  const provider = function(modelId) {
2022
2057
  if (new.target) {