@@ -92,14 +92,7 @@ function isContentSelectedForStreaming(ctx: ExecutionContext, block: SerializedB
9292 return (
9393 ctx . selectedOutputs ?. some ( ( outputId ) => {
9494 if ( outputId === block . id ) return true
95- if ( outputId === `${ block . id } .content` || outputId === `${ block . id } _content` ) return true
96-
97- const firstUnderscoreIndex = outputId . indexOf ( '_' )
98- if ( firstUnderscoreIndex === - 1 ) return false
99- return (
100- outputId . substring ( 0 , firstUnderscoreIndex ) === block . id &&
101- outputId . substring ( firstUnderscoreIndex + 1 ) === 'content'
102- )
95+ return outputId === `${ block . id } .content` || outputId === `${ block . id } _content`
10396 } ) ?? false
10497 )
10598}
@@ -139,26 +132,30 @@ async function readMothershipExecuteResponse(response: Response): Promise<Mother
139132 throw new Error ( 'Mothership execution stream returned an unknown event' )
140133 }
141134
142- while ( true ) {
143- const { done, value } = await reader . read ( )
144- if ( done ) break
145-
146- buffer += decoder . decode ( value , { stream : true } )
147- const lines = buffer . split ( '\n' )
148- buffer = lines . pop ( ) ?? ''
149- for ( const line of lines ) {
150- processLine ( line )
135+ try {
136+ while ( true ) {
137+ const { done, value } = await reader . read ( )
138+ if ( done ) break
139+
140+ buffer += decoder . decode ( value , { stream : true } )
141+ const lines = buffer . split ( '\n' )
142+ buffer = lines . pop ( ) ?? ''
143+ for ( const line of lines ) {
144+ processLine ( line )
145+ }
151146 }
152- }
153147
154- buffer += decoder . decode ( )
155- processLine ( buffer )
148+ buffer += decoder . decode ( )
149+ processLine ( buffer )
156150
157- if ( ! finalResult ) {
158- throw new Error ( 'Mothership execution stream ended without a final result' )
159- }
151+ if ( ! finalResult ) {
152+ throw new Error ( 'Mothership execution stream ended without a final result' )
153+ }
160154
161- return finalResult
155+ return finalResult
156+ } finally {
157+ reader . releaseLock ( )
158+ }
162159}
163160
164161function createMothershipStreamingExecution (
@@ -273,7 +270,7 @@ function createMothershipStreamingExecution(
273270 startTime : new Date ( ) . toISOString ( ) ,
274271 } ,
275272 isStreaming : true ,
276- } ,
273+ } as StreamingExecution [ 'execution' ] & { blockId : string } ,
277274 }
278275}
279276
0 commit comments