mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 05:02:14 +00:00
fix(ai): respect region from profile config when AWS_PROFILE is set (#1800)
This commit is contained in:
parent
5c61d6bc92
commit
d4b473e298
1 changed files with 13 additions and 4 deletions
|
|
@ -88,13 +88,20 @@ export const streamBedrock: StreamFunction<"bedrock-converse-stream", BedrockOpt
|
||||||
const blocks = output.content as Block[];
|
const blocks = output.content as Block[];
|
||||||
|
|
||||||
const config: BedrockRuntimeClientConfig = {
|
const config: BedrockRuntimeClientConfig = {
|
||||||
region: options.region,
|
|
||||||
profile: options.profile,
|
profile: options.profile,
|
||||||
};
|
};
|
||||||
|
|
||||||
// in Node.js/Bun environment only
|
// in Node.js/Bun environment only
|
||||||
if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
|
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
|
// Support proxies that don't need authentication
|
||||||
if (process.env.AWS_BEDROCK_SKIP_AUTH === "1") {
|
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");
|
const nodeHttpHandler = await import("@smithy/node-http-handler");
|
||||||
config.requestHandler = new nodeHttpHandler.NodeHttpHandler();
|
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 {
|
try {
|
||||||
const client = new BedrockRuntimeClient(config);
|
const client = new BedrockRuntimeClient(config);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue