@@ -13,6 +13,7 @@ import {
1313 EuiSmallButton ,
1414 EuiText ,
1515} from '@elastic/eui' ;
16+ import { TOOL_TYPE } from '../../../../../common' ;
1617
1718interface AgentSummaryModalProps {
1819 onClose : ( ) => void ;
@@ -26,11 +27,8 @@ export function AgentSummaryModal(props: AgentSummaryModalProps) {
2627 < EuiModalHeaderTitle > Agent Summary</ EuiModalHeaderTitle >
2728 </ EuiModalHeader >
2829 < EuiModalBody >
29- { /**
30- * Handle newline formatting, as the agent response will likely have plaintext "\n" characters.
31- */ }
32- < EuiText style = { { whiteSpace : 'pre-wrap' } } >
33- < i > { props . agentSummary } </ i >
30+ < EuiText style = { { whiteSpace : 'pre-wrap' , lineHeight : 1.5 } } >
31+ { prettifyAgentSummary ( props . agentSummary ) }
3432 </ EuiText >
3533 </ EuiModalBody >
3634 < EuiModalFooter >
@@ -41,3 +39,34 @@ export function AgentSummaryModal(props: AgentSummaryModalProps) {
4139 </ EuiModal >
4240 ) ;
4341}
42+
43+ // Post-processing of the agent summary string returned from the LLM.
44+ // Clean up any escape characters, highlight the tools mentioned, and other
45+ // minor formatting / styling improvements
46+ function prettifyAgentSummary ( text : string ) : any {
47+ // rm backslashes before quotes
48+ let updatedText = text . replace ( / \\ " / g, '"' ) ;
49+
50+ const tools = [
51+ ...( Object . values ( TOOL_TYPE ) as string [ ] ) ,
52+ 'query_planner_tool' ,
53+ ] ;
54+ updatedText = updatedText . replace (
55+ new RegExp ( `\\b(${ tools . join ( '|' ) } )\\b` , 'g' ) ,
56+ '**_$1_**'
57+ ) ;
58+
59+ return updatedText . split ( '\n' ) . map ( ( line , idx ) => (
60+ < div key = { idx } style = { { marginBottom : '1rem' } } >
61+ { line . split ( / ( \* \* .* ?\* \* ) / ) . map ( ( segment , j ) =>
62+ segment . startsWith ( '**_' ) && segment . endsWith ( '_**' ) ? (
63+ < strong key = { j } >
64+ < em > { segment . slice ( 3 , - 3 ) } </ em >
65+ </ strong >
66+ ) : (
67+ segment
68+ )
69+ ) }
70+ </ div >
71+ ) ) ;
72+ }
0 commit comments