mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
fix: preserve unknown model identity and pending costs
This commit is contained in:
@@ -37,18 +37,20 @@ export function formatDateSpanBadge(startMs, endMs) {
|
||||
return `${s.getMonth() + 1}月${s.getDate()}日 ~ ${e.getMonth() + 1}月${e.getDate()}日`;
|
||||
}
|
||||
|
||||
export function formatUsd(amount, { precise = false, estimated = false } = {}) {
|
||||
export function formatUsd(amount, { precise = false, estimated = false, unpricedCalls = 0 } = {}) {
|
||||
if (amount == null || !Number.isFinite(Number(amount))) return '待定';
|
||||
const val = Number(amount || 0);
|
||||
const prefix = estimated ? '≈$' : '$';
|
||||
const suffix = unpricedCalls > 0 ? ' + 待定' : '';
|
||||
if (precise) {
|
||||
return val >= 1 ? `${prefix}${val.toFixed(2)}` : `${prefix}${val.toFixed(3)}`;
|
||||
return (val >= 1 ? `${prefix}${val.toFixed(2)}` : `${prefix}${val.toFixed(3)}`) + suffix;
|
||||
}
|
||||
return `${prefix}${val.toFixed(2)}`;
|
||||
return `${prefix}${val.toFixed(2)}${suffix}`;
|
||||
}
|
||||
|
||||
export function speedReasonText(reason) {
|
||||
return ({
|
||||
compaction: '自动压缩不计测速',
|
||||
compaction: '自动压缩不计均速',
|
||||
incomplete_or_invalid_timing: '未完成或计时缺失',
|
||||
invalid_output_tokens: '输出 Token 计数无效',
|
||||
inconsistent_timing: '原生首响应与总计时不一致',
|
||||
|
||||
@@ -34,6 +34,8 @@ function isEquivalentTelemetry(prev, next) {
|
||||
if (pAct?.isRunning !== nAct?.isRunning) return false;
|
||||
if (pAct?.latestTokPerSec !== nAct?.latestTokPerSec) return false;
|
||||
if (pAct?.latestTtftSec !== nAct?.latestTtftSec) return false;
|
||||
if (pAct?.activeModelShort !== nAct?.activeModelShort || pAct?.activeModelLabel !== nAct?.activeModelLabel) return false;
|
||||
if (pAct?.latestStepCostUsd !== nAct?.latestStepCostUsd || pAct?.sessionUnpricedCalls !== nAct?.sessionUnpricedCalls) return false;
|
||||
const pCtx = pAct?.context;
|
||||
const nCtx = nAct?.context;
|
||||
if (pCtx?.totalTokens !== nCtx?.totalTokens) return false;
|
||||
@@ -44,6 +46,11 @@ function isEquivalentTelemetry(prev, next) {
|
||||
if (pCtx?.systemPromptTokens !== nCtx?.systemPromptTokens) return false;
|
||||
if (pCtx?.userRulesTokens !== nCtx?.userRulesTokens) return false;
|
||||
if ((pAct?.recentSteps?.length || 0) !== (nAct?.recentSteps?.length || 0)) return false;
|
||||
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.modelSource !== after.modelSource || before.costUsd !== after.costUsd) return false;
|
||||
}
|
||||
|
||||
const pRange = prev.consumption?.selectedRange;
|
||||
const nRange = next.consumption?.selectedRange;
|
||||
@@ -56,12 +63,14 @@ function isEquivalentTelemetry(prev, next) {
|
||||
const nCons = next.consumption?.session;
|
||||
if (pCons?.totalTokens !== nCons?.totalTokens) return false;
|
||||
if (pCons?.costUsd !== nCons?.costUsd) return false;
|
||||
if (pCons?.unpricedCalls !== nCons?.unpricedCalls) return false;
|
||||
|
||||
const pAcct = prev.consumption?.account;
|
||||
const nAcct = next.consumption?.account;
|
||||
if (pAcct?.totalTokens !== nAcct?.totalTokens) return false;
|
||||
if (pAcct?.calls !== nAcct?.calls) return false;
|
||||
if (pAcct?.costUsd !== nAcct?.costUsd) return false;
|
||||
if (pAcct?.unpricedCalls !== nAcct?.unpricedCalls) return false;
|
||||
|
||||
const pTrend = prev.consumption?.trendSeries || [];
|
||||
const nTrend = next.consumption?.trendSeries || [];
|
||||
@@ -78,6 +87,9 @@ function isEquivalentTelemetry(prev, next) {
|
||||
for (let i = 0; i < pModels.length; i++) {
|
||||
if (
|
||||
pModels[i]?.label !== nModels[i]?.label ||
|
||||
pModels[i]?.shortName !== nModels[i]?.shortName ||
|
||||
pModels[i]?.costUsd !== nModels[i]?.costUsd ||
|
||||
pModels[i]?.unpricedCalls !== nModels[i]?.unpricedCalls ||
|
||||
pModels[i]?.totalTokens !== nModels[i]?.totalTokens ||
|
||||
pModels[i]?.calls !== nModels[i]?.calls
|
||||
) {
|
||||
@@ -91,6 +103,8 @@ function isEquivalentTelemetry(prev, next) {
|
||||
for (let i = 0; i < pSources.length; i++) {
|
||||
if (
|
||||
pSources[i]?.name !== nSources[i]?.name ||
|
||||
pSources[i]?.costUsd !== nSources[i]?.costUsd ||
|
||||
pSources[i]?.unpricedCalls !== nSources[i]?.unpricedCalls ||
|
||||
pSources[i]?.totalTokens !== nSources[i]?.totalTokens ||
|
||||
pSources[i]?.calls !== nSources[i]?.calls
|
||||
) {
|
||||
|
||||
@@ -521,7 +521,7 @@ export const ConsumptionView = defineComponent({
|
||||
patchText(refs.pctBadge, `${share.toFixed(1)}%`);
|
||||
patchText(refs.totalTokEl, showTokensInHeader ? formatTokensPrecise(total) : '');
|
||||
patchAttr(refs.totalTokEl, 'hidden', !showTokensInHeader);
|
||||
patchText(refs.costEl, formatUsd(item.costUsd || 0));
|
||||
patchText(refs.costEl, formatUsd(item.costUsd || 0, { unpricedCalls: item.unpricedCalls }));
|
||||
|
||||
const responseTok =
|
||||
item.responseTokens != null
|
||||
@@ -573,8 +573,8 @@ export const ConsumptionView = defineComponent({
|
||||
|
||||
patchText(heroTotalTokens, formatTokensPrecise(totalTokens));
|
||||
patchText(heroTotalCalls, `${acct.calls || 0} 调用`);
|
||||
patchText(heroCostUsd, formatUsd(costUsd));
|
||||
patchText(heroCostCny, formatCnyApprox(costUsd));
|
||||
patchText(heroCostUsd, formatUsd(costUsd, { unpricedCalls: acct.unpricedCalls }));
|
||||
patchText(heroCostCny, acct.unpricedCalls > 0 ? `${acct.unpricedCalls} 步费用待定` : formatCnyApprox(costUsd));
|
||||
|
||||
patchText(cacheHitPctEl, `${Number(acct.cacheHitPct ?? 0).toFixed(1)}%`);
|
||||
patchText(cacheTokensEl, `命中 ${formatTokensPrecise(cacheTokens)}`);
|
||||
@@ -627,7 +627,7 @@ export const ConsumptionView = defineComponent({
|
||||
patchKeyedList(modelsListEl, models, {
|
||||
keyFn: (m) => m.label || m.shortName,
|
||||
sigFn: (m) =>
|
||||
`${m.label}:${m.totalTokens}:${m.costUsd}:${m.calls}:${modelsTotalTok}`,
|
||||
`${m.label}:${m.totalTokens}:${m.costUsd}:${m.unpricedCalls}:${m.calls}:${modelsTotalTok}`,
|
||||
createRow: createBreakdownItemRow,
|
||||
updateRow: (refs, m) => updateBreakdownItemRow(refs, m, modelsTotalTok, true),
|
||||
});
|
||||
@@ -637,7 +637,7 @@ export const ConsumptionView = defineComponent({
|
||||
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}`,
|
||||
sigFn: (s) => `${s.name}:${s.totalTokens}:${s.costUsd}:${s.unpricedCalls}:${s.calls}:${sourcesTotalTok}`,
|
||||
createRow: createBreakdownItemRow,
|
||||
updateRow: (refs, s) => updateBreakdownItemRow(refs, s, sourcesTotalTok, true),
|
||||
});
|
||||
@@ -667,7 +667,8 @@ export const ConsumptionView = defineComponent({
|
||||
patchText(col.tokText, '');
|
||||
} else {
|
||||
const cVal = Number(m.costUsd || 0);
|
||||
patchText(col.costText, cVal >= 10 ? `$${Math.round(cVal)}` : `$${cVal.toFixed(2)}`);
|
||||
patchText(col.costText, m.unpricedCalls > 0 ? formatUsd(cVal, { unpricedCalls: m.unpricedCalls })
|
||||
: cVal >= 10 ? `$${Math.round(cVal)}` : `$${cVal.toFixed(2)}`);
|
||||
patchText(col.tokText, formatTokensPrecise(mTot));
|
||||
|
||||
const totalHeightPct = Math.max(8, Math.min(100, (mTot / maxMonthTokens) * 100));
|
||||
|
||||
@@ -31,7 +31,7 @@ export const LiveOverviewView = defineComponent({
|
||||
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 tpsSub = h('span', { className: 'cell-sub', text: '模型未知' });
|
||||
const pulseDot = createSvgIcon('dot', { size: 10 });
|
||||
|
||||
const ttftVal = h('strong', { className: 'cell-value', text: '—' });
|
||||
@@ -265,7 +265,7 @@ export const LiveOverviewView = defineComponent({
|
||||
const reason = speedReasonText(active.latestSpeedReason);
|
||||
patchText(
|
||||
tpsSub,
|
||||
reason ? `${active.activeModelShort || 'argon-4'} · ${reason}` : active.activeModelShort || 'argon-4'
|
||||
reason ? `${active.activeModelShort || '模型未知'} · ${reason}` : active.activeModelShort || '模型未知'
|
||||
);
|
||||
|
||||
patchText(ttftVal, formatMetric(active.latestTtftSec, 's'));
|
||||
@@ -274,11 +274,11 @@ export const LiveOverviewView = defineComponent({
|
||||
patchText(avgVal, formatMetric(active.avgTokPerSec, ' tok/s'));
|
||||
patchText(avgSub, `有效 ${sampleSummary(active.speedSummary)}`);
|
||||
|
||||
const stepCost = Number(active.latestStepCostUsd ?? active.recentSteps?.[0]?.costUsd ?? 0);
|
||||
const stepCost = active.latestStepCostUsd;
|
||||
patchText(costVal, formatUsd(stepCost, { precise: true }));
|
||||
patchText(
|
||||
cacheSub,
|
||||
`缓 ${active.latestCacheHitPct ?? 0}% · 累 ${formatUsd(active.sessionCostUsd || 0)}`
|
||||
`缓 ${active.latestCacheHitPct ?? 0}% · 累 ${formatUsd(active.sessionCostUsd || 0, { unpricedCalls: active.sessionUnpricedCalls })}`
|
||||
);
|
||||
|
||||
// 2. Context (Auto Compaction Baseline)
|
||||
@@ -313,16 +313,17 @@ export const LiveOverviewView = defineComponent({
|
||||
{};
|
||||
const claudePool =
|
||||
pools.find((p) => p.family === 'Claude & GPT' || p.family === 'Claude') ||
|
||||
(activePool.family && activePool.family !== 'Gemini' ? activePool : null) ||
|
||||
(['Claude & GPT', 'Claude', 'GPT'].includes(activePool.family) ? activePool : null) ||
|
||||
{};
|
||||
|
||||
const activeIsGemini = (activePool.family || 'Gemini') === 'Gemini';
|
||||
const activeIsGemini = activePool.family === 'Gemini';
|
||||
const activeIsThirdParty = ['Claude & GPT', 'Claude', 'GPT'].includes(activePool.family);
|
||||
syncPoolQuotaBlock(geminiQuotaBlock, 'Gemini', geminiPool, weekly, activeIsGemini);
|
||||
syncPoolQuotaBlock(claudeQuotaBlock, 'Claude & GPT', claudePool, weekly, !activeIsGemini);
|
||||
syncPoolQuotaBlock(claudeQuotaBlock, 'Claude & GPT', claudePool, weekly, activeIsThirdParty);
|
||||
|
||||
patchText(
|
||||
wkFootLeft,
|
||||
`本周本机: ${formatTokens(weekly.tokens || 0)} (${formatUsd(weekly.costUsd || 0)})`
|
||||
`本周本机: ${formatTokens(weekly.tokens || 0)} (${formatUsd(weekly.costUsd || 0, { unpricedCalls: weekly.unpricedCalls })})`
|
||||
);
|
||||
patchText(
|
||||
wkFootRight,
|
||||
|
||||
@@ -189,7 +189,7 @@ export const StepsDetailView = defineComponent({
|
||||
);
|
||||
patchText(refs.tdCache, `${Number(st.cacheHitPct ?? 0)}%`);
|
||||
|
||||
const costVal = Number(st.costUsd || 0);
|
||||
const costVal = st.costUsd;
|
||||
patchText(refs.tdCost, formatUsd(costVal, { precise: true }));
|
||||
patchClasses(refs.tdCost, { 'accent-speed': costVal >= 0.15 });
|
||||
},
|
||||
@@ -198,7 +198,7 @@ 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.speedSummary?.sampleCount}`,
|
||||
`${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 tdCalls = h('td');
|
||||
@@ -219,7 +219,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 || 0, { estimated: m.isEstimatedPrice }));
|
||||
patchText(refs.tdCost, formatUsd(m.costUsd, { estimated: m.isEstimatedPrice, unpricedCalls: m.unpricedCalls }));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user