mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): add experimental quota reservation estimator, violet bar indicator, and clipboard log export
This commit is contained in:
@@ -389,9 +389,13 @@ export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides
|
||||
family: 'Gemini',
|
||||
usedPct: 36,
|
||||
remainingPct: 64,
|
||||
reservedPct: 1.0,
|
||||
reservedLeaseCount: 1,
|
||||
resetTime: reset5hIso,
|
||||
weeklyUsedPct: 48,
|
||||
weeklyRemainingPct: 52,
|
||||
weeklyReservedPct: 0.5,
|
||||
weeklyReservedLeaseCount: 1,
|
||||
weeklyResetTime: resetWkIso,
|
||||
cycle5h: { tokens: 1754800, costUsd: 1.28, calls: 24 },
|
||||
cycleWeekly: { tokens: 14200000, costUsd: 11.4, calls: 186 },
|
||||
|
||||
@@ -25,7 +25,11 @@ import { getEffectiveLocale, t } from '../../i18n/index.js';
|
||||
* @param {{ isPending?: boolean }} [options]
|
||||
* @returns {Array<object>}
|
||||
*/
|
||||
export function buildQuotaPoolItems(quotas, minuteTick = 0, { isPending = false } = {}) {
|
||||
export function buildQuotaPoolItems(
|
||||
quotas,
|
||||
minuteTick = 0,
|
||||
{ isPending = false, showReserved = false } = {}
|
||||
) {
|
||||
const safeQuotas = quotas || {};
|
||||
const activePool = safeQuotas.activePool || {};
|
||||
const rawPools =
|
||||
@@ -52,6 +56,7 @@ export function buildQuotaPoolItems(quotas, minuteTick = 0, { isPending = false
|
||||
isActivePool,
|
||||
minuteTick,
|
||||
isPending,
|
||||
showReserved: Boolean(showReserved),
|
||||
};
|
||||
});
|
||||
if (
|
||||
@@ -65,27 +70,45 @@ export function buildQuotaPoolItems(quotas, minuteTick = 0, { isPending = false
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建单个配额池的 DOM 行结构,内含 5h 限额与每周限额两个可独立显隐的子窗口进度条。
|
||||
* 创建单个配额池的 DOM 行结构,内含 5h 限额及每周限额两个可独立显隐的子窗口进度条。
|
||||
*/
|
||||
export function createPoolQuotaRow() {
|
||||
const title5h = h('span', { className: 'quota-win-title', text: '5h' });
|
||||
const usage5h = h('span', { className: 'quota-win-usage', hidden: true, text: '' });
|
||||
const left5h = h('span', { className: 'quota-win-left' }, [title5h, usage5h]);
|
||||
const meta5h = h('span', { className: 'panel-meta quota-win-meta text-mono', text: '--' });
|
||||
const meta5hBefore = h('span', { text: '--' });
|
||||
const meta5hReserved = h('span', { className: 'quota-reserved-pct', hidden: true, text: '' });
|
||||
const meta5hAfter = h('span', { hidden: true, text: '' });
|
||||
const meta5h = h('span', { className: 'panel-meta quota-win-meta text-mono' }, [
|
||||
meta5hBefore,
|
||||
meta5hReserved,
|
||||
meta5hAfter,
|
||||
]);
|
||||
const fill5h = h('div', { className: 'progress-fill' });
|
||||
const fillReserved5h = h('div', { className: 'progress-fill-reserved' });
|
||||
const track5h = h('div', { className: 'progress-track' }, [fill5h, fillReserved5h]);
|
||||
const row5h = h('div', { style: 'display: flex; flex-direction: column; gap: 4px;' }, [
|
||||
h('div', { className: 'panel-header quota-win-head' }, [left5h, meta5h]),
|
||||
h('div', { className: 'progress-track' }, [fill5h]),
|
||||
track5h,
|
||||
]);
|
||||
|
||||
const titleWk = h('span', { className: 'quota-win-title', text: t('quota.weeklyShort') });
|
||||
const usageWk = h('span', { className: 'quota-win-usage', hidden: true, text: '' });
|
||||
const leftWk = h('span', { className: 'quota-win-left' }, [titleWk, usageWk]);
|
||||
const metaWk = h('span', { className: 'panel-meta quota-win-meta text-mono', text: '--' });
|
||||
const metaWkBefore = h('span', { text: '--' });
|
||||
const metaWkReserved = h('span', { className: 'quota-reserved-pct', hidden: true, text: '' });
|
||||
const metaWkAfter = h('span', { hidden: true, text: '' });
|
||||
const metaWk = h('span', { className: 'panel-meta quota-win-meta text-mono' }, [
|
||||
metaWkBefore,
|
||||
metaWkReserved,
|
||||
metaWkAfter,
|
||||
]);
|
||||
const fillWk = h('div', { className: 'progress-fill' });
|
||||
const fillReservedWk = h('div', { className: 'progress-fill-reserved' });
|
||||
const trackWk = h('div', { className: 'progress-track' }, [fillWk, fillReservedWk]);
|
||||
const rowWk = h('div', { style: 'display: flex; flex-direction: column; gap: 4px;' }, [
|
||||
h('div', { className: 'panel-header quota-win-head' }, [leftWk, metaWk]),
|
||||
h('div', { className: 'progress-track' }, [fillWk]),
|
||||
trackWk,
|
||||
]);
|
||||
|
||||
const el = h('div', { className: 'quota-pool-row' }, [
|
||||
@@ -101,13 +124,23 @@ export function createPoolQuotaRow() {
|
||||
title5h,
|
||||
usage5h,
|
||||
meta5h,
|
||||
meta5hBefore,
|
||||
meta5hReserved,
|
||||
meta5hAfter,
|
||||
track5h,
|
||||
fill5h,
|
||||
fillReserved5h,
|
||||
rowWk,
|
||||
leftWk,
|
||||
titleWk,
|
||||
usageWk,
|
||||
metaWk,
|
||||
metaWkBefore,
|
||||
metaWkReserved,
|
||||
metaWkAfter,
|
||||
trackWk,
|
||||
fillWk,
|
||||
fillReservedWk,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -133,11 +166,84 @@ export function formatQuotaSummaryFooter(quotas, account) {
|
||||
return { leftText, rightText, tooltip };
|
||||
}
|
||||
|
||||
function syncQuotaWindowMeter({
|
||||
hasData,
|
||||
usedVal,
|
||||
remVal,
|
||||
resetTime,
|
||||
fallbackMetaText,
|
||||
showReserved,
|
||||
rawReservedPct,
|
||||
leaseCount,
|
||||
metaBeforeEl,
|
||||
metaReservedEl,
|
||||
metaAfterEl,
|
||||
trackEl,
|
||||
fillEl,
|
||||
fillReservedEl,
|
||||
}) {
|
||||
const numReserved = showReserved && hasData ? Number(rawReservedPct || 0) : 0;
|
||||
const rsvVal =
|
||||
Number.isFinite(numReserved) && numReserved >= 0.05 ? Math.min(usedVal, numReserved) : 0;
|
||||
const actualVal = Math.max(0, usedVal - rsvVal);
|
||||
const resetStr = hasData ? formatCountdown(resetTime) : '';
|
||||
|
||||
if (hasData && rsvVal > 0) {
|
||||
const rsvStr = rsvVal.toFixed(1);
|
||||
const actualStr = actualVal.toFixed(1);
|
||||
const leases = Math.max(1, Number(leaseCount) || 1);
|
||||
const tipText =
|
||||
leases >= 2
|
||||
? t('quota.reservedTipMulti', { rsv: rsvStr, leases, actual: actualStr })
|
||||
: t('quota.reservedTip', { rsv: rsvStr, actual: actualStr });
|
||||
patchText(
|
||||
metaBeforeEl,
|
||||
t('quota.usedBeforeReserved', { reset: resetStr, used: usedVal.toFixed(1) })
|
||||
);
|
||||
metaReservedEl.hidden = false;
|
||||
patchText(metaReservedEl, t('quota.reservedTag', { rsv: rsvStr }));
|
||||
patchAttr(metaReservedEl, 'title', tipText);
|
||||
metaAfterEl.hidden = false;
|
||||
patchText(metaAfterEl, t('quota.usedAfterReserved', { rem: remVal.toFixed(1) }));
|
||||
patchAttr(trackEl, 'title', tipText);
|
||||
const actualWidth = +Math.min(100, actualVal).toFixed(2);
|
||||
const rsvWidth = +Math.min(Math.max(0, 100 - actualWidth), rsvVal).toFixed(2);
|
||||
patchStyleVar(fillEl, '--fill-w', `${actualWidth}%`);
|
||||
patchStyleVar(fillReservedEl, '--reserved-w', `${rsvWidth}%`);
|
||||
patchClasses(fillReservedEl, { 'is-active': true });
|
||||
} else {
|
||||
patchText(
|
||||
metaBeforeEl,
|
||||
hasData
|
||||
? t('quota.usedAndLeft', {
|
||||
reset: resetStr,
|
||||
used: usedVal.toFixed(1),
|
||||
rem: remVal.toFixed(1),
|
||||
})
|
||||
: fallbackMetaText
|
||||
);
|
||||
metaReservedEl.hidden = true;
|
||||
patchText(metaReservedEl, '');
|
||||
patchAttr(metaReservedEl, 'title', null);
|
||||
metaAfterEl.hidden = true;
|
||||
patchText(metaAfterEl, '');
|
||||
patchAttr(trackEl, 'title', null);
|
||||
patchStyleVar(fillEl, '--fill-w', `${Math.min(100, usedVal)}%`);
|
||||
patchStyleVar(fillReservedEl, '--reserved-w', '0%');
|
||||
patchClasses(fillReservedEl, { 'is-active': false });
|
||||
}
|
||||
|
||||
patchClasses(fillEl, {
|
||||
'tone-warn': usedVal >= 70 && usedVal < 85,
|
||||
'tone-danger': usedVal >= 85,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步单个配额池行的 5h 与每周窗口状态。
|
||||
* 同步单个配额池行的 5h 及每周窗口状态。
|
||||
*/
|
||||
export function syncPoolQuotaRow(refs, item, idx, rowEl) {
|
||||
const { poolData, poolLabel, fallbackWeekly, isActivePool, isPending } = item;
|
||||
const { poolData, poolLabel, fallbackWeekly, isActivePool, isPending, showReserved } = item;
|
||||
patchClasses(rowEl, { 'quota-pool-row': true, 'has-divider': idx > 0 });
|
||||
|
||||
const has5h = poolData?.usedPct != null && poolData?.remainingPct != null;
|
||||
@@ -166,6 +272,7 @@ export function syncPoolQuotaRow(refs, item, idx, rowEl) {
|
||||
refs.rowWk.style.display = hideWk ? 'none' : 'flex';
|
||||
|
||||
const fallbackMetaText = isPending ? t('quota.loading') : t('quota.failed');
|
||||
const allowReserved = Boolean(showReserved && !isPending);
|
||||
|
||||
patchText(refs.title5h, `5h (${poolLabel})`);
|
||||
const c5h = poolData?.cycle5h;
|
||||
@@ -190,20 +297,21 @@ export function syncPoolQuotaRow(refs, item, idx, rowEl) {
|
||||
patchText(refs.usage5h, '');
|
||||
patchAttr(refs.left5h, 'title', null);
|
||||
}
|
||||
patchText(
|
||||
refs.meta5h,
|
||||
has5h
|
||||
? t('quota.usedAndLeft', {
|
||||
reset: formatCountdown(poolData.resetTime),
|
||||
used: used5hVal.toFixed(1),
|
||||
rem: rem5hVal.toFixed(1),
|
||||
})
|
||||
: fallbackMetaText
|
||||
);
|
||||
patchStyleVar(refs.fill5h, '--fill-w', `${Math.min(100, used5hVal)}%`);
|
||||
patchClasses(refs.fill5h, {
|
||||
'tone-warn': used5hVal >= 70 && used5hVal < 85,
|
||||
'tone-danger': used5hVal >= 85,
|
||||
syncQuotaWindowMeter({
|
||||
hasData: has5h,
|
||||
usedVal: used5hVal,
|
||||
remVal: rem5hVal,
|
||||
resetTime: poolData?.resetTime,
|
||||
fallbackMetaText,
|
||||
showReserved: allowReserved,
|
||||
rawReservedPct: poolData?.reservedPct,
|
||||
leaseCount: poolData?.reservedLeaseCount,
|
||||
metaBeforeEl: refs.meta5hBefore,
|
||||
metaReservedEl: refs.meta5hReserved,
|
||||
metaAfterEl: refs.meta5hAfter,
|
||||
trackEl: refs.track5h,
|
||||
fillEl: refs.fill5h,
|
||||
fillReservedEl: refs.fillReserved5h,
|
||||
});
|
||||
|
||||
const customTitle =
|
||||
@@ -237,20 +345,21 @@ export function syncPoolQuotaRow(refs, item, idx, rowEl) {
|
||||
patchText(refs.usageWk, '');
|
||||
patchAttr(refs.leftWk, 'title', null);
|
||||
}
|
||||
patchText(
|
||||
refs.metaWk,
|
||||
hasWk
|
||||
? t('quota.usedAndLeft', {
|
||||
reset: formatCountdown(wkResetRaw),
|
||||
used: usedWkVal.toFixed(1),
|
||||
rem: remWkVal.toFixed(1),
|
||||
})
|
||||
: fallbackMetaText
|
||||
);
|
||||
patchStyleVar(refs.fillWk, '--fill-w', `${Math.min(100, usedWkVal)}%`);
|
||||
patchClasses(refs.fillWk, {
|
||||
'tone-warn': usedWkVal >= 70 && usedWkVal < 85,
|
||||
'tone-danger': usedWkVal >= 85,
|
||||
syncQuotaWindowMeter({
|
||||
hasData: hasWk,
|
||||
usedVal: usedWkVal,
|
||||
remVal: remWkVal,
|
||||
resetTime: wkResetRaw,
|
||||
fallbackMetaText,
|
||||
showReserved: allowReserved && !useCustomWeekly,
|
||||
rawReservedPct: poolData?.weeklyReservedPct,
|
||||
leaseCount: poolData?.weeklyReservedLeaseCount,
|
||||
metaBeforeEl: refs.metaWkBefore,
|
||||
metaReservedEl: refs.metaWkReserved,
|
||||
metaAfterEl: refs.metaWkAfter,
|
||||
trackEl: refs.trackWk,
|
||||
fillEl: refs.fillWk,
|
||||
fillReservedEl: refs.fillReservedWk,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -258,7 +367,7 @@ export function quotaPoolRowSig(item, idx) {
|
||||
const c5h = item.poolData?.cycle5h;
|
||||
const cWk = item.poolData?.cycleWeekly;
|
||||
const fw = item.fallbackWeekly;
|
||||
return `${getEffectiveLocale()}:${idx}:${item.poolLabel}:${item.isActivePool}:${Boolean(item.isPending)}:${item.minuteTick}:${item.poolData?.usedPct}:${item.poolData?.remainingPct}:${item.poolData?.resetTime}:${item.poolData?.weeklyUsedPct}:${item.poolData?.weeklyRemainingPct}:${item.poolData?.weeklyResetTime}:${c5h?.tokens}:${c5h?.costUsd}:${c5h?.calls}:${cWk?.tokens}:${cWk?.costUsd}:${cWk?.calls}:${fw?.isOfficial}:${fw?.usedPct}:${fw?.remainingPct}:${fw?.resetTime}:${fw?.title}:${fw?.tokens}:${fw?.costUsd}:${fw?.calls}`;
|
||||
return `${getEffectiveLocale()}:${idx}:${item.poolLabel}:${item.isActivePool}:${Boolean(item.isPending)}:${Boolean(item.showReserved)}:${item.minuteTick}:${item.poolData?.usedPct}:${item.poolData?.remainingPct}:${item.poolData?.reservedPct}:${item.poolData?.reservedLeaseCount}:${item.poolData?.resetTime}:${item.poolData?.weeklyUsedPct}:${item.poolData?.weeklyRemainingPct}:${item.poolData?.weeklyReservedPct}:${item.poolData?.weeklyReservedLeaseCount}:${item.poolData?.weeklyResetTime}:${c5h?.tokens}:${c5h?.costUsd}:${c5h?.calls}:${cWk?.tokens}:${cWk?.costUsd}:${cWk?.calls}:${fw?.isOfficial}:${fw?.usedPct}:${fw?.remainingPct}:${fw?.resetTime}:${fw?.title}:${fw?.tokens}:${fw?.costUsd}:${fw?.calls}`;
|
||||
}
|
||||
|
||||
export const QuotaPoolsWidget = defineComponent({
|
||||
@@ -309,12 +418,13 @@ export const QuotaPoolsWidget = defineComponent({
|
||||
}
|
||||
|
||||
const quotas = data.quotas || {};
|
||||
const showReserved = data.settings?.experimentalQuotaReservation === true;
|
||||
const effTick = Number.isFinite(minuteTick) ? minuteTick : Math.floor(Date.now() / 30000);
|
||||
patchText(
|
||||
tierBadge,
|
||||
`${data.account?.tierName || 'Google AI'} · ${data.account?.planName || 'Pro'}`
|
||||
);
|
||||
patchKeyedList(poolsListEl, buildQuotaPoolItems(quotas, effTick), {
|
||||
patchKeyedList(poolsListEl, buildQuotaPoolItems(quotas, effTick, { showReserved }), {
|
||||
keyFn: (item) => item.key,
|
||||
sigFn: quotaPoolRowSig,
|
||||
createRow: createPoolQuotaRow,
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import {
|
||||
normalizeCliStatusLineSlots,
|
||||
normalizeContextAgentMode,
|
||||
normalizeExperimentalQuotaReservation,
|
||||
normalizeFontScale,
|
||||
normalizeHoverModules,
|
||||
normalizeLanguageSetting,
|
||||
@@ -120,6 +121,9 @@ export function buildExportableSettingsJson(settings = {}) {
|
||||
showStepFilterToolbar: src.showStepFilterToolbar === true,
|
||||
stepTokenComboFormat: normalizeStepTokenComboFormat(src.stepTokenComboFormat),
|
||||
stepTableColumns: normalizeStepTableColumns(src.stepTableColumns),
|
||||
experimentalQuotaReservation: normalizeExperimentalQuotaReservation(
|
||||
src.experimentalQuotaReservation
|
||||
),
|
||||
},
|
||||
};
|
||||
return `${JSON.stringify(payload, null, 2)}\n`;
|
||||
@@ -242,6 +246,11 @@ export function parseImportedSettingsJson(rawText) {
|
||||
if (hasKey('stepTableColumns') && Array.isArray(src.stepTableColumns)) {
|
||||
patch.stepTableColumns = normalizeStepTableColumns(src.stepTableColumns);
|
||||
}
|
||||
if (hasKey('experimentalQuotaReservation')) {
|
||||
patch.experimentalQuotaReservation = normalizeExperimentalQuotaReservation(
|
||||
src.experimentalQuotaReservation
|
||||
);
|
||||
}
|
||||
|
||||
const appliedCount = Object.keys(patch).length;
|
||||
if (appliedCount === 0) {
|
||||
|
||||
@@ -182,6 +182,11 @@ export const I18N_MESSAGES_EN_US = Object.freeze({
|
||||
'quota.loading': 'Loading...',
|
||||
'quota.failed': 'Unavailable (--%)',
|
||||
'quota.usedAndLeft': '{reset} · Used {used}% ({rem}% left)',
|
||||
'quota.usedBeforeReserved': '{reset} · Used {used}% (',
|
||||
'quota.reservedTag': '{rsv}% rsv',
|
||||
'quota.usedAfterReserved': ' · {rem}% left)',
|
||||
'quota.reservedTip': 'Estimated lease reservation (Experimental): ~{rsv}% (~{actual}% actual used); unused share refunds after ~10 min idle',
|
||||
'quota.reservedTipMulti': 'Estimated lease reservation (Experimental): ~{rsv}% ({leases} stacked leases, ~{actual}% actual used); unused share refunds after ~10 min idle',
|
||||
'quota.cycle5hTitle': 'Current 5h cycle ({pool}): {tok} Tokens · {cost} · {calls} calls',
|
||||
'quota.cycleWkCustomTitle': 'Current calendar week: {tok} Tokens · {cost} · {calls} calls',
|
||||
'quota.cycleWkPoolTitle': 'Current weekly cycle ({pool}): {tok} Tokens · {cost} · {calls} calls',
|
||||
@@ -681,6 +686,16 @@ export const I18N_MESSAGES_EN_US = Object.freeze({
|
||||
'settings.oth.orchFormat': 'Orchestrator Series ID',
|
||||
'settings.oth.orchCompact': 'Compact Alias (e.g. orchestrator-argon)',
|
||||
'settings.oth.orchFull': 'Full Upstream ID (e.g. gemini-pro-orchestrator)',
|
||||
'settings.oth.expTitle': 'Experimental',
|
||||
'settings.oth.expBadge': 'Experimental',
|
||||
'settings.oth.quotaReserveLabel': 'Quota Reservation Estimate',
|
||||
'settings.oth.quotaReserveDesc': 'Estimate 0.5% / 1% 5h & weekly lease holds in Available Quotas and highlight the reserved share in violet',
|
||||
'settings.oth.quotaReserveLogLabel': 'Reservation Observation Log',
|
||||
'settings.oth.quotaReserveLogDesc': 'Copy in-memory quota jump & refund events to clipboard for threshold tuning',
|
||||
'settings.oth.exportReserveLogBtn': 'Export Reserve Log',
|
||||
'settings.oth.exportReserveLogCopied': 'Copied {count} log entries to clipboard',
|
||||
'settings.oth.exportReserveLogEmpty': 'No events yet; copied current summary to clipboard',
|
||||
'settings.oth.exportReserveLogFailed': 'Failed to copy reservation log',
|
||||
'settings.oth.baselineTitle': 'Model Context Settings',
|
||||
'settings.oth.ctxRiskTitle': 'Unofficial Override Risk Warning',
|
||||
'settings.oth.ctxRiskBody': 'Google has not authorized modifying model context limits in Antigravity App / IDE. Altering context limits may get your Antigravity access, GCP services, or Google account disabled or banned; enabling this feature means you assume all associated risks. Make sure you know what you are doing!',
|
||||
|
||||
@@ -182,6 +182,11 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({
|
||||
'quota.loading': '读取中...',
|
||||
'quota.failed': '获取失败 (--%)',
|
||||
'quota.usedAndLeft': '{reset} · 已用 {used}% (余 {rem}%)',
|
||||
'quota.usedBeforeReserved': '{reset} · 已用 {used}% (',
|
||||
'quota.reservedTag': '预占 {rsv}%',
|
||||
'quota.usedAfterReserved': ' · 余 {rem}%)',
|
||||
'quota.reservedTip': '预占估算(试验性):约 {rsv}%(实际已用约 {actual}%),静默约 10 分钟后未用差额自动退还',
|
||||
'quota.reservedTipMulti': '预占估算(试验性):约 {rsv}%(检测到 {leases} 笔叠加租约,实际已用约 {actual}%),静默约 10 分钟后未用差额自动退还',
|
||||
'quota.cycle5hTitle': '当前 5h 周期累计 ({pool}):{tok} Tokens · {cost} · {calls} 次调用',
|
||||
'quota.cycleWkCustomTitle': '本周自然周累计:{tok} Tokens · {cost} · {calls} 次调用',
|
||||
'quota.cycleWkPoolTitle': '当前周限周期累计 ({pool}):{tok} Tokens · {cost} · {calls} 次调用',
|
||||
@@ -681,6 +686,16 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({
|
||||
'settings.oth.orchFormat': 'Orchestrator 系列 ID',
|
||||
'settings.oth.orchCompact': '精简代号 (如 orchestrator-argon)',
|
||||
'settings.oth.orchFull': '原始完整 ID (如 gemini-pro-orchestrator)',
|
||||
'settings.oth.expTitle': '试验性功能',
|
||||
'settings.oth.expBadge': '试验性',
|
||||
'settings.oth.quotaReserveLabel': '配额预占估算',
|
||||
'settings.oth.quotaReserveDesc': '在可用额度中估算 5h / 周限的 0.5% / 1% 租约预占,并用紫色标注占比及进度条段',
|
||||
'settings.oth.quotaReserveLogLabel': '预占观测日志',
|
||||
'settings.oth.quotaReserveLogDesc': '将内存中的配额跳变及退还记录复制到剪贴板,便于分析触发阈值',
|
||||
'settings.oth.exportReserveLogBtn': '导出预占日志',
|
||||
'settings.oth.exportReserveLogCopied': '已复制 {count} 条观测日志到剪贴板',
|
||||
'settings.oth.exportReserveLogEmpty': '暂无跳变记录,已复制当前摘要到剪贴板',
|
||||
'settings.oth.exportReserveLogFailed': '获取或复制预占日志失败',
|
||||
'settings.oth.baselineTitle': '模型上下文设置',
|
||||
'settings.oth.ctxRiskTitle': '非官方能力风险提示',
|
||||
'settings.oth.ctxRiskBody': 'Google 官方并未授权在 Antigravity App / IDE 中修改模型上下文上限。擅自修改可能导致 Antigravity 或 GCP 服务被禁用,甚至触发账号封禁;启用该功能即默认由你自行承担全部风险。你最好清楚自己在做什么!',
|
||||
|
||||
@@ -44,6 +44,7 @@ import {
|
||||
TOPBAR_SLOT_KEYS,
|
||||
normalizeCliStatusLineSlots,
|
||||
normalizeContextAgentMode,
|
||||
normalizeExperimentalQuotaReservation,
|
||||
normalizeHoverModules,
|
||||
normalizeModelDisplayMode,
|
||||
normalizeOrchestratorIdMode,
|
||||
@@ -468,6 +469,7 @@ export const normalizeClientPopoverWidth = normalizePopoverWidth;
|
||||
export const normalizeClientModelDisplayMode = normalizeModelDisplayMode;
|
||||
export const normalizeClientTopbarSlots = normalizeTopbarCapsuleSlots;
|
||||
export const normalizeClientContextAgentMode = normalizeContextAgentMode;
|
||||
export const normalizeClientExperimentalQuotaReservation = normalizeExperimentalQuotaReservation;
|
||||
export const normalizeClientCliStatusLineSlots = normalizeCliStatusLineSlots;
|
||||
|
||||
/**
|
||||
@@ -606,6 +608,12 @@ export function isEquivalentTelemetry(prev, next) {
|
||||
if (Boolean(pSet?.showStepFilterToolbar) !== Boolean(nSet?.showStepFilterToolbar)) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
normalizeClientExperimentalQuotaReservation(pSet?.experimentalQuotaReservation) !==
|
||||
normalizeClientExperimentalQuotaReservation(nSet?.experimentalQuotaReservation)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (!sameArr(pSet?.topbarCapsuleSlots, nSet?.topbarCapsuleSlots)) return false;
|
||||
if (!sameArr(pSet?.hoverModules, nSet?.hoverModules)) return false;
|
||||
if (!sameArr(pSet?.overviewModules, nSet?.overviewModules)) return false;
|
||||
@@ -1068,9 +1076,13 @@ export function isEquivalentTelemetry(prev, next) {
|
||||
pPools[i]?.poolLabel !== nPools[i]?.poolLabel ||
|
||||
pPools[i]?.usedPct !== nPools[i]?.usedPct ||
|
||||
pPools[i]?.remainingPct !== nPools[i]?.remainingPct ||
|
||||
pPools[i]?.reservedPct !== nPools[i]?.reservedPct ||
|
||||
pPools[i]?.reservedLeaseCount !== nPools[i]?.reservedLeaseCount ||
|
||||
pPools[i]?.resetTime !== nPools[i]?.resetTime ||
|
||||
pPools[i]?.weeklyUsedPct !== nPools[i]?.weeklyUsedPct ||
|
||||
pPools[i]?.weeklyRemainingPct !== nPools[i]?.weeklyRemainingPct ||
|
||||
pPools[i]?.weeklyReservedPct !== nPools[i]?.weeklyReservedPct ||
|
||||
pPools[i]?.weeklyReservedLeaseCount !== nPools[i]?.weeklyReservedLeaseCount ||
|
||||
pPools[i]?.weeklyResetTime !== nPools[i]?.weeklyResetTime ||
|
||||
pPools[i]?.cycle5h?.tokens !== nPools[i]?.cycle5h?.tokens ||
|
||||
pPools[i]?.cycle5h?.costUsd !== nPools[i]?.cycle5h?.costUsd ||
|
||||
@@ -1794,6 +1806,11 @@ export async function saveSettingsPatch(patch) {
|
||||
if (Object.prototype.hasOwnProperty.call(safePatch, 'showStepFilterToolbar')) {
|
||||
safePatch.showStepFilterToolbar = Boolean(safePatch.showStepFilterToolbar);
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(safePatch, 'experimentalQuotaReservation')) {
|
||||
safePatch.experimentalQuotaReservation = normalizeClientExperimentalQuotaReservation(
|
||||
safePatch.experimentalQuotaReservation
|
||||
);
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(safePatch, 'topbarCapsuleSlots')) {
|
||||
safePatch.topbarCapsuleSlots = normalizeClientTopbarSlots(safePatch.topbarCapsuleSlots);
|
||||
}
|
||||
@@ -2074,6 +2091,17 @@ export async function fetchSessionMigrationCatalog() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchQuotaReservationLog() {
|
||||
try {
|
||||
return await callSidecarApi('/api/quota-reservation/log', { method: 'GET' });
|
||||
} catch {
|
||||
return callSidecarApi('/api/settings', {
|
||||
method: 'POST',
|
||||
body: { __quotaReservationAction: 'log' },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function executeSessionMigration(payload) {
|
||||
let res;
|
||||
try {
|
||||
|
||||
@@ -88,6 +88,10 @@
|
||||
--metric-danger: hsl(4 78% 55%);
|
||||
--metric-danger-soft: color-mix(in srgb, var(--metric-danger) 14%, transparent);
|
||||
|
||||
--quota-reserved: hsl(262 76% 58%);
|
||||
--quota-reserved-soft: color-mix(in srgb, var(--quota-reserved) 13%, transparent);
|
||||
--quota-reserved-border: color-mix(in srgb, var(--quota-reserved) 34%, transparent);
|
||||
|
||||
/* Context Window 10-Channel Palette */
|
||||
--ctx-assistant: hsl(215 62% 52%);
|
||||
--ctx-tool-results: hsl(172 68% 40%);
|
||||
@@ -126,6 +130,7 @@
|
||||
:root[data-color-scheme="dark"],
|
||||
:host([data-color-scheme="dark"]),
|
||||
[data-color-scheme="dark"] {
|
||||
--quota-reserved: hsl(264 86% 72%);
|
||||
--ctx-assistant: hsl(216 30% 58%);
|
||||
--ctx-tool-results: hsl(168 72% 54%);
|
||||
--ctx-user-input: hsl(258 86% 73%);
|
||||
|
||||
@@ -577,6 +577,23 @@
|
||||
background: var(--metric-danger);
|
||||
}
|
||||
|
||||
.progress-fill-reserved {
|
||||
height: 100%;
|
||||
width: var(--reserved-w, 0%);
|
||||
background: var(--quota-reserved);
|
||||
transition: width var(--dur-normal) var(--ease-fast);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.progress-fill-reserved.is-active {
|
||||
min-width: 3px;
|
||||
}
|
||||
|
||||
.quota-reserved-pct {
|
||||
color: var(--quota-reserved);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* --- 4. 上下文双列图例网格 (Context 10-Channel Legend Grid) --- */
|
||||
.ctx-legend-grid {
|
||||
display: grid;
|
||||
|
||||
@@ -1559,3 +1559,25 @@
|
||||
.cli-status-action-btn[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.settings-experimental-label-group {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.settings-experimental-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--radius-pill);
|
||||
background: var(--quota-reserved-soft);
|
||||
border: 1px solid var(--quota-reserved-border);
|
||||
color: var(--quota-reserved);
|
||||
font-size: var(--fs-2xs);
|
||||
font-weight: 600;
|
||||
line-height: 1.35;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,13 @@ import {
|
||||
buildExportableSettingsJson,
|
||||
parseImportedSettingsJson,
|
||||
} from '../../core/settingsBackup.js';
|
||||
import { exportTextFileWithFeedback } from '../../core/fileExportClient.js';
|
||||
import {
|
||||
copyTextWithFeedback,
|
||||
exportTextFileWithFeedback,
|
||||
} from '../../core/fileExportClient.js';
|
||||
import {
|
||||
fetchQuotaReservationLog,
|
||||
normalizeClientExperimentalQuotaReservation,
|
||||
normalizeClientModelDisplayMode,
|
||||
normalizeClientOrchestratorIdMode,
|
||||
rebuildTrajectoryCache,
|
||||
@@ -22,9 +27,33 @@ import {
|
||||
saveSettingsPatch,
|
||||
} from '../../store/telemetryStore.js';
|
||||
import { CustomSelect } from '../../components/ui/CustomSelect.js';
|
||||
import { SegmentedControl } from '../../components/ui/SegmentedControl.js';
|
||||
import { BridgeStatusNotice } from '../../components/settings/BridgeStatusNotice.js';
|
||||
import { SessionMigrationCard } from '../../components/settings/SessionMigrationCard.js';
|
||||
|
||||
function getEnableToggleOptions() {
|
||||
return [
|
||||
{ value: 'on', label: t('settings.str.on') },
|
||||
{ value: 'off', label: t('settings.str.off') },
|
||||
];
|
||||
}
|
||||
|
||||
function formatQuotaReservationLogForClipboard(snapshot) {
|
||||
const safe = snapshot && typeof snapshot === 'object' ? snapshot : {};
|
||||
const buckets = Array.isArray(safe.buckets) ? safe.buckets : [];
|
||||
const events = Array.isArray(safe.events) ? safe.events : [];
|
||||
const bucketLines = buckets.map((b) => ` ${JSON.stringify(b)}`).join(',\n');
|
||||
const eventLines = events.map((e) => ` ${JSON.stringify(e)}`).join(',\n');
|
||||
return [
|
||||
'{',
|
||||
` "generatedAt": ${JSON.stringify(safe.generatedAt || new Date().toISOString())},`,
|
||||
` "count": ${events.length},`,
|
||||
` "buckets": [${bucketLines ? `\n${bucketLines}\n ` : ''}],`,
|
||||
` "events": [${eventLines ? `\n${eventLines}\n ` : ''}]`,
|
||||
'}',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function getStepModelDisplayOptions() {
|
||||
return [
|
||||
{ value: 'short', label: t('settings.oth.modelShort') },
|
||||
@@ -45,6 +74,7 @@ export const SettingsOtherTab = defineComponent({
|
||||
setup({ onCleanup, getProps }) {
|
||||
let draftModelDisplayMode = 'short';
|
||||
let draftOrchestratorIdMode = 'compact';
|
||||
let draftExperimentalQuotaReservation = false;
|
||||
let draftContextRiskAccepted = false;
|
||||
let acceptingContextRisk = false;
|
||||
let latestSettings = null;
|
||||
@@ -55,6 +85,7 @@ export const SettingsOtherTab = defineComponent({
|
||||
let savingContextWindow = false;
|
||||
let contextFeedback = '';
|
||||
let modelTimer = null;
|
||||
let expTimer = null;
|
||||
let maintTimer = null;
|
||||
let resetConfirmTimer = null;
|
||||
let resetConfirmArmed = false;
|
||||
@@ -66,12 +97,31 @@ export const SettingsOtherTab = defineComponent({
|
||||
style: 'font-size: var(--fs-md);',
|
||||
text: '',
|
||||
});
|
||||
const expStatusText = h('span', {
|
||||
className: 'text-muted',
|
||||
style: 'font-size: var(--fs-md);',
|
||||
text: '',
|
||||
});
|
||||
const maintStatusText = h('span', {
|
||||
className: 'text-muted',
|
||||
style: 'font-size: var(--fs-md);',
|
||||
text: '',
|
||||
});
|
||||
|
||||
function showExpFeedback(text, autoClearMs = 1500) {
|
||||
if (expTimer) {
|
||||
clearTimeout(expTimer);
|
||||
expTimer = null;
|
||||
}
|
||||
patchText(expStatusText, text);
|
||||
if (text && autoClearMs > 0) {
|
||||
expTimer = setTimeout(() => {
|
||||
expTimer = null;
|
||||
patchText(expStatusText, '');
|
||||
}, autoClearMs);
|
||||
}
|
||||
}
|
||||
|
||||
function showModelFeedback(text, autoClearMs = 1500) {
|
||||
if (modelTimer) {
|
||||
clearTimeout(modelTimer);
|
||||
@@ -164,6 +214,112 @@ export const SettingsOtherTab = defineComponent({
|
||||
h('div', { className: 'form-row' }, [orchFormatLabelEl, orchestratorIdSelect.el]),
|
||||
]);
|
||||
|
||||
// --- Card 2: 试验性功能 ---
|
||||
const expTitleEl = h('span', { text: t('settings.oth.expTitle') });
|
||||
const quotaReserveLabelEl = h('span', {
|
||||
className: 'settings-action-title',
|
||||
text: t('settings.oth.quotaReserveLabel'),
|
||||
});
|
||||
const quotaReserveBadgeEl = h('span', {
|
||||
className: 'settings-experimental-badge',
|
||||
text: t('settings.oth.expBadge'),
|
||||
});
|
||||
const quotaReserveDescEl = h('span', {
|
||||
className: 'settings-action-desc',
|
||||
text: t('settings.oth.quotaReserveDesc'),
|
||||
});
|
||||
const quotaReserveLogLabelEl = h('span', {
|
||||
className: 'settings-action-title',
|
||||
text: t('settings.oth.quotaReserveLogLabel'),
|
||||
});
|
||||
const quotaReserveLogDescEl = h('span', {
|
||||
className: 'settings-action-desc',
|
||||
text: t('settings.oth.quotaReserveLogDesc'),
|
||||
});
|
||||
const exportReserveLogBtnText = h('span', {
|
||||
text: t('settings.oth.exportReserveLogBtn'),
|
||||
});
|
||||
let isExportingReserveLog = false;
|
||||
|
||||
const exportReserveLogBtn = h(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
className: 'btn-secondary',
|
||||
onClick: async () => {
|
||||
if (isExportingReserveLog) return;
|
||||
isExportingReserveLog = true;
|
||||
patchAttr(exportReserveLogBtn, 'disabled', true);
|
||||
try {
|
||||
const snapshot = await fetchQuotaReservationLog();
|
||||
const text = formatQuotaReservationLogForClipboard(snapshot);
|
||||
const count = Array.isArray(snapshot?.events) ? snapshot.events.length : 0;
|
||||
const successMsg =
|
||||
count > 0
|
||||
? t('settings.oth.exportReserveLogCopied', { count })
|
||||
: t('settings.oth.exportReserveLogEmpty');
|
||||
const ok = await copyTextWithFeedback(text, successMsg);
|
||||
showExpFeedback(ok ? successMsg : t('settings.oth.exportReserveLogFailed'), 2800);
|
||||
} catch {
|
||||
showExpFeedback(t('settings.oth.exportReserveLogFailed'), 2800);
|
||||
} finally {
|
||||
isExportingReserveLog = false;
|
||||
patchAttr(exportReserveLogBtn, 'disabled', false);
|
||||
}
|
||||
},
|
||||
},
|
||||
[createSvgIcon('copy', { size: 12 }), exportReserveLogBtnText]
|
||||
);
|
||||
|
||||
const quotaReserveToggle = SegmentedControl({
|
||||
modelValue: 'off',
|
||||
ariaLabel: t('settings.oth.quotaReserveLabel'),
|
||||
options: getEnableToggleOptions(),
|
||||
onUpdateModelValue: async (val) => {
|
||||
const nextEnabled = val === 'on';
|
||||
draftExperimentalQuotaReservation = nextEnabled;
|
||||
quotaReserveToggle.setProps({
|
||||
modelValue: nextEnabled ? 'on' : 'off',
|
||||
options: getEnableToggleOptions(),
|
||||
});
|
||||
showExpFeedback(t('settings.saving'), 0);
|
||||
try {
|
||||
await saveSettingsPatch({ experimentalQuotaReservation: nextEnabled });
|
||||
showExpFeedback(t('settings.saved'), 1500);
|
||||
} catch {
|
||||
if (latestSettings) renderSettings(latestSettings);
|
||||
showExpFeedback(t('settings.saveFailed'), 2500);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const experimentalPanel = h('section', { className: 'panel' }, [
|
||||
h('div', { className: 'panel-header' }, [
|
||||
h('span', { className: 'panel-title' }, [
|
||||
createSvgIcon('pulse', { size: 13 }),
|
||||
expTitleEl,
|
||||
]),
|
||||
expStatusText,
|
||||
]),
|
||||
h('div', { className: 'settings-action-block' }, [
|
||||
h('div', { className: 'settings-action-info' }, [
|
||||
h('div', { className: 'settings-experimental-label-group' }, [
|
||||
quotaReserveLabelEl,
|
||||
quotaReserveBadgeEl,
|
||||
]),
|
||||
quotaReserveDescEl,
|
||||
]),
|
||||
quotaReserveToggle.el,
|
||||
]),
|
||||
h('div', { className: 'settings-action-block' }, [
|
||||
h('div', { className: 'settings-action-info' }, [
|
||||
quotaReserveLogLabelEl,
|
||||
quotaReserveLogDescEl,
|
||||
]),
|
||||
exportReserveLogBtn,
|
||||
]),
|
||||
]);
|
||||
|
||||
// --- Card 2: 按模型设置上下文窗口 ---
|
||||
const baselineTitleEl = h('span', { text: t('settings.oth.baselineTitle') });
|
||||
const ctxModelLabel = h('span', { className: 'form-label' });
|
||||
@@ -611,6 +767,7 @@ export const SettingsOtherTab = defineComponent({
|
||||
|
||||
const rootEl = h('div', { className: 'settings-tab-stack' }, [
|
||||
modelPanel,
|
||||
experimentalPanel,
|
||||
baselinePanel,
|
||||
maintPanel,
|
||||
sessionMigrationCard.el,
|
||||
@@ -632,6 +789,9 @@ export const SettingsOtherTab = defineComponent({
|
||||
settings.showUpstreamModel
|
||||
);
|
||||
draftOrchestratorIdMode = normalizeClientOrchestratorIdMode(settings.orchestratorIdMode);
|
||||
draftExperimentalQuotaReservation = normalizeClientExperimentalQuotaReservation(
|
||||
settings.experimentalQuotaReservation
|
||||
);
|
||||
if (!acceptingContextRisk) {
|
||||
draftContextRiskAccepted = Boolean(settings.contextWindowRiskAccepted);
|
||||
}
|
||||
@@ -643,6 +803,11 @@ export const SettingsOtherTab = defineComponent({
|
||||
modelValue: draftOrchestratorIdMode,
|
||||
options: getOrchestratorIdDisplayOptions(),
|
||||
});
|
||||
quotaReserveToggle.setProps({
|
||||
modelValue: draftExperimentalQuotaReservation ? 'on' : 'off',
|
||||
options: getEnableToggleOptions(),
|
||||
ariaLabel: t('settings.oth.quotaReserveLabel'),
|
||||
});
|
||||
renderContextWindows();
|
||||
void sessionMigrationCard.refs.ensureLoaded();
|
||||
}
|
||||
@@ -651,6 +816,18 @@ export const SettingsOtherTab = defineComponent({
|
||||
patchText(modelCardTitleEl, t('settings.oth.modelTitle'));
|
||||
patchText(modelFormatLabelEl, t('settings.oth.modelFormat'));
|
||||
patchText(orchFormatLabelEl, t('settings.oth.orchFormat'));
|
||||
patchText(expTitleEl, t('settings.oth.expTitle'));
|
||||
patchText(quotaReserveLabelEl, t('settings.oth.quotaReserveLabel'));
|
||||
patchText(quotaReserveBadgeEl, t('settings.oth.expBadge'));
|
||||
patchText(quotaReserveDescEl, t('settings.oth.quotaReserveDesc'));
|
||||
patchText(quotaReserveLogLabelEl, t('settings.oth.quotaReserveLogLabel'));
|
||||
patchText(quotaReserveLogDescEl, t('settings.oth.quotaReserveLogDesc'));
|
||||
patchText(exportReserveLogBtnText, t('settings.oth.exportReserveLogBtn'));
|
||||
quotaReserveToggle.setProps({
|
||||
modelValue: draftExperimentalQuotaReservation ? 'on' : 'off',
|
||||
options: getEnableToggleOptions(),
|
||||
ariaLabel: t('settings.oth.quotaReserveLabel'),
|
||||
});
|
||||
patchText(baselineTitleEl, t('settings.oth.baselineTitle'));
|
||||
renderContextWindows();
|
||||
patchText(maintTitleEl, t('settings.oth.maintTitle'));
|
||||
@@ -686,10 +863,12 @@ export const SettingsOtherTab = defineComponent({
|
||||
|
||||
onCleanup(() => {
|
||||
if (modelTimer) clearTimeout(modelTimer);
|
||||
if (expTimer) clearTimeout(expTimer);
|
||||
if (maintTimer) clearTimeout(maintTimer);
|
||||
if (resetConfirmTimer) clearTimeout(resetConfirmTimer);
|
||||
stepModelSelect.destroy();
|
||||
orchestratorIdSelect.destroy();
|
||||
quotaReserveToggle.destroy();
|
||||
ctxBridgeNotice.destroy();
|
||||
ctxModelSelect.destroy();
|
||||
ctxWindowSelect.destroy();
|
||||
@@ -701,6 +880,8 @@ export const SettingsOtherTab = defineComponent({
|
||||
refs: {
|
||||
stepModelSelect,
|
||||
orchestratorIdSelect,
|
||||
quotaReserveToggle,
|
||||
exportReserveLogBtn,
|
||||
ctxBridgeNotice,
|
||||
ctxModelSelect,
|
||||
ctxWindowSelect,
|
||||
|
||||
Reference in New Issue
Block a user