fix(core): fill Bedrock endpoint region from provider settings (#58538)

This commit is contained in:
Aiden Cline
2026-10-24 12:33:51 -05:00
committed by GitHub
Unverified
parent 53b044d313
commit a5328d2b66
2 changed files with 26 additions and 2 deletions
+8 -2
View File
@@ -278,7 +278,7 @@ function prepareProviderSettings(
): Effect.Effect<Readonly<Record<string, unknown>>, UnresolvedProviderVariablesError> {
const baseURL = settings.baseURL
if (typeof baseURL !== "string") return Effect.succeed(settings)
return prepareProviderURL(model, baseURL).pipe(
return prepareProviderURL(model, baseURL, settings).pipe(
Effect.map((prepared) => (prepared === baseURL ? settings : { ...settings, baseURL: prepared })),
)
}
@@ -286,9 +286,15 @@ function prepareProviderSettings(
function prepareProviderURL(
model: RuntimeInfo,
baseURL: string,
settings: Readonly<Record<string, unknown>>,
): Effect.Effect<string, UnresolvedProviderVariablesError> {
if (!baseURL.includes("${")) return Effect.succeed(baseURL)
const prepared = baseURL.replace(/\$\{([^}]+)\}/g, (placeholder, name: string) => process.env[name] ?? placeholder)
// Catalog Bedrock URLs are model settings while `region` is a provider setting, so they only meet here.
const prepared = baseURL.replace(
/\$\{([^}]+)\}/g,
(placeholder, name: string) =>
(name === "AWS_REGION" && typeof settings.region === "string" ? settings.region : process.env[name]) ?? placeholder,
)
const failure = unresolvedProviderVariables(model, prepared)
return failure ? Effect.fail(failure) : Effect.succeed(prepared)
}
+18
View File
@@ -242,6 +242,24 @@ describe("ModelResolver", () => {
),
)
it.effect("fills Mantle catalog URLs from the provider region", () =>
withEnv({ AWS_REGION: undefined, AWS_DEFAULT_REGION: undefined }, () =>
Effect.gen(function* () {
const catalog = model(Provider.aisdk("@ai-sdk/amazon-bedrock/mantle"), {
providerID: Provider.ID.amazonBedrock,
modelID: "openai.gpt-5.5",
settings: { baseURL: "https://bedrock-mantle.${AWS_REGION}.api.aws/openai/v1" },
})
const resolved = yield* ModelResolver.fromCatalogModel({
...catalog,
settings: Provider.mergeOverlay({ region: "us-west-2" }, catalog.settings),
})
expect(resolved.route.endpoint.baseURL).toBe("https://bedrock-mantle.us-west-2.api.aws/openai/v1")
}),
),
)
it.effect("prefers the configured Mantle region over the environment", () =>
withEnv({ AWS_REGION: "us-east-1" }, () =>
Effect.gen(function* () {