Files
codex/codex-rs/tui/src/analytics/models.rs
T
Eric Traut fea1d7f7d1 Add support for Academic Researchers plans (#55387)
## What changed

- Recognize `sci` and `sci_plus` in authentication, account responses, rate limits, and generated client schemas.
- Treat both plans as workspace accounts eligible for cloud configuration, and use business analytics routes.
- Display “Academic Researchers” and “Academic Researchers Plus” in the TUI and direct users to their admin when usage limits are reached.

## Testing

Add coverage for plan parsing, workspace classification, account and rate-limit responses, cloud configuration eligibility, analytics routing, TUI labels, and usage-limit guidance. Exercise installed-app refresh and listing with `sci_plus` authentication.

GitOrigin-RevId: b51c5df03029b8bc249d44f11b353a7755e7dd04
2026-10-19 21:43:19 +00:00

101 lines
2.9 KiB
Rust

//! 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<Option<PlanType>> for AccountKind {
fn from(plan: Option<PlanType>) -> 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<PlanType>) -> 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<PlanType>) -> &'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<i64>,
pub(crate) data: Vec<AccountAnalyticsDay>,
}
#[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<AccountAnalyticsValue>,
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct AccountAnalyticsValue {
pub(crate) key: String,
pub(crate) label: String,
pub(crate) value: f64,
}