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;
|
||||
|
||||
Reference in New Issue
Block a user