feat(panel): dual-mount topbar capsule, live multi-session HUD, and customizable topbar metrics (v1.4.3)

This commit is contained in:
fish
2026-11-11 17:31:42 +09:00
parent d60a3cde9b
commit e1da514515
56 changed files with 13389 additions and 3679 deletions
+59 -36
View File
@@ -1,12 +1,12 @@
/**
* @fileoverview 官方配额桶归一化、周期窗口识别与多模型池(Gemini / Argon / Claude & GPT)构建。
* @fileoverview 官方配额桶归一化、周期窗口识别与多模型池(Gemini / Argon / Carbon / Claude & GPT)构建。
*
* 处理所有已知的 Antigravity 服务端配额形态:
* - Google AI Ultra:Argon 与 Flash 共享同一个 Gemini Models 配额池;
* - Google AI Pro(形态 1):`RetrieveUserQuotaSummary` 返回独立的 `Gemini 4 Argon` 组;
* - Google AI Pro(形态 2):`Gemini Models` 组内嵌套独立的 `argon-weekly` 桶;
* - Google AI Pro(形态 3):`GetUserStatus` 的 `clientModelConfigs.quotaInfo` 为 Argon 报告了与标准 Gemini 不同的独立剩余比例;
* - Proto3 零值省略兼容:当配额耗尽(`remainingFraction === 0`)导致字段被省略但存在有效 `resetTime` 时,正确识别为 0% 剩余(100% 已用)。
* - Google AI Ultra:Argon / Carbon 与 Flash 共享同一个 Gemini Models 配额池;
* - Google AI Pro(形态 1):`RetrieveUserQuotaSummary` 返回独立的 `Gemini 4 Argon` / `Gemini 4 Carbon` 组;
* - Google AI Pro(形态 2):`Gemini Models` 组内嵌套独立的 `argon-weekly` / `carbon-weekly` 桶;
* - Google AI Pro(形态 3):`GetUserStatus` 的 `clientModelConfigs.quotaInfo` 为 Argon / Carbon 报告了与标准 Gemini 不同的独立剩余比例;
* - Proto3 零值省略兼容:当配额耗尽(`remainingFraction === 0`)导致字段被省略且存在尚未过期的有效 `resetTime` 时,正确识别为 0% 剩余(100% 已用)。
*/
import { parseIsoMs } from '../speed-metrics.mjs';
@@ -20,6 +20,7 @@ import {
* 将原始配额对象(来自 `RetrieveUserQuotaSummary` 桶或 `clientModelConfigs.quotaInfo`)归一化为百分比结构。
*
* @param {object} rawObj
* @param {number} [nowMs=Date.now()]
* @returns {{
* remainingFraction: number,
* remainingPct: number,
@@ -29,7 +30,7 @@ import {
* description: string
* } | null}
*/
export function normalizeQuotaFraction(rawObj) {
function normalizeQuotaFraction(rawObj, nowMs = Date.now()) {
if (!rawObj || typeof rawObj !== 'object') return null;
let remFrac = null;
if (rawObj.disabled === true) {
@@ -41,8 +42,11 @@ export function normalizeQuotaFraction(rawObj) {
) {
remFrac = Math.max(0, Math.min(1, Number(rawObj.remainingFraction)));
} else if (typeof rawObj.resetTime === 'string' && rawObj.resetTime.trim().length > 0) {
// Proto3 在配额完全耗尽(0.0)时会省略默认数值字段,此时凭有效 resetTime 判定为剩余 0
remFrac = 0;
// Proto3 在配额完全耗尽(0.0)时会省略默认数值字段;仅当 resetTime 是未来有效时间戳时才判定为 0% 剩余
const resetMs = parseIsoMs(rawObj.resetTime);
if (resetMs > nowMs) {
remFrac = 0;
}
}
if (remFrac === null) return null;
const usedFrac = Math.max(0, Math.min(1, 1 - remFrac));
@@ -60,11 +64,11 @@ export function normalizeQuotaFraction(rawObj) {
* 识别官方配额桶所属的时间窗口类型(`'5h'` 或 `'weekly'`)。
*
* @param {object} bucket
* @param {number} [groupBucketCount=1] 所属分组内的桶总数
* @param {number} [_groupBucketCount=1] 所属分组内的桶总数(保留参数签名兼容)
* @param {number} [nowMs=Date.now()] 当前毫秒时间戳
* @returns {'5h'|'weekly'}
*/
export function classifyOfficialBucketWindow(bucket, groupBucketCount = 1, nowMs = Date.now()) {
function classifyOfficialBucketWindow(bucket, _groupBucketCount = 1, nowMs = Date.now()) {
const w = String(bucket?.window || '')
.trim()
.toLowerCase();
@@ -80,19 +84,23 @@ export function classifyOfficialBucketWindow(bucket, groupBucketCount = 1, nowMs
return 'weekly';
}
const resetMs = parseIsoMs(bucket?.resetTime);
if (resetMs > nowMs + 6 * 3600 * 1000 || groupBucketCount === 1) {
return 'weekly';
if (resetMs > 0 && resetMs <= nowMs + 6 * 3600 * 1000) {
return '5h';
}
return '5h';
return 'weekly';
}
const THIRD_PARTY_POOL_RE =
/3p|claude|anthropic|fable|gpt|openai|oss|sonnet|opus|haiku|third[-_\s]?party/i;
/**
* 根据分组名称、分组描述及桶 ID 识别配额池归属身份(`Gemini` / `Argon` / `Claude & GPT`)。
* 根据分组名称、分组描述及桶 ID 识别配额池归属身份(`Gemini` / `Argon` / `Carbon` / `Claude & GPT`)。
* 优先识别显式的第三方模型池标识,防止分组描述附带 `"separate from Gemini"` 时把第三方池误吞入 Gemini。
*
* @param {{ groupName?: string, groupDesc?: string, bucketId?: string, bucketName?: string }} params
* @returns {{ poolKey: string, poolLabel: string, poolName: string }}
*/
export function classifyQuotaPoolIdentity({
function classifyQuotaPoolIdentity({
groupName = '',
groupDesc = '',
bucketId = '',
@@ -102,6 +110,8 @@ export function classifyQuotaPoolIdentity({
const bName = String(bucketName || '');
const gName = String(groupName || '');
const gDesc = String(groupDesc || '');
const primaryText = `${bId} ${bName} ${gName}`;
if (
/carbon/i.test(bId) ||
/carbon/i.test(bName) ||
@@ -130,20 +140,23 @@ export function classifyQuotaPoolIdentity({
poolName: 'Gemini 4 Argon 模型池',
};
}
if (/gemini/i.test(`${bId} ${bName} ${gName} ${gDesc}`)) {
return {
poolKey: 'Gemini',
poolLabel: 'Gemini',
poolName: 'Gemini 模型池',
};
}
if (/3p|claude|fable|gpt|sonnet|opus|haiku|third[-_\s]?party/i.test(`${bId} ${gName} ${gDesc}`)) {
if (
THIRD_PARTY_POOL_RE.test(primaryText) ||
(!/gemini/i.test(primaryText) && THIRD_PARTY_POOL_RE.test(gDesc))
) {
return {
poolKey: 'Claude & GPT',
poolLabel: 'Claude & GPT',
poolName: 'Claude & GPT 模型池',
};
}
if (/gemini/i.test(`${primaryText} ${gDesc}`)) {
return {
poolKey: 'Gemini',
poolLabel: 'Gemini',
poolName: 'Gemini 模型池',
};
}
const cleanLabel = (gName || bId || 'Other').trim();
return {
poolKey: cleanLabel,
@@ -159,7 +172,7 @@ export function classifyQuotaPoolIdentity({
* @param {ReturnType<typeof normalizeQuotaFraction>} b
* @returns {boolean}
*/
export function quotaFractionsMatch(a, b) {
function quotaFractionsMatch(a, b) {
if (!a || !b) return false;
if (Math.abs(a.remainingFraction - b.remainingFraction) > 0.015) return false;
if (a.resetTime && b.resetTime) {
@@ -213,7 +226,7 @@ export function buildOfficialQuotaPools(officialQuota, clientConfigs = []) {
for (const grp of rawGroups) {
const grpBuckets = Array.isArray(grp?.buckets) ? grp.buckets : [];
for (const b of grpBuckets) {
const norm = normalizeQuotaFraction(b);
const norm = normalizeQuotaFraction(b, nowForQuotaMs);
if (!norm) continue;
const ident = classifyQuotaPoolIdentity({
groupName: grp?.displayName,
@@ -229,17 +242,27 @@ export function buildOfficialQuotaPools(officialQuota, clientConfigs = []) {
window: win,
};
const builder = ensurePoolBuilder(ident);
if (win === '5h' && !builder.bucket5h) {
builder.bucket5h = entry;
} else if (win === 'weekly' && !builder.bucketWeekly) {
builder.bucketWeekly = entry;
} else if (win !== '5h' && !builder.bucketWeekly) {
if (win === '5h') {
if (!builder.bucket5h) {
builder.bucket5h = entry;
} else if (!builder.bucketWeekly) {
// 当同池两个无显式标签桶都处于 <6h 临近重置期时,按重置时间早晚区分 5h 与周限桶
const prevResetMs = parseIsoMs(builder.bucket5h.resetTime);
const nextResetMs = parseIsoMs(entry.resetTime);
if (prevResetMs > 0 && nextResetMs > 0 && nextResetMs < prevResetMs) {
builder.bucketWeekly = { ...builder.bucket5h, window: 'weekly' };
builder.bucket5h = entry;
} else {
builder.bucketWeekly = { ...entry, window: 'weekly' };
}
}
} else if (!builder.bucketWeekly) {
builder.bucketWeekly = entry;
}
}
}
// 注册动态模型字典,并采样 Carbon / Argon 与标准 Gemini 的单模型 quotaInfo
// 注册动态模型字典(不把占位符 rawKey 污染进 modelId),并采样 Carbon / Argon 与标准 Gemini 的单模型 quotaInfo
let sampleCarbonCfgQuota = null;
let sampleArgonCfgQuota = null;
let sampleStdGeminiCfgQuota = null;
@@ -248,13 +271,13 @@ export function buildOfficialQuotaPools(officialQuota, clientConfigs = []) {
const rawKey = cfg?.modelOrAlias?.model;
if (rawKey) {
dynamicModelMap.set(rawKey, {
modelId: cfg.modelId || rawKey,
modelId: cfg.modelId || '',
label: cfg.label || cfg.modelId || rawKey,
quotaInfo: cfg.quotaInfo || null,
});
}
const info = resolveModelInfo(rawKey, dynamicModelMap);
const cfgQuota = normalizeQuotaFraction(cfg?.quotaInfo);
const cfgQuota = normalizeQuotaFraction(cfg?.quotaInfo, nowForQuotaMs);
if (!cfgQuota || info.family !== 'Gemini') continue;
if (isCarbonModelIdentifier(rawKey, cfg?.modelId, cfg?.label, info.modelId)) {
if (!sampleCarbonCfgQuota) sampleCarbonCfgQuota = cfgQuota;
@@ -348,7 +371,7 @@ export function buildOfficialQuotaPools(officialQuota, clientConfigs = []) {
builder.models.push(cfg.label);
}
const cfgQuota = normalizeQuotaFraction(cfg?.quotaInfo);
const cfgQuota = normalizeQuotaFraction(cfg?.quotaInfo, nowForQuotaMs);
if (!builder.bucket5h && !builder.bucketWeekly && !builder.fallback5h && cfgQuota) {
if (targetIdent.poolKey === 'Argon' || targetIdent.poolKey === 'Carbon') {
builder.bucketWeekly = cfgQuota;
@@ -362,7 +385,7 @@ export function buildOfficialQuotaPools(officialQuota, clientConfigs = []) {
const hasValid5h = Boolean(eff5h);
modelQuotas.push({
label: cfg.label,
modelId: cfg.modelId,
modelId: cfg.modelId || info.modelId,
rawKey,
family: targetIdent.poolKey,
isAvailable: Boolean(eff5h || effWk || cfgQuota),