mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add an account Summary tab to Analytics (#45769)
## What changed - Make Summary the initial Analytics tab, showing profile identity, token totals, streaks, activity insights, and most-used plugins and skills. - Move daily, weekly, and cumulative token activity charts into Summary. Replace the usage menu's separate views with “View analytics”; `/usage weekly` and the other explicit modes open Summary with the requested view, while reopening from the menu retains navigation. - Load account profiles independently of other reports, preserve missing values separately from zero, and reject responses when the active account changes. Refresh retries profile failures. - Adapt Summary to narrow terminals and compact large chart totals and axis labels. Show the account email without its ID in the Analytics header. - Flush queued transcript history before opening an overlay so startup output stays in the transcript. ## Testing Add profile decoding and account identity tests, Summary layout and navigation snapshots, refresh and cancellation coverage, and regression tests for retained navigation and transcript history when opening Analytics. GitOrigin-RevId: 6dbe6c4c98209000d8b4bc18a4e01b98fab5991a
This commit is contained in:
1 parent
8f0d2459ac
commit
9bd49c9dcc
122 files changed
+3685
-1980
No files matched your search
@@ -37,6 +37,7 @@ use std::fmt;
|
||||
pub(crate) mod analytics;
|
||||
mod chatgpt_turn_cost;
|
||||
pub(crate) mod plan_history;
|
||||
pub(crate) mod profile;
|
||||
mod rate_limit_resets;
|
||||
pub(crate) mod task_usage;
|
||||
mod thread_usage;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
//! Read-only profile statistics shared with the desktop account summary.
|
||||
//! Optional fields retain absence; unknown invocation kinds do not invalidate other statistics.
|
||||
|
||||
use super::Client;
|
||||
use super::RequestError;
|
||||
use crate::TokenUsageProfileStats;
|
||||
use http::Method;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||
pub struct AccountProfile {
|
||||
pub profile: Option<ProfileIdentity>,
|
||||
pub metadata: Option<ProfileMetadata>,
|
||||
pub stats: ProfileStats,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||
pub struct ProfileIdentity {
|
||||
pub display_name: Option<String>,
|
||||
pub username: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||
pub struct ProfileMetadata {
|
||||
pub stats_as_of: Option<String>,
|
||||
pub stats_error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||
pub struct ProfileStats {
|
||||
#[serde(flatten)]
|
||||
pub tokens: TokenUsageProfileStats,
|
||||
pub fast_mode_usage_percentage: Option<serde_json::Number>,
|
||||
pub most_used_reasoning_effort: Option<String>,
|
||||
pub most_used_reasoning_effort_percentage: Option<serde_json::Number>,
|
||||
pub unique_skills_used: Option<u64>,
|
||||
pub total_skills_used: Option<u64>,
|
||||
pub total_threads: Option<u64>,
|
||||
pub top_invocations: Option<Vec<ProfileInvocation>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||
pub struct ProfileInvocation {
|
||||
#[serde(rename = "type")]
|
||||
pub kind: ProfileInvocationKind,
|
||||
pub plugin_name: Option<String>,
|
||||
pub skill_name: Option<String>,
|
||||
pub usage_count: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ProfileInvocationKind {
|
||||
Plugin,
|
||||
Skill,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Read the full profile using the same route as account token usage.
|
||||
pub async fn get_account_profile(&self) -> Result<AccountProfile, RequestError> {
|
||||
let url = self.token_usage_profile_url();
|
||||
let request = self.request(Method::GET, &url).headers(self.headers());
|
||||
let (body, _) = self.exec_request_detailed(request, "GET", &url).await?;
|
||||
serde_json::from_str(&body)
|
||||
.map_err(|_| RequestError::Other(anyhow::anyhow!("Invalid account profile response.")))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "profile_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,126 @@
|
||||
//! Full and partial profile decoding through the authenticated HTTP client.
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
|
||||
#[tokio::test]
|
||||
async fn profile_keeps_missing_zero_and_future_invocations_distinct() {
|
||||
let server = MockServer::start().await;
|
||||
let client = Client::new(
|
||||
server.uri(),
|
||||
codex_http_client::HttpClientFactory::new(
|
||||
codex_http_client::OutboundProxyPolicy::ReqwestDefault,
|
||||
),
|
||||
);
|
||||
let empty = AccountProfile {
|
||||
profile: None,
|
||||
metadata: None,
|
||||
stats: ProfileStats {
|
||||
tokens: TokenUsageProfileStats {
|
||||
lifetime_tokens: None,
|
||||
peak_daily_tokens: None,
|
||||
longest_running_turn_sec: None,
|
||||
current_streak_days: None,
|
||||
longest_streak_days: None,
|
||||
daily_usage_buckets: None,
|
||||
},
|
||||
fast_mode_usage_percentage: None,
|
||||
most_used_reasoning_effort: None,
|
||||
most_used_reasoning_effort_percentage: None,
|
||||
unique_skills_used: None,
|
||||
total_skills_used: None,
|
||||
total_threads: None,
|
||||
top_invocations: None,
|
||||
},
|
||||
};
|
||||
let full = AccountProfile {
|
||||
profile: Some(ProfileIdentity {
|
||||
display_name: Some("Test user".into()),
|
||||
username: Some("test.user".into()),
|
||||
}),
|
||||
metadata: Some(ProfileMetadata {
|
||||
stats_as_of: Some("2026-09-09".into()),
|
||||
stats_error: Some("partial upstream data".into()),
|
||||
}),
|
||||
stats: ProfileStats {
|
||||
tokens: TokenUsageProfileStats {
|
||||
lifetime_tokens: Some(142_300_000_000),
|
||||
peak_daily_tokens: Some(7_000_000_000),
|
||||
longest_running_turn_sec: Some(158_760),
|
||||
current_streak_days: Some(158),
|
||||
longest_streak_days: Some(160),
|
||||
daily_usage_buckets: Some(vec![crate::TokenUsageProfileDailyBucket {
|
||||
start_date: "2026-09-09".into(),
|
||||
tokens: 42,
|
||||
}]),
|
||||
},
|
||||
fast_mode_usage_percentage: serde_json::Number::from_f64(/*f*/ 37.5),
|
||||
most_used_reasoning_effort: Some("high".into()),
|
||||
most_used_reasoning_effort_percentage: Some(26.into()),
|
||||
unique_skills_used: Some(147),
|
||||
total_skills_used: Some(13_190),
|
||||
total_threads: Some(0),
|
||||
top_invocations: Some(vec![
|
||||
ProfileInvocation {
|
||||
kind: ProfileInvocationKind::Unknown,
|
||||
plugin_name: None,
|
||||
skill_name: None,
|
||||
usage_count: None,
|
||||
},
|
||||
ProfileInvocation {
|
||||
kind: ProfileInvocationKind::Skill,
|
||||
plugin_name: None,
|
||||
skill_name: Some("review".into()),
|
||||
usage_count: Some(12),
|
||||
},
|
||||
ProfileInvocation {
|
||||
kind: ProfileInvocationKind::Plugin,
|
||||
plugin_name: Some("github".into()),
|
||||
skill_name: None,
|
||||
usage_count: Some(34),
|
||||
},
|
||||
]),
|
||||
},
|
||||
};
|
||||
for (body, expected) in [
|
||||
(json!({"stats":{}}), empty),
|
||||
(
|
||||
json!({
|
||||
"profile":{"display_name":"Test user","username":"test.user"},
|
||||
"metadata":{"stats_as_of":"2026-09-09","stats_error":"partial upstream data"},
|
||||
"stats":{
|
||||
"lifetime_tokens":142_300_000_000_i64,"peak_daily_tokens":7_000_000_000_i64,
|
||||
"longest_running_turn_sec":158_760,"current_streak_days":158,"longest_streak_days":160,
|
||||
"daily_usage_buckets":[{"start_date":"2026-09-09","tokens":42}],
|
||||
"fast_mode_usage_percentage":37.5,"most_used_reasoning_effort":"high",
|
||||
"most_used_reasoning_effort_percentage":26,"unique_skills_used":147,
|
||||
"total_skills_used":13_190,"total_threads":0,
|
||||
"top_invocations":[{"type":"future_kind"},{"type":"skill","skill_name":"review","usage_count":12},
|
||||
{"type":"plugin","plugin_name":"github","usage_count":34}]
|
||||
}
|
||||
}),
|
||||
full,
|
||||
),
|
||||
] {
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/api/codex/profiles/me"))
|
||||
.respond_with(ResponseTemplate::new(/*s*/ 200).set_body_json(body))
|
||||
.expect(/*r*/ 1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
assert_eq!(client.get_account_profile().await.unwrap(), expected);
|
||||
server.verify().await;
|
||||
server.reset().await;
|
||||
}
|
||||
Mock::given(method("GET"))
|
||||
.respond_with(ResponseTemplate::new(/*s*/ 200).set_body_string("private invalid payload"))
|
||||
.mount(&server)
|
||||
.await;
|
||||
let error = client.get_account_profile().await.unwrap_err().to_string();
|
||||
assert_eq!(error, "Invalid account profile response.");
|
||||
}
|
||||
@@ -13,6 +13,12 @@ pub use client::ThreadUsage;
|
||||
pub use client::ThreadUsageBreakdownGroup;
|
||||
pub use client::analytics::AnalyticsReport;
|
||||
pub use client::analytics::AnalyticsResponse;
|
||||
pub use client::profile::AccountProfile;
|
||||
pub use client::profile::ProfileIdentity;
|
||||
pub use client::profile::ProfileInvocation;
|
||||
pub use client::profile::ProfileInvocationKind;
|
||||
pub use client::profile::ProfileMetadata;
|
||||
pub use client::profile::ProfileStats;
|
||||
pub use client::turn_usage::ApiKeyResponseCost;
|
||||
pub use client::turn_usage::ApiKeyTurnCost;
|
||||
pub use client::turn_usage::ApiKeyTurnCostStatus;
|
||||
|
||||
Reference in new issue
Block a user