show token usage on per-agent web ui after each turn

This commit is contained in:
damocles 2026-05-17 02:25:25 +02:00
parent ca86bcf4bd
commit ce740483c6
6 changed files with 91 additions and 1 deletions

View file

@ -412,6 +412,21 @@
el_.hidden = false;
el_.textContent = 'model · ' + model;
}
function renderTokenUsage(u) {
const el_ = $('token-usage');
if (!el_) return;
if (!u) { el_.hidden = true; return; }
const ctx = u.input_tokens + u.cache_read_input_tokens + u.cache_creation_input_tokens;
const fmt = (n) => n >= 1000 ? (n / 1000).toFixed(1) + 'k' : String(n);
el_.hidden = false;
el_.title = [
'input: ' + u.input_tokens,
'output: ' + u.output_tokens,
'cache_read: ' + u.cache_read_input_tokens,
'cache_write: ' + u.cache_creation_input_tokens,
].join(' · ');
el_.textContent = '· ctx ' + fmt(ctx) + ' in · ' + fmt(u.output_tokens) + ' out';
}
function renderLastTurn(ms) {
const el_ = $('last-turn');
if (!el_) return;
@ -485,6 +500,7 @@
setStateAbs(s.turn_state, s.turn_state_since);
}
renderModelChip(s.model);
renderTokenUsage(s.token_usage);
// Skip the re-render if nothing structurally changed. The most
// common case is `online` polling itself — without this guard, the
// operator's <input value> gets clobbered every cycle.