@@ -297,6 +297,7 @@ async function processStreamingResponse(response, loadingId = null) {
297297 let lastUpdateTime = Date . now ( ) ;
298298 let pauseIndicator = null ;
299299 let isSSE = null ;
300+ let eventDataLines = [ ] ; // Track data lines within current event
300301
301302 const pauseCheckInterval = setInterval ( ( ) => {
302303 const timeSinceUpdate = Date . now ( ) - lastUpdateTime ;
@@ -333,8 +334,13 @@ async function processStreamingResponse(response, loadingId = null) {
333334
334335 for ( const line of lines ) {
335336 if ( line . startsWith ( 'data:' ) ) {
336- const content = line . substring ( 5 ) ;
337- fullResponse += ( content === '' || content === '\r' ) ? '\n' : content ;
337+ eventDataLines . push ( line . substring ( 5 ) ) ;
338+ } else if ( line === '' || line === '\r' ) {
339+ // Blank line = end of event, join data lines with \n per SSE spec
340+ if ( eventDataLines . length > 0 ) {
341+ fullResponse += eventDataLines . join ( '\n' ) ;
342+ eventDataLines = [ ] ;
343+ }
338344 }
339345 }
340346 } else {
@@ -355,9 +361,9 @@ async function processStreamingResponse(response, loadingId = null) {
355361 }
356362 }
357363
358- // Flush remaining SSE buffer
359- if ( isSSE && buffer && buffer . startsWith ( 'data:' ) ) {
360- fullResponse += buffer . substring ( 5 ) ;
364+ // Flush remaining SSE data
365+ if ( eventDataLines . length > 0 ) {
366+ fullResponse += eventDataLines . join ( '\n' ) ;
361367 }
362368 } finally {
363369 clearInterval ( pauseCheckInterval ) ;
0 commit comments