mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
fix: restore tool calls on page refresh — handle server type mapping
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 <noreply@anthropic.com>
This commit is contained in:
parent
5e4e7d3955
commit
767abfc233
@ -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[] = []
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user