fix(panel): reconcile context window breakdown with API tokens and decouple agent badge from step column

This commit is contained in:
fish
2026-11-15 18:19:36 +09:00
parent 228031e335
commit 2db06050be
10 changed files with 784 additions and 243 deletions
@@ -13,12 +13,7 @@ import {
resolveModelDisplayInfo,
speedReasonText,
} from '../core/formatters.js';
import { isEnglishLocale, t } from '../i18n/index.js';
import {
formatAgentBadgeText,
formatAgentLabel,
getAgentBadgeClass,
} from '../store/telemetryStore.js';
import { t } from '../i18n/index.js';
export const STEP_COLUMN_KEYS = Object.freeze([
'step',
@@ -62,65 +57,14 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
key: 'step',
thLabel: () => t('stepCol.step.th'),
optLabel: () => t('stepCol.step.opt'),
sigPart: (st, ctx) =>
`${Boolean(ctx.showAgentBadge)}:${ctx.scopeSigKey}:${st.agentId || 'main'}:${st.stepIndex}:${st.agentBadge || ''}:${st.agentLabel || ''}`,
sigPart: (st) => `${st.stepIndex}`,
createCell: () => {
const agentBadgeEl = h('span', {
className: 'agent-badge is-clickable',
hidden: true,
style: 'margin-right: 4px;',
});
const stepNumText = h('span');
const td = h('td', {}, [agentBadgeEl, stepNumText]);
return { td, refs: { agentBadgeEl, stepNumText } };
const valEl = h('span');
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st, ctx) => {
const { showAgentBadge, effectiveScopes, onSelectAgentScopes } = ctx;
patchAttr(refs.agentBadgeEl, 'hidden', !showAgentBadge);
if (showAgentBadge) {
const badgeCls = getAgentBadgeClass(st.agentIndex || 0, !st.isSubagent);
patchAttr(refs.agentBadgeEl, 'class', `agent-badge is-clickable ${badgeCls}`);
const badgeText = isEnglishLocale()
? formatAgentBadgeText({
isMain: !st.isSubagent,
index: st.agentIndex || 0,
badgeText: st.agentBadge,
})
: st.agentBadge || (st.isSubagent ? '子' : '主');
patchText(refs.agentBadgeEl, badgeText);
const targetScope = st.agentId || 'main';
const isSoleTarget =
effectiveScopes.length === 1 && effectiveScopes[0] === targetScope;
const agentName = isEnglishLocale()
? formatAgentLabel({
isMain: !st.isSubagent,
index: st.agentIndex || 0,
role: st.agentRole || '',
})
: st.agentLabel || t('steps.unitAgent');
patchAttr(
refs.agentBadgeEl,
'title',
isSoleTarget
? t('steps.badgeBackAll')
: t('steps.badgeFilterAgent', { agent: agentName })
);
refs.agentBadgeEl.onclick = (e) => {
if (typeof onSelectAgentScopes !== 'function') return;
if (e && (e.ctrlKey || e.metaKey || e.shiftKey) && effectiveScopes[0] !== 'all') {
const next = effectiveScopes.includes(targetScope)
? effectiveScopes.filter((id) => id !== targetScope)
: [...effectiveScopes, targetScope];
onSelectAgentScopes(next.length > 0 ? next : ['all']);
} else {
onSelectAgentScopes(isSoleTarget ? ['all'] : [targetScope]);
}
};
} else {
refs.agentBadgeEl.onclick = null;
}
patchText(refs.stepNumText, `#${Number(st.stepIndex)}`);
updateCell: (refs, st) => {
patchText(refs.valEl, `#${Number(st.stepIndex)}`);
},
},
@@ -130,12 +74,13 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.time.opt'),
sigPart: (st) => `${st.createdAtMs || 0}`,
createCell: () => {
const td = h('td', { className: 'text-muted' });
return { td, refs: { td } };
const valEl = h('span');
const td = h('td', { className: 'text-muted' }, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
const { text, title } = formatStepClockTime(st.createdAtMs);
patchText(refs.td, text);
patchText(refs.valEl, text);
patchAttr(refs.td, 'title', title || null);
},
},
@@ -149,14 +94,16 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
return `${disp.text}:${disp.title}`;
},
createCell: () => {
const td = h('td', {
style: 'max-width: 120px; overflow: hidden; text-overflow: ellipsis;',
const valEl = h('span', {
style:
'display: inline-block; max-width: 120px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom;',
});
return { td, refs: { td } };
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st, ctx) => {
const modelDisplay = resolveModelDisplayInfo(st, ctx.displaySettings, { fallback: '—' });
patchText(refs.td, modelDisplay.text);
patchText(refs.valEl, modelDisplay.text);
patchAttr(refs.td, 'title', modelDisplay.title);
},
},
@@ -175,8 +122,13 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
className: 'text-muted',
style: 'font-size: var(--fs-2xs);',
});
const td = h('td', {}, [speedMain, speedReason]);
return { td, refs: { speedMain, speedReason } };
const wrapEl = h(
'span',
{ style: 'display: inline-block; vertical-align: middle;' },
[speedMain, speedReason]
);
const td = h('td', {}, [wrapEl]);
return { td, refs: { td, speedMain, speedReason } };
},
updateCell: (refs, st) => {
patchText(refs.speedMain, formatMetric(st.tokPerSec, ' tok/s'));
@@ -192,11 +144,12 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.ttft.opt'),
sigPart: (st) => `${st.ttftSec}`,
createCell: () => {
const td = h('td');
return { td, refs: { td } };
const valEl = h('span');
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
patchText(refs.td, formatMetric(st.ttftSec, 's'));
patchText(refs.valEl, formatMetric(st.ttftSec, 's'));
},
},
@@ -206,12 +159,13 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.duration.opt'),
sigPart: (st) => `${st.totalDurationSec ?? st.streamDurationSec ?? ''}`,
createCell: () => {
const td = h('td');
return { td, refs: { td } };
const valEl = h('span');
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
const dur = st.totalDurationSec ?? st.streamDurationSec ?? null;
patchText(refs.td, formatMetric(dur, 's'));
patchText(refs.valEl, formatMetric(dur, 's'));
},
},
@@ -222,8 +176,9 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
sigPart: (st) =>
`${st.contextTokens}:${st.outputTokens}:${st.thinkingTokens}:${st.responseTokens}`,
createCell: () => {
const td = h('td');
return { td, refs: { td } };
const valEl = h('span');
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
const outTok = Math.max(0, Number(st.outputTokens || 0));
@@ -233,7 +188,7 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
? Math.max(0, Number(st.responseTokens))
: Math.max(0, outTok - thinkTok);
patchText(
refs.td,
refs.valEl,
`${formatTokens(st.contextTokens)} / ${formatTokens(thinkTok)} / ${formatTokens(respTok)}`
);
patchAttr(
@@ -254,11 +209,12 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.input_tokens.opt'),
sigPart: (st) => `${st.inputTokens || 0}`,
createCell: () => {
const td = h('td');
return { td, refs: { td } };
const valEl = h('span');
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
patchText(refs.td, formatTokens(st.inputTokens || 0));
patchText(refs.valEl, formatTokens(st.inputTokens || 0));
},
},
@@ -268,11 +224,12 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.cache_tokens.opt'),
sigPart: (st) => `${st.cacheReadTokens || 0}`,
createCell: () => {
const td = h('td');
return { td, refs: { td } };
const valEl = h('span');
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
patchText(refs.td, formatTokens(st.cacheReadTokens || 0));
patchText(refs.valEl, formatTokens(st.cacheReadTokens || 0));
},
},
@@ -282,11 +239,12 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.output_tokens.opt'),
sigPart: (st) => `${st.outputTokens || 0}`,
createCell: () => {
const td = h('td');
return { td, refs: { td } };
const valEl = h('span');
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
patchText(refs.td, formatTokens(st.outputTokens || 0));
patchText(refs.valEl, formatTokens(st.outputTokens || 0));
},
},
@@ -296,14 +254,19 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.cache.opt'),
sigPart: (st) => `${st.cacheHitPct ?? 0}`,
createCell: () => {
const td = h('td', {
className: 'cell-value accent-ok',
style: 'font-size: var(--fs-base-sm);',
});
return { td, refs: { td } };
const valEl = h('span');
const td = h(
'td',
{
className: 'cell-value accent-ok',
style: 'font-size: var(--fs-base-sm);',
},
[valEl]
);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
patchText(refs.td, `${Number(st.cacheHitPct ?? 0)}%`);
patchText(refs.valEl, `${Number(st.cacheHitPct ?? 0)}%`);
},
},
@@ -313,12 +276,13 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.cost.opt'),
sigPart: (st) => `${st.costUsd}`,
createCell: () => {
const td = h('td', { style: 'font-weight: 600;' });
return { td, refs: { td } };
const valEl = h('span');
const td = h('td', { style: 'font-weight: 600;' }, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
const costVal = st.costUsd;
patchText(refs.td, formatUsd(costVal, { precise: true }));
patchText(refs.valEl, formatUsd(costVal, { precise: true }));
patchClasses(refs.td, { 'accent-speed': costVal >= 0.15 });
},
},