fix(ai): respect region from profile config when AWS_PROFILE is set (#1800)

This commit is contained in:
xu0o0 2026-03-04 15:56:06 +08:00 committed by GitHub
parent 5c61d6bc92
commit d4b473e298
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -88,13 +88,20 @@ export const streamBedrock: StreamFunction<"bedrock-converse-stream", BedrockOpt
const blocks = output.content as Block[];
const config: BedrockRuntimeClientConfig = {
region: options.region,
profile: options.profile,
};
// in Node.js/Bun environment only
if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
config.region = config.region || process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION;
// Region resolution: explicit option > env vars > SDK default chain.
// When AWS_PROFILE is set, we leave region undefined so the SDK can
// resovle it from aws profile configs. Otherwise fall back to us-east-1.
const explicitRegion = options.region || process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION;
if (explicitRegion) {
config.region = explicitRegion;
} else if (!process.env.AWS_PROFILE) {
config.region = "us-east-1";
}
// Support proxies that don't need authentication
if (process.env.AWS_BEDROCK_SKIP_AUTH === "1") {
@ -129,10 +136,12 @@ export const streamBedrock: StreamFunction<"bedrock-converse-stream", BedrockOpt
const nodeHttpHandler = await import("@smithy/node-http-handler");
config.requestHandler = new nodeHttpHandler.NodeHttpHandler();
}
} else {
// Non-Node environment (browser): fall back to us-east-1 since
// there's no config file resolution available.
config.region = options.region || "us-east-1";
}
config.region = config.region || "us-east-1";
try {
const client = new BedrockRuntimeClient(config);