1
- import { useState } from ' react' ;
2
- import cx from ' ../utils/cx' ;
3
- import CodeBlock from ' ./code-block' ;
4
- import { IconCaretDownFilled } from ' ../icons/caret-dropdown' ;
5
- import { AgentName , StepRecord } from ' ../types' ;
6
- import Markdown from ' markdown-to-jsx' ;
1
+ import { useState } from " react" ;
2
+ import cx from " ../utils/cx" ;
3
+ import CodeBlock from " ./code-block" ;
4
+ import { IconCaretDownFilled } from " ../icons/caret-dropdown" ;
5
+ import { AgentName , StepRecord } from " ../types" ;
6
+ import Markdown from " markdown-to-jsx" ;
7
7
8
8
const CollapsibleText = ( {
9
9
title,
10
10
text,
11
- maxLength = 300
11
+ maxLength = 300 ,
12
12
} : {
13
13
title : string ;
14
14
text : string ;
15
15
maxLength ?: number ;
16
16
} ) => {
17
17
const [ isExpanded , setIsExpanded ] = useState ( false ) ;
18
18
19
+ // Ensure text starts on a new line by adding a newline if it doesn't already have one
20
+ const formattedText = text && ! text . startsWith ( '\n' ) ? `\n${ text } ` : text ;
21
+
19
22
if ( ! text || text . length <= maxLength )
20
23
return (
21
24
< div className = "border-gray-300 border-2 p-3 rounded-xl text-md font-mono break-words" >
22
- { ' ' }
25
+ { " " }
23
26
< label className = "text-base font-semibold text-purple-500" >
24
27
{ title }
25
28
</ label >
@@ -32,16 +35,16 @@ const CollapsibleText = ({
32
35
) ,
33
36
ul : ( { children } ) => (
34
37
< ol className = "list-disc list-inside" > { children } </ ol >
35
- )
36
- }
38
+ ) ,
39
+ } ,
37
40
} }
38
41
>
39
- { text }
42
+ { formattedText }
40
43
</ Markdown >
41
44
</ div >
42
45
) ;
43
46
44
- const displayText = isExpanded ? text : text . slice ( 0 , maxLength ) + ' ...' ;
47
+ const displayText = isExpanded ? formattedText : formattedText . slice ( 0 , maxLength ) + " ..." ;
45
48
46
49
return (
47
50
< div className = "border-gray-300 border-2 p-3 rounded-xl text-md font-mono break-words" >
@@ -55,8 +58,8 @@ const CollapsibleText = ({
55
58
) ,
56
59
ul : ( { children } ) => (
57
60
< ol className = "list-disc list-inside" > { children } </ ol >
58
- )
59
- }
61
+ ) ,
62
+ } ,
60
63
} }
61
64
>
62
65
{ displayText }
@@ -65,7 +68,7 @@ const CollapsibleText = ({
65
68
onClick = { ( ) => setIsExpanded ( ! isExpanded ) }
66
69
className = "text-purple-500 hover:text-purple-600 font-medium text-sm font-mono mt-2"
67
70
>
68
- { isExpanded ? ' Read Less' : ' Read More' }
71
+ { isExpanded ? " Read Less" : " Read More" }
69
72
</ button >
70
73
</ div >
71
74
) ;
@@ -74,14 +77,16 @@ const CollapsibleText = ({
74
77
export const AgentInfo = ( {
75
78
name,
76
79
code,
77
- state
80
+ state,
78
81
} : {
79
82
name : AgentName ;
80
83
code : string ;
81
- state : false | ' loading' | StepRecord [ ] ;
84
+ state : false | " loading" | StepRecord [ ] ;
82
85
} ) => {
83
86
const [ displayCode , setDisplayCode ] = useState ( false ) ;
84
- const [ displayOutput , setDisplayOutput ] = useState ( false ) ;
87
+ const [ displayOutput , setDisplayOutput ] = useState (
88
+ name === "Cross Reference"
89
+ ) ;
85
90
return (
86
91
< div className = "flex flex-col gap-4" >
87
92
< div className = "flex flex-col gap-2 w-full" >
@@ -91,8 +96,8 @@ export const AgentInfo = ({
91
96
>
92
97
< IconCaretDownFilled
93
98
className = { cx (
94
- ' transform transition-transform' ,
95
- displayCode && ' rotate-180'
99
+ " transform transition-transform" ,
100
+ displayCode && " rotate-180"
96
101
) }
97
102
/>
98
103
< label className = "" > { name } Agent Code</ label >
@@ -104,31 +109,31 @@ export const AgentInfo = ({
104
109
< div className = "flex flex-col gap-4 w-full" >
105
110
< button
106
111
id = {
107
- name === ' Cross Reference'
108
- ? ' cross-reference-output'
109
- : ' intermediate-output'
112
+ name === " Cross Reference"
113
+ ? " cross-reference-output"
114
+ : " intermediate-output"
110
115
}
111
116
className = { cx (
112
- ' flex gap-1 w-full px-2 py-2 rounded-xl items-center' ,
113
- state && state !== ' loading'
114
- ? ' bg-purple-500/10 text-purple-500'
115
- : ' bg-gray-100 text-gray-400'
117
+ " flex gap-1 w-full px-2 py-2 rounded-xl items-center" ,
118
+ state && state !== " loading"
119
+ ? " bg-purple-500/10 text-purple-500"
120
+ : " bg-gray-100 text-gray-400"
116
121
) }
117
122
onClick = { ( ) => {
118
- if ( state && state !== ' loading' ) setDisplayOutput ( ! displayOutput ) ;
123
+ if ( state && state !== " loading" ) setDisplayOutput ( ! displayOutput ) ;
119
124
} }
120
125
>
121
126
< IconCaretDownFilled
122
127
className = { cx (
123
- ' transform transition-transform' ,
124
- displayOutput && ' rotate-180'
128
+ " transform transition-transform" ,
129
+ displayOutput && " rotate-180"
125
130
) }
126
131
/>
127
- < label className = { '' } > { name } Agent Output</ label >
132
+ < label className = { "" } > { name } Agent Output</ label >
128
133
</ button >
129
134
{ displayOutput &&
130
135
state &&
131
- state !== ' loading' &&
136
+ state !== " loading" &&
132
137
state . map ( ( s , i ) => (
133
138
< div key = { i } >
134
139
< CollapsibleText title = { s . stepName } text = { s . stepOut } />
0 commit comments