11import { TextAttributes } from '@opentui/core'
2- import { useCallback , useMemo , type ReactNode } from 'react'
2+ import { useMemo , type ReactNode } from 'react'
33import React from 'react'
44
55import { MessageBlock } from '../components/message-block'
@@ -182,15 +182,22 @@ export const useMessageRenderer = (
182182 style = { {
183183 flexDirection : 'row' ,
184184 alignSelf : 'flex-start' ,
185- backgroundColor : isCollapsed ? theme . muted : theme . success ,
185+ backgroundColor : isCollapsed
186+ ? theme . muted
187+ : theme . success ,
186188 paddingLeft : 1 ,
187189 paddingRight : 1 ,
188190 } }
189191 onMouseDown = { handleTitleClick }
190192 >
191193 < text style = { { wrapMode : 'word' } } >
192- < span fg = { theme . foreground } > { isCollapsed ? '▸ ' : '▾ ' } </ span >
193- < span fg = { theme . foreground } attributes = { TextAttributes . BOLD } >
194+ < span fg = { theme . foreground } >
195+ { isCollapsed ? '▸ ' : '▾ ' }
196+ </ span >
197+ < span
198+ fg = { theme . foreground }
199+ attributes = { TextAttributes . BOLD }
200+ >
194201 { agentInfo . agentName }
195202 </ span >
196203 </ text >
@@ -236,7 +243,10 @@ export const useMessageRenderer = (
236243 >
237244 { agentChildren . map ( ( childAgent , idx ) => (
238245 < box key = { childAgent . id } style = { { flexShrink : 0 } } >
239- { renderMessageWithAgents ( childAgent , depth + 1 ) }
246+ { renderMessageWithAgents (
247+ childAgent ,
248+ depth + 1 ,
249+ ) }
240250 </ box >
241251 ) ) }
242252 </ box >
@@ -253,13 +263,16 @@ export const useMessageRenderer = (
253263 const isAgent = message . variant === 'agent'
254264
255265 if ( isAgent ) {
256- return renderAgentMessage ( message , depth )
266+ return renderAgentMessage (
267+ message ,
268+ depth ,
269+ )
257270 }
258271
259272 const isAi = message . variant === 'ai'
260273 const isUser = message . variant === 'user'
261274 const isError = message . variant === 'error'
262-
275+
263276 // Check if this is a mode divider message
264277 if (
265278 message . blocks &&
@@ -281,7 +294,11 @@ export const useMessageRenderer = (
281294 : isAi
282295 ? theme . foreground
283296 : theme . foreground
284- const timestampColor = isError ? 'red' : isAi ? theme . muted : theme . muted
297+ const timestampColor = isError
298+ ? 'red'
299+ : isAi
300+ ? theme . muted
301+ : theme . muted
285302 const estimatedMessageWidth = availableWidth
286303 const codeBlockWidth = Math . max ( 10 , estimatedMessageWidth - 8 )
287304 const paletteForMessage : MarkdownPalette = {
@@ -300,34 +317,6 @@ export const useMessageRenderer = (
300317 const hasAgentChildren = agentChildren . length > 0
301318 const showVerticalLine = isUser
302319
303- const onToggleCollapsed = useCallback (
304- ( id : string ) => {
305- const wasCollapsed = collapsedAgents . has ( id )
306- setCollapsedAgents ( ( prev ) => {
307- const next = new Set ( prev )
308- if ( next . has ( id ) ) {
309- next . delete ( id )
310- } else {
311- next . add ( id )
312- }
313- return next
314- } )
315- // Track user interaction
316- setUserOpenedAgents ( ( prev ) => {
317- const next = new Set ( prev )
318- if ( wasCollapsed ) {
319- // User is opening it, mark as user-opened
320- next . add ( id )
321- } else {
322- // User is closing it, remove from user-opened
323- next . delete ( id )
324- }
325- return next
326- } )
327- } ,
328- [ collapsedAgents , setCollapsedAgents , setUserOpenedAgents ] ,
329- )
330-
331320 return (
332321 < box
333322 key = { message . id }
@@ -395,7 +384,30 @@ export const useMessageRenderer = (
395384 markdownPalette = { markdownPalette }
396385 collapsedAgents = { collapsedAgents }
397386 streamingAgents = { streamingAgents }
398- onToggleCollapsed = { onToggleCollapsed }
387+ onToggleCollapsed = { ( id : string ) => {
388+ const wasCollapsed = collapsedAgents . has ( id )
389+ setCollapsedAgents ( ( prev ) => {
390+ const next = new Set ( prev )
391+ if ( next . has ( id ) ) {
392+ next . delete ( id )
393+ } else {
394+ next . add ( id )
395+ }
396+ return next
397+ } )
398+ // Track user interaction
399+ setUserOpenedAgents ( ( prev ) => {
400+ const next = new Set ( prev )
401+ if ( wasCollapsed ) {
402+ // User is opening it, mark as user-opened
403+ next . add ( id )
404+ } else {
405+ // User is closing it, remove from user-opened
406+ next . delete ( id )
407+ }
408+ return next
409+ } )
410+ } }
399411 />
400412 </ box >
401413 </ box >
@@ -466,7 +478,10 @@ export const useMessageRenderer = (
466478 < box style = { { flexDirection : 'column' , width : '100%' , gap : 0 } } >
467479 { agentChildren . map ( ( agent , idx ) => (
468480 < box key = { agent . id } style = { { width : '100%' } } >
469- { renderMessageWithAgents ( agent , depth + 1 ) }
481+ { renderMessageWithAgents (
482+ agent ,
483+ depth + 1 ,
484+ ) }
470485 </ box >
471486 ) ) }
472487 </ box >
0 commit comments