diff --git a/codex-rs/core/src/codex_thread.rs b/codex-rs/core/src/codex_thread.rs index 1fad2a6a12..bead5769c3 100644 --- a/codex-rs/core/src/codex_thread.rs +++ b/codex-rs/core/src/codex_thread.rs @@ -8,7 +8,6 @@ use crate::file_watcher::WatchRegistration; use crate::protocol::Event; use crate::protocol::Op; use crate::protocol::Submission; -use std::collections::HashMap; use codex_features::Feature; use codex_protocol::config_types::ApprovalsReviewer; use codex_protocol::config_types::Personality; @@ -23,6 +22,7 @@ use codex_protocol::protocol::SessionSource; use codex_protocol::protocol::TokenUsage; use codex_protocol::protocol::W3cTraceContext; use codex_protocol::user_input::UserInput; +use std::collections::HashMap; use std::path::PathBuf; use tokio::sync::Mutex; use tokio::sync::watch; @@ -124,7 +124,7 @@ impl CodexThread { } pub async fn set_dependency_env(&self, values: HashMap) { - self.codex.set_dependency_env(values).await; + self.codex.session.set_dependency_env(values).await; } pub(crate) fn subscribe_status(&self) -> watch::Receiver { diff --git a/codex-rs/tui/src/chatwidget/create_api_key.rs b/codex-rs/tui/src/chatwidget/create_api_key.rs index 941acd5613..d80faab7dd 100644 --- a/codex-rs/tui/src/chatwidget/create_api_key.rs +++ b/codex-rs/tui/src/chatwidget/create_api_key.rs @@ -30,9 +30,7 @@ impl ChatWidget { } } -fn start_create_api_key_command( - app_event_tx: AppEventSender, -) -> Result { +fn start_create_api_key_command(app_event_tx: AppEventSender) -> Result { if read_openai_api_key_from_env().is_some() { return Ok(existing_shell_api_key_message()); } @@ -40,11 +38,8 @@ fn start_create_api_key_command( let session = start_create_api_key_flow() .map_err(|err| format!("Failed to start API key creation: {err}"))?; let browser_opened = session.open_browser(); - let start_message = continue_in_browser_message( - session.auth_url(), - session.callback_port(), - browser_opened, - ); + let start_message = + continue_in_browser_message(session.auth_url(), session.callback_port(), browser_opened); let app_event_tx_for_task = app_event_tx; tokio::spawn(async move { @@ -129,11 +124,8 @@ async fn complete_command( } }; let copy_result = clipboard_text::copy_text_to_clipboard(&provisioned.project_api_key); - let session_env_result = apply_api_key_to_current_session( - &provisioned.project_api_key, - app_event_tx, - ) - .await; + let session_env_result = + apply_api_key_to_current_session(&provisioned.project_api_key, app_event_tx).await; success_cell(&provisioned, copy_result, session_env_result) } @@ -197,9 +189,7 @@ fn success_cell( let hint = Some(format!("{copy_status} {session_env_status}")); history_cell::new_info_event( - format!( - "Created an API key for {organization} / {project}: {masked_api_key}" - ), + format!("Created an API key for {organization} / {project}: {masked_api_key}"), hint, ) } diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__continue_in_browser_message_snapshot.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__continue_in_browser_message_snapshot.snap index 76cafb95c0..f593e47bd2 100644 --- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__continue_in_browser_message_snapshot.snap +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__continue_in_browser_message_snapshot.snap @@ -1,5 +1,6 @@ --- source: tui/src/chatwidget/create_api_key.rs +assertion_line: 260 expression: render_cell(&cell) --- • Finish API key creation via your browser. @@ -10,6 +11,6 @@ expression: render_cell(&cell) https://auth.openai.com/oauth/authorize?client_id=abc - Codex will save OPENAI_API_KEY to /tmp/workspace/.env.local and hot-apply it here when allowed. + Codex will display the new OPENAI_API_KEY here and copy it to your clipboard. On a remote or headless machine, forward localhost:5000 back to this Codex host before opening the link. diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot.snap index 6e50971277..57e054a59d 100644 --- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot.snap +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot.snap @@ -1,5 +1,6 @@ --- source: tui/src/chatwidget/create_api_key.rs +assertion_line: 232 expression: render_cell(&cell) --- -• Created 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 created API key without touching auth.json. +• Created an API key for Default Org / Default Project: sk-proj-123 Copied the full key to your clipboard. Set OPENAI_API_KEY in this Codex session for spawned commands. diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot_when_clipboard_copy_fails.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot_when_clipboard_copy_fails.snap new file mode 100644 index 0000000000..901fafb2eb --- /dev/null +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot_when_clipboard_copy_fails.snap @@ -0,0 +1,6 @@ +--- +source: tui/src/chatwidget/create_api_key.rs +assertion_line: 249 +expression: render_cell(&cell) +--- +• Created an API key for org-default / proj-default: sk-proj-123 Could not copy the key to your clipboard: clipboard unavailable Could not set OPENAI_API_KEY in this Codex session: dependency env unavailable diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot_when_live_apply_is_skipped.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot_when_live_apply_is_skipped.snap deleted file mode 100644 index 6acb8e1fb6..0000000000 --- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__create_api_key__tests__success_cell_snapshot_when_live_apply_is_skipped.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: tui/src/chatwidget/create_api_key.rs -expression: render_cell(&cell) ---- -• Created 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.