mirror of
https://github.com/openai/codex.git
synced 2026-05-02 12:21:26 +03:00
fix: taking plan type from usage endpoint instead of thru auth token (#7610)
pull plan type from the usage endpoint, persist it in session state / tui state, and propagate through rate limit snapshots
This commit is contained in:
@@ -10,6 +10,7 @@ use codex_core::config::Config;
|
||||
use codex_core::protocol::SandboxPolicy;
|
||||
use codex_core::protocol::TokenUsage;
|
||||
use codex_protocol::ConversationId;
|
||||
use codex_protocol::account::PlanType;
|
||||
use ratatui::prelude::*;
|
||||
use ratatui::style::Stylize;
|
||||
use std::collections::BTreeSet;
|
||||
@@ -65,6 +66,7 @@ struct StatusHistoryCell {
|
||||
rate_limits: StatusRateLimitData,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn new_status_output(
|
||||
config: &Config,
|
||||
auth_manager: &AuthManager,
|
||||
@@ -72,6 +74,7 @@ pub(crate) fn new_status_output(
|
||||
context_usage: Option<&TokenUsage>,
|
||||
session_id: &Option<ConversationId>,
|
||||
rate_limits: Option<&RateLimitSnapshotDisplay>,
|
||||
plan_type: Option<PlanType>,
|
||||
now: DateTime<Local>,
|
||||
) -> CompositeHistoryCell {
|
||||
let command = PlainHistoryCell::new(vec!["/status".magenta().into()]);
|
||||
@@ -82,6 +85,7 @@ pub(crate) fn new_status_output(
|
||||
context_usage,
|
||||
session_id,
|
||||
rate_limits,
|
||||
plan_type,
|
||||
now,
|
||||
);
|
||||
|
||||
@@ -89,6 +93,7 @@ pub(crate) fn new_status_output(
|
||||
}
|
||||
|
||||
impl StatusHistoryCell {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn new(
|
||||
config: &Config,
|
||||
auth_manager: &AuthManager,
|
||||
@@ -96,6 +101,7 @@ impl StatusHistoryCell {
|
||||
context_usage: Option<&TokenUsage>,
|
||||
session_id: &Option<ConversationId>,
|
||||
rate_limits: Option<&RateLimitSnapshotDisplay>,
|
||||
plan_type: Option<PlanType>,
|
||||
now: DateTime<Local>,
|
||||
) -> Self {
|
||||
let config_entries = create_config_summary_entries(config);
|
||||
@@ -111,7 +117,7 @@ impl StatusHistoryCell {
|
||||
SandboxPolicy::WorkspaceWrite { .. } => "workspace-write".to_string(),
|
||||
};
|
||||
let agents_summary = compose_agents_summary(config);
|
||||
let account = compose_account_display(auth_manager);
|
||||
let account = compose_account_display(auth_manager, plan_type);
|
||||
let session_id = session_id.as_ref().map(std::string::ToString::to_string);
|
||||
let context_window = config.model_context_window.and_then(|window| {
|
||||
context_usage.map(|usage| StatusContextWindowData {
|
||||
|
||||
@@ -6,6 +6,7 @@ use codex_app_server_protocol::AuthMode;
|
||||
use codex_core::AuthManager;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::project_doc::discover_project_doc_paths;
|
||||
use codex_protocol::account::PlanType;
|
||||
use std::path::Path;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
@@ -83,13 +84,18 @@ pub(crate) fn compose_agents_summary(config: &Config) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn compose_account_display(auth_manager: &AuthManager) -> Option<StatusAccountDisplay> {
|
||||
pub(crate) fn compose_account_display(
|
||||
auth_manager: &AuthManager,
|
||||
plan: Option<PlanType>,
|
||||
) -> Option<StatusAccountDisplay> {
|
||||
let auth = auth_manager.auth()?;
|
||||
|
||||
match auth.mode {
|
||||
AuthMode::ChatGPT => {
|
||||
let email = auth.get_account_email();
|
||||
let plan = auth.raw_plan_type().map(|plan| title_case(plan.as_str()));
|
||||
let plan = plan
|
||||
.map(|plan_type| title_case(format!("{plan_type:?}").as_str()))
|
||||
.or_else(|| Some("Unknown".to_string()));
|
||||
Some(StatusAccountDisplay::ChatGpt { email, plan })
|
||||
}
|
||||
AuthMode::ApiKey => Some(StatusAccountDisplay::ApiKey),
|
||||
|
||||
@@ -120,6 +120,7 @@ fn status_snapshot_includes_reasoning_details() {
|
||||
resets_at: Some(reset_at_from(&captured_at, 1_200)),
|
||||
}),
|
||||
credits: None,
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
|
||||
@@ -130,6 +131,7 @@ fn status_snapshot_includes_reasoning_details() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
captured_at,
|
||||
);
|
||||
let mut rendered_lines = render_lines(&composite.display_lines(80));
|
||||
@@ -171,6 +173,7 @@ fn status_snapshot_includes_monthly_limit() {
|
||||
}),
|
||||
secondary: None,
|
||||
credits: None,
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
|
||||
@@ -181,6 +184,7 @@ fn status_snapshot_includes_monthly_limit() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
captured_at,
|
||||
);
|
||||
let mut rendered_lines = render_lines(&composite.display_lines(80));
|
||||
@@ -211,6 +215,7 @@ fn status_snapshot_shows_unlimited_credits() {
|
||||
unlimited: true,
|
||||
balance: None,
|
||||
}),
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
let composite = new_status_output(
|
||||
@@ -220,6 +225,7 @@ fn status_snapshot_shows_unlimited_credits() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
captured_at,
|
||||
);
|
||||
let rendered = render_lines(&composite.display_lines(120));
|
||||
@@ -249,6 +255,7 @@ fn status_snapshot_shows_positive_credits() {
|
||||
unlimited: false,
|
||||
balance: Some("12.5".to_string()),
|
||||
}),
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
let composite = new_status_output(
|
||||
@@ -258,6 +265,7 @@ fn status_snapshot_shows_positive_credits() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
captured_at,
|
||||
);
|
||||
let rendered = render_lines(&composite.display_lines(120));
|
||||
@@ -287,6 +295,7 @@ fn status_snapshot_hides_zero_credits() {
|
||||
unlimited: false,
|
||||
balance: Some("0".to_string()),
|
||||
}),
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
let composite = new_status_output(
|
||||
@@ -296,6 +305,7 @@ fn status_snapshot_hides_zero_credits() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
captured_at,
|
||||
);
|
||||
let rendered = render_lines(&composite.display_lines(120));
|
||||
@@ -323,6 +333,7 @@ fn status_snapshot_hides_when_has_no_credits_flag() {
|
||||
unlimited: true,
|
||||
balance: None,
|
||||
}),
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
let composite = new_status_output(
|
||||
@@ -332,6 +343,7 @@ fn status_snapshot_hides_when_has_no_credits_flag() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
captured_at,
|
||||
);
|
||||
let rendered = render_lines(&composite.display_lines(120));
|
||||
@@ -369,6 +381,7 @@ fn status_card_token_usage_excludes_cached_tokens() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
None,
|
||||
None,
|
||||
now,
|
||||
);
|
||||
let rendered = render_lines(&composite.display_lines(120));
|
||||
@@ -410,6 +423,7 @@ fn status_snapshot_truncates_in_narrow_terminal() {
|
||||
}),
|
||||
secondary: None,
|
||||
credits: None,
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
|
||||
@@ -420,6 +434,7 @@ fn status_snapshot_truncates_in_narrow_terminal() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
captured_at,
|
||||
);
|
||||
let mut rendered_lines = render_lines(&composite.display_lines(70));
|
||||
@@ -461,6 +476,7 @@ fn status_snapshot_shows_missing_limits_message() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
None,
|
||||
None,
|
||||
now,
|
||||
);
|
||||
let mut rendered_lines = render_lines(&composite.display_lines(80));
|
||||
@@ -509,6 +525,7 @@ fn status_snapshot_includes_credits_and_limits() {
|
||||
unlimited: false,
|
||||
balance: Some("37.5".to_string()),
|
||||
}),
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
|
||||
@@ -519,6 +536,7 @@ fn status_snapshot_includes_credits_and_limits() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
captured_at,
|
||||
);
|
||||
let mut rendered_lines = render_lines(&composite.display_lines(80));
|
||||
@@ -551,6 +569,7 @@ fn status_snapshot_shows_empty_limits_message() {
|
||||
primary: None,
|
||||
secondary: None,
|
||||
credits: None,
|
||||
plan_type: None,
|
||||
};
|
||||
let captured_at = chrono::Local
|
||||
.with_ymd_and_hms(2024, 6, 7, 8, 9, 10)
|
||||
@@ -565,6 +584,7 @@ fn status_snapshot_shows_empty_limits_message() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
captured_at,
|
||||
);
|
||||
let mut rendered_lines = render_lines(&composite.display_lines(80));
|
||||
@@ -609,6 +629,7 @@ fn status_snapshot_shows_stale_limits_message() {
|
||||
resets_at: Some(reset_at_from(&captured_at, 1_800)),
|
||||
}),
|
||||
credits: None,
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
let now = captured_at + ChronoDuration::minutes(20);
|
||||
@@ -620,6 +641,7 @@ fn status_snapshot_shows_stale_limits_message() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
now,
|
||||
);
|
||||
let mut rendered_lines = render_lines(&composite.display_lines(80));
|
||||
@@ -668,6 +690,7 @@ fn status_snapshot_cached_limits_hide_credits_without_flag() {
|
||||
unlimited: false,
|
||||
balance: Some("80".to_string()),
|
||||
}),
|
||||
plan_type: None,
|
||||
};
|
||||
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
|
||||
let now = captured_at + ChronoDuration::minutes(20);
|
||||
@@ -679,6 +702,7 @@ fn status_snapshot_cached_limits_hide_credits_without_flag() {
|
||||
Some(&usage),
|
||||
&None,
|
||||
Some(&rate_display),
|
||||
None,
|
||||
now,
|
||||
);
|
||||
let mut rendered_lines = render_lines(&composite.display_lines(80));
|
||||
@@ -725,6 +749,7 @@ fn status_context_window_uses_last_usage() {
|
||||
Some(&last_usage),
|
||||
&None,
|
||||
None,
|
||||
None,
|
||||
now,
|
||||
);
|
||||
let rendered_lines = render_lines(&composite.display_lines(80));
|
||||
|
||||
Reference in New Issue
Block a user