feat(panel): add conversation turn rail, prompt preview, and decoupled step toggles

- Track user input turn boundaries and prompt previews in extractModelSteps while stripping compaction summary headers
- Align interleaved main and subagent steps onto unified rootTurnIndex in telemetry-builder and scope lazy cache refresh to the active session family
- Render dynamic left-edge turn rail and viewport-clamped prompt tooltip in StepsDetailView across arbitrary custom column orders
- Decouple [主]/[子] agent badges from step index and add independent switches for Turn Rail and Agent Badge under Preferences -> Structure

Co-authored-by: Swei <sweilo@qq.com>
This commit is contained in:
fish
2026-11-15 16:55:26 +09:00
co-authored by Swei
parent f2a68c6d82
commit 228031e335
17 changed files with 1350 additions and 54 deletions
+80
View File
@@ -610,14 +610,91 @@ export function extractModelSteps(rawSteps = [], generatorMetadata = []) {
const result = [];
let lastCompactionStepIdx = -1;
let turnCounter = 0;
let activeTurnIndex = null;
let pendingTurnPrompts = [];
let hasUnconsumedTurn = false;
const isUserTurnBoundary = (step) => {
if (!step || typeof step !== 'object') return false;
const t = String(step.type || '').trim().toUpperCase();
if (t === 'CORTEX_STEP_TYPE_USER_INPUT' || t === 'USER_INPUT') {
return true;
}
return Boolean(step.userInput && typeof step.userInput === 'object');
};
const extractUserTurnPrompt = (step) => {
const ui = step?.userInput;
let raw = '';
if (typeof ui?.userResponse === 'string' && ui.userResponse.trim()) {
raw = ui.userResponse;
} else if (Array.isArray(ui?.items)) {
raw = ui.items
.map((it) => (typeof it?.text === 'string' ? it.text : ''))
.filter(Boolean)
.join('\n');
} else if (typeof step?.content === 'string' && step.content.trim()) {
const withoutSummary = step.content
.replace(/<CONTEXT_SUMMARY>[\s\S]*?<\/CONTEXT_SUMMARY>/gi, '')
.replace(/<SYSTEM_MESSAGE>[\s\S]*$/i, '');
const reqMatches = [...withoutSummary.matchAll(/<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/gi)];
raw =
reqMatches.length > 0
? reqMatches[reqMatches.length - 1][1]
: withoutSummary.replace(/<ADDITIONAL_METADATA>[\s\S]*$/i, '');
}
const cleaned = String(raw || '')
.split(/\r?\n/)
.map((l) => l.replace(/\s+/g, ' ').trim())
.filter(Boolean)
.join('\n');
const mediaArr = Array.isArray(ui?.media)
? ui.media
: Array.isArray(step?.media)
? step.media
: [];
const hasMedia = mediaArr.length > 0;
if (!cleaned) {
return hasMedia ? '[图片/附件提问]' : '';
}
const withMedia = hasMedia ? `${cleaned} [附图]` : cleaned;
return withMedia.length > 180 ? `${withMedia.slice(0, 179)}…` : withMedia;
};
rawSteps.forEach((s, index) => {
if (isUserTurnBoundary(s)) {
const promptText = extractUserTurnPrompt(s);
if (!hasUnconsumedTurn) {
hasUnconsumedTurn = true;
pendingTurnPrompts = promptText ? [promptText] : [];
} else if (
promptText &&
pendingTurnPrompts[pendingTurnPrompts.length - 1] !== promptText
) {
pendingTurnPrompts.push(promptText);
}
}
const m = s?.metadata;
const u = m?.modelUsage || m?.retryInfos?.[0]?.usage;
if (!u) {
return;
}
let stepIsTurnStart = false;
let stepTurnPrompt = '';
if (hasUnconsumedTurn) {
turnCounter += 1;
activeTurnIndex = turnCounter;
stepIsTurnStart = true;
const joinedPrompt = pendingTurnPrompts.join('\n').trim();
stepTurnPrompt =
joinedPrompt.length > 180 ? `${joinedPrompt.slice(0, 179)}…` : joinedPrompt;
hasUnconsumedTurn = false;
pendingTurnPrompts = [];
}
const stepIndex = m.sourceTrajectoryStepInfo?.stepIndex ?? index;
if (Array.isArray(m.generatorMetadata)) {
for (const g of m.generatorMetadata) {
@@ -781,6 +858,9 @@ export function extractModelSteps(rawSteps = [], generatorMetadata = []) {
speedSampleEligible:
totalTokPerSec !== null && !shortOutputSample && !isCompactionStep,
speedReason,
turnIndex: activeTurnIndex,
isTurnStart: stepIsTurnStart,
...(stepIsTurnStart && stepTurnPrompt ? { turnPrompt: stepTurnPrompt } : {}),
});
});