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
@@ -0,0 +1,186 @@
/**
* @fileoverview Decoupled Overview & Hover Widget Registry (`widgetRegistry.js`).
* Maps module keys (`metrics`, `context`, `quotas`, `live_tasks`) to standalone
* widget components and provides `createDynamicWidgetHost` for zero-hardcode mounting,
* live reordering, and clean instance disposal.
*/
import { ContextWindowWidget } from '../components/widgets/ContextWindowWidget.js';
import { LiveActivityWidget } from '../components/widgets/LiveActivityWidget.js';
import { MetricMatrixWidget } from '../components/widgets/MetricMatrixWidget.js';
import { QuotaPoolsWidget } from '../components/widgets/QuotaPoolsWidget.js';
import { t } from '../i18n/index.js';
export const OVERVIEW_WIDGET_KEYS = Object.freeze([
'metrics',
'context',
'quotas',
'live_tasks',
]);
export const OVERVIEW_WIDGET_REGISTRY = Object.freeze({
metrics: {
key: 'metrics',
labelKey: 'module.metrics',
create: ({ mode, isVisibleFn }) => MetricMatrixWidget({ mode, isVisibleFn }),
},
context: {
key: 'context',
labelKey: 'module.context',
create: ({ mode, isVisibleFn }) =>
ContextWindowWidget({
interactiveInspector: mode !== 'hover',
isVisibleFn,
}),
},
quotas: {
key: 'quotas',
labelKey: 'module.quotas',
create: ({ mode }) =>
QuotaPoolsWidget({
compactHover: mode === 'hover',
}),
},
live_tasks: {
key: 'live_tasks',
labelKey: 'module.live_tasks',
create: ({ mode, isVisibleFn }) =>
LiveActivityWidget({
interactive: mode !== 'hover',
isVisibleFn,
}),
},
});
export function getOverviewModuleOptions() {
return OVERVIEW_WIDGET_KEYS.map((key) => ({
value: key,
label: t(`module.${key}`),
}));
}
/**
* Create a dynamic container host that mounts, reorders, updates, and disposes
* standalone telemetry widgets based on user-configured module keys.
*
* @param {{
* containerEl: HTMLElement,
* mode?: 'overview' | 'hover',
* isVisibleFn?: () => boolean,
* initialModuleKeys?: string[]
* }} options
*/
export function createDynamicWidgetHost({
containerEl,
mode = 'overview',
isVisibleFn = () => true,
initialModuleKeys = [],
}) {
const instances = new Map();
let currentKeys = [];
function syncModules(nextKeys) {
const validKeys = [];
const seen = new Set();
for (const rawKey of Array.isArray(nextKeys) ? nextKeys : []) {
const k = String(rawKey || '').trim();
if (!k || seen.has(k) || !OVERVIEW_WIDGET_REGISTRY[k]) continue;
seen.add(k);
validKeys.push(k);
}
// Remove and destroy widgets no longer present
for (const [existingKey, inst] of [...instances.entries()]) {
if (!seen.has(existingKey)) {
try {
inst.el?.remove?.();
} catch {}
try {
inst.destroy?.();
} catch {}
instances.delete(existingKey);
}
}
// Instantiate newly added widgets
for (const key of validKeys) {
if (!instances.has(key)) {
const inst = OVERVIEW_WIDGET_REGISTRY[key].create({ mode, isVisibleFn });
instances.set(key, inst);
}
}
// Reorder DOM nodes in containerEl only where needed
const orderChanged =
validKeys.length !== currentKeys.length ||
validKeys.some((k, idx) => currentKeys[idx] !== k) ||
(containerEl.children && containerEl.children.length !== validKeys.length);
if (orderChanged) {
for (let i = 0; i < validKeys.length; i += 1) {
const targetEl = instances.get(validKeys[i]).el;
const curChild = containerEl.children ? containerEl.children[i] : null;
if (curChild !== targetEl) {
if (curChild && typeof containerEl.insertBefore === 'function') {
containerEl.insertBefore(targetEl, curChild);
} else {
containerEl.appendChild(targetEl);
}
}
}
currentKeys = [...validKeys];
}
return validKeys;
}
function update({ moduleKeys = [], data = null, minuteTick = undefined } = {}) {
const validKeys = syncModules(moduleKeys);
for (const key of validKeys) {
const inst = instances.get(key);
inst?.refs?.update?.({ data, minuteTick });
}
}
function pauseTickers() {
for (const inst of instances.values()) {
inst?.refs?.pauseTicker?.();
}
}
function resumeTickers() {
for (const inst of instances.values()) {
inst?.refs?.resumeTicker?.();
}
}
function getInstance(key) {
return instances.get(key) || null;
}
function destroy() {
for (const inst of instances.values()) {
try {
inst.el?.remove?.();
} catch {}
try {
inst.destroy?.();
} catch {}
}
instances.clear();
currentKeys = [];
}
if (Array.isArray(initialModuleKeys) && initialModuleKeys.length > 0) {
syncModules(initialModuleKeys);
}
return {
update,
pauseTickers,
resumeTickers,
getInstance,
getActiveKeys: () => [...currentKeys],
destroy,
};
}