mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add Top chats to usage analytics (#45765)
## What changed - Show local chats active in the past 30 days, ranked by estimated lifetime credits, for supported Business and Enterprise plans. Exclude archived chats and subagents. - Add expandable model, reasoning effort, and speed breakdowns, optional zero-credit groups, and dollar estimates when supplied by the backend. - Load estimates in bounded batches of up to 100 distinct threads, retaining available results when some estimates are unavailable. Hide chat titles without a returned estimate and distinguish missing usage from zero. ## Testing Add coverage for batch validation, partial failures, request limits, pagination and ranking, plan eligibility, title visibility, and responsive table navigation and details. GitOrigin-RevId: 783b960a780f4e0fd39f57e2fa78fb31b3090c44
This commit is contained in:
1 parent
ca53e19c75
commit
0e7ab7c1b5
47 files changed
+2491
-356
No files matched your search
@@ -50,22 +50,29 @@ impl<T: Send + 'static> Load<T> {
|
||||
pub(super) fn start(
|
||||
future: impl std::future::Future<Output = Result<Option<T>, String>> + Send + 'static,
|
||||
frame: FrameRequester,
|
||||
) -> Self {
|
||||
Self::start_with_timeout(future, frame, std::time::Duration::from_secs(/*secs*/ 30))
|
||||
}
|
||||
|
||||
pub(super) fn start_with_timeout(
|
||||
future: impl std::future::Future<Output = Result<Option<T>, String>> + Send + 'static,
|
||||
frame: FrameRequester,
|
||||
timeout: std::time::Duration,
|
||||
) -> Self {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
let task = tokio::spawn(async move {
|
||||
let result = match tokio::time::timeout(
|
||||
std::time::Duration::from_secs(/*secs*/ 30),
|
||||
AssertUnwindSafe(future).catch_unwind(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(Ok(result)) => result,
|
||||
Ok(Err(_)) => Err("Request interrupted. Press R to retry.".into()),
|
||||
Err(_) => Err("Request timed out. Press R to retry.".into()),
|
||||
};
|
||||
let _ = sender.send(result);
|
||||
frame.schedule_frame();
|
||||
});
|
||||
let task =
|
||||
tokio::spawn(async move {
|
||||
let result =
|
||||
match tokio::time::timeout(timeout, AssertUnwindSafe(future).catch_unwind())
|
||||
.await
|
||||
{
|
||||
Ok(Ok(result)) => result,
|
||||
Ok(Err(_)) => Err("Request interrupted. Press R to retry.".into()),
|
||||
Err(_) => Err("Request timed out. Press R to retry.".into()),
|
||||
};
|
||||
let _ = sender.send(result);
|
||||
frame.schedule_frame();
|
||||
});
|
||||
Self::Loading(Pending { receiver, task })
|
||||
}
|
||||
|
||||
@@ -101,6 +108,11 @@ impl<T: Send + 'static> Load<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Keep untyped server and transport diagnostics out of account reports.
|
||||
pub(super) fn error(_error: codex_app_server_client::TypedRequestError) -> String {
|
||||
"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 {
|
||||
@@ -147,6 +159,31 @@ pub(super) fn credit_amount(value: f64) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
|
||||
Reference in new issue
Block a user