@@ -16,6 +16,9 @@ import type { ChatTheme } from '../utils/theme-system'
1616const trimTrailingNewlines = ( value : string ) : string =>
1717 value . replace ( / [ \r \n ] + $ / g, '' )
1818
19+ const sanitizePreview = ( value : string ) : string =>
20+ value . replace ( / [ # * _ ` ~ \[ \] ( ) ] / g, '' ) . trim ( )
21+
1922interface MessageBlockProps {
2023 messageId : string
2124 blocks ?: ContentBlock [ ]
@@ -123,13 +126,23 @@ export const MessageBlock = ({
123126 . split ( '\n' )
124127 . filter ( ( line ) => line . trim ( ) )
125128 const firstLine = lines [ 0 ] || ''
129+ const lastLine = lines [ lines . length - 1 ] || firstLine
130+ const commandPreview =
131+ block . toolName === 'run_terminal_command' &&
132+ block . input &&
133+ typeof ( block . input as any ) . command === 'string'
134+ ? `$ ${ ( block . input as any ) . command . trim ( ) } `
135+ : null
136+
126137 const streamingPreview = isStreaming
127- ? firstLine . replace ( / [ # * _ ` ~ \[ \] ( ) ] / g , '' ) . trim ( ) + '...'
138+ ? commandPreview ?? ` ${ sanitizePreview ( firstLine ) } ...`
128139 : ''
129140
130141 let finishedPreview = ''
131142 if ( ! isStreaming && isCollapsed ) {
132- if ( block . toolName === 'run_terminal_command' && block . output ) {
143+ if ( commandPreview ) {
144+ finishedPreview = commandPreview
145+ } else if ( block . toolName === 'run_terminal_command' && block . output ) {
133146 const outputLines = block . output
134147 . split ( '\n' )
135148 . filter ( ( line ) => line . trim ( ) )
@@ -139,9 +152,7 @@ export const MessageBlock = ({
139152 ? '...\n' + lastThreeLines . join ( '\n' )
140153 : lastThreeLines . join ( '\n' )
141154 } else {
142- finishedPreview = lastLine
143- . replace ( / [ # * _ ` ~ \[ \] ( ) ] / g, '' )
144- . trim ( )
155+ finishedPreview = sanitizePreview ( lastLine )
145156 }
146157 }
147158
@@ -284,15 +295,22 @@ export const MessageBlock = ({
284295 const lastNestedLine =
285296 nestedLines [ nestedLines . length - 1 ] || firstNestedLine
286297
298+ const nestedCommandPreview =
299+ nestedBlock . toolName === 'run_terminal_command' &&
300+ nestedBlock . input &&
301+ typeof ( nestedBlock . input as any ) . command === 'string'
302+ ? `$ ${ ( nestedBlock . input as any ) . command . trim ( ) } `
303+ : null
304+
287305 const nestedStreamingPreview = isNestedStreaming
288- ? firstNestedLine
289- . replace ( / [ # * _ ` ~ \[ \] ( ) ] / g, '' )
290- . trim ( ) + '...'
306+ ? nestedCommandPreview ?? `${ sanitizePreview ( firstNestedLine ) } ...`
291307 : ''
292308
293309 let nestedFinishedPreview = ''
294310 if ( ! isNestedStreaming && isNestedCollapsed ) {
295- if (
311+ if ( nestedCommandPreview ) {
312+ nestedFinishedPreview = nestedCommandPreview
313+ } else if (
296314 nestedBlock . toolName === 'run_terminal_command' &&
297315 nestedBlock . output
298316 ) {
@@ -305,9 +323,9 @@ export const MessageBlock = ({
305323 ? '...\n' + lastThreeLines . join ( '\n' )
306324 : lastThreeLines . join ( '\n' )
307325 } else {
308- nestedFinishedPreview = lastNestedLine
309- . replace ( / [ # * _ ` ~ \[ \] ( ) ] / g , '' )
310- . trim ( )
326+ nestedFinishedPreview = sanitizePreview (
327+ lastNestedLine ,
328+ )
311329 }
312330 }
313331
0 commit comments