@@ -91,14 +91,23 @@ function TextContent({
91
91
function ProgressContent ( {
92
92
progress,
93
93
isFinished,
94
- progressValue,
95
94
msg,
96
95
} : {
97
96
progress : ProgressData ;
98
97
isFinished : boolean ;
99
- progressValue : number ;
100
98
msg ?: string ;
101
99
} ) {
100
+ const [ progressValue , setProgressValue ] = useState ( 0 ) ;
101
+
102
+ useEffect ( ( ) => {
103
+ if ( progress . total !== 0 ) {
104
+ const value = Math . round ( ( ( progress . current + 1 ) / progress . total ) * 100 ) ;
105
+ setProgressValue ( value ) ;
106
+ } else {
107
+ setProgressValue ( 0 ) ;
108
+ }
109
+ } , [ progress ] ) ;
110
+
102
111
return (
103
112
< div className = "space-y-2 mt-2" >
104
113
{ ! isFinished && msg && (
@@ -124,15 +133,6 @@ function AgentEventContent({
124
133
} ) {
125
134
const { agent, texts, progress } = event ;
126
135
const AgentIcon = event . icon ;
127
- const [ progressValue , setProgressValue ] = useState ( 0 ) ;
128
-
129
- useEffect ( ( ) => {
130
- if ( progress ) {
131
- // Add 1 to current_step to match the display value
132
- const value = Math . round ( ( ( progress . current + 1 ) / progress . total ) * 100 ) ;
133
- setProgressValue ( value ) ;
134
- }
135
- } , [ progress ] ) ;
136
136
137
137
return (
138
138
< div className = "flex gap-4 border-b pb-4 items-center fadein-agent" >
@@ -158,7 +158,6 @@ function AgentEventContent({
158
158
< ProgressContent
159
159
progress = { progress }
160
160
isFinished = { isFinished }
161
- progressValue = { progressValue }
162
161
msg = { texts [ texts . length - 1 ] }
163
162
/>
164
163
) }
@@ -200,41 +199,17 @@ function mergeAdjacentEvents(events: AgentEventData[]): MergedEvent[] {
200
199
for ( const event of events ) {
201
200
const lastMergedEvent = mergedEvents [ mergedEvents . length - 1 ] ;
202
201
203
- // Check the event_type first
204
- if ( event . type === "progress" ) {
205
- try {
206
- const progressData = event . data ;
207
-
208
- if ( lastMergedEvent && lastMergedEvent . agent === event . agent ) {
209
- lastMergedEvent . progress = progressData ;
210
- lastMergedEvent . texts . push ( event . text ) ;
211
- } else {
212
- mergedEvents . push ( {
213
- agent : event . agent ,
214
- texts : [ ] ,
215
- icon : AgentIcons [ event . agent . toLowerCase ( ) ] ?? icons . Bot ,
216
- progress : progressData ,
217
- } ) ;
218
- }
219
- } catch ( e ) {
220
- console . error (
221
- "Failed to parse progress data:" ,
222
- e ,
223
- "Raw text:" ,
224
- event . text ,
225
- ) ;
226
- }
227
- continue ;
228
- }
229
-
230
- // Handle regular text events
202
+ const progressData = event . data ;
231
203
if ( lastMergedEvent && lastMergedEvent . agent === event . agent ) {
204
+ // Update for the last merged event
205
+ lastMergedEvent . progress = progressData ;
232
206
lastMergedEvent . texts . push ( event . text ) ;
233
207
} else {
234
208
mergedEvents . push ( {
235
209
agent : event . agent ,
236
210
texts : [ event . text ] ,
237
211
icon : AgentIcons [ event . agent . toLowerCase ( ) ] ?? icons . Bot ,
212
+ progress : progressData ,
238
213
} ) ;
239
214
}
240
215
}
0 commit comments