@@ -2,7 +2,7 @@ import { createLogger } from '@sim/logger'
22import { type NextRequest , NextResponse } from 'next/server'
33import { validate as uuidValidate , v4 as uuidv4 } from 'uuid'
44import { z } from 'zod'
5- import { AuthType , checkHybridAuth } from '@/lib/auth/hybrid'
5+ import { AuthType , checkHybridAuth , hasExternalApiCredentials } from '@/lib/auth/hybrid'
66import { admissionRejectedResponse , tryAdmit } from '@/lib/core/admission/gate'
77import { getJobQueue , shouldExecuteInline , shouldUseBullMQ } from '@/lib/core/async-jobs'
88import { createBullMQJobData } from '@/lib/core/bullmq'
@@ -326,6 +326,10 @@ async function enqueueDirectWorkflowExecution(
326326 * Supports both SSE streaming (for interactive/manual runs) and direct JSON responses (for background jobs).
327327 */
328328export async function POST ( req : NextRequest , { params } : { params : Promise < { id : string } > } ) {
329+ if ( ! hasExternalApiCredentials ( req . headers ) ) {
330+ return handleExecutePost ( req , params )
331+ }
332+
329333 const ticket = tryAdmit ( )
330334 if ( ! ticket ) {
331335 return admissionRejectedResponse ( )
@@ -784,7 +788,7 @@ async function handleExecutePost(
784788
785789 const executionVariables = cachedWorkflowData ?. variables ?? workflow . variables ?? { }
786790
787- if ( shouldUseBullMQ ( ) ) {
791+ if ( shouldUseBullMQ ( ) && triggerType !== 'manual' ) {
788792 try {
789793 const dispatchJobId = await enqueueDirectWorkflowExecution (
790794 {
@@ -799,7 +803,7 @@ async function handleExecutePost(
799803 timeoutMs : preprocessResult . executionTimeout ?. sync ,
800804 runFromBlock : resolvedRunFromBlock ,
801805 } ,
802- triggerType === 'manual' ? 1 : 5 ,
806+ 5 ,
803807 'interactive'
804808 )
805809
@@ -973,7 +977,8 @@ async function handleExecutePost(
973977 }
974978
975979 if ( shouldUseDraftState ) {
976- if ( shouldUseBullMQ ( ) ) {
980+ const useDispatchForManual = shouldUseBullMQ ( ) && triggerType !== 'manual'
981+ if ( useDispatchForManual ) {
977982 const metadata : ExecutionMetadata = {
978983 requestId,
979984 executionId,
0 commit comments