mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): upgrade modular dashboard UI, 6-segment context meter, and consumption analytics
This commit is contained in:
@@ -0,0 +1,736 @@
|
||||
/**
|
||||
* @fileoverview View 2: ConsumptionView (全景消耗统计视图).
|
||||
* Implements the 5-part analytics layout:
|
||||
* 1. 用量概览 (Total Tokens k/M/B, USD + CNY approx, Input/Output split, Cache Hit % + Saved Cost badge, 4-color bar)
|
||||
* 2. 历史趋势 (Pure SVG smooth cubic-bezier spline area chart with peak callout and 3 time anchors)
|
||||
* 3. 热门模型 (Per-model share badge, 4-segment bar, and Input/Cache/Output/Thinking breakdown)
|
||||
* 4. 数据来源 (SOURCES breakdown with 4-segment bar)
|
||||
* 5. 按月细分 (12-month stacked vertical bar chart with cost, stacked bars, and k/M/B totals)
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../core/component.js';
|
||||
import {
|
||||
h,
|
||||
patchAttr,
|
||||
patchClasses,
|
||||
patchKeyedList,
|
||||
patchStyleVar,
|
||||
patchText,
|
||||
} from '../core/domPatch.js';
|
||||
import {
|
||||
formatCnyApprox,
|
||||
formatDateSpanBadge,
|
||||
formatTokensPrecise,
|
||||
formatUsd,
|
||||
} from '../core/formatters.js';
|
||||
import { createSvgIcon, SVG_NS } from '../icons/SvgIcon.js';
|
||||
import { fetchTelemetry, telemetryStore } from '../store/telemetryStore.js';
|
||||
import { uiStore } from '../store/uiStore.js';
|
||||
import { CustomDateTimePicker } from '../components/ui/CustomDateTimePicker.js';
|
||||
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
|
||||
import { SegmentedControl } from '../components/ui/SegmentedControl.js';
|
||||
|
||||
const TIME_RANGE_OPTIONS = [
|
||||
{ value: 'today', label: '今天' },
|
||||
{ value: '24h', label: '1天' },
|
||||
{ value: '7d', label: '7天' },
|
||||
{ value: '14d', label: '14天' },
|
||||
{ value: '30d', label: '30天' },
|
||||
{ value: 'all', label: '全部' },
|
||||
{ value: 'custom', label: '自定义' },
|
||||
];
|
||||
|
||||
function createFourSegmentBar() {
|
||||
const segInput = h('div', { className: 'progress-seg seg-input' });
|
||||
const segCached = h('div', { className: 'progress-seg seg-cached' });
|
||||
const segOutput = h('div', { className: 'progress-seg seg-output' });
|
||||
const segThinking = h('div', { className: 'progress-seg seg-thinking' });
|
||||
const el = h('div', { className: 'progress-track cons-seg-bar' }, [
|
||||
segInput,
|
||||
segCached,
|
||||
segOutput,
|
||||
segThinking,
|
||||
]);
|
||||
|
||||
function update({ inputTokens = 0, cacheReadTokens = 0, responseTokens = 0, thinkingTokens = 0 }) {
|
||||
const total = Math.max(1, inputTokens + cacheReadTokens + responseTokens + thinkingTokens);
|
||||
patchStyleVar(segInput, '--seg-w', `${((inputTokens / total) * 100).toFixed(2)}%`);
|
||||
patchStyleVar(segCached, '--seg-w', `${((cacheReadTokens / total) * 100).toFixed(2)}%`);
|
||||
patchStyleVar(segOutput, '--seg-w', `${((responseTokens / total) * 100).toFixed(2)}%`);
|
||||
patchStyleVar(segThinking, '--seg-w', `${((thinkingTokens / total) * 100).toFixed(2)}%`);
|
||||
}
|
||||
|
||||
return { el, update };
|
||||
}
|
||||
|
||||
function buildSmoothSplinePath(points) {
|
||||
if (!points.length) return '';
|
||||
if (points.length === 1) return `M ${points[0].x} ${points[0].y}`;
|
||||
let d = `M ${points[0].x.toFixed(1)} ${points[0].y.toFixed(1)}`;
|
||||
for (let i = 0; i < points.length - 1; i++) {
|
||||
const p0 = points[i];
|
||||
const p1 = points[i + 1];
|
||||
const cpx1 = p0.x + (p1.x - p0.x) * 0.45;
|
||||
const cpx2 = p1.x - (p1.x - p0.x) * 0.45;
|
||||
d += ` C ${cpx1.toFixed(1)} ${p0.y.toFixed(1)}, ${cpx2.toFixed(1)} ${p1.y.toFixed(1)}, ${p1.x.toFixed(1)} ${p1.y.toFixed(1)}`;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
function createTrendAreaChart() {
|
||||
const svg = document.createElementNS(SVG_NS, 'svg');
|
||||
svg.setAttribute('viewBox', '0 0 460 116');
|
||||
svg.setAttribute('class', 'trend-svg');
|
||||
svg.setAttribute('aria-hidden', 'true');
|
||||
|
||||
const defs = document.createElementNS(SVG_NS, 'defs');
|
||||
const grad = document.createElementNS(SVG_NS, 'linearGradient');
|
||||
grad.setAttribute('id', 'trend-area-grad');
|
||||
grad.setAttribute('x1', '0');
|
||||
grad.setAttribute('y1', '0');
|
||||
grad.setAttribute('x2', '0');
|
||||
grad.setAttribute('y2', '1');
|
||||
|
||||
const stop1 = document.createElementNS(SVG_NS, 'stop');
|
||||
stop1.setAttribute('offset', '0%');
|
||||
stop1.setAttribute('stop-color', 'var(--ctx-cached)');
|
||||
stop1.setAttribute('stop-opacity', '0.36');
|
||||
|
||||
const stop2 = document.createElementNS(SVG_NS, 'stop');
|
||||
stop2.setAttribute('offset', '100%');
|
||||
stop2.setAttribute('stop-color', 'var(--ctx-cached)');
|
||||
stop2.setAttribute('stop-opacity', '0.0');
|
||||
|
||||
grad.appendChild(stop1);
|
||||
grad.appendChild(stop2);
|
||||
defs.appendChild(grad);
|
||||
svg.appendChild(defs);
|
||||
|
||||
// Subtle grid lines
|
||||
const gridGroup = document.createElementNS(SVG_NS, 'g');
|
||||
gridGroup.setAttribute('class', 'trend-grid');
|
||||
for (const y of [26, 62, 98]) {
|
||||
const line = document.createElementNS(SVG_NS, 'line');
|
||||
line.setAttribute('x1', '10');
|
||||
line.setAttribute('y1', String(y));
|
||||
line.setAttribute('x2', '450');
|
||||
line.setAttribute('y2', String(y));
|
||||
gridGroup.appendChild(line);
|
||||
}
|
||||
for (const x of [118, 230, 342]) {
|
||||
const line = document.createElementNS(SVG_NS, 'line');
|
||||
line.setAttribute('x1', String(x));
|
||||
line.setAttribute('y1', '16');
|
||||
line.setAttribute('x2', String(x));
|
||||
line.setAttribute('y2', '98');
|
||||
gridGroup.appendChild(line);
|
||||
}
|
||||
svg.appendChild(gridGroup);
|
||||
|
||||
const areaPath = document.createElementNS(SVG_NS, 'path');
|
||||
areaPath.setAttribute('fill', 'url(#trend-area-grad)');
|
||||
svg.appendChild(areaPath);
|
||||
|
||||
const linePath = document.createElementNS(SVG_NS, 'path');
|
||||
linePath.setAttribute('class', 'trend-line');
|
||||
linePath.setAttribute('fill', 'none');
|
||||
svg.appendChild(linePath);
|
||||
|
||||
const peakDot = document.createElementNS(SVG_NS, 'circle');
|
||||
peakDot.setAttribute('r', '3');
|
||||
peakDot.setAttribute('class', 'trend-peak-dot');
|
||||
svg.appendChild(peakDot);
|
||||
|
||||
const peakPill = h('span', { className: 'trend-peak-pill text-mono', text: '0' });
|
||||
const chartWrap = h('div', { className: 'trend-chart-wrap' }, [peakPill, svg]);
|
||||
|
||||
let lastLineD = '';
|
||||
|
||||
function update(series = []) {
|
||||
const slots = series.length >= 2 ? series : [
|
||||
{ label: '00:00', tokens: 0 },
|
||||
{ label: '06:00', tokens: 0 },
|
||||
{ label: '12:00', tokens: 0 },
|
||||
];
|
||||
let maxTokens = 0;
|
||||
let peakIdx = 0;
|
||||
for (let i = 0; i < slots.length; i++) {
|
||||
const t = Number(slots[i].tokens || 0);
|
||||
if (t >= maxTokens) {
|
||||
maxTokens = t;
|
||||
peakIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
const leftX = 12;
|
||||
const rightX = 448;
|
||||
const topY = 26;
|
||||
const bottomY = 98;
|
||||
const spanX = rightX - leftX;
|
||||
const spanY = bottomY - topY;
|
||||
const denom = Math.max(1, maxTokens);
|
||||
|
||||
const pts = slots.map((s, idx) => {
|
||||
const x = leftX + (idx / Math.max(1, slots.length - 1)) * spanX;
|
||||
const ratio = maxTokens > 0 ? Number(s.tokens || 0) / denom : 0;
|
||||
const y = bottomY - ratio * spanY;
|
||||
return { x, y };
|
||||
});
|
||||
|
||||
const lineD = buildSmoothSplinePath(pts);
|
||||
if (lineD !== lastLineD) {
|
||||
lastLineD = lineD;
|
||||
const areaD = `${lineD} L ${pts[pts.length - 1].x.toFixed(1)} ${bottomY} L ${pts[0].x.toFixed(1)} ${bottomY} Z`;
|
||||
patchAttr(linePath, 'd', lineD);
|
||||
patchAttr(areaPath, 'd', areaD);
|
||||
}
|
||||
|
||||
const peakPt = pts[peakIdx] || { x: 230, y: bottomY };
|
||||
patchAttr(peakDot, 'cx', peakPt.x.toFixed(1));
|
||||
patchAttr(peakDot, 'cy', peakPt.y.toFixed(1));
|
||||
|
||||
patchText(peakPill, formatTokensPrecise(maxTokens));
|
||||
const pctLeft = Math.max(8, Math.min(92, (peakPt.x / 460) * 100));
|
||||
patchStyleVar(peakPill, '--peak-x', `${pctLeft.toFixed(1)}%`);
|
||||
}
|
||||
|
||||
return { el: chartWrap, update };
|
||||
}
|
||||
|
||||
export const ConsumptionView = defineComponent({
|
||||
name: 'ConsumptionView',
|
||||
setup({ onCleanup }) {
|
||||
// Default to 'today' if store is on initial 'all' or keep user's selection
|
||||
const timeFilterSwitch = SegmentedControl({
|
||||
ariaLabel: '消耗统计时间范围',
|
||||
modelValue: telemetryStore.getState().selectedTimeRange,
|
||||
options: TIME_RANGE_OPTIONS,
|
||||
onUpdateModelValue: (nextRange) => {
|
||||
telemetryStore.setState({ selectedTimeRange: nextRange });
|
||||
fetchTelemetry({ force: false });
|
||||
},
|
||||
});
|
||||
|
||||
const startPicker = CustomDateTimePicker({
|
||||
modelValue: telemetryStore.getState().customStartMs,
|
||||
onUpdateModelValue: (ms) => {
|
||||
telemetryStore.setState({ customStartMs: ms });
|
||||
},
|
||||
});
|
||||
|
||||
const endPicker = CustomDateTimePicker({
|
||||
modelValue: telemetryStore.getState().customEndMs,
|
||||
onUpdateModelValue: (ms) => {
|
||||
telemetryStore.setState({ customEndMs: ms });
|
||||
},
|
||||
});
|
||||
|
||||
const applyCustomBtn = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'btn-primary',
|
||||
style: 'height: 26px; padding: 0 10px;',
|
||||
onClick: () => {
|
||||
telemetryStore.setState({ selectedTimeRange: 'custom' });
|
||||
fetchTelemetry({ force: true });
|
||||
},
|
||||
},
|
||||
[createSvgIcon('check', { size: 12 }), h('span', { text: '筛选' })]
|
||||
);
|
||||
|
||||
const customRangeBar = h(
|
||||
'div',
|
||||
{
|
||||
style:
|
||||
'display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 6px 8px; background: var(--surface-subtle); border: 1px solid var(--border-hairline); border-radius: var(--radius-xs);',
|
||||
hidden: true,
|
||||
},
|
||||
[
|
||||
startPicker.el,
|
||||
h('span', { className: 'text-muted', text: '至' }),
|
||||
endPicker.el,
|
||||
applyCustomBtn,
|
||||
]
|
||||
);
|
||||
|
||||
// --- Section 1: 用量概览 (Compact Integrated Overview) ---
|
||||
const dateSpanBadge = h('span', { className: 'cons-badge text-mono', text: '-- ~ --' });
|
||||
const heroTotalTokens = h('strong', { className: 'cons-hero-num text-mono', text: '0' });
|
||||
const heroTotalCalls = h('span', { className: 'text-muted text-mono', style: 'font-size: 11px;', text: '0 调用' });
|
||||
const heroCostUsd = h('strong', { className: 'cons-hero-cost text-mono', text: '$0.00' });
|
||||
const heroCostCny = h('span', { className: 'text-muted text-mono', style: 'font-size: 11px;', text: '≈ ¥0' });
|
||||
|
||||
const cacheHitPctEl = h('strong', { className: 'cons-hero-cache text-mono', text: '0%' });
|
||||
const cacheTokensEl = h('span', { className: 'text-muted text-mono', style: 'font-size: 11px;', text: '命中 0' });
|
||||
|
||||
const inputSharePct = h('span', { className: 'text-mono', style: 'color: var(--ctx-input); font-weight: 600; font-size: 11.5px;', text: '0%' });
|
||||
const inputMainTokens = h('strong', { className: 'cons-mid-num text-mono', text: '0' });
|
||||
const inputSubText = h('span', { className: 'text-muted text-mono', style: 'font-size: 11px;', text: '直接输入 0 · 缓存读取 0' });
|
||||
|
||||
const outputSharePct = h('span', { className: 'text-mono', style: 'color: var(--ctx-output); font-weight: 600; font-size: 11.5px;', text: '0%' });
|
||||
const outputMainTokens = h('strong', { className: 'cons-mid-num text-mono', text: '0' });
|
||||
const outputSubText = h('span', { className: 'text-muted text-mono', style: 'font-size: 11px;', text: '内容生成 0 · 思考推理 0' });
|
||||
|
||||
const overviewSegBar = createFourSegmentBar();
|
||||
|
||||
const overviewPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header cons-overview-head' }, [
|
||||
h('span', { className: 'panel-title' }, [
|
||||
h('span', { text: '用量概览' }),
|
||||
dateSpanBadge,
|
||||
]),
|
||||
timeFilterSwitch.el,
|
||||
]),
|
||||
customRangeBar,
|
||||
h('div', { className: 'cons-box cons-unified-matrix' }, [
|
||||
h('div', { className: 'cons-split-3' }, [
|
||||
h('div', { className: 'cons-col' }, [
|
||||
h('span', { className: 'text-muted', style: 'font-size: 11px;', text: '总 Token 数' }),
|
||||
h('div', { className: 'cons-baseline' }, [heroTotalTokens, heroTotalCalls]),
|
||||
]),
|
||||
h('div', { className: 'cons-col is-bordered-col' }, [
|
||||
h('span', { className: 'text-muted', style: 'font-size: 11px;', text: '预估费用' }),
|
||||
h('div', { className: 'cons-baseline' }, [heroCostUsd, heroCostCny]),
|
||||
]),
|
||||
h('div', { className: 'cons-col is-bordered-col' }, [
|
||||
h('span', { className: 'legend-left', style: 'font-size: 11px;' }, [
|
||||
h('span', { className: 'dot-swatch seg-cached' }),
|
||||
h('span', { text: '缓存命中率' }),
|
||||
]),
|
||||
h('div', { className: 'cons-baseline' }, [cacheHitPctEl, cacheTokensEl]),
|
||||
]),
|
||||
]),
|
||||
h('div', { className: 'cons-split-2 cons-matrix-bottom' }, [
|
||||
h('div', { className: 'cons-col' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-input' }),
|
||||
h('span', { style: 'color: var(--text-primary); font-weight: 600; font-size: 11.5px;', text: '输入用量' }),
|
||||
inputMainTokens,
|
||||
]),
|
||||
inputSharePct,
|
||||
]),
|
||||
inputSubText,
|
||||
]),
|
||||
h('div', { className: 'cons-col is-bordered-col' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-output' }),
|
||||
h('span', { style: 'color: var(--text-primary); font-weight: 600; font-size: 11.5px;', text: '输出用量' }),
|
||||
outputMainTokens,
|
||||
]),
|
||||
outputSharePct,
|
||||
]),
|
||||
outputSubText,
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
overviewSegBar.el,
|
||||
]);
|
||||
|
||||
// --- Section 2: 历史趋势 (Historical Trend SVG Spline Area Chart) ---
|
||||
const trendRangeBadge = h('span', { className: 'cons-badge', text: '全部时间' });
|
||||
const trendChart = createTrendAreaChart();
|
||||
const anchorStartTime = h('span', { className: 'text-muted text-mono', text: '00:00' });
|
||||
const anchorStartVal = h('strong', { className: 'text-mono', text: '0' });
|
||||
const anchorMidTime = h('span', { className: 'text-muted text-mono', text: '06:00' });
|
||||
const anchorMidVal = h('strong', { className: 'text-mono', text: '0' });
|
||||
const anchorEndTime = h('span', { className: 'text-muted text-mono', text: '12:00' });
|
||||
const anchorEndVal = h('strong', { className: 'text-mono', text: '0' });
|
||||
|
||||
const trendPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title', text: '历史趋势' }),
|
||||
trendRangeBadge,
|
||||
]),
|
||||
trendChart.el,
|
||||
h('div', { className: 'trend-anchors' }, [
|
||||
h('div', { className: 'trend-anchor-col' }, [anchorStartTime, anchorStartVal]),
|
||||
h('div', { className: 'trend-anchor-col is-center' }, [anchorMidTime, anchorMidVal]),
|
||||
h('div', { className: 'trend-anchor-col is-end' }, [anchorEndTime, anchorEndVal]),
|
||||
]),
|
||||
]);
|
||||
|
||||
// --- Section 3: 热门模型 (Popular Models Breakdown) ---
|
||||
const modelsListEl = h('div', { className: 'cons-item-list' });
|
||||
const modelsPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title', text: '热门模型' }),
|
||||
]),
|
||||
modelsListEl,
|
||||
]);
|
||||
|
||||
// --- Section 4: 数据来源 ---
|
||||
const sourcesListEl = h('div', { className: 'cons-item-list' });
|
||||
const sourcesPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title', text: '数据来源' }),
|
||||
]),
|
||||
sourcesListEl,
|
||||
]);
|
||||
|
||||
// --- Section 5: 按月细分 (12-Month Stacked Bar Chart) ---
|
||||
const monthlyYearBadge = h('span', { className: 'cons-badge text-mono', text: '2026' });
|
||||
const monthlyCols = Array.from({ length: 12 }, (_, idx) => {
|
||||
const costText = h('span', { className: 'month-cost text-mono', text: '' });
|
||||
const barThink = h('div', { className: 'month-seg seg-thinking' });
|
||||
const barOut = h('div', { className: 'month-seg seg-output' });
|
||||
const barCache = h('div', { className: 'month-seg seg-cached' });
|
||||
const barIn = h('div', { className: 'month-seg seg-input' });
|
||||
const stackWrap = h('div', { className: 'month-stack' }, [
|
||||
barThink,
|
||||
barOut,
|
||||
barCache,
|
||||
barIn,
|
||||
]);
|
||||
const zeroDot = h('span', { className: 'month-zero-dot' });
|
||||
const monthLabel = h('span', { className: 'month-label', text: `${idx + 1}月` });
|
||||
const tokText = h('span', { className: 'month-tok text-mono', text: '' });
|
||||
|
||||
const colEl = h('div', { className: 'month-col' }, [
|
||||
costText,
|
||||
h('div', { className: 'month-bar-well' }, [stackWrap, zeroDot]),
|
||||
monthLabel,
|
||||
tokText,
|
||||
]);
|
||||
return {
|
||||
el: colEl,
|
||||
costText,
|
||||
stackWrap,
|
||||
zeroDot,
|
||||
barThink,
|
||||
barOut,
|
||||
barCache,
|
||||
barIn,
|
||||
monthLabel,
|
||||
tokText,
|
||||
};
|
||||
});
|
||||
|
||||
const monthlyPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title', text: '按月细分' }),
|
||||
monthlyYearBadge,
|
||||
]),
|
||||
h(
|
||||
'div',
|
||||
{ className: 'monthly-grid' },
|
||||
monthlyCols.map((c) => c.el)
|
||||
),
|
||||
h('div', { className: 'monthly-legend' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-input' }),
|
||||
h('span', { text: '输入' }),
|
||||
]),
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-cached' }),
|
||||
h('span', { text: '缓存' }),
|
||||
]),
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-output' }),
|
||||
h('span', { text: '输出' }),
|
||||
]),
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-thinking' }),
|
||||
h('span', { text: '思考' }),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
|
||||
const scrollInner = h(
|
||||
'div',
|
||||
{
|
||||
style: 'display: flex; flex-direction: column; gap: var(--space-3); padding-bottom: var(--space-3);',
|
||||
},
|
||||
[
|
||||
overviewPanel,
|
||||
trendPanel,
|
||||
modelsPanel,
|
||||
sourcesPanel,
|
||||
monthlyPanel,
|
||||
]
|
||||
);
|
||||
|
||||
const viewScrollbar = CustomScrollbar({
|
||||
contentEl: scrollInner,
|
||||
className: 'view-pane',
|
||||
});
|
||||
|
||||
function createBreakdownItemRow() {
|
||||
const nameEl = h('strong', { className: 'cons-row-title' });
|
||||
const pctBadge = h('span', { className: 'cons-share-pill text-mono', text: '0%' });
|
||||
const totalTokEl = h('span', { className: 'cons-row-tok text-mono' });
|
||||
const costEl = h('strong', { className: 'cons-row-cost text-mono' });
|
||||
const segBar = createFourSegmentBar();
|
||||
|
||||
const inVal = h('strong', { className: 'text-mono' });
|
||||
const cacheVal = h('strong', { className: 'text-mono' });
|
||||
const outVal = h('strong', { className: 'text-mono' });
|
||||
const thinkVal = h('strong', { className: 'text-mono' });
|
||||
const callsVal = h('strong', { className: 'text-mono' });
|
||||
|
||||
const rowEl = h('div', { className: 'cons-item-row' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
nameEl,
|
||||
h('span', { className: 'cons-row-metrics' }, [
|
||||
pctBadge,
|
||||
totalTokEl,
|
||||
costEl,
|
||||
]),
|
||||
]),
|
||||
segBar.el,
|
||||
h('div', { className: 'cons-item-foot' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-input' }),
|
||||
h('span', { text: '输入 ' }),
|
||||
inVal,
|
||||
]),
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-cached' }),
|
||||
h('span', { text: '缓存 ' }),
|
||||
cacheVal,
|
||||
]),
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-output' }),
|
||||
h('span', { text: '输出 ' }),
|
||||
outVal,
|
||||
]),
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'dot-swatch seg-thinking' }),
|
||||
h('span', { text: '思考 ' }),
|
||||
thinkVal,
|
||||
]),
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { text: '调用 ' }),
|
||||
callsVal,
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
|
||||
return {
|
||||
el: rowEl,
|
||||
refs: { nameEl, pctBadge, totalTokEl, costEl, segBar, inVal, cacheVal, outVal, thinkVal, callsVal },
|
||||
};
|
||||
}
|
||||
|
||||
function updateBreakdownItemRow(refs, item, grandTotalTokens, showTokensInHeader = true) {
|
||||
patchText(refs.nameEl, item.label || item.name || item.shortName || '—');
|
||||
const total = Number(item.totalTokens || 0);
|
||||
const share = grandTotalTokens > 0 ? +((total / grandTotalTokens) * 100).toFixed(1) : 0;
|
||||
patchText(refs.pctBadge, `${share.toFixed(1)}%`);
|
||||
patchText(refs.totalTokEl, showTokensInHeader ? formatTokensPrecise(total) : '');
|
||||
patchAttr(refs.totalTokEl, 'hidden', !showTokensInHeader);
|
||||
patchText(refs.costEl, formatUsd(item.costUsd || 0));
|
||||
|
||||
const responseTok =
|
||||
item.responseTokens != null
|
||||
? Number(item.responseTokens)
|
||||
: Math.max(0, Number(item.outputTokens || 0) - Number(item.thinkingTokens || 0));
|
||||
const thinkingTok = Number(item.thinkingTokens || 0);
|
||||
|
||||
refs.segBar.update({
|
||||
inputTokens: Number(item.inputTokens || 0),
|
||||
cacheReadTokens: Number(item.cacheReadTokens || 0),
|
||||
responseTokens: responseTok,
|
||||
thinkingTokens: thinkingTok,
|
||||
});
|
||||
|
||||
patchText(refs.inVal, formatTokensPrecise(item.inputTokens || 0));
|
||||
patchText(refs.cacheVal, formatTokensPrecise(item.cacheReadTokens || 0));
|
||||
patchText(refs.outVal, formatTokensPrecise(responseTok));
|
||||
patchText(refs.thinkVal, formatTokensPrecise(thinkingTok));
|
||||
patchText(refs.callsVal, String(Number(item.calls || 0)));
|
||||
}
|
||||
|
||||
let latestSlice = null;
|
||||
let isDirty = false;
|
||||
|
||||
function renderConsumptionData(slice) {
|
||||
if (!slice) return;
|
||||
timeFilterSwitch.setValue(slice.range);
|
||||
patchAttr(customRangeBar, 'hidden', slice.range !== 'custom');
|
||||
startPicker.setValue(slice.customStartMs);
|
||||
endPicker.setValue(slice.customEndMs);
|
||||
|
||||
const cons = slice.consumption || {};
|
||||
const preset =
|
||||
slice.range !== 'custom' && cons.presets?.[slice.range]
|
||||
? cons.presets[slice.range]
|
||||
: null;
|
||||
const acct = preset?.account || cons.account || {};
|
||||
const rangeInfo = cons.selectedRange || {};
|
||||
|
||||
// 1. Overview
|
||||
patchText(dateSpanBadge, formatDateSpanBadge(rangeInfo.startMs, rangeInfo.endMs));
|
||||
const totalTokens = Number(acct.totalTokens || 0);
|
||||
const inputTokens = Number(acct.inputTokens || 0);
|
||||
const cacheTokens = Number(acct.cacheReadTokens || 0);
|
||||
const outputTokens = Number(acct.outputTokens || 0);
|
||||
const responseTokens = Number(acct.responseTokens || 0);
|
||||
const thinkingTokens = Number(acct.thinkingTokens || 0);
|
||||
const costUsd = Number(acct.costUsd || 0);
|
||||
|
||||
patchText(heroTotalTokens, formatTokensPrecise(totalTokens));
|
||||
patchText(heroTotalCalls, `${acct.calls || 0} 调用`);
|
||||
patchText(heroCostUsd, formatUsd(costUsd));
|
||||
patchText(heroCostCny, formatCnyApprox(costUsd));
|
||||
|
||||
patchText(cacheHitPctEl, `${Number(acct.cacheHitPct ?? 0).toFixed(1)}%`);
|
||||
patchText(cacheTokensEl, `命中 ${formatTokensPrecise(cacheTokens)}`);
|
||||
|
||||
const inPct = totalTokens > 0 ? +((inputTokens / totalTokens) * 100).toFixed(1) : 0;
|
||||
const outPct = totalTokens > 0 ? +((outputTokens / totalTokens) * 100).toFixed(1) : 0;
|
||||
patchText(inputSharePct, `${inPct}%`);
|
||||
patchText(inputMainTokens, formatTokensPrecise(inputTokens));
|
||||
patchText(
|
||||
inputSubText,
|
||||
`直接输入 ${formatTokensPrecise(inputTokens)} · 缓存读取 ${formatTokensPrecise(cacheTokens)}`
|
||||
);
|
||||
|
||||
patchText(outputSharePct, `${outPct}%`);
|
||||
patchText(outputMainTokens, formatTokensPrecise(outputTokens));
|
||||
patchText(
|
||||
outputSubText,
|
||||
`内容生成 ${formatTokensPrecise(responseTokens)} · 思考推理 ${formatTokensPrecise(thinkingTokens)}`
|
||||
);
|
||||
|
||||
overviewSegBar.update({
|
||||
inputTokens,
|
||||
cacheReadTokens: cacheTokens,
|
||||
responseTokens,
|
||||
thinkingTokens,
|
||||
});
|
||||
|
||||
// 2. Historical Trend
|
||||
patchText(trendRangeBadge, preset?.label || rangeInfo.label || '全部时间');
|
||||
const trendSeries = cons.trendSeries || [];
|
||||
trendChart.update(trendSeries);
|
||||
if (trendSeries.length > 0) {
|
||||
const first = trendSeries[0];
|
||||
const mid = trendSeries[Math.floor(trendSeries.length / 2)];
|
||||
const last = trendSeries[trendSeries.length - 1];
|
||||
patchText(anchorStartTime, first.label);
|
||||
patchText(anchorStartVal, formatTokensPrecise(first.tokens));
|
||||
patchText(anchorMidTime, mid.label);
|
||||
patchText(anchorMidVal, formatTokensPrecise(mid.tokens));
|
||||
patchText(anchorEndTime, last.label);
|
||||
patchText(anchorEndVal, formatTokensPrecise(last.tokens));
|
||||
}
|
||||
|
||||
// 3. Popular Models
|
||||
const models = (slice.modelBreakdown || [])
|
||||
.slice()
|
||||
.sort((a, b) => (b.totalTokens || 0) - (a.totalTokens || 0));
|
||||
const modelsTotalTok = models.reduce((s, m) => s + Number(m.totalTokens || 0), 0);
|
||||
|
||||
patchKeyedList(modelsListEl, models, {
|
||||
keyFn: (m) => m.label || m.shortName,
|
||||
sigFn: (m) =>
|
||||
`${m.label}:${m.totalTokens}:${m.costUsd}:${m.calls}:${modelsTotalTok}`,
|
||||
createRow: createBreakdownItemRow,
|
||||
updateRow: (refs, m) => updateBreakdownItemRow(refs, m, modelsTotalTok, true),
|
||||
});
|
||||
|
||||
// 4. Sources Breakdown
|
||||
const sources = cons.sourcesBreakdown || [];
|
||||
const sourcesTotalTok = sources.reduce((s, x) => s + Number(x.totalTokens || 0), 0);
|
||||
patchKeyedList(sourcesListEl, sources, {
|
||||
keyFn: (s) => s.name,
|
||||
sigFn: (s) => `${s.name}:${s.totalTokens}:${s.costUsd}:${s.calls}:${sourcesTotalTok}`,
|
||||
createRow: createBreakdownItemRow,
|
||||
updateRow: (refs, s) => updateBreakdownItemRow(refs, s, sourcesTotalTok, true),
|
||||
});
|
||||
|
||||
// 5. Monthly Breakdown
|
||||
const monthlyYear = cons.monthlyYear || new Date().getFullYear();
|
||||
const currentMonthIdx = new Date().getMonth();
|
||||
patchText(monthlyYearBadge, String(monthlyYear));
|
||||
const monthlySeries = cons.monthlySeries || [];
|
||||
const maxMonthTokens = Math.max(
|
||||
1,
|
||||
...monthlySeries.map((m) => Number(m.totalTokens || 0))
|
||||
);
|
||||
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const col = monthlyCols[i];
|
||||
const m = monthlySeries[i] || { totalTokens: 0, costUsd: 0 };
|
||||
const mTot = Number(m.totalTokens || 0);
|
||||
const hasData = mTot > 0;
|
||||
|
||||
patchClasses(col.monthLabel, { 'is-current': i === currentMonthIdx });
|
||||
patchAttr(col.stackWrap, 'hidden', !hasData);
|
||||
patchAttr(col.zeroDot, 'hidden', hasData);
|
||||
|
||||
if (!hasData) {
|
||||
patchText(col.costText, '');
|
||||
patchText(col.tokText, '');
|
||||
} else {
|
||||
const cVal = Number(m.costUsd || 0);
|
||||
patchText(col.costText, cVal >= 10 ? `$${Math.round(cVal)}` : `$${cVal.toFixed(2)}`);
|
||||
patchText(col.tokText, formatTokensPrecise(mTot));
|
||||
|
||||
const totalHeightPct = Math.max(8, Math.min(100, (mTot / maxMonthTokens) * 100));
|
||||
patchStyleVar(col.stackWrap, '--bar-h', `${totalHeightPct.toFixed(1)}%`);
|
||||
|
||||
const inPctM = (Number(m.inputTokens || 0) / mTot) * 100;
|
||||
const cachePctM = (Number(m.cacheReadTokens || 0) / mTot) * 100;
|
||||
const outPctM = (Number(m.responseTokens || 0) / mTot) * 100;
|
||||
const thinkPctM = (Number(m.thinkingTokens || 0) / mTot) * 100;
|
||||
|
||||
patchStyleVar(col.barIn, '--seg-h', `${inPctM.toFixed(1)}%`);
|
||||
patchStyleVar(col.barCache, '--seg-h', `${cachePctM.toFixed(1)}%`);
|
||||
patchStyleVar(col.barOut, '--seg-h', `${outPctM.toFixed(1)}%`);
|
||||
patchStyleVar(col.barThink, '--seg-h', `${thinkPctM.toFixed(1)}%`);
|
||||
}
|
||||
}
|
||||
|
||||
viewScrollbar.refresh();
|
||||
}
|
||||
|
||||
const unsub = telemetryStore.subscribe(
|
||||
(st) => ({
|
||||
range: st.selectedTimeRange,
|
||||
customStartMs: st.customStartMs,
|
||||
customEndMs: st.customEndMs,
|
||||
consumption: st.telemetry?.consumption,
|
||||
modelBreakdown: st.telemetry?.modelBreakdown,
|
||||
}),
|
||||
(slice) => {
|
||||
latestSlice = slice;
|
||||
if (uiStore.getState().activeView !== 'consumption') {
|
||||
isDirty = true;
|
||||
return;
|
||||
}
|
||||
isDirty = false;
|
||||
renderConsumptionData(slice);
|
||||
}
|
||||
);
|
||||
|
||||
const unsubView = uiStore.subscribe(
|
||||
(st) => st.activeView,
|
||||
(activeView) => {
|
||||
if (activeView === 'consumption' && isDirty) {
|
||||
isDirty = false;
|
||||
if (latestSlice) {
|
||||
renderConsumptionData(latestSlice);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onCleanup(() => {
|
||||
unsub();
|
||||
unsubView();
|
||||
timeFilterSwitch.destroy();
|
||||
startPicker.destroy();
|
||||
endPicker.destroy();
|
||||
viewScrollbar.destroy();
|
||||
});
|
||||
|
||||
return {
|
||||
el: viewScrollbar.el,
|
||||
refs: { timeFilterSwitch, startPicker, endPicker, viewScrollbar },
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,374 @@
|
||||
/**
|
||||
* @fileoverview View 1: LiveOverviewView (实时监控视图).
|
||||
* Displays real-time TPS, TTFT, weighted mean speed, 4-channel Context Window
|
||||
* breakdown automatically anchored to the current model's compaction baseline,
|
||||
* and official 5h/weekly quota pools for both Gemini and Claude & GPT.
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../core/component.js';
|
||||
import {
|
||||
h,
|
||||
patchClasses,
|
||||
patchStyleVar,
|
||||
patchText,
|
||||
} from '../core/domPatch.js';
|
||||
import {
|
||||
formatCountdown,
|
||||
formatMetric,
|
||||
formatTokens,
|
||||
formatUsd,
|
||||
sampleSummary,
|
||||
speedReasonText,
|
||||
} from '../core/formatters.js';
|
||||
import { createSvgIcon } from '../icons/SvgIcon.js';
|
||||
import { telemetryStore } from '../store/telemetryStore.js';
|
||||
import { uiStore } from '../store/uiStore.js';
|
||||
import { ContextSegmentMeter } from '../components/ui/ContextSegmentMeter.js';
|
||||
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
|
||||
|
||||
export const LiveOverviewView = defineComponent({
|
||||
name: 'LiveOverviewView',
|
||||
setup({ onCleanup }) {
|
||||
// 1. 4-Cell Real-time Telemetry Matrix
|
||||
const tpsVal = h('strong', { className: 'cell-value accent-speed', text: '—' });
|
||||
const tpsSub = h('span', { className: 'cell-sub', text: 'argon-4' });
|
||||
const pulseDot = createSvgIcon('dot', { size: 10 });
|
||||
|
||||
const ttftVal = h('strong', { className: 'cell-value', text: '—' });
|
||||
const ttftSub = h('span', { className: 'cell-sub', text: '均值 —' });
|
||||
|
||||
const avgVal = h('strong', { className: 'cell-value', text: '—' });
|
||||
const avgSub = h('span', { className: 'cell-sub', text: '有效 0/0 步' });
|
||||
|
||||
const costVal = h('strong', { className: 'cell-value', text: '$0.000' });
|
||||
const cacheSub = h('span', { className: 'cell-sub accent-ok', text: '缓存 0% · 累 $0.00' });
|
||||
|
||||
const matrixEl = h('section', { className: 'telemetry-matrix', 'aria-label': '核心测速指标' }, [
|
||||
h('div', { className: 'matrix-cell' }, [
|
||||
h('div', { className: 'cell-label' }, [h('span', { text: '实时吞吐' }), pulseDot]),
|
||||
tpsVal,
|
||||
tpsSub,
|
||||
]),
|
||||
h('div', { className: 'matrix-cell' }, [
|
||||
h('div', { className: 'cell-label' }, [
|
||||
h('span', { text: '首Token' }),
|
||||
createSvgIcon('clock', { size: 11 }),
|
||||
]),
|
||||
ttftVal,
|
||||
ttftSub,
|
||||
]),
|
||||
h('div', { className: 'matrix-cell' }, [
|
||||
h('div', { className: 'cell-label' }, [
|
||||
h('span', { text: '会话均速' }),
|
||||
createSvgIcon('pulse', { size: 11 }),
|
||||
]),
|
||||
avgVal,
|
||||
avgSub,
|
||||
]),
|
||||
h('div', { className: 'matrix-cell' }, [
|
||||
h('div', { className: 'cell-label' }, [
|
||||
h('span', { text: '本步消费' }),
|
||||
createSvgIcon('bolt', { size: 11 }),
|
||||
]),
|
||||
costVal,
|
||||
cacheSub,
|
||||
]),
|
||||
]);
|
||||
|
||||
// 2. Context Window 6-Segment Panel (Auto Compaction Baseline)
|
||||
const ctxSummaryText = h('span', { className: 'text-mono', text: '0 / 256.0k (0%)' });
|
||||
const ctxSegmentBar = ContextSegmentMeter({ context: {} });
|
||||
|
||||
const bdMessages = h('strong', { className: 'text-mono', text: '0' });
|
||||
const bdSystemTools = h('strong', { className: 'text-mono', text: '0' });
|
||||
const bdMcpTools = h('strong', { className: 'text-mono', text: '0' });
|
||||
const bdSkills = h('strong', { className: 'text-mono', text: '0' });
|
||||
const bdSystemPrompt = h('strong', { className: 'text-mono', text: '0' });
|
||||
const bdUserRules = h('strong', { className: 'text-mono', text: '0' });
|
||||
|
||||
const ctxPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title' }, [
|
||||
createSvgIcon('layers', { size: 13 }),
|
||||
h('span', { text: '上下文窗口构成' }),
|
||||
]),
|
||||
h('span', { className: 'panel-meta' }, [ctxSummaryText]),
|
||||
]),
|
||||
ctxSegmentBar.el,
|
||||
h('div', { className: 'ctx-legend-grid' }, [
|
||||
h('div', { className: 'legend-item' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'swatch seg-messages' }),
|
||||
h('span', { text: '消息' }),
|
||||
]),
|
||||
bdMessages,
|
||||
]),
|
||||
h('div', { className: 'legend-item' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'swatch seg-system-tools' }),
|
||||
h('span', { text: '系统工具' }),
|
||||
]),
|
||||
bdSystemTools,
|
||||
]),
|
||||
h('div', { className: 'legend-item' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'swatch seg-mcp-tools' }),
|
||||
h('span', { text: 'MCP 工具' }),
|
||||
]),
|
||||
bdMcpTools,
|
||||
]),
|
||||
h('div', { className: 'legend-item' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'swatch seg-skills' }),
|
||||
h('span', { text: 'Skill' }),
|
||||
]),
|
||||
bdSkills,
|
||||
]),
|
||||
h('div', { className: 'legend-item' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'swatch seg-system-prompt' }),
|
||||
h('span', { text: '系统提示词' }),
|
||||
]),
|
||||
bdSystemPrompt,
|
||||
]),
|
||||
h('div', { className: 'legend-item' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('span', { className: 'swatch seg-user-rules' }),
|
||||
h('span', { text: 'user_rule' }),
|
||||
]),
|
||||
bdUserRules,
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
|
||||
// 3. Official 5h & Weekly Quotas Panel (Gemini Pool + Claude Pool)
|
||||
const tierBadge = h('span', { className: 'panel-meta', text: 'Google AI · Pro' });
|
||||
|
||||
function createPoolQuotaBlock(poolLabel) {
|
||||
const title5h = h('span', { text: `5h 限额 (${poolLabel})` });
|
||||
const meta5h = h('span', { className: 'panel-meta text-mono', text: '--' });
|
||||
const fill5h = h('div', { className: 'progress-fill' });
|
||||
|
||||
const titleWk = h('span', { text: `每周限额 (${poolLabel})` });
|
||||
const metaWk = h('span', { className: 'panel-meta text-mono', text: '--' });
|
||||
const fillWk = h('div', { className: 'progress-fill' });
|
||||
|
||||
const el = h('div', { style: 'display: flex; flex-direction: column; gap: 8px;' }, [
|
||||
h('div', { style: 'display: flex; flex-direction: column; gap: 4px;' }, [
|
||||
h('div', { className: 'panel-header' }, [title5h, meta5h]),
|
||||
h('div', { className: 'progress-track' }, [fill5h]),
|
||||
]),
|
||||
h('div', { style: 'display: flex; flex-direction: column; gap: 4px;' }, [
|
||||
h('div', { className: 'panel-header' }, [titleWk, metaWk]),
|
||||
h('div', { className: 'progress-track' }, [fillWk]),
|
||||
]),
|
||||
]);
|
||||
|
||||
return { el, title5h, meta5h, fill5h, titleWk, metaWk, fillWk };
|
||||
}
|
||||
|
||||
const geminiQuotaBlock = createPoolQuotaBlock('Gemini');
|
||||
const claudeQuotaBlock = createPoolQuotaBlock('Claude & GPT');
|
||||
claudeQuotaBlock.el.setAttribute(
|
||||
'style',
|
||||
'display: flex; flex-direction: column; gap: 8px; margin-top: 3px; padding-top: 10px; border-top: 1px solid var(--border-hairline);'
|
||||
);
|
||||
|
||||
const wkFootLeft = h('span', { className: 'text-muted', text: '本周本机: 0 ($0.00)' });
|
||||
const wkFootRight = h('span', { className: 'text-muted', text: '' });
|
||||
|
||||
const quotaPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title' }, [
|
||||
createSvgIcon('pulse', { size: 13 }),
|
||||
h('span', { text: '官方配额与周期监控' }),
|
||||
]),
|
||||
tierBadge,
|
||||
]),
|
||||
geminiQuotaBlock.el,
|
||||
claudeQuotaBlock.el,
|
||||
h('div', { className: 'panel-header', style: 'font-size: 11px; padding-top: 2px;' }, [
|
||||
wkFootLeft,
|
||||
wkFootRight,
|
||||
]),
|
||||
]);
|
||||
|
||||
const overviewInner = h(
|
||||
'div',
|
||||
{
|
||||
style: 'display: flex; flex-direction: column; gap: var(--space-3); padding-bottom: 2px;',
|
||||
},
|
||||
[matrixEl, ctxPanel, quotaPanel]
|
||||
);
|
||||
const viewScrollbar = CustomScrollbar({
|
||||
contentEl: overviewInner,
|
||||
className: 'view-pane',
|
||||
});
|
||||
|
||||
function syncPoolQuotaBlock(block, poolLabel, poolData, fallbackWeekly, isActiveFamily) {
|
||||
const has5h = poolData?.usedPct != null && poolData?.remainingPct != null;
|
||||
const used5hVal = has5h ? Number(poolData.usedPct) : 0;
|
||||
const rem5hVal = has5h ? Number(poolData.remainingPct) : 0;
|
||||
patchText(block.title5h, `5h 限额 (${poolLabel})`);
|
||||
patchText(
|
||||
block.meta5h,
|
||||
has5h
|
||||
? `${formatCountdown(poolData.resetTime)} · 已用 ${used5hVal.toFixed(1)}% (余 ${rem5hVal.toFixed(1)}%)`
|
||||
: '获取失败 (--%)'
|
||||
);
|
||||
patchStyleVar(block.fill5h, '--fill-w', `${Math.min(100, used5hVal)}%`);
|
||||
patchClasses(block.fill5h, {
|
||||
'tone-warn': used5hVal >= 60 && used5hVal < 85,
|
||||
'tone-danger': used5hVal >= 85,
|
||||
});
|
||||
|
||||
const wkUsedRaw =
|
||||
poolData?.weeklyUsedPct ?? (isActiveFamily ? fallbackWeekly?.usedPct : null);
|
||||
const wkRemRaw =
|
||||
poolData?.weeklyRemainingPct ?? (isActiveFamily ? fallbackWeekly?.remainingPct : null);
|
||||
const wkResetRaw =
|
||||
poolData?.weeklyResetTime || (isActiveFamily ? fallbackWeekly?.resetTime : null);
|
||||
const hasWk = wkUsedRaw != null && wkRemRaw != null;
|
||||
const usedWkVal = hasWk ? Number(wkUsedRaw) : 0;
|
||||
const remWkVal = hasWk ? Number(wkRemRaw) : 0;
|
||||
|
||||
const customTitle =
|
||||
isActiveFamily && fallbackWeekly?.isOfficial === false && fallbackWeekly?.title
|
||||
? fallbackWeekly.title
|
||||
: `每周限额 (${poolLabel})`;
|
||||
patchText(block.titleWk, customTitle);
|
||||
patchText(
|
||||
block.metaWk,
|
||||
hasWk
|
||||
? `${formatCountdown(wkResetRaw)} · 已用 ${usedWkVal.toFixed(1)}% (余 ${remWkVal.toFixed(1)}%)`
|
||||
: '获取失败 (--%)'
|
||||
);
|
||||
patchStyleVar(block.fillWk, '--fill-w', `${Math.min(100, usedWkVal)}%`);
|
||||
patchClasses(block.fillWk, {
|
||||
'tone-warn': usedWkVal >= 60 && usedWkVal < 85,
|
||||
'tone-danger': usedWkVal >= 85,
|
||||
});
|
||||
}
|
||||
|
||||
let latestData = null;
|
||||
let isDirty = false;
|
||||
|
||||
function renderData(data) {
|
||||
if (!data) return;
|
||||
const active = data.activeConversation || {};
|
||||
const ctx = active.context || {};
|
||||
const quotas = data.quotas || {};
|
||||
|
||||
// 1. Matrix
|
||||
patchClasses(pulseDot, { 'is-pulsing': Boolean(active.isRunning) });
|
||||
patchText(tpsVal, formatMetric(active.latestTokPerSec, ' tok/s'));
|
||||
const reason = speedReasonText(active.latestSpeedReason);
|
||||
patchText(
|
||||
tpsSub,
|
||||
reason ? `${active.activeModelShort || 'argon-4'} · ${reason}` : active.activeModelShort || 'argon-4'
|
||||
);
|
||||
|
||||
patchText(ttftVal, formatMetric(active.latestTtftSec, 's'));
|
||||
patchText(ttftSub, `均值 ${formatMetric(active.ttftSummary?.avgSec, 's')}`);
|
||||
|
||||
patchText(avgVal, formatMetric(active.avgTokPerSec, ' tok/s'));
|
||||
patchText(avgSub, `有效 ${sampleSummary(active.speedSummary)}`);
|
||||
|
||||
const stepCost = Number(active.latestStepCostUsd ?? active.recentSteps?.[0]?.costUsd ?? 0);
|
||||
patchText(costVal, formatUsd(stepCost, { precise: true }));
|
||||
patchText(
|
||||
cacheSub,
|
||||
`缓 ${active.latestCacheHitPct ?? 0}% · 累 ${formatUsd(active.sessionCostUsd || 0)}`
|
||||
);
|
||||
|
||||
// 2. Context (Auto Compaction Baseline)
|
||||
const limitTokens = Number(ctx.compactionLimitTokens || ctx.limitTokens || 256000);
|
||||
const totalTokens = Number(ctx.totalTokens || 0);
|
||||
const usedPct =
|
||||
limitTokens > 0 ? Math.min(100, +((totalTokens / limitTokens) * 100).toFixed(1)) : 0;
|
||||
patchText(
|
||||
ctxSummaryText,
|
||||
`${formatTokens(totalTokens)} / ${formatTokens(limitTokens)} (${usedPct}%)`
|
||||
);
|
||||
ctxSegmentBar.setProps({ context: { ...ctx, limitTokens, usedPct } });
|
||||
patchText(bdMessages, formatTokens(ctx.messagesTokens || 0));
|
||||
patchText(bdSystemTools, formatTokens(ctx.systemToolsTokens || 0));
|
||||
patchText(bdMcpTools, formatTokens(ctx.mcpToolsTokens || 0));
|
||||
patchText(bdSkills, formatTokens(ctx.skillsTokens || 0));
|
||||
patchText(bdSystemPrompt, formatTokens(ctx.systemPromptTokens || 0));
|
||||
patchText(bdUserRules, formatTokens(ctx.userRulesTokens || 0));
|
||||
|
||||
// 3. Quotas (Gemini + Claude & GPT)
|
||||
patchText(
|
||||
tierBadge,
|
||||
`${data.account?.tierName || 'Google AI'} · ${data.account?.planName || 'Pro'}`
|
||||
);
|
||||
const activePool = quotas.activePool || {};
|
||||
const pools = quotas.pools || [];
|
||||
const weekly = quotas.weekly || {};
|
||||
|
||||
const geminiPool =
|
||||
pools.find((p) => p.family === 'Gemini') ||
|
||||
(activePool.family === 'Gemini' ? activePool : null) ||
|
||||
{};
|
||||
const claudePool =
|
||||
pools.find((p) => p.family === 'Claude & GPT' || p.family === 'Claude') ||
|
||||
(activePool.family && activePool.family !== 'Gemini' ? activePool : null) ||
|
||||
{};
|
||||
|
||||
const activeIsGemini = (activePool.family || 'Gemini') === 'Gemini';
|
||||
syncPoolQuotaBlock(geminiQuotaBlock, 'Gemini', geminiPool, weekly, activeIsGemini);
|
||||
syncPoolQuotaBlock(claudeQuotaBlock, 'Claude & GPT', claudePool, weekly, !activeIsGemini);
|
||||
|
||||
patchText(
|
||||
wkFootLeft,
|
||||
`本周本机: ${formatTokens(weekly.tokens || 0)} (${formatUsd(weekly.costUsd || 0)})`
|
||||
);
|
||||
patchText(
|
||||
wkFootRight,
|
||||
data.account?.aiCredits > 0
|
||||
? `AI 积分: ${data.account.aiCredits}`
|
||||
: `本机调用: ${weekly.calls || 0} 步`
|
||||
);
|
||||
|
||||
viewScrollbar.refresh();
|
||||
}
|
||||
|
||||
const unsub = telemetryStore.subscribe(
|
||||
(st) => st.telemetry,
|
||||
(data) => {
|
||||
latestData = data;
|
||||
if (uiStore.getState().activeView !== 'overview') {
|
||||
isDirty = true;
|
||||
return;
|
||||
}
|
||||
isDirty = false;
|
||||
renderData(data);
|
||||
}
|
||||
);
|
||||
|
||||
const unsubView = uiStore.subscribe(
|
||||
(st) => st.activeView,
|
||||
(activeView) => {
|
||||
if (activeView === 'overview' && isDirty) {
|
||||
isDirty = false;
|
||||
if (latestData) {
|
||||
renderData(latestData);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onCleanup(() => {
|
||||
unsub();
|
||||
unsubView();
|
||||
ctxSegmentBar.destroy();
|
||||
viewScrollbar.destroy();
|
||||
});
|
||||
|
||||
return {
|
||||
el: viewScrollbar.el,
|
||||
refs: { viewScrollbar },
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* @fileoverview View 4: SettingsView (系统设置视图).
|
||||
* Replaces all native form controls (<select>, <input type="number">) with
|
||||
* bespoke CustomSelect and CustomNumberInput components.
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../core/component.js';
|
||||
import { h, patchText } from '../core/domPatch.js';
|
||||
import { createSvgIcon } from '../icons/SvgIcon.js';
|
||||
import {
|
||||
saveSettingsPatch,
|
||||
telemetryStore,
|
||||
} from '../store/telemetryStore.js';
|
||||
import { uiStore } from '../store/uiStore.js';
|
||||
import { CustomNumberInput } from '../components/ui/CustomNumberInput.js';
|
||||
import { CustomSelect } from '../components/ui/CustomSelect.js';
|
||||
|
||||
const WEEKLY_MODE_OPTIONS = [
|
||||
{ value: 'official', label: '官方云端周限额 (与 Models & Usage 同步)' },
|
||||
{ value: 'custom_tokens', label: '按自定义每周 Token 预算计算百分比' },
|
||||
{ value: 'custom_cost', label: '按自定义每周美元 ($) 预算计算百分比' },
|
||||
];
|
||||
|
||||
export const SettingsView = defineComponent({
|
||||
name: 'SettingsView',
|
||||
setup({ onCleanup }) {
|
||||
let draftMode = 'official';
|
||||
let draftTokens = 150000000;
|
||||
let draftCost = 100;
|
||||
|
||||
const modeSelect = CustomSelect({
|
||||
modelValue: draftMode,
|
||||
icon: 'sliders',
|
||||
options: WEEKLY_MODE_OPTIONS,
|
||||
onUpdateModelValue: (val) => {
|
||||
draftMode = val;
|
||||
},
|
||||
});
|
||||
|
||||
const tokenBudgetInput = CustomNumberInput({
|
||||
modelValue: draftTokens,
|
||||
min: 100000,
|
||||
max: 10000000000,
|
||||
step: 1000000,
|
||||
onUpdateModelValue: (val) => {
|
||||
draftTokens = val;
|
||||
},
|
||||
});
|
||||
|
||||
const costBudgetInput = CustomNumberInput({
|
||||
modelValue: draftCost,
|
||||
min: 1,
|
||||
max: 100000,
|
||||
step: 5,
|
||||
onUpdateModelValue: (val) => {
|
||||
draftCost = val;
|
||||
},
|
||||
});
|
||||
|
||||
const saveStatusText = h('span', { className: 'text-muted', style: 'font-size: 11px;', text: '' });
|
||||
|
||||
const saveBtn = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'btn-primary',
|
||||
onClick: async () => {
|
||||
patchText(saveStatusText, '正在异步保存...');
|
||||
await saveSettingsPatch({
|
||||
weeklyLimitMode: draftMode,
|
||||
weeklyTokenBudget: draftTokens,
|
||||
weeklyCostBudget: draftCost,
|
||||
});
|
||||
patchText(saveStatusText, '设置已生效');
|
||||
setTimeout(() => patchText(saveStatusText, ''), 1500);
|
||||
},
|
||||
},
|
||||
[createSvgIcon('check', { size: 13 }), h('span', { text: '保存参数设置' })]
|
||||
);
|
||||
|
||||
const budgetPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title' }, [
|
||||
createSvgIcon('sliders', { size: 13 }),
|
||||
h('span', { text: '监控口径与周限额基准设置' }),
|
||||
]),
|
||||
saveStatusText,
|
||||
]),
|
||||
h('div', { className: 'form-row' }, [
|
||||
h('span', { className: 'form-label', text: '每周进度条统计维度' }),
|
||||
modeSelect.el,
|
||||
]),
|
||||
h('div', { className: 'dual-grid' }, [
|
||||
h('div', { className: 'form-row' }, [
|
||||
h('span', { className: 'form-label', text: '每周 Token 预算基准 (步进 1M)' }),
|
||||
tokenBudgetInput.el,
|
||||
]),
|
||||
h('div', { className: 'form-row' }, [
|
||||
h('span', { className: 'form-label', text: '每周费用预算基准 (USD $, 步进 $5)' }),
|
||||
costBudgetInput.el,
|
||||
]),
|
||||
]),
|
||||
h('div', { style: 'display: flex; justify-content: flex-end;' }, [saveBtn]),
|
||||
]);
|
||||
|
||||
const rootEl = h('div', { className: 'view-pane' }, [budgetPanel]);
|
||||
|
||||
let latestSettings = null;
|
||||
let isDirty = false;
|
||||
|
||||
function renderSettings(settings) {
|
||||
if (!settings) return;
|
||||
draftMode =
|
||||
settings.weeklyLimitMode === 'custom_tokens' ||
|
||||
settings.weeklyLimitMode === 'custom_cost'
|
||||
? settings.weeklyLimitMode
|
||||
: 'official';
|
||||
draftTokens = Number(settings.weeklyTokenBudget || 150000000);
|
||||
draftCost = Number(settings.weeklyCostBudget || 100);
|
||||
modeSelect.setValue(draftMode);
|
||||
tokenBudgetInput.setValue(draftTokens);
|
||||
costBudgetInput.setValue(draftCost);
|
||||
}
|
||||
|
||||
const unsub = telemetryStore.subscribe(
|
||||
(st) => st.telemetry?.settings,
|
||||
(settings) => {
|
||||
latestSettings = settings;
|
||||
if (uiStore.getState().activeView !== 'settings') {
|
||||
isDirty = true;
|
||||
return;
|
||||
}
|
||||
isDirty = false;
|
||||
renderSettings(settings);
|
||||
}
|
||||
);
|
||||
|
||||
const unsubView = uiStore.subscribe(
|
||||
(st) => st.activeView,
|
||||
(activeView) => {
|
||||
if (activeView === 'settings' && isDirty) {
|
||||
isDirty = false;
|
||||
if (latestSettings) {
|
||||
renderSettings(latestSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onCleanup(() => {
|
||||
unsub();
|
||||
unsubView();
|
||||
modeSelect.destroy();
|
||||
tokenBudgetInput.destroy();
|
||||
costBudgetInput.destroy();
|
||||
});
|
||||
|
||||
return {
|
||||
el: rootEl,
|
||||
refs: { modeSelect, tokenBudgetInput, costBudgetInput },
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,274 @@
|
||||
/**
|
||||
* @fileoverview View 3: StepsDetailView (步骤明细与按模型汇总视图).
|
||||
* Uses patchKeyedList for incremental row reconciliation without innerHTML resets,
|
||||
* wraps tables in bespoke CustomScrollbar (zero native OS scrollbars), and provides
|
||||
* a live row inspector bar replacing native browser title tooltips.
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../core/component.js';
|
||||
import {
|
||||
h,
|
||||
patchAttr,
|
||||
patchClasses,
|
||||
patchKeyedList,
|
||||
patchText,
|
||||
} from '../core/domPatch.js';
|
||||
import {
|
||||
formatMetric,
|
||||
formatTokens,
|
||||
formatUsd,
|
||||
sampleSummary,
|
||||
speedReasonText,
|
||||
} from '../core/formatters.js';
|
||||
import { createSvgIcon } from '../icons/SvgIcon.js';
|
||||
import { telemetryStore } from '../store/telemetryStore.js';
|
||||
import { uiStore } from '../store/uiStore.js';
|
||||
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
|
||||
import { SegmentedControl } from '../components/ui/SegmentedControl.js';
|
||||
|
||||
export const StepsDetailView = defineComponent({
|
||||
name: 'StepsDetailView',
|
||||
setup({ onCleanup }) {
|
||||
const subTabSwitch = SegmentedControl({
|
||||
ariaLabel: '明细表视图切换',
|
||||
modelValue: uiStore.getState().stepsSubTab,
|
||||
options: [
|
||||
{ value: 'steps', label: '单步测速 (0步)' },
|
||||
{ value: 'models', label: '按模型汇总' },
|
||||
],
|
||||
onUpdateModelValue: (nextTab) => {
|
||||
uiStore.setState({ stepsSubTab: nextTab });
|
||||
},
|
||||
});
|
||||
|
||||
const stepsTbody = h('tbody');
|
||||
const stepsTablePane = h('div', { className: 'table-viewport' }, [
|
||||
h('table', { className: 'data-table' }, [
|
||||
h('thead', {}, [
|
||||
h('tr', {}, [
|
||||
h('th', { text: '步' }),
|
||||
h('th', { text: '模型' }),
|
||||
h('th', { text: '速度' }),
|
||||
h('th', { text: '首Token' }),
|
||||
h('th', { text: '上下文/输出' }),
|
||||
h('th', { text: '缓存' }),
|
||||
h('th', { text: '消费' }),
|
||||
]),
|
||||
]),
|
||||
stepsTbody,
|
||||
]),
|
||||
]);
|
||||
const stepsScroll = CustomScrollbar({
|
||||
contentEl: stepsTablePane,
|
||||
className: 'table-scroll-host',
|
||||
});
|
||||
|
||||
const modelsTbody = h('tbody');
|
||||
const modelsTablePane = h('div', { className: 'table-viewport' }, [
|
||||
h('table', { className: 'data-table' }, [
|
||||
h('thead', {}, [
|
||||
h('tr', {}, [
|
||||
h('th', { text: '模型' }),
|
||||
h('th', { text: '次数' }),
|
||||
h('th', { text: '均速' }),
|
||||
h('th', { text: '总 Token' }),
|
||||
h('th', { text: '折算费用' }),
|
||||
]),
|
||||
]),
|
||||
modelsTbody,
|
||||
]),
|
||||
]);
|
||||
const modelsScroll = CustomScrollbar({
|
||||
contentEl: modelsTablePane,
|
||||
className: 'table-scroll-host',
|
||||
});
|
||||
modelsScroll.el.setAttribute('hidden', '');
|
||||
|
||||
const panelEl = h(
|
||||
'section',
|
||||
{
|
||||
className: 'panel',
|
||||
style: 'flex: 1; min-height: 0; display: flex; flex-direction: column;',
|
||||
},
|
||||
[
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title' }, [
|
||||
createSvgIcon('table', { size: 13 }),
|
||||
h('span', { text: '全量测速与计费矩阵' }),
|
||||
]),
|
||||
subTabSwitch.el,
|
||||
]),
|
||||
stepsScroll.el,
|
||||
modelsScroll.el,
|
||||
]
|
||||
);
|
||||
|
||||
const rootEl = h('div', { className: 'view-pane' }, [panelEl]);
|
||||
|
||||
const unsubUi = uiStore.subscribe(
|
||||
(st) => st.stepsSubTab,
|
||||
(tab) => {
|
||||
subTabSwitch.setValue(tab);
|
||||
patchAttr(stepsScroll.el, 'hidden', tab !== 'steps');
|
||||
patchAttr(modelsScroll.el, 'hidden', tab !== 'models');
|
||||
if (tab === 'steps') stepsScroll.refresh();
|
||||
else modelsScroll.refresh();
|
||||
}
|
||||
);
|
||||
|
||||
let latestSlice = null;
|
||||
let isDirty = false;
|
||||
|
||||
function renderStepsData(slice) {
|
||||
if (!slice) return;
|
||||
const steps = slice.recentSteps || [];
|
||||
const models = slice.modelBreakdown || [];
|
||||
|
||||
subTabSwitch.setProps({
|
||||
options: [
|
||||
{ value: 'steps', label: `单步测速 (${steps.length}步)` },
|
||||
{ value: 'models', label: `按模型汇总 (${slice.rangeLabel})` },
|
||||
],
|
||||
});
|
||||
|
||||
patchKeyedList(stepsTbody, steps, {
|
||||
keyFn: (st) => `${slice.cascadeId || 'conv'}-${st.stepIndex}`,
|
||||
sigFn: (st) =>
|
||||
`${st.stepIndex}:${st.modelShort}:${st.tokPerSec}:${st.ttftSec}:${st.contextTokens}:${st.outputTokens}:${st.cacheHitPct}:${st.costUsd}:${st.selectedSpeedReason}`,
|
||||
createRow: () => {
|
||||
const stepNumText = h('span');
|
||||
const compIcon = createSvgIcon('bolt', { size: 11, className: 'text-muted' });
|
||||
const tdStep = h('td', {}, [stepNumText, compIcon]);
|
||||
|
||||
const tdModel = h('td');
|
||||
const speedMain = h('strong', {
|
||||
className: 'cell-value accent-speed',
|
||||
style: 'font-size: 11px;',
|
||||
});
|
||||
const speedReason = h('div', { className: 'text-muted', style: 'font-size: 9.5px;' });
|
||||
const tdSpeed = h('td', {}, [speedMain, speedReason]);
|
||||
|
||||
const tdTtft = h('td');
|
||||
const tdCtx = h('td');
|
||||
const tdCache = h('td', {
|
||||
className: 'cell-value accent-ok',
|
||||
style: 'font-size: 11px;',
|
||||
});
|
||||
const tdCost = h('td', { style: 'font-weight: 600;' });
|
||||
|
||||
const tr = h('tr', {}, [tdStep, tdModel, tdSpeed, tdTtft, tdCtx, tdCache, tdCost]);
|
||||
return {
|
||||
el: tr,
|
||||
refs: {
|
||||
stepNumText,
|
||||
compIcon,
|
||||
tdModel,
|
||||
speedMain,
|
||||
speedReason,
|
||||
tdTtft,
|
||||
tdCtx,
|
||||
tdCache,
|
||||
tdCost,
|
||||
},
|
||||
};
|
||||
},
|
||||
updateRow: (refs, st) => {
|
||||
patchText(refs.stepNumText, `#${Number(st.stepIndex)} `);
|
||||
patchAttr(refs.compIcon, 'hidden', !st.isCompactionStep);
|
||||
patchText(refs.tdModel, st.modelShort || '—');
|
||||
|
||||
patchText(refs.speedMain, formatMetric(st.tokPerSec, ' tok/s'));
|
||||
const reason = speedReasonText(st.selectedSpeedReason);
|
||||
patchText(refs.speedReason, reason);
|
||||
patchAttr(refs.speedReason, 'hidden', !reason);
|
||||
|
||||
patchText(refs.tdTtft, formatMetric(st.ttftSec, 's'));
|
||||
patchText(
|
||||
refs.tdCtx,
|
||||
`${formatTokens(st.contextTokens)} / +${Number(st.outputTokens || 0)}`
|
||||
);
|
||||
patchText(refs.tdCache, `${Number(st.cacheHitPct ?? 0)}%`);
|
||||
|
||||
const costVal = Number(st.costUsd || 0);
|
||||
patchText(refs.tdCost, formatUsd(costVal, { precise: true }));
|
||||
patchClasses(refs.tdCost, { 'accent-speed': costVal >= 0.15 });
|
||||
},
|
||||
});
|
||||
|
||||
patchKeyedList(modelsTbody, models, {
|
||||
keyFn: (m) => m.label || m.shortName,
|
||||
sigFn: (m) =>
|
||||
`${m.shortName}:${m.calls}:${m.avgTokPerSec}:${m.totalTokens}:${m.costUsd}:${m.speedSummary?.sampleCount}`,
|
||||
createRow: () => {
|
||||
const tdName = h('td', { style: 'font-weight: 600;' });
|
||||
const tdCalls = h('td');
|
||||
const speedMain = h('div');
|
||||
const speedSub = h('div', { className: 'text-muted', style: 'font-size: 9.5px;' });
|
||||
const tdSpeed = h('td', {}, [speedMain, speedSub]);
|
||||
const tdTokens = h('td');
|
||||
const tdCost = h('td', { style: 'font-weight: 600;' });
|
||||
const tr = h('tr', {}, [tdName, tdCalls, tdSpeed, tdTokens, tdCost]);
|
||||
return {
|
||||
el: tr,
|
||||
refs: { tdName, tdCalls, speedMain, speedSub, tdTokens, tdCost },
|
||||
};
|
||||
},
|
||||
updateRow: (refs, m) => {
|
||||
patchText(refs.tdName, m.shortName || m.label);
|
||||
patchText(refs.tdCalls, String(Number(m.calls || 0)));
|
||||
patchText(refs.speedMain, formatMetric(m.avgTokPerSec, ' tok/s'));
|
||||
patchText(refs.speedSub, `有效 ${sampleSummary(m.speedSummary)}`);
|
||||
patchText(refs.tdTokens, formatTokens(m.totalTokens || 0));
|
||||
patchText(refs.tdCost, formatUsd(m.costUsd || 0, { estimated: m.isEstimatedPrice }));
|
||||
},
|
||||
});
|
||||
|
||||
stepsScroll.refresh();
|
||||
modelsScroll.refresh();
|
||||
}
|
||||
|
||||
const unsubTelemetry = telemetryStore.subscribe(
|
||||
(st) => ({
|
||||
cascadeId: st.telemetry?.activeConversation?.cascadeId,
|
||||
recentSteps: st.telemetry?.activeConversation?.recentSteps,
|
||||
modelBreakdown: st.telemetry?.modelBreakdown,
|
||||
rangeLabel: st.telemetry?.consumption?.selectedRange?.label || '全部时间',
|
||||
}),
|
||||
(slice) => {
|
||||
latestSlice = slice;
|
||||
if (uiStore.getState().activeView !== 'steps') {
|
||||
isDirty = true;
|
||||
return;
|
||||
}
|
||||
isDirty = false;
|
||||
renderStepsData(slice);
|
||||
}
|
||||
);
|
||||
|
||||
const unsubView = uiStore.subscribe(
|
||||
(st) => st.activeView,
|
||||
(activeView) => {
|
||||
if (activeView === 'steps' && isDirty) {
|
||||
isDirty = false;
|
||||
if (latestSlice) {
|
||||
renderStepsData(latestSlice);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onCleanup(() => {
|
||||
unsubUi();
|
||||
unsubTelemetry();
|
||||
unsubView();
|
||||
subTabSwitch.destroy();
|
||||
stepsScroll.destroy();
|
||||
modelsScroll.destroy();
|
||||
});
|
||||
|
||||
return {
|
||||
el: rootEl,
|
||||
refs: { stepsTbody, modelsTbody, subTabSwitch, stepsScroll, modelsScroll },
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user