mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
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:
1 parent
af3bc6f796
commit
ca53e19c75
68 files changed
+6357
-67
No files matched your search
@@ -235,6 +235,12 @@ impl App {
|
||||
self.agents_overview.usage_disabled = false;
|
||||
self.repaint_agents_overview();
|
||||
self.chat_widget.cyber_policy_notice = Default::default();
|
||||
if let Some(crate::pager_overlay::Overlay::Analytics(view)) = &mut self.overlay {
|
||||
view.refresh();
|
||||
}
|
||||
if let Some(view) = &mut self.retained_analytics {
|
||||
view.cancel_loads();
|
||||
}
|
||||
self.rate_limit_hard_stop_generation =
|
||||
self.rate_limit_hard_stop_generation.wrapping_add(1);
|
||||
self.rate_limit_refresh_state.invalidate_recovery();
|
||||
|
||||
@@ -1609,6 +1609,21 @@ impl App {
|
||||
self.chat_widget
|
||||
.add_token_activity_output(crate::chatwidget::TokenActivityView::Daily);
|
||||
}
|
||||
AppEvent::OpenAnalytics => {
|
||||
tui.enter_alt_screen()?;
|
||||
let mut view = self.retained_analytics.take().unwrap_or_else(|| {
|
||||
Box::new(crate::analytics::AnalyticsView::new(self.keymap.list.clone()))
|
||||
});
|
||||
view.keymap = self.keymap.list.clone();
|
||||
view.open(
|
||||
app_server.request_handle(),
|
||||
tui.frame_requester(),
|
||||
self.model_catalog.try_list_models()?,
|
||||
std::sync::Arc::new(self.config.clone()),
|
||||
);
|
||||
self.overlay = Some(Overlay::Analytics(view));
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
AppEvent::OpenRateLimitResetCredits => {
|
||||
let request_id = self.chat_widget.show_rate_limit_reset_loading_popup();
|
||||
self.refresh_rate_limits(
|
||||
|
||||
@@ -755,6 +755,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
last_thread_usage_status_cell: None,
|
||||
pending_thread_usage_history_refresh: false,
|
||||
overlay: None,
|
||||
retained_analytics: None,
|
||||
deferred_history_lines: Vec::new(),
|
||||
has_emitted_history_lines: false,
|
||||
transcript_reflow: TranscriptReflowState::default(),
|
||||
|
||||
@@ -41,6 +41,7 @@ pub(super) async fn make_test_app() -> App {
|
||||
last_thread_usage_status_cell: None,
|
||||
pending_thread_usage_history_refresh: false,
|
||||
overlay: None,
|
||||
retained_analytics: None,
|
||||
deferred_history_lines: Vec::new(),
|
||||
has_emitted_history_lines: false,
|
||||
transcript_reflow: TranscriptReflowState::default(),
|
||||
|
||||
@@ -5888,6 +5888,7 @@ async fn make_test_app() -> App {
|
||||
last_thread_usage_status_cell: None,
|
||||
pending_thread_usage_history_refresh: false,
|
||||
overlay: None,
|
||||
retained_analytics: None,
|
||||
deferred_history_lines: Vec::new(),
|
||||
has_emitted_history_lines: false,
|
||||
transcript_reflow: TranscriptReflowState::default(),
|
||||
@@ -5987,6 +5988,7 @@ pub(super) async fn make_test_app_with_channels() -> (
|
||||
last_thread_usage_status_cell: None,
|
||||
pending_thread_usage_history_refresh: false,
|
||||
overlay: None,
|
||||
retained_analytics: None,
|
||||
deferred_history_lines: Vec::new(),
|
||||
has_emitted_history_lines: false,
|
||||
transcript_reflow: TranscriptReflowState::default(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Regression coverage for transcript viewer input, prompt selection, and restoration.
|
||||
//!
|
||||
//! The default-off feature must leave the existing viewer and its draft intact.
|
||||
//! Analytics also preserves the composer and stays separate from transcript backtracking.
|
||||
|
||||
use super::*;
|
||||
use crate::test_support::test_path_display;
|
||||
@@ -39,6 +40,40 @@ async fn press_key(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn analytics_preserves_the_draft_and_retains_the_view_on_reopen() -> Result<()> {
|
||||
let (mut app, _app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
let mut app_server = start_config_write_test_app_server(&app).await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
app.chat_widget
|
||||
.apply_external_edit("preserved draft".into());
|
||||
app.handle_event(&mut tui, &mut app_server, AppEvent::OpenAnalytics)
|
||||
.await?;
|
||||
for code in [
|
||||
KeyCode::Char('4'),
|
||||
KeyCode::Enter,
|
||||
KeyCode::Down,
|
||||
KeyCode::Char('r'),
|
||||
] {
|
||||
press_key(&mut app, &mut tui, &mut app_server, code).await?;
|
||||
assert!(matches!(app.overlay, Some(Overlay::Analytics(_))));
|
||||
assert!(!app.backtrack.overlay_preview_active);
|
||||
}
|
||||
press_key(&mut app, &mut tui, &mut app_server, KeyCode::Char('q')).await?;
|
||||
assert!(app.overlay.is_none());
|
||||
assert!(app.retained_analytics.is_some());
|
||||
app.handle_event(&mut tui, &mut app_server, AppEvent::OpenAnalytics)
|
||||
.await?;
|
||||
assert!(matches!(app.overlay, Some(Overlay::Analytics(_))));
|
||||
assert!(app.retained_analytics.is_none());
|
||||
press_key(&mut app, &mut tui, &mut app_server, KeyCode::Char('q')).await?;
|
||||
assert_eq!(
|
||||
app.chat_widget.composer_text_with_pending(),
|
||||
"preserved draft"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn transcript_flag_off_preserves_viewer_and_backtracking() -> Result<()> {
|
||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
|
||||
Reference in new issue
Block a user