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
+347 -74
View File
@@ -26,11 +26,30 @@ import {
speedReasonText,
} from '../core/formatters.js';
import { createSvgIcon } from '../icons/SvgIcon.js';
import { telemetryStore } from '../store/telemetryStore.js';
import {
formatAgentLabel,
getAgentBadgeClass,
resolveScopedConversation,
telemetryStore,
} from '../store/telemetryStore.js';
import { uiStore } from '../store/uiStore.js';
import { ContextSegmentMeter } from '../components/ui/ContextSegmentMeter.js';
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
const PILL_BASE_PAD_PX = 14;
const CJK_CHAR_PX = 11;
const ASCII_CHAR_PX = 6.1;
const PILL_GAP_PX = 4;
const DEFAULT_BAR_WIDTH_PX = 310;
function estPillWidth(text) {
let w = PILL_BASE_PAD_PX;
for (const ch of String(text || '')) {
w += ch.charCodeAt(0) > 255 ? CJK_CHAR_PX : ASCII_CHAR_PX;
}
return Math.ceil(w);
}
export const LiveOverviewView = defineComponent({
name: 'LiveOverviewView',
setup({ onCleanup }) {
@@ -80,70 +99,124 @@ export const LiveOverviewView = defineComponent({
]),
]);
// --- 2. 6 段上下文窗口构成面板(自动锚定模型上下文压缩基线) ---
// --- 2. 6 段上下文窗口构成面板(自动锚定模型上下文压缩基线 + 方案 B 内嵌独立 256k 窗口检视条) ---
const ctxAgentBadge = h('span', {
className: 'agent-badge badge-main',
hidden: true,
text: '主代理',
});
const ctxSummaryText = h('span', { className: 'text-mono', text: '0 / 256.0k (0%)' });
const ctxSegmentBar = ContextSegmentMeter({ context: {} });
const bdMessages = h('strong', { className: 'text-mono', text: '0' });
const bdSystemTools = h('strong', { className: 'text-mono', text: '0' });
const bdMcpTools = h('strong', { className: 'text-mono', text: '0' });
const bdSkills = h('strong', { className: 'text-mono', text: '0' });
const bdSystemPrompt = h('strong', { className: 'text-mono', text: '0' });
const bdUserRules = h('strong', { className: 'text-mono', text: '0' });
const ctxPillGroup = h('div', { className: 'ctx-pill-group' });
const ctxInspectorBar = h(
'div',
{ className: 'ctx-inspector-bar', hidden: true },
[ctxPillGroup]
);
const ctxChannels = [
{
key: 'assistant',
label: '模型回复',
segClass: 'seg-assistant',
title: '模型推理思考、回复正文与工具调用入参',
getValue: (c) => Number(c.assistantTokens || 0),
},
{
key: 'toolResults',
label: '工具结果',
segClass: 'seg-tool-results',
title: '文件读取、终端输出与工具执行返回内容',
getValue: (c) => Number(c.toolResultsTokens || 0),
},
{
key: 'userInput',
label: '用户消息',
segClass: 'seg-user-input',
title: '用户提问文本与上传附件',
getValue: (c) => Number(c.userInputTokens ?? c.messagesTokens ?? 0),
},
{
key: 'subagent',
label: '子代理通知',
segClass: 'seg-subagent-msg',
title: '子代理完成汇报与后台任务系统通知',
getValue: (c) => Number(c.subagentTokens || 0),
},
{
key: 'checkpoint',
label: '压缩摘要',
segClass: 'seg-checkpoint',
title: '自动上下文压缩生成的历史摘要检查点',
getValue: (c) => Number(c.checkpointTokens || 0),
},
{
key: 'systemPrompt',
label: '系统提示词',
segClass: 'seg-system-prompt',
title: '核心身份、终端沙箱、制品与环境提示词',
getValue: (c) => Number(c.systemPromptTokens || 0),
},
{
key: 'systemTools',
label: '系统工具',
segClass: 'seg-system-tools',
title: '内置系统工具 Schema 定义',
getValue: (c) => Number(c.systemToolsTokens || 0),
},
{
key: 'mcpTools',
label: 'MCP 工具',
segClass: 'seg-mcp-tools',
title: 'MCP 外部服务工具与资源定义',
getValue: (c) => Number(c.mcpToolsTokens || 0),
},
{
key: 'skills',
label: 'Skill',
segClass: 'seg-skills',
title: '已挂载的 Skills 技能索引与说明',
getValue: (c) => Number(c.skillsTokens || 0),
},
{
key: 'userRules',
label: '用户规则',
segClass: 'seg-user-rules',
title: '全局与工作区自定义规则 (user_rules)',
getValue: (c) => Number(c.userRulesTokens || 0),
},
].map((ch, idx) => {
const valEl = h('strong', { className: 'text-mono', text: '0' });
const itemEl = h('div', { className: 'legend-item', title: ch.title }, [
h('span', { className: 'legend-left' }, [
h('span', { className: `swatch ${ch.segClass}` }),
h('span', { text: ch.label }),
]),
valEl,
]);
return { ...ch, defaultOrder: idx, valEl, itemEl };
});
const ctxLegendGrid = h(
'div',
{ className: 'ctx-legend-grid' },
ctxChannels.map((ch) => ch.itemEl)
);
let lastLegendOrderSig = ctxChannels.map((ch) => ch.key).join(',');
const ctxPanel = h('section', { className: 'panel' }, [
h('div', { className: 'panel-header' }, [
h('span', { className: 'panel-title' }, [
createSvgIcon('layers', { size: 13 }),
h('span', { text: '上下文占用' }),
h('span', { text: '上下文窗口' }),
ctxAgentBadge,
]),
h('span', { className: 'panel-meta' }, [ctxSummaryText]),
]),
ctxInspectorBar,
ctxSegmentBar.el,
h('div', { className: 'ctx-legend-grid' }, [
h('div', { className: 'legend-item' }, [
h('span', { className: 'legend-left' }, [
h('span', { className: 'swatch seg-messages' }),
h('span', { text: '消息' }),
]),
bdMessages,
]),
h('div', { className: 'legend-item' }, [
h('span', { className: 'legend-left' }, [
h('span', { className: 'swatch seg-system-tools' }),
h('span', { text: '系统工具' }),
]),
bdSystemTools,
]),
h('div', { className: 'legend-item' }, [
h('span', { className: 'legend-left' }, [
h('span', { className: 'swatch seg-mcp-tools' }),
h('span', { text: 'MCP 工具' }),
]),
bdMcpTools,
]),
h('div', { className: 'legend-item' }, [
h('span', { className: 'legend-left' }, [
h('span', { className: 'swatch seg-skills' }),
h('span', { text: 'Skill' }),
]),
bdSkills,
]),
h('div', { className: 'legend-item' }, [
h('span', { className: 'legend-left' }, [
h('span', { className: 'swatch seg-system-prompt' }),
h('span', { text: '系统提示词' }),
]),
bdSystemPrompt,
]),
h('div', { className: 'legend-item' }, [
h('span', { className: 'legend-left' }, [
h('span', { className: 'swatch seg-user-rules' }),
h('span', { text: '用户规则' }),
]),
bdUserRules,
]),
]),
ctxLegendGrid,
]);
// --- 3. 官方动态多配额池监控面板 (Gemini / Pro 独立 Argon 池 / Claude & GPT) ---
@@ -282,24 +355,55 @@ export const LiveOverviewView = defineComponent({
let latestData = null;
let isDirty = false;
let ctxPillsExpanded = false;
let lastCascadeId = '';
let cachedBarWidth = 0;
/**
* 将最新遥测载荷渲染至 4 格测速矩阵、6 段上下文进度条与动态配额池列表。
* 将最新遥测载荷渲染至 4 格测速矩阵、6 段上下文进度条(支持主/子代理切换检视)与动态配额池列表。
*/
function renderData(data) {
if (!data) return;
const active = data.activeConversation || {};
const ctx = active.context || {};
// 在本帧任何 DOM 写入前先读取容器宽度,避免写后读触发浏览器强制同步重排 (Forced Reflow)
const measuredWidth =
ctxInspectorBar.clientWidth || (ctxPanel.clientWidth ? ctxPanel.clientWidth - 24 : 0);
if (measuredWidth > 160) {
cachedBarWidth = measuredWidth;
}
const availRowWidth = cachedBarWidth > 160 ? cachedBarWidth : DEFAULT_BAR_WIDTH_PX;
const currentCascadeId = data.activeConversation?.cascadeId || '';
if (currentCascadeId && currentCascadeId !== lastCascadeId) {
if (lastCascadeId) {
ctxPillsExpanded = false;
}
lastCascadeId = currentCascadeId;
}
const uiSt = uiStore.getState();
const {
hasSubagents,
effectiveScope,
effectiveCtxScope,
agents,
aggregated,
scopedConv,
ctxAgent,
} = resolveScopedConversation(data, uiSt.selectedAgentScope, uiSt.ctxInspectorAgentId);
const active = scopedConv || data.activeConversation || {};
const ctx = ctxAgent?.context || active.context || {};
const quotas = data.quotas || {};
// 1. 更新 4 格实时测速矩阵
// 1. 更新 4 格实时测速矩阵(根据当前代理作用域动态展示全部汇总或单代理指标)
patchClasses(pulseDot, { 'is-pulsing': Boolean(active.isRunning) });
patchText(tpsVal, formatMetric(active.latestTokPerSec, ' tok/s'));
const reason = speedReasonText(active.latestSpeedReason);
patchText(
tpsSub,
reason ? `${active.activeModelShort || '模型未知'} · ${reason}` : active.activeModelShort || '模型未知'
);
const modelAndAgent =
hasSubagents && effectiveScope === 'all' && active.activeAgentBadge
? `[${active.activeAgentBadge}] ${active.activeModelShort || '模型未知'}`
: active.activeModelShort || '模型未知';
patchText(tpsSub, reason ? `${modelAndAgent} · ${reason}` : modelAndAgent);
patchText(ttftVal, formatMetric(active.latestTtftSec, 's'));
patchText(ttftSub, `均值 ${formatMetric(active.ttftSummary?.avgSec, 's')}`);
@@ -314,7 +418,138 @@ export const LiveOverviewView = defineComponent({
`缓存 ${active.latestCacheHitPct ?? 0}% · 累计 ${formatUsd(active.sessionCostUsd || 0, { unpricedCalls: active.sessionUnpricedCalls })}`
);
// 2. 更新 6 段上下文窗口构成(优先使用模型自动压缩基线 compactionLimitTokens)
// 2. 更新 6 段上下文窗口构成与方案 B 内嵌上下文窗口检视胶囊条
patchAttr(ctxAgentBadge, 'hidden', !hasSubagents);
patchAttr(ctxInspectorBar, 'hidden', !hasSubagents);
if (hasSubagents && ctxAgent) {
const badgeCls = getAgentBadgeClass(ctxAgent.index || 0, Boolean(ctxAgent.isMain));
patchAttr(ctxAgentBadge, 'class', `agent-badge ${badgeCls}`);
const badgeFullText = formatAgentLabel(ctxAgent);
patchText(ctxAgentBadge, badgeFullText);
patchAttr(ctxAgentBadge, 'title', badgeFullText);
const pillItems = [];
if (effectiveScope === 'all') {
pillItems.push({
key: 'auto',
label: `跟随活跃 (${aggregated?.activeAgentBadge || '主'})`,
title: '自动展示当前正在运行或最新活跃的代理上下文窗口',
isActive: effectiveCtxScope === 'auto',
mode: 'ctx-only',
});
} else {
pillItems.push({
key: 'all',
label: `全部汇总 (${aggregated?.stepCount ?? 0}步)`,
title: '切回全部代理汇总视图',
isActive: false,
mode: 'scope',
});
}
const allAgentPills = agents.map((ag) => {
const agPct = ag.context?.usedPct ?? 0;
const isAct =
effectiveScope === 'all'
? effectiveCtxScope === ag.agentId
: effectiveScope === ag.agentId;
return {
key: ag.agentId,
label: `${ag.badgeText || ag.shortLabel} ${agPct}%`,
title: `${formatAgentLabel(ag)} (${ag.activeModelShort || '模型未知'} · ${ag.stepCount || 0}步)`,
isActive: isAct,
mode: effectiveScope === 'all' ? 'ctx-only' : 'scope',
};
});
// 根据当前卡片的实际像素宽度估算单行可容纳的胶囊数量,尽可能塞满整行右侧空间
const firstPillWidth = pillItems.length > 0 ? estPillWidth(pillItems[0].label) : 0;
const totalAllWidth = allAgentPills.reduce(
(sum, p) => sum + PILL_GAP_PX + estPillWidth(p.label),
firstPillWidth
);
const needsCollapse = totalAllWidth > availRowWidth && allAgentPills.length > 2;
if (needsCollapse && !ctxPillsExpanded) {
const toggleReservePx = PILL_GAP_PX + estPillWidth(`+${allAgentPills.length} 展开 ▾`);
let usedW = firstPillWidth;
let fitCount = 0;
for (let i = 0; i < allAgentPills.length; i++) {
const pw = PILL_GAP_PX + estPillWidth(allAgentPills[i].label);
if (fitCount >= 1 && usedW + pw + toggleReservePx > availRowWidth) {
break;
}
usedW += pw;
fitCount++;
}
// 至少折叠 2 个胶囊(避免出现比胶囊本身还宽的 "+1 展开 ▾")
const maxKeep = Math.max(1, allAgentPills.length - 2);
const maxCollapsedCount = Math.max(1, Math.min(maxKeep, fitCount));
const visibleAgentPills = allAgentPills.slice(0, maxCollapsedCount);
const activeHiddenPill = allAgentPills
.slice(maxCollapsedCount)
.find((p) => p.isActive);
if (activeHiddenPill) {
if (visibleAgentPills.length >= 2) {
visibleAgentPills[visibleAgentPills.length - 1] = activeHiddenPill;
} else {
visibleAgentPills.push(activeHiddenPill);
}
}
const hiddenCount = allAgentPills.length - visibleAgentPills.length;
pillItems.push(...visibleAgentPills, {
key: '__toggle_more__',
label: `+${hiddenCount} 展开 ▾`,
title: `展开全部 ${allAgentPills.length - 1} 个子代理的上下文窗口胶囊`,
isActive: false,
isMoreToggle: true,
mode: 'toggle-expand',
});
} else {
pillItems.push(...allAgentPills);
if (needsCollapse) {
pillItems.push({
key: '__toggle_more__',
label: '收起 ▴',
title: '折叠多余子代理胶囊',
isActive: false,
isMoreToggle: true,
mode: 'toggle-expand',
});
}
}
patchKeyedList(ctxPillGroup, pillItems, {
keyFn: (item) => item.key,
sigFn: (item) =>
`${item.key}:${item.label}:${item.isActive}:${item.isMoreToggle}:${item.mode}:${item.title}`,
createRow: () => {
const btn = h('button', { type: 'button', className: 'ctx-agent-pill' });
return { el: btn, refs: { btn } };
},
updateRow: (refs, item) => {
patchText(refs.btn, item.label);
patchAttr(refs.btn, 'title', item.title);
patchClasses(refs.btn, {
'is-active': item.isActive,
'is-more-toggle': Boolean(item.isMoreToggle),
});
refs.btn.onclick = () => {
if (item.mode === 'toggle-expand') {
ctxPillsExpanded = !ctxPillsExpanded;
renderData(latestData);
} else if (item.mode === 'ctx-only') {
uiStore.setState({ ctxInspectorAgentId: item.key });
} else if (item.key === 'all') {
uiStore.setState({ selectedAgentScope: 'all', ctxInspectorAgentId: 'auto' });
} else {
uiStore.setState({ selectedAgentScope: item.key });
}
};
},
});
}
const limitTokens = Number(ctx.compactionLimitTokens || ctx.limitTokens || 256000);
const totalTokens = Number(ctx.totalTokens || 0);
const usedPct =
@@ -324,12 +559,19 @@ export const LiveOverviewView = defineComponent({
`${formatTokens(totalTokens)} / ${formatTokens(limitTokens)} (${usedPct}%)`
);
ctxSegmentBar.setProps({ context: { ...ctx, limitTokens, usedPct } });
patchText(bdMessages, formatTokens(ctx.messagesTokens || 0));
patchText(bdSystemTools, formatTokens(ctx.systemToolsTokens || 0));
patchText(bdMcpTools, formatTokens(ctx.mcpToolsTokens || 0));
patchText(bdSkills, formatTokens(ctx.skillsTokens || 0));
patchText(bdSystemPrompt, formatTokens(ctx.systemPromptTokens || 0));
patchText(bdUserRules, formatTokens(ctx.userRulesTokens || 0));
const scoredChannels = ctxChannels.map((ch) => {
const val = ch.getValue(ctx);
patchText(ch.valEl, formatTokens(val));
return { ch, val };
});
scoredChannels.sort((a, b) => b.val - a.val || a.ch.defaultOrder - b.ch.defaultOrder);
const nextLegendOrderSig = scoredChannels.map((x) => x.ch.key).join(',');
if (nextLegendOrderSig !== lastLegendOrderSig) {
lastLegendOrderSig = nextLegendOrderSig;
for (const { ch } of scoredChannels) {
ctxLegendGrid.appendChild(ch.itemEl);
}
}
// 3. 更新动态配额池列表(支持 Gemini、Pro 独立 Argon 池、Claude & GPT 等)
patchText(
@@ -398,21 +640,52 @@ export const LiveOverviewView = defineComponent({
}
);
let prevScope = uiStore.getState().selectedAgentScope;
let prevCtxTarget = uiStore.getState().ctxInspectorAgentId;
const unsubView = uiStore.subscribe(
(st) => st.activeView,
(activeView) => {
if (activeView === 'overview' && isDirty) {
(st) => ({
activeView: st.activeView,
selectedAgentScope: st.selectedAgentScope,
ctxInspectorAgentId: st.ctxInspectorAgentId,
}),
(slice) => {
const scopeChanged =
slice.selectedAgentScope !== prevScope || slice.ctxInspectorAgentId !== prevCtxTarget;
prevScope = slice.selectedAgentScope;
prevCtxTarget = slice.ctxInspectorAgentId;
if (slice.activeView !== 'overview') {
if (scopeChanged) isDirty = true;
return;
}
if ((isDirty || scopeChanged) && latestData) {
isDirty = false;
if (latestData) {
renderData(latestData);
}
renderData(latestData);
}
}
);
let ro = null;
if (typeof ResizeObserver !== 'undefined') {
ro = new ResizeObserver(() => {
if (uiStore.getState().activeView !== 'overview') return;
const nextW =
ctxInspectorBar.clientWidth || (ctxPanel.clientWidth ? ctxPanel.clientWidth - 24 : 0);
if (nextW > 160 && Math.abs(nextW - cachedBarWidth) >= 6) {
cachedBarWidth = nextW;
if (latestData?.activeConversation?.hasSubagents) {
renderData(latestData);
}
}
});
ro.observe(ctxPanel);
}
onCleanup(() => {
unsub();
unsubView();
if (ro) ro.disconnect();
ctxSegmentBar.destroy();
viewScrollbar.destroy();
});
+3 -3
View File
@@ -221,7 +221,7 @@ export const SettingsView = defineComponent({
// --- 面板 2:版本更新面板 ---
const pricingCountVal = h('strong', { className: 'cell-value', text: '—' });
const pricingSyncSub = h('span', { className: 'cell-sub', text: '读取中…' });
const versionVal = h('strong', { className: 'cell-value', text: 'v1.4.0' });
const versionVal = h('strong', { className: 'cell-value', text: 'v1.4.1' });
const versionSub = h('span', { className: 'cell-sub', text: '检查中…' });
const syncPricingBtnText = h('span', { text: '更新价格表' });
@@ -276,7 +276,7 @@ export const SettingsView = defineComponent({
return;
}
if (!cs?.updateAvailable) {
const curVer = cs?.currentPluginVersion || '1.4.0';
const curVer = cs?.currentPluginVersion || '1.4.1';
showCloudFeedback(`当前已是最新版本 (v${curVer})`, 4500);
return;
}
@@ -379,7 +379,7 @@ export const SettingsView = defineComponent({
`${srcLabel} · ${formatSyncTimeText(cs.lastSyncedAtMs, cs.catalogUpdatedAt)}`
);
const curVer = cs.currentPluginVersion || '1.4.0';
const curVer = cs.currentPluginVersion || '1.4.1';
const latVer = cs.latestPluginVersion || curVer;
const modeTag = cs.installMode === 'git' ? 'Git' : 'ZIP';
patchText(versionVal, `v${curVer}`);
+146 -22
View File
@@ -22,14 +22,38 @@ import {
speedReasonText,
} from '../core/formatters.js';
import { createSvgIcon } from '../icons/SvgIcon.js';
import { telemetryStore } from '../store/telemetryStore.js';
import {
formatAgentLabel,
getAgentBadgeClass,
resolveScopedConversation,
telemetryStore,
} from '../store/telemetryStore.js';
import { uiStore } from '../store/uiStore.js';
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
import { CustomSelect } from '../components/ui/CustomSelect.js';
import { SegmentedControl } from '../components/ui/SegmentedControl.js';
export const StepsDetailView = defineComponent({
name: 'StepsDetailView',
setup({ onCleanup }) {
// 方案 B:明细面板标题栏内嵌代理筛选下拉框(与顶栏代理切换条双向同步)
const inlineScopeSelect = CustomSelect({
modelValue: uiStore.getState().selectedAgentScope,
icon: 'layers',
placeholder: '全部代理',
className: 'steps-inline-scope-select',
options: [{ value: 'all', label: '全部代理' }],
onUpdateModelValue: (nextScope) => {
if (nextScope) {
uiStore.setState({
selectedAgentScope: nextScope,
...(nextScope === 'all' ? { ctxInspectorAgentId: 'auto' } : {}),
});
}
},
});
inlineScopeSelect.el.setAttribute('hidden', '');
// 顶部子表分段切换器:在“按步查看”与“按模型汇总”之间切换
const subTabSwitch = SegmentedControl({
ariaLabel: '明细表视图切换',
@@ -100,7 +124,10 @@ export const StepsDetailView = defineComponent({
createSvgIcon('table', { size: 13 }),
h('span', { text: '调用记录' }),
]),
subTabSwitch.el,
h('div', { className: 'steps-header-controls' }, [
inlineScopeSelect.el,
subTabSwitch.el,
]),
]),
stepsScroll.el,
modelsScroll.el,
@@ -128,26 +155,82 @@ export const StepsDetailView = defineComponent({
*/
function renderStepsData(slice) {
if (!slice) return;
const steps = slice.recentSteps || [];
const models = slice.modelBreakdown || [];
const uiSt = uiStore.getState();
const {
hasSubagents,
effectiveScope,
subagents,
mainAgent,
aggregated,
scopedConv,
} = resolveScopedConversation(
{ activeConversation: slice.activeConversation },
uiSt.selectedAgentScope,
uiSt.ctxInspectorAgentId
);
patchAttr(inlineScopeSelect.el, 'hidden', !hasSubagents);
if (hasSubagents) {
const scopeOpts = [
{
value: 'all',
label: '全部汇总',
meta: `${aggregated?.stepCount ?? 0}步`,
},
{
value: 'main',
label: '主代理',
meta: `${mainAgent?.stepCount ?? 0}步`,
},
...subagents.map((s) => ({
value: s.agentId,
label: formatAgentLabel(s),
meta: `${s.stepCount || 0}步`,
})),
];
inlineScopeSelect.setProps({
modelValue: effectiveScope,
options: scopeOpts,
});
} else {
inlineScopeSelect.close();
}
const steps =
(hasSubagents ? scopedConv?.recentSteps : slice.recentSteps) ||
slice.recentSteps ||
[];
const models =
hasSubagents && Array.isArray(scopedConv?.modelBreakdown)
? scopedConv.modelBreakdown
: slice.modelBreakdown || [];
const showUpstream = Boolean(slice.showUpstreamModel);
const modelsTabBadge = hasSubagents
? effectiveScope === 'all'
? '本会话汇总'
: scopedConv?.shortLabel || '当前代理'
: slice.rangeLabel;
subTabSwitch.setProps({
options: [
{ value: 'steps', label: `按步查看 (${steps.length})` },
{ value: 'models', label: `按模型汇总 (${slice.rangeLabel})` },
{ value: 'models', label: `按模型汇总 (${modelsTabBadge})` },
],
});
// 1. 单步测速表增量对账:以 `<cascadeId>-<stepIndex>` 为稳定行键,仅在签名变化时刷新单元格
// 1. 单步测速表增量对账:以 `<agentCascadeId>-<stepIndex>` 为稳定行键,仅在签名变化时刷新单元格
patchKeyedList(stepsTbody, steps, {
keyFn: (st) => `${slice.cascadeId || 'conv'}-${st.stepIndex}`,
keyFn: (st) => `${st.agentCascadeId || slice.cascadeId || 'conv'}-${st.stepIndex}`,
sigFn: (st) =>
`${st.stepIndex}:${showUpstream ? st.modelUpstream || st.responseModel || st.modelShort : st.modelShort}:${st.tokPerSec}:${st.ttftSec}:${st.contextTokens}:${st.outputTokens}:${st.cacheHitPct}:${st.costUsd}:${st.selectedSpeedReason}`,
`${hasSubagents}:${effectiveScope}:${st.agentId || 'main'}:${st.stepIndex}:${showUpstream ? st.modelUpstream || st.responseModel || st.modelShort : st.modelShort}:${st.tokPerSec}:${st.ttftSec}:${st.contextTokens}:${st.outputTokens}:${st.cacheHitPct}:${st.costUsd}:${st.selectedSpeedReason}`,
createRow: () => {
const agentBadgeEl = h('span', {
className: 'agent-badge is-clickable',
hidden: true,
style: 'margin-right: 4px;',
});
const stepNumText = h('span');
const compIcon = createSvgIcon('bolt', { size: 11, className: 'text-muted' });
const tdStep = h('td', {}, [stepNumText, compIcon]);
const tdStep = h('td', {}, [agentBadgeEl, stepNumText]);
const tdModel = h('td', {
style: 'max-width: 140px; overflow: hidden; text-overflow: ellipsis;',
@@ -171,8 +254,8 @@ export const StepsDetailView = defineComponent({
return {
el: tr,
refs: {
agentBadgeEl,
stepNumText,
compIcon,
tdModel,
speedMain,
speedReason,
@@ -184,8 +267,28 @@ export const StepsDetailView = defineComponent({
};
},
updateRow: (refs, st) => {
patchText(refs.stepNumText, `#${Number(st.stepIndex)} `);
patchAttr(refs.compIcon, 'hidden', !st.isCompactionStep);
patchAttr(refs.agentBadgeEl, 'hidden', !hasSubagents);
if (hasSubagents) {
const badgeCls = getAgentBadgeClass(st.agentIndex || 0, !st.isSubagent);
patchAttr(refs.agentBadgeEl, 'class', `agent-badge is-clickable ${badgeCls}`);
patchText(refs.agentBadgeEl, st.agentBadge || (st.isSubagent ? '子' : '主'));
patchAttr(
refs.agentBadgeEl,
'title',
effectiveScope === 'all'
? `点击仅过滤查看 ${st.agentLabel || '该代理'}`
: '点击切回全部汇总'
);
refs.agentBadgeEl.onclick = () => {
const targetScope = st.agentId || 'main';
const nextScope = effectiveScope === targetScope ? 'all' : targetScope;
uiStore.setState({
selectedAgentScope: nextScope,
...(nextScope === 'all' ? { ctxInspectorAgentId: 'auto' } : {}),
});
};
}
patchText(refs.stepNumText, `#${Number(st.stepIndex)}`);
const modelText =
(showUpstream ? st.modelUpstream || st.responseModel : st.modelShort) ||
st.modelShort ||
@@ -250,12 +353,16 @@ export const StepsDetailView = defineComponent({
},
});
stepsScroll.refresh();
modelsScroll.refresh();
if (uiSt.stepsSubTab === 'models') {
modelsScroll.refresh();
} else {
stepsScroll.refresh();
}
}
const unsubTelemetry = telemetryStore.subscribe(
(st) => ({
activeConversation: st.telemetry?.activeConversation,
cascadeId: st.telemetry?.activeConversation?.cascadeId,
recentSteps: st.telemetry?.activeConversation?.recentSteps,
modelBreakdown: st.telemetry?.modelBreakdown,
@@ -273,14 +380,23 @@ export const StepsDetailView = defineComponent({
}
);
let prevScope = uiStore.getState().selectedAgentScope;
const unsubView = uiStore.subscribe(
(st) => st.activeView,
(activeView) => {
if (activeView === 'steps' && isDirty) {
(st) => ({
activeView: st.activeView,
selectedAgentScope: st.selectedAgentScope,
}),
(uiSlice) => {
const scopeChanged = uiSlice.selectedAgentScope !== prevScope;
prevScope = uiSlice.selectedAgentScope;
if (uiSlice.activeView !== 'steps') {
if (scopeChanged) isDirty = true;
return;
}
if ((isDirty || scopeChanged) && latestSlice) {
isDirty = false;
if (latestSlice) {
renderStepsData(latestSlice);
}
renderStepsData(latestSlice);
}
}
);
@@ -289,6 +405,7 @@ export const StepsDetailView = defineComponent({
unsubUi();
unsubTelemetry();
unsubView();
inlineScopeSelect.destroy();
subTabSwitch.destroy();
stepsScroll.destroy();
modelsScroll.destroy();
@@ -296,7 +413,14 @@ export const StepsDetailView = defineComponent({
return {
el: rootEl,
refs: { stepsTbody, modelsTbody, subTabSwitch, stepsScroll, modelsScroll },
refs: {
stepsTbody,
modelsTbody,
inlineScopeSelect,
subTabSwitch,
stepsScroll,
modelsScroll,
},
};
},
});