mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): support upstream responseModel display and infer compaction step model & pricing
This commit is contained in:
@@ -29,6 +29,10 @@ function isEquivalentTelemetry(prev, next) {
|
||||
|
||||
const pAct = prev.activeConversation;
|
||||
const nAct = next.activeConversation;
|
||||
if (prev.settings?.showUpstreamModel !== next.settings?.showUpstreamModel) return false;
|
||||
if (prev.settings?.weeklyLimitMode !== next.settings?.weeklyLimitMode) return false;
|
||||
if (prev.settings?.weeklyTokenBudget !== next.settings?.weeklyTokenBudget) return false;
|
||||
if (prev.settings?.weeklyCostBudget !== next.settings?.weeklyCostBudget) return false;
|
||||
if (pAct?.cascadeId !== nAct?.cascadeId) return false;
|
||||
if (pAct?.stepCount !== nAct?.stepCount) return false;
|
||||
if (pAct?.isRunning !== nAct?.isRunning) return false;
|
||||
@@ -49,6 +53,7 @@ function isEquivalentTelemetry(prev, next) {
|
||||
for (let i = 0; i < (pAct?.recentSteps?.length || 0); i++) {
|
||||
const before = pAct.recentSteps[i], after = nAct.recentSteps[i];
|
||||
if (before.modelKey !== after.modelKey || before.modelShort !== after.modelShort ||
|
||||
before.modelUpstream !== after.modelUpstream || before.responseModel !== after.responseModel ||
|
||||
before.modelSource !== after.modelSource || before.costUsd !== after.costUsd) return false;
|
||||
}
|
||||
|
||||
@@ -88,6 +93,7 @@ function isEquivalentTelemetry(prev, next) {
|
||||
if (
|
||||
pModels[i]?.label !== nModels[i]?.label ||
|
||||
pModels[i]?.shortName !== nModels[i]?.shortName ||
|
||||
pModels[i]?.upstreamName !== nModels[i]?.upstreamName ||
|
||||
pModels[i]?.costUsd !== nModels[i]?.costUsd ||
|
||||
pModels[i]?.unpricedCalls !== nModels[i]?.unpricedCalls ||
|
||||
pModels[i]?.totalTokens !== nModels[i]?.totalTokens ||
|
||||
|
||||
@@ -21,12 +21,36 @@ const WEEKLY_MODE_OPTIONS = [
|
||||
{ value: 'custom_cost', label: '按自定义每周美元 ($) 预算计算百分比' },
|
||||
];
|
||||
|
||||
const STEP_MODEL_DISPLAY_OPTIONS = [
|
||||
{ value: 'short', label: '本地简称 (如 argon-4-high / flash-3.8-high)' },
|
||||
{ value: 'upstream', label: '上游真实模型名 (如 gemini-4-argon / gemini-3.8-flash-n)' },
|
||||
];
|
||||
|
||||
export const SettingsView = defineComponent({
|
||||
name: 'SettingsView',
|
||||
setup({ onCleanup }) {
|
||||
let draftMode = 'official';
|
||||
let draftTokens = 150000000;
|
||||
let draftCost = 100;
|
||||
let draftShowUpstreamModel = false;
|
||||
let statusTimer = null;
|
||||
let lastSyncedSettingsSig = '';
|
||||
|
||||
const saveStatusText = h('span', { className: 'text-muted', style: 'font-size: 11px;', text: '' });
|
||||
|
||||
function showSaveFeedback(text) {
|
||||
if (statusTimer) {
|
||||
clearTimeout(statusTimer);
|
||||
statusTimer = null;
|
||||
}
|
||||
patchText(saveStatusText, text);
|
||||
if (text === '设置已生效') {
|
||||
statusTimer = setTimeout(() => {
|
||||
statusTimer = null;
|
||||
patchText(saveStatusText, '');
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
const modeSelect = CustomSelect({
|
||||
modelValue: draftMode,
|
||||
@@ -37,6 +61,26 @@ export const SettingsView = defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
const stepModelSelect = CustomSelect({
|
||||
modelValue: 'short',
|
||||
icon: 'table',
|
||||
options: STEP_MODEL_DISPLAY_OPTIONS,
|
||||
onUpdateModelValue: async (val) => {
|
||||
draftShowUpstreamModel = val === 'upstream';
|
||||
if (latestSettings) {
|
||||
lastSyncedSettingsSig = settingsSig({
|
||||
...latestSettings,
|
||||
showUpstreamModel: draftShowUpstreamModel,
|
||||
});
|
||||
}
|
||||
showSaveFeedback('正在异步保存...');
|
||||
await saveSettingsPatch({
|
||||
showUpstreamModel: draftShowUpstreamModel,
|
||||
});
|
||||
showSaveFeedback('设置已生效');
|
||||
},
|
||||
});
|
||||
|
||||
const tokenBudgetInput = CustomNumberInput({
|
||||
modelValue: draftTokens,
|
||||
min: 100000,
|
||||
@@ -57,22 +101,20 @@ export const SettingsView = defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
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, '正在异步保存...');
|
||||
showSaveFeedback('正在异步保存...');
|
||||
await saveSettingsPatch({
|
||||
weeklyLimitMode: draftMode,
|
||||
weeklyTokenBudget: draftTokens,
|
||||
weeklyCostBudget: draftCost,
|
||||
showUpstreamModel: draftShowUpstreamModel,
|
||||
});
|
||||
patchText(saveStatusText, '设置已生效');
|
||||
setTimeout(() => patchText(saveStatusText, ''), 1500);
|
||||
showSaveFeedback('设置已生效');
|
||||
},
|
||||
},
|
||||
[createSvgIcon('check', { size: 13 }), h('span', { text: '保存参数设置' })]
|
||||
@@ -86,6 +128,10 @@ export const SettingsView = defineComponent({
|
||||
]),
|
||||
saveStatusText,
|
||||
]),
|
||||
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,
|
||||
@@ -108,8 +154,16 @@ export const SettingsView = defineComponent({
|
||||
let latestSettings = null;
|
||||
let isDirty = false;
|
||||
|
||||
function settingsSig(s) {
|
||||
if (!s) return '';
|
||||
return `${s.weeklyLimitMode}:${s.weeklyTokenBudget}:${s.weeklyCostBudget}:${Boolean(s.showUpstreamModel)}`;
|
||||
}
|
||||
|
||||
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'
|
||||
@@ -117,7 +171,9 @@ export const SettingsView = defineComponent({
|
||||
: 'official';
|
||||
draftTokens = Number(settings.weeklyTokenBudget || 150000000);
|
||||
draftCost = Number(settings.weeklyCostBudget || 100);
|
||||
draftShowUpstreamModel = Boolean(settings.showUpstreamModel);
|
||||
modeSelect.setValue(draftMode);
|
||||
stepModelSelect.setValue(draftShowUpstreamModel ? 'upstream' : 'short');
|
||||
tokenBudgetInput.setValue(draftTokens);
|
||||
costBudgetInput.setValue(draftCost);
|
||||
}
|
||||
@@ -148,16 +204,18 @@ export const SettingsView = defineComponent({
|
||||
);
|
||||
|
||||
onCleanup(() => {
|
||||
if (statusTimer) clearTimeout(statusTimer);
|
||||
unsub();
|
||||
unsubView();
|
||||
modeSelect.destroy();
|
||||
stepModelSelect.destroy();
|
||||
tokenBudgetInput.destroy();
|
||||
costBudgetInput.destroy();
|
||||
});
|
||||
|
||||
return {
|
||||
el: rootEl,
|
||||
refs: { modeSelect, tokenBudgetInput, costBudgetInput },
|
||||
refs: { modeSelect, stepModelSelect, tokenBudgetInput, costBudgetInput },
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -123,6 +123,7 @@ export const StepsDetailView = defineComponent({
|
||||
if (!slice) return;
|
||||
const steps = slice.recentSteps || [];
|
||||
const models = slice.modelBreakdown || [];
|
||||
const showUpstream = Boolean(slice.showUpstreamModel);
|
||||
|
||||
subTabSwitch.setProps({
|
||||
options: [
|
||||
@@ -134,13 +135,15 @@ export const StepsDetailView = defineComponent({
|
||||
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}`,
|
||||
`${st.stepIndex}:${showUpstream ? st.modelUpstream || st.responseModel || st.modelShort : 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 tdModel = h('td', {
|
||||
style: 'max-width: 140px; overflow: hidden; text-overflow: ellipsis;',
|
||||
});
|
||||
const speedMain = h('strong', {
|
||||
className: 'cell-value accent-speed',
|
||||
style: 'font-size: 11px;',
|
||||
@@ -175,7 +178,12 @@ export const StepsDetailView = defineComponent({
|
||||
updateRow: (refs, st) => {
|
||||
patchText(refs.stepNumText, `#${Number(st.stepIndex)} `);
|
||||
patchAttr(refs.compIcon, 'hidden', !st.isCompactionStep);
|
||||
patchText(refs.tdModel, st.modelShort || '—');
|
||||
const modelText =
|
||||
(showUpstream ? st.modelUpstream || st.responseModel : st.modelShort) ||
|
||||
st.modelShort ||
|
||||
'—';
|
||||
patchText(refs.tdModel, modelText);
|
||||
patchAttr(refs.tdModel, 'title', modelText);
|
||||
|
||||
patchText(refs.speedMain, formatMetric(st.tokPerSec, ' tok/s'));
|
||||
const reason = speedReasonText(st.selectedSpeedReason);
|
||||
@@ -198,9 +206,11 @@ export const StepsDetailView = defineComponent({
|
||||
patchKeyedList(modelsTbody, models, {
|
||||
keyFn: (m) => m.label || m.shortName,
|
||||
sigFn: (m) =>
|
||||
`${m.shortName}:${m.calls}:${m.avgTokPerSec}:${m.totalTokens}:${m.costUsd}:${m.unpricedCalls}:${m.speedSummary?.sampleCount}`,
|
||||
`${showUpstream ? m.upstreamName || m.shortName : m.shortName}:${m.calls}:${m.avgTokPerSec}:${m.totalTokens}:${m.costUsd}:${m.unpricedCalls}:${m.speedSummary?.sampleCount}`,
|
||||
createRow: () => {
|
||||
const tdName = h('td', { style: 'font-weight: 600;' });
|
||||
const tdName = h('td', {
|
||||
style: 'font-weight: 600; max-width: 165px; overflow: hidden; text-overflow: ellipsis;',
|
||||
});
|
||||
const tdCalls = h('td');
|
||||
const speedMain = h('div');
|
||||
const speedSub = h('div', { className: 'text-muted', style: 'font-size: 9.5px;' });
|
||||
@@ -214,7 +224,15 @@ export const StepsDetailView = defineComponent({
|
||||
};
|
||||
},
|
||||
updateRow: (refs, m) => {
|
||||
patchText(refs.tdName, m.shortName || m.label);
|
||||
const nameText = showUpstream
|
||||
? m.upstreamName || m.shortName || m.label
|
||||
: m.shortName || m.label;
|
||||
patchText(refs.tdName, nameText);
|
||||
const fullUpstreamTitle =
|
||||
showUpstream && Array.isArray(m.upstreamModels) && m.upstreamModels.length > 1
|
||||
? m.upstreamModels.join(' / ')
|
||||
: nameText;
|
||||
patchAttr(refs.tdName, 'title', fullUpstreamTitle);
|
||||
patchText(refs.tdCalls, String(Number(m.calls || 0)));
|
||||
patchText(refs.speedMain, formatMetric(m.avgTokPerSec, ' tok/s'));
|
||||
patchText(refs.speedSub, `有效 ${sampleSummary(m.speedSummary)}`);
|
||||
@@ -233,6 +251,7 @@ export const StepsDetailView = defineComponent({
|
||||
recentSteps: st.telemetry?.activeConversation?.recentSteps,
|
||||
modelBreakdown: st.telemetry?.modelBreakdown,
|
||||
rangeLabel: st.telemetry?.consumption?.selectedRange?.label || '全部时间',
|
||||
showUpstreamModel: Boolean(st.telemetry?.settings?.showUpstreamModel),
|
||||
}),
|
||||
(slice) => {
|
||||
latestSlice = slice;
|
||||
|
||||
Reference in New Issue
Block a user