feat: preserve codex plan metadata in rust state

This commit is contained in:
RCD
2026-04-05 14:52:33 +07:00
parent 469fd38420
commit 20fda28fb4
4 changed files with 42 additions and 3 deletions
+1 -1
View File
@@ -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
+3 -2
View File
@@ -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
);
}
+35
View File
@@ -28,6 +28,8 @@ pub struct AccountEntry {
#[serde(default)]
pub account_id: Option<String>,
#[serde(default)]
pub plan_type: Option<String>,
#[serde(default)]
pub expires_at: Option<String>,
#[serde(default)]
pub source: Option<String>,
@@ -41,6 +43,7 @@ pub struct ActiveCodexAccount {
pub id_token: Option<String>,
pub email: Option<String>,
pub account_id: Option<String>,
pub plan_type: Option<String>,
pub expires_at: Option<String>,
}
@@ -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"));
}
}
+3
View File
@@ -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,