diff --git a/sidecars/panel/app.js b/sidecars/panel/app.js
index 23732b0..780e7dd 100644
--- a/sidecars/panel/app.js
+++ b/sidecars/panel/app.js
@@ -39,6 +39,25 @@ function sampleSummary(summary) {
return `${summary?.sampleCount || 0}/${(summary?.sampleCount || 0) + (summary?.excludedCount || 0)} 步`;
}
+// Display a measured request rate when the answer phase cannot be separated.
+// This presentation choice never changes the backend's homogeneous means.
+function stepSpeedDisplay(step = {}, mode = 'stream') {
+ const reason = speedReasonText(step.selectedSpeedReason || step.speedReason);
+ const valid = step.measurementVersion === 1 && step.isComplete === true;
+ if (valid && mode !== 'total' && !step.isCompactionStep && Number.isFinite(step.streamTokPerSec)) {
+ return { value: step.streamTokPerSec, estimated: true, label: '正文估算',
+ detail: step.responseShortSample ? '正文估算 · 短样本' : '正文估算',
+ explanation: reason || '正文阶段估算' };
+ }
+ if (valid && Number.isFinite(step.totalTokPerSec) && step.totalDurationSec > 0) {
+ return { value: step.totalTokPerSec, estimated: false, label: '整体吞吐',
+ detail: step.isCompactionStep ? '整体吞吐 · 压缩' : '整体吞吐',
+ explanation: `${mode !== 'total' && reason ? `${reason};` : ''}总输出 Token(含思考)÷ 请求总耗时${mode !== 'total' ? ';不计正文均速' : ''}${step.isCompactionStep ? ';压缩不计均速' : ''}` };
+ }
+ return { value: null, estimated: false, label: '待计时', detail: reason || '计时不可用',
+ explanation: reason || '计时不可用' };
+}
+
function formatTokens(num) {
const n = Number(num || 0);
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
@@ -179,6 +198,7 @@ function renderTables(activeConv, modelBreakdown, speedMode = 'stream') {
: '';
const compTag = st.isCompactionStep ? ' [压缩汇总步]' : '';
const reason = speedReasonText(st.selectedSpeedReason);
+ const displaySpeed = stepSpeedDisplay(st, speedMode);
const timingSource = st.responseTimingSource === 'post_thinking_estimate' ? '总时长减记录的思考阶段(估算)' : st.responseTimingSource === 'native_text_stream' ? '无思考正文的原始流时长(估算)' : '不可用';
const stepCostVal = Number(st.costUsd || 0);
const stepCostDisplay = stepCostVal >= 1 ? `$${stepCostVal.toFixed(2)}` : `$${stepCostVal.toFixed(3)}`;
@@ -192,7 +212,7 @@ function renderTables(activeConv, modelBreakdown, speedMode = 'stream') {
tr.innerHTML = `
#${Number(st.stepIndex)}${compTag ? '⚡' : ''} |
${escapeHtml(st.modelShort)} |
- ${formatMetric(st.tokPerSec, ' tok/s', estimated)} ${escapeHtml(reason)} |
+ ${formatMetric(displaySpeed.value, ' tok/s', displaySpeed.estimated)} ${escapeHtml(displaySpeed.detail)} |
${formatMetric(st.ttftSec, 's')} |
${formatTokens(st.contextTokens)} / +${Number(st.outputTokens)} |
${Number(st.cacheHitPct)}% |
@@ -321,15 +341,18 @@ function applyTelemetryToDom(data) {
// 2. Status strip metrics
const estimatedSpeed = settings.speedMode !== 'total';
- $('tok-per-sec').textContent = formatMetric(active.latestTokPerSec, ' tok/s', estimatedSpeed);
- $('speed-mode-toggle').title = `最新一步:${speedReasonText(active.latestSpeedReason) || (estimatedSpeed ? '正文阶段估算' : '请求整体吞吐')};点击切换口径`;
+ const latestSpeed = stepSpeedDisplay(active.recentSteps?.[0], settings.speedMode);
+ $('tok-per-sec').textContent = formatMetric(latestSpeed.value, ' tok/s', latestSpeed.estimated);
+ $('latest-speed-basis').textContent = latestSpeed.label;
+ $('speed-mode-toggle').title = `最新一步:${latestSpeed.explanation};点击切换均速口径`;
$('ttft-value').textContent = formatMetric(active.latestTtftSec, 's');
$('ttft-value').title = `原始首 Token 延迟,可能先返回思考内容;会话平均 ${formatMetric(active.ttftSummary?.avgSec, 's')}(${active.ttftSummary?.sampleCount || 0} 步)`;
$('avg-speed-value').textContent = formatMetric(active.avgTokPerSec, '', estimatedSpeed);
+ $('avg-speed-label').textContent = estimatedSpeed ? '正文均速' : '整体均速';
$('speed-sample-count').textContent = `有效 ${sampleSummary(active.speedSummary)}`;
$('speed-sample-count').title = Object.entries(active.speedSummary?.excludedReasons || {}).map(([reason, count]) => `${speedReasonText(reason)}:${count} 步`).join(';') || '全部有效;自动压缩单独排除';
$('speed-method-note').textContent = estimatedSpeed
- ? '正文阶段估算;工具混合输出和起点不明的步骤不计均速,短样本单列。'
+ ? '正文均速只计有效正文样本;其余已完成且计时有效的步骤显示整体 TPS,口径逐步标注。'
: '含思考的输出 Token ÷ 请求总耗时;不含调用之间的空闲和外部工具执行时间。';
const latestStepCost = Number(active.latestStepCostUsd ?? active.recentSteps?.[0]?.costUsd ?? 0);
if ($('step-cost-value')) {
@@ -343,7 +366,7 @@ function applyTelemetryToDom(data) {
$('active-model-short').title = active.activeModelLabel || '';
$('today-tokens').textContent = formatTokens(quotas.today?.tokens || 0);
$('today-cost').textContent = `$${Number(quotas.today?.costUsd || 0).toFixed(2)}`;
- $('speed-mode-badge').textContent = settings.speedMode === 'total' ? '整体吞吐' : '正文估算';
+ $('speed-mode-badge').textContent = settings.speedMode === 'total' ? '均速:整体吞吐' : '均速:正文估算';
// 3. Context Window Popover Section
const limitTokens = ctx.limitTokens || 256000;
diff --git a/sidecars/panel/index.html b/sidecars/panel/index.html
index b50b6e4..cf8ad93 100644
--- a/sidecars/panel/index.html
+++ b/sidecars/panel/index.html
@@ -29,9 +29,10 @@
—
+ 待计时
首Token —
- 均速 — 有效 0/0 步
+ 正文均速 — 有效 0/0 步
|
本步 $0.000 · 累计 $0.00
缓存 0%
@@ -50,9 +51,9 @@
今日 0 · ≈$0.00
- 正文估算
+ 均速:正文估算
- 正文阶段估算;计时不明的步骤不计均速。
+ 正文均速只计有效正文样本;其余已完成且计时有效的步骤显示整体 TPS,口径逐步标注。
@@ -247,7 +248,7 @@
diff --git a/sidecars/panel/test/speed-display.test.mjs b/sidecars/panel/test/speed-display.test.mjs
new file mode 100644
index 0000000..cc10e1e
--- /dev/null
+++ b/sidecars/panel/test/speed-display.test.mjs
@@ -0,0 +1,55 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import {readFileSync} from 'node:fs';
+import vm from 'node:vm';
+import {summarizeSpeed} from '../speed-metrics.mjs';
+
+const context = vm.createContext({window: {}});
+const source = readFileSync(new URL('../app.js', import.meta.url), 'utf8');
+assert.match(source, /\ninit\(\);\s*$/);
+vm.runInContext(source.replace(/\ninit\(\);\s*$/, '\n'), context);
+const show = (step, mode = 'stream') => context.stepSpeedDisplay(step, mode);
+const tool = {measurementVersion: 1, isComplete: true, hasToolCalls: true,
+ outputTokens: 300, totalDurationSec: 10, totalTokPerSec: 30,
+ streamTokPerSec: null, responseSampleEligible: false,
+ speedReason: 'tool_timing_unavailable'};
+const answer = {measurementVersion: 1, isComplete: true, outputTokens: 600,
+ totalDurationSec: 10, totalTokPerSec: 60, streamTokPerSec: 100,
+ streamTokens: 500, streamDurationSec: 5, responseSampleEligible: true,
+ responseTimingSource: 'post_thinking_estimate'};
+
+test('completed tools have a labelled total TPS without contaminating the response mean', () => {
+ const display = show(tool);
+ assert.equal(display.value, 30);
+ assert.equal(display.label, '整体吞吐');
+ assert.equal(display.estimated, false);
+ assert.match(display.explanation, /不计正文均速/);
+ assert.equal(summarizeSpeed([tool, answer], 'stream').avgTokPerSec, 100);
+ assert.equal(summarizeSpeed([tool, answer], 'total').avgTokPerSec, 45);
+ assert.equal(tool.streamTokPerSec, null);
+});
+test('answer and total modes keep their distinct labels and formulas', () => {
+ assert.equal(show(answer).value, 100);
+ assert.equal(show(answer).label, '正文估算');
+ assert.equal(show(answer).estimated, true);
+ assert.equal(show(answer, 'total').value, 60);
+ assert.equal(show(answer, 'total').label, '整体吞吐');
+ assert.equal(show({...answer, responseShortSample: true}).detail, '正文估算 · 短样本');
+});
+test('missing answer start can display measured total TPS, including zero output', () => {
+ assert.equal(show({...tool, hasToolCalls: false, speedReason: 'answer_start_unavailable'}).value, 30);
+ assert.equal(show({...tool, outputTokens: 0, totalTokPerSec: 0}).value, 0);
+});
+test('incomplete and legacy rows never acquire a fabricated total TPS', () => {
+ assert.equal(show({...tool, isComplete: false}).value, null);
+ assert.equal(show({...tool, measurementVersion: null}).value, null);
+ assert.equal(show({...tool, totalTokPerSec: null}).value, null);
+ assert.equal(show({...tool, totalDurationSec: 0}).value, null);
+ assert.equal(show().value, null);
+});
+test('compaction can show its measured rate while remaining excluded from means', () => {
+ const step = {...tool, isCompactionStep: true, speedReason: 'compaction'};
+ assert.equal(show(step).value, 30);
+ assert.match(show(step).detail, /压缩/);
+ assert.equal(summarizeSpeed([step], 'total').sampleCount, 0);
+});