fix(panel): add semantic speed/cache color tiers and clean up overview metric subtexts

This commit is contained in:
fish
2026-11-15 18:53:43 +09:00
parent 2db06050be
commit 6517ee434e
14 changed files with 531 additions and 149 deletions
+80 -43
View File
@@ -6,9 +6,14 @@
*/
import {
formatCachePct,
formatMetric,
formatTokens,
formatUsd,
getCacheToneClass,
getSpeedToneClass,
getStepCostToneClass,
getTtftToneClass,
resolveModelDisplayInfo,
sampleSummary,
speedReasonText,
@@ -63,6 +68,7 @@ export function resolveQuotaCapsuleSummary(quotas) {
if (!quotas) return null;
const activePool = quotas.activePool;
const weekly = quotas.weekly;
const pools = Array.isArray(quotas.pools) ? quotas.pools : [];
const candidates = [];
const defaultPoolName = isEnglishLocale() ? 'Active Pool' : '当前池';
const wkTag = isEnglishLocale() ? 'Wk' : '周';
@@ -88,13 +94,32 @@ export function resolveQuotaCapsuleSummary(quotas) {
windowTag: wkTag,
});
}
if (!candidates.length && pools.length > 0) {
for (const p of pools) {
const pLabel = p?.poolLabel || p?.family || defaultPoolName;
if (p && Number.isFinite(Number(p.remainingPct))) {
candidates.push({ pct: Number(p.remainingPct), label: pLabel, windowTag: '5h' });
}
if (p && Number.isFinite(Number(p.weeklyRemainingPct))) {
candidates.push({ pct: Number(p.weeklyRemainingPct), label: pLabel, windowTag: wkTag });
}
}
}
if (!candidates.length) return null;
candidates.sort((a, b) => a.pct - b.pct);
const tightest = candidates[0];
const runnerUp = candidates.length > 1 ? candidates[1] : null;
const rounded = Math.max(0, Math.min(100, Math.round(tightest.pct)));
const runnerPct = runnerUp ? Math.max(0, Math.min(100, Math.round(runnerUp.pct))) : null;
const subLabelText = runnerUp
? runnerUp.label === tightest.label
? `${tightest.label} ${tightest.windowTag} · ${runnerUp.windowTag} ${runnerPct}%`
: `${tightest.label} ${tightest.windowTag} · ${runnerUp.label} ${runnerUp.windowTag} ${runnerPct}%`
: `${tightest.label} · ${tightest.windowTag}`;
return {
roundedPct: rounded,
shortText: t('capsule.quotaLeft', { pct: rounded }),
subLabelText,
detailText: candidates
.map((c) => {
const cPct = Math.max(0, Math.min(100, Math.round(c.pct)));
@@ -353,6 +378,10 @@ export function resolveCapsuleMetricPresentation(metricKey, slotCtx, ringCircumf
if (metricKey === 'cache_hit') {
const cachePct = slotCtx.hasTelemetry ? slotCtx.cacheHitPct : null;
const valid = cachePct != null && Number.isFinite(Number(cachePct));
const numVal = valid ? Number(cachePct) : 0;
const hasPrompt = slotCtx.latestPromptTokens == null || Number(slotCtx.latestPromptTokens) > 0;
const isDanger = valid && hasPrompt && numVal < 30;
const isWarn = valid && hasPrompt && !isDanger && numVal < 65;
return {
hidden: false,
metric: 'cache_hit',
@@ -360,10 +389,10 @@ export function resolveCapsuleMetricPresentation(metricKey, slotCtx, ringCircumf
textClass: 'wm-slot-text wm-cache-text',
showRing: false,
dashOffset: ringCircumference,
text: valid ? `${Math.round(Number(cachePct))}%` : '--%',
text: valid ? `${Math.round(numVal)}%` : '--%',
running: false,
warn: false,
danger: false,
warn: isWarn,
danger: isDanger,
};
}
@@ -438,6 +467,8 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
const badgeStr = translateRawAgentBadge(active.activeAgentBadge);
const modelAndAgent =
hasSubagents && badgeStr ? `[${badgeStr}] ${activeModelDisplay}` : activeModelDisplay;
const hasSpeed = Number.isFinite(active.latestTokPerSec) && Number(active.latestTokPerSec) > 0;
const speedTone = hasAnySteps && hasSpeed ? getSpeedToneClass(active.latestTokPerSec) : '';
return {
key: 'tps',
label: t('ovMetric.tps'),
@@ -445,13 +476,18 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
iconSize: 10,
isPulsing: Boolean(active.isRunning),
valueText: formatMetric(active.latestTokPerSec, ' tok/s'),
valueClass: 'cell-value accent-speed',
subText: reason ? `${modelAndAgent} · ${reason}` : modelAndAgent,
valueClass: speedTone ? `cell-value ${speedTone}` : 'cell-value',
subText: reason
? !hasSpeed
? `${reason} · ${modelAndAgent}`
: `${modelAndAgent} · ${reason}`
: modelAndAgent,
subClass: 'cell-sub',
};
}
if (metricKey === 'ttft') {
const ttftTone = hasAnySteps ? getTtftToneClass(active.latestTtftSec) : '';
return {
key: 'ttft',
label: t('ovMetric.ttft'),
@@ -459,7 +495,7 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
iconSize: 11,
isPulsing: false,
valueText: formatMetric(active.latestTtftSec, 's'),
valueClass: 'cell-value',
valueClass: ttftTone ? `cell-value ${ttftTone}` : 'cell-value',
subText: t('ovMetric.subAvgTtft', {
val: formatMetric(active.ttftSummary?.avgSec, 's'),
}),
@@ -483,64 +519,65 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
};
}
if (metricKey === 'step_cost') {
if (metricKey === 'step_cost' || metricKey === 'session_cost') {
const stepCost = active.latestStepCostUsd;
return {
key: 'step_cost',
label: t('ovMetric.step_cost'),
icon: 'bolt',
iconSize: 11,
isPulsing: false,
valueText: !hasAnySteps && stepCost == null ? '—' : formatUsd(stepCost, { precise: true }),
valueClass: 'cell-value',
subText: t('ovMetric.subCacheAndTotal', {
cache: active.latestCacheHitPct ?? 0,
cost: formatUsd(active.sessionCostUsd || 0),
}),
subClass: 'cell-sub accent-ok',
};
}
if (metricKey === 'session_cost') {
const sessCost = Number(active.sessionCostUsd || 0);
const stepCnt = Number(active.stepCount || 0);
const isAllUnpriced =
stepCnt > 0 && Number(active.sessionUnpricedCalls || 0) >= stepCnt && !(sessCost > 0);
const stepCostText =
!hasAnySteps && stepCost == null ? '—' : formatUsd(stepCost, { precise: true });
const totalCostText =
!hasAnySteps && active.sessionCostUsd == null
? '—'
: formatUsd(isAllUnpriced ? null : sessCost, {
precise: sessCost > 0 && sessCost < 0.1,
});
if (metricKey === 'step_cost') {
const costTone = hasAnySteps ? getStepCostToneClass(stepCost) : '';
return {
key: 'step_cost',
label: t('ovMetric.step_cost'),
icon: 'bolt',
iconSize: 11,
isPulsing: false,
valueText: stepCostText,
valueClass: costTone ? `cell-value ${costTone}` : 'cell-value',
subText: t('ovMetric.subTotalCost', { cost: totalCostText }),
subClass: 'cell-sub',
};
}
return {
key: 'session_cost',
label: t('ovMetric.session_cost'),
icon: 'bolt',
iconSize: 11,
isPulsing: false,
valueText:
!hasAnySteps && active.sessionCostUsd == null
? '—'
: formatUsd(isAllUnpriced ? null : sessCost, {
precise: sessCost > 0 && sessCost < 0.1,
}),
valueText: totalCostText,
valueClass: 'cell-value',
subText: t('ovMetric.subStepsAndCache', {
steps: stepCnt,
cache: Math.round(Number(active.sessionCacheHitPct ?? active.latestCacheHitPct ?? 0)),
}),
subClass: 'cell-sub accent-ok',
subText: t('ovMetric.subStepCost', { cost: stepCostText }),
subClass: 'cell-sub',
};
}
if (metricKey === 'cache_hit') {
const avgCache = Number(active.sessionCacheHitPct ?? active.latestCacheHitPct ?? 0);
const latestCache = Number(active.latestCacheHitPct ?? 0);
const latestCache = active.latestCacheHitPct;
const avgCache = active.sessionCacheHitPct ?? active.latestCacheHitPct;
const hasLatest = hasAnySteps && latestCache != null && Number.isFinite(Number(latestCache));
const hasAvg = hasAnySteps && avgCache != null && Number.isFinite(Number(avgCache));
const cacheTone = hasLatest ? getCacheToneClass(latestCache, active.latestPromptTokens) : '';
return {
key: 'cache_hit',
label: t('ovMetric.cache_hit'),
icon: 'layers',
iconSize: 11,
isPulsing: false,
valueText: !hasAnySteps ? '—' : `${Math.round(avgCache)}%`,
valueClass: 'cell-value accent-ok',
subText: t('ovMetric.subPromptHit', {
latest: Math.round(latestCache),
avg: Math.round(avgCache),
valueText: hasLatest ? formatCachePct(latestCache) : '—',
valueClass: cacheTone ? `cell-value ${cacheTone}` : 'cell-value',
subText: t('ovMetric.subAvgCache', {
val: hasAvg ? formatCachePct(avgCache) : '—',
}),
subClass: 'cell-sub',
};
@@ -610,7 +647,7 @@ export function resolveOverviewMetricCell(metricKey, cellCtx = {}) {
valueText: quotaSum ? quotaSum.shortText : '—',
valueClass: quotaToneCls,
subText: quotaSum
? t('ovMetric.subQuotaPool', { label: quotaSum.detailText })
? t('ovMetric.subQuotaPool', { label: quotaSum.subLabelText })
: t('ovMetric.subQuotaPending'),
subClass: 'cell-sub',
};
@@ -5,11 +5,16 @@
* speed reason sub-lines, token combo tooltips, and high-cost highlights.
*/
import { h, patchAttr, patchClasses, patchText } from '../core/domPatch.js';
import { h, patchAttr, patchText } from '../core/domPatch.js';
import {
formatCachePct,
formatMetric,
formatTokens,
formatUsd,
getCacheToneClass,
getSpeedToneClass,
getStepCostToneClass,
getTtftToneClass,
resolveModelDisplayInfo,
speedReasonText,
} from '../core/formatters.js';
@@ -115,7 +120,7 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
sigPart: (st) => `${st.tokPerSec}:${st.selectedSpeedReason || ''}`,
createCell: () => {
const speedMain = h('strong', {
className: 'cell-value accent-speed',
className: 'cell-value tone-muted',
style: 'font-size: var(--fs-base-sm);',
});
const speedReason = h('div', {
@@ -132,6 +137,7 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
},
updateCell: (refs, st) => {
patchText(refs.speedMain, formatMetric(st.tokPerSec, ' tok/s'));
patchAttr(refs.speedMain, 'class', `cell-value ${getSpeedToneClass(st.tokPerSec)}`);
const reason = speedReasonText(st.selectedSpeedReason);
patchText(refs.speedReason, reason);
patchAttr(refs.speedReason, 'hidden', !reason);
@@ -150,6 +156,8 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
},
updateCell: (refs, st) => {
patchText(refs.valEl, formatMetric(st.ttftSec, 's'));
const tone = getTtftToneClass(st.ttftSec);
patchAttr(refs.valEl, 'class', tone || null);
},
},
@@ -252,21 +260,24 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
key: 'cache',
thLabel: () => t('stepCol.cache.th'),
optLabel: () => t('stepCol.cache.opt'),
sigPart: (st) => `${st.cacheHitPct ?? 0}`,
sigPart: (st) =>
`${st.cacheHitPct ?? 0}:${(st.inputTokens || 0) + (st.cacheReadTokens || 0) > 0 ? 1 : 0}`,
createCell: () => {
const valEl = h('span');
const td = h(
'td',
{
className: 'cell-value accent-ok',
style: 'font-size: var(--fs-base-sm);',
},
[valEl]
);
const valEl = h('span', {
className: 'cell-value tone-muted',
style: 'font-size: var(--fs-base-sm);',
});
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
patchText(refs.valEl, `${Number(st.cacheHitPct ?? 0)}%`);
const promptTokens = Number(st.inputTokens || 0) + Number(st.cacheReadTokens || 0);
patchText(refs.valEl, formatCachePct(st.cacheHitPct ?? 0));
patchAttr(
refs.valEl,
'class',
`cell-value ${getCacheToneClass(st.cacheHitPct ?? 0, promptTokens)}`
);
},
},
@@ -276,14 +287,15 @@ export const STEP_COLUMN_REGISTRY = Object.freeze({
optLabel: () => t('stepCol.cost.opt'),
sigPart: (st) => `${st.costUsd}`,
createCell: () => {
const valEl = h('span');
const td = h('td', { style: 'font-weight: 600;' }, [valEl]);
const valEl = h('span', { style: 'font-weight: 600;' });
const td = h('td', {}, [valEl]);
return { td, refs: { td, valEl } };
},
updateCell: (refs, st) => {
const costVal = st.costUsd;
patchText(refs.valEl, formatUsd(costVal, { precise: true }));
patchClasses(refs.td, { 'accent-speed': costVal >= 0.15 });
const tone = getStepCostToneClass(costVal);
patchAttr(refs.valEl, 'class', tone || null);
},
},
});