@@ -181,8 +181,8 @@ export const MessageBlock = ({
181181 : ''
182182
183183 const finishedPreview =
184- ! isStreaming && isCollapsed
185- ? lastLine . replace ( / [ # * _ ` ~ \[ \] ( ) ] / g, '' ) . trim ( )
184+ ! isStreaming && isCollapsed && block . initialPrompt
185+ ? block . initialPrompt . replace ( / [ # * _ ` ~ \[ \] ( ) ] / g, '' ) . trim ( )
186186 : ''
187187
188188 const agentCodeBlockWidth = Math . max ( 10 , availableWidth - 12 )
@@ -195,16 +195,88 @@ export const MessageBlock = ({
195195 codeBlockWidth : agentCodeBlockWidth ,
196196 palette : agentPalette ,
197197 }
198- const displayContent = hasMarkdown ( block . content )
199- ? renderMarkdown ( block . content , agentMarkdownOptions )
200- : block . content
198+
199+ const displayContent = block . content
200+ ? ( hasMarkdown ( block . content )
201+ ? renderMarkdown ( block . content , agentMarkdownOptions )
202+ : block . content )
203+ : ''
204+
205+ const nestedToolBlocks = block . blocks && block . blocks . length > 0 && ! isCollapsed
206+ ? block . blocks . map ( ( nestedBlock , nestedIdx ) => {
207+ if ( nestedBlock . type === 'tool' ) {
208+ const displayInfo = getToolDisplayInfo ( nestedBlock . toolName )
209+ const isNestedCollapsed = collapsedAgents . has ( nestedBlock . toolCallId )
210+ const isNestedStreaming = streamingAgents . has ( nestedBlock . toolCallId )
211+
212+ const inputContent = `\`\`\`json\n${ JSON . stringify ( nestedBlock . input , null , 2 ) } \n\`\`\``
213+ const codeBlockLang =
214+ nestedBlock . toolName === 'run_terminal_command' ? '' : 'yaml'
215+ const resultContent = nestedBlock . output
216+ ? `\n\n**Result:**\n\`\`\`${ codeBlockLang } \n${ nestedBlock . output } \n\`\`\``
217+ : ''
218+ const fullNestedContent = inputContent + resultContent
219+
220+ const nestedLines = fullNestedContent . split ( '\n' ) . filter ( ( line ) => line . trim ( ) )
221+ const firstNestedLine = nestedLines [ 0 ] || ''
222+ const lastNestedLine = nestedLines [ nestedLines . length - 1 ] || firstNestedLine
223+
224+ const nestedStreamingPreview = isNestedStreaming
225+ ? firstNestedLine . replace ( / [ # * _ ` ~ \[ \] ( ) ] / g, '' ) . trim ( ) + '...'
226+ : ''
227+
228+ let nestedFinishedPreview = ''
229+ if ( ! isNestedStreaming && isNestedCollapsed ) {
230+ if ( nestedBlock . toolName === 'run_terminal_command' && nestedBlock . output ) {
231+ const outputLines = nestedBlock . output
232+ . split ( '\n' )
233+ . filter ( ( line ) => line . trim ( ) )
234+ const lastThreeLines = outputLines . slice ( - 3 )
235+ const hasMoreLines = outputLines . length > 3
236+ nestedFinishedPreview = hasMoreLines
237+ ? '...\n' + lastThreeLines . join ( '\n' )
238+ : lastThreeLines . join ( '\n' )
239+ } else {
240+ nestedFinishedPreview = lastNestedLine
241+ . replace ( / [ # * _ ` ~ \[ \] ( ) ] / g, '' )
242+ . trim ( )
243+ }
244+ }
245+
246+ const nestedDisplayContent = hasMarkdown ( fullNestedContent )
247+ ? renderMarkdown ( fullNestedContent , agentMarkdownOptions )
248+ : fullNestedContent
249+
250+ const nextNestedBlock = block . blocks ! [ nestedIdx + 1 ]
251+ const isLastNestedBranch = ! nextNestedBlock
252+ const nestedBranchChar = isLastNestedBranch ? ' └─ ' : ' ├─ '
253+
254+ return (
255+ < box key = { `${ messageId } -agent-${ block . agentId } -tool-${ nestedBlock . toolCallId } ` } >
256+ < BranchItem
257+ name = { displayInfo . name }
258+ content = { nestedDisplayContent }
259+ isCollapsed = { isNestedCollapsed }
260+ isStreaming = { isNestedStreaming }
261+ branchChar = { nestedBranchChar }
262+ streamingPreview = { nestedStreamingPreview }
263+ finishedPreview = { nestedFinishedPreview }
264+ theme = { theme }
265+ onToggle = { ( ) => onToggleCollapsed ( nestedBlock . toolCallId ) }
266+ />
267+ </ box >
268+ )
269+ }
270+ return null
271+ } )
272+ : null
201273
202274 const nextBlock = blocks [ idx + 1 ]
203275 const isLastBranch = ! nextBlock || nextBlock . type === 'text'
204276 const branchChar = isLastBranch ? '└─ ' : '├─ '
205277
206278 return (
207- < box key = { `${ messageId } -agent-${ block . agentId } ` } >
279+ < box key = { `${ messageId } -agent-${ block . agentId } ` } style = { { flexDirection : 'column' , gap : 0 } } >
208280 < BranchItem
209281 name = { block . agentName }
210282 content = { displayContent }
@@ -216,6 +288,7 @@ export const MessageBlock = ({
216288 theme = { theme }
217289 onToggle = { ( ) => onToggleCollapsed ( block . agentId ) }
218290 />
291+ { nestedToolBlocks }
219292 </ box >
220293 )
221294 }
0 commit comments