fix: 工具卡片状态更新后即时刷新消息渲染

updateMessageToolRecord 更新 state 后缺少 renderMessages() 调用,
导致消息中的工具卡片状态不会实时更新(始终显示 running)。

添加 renderMessages() 调用,确保工具执行完成后消息中的卡片
立即显示正确状态(/)。
This commit is contained in:
thzxx
2026-04-23 12:36:32 +08:00
parent 4d03c35ea9
commit 7ed75415a3
+7 -3
View File
@@ -851,6 +851,7 @@ export async function sendMessage(): Promise<void> {
/** 更新当前会话消息中最近一个 'running' 状态的同名工具记录 */ /** 更新当前会话消息中最近一个 'running' 状态的同名工具记录 */
function updateMessageToolRecord(toolName: string, status: 'success' | 'error', result: Record<string, unknown>): void { function updateMessageToolRecord(toolName: string, status: 'success' | 'error', result: Record<string, unknown>): void {
let updated = false;
state.update(KEYS.CURRENT_SESSION, (session: ChatSession | null) => { state.update(KEYS.CURRENT_SESSION, (session: ChatSession | null) => {
if (!session) return session; if (!session) return session;
const messages = [...session.messages]; const messages = [...session.messages];
@@ -860,14 +861,17 @@ function updateMessageToolRecord(toolName: string, status: 'success' | 'error',
if (!msg.toolCalls) continue; if (!msg.toolCalls) continue;
const idx = msg.toolCalls.findIndex(tc => tc.name === toolName && tc.status === 'running'); const idx = msg.toolCalls.findIndex(tc => tc.name === toolName && tc.status === 'running');
if (idx !== -1) { if (idx !== -1) {
const updated = [...msg.toolCalls]; const updatedRecords = [...msg.toolCalls];
updated[idx] = { ...updated[idx], status, result }; updatedRecords[idx] = { ...updatedRecords[idx], status, result };
messages[i] = { ...msg, toolCalls: updated }; messages[i] = { ...msg, toolCalls: updatedRecords };
updated = true;
return { ...session, messages, updatedAt: Date.now() }; return { ...session, messages, updatedAt: Date.now() };
} }
} }
return session; return session;
}); });
// 状态更新后重新渲染消息,使工具卡片状态即时生效
if (updated) renderMessages();
} }
async function sendMessageWithAgentLoop(text: string, currentSession: ChatSession, model: string): Promise<void> { async function sendMessageWithAgentLoop(text: string, currentSession: ChatSession, model: string): Promise<void> {