mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
perf(panel): add incremental step transport, memoized aggregation, atomic cache writes, and hidden-view gating
- Project display-only step fields in /api/telemetry, skip unchanged step payloads via stepRevision, coalesce identical client refreshes, and share in-flight backend trajectory scans across same-account requests - Reuse normalized step values and memoize up to two range aggregations in usage-aggregator gated by step timestamps, pricing revision, model overrides, timezone, and source identity; cache per-trajectory model facts and single-agent step preparation via WeakMap/WeakRef - Persist trajectory checkpoints atomically in trajectory-cache-file.mjs via chunked writevSync + renameSync while reusing serialized step byte slices for unchanged conversations - Render step turn-rail lines/dots via CSS pseudo-elements, allocate speed-reason nodes on demand, short-circuit unchanged table reconciliations, and cache per-series LOESS publication fits in SessionStepCharts - Gate DOM updates and timers across closed overlay panels, hover popups, inactive settings tabs, and unchanged ConsumptionView payloads - Distinguish canceled steps (CORTEX_STEP_STATUS_CANCELED) and untimed compaction steps from generic incomplete timing in speed-metrics and bilingual i18n labels
This commit is contained in:
@@ -29,7 +29,7 @@ import {
|
||||
import { i18nStore, isEnglishLocale, t } from '../i18n/index.js';
|
||||
import { createSvgIcon } from '../icons/SvgIcon.js';
|
||||
import { fetchTelemetry, telemetryStore } from '../store/telemetryStore.js';
|
||||
import { uiStore } from '../store/uiStore.js';
|
||||
import { getVisibleMonitorView, uiStore } from '../store/uiStore.js';
|
||||
import {
|
||||
createTrendAreaChart,
|
||||
HEATMAP_DAYS_THRESHOLD,
|
||||
@@ -506,11 +506,38 @@ export const ConsumptionView = defineComponent({
|
||||
let latestSlice = null;
|
||||
let isDirty = false;
|
||||
|
||||
let lastRenderedUsage = '';
|
||||
|
||||
/**
|
||||
* 将遥测状态切片同步渲染至消费统计视图的 5 个子面板。
|
||||
*/
|
||||
function renderConsumptionData(slice) {
|
||||
if (!slice) return;
|
||||
const cons = slice.consumption || {};
|
||||
const preset =
|
||||
slice.range !== 'custom' && cons.presets?.[slice.range]
|
||||
? cons.presets[slice.range]
|
||||
: null;
|
||||
const acct = preset?.account || cons.account || {};
|
||||
const rangeInfo = cons.selectedRange || {};
|
||||
const dateSpan = formatDateSpanBadge(rangeInfo.startMs, rangeInfo.endMs);
|
||||
const now = new Date();
|
||||
const currentMonthIdx = now.getMonth();
|
||||
const monthlyYear = cons.monthlyYear || now.getFullYear();
|
||||
const locale = i18nStore.getState().locale;
|
||||
// 额度与会话状态也会发布遥测更新,只对用量页实际展示的数据重绘。
|
||||
const signature = JSON.stringify([
|
||||
locale, slice.range, slice.customStartMs, slice.customEndMs, slice.showUpstreamModel,
|
||||
slice.orchestratorIdMode, dateSpan, preset?.label || rangeInfo.label, acct,
|
||||
cons.trendSeries, slice.modelBreakdown, cons.sourcesBreakdown,
|
||||
monthlyYear, currentMonthIdx, cons.monthlySeries,
|
||||
]);
|
||||
if (signature === lastRenderedUsage) return;
|
||||
drawConsumptionData(slice, { cons, preset, acct, rangeInfo, dateSpan, currentMonthIdx, monthlyYear });
|
||||
lastRenderedUsage = signature;
|
||||
}
|
||||
|
||||
function drawConsumptionData(slice, { cons, preset, acct, rangeInfo, dateSpan, currentMonthIdx, monthlyYear }) {
|
||||
timeFilterSwitch.setValue(slice.range);
|
||||
patchAttr(customRangeBar, 'hidden', slice.range !== 'custom');
|
||||
if (!hasUncommittedCustomDraft) {
|
||||
@@ -520,16 +547,8 @@ export const ConsumptionView = defineComponent({
|
||||
endPicker.setValue(draftEndMs);
|
||||
}
|
||||
|
||||
const cons = slice.consumption || {};
|
||||
const preset =
|
||||
slice.range !== 'custom' && cons.presets?.[slice.range]
|
||||
? cons.presets[slice.range]
|
||||
: null;
|
||||
const acct = preset?.account || cons.account || {};
|
||||
const rangeInfo = cons.selectedRange || {};
|
||||
|
||||
// 1. 同步用量概览矩阵与顶部 4 段比例条
|
||||
patchText(dateSpanBadge, formatDateSpanBadge(rangeInfo.startMs, rangeInfo.endMs));
|
||||
patchText(dateSpanBadge, dateSpan);
|
||||
const totalTokens = Number(acct.totalTokens || 0);
|
||||
const inputTokens = Number(acct.inputTokens || 0);
|
||||
const cacheTokens = Number(acct.cacheReadTokens || 0);
|
||||
@@ -656,8 +675,6 @@ export const ConsumptionView = defineComponent({
|
||||
});
|
||||
|
||||
// 5. 同步 12 个月垂直堆叠柱状图(相对于年度峰值月缩放柱高,最低保留 8% 可视高度)
|
||||
const monthlyYear = cons.monthlyYear || new Date().getFullYear();
|
||||
const currentMonthIdx = new Date().getMonth();
|
||||
patchText(monthlyYearBadge, String(monthlyYear));
|
||||
const monthlySeries = cons.monthlySeries || [];
|
||||
const maxMonthTokens = Math.max(
|
||||
@@ -718,7 +735,7 @@ export const ConsumptionView = defineComponent({
|
||||
}),
|
||||
(slice) => {
|
||||
latestSlice = slice;
|
||||
if (uiStore.getState().activeView !== 'consumption') {
|
||||
if (getVisibleMonitorView() !== 'consumption') {
|
||||
isDirty = true;
|
||||
return;
|
||||
}
|
||||
@@ -728,7 +745,7 @@ export const ConsumptionView = defineComponent({
|
||||
);
|
||||
|
||||
const unsubView = uiStore.subscribe(
|
||||
(st) => st.activeView,
|
||||
getVisibleMonitorView,
|
||||
(activeView) => {
|
||||
if (activeView === 'consumption' && isDirty) {
|
||||
isDirty = false;
|
||||
@@ -770,7 +787,7 @@ export const ConsumptionView = defineComponent({
|
||||
(st) => st.locale,
|
||||
() => {
|
||||
syncStaticLocaleLabels();
|
||||
if (uiStore.getState().activeView === 'consumption' && latestSlice) {
|
||||
if (getVisibleMonitorView() === 'consumption' && latestSlice) {
|
||||
isDirty = false;
|
||||
renderConsumptionData(latestSlice);
|
||||
} else {
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
normalizeClientOverviewModules,
|
||||
telemetryStore,
|
||||
} from '../store/telemetryStore.js';
|
||||
import { uiStore } from '../store/uiStore.js';
|
||||
import { getVisibleMonitorView, uiStore } from '../store/uiStore.js';
|
||||
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
|
||||
|
||||
export { CTX_CHANNEL_DEFS } from '../components/widgets/ContextWindowWidget.js';
|
||||
@@ -37,7 +37,7 @@ export const LiveOverviewView = defineComponent({
|
||||
const widgetHost = createDynamicWidgetHost({
|
||||
containerEl: overviewInner,
|
||||
mode: 'overview',
|
||||
isVisibleFn: () => uiStore.getState().activeView === 'overview',
|
||||
isVisibleFn: () => getVisibleMonitorView() === 'overview',
|
||||
initialModuleKeys: DEFAULT_CLIENT_OVERVIEW_MODULES,
|
||||
});
|
||||
|
||||
@@ -58,13 +58,13 @@ export const LiveOverviewView = defineComponent({
|
||||
}
|
||||
|
||||
function ensureCountdownTicker() {
|
||||
if (uiStore.getState().activeView !== 'overview') {
|
||||
if (getVisibleMonitorView() !== 'overview') {
|
||||
stopCountdownTicker();
|
||||
return;
|
||||
}
|
||||
if (!countdownTickTimer) {
|
||||
countdownTickTimer = setInterval(() => {
|
||||
if (uiStore.getState().activeView === 'overview' && latestData) {
|
||||
if (getVisibleMonitorView() === 'overview' && latestData) {
|
||||
renderData(latestData);
|
||||
}
|
||||
}, 30_000);
|
||||
@@ -88,7 +88,7 @@ export const LiveOverviewView = defineComponent({
|
||||
(st) => ({ telemetry: st.telemetry, minuteTick: st.minuteTick }),
|
||||
({ telemetry: data }) => {
|
||||
latestData = data;
|
||||
if (uiStore.getState().activeView !== 'overview') {
|
||||
if (getVisibleMonitorView() !== 'overview') {
|
||||
const stillRunning =
|
||||
(Array.isArray(data?.runningConversations) && data.runningConversations.length > 0) ||
|
||||
Boolean(
|
||||
@@ -110,7 +110,7 @@ export const LiveOverviewView = defineComponent({
|
||||
|
||||
const unsubView = uiStore.subscribe(
|
||||
(st) => ({
|
||||
activeView: st.activeView,
|
||||
activeView: getVisibleMonitorView(st),
|
||||
ctxInspectorAgentId: st.ctxInspectorAgentId,
|
||||
}),
|
||||
(slice) => {
|
||||
@@ -136,7 +136,7 @@ export const LiveOverviewView = defineComponent({
|
||||
const unsubI18n = i18nStore.subscribe(
|
||||
(st) => st.locale,
|
||||
() => {
|
||||
if (uiStore.getState().activeView !== 'overview') {
|
||||
if (getVisibleMonitorView() !== 'overview') {
|
||||
isDirty = true;
|
||||
// Refresh initial skeleton labels even before telemetry arrives
|
||||
if (!latestData) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { defineComponent } from '../core/component.js';
|
||||
import { h, patchAttr } from '../core/domPatch.js';
|
||||
import { i18nStore, t } from '../i18n/index.js';
|
||||
import { telemetryStore } from '../store/telemetryStore.js';
|
||||
import { uiStore } from '../store/uiStore.js';
|
||||
import { getVisibleMonitorView, uiStore } from '../store/uiStore.js';
|
||||
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
|
||||
import { SegmentedControl } from '../components/ui/SegmentedControl.js';
|
||||
import { SettingsAccountTab } from './settings/SettingsAccountTab.js';
|
||||
@@ -37,7 +37,7 @@ export const SettingsView = defineComponent({
|
||||
modelValue: initialSubTab,
|
||||
options: getSettingsSubTabOptions(),
|
||||
onUpdateModelValue: (nextSubTab) => {
|
||||
uiStore.setState({ settingsSubTab: nextSubTab });
|
||||
uiStore.setState({ settingsSubTab: nextSubTab }, { sync: true });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -95,20 +95,21 @@ export const SettingsView = defineComponent({
|
||||
viewScrollbar.el,
|
||||
]);
|
||||
|
||||
let latestSettings = null;
|
||||
let latestCloudStatus = null;
|
||||
let latestContextWindowModels = [];
|
||||
const initialTelemetry = telemetryStore.getState().telemetry;
|
||||
accountTab.refs.renderAccount(initialTelemetry?.account, initialTelemetry?.quotas);
|
||||
|
||||
function syncAllTabs(settings, cloudStatus) {
|
||||
if (settings) {
|
||||
generalTab.refs.renderSettings(settings);
|
||||
structureTab.refs.renderSettings(settings);
|
||||
otherTab.refs.renderSettings(settings, latestContextWindowModels);
|
||||
}
|
||||
if (cloudStatus) {
|
||||
generalTab.refs.renderCloudStatus(cloudStatus);
|
||||
function syncActiveTab() {
|
||||
const ui = uiStore.getState();
|
||||
const { settingsSubTab } = ui;
|
||||
if (getVisibleMonitorView(ui) !== 'settings') return;
|
||||
const telemetry = telemetryStore.getState().telemetry;
|
||||
const settings = telemetry?.settings;
|
||||
if (settingsSubTab === 'structure') {
|
||||
if (settings) structureTab.refs.renderSettings(settings);
|
||||
} else if (settingsSubTab === 'other') {
|
||||
if (settings) otherTab.refs.renderSettings(settings, telemetry.contextWindowModels || []);
|
||||
} else if (SHOW_ACCOUNT_TAB && settingsSubTab === 'account') {
|
||||
accountTab.refs.renderAccount(telemetry?.account, telemetry?.quotas);
|
||||
} else {
|
||||
if (settings) generalTab.refs.renderSettings(settings);
|
||||
if (telemetry?.cloudStatus) generalTab.refs.renderCloudStatus(telemetry.cloudStatus);
|
||||
}
|
||||
refreshScroll();
|
||||
}
|
||||
@@ -121,33 +122,17 @@ export const SettingsView = defineComponent({
|
||||
account: st.telemetry?.account,
|
||||
quotas: st.telemetry?.quotas,
|
||||
}),
|
||||
(slice) => {
|
||||
latestSettings = slice.settings;
|
||||
latestCloudStatus = slice.cloudStatus;
|
||||
latestContextWindowModels = slice.contextWindowModels || [];
|
||||
accountTab.refs.renderAccount(slice.account, slice.quotas);
|
||||
if (slice.settings) {
|
||||
generalTab.refs.renderSettings(slice.settings);
|
||||
structureTab.refs.renderSettings(slice.settings);
|
||||
otherTab.refs.renderSettings(slice.settings, latestContextWindowModels);
|
||||
}
|
||||
if (uiStore.getState().activeView === 'settings' && slice.cloudStatus) {
|
||||
generalTab.refs.renderCloudStatus(slice.cloudStatus);
|
||||
}
|
||||
refreshScroll();
|
||||
}
|
||||
syncActiveTab
|
||||
);
|
||||
|
||||
const unsubUi = uiStore.subscribe(
|
||||
(st) => ({
|
||||
activeView: st.activeView,
|
||||
activeView: getVisibleMonitorView(st),
|
||||
settingsSubTab: st.settingsSubTab,
|
||||
}),
|
||||
(slice) => {
|
||||
applyActiveSubTab(slice.settingsSubTab, slice.activeView);
|
||||
if (slice.activeView === 'settings') {
|
||||
syncAllTabs(latestSettings, latestCloudStatus);
|
||||
}
|
||||
syncActiveTab();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
resolveScopedConversation,
|
||||
telemetryStore,
|
||||
} from '../store/telemetryStore.js';
|
||||
import { uiStore } from '../store/uiStore.js';
|
||||
import { getVisibleMonitorView, uiStore } from '../store/uiStore.js';
|
||||
import {
|
||||
MODEL_COLOR_VARS,
|
||||
createModelFitChart,
|
||||
@@ -50,7 +50,7 @@ function mergeSelectedAgentUnits(units) {
|
||||
for (const ag of units) {
|
||||
if (!ag || typeof ag !== 'object') continue;
|
||||
if (Array.isArray(ag.recentSteps)) {
|
||||
combinedSteps.push(...ag.recentSteps);
|
||||
for (const step of ag.recentSteps) combinedSteps.push(step);
|
||||
}
|
||||
const breakdown = Array.isArray(ag.modelBreakdown) ? ag.modelBreakdown : [];
|
||||
for (const m of breakdown) {
|
||||
@@ -520,7 +520,8 @@ export const StepsDetailView = defineComponent({
|
||||
const baseScope = resolveScopedConversation(
|
||||
{ activeConversation: slice.activeConversation },
|
||||
'all',
|
||||
uiSt.ctxInspectorAgentId
|
||||
uiSt.ctxInspectorAgentId,
|
||||
true
|
||||
);
|
||||
const { hasSubagents, agents, subagents, mainAgent, aggregated } = baseScope;
|
||||
|
||||
@@ -1027,7 +1028,7 @@ export const StepsDetailView = defineComponent({
|
||||
subTabSwitch.setValue(tab);
|
||||
patchAttr(stepsScroll.el, 'hidden', tab !== 'steps');
|
||||
patchAttr(modelsScroll.el, 'hidden', tab !== 'models');
|
||||
if (uiStore.getState().activeView === 'steps' && latestSlice) {
|
||||
if (getVisibleMonitorView() === 'steps' && latestSlice) {
|
||||
renderStepsData(latestSlice);
|
||||
} else if (tab === 'steps') {
|
||||
stepsScroll.refresh();
|
||||
@@ -1053,7 +1054,7 @@ export const StepsDetailView = defineComponent({
|
||||
}),
|
||||
(slice) => {
|
||||
latestSlice = slice;
|
||||
if (uiStore.getState().activeView !== 'steps') {
|
||||
if (getVisibleMonitorView() !== 'steps') {
|
||||
if (!fitUserPicked) {
|
||||
fitPinnedWhileVisible = false;
|
||||
}
|
||||
@@ -1066,11 +1067,11 @@ export const StepsDetailView = defineComponent({
|
||||
);
|
||||
|
||||
let prevScope = uiStore.getState().selectedAgentScope;
|
||||
let prevActiveView = uiStore.getState().activeView;
|
||||
let prevActiveView = getVisibleMonitorView();
|
||||
|
||||
const unsubView = uiStore.subscribe(
|
||||
(st) => ({
|
||||
activeView: st.activeView,
|
||||
activeView: getVisibleMonitorView(st),
|
||||
selectedAgentScope: st.selectedAgentScope,
|
||||
}),
|
||||
(uiSlice) => {
|
||||
@@ -1099,7 +1100,7 @@ export const StepsDetailView = defineComponent({
|
||||
(st) => st.locale,
|
||||
() => {
|
||||
refreshStaticLocaleLabels();
|
||||
if (uiStore.getState().activeView === 'steps' && latestSlice) {
|
||||
if (getVisibleMonitorView() === 'steps' && latestSlice) {
|
||||
renderStepsData(latestSlice);
|
||||
} else {
|
||||
isDirty = true;
|
||||
|
||||
@@ -33,7 +33,7 @@ import {
|
||||
normalizeClientWindowMountMode,
|
||||
saveSettingsPatch,
|
||||
} from '../../store/telemetryStore.js';
|
||||
import { uiStore } from '../../store/uiStore.js';
|
||||
import { getVisibleMonitorView, uiStore } from '../../store/uiStore.js';
|
||||
import { CollapsibleSection } from '../../components/settings/CollapsibleSection.js';
|
||||
import { EditableSlotList } from '../../components/settings/EditableSlotList.js';
|
||||
import { buildStructurePreviewTelemetry } from '../../components/settings/structurePreviewMock.js';
|
||||
@@ -94,7 +94,7 @@ export const SettingsStructureTab = defineComponent({
|
||||
|
||||
function isStructureVisible() {
|
||||
const st = uiStore.getState();
|
||||
return st.activeView === 'settings' && st.settingsSubTab === 'structure';
|
||||
return getVisibleMonitorView(st) === 'settings' && st.settingsSubTab === 'structure';
|
||||
}
|
||||
|
||||
function buildDraftTelemetry() {
|
||||
@@ -789,7 +789,7 @@ export const SettingsStructureTab = defineComponent({
|
||||
let wasStructureVisible = isStructureVisible();
|
||||
const unsubUi = uiStore.subscribe(
|
||||
(st) => ({
|
||||
activeView: st.activeView,
|
||||
activeView: getVisibleMonitorView(st),
|
||||
settingsSubTab: st.settingsSubTab,
|
||||
settingsStructureTab: st.settingsStructureTab,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user