feat(panel): add per-pool cycle filter and harden weekly reset anchors

- Add a compact inline quota-pool selector on ConsumptionView when Cycle is active, pre-bundling per-pool cycle slices for instant switching and scoping range labels in exports
- Classify >6h clientModelConfigs resetTime fallbacks as weekly anchors and advance usageRevision when official reset windows arrive or shift
- Deduplicate same-day and same-month date span badges (e.g. Nov 24, Nov 24 ~ 25)
This commit is contained in:
fish
2026-11-24 19:30:53 +09:00
parent 1692599fd8
commit 02237692f7
18 changed files with 1346 additions and 152 deletions
+173 -13
View File
@@ -50,6 +50,7 @@ import { ActionMenu } from '../components/ui/ActionMenu.js';
import {
getDefaultCtxInspectorAgentId,
prefetchConsumptionPresets,
selectConsumptionCyclePool,
selectConsumptionTimeRange,
selectConversation,
telemetryStore,
@@ -61,6 +62,7 @@ import {
} from '../components/charts/TrendAreaChart.js';
import { CustomDateTimePicker } from '../components/ui/CustomDateTimePicker.js';
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
import { CustomSelect } from '../components/ui/CustomSelect.js';
import { createFourSegmentBar } from '../components/ui/FourSegmentBar.js';
import { createConsumptionBreakdownContent } from '../components/ui/ConsumptionTooltipContent.js';
import { SegmentedControl } from '../components/ui/SegmentedControl.js';
@@ -95,6 +97,86 @@ function ceilToEndOfMinuteMs(ms) {
return d.getTime();
}
function formatCyclePoolShortLabel(poolKey, poolLabel) {
if (poolKey === 'Argon') return 'Argon';
if (poolKey === 'Carbon') return 'Carbon';
if (poolKey === 'Claude & GPT') return 'Claude/GPT';
return poolLabel || poolKey;
}
function buildCyclePoolSelectOptions(pools, isCustomWeeklyMode = false) {
const list = Array.isArray(pools) ? pools : [];
let sumCycleCost = 0;
let hasAnyCycleCost = false;
for (let i = 0; i < list.length; i++) {
const c = Number(list[i]?.cycleWeekly?.costUsd);
if (Number.isFinite(c) && c >= 0 && list[i]?.cycleWeekly) {
sumCycleCost += c;
hasAnyCycleCost = true;
}
}
const allLabel = t('cons.cyclePoolAll');
const opts = [
{
value: 'all',
label: allLabel,
shortLabel: t('cons.cyclePoolAllShort'),
meta: !isCustomWeeklyMode && hasAnyCycleCost ? formatUsd(sumCycleCost) : '',
title: allLabel,
},
];
for (let i = 0; i < list.length; i++) {
const p = list[i];
const key = String(p?.poolKey || p?.family || '').trim();
if (!key || key === 'Unknown') continue;
const label = String(p?.poolLabel || key).trim();
const shortLabel = formatCyclePoolShortLabel(key, label);
const metaParts = [];
if (
!isCustomWeeklyMode &&
p?.weeklyRemainingPct != null &&
Number.isFinite(Number(p.weeklyRemainingPct))
) {
metaParts.push(
t('cons.cyclePoolRemMeta', {
pct: formatPctNumber(p.weeklyRemainingPct, { withSymbol: true }),
})
);
}
if (!isCustomWeeklyMode && p?.cycleWeekly && Number.isFinite(Number(p.cycleWeekly.costUsd))) {
metaParts.push(formatUsd(p.cycleWeekly.costUsd));
}
const meta = metaParts.join(' · ');
opts.push({
value: key,
label,
shortLabel,
meta,
title: meta ? `${label} (${meta})` : label,
});
}
return opts;
}
function formatCycleMinuteSpanTip(startMs, endMs, isFallbackWeek = false) {
const s = Number(startMs);
const e = Number(endMs);
if (!(s > 0 && e > 0 && Number.isFinite(s) && Number.isFinite(e))) return null;
const sd = new Date(s);
const ed = new Date(e);
const pad2 = (n) => String(n).padStart(2, '0');
const sTime = `${pad2(sd.getHours())}:${pad2(sd.getMinutes())}`;
const eTime = `${pad2(ed.getHours())}:${pad2(ed.getMinutes())}`;
const sameDay =
sd.getFullYear() === ed.getFullYear() &&
sd.getMonth() === ed.getMonth() &&
sd.getDate() === ed.getDate();
const sDate = `${sd.getMonth() + 1}/${pad2(sd.getDate())}`;
const eDate = `${ed.getMonth() + 1}/${pad2(ed.getDate())}`;
const base = sameDay ? `${sDate} ${sTime} ~ ${eTime}` : `${sDate} ${sTime} ~ ${eDate} ${eTime}`;
return isFallbackWeek ? `${base} · ${t('cons.cycleFallbackWeekTip')}` : base;
}
export const ConsumptionView = defineComponent({
name: 'ConsumptionView',
setup({ onCleanup }) {
@@ -200,6 +282,16 @@ export const ConsumptionView = defineComponent({
// --- Section 1: 用量概览矩阵 (上层 3 列核心总量 + 下层 3 列新输入/缓存读取/输出拆分 + 底部 4 段比例条) ---
const dateSpanBadge = h('span', { className: 'cons-badge text-mono', text: '-- ~ --' });
const cyclePoolSelect = CustomSelect({
className: 'cons-cycle-pool-select',
modelValue: telemetryStore.getState().selectedCyclePool || 'all',
options: buildCyclePoolSelectOptions([]),
onUpdateModelValue: (nextPool) => {
selectConsumptionCyclePool(nextPool || 'all');
},
});
patchAttr(cyclePoolSelect.el, 'hidden', true);
patchAttr(cyclePoolSelect.refs.triggerBtn, 'aria-label', t('cons.cyclePoolAria'));
const heroTotalTokens = h('strong', { className: 'cons-hero-num text-mono', text: '0' });
const heroTotalCalls = h('span', { className: 'text-muted text-mono', style: 'font-size: var(--fs-md);', text: t('cons.callsCount', { calls: 0 }) });
const heroCostUsd = h('strong', { className: 'cons-hero-cost text-mono', text: '$0.00' });
@@ -337,8 +429,9 @@ export const ConsumptionView = defineComponent({
const overviewPanel = h('section', { className: 'panel' }, [
h('div', { className: 'panel-header cons-overview-head' }, [
h('span', { className: 'panel-title' }, [
h('span', { className: 'panel-title cons-overview-title' }, [
dateSpanBadge,
cyclePoolSelect.el,
]),
h('div', { className: 'cons-overview-controls' }, [
timeFilterSwitch.el,
@@ -1791,7 +1884,7 @@ export const ConsumptionView = defineComponent({
const cons = slice.consumption || {};
const rangeInfo = cons.selectedRange || {};
// 始终在 0ms 同步顶部时间段滑块与自定义日期条显隐,给予即刻交互反馈
// 始终在 0ms 同步顶部时间段滑块、周期池选择器及自定义日期条显隐,给予即刻交互反馈
timeFilterSwitch.setValue(slice.range);
patchAttr(customRangeBar, 'hidden', slice.range !== 'custom');
if (!hasUncommittedCustomDraft) {
@@ -1801,17 +1894,45 @@ export const ConsumptionView = defineComponent({
endPicker.setValue(draftEndMs);
}
const isCustomWeeklyMode =
slice.weeklyLimitMode === 'custom_tokens' || slice.weeklyLimitMode === 'custom_cost';
const cyclePoolOptions =
slice.range === 'cycle'
? buildCyclePoolSelectOptions(slice.quotaPools, isCustomWeeklyMode)
: [];
const activePoolFilter = slice.range === 'cycle' ? slice.cyclePool || 'all' : 'all';
const showCyclePoolSelect = slice.range === 'cycle' && cyclePoolOptions.length > 2;
if (!showCyclePoolSelect) {
cyclePoolSelect.close?.();
patchAttr(cyclePoolSelect.el, 'hidden', true);
} else {
cyclePoolSelect.setProps({
modelValue: activePoolFilter,
options: cyclePoolOptions,
});
patchAttr(cyclePoolSelect.el, 'hidden', false);
}
// 极少数缓存未命中时(如自定义新区间或进页瞬间抢点),跳过用旧趋势/模型跑无效半更新重绘,待几毫秒后单帧原子绘制
if (rangeInfo.key && slice.range && rangeInfo.key !== slice.range) {
const payloadPool = rangeInfo.key === 'cycle' ? rangeInfo.pool || 'all' : 'all';
if (
(rangeInfo.key && slice.range && rangeInfo.key !== slice.range) ||
(slice.range === 'cycle' && rangeInfo.pool && payloadPool !== activePoolFilter)
) {
return;
}
const preset =
slice.range !== 'custom' && cons.presets?.[slice.range]
slice.range !== 'custom' &&
!(slice.range === 'cycle' && activePoolFilter !== 'all') &&
cons.presets?.[slice.range]
? cons.presets[slice.range]
: null;
const acct = cons.account || preset?.account || {};
const dateSpan = formatDateSpanBadge(rangeInfo.startMs, rangeInfo.endMs);
const cycleOptionsSig = showCyclePoolSelect
? cyclePoolOptions.map((o) => `${o.value}:${o.label}:${o.meta || ''}`).join('|')
: '';
const now = new Date();
const currentMonthIdx = now.getMonth();
const monthlyYear = cons.monthlyYear || now.getFullYear();
@@ -1819,6 +1940,9 @@ export const ConsumptionView = defineComponent({
const renderTuple = [
locale,
slice.range,
activePoolFilter,
cycleOptionsSig,
Boolean(rangeInfo.isFallbackWeek),
slice.customStartMs,
slice.customEndMs,
slice.modelDisplayMode,
@@ -1839,13 +1963,36 @@ export const ConsumptionView = defineComponent({
cons.monthlySeries,
];
if (isSameRenderTuple(lastRenderedTuple, renderTuple)) return;
drawConsumptionData(slice, { cons, preset, acct, rangeInfo, dateSpan, currentMonthIdx, monthlyYear });
drawConsumptionData(slice, {
cons,
preset,
acct,
rangeInfo,
activePoolFilter,
dateSpan,
currentMonthIdx,
monthlyYear,
});
lastRenderedTuple = renderTuple;
}
function drawConsumptionData(slice, { cons, preset, acct, rangeInfo, dateSpan, currentMonthIdx, monthlyYear }) {
// 1. 同步用量概览矩阵与顶部 4 段比例条
function drawConsumptionData(
slice,
{ cons, preset, acct, rangeInfo, activePoolFilter, dateSpan, currentMonthIdx, monthlyYear }
) {
// 1. 同步用量概览矩阵及顶部 4 段比例条
patchText(dateSpanBadge, dateSpan);
patchAttr(
dateSpanBadge,
'title',
slice.range === 'cycle'
? formatCycleMinuteSpanTip(
rangeInfo.startMs,
rangeInfo.endMs,
Boolean(rangeInfo.isFallbackWeek)
)
: null
);
const totalTokens = Number(acct.totalTokens || 0);
const inputTokens = Number(acct.inputTokens || 0);
const cacheTokens = Number(acct.cacheReadTokens || 0);
@@ -2036,11 +2183,18 @@ export const ConsumptionView = defineComponent({
...allTrendMergedModels,
]);
// 2. 同步历史趋势交互式 SVG 面积图 / 类 GitHub 每日热力图(>90天)与悬停分模型浮层
const rangeBadgeText = isEnglishLocale()
? getConsumptionTimeRangeOptions().find((o) => o.value === slice.range)?.label ||
t('cons.allTime')
: preset?.label || rangeInfo.label || t('cons.allTime');
// 2. 同步历史趋势交互式 SVG 面积图 / 类 GitHub 每日热力图(>90天)及悬停分模型浮层
const rangeBadgeText =
slice.range === 'cycle'
? `${rangeInfo.isFallbackWeek || slice.weeklyLimitMode === 'custom_tokens' || slice.weeklyLimitMode === 'custom_cost' ? t('cons.cycleFallbackWeek') : t('cons.currentCycle')}${
activePoolFilter && activePoolFilter !== 'all'
? ` · ${rangeInfo.poolLabel || activePoolFilter}`
: ''
}`
: isEnglishLocale()
? getConsumptionTimeRangeOptions().find((o) => o.value === slice.range)?.label ||
t('cons.allTime')
: preset?.label || rangeInfo.label || t('cons.allTime');
patchText(trendRangeBadge, rangeBadgeText);
const firstTrendSlot = rawTrendSeries[0] || null;
const isMinuteTrend = firstTrendSlot?.granularity === 'minute';
@@ -2200,7 +2354,7 @@ export const ConsumptionView = defineComponent({
updateRow: (refs, s) => updateSourceBreakdownRow(refs, s, sourcesTotalTok, modelColorMap),
});
const nextRangeSig = `${slice.range || ''}:${slice.customStartMs || 0}:${slice.customEndMs || 0}`;
const nextRangeSig = `${slice.range || ''}:${activePoolFilter || 'all'}:${slice.customStartMs || 0}:${slice.customEndMs || 0}`;
const nextRankingKey = showWorkspacesTab
? 'workspaces'
: showSessionsTab
@@ -2336,8 +2490,11 @@ export const ConsumptionView = defineComponent({
const unsub = telemetryStore.subscribe(
(st) => ({
range: st.selectedTimeRange,
cyclePool: st.selectedCyclePool || 'all',
customStartMs: st.customStartMs,
customEndMs: st.customEndMs,
quotaPools: st.telemetry?.quotas?.pools,
weeklyLimitMode: st.telemetry?.settings?.weeklyLimitMode,
consumption: st.telemetry?.consumption,
modelBreakdown: st.telemetry?.modelBreakdown,
modelDisplayMode: normalizeModelDisplayMode(
@@ -2391,6 +2548,7 @@ export const ConsumptionView = defineComponent({
ariaLabel: t('cons.rangeAria'),
options: getConsumptionTimeRangeOptions(),
});
patchAttr(cyclePoolSelect.refs.triggerBtn, 'aria-label', t('cons.cyclePoolAria'));
patchText(applyCustomBtnLabel, t('cons.applyFilter'));
patchText(rangeToSpan, t('cons.rangeTo'));
patchText(totalTokensLabel, t('cons.totalTokens'));
@@ -2448,6 +2606,7 @@ export const ConsumptionView = defineComponent({
unsubView();
unsubI18n();
consExportMenu.destroy();
cyclePoolSelect.destroy();
trendChart.destroy?.();
rankingTabSwitch.destroy();
modelsSortSwitch.destroy();
@@ -2462,6 +2621,7 @@ export const ConsumptionView = defineComponent({
el: rootEl,
refs: {
timeFilterSwitch,
cyclePoolSelect,
startPicker,
endPicker,
viewScrollbar,