feat(panel): subagent monitoring and 10-channel context window (v1.4.1)

This commit is contained in:
yuhuan2498281558
2026-11-07 23:24:32 +09:00
parent 551eeb35c3
commit 4b3b745598
27 changed files with 3926 additions and 664 deletions
@@ -6,20 +6,36 @@
import { defineComponent } from '../../core/component.js';
import { h, patchAttr, patchClasses, patchText } from '../../core/domPatch.js';
import { formatUsd } from '../../core/formatters.js';
import { createSvgIcon, patchSvgIcon } from '../../icons/SvgIcon.js';
import { fetchTelemetry, telemetryStore, triggerPluginUpdate } from '../../store/telemetryStore.js';
import {
fetchTelemetry,
formatAgentLabel,
resolveScopedConversation,
telemetryStore,
triggerPluginUpdate,
} from '../../store/telemetryStore.js';
import { uiStore } from '../../store/uiStore.js';
import { CustomSelect } from '../ui/CustomSelect.js';
function formatConvOptionMeta(c) {
if (!c) return '';
const subs = Number(c.subagentCount || 0);
if (subs > 0) {
return `主${c.stepCount || 0} · ${subs}子 (共${c.totalStepCount || c.stepCount || 0}步)`;
}
return `${c.stepCount || 0}步`;
}
export const TopSessionHeader = defineComponent({
name: 'TopSessionHeader',
setup({ onCleanup }) {
const convSelect = CustomSelect({
modelValue: telemetryStore.getState().selectedConversationId,
icon: 'bolt',
placeholder: '跟随最新会话',
options: [{ value: '', label: '跟随最新会话' }],
onUpdateModelValue: (nextConvId) => {
uiStore.setState({ selectedAgentScope: 'all', ctxInspectorAgentId: 'auto' });
telemetryStore.setState({ selectedConversationId: nextConvId });
fetchTelemetry({ force: false });
},
@@ -76,116 +92,237 @@ export const TopSessionHeader = defineComponent({
[createSvgIcon('refresh', { size: 13 })]
);
const headerEl = h('header', { className: 'session-header' }, [
const headerRowEl = h('div', { className: 'session-header' }, [
h('div', { className: 'session-left' }, [convSelect.el]),
h('div', { className: 'session-right' }, [updateBtn, statusTag, refreshBtn]),
]);
// --- 方案 A:顶栏二级主/子代理切换条 (.agent-scope-bar,无子代理时自动隐藏) ---
const scopeAllBtnText = h('span', { text: '全部汇总' });
const scopeAllBtn = h(
'button',
{
type: 'button',
className: 'scope-pill-btn is-active',
onClick: () =>
uiStore.setState({ selectedAgentScope: 'all', ctxInspectorAgentId: 'auto' }),
},
[scopeAllBtnText]
);
const scopeMainBtnText = h('span', { text: '主代理' });
const scopeMainBtn = h(
'button',
{
type: 'button',
className: 'scope-pill-btn',
onClick: () => uiStore.setState({ selectedAgentScope: 'main' }),
},
[scopeMainBtnText]
);
const subagentSelect = CustomSelect({
modelValue: '',
icon: 'cpu',
placeholder: '子代理 (0)',
className: 'scope-subagent-select',
options: [],
onUpdateModelValue: (nextSubId) => {
if (nextSubId) {
uiStore.setState({ selectedAgentScope: nextSubId });
}
},
});
const scopeRightText = h('span', { className: 'agent-scope-right text-mono', text: '' });
const scopeBarEl = h(
'div',
{ className: 'agent-scope-bar', hidden: true },
[
h('div', { className: 'agent-scope-left' }, [
scopeAllBtn,
scopeMainBtn,
subagentSelect.el,
]),
scopeRightText,
]
);
const headerEl = h('header', { className: 'top-session-stack' }, [headerRowEl, scopeBarEl]);
let lastActiveCascadeId = '';
function renderHeaderState() {
const telSt = telemetryStore.getState();
const uiSt = uiStore.getState();
const telemetry = telSt.telemetry;
const currentCascadeId = telemetry?.activeConversation?.cascadeId || '';
if (currentCascadeId && lastActiveCascadeId && currentCascadeId !== lastActiveCascadeId) {
lastActiveCascadeId = currentCascadeId;
if (uiSt.selectedAgentScope !== 'all' || uiSt.ctxInspectorAgentId !== 'auto') {
uiStore.setState({ selectedAgentScope: 'all', ctxInspectorAgentId: 'auto' });
return;
}
} else if (currentCascadeId) {
lastActiveCascadeId = currentCascadeId;
}
const convs = telemetry?.conversations || [];
const latestTitle = convs[0]?.title ? `最新 (${convs[0].title})` : '跟随最新会话';
const options = [
{ value: '', label: latestTitle, meta: convs[0] ? formatConvOptionMeta(convs[0]) : '' },
...convs.map((c) => ({
value: c.cascadeId,
label: c.title || c.cascadeId.slice(0, 8),
meta: formatConvOptionMeta(c),
})),
];
convSelect.setProps({
modelValue: telSt.selectedConversationId,
options,
});
const {
hasSubagents,
effectiveScope,
subagents,
mainAgent,
aggregated,
scopedConv,
} = resolveScopedConversation(telemetry, uiSt.selectedAgentScope, uiSt.ctxInspectorAgentId);
patchAttr(scopeBarEl, 'hidden', !hasSubagents);
if (hasSubagents) {
patchText(scopeAllBtnText, `全部 (${aggregated?.stepCount ?? 0})`);
patchClasses(scopeAllBtn, { 'is-active': effectiveScope === 'all' });
patchText(scopeMainBtnText, `主代理 (${mainAgent?.stepCount ?? 0})`);
patchClasses(scopeMainBtn, { 'is-active': effectiveScope === 'main' });
const isSubSelected = effectiveScope !== 'all' && effectiveScope !== 'main';
patchClasses(subagentSelect.el, { 'is-active-sub': isSubSelected });
const subOptions = subagents.map((s) => ({
value: s.agentId,
label: formatAgentLabel(s),
meta: `${s.stepCount || 0}步 · 窗${s.context?.usedPct ?? 0}%`,
}));
subagentSelect.setProps({
modelValue: isSubSelected ? effectiveScope : '',
placeholder: `子代理 (${subagents.length})`,
options: subOptions,
});
patchText(
scopeRightText,
formatUsd(scopedConv?.sessionCostUsd || 0, {
unpricedCalls: scopedConv?.sessionUnpricedCalls,
})
);
} else {
subagentSelect.close();
}
const cloudStatus = telemetry?.cloudStatus;
const hasUpdate = Boolean(cloudStatus?.updateAvailable);
patchAttr(updateBtn, 'hidden', !hasUpdate);
if (hasUpdate && !isHeaderUpdating) {
patchText(
updateBtnText,
cloudStatus?.latestPluginVersion
? `升级 v${cloudStatus.latestPluginVersion}`
: '有新版本'
);
}
const isSyncing = telSt.syncState === 'syncing';
const isSynced = telSt.syncState === 'synced';
const isError = telSt.syncState === 'error';
const isRunning = Boolean(aggregated?.isRunning || telemetry?.activeConversation?.isRunning);
const quotaMeta = telemetry?.quotas?.meta;
const quotaStale = Boolean(quotaMeta?.refreshFailed || quotaMeta?.isStale);
patchClasses(refreshBtn, { 'is-spinning': isSyncing });
patchAttr(refreshBtn, 'disabled', isSyncing);
if (isSyncing) {
patchSvgIcon(statusIcon, 'refresh');
patchText(statusText, '同步中');
patchClasses(statusTag, {
'state-running': false,
'state-synced': true,
'state-warn': false,
});
} else if (isSynced) {
patchSvgIcon(statusIcon, 'check');
patchText(statusText, '已刷新');
patchClasses(statusTag, {
'state-running': false,
'state-synced': true,
'state-warn': false,
});
} else if (isError) {
patchSvgIcon(statusIcon, 'warning');
patchText(statusText, '重试中');
patchClasses(statusTag, {
'state-running': false,
'state-synced': false,
'state-warn': true,
});
} else if (isRunning) {
const runningAgent = (telemetry?.activeConversation?.agents || []).find((a) => a.isRunning);
const runSuffix =
hasSubagents && runningAgent ? ` · ${runningAgent.badgeText || runningAgent.shortLabel}` : '';
patchSvgIcon(statusIcon, 'bolt');
patchText(statusText, `生成中${runSuffix}`);
patchClasses(statusTag, {
'state-running': true,
'state-synced': false,
'state-warn': false,
});
} else if (quotaStale) {
patchSvgIcon(statusIcon, 'warning');
patchText(statusText, quotaMeta?.hasOfficialData ? '额度缓存' : '额度离线');
patchClasses(statusTag, {
'state-running': false,
'state-synced': false,
'state-warn': true,
});
} else {
patchSvgIcon(statusIcon, 'pulse');
patchText(statusText, '实时 2s');
patchClasses(statusTag, {
'state-running': false,
'state-synced': false,
'state-warn': false,
});
}
}
const unsubTelemetry = telemetryStore.subscribe(
(st) => ({
selectedConversationId: st.selectedConversationId,
syncState: st.syncState,
conversations: st.telemetry?.conversations,
isRunning: st.telemetry?.activeConversation?.isRunning,
quotaMeta: st.telemetry?.quotas?.meta,
cloudStatus: st.telemetry?.cloudStatus,
telemetry: st.telemetry,
}),
(slice) => {
const convs = slice.conversations || [];
const latestTitle = convs[0]?.title ? `最新 (${convs[0].title})` : '跟随最新会话';
const options = [
{ value: '', label: latestTitle, meta: convs[0] ? `${convs[0].stepCount}步` : '' },
...convs.map((c) => ({
value: c.cascadeId,
label: c.title || c.cascadeId.slice(0, 8),
meta: `${c.stepCount || 0}步`,
})),
];
convSelect.setProps({
modelValue: slice.selectedConversationId,
options,
});
() => renderHeaderState()
);
const hasUpdate = Boolean(slice.cloudStatus?.updateAvailable);
patchAttr(updateBtn, 'hidden', !hasUpdate);
if (hasUpdate && !isHeaderUpdating) {
patchText(
updateBtnText,
slice.cloudStatus?.latestPluginVersion
? `升级 v${slice.cloudStatus.latestPluginVersion}`
: '有新版本'
);
}
const isSyncing = slice.syncState === 'syncing';
const isSynced = slice.syncState === 'synced';
const isError = slice.syncState === 'error';
const isRunning = Boolean(slice.isRunning);
const quotaStale = Boolean(slice.quotaMeta?.refreshFailed || slice.quotaMeta?.isStale);
patchClasses(refreshBtn, { 'is-spinning': isSyncing });
patchAttr(refreshBtn, 'disabled', isSyncing);
if (isSyncing) {
patchSvgIcon(statusIcon, 'refresh');
patchText(statusText, '同步中');
patchClasses(statusTag, {
'state-running': false,
'state-synced': true,
'state-warn': false,
});
} else if (isSynced) {
patchSvgIcon(statusIcon, 'check');
patchText(statusText, '已刷新');
patchClasses(statusTag, {
'state-running': false,
'state-synced': true,
'state-warn': false,
});
} else if (isError) {
patchSvgIcon(statusIcon, 'warning');
patchText(statusText, '重试中');
patchClasses(statusTag, {
'state-running': false,
'state-synced': false,
'state-warn': true,
});
} else if (isRunning) {
patchSvgIcon(statusIcon, 'bolt');
patchText(statusText, '生成中');
patchClasses(statusTag, {
'state-running': true,
'state-synced': false,
'state-warn': false,
});
} else if (quotaStale) {
patchSvgIcon(statusIcon, 'warning');
patchText(statusText, slice.quotaMeta?.hasOfficialData ? '额度缓存' : '额度离线');
patchClasses(statusTag, {
'state-running': false,
'state-synced': false,
'state-warn': true,
});
} else {
patchSvgIcon(statusIcon, 'pulse');
patchText(statusText, '实时 2s');
patchClasses(statusTag, {
'state-running': false,
'state-synced': false,
'state-warn': false,
});
}
}
const unsubUi = uiStore.subscribe(
(st) => st.selectedAgentScope,
() => renderHeaderState()
);
onCleanup(() => {
unsubTelemetry();
unsubUi();
convSelect.destroy();
subagentSelect.destroy();
});
return {
el: headerEl,
refs: { convSelect, statusTag, refreshBtn },
refs: { convSelect, subagentSelect, statusTag, refreshBtn, scopeBarEl },
};
},
});
@@ -1,20 +1,37 @@
/**
* @fileoverview 6-channel segmented context window progress bar updated via
* CSS custom variables against the current model's automatic compaction baseline.
* @fileoverview 10-channel segmented context window progress bar updated via
* CSS custom variables against the current model's automatic compaction baseline,
* dynamically ordered from largest to smallest segment.
*/
import { defineComponent } from '../../core/component.js';
import { h, patchAttr, patchStyleVar } from '../../core/domPatch.js';
const SEGMENT_DEFS = [
{ key: 'assistant', cls: 'seg-assistant', getVal: (c) => Number(c.assistantTokens || 0) },
{ key: 'toolResults', cls: 'seg-tool-results', getVal: (c) => Number(c.toolResultsTokens || 0) },
{
key: 'userInput',
cls: 'seg-user-input',
getVal: (c) => Number(c.userInputTokens ?? c.messagesTokens ?? 0),
},
{ key: 'subagent', cls: 'seg-subagent-msg', getVal: (c) => Number(c.subagentTokens || 0) },
{ key: 'checkpoint', cls: 'seg-checkpoint', getVal: (c) => Number(c.checkpointTokens || 0) },
{ key: 'systemPrompt', cls: 'seg-system-prompt', getVal: (c) => Number(c.systemPromptTokens || 0) },
{ key: 'systemTools', cls: 'seg-system-tools', getVal: (c) => Number(c.systemToolsTokens || 0) },
{ key: 'mcpTools', cls: 'seg-mcp-tools', getVal: (c) => Number(c.mcpToolsTokens || 0) },
{ key: 'skills', cls: 'seg-skills', getVal: (c) => Number(c.skillsTokens || 0) },
{ key: 'userRules', cls: 'seg-user-rules', getVal: (c) => Number(c.userRulesTokens || 0) },
];
export const ContextSegmentMeter = defineComponent({
name: 'ContextSegmentMeter',
setup({ getProps }) {
const segMessages = h('div', { className: 'progress-seg seg-messages' });
const segSystemTools = h('div', { className: 'progress-seg seg-system-tools' });
const segMcpTools = h('div', { className: 'progress-seg seg-mcp-tools' });
const segSkills = h('div', { className: 'progress-seg seg-skills' });
const segSystemPrompt = h('div', { className: 'progress-seg seg-system-prompt' });
const segUserRules = h('div', { className: 'progress-seg seg-user-rules' });
const segments = SEGMENT_DEFS.map((def, idx) => ({
...def,
defaultOrder: idx,
el: h('div', { className: `progress-seg ${def.cls}` }),
}));
const trackEl = h(
'div',
@@ -24,25 +41,30 @@ export const ContextSegmentMeter = defineComponent({
'aria-valuemin': '0',
'aria-valuemax': '100',
},
[segMessages, segSystemTools, segMcpTools, segSkills, segSystemPrompt, segUserRules]
segments.map((s) => s.el)
);
let lastOrderSig = segments.map((s) => s.key).join(',');
function syncMeter() {
const ctx = getProps().context || {};
const limit = Math.max(1, Number(ctx.compactionLimitTokens || ctx.limitTokens || 256000));
const pctMessages = Math.min(100, ((ctx.messagesTokens || 0) / limit) * 100);
const pctSystemTools = Math.min(100, ((ctx.systemToolsTokens || 0) / limit) * 100);
const pctMcpTools = Math.min(100, ((ctx.mcpToolsTokens || 0) / limit) * 100);
const pctSkills = Math.min(100, ((ctx.skillsTokens || 0) / limit) * 100);
const pctSystemPrompt = Math.min(100, ((ctx.systemPromptTokens || 0) / limit) * 100);
const pctUserRules = Math.min(100, ((ctx.userRulesTokens || 0) / limit) * 100);
const scored = segments.map((seg) => {
const val = seg.getVal(ctx);
const pct = Math.min(100, (val / limit) * 100);
patchStyleVar(seg.el, '--seg-w', `${pct.toFixed(2)}%`);
return { seg, val };
});
scored.sort((a, b) => b.val - a.val || a.seg.defaultOrder - b.seg.defaultOrder);
const nextOrderSig = scored.map((x) => x.seg.key).join(',');
if (nextOrderSig !== lastOrderSig) {
lastOrderSig = nextOrderSig;
for (const { seg } of scored) {
trackEl.appendChild(seg.el);
}
}
patchStyleVar(segMessages, '--seg-w', `${pctMessages.toFixed(2)}%`);
patchStyleVar(segSystemTools, '--seg-w', `${pctSystemTools.toFixed(2)}%`);
patchStyleVar(segMcpTools, '--seg-w', `${pctMcpTools.toFixed(2)}%`);
patchStyleVar(segSkills, '--seg-w', `${pctSkills.toFixed(2)}%`);
patchStyleVar(segSystemPrompt, '--seg-w', `${pctSystemPrompt.toFixed(2)}%`);
patchStyleVar(segUserRules, '--seg-w', `${pctUserRules.toFixed(2)}%`);
patchAttr(trackEl, 'aria-valuenow', Math.round(ctx.compactionUsedPct ?? ctx.usedPct ?? 0));
}
@@ -50,14 +72,7 @@ export const ContextSegmentMeter = defineComponent({
return {
el: trackEl,
refs: {
segMessages,
segSystemTools,
segMcpTools,
segSkills,
segSystemPrompt,
segUserRules,
},
refs: { segments },
onPropsChange: syncMeter,
};
},
@@ -13,7 +13,9 @@ export const CustomSelect = defineComponent({
let isOpen = false;
let focusedIndex = -1;
const leadIcon = createSvgIcon(getProps().icon || 'bolt', { size: 13 });
const initialIcon = getProps().icon;
const leadIcon = createSvgIcon(initialIcon || 'bolt', { size: 13 });
patchAttr(leadIcon, 'hidden', !initialIcon);
const triggerLabel = h('span', { className: 'select-label' });
const chevronIcon = createSvgIcon('chevron-down', { size: 13 });
@@ -40,7 +42,8 @@ export const CustomSelect = defineComponent({
hidden: true,
});
const rootEl = h('div', { className: 'custom-select' }, [triggerBtn, menuEl]);
const initialClass = ['custom-select', getProps().className].filter(Boolean).join(' ');
const rootEl = h('div', { className: initialClass }, [triggerBtn, menuEl]);
function toggleOpen(nextOpen) {
isOpen = Boolean(nextOpen);
@@ -142,9 +145,16 @@ export const CustomSelect = defineComponent({
}
function syncTriggerAndMenu() {
const { options = [], modelValue, placeholder = '请选择', icon = 'bolt' } = getProps();
patchSvgIcon(leadIcon, icon);
const selectedOpt = options.find((o) => o.value === modelValue) || options[0];
const { options = [], modelValue, placeholder = '请选择', icon } = getProps();
patchAttr(leadIcon, 'hidden', !icon);
if (icon) {
patchSvgIcon(leadIcon, icon);
}
const selectedOpt =
options.find((o) => o.value === modelValue) ||
(modelValue !== '' && modelValue !== null && modelValue !== undefined
? options[0]
: undefined);
patchText(triggerLabel, selectedOpt ? selectedOpt.label : placeholder);
if (isOpen) {
renderMenuOptions();