//! Private analytics display types, independent of the app-server wire protocol. use codex_protocol::account::PlanType; /// Billing families match the App's consumer, business, and workspace scopes. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(super) enum AccountKind { Consumer, Business, Enterprise, Unknown, } impl From> for AccountKind { fn from(plan: Option) -> Self { match plan { None | Some(PlanType::Unknown) => Self::Unknown, Some(PlanType::Sci | PlanType::SciPlus) => Self::Business, Some(plan) if plan.is_team_like() => Self::Business, Some(plan) if plan.is_workspace_account() => Self::Enterprise, Some(_) => Self::Consumer, } } } /// Match the existing CLI thread-usage capability without widening other workspace reports. pub(super) fn thread_usage_supported(plan: Option) -> bool { matches!( plan, Some( PlanType::Business | PlanType::EnterpriseCbpUsageBased | PlanType::EnterpriseCbpAutomation ) ) } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum AccountAnalyticsReport { Usage, Credits, Messages, Plugins, Skills, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum AccountAnalyticsGrouping { Feature, Model, Surface, TaskStart, Speed, Reasoning, TokenType, } impl AccountAnalyticsGrouping { /// Credit breakdowns supported by the account's billing report. pub(crate) fn credit_groupings(plan: Option) -> &'static [Self] { match AccountKind::from(plan) { AccountKind::Business => &[Self::Surface, Self::Model, Self::Speed], AccountKind::Enterprise => &[Self::Surface, Self::Model, Self::Speed, Self::Reasoning], AccountKind::Consumer => &[Self::Surface], AccountKind::Unknown => &[], } } } #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum AccountAnalyticsUnit { RelativeUsage, Credits, Count, Tokens, } #[derive(Debug, Clone, PartialEq)] pub(crate) struct AccountAnalyticsHistory { pub(crate) unit: AccountAnalyticsUnit, /// Source freshness in Unix seconds, when provided. Not a completeness watermark. pub(crate) updated_at: Option, pub(crate) data: Vec, } #[derive(Debug, Clone, PartialEq)] pub(crate) struct AccountAnalyticsDay { /// Source reporting date; display formatting belongs to the UI. pub(crate) date: chrono::NaiveDate, /// Full daily denominator, including non-task usage when grouped by task start. pub(crate) total: f64, pub(crate) values: Vec, } #[derive(Debug, Clone, PartialEq)] pub(crate) struct AccountAnalyticsValue { pub(crate) key: String, pub(crate) label: String, pub(crate) value: f64, }