mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
codex: reorganize api provision modules
Move the TUI slash command into the chatwidget module and rename the login helper module to match API provisioning behavior. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//! Browser-based helper for onboarding login and Codex auth provisioning.
|
||||
//! Browser-based OAuth flow for provisioning OpenAI project API keys.
|
||||
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
@@ -851,5 +851,5 @@ impl std::fmt::Display for HelperError {
|
||||
impl std::error::Error for HelperError {}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "onboard_oauth_helper_tests.rs"]
|
||||
#[path = "api_provision_tests.rs"]
|
||||
mod tests;
|
||||
@@ -1,6 +1,6 @@
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
if let Err(err) = codex_login::run_onboard_oauth_helper_from_env().await {
|
||||
if let Err(err) = codex_login::run_api_provision_helper_from_env().await {
|
||||
eprintln!("{err}");
|
||||
if let Some(body) = err.body()
|
||||
&& !body.is_empty()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
pub mod auth;
|
||||
pub mod token_data;
|
||||
|
||||
mod api_provision;
|
||||
mod device_code_auth;
|
||||
mod dotenv_api_key;
|
||||
mod onboard_oauth_helper;
|
||||
mod pkce;
|
||||
mod server;
|
||||
|
||||
@@ -17,6 +17,13 @@ pub use server::ServerOptions;
|
||||
pub use server::ShutdownHandle;
|
||||
pub use server::run_login_server;
|
||||
|
||||
pub use ApiProvisionError as OnboardOauthHelperError;
|
||||
pub use api_provision::ApiProvisionOptions;
|
||||
pub use api_provision::HelperError as ApiProvisionError;
|
||||
pub use api_provision::PendingApiProvisioning;
|
||||
pub use api_provision::ProvisionedApiKey;
|
||||
pub use api_provision::run_from_env as run_api_provision_helper_from_env;
|
||||
pub use api_provision::start_api_provisioning;
|
||||
pub use auth::AuthConfig;
|
||||
pub use auth::AuthCredentialsStoreMode;
|
||||
pub use auth::AuthDotJson;
|
||||
@@ -38,10 +45,5 @@ pub use auth::save_auth;
|
||||
pub use codex_app_server_protocol::AuthMode;
|
||||
pub use dotenv_api_key::upsert_dotenv_api_key;
|
||||
pub use dotenv_api_key::validate_dotenv_target;
|
||||
pub use onboard_oauth_helper::ApiProvisionOptions;
|
||||
pub use onboard_oauth_helper::HelperError as OnboardOauthHelperError;
|
||||
pub use onboard_oauth_helper::PendingApiProvisioning;
|
||||
pub use onboard_oauth_helper::ProvisionedApiKey;
|
||||
pub use onboard_oauth_helper::run_from_env as run_onboard_oauth_helper_from_env;
|
||||
pub use onboard_oauth_helper::start_api_provisioning;
|
||||
pub use run_api_provision_helper_from_env as run_onboard_oauth_helper_from_env;
|
||||
pub use token_data::TokenData;
|
||||
|
||||
@@ -291,6 +291,7 @@ use crate::status_indicator_widget::STATUS_DETAILS_DEFAULT_MAX_LINES;
|
||||
use crate::status_indicator_widget::StatusDetailsCapitalization;
|
||||
use crate::text_formatting::truncate_text;
|
||||
use crate::tui::FrameRequester;
|
||||
mod api_provision;
|
||||
mod interrupts;
|
||||
use self::interrupts::InterruptManager;
|
||||
mod agent;
|
||||
@@ -4734,22 +4735,7 @@ impl ChatWidget {
|
||||
});
|
||||
}
|
||||
SlashCommand::ApiProvision => {
|
||||
let cwd = self.status_line_cwd().to_path_buf();
|
||||
match crate::api_provision::start_command(
|
||||
self.app_event_tx.clone(),
|
||||
self.auth_manager.clone(),
|
||||
self.config.codex_home.clone(),
|
||||
cwd,
|
||||
self.config.forced_login_method,
|
||||
) {
|
||||
Ok(start_message) => {
|
||||
self.add_boxed_history(Box::new(start_message));
|
||||
self.request_redraw();
|
||||
}
|
||||
Err(err) => {
|
||||
self.add_error_message(err);
|
||||
}
|
||||
}
|
||||
self.start_api_provision();
|
||||
}
|
||||
SlashCommand::Copy => {
|
||||
let Some(text) = self.last_copyable_output.as_deref() else {
|
||||
|
||||
@@ -17,12 +17,33 @@ use codex_protocol::config_types::ForcedLoginMethod;
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Line;
|
||||
|
||||
use super::ChatWidget;
|
||||
use crate::app_event::AppEvent;
|
||||
use crate::app_event_sender::AppEventSender;
|
||||
use crate::history_cell;
|
||||
use crate::history_cell::PlainHistoryCell;
|
||||
|
||||
pub(crate) fn start_command(
|
||||
impl ChatWidget {
|
||||
pub(crate) fn start_api_provision(&mut self) {
|
||||
match start_api_provision(
|
||||
self.app_event_tx.clone(),
|
||||
self.auth_manager.clone(),
|
||||
self.config.codex_home.clone(),
|
||||
self.status_line_cwd().to_path_buf(),
|
||||
self.config.forced_login_method,
|
||||
) {
|
||||
Ok(start_message) => {
|
||||
self.add_to_history(start_message);
|
||||
self.request_redraw();
|
||||
}
|
||||
Err(err) => {
|
||||
self.add_error_message(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn start_api_provision(
|
||||
app_event_tx: AppEventSender,
|
||||
auth_manager: Arc<AuthManager>,
|
||||
codex_home: PathBuf,
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
source: tui/src/api_provision.rs
|
||||
source: tui/src/chatwidget/api_provision.rs
|
||||
expression: render_cell(&cell)
|
||||
---
|
||||
• Finish API provisioning via your browser.
|
||||
@@ -1,6 +1,5 @@
|
||||
---
|
||||
source: tui/src/api_provision.rs
|
||||
assertion_line: 192
|
||||
source: tui/src/chatwidget/api_provision.rs
|
||||
expression: render_cell(&cell)
|
||||
---
|
||||
• Provisioned an API key for Default Org / Default Project and saved OPENAI_API_KEY to /tmp/workspace/.env.local. Updated this session to use the newly provisioned API key without touching auth.json.
|
||||
@@ -1,6 +1,5 @@
|
||||
---
|
||||
source: tui/src/api_provision.rs
|
||||
assertion_line: 214
|
||||
source: tui/src/chatwidget/api_provision.rs
|
||||
expression: render_cell(&cell)
|
||||
---
|
||||
• Provisioned an API key for org-default / proj-default and saved OPENAI_API_KEY to /tmp/workspace/.env.local. Saved OPENAI_API_KEY to .env.local, but left this session unchanged because ChatGPT login is required here.
|
||||
@@ -61,7 +61,6 @@ use tracing_subscriber::prelude::*;
|
||||
use uuid::Uuid;
|
||||
|
||||
mod additional_dirs;
|
||||
mod api_provision;
|
||||
mod app;
|
||||
mod app_backtrack;
|
||||
mod app_event;
|
||||
|
||||
Reference in New Issue
Block a user