Allow Bedrock Runtime selection during setup and login (#62222)

## Why

The app server's Bedrock setup and login flows always selected Mantle.
Clients using Bedrock Runtime had to configure that provider separately.

## What changed

Accept an optional `providerId` in `account/bedrock/setup` for AWS profiles
and environment credentials, and in `account/login/start` for Bedrock API
keys and AWS access keys. Pass `"amazon-bedrock-runtime"` to select
Runtime. Omit the field or pass `null` to keep the Mantle default.

Save configuration for the selected provider and check that provider for
an existing `aws.credential_export` before changing credential sources.

## Testing

Extend app-server tests to cover Runtime setup with profiles and
environment credentials, Runtime login with both key types, and Mantle
fallback. Verify that environment setup selects the Runtime default
model for a new thread and that a configured Runtime credential exporter
blocks profile setup.

GitOrigin-RevId: 6396b638208ab9b12f50f13f13bd517a919d0848
This commit is contained in:
alexsong-oai
2026-11-18 07:43:45 +00:00
committed by copyberry
parent bcff988bd1
commit 24e236514b
20 changed files with 267 additions and 44 deletions
@@ -8,6 +8,7 @@ use crate::external_auth::ExternalAuthBridge;
use crate::model_catalog::ModelCatalog;
use crate::outgoing_message::AccountNotification;
use chrono::DateTime;
use codex_app_server_protocol::BedrockProviderId;
use codex_app_server_protocol::DesktopOnboardingEntrypoint;
use codex_app_server_protocol::GetAccountRateLimitsParams;
use codex_core::McpRefreshReason;
@@ -408,11 +409,16 @@ impl AccountRequestProcessor {
)
.await;
}
LoginAccountParams::AmazonBedrock { api_key, region } => {
LoginAccountParams::AmazonBedrock {
api_key,
region,
provider_id,
} => {
self.login_amazon_bedrock_v2(
request_id,
BedrockLoginCredentials::ApiKey(api_key),
region,
provider_id.unwrap_or(BedrockProviderId::AmazonBedrock),
)
.await;
}
@@ -421,6 +427,7 @@ impl AccountRequestProcessor {
secret_access_key,
session_token,
region,
provider_id,
} => {
self.login_amazon_bedrock_v2(
request_id,
@@ -430,6 +437,7 @@ impl AccountRequestProcessor {
session_token,
},
region,
provider_id.unwrap_or(BedrockProviderId::AmazonBedrock),
)
.await;
}
@@ -536,6 +544,7 @@ impl AccountRequestProcessor {
request_id: ConnectionRequestId,
credentials: BedrockLoginCredentials,
region: String,
provider_id: BedrockProviderId,
) {
let result = async {
self.ensure_provider_login_allowed(CloudLoginProvider::AmazonBedrock)?;
@@ -569,6 +578,7 @@ impl AccountRequestProcessor {
let write = prepare_bedrock_provider(
&self.config_manager,
BedrockProviderConfig {
provider_id,
region: matches!(&credentials, BedrockLoginCredentials::AccessKeys { .. })
.then_some(region),
profile: None,
@@ -10,6 +10,7 @@ use codex_app_server_protocol::BedrockAwsProfile;
use codex_app_server_protocol::BedrockDiscoverParams;
use codex_app_server_protocol::BedrockDiscoverResponse;
use codex_app_server_protocol::BedrockEnvironmentCredential;
use codex_app_server_protocol::BedrockProviderId;
use codex_app_server_protocol::BedrockSetupParams;
use codex_app_server_protocol::BedrockSetupResponse;
use codex_app_server_protocol::ClientResponsePayload;
@@ -71,15 +72,21 @@ impl AccountRequestProcessor {
params: BedrockSetupParams,
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
self.ensure_provider_login_allowed(CloudLoginProvider::AmazonBedrock)?;
let (profile, region) = match &params {
BedrockSetupParams::Profile { profile, region } => {
(Some(profile.trim()), region.trim())
}
BedrockSetupParams::Environment { region } => (None, region.trim()),
let (profile, region, provider_id) = match &params {
BedrockSetupParams::Profile {
profile,
region,
provider_id,
} => (Some(profile.trim()), region.trim(), *provider_id),
BedrockSetupParams::Environment {
region,
provider_id,
} => (None, region.trim(), *provider_id),
};
let write = prepare_bedrock_provider(
&self.config_manager,
BedrockProviderConfig {
provider_id: provider_id.unwrap_or(BedrockProviderId::AmazonBedrock),
region: Some(region),
profile,
},
@@ -3,6 +3,7 @@ use crate::config_manager::ConfigManager;
use crate::config_manager_service::PreparedProviderWrite;
use crate::error_code::internal_error;
use crate::error_code::invalid_request;
use codex_app_server_protocol::BedrockProviderId;
use codex_app_server_protocol::ConfigBatchWriteParams;
use codex_app_server_protocol::ConfigEdit;
use codex_app_server_protocol::ConfigWriteErrorCode;
@@ -11,8 +12,10 @@ use codex_app_server_protocol::MergeStrategy;
use codex_core::config::Config;
use codex_core::config::edit::ConfigEditsBuilder;
use codex_model_provider::AMAZON_BEDROCK_PROVIDER_ID;
use codex_model_provider::AMAZON_BEDROCK_RUNTIME_PROVIDER_ID;
pub(super) struct BedrockProviderConfig<'a> {
pub(super) provider_id: BedrockProviderId,
pub(super) region: Option<&'a str>,
pub(super) profile: Option<&'a str>,
}
@@ -29,8 +32,12 @@ pub(super) async fn prepare_bedrock_provider(
if let Some(region) = config.region {
settings.push(("aws.region", Some(region)));
}
let provider_id = match config.provider_id {
BedrockProviderId::AmazonBedrock => AMAZON_BEDROCK_PROVIDER_ID,
BedrockProviderId::AmazonBedrockRuntime => AMAZON_BEDROCK_RUNTIME_PROVIDER_ID,
};
let (write, provider) = config_manager
.prepare_provider_config(&layers, AMAZON_BEDROCK_PROVIDER_ID, settings)
.prepare_provider_config(&layers, provider_id, settings)
.map_err(map_config_error)?;
if provider
.aws