Add an account analytics dashboard to /usage (#45764)

## What changed

- Add “Explore analytics” to the `/usage` menu for ChatGPT accounts, opening a full-screen dashboard.
- Show usage and messages for consumer accounts, credits and token usage for Business and Enterprise accounts, and plugin and skill activity for both.
- Support overview and maximized views, 7- and 30-day ranges, report grouping, daily details, model filtering for token usage, and refresh.
- Keep report loading and errors independent, cancel pending loads on close, and retain navigation state across reopening while preserving the composer draft.

## Testing

Add regression and snapshot coverage for account-specific reports, range and grouping changes, model filtering, loading and cancellation, small terminals, terminal colors, and draft preservation.

GitOrigin-RevId: 46da94a14d6e227551e740b85f9d2d552aaf75b0
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-09-15 19:01:41 +00:00
1 parent af3bc6f796
commit ca53e19c75
68 files changed
+6357 -67

No files matched your search

-33
View File
@@ -101,13 +101,6 @@ impl<T: Send + 'static> Load<T> {
}
}
pub(super) fn error(error: codex_app_server_client::TypedRequestError) -> String {
match error {
codex_app_server_client::TypedRequestError::Server { source, .. } => source.message,
_ => "Couldn't load analytics. Press R to retry.".into(),
}
}
/// Keep tiny refunds visible while avoiding noise on ordinary credit amounts.
pub(super) fn amount(value: f64) -> String {
if value == 0.0 {
@@ -154,32 +147,6 @@ pub(super) fn credit_amount(value: f64) -> String {
}
}
/// Format integer millionths without floating-point rounding or hiding tiny adjustments.
pub(super) fn credits(micros: i64) -> String {
let magnitude = micros.unsigned_abs();
if magnitude > 0 && magnitude < 10_000 {
let fractional = format!("{magnitude:06}");
return format!(
"{}0.{}",
if micros < 0 { "-" } else { "" },
fractional.trim_end_matches('0')
);
}
let cents = (magnitude + 5_000) / 10_000;
let mut whole = (cents / 100).to_string();
let digits = whole.len();
for index in (1..digits).rev() {
if (digits - index).is_multiple_of(/*rhs*/ 3) {
whole.insert(index, ',');
}
}
format!(
"{}{whole}.{:02}",
if micros < 0 { "-" } else { "" },
cents % 100
)
}
pub(super) fn date(date: &str) -> String {
chrono::NaiveDate::parse_from_str(date, "%Y-%m-%d")
.map(|date| date.format("%b %-d").to_string())