@@ -141,6 +141,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
141
141
} else {
142
142
props . workflowDispatchDeep += 1 ;
143
143
}
144
+ const isRootRuntime = props . workflowDispatchDeep === 1 ;
144
145
145
146
if ( props . workflowDispatchDeep > 20 ) {
146
147
return {
@@ -161,25 +162,28 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
161
162
let workflowRunTimes = 0 ;
162
163
163
164
// set sse response headers
164
- if ( stream && res ) {
165
- res . setHeader ( 'Content-Type' , 'text/event-stream;charset=utf-8' ) ;
166
- res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
167
- res . setHeader ( 'X-Accel-Buffering' , 'no' ) ;
168
- res . setHeader ( 'Cache-Control' , 'no-cache, no-transform' ) ;
169
-
170
- // 10s sends a message to prevent the browser from thinking that the connection is disconnected
171
- const sendStreamTimerSign = ( ) => {
172
- setTimeout ( ( ) => {
173
- props ?. workflowStreamResponse ?.( {
174
- event : SseResponseEventEnum . answer ,
175
- data : textAdaptGptResponse ( {
176
- text : ''
177
- } )
178
- } ) ;
179
- sendStreamTimerSign ( ) ;
180
- } , 10000 ) ;
181
- } ;
182
- sendStreamTimerSign ( ) ;
165
+ if ( isRootRuntime ) {
166
+ res ?. setHeader ( 'Connection' , 'keep-alive' ) ; // Set keepalive for long connection
167
+ if ( stream && res ) {
168
+ res . setHeader ( 'Content-Type' , 'text/event-stream;charset=utf-8' ) ;
169
+ res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
170
+ res . setHeader ( 'X-Accel-Buffering' , 'no' ) ;
171
+ res . setHeader ( 'Cache-Control' , 'no-cache, no-transform' ) ;
172
+
173
+ // 10s sends a message to prevent the browser from thinking that the connection is disconnected
174
+ const sendStreamTimerSign = ( ) => {
175
+ setTimeout ( ( ) => {
176
+ props ?. workflowStreamResponse ?.( {
177
+ event : SseResponseEventEnum . answer ,
178
+ data : textAdaptGptResponse ( {
179
+ text : ''
180
+ } )
181
+ } ) ;
182
+ sendStreamTimerSign ( ) ;
183
+ } , 10000 ) ;
184
+ } ;
185
+ sendStreamTimerSign ( ) ;
186
+ }
183
187
}
184
188
185
189
variables = {
@@ -373,7 +377,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
373
377
} ;
374
378
375
379
// Tool call, not need interactive response
376
- if ( ! props . isToolCall && ! props . runningAppInfo . isChildApp ) {
380
+ if ( ! props . isToolCall && isRootRuntime ) {
377
381
props . workflowStreamResponse ?.( {
378
382
event : SseResponseEventEnum . interactive ,
379
383
data : { interactive : interactiveResult }
@@ -427,14 +431,6 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
427
431
} ) ( ) ;
428
432
429
433
if ( ! nodeRunResult ) return [ ] ;
430
- if ( res ?. closed ) {
431
- addLog . warn ( 'Request is closed' , {
432
- appId : props . runningAppInfo . id ,
433
- nodeId : node . nodeId ,
434
- nodeName : node . name
435
- } ) ;
436
- return [ ] ;
437
- }
438
434
439
435
/*
440
436
特殊情况:
@@ -491,6 +487,15 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
491
487
await Promise . all ( nextStepSkipNodes . map ( ( node ) => checkNodeCanRun ( node , skippedNodeIdList ) ) )
492
488
) . flat ( ) ;
493
489
490
+ if ( res ?. closed ) {
491
+ addLog . warn ( 'Request is closed' , {
492
+ appId : props . runningAppInfo . id ,
493
+ nodeId : node . nodeId ,
494
+ nodeName : node . name
495
+ } ) ;
496
+ return [ ] ;
497
+ }
498
+
494
499
return [
495
500
...nextStepActiveNodes ,
496
501
...nextStepSkipNodes ,
@@ -631,7 +636,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
631
636
if (
632
637
version === 'v2' &&
633
638
! props . isToolCall &&
634
- ! props . runningAppInfo . isChildApp &&
639
+ isRootRuntime &&
635
640
formatResponseData &&
636
641
! ( ! props . responseDetail && filterModuleTypeList . includes ( formatResponseData . moduleType ) )
637
642
) {
@@ -720,7 +725,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
720
725
entryNodeIds : nodeInteractiveResponse . entryNodeIds ,
721
726
interactiveResponse : nodeInteractiveResponse . interactiveResponse
722
727
} ) ;
723
- if ( ! props . runningAppInfo . isChildApp ) {
728
+ if ( isRootRuntime ) {
724
729
chatAssistantResponse . push ( interactiveAssistant ) ;
725
730
}
726
731
return interactiveAssistant . interactive ;
0 commit comments