fix: 工具页签自动切换协调性修复
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果当前在工具页签,刷新显示
|
||||||
|
if (activeTab === 'tools') {
|
||||||
renderToolCalls();
|
renderToolCalls();
|
||||||
|
}
|
||||||
updateToolsHint();
|
updateToolsHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearToolCards(): void {
|
function clearToolCards(): void {
|
||||||
toolCards = [];
|
toolCards = [];
|
||||||
|
if (activeTab === 'tools') {
|
||||||
renderToolCalls();
|
renderToolCalls();
|
||||||
|
}
|
||||||
updateToolsHint();
|
updateToolsHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user