mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): add worker hot-reload, sticky bridge lease, custom token combos, trimmed model IDs, and adaptive popover width
- Isolate SidecarApp /api/* backend runtime inside a hot-swappable Worker thread (sidecar-worker.mjs) with 3s disk-drift detection and queued request handoff so live plugin updates never drop the host-assigned SidecarApp port - Persist and reuse sticky loopback bridge port/token leases across bridge-daemon and worker reloads, pre-bind the bridge server on boot, allow /api/cache/rebuild on the bridge, and self-heal poisoned CDP fallback states back to HTTP - Add billing-aligned In / Out / Cache (tokens_io_cache) preset with per-segment USD hover breakdown and custom format DSL (tokens_custom + stepTokenComboFormat, e.g. context:new:cache, in:out:cache) - Add 3-way model name format (short / upstream / upstream_compact) stripping gemini-, claude-, and gpt- prefixes while protecting compaction suffixes from ellipsis truncation - Add adaptive content-fit popover width (auto up to viewport bounds on wide step tables) alongside custom fixed width (440-1080 px)
This commit is contained in:
@@ -35,6 +35,8 @@ import {
|
||||
formatAgentBadgeText,
|
||||
getAgentBadgeClass,
|
||||
normalizeClientHoverModules,
|
||||
normalizeClientPopoverWidth,
|
||||
normalizeClientPopoverWidthMode,
|
||||
normalizeClientTopbarSlots,
|
||||
normalizeClientUpdateMode,
|
||||
normalizeClientWindowMountMode,
|
||||
@@ -49,6 +51,8 @@ import { uiStore } from '../../store/uiStore.js';
|
||||
const CAPSULE_HOST_ID = 'ag-usage-monitor-capsule';
|
||||
const PORTAL_HOST_ID = 'ag-usage-monitor-portal';
|
||||
const FLOATING_CARD_WIDTH = 522;
|
||||
const POPOVER_BASE_WIDTH = 540;
|
||||
const POPOVER_MAX_AUTO_WIDTH = 960;
|
||||
const MULTI_PANEL_WIDTH = 464;
|
||||
|
||||
/**
|
||||
@@ -1969,11 +1973,72 @@ export function mountWindowOverlay() {
|
||||
: bRect.right;
|
||||
|
||||
if (popoverOpen) {
|
||||
const maxPopCardW = Math.max(280, vw - minLeft - 12);
|
||||
const curSettings = telemetryStore.getState().telemetry?.settings;
|
||||
const popWidthMode = normalizeClientPopoverWidthMode(curSettings?.popoverWidthMode);
|
||||
let desiredPopW = Math.min(POPOVER_BASE_WIDTH, maxPopCardW);
|
||||
if (popWidthMode === 'custom') {
|
||||
desiredPopW = Math.min(
|
||||
normalizeClientPopoverWidth(curSettings?.popoverWidth),
|
||||
maxPopCardW
|
||||
);
|
||||
} else if (typeof popoverEl.querySelectorAll === 'function') {
|
||||
const panes = popoverEl.querySelectorAll('.table-viewport.is-step-table');
|
||||
for (const pane of panes) {
|
||||
let anc = pane;
|
||||
let inHiddenTree = false;
|
||||
while (anc && anc !== popoverEl) {
|
||||
if (anc.hasAttribute?.('hidden')) {
|
||||
inHiddenTree = true;
|
||||
break;
|
||||
}
|
||||
anc = anc.parentElement || anc.parentNode;
|
||||
}
|
||||
if (inHiddenTree) continue;
|
||||
const tableEl = pane.querySelector?.('.steps-data-table') || pane.firstElementChild;
|
||||
if (!tableEl) continue;
|
||||
const paneClientW = Number(pane.clientWidth || 0);
|
||||
const curPopW = Number(
|
||||
popoverEl.offsetWidth ||
|
||||
popoverEl.getBoundingClientRect?.().width ||
|
||||
POPOVER_BASE_WIDTH
|
||||
);
|
||||
let naturalTableW = 0;
|
||||
if (tableEl.style) {
|
||||
const prevW = tableEl.style.width || '';
|
||||
tableEl.style.width = 'max-content';
|
||||
naturalTableW = Math.ceil(
|
||||
Number(
|
||||
tableEl.getBoundingClientRect?.().width ||
|
||||
tableEl.scrollWidth ||
|
||||
tableEl.offsetWidth ||
|
||||
0
|
||||
)
|
||||
);
|
||||
tableEl.style.width = prevW;
|
||||
} else {
|
||||
naturalTableW = Math.ceil(Number(tableEl.scrollWidth || tableEl.offsetWidth || 0));
|
||||
}
|
||||
if (naturalTableW > 0) {
|
||||
const chromeW =
|
||||
paneClientW > 0 && curPopW >= paneClientW
|
||||
? Math.max(24, curPopW - paneClientW)
|
||||
: 34;
|
||||
desiredPopW = Math.max(
|
||||
desiredPopW,
|
||||
Math.min(POPOVER_MAX_AUTO_WIDTH, maxPopCardW, naturalTableW + chromeW + 4)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
popoverEl.style.setProperty?.('--wm-popover-w', `${desiredPopW}px`);
|
||||
popoverEl.style.width = `${desiredPopW}px`;
|
||||
|
||||
const rawW =
|
||||
Number(popoverEl.offsetWidth) ||
|
||||
Number(popoverEl.getBoundingClientRect?.().width) ||
|
||||
defaultCardW;
|
||||
const panelW = Math.min(rawW, Math.max(280, vw - minLeft - 12));
|
||||
desiredPopW;
|
||||
const panelW = Math.min(rawW, maxPopCardW);
|
||||
const spaceBelowPop = vh - bRect.bottom - 12;
|
||||
const spaceAbovePop = bRect.top - 16;
|
||||
const openPopAbove =
|
||||
@@ -2804,6 +2869,9 @@ export function mountWindowOverlay() {
|
||||
}
|
||||
lastAppliedMountMode = nextMountMode;
|
||||
renderCapsuleTelemetry();
|
||||
if (popoverOpen) {
|
||||
positionFloatingElements();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -2811,8 +2879,25 @@ export function mountWindowOverlay() {
|
||||
(st) => ({
|
||||
selectedAgentScope: st.selectedAgentScope,
|
||||
ctxInspectorAgentId: st.ctxInspectorAgentId,
|
||||
activeView: st.activeView,
|
||||
stepsSubTab: st.stepsSubTab,
|
||||
settingsSubTab: st.settingsSubTab,
|
||||
settingsStructureTab: st.settingsStructureTab,
|
||||
}),
|
||||
() => renderCapsuleTelemetry()
|
||||
() => {
|
||||
renderCapsuleTelemetry();
|
||||
if (popoverOpen) {
|
||||
positionFloatingElements();
|
||||
if (typeof requestAnimationFrame === 'function') {
|
||||
requestAnimationFrame(() => {
|
||||
if (!disposed && popoverOpen) {
|
||||
positionFloatingElements();
|
||||
refreshActiveViewScrollbars();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const unsubI18n = i18nStore.subscribe(
|
||||
@@ -3000,10 +3085,10 @@ export function mountWindowOverlay() {
|
||||
const token = String(nextBridge.token || '');
|
||||
if (!Number.isInteger(port) || port <= 0 || !token) return false;
|
||||
const cur = window.__AGUsageMonitorBridge || {};
|
||||
const portChanged = Number(cur.port || 0) !== port;
|
||||
const portChanged = Number(cur.port || 0) !== port || String(cur.token || '') !== token;
|
||||
cur.port = port;
|
||||
cur.token = token;
|
||||
if (portChanged && cur.transportMode !== 'cdp') {
|
||||
if (portChanged) {
|
||||
cur.transportMode = 'http';
|
||||
}
|
||||
window.__AGUsageMonitorBridge = cur;
|
||||
|
||||
@@ -67,8 +67,9 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
agentBadge: '主',
|
||||
agentLabel: t('fmt.mainAgent'),
|
||||
modelLabel: 'Gemini 4 Carbon (High)',
|
||||
modelShort: 'gemini-4-carbon',
|
||||
modelShort: 'carbon-4-high',
|
||||
rawModel: 'MODEL_PLACEHOLDER_M37',
|
||||
modelUpstream: 'gemini-4-carbon-high',
|
||||
upstreamModel: 'gemini-4-carbon-high',
|
||||
tokPerSec: 68.4,
|
||||
ttftSec: 1.15,
|
||||
@@ -82,6 +83,9 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
responseTokens: 560,
|
||||
cacheHitPct: 94.5,
|
||||
costUsd: 0.042,
|
||||
inCostUsd: 0.0156,
|
||||
cacheCostUsd: 0.0134,
|
||||
outCostUsd: 0.0142,
|
||||
createdAtMs: anchorMinMs - 14_000,
|
||||
turnIndex: 2,
|
||||
rootTurnIndex: 2,
|
||||
@@ -102,8 +106,9 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
agentRole: subRole,
|
||||
agentLabel: subRole,
|
||||
modelLabel: 'Gemini 3.8 Flash',
|
||||
modelShort: 'gemini-3.8-flash',
|
||||
modelShort: 'flash-3.8',
|
||||
rawModel: 'MODEL_PLACEHOLDER_M42',
|
||||
modelUpstream: 'gemini-3.8-flash-n',
|
||||
upstreamModel: 'gemini-3.8-flash-n',
|
||||
tokPerSec: 96.2,
|
||||
ttftSec: 0.68,
|
||||
@@ -117,6 +122,9 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
responseTokens: 464,
|
||||
cacheHitPct: 88.1,
|
||||
costUsd: 0.009,
|
||||
inCostUsd: 0.0065,
|
||||
cacheCostUsd: 0.0005,
|
||||
outCostUsd: 0.0026,
|
||||
createdAtMs: anchorMinMs - 42_000,
|
||||
turnIndex: 1,
|
||||
rootTurnIndex: 2,
|
||||
@@ -135,9 +143,11 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
isSubagent: false,
|
||||
agentBadge: '主',
|
||||
agentLabel: t('fmt.mainAgent'),
|
||||
modelLabel: 'Gemini 4 Carbon (High)',
|
||||
modelShort: 'gemini-4-carbon',
|
||||
isCompactionStep: true,
|
||||
modelLabel: 'Gemini 4 Carbon (High) [自动压缩]',
|
||||
modelShort: 'carbon-4-high·压缩',
|
||||
rawModel: 'MODEL_PLACEHOLDER_M37',
|
||||
modelUpstream: 'gemini-4-carbon-high·压缩',
|
||||
upstreamModel: 'gemini-4-carbon-high',
|
||||
tokPerSec: 46.5,
|
||||
ttftSec: 3.4,
|
||||
@@ -151,6 +161,9 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
responseTokens: 380,
|
||||
cacheHitPct: 61.4,
|
||||
costUsd: 0.068,
|
||||
inCostUsd: 0.0492,
|
||||
cacheCostUsd: 0.0078,
|
||||
outCostUsd: 0.011,
|
||||
createdAtMs: anchorMinMs - 88_000,
|
||||
turnIndex: 2,
|
||||
rootTurnIndex: 2,
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
formatAgentBadgeText,
|
||||
formatAgentLabel,
|
||||
getAgentBadgeClass,
|
||||
normalizeClientStepTokenComboFormat,
|
||||
} from '../../store/telemetryStore.js';
|
||||
|
||||
export function formatTurnPromptText(rawPrompt) {
|
||||
@@ -45,17 +46,19 @@ export const StepTableWidget = defineComponent({
|
||||
const stepsTheadRow = h('tr');
|
||||
const stepsTbody = h('tbody');
|
||||
|
||||
function syncTableHeaderColumns(colKeys) {
|
||||
function syncTableHeaderColumns(colKeys, headerCtx = {}) {
|
||||
const locale = getEffectiveLocale();
|
||||
const fmtKey = normalizeClientStepTokenComboFormat(headerCtx?.stepTokenComboFormat);
|
||||
const ctx = { stepTokenComboFormat: fmtKey };
|
||||
patchKeyedList(stepsTheadRow, colKeys, {
|
||||
keyFn: (colKey) => colKey,
|
||||
sigFn: (colKey) => `${locale}:${colKey}:${STEP_COLUMN_REGISTRY[colKey].thLabel()}`,
|
||||
sigFn: (colKey) => `${locale}:${colKey}:${fmtKey}:${STEP_COLUMN_REGISTRY[colKey].thLabel(ctx)}`,
|
||||
createRow: (colKey) => {
|
||||
const th = h('th', { text: STEP_COLUMN_REGISTRY[colKey].thLabel() });
|
||||
const th = h('th', { text: STEP_COLUMN_REGISTRY[colKey].thLabel(ctx) });
|
||||
return { el: th, refs: { th } };
|
||||
},
|
||||
updateRow: (refs, colKey) => {
|
||||
patchText(refs.th, STEP_COLUMN_REGISTRY[colKey].thLabel());
|
||||
patchText(refs.th, STEP_COLUMN_REGISTRY[colKey].thLabel(ctx));
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -169,13 +172,16 @@ export const StepTableWidget = defineComponent({
|
||||
showStepTurnRail = false,
|
||||
showStepAgentBadge = true,
|
||||
showStepSpeedColor = false,
|
||||
stepTokenComboFormat = undefined,
|
||||
displaySettings = {},
|
||||
} = {}
|
||||
) {
|
||||
const colOrderSig = colKeys.join(',');
|
||||
const normTokenFmt = normalizeClientStepTokenComboFormat(stepTokenComboFormat);
|
||||
const renderOptions = JSON.stringify([
|
||||
cascadeId, locale, colOrderSig, effectiveScopes, hasSubagents, isMergedMultiAgents,
|
||||
showStepTurnRail, showStepAgentBadge, showStepSpeedColor, displaySettings.showUpstreamModel,
|
||||
showStepTurnRail, showStepAgentBadge, showStepSpeedColor, normTokenFmt,
|
||||
displaySettings.modelDisplayMode, displaySettings.showUpstreamModel,
|
||||
displaySettings.orchestratorIdMode,
|
||||
]);
|
||||
if (lastRenderOptions === renderOptions && lastRenderedRows &&
|
||||
@@ -184,13 +190,14 @@ export const StepTableWidget = defineComponent({
|
||||
return;
|
||||
}
|
||||
const wantedSet = new Set(colKeys);
|
||||
syncTableHeaderColumns(colKeys);
|
||||
syncTableHeaderColumns(colKeys, { stepTokenComboFormat: normTokenFmt });
|
||||
|
||||
const showAgentBadge = Boolean(hasSubagents && showStepAgentBadge);
|
||||
const cellCtx = {
|
||||
hasSubagents,
|
||||
showAgentBadge,
|
||||
showStepSpeedColor,
|
||||
stepTokenComboFormat: normTokenFmt,
|
||||
effectiveScopes,
|
||||
scopeSigKey: effectiveScopes.join(','),
|
||||
displaySettings,
|
||||
|
||||
Reference in New Issue
Block a user