mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
refactor(panel): unify settings and bridge contracts, prune dead code, and rename trajectory metrics
- Share settings normalization and window-bridge protocol contracts across frontend and backend - Encapsulate trajectory cache accessors inside config.mjs and validate bundle imports/syntax before writing - Remove dead selectors, unused symbols, duplicate re-export imports, and unmounted account tab instantiation - Rename speed-metrics.mjs to trajectory-metrics.mjs and audit-fixes.test.mjs to cross-module-regressions.test.mjs
This commit is contained in:
@@ -6,6 +6,27 @@
|
||||
*/
|
||||
|
||||
import { isContextWindowSettingId, isContextWindowOption } from './context-windows.mjs';
|
||||
import {
|
||||
DEFAULT_OVERVIEW_METRICS,
|
||||
DEFAULT_TOPBAR_SLOTS,
|
||||
normalizeOverviewMetrics,
|
||||
normalizeTopbarCapsuleSlots,
|
||||
normalizeWeeklyLimitMode,
|
||||
normalizeWindowMountMode,
|
||||
} from '../shared/settings-normalization.mjs';
|
||||
|
||||
export {
|
||||
DEFAULT_OVERVIEW_METRICS,
|
||||
DEFAULT_TOPBAR_SLOTS,
|
||||
MAX_TOPBAR_SLOTS,
|
||||
MIN_TOPBAR_SLOTS,
|
||||
OVERVIEW_METRIC_KEYS,
|
||||
TOPBAR_SLOT_KEYS,
|
||||
normalizeOverviewMetrics,
|
||||
normalizeTopbarCapsuleSlots,
|
||||
normalizeWeeklyLimitMode,
|
||||
normalizeWindowMountMode,
|
||||
} from '../shared/settings-normalization.mjs';
|
||||
|
||||
export const SUPPORTED_LANGUAGES = Object.freeze(['auto', 'zh-CN', 'en-US']);
|
||||
|
||||
@@ -21,26 +42,6 @@ export const THEME_ACCENT_KEYS = Object.freeze([
|
||||
|
||||
export const FONT_SCALE_KEYS = Object.freeze(['sm', 'md', 'lg', 'xl']);
|
||||
|
||||
export const TOPBAR_SLOT_KEYS = Object.freeze([
|
||||
'context',
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'cost',
|
||||
'session_cost',
|
||||
'cache_hit',
|
||||
'session_tokens',
|
||||
'quota_auto',
|
||||
'gemini_5h',
|
||||
'gemini_weekly',
|
||||
'claude_5h',
|
||||
'claude_weekly',
|
||||
]);
|
||||
|
||||
export const DEFAULT_TOPBAR_SLOTS = Object.freeze(['tps', 'ttft', 'context']);
|
||||
export const MIN_TOPBAR_SLOTS = 1;
|
||||
export const MAX_TOPBAR_SLOTS = 5;
|
||||
|
||||
export const OVERVIEW_MODULE_KEYS = Object.freeze([
|
||||
'metrics',
|
||||
'context',
|
||||
@@ -57,25 +58,6 @@ export const DEFAULT_OVERVIEW_MODULES = Object.freeze([
|
||||
|
||||
export const DEFAULT_HOVER_MODULES = Object.freeze(['metrics', 'context', 'quotas']);
|
||||
|
||||
export const OVERVIEW_METRIC_KEYS = Object.freeze([
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'step_cost',
|
||||
'session_cost',
|
||||
'cache_hit',
|
||||
'session_tokens',
|
||||
'context_usage',
|
||||
'quota_tightest',
|
||||
]);
|
||||
|
||||
export const DEFAULT_OVERVIEW_METRICS = Object.freeze([
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'step_cost',
|
||||
]);
|
||||
|
||||
export const STEP_TABLE_COLUMN_KEYS = Object.freeze([
|
||||
'step',
|
||||
'time',
|
||||
@@ -141,14 +123,6 @@ export const STEP_TOKEN_SEGMENT_ALIASES = Object.freeze({
|
||||
'总token': 'total',
|
||||
});
|
||||
|
||||
export const PLUGIN_UPDATE_MODES = Object.freeze(['off', 'manual', 'auto']);
|
||||
|
||||
export const MODEL_DISPLAY_MODES = Object.freeze(['short', 'upstream', 'upstream_compact']);
|
||||
|
||||
export const ORCHESTRATOR_ID_MODES = Object.freeze(['compact', 'full']);
|
||||
|
||||
export const WINDOW_MOUNT_MODES = Object.freeze(['dual', 'composer', 'sidebar']);
|
||||
|
||||
export const POPOVER_WIDTH_MODES = Object.freeze(['auto', 'custom']);
|
||||
export const MIN_POPOVER_WIDTH = 440;
|
||||
export const MAX_POPOVER_WIDTH = 1080;
|
||||
@@ -201,23 +175,6 @@ export function normalizeFontScale(scale) {
|
||||
return FONT_SCALE_KEYS.includes(clean) ? /** @type {any} */ (clean) : 'md';
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化面板挂载方式枚举(`'dual'` 顶部栏+侧边栏 | `'composer'` 输入框+侧边栏 | `'sidebar'` 仅侧边栏),
|
||||
* 兼容历史 `enableWindowOverlay` 布尔开关,默认 `'dual'`。
|
||||
*
|
||||
* @param {unknown} mode
|
||||
* @param {unknown} [legacyEnableOverlay]
|
||||
* @returns {'dual'|'composer'|'sidebar'}
|
||||
*/
|
||||
export function normalizeWindowMountMode(mode, legacyEnableOverlay) {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
if (m === 'composer' || m === 'input') return 'composer';
|
||||
if (m === 'sidebar' || m === 'sidebar_only' || m === 'off') return 'sidebar';
|
||||
if (m === 'dual' || m === 'topbar') return 'dual';
|
||||
if (legacyEnableOverlay === false) return 'sidebar';
|
||||
return 'dual';
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化模型名称展示模式(`'short'` 精简代号 | `'upstream_compact'` 去前缀原始 ID | `'upstream'` 完整原始 ID),
|
||||
* 兼容历史 `showUpstreamModel` 布尔开关,默认 `'short'`。
|
||||
@@ -321,46 +278,6 @@ export function normalizePluginUpdateMode(mode, legacyAutoUpdate) {
|
||||
return 'manual';
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化每周额度统计模式枚举(兼容历史简写 `'tokens'` / `'cost'` 与标准枚举 `'custom_tokens'` / `'custom_cost'`)。
|
||||
*
|
||||
* @param {unknown} mode
|
||||
* @returns {'official'|'custom_tokens'|'custom_cost'}
|
||||
*/
|
||||
export function normalizeWeeklyLimitMode(mode) {
|
||||
const m = String(mode || '').trim().toLowerCase();
|
||||
if (m === 'custom_tokens' || m === 'tokens') return 'custom_tokens';
|
||||
if (m === 'custom_cost' || m === 'cost') return 'custom_cost';
|
||||
return 'official';
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化顶栏/输入框胶囊槽位数组(1~5 项动态自添加,默认 3 项,自动清洗历史 `'none'` 与重复项)。
|
||||
*
|
||||
* @param {unknown} raw
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function normalizeTopbarCapsuleSlots(raw) {
|
||||
if (!Array.isArray(raw)) {
|
||||
return [...DEFAULT_TOPBAR_SLOTS];
|
||||
}
|
||||
const seen = new Set();
|
||||
const out = [];
|
||||
for (const item of raw) {
|
||||
const val = String(item ?? '').trim();
|
||||
if (!val || val === 'none') continue;
|
||||
const mapped = val === 'step_cost' ? 'cost' : val;
|
||||
if (!TOPBAR_SLOT_KEYS.includes(mapped) || seen.has(mapped)) continue;
|
||||
seen.add(mapped);
|
||||
out.push(mapped);
|
||||
if (out.length >= MAX_TOPBAR_SLOTS) break;
|
||||
}
|
||||
if (out.length < MIN_TOPBAR_SLOTS) {
|
||||
return ['context'];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化实时监控视图展示的模块及上下顺序(1~4 项,默认 4 项全开)。
|
||||
*
|
||||
@@ -405,29 +322,6 @@ export function normalizeHoverModules(raw) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化实时监控第一行指标矩阵的槽位与顺序(1~4 项,默认 4 项)。
|
||||
*
|
||||
* @param {unknown} raw
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function normalizeOverviewMetrics(raw) {
|
||||
if (!Array.isArray(raw)) {
|
||||
return [...DEFAULT_OVERVIEW_METRICS];
|
||||
}
|
||||
const seen = new Set();
|
||||
const out = [];
|
||||
for (const item of raw) {
|
||||
const rawVal = String(item ?? '').trim();
|
||||
const val = rawVal === 'cost' ? 'step_cost' : rawVal;
|
||||
if (!OVERVIEW_METRIC_KEYS.includes(val) || seen.has(val)) continue;
|
||||
seen.add(val);
|
||||
out.push(val);
|
||||
if (out.length >= 4) break;
|
||||
}
|
||||
return out.length > 0 ? out : ['tps'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化调用明细「按步查看」表格列配置与左右顺序(2~12 列,默认保留现有 7 列)。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user