@@ -10,6 +10,7 @@ import { hasAdminPermission } from '@/lib/permissions/utils'
10
10
import { processStreamingBlockLogs } from '@/lib/tokenization'
11
11
import { getEmailDomain } from '@/lib/urls/utils'
12
12
import { decryptSecret } from '@/lib/utils'
13
+ import { getBlock } from '@/blocks'
13
14
import { db } from '@/db'
14
15
import { chat , environment as envTable , userStats , workflow } from '@/db/schema'
15
16
import { Executor } from '@/executor'
@@ -423,7 +424,22 @@ export async function executeWorkflowForChat(
423
424
424
425
// Prepare for execution, similar to use-workflow-execution.ts
425
426
const mergedStates = mergeSubblockState ( blocks )
426
- const currentBlockStates = Object . entries ( mergedStates ) . reduce (
427
+
428
+ const filteredStates = Object . entries ( mergedStates ) . reduce (
429
+ ( acc , [ id , block ] ) => {
430
+ const blockConfig = getBlock ( block . type )
431
+ const isTriggerBlock = blockConfig ?. category === 'triggers'
432
+
433
+ // Skip trigger blocks during chat execution
434
+ if ( ! isTriggerBlock ) {
435
+ acc [ id ] = block
436
+ }
437
+ return acc
438
+ } ,
439
+ { } as typeof mergedStates
440
+ )
441
+
442
+ const currentBlockStates = Object . entries ( filteredStates ) . reduce (
427
443
( acc , [ id , block ] ) => {
428
444
acc [ id ] = Object . entries ( block . subBlocks ) . reduce (
429
445
( subAcc , [ key , subBlock ] ) => {
@@ -465,10 +481,20 @@ export async function executeWorkflowForChat(
465
481
logger . warn ( `[${ requestId } ] Could not parse workflow variables:` , error )
466
482
}
467
483
468
- // Create serialized workflow
484
+ // Filter edges to exclude connections to/from trigger blocks (same as manual execution)
485
+ const triggerBlockIds = Object . keys ( mergedStates ) . filter ( ( id ) => {
486
+ const blockConfig = getBlock ( mergedStates [ id ] . type )
487
+ return blockConfig ?. category === 'triggers'
488
+ } )
489
+
490
+ const filteredEdges = edges . filter (
491
+ ( edge ) => ! triggerBlockIds . includes ( edge . source ) && ! triggerBlockIds . includes ( edge . target )
492
+ )
493
+
494
+ // Create serialized workflow with filtered blocks and edges
469
495
const serializedWorkflow = new Serializer ( ) . serializeWorkflow (
470
- mergedStates ,
471
- edges ,
496
+ filteredStates ,
497
+ filteredEdges ,
472
498
loops ,
473
499
parallels ,
474
500
true // Enable validation during execution
@@ -562,7 +588,7 @@ export async function executeWorkflowForChat(
562
588
contextExtensions : {
563
589
stream : true ,
564
590
selectedOutputIds : selectedOutputIds . length > 0 ? selectedOutputIds : outputBlockIds ,
565
- edges : edges . map ( ( e : any ) => ( {
591
+ edges : filteredEdges . map ( ( e : any ) => ( {
566
592
source : e . source ,
567
593
target : e . target ,
568
594
} ) ) ,
0 commit comments