mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
fix(panel): drop decimals at >=100s, round segmented context bar, and suppress card title over anomaly tip
This commit is contained in:
@@ -6,22 +6,25 @@
|
||||
|
||||
import { defineComponent } from '../../core/component.js';
|
||||
import { h, patchAttr, patchClasses, patchStyleVar } from '../../core/domPatch.js';
|
||||
import { formatTokens } from '../../core/formatters.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
|
||||
const SEGMENT_DEFS = [
|
||||
{ key: 'assistant', cls: 'seg-assistant', getVal: (c) => Number(c.assistantTokens || 0) },
|
||||
{ key: 'toolResults', cls: 'seg-tool-results', getVal: (c) => Number(c.toolResultsTokens || 0) },
|
||||
{ key: 'assistant', labelKey: 'ctx.ch.assistant', cls: 'seg-assistant', getVal: (c) => Number(c.assistantTokens || 0) },
|
||||
{ key: 'toolResults', labelKey: 'ctx.ch.toolResults', cls: 'seg-tool-results', getVal: (c) => Number(c.toolResultsTokens || 0) },
|
||||
{
|
||||
key: 'userInput',
|
||||
labelKey: 'ctx.ch.userInput',
|
||||
cls: 'seg-user-input',
|
||||
getVal: (c) => Number(c.userInputTokens ?? c.messagesTokens ?? 0),
|
||||
},
|
||||
{ key: 'subagent', cls: 'seg-subagent-msg', getVal: (c) => Number(c.subagentTokens || 0) },
|
||||
{ key: 'checkpoint', cls: 'seg-checkpoint', getVal: (c) => Number(c.checkpointTokens || 0) },
|
||||
{ key: 'systemPrompt', cls: 'seg-system-prompt', getVal: (c) => Number(c.systemPromptTokens || 0) },
|
||||
{ key: 'systemTools', cls: 'seg-system-tools', getVal: (c) => Number(c.systemToolsTokens || 0) },
|
||||
{ key: 'mcpTools', cls: 'seg-mcp-tools', getVal: (c) => Number(c.mcpToolsTokens || 0) },
|
||||
{ key: 'skills', cls: 'seg-skills', getVal: (c) => Number(c.skillsTokens || 0) },
|
||||
{ key: 'userRules', cls: 'seg-user-rules', getVal: (c) => Number(c.userRulesTokens || 0) },
|
||||
{ key: 'subagent', labelKey: 'ctx.ch.subagent', cls: 'seg-subagent-msg', getVal: (c) => Number(c.subagentTokens || 0) },
|
||||
{ key: 'checkpoint', labelKey: 'ctx.ch.checkpoint', cls: 'seg-checkpoint', getVal: (c) => Number(c.checkpointTokens || 0) },
|
||||
{ key: 'systemPrompt', labelKey: 'ctx.ch.systemPrompt', cls: 'seg-system-prompt', getVal: (c) => Number(c.systemPromptTokens || 0) },
|
||||
{ key: 'systemTools', labelKey: 'ctx.ch.systemTools', cls: 'seg-system-tools', getVal: (c) => Number(c.systemToolsTokens || 0) },
|
||||
{ key: 'mcpTools', labelKey: 'ctx.ch.mcpTools', cls: 'seg-mcp-tools', getVal: (c) => Number(c.mcpToolsTokens || 0) },
|
||||
{ key: 'skills', labelKey: 'ctx.ch.skills', cls: 'seg-skills', getVal: (c) => Number(c.skillsTokens || 0) },
|
||||
{ key: 'userRules', labelKey: 'ctx.ch.userRules', cls: 'seg-user-rules', getVal: (c) => Number(c.userRulesTokens || 0) },
|
||||
];
|
||||
|
||||
export const ContextSegmentMeter = defineComponent({
|
||||
@@ -35,7 +38,7 @@ export const ContextSegmentMeter = defineComponent({
|
||||
const trackEl = h(
|
||||
'div',
|
||||
{
|
||||
className: 'progress-track',
|
||||
className: 'progress-track ctx-segment-meter',
|
||||
role: 'progressbar',
|
||||
'aria-valuemin': '0',
|
||||
'aria-valuemax': '100',
|
||||
@@ -67,11 +70,23 @@ export const ContextSegmentMeter = defineComponent({
|
||||
|
||||
patchClasses(trackEl, { 'is-reordering': orderChanged });
|
||||
|
||||
let seenActive = false;
|
||||
for (let i = 0; i < slotEls.length; i++) {
|
||||
const slotEl = slotEls[i];
|
||||
const item = scored[i];
|
||||
patchAttr(slotEl, 'class', `progress-seg ${item.def.cls}`);
|
||||
patchStyleVar(slotEl, '--seg-w', `${item.pct.toFixed(2)}%`);
|
||||
const isActive = item.val > 0 && item.pct > 0;
|
||||
const hasSep = isActive && seenActive;
|
||||
if (isActive) seenActive = true;
|
||||
const cls = `progress-seg ${item.def.cls}${isActive ? ' is-active' : ''}${hasSep ? ' has-sep' : ''}`;
|
||||
patchAttr(slotEl, 'class', cls);
|
||||
patchStyleVar(slotEl, '--seg-w', isActive ? `${item.pct.toFixed(2)}%` : '0%');
|
||||
patchAttr(
|
||||
slotEl,
|
||||
'title',
|
||||
isActive
|
||||
? `${t(item.def.labelKey)} · ${formatTokens(item.val)} (${item.pct.toFixed(1)}%)`
|
||||
: null
|
||||
);
|
||||
}
|
||||
|
||||
patchAttr(trackEl, 'aria-valuenow', Math.round(ctx.compactionUsedPct ?? ctx.usedPct ?? 0));
|
||||
|
||||
Reference in New Issue
Block a user