@@ -129,6 +129,7 @@ export function agentStreamProtocolResponseHeaders(options: {
129129
130130interface StreamingState {
131131 streamedChunks : Map < string , string [ ] >
132+ streamedBlockIds : Set < string >
132133 processedOutputs : Set < string >
133134 streamCompletionTimes : Map < string , number >
134135 completedBlockIds : Set < string >
@@ -319,6 +320,7 @@ async function buildMinimalResult(
319320 result : ExecutionResult ,
320321 selectedOutputs : string [ ] | undefined ,
321322 streamedContent : Map < string , string > ,
323+ streamedBlockIds : Set < string > ,
322324 completedBlockIds : Set < string > ,
323325 streamedSelectedOutputKeys : Set < string > ,
324326 requestId : string ,
@@ -387,15 +389,8 @@ async function buildMinimalResult(
387389 let selectedOutputBytes = assertSelectedOutputBytes ( minimalResult . output )
388390 for ( const descriptor of getSelectedOutputDescriptors ( selectedOutputs ) ) {
389391 const { blockId, path } = descriptor
390- const blockLogs = result . logs . filter ( ( log : BlockLog ) => log . blockId === blockId )
391392
392- if (
393- streamedContent . has ( blockId ) ||
394- blockLogs . some (
395- ( log : BlockLog ) =>
396- log . blockExecutionId !== undefined && streamedContent . has ( log . blockExecutionId )
397- )
398- ) {
393+ if ( streamedContent . has ( blockId ) || streamedBlockIds . has ( blockId ) ) {
399394 continue
400395 }
401396
@@ -417,7 +412,7 @@ async function buildMinimalResult(
417412 continue
418413 }
419414
420- const blockLog = blockLogs [ 0 ]
415+ const blockLog = result . logs . find ( ( log : BlockLog ) => log . blockId === blockId )
421416 if ( ! blockLog ?. output ) {
422417 continue
423418 }
@@ -545,6 +540,7 @@ export async function createStreamingResponse(
545540 async start ( controller ) {
546541 const state : StreamingState = {
547542 streamedChunks : new Map ( ) ,
543+ streamedBlockIds : new Set ( ) ,
548544 processedOutputs : new Set ( ) ,
549545 streamCompletionTimes : new Map ( ) ,
550546 completedBlockIds : new Set ( ) ,
@@ -689,6 +685,7 @@ export async function createStreamingResponse(
689685 }
690686
691687 const textChunk = decoder . decode ( value , { stream : true } )
688+ state . streamedBlockIds . add ( blockId )
692689 if ( ! state . streamedChunks . has ( streamKey ) ) {
693690 state . streamedChunks . set ( streamKey , [ ] )
694691 }
@@ -728,7 +725,7 @@ export async function createStreamingResponse(
728725 return
729726 }
730727
731- if ( state . streamedChunks . has ( blockExecutionId ?? blockId ) ) {
728+ if ( state . streamedBlockIds . has ( blockId ) ) {
732729 return
733730 }
734731
@@ -880,6 +877,7 @@ export async function createStreamingResponse(
880877 result ,
881878 streamConfig . selectedOutputs ,
882879 streamedContent ,
880+ state . streamedBlockIds ,
883881 state . completedBlockIds ,
884882 state . streamedSelectedOutputKeys ,
885883 requestId ,
0 commit comments