From 20fda28fb4ffafb103a94dddd3d09f9e331c5562 Mon Sep 17 00:00:00 2001 From: RCD <90105158+Finesssee@users.noreply.github.com> Date: Sun, 5 Apr 2026 14:52:33 +0700 Subject: [PATCH] feat: preserve codex plan metadata in rust state --- docs/rust-replatform.md | 2 +- rust/proxypilot-rs/src/accounts.rs | 5 +++-- rust/proxypilot-rs/src/state.rs | 35 ++++++++++++++++++++++++++++++ rust/proxypilot-rs/src/tui.rs | 3 +++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/docs/rust-replatform.md b/docs/rust-replatform.md index 203772af..010c9355 100644 --- a/docs/rust-replatform.md +++ b/docs/rust-replatform.md @@ -18,7 +18,7 @@ This branch carries the Rust rewrite line for ProxyPilot. - a TOML config model plus a separate local state file for saved accounts - explicit Codex-facing routes for `/v1/models`, `/v1/chat/completions`, and `/v1/responses` - CLI account commands for adding, importing, device-login, refresh, listing, activating, and removing Codex accounts -- a TUI account/operator panel that shows models, local accounts, active account state, terminal actions for activate/refresh/delete, and selected-account token expiry health +- a TUI account/operator panel that shows models, local accounts, active account state, terminal actions for activate/refresh/delete, and selected-account token expiry and plan metadata - runtime credential resolution that prefers the active saved account over the config fallback key - end-to-end tests against a mocked upstream server diff --git a/rust/proxypilot-rs/src/accounts.rs b/rust/proxypilot-rs/src/accounts.rs index bcd904b2..bbdc29cf 100644 --- a/rust/proxypilot-rs/src/accounts.rs +++ b/rust/proxypilot-rs/src/accounts.rs @@ -49,9 +49,10 @@ pub fn list_accounts(config: &AppConfig, config_path: &Path) -> Result<()> { }; let email = account.email.as_deref().unwrap_or("-"); let source = account.source.as_deref().unwrap_or("-"); + let plan = account.plan_type.as_deref().unwrap_or("-"); println!( - "{marker} {:<16} provider={} email={} source={}", - account.name, account.provider, email, source + "{marker} {:<16} provider={} email={} plan={} source={}", + account.name, account.provider, email, plan, source ); } diff --git a/rust/proxypilot-rs/src/state.rs b/rust/proxypilot-rs/src/state.rs index 5bf1ac85..424951bd 100644 --- a/rust/proxypilot-rs/src/state.rs +++ b/rust/proxypilot-rs/src/state.rs @@ -28,6 +28,8 @@ pub struct AccountEntry { #[serde(default)] pub account_id: Option, #[serde(default)] + pub plan_type: Option, + #[serde(default)] pub expires_at: Option, #[serde(default)] pub source: Option, @@ -41,6 +43,7 @@ pub struct ActiveCodexAccount { pub id_token: Option, pub email: Option, pub account_id: Option, + pub plan_type: Option, pub expires_at: Option, } @@ -94,6 +97,7 @@ impl AccountState { id_token: None, email: None, account_id: None, + plan_type: None, expires_at: None, source: Some("manual".to_string()), }); @@ -154,6 +158,7 @@ impl AccountState { id_token: account.id_token.clone(), email: account.email.clone(), account_id: account.account_id.clone(), + plan_type: account.plan_type.clone(), expires_at: account.expires_at.clone(), }) } @@ -170,6 +175,7 @@ impl AccountState { id_token: account.id_token.clone(), email: account.email.clone(), account_id: account.account_id.clone(), + plan_type: account.plan_type.clone(), expires_at: account.expires_at.clone(), }) } @@ -233,6 +239,7 @@ impl AccountState { id_token: None, email: optional_trimmed(imported.email), account_id: optional_trimmed(imported.account_id), + plan_type: None, expires_at: optional_trimmed(imported.expires_at), source: Some(source), }); @@ -269,6 +276,7 @@ impl AccountState { id_token: optional_trimmed(result.id_token), email: result.email, account_id: result.account_id, + plan_type: result.plan_type, expires_at: result.expires_at, source: Some("device-login".to_string()), }); @@ -301,6 +309,9 @@ impl AccountState { if result.account_id.is_some() { entry.account_id = result.account_id; } + if result.plan_type.is_some() { + entry.plan_type = result.plan_type; + } if result.expires_at.is_some() { entry.expires_at = result.expires_at; } @@ -378,6 +389,7 @@ mod tests { .unwrap(); assert_eq!(account.email.as_deref(), Some("dev@example.com")); assert_eq!(account.account_id.as_deref(), Some("acct_123")); + assert_eq!(account.plan_type.as_deref(), None); assert_eq!(account.expires_at.as_deref(), Some("2026-04-06T00:00:00Z")); assert_eq!(account.source.as_deref(), Some("file")); } @@ -398,4 +410,27 @@ mod tests { assert_eq!(state.accounts.len(), 1); assert_eq!(state.accounts[0].name, "backup"); } + + #[test] + fn device_account_carries_plan_type() { + let mut state = AccountState::default(); + state + .add_device_codex_account( + "device".to_string(), + crate::codex::DeviceAuthResult { + access_token: "access".to_string(), + refresh_token: "refresh".to_string(), + id_token: "id".to_string(), + email: Some("dev@example.com".to_string()), + account_id: Some("acct_123".to_string()), + plan_type: Some("pro".to_string()), + expires_at: Some("2026-04-06T00:00:00Z".to_string()), + }, + true, + ) + .unwrap(); + + let account = state.active_codex_account().unwrap(); + assert_eq!(account.plan_type.as_deref(), Some("pro")); + } } diff --git a/rust/proxypilot-rs/src/tui.rs b/rust/proxypilot-rs/src/tui.rs index 6adf0123..c8508344 100644 --- a/rust/proxypilot-rs/src/tui.rs +++ b/rust/proxypilot-rs/src/tui.rs @@ -147,6 +147,7 @@ impl TuiApp { .account_id .clone() .unwrap_or_else(|| "-".to_string()), + plan_type: account.plan_type.clone().unwrap_or_else(|| "-".to_string()), source: account.source.clone().unwrap_or_else(|| "-".to_string()), is_active: state.active_account.as_deref() == Some(account.name.as_str()), can_refresh: account @@ -416,6 +417,7 @@ fn render(frame: &mut ratatui::Frame<'_>, app: &TuiApp) { Line::from(format!("Name: {}", selected.name)), Line::from(format!("Email: {}", selected.email)), Line::from(format!("Account ID: {}", selected.account_id)), + Line::from(format!("Plan: {}", selected.plan_type)), Line::from(format!("Token mode: {}", selected.token_mode())), Line::from(format!("Expiry: {}", selected.expiry_detail())), Line::from(format!("Source: {}", selected.source)), @@ -473,6 +475,7 @@ struct AccountRow { name: String, email: String, account_id: String, + plan_type: String, source: String, is_active: bool, can_refresh: bool,