mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): dual-mount topbar capsule, live multi-session HUD, and customizable topbar metrics (v1.4.3)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* @fileoverview View 2: ConsumptionView (全景消耗统计视图).
|
||||
* 采用 5 段式分析布局展示指定时间窗口内的全量 Token 与费用消耗:
|
||||
* 1. 用量概览:支持预设时间段与自定义区间筛选,通过 3+2 组合矩阵展示总 Token/调用次数、
|
||||
* USD/CNY 预估费用、缓存命中率与命中量、输入/输出细分占比,以及底部 4 段比例条 (`FourSegmentBar`)。
|
||||
* 2. 历史趋势:基于 `TrendAreaChart` 渲染纯 SVG 三次贝塞尔平滑曲线面积图、峰值气泡与首/中/末三时间锚点。
|
||||
* 1. 用量概览:支持预设时间段与自定义区间筛选,通过 3+3 组合矩阵展示总 Token/调用次数、
|
||||
* USD/CNY 预估费用、缓存命中率与命中量、新输入/缓存读取(含节省费用)/输出细分占比,以及底部 4 段比例条 (`FourSegmentBar`)。
|
||||
* 2. 历史趋势:基于 `TrendAreaChart` 渲染纯 SVG 三次贝塞尔平滑曲线面积图、峰值气泡、对齐多刻度时间轴与悬停详情浮层。
|
||||
* 3. 热门模型:按 Token 总量降序展示各模型的消耗占比徽章、4 段构成条及输入/缓存/输出/思考/调用明细。
|
||||
* 4. 数据来源:按调用来源聚合展示 Token 构成、占比与费用明细。
|
||||
* 5. 按月细分:12 个月垂直 4 段堆叠柱状图,直观对比全年各月费用、Token 总量与缓存/思考结构。
|
||||
@@ -48,27 +48,45 @@ export const ConsumptionView = defineComponent({
|
||||
name: 'ConsumptionView',
|
||||
setup({ onCleanup }) {
|
||||
// --- 时间筛选栏:快速时间段分段控制器与自定义起止时间选择条 ---
|
||||
let draftStartMs = telemetryStore.getState().customStartMs;
|
||||
let draftEndMs = telemetryStore.getState().customEndMs;
|
||||
let hasUncommittedCustomDraft = false;
|
||||
|
||||
const timeFilterSwitch = SegmentedControl({
|
||||
ariaLabel: '消耗统计时间范围',
|
||||
modelValue: telemetryStore.getState().selectedTimeRange,
|
||||
options: TIME_RANGE_OPTIONS,
|
||||
onUpdateModelValue: (nextRange) => {
|
||||
if (nextRange === 'custom') {
|
||||
const st = telemetryStore.getState();
|
||||
draftStartMs = st.customStartMs;
|
||||
draftEndMs = st.customEndMs;
|
||||
hasUncommittedCustomDraft = false;
|
||||
startPicker.setValue(draftStartMs);
|
||||
endPicker.setValue(draftEndMs);
|
||||
} else {
|
||||
hasUncommittedCustomDraft = false;
|
||||
}
|
||||
telemetryStore.setState({ selectedTimeRange: nextRange });
|
||||
fetchTelemetry({ force: false });
|
||||
},
|
||||
});
|
||||
|
||||
const startPicker = CustomDateTimePicker({
|
||||
modelValue: telemetryStore.getState().customStartMs,
|
||||
modelValue: draftStartMs,
|
||||
onUpdateModelValue: (ms) => {
|
||||
telemetryStore.setState({ customStartMs: ms });
|
||||
draftStartMs = ms;
|
||||
hasUncommittedCustomDraft = true;
|
||||
startPicker.setValue(ms);
|
||||
},
|
||||
});
|
||||
|
||||
const endPicker = CustomDateTimePicker({
|
||||
modelValue: telemetryStore.getState().customEndMs,
|
||||
modelValue: draftEndMs,
|
||||
onUpdateModelValue: (ms) => {
|
||||
telemetryStore.setState({ customEndMs: ms });
|
||||
draftEndMs = ms;
|
||||
hasUncommittedCustomDraft = true;
|
||||
endPicker.setValue(ms);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -79,20 +97,20 @@ export const ConsumptionView = defineComponent({
|
||||
className: 'btn-primary',
|
||||
style: 'height: 26px; padding: 0 10px;',
|
||||
onClick: () => {
|
||||
const st = telemetryStore.getState();
|
||||
const sMs = Number(st.customStartMs || 0);
|
||||
const eMs = Number(st.customEndMs || 0);
|
||||
if (sMs > 0 && eMs > 0 && sMs > eMs) {
|
||||
startPicker.setValue(eMs);
|
||||
endPicker.setValue(sMs);
|
||||
telemetryStore.setState({
|
||||
selectedTimeRange: 'custom',
|
||||
customStartMs: eMs,
|
||||
customEndMs: sMs,
|
||||
});
|
||||
} else {
|
||||
telemetryStore.setState({ selectedTimeRange: 'custom' });
|
||||
}
|
||||
const sMs = Number(draftStartMs || 0);
|
||||
const eMs = Number(draftEndMs || 0);
|
||||
const minMs = sMs > 0 && eMs > 0 ? Math.min(sMs, eMs) : sMs;
|
||||
const maxMs = sMs > 0 && eMs > 0 ? Math.max(sMs, eMs) : eMs;
|
||||
draftStartMs = minMs;
|
||||
draftEndMs = maxMs;
|
||||
hasUncommittedCustomDraft = false;
|
||||
startPicker.setValue(minMs);
|
||||
endPicker.setValue(maxMs);
|
||||
telemetryStore.setState({
|
||||
selectedTimeRange: 'custom',
|
||||
customStartMs: minMs,
|
||||
customEndMs: maxMs,
|
||||
});
|
||||
fetchTelemetry({ force: true });
|
||||
},
|
||||
},
|
||||
@@ -114,7 +132,7 @@ export const ConsumptionView = defineComponent({
|
||||
]
|
||||
);
|
||||
|
||||
// --- Section 1: 用量概览矩阵 (上层 3 列核心总量 + 下层 2 列输入/输出拆分 + 底部 4 段比例条) ---
|
||||
// --- Section 1: 用量概览矩阵 (上层 3 列核心总量 + 下层 3 列新输入/缓存读取/输出拆分 + 底部 4 段比例条) ---
|
||||
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 次' });
|
||||
@@ -126,7 +144,11 @@ export const ConsumptionView = defineComponent({
|
||||
|
||||
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 inputSubText = h('span', { className: 'text-muted text-mono', style: 'font-size: 11px;', text: '未命中缓存输入' });
|
||||
|
||||
const cacheSharePct = h('span', { className: 'text-mono', style: 'color: var(--ctx-cached); font-weight: 600; font-size: 11.5px;', text: '0%' });
|
||||
const cacheMainTokens = h('strong', { className: 'cons-mid-num text-mono', text: '0' });
|
||||
const cacheSubText = h('span', { className: 'text-muted text-mono', style: 'font-size: 11px;', text: '节省 $0.00' });
|
||||
|
||||
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' });
|
||||
@@ -161,27 +183,38 @@ export const ConsumptionView = defineComponent({
|
||||
h('div', { className: 'cons-baseline' }, [cacheHitPctEl, cacheTokensEl]),
|
||||
]),
|
||||
]),
|
||||
h('div', { className: 'cons-split-2 cons-matrix-bottom' }, [
|
||||
h('div', { className: 'cons-split-3 cons-matrix-bottom' }, [
|
||||
h('div', { className: 'cons-col' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('div', { className: 'cons-sub-head' }, [
|
||||
h('span', { className: 'legend-left cons-sub-label' }, [
|
||||
h('span', { className: 'dot-swatch seg-input' }),
|
||||
h('span', { style: 'color: var(--text-primary); font-weight: 600; font-size: 11.5px;', text: '输入用量' }),
|
||||
inputMainTokens,
|
||||
h('span', { text: '新输入' }),
|
||||
]),
|
||||
inputSharePct,
|
||||
]),
|
||||
inputMainTokens,
|
||||
inputSubText,
|
||||
]),
|
||||
h('div', { className: 'cons-col is-bordered-col' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
h('div', { className: 'cons-sub-head' }, [
|
||||
h('span', { className: 'legend-left cons-sub-label' }, [
|
||||
h('span', { className: 'dot-swatch seg-cached' }),
|
||||
h('span', { text: '缓存读取' }),
|
||||
]),
|
||||
cacheSharePct,
|
||||
]),
|
||||
cacheMainTokens,
|
||||
cacheSubText,
|
||||
]),
|
||||
h('div', { className: 'cons-col is-bordered-col' }, [
|
||||
h('div', { className: 'cons-sub-head' }, [
|
||||
h('span', { className: 'legend-left cons-sub-label' }, [
|
||||
h('span', { className: 'dot-swatch seg-output' }),
|
||||
h('span', { style: 'color: var(--text-primary); font-weight: 600; font-size: 11.5px;', text: '输出用量' }),
|
||||
outputMainTokens,
|
||||
h('span', { text: '输出用量' }),
|
||||
]),
|
||||
outputSharePct,
|
||||
]),
|
||||
outputMainTokens,
|
||||
outputSubText,
|
||||
]),
|
||||
]),
|
||||
@@ -416,8 +449,12 @@ export const ConsumptionView = defineComponent({
|
||||
if (!slice) return;
|
||||
timeFilterSwitch.setValue(slice.range);
|
||||
patchAttr(customRangeBar, 'hidden', slice.range !== 'custom');
|
||||
startPicker.setValue(slice.customStartMs);
|
||||
endPicker.setValue(slice.customEndMs);
|
||||
if (!hasUncommittedCustomDraft) {
|
||||
draftStartMs = slice.customStartMs;
|
||||
draftEndMs = slice.customEndMs;
|
||||
startPicker.setValue(draftStartMs);
|
||||
endPicker.setValue(draftEndMs);
|
||||
}
|
||||
|
||||
const cons = slice.consumption || {};
|
||||
const preset =
|
||||
@@ -436,6 +473,7 @@ export const ConsumptionView = defineComponent({
|
||||
const responseTokens = Number(acct.responseTokens || 0);
|
||||
const thinkingTokens = Number(acct.thinkingTokens || 0);
|
||||
const costUsd = Number(acct.costUsd || 0);
|
||||
const savedCostUsd = Number(acct.savedCostUsd || 0);
|
||||
|
||||
patchText(heroTotalTokens, formatTokensPrecise(totalTokens));
|
||||
patchText(heroTotalCalls, `${acct.calls || 0} 次`);
|
||||
@@ -445,13 +483,37 @@ export const ConsumptionView = defineComponent({
|
||||
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;
|
||||
let inPct = 0;
|
||||
let cachePct = 0;
|
||||
let outPct = 0;
|
||||
if (totalTokens > 0) {
|
||||
const rawTenths = [
|
||||
(inputTokens / totalTokens) * 1000,
|
||||
(cacheTokens / totalTokens) * 1000,
|
||||
(outputTokens / totalTokens) * 1000,
|
||||
];
|
||||
const floored = rawTenths.map((v) => Math.max(0, Math.floor(v)));
|
||||
const rem = Math.max(0, 1000 - (floored[0] + floored[1] + floored[2]));
|
||||
const order = [0, 1, 2].sort(
|
||||
(a, b) => rawTenths[b] - floored[b] - (rawTenths[a] - floored[a])
|
||||
);
|
||||
for (let k = 0; k < rem && k < 3; k++) {
|
||||
floored[order[k]] += 1;
|
||||
}
|
||||
inPct = +(floored[0] / 10).toFixed(1);
|
||||
cachePct = +(floored[1] / 10).toFixed(1);
|
||||
outPct = +(floored[2] / 10).toFixed(1);
|
||||
}
|
||||
|
||||
patchText(inputSharePct, `${inPct}%`);
|
||||
patchText(inputMainTokens, formatTokensPrecise(inputTokens));
|
||||
patchText(inputSubText, '未命中缓存输入');
|
||||
|
||||
patchText(cacheSharePct, `${cachePct}%`);
|
||||
patchText(cacheMainTokens, formatTokensPrecise(cacheTokens));
|
||||
patchText(
|
||||
inputSubText,
|
||||
`新输入 ${formatTokensPrecise(inputTokens)} · 缓存 ${formatTokensPrecise(cacheTokens)}`
|
||||
cacheSubText,
|
||||
`节省 ${formatUsd(savedCostUsd, { precise: savedCostUsd > 0 && savedCostUsd < 0.01 })}`
|
||||
);
|
||||
|
||||
patchText(outputSharePct, `${outPct}%`);
|
||||
@@ -480,7 +542,8 @@ export const ConsumptionView = defineComponent({
|
||||
);
|
||||
trendChart.update(trendSeries);
|
||||
|
||||
// 3. 同步热门模型列表(按总 Token 数降序排列并执行键值增量对账)
|
||||
// 3. 同步热门模型列表(按总 Token 数降序排列并执行键值增量对账,遵循模型名称显示格式设置)
|
||||
const showUpstream = Boolean(slice.showUpstreamModel);
|
||||
const models = (slice.modelBreakdown || [])
|
||||
.slice()
|
||||
.sort((a, b) => (b.totalTokens || 0) - (a.totalTokens || 0));
|
||||
@@ -489,9 +552,17 @@ export const ConsumptionView = defineComponent({
|
||||
patchKeyedList(modelsListEl, models, {
|
||||
keyFn: (m) => m.label || m.shortName,
|
||||
sigFn: (m) =>
|
||||
`${m.label}:${m.totalTokens}:${m.costUsd}:${m.unpricedCalls}:${m.calls}:${modelsTotalTok}`,
|
||||
`${showUpstream}:${m.label}:${m.upstreamName || ''}:${m.totalTokens}:${m.costUsd}:${m.unpricedCalls}:${m.calls}:${modelsTotalTok}`,
|
||||
createRow: createBreakdownItemRow,
|
||||
updateRow: (refs, m) => updateBreakdownItemRow(refs, m, modelsTotalTok, true),
|
||||
updateRow: (refs, m) =>
|
||||
updateBreakdownItemRow(
|
||||
refs,
|
||||
showUpstream
|
||||
? { ...m, label: m.upstreamName || m.label || m.shortName }
|
||||
: m,
|
||||
modelsTotalTok,
|
||||
true
|
||||
),
|
||||
});
|
||||
|
||||
// 4. 同步数据来源列表
|
||||
@@ -529,8 +600,14 @@ export const ConsumptionView = defineComponent({
|
||||
patchText(col.tokText, '');
|
||||
} else {
|
||||
const cVal = Number(m.costUsd || 0);
|
||||
patchText(col.costText, m.unpricedCalls > 0 ? formatUsd(cVal, { unpricedCalls: m.unpricedCalls })
|
||||
: cVal >= 10 ? `$${Math.round(cVal)}` : `$${cVal.toFixed(2)}`);
|
||||
patchText(
|
||||
col.costText,
|
||||
m.unpricedCalls > 0
|
||||
? formatUsd(cVal, { unpricedCalls: m.unpricedCalls, compactPending: true })
|
||||
: cVal >= 10
|
||||
? `$${Math.round(cVal)}`
|
||||
: `$${cVal.toFixed(2)}`
|
||||
);
|
||||
patchText(col.tokText, formatTokensPrecise(mTot));
|
||||
|
||||
const totalHeightPct = Math.max(8, Math.min(100, (mTot / maxMonthTokens) * 100));
|
||||
@@ -558,6 +635,7 @@ export const ConsumptionView = defineComponent({
|
||||
customEndMs: st.customEndMs,
|
||||
consumption: st.telemetry?.consumption,
|
||||
modelBreakdown: st.telemetry?.modelBreakdown,
|
||||
showUpstreamModel: Boolean(st.telemetry?.settings?.showUpstreamModel),
|
||||
}),
|
||||
(slice) => {
|
||||
latestSlice = slice;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* @fileoverview View 1: LiveOverviewView (实时监控视图).
|
||||
* 负责展示当前活跃会话的核心实时遥测指标:
|
||||
* 1. 4 格实时测速矩阵:实时吞吐 (TPS)、首 Token 延迟 (TTFT)、会话有效加权均速与本步费用/缓存命中率;
|
||||
* 2. 6 通道上下文窗口构成:自动锚定当前模型的上下文压缩基线 (`compactionLimitTokens`),
|
||||
* 通过 6 段进度条与双列图例展示消息、系统工具、MCP 工具、Skill、系统提示词与用户规则的 Token 占用;
|
||||
* 3. 动态多配额池监控卡片:支持 Gemini、Pro 订阅专属独立 Argon 周配额池、Claude & GPT 等动态配额池,
|
||||
* 2. 10 通道上下文窗口构成:自动锚定当前模型的上下文压缩基线 (`compactionLimitTokens`),
|
||||
* 通过 10 段进度条与双列图例展示模型回复、工具结果、用户消息、子代理通知、压缩摘要及系统提示词/工具/MCP/Skill/规则的 Token 占用;
|
||||
* 3. 动态多配额池监控卡片:支持 Gemini、Pro 订阅专属独立 Argon/Carbon 周配额池、Claude & GPT 等动态配额池,
|
||||
* 自动适配 5h/每周双窗口或单窗口模式,并展示本机周累计消耗与 AI 积分脚标。
|
||||
*/
|
||||
|
||||
@@ -52,6 +52,239 @@ function estPillWidth(text) {
|
||||
return Math.ceil(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* 10 通道上下文窗口构成定义(供实时监控主视图与主窗口顶栏悬停概览卡共享)。
|
||||
*/
|
||||
export const CTX_CHANNEL_DEFS = [
|
||||
{
|
||||
key: 'assistant',
|
||||
label: '模型回复',
|
||||
segClass: 'seg-assistant',
|
||||
title: '模型推理思考、回复正文与工具调用入参',
|
||||
getValue: (c) => Number(c.assistantTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'toolResults',
|
||||
label: '工具结果',
|
||||
segClass: 'seg-tool-results',
|
||||
title: '文件读取、终端输出与工具执行返回内容',
|
||||
getValue: (c) => Number(c.toolResultsTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'userInput',
|
||||
label: '用户消息',
|
||||
segClass: 'seg-user-input',
|
||||
title: '用户提问文本与上传附件',
|
||||
getValue: (c) => Number(c.userInputTokens ?? c.messagesTokens ?? 0),
|
||||
},
|
||||
{
|
||||
key: 'subagent',
|
||||
label: '子代理通知',
|
||||
segClass: 'seg-subagent-msg',
|
||||
title: '子代理完成汇报与后台任务系统通知',
|
||||
getValue: (c) => Number(c.subagentTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'checkpoint',
|
||||
label: '压缩摘要',
|
||||
segClass: 'seg-checkpoint',
|
||||
title: '自动上下文压缩生成的历史摘要检查点',
|
||||
getValue: (c) => Number(c.checkpointTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'systemPrompt',
|
||||
label: '系统提示词',
|
||||
segClass: 'seg-system-prompt',
|
||||
title: '核心身份、终端沙箱、制品与环境提示词',
|
||||
getValue: (c) => Number(c.systemPromptTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'systemTools',
|
||||
label: '系统工具',
|
||||
segClass: 'seg-system-tools',
|
||||
title: '内置系统工具 Schema 定义',
|
||||
getValue: (c) => Number(c.systemToolsTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'mcpTools',
|
||||
label: 'MCP 工具',
|
||||
segClass: 'seg-mcp-tools',
|
||||
title: 'MCP 外部服务工具与资源定义',
|
||||
getValue: (c) => Number(c.mcpToolsTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'skills',
|
||||
label: 'Skill',
|
||||
segClass: 'seg-skills',
|
||||
title: '已挂载的 Skills 技能索引与说明',
|
||||
getValue: (c) => Number(c.skillsTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'userRules',
|
||||
label: '用户规则',
|
||||
segClass: 'seg-user-rules',
|
||||
title: '全局与工作区自定义规则 (user_rules)',
|
||||
getValue: (c) => Number(c.userRulesTokens || 0),
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* 归一化动态配额池列表;在官方配额尚未返回时回退预占 Gemini 与 Claude & GPT 两个标准池槽位。
|
||||
*
|
||||
* @param {object|null|undefined} quotas
|
||||
* @param {number} minuteTick
|
||||
* @param {{ isPending?: boolean }} [options]
|
||||
* @returns {Array<object>}
|
||||
*/
|
||||
export function buildQuotaPoolItems(quotas, minuteTick = 0, { isPending = false } = {}) {
|
||||
const safeQuotas = quotas || {};
|
||||
const activePool = safeQuotas.activePool || {};
|
||||
const rawPools =
|
||||
Array.isArray(safeQuotas.pools) && safeQuotas.pools.length > 0
|
||||
? safeQuotas.pools
|
||||
: [
|
||||
{ poolKey: 'Gemini', poolLabel: 'Gemini', family: 'Gemini' },
|
||||
{ poolKey: 'Claude & GPT', poolLabel: 'Claude & GPT', family: 'Claude & GPT' },
|
||||
];
|
||||
const weekly = safeQuotas.weekly || {};
|
||||
const poolItems = rawPools.map((p) => {
|
||||
const key = p.poolKey || p.family || p.poolLabel || 'Other';
|
||||
const poolLabel = p.poolLabel || p.family || key;
|
||||
const isActivePool =
|
||||
Boolean(activePool.family) &&
|
||||
(activePool.poolKey === key ||
|
||||
activePool.family === p.family ||
|
||||
(key === 'Claude & GPT' && ['Claude', 'GPT'].includes(activePool.family)));
|
||||
return {
|
||||
key,
|
||||
poolLabel,
|
||||
poolData: p,
|
||||
fallbackWeekly: weekly,
|
||||
isActivePool,
|
||||
minuteTick,
|
||||
isPending,
|
||||
};
|
||||
});
|
||||
if (
|
||||
weekly?.isOfficial === false &&
|
||||
poolItems.length > 0 &&
|
||||
!poolItems.some((item) => item.isActivePool)
|
||||
) {
|
||||
poolItems[0].isActivePool = true;
|
||||
}
|
||||
return poolItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建单个配额池的 DOM 行结构,内含 5h 限额与每周限额两个可独立显隐的子窗口进度条。
|
||||
*/
|
||||
export function createPoolQuotaRow() {
|
||||
const title5h = h('span', { text: '5h 限额' });
|
||||
const meta5h = h('span', { className: 'panel-meta text-mono', text: '--' });
|
||||
const fill5h = h('div', { className: 'progress-fill' });
|
||||
const row5h = h('div', { style: 'display: flex; flex-direction: column; gap: 4px;' }, [
|
||||
h('div', { className: 'panel-header' }, [title5h, meta5h]),
|
||||
h('div', { className: 'progress-track' }, [fill5h]),
|
||||
]);
|
||||
|
||||
const titleWk = h('span', { text: '每周限额' });
|
||||
const metaWk = h('span', { className: 'panel-meta text-mono', text: '--' });
|
||||
const fillWk = h('div', { className: 'progress-fill' });
|
||||
const rowWk = h('div', { style: 'display: flex; flex-direction: column; gap: 4px;' }, [
|
||||
h('div', { className: 'panel-header' }, [titleWk, metaWk]),
|
||||
h('div', { className: 'progress-track' }, [fillWk]),
|
||||
]);
|
||||
|
||||
const el = h('div', { style: 'display: flex; flex-direction: column; gap: 8px;' }, [
|
||||
row5h,
|
||||
rowWk,
|
||||
]);
|
||||
|
||||
return {
|
||||
el,
|
||||
refs: { row5h, title5h, meta5h, fill5h, rowWk, titleWk, metaWk, fillWk },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步单个配额池行的 5h 与每周窗口状态:
|
||||
* - 对于仅有周限额的独立配额池(例如 Google AI Pro 账号下的 Argon 池或 Plus 档位)自动隐藏 5h 行;
|
||||
* - 对于仅有 5h 限额的配额池自动隐藏每周行;
|
||||
* - 若两个窗口均无数据(首次加载或拉取失败),同时保留两行以维持预占高度不跳动。
|
||||
*/
|
||||
export function syncPoolQuotaRow(refs, item, idx, rowEl) {
|
||||
const { poolData, poolLabel, fallbackWeekly, isActivePool, isPending } = item;
|
||||
patchAttr(
|
||||
rowEl,
|
||||
'style',
|
||||
idx === 0
|
||||
? 'display: flex; flex-direction: column; gap: 8px;'
|
||||
: 'display: flex; flex-direction: column; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-hairline);'
|
||||
);
|
||||
|
||||
const has5h = poolData?.usedPct != null && poolData?.remainingPct != null;
|
||||
const used5hVal = has5h ? Number(poolData.usedPct) : 0;
|
||||
const rem5hVal = has5h ? Number(poolData.remainingPct) : 0;
|
||||
|
||||
const useCustomWeekly = Boolean(isActivePool && fallbackWeekly?.isOfficial === false);
|
||||
const wkUsedRaw = useCustomWeekly
|
||||
? fallbackWeekly?.usedPct
|
||||
: poolData?.weeklyUsedPct ?? (isActivePool ? fallbackWeekly?.usedPct : null);
|
||||
const wkRemRaw = useCustomWeekly
|
||||
? fallbackWeekly?.remainingPct
|
||||
: poolData?.weeklyRemainingPct ?? (isActivePool ? fallbackWeekly?.remainingPct : null);
|
||||
const wkResetRaw = useCustomWeekly
|
||||
? fallbackWeekly?.resetTime || poolData?.weeklyResetTime
|
||||
: poolData?.weeklyResetTime || (isActivePool ? fallbackWeekly?.resetTime : null);
|
||||
const hasWk = wkUsedRaw != null && wkRemRaw != null;
|
||||
const usedWkVal = hasWk ? Number(wkUsedRaw) : 0;
|
||||
const remWkVal = hasWk ? Number(wkRemRaw) : 0;
|
||||
|
||||
// 在单窗口配额池(如 Pro 账号独立 Argon 周配额池或仅 5h 池)中隐藏不适用的另一窗口
|
||||
const hide5h = !has5h && hasWk;
|
||||
const hideWk = !hasWk && has5h;
|
||||
refs.row5h.hidden = hide5h;
|
||||
refs.row5h.style.display = hide5h ? 'none' : 'flex';
|
||||
refs.rowWk.hidden = hideWk;
|
||||
refs.rowWk.style.display = hideWk ? 'none' : 'flex';
|
||||
|
||||
const fallbackMetaText = isPending ? '读取中...' : '获取失败 (--%)';
|
||||
|
||||
patchText(refs.title5h, `5h 限额 (${poolLabel})`);
|
||||
patchText(
|
||||
refs.meta5h,
|
||||
has5h
|
||||
? `${formatCountdown(poolData.resetTime)} · 已用 ${used5hVal.toFixed(1)}% (余 ${rem5hVal.toFixed(1)}%)`
|
||||
: fallbackMetaText
|
||||
);
|
||||
patchStyleVar(refs.fill5h, '--fill-w', `${Math.min(100, used5hVal)}%`);
|
||||
patchClasses(refs.fill5h, {
|
||||
'tone-warn': used5hVal >= 60 && used5hVal < 85,
|
||||
'tone-danger': used5hVal >= 85,
|
||||
});
|
||||
|
||||
const customTitle =
|
||||
isActivePool && fallbackWeekly?.isOfficial === false && fallbackWeekly?.title
|
||||
? fallbackWeekly.title
|
||||
: `每周限额 (${poolLabel})`;
|
||||
patchText(refs.titleWk, customTitle);
|
||||
patchText(
|
||||
refs.metaWk,
|
||||
hasWk
|
||||
? `${formatCountdown(wkResetRaw)} · 已用 ${usedWkVal.toFixed(1)}% (余 ${remWkVal.toFixed(1)}%)`
|
||||
: fallbackMetaText
|
||||
);
|
||||
patchStyleVar(refs.fillWk, '--fill-w', `${Math.min(100, usedWkVal)}%`);
|
||||
patchClasses(refs.fillWk, {
|
||||
'tone-warn': usedWkVal >= 60 && usedWkVal < 85,
|
||||
'tone-danger': usedWkVal >= 85,
|
||||
});
|
||||
}
|
||||
|
||||
export function quotaPoolRowSig(item, idx) {
|
||||
return `${idx}:${item.poolLabel}:${item.isActivePool}:${Boolean(item.isPending)}:${item.minuteTick}:${item.poolData?.usedPct}:${item.poolData?.remainingPct}:${item.poolData?.resetTime}:${item.poolData?.weeklyUsedPct}:${item.poolData?.weeklyRemainingPct}:${item.poolData?.weeklyResetTime}:${item.fallbackWeekly?.isOfficial}:${item.fallbackWeekly?.usedPct}:${item.fallbackWeekly?.remainingPct}:${item.fallbackWeekly?.resetTime}:${item.fallbackWeekly?.title}`;
|
||||
}
|
||||
|
||||
export const LiveOverviewView = defineComponent({
|
||||
name: 'LiveOverviewView',
|
||||
setup({ onCleanup }) {
|
||||
@@ -65,6 +298,7 @@ export const LiveOverviewView = defineComponent({
|
||||
const expandedTaskConvIds = new Set();
|
||||
const activityTimersMap = new Map();
|
||||
let liveTickTimer = null;
|
||||
let countdownTickTimer = null;
|
||||
|
||||
function bindLiveElapsedTimer(timerKey, sig, rawStartMs, targetEl) {
|
||||
const now = Date.now();
|
||||
@@ -90,22 +324,51 @@ export const LiveOverviewView = defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
function stopLiveTicker() {
|
||||
function pauseLiveTicker() {
|
||||
if (liveTickTimer) {
|
||||
clearInterval(liveTickTimer);
|
||||
liveTickTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function stopLiveTicker() {
|
||||
pauseLiveTicker();
|
||||
activityTimersMap.clear();
|
||||
}
|
||||
|
||||
function ensureLiveTicker() {
|
||||
if (uiStore.getState().activeView !== 'overview' || activityTimersMap.size === 0) {
|
||||
pauseLiveTicker();
|
||||
return;
|
||||
}
|
||||
if (!liveTickTimer) {
|
||||
liveTickTimer = setInterval(updateLiveElapsedDisplay, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function stopCountdownTicker() {
|
||||
if (countdownTickTimer) {
|
||||
clearInterval(countdownTickTimer);
|
||||
countdownTickTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function ensureCountdownTicker() {
|
||||
if (uiStore.getState().activeView !== 'overview') {
|
||||
stopCountdownTicker();
|
||||
return;
|
||||
}
|
||||
if (!countdownTickTimer) {
|
||||
countdownTickTimer = setInterval(() => {
|
||||
if (uiStore.getState().activeView === 'overview' && latestData) {
|
||||
renderData(latestData);
|
||||
}
|
||||
}, 30_000);
|
||||
}
|
||||
}
|
||||
|
||||
function createLiveTaskCard() {
|
||||
const dotIcon = createSvgIcon('dot', { size: 9 });
|
||||
const dotIcon = createSvgIcon('dot', { size: 11 });
|
||||
patchClasses(dotIcon, { 'is-pulsing': true });
|
||||
const dotWrap = h('span', { className: 'live-activity-dot' }, [dotIcon]);
|
||||
const titleEl = h('strong', { className: 'live-task-title', text: '当前会话' });
|
||||
@@ -125,7 +388,11 @@ export const LiveOverviewView = defineComponent({
|
||||
h('div', { className: 'live-task-header-right' }, [subToggleBtn, elapsedEl]),
|
||||
]);
|
||||
|
||||
const mainBadge = h('span', { className: 'agent-badge badge-main', text: '主' });
|
||||
const mainBadge = h('span', {
|
||||
className: 'agent-badge badge-main',
|
||||
hidden: true,
|
||||
text: '主',
|
||||
});
|
||||
const mainPhase = h('strong', { className: 'live-activity-phase', text: '推理中' });
|
||||
const mainProgress = h('span', {
|
||||
className: 'live-activity-progress text-mono',
|
||||
@@ -158,6 +425,7 @@ export const LiveOverviewView = defineComponent({
|
||||
titleEl,
|
||||
subToggleBtn,
|
||||
elapsedEl,
|
||||
mainBadge,
|
||||
mainPhase,
|
||||
mainProgress,
|
||||
mainSep,
|
||||
@@ -205,7 +473,7 @@ export const LiveOverviewView = defineComponent({
|
||||
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 costVal = h('strong', { className: 'cell-value', text: '—' });
|
||||
const cacheSub = h('span', { className: 'cell-sub accent-ok', text: '缓存 0% · 累计 $0.00' });
|
||||
|
||||
const matrixEl = h('section', { className: 'telemetry-matrix', 'aria-label': '实时指标' }, [
|
||||
@@ -256,78 +524,7 @@ export const LiveOverviewView = defineComponent({
|
||||
[ctxPillGroup]
|
||||
);
|
||||
|
||||
const ctxChannels = [
|
||||
{
|
||||
key: 'assistant',
|
||||
label: '模型回复',
|
||||
segClass: 'seg-assistant',
|
||||
title: '模型推理思考、回复正文与工具调用入参',
|
||||
getValue: (c) => Number(c.assistantTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'toolResults',
|
||||
label: '工具结果',
|
||||
segClass: 'seg-tool-results',
|
||||
title: '文件读取、终端输出与工具执行返回内容',
|
||||
getValue: (c) => Number(c.toolResultsTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'userInput',
|
||||
label: '用户消息',
|
||||
segClass: 'seg-user-input',
|
||||
title: '用户提问文本与上传附件',
|
||||
getValue: (c) => Number(c.userInputTokens ?? c.messagesTokens ?? 0),
|
||||
},
|
||||
{
|
||||
key: 'subagent',
|
||||
label: '子代理通知',
|
||||
segClass: 'seg-subagent-msg',
|
||||
title: '子代理完成汇报与后台任务系统通知',
|
||||
getValue: (c) => Number(c.subagentTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'checkpoint',
|
||||
label: '压缩摘要',
|
||||
segClass: 'seg-checkpoint',
|
||||
title: '自动上下文压缩生成的历史摘要检查点',
|
||||
getValue: (c) => Number(c.checkpointTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'systemPrompt',
|
||||
label: '系统提示词',
|
||||
segClass: 'seg-system-prompt',
|
||||
title: '核心身份、终端沙箱、制品与环境提示词',
|
||||
getValue: (c) => Number(c.systemPromptTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'systemTools',
|
||||
label: '系统工具',
|
||||
segClass: 'seg-system-tools',
|
||||
title: '内置系统工具 Schema 定义',
|
||||
getValue: (c) => Number(c.systemToolsTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'mcpTools',
|
||||
label: 'MCP 工具',
|
||||
segClass: 'seg-mcp-tools',
|
||||
title: 'MCP 外部服务工具与资源定义',
|
||||
getValue: (c) => Number(c.mcpToolsTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'skills',
|
||||
label: 'Skill',
|
||||
segClass: 'seg-skills',
|
||||
title: '已挂载的 Skills 技能索引与说明',
|
||||
getValue: (c) => Number(c.skillsTokens || 0),
|
||||
},
|
||||
{
|
||||
key: 'userRules',
|
||||
label: '用户规则',
|
||||
segClass: 'seg-user-rules',
|
||||
title: '全局与工作区自定义规则 (user_rules)',
|
||||
getValue: (c) => Number(c.userRulesTokens || 0),
|
||||
},
|
||||
].map((ch, idx) => {
|
||||
const ctxChannels = CTX_CHANNEL_DEFS.map((ch, idx) => {
|
||||
const valEl = h('strong', { className: 'text-mono', text: '0' });
|
||||
const itemEl = h('div', { className: 'legend-item', title: ch.title }, [
|
||||
h('span', { className: 'legend-left' }, [
|
||||
@@ -364,37 +561,6 @@ export const LiveOverviewView = defineComponent({
|
||||
const tierBadge = h('span', { className: 'panel-meta', text: 'Google AI · Pro' });
|
||||
const poolsListEl = h('div', { style: 'display: flex; flex-direction: column; gap: 0;' });
|
||||
|
||||
/**
|
||||
* 创建单个配额池的 DOM 行结构,内含 5h 限额与每周限额两个可独立显隐的子窗口进度条。
|
||||
*/
|
||||
function createPoolQuotaRow() {
|
||||
const title5h = h('span', { text: '5h 限额' });
|
||||
const meta5h = h('span', { className: 'panel-meta text-mono', text: '--' });
|
||||
const fill5h = h('div', { className: 'progress-fill' });
|
||||
const row5h = h('div', { style: 'display: flex; flex-direction: column; gap: 4px;' }, [
|
||||
h('div', { className: 'panel-header' }, [title5h, meta5h]),
|
||||
h('div', { className: 'progress-track' }, [fill5h]),
|
||||
]);
|
||||
|
||||
const titleWk = h('span', { text: '每周限额' });
|
||||
const metaWk = h('span', { className: 'panel-meta text-mono', text: '--' });
|
||||
const fillWk = h('div', { className: 'progress-fill' });
|
||||
const rowWk = h('div', { style: 'display: flex; flex-direction: column; gap: 4px;' }, [
|
||||
h('div', { className: 'panel-header' }, [titleWk, metaWk]),
|
||||
h('div', { className: 'progress-track' }, [fillWk]),
|
||||
]);
|
||||
|
||||
const el = h('div', { style: 'display: flex; flex-direction: column; gap: 8px;' }, [
|
||||
row5h,
|
||||
rowWk,
|
||||
]);
|
||||
|
||||
return {
|
||||
el,
|
||||
refs: { row5h, title5h, meta5h, fill5h, rowWk, titleWk, metaWk, fillWk },
|
||||
};
|
||||
}
|
||||
|
||||
const wkFootLeft = h('span', { className: 'text-muted', text: '本周累计: 0 ($0.00)' });
|
||||
const wkFootRight = h('span', { className: 'text-muted', text: '' });
|
||||
|
||||
@@ -425,75 +591,6 @@ export const LiveOverviewView = defineComponent({
|
||||
className: 'view-pane',
|
||||
});
|
||||
|
||||
/**
|
||||
* 同步单个配额池行的 5h 与每周窗口状态:
|
||||
* - 对于仅有周限额的独立配额池(例如 Google AI Pro 账号下的 Argon 池或 Plus 档位)自动隐藏 5h 行;
|
||||
* - 对于仅有 5h 限额的配额池自动隐藏每周行;
|
||||
* - 若两个窗口均无数据(如首次拉取失败),则同时保留两行并显示“获取失败 (--%)”占位提示。
|
||||
*/
|
||||
function syncPoolQuotaRow(refs, item, idx, rowEl) {
|
||||
const { poolData, poolLabel, fallbackWeekly, isActivePool } = item;
|
||||
patchAttr(
|
||||
rowEl,
|
||||
'style',
|
||||
idx === 0
|
||||
? 'display: flex; flex-direction: column; gap: 8px;'
|
||||
: 'display: flex; flex-direction: column; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-hairline);'
|
||||
);
|
||||
|
||||
const has5h = poolData?.usedPct != null && poolData?.remainingPct != null;
|
||||
const used5hVal = has5h ? Number(poolData.usedPct) : 0;
|
||||
const rem5hVal = has5h ? Number(poolData.remainingPct) : 0;
|
||||
|
||||
const wkUsedRaw =
|
||||
poolData?.weeklyUsedPct ?? (isActivePool ? fallbackWeekly?.usedPct : null);
|
||||
const wkRemRaw =
|
||||
poolData?.weeklyRemainingPct ?? (isActivePool ? fallbackWeekly?.remainingPct : null);
|
||||
const wkResetRaw =
|
||||
poolData?.weeklyResetTime || (isActivePool ? fallbackWeekly?.resetTime : null);
|
||||
const hasWk = wkUsedRaw != null && wkRemRaw != null;
|
||||
const usedWkVal = hasWk ? Number(wkUsedRaw) : 0;
|
||||
const remWkVal = hasWk ? Number(wkRemRaw) : 0;
|
||||
|
||||
// 在单窗口配额池(如 Pro 账号独立 Argon 周配额池或仅 5h 池)中隐藏不适用的另一窗口
|
||||
const hide5h = !has5h && hasWk;
|
||||
const hideWk = !hasWk && has5h;
|
||||
refs.row5h.hidden = hide5h;
|
||||
refs.row5h.style.display = hide5h ? 'none' : 'flex';
|
||||
refs.rowWk.hidden = hideWk;
|
||||
refs.rowWk.style.display = hideWk ? 'none' : 'flex';
|
||||
|
||||
patchText(refs.title5h, `5h 限额 (${poolLabel})`);
|
||||
patchText(
|
||||
refs.meta5h,
|
||||
has5h
|
||||
? `${formatCountdown(poolData.resetTime)} · 已用 ${used5hVal.toFixed(1)}% (余 ${rem5hVal.toFixed(1)}%)`
|
||||
: '获取失败 (--%)'
|
||||
);
|
||||
patchStyleVar(refs.fill5h, '--fill-w', `${Math.min(100, used5hVal)}%`);
|
||||
patchClasses(refs.fill5h, {
|
||||
'tone-warn': used5hVal >= 60 && used5hVal < 85,
|
||||
'tone-danger': used5hVal >= 85,
|
||||
});
|
||||
|
||||
const customTitle =
|
||||
isActivePool && fallbackWeekly?.isOfficial === false && fallbackWeekly?.title
|
||||
? fallbackWeekly.title
|
||||
: `每周限额 (${poolLabel})`;
|
||||
patchText(refs.titleWk, customTitle);
|
||||
patchText(
|
||||
refs.metaWk,
|
||||
hasWk
|
||||
? `${formatCountdown(wkResetRaw)} · 已用 ${usedWkVal.toFixed(1)}% (余 ${remWkVal.toFixed(1)}%)`
|
||||
: '获取失败 (--%)'
|
||||
);
|
||||
patchStyleVar(refs.fillWk, '--fill-w', `${Math.min(100, usedWkVal)}%`);
|
||||
patchClasses(refs.fillWk, {
|
||||
'tone-warn': usedWkVal >= 60 && usedWkVal < 85,
|
||||
'tone-danger': usedWkVal >= 85,
|
||||
});
|
||||
}
|
||||
|
||||
let latestData = null;
|
||||
let isDirty = false;
|
||||
let ctxPillsExpanded = false;
|
||||
@@ -605,10 +702,10 @@ export const LiveOverviewView = defineComponent({
|
||||
const subSig = (item.subagents || [])
|
||||
.map(
|
||||
(s) =>
|
||||
`${s.cascadeId}:${s.isRunning}:${s.stepCount}:${s.liveActivity?.signature || ''}`
|
||||
`${s.cascadeId}:${s.isRunning}:${s.stepCount}:${s.liveActivity?.signature || ''}:${s.liveActivity?.startedAtMs || 0}`
|
||||
)
|
||||
.join('|');
|
||||
return `${item.cascadeId}:${item.title}:${item.isMainRunning}:${item.subagentCount}:${item.runningSubagentCount}:${isExp}:${item.mainActivity?.signature || ''}:${subSig}`;
|
||||
return `${item.cascadeId}:${item.title}:${item.isMainRunning}:${item.subagentCount}:${item.runningSubagentCount}:${isExp}:${item.mainActivity?.signature || ''}:${item.mainActivity?.startedAtMs || 0}:${subSig}`;
|
||||
},
|
||||
createRow: createLiveTaskCard,
|
||||
updateRow: (refs, item) => {
|
||||
@@ -622,7 +719,11 @@ export const LiveOverviewView = defineComponent({
|
||||
};
|
||||
|
||||
const isWaiting = act.phase === 'waiting';
|
||||
patchClasses(refs.cardEl, { 'is-waiting': isWaiting });
|
||||
const isCompacting = act.phase === 'compacting';
|
||||
patchClasses(refs.cardEl, {
|
||||
'is-waiting': isWaiting,
|
||||
'is-compacting': isCompacting,
|
||||
});
|
||||
patchClasses(refs.dotIcon, { 'is-pulsing': true });
|
||||
|
||||
const convTitle = item.title || item.cascadeId?.slice(0, 8) || '当前会话';
|
||||
@@ -639,6 +740,7 @@ export const LiveOverviewView = defineComponent({
|
||||
const subCount = Number(item.subagentCount || item.subagents?.length || 0);
|
||||
const runSubCount = Number(item.runningSubagentCount || 0);
|
||||
const isExpanded = expandedTaskConvIds.has(item.cascadeId);
|
||||
patchAttr(refs.mainBadge, 'hidden', subCount === 0);
|
||||
patchAttr(refs.subToggleBtn, 'hidden', subCount === 0);
|
||||
if (subCount > 0) {
|
||||
const arrow = isExpanded ? '▾' : '▸';
|
||||
@@ -758,14 +860,19 @@ export const LiveOverviewView = defineComponent({
|
||||
ensureLiveTicker();
|
||||
}
|
||||
|
||||
// 1. 更新 4 格实时测速矩阵(展示当前会话全局汇总指标)
|
||||
// 1. 更新 4 格实时测速矩阵(展示当前会话全局汇总指标,遵循模型名称格式设置)
|
||||
const showUpstream = Boolean(data.settings?.showUpstreamModel);
|
||||
const activeModelDisplay =
|
||||
(showUpstream
|
||||
? active.activeModelUpstream || active.activeModelShort
|
||||
: active.activeModelShort) || '模型未知';
|
||||
patchClasses(pulseDot, { 'is-pulsing': Boolean(active.isRunning) });
|
||||
patchText(tpsVal, formatMetric(active.latestTokPerSec, ' tok/s'));
|
||||
const reason = speedReasonText(active.latestSpeedReason);
|
||||
const modelAndAgent =
|
||||
hasSubagents && active.activeAgentBadge
|
||||
? `[${active.activeAgentBadge}] ${active.activeModelShort || '模型未知'}`
|
||||
: active.activeModelShort || '模型未知';
|
||||
? `[${active.activeAgentBadge}] ${activeModelDisplay}`
|
||||
: activeModelDisplay;
|
||||
patchText(tpsSub, reason ? `${modelAndAgent} · ${reason}` : modelAndAgent);
|
||||
|
||||
patchText(ttftVal, formatMetric(active.latestTtftSec, 's'));
|
||||
@@ -775,7 +882,11 @@ export const LiveOverviewView = defineComponent({
|
||||
patchText(avgSub, `有效 ${sampleSummary(active.speedSummary)}`);
|
||||
|
||||
const stepCost = active.latestStepCostUsd;
|
||||
patchText(costVal, formatUsd(stepCost, { precise: true }));
|
||||
const hasAnySteps = Number(active.stepCount || 0) > 0;
|
||||
patchText(
|
||||
costVal,
|
||||
!hasAnySteps && stepCost == null ? '—' : formatUsd(stepCost, { precise: true })
|
||||
);
|
||||
patchText(
|
||||
cacheSub,
|
||||
`缓存 ${active.latestCacheHitPct ?? 0}% · 累计 ${formatUsd(active.sessionCostUsd || 0, { unpricedCalls: active.sessionUnpricedCalls })}`
|
||||
@@ -803,10 +914,13 @@ export const LiveOverviewView = defineComponent({
|
||||
|
||||
const allAgentPills = agents.map((ag) => {
|
||||
const agPct = ag.context?.usedPct ?? 0;
|
||||
const agModelDisplay =
|
||||
(showUpstream ? ag.activeModelUpstream || ag.activeModelShort : ag.activeModelShort) ||
|
||||
'模型未知';
|
||||
return {
|
||||
key: ag.agentId,
|
||||
label: `${ag.badgeText || ag.shortLabel} ${agPct}%`,
|
||||
title: `${formatAgentLabel(ag)} (${ag.activeModelShort || '模型未知'} · ${ag.stepCount || 0}步)`,
|
||||
title: `${formatAgentLabel(ag)} (${agModelDisplay} · ${ag.stepCount || 0}步)`,
|
||||
isActive: effectiveCtxScope === ag.agentId,
|
||||
mode: 'ctx-only',
|
||||
};
|
||||
@@ -888,12 +1002,8 @@ export const LiveOverviewView = defineComponent({
|
||||
if (item.mode === 'toggle-expand') {
|
||||
ctxPillsExpanded = !ctxPillsExpanded;
|
||||
renderData(latestData);
|
||||
} else if (item.mode === 'ctx-only') {
|
||||
uiStore.setState({ ctxInspectorAgentId: item.key });
|
||||
} else if (item.key === 'all') {
|
||||
uiStore.setState({ selectedAgentScope: 'all', ctxInspectorAgentId: 'auto' });
|
||||
} else {
|
||||
uiStore.setState({ selectedAgentScope: item.key });
|
||||
uiStore.setState({ ctxInspectorAgentId: item.key });
|
||||
}
|
||||
};
|
||||
},
|
||||
@@ -928,37 +1038,13 @@ export const LiveOverviewView = defineComponent({
|
||||
tierBadge,
|
||||
`${data.account?.tierName || 'Google AI'} · ${data.account?.planName || 'Pro'}`
|
||||
);
|
||||
const activePool = quotas.activePool || {};
|
||||
const rawPools = Array.isArray(quotas.pools) && quotas.pools.length > 0
|
||||
? quotas.pools
|
||||
: [
|
||||
{ poolKey: 'Gemini', poolLabel: 'Gemini', family: 'Gemini' },
|
||||
{ poolKey: 'Claude & GPT', poolLabel: 'Claude & GPT', family: 'Claude & GPT' },
|
||||
];
|
||||
const weekly = quotas.weekly || {};
|
||||
const minuteTick = Math.floor(Date.now() / 30000);
|
||||
const poolItems = rawPools.map((p) => {
|
||||
const key = p.poolKey || p.family || p.poolLabel || 'Other';
|
||||
const poolLabel = p.poolLabel || p.family || key;
|
||||
const isActivePool =
|
||||
Boolean(activePool.family) &&
|
||||
(activePool.poolKey === key ||
|
||||
activePool.family === p.family ||
|
||||
(key === 'Claude & GPT' && ['Claude', 'GPT'].includes(activePool.family)));
|
||||
return {
|
||||
key,
|
||||
poolLabel,
|
||||
poolData: p,
|
||||
fallbackWeekly: weekly,
|
||||
isActivePool,
|
||||
minuteTick,
|
||||
};
|
||||
});
|
||||
const poolItems = buildQuotaPoolItems(quotas, minuteTick);
|
||||
|
||||
patchKeyedList(poolsListEl, poolItems, {
|
||||
keyFn: (item) => item.key,
|
||||
sigFn: (item, idx) =>
|
||||
`${idx}:${item.poolLabel}:${item.isActivePool}:${item.minuteTick}:${item.poolData?.usedPct}:${item.poolData?.remainingPct}:${item.poolData?.resetTime}:${item.poolData?.weeklyUsedPct}:${item.poolData?.weeklyRemainingPct}:${item.poolData?.weeklyResetTime}:${item.fallbackWeekly?.isOfficial}:${item.fallbackWeekly?.usedPct}:${item.fallbackWeekly?.title}`,
|
||||
sigFn: quotaPoolRowSig,
|
||||
createRow: createPoolQuotaRow,
|
||||
updateRow: syncPoolQuotaRow,
|
||||
});
|
||||
@@ -974,12 +1060,13 @@ export const LiveOverviewView = defineComponent({
|
||||
: `本周调用: ${weekly.calls || 0} 次`
|
||||
);
|
||||
|
||||
ensureCountdownTicker();
|
||||
viewScrollbar.refresh();
|
||||
}
|
||||
|
||||
const unsub = telemetryStore.subscribe(
|
||||
(st) => st.telemetry,
|
||||
(data) => {
|
||||
(st) => ({ telemetry: st.telemetry, minuteTick: st.minuteTick }),
|
||||
({ telemetry: data }) => {
|
||||
latestData = data;
|
||||
if (uiStore.getState().activeView !== 'overview') {
|
||||
const stillRunning =
|
||||
@@ -1011,12 +1098,18 @@ export const LiveOverviewView = defineComponent({
|
||||
prevCtxTarget = slice.ctxInspectorAgentId;
|
||||
|
||||
if (slice.activeView !== 'overview') {
|
||||
pauseLiveTicker();
|
||||
stopCountdownTicker();
|
||||
if (scopeChanged) isDirty = true;
|
||||
return;
|
||||
}
|
||||
ensureCountdownTicker();
|
||||
if ((isDirty || scopeChanged) && latestData) {
|
||||
isDirty = false;
|
||||
renderData(latestData);
|
||||
} else if (activityTimersMap.size > 0) {
|
||||
updateLiveElapsedDisplay();
|
||||
ensureLiveTicker();
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -1039,6 +1132,7 @@ export const LiveOverviewView = defineComponent({
|
||||
|
||||
onCleanup(() => {
|
||||
stopLiveTicker();
|
||||
stopCountdownTicker();
|
||||
unsub();
|
||||
unsubView();
|
||||
if (ro) ro.disconnect();
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
/**
|
||||
* @fileoverview View 4: SettingsView (系统设置视图).
|
||||
* 采用定制的 `CustomSelect` 与 `CustomNumberInput` 替代所有原生表单控件,分为两个设置面板:
|
||||
* 1. 本地配额监控与预算表单:配置模型名称显示方式(内部代号/实际模型名)、周用量计算模式及自定义 Token/USD 预算;
|
||||
* 2. 云端价格同步与插件更新面板:配置插件自动更新策略、手动同步云端模型价格表,以及检查并执行 Git/ZIP 双模式插件升级。
|
||||
* 采用定制的 `CustomSelect` 与 `SegmentedControl` 替代所有原生表单控件,分为三个单层细线设置面板:
|
||||
* 1. 常规设置:配置面板挂载方式(双栖挂载 / 仅右侧辅助栏)与模型名称格式(精简代号 / 原始模型 ID);
|
||||
* 2. 顶部栏定制:控制左侧「实时运行会话」入口开关,以及自由定义右侧精简胶囊三个数值槽位的显示内容与左右顺序;
|
||||
* 3. 版本更新:配置插件自动更新策略、手动同步云端模型价格表,以及检查并执行 Git/ZIP 双模式插件升级。
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../core/component.js';
|
||||
import { h, patchAttr, patchClasses, patchText } from '../core/domPatch.js';
|
||||
import { createSvgIcon } from '../icons/SvgIcon.js';
|
||||
import {
|
||||
DEFAULT_CLIENT_TOPBAR_SLOTS,
|
||||
normalizeClientTopbarSlots,
|
||||
saveSettingsPatch,
|
||||
telemetryStore,
|
||||
triggerCloudSync,
|
||||
triggerPluginUpdate,
|
||||
} from '../store/telemetryStore.js';
|
||||
import { uiStore } from '../store/uiStore.js';
|
||||
import { CustomNumberInput } from '../components/ui/CustomNumberInput.js';
|
||||
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
|
||||
import { CustomSelect } from '../components/ui/CustomSelect.js';
|
||||
|
||||
/** 每周配额计算模式可选项 */
|
||||
const WEEKLY_MODE_OPTIONS = [
|
||||
{ value: 'official', label: '跟随官方额度' },
|
||||
{ value: 'custom_tokens', label: '自定义 Token 上限' },
|
||||
{ value: 'custom_cost', label: '自定义费用上限 (USD)' },
|
||||
];
|
||||
import { SegmentedControl } from '../components/ui/SegmentedControl.js';
|
||||
|
||||
/** 步骤明细表中的模型名称显示方式可选项 */
|
||||
const STEP_MODEL_DISPLAY_OPTIONS = [
|
||||
@@ -31,6 +28,32 @@ const STEP_MODEL_DISPLAY_OPTIONS = [
|
||||
{ value: 'upstream', label: '原始模型 ID (如 gemini-3.8-flash-n)' },
|
||||
];
|
||||
|
||||
/** 面板挂载模式可选项(顶部栏 + 侧边栏 vs 仅侧边栏) */
|
||||
const WINDOW_MOUNT_OPTIONS = [
|
||||
{ value: 'dual', label: '双栖挂载 (顶部栏 + 侧边栏)' },
|
||||
{ value: 'sidebar', label: '仅侧边栏' },
|
||||
];
|
||||
|
||||
/** 顶栏左侧实时运行会话入口显隐选项 */
|
||||
const TOPBAR_MULTI_TOGGLE_OPTIONS = [
|
||||
{ value: 'show', label: '显示' },
|
||||
{ value: 'hide', label: '隐藏' },
|
||||
];
|
||||
|
||||
/** 顶栏右侧精简胶囊三槽位可选指标项 */
|
||||
const TOPBAR_SLOT_OPTIONS = [
|
||||
{ value: 'context', label: '上下文占用 (%)' },
|
||||
{ value: 'tps', label: '输出速度 (TPS)' },
|
||||
{ value: 'ttft', label: '首字延迟 (TTFT)' },
|
||||
{ value: 'cost', label: '本次费用 ($)' },
|
||||
{ value: 'quota_auto', label: '自动紧俏额度' },
|
||||
{ value: 'gemini_5h', label: 'Gemini 5h 额度' },
|
||||
{ value: 'gemini_weekly', label: 'Gemini 周额度' },
|
||||
{ value: 'claude_5h', label: 'Claude 5h 额度' },
|
||||
{ value: 'claude_weekly', label: 'Claude 周额度' },
|
||||
{ value: 'none', label: '不显示' },
|
||||
];
|
||||
|
||||
/** 插件版本更新策略可选项 */
|
||||
const AUTO_UPDATE_OPTIONS = [
|
||||
{ value: 'manual', label: '仅提示新版本,手动更新 (推荐)' },
|
||||
@@ -55,20 +78,20 @@ function formatSyncTimeText(tsMs, updatedAt) {
|
||||
export const SettingsView = defineComponent({
|
||||
name: 'SettingsView',
|
||||
setup({ onCleanup }) {
|
||||
// --- 面板 1:本地配额监控与预算表单状态与控件 ---
|
||||
let draftMode = 'official';
|
||||
let draftTokens = 150000000;
|
||||
let draftCost = 100;
|
||||
let draftShowUpstreamModel = false;
|
||||
let draftAutoUpdatePlugin = false;
|
||||
let draftEnableWindowOverlay = true;
|
||||
let draftShowTopbarMulti = true;
|
||||
let draftTopbarSlots = [...DEFAULT_CLIENT_TOPBAR_SLOTS];
|
||||
let statusTimer = null;
|
||||
let topbarTimer = null;
|
||||
let cloudTimer = null;
|
||||
let lastSyncedSettingsSig = '';
|
||||
|
||||
const saveStatusText = h('span', { className: 'text-muted', style: 'font-size: 11px;', text: '' });
|
||||
const topbarStatusText = h('span', { className: 'text-muted', style: 'font-size: 11px;', text: '' });
|
||||
const cloudStatusMsg = h('span', { className: 'text-muted', style: 'font-size: 11px;', text: '' });
|
||||
|
||||
/** 在本地预算面板右上角展示短暂的保存状态提示 */
|
||||
/** 在常规设置面板右上角展示短暂的保存状态提示 */
|
||||
function showSaveFeedback(text) {
|
||||
if (statusTimer) {
|
||||
clearTimeout(statusTimer);
|
||||
@@ -83,6 +106,21 @@ export const SettingsView = defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
/** 在顶部栏定制面板右上角展示短暂的状态提示 */
|
||||
function showTopbarFeedback(text, autoClearMs = 1500) {
|
||||
if (topbarTimer) {
|
||||
clearTimeout(topbarTimer);
|
||||
topbarTimer = null;
|
||||
}
|
||||
patchText(topbarStatusText, text);
|
||||
if (autoClearMs > 0) {
|
||||
topbarTimer = setTimeout(() => {
|
||||
topbarTimer = null;
|
||||
patchText(topbarStatusText, '');
|
||||
}, autoClearMs);
|
||||
}
|
||||
}
|
||||
|
||||
/** 在云端同步面板右上角展示同步或更新进度提示 */
|
||||
function showCloudFeedback(text, autoClearMs = 3500) {
|
||||
if (cloudTimer) {
|
||||
@@ -98,110 +136,54 @@ export const SettingsView = defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
const modeSelect = CustomSelect({
|
||||
modelValue: draftMode,
|
||||
icon: 'sliders',
|
||||
options: WEEKLY_MODE_OPTIONS,
|
||||
onUpdateModelValue: (val) => {
|
||||
draftMode = val;
|
||||
},
|
||||
});
|
||||
|
||||
// 模型名显示方式切换后立即持久化并刷新遥测数据
|
||||
const stepModelSelect = CustomSelect({
|
||||
modelValue: 'short',
|
||||
icon: 'table',
|
||||
options: STEP_MODEL_DISPLAY_OPTIONS,
|
||||
// --- 面板 1:常规设置 ---
|
||||
const windowMountSelect = CustomSelect({
|
||||
modelValue: 'dual',
|
||||
icon: 'dock',
|
||||
options: WINDOW_MOUNT_OPTIONS,
|
||||
onUpdateModelValue: async (val) => {
|
||||
draftShowUpstreamModel = val === 'upstream';
|
||||
if (latestSettings) {
|
||||
lastSyncedSettingsSig = settingsSig({
|
||||
...latestSettings,
|
||||
showUpstreamModel: draftShowUpstreamModel,
|
||||
});
|
||||
}
|
||||
const nextEnable = val !== 'sidebar';
|
||||
draftEnableWindowOverlay = nextEnable;
|
||||
windowMountSelect.setValue(nextEnable ? 'dual' : 'sidebar');
|
||||
showSaveFeedback('保存中…');
|
||||
try {
|
||||
await saveSettingsPatch({
|
||||
showUpstreamModel: draftShowUpstreamModel,
|
||||
enableWindowOverlay: nextEnable,
|
||||
});
|
||||
showSaveFeedback('已保存');
|
||||
} catch {
|
||||
if (latestSettings) {
|
||||
renderSettings(latestSettings);
|
||||
}
|
||||
showSaveFeedback('保存失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 插件自动更新策略切换后立即保存至后端
|
||||
const autoUpdateSelect = CustomSelect({
|
||||
modelValue: 'manual',
|
||||
icon: 'refresh',
|
||||
options: AUTO_UPDATE_OPTIONS,
|
||||
const stepModelSelect = CustomSelect({
|
||||
modelValue: 'short',
|
||||
icon: 'table',
|
||||
options: STEP_MODEL_DISPLAY_OPTIONS,
|
||||
onUpdateModelValue: async (val) => {
|
||||
draftAutoUpdatePlugin = val === 'auto';
|
||||
if (latestSettings) {
|
||||
lastSyncedSettingsSig = settingsSig({
|
||||
...latestSettings,
|
||||
autoUpdatePlugin: draftAutoUpdatePlugin,
|
||||
});
|
||||
}
|
||||
showCloudFeedback('保存中…', 0);
|
||||
const nextUpstream = val === 'upstream';
|
||||
draftShowUpstreamModel = nextUpstream;
|
||||
stepModelSelect.setValue(nextUpstream ? 'upstream' : 'short');
|
||||
showSaveFeedback('保存中…');
|
||||
try {
|
||||
await saveSettingsPatch({
|
||||
autoUpdatePlugin: draftAutoUpdatePlugin,
|
||||
showUpstreamModel: nextUpstream,
|
||||
});
|
||||
showCloudFeedback('已保存', 1800);
|
||||
showSaveFeedback('已保存');
|
||||
} catch {
|
||||
showCloudFeedback('保存失败', 2500);
|
||||
if (latestSettings) {
|
||||
renderSettings(latestSettings);
|
||||
}
|
||||
showSaveFeedback('保存失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
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 saveBtn = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'btn-primary',
|
||||
onClick: async () => {
|
||||
showSaveFeedback('保存中…');
|
||||
try {
|
||||
await saveSettingsPatch({
|
||||
weeklyLimitMode: draftMode,
|
||||
weeklyTokenBudget: draftTokens,
|
||||
weeklyCostBudget: draftCost,
|
||||
showUpstreamModel: draftShowUpstreamModel,
|
||||
autoUpdatePlugin: draftAutoUpdatePlugin,
|
||||
});
|
||||
showSaveFeedback('已保存');
|
||||
} catch {
|
||||
showSaveFeedback('保存失败');
|
||||
}
|
||||
},
|
||||
},
|
||||
[createSvgIcon('check', { size: 13 }), h('span', { text: '保存设置' })]
|
||||
);
|
||||
|
||||
const budgetPanel = h('section', { className: 'panel' }, [
|
||||
const generalPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title' }, [
|
||||
createSvgIcon('sliders', { size: 13 }),
|
||||
@@ -209,31 +191,211 @@ export const SettingsView = defineComponent({
|
||||
]),
|
||||
saveStatusText,
|
||||
]),
|
||||
h('div', { className: 'form-row' }, [
|
||||
h('span', { className: 'form-label', text: '面板挂载方式' }),
|
||||
windowMountSelect.el,
|
||||
]),
|
||||
h('div', { className: 'form-row' }, [
|
||||
h('span', { className: 'form-label', text: '模型名称格式' }),
|
||||
stepModelSelect.el,
|
||||
]),
|
||||
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 上限' }),
|
||||
tokenBudgetInput.el,
|
||||
]),
|
||||
h('div', { className: 'form-row' }, [
|
||||
h('span', { className: 'form-label', text: '每周费用上限 ($)' }),
|
||||
costBudgetInput.el,
|
||||
]),
|
||||
]),
|
||||
h('div', { style: 'display: flex; justify-content: flex-end;' }, [saveBtn]),
|
||||
]);
|
||||
|
||||
// --- 面板 2:版本更新面板 ---
|
||||
// --- 面板 2:顶部栏定制(实时运行会话开关 + 右侧三槽位指标与顺序自定义) ---
|
||||
const multiSessionToggle = SegmentedControl({
|
||||
ariaLabel: '实时运行会话开关',
|
||||
modelValue: 'show',
|
||||
options: TOPBAR_MULTI_TOGGLE_OPTIONS,
|
||||
onUpdateModelValue: async (val) => {
|
||||
const nextShow = val !== 'hide';
|
||||
draftShowTopbarMulti = nextShow;
|
||||
syncTopbarControls();
|
||||
showTopbarFeedback('保存中…', 0);
|
||||
try {
|
||||
await saveSettingsPatch({
|
||||
showTopbarMultiSession: nextShow,
|
||||
});
|
||||
showTopbarFeedback('已保存', 1500);
|
||||
} catch {
|
||||
if (latestSettings) {
|
||||
renderSettings(latestSettings);
|
||||
}
|
||||
showTopbarFeedback('保存失败', 2500);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
async function persistTopbarSlots(nextRawSlots, noticeText = '') {
|
||||
const normalized = normalizeClientTopbarSlots(nextRawSlots);
|
||||
draftTopbarSlots = normalized;
|
||||
syncTopbarControls();
|
||||
showTopbarFeedback(noticeText || '保存中…', 0);
|
||||
try {
|
||||
await saveSettingsPatch({
|
||||
topbarCapsuleSlots: normalized,
|
||||
});
|
||||
showTopbarFeedback(noticeText || '已保存', noticeText ? 2000 : 1500);
|
||||
} catch {
|
||||
if (latestSettings) {
|
||||
renderSettings(latestSettings);
|
||||
}
|
||||
showTopbarFeedback('保存失败', 2500);
|
||||
}
|
||||
}
|
||||
|
||||
function handleSlotMetricChange(slotIndex, nextVal) {
|
||||
const candidate = [...draftTopbarSlots];
|
||||
candidate[slotIndex] = nextVal;
|
||||
const wouldAllBeHidden = candidate.every((item) => item === 'none');
|
||||
void persistTopbarSlots(
|
||||
candidate,
|
||||
wouldAllBeHidden ? '至少保留 1 项显示' : ''
|
||||
);
|
||||
}
|
||||
|
||||
function swapTopbarSlots(idxA, idxB) {
|
||||
if (idxA < 0 || idxA > 2 || idxB < 0 || idxB > 2 || idxA === idxB) return;
|
||||
const candidate = [...draftTopbarSlots];
|
||||
const temp = candidate[idxA];
|
||||
candidate[idxA] = candidate[idxB];
|
||||
candidate[idxB] = temp;
|
||||
void persistTopbarSlots(candidate);
|
||||
}
|
||||
|
||||
const slotSelects = [0, 1, 2].map((idx) =>
|
||||
CustomSelect({
|
||||
modelValue: draftTopbarSlots[idx],
|
||||
options: TOPBAR_SLOT_OPTIONS,
|
||||
onUpdateModelValue: (val) => handleSlotMetricChange(idx, val),
|
||||
})
|
||||
);
|
||||
|
||||
const slotRows = [0, 1, 2].map((idx) => {
|
||||
const upBtn = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'slot-move-btn',
|
||||
disabled: idx === 0,
|
||||
'aria-label': `槽位 ${idx + 1} 左移`,
|
||||
title: idx === 0 ? '已在最左' : '上移 (在顶栏靠左)',
|
||||
onClick: (e) => {
|
||||
e.stopPropagation();
|
||||
swapTopbarSlots(idx, idx - 1);
|
||||
},
|
||||
},
|
||||
[createSvgIcon('chevron-up', { size: 12 })]
|
||||
);
|
||||
|
||||
const downBtn = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'slot-move-btn',
|
||||
disabled: idx === 2,
|
||||
'aria-label': `槽位 ${idx + 1} 右移`,
|
||||
title: idx === 2 ? '已在最右' : '下移 (在顶栏靠右)',
|
||||
onClick: (e) => {
|
||||
e.stopPropagation();
|
||||
swapTopbarSlots(idx, idx + 1);
|
||||
},
|
||||
},
|
||||
[createSvgIcon('chevron-down', { size: 12 })]
|
||||
);
|
||||
|
||||
return h('div', { className: 'topbar-slot-row', 'data-slot-row': String(idx) }, [
|
||||
h('span', { className: 'slot-index-badge', text: String(idx + 1) }),
|
||||
slotSelects[idx].el,
|
||||
h('span', { className: 'slot-order-btns' }, [upBtn, downBtn]),
|
||||
]);
|
||||
});
|
||||
|
||||
const resetTopbarBtn = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'btn-ghost-sm',
|
||||
disabled: true,
|
||||
onClick: async () => {
|
||||
draftShowTopbarMulti = true;
|
||||
draftTopbarSlots = [...DEFAULT_CLIENT_TOPBAR_SLOTS];
|
||||
syncTopbarControls();
|
||||
showTopbarFeedback('保存中…', 0);
|
||||
try {
|
||||
await saveSettingsPatch({
|
||||
showTopbarMultiSession: true,
|
||||
topbarCapsuleSlots: [...DEFAULT_CLIENT_TOPBAR_SLOTS],
|
||||
});
|
||||
showTopbarFeedback('已恢复默认', 1600);
|
||||
} catch {
|
||||
if (latestSettings) {
|
||||
renderSettings(latestSettings);
|
||||
}
|
||||
showTopbarFeedback('保存失败', 2500);
|
||||
}
|
||||
},
|
||||
},
|
||||
[h('span', { text: '恢复默认' })]
|
||||
);
|
||||
|
||||
function syncTopbarControls() {
|
||||
multiSessionToggle.setValue(draftShowTopbarMulti ? 'show' : 'hide');
|
||||
for (let i = 0; i < 3; i += 1) {
|
||||
slotSelects[i].setValue(draftTopbarSlots[i]);
|
||||
}
|
||||
const isDefault =
|
||||
draftShowTopbarMulti === true &&
|
||||
draftTopbarSlots[0] === DEFAULT_CLIENT_TOPBAR_SLOTS[0] &&
|
||||
draftTopbarSlots[1] === DEFAULT_CLIENT_TOPBAR_SLOTS[1] &&
|
||||
draftTopbarSlots[2] === DEFAULT_CLIENT_TOPBAR_SLOTS[2];
|
||||
patchAttr(resetTopbarBtn, 'disabled', isDefault);
|
||||
}
|
||||
|
||||
const topbarPanel = h('section', { className: 'panel topbar-config-panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title' }, [
|
||||
createSvgIcon('dock', { size: 13 }),
|
||||
h('span', { text: '顶部栏定制' }),
|
||||
]),
|
||||
h('span', { className: 'topbar-header-right' }, [topbarStatusText, resetTopbarBtn]),
|
||||
]),
|
||||
h('div', { className: 'settings-inline-row' }, [
|
||||
h('span', { className: 'form-label', text: '实时运行会话' }),
|
||||
multiSessionToggle.el,
|
||||
]),
|
||||
h('div', { className: 'form-row' }, [
|
||||
h('span', { className: 'form-label', text: '胶囊数值与顺序 (左 → 右)' }),
|
||||
h('div', { className: 'topbar-slot-list' }, slotRows),
|
||||
]),
|
||||
]);
|
||||
|
||||
// --- 面板 3:版本更新面板 ---
|
||||
const autoUpdateSelect = CustomSelect({
|
||||
modelValue: 'manual',
|
||||
icon: 'refresh',
|
||||
options: AUTO_UPDATE_OPTIONS,
|
||||
onUpdateModelValue: async (val) => {
|
||||
const nextAuto = val === 'auto';
|
||||
draftAutoUpdatePlugin = nextAuto;
|
||||
autoUpdateSelect.setValue(nextAuto ? 'auto' : 'manual');
|
||||
showCloudFeedback('保存中…', 0);
|
||||
try {
|
||||
await saveSettingsPatch({
|
||||
autoUpdatePlugin: nextAuto,
|
||||
});
|
||||
showCloudFeedback('已保存', 1800);
|
||||
} catch {
|
||||
if (latestSettings) {
|
||||
renderSettings(latestSettings);
|
||||
}
|
||||
showCloudFeedback('保存失败', 2500);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const pricingCountVal = h('strong', { className: 'cell-value', text: '—' });
|
||||
const pricingSyncSub = h('span', { className: 'cell-sub', text: '读取中…' });
|
||||
const versionVal = h('strong', { className: 'cell-value', text: 'v1.4.1' });
|
||||
const versionVal = h('strong', { className: 'cell-value', text: 'v1.4.3' });
|
||||
const versionSub = h('span', { className: 'cell-sub', text: '检查中…' });
|
||||
|
||||
const syncPricingBtnText = h('span', { text: '更新价格表' });
|
||||
@@ -288,7 +450,7 @@ export const SettingsView = defineComponent({
|
||||
return;
|
||||
}
|
||||
if (!cs?.updateAvailable) {
|
||||
const curVer = cs?.currentPluginVersion || '1.4.1';
|
||||
const curVer = cs?.currentPluginVersion || '1.4.3';
|
||||
showCloudFeedback(`当前已是最新版本 (v${curVer})`, 4500);
|
||||
return;
|
||||
}
|
||||
@@ -342,38 +504,35 @@ export const SettingsView = defineComponent({
|
||||
h('div', { className: 'cloud-actions-row' }, [syncPricingBtn, updatePluginBtn]),
|
||||
]);
|
||||
|
||||
const rootEl = h('div', { className: 'view-pane' }, [budgetPanel, cloudPanel]);
|
||||
const settingsInner = h(
|
||||
'div',
|
||||
{
|
||||
style: 'display: flex; flex-direction: column; gap: var(--space-3); padding-bottom: 2px;',
|
||||
},
|
||||
[generalPanel, topbarPanel, cloudPanel]
|
||||
);
|
||||
const viewScrollbar = CustomScrollbar({
|
||||
contentEl: settingsInner,
|
||||
className: 'view-pane',
|
||||
});
|
||||
|
||||
let latestSettings = null;
|
||||
let latestCloudStatus = null;
|
||||
let isDirty = false;
|
||||
|
||||
/** 生成设置项签名,避免轮询返回相同配置时覆盖用户正在编辑的草稿值 */
|
||||
function settingsSig(s) {
|
||||
if (!s) return '';
|
||||
return `${s.weeklyLimitMode}:${s.weeklyTokenBudget}:${s.weeklyCostBudget}:${Boolean(s.showUpstreamModel)}:${Boolean(s.autoUpdatePlugin)}`;
|
||||
}
|
||||
|
||||
/** 将后端返回的最新设置同步至表单控件 */
|
||||
function renderSettings(settings) {
|
||||
if (!settings) return;
|
||||
const nextSig = settingsSig(settings);
|
||||
if (nextSig === lastSyncedSettingsSig) return;
|
||||
lastSyncedSettingsSig = nextSig;
|
||||
draftMode =
|
||||
settings.weeklyLimitMode === 'custom_tokens' ||
|
||||
settings.weeklyLimitMode === 'custom_cost'
|
||||
? settings.weeklyLimitMode
|
||||
: 'official';
|
||||
draftTokens = Number(settings.weeklyTokenBudget || 150000000);
|
||||
draftCost = Number(settings.weeklyCostBudget || 100);
|
||||
draftShowUpstreamModel = Boolean(settings.showUpstreamModel);
|
||||
draftAutoUpdatePlugin = Boolean(settings.autoUpdatePlugin);
|
||||
modeSelect.setValue(draftMode);
|
||||
draftEnableWindowOverlay = settings.enableWindowOverlay !== false;
|
||||
draftShowTopbarMulti = settings.showTopbarMultiSession !== false;
|
||||
draftTopbarSlots = normalizeClientTopbarSlots(settings.topbarCapsuleSlots);
|
||||
|
||||
windowMountSelect.setValue(draftEnableWindowOverlay ? 'dual' : 'sidebar');
|
||||
stepModelSelect.setValue(draftShowUpstreamModel ? 'upstream' : 'short');
|
||||
autoUpdateSelect.setValue(draftAutoUpdatePlugin ? 'auto' : 'manual');
|
||||
tokenBudgetInput.setValue(draftTokens);
|
||||
costBudgetInput.setValue(draftCost);
|
||||
syncTopbarControls();
|
||||
viewScrollbar.refresh();
|
||||
}
|
||||
|
||||
/** 将云端价格表统计与插件版本对比状态同步至云端面板 */
|
||||
@@ -391,7 +550,7 @@ export const SettingsView = defineComponent({
|
||||
`${srcLabel} · ${formatSyncTimeText(cs.lastSyncedAtMs, cs.catalogUpdatedAt)}`
|
||||
);
|
||||
|
||||
const curVer = cs.currentPluginVersion || '1.4.1';
|
||||
const curVer = cs.currentPluginVersion || '1.4.3';
|
||||
const latVer = cs.latestPluginVersion || curVer;
|
||||
const modeTag = cs.installMode === 'git' ? 'Git' : 'ZIP';
|
||||
patchText(versionVal, `v${curVer}`);
|
||||
@@ -410,6 +569,7 @@ export const SettingsView = defineComponent({
|
||||
if (!cloudTimer && (cs.lastUpdateError || (cs.lastUpdateResult?.ok === false && cs.lastUpdateResult?.message))) {
|
||||
showCloudFeedback(cs.lastUpdateError || cs.lastUpdateResult.message, 5500);
|
||||
}
|
||||
viewScrollbar.refresh();
|
||||
}
|
||||
|
||||
const unsub = telemetryStore.subscribe(
|
||||
@@ -420,42 +580,51 @@ export const SettingsView = defineComponent({
|
||||
(slice) => {
|
||||
latestSettings = slice.settings;
|
||||
latestCloudStatus = slice.cloudStatus;
|
||||
if (uiStore.getState().activeView !== 'settings') {
|
||||
isDirty = true;
|
||||
return;
|
||||
}
|
||||
isDirty = false;
|
||||
renderSettings(slice.settings);
|
||||
renderCloudStatus(slice.cloudStatus);
|
||||
if (uiStore.getState().activeView === 'settings') {
|
||||
renderCloudStatus(slice.cloudStatus);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const unsubView = uiStore.subscribe(
|
||||
(st) => st.activeView,
|
||||
(activeView) => {
|
||||
if (activeView === 'settings' && isDirty) {
|
||||
isDirty = false;
|
||||
if (activeView === 'settings') {
|
||||
if (latestSettings) renderSettings(latestSettings);
|
||||
if (latestCloudStatus) renderCloudStatus(latestCloudStatus);
|
||||
viewScrollbar.refresh();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onCleanup(() => {
|
||||
if (statusTimer) clearTimeout(statusTimer);
|
||||
if (topbarTimer) clearTimeout(topbarTimer);
|
||||
if (cloudTimer) clearTimeout(cloudTimer);
|
||||
unsub();
|
||||
unsubView();
|
||||
modeSelect.destroy();
|
||||
windowMountSelect.destroy();
|
||||
stepModelSelect.destroy();
|
||||
multiSessionToggle.destroy();
|
||||
for (const sel of slotSelects) {
|
||||
sel.destroy();
|
||||
}
|
||||
autoUpdateSelect.destroy();
|
||||
tokenBudgetInput.destroy();
|
||||
costBudgetInput.destroy();
|
||||
viewScrollbar.destroy();
|
||||
});
|
||||
|
||||
return {
|
||||
el: rootEl,
|
||||
refs: { modeSelect, stepModelSelect, autoUpdateSelect, tokenBudgetInput, costBudgetInput },
|
||||
el: viewScrollbar.el,
|
||||
refs: {
|
||||
windowMountSelect,
|
||||
stepModelSelect,
|
||||
multiSessionToggle,
|
||||
slotSelects,
|
||||
resetTopbarBtn,
|
||||
autoUpdateSelect,
|
||||
viewScrollbar,
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -349,7 +349,7 @@ export const StepsDetailView = defineComponent({
|
||||
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, { estimated: m.isEstimatedPrice, unpricedCalls: m.unpricedCalls }));
|
||||
patchText(refs.tdCost, formatUsd(m.costUsd, { unpricedCalls: m.unpricedCalls }));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -367,7 +367,6 @@ export const StepsDetailView = defineComponent({
|
||||
recentSteps: st.telemetry?.activeConversation?.recentSteps,
|
||||
sessionModelBreakdown: st.telemetry?.activeConversation?.modelBreakdown,
|
||||
modelBreakdown: st.telemetry?.modelBreakdown,
|
||||
rangeLabel: st.telemetry?.consumption?.selectedRange?.label || '全部时间',
|
||||
showUpstreamModel: Boolean(st.telemetry?.settings?.showUpstreamModel),
|
||||
}),
|
||||
(slice) => {
|
||||
|
||||
Reference in New Issue
Block a user