mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
Expose token usage totals in statusline state (#61408)
## What changed Add `thread.usage.total` to the provider-facing statusline snapshot with total input, cache-read input, cache-write input, other input, and output token counts. Preserve cache-write counts when converting app-server token reports for the TUI. Omit totals when usage is unavailable, the breakdown is invalid, or the report represents a synthetic context fill. Keep measured zero totals. ## Testing Add coverage for the reported token breakdown, cache counts exceeding total input, synthetic context fills, and measured zero usage. GitOrigin-RevId: 6c506af30d6e51a49a780a0316304ef9c067fe43
This commit is contained in:
@@ -12,11 +12,26 @@ const BASELINE_TOKENS: i64 = 12000;
|
||||
pub struct TokenUsage {
|
||||
pub input_tokens: i64,
|
||||
pub cached_input_tokens: i64,
|
||||
#[serde(default)]
|
||||
pub cache_write_input_tokens: i64,
|
||||
pub output_tokens: i64,
|
||||
pub reasoning_output_tokens: i64,
|
||||
pub total_tokens: i64,
|
||||
}
|
||||
|
||||
impl From<codex_app_server_protocol::TokenUsageBreakdown> for TokenUsage {
|
||||
fn from(usage: codex_app_server_protocol::TokenUsageBreakdown) -> Self {
|
||||
Self {
|
||||
input_tokens: usage.input_tokens,
|
||||
cached_input_tokens: usage.cached_input_tokens,
|
||||
cache_write_input_tokens: usage.cache_write_input_tokens,
|
||||
output_tokens: usage.output_tokens,
|
||||
reasoning_output_tokens: usage.reasoning_output_tokens,
|
||||
total_tokens: usage.total_tokens,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TokenUsage {
|
||||
pub fn is_zero(&self) -> bool {
|
||||
self.total_tokens == 0
|
||||
|
||||
Reference in New Issue
Block a user