feat(panel): modularize 3-tab preferences, add model context windows, and optimize telemetry

- Refactor Preferences into decoupled General, Structure, and Other tabs with unified settings schema, factory reset, and trajectory cache rebuild endpoints
- Extract standalone widget, metric, and step-table column registries to customize topbar/composer slots, hover popup modules, live overview layout, and step detail columns
- Add bilingual zh-CN/en-US i18n dictionaries, theme accent presets, and font scale controls across Shadow DOM overlay and sidebar views
- Support per-model host-advertised context window rules across App and IDE transports
- Preserve CLEARED step generation timings, memoize per-poll model resolution, optimize LOESS sorted-x fitting, and update bilingual READMEs and test suites
This commit is contained in:
fish
2026-11-15 01:18:29 +09:00
parent ad33e9cc62
commit 18c608ae63
63 changed files with 16614 additions and 5873 deletions
+81
View File
@@ -0,0 +1,81 @@
/**
* @fileoverview Theme accent palette & panel font-scale appearance engine.
* Applies CSS custom properties cleanly to Sidebar `:root` and Shadow DOM hosts,
* while strictly isolating `#ag-usage-monitor-capsule` from font scaling.
*/
export const THEME_ACCENT_PRESETS = Object.freeze([
{ key: 'host', labelKey: 'settings.gen.accentHost', cssColor: '' },
{ key: 'blue', labelKey: 'settings.gen.accentBlue', cssColor: 'hsl(217 84% 53%)' },
{ key: 'emerald', labelKey: 'settings.gen.accentEmerald', cssColor: 'hsl(152 66% 39%)' },
{ key: 'amber', labelKey: 'settings.gen.accentAmber', cssColor: 'hsl(34 88% 46%)' },
{ key: 'violet', labelKey: 'settings.gen.accentViolet', cssColor: 'hsl(262 76% 58%)' },
{ key: 'cyan', labelKey: 'settings.gen.accentCyan', cssColor: 'hsl(191 82% 41%)' },
{ key: 'rose', labelKey: 'settings.gen.accentRose', cssColor: 'hsl(346 78% 54%)' },
]);
export const FONT_SCALE_FACTORS = Object.freeze({
sm: 0.92,
md: 1,
lg: 1.08,
xl: 1.15,
});
export function normalizeClientThemeAccent(raw) {
const val = String(raw ?? '').trim().toLowerCase();
return THEME_ACCENT_PRESETS.some((p) => p.key === val) ? val : 'host';
}
export function normalizeClientFontScale(raw) {
const val = String(raw ?? '').trim().toLowerCase();
return Object.prototype.hasOwnProperty.call(FONT_SCALE_FACTORS, val) ? val : 'md';
}
function setOrClearStyleVar(el, propName, value) {
if (!el || !el.style) return;
if (value) {
if (typeof el.style.setProperty === 'function') {
el.style.setProperty(propName, value);
} else {
el.style[propName] = value;
}
} else if (typeof el.style.removeProperty === 'function') {
el.style.removeProperty(propName);
} else if (typeof el.style.setProperty === 'function') {
el.style.setProperty(propName, '');
}
}
/**
* Synchronize theme accent and (optionally) font scale tokens onto a root/host element.
*
* @param {HTMLElement | null | undefined} targetEl
* @param {object | null | undefined} settings
* @param {{ includeFontScale?: boolean }} [options]
*/
export function applyAppearanceToRoot(targetEl, settings, { includeFontScale = true } = {}) {
if (!targetEl || !targetEl.style) return;
const accentKey = normalizeClientThemeAccent(settings?.themeAccent);
const preset = THEME_ACCENT_PRESETS.find((p) => p.key === accentKey) || THEME_ACCENT_PRESETS[0];
if (preset.key !== 'host' && preset.cssColor) {
setOrClearStyleVar(targetEl, '--user-accent-primary', preset.cssColor);
setOrClearStyleVar(targetEl, '--user-accent-contrast', '#ffffff');
} else {
setOrClearStyleVar(targetEl, '--user-accent-primary', '');
setOrClearStyleVar(targetEl, '--user-accent-contrast', '');
}
targetEl.setAttribute?.('data-accent', preset.key);
if (includeFontScale) {
const scaleKey = normalizeClientFontScale(settings?.fontScale);
const factor = FONT_SCALE_FACTORS[scaleKey] ?? 1;
setOrClearStyleVar(targetEl, '--ui-font-scale', factor === 1 ? '' : String(factor));
targetEl.setAttribute?.('data-font-scale', scaleKey);
} else {
setOrClearStyleVar(targetEl, '--ui-font-scale', '');
if (typeof targetEl.removeAttribute === 'function') {
targetEl.removeAttribute('data-font-scale');
}
}
}
+3 -2
View File
@@ -6,7 +6,7 @@
export function defineComponent({ name, setup }) {
return function createInstance(initialProps = {}) {
let props = { ...initialProps };
const props = { ...initialProps };
const cleanups = [];
function emit(event, payload) {
@@ -30,7 +30,7 @@ export function defineComponent({ name, setup }) {
let setupResult = null;
function setProps(nextProps = {}) {
props = { ...props, ...nextProps };
Object.assign(props, nextProps);
if (setupResult && typeof setupResult.onPropsChange === 'function') {
setupResult.onPropsChange(props);
}
@@ -41,6 +41,7 @@ export function defineComponent({ name, setup }) {
}
setupResult = setup({
props,
getProps: () => props,
setProps,
emit,
+9
View File
@@ -179,6 +179,15 @@ export function patchKeyedList(container, items, { keyFn, sigFn, createRow, upda
}
}
if (!container.firstChild && orderedNodes.length > 1 && typeof document.createDocumentFragment === 'function') {
const fragment = document.createDocumentFragment();
for (const node of orderedNodes) {
fragment.appendChild(node);
}
container.appendChild(fragment);
return;
}
// Reorder or insert nodes with minimal DOM moves
for (let i = 0; i < orderedNodes.length; i++) {
const targetNode = orderedNodes[i];
+37 -18
View File
@@ -3,6 +3,13 @@
* USD estimates, countdown timers, and custom datetime displays.
*/
import { isEnglishLocale, t } from '../i18n/index.js';
const EN_MONTH_SHORT = Object.freeze([
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
]);
export function formatMetric(value, unit = '') {
return Number.isFinite(value) ? `${value.toFixed(1)}${unit}` : '—';
}
@@ -34,6 +41,14 @@ export function formatCnyApprox(usdAmount, rate = 7.2) {
export function formatDateSpanBadge(startMs, endMs) {
const s = startMs && Number.isFinite(startMs) ? new Date(startMs) : new Date();
const e = endMs && Number.isFinite(endMs) ? new Date(endMs) : new Date();
if (isEnglishLocale()) {
const sMon = EN_MONTH_SHORT[s.getMonth()] || '';
const eMon = EN_MONTH_SHORT[e.getMonth()] || '';
if (s.getFullYear() !== e.getFullYear()) {
return `${sMon} ${s.getDate()}, ${s.getFullYear()} ~ ${eMon} ${e.getDate()}, ${e.getFullYear()}`;
}
return `${sMon} ${s.getDate()} ~ ${eMon} ${e.getDate()}`;
}
if (s.getFullYear() !== e.getFullYear()) {
return `${s.getFullYear()}年${s.getMonth() + 1}月${s.getDate()}日 ~ ${e.getFullYear()}年${e.getMonth() + 1}月${e.getDate()}日`;
}
@@ -41,7 +56,7 @@ export function formatDateSpanBadge(startMs, endMs) {
}
export function formatUsd(amount, { precise = false } = {}) {
if (amount == null || !Number.isFinite(Number(amount))) return '待定';
if (amount == null || !Number.isFinite(Number(amount))) return t('fmt.pending');
const val = Number(amount || 0);
if (precise) {
if (val > 0 && val < 0.001) return '<$0.001';
@@ -50,42 +65,46 @@ export function formatUsd(amount, { precise = false } = {}) {
return `$${val.toFixed(2)}`;
}
const SPEED_REASON_LABELS = {
__proto__: null,
incomplete_or_invalid_timing: 'fmt.speedIncomplete',
invalid_output_tokens: 'fmt.speedInvalidOutput',
inconsistent_timing: 'fmt.speedInconsistent',
short_timing: 'fmt.speedShort',
legacy_cache: 'fmt.speedLegacy',
};
export function speedReasonText(reason) {
return ({
incomplete_or_invalid_timing: '生成未完成',
invalid_output_tokens: '无有效输出',
inconsistent_timing: '耗时数据异常',
short_timing: '耗时过短 (<0.5s)',
legacy_cache: '旧版缓存记录',
})[reason] || '';
const label = SPEED_REASON_LABELS[reason];
return label ? t(label) : '';
}
export function sampleSummary(summary) {
const valid = summary?.sampleCount || 0;
const excluded = summary?.excludedCount || 0;
return `${valid}/${valid + excluded} 步`;
return t('fmt.sampleSteps', { valid, total: valid + excluded });
}
export function formatCountdown(isoTime, nowMs = Date.now()) {
if (!isoTime) return '未知重置时间';
if (!isoTime) return t('fmt.resetUnknown');
const targetMs = Date.parse(isoTime);
if (!Number.isFinite(targetMs) || targetMs <= 0) return '未知重置时间';
if (!Number.isFinite(targetMs) || targetMs <= 0) return t('fmt.resetUnknown');
const diffMs = targetMs - nowMs;
if (diffMs <= 0) return '即将重置';
if (diffMs < 60_000) return '<1分钟后重置';
if (diffMs <= 0) return t('fmt.resetSoon');
if (diffMs < 60_000) return t('fmt.resetUnder1m');
const totalMinutes = Math.floor(diffMs / 60000);
const days = Math.floor(totalMinutes / (60 * 24));
const hours = Math.floor((totalMinutes % (60 * 24)) / 60);
const minutes = totalMinutes % 60;
if (days > 0) return `${days}天 ${hours}小时后重置`;
if (hours > 0) return `${hours}小时 ${minutes}分后重置`;
return `${minutes}分钟后重置`;
if (days > 0) return t('fmt.resetDaysHours', { d: days, h: hours });
if (hours > 0) return t('fmt.resetHoursMins', { h: hours, m: minutes });
return t('fmt.resetMins', { m: minutes });
}
export function formatCompactDateTime(ms) {
if (!ms || !Number.isFinite(ms)) return '选择时间';
if (!ms || !Number.isFinite(ms)) return t('fmt.selectTime');
const d = new Date(ms);
const pad = (n) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
@@ -135,7 +154,7 @@ export function resolveModelDisplayInfo(target, settings = {}, options = {}) {
typeof settings === 'object' && settings ? settings.orchestratorIdMode : 'compact'
);
const preferLabelInShort = Boolean(options?.preferLabelInShort);
const fallback = options?.fallback ?? '模型未知';
const fallback = options?.fallback ?? t('fmt.unknownModel');
if (!target || typeof target !== 'object') {
return { text: fallback, title: fallback, isOrchestratorSeries: false };