Files
codex/codex-rs/config/src/model_provider_defaults.rs
T
alexsong-oai 970111f6cb Allow configuring GCP project and location in provider settings (#56560)
## Why

Deriving a Vertex AI endpoint previously required environment variables. Allow the project and location to be specified directly in GCP provider configuration.

## What changed

- Add `model_providers.gcp.project_id` and `model_providers.gcp.location`, with each taking precedence over its corresponding environment variable. Keep `global` as the default location and preserve explicit `base_url` overrides.
- Validate configured endpoint fields and preserve them through thread configuration serialization.
- Apply built-in GCP defaults, including default command authentication, when checking managed provider requirements so unchanged requirements are accepted.

## Testing

Add coverage for endpoint precedence, invalid explicit configuration, provider construction, thread configuration round trips, and managed GCP requirement checks, including repeated model listing.

GitOrigin-RevId: c3704bcc0b7d4872374e2cae623fd24d75fb02b4
2026-10-23 18:50:54 +00:00

28 lines
1007 B
Rust

//! Applies runtime provider defaults using the resolved session working directory.
use codex_model_provider_info::ModelProviderInfo;
use codex_protocol::config_types::ModelProviderAuthInfo;
use codex_utils_absolute_path::AbsolutePathBuf;
use std::num::NonZeroU64;
/// Supplies GCP command auth when no explicit auth override is configured.
pub fn apply_default_gcp_auth(provider: &mut ModelProviderInfo, cwd: &AbsolutePathBuf) {
provider.auth.get_or_insert_with(|| ModelProviderAuthInfo {
command: if cfg!(windows) {
"gcloud.cmd"
} else {
"gcloud"
}
.to_string(),
args: vec![
"auth".into(),
"application-default".into(),
"print-access-token".into(),
],
timeout_ms: NonZeroU64::new(30_000).unwrap_or(NonZeroU64::MIN),
refresh_interval_ms: 3_000_000,
// Registry construction must not depend on the process cwd, which may be deleted.
cwd: cwd.clone(),
});
}