mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
refactor(panel): complete shared single-source rules, isolate per-module bundle scopes, and purify scoped selector
This commit is contained in:
@@ -27,7 +27,9 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
totalTokens: 142800,
|
||||
limitTokens: 256000,
|
||||
compactionLimitTokens: 256000,
|
||||
compactionUsedTokens: 142800,
|
||||
usedPct: 55.8,
|
||||
messagesTokens: 119660,
|
||||
toolResultsTokens: 86400,
|
||||
assistantTokens: 24200,
|
||||
systemToolsTokens: 11800,
|
||||
@@ -44,7 +46,9 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
totalTokens: 72704,
|
||||
limitTokens: 256000,
|
||||
compactionLimitTokens: 256000,
|
||||
compactionUsedTokens: 72704,
|
||||
usedPct: 28.4,
|
||||
messagesTokens: 63704,
|
||||
toolResultsTokens: 51200,
|
||||
assistantTokens: 11400,
|
||||
systemToolsTokens: 5600,
|
||||
@@ -198,6 +202,9 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
responseTokens: 260,
|
||||
cacheHitPct: 0,
|
||||
costUsd: 0.198,
|
||||
inCostUsd: 0.19,
|
||||
cacheCostUsd: 0,
|
||||
outCostUsd: 0.008,
|
||||
createdAtMs: anchorMinMs - 215_000,
|
||||
turnIndex: 1,
|
||||
rootTurnIndex: 1,
|
||||
@@ -241,6 +248,24 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
latestUpstreamModel: 'gemini-4-carbon-high',
|
||||
activeModelLabel: 'Gemini 4 Carbon (High)',
|
||||
activeModelShort: 'gemini-4-carbon',
|
||||
activeModelUpstream: 'gemini-4-carbon-high',
|
||||
sessionUnpricedCalls: 0,
|
||||
modelBreakdown: [
|
||||
{
|
||||
modelKey: 'MODEL_PLACEHOLDER_M37',
|
||||
modelShort: 'gemini-4-carbon',
|
||||
modelLabel: 'Gemini 4 Carbon (High)',
|
||||
upstreamModel: 'gemini-4-carbon-high',
|
||||
calls: 16,
|
||||
inputTokens: 152400,
|
||||
cacheReadTokens: 1260000,
|
||||
outputTokens: 22100,
|
||||
thinkingTokens: 14200,
|
||||
totalTokens: 1434500,
|
||||
costUsd: 1.16,
|
||||
sharePct: 100,
|
||||
},
|
||||
],
|
||||
context: mainContext,
|
||||
recentSteps: mockSteps.filter((s) => !s.isSubagent),
|
||||
};
|
||||
@@ -277,12 +302,34 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
latestUpstreamModel: 'gemini-3.8-flash-n',
|
||||
activeModelLabel: 'Gemini 3.8 Flash',
|
||||
activeModelShort: 'gemini-3.8-flash',
|
||||
activeModelUpstream: 'gemini-3.8-flash-n',
|
||||
sessionUnpricedCalls: 0,
|
||||
modelBreakdown: [
|
||||
{
|
||||
modelKey: 'MODEL_PLACEHOLDER_M42',
|
||||
modelShort: 'gemini-3.8-flash',
|
||||
modelLabel: 'Gemini 3.8 Flash',
|
||||
upstreamModel: 'gemini-3.8-flash-n',
|
||||
calls: 8,
|
||||
inputTokens: 34000,
|
||||
cacheReadTokens: 280000,
|
||||
outputTokens: 6300,
|
||||
thinkingTokens: 2100,
|
||||
totalTokens: 320300,
|
||||
costUsd: 0.12,
|
||||
sharePct: 100,
|
||||
},
|
||||
],
|
||||
context: subContext,
|
||||
recentSteps: mockSteps.filter((s) => s.isSubagent),
|
||||
};
|
||||
|
||||
const aggregated = {
|
||||
...mainAgent,
|
||||
agentId: 'all',
|
||||
isMain: false,
|
||||
badgeText: '全部',
|
||||
activeAgentId: 'main',
|
||||
stepCount: 24,
|
||||
speedSampleCount: 23,
|
||||
speedSummary: { sampleCount: 23, excludedCount: 1 },
|
||||
@@ -290,12 +337,14 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
avgTtftSec: 1.38,
|
||||
ttftSummary: { avgSec: 1.38, sampleCount: 23 },
|
||||
sessionCostUsd: 1.28,
|
||||
sessionUnpricedCalls: 0,
|
||||
sessionCacheHitPct: 88.9,
|
||||
inputTokens: 186400,
|
||||
cacheReadTokens: 1540000,
|
||||
outputTokens: 28400,
|
||||
totalTokens: 1754800,
|
||||
activeAgentBadge: '主',
|
||||
modelBreakdown: [...mainAgent.modelBreakdown, ...subAgent1.modelBreakdown],
|
||||
recentSteps: mockSteps,
|
||||
};
|
||||
|
||||
@@ -307,6 +356,11 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
aiCredits: 0,
|
||||
},
|
||||
quotas: {
|
||||
meta: {
|
||||
hasOfficialData: true,
|
||||
isStale: false,
|
||||
refreshFailed: false,
|
||||
},
|
||||
activePool: {
|
||||
family: 'Gemini',
|
||||
poolKey: 'Gemini',
|
||||
|
||||
@@ -4,6 +4,17 @@
|
||||
*/
|
||||
|
||||
import { isEnglishLocale, t } from '../i18n/index.js';
|
||||
import {
|
||||
normalizeModelDisplayMode,
|
||||
normalizeOrchestratorIdMode,
|
||||
} from '../../shared/settings-normalization.mjs';
|
||||
import {
|
||||
classifyCacheTier,
|
||||
classifySpeedTier,
|
||||
classifyStepCostTier,
|
||||
classifyTtftTier,
|
||||
formatCompactTokens,
|
||||
} from '../../shared/telemetry-display-rules.mjs';
|
||||
|
||||
const EN_MONTH_SHORT = Object.freeze([
|
||||
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||
@@ -21,53 +32,24 @@ export function formatCachePct(value) {
|
||||
}
|
||||
|
||||
export function getSpeedToneClass(tokPerSec) {
|
||||
if (tokPerSec == null || !Number.isFinite(Number(tokPerSec)) || Number(tokPerSec) <= 0) {
|
||||
return 'tone-muted';
|
||||
}
|
||||
const v = Number(tokPerSec);
|
||||
if (v >= 60) return 'tone-good';
|
||||
if (v >= 35) return 'tone-info';
|
||||
if (v >= 20) return 'tone-warn';
|
||||
return 'tone-danger';
|
||||
return `tone-${classifySpeedTier(tokPerSec)}`;
|
||||
}
|
||||
|
||||
export function getCacheToneClass(cacheHitPct, promptTokens = null) {
|
||||
if (cacheHitPct == null || !Number.isFinite(Number(cacheHitPct))) {
|
||||
return 'tone-muted';
|
||||
}
|
||||
const v = Number(cacheHitPct);
|
||||
if (promptTokens != null && Number(promptTokens) <= 0 && v <= 0) {
|
||||
return 'tone-muted';
|
||||
}
|
||||
if (v >= 85) return 'tone-good';
|
||||
if (v >= 65) return 'tone-info';
|
||||
if (v >= 30) return 'tone-warn';
|
||||
return 'tone-danger';
|
||||
return `tone-${classifyCacheTier(cacheHitPct, promptTokens)}`;
|
||||
}
|
||||
|
||||
export function getStepCostToneClass(costUsd) {
|
||||
if (costUsd == null || !Number.isFinite(Number(costUsd))) return '';
|
||||
const v = Number(costUsd);
|
||||
if (v >= 0.3) return 'tone-danger';
|
||||
if (v >= 0.15) return 'tone-warn';
|
||||
return '';
|
||||
const tier = classifyStepCostTier(costUsd);
|
||||
return tier ? `tone-${tier}` : '';
|
||||
}
|
||||
|
||||
export function getTtftToneClass(ttftSec) {
|
||||
if (ttftSec == null || !Number.isFinite(Number(ttftSec)) || Number(ttftSec) < 0) return '';
|
||||
const v = Number(ttftSec);
|
||||
if (v >= 30) return 'tone-danger';
|
||||
if (v >= 18) return 'tone-warn';
|
||||
return '';
|
||||
const tier = classifyTtftTier(ttftSec);
|
||||
return tier === 'warn' || tier === 'danger' ? `tone-${tier}` : '';
|
||||
}
|
||||
|
||||
export function formatTokens(num) {
|
||||
const n = Number(num || 0);
|
||||
if (n >= 1_000_000_000) return `${(n / 1_000_000_000).toFixed(2)}B`;
|
||||
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
|
||||
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`;
|
||||
return String(Math.round(n));
|
||||
}
|
||||
export const formatTokens = formatCompactTokens;
|
||||
|
||||
export function formatTokensPrecise(num) {
|
||||
const n = Number(num || 0);
|
||||
@@ -172,23 +154,7 @@ export function formatElapsedSec(seconds) {
|
||||
return `${h}h ${remM}m`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化普通模型显示模式(`'short'` 精简代号 | `'upstream_compact'` 去厂商前缀原始 ID | `'upstream'` 完整原始 ID)。
|
||||
*
|
||||
* @param {unknown} mode
|
||||
* @param {unknown} [legacyShowUpstream]
|
||||
* @returns {'short'|'upstream_compact'|'upstream'}
|
||||
*/
|
||||
export function normalizeModelDisplayMode(mode, legacyShowUpstream) {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
if (m === 'upstream' || m === 'raw' || m === 'full') return 'upstream';
|
||||
if (m === 'upstream_compact' || m === 'compact_upstream' || m === 'trimmed') {
|
||||
return 'upstream_compact';
|
||||
}
|
||||
if (m === 'short') return 'short';
|
||||
if (legacyShowUpstream === true) return 'upstream';
|
||||
return 'short';
|
||||
}
|
||||
export { normalizeModelDisplayMode };
|
||||
|
||||
/**
|
||||
* 隐藏原始模型 ID 开头的 `gemini-`、`claude-`、`gpt-` 厂商前缀以节省单行表格空间(确保剥离后非空)。
|
||||
@@ -208,15 +174,7 @@ function stripCompactionMarker(rawText) {
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化 Orchestrator 系列 ID 显示格式枚举(`'compact'` 精简代号 vs `'full'` 原始完整 ID,默认 `'compact'`)。
|
||||
*
|
||||
* @param {unknown} mode
|
||||
* @returns {'compact'|'full'}
|
||||
*/
|
||||
export function normalizeOrchestratorIdDisplayMode(mode) {
|
||||
return String(mode ?? '').trim().toLowerCase() === 'full' ? 'full' : 'compact';
|
||||
}
|
||||
export const normalizeOrchestratorIdDisplayMode = normalizeOrchestratorIdMode;
|
||||
|
||||
/**
|
||||
* 统一解析步骤、会话摘要或模型汇总行面向用户的模型显示文本与悬停提示。
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import { createReactiveStore } from '../core/reactive.js';
|
||||
import { normalizeLanguageSetting } from '../../shared/settings-normalization.mjs';
|
||||
import { I18N_MESSAGES_ZH_CN } from './zh-CN.js';
|
||||
import { I18N_MESSAGES_EN_US } from './en-US.js';
|
||||
|
||||
@@ -13,11 +14,7 @@ export const I18N_DICTIONARIES = Object.freeze({
|
||||
});
|
||||
|
||||
export function normalizeI18nLanguage(raw) {
|
||||
const val = String(raw ?? '').trim();
|
||||
if (val === 'auto') return 'auto';
|
||||
if (/^en(?:-|$)/i.test(val)) return 'en-US';
|
||||
if (/^zh(?:-|$)/i.test(val)) return 'zh-CN';
|
||||
return 'zh-CN';
|
||||
return normalizeLanguageSetting(raw);
|
||||
}
|
||||
|
||||
export function detectHostSystemLocale() {
|
||||
|
||||
@@ -19,14 +19,16 @@ import {
|
||||
speedReasonText,
|
||||
} from '../core/formatters.js';
|
||||
import { isEnglishLocale, t } from '../i18n/index.js';
|
||||
|
||||
import { OVERVIEW_METRIC_KEYS, TOPBAR_SLOT_KEYS } from '../../shared/settings-normalization.mjs';
|
||||
import {
|
||||
formatCompactCapsuleCost,
|
||||
formatCompactCapsuleTtft,
|
||||
resolveCapsuleQuotaSlotPct,
|
||||
} from '../../shared/telemetry-display-rules.mjs';
|
||||
|
||||
export { OVERVIEW_METRIC_KEYS };
|
||||
export { OVERVIEW_METRIC_KEYS, formatCompactCapsuleCost, formatCompactCapsuleTtft };
|
||||
export const CAPSULE_METRIC_KEYS = TOPBAR_SLOT_KEYS;
|
||||
|
||||
const THIRD_PARTY_FAMILY_RE = /claude|gpt|anthropic|openai|3p|sonnet|opus|haiku/i;
|
||||
|
||||
export function getCapsuleMetricOptions() {
|
||||
return CAPSULE_METRIC_KEYS.map((key) => ({
|
||||
value: key,
|
||||
@@ -114,98 +116,14 @@ export function resolveQuotaCapsuleSummary(quotas) {
|
||||
* @returns {{ roundedPct: number, shortText: string } | null}
|
||||
*/
|
||||
export function resolveSpecificQuotaSlotSummary(quotas, slotKey) {
|
||||
if (!quotas) return null;
|
||||
const pools = Array.isArray(quotas.pools) ? quotas.pools : [];
|
||||
const activePool = quotas.activePool || null;
|
||||
const isClaude = slotKey.startsWith('claude_');
|
||||
const isWeekly = slotKey.endsWith('_weekly');
|
||||
let rawPct = null;
|
||||
|
||||
if (isClaude) {
|
||||
const claudePool =
|
||||
pools.find((p) => p?.poolKey === 'Claude & GPT') ||
|
||||
pools.find((p) => THIRD_PARTY_FAMILY_RE.test(String(p?.poolKey || p?.poolLabel || '')));
|
||||
const cand = isWeekly ? claudePool?.weeklyRemainingPct : claudePool?.remainingPct;
|
||||
if (cand != null && Number.isFinite(Number(cand))) {
|
||||
rawPct = Number(cand);
|
||||
} else if (
|
||||
activePool &&
|
||||
THIRD_PARTY_FAMILY_RE.test(String(activePool.family || activePool.poolLabel || ''))
|
||||
) {
|
||||
const fb = isWeekly ? activePool.weeklyRemainingPct : activePool.remainingPct;
|
||||
if (fb != null && Number.isFinite(Number(fb))) {
|
||||
rawPct = Number(fb);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const stdGemini =
|
||||
pools.find((p) => p?.poolKey === 'Gemini') ||
|
||||
pools.find(
|
||||
(p) =>
|
||||
/gemini/i.test(String(p?.poolKey || p?.poolLabel || '')) &&
|
||||
!/carbon|argon/i.test(String(p?.poolKey || ''))
|
||||
);
|
||||
const geminiFamilyPools = pools.filter((p) =>
|
||||
/gemini|carbon|argon/i.test(String(p?.poolKey || p?.poolLabel || ''))
|
||||
);
|
||||
const primaryCand = isWeekly ? stdGemini?.weeklyRemainingPct : stdGemini?.remainingPct;
|
||||
if (primaryCand != null && Number.isFinite(Number(primaryCand))) {
|
||||
rawPct = Number(primaryCand);
|
||||
} else {
|
||||
const familyVals = geminiFamilyPools
|
||||
.map((p) => (isWeekly ? p?.weeklyRemainingPct : p?.remainingPct))
|
||||
.filter((v) => v != null && Number.isFinite(Number(v)))
|
||||
.map(Number);
|
||||
if (familyVals.length > 0) {
|
||||
rawPct = Math.min(...familyVals);
|
||||
} else if (
|
||||
activePool &&
|
||||
!THIRD_PARTY_FAMILY_RE.test(String(activePool.family || activePool.poolLabel || ''))
|
||||
) {
|
||||
const fb = isWeekly ? activePool.weeklyRemainingPct : activePool.remainingPct;
|
||||
if (fb != null && Number.isFinite(Number(fb))) {
|
||||
rawPct = Number(fb);
|
||||
}
|
||||
}
|
||||
if (
|
||||
rawPct == null &&
|
||||
isWeekly &&
|
||||
quotas.weekly &&
|
||||
!THIRD_PARTY_FAMILY_RE.test(String(quotas.weekly.poolFamily || '')) &&
|
||||
quotas.weekly.remainingPct != null &&
|
||||
Number.isFinite(Number(quotas.weekly.remainingPct))
|
||||
) {
|
||||
rawPct = Number(quotas.weekly.remainingPct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rawPct == null || !Number.isFinite(rawPct)) return null;
|
||||
const rounded = Math.max(0, Math.min(100, Math.round(rawPct)));
|
||||
const rounded = resolveCapsuleQuotaSlotPct(quotas, slotKey);
|
||||
if (rounded == null) return null;
|
||||
return {
|
||||
roundedPct: rounded,
|
||||
shortText: t('capsule.quotaLeft', { pct: rounded }),
|
||||
};
|
||||
}
|
||||
|
||||
export function formatCompactCapsuleCost(costUsd) {
|
||||
if (costUsd == null || !Number.isFinite(Number(costUsd))) return '--';
|
||||
const val = Math.max(0, Number(costUsd));
|
||||
if (val === 0) return '$0.00';
|
||||
if (val < 0.001) return '<$0.001';
|
||||
if (val < 1) return `$${val.toFixed(3)}`;
|
||||
if (val < 100) return `$${val.toFixed(2)}`;
|
||||
return `$${Math.round(val)}`;
|
||||
}
|
||||
|
||||
export function formatCompactCapsuleTtft(ttftSec) {
|
||||
if (ttftSec == null || !Number.isFinite(Number(ttftSec)) || Number(ttftSec) < 0) return '--s';
|
||||
const val = Number(ttftSec);
|
||||
if (val < 1) return `${val.toFixed(2)}s`;
|
||||
if (val < 100) return `${val.toFixed(1)}s`;
|
||||
return `${Math.round(val)}s`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析顶栏/输入框精简胶囊单槽位展示结构。
|
||||
*
|
||||
|
||||
@@ -20,37 +20,18 @@ import {
|
||||
} from '../core/formatters.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
import {
|
||||
DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT,
|
||||
normalizeClientStepTokenComboFormat,
|
||||
parseClientStepTokenComboSegments,
|
||||
} from '../store/telemetryStore.js';
|
||||
DEFAULT_STEP_TABLE_COLUMNS,
|
||||
DEFAULT_STEP_TOKEN_COMBO_FORMAT,
|
||||
STEP_TABLE_COLUMN_KEYS,
|
||||
normalizeStepTokenComboFormat,
|
||||
parseStepTokenComboSegments,
|
||||
} from '../../shared/settings-normalization.mjs';
|
||||
|
||||
export const STEP_COLUMN_KEYS = Object.freeze([
|
||||
'step',
|
||||
'time',
|
||||
'model',
|
||||
'tps',
|
||||
'ttft',
|
||||
'duration',
|
||||
'tokens_combo',
|
||||
'tokens_io_cache',
|
||||
'tokens_custom',
|
||||
'input_tokens',
|
||||
'cache_tokens',
|
||||
'output_tokens',
|
||||
'cache',
|
||||
'cost',
|
||||
]);
|
||||
|
||||
export const DEFAULT_STEP_COLUMN_KEYS = Object.freeze([
|
||||
'step',
|
||||
'model',
|
||||
'tps',
|
||||
'ttft',
|
||||
'tokens_combo',
|
||||
'cache',
|
||||
'cost',
|
||||
]);
|
||||
export const STEP_COLUMN_KEYS = STEP_TABLE_COLUMN_KEYS;
|
||||
export const DEFAULT_STEP_COLUMN_KEYS = DEFAULT_STEP_TABLE_COLUMNS;
|
||||
const DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT = DEFAULT_STEP_TOKEN_COMBO_FORMAT;
|
||||
const normalizeClientStepTokenComboFormat = normalizeStepTokenComboFormat;
|
||||
const parseClientStepTokenComboSegments = parseStepTokenComboSegments;
|
||||
|
||||
function resolveStepTokenParts(st) {
|
||||
const inTok = Math.max(0, Number(st?.inputTokens || 0));
|
||||
|
||||
@@ -5,18 +5,14 @@
|
||||
* live reordering, and clean instance disposal.
|
||||
*/
|
||||
|
||||
import { OVERVIEW_MODULE_KEYS } from '../../shared/settings-normalization.mjs';
|
||||
import { ContextWindowWidget } from '../components/widgets/ContextWindowWidget.js';
|
||||
import { LiveActivityWidget } from '../components/widgets/LiveActivityWidget.js';
|
||||
import { MetricMatrixWidget } from '../components/widgets/MetricMatrixWidget.js';
|
||||
import { QuotaPoolsWidget } from '../components/widgets/QuotaPoolsWidget.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
|
||||
export const OVERVIEW_WIDGET_KEYS = Object.freeze([
|
||||
'metrics',
|
||||
'context',
|
||||
'quotas',
|
||||
'live_tasks',
|
||||
]);
|
||||
export const OVERVIEW_WIDGET_KEYS = OVERVIEW_MODULE_KEYS;
|
||||
|
||||
export const OVERVIEW_WIDGET_REGISTRY = Object.freeze({
|
||||
metrics: {
|
||||
|
||||
@@ -8,14 +8,33 @@ import { callSidecarApi, getWindowBridgeConfig, isWindowOverlayMode } from '../c
|
||||
import { isEnglishLocale, normalizeI18nLanguage, t } from '../i18n/index.js';
|
||||
import { normalizeClientFontScale, normalizeClientThemeAccent } from '../core/appearance.js';
|
||||
import {
|
||||
DEFAULT_HOVER_MODULES,
|
||||
DEFAULT_OVERVIEW_METRICS,
|
||||
DEFAULT_OVERVIEW_MODULES,
|
||||
DEFAULT_POPOVER_WIDTH,
|
||||
DEFAULT_STEP_TABLE_COLUMNS,
|
||||
DEFAULT_STEP_TOKEN_COMBO_FORMAT,
|
||||
DEFAULT_TOPBAR_SLOTS,
|
||||
MAX_POPOVER_WIDTH,
|
||||
MIN_POPOVER_WIDTH,
|
||||
OVERVIEW_METRIC_KEYS,
|
||||
OVERVIEW_MODULE_KEYS,
|
||||
STEP_TABLE_COLUMN_KEYS,
|
||||
TOPBAR_SLOT_KEYS,
|
||||
normalizeHoverModules,
|
||||
normalizeModelDisplayMode,
|
||||
normalizeOrchestratorIdMode,
|
||||
normalizeOverviewMetrics,
|
||||
normalizeOverviewModules,
|
||||
normalizePluginUpdateMode,
|
||||
normalizePopoverWidth,
|
||||
normalizePopoverWidthMode,
|
||||
normalizeStepTableColumns,
|
||||
normalizeStepTokenComboFormat,
|
||||
normalizeTopbarCapsuleSlots,
|
||||
normalizeWeeklyLimitMode,
|
||||
normalizeWindowMountMode,
|
||||
parseStepTokenComboSegments,
|
||||
} from '../../shared/settings-normalization.mjs';
|
||||
import { WINDOW_BRIDGE_ROUTE_KEY, readInjectedWindowBridge } from '../../shared/window-bridge-protocol.mjs';
|
||||
|
||||
@@ -119,265 +138,34 @@ let loopIntervalMs = 2000;
|
||||
let loopTickFn = null;
|
||||
|
||||
export const CLIENT_TOPBAR_SLOT_KEYS = TOPBAR_SLOT_KEYS;
|
||||
|
||||
export const DEFAULT_CLIENT_TOPBAR_SLOTS = DEFAULT_TOPBAR_SLOTS;
|
||||
|
||||
export const CLIENT_OVERVIEW_MODULE_KEYS = Object.freeze([
|
||||
'metrics',
|
||||
'context',
|
||||
'quotas',
|
||||
'live_tasks',
|
||||
]);
|
||||
|
||||
export const DEFAULT_CLIENT_OVERVIEW_MODULES = Object.freeze([
|
||||
'metrics',
|
||||
'context',
|
||||
'quotas',
|
||||
'live_tasks',
|
||||
]);
|
||||
|
||||
export const DEFAULT_CLIENT_HOVER_MODULES = Object.freeze(['metrics', 'context', 'quotas']);
|
||||
|
||||
export const CLIENT_OVERVIEW_MODULE_KEYS = OVERVIEW_MODULE_KEYS;
|
||||
export const DEFAULT_CLIENT_OVERVIEW_MODULES = DEFAULT_OVERVIEW_MODULES;
|
||||
export const DEFAULT_CLIENT_HOVER_MODULES = DEFAULT_HOVER_MODULES;
|
||||
export const CLIENT_OVERVIEW_METRIC_KEYS = OVERVIEW_METRIC_KEYS;
|
||||
|
||||
export const DEFAULT_CLIENT_OVERVIEW_METRICS = DEFAULT_OVERVIEW_METRICS;
|
||||
export const CLIENT_STEP_COLUMN_KEYS = STEP_TABLE_COLUMN_KEYS;
|
||||
export const DEFAULT_CLIENT_STEP_COLUMNS = DEFAULT_STEP_TABLE_COLUMNS;
|
||||
export const DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT = DEFAULT_STEP_TOKEN_COMBO_FORMAT;
|
||||
export const MIN_CLIENT_POPOVER_WIDTH = MIN_POPOVER_WIDTH;
|
||||
export const MAX_CLIENT_POPOVER_WIDTH = MAX_POPOVER_WIDTH;
|
||||
export const DEFAULT_CLIENT_POPOVER_WIDTH = DEFAULT_POPOVER_WIDTH;
|
||||
|
||||
export const CLIENT_STEP_COLUMN_KEYS = Object.freeze([
|
||||
'step',
|
||||
'time',
|
||||
'model',
|
||||
'tps',
|
||||
'ttft',
|
||||
'duration',
|
||||
'tokens_combo',
|
||||
'tokens_io_cache',
|
||||
'tokens_custom',
|
||||
'input_tokens',
|
||||
'cache_tokens',
|
||||
'output_tokens',
|
||||
'cache',
|
||||
'cost',
|
||||
]);
|
||||
export const parseClientStepTokenComboSegments = parseStepTokenComboSegments;
|
||||
export const normalizeClientStepTokenComboFormat = normalizeStepTokenComboFormat;
|
||||
export const normalizeClientPopoverWidthMode = normalizePopoverWidthMode;
|
||||
export const normalizeClientPopoverWidth = normalizePopoverWidth;
|
||||
export const normalizeClientModelDisplayMode = normalizeModelDisplayMode;
|
||||
export const normalizeClientTopbarSlots = normalizeTopbarCapsuleSlots;
|
||||
export const normalizeClientHoverModules = normalizeHoverModules;
|
||||
export const normalizeClientOverviewModules = normalizeOverviewModules;
|
||||
export const normalizeClientOverviewMetrics = normalizeOverviewMetrics;
|
||||
export const normalizeClientStepColumns = normalizeStepTableColumns;
|
||||
export const normalizeClientUpdateMode = normalizePluginUpdateMode;
|
||||
export const normalizeClientOrchestratorIdMode = normalizeOrchestratorIdMode;
|
||||
export const normalizeClientWindowMountMode = normalizeWindowMountMode;
|
||||
|
||||
export const DEFAULT_CLIENT_STEP_COLUMNS = Object.freeze([
|
||||
'step',
|
||||
'model',
|
||||
'tps',
|
||||
'ttft',
|
||||
'tokens_combo',
|
||||
'cache',
|
||||
'cost',
|
||||
]);
|
||||
|
||||
export const DEFAULT_CLIENT_STEP_TOKEN_COMBO_FORMAT = 'context:in:cache';
|
||||
|
||||
const CLIENT_STEP_TOKEN_ALIASES = Object.freeze({
|
||||
context: 'context',
|
||||
ctx: 'context',
|
||||
'上下文': 'context',
|
||||
in: 'in',
|
||||
new: 'in',
|
||||
input: 'in',
|
||||
'输入': 'in',
|
||||
'新输入': 'in',
|
||||
out: 'out',
|
||||
output: 'out',
|
||||
'输出': 'out',
|
||||
'总输出': 'out',
|
||||
cache: 'cache',
|
||||
cached: 'cache',
|
||||
cache_read: 'cache',
|
||||
cacheread: 'cache',
|
||||
'缓存': 'cache',
|
||||
'缓存读': 'cache',
|
||||
think: 'think',
|
||||
thinking: 'think',
|
||||
'思考': 'think',
|
||||
reply: 'reply',
|
||||
body: 'reply',
|
||||
resp: 'reply',
|
||||
response: 'reply',
|
||||
text: 'reply',
|
||||
'正文': 'reply',
|
||||
'回复': 'reply',
|
||||
total: 'total',
|
||||
all: 'total',
|
||||
sum: 'total',
|
||||
'总计': 'total',
|
||||
'总token': 'total',
|
||||
});
|
||||
|
||||
export function parseClientStepTokenComboSegments(raw) {
|
||||
const str = String(raw ?? '').trim();
|
||||
const out = [];
|
||||
const seen = new Set();
|
||||
if (str) {
|
||||
for (const part of str.split(/[:/,|]+/)) {
|
||||
const key = part.trim().toLowerCase();
|
||||
if (!key) continue;
|
||||
const mapped = Object.prototype.hasOwnProperty.call(CLIENT_STEP_TOKEN_ALIASES, key)
|
||||
? CLIENT_STEP_TOKEN_ALIASES[key]
|
||||
: null;
|
||||
if (!mapped || seen.has(mapped)) continue;
|
||||
seen.add(mapped);
|
||||
out.push(mapped);
|
||||
if (out.length >= 4) break;
|
||||
}
|
||||
}
|
||||
return out.length > 0 ? out : ['context', 'in', 'cache'];
|
||||
}
|
||||
|
||||
export function normalizeClientStepTokenComboFormat(raw) {
|
||||
return parseClientStepTokenComboSegments(raw).join(':');
|
||||
}
|
||||
|
||||
export const MIN_CLIENT_POPOVER_WIDTH = 440;
|
||||
export const MAX_CLIENT_POPOVER_WIDTH = 1080;
|
||||
export const DEFAULT_CLIENT_POPOVER_WIDTH = 580;
|
||||
|
||||
export function normalizeClientPopoverWidthMode(mode) {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
return m === 'custom' || m === 'fixed' ? 'custom' : 'auto';
|
||||
}
|
||||
|
||||
export function normalizeClientPopoverWidth(width) {
|
||||
const num = Number(width);
|
||||
if (!Number.isFinite(num) || num <= 0) return DEFAULT_CLIENT_POPOVER_WIDTH;
|
||||
return Math.max(MIN_CLIENT_POPOVER_WIDTH, Math.min(MAX_CLIENT_POPOVER_WIDTH, Math.round(num)));
|
||||
}
|
||||
|
||||
export function normalizeClientModelDisplayMode(mode, legacyShowUpstream) {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
if (m === 'upstream' || m === 'raw' || m === 'full') return 'upstream';
|
||||
if (m === 'upstream_compact' || m === 'compact_upstream' || m === 'trimmed') {
|
||||
return 'upstream_compact';
|
||||
}
|
||||
if (m === 'short') return 'short';
|
||||
if (legacyShowUpstream === true) return 'upstream';
|
||||
return 'short';
|
||||
}
|
||||
|
||||
function normalizeClientOrderedList(raw, { allowedKeys, defaultItems, minLen, maxLen }) {
|
||||
if (!Array.isArray(raw)) {
|
||||
return [...defaultItems];
|
||||
}
|
||||
const allowedSet = new Set(allowedKeys);
|
||||
const seen = new Set();
|
||||
const out = [];
|
||||
for (const item of raw) {
|
||||
const key = String(item ?? '').trim();
|
||||
if (!key || key === 'none' || !allowedSet.has(key) || seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
out.push(key);
|
||||
if (out.length >= maxLen) break;
|
||||
}
|
||||
if (out.length < minLen) {
|
||||
for (const fallbackKey of [...defaultItems, ...allowedKeys]) {
|
||||
if (!seen.has(fallbackKey) && allowedSet.has(fallbackKey)) {
|
||||
seen.add(fallbackKey);
|
||||
out.push(fallbackKey);
|
||||
if (out.length >= minLen) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化前端顶栏胶囊动态槽位配置数组(支持 1..5 项不重复指标,兼容迁移旧版 `'none'` 占位)。
|
||||
*
|
||||
* @param {unknown} raw
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function normalizeClientTopbarSlots(raw) {
|
||||
return normalizeTopbarCapsuleSlots(raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化鼠标悬浮速览窗展示模块列表(支持 0..4 项,`0` 项代表关闭悬浮窗)。
|
||||
*
|
||||
* @param {unknown} raw
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function normalizeClientHoverModules(raw) {
|
||||
return normalizeClientOrderedList(raw, {
|
||||
allowedKeys: CLIENT_OVERVIEW_MODULE_KEYS,
|
||||
defaultItems: DEFAULT_CLIENT_HOVER_MODULES,
|
||||
minLen: 0,
|
||||
maxLen: 4,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化实时监控视图展示模块列表(支持 1..4 项)。
|
||||
*
|
||||
* @param {unknown} raw
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function normalizeClientOverviewModules(raw) {
|
||||
return normalizeClientOrderedList(raw, {
|
||||
allowedKeys: CLIENT_OVERVIEW_MODULE_KEYS,
|
||||
defaultItems: DEFAULT_CLIENT_OVERVIEW_MODULES,
|
||||
minLen: 1,
|
||||
maxLen: 4,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化实时监控第一行指标矩阵配置(支持 1..4 项)。
|
||||
*
|
||||
* @param {unknown} raw
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function normalizeClientOverviewMetrics(raw) {
|
||||
return normalizeOverviewMetrics(raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化调用明细「按步查看」显示列配置(支持 2..12 列)。
|
||||
*
|
||||
* @param {unknown} raw
|
||||
* @returns {string[]}
|
||||
*/
|
||||
export function normalizeClientStepColumns(raw) {
|
||||
return normalizeClientOrderedList(raw, {
|
||||
allowedKeys: CLIENT_STEP_COLUMN_KEYS,
|
||||
defaultItems: DEFAULT_CLIENT_STEP_COLUMNS,
|
||||
minLen: 2,
|
||||
maxLen: CLIENT_STEP_COLUMN_KEYS.length,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化前端插件更新策略(`'off'` | `'manual'` | `'auto'`),兼容旧版布尔字段。
|
||||
*
|
||||
* @param {unknown} mode
|
||||
* @param {unknown} [legacyAutoUpdate]
|
||||
* @returns {'off'|'manual'|'auto'}
|
||||
*/
|
||||
export function normalizeClientUpdateMode(mode, legacyAutoUpdate) {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
if (m === 'off' || m === 'manual' || m === 'auto') return m;
|
||||
if (legacyAutoUpdate === true) return 'auto';
|
||||
return 'manual';
|
||||
}
|
||||
|
||||
export function normalizeClientOrchestratorIdMode(mode) {
|
||||
return String(mode ?? '').trim().toLowerCase() === 'full' ? 'full' : 'compact';
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化前端面板挂载方式(`'dual'` | `'composer'` | `'sidebar'`),兼容旧版 `enableWindowOverlay` 布尔字段。
|
||||
*
|
||||
* @param {unknown} mode
|
||||
* @param {unknown} [legacyEnableOverlay]
|
||||
* @returns {'dual'|'composer'|'sidebar'}
|
||||
*/
|
||||
export function normalizeClientWindowMountMode(mode, legacyEnableOverlay) {
|
||||
return normalizeWindowMountMode(mode, legacyEnableOverlay);
|
||||
}
|
||||
|
||||
function isEquivalentTelemetry(prev, next) {
|
||||
export function isEquivalentTelemetry(prev, next) {
|
||||
if (!prev || !next) return false;
|
||||
if (prev === next) return true;
|
||||
|
||||
@@ -409,51 +197,29 @@ function isEquivalentTelemetry(prev, next) {
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const normModelMode = (mode, legacyShowUpstream) => {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
if (m === 'upstream' || m === 'raw' || m === 'full') return 'upstream';
|
||||
if (m === 'upstream_compact' || m === 'compact_upstream' || m === 'trimmed') {
|
||||
return 'upstream_compact';
|
||||
}
|
||||
if (m === 'short') return 'short';
|
||||
return legacyShowUpstream === true ? 'upstream' : 'short';
|
||||
};
|
||||
const normPopMode = (mode) => {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
return m === 'custom' || m === 'fixed' ? 'custom' : 'auto';
|
||||
};
|
||||
const normPopW = (w) => {
|
||||
const n = Number(w);
|
||||
return Number.isFinite(n) && n > 0 ? Math.max(440, Math.min(1080, Math.round(n))) : 580;
|
||||
};
|
||||
if (
|
||||
normModelMode(pSet?.modelDisplayMode, pSet?.showUpstreamModel) !==
|
||||
normModelMode(nSet?.modelDisplayMode, nSet?.showUpstreamModel)
|
||||
normalizeModelDisplayMode(pSet?.modelDisplayMode, pSet?.showUpstreamModel) !==
|
||||
normalizeModelDisplayMode(nSet?.modelDisplayMode, nSet?.showUpstreamModel)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (pSet?.showUpstreamModel !== nSet?.showUpstreamModel) return false;
|
||||
if (normPopMode(pSet?.popoverWidthMode) !== normPopMode(nSet?.popoverWidthMode)) {
|
||||
if (normalizePopoverWidthMode(pSet?.popoverWidthMode) !== normalizePopoverWidthMode(nSet?.popoverWidthMode)) {
|
||||
return false;
|
||||
}
|
||||
if (normPopW(pSet?.popoverWidth) !== normPopW(nSet?.popoverWidth)) {
|
||||
if (normalizePopoverWidth(pSet?.popoverWidth) !== normalizePopoverWidth(nSet?.popoverWidth)) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
String(pSet?.stepTokenComboFormat ?? 'context:in:cache').trim() !==
|
||||
String(nSet?.stepTokenComboFormat ?? 'context:in:cache').trim()
|
||||
String(pSet?.stepTokenComboFormat ?? DEFAULT_STEP_TOKEN_COMBO_FORMAT).trim() !==
|
||||
String(nSet?.stepTokenComboFormat ?? DEFAULT_STEP_TOKEN_COMBO_FORMAT).trim()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const prevOrchIdMode =
|
||||
String(pSet?.orchestratorIdMode ?? 'compact').trim().toLowerCase() === 'full'
|
||||
? 'full'
|
||||
: 'compact';
|
||||
const nextOrchIdMode =
|
||||
String(nSet?.orchestratorIdMode ?? 'compact').trim().toLowerCase() === 'full'
|
||||
? 'full'
|
||||
: 'compact';
|
||||
if (prevOrchIdMode !== nextOrchIdMode) {
|
||||
if (
|
||||
normalizeOrchestratorIdMode(pSet?.orchestratorIdMode) !==
|
||||
normalizeOrchestratorIdMode(nSet?.orchestratorIdMode)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (pSet?.weeklyLimitMode !== nSet?.weeklyLimitMode) return false;
|
||||
@@ -1392,46 +1158,73 @@ export function formatAgentLabel(agent) {
|
||||
* @param {string} [ctxInspectorAgentId='auto']
|
||||
* @param {boolean} [includeSteps=false] 是否组装调用明细所需的步骤列表
|
||||
*/
|
||||
const scopedStepProjectionMemo = new WeakMap();
|
||||
|
||||
export function resolveScopedConversation(
|
||||
telemetry,
|
||||
selectedAgentScope = 'all',
|
||||
ctxInspectorAgentId = 'auto',
|
||||
includeSteps = false
|
||||
) {
|
||||
const active = telemetry?.activeConversation || {};
|
||||
const rawActive = telemetry?.activeConversation;
|
||||
const active = rawActive || {};
|
||||
const agents = Array.isArray(active.agents) && active.agents.length > 0 ? active.agents : [];
|
||||
const hasSubagents = Boolean(active.hasSubagents && agents.length > 1);
|
||||
const subagents = agents.filter((a) => !a.isMain);
|
||||
const mainAgent = agents.find((a) => a.isMain) || active;
|
||||
if (includeSteps && !Array.isArray(mainAgent.recentSteps) && Array.isArray(active.recentSteps)) {
|
||||
mainAgent.recentSteps = active.recentSteps;
|
||||
}
|
||||
const aggregated = active.aggregated || active;
|
||||
if (includeSteps && hasSubagents && !Array.isArray(aggregated.recentSteps)) {
|
||||
const combined = [];
|
||||
for (const ag of agents) {
|
||||
const steps = ag.isMain ? ag.recentSteps || active.recentSteps || [] : ag.recentSteps || [];
|
||||
for (const step of steps) combined.push(step);
|
||||
let mainAgent = agents.find((a) => a.isMain) || active;
|
||||
let aggregated = active.aggregated || active;
|
||||
let resolvedAgents = agents;
|
||||
|
||||
if (includeSteps) {
|
||||
let cached = rawActive && typeof rawActive === 'object' ? scopedStepProjectionMemo.get(rawActive) : null;
|
||||
if (!cached) {
|
||||
let nextMain = mainAgent;
|
||||
let nextAgents = agents;
|
||||
if (!Array.isArray(mainAgent.recentSteps) && Array.isArray(active.recentSteps)) {
|
||||
nextMain = { ...mainAgent, recentSteps: active.recentSteps };
|
||||
if (agents.includes(mainAgent)) {
|
||||
nextAgents = agents.map((ag) => (ag === mainAgent ? nextMain : ag));
|
||||
}
|
||||
}
|
||||
let nextAgg = aggregated;
|
||||
if (hasSubagents && !Array.isArray(aggregated.recentSteps)) {
|
||||
const combined = [];
|
||||
for (const ag of nextAgents) {
|
||||
const steps = ag.isMain ? ag.recentSteps || active.recentSteps || [] : ag.recentSteps || [];
|
||||
for (const step of steps) combined.push(step);
|
||||
}
|
||||
combined.sort(
|
||||
(a, b) =>
|
||||
(b.createdAtMs || 0) - (a.createdAtMs || 0) ||
|
||||
(b.agentIndex || 0) - (a.agentIndex || 0) ||
|
||||
(b.stepIndex || 0) - (a.stepIndex || 0)
|
||||
);
|
||||
nextAgg = { ...aggregated, recentSteps: combined };
|
||||
}
|
||||
cached = { mainAgent: nextMain, aggregated: nextAgg, agents: nextAgents };
|
||||
if (rawActive && typeof rawActive === 'object') {
|
||||
scopedStepProjectionMemo.set(rawActive, cached);
|
||||
}
|
||||
}
|
||||
combined.sort(
|
||||
(a, b) =>
|
||||
(b.createdAtMs || 0) - (a.createdAtMs || 0) ||
|
||||
(b.agentIndex || 0) - (a.agentIndex || 0) ||
|
||||
(b.stepIndex || 0) - (a.stepIndex || 0)
|
||||
);
|
||||
aggregated.recentSteps = combined;
|
||||
mainAgent = cached.mainAgent;
|
||||
aggregated = cached.aggregated;
|
||||
resolvedAgents = cached.agents;
|
||||
}
|
||||
|
||||
if (!hasSubagents) {
|
||||
const singleScoped =
|
||||
includeSteps && !Array.isArray(active.recentSteps) && Array.isArray(mainAgent.recentSteps)
|
||||
? { ...active, recentSteps: mainAgent.recentSteps }
|
||||
: active;
|
||||
return {
|
||||
hasSubagents: false,
|
||||
effectiveScope: 'main',
|
||||
effectiveCtxScope: 'main',
|
||||
agents,
|
||||
agents: resolvedAgents,
|
||||
subagents: [],
|
||||
mainAgent,
|
||||
aggregated,
|
||||
scopedConv: active,
|
||||
scopedConv: singleScoped,
|
||||
ctxAgent: mainAgent,
|
||||
};
|
||||
}
|
||||
@@ -1447,13 +1240,13 @@ export function resolveScopedConversation(
|
||||
const scopedConv =
|
||||
effectiveScope === 'all'
|
||||
? aggregated
|
||||
: agents.find((a) => a.agentId === effectiveScope) || mainAgent;
|
||||
: resolvedAgents.find((a) => a.agentId === effectiveScope) || mainAgent;
|
||||
|
||||
let ctxAgent = scopedConv;
|
||||
let effectiveCtxScope = effectiveScope;
|
||||
if (effectiveScope === 'all') {
|
||||
if (ctxInspectorAgentId && ctxInspectorAgentId !== 'auto') {
|
||||
const matched = agents.find((a) => a.agentId === ctxInspectorAgentId);
|
||||
const matched = resolvedAgents.find((a) => a.agentId === ctxInspectorAgentId);
|
||||
if (matched) {
|
||||
ctxAgent = matched;
|
||||
effectiveCtxScope = matched.agentId;
|
||||
@@ -1465,8 +1258,8 @@ export function resolveScopedConversation(
|
||||
}
|
||||
if (effectiveCtxScope === 'auto') {
|
||||
ctxAgent =
|
||||
agents.find((a) => !a.isSideQuestion && a.agentId === aggregated.activeAgentId) ||
|
||||
agents.find((a) => !a.isSideQuestion && a.isRunning) ||
|
||||
resolvedAgents.find((a) => !a.isSideQuestion && a.agentId === aggregated.activeAgentId) ||
|
||||
resolvedAgents.find((a) => !a.isSideQuestion && a.isRunning) ||
|
||||
mainAgent;
|
||||
}
|
||||
}
|
||||
@@ -1475,7 +1268,7 @@ export function resolveScopedConversation(
|
||||
hasSubagents: true,
|
||||
effectiveScope,
|
||||
effectiveCtxScope,
|
||||
agents,
|
||||
agents: resolvedAgents,
|
||||
subagents,
|
||||
mainAgent,
|
||||
aggregated,
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
normalizeModelDisplayMode,
|
||||
normalizeOrchestratorIdDisplayMode,
|
||||
} from '../core/formatters.js';
|
||||
import { scaleBucketsExact } from '../../shared/telemetry-display-rules.mjs';
|
||||
import { i18nStore, isEnglishLocale, t } from '../i18n/index.js';
|
||||
import { createSvgIcon } from '../icons/SvgIcon.js';
|
||||
import { fetchTelemetry, telemetryStore } from '../store/telemetryStore.js';
|
||||
@@ -572,22 +573,14 @@ export const ConsumptionView = defineComponent({
|
||||
let cachePct = 0;
|
||||
let outPct = 0;
|
||||
if (totalTokens > 0) {
|
||||
const rawTenths = [
|
||||
(inputTokens / totalTokens) * 1000,
|
||||
(cacheTokens / totalTokens) * 1000,
|
||||
(outputTokens / totalTokens) * 1000,
|
||||
];
|
||||
const floored = rawTenths.map((v) => Math.max(0, Math.floor(v)));
|
||||
const rem = Math.max(0, 1000 - (floored[0] + floored[1] + floored[2]));
|
||||
const order = [0, 1, 2].sort(
|
||||
(a, b) => rawTenths[b] - floored[b] - (rawTenths[a] - floored[a])
|
||||
const scaled = scaleBucketsExact(
|
||||
{ in: inputTokens, cache: cacheTokens, out: outputTokens },
|
||||
['in', 'cache', 'out'],
|
||||
1000
|
||||
);
|
||||
for (let k = 0; k < rem && k < 3; k++) {
|
||||
floored[order[k]] += 1;
|
||||
}
|
||||
inPct = +(floored[0] / 10).toFixed(1);
|
||||
cachePct = +(floored[1] / 10).toFixed(1);
|
||||
outPct = +(floored[2] / 10).toFixed(1);
|
||||
inPct = +(scaled.in / 10).toFixed(1);
|
||||
cachePct = +(scaled.cache / 10).toFixed(1);
|
||||
outPct = +(scaled.out / 10).toFixed(1);
|
||||
}
|
||||
|
||||
patchText(inputSharePct, `${inPct}%`);
|
||||
|
||||
@@ -11,7 +11,6 @@ import { telemetryStore } from '../store/telemetryStore.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';
|
||||
import { SettingsGeneralTab } from './settings/SettingsGeneralTab.js';
|
||||
import { SettingsOtherTab } from './settings/SettingsOtherTab.js';
|
||||
import { SettingsStructureTab } from './settings/SettingsStructureTab.js';
|
||||
@@ -52,7 +51,7 @@ export const SettingsView = defineComponent({
|
||||
|
||||
const generalTab = SettingsGeneralTab({ onLayoutChange: refreshScroll });
|
||||
const structureTab = SettingsStructureTab({ onLayoutChange: refreshScroll });
|
||||
const accountTab = SHOW_ACCOUNT_TAB ? SettingsAccountTab({ onLayoutChange: refreshScroll }) : null;
|
||||
const accountTab = null; // SettingsAccountTab kept in src/views/settings/ for future opt-in
|
||||
const otherTab = SettingsOtherTab({ onLayoutChange: refreshScroll });
|
||||
|
||||
let showingAccount = false;
|
||||
|
||||
Reference in New Issue
Block a user