mirror of
https://github.com/openai/codex.git
synced 2026-10-20 17:38:45 +00:00
## Why `token_data` is owned by `codex-login`, but `codex-core` was still re-exporting it. That let callers pull auth token types through `codex-core`, which keeps otherwise unrelated crates coupled to `codex-core` and makes `codex-core` more of a build-graph bottleneck. ## What changed - remove the `codex-core` re-export of `codex_login::token_data` - update the remaining `codex-core` internals that used `crate::token_data` to import `codex_login::token_data` directly - update downstream callers in `codex-rs/chatgpt`, `codex-rs/tui_app_server`, `codex-rs/app-server/tests/common`, and `codex-rs/core/tests` to import `codex_login::token_data` directly - add explicit `codex-login` workspace dependencies and refresh lock metadata for crates that now depend on it directly ## Validation - `cargo test -p codex-chatgpt --locked` - `just argument-comment-lint` - `just bazel-lock-update` - `just bazel-lock-check` ## Notes - attempted `cargo test -p codex-core --locked` and `cargo test -p codex-core auth_refresh --locked`, but both ran out of disk while linking `codex-core` test binaries in the local environment
37 lines
1.0 KiB
Rust
37 lines
1.0 KiB
Rust
use codex_core::AuthManager;
|
|
use codex_login::token_data::TokenData;
|
|
use std::path::Path;
|
|
use std::sync::LazyLock;
|
|
use std::sync::RwLock;
|
|
|
|
use codex_core::auth::AuthCredentialsStoreMode;
|
|
|
|
static CHATGPT_TOKEN: LazyLock<RwLock<Option<TokenData>>> = LazyLock::new(|| RwLock::new(None));
|
|
|
|
pub fn get_chatgpt_token_data() -> Option<TokenData> {
|
|
CHATGPT_TOKEN.read().ok()?.clone()
|
|
}
|
|
|
|
pub fn set_chatgpt_token_data(value: TokenData) {
|
|
if let Ok(mut guard) = CHATGPT_TOKEN.write() {
|
|
*guard = Some(value);
|
|
}
|
|
}
|
|
|
|
/// Initialize the ChatGPT token from auth.json file
|
|
pub async fn init_chatgpt_token_from_auth(
|
|
codex_home: &Path,
|
|
auth_credentials_store_mode: AuthCredentialsStoreMode,
|
|
) -> std::io::Result<()> {
|
|
let auth_manager = AuthManager::new(
|
|
codex_home.to_path_buf(),
|
|
/*enable_codex_api_key_env*/ false,
|
|
auth_credentials_store_mode,
|
|
);
|
|
if let Some(auth) = auth_manager.auth().await {
|
|
let token_data = auth.get_token_data()?;
|
|
set_chatgpt_token_data(token_data);
|
|
}
|
|
Ok(())
|
|
}
|