mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
feat(panel): Orchestrator compatibility, ID display toggle, and Hydrogen pricing (v1.4.5)
This commit is contained in:
@@ -95,6 +95,19 @@ export const DEFAULT_TOPBAR_SLOTS = Object.freeze(['context', 'tps', 'quota_auto
|
||||
|
||||
export const PLUGIN_UPDATE_MODES = Object.freeze(['off', 'manual', 'auto']);
|
||||
|
||||
export const ORCHESTRATOR_ID_MODES = Object.freeze(['compact', 'full']);
|
||||
|
||||
/**
|
||||
* 归一化 Orchestrator 系列模型 ID 显示风格(`'compact'` 精简代号 vs `'full'` 完整模型 ID,默认 `'compact'`)。
|
||||
*
|
||||
* @param {unknown} mode
|
||||
* @returns {'compact'|'full'}
|
||||
*/
|
||||
export function normalizeOrchestratorIdMode(mode) {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
return m === 'full' ? 'full' : 'compact';
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化插件更新策略枚举(兼容历史 `autoUpdatePlugin` 布尔开关,默认 `'manual'`)。
|
||||
*
|
||||
@@ -135,6 +148,7 @@ const DEFAULT_SETTINGS = {
|
||||
weeklyCostBudget: 100, // 自定义每周美元费用预算默认值 ($100,保留底层兼容)
|
||||
weeklyLimitMode: 'official', // 'official' | 'custom_tokens' | 'custom_cost'
|
||||
showUpstreamModel: false, // 是否显示上游真实 responseModel 名称
|
||||
orchestratorIdMode: 'compact', // 'compact' | 'full'(Orchestrator 系列显示精简 ID 或完整 ID)
|
||||
pluginUpdateMode: 'manual', // 'off' | 'manual' | 'auto'(默认仅提示新版本,手动更新)
|
||||
autoUpdatePlugin: false, // 派生自 pluginUpdateMode === 'auto',保留底层兼容
|
||||
enableWindowOverlay: true, // 是否启用双栖模式(自动通过 CDP 在主窗口顶栏挂载胶囊与悬浮面板)
|
||||
@@ -233,6 +247,7 @@ export function loadSettings() {
|
||||
),
|
||||
weeklyLimitMode: normalizeWeeklyLimitMode(merged.weeklyLimitMode),
|
||||
showUpstreamModel: merged.showUpstreamModel === true,
|
||||
orchestratorIdMode: normalizeOrchestratorIdMode(merged.orchestratorIdMode),
|
||||
pluginUpdateMode,
|
||||
autoUpdatePlugin: pluginUpdateMode === 'auto',
|
||||
enableWindowOverlay: merged.enableWindowOverlay !== false,
|
||||
@@ -263,6 +278,7 @@ export function computeRuntimeCodeVersion() {
|
||||
join(HERE, 'styles.css'),
|
||||
join(HERE, 'main.mjs'),
|
||||
join(HERE, 'speed-metrics.mjs'),
|
||||
LOCAL_CATALOG_FILE,
|
||||
];
|
||||
const backendDir = join(HERE, 'backend');
|
||||
try {
|
||||
|
||||
@@ -49,6 +49,7 @@ function inferFamilyFromProviderOrKey(rawModelKey = '', modelId = '', apiProvide
|
||||
combined.includes('CARBON') ||
|
||||
combined.includes('ARGON') ||
|
||||
combined.includes('HYDROGEN') ||
|
||||
combined.includes('ORCHESTRATOR') ||
|
||||
combined.includes('HELIX') ||
|
||||
combined.includes('FLASH') ||
|
||||
combined.includes('GOOGLE')
|
||||
@@ -59,29 +60,42 @@ function inferFamilyFromProviderOrKey(rawModelKey = '', modelId = '', apiProvide
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一组模型标识字段是否指向 Gemini 4 Argon 系列模型(含 M417/M418/M419 枚举)。
|
||||
* 判断一组模型标识字段是否指向 Gemini 4 Argon 系列模型(含 M417/M418/M419 及 M681 Orchestrator (Argon))。
|
||||
*
|
||||
* @param {...string} parts 待检测的标识片段
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isArgonModelIdentifier(...parts) {
|
||||
return /argon|MODEL_PLACEHOLDER_M41[789]\b/i.test(parts.filter(Boolean).join(' '));
|
||||
const text = parts.filter(Boolean).join(' ');
|
||||
if (
|
||||
/\bhydrogen\b|\bgemini-flash-worker-agy\b|MODEL_PLACEHOLDER_M(?:669|52[5678])\b/i.test(text) &&
|
||||
!/\bargon\b|MODEL_PLACEHOLDER_M(?:41[789]|681)\b/i.test(text)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return /argon|MODEL_PLACEHOLDER_M(?:41[789]|681)\b/i.test(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一组模型标识字段是否指向 Gemini 4 Carbon 系列模型(含 M429 枚举)。
|
||||
* 判断一组模型标识字段是否指向 Gemini 4 Carbon 系列模型(含 M427/M429/M437/M438 及 M667 Orchestrator (Carbon))。
|
||||
*
|
||||
* @param {...string} parts 待检测的标识片段
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isCarbonModelIdentifier(...parts) {
|
||||
return /\bcarbon\b|gemini-4-carbon|MODEL_PLACEHOLDER_M429\b/i.test(
|
||||
parts.filter(Boolean).join(' ')
|
||||
);
|
||||
const text = parts.filter(Boolean).join(' ');
|
||||
if (/\bcarbon\b|gemini-4-carbon|MODEL_PLACEHOLDER_M(?:42[79]|43[78]|667)\b/i.test(text)) {
|
||||
return true;
|
||||
}
|
||||
if (/\bhydrogen\b|\bgemini-flash-worker-agy\b|MODEL_PLACEHOLDER_M(?:669|52[5678])\b/i.test(text)) {
|
||||
return false;
|
||||
}
|
||||
return /\bgemini-pro-orchestrator\b(?!-argon)/i.test(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 剥离模型展示名称末尾的思考档位后缀(如 `(High)`、`(Medium)`、`(Thinking)`),提取基础模型族名。
|
||||
* 剥离模型展示名称末尾的思考档位后缀(如 `(XHigh)`、`(High)`、`(Medium)`、`(Thinking)`),提取基础模型族名。
|
||||
* 保留 `(Carbon)` / `(Argon)` 后缀,以便 `Orchestrator (Carbon)` 与 `Orchestrator (Argon)` 在汇总表中保持分列。
|
||||
*
|
||||
* @param {string} [label='']
|
||||
* @returns {string}
|
||||
@@ -89,7 +103,7 @@ export function isCarbonModelIdentifier(...parts) {
|
||||
export function getBaseModelLabel(label = '') {
|
||||
return (
|
||||
String(label || '')
|
||||
.replace(/\s*\((?:Max|High|Medium|Low|Thinking|Extra Low|Tiered)\)\s*$/i, '')
|
||||
.replace(/\s*\((?:Max|XHigh|High|Medium|Low|Thinking|Extra Low|Tiered)\)\s*$/i, '')
|
||||
.trim() || String(label || 'Unknown Model')
|
||||
);
|
||||
}
|
||||
@@ -121,6 +135,9 @@ export function formatGenericModelSlug(slug = '') {
|
||||
codenameMatch[1].charAt(0).toUpperCase() + codenameMatch[1].slice(1).toLowerCase();
|
||||
return `Gemini ${codename}`;
|
||||
}
|
||||
if (/^gemini-flash-worker-agy$/i.test(s)) {
|
||||
return 'Orchestrator Worker (Hydrogen)';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -156,8 +173,24 @@ export function resolveModelInfo(
|
||||
responseModel && responseModel !== 'unknown' ? String(responseModel).trim() : '';
|
||||
const cleanRawFallback =
|
||||
rawModelKey && rawModelKey !== 'unknown' ? rawModelKey : cleanResponseModel;
|
||||
const isWorkerSlot =
|
||||
rawModelKey === 'MODEL_PLACEHOLDER_M669' ||
|
||||
/^gemini-flash-worker-agy$/i.test(cleanResponseModel);
|
||||
const isVagueGenericDisplay = Boolean(
|
||||
modelDisplayName &&
|
||||
(/^gemini\s+(?:flash|pro)(?:\s+worker)?$/i.test(modelDisplayName.trim()) ||
|
||||
(isWorkerSlot && /^gemini\s+4\s+hydrogen$/i.test(modelDisplayName.trim())))
|
||||
);
|
||||
const effectiveDisplayName =
|
||||
modelDisplayName &&
|
||||
((mergedLabel &&
|
||||
(/\borchestrator\b/i.test(modelDisplayName) || isVagueGenericDisplay) &&
|
||||
!/\borchestrator\b/i.test(mergedLabel)) ||
|
||||
(isVagueGenericDisplay && /^gemini-flash-worker-agy$/i.test(cleanResponseModel)))
|
||||
? ''
|
||||
: modelDisplayName;
|
||||
const derivedDisplay =
|
||||
modelDisplayName ||
|
||||
effectiveDisplayName ||
|
||||
mergedLabel ||
|
||||
formatGenericModelSlug(rawModelKey) ||
|
||||
formatGenericModelSlug(cleanResponseModel) ||
|
||||
@@ -181,14 +214,22 @@ export function resolveModelInfo(
|
||||
(rawModelKey && rawModelKey !== 'unknown' ? rawModelKey : cleanResponseModel) ||
|
||||
'unknown';
|
||||
|
||||
const isOpaqueOrchestratorResp = Boolean(
|
||||
cleanResponseModel && /\borchestrator\b/i.test(cleanResponseModel)
|
||||
);
|
||||
const explicitPricing =
|
||||
MODEL_PRICING[modelId] ||
|
||||
MODEL_PRICING[rawModelKey] ||
|
||||
(cleanResponseModel ? MODEL_PRICING[cleanResponseModel] : null) ||
|
||||
(cleanResponseModel && !isOpaqueOrchestratorResp
|
||||
? MODEL_PRICING[cleanResponseModel]
|
||||
: null) ||
|
||||
MODEL_PRICING[tieredSlug] ||
|
||||
MODEL_PRICING[tieredDashedSlug] ||
|
||||
MODEL_PRICING[canonicalSlug] ||
|
||||
MODEL_PRICING[dashedSlug];
|
||||
MODEL_PRICING[dashedSlug] ||
|
||||
(cleanResponseModel && isOpaqueOrchestratorResp
|
||||
? MODEL_PRICING[cleanResponseModel]
|
||||
: null);
|
||||
|
||||
if (explicitPricing) {
|
||||
return {
|
||||
@@ -216,6 +257,36 @@ export function resolveModelInfo(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 为不透明的 Orchestrator 路由模型 ID 补充底层实际模型代号标注(如 `gemini-pro-orchestrator (carbon-4)`),
|
||||
* 普通透明上游模型 ID(如 `gemini-3.8-flash-n`、`gemini-4-hydrogen`)原样返回。
|
||||
*
|
||||
* @param {string} [rawUpstream='']
|
||||
* @param {ReturnType<typeof resolveModelInfo>|null} [mInfo=null]
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatUpstreamModelId(rawUpstream = '', mInfo = null) {
|
||||
const s = String(rawUpstream || '').trim();
|
||||
if (!s || !/(?:orchestrator|-worker-agy\b)/i.test(s) || /\([^)]+\)\s*$/.test(s)) {
|
||||
return s;
|
||||
}
|
||||
const metaText = `${mInfo?.rawModel || ''} ${mInfo?.modelId || ''} ${mInfo?.shortName || ''} ${mInfo?.label || ''} ${s}`;
|
||||
if (
|
||||
/\bhydrogen\b|\bgemini-flash-worker-agy\b|MODEL_PLACEHOLDER_M(?:669|52[5678])\b/i.test(
|
||||
metaText
|
||||
)
|
||||
) {
|
||||
return `${s} (hydrogen-4)`;
|
||||
}
|
||||
if (isArgonModelIdentifier(mInfo?.rawModel, mInfo?.modelId, mInfo?.label, s)) {
|
||||
return `${s} (argon-4)`;
|
||||
}
|
||||
if (isCarbonModelIdentifier(mInfo?.rawModel, mInfo?.modelId, mInfo?.label, s)) {
|
||||
return `${s} (carbon-4)`;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算单个步骤的 API 等效美元成本;若模型未定价(`pricing === null`)则返回 `null`。
|
||||
* 对负数、NaN 或非有限数值统一安全钳制为 0。
|
||||
|
||||
@@ -28,6 +28,7 @@ import { enumerateAndSyncConversations } from './local-scanner.mjs';
|
||||
import { callLsRpc, getOfficialQuotaSummary } from './ls-rpc.mjs';
|
||||
import {
|
||||
computeStepCost,
|
||||
formatUpstreamModelId,
|
||||
isArgonModelIdentifier,
|
||||
isCarbonModelIdentifier,
|
||||
resolveModelInfo,
|
||||
@@ -135,7 +136,10 @@ function enrichActiveConversationSteps(
|
||||
const rawUpstreamModel =
|
||||
resolvedResponseModel ||
|
||||
(mInfo.modelId && mInfo.modelId !== 'unknown' ? mInfo.modelId : mInfo.shortName);
|
||||
const modelUpstream = st.isCompactionStep ? `${rawUpstreamModel}·压缩` : rawUpstreamModel;
|
||||
const annotatedUpstreamModel = formatUpstreamModelId(rawUpstreamModel, mInfo);
|
||||
const modelUpstream = st.isCompactionStep
|
||||
? `${annotatedUpstreamModel}·压缩`
|
||||
: annotatedUpstreamModel;
|
||||
|
||||
const {
|
||||
viewableDelaySec: _viewableDelaySec,
|
||||
@@ -898,10 +902,11 @@ export async function buildTelemetryPayloadInternal(
|
||||
? knownUpstreamByModelKey.get(bestMetricStep.modelKey) || ''
|
||||
: '');
|
||||
modelShort = mInfo.shortName || '';
|
||||
modelUpstream =
|
||||
const rawQuickUpstream =
|
||||
resolvedResp ||
|
||||
(mInfo.modelId && mInfo.modelId !== 'unknown' ? mInfo.modelId : mInfo.shortName) ||
|
||||
'';
|
||||
modelUpstream = formatUpstreamModelId(rawQuickUpstream, mInfo);
|
||||
latestTokPerSec = roundMetric(speedMetric(bestMetricStep).value);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,11 @@ import {
|
||||
} from '../speed-metrics.mjs';
|
||||
import { roundMetric, trajectoryCache } from './config.mjs';
|
||||
import { loadExternalDeepStatsCache } from './local-scanner.mjs';
|
||||
import { computeStepCost, resolveModelInfo } from './model-pricing.mjs';
|
||||
import {
|
||||
computeStepCost,
|
||||
formatUpstreamModelId,
|
||||
resolveModelInfo,
|
||||
} from './model-pricing.mjs';
|
||||
|
||||
function safeTok(val) {
|
||||
const n = Number(val);
|
||||
@@ -260,7 +264,10 @@ function accumulateStepIntoModelMap(perModelStats, st, mInfo, stepCost) {
|
||||
perModelStats.set(modelGroupKey, {
|
||||
label: modelGroupKey,
|
||||
shortName: mInfo.shortName,
|
||||
fallbackModelId: mInfo.modelId && mInfo.modelId !== 'unknown' ? mInfo.modelId : '',
|
||||
fallbackModelId:
|
||||
mInfo.modelId && mInfo.modelId !== 'unknown'
|
||||
? formatUpstreamModelId(mInfo.modelId, mInfo)
|
||||
: '',
|
||||
upstreamModelCounts: new Map(),
|
||||
family: mInfo.family,
|
||||
calls: 0,
|
||||
@@ -276,9 +283,10 @@ function accumulateStepIntoModelMap(perModelStats, st, mInfo, stepCost) {
|
||||
}
|
||||
const agg = perModelStats.get(modelGroupKey);
|
||||
if (st.responseModel) {
|
||||
const formattedResp = formatUpstreamModelId(st.responseModel, mInfo);
|
||||
agg.upstreamModelCounts.set(
|
||||
st.responseModel,
|
||||
(agg.upstreamModelCounts.get(st.responseModel) || 0) + 1
|
||||
formattedResp,
|
||||
(agg.upstreamModelCounts.get(formattedResp) || 0) + 1
|
||||
);
|
||||
}
|
||||
accumulateSpeed(agg.speedAccumulator, st);
|
||||
|
||||
Reference in New Issue
Block a user