mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-13 01:31:22 +03:00
fix(core): fill Bedrock endpoint region from provider settings (#58538)
This commit is contained in:
committed by
GitHub
Unverified
parent
53b044d313
commit
a5328d2b66
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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* () {
|
||||
|
||||
Reference in New Issue
Block a user