(metadata?: Partial<ChatMessage>)
| 55 | } |
| 56 | |
| 57 | const markComplete = (metadata?: Partial<ChatMessage>) => { |
| 58 | updateAiMessage((msg) => { |
| 59 | const { metadata: messageMetadata, ...rest } = metadata ?? {} |
| 60 | |
| 61 | // Mark native reasoning blocks as complete by setting thinkingOpen = false |
| 62 | // This ensures thinking blocks auto-collapse when the message finishes |
| 63 | // Check for thinkingOpen !== false to handle both true (native) and undefined (legacy) |
| 64 | const updatedBlocks = msg.blocks?.map((block) => { |
| 65 | if ( |
| 66 | block.type === 'text' && |
| 67 | (block as TextContentBlock).textType === 'reasoning' && |
| 68 | (block as TextContentBlock).thinkingOpen !== false |
| 69 | ) { |
| 70 | return { ...block, thinkingOpen: false } as ContentBlock |
| 71 | } |
| 72 | return block |
| 73 | }) |
| 74 | |
| 75 | const nextMessage: ChatMessage = { |
| 76 | ...msg, |
| 77 | isComplete: true, |
| 78 | ...(updatedBlocks && { blocks: updatedBlocks }), |
| 79 | ...rest, |
| 80 | } |
| 81 | |
| 82 | if (messageMetadata) { |
| 83 | nextMessage.metadata = { |
| 84 | ...(msg.metadata ?? {}), |
| 85 | ...messageMetadata, |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return nextMessage |
| 90 | }) |
| 91 | } |
| 92 | |
| 93 | const setError = (message: string) => { |
| 94 | updateAiMessage((msg) => ({ |
nothing calls this directly
no test coverage detected