|
3 | 3 | * This allows workflow execution with proper logging from both React hooks and tools |
4 | 4 | */ |
5 | 5 |
|
| 6 | +import type { Edge } from 'reactflow' |
6 | 7 | import { v4 as uuidv4 } from 'uuid' |
7 | 8 | import { createLogger } from '@/lib/logs/console/logger' |
8 | 9 | import { buildTraceSpans } from '@/lib/logs/execution/trace-spans/trace-spans' |
| 10 | +import { TriggerUtils } from '@/lib/workflows/triggers' |
9 | 11 | import type { BlockOutput } from '@/blocks/types' |
10 | 12 | import { Executor } from '@/executor' |
11 | 13 | import type { ExecutionResult, StreamingExecution } from '@/executor/types' |
@@ -81,6 +83,37 @@ export function getWorkflowExecutionContext(): WorkflowExecutionContext { |
81 | 83 | } |
82 | 84 | } |
83 | 85 |
|
| 86 | +/** |
| 87 | + * Filter out edges between trigger blocks. |
| 88 | + * Trigger blocks are independent entry points and should not have edges to other trigger blocks. |
| 89 | + * However, trigger blocks can have edges to regular blocks. |
| 90 | + */ |
| 91 | +export function filterEdgesFromTriggerBlocks(blocks: Record<string, any>, edges: Edge[]): Edge[] { |
| 92 | + return edges.filter((edge) => { |
| 93 | + const sourceBlock = blocks[edge.source] |
| 94 | + const targetBlock = blocks[edge.target] |
| 95 | + |
| 96 | + // If either block not found, keep the edge (might be in a different state structure) |
| 97 | + if (!sourceBlock || !targetBlock) { |
| 98 | + return true |
| 99 | + } |
| 100 | + |
| 101 | + const sourceIsTrigger = TriggerUtils.isTriggerBlock({ |
| 102 | + type: sourceBlock.type, |
| 103 | + triggerMode: sourceBlock.triggerMode, |
| 104 | + }) |
| 105 | + |
| 106 | + const targetIsTrigger = TriggerUtils.isTriggerBlock({ |
| 107 | + type: targetBlock.type, |
| 108 | + triggerMode: targetBlock.triggerMode, |
| 109 | + }) |
| 110 | + |
| 111 | + // Filter out edges where source is trigger AND target is trigger |
| 112 | + // Keep edges from triggers to regular blocks |
| 113 | + return !(sourceIsTrigger && targetIsTrigger) |
| 114 | + }) |
| 115 | +} |
| 116 | + |
84 | 117 | /** |
85 | 118 | * Execute a workflow with proper state management and logging |
86 | 119 | * This is the core execution logic extracted from useWorkflowExecution |
@@ -168,9 +201,9 @@ export async function executeWorkflowWithLogging( |
168 | 201 | {} as Record<string, any> |
169 | 202 | ) |
170 | 203 |
|
171 | | - // Don't filter edges - let all connections remain intact |
172 | | - // The executor's routing system will handle execution paths properly |
173 | | - const filteredEdges = workflowEdges |
| 204 | + // Filter out edges from trigger blocks - triggers are independent entry points |
| 205 | + // and should not have edges to other trigger blocks |
| 206 | + const filteredEdges = filterEdgesFromTriggerBlocks(validBlocks, workflowEdges) |
174 | 207 |
|
175 | 208 | // Create serialized workflow with filtered blocks and edges |
176 | 209 | const workflow = new Serializer().serializeWorkflow( |
|
0 commit comments