@@ -49,126 +49,6 @@ const ExecuteWorkflowSchema = z.object({
4949export const runtime = 'nodejs'
5050export const dynamic = 'force-dynamic'
5151
52- /**
53- * Execute workflow with streaming support - used by chat and other streaming endpoints
54- *
55- * This function assumes preprocessing has already been completed.
56- * Callers must run preprocessExecution() first to validate workflow, check usage limits,
57- * and resolve actor before calling this function.
58- *
59- * This is a wrapper function that:
60- * - Supports streaming callbacks (onStream, onBlockComplete)
61- * - Returns ExecutionResult instead of NextResponse
62- * - Handles pause/resume logic
63- *
64- * Used by:
65- * - Chat execution (/api/chat/[identifier]/route.ts)
66- * - Streaming responses (lib/workflows/streaming.ts)
67- */
68- export async function executeWorkflow (
69- workflow : any ,
70- requestId : string ,
71- input : any | undefined ,
72- actorUserId : string ,
73- streamConfig ?: {
74- enabled : boolean
75- selectedOutputs ?: string [ ]
76- isSecureMode ?: boolean
77- workflowTriggerType ?: 'api' | 'chat'
78- onStream ?: ( streamingExec : any ) => Promise < void >
79- onBlockComplete ?: ( blockId : string , output : any ) => Promise < void >
80- skipLoggingComplete ?: boolean
81- } ,
82- providedExecutionId ?: string
83- ) : Promise < any > {
84- const workflowId = workflow . id
85- const executionId = providedExecutionId || uuidv4 ( )
86- const triggerType = streamConfig ?. workflowTriggerType || 'api'
87- const loggingSession = new LoggingSession ( workflowId , executionId , triggerType , requestId )
88-
89- try {
90- const metadata : ExecutionMetadata = {
91- requestId,
92- executionId,
93- workflowId,
94- workspaceId : workflow . workspaceId ,
95- userId : actorUserId ,
96- workflowUserId : workflow . userId ,
97- triggerType,
98- useDraftState : false ,
99- startTime : new Date ( ) . toISOString ( ) ,
100- isClientSession : false ,
101- }
102-
103- const snapshot = new ExecutionSnapshot (
104- metadata ,
105- workflow ,
106- input ,
107- workflow . variables || { } ,
108- streamConfig ?. selectedOutputs || [ ]
109- )
110-
111- const result = await executeWorkflowCore ( {
112- snapshot,
113- callbacks : {
114- onStream : streamConfig ?. onStream ,
115- onBlockComplete : streamConfig ?. onBlockComplete
116- ? async ( blockId : string , _blockName : string , _blockType : string , output : any ) => {
117- await streamConfig . onBlockComplete ! ( blockId , output )
118- }
119- : undefined ,
120- } ,
121- loggingSession,
122- } )
123-
124- if ( result . status === 'paused' ) {
125- if ( ! result . snapshotSeed ) {
126- logger . error ( `[${ requestId } ] Missing snapshot seed for paused execution` , {
127- executionId,
128- } )
129- } else {
130- await PauseResumeManager . persistPauseResult ( {
131- workflowId,
132- executionId,
133- pausePoints : result . pausePoints || [ ] ,
134- snapshotSeed : result . snapshotSeed ,
135- executorUserId : result . metadata ?. userId ,
136- } )
137- }
138- } else {
139- await PauseResumeManager . processQueuedResumes ( executionId )
140- }
141-
142- if ( streamConfig ?. skipLoggingComplete ) {
143- return {
144- ...result ,
145- _streamingMetadata : {
146- loggingSession,
147- processedInput : input ,
148- } ,
149- }
150- }
151-
152- return result
153- } catch ( error : any ) {
154- logger . error ( `[${ requestId } ] Workflow execution failed:` , error )
155- throw error
156- }
157- }
158-
159- export function createFilteredResult ( result : any ) {
160- return {
161- ...result ,
162- logs : undefined ,
163- metadata : result . metadata
164- ? {
165- ...result . metadata ,
166- workflowConnections : undefined ,
167- }
168- : undefined ,
169- }
170- }
171-
17252function resolveOutputIds (
17353 selectedOutputs : string [ ] | undefined ,
17454 blocks : Record < string , any >
@@ -606,7 +486,6 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
606486 isSecureMode : false ,
607487 workflowTriggerType : triggerType === 'chat' ? 'chat' : 'api' ,
608488 } ,
609- createFilteredResult,
610489 executionId,
611490 } )
612491
0 commit comments