From 767abfc23343e7ed4064d4b31fce716efcd4dbae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E9=98=BF=E6=B1=9F=28Relakkes?= =?UTF-8?q?=29?= Date: Mon, 6 Apr 2026 23:26:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20restore=20tool=20calls=20on=20page=20ref?= =?UTF-8?q?resh=20=E2=80=94=20handle=20server=20type=20mapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Server marks assistant messages with tool_use blocks as type='tool_use' (not 'assistant'), and user messages with tool_result blocks as type='tool_result' (not 'user'). mapHistoryMessagesToUiMessages now handles both type variants when parsing content arrays, so tool calls are properly restored after page refresh. Co-Authored-By: Claude Opus 4.6 --- desktop/src/stores/chatStore.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/desktop/src/stores/chatStore.ts b/desktop/src/stores/chatStore.ts index 1b18c75d..03f12b2c 100644 --- a/desktop/src/stores/chatStore.ts +++ b/desktop/src/stores/chatStore.ts @@ -423,7 +423,9 @@ export function mapHistoryMessagesToUiMessages(messages: MessageEntry[]): UIMess continue } - if (msg.type === 'assistant' && Array.isArray(msg.content)) { + // Server marks assistant messages containing tool_use blocks as type 'tool_use', + // but the content array structure is the same as 'assistant' — handle both. + if ((msg.type === 'assistant' || msg.type === 'tool_use') && Array.isArray(msg.content)) { for (const block of msg.content as AssistantHistoryBlock[]) { if (block.type === 'thinking' && block.thinking) { uiMessages.push({ @@ -454,7 +456,9 @@ export function mapHistoryMessagesToUiMessages(messages: MessageEntry[]): UIMess continue } - if (msg.type === 'user' && Array.isArray(msg.content)) { + // Server marks user messages containing tool_result blocks as type 'tool_result', + // but the content array structure is the same as 'user' — handle both. + if ((msg.type === 'user' || msg.type === 'tool_result') && Array.isArray(msg.content)) { const textParts: string[] = [] const attachments: UIAttachment[] = []