fix: 工具页签自动切换协调性修复

This commit is contained in:
thzxx
2026-04-19 19:40:41 +08:00
parent 6b1d790436
commit aa33f8845e
+24 -6
View File
@@ -329,6 +329,12 @@ function handleToolDone(command: string, exitCode: number | null): void {
renderTerminal(); renderTerminal();
updateStopBtnState(); updateStopBtnState();
updateHint(); updateHint();
// 命令结束后,如果没有其他正在运行的工具,切到工具页签看结果
const hasRunningTools = toolCards.some(c => c.status === 'running' && c.name !== 'run_command');
if (!hasRunningTools && toolCards.length > 0) {
setTimeout(() => switchToTab('tools'), 600);
}
} }
function appendTerminalOutput(sessionId: string, type: 'stdout' | 'stderr', data: string): void { function appendTerminalOutput(sessionId: string, type: 'stdout' | 'stderr', data: string): void {
@@ -739,17 +745,23 @@ function formatSize(bytes: number): string {
// ── 工具调用管理 ── // ── 工具调用管理 ──
/** 是否有命令正在终端中执行 */
function isTerminalBusy(): boolean {
return currentAiCommand !== null || (terminal?.running ?? false);
}
/** 添加工具调用卡片(由外部调用) */ /** 添加工具调用卡片(由外部调用) */
export function addToolCard(tc: ToolCallRecord): void { export function addToolCard(tc: ToolCallRecord): void {
toolCards.push(tc); toolCards.push(tc);
// 如果是 run_command,自动切到终端 tab
if (tc.name === 'run_command') { if (tc.name === 'run_command') {
// run_command:始终切到终端
switchToTab('terminal'); switchToTab('terminal');
} else { } else if (!isTerminalBusy()) {
// 终端空闲时才切到工具页签
switchToTab('tools'); switchToTab('tools');
} }
renderToolCalls(); // 终端忙碌时不切换,避免打断用户看命令输出
updateToolsHint();
} }
/** 更新工具调用卡片状态(由外部调用) */ /** 更新工具调用卡片状态(由外部调用) */
@@ -761,13 +773,19 @@ export function updateToolCard(tc: ToolCallRecord): void {
break; break;
} }
} }
renderToolCalls();
// 如果当前在工具页签,刷新显示
if (activeTab === 'tools') {
renderToolCalls();
}
updateToolsHint(); updateToolsHint();
} }
function clearToolCards(): void { function clearToolCards(): void {
toolCards = []; toolCards = [];
renderToolCalls(); if (activeTab === 'tools') {
renderToolCalls();
}
updateToolsHint(); updateToolsHint();
} }