diff --git a/codex-rs/app-server-protocol/src/protocol/common.rs b/codex-rs/app-server-protocol/src/protocol/common.rs index efcc651b33..eb59480b58 100644 --- a/codex-rs/app-server-protocol/src/protocol/common.rs +++ b/codex-rs/app-server-protocol/src/protocol/common.rs @@ -30,7 +30,7 @@ pub enum AuthMode { /// OpenAI API key provided by the caller and stored by Codex. ApiKey, /// ChatGPT OAuth managed by Codex (tokens persisted and refreshed by Codex). - ChatGPT, + Chatgpt, /// [UNSTABLE] FOR OPENAI INTERNAL USE ONLY - DO NOT USE. /// /// ChatGPT auth tokens are supplied by an external host app and are only diff --git a/codex-rs/app-server/src/codex_message_processor.rs b/codex-rs/app-server/src/codex_message_processor.rs index c02f3c7368..78f670c049 100644 --- a/codex-rs/app-server/src/codex_message_processor.rs +++ b/codex-rs/app-server/src/codex_message_processor.rs @@ -1246,7 +1246,7 @@ impl CodexMessageProcessor { let account = match self.auth_manager.auth_cached() { Some(auth) => Some(match auth { CodexAuth::ApiKey(_) => Account::ApiKey {}, - CodexAuth::ChatGpt(_) | CodexAuth::ChatGptAuthTokens(_) => { + CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_) => { let email = auth.get_account_email(); let plan_type = auth.account_plan_type(); diff --git a/codex-rs/app-server/tests/common/auth_fixtures.rs b/codex-rs/app-server/tests/common/auth_fixtures.rs index b78d5b105d..e689e41838 100644 --- a/codex-rs/app-server/tests/common/auth_fixtures.rs +++ b/codex-rs/app-server/tests/common/auth_fixtures.rs @@ -159,7 +159,7 @@ pub fn write_chatgpt_auth( let last_refresh = fixture.last_refresh.unwrap_or_else(|| Some(Utc::now())); let auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(tokens), last_refresh, diff --git a/codex-rs/cli/src/login.rs b/codex-rs/cli/src/login.rs index cee002f339..01a830acb2 100644 --- a/codex-rs/cli/src/login.rs +++ b/codex-rs/cli/src/login.rs @@ -236,7 +236,7 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! { std::process::exit(1); } }, - AuthMode::ChatGPT => { + AuthMode::Chatgpt => { eprintln!("Logged in using ChatGPT"); std::process::exit(0); } diff --git a/codex-rs/core/src/auth.rs b/codex-rs/core/src/auth.rs index 4bddbe3031..fb4114a7c2 100644 --- a/codex-rs/core/src/auth.rs +++ b/codex-rs/core/src/auth.rs @@ -44,15 +44,15 @@ use thiserror::Error; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum AuthMode { ApiKey, - ChatGPT, + Chatgpt, } /// Authentication mechanism used by the current user. #[derive(Debug, Clone)] pub enum CodexAuth { ApiKey(ApiKeyAuth), - ChatGpt(ChatGptAuth), - ChatGptAuthTokens(ChatGptAuthTokens), + Chatgpt(ChatgptAuth), + ChatgptAuthTokens(ChatgptAuthTokens), } #[derive(Debug, Clone)] @@ -61,18 +61,18 @@ pub struct ApiKeyAuth { } #[derive(Debug, Clone)] -pub struct ChatGptAuth { - state: ChatGptAuthState, +pub struct ChatgptAuth { + state: ChatgptAuthState, storage: Arc, } #[derive(Debug, Clone)] -pub struct ChatGptAuthTokens { - state: ChatGptAuthState, +pub struct ChatgptAuthTokens { + state: ChatgptAuthState, } #[derive(Debug, Clone)] -struct ChatGptAuthState { +struct ChatgptAuthState { auth_dot_json: Arc>>, client: CodexHttpClient, } @@ -161,18 +161,18 @@ impl CodexAuth { } let storage_mode = auth_dot_json.storage_mode(auth_credentials_store_mode); - let state = ChatGptAuthState { + let state = ChatgptAuthState { auth_dot_json: Arc::new(Mutex::new(Some(auth_dot_json))), client, }; match auth_mode { - ApiAuthMode::ChatGPT => { + ApiAuthMode::Chatgpt => { let storage = create_auth_storage(codex_home.to_path_buf(), storage_mode); - Ok(Self::ChatGpt(ChatGptAuth { state, storage })) + Ok(Self::Chatgpt(ChatgptAuth { state, storage })) } ApiAuthMode::ChatgptAuthTokens => { - Ok(Self::ChatGptAuthTokens(ChatGptAuthTokens { state })) + Ok(Self::ChatgptAuthTokens(ChatgptAuthTokens { state })) } ApiAuthMode::ApiKey => unreachable!("api key mode is handled above"), } @@ -189,31 +189,31 @@ impl CodexAuth { pub fn internal_auth_mode(&self) -> AuthMode { match self { Self::ApiKey(_) => AuthMode::ApiKey, - Self::ChatGpt(_) | Self::ChatGptAuthTokens(_) => AuthMode::ChatGPT, + Self::Chatgpt(_) | Self::ChatgptAuthTokens(_) => AuthMode::Chatgpt, } } pub fn api_auth_mode(&self) -> ApiAuthMode { match self { Self::ApiKey(_) => ApiAuthMode::ApiKey, - Self::ChatGpt(_) => ApiAuthMode::ChatGPT, - Self::ChatGptAuthTokens(_) => ApiAuthMode::ChatgptAuthTokens, + Self::Chatgpt(_) => ApiAuthMode::Chatgpt, + Self::ChatgptAuthTokens(_) => ApiAuthMode::ChatgptAuthTokens, } } pub fn is_chatgpt_auth(&self) -> bool { - self.internal_auth_mode() == AuthMode::ChatGPT + self.internal_auth_mode() == AuthMode::Chatgpt } pub fn is_external_chatgpt_tokens(&self) -> bool { - matches!(self, Self::ChatGptAuthTokens(_)) + matches!(self, Self::ChatgptAuthTokens(_)) } /// Returns `None` is `is_internal_auth_mode() != AuthMode::ApiKey`. pub fn api_key(&self) -> Option<&str> { match self { Self::ApiKey(auth) => Some(auth.api_key.as_str()), - Self::ChatGpt(_) | Self::ChatGptAuthTokens(_) => None, + Self::Chatgpt(_) | Self::ChatgptAuthTokens(_) => None, } } @@ -234,7 +234,7 @@ impl CodexAuth { pub fn get_token(&self) -> Result { match self { Self::ApiKey(auth) => Ok(auth.api_key.clone()), - Self::ChatGpt(_) | Self::ChatGptAuthTokens(_) => { + Self::Chatgpt(_) | Self::ChatgptAuthTokens(_) => { let access_token = self.get_token_data()?.access_token; Ok(access_token) } @@ -278,8 +278,8 @@ impl CodexAuth { /// Returns `None` if `is_chatgpt_auth()` is false. fn get_current_auth_json(&self) -> Option { let state = match self { - Self::ChatGpt(auth) => &auth.state, - Self::ChatGptAuthTokens(auth) => &auth.state, + Self::Chatgpt(auth) => &auth.state, + Self::ChatgptAuthTokens(auth) => &auth.state, Self::ApiKey(_) => return None, }; #[expect(clippy::unwrap_used)] @@ -294,7 +294,7 @@ impl CodexAuth { /// Consider this private to integration tests. pub fn create_dummy_chatgpt_auth_for_testing() -> Self { let auth_dot_json = AuthDotJson { - auth_mode: Some(ApiAuthMode::ChatGPT), + auth_mode: Some(ApiAuthMode::Chatgpt), openai_api_key: None, tokens: Some(TokenData { id_token: Default::default(), @@ -306,12 +306,12 @@ impl CodexAuth { }; let client = crate::default_client::create_client(); - let state = ChatGptAuthState { + let state = ChatgptAuthState { auth_dot_json: Arc::new(Mutex::new(Some(auth_dot_json))), client, }; let storage = create_auth_storage(PathBuf::new(), AuthCredentialsStoreMode::File); - Self::ChatGpt(ChatGptAuth { state, storage }) + Self::Chatgpt(ChatgptAuth { state, storage }) } fn from_api_key_with_client(api_key: &str, _client: CodexHttpClient) -> Self { @@ -325,7 +325,7 @@ impl CodexAuth { } } -impl ChatGptAuth { +impl ChatgptAuth { fn current_auth_json(&self) -> Option { #[expect(clippy::unwrap_used)] self.state.auth_dot_json.lock().unwrap().clone() @@ -436,8 +436,8 @@ pub fn enforce_login_restrictions(config: &Config) -> std::io::Result<()> { if let Some(required_method) = config.forced_login_method { let method_violation = match (required_method, auth.internal_auth_mode()) { (ForcedLoginMethod::Api, AuthMode::ApiKey) => None, - (ForcedLoginMethod::Chatgpt, AuthMode::ChatGPT) => None, - (ForcedLoginMethod::Api, AuthMode::ChatGPT) => Some( + (ForcedLoginMethod::Chatgpt, AuthMode::Chatgpt) => None, + (ForcedLoginMethod::Api, AuthMode::Chatgpt) => Some( "API key login is required, but ChatGPT is currently being used. Logging out." .to_string(), ), @@ -750,7 +750,7 @@ impl AuthDotJson { if self.openai_api_key.is_some() { return ApiAuthMode::ApiKey; } - ApiAuthMode::ChatGPT + ApiAuthMode::Chatgpt } fn storage_mode( @@ -1127,11 +1127,11 @@ impl AuthManager { None => return Ok(()), }; match auth { - CodexAuth::ChatGptAuthTokens(_) => { + CodexAuth::ChatgptAuthTokens(_) => { self.refresh_external_auth(ExternalAuthRefreshReason::Unauthorized) .await } - CodexAuth::ChatGpt(chatgpt_auth) => { + CodexAuth::Chatgpt(chatgpt_auth) => { let token_data = chatgpt_auth.current_token_data().ok_or_else(|| { RefreshTokenError::Transient(std::io::Error::other( "Token data is not available.", @@ -1170,7 +1170,7 @@ impl AuthManager { async fn refresh_if_stale(&self, auth: &CodexAuth) -> Result { let chatgpt_auth = match auth { - CodexAuth::ChatGpt(chatgpt_auth) => chatgpt_auth, + CodexAuth::Chatgpt(chatgpt_auth) => chatgpt_auth, _ => return Ok(false), }; @@ -1250,7 +1250,7 @@ impl AuthManager { async fn refresh_tokens( &self, - auth: &ChatGptAuth, + auth: &ChatgptAuth, refresh_token: String, ) -> Result<(), RefreshTokenError> { let refresh_response = try_refresh_token(refresh_token, auth.client()).await?; @@ -1373,7 +1373,7 @@ mod tests { .unwrap() .unwrap(); assert_eq!(None, auth.api_key()); - assert_eq!(AuthMode::ChatGPT, auth.internal_auth_mode()); + assert_eq!(AuthMode::Chatgpt, auth.internal_auth_mode()); let auth_dot_json = auth .get_current_auth_json() diff --git a/codex-rs/core/src/auth/storage.rs b/codex-rs/core/src/auth/storage.rs index b4f4bb8e7e..1ac1b2ee18 100644 --- a/codex-rs/core/src/auth/storage.rs +++ b/codex-rs/core/src/auth/storage.rs @@ -565,7 +565,7 @@ mod tests { let auth_file = get_auth_file(codex_home.path()); std::fs::write(&auth_file, "stale")?; let auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(TokenData { id_token: Default::default(), diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 30dd8d24fc..5a1ce90dd9 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -5271,7 +5271,7 @@ mod tests { model_info.slug.as_str(), None, Some("test@test.com".to_string()), - Some(AuthMode::ChatGPT), + Some(AuthMode::Chatgpt), false, "test".to_string(), session_source, diff --git a/codex-rs/core/src/model_provider_info.rs b/codex-rs/core/src/model_provider_info.rs index 0f5a8643a7..56ff76d7f6 100644 --- a/codex-rs/core/src/model_provider_info.rs +++ b/codex-rs/core/src/model_provider_info.rs @@ -137,7 +137,7 @@ impl ModelProviderInfo { &self, auth_mode: Option, ) -> crate::error::Result { - let default_base_url = if matches!(auth_mode, Some(AuthMode::ChatGPT)) { + let default_base_url = if matches!(auth_mode, Some(AuthMode::Chatgpt)) { "https://chatgpt.com/backend-api/codex" } else { "https://api.openai.com/v1" diff --git a/codex-rs/core/src/models_manager/manager.rs b/codex-rs/core/src/models_manager/manager.rs index 40f9c8ccdc..936e40d1bc 100644 --- a/codex-rs/core/src/models_manager/manager.rs +++ b/codex-rs/core/src/models_manager/manager.rs @@ -274,7 +274,7 @@ impl ModelsManager { let mut merged_presets = ModelPreset::merge(remote_presets, existing_presets); let chatgpt_mode = matches!( self.auth_manager.get_internal_auth_mode(), - Some(AuthMode::ChatGPT) + Some(AuthMode::Chatgpt) ); merged_presets = ModelPreset::filter_by_auth(merged_presets, chatgpt_mode); diff --git a/codex-rs/core/tests/responses_headers.rs b/codex-rs/core/tests/responses_headers.rs index b2c64818cc..86d6e8ce61 100644 --- a/codex-rs/core/tests/responses_headers.rs +++ b/codex-rs/core/tests/responses_headers.rs @@ -71,7 +71,7 @@ async fn responses_stream_includes_subagent_header_on_review() { let config = Arc::new(config); let conversation_id = ThreadId::new(); - let auth_mode = AuthMode::ChatGPT; + let auth_mode = AuthMode::Chatgpt; let session_source = SessionSource::SubAgent(SubAgentSource::Review); let model_info = ModelsManager::construct_model_info_offline(model.as_str(), &config); let otel_manager = OtelManager::new( @@ -169,7 +169,7 @@ async fn responses_stream_includes_subagent_header_on_other() { let config = Arc::new(config); let conversation_id = ThreadId::new(); - let auth_mode = AuthMode::ChatGPT; + let auth_mode = AuthMode::Chatgpt; let session_source = SessionSource::SubAgent(SubAgentSource::Other("my-task".to_string())); let model_info = ModelsManager::construct_model_info_offline(model.as_str(), &config); diff --git a/codex-rs/core/tests/suite/auth_refresh.rs b/codex-rs/core/tests/suite/auth_refresh.rs index 4ef3b82eec..a6be08f23c 100644 --- a/codex-rs/core/tests/suite/auth_refresh.rs +++ b/codex-rs/core/tests/suite/auth_refresh.rs @@ -51,7 +51,7 @@ async fn refresh_token_succeeds_updates_storage() -> Result<()> { let initial_last_refresh = Utc::now() - Duration::days(1); let initial_tokens = build_tokens(INITIAL_ACCESS_TOKEN, INITIAL_REFRESH_TOKEN); let initial_auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(initial_tokens.clone()), last_refresh: Some(initial_last_refresh), @@ -113,7 +113,7 @@ async fn returns_fresh_tokens_as_is() -> Result<()> { let initial_last_refresh = Utc::now() - Duration::days(1); let initial_tokens = build_tokens(INITIAL_ACCESS_TOKEN, INITIAL_REFRESH_TOKEN); let initial_auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(initial_tokens.clone()), last_refresh: Some(initial_last_refresh), @@ -159,7 +159,7 @@ async fn refreshes_token_when_last_refresh_is_stale() -> Result<()> { let stale_refresh = Utc::now() - Duration::days(9); let initial_tokens = build_tokens(INITIAL_ACCESS_TOKEN, INITIAL_REFRESH_TOKEN); let initial_auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(initial_tokens.clone()), last_refresh: Some(stale_refresh), @@ -218,7 +218,7 @@ async fn refresh_token_returns_permanent_error_for_expired_refresh_token() -> Re let initial_last_refresh = Utc::now() - Duration::days(1); let initial_tokens = build_tokens(INITIAL_ACCESS_TOKEN, INITIAL_REFRESH_TOKEN); let initial_auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(initial_tokens.clone()), last_refresh: Some(initial_last_refresh), @@ -268,7 +268,7 @@ async fn refresh_token_returns_transient_error_on_server_failure() -> Result<()> let initial_last_refresh = Utc::now() - Duration::days(1); let initial_tokens = build_tokens(INITIAL_ACCESS_TOKEN, INITIAL_REFRESH_TOKEN); let initial_auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(initial_tokens.clone()), last_refresh: Some(initial_last_refresh), @@ -320,7 +320,7 @@ async fn unauthorized_recovery_reloads_then_refreshes_tokens() -> Result<()> { let initial_last_refresh = Utc::now() - Duration::days(1); let initial_tokens = build_tokens(INITIAL_ACCESS_TOKEN, INITIAL_REFRESH_TOKEN); let initial_auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(initial_tokens.clone()), last_refresh: Some(initial_last_refresh), @@ -329,7 +329,7 @@ async fn unauthorized_recovery_reloads_then_refreshes_tokens() -> Result<()> { let disk_tokens = build_tokens("disk-access-token", "disk-refresh-token"); let disk_auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(disk_tokens.clone()), last_refresh: Some(initial_last_refresh), @@ -412,7 +412,7 @@ async fn unauthorized_recovery_skips_reload_on_account_mismatch() -> Result<()> let initial_last_refresh = Utc::now() - Duration::days(1); let initial_tokens = build_tokens(INITIAL_ACCESS_TOKEN, INITIAL_REFRESH_TOKEN); let initial_auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(initial_tokens.clone()), last_refresh: Some(initial_last_refresh), @@ -427,7 +427,7 @@ async fn unauthorized_recovery_skips_reload_on_account_mismatch() -> Result<()> ..disk_tokens.clone() }; let disk_auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: None, tokens: Some(disk_tokens), last_refresh: Some(initial_last_refresh), diff --git a/codex-rs/login/src/server.rs b/codex-rs/login/src/server.rs index 5272c84eaa..e571d9b824 100644 --- a/codex-rs/login/src/server.rs +++ b/codex-rs/login/src/server.rs @@ -560,7 +560,7 @@ pub(crate) async fn persist_tokens_async( tokens.account_id = Some(acc.to_string()); } let auth = AuthDotJson { - auth_mode: Some(AuthMode::ChatGPT), + auth_mode: Some(AuthMode::Chatgpt), openai_api_key: api_key, tokens: Some(tokens), last_refresh: Some(Utc::now()), diff --git a/codex-rs/tui/src/onboarding/auth.rs b/codex-rs/tui/src/onboarding/auth.rs index daf64f36d8..7378b6628e 100644 --- a/codex-rs/tui/src/onboarding/auth.rs +++ b/codex-rs/tui/src/onboarding/auth.rs @@ -663,7 +663,7 @@ impl AuthModeWidget { fn handle_existing_chatgpt_login(&mut self) -> bool { if matches!( self.login_status, - LoginStatus::AuthMode(AuthMode::ChatGPT | AuthMode::ChatgptAuthTokens) + LoginStatus::AuthMode(AuthMode::Chatgpt | AuthMode::ChatgptAuthTokens) ) { *self.sign_in_state.write().unwrap() = SignInState::ChatGptSuccess; self.request_frame.schedule_frame(); diff --git a/codex-rs/tui/src/status/helpers.rs b/codex-rs/tui/src/status/helpers.rs index 0a801227f5..bc4cbb9c16 100644 --- a/codex-rs/tui/src/status/helpers.rs +++ b/codex-rs/tui/src/status/helpers.rs @@ -91,7 +91,7 @@ pub(crate) fn compose_account_display( let auth = auth_manager.auth_cached()?; match auth { - CodexAuth::ChatGpt(_) | CodexAuth::ChatGptAuthTokens(_) => { + CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_) => { let email = auth.get_account_email(); let plan = plan .map(|plan_type| title_case(format!("{plan_type:?}").as_str()))