( workflow: WorkflowInfo, requestId: string, input: unknown | undefined, actorUserId: string, streamConfig?: ExecuteWorkflowOptions, providedExecutionId?: string )
| 59 | } |
| 60 | |
| 61 | export async function executeWorkflow( |
| 62 | workflow: WorkflowInfo, |
| 63 | requestId: string, |
| 64 | input: unknown | undefined, |
| 65 | actorUserId: string, |
| 66 | streamConfig?: ExecuteWorkflowOptions, |
| 67 | providedExecutionId?: string |
| 68 | ): Promise<ExecutionResult> { |
| 69 | if (!workflow.workspaceId) { |
| 70 | throw new Error(`Workflow ${workflow.id} has no workspaceId`) |
| 71 | } |
| 72 | |
| 73 | const workflowId = workflow.id |
| 74 | const workspaceId = workflow.workspaceId |
| 75 | const executionId = providedExecutionId || generateId() |
| 76 | const triggerType = streamConfig?.workflowTriggerType || 'api' |
| 77 | const loggingSession = new LoggingSession(workflowId, executionId, triggerType, requestId) |
| 78 | |
| 79 | try { |
| 80 | const metadata: ExecutionMetadata = { |
| 81 | requestId, |
| 82 | executionId, |
| 83 | workflowId, |
| 84 | workspaceId, |
| 85 | userId: actorUserId, |
| 86 | workflowUserId: workflow.userId, |
| 87 | triggerType, |
| 88 | triggerBlockId: streamConfig?.triggerBlockId, |
| 89 | useDraftState: streamConfig?.useDraftState ?? false, |
| 90 | startTime: new Date().toISOString(), |
| 91 | isClientSession: false, |
| 92 | largeValueExecutionIds: Array.from(new Set([executionId])), |
| 93 | largeValueKeys: streamConfig?.largeValueKeys, |
| 94 | fileKeys: streamConfig?.fileKeys, |
| 95 | executionMode: streamConfig?.executionMode, |
| 96 | } |
| 97 | |
| 98 | const snapshot = new ExecutionSnapshot( |
| 99 | metadata, |
| 100 | workflow, |
| 101 | input, |
| 102 | workflow.variables || {}, |
| 103 | streamConfig?.selectedOutputs || [] |
| 104 | ) |
| 105 | |
| 106 | const executionStartMs = Date.now() |
| 107 | |
| 108 | const result = await executeWorkflowCore({ |
| 109 | snapshot, |
| 110 | callbacks: { |
| 111 | onStream: streamConfig?.onStream, |
| 112 | onBlockStart: streamConfig?.onBlockStart |
| 113 | ? async ( |
| 114 | blockId: string, |
| 115 | blockName: string, |
| 116 | blockType: string, |
| 117 | executionOrder: number |
| 118 | ) => { |
no test coverage detected