mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
refactor(panel): extract sqlite/wire primitives, localize charts & structured status, and unify overlay/mock-dom (P2)
This commit is contained in:
@@ -217,23 +217,35 @@ export function resolveModelDisplayInfo(target, settings = {}, options = {}) {
|
||||
}
|
||||
|
||||
const shortText = String(
|
||||
target.activeModelShort ?? target.modelShort ?? target.shortName ?? ''
|
||||
target.activeBaseModelShort ??
|
||||
target.baseModelShort ??
|
||||
target.activeModelShort ??
|
||||
target.modelShort ??
|
||||
target.shortName ??
|
||||
''
|
||||
).trim();
|
||||
const labelText = String(
|
||||
target.activeModelLabel ?? target.modelLabel ?? target.label ?? ''
|
||||
target.activeBaseModelLabel ??
|
||||
target.baseModelLabel ??
|
||||
target.activeModelLabel ??
|
||||
target.modelLabel ??
|
||||
target.label ??
|
||||
''
|
||||
).trim();
|
||||
const upstreamText = String(
|
||||
target.activeModelUpstream ?? target.modelUpstream ?? target.upstreamName ?? ''
|
||||
target.baseModelUpstream ??
|
||||
target.activeModelUpstream ??
|
||||
target.modelUpstream ??
|
||||
target.upstreamName ??
|
||||
''
|
||||
).trim();
|
||||
const rawCompactionText = `${target.activeModelShort ?? target.modelShort ?? ''} ${target.activeModelLabel ?? target.modelLabel ?? ''} ${target.activeModelUpstream ?? target.modelUpstream ?? ''}`;
|
||||
const responseText = String(target.responseModel ?? '').trim();
|
||||
const modelKeyText = String(target.modelKey ?? '').trim();
|
||||
|
||||
const isCompaction =
|
||||
Boolean(target.isCompactionStep) ||
|
||||
/·(?:压缩|compact)\s*$/iu.test(shortText) ||
|
||||
/·(?:压缩|compact)\s*$/iu.test(upstreamText) ||
|
||||
/·(?:压缩|compact)\s*$/iu.test(labelText) ||
|
||||
/\[自动压缩\]\s*$/u.test(labelText);
|
||||
/·(?:压缩|compact)(?=\s|$)|\[自动压缩\]/iu.test(rawCompactionText);
|
||||
|
||||
const compactionSuffix = isCompaction ? t('fmt.compactionSuffix') : '';
|
||||
|
||||
@@ -470,3 +482,131 @@ export function mergeModelsByDisplayName(models = [], settings = {}, options = {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据代理索引返回对应的微边框语义徽章样式类名。
|
||||
*
|
||||
* @param {number} [index=0]
|
||||
* @param {boolean} [isMain=false]
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getAgentBadgeClass(index = 0, isMain = false) {
|
||||
if (isMain || index <= 0) return 'badge-main';
|
||||
const slot = ((index - 1) % 3) + 1;
|
||||
return `badge-sub-${slot}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于结构化 `agentKind` / `agentOrdinal` 格式化主/子代理或旁路提问的紧凑徽章文本(零正则反拆中文)。
|
||||
*
|
||||
* @param {object|null|undefined} agent
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatAgentBadgeText(agent) {
|
||||
if (!agent) return t('fmt.mainBadge');
|
||||
const kind =
|
||||
agent.agentKind ||
|
||||
(agent.isMain
|
||||
? 'main'
|
||||
: agent.isSideQuestion || agent.typeName === 'side_question'
|
||||
? 'side_question'
|
||||
: 'subagent');
|
||||
if (kind === 'all') return t('header.scopeAllShort');
|
||||
if (kind === 'main') return t('fmt.mainBadge');
|
||||
if (kind === 'side_question') {
|
||||
const ord = Number(agent.agentOrdinal || agent.sideIndex || 0);
|
||||
if (ord > 0) return t('fmt.sideBadge', { index: ord });
|
||||
if (!isEnglishLocale() && agent.badgeText) return String(agent.badgeText);
|
||||
return t('fmt.sideBadgeShort');
|
||||
}
|
||||
const ord = Number(agent.agentOrdinal || agent.index || 0);
|
||||
if (ord > 0) return t('fmt.subBadge', { index: ord });
|
||||
if (!isEnglishLocale() && agent.badgeText) return String(agent.badgeText);
|
||||
return t('fmt.subBadgeShort');
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于结构化 `agentKind` / `agentOrdinal` / `customRole` 格式化代理完整显示名称(零正则反拆中文)。
|
||||
*
|
||||
* @param {object|null|undefined} agent
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatAgentLabel(agent) {
|
||||
if (!agent) return t('fmt.mainAgent');
|
||||
const kind =
|
||||
agent.agentKind ||
|
||||
(agent.isMain
|
||||
? 'main'
|
||||
: agent.isSideQuestion || agent.typeName === 'side_question'
|
||||
? 'side_question'
|
||||
: 'subagent');
|
||||
if (kind === 'all') return t('header.scopeAll');
|
||||
if (kind === 'main') return t('fmt.mainAgent');
|
||||
|
||||
const rawCustom =
|
||||
agent.customRole !== undefined
|
||||
? String(agent.customRole || '').trim()
|
||||
: String(agent.role || '').trim();
|
||||
if (kind === 'side_question') {
|
||||
const ord = Number(agent.agentOrdinal || agent.sideIndex || 0);
|
||||
const baseLabel = ord > 0 ? `${t('fmt.sideQuestion')} #${ord}` : t('fmt.sideQuestion');
|
||||
const isGeneric =
|
||||
!rawCustom ||
|
||||
rawCustom === baseLabel ||
|
||||
rawCustom === agent.shortLabel ||
|
||||
rawCustom === t('fmt.sideQuestion') ||
|
||||
rawCustom === 'Side Question' ||
|
||||
rawCustom === 'side_question';
|
||||
return isGeneric ? baseLabel : `${baseLabel} · ${rawCustom}`;
|
||||
}
|
||||
|
||||
const ord = Number(agent.agentOrdinal || agent.index || 0);
|
||||
const baseLabel = ord > 0 ? `${t('fmt.subAgent')} #${ord}` : t('fmt.subAgent');
|
||||
const isGeneric =
|
||||
!rawCustom ||
|
||||
rawCustom === baseLabel ||
|
||||
rawCustom === agent.shortLabel ||
|
||||
rawCustom === t('fmt.subAgent') ||
|
||||
rawCustom === 'Subagent';
|
||||
return isGeneric ? baseLabel : `${baseLabel} · ${rawCustom}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于后端结构化 `actionKey` + `waitingApproval` 渲染实时动作短标题(兼容自定义 `label` 回退)。
|
||||
*
|
||||
* @param {object|null|undefined} act
|
||||
* @param {string} [fallbackKey='live.thinking']
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatLiveActivityLabel(act, fallbackKey = 'live.thinking') {
|
||||
if (!act || typeof act !== 'object') return t(fallbackKey);
|
||||
let baseLabel = '';
|
||||
if (act.actionKey) {
|
||||
const i18nKey = `live.act.${act.actionKey}`;
|
||||
const translated = t(i18nKey);
|
||||
if (translated && translated !== i18nKey) {
|
||||
baseLabel = translated;
|
||||
}
|
||||
}
|
||||
if (!baseLabel) {
|
||||
baseLabel = String(act.label || '').trim() || t(fallbackKey);
|
||||
}
|
||||
if (act.waitingApproval) {
|
||||
return t('live.act.awaitingApproval', { label: baseLabel });
|
||||
}
|
||||
return baseLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于后端结构化 `detailKey` 渲染实时动作补充说明(兼容自由文本 `detail`)。
|
||||
*
|
||||
* @param {object|null|undefined} act
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatLiveActivityDetail(act) {
|
||||
if (!act || typeof act !== 'object') return '';
|
||||
if (act.detailKey === 'compaction_resuming') {
|
||||
return t('live.act.compactionResuming');
|
||||
}
|
||||
return String(act.detail || '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user