diff --git a/apps/sim/app/api/workflows/[id]/execute-from-block/route.ts b/apps/sim/app/api/workflows/[id]/execute-from-block/route.ts index 88b0521f2..647012589 100644 --- a/apps/sim/app/api/workflows/[id]/execute-from-block/route.ts +++ b/apps/sim/app/api/workflows/[id]/execute-from-block/route.ts @@ -33,6 +33,7 @@ const ExecuteFromBlockSchema = z.object({ parallelBlockMapping: z.record(z.any()).optional(), activeExecutionPath: z.array(z.string()), }), + input: z.any().optional(), }) export const runtime = 'nodejs' @@ -71,7 +72,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id: ) } - const { startBlockId, sourceSnapshot } = validation.data + const { startBlockId, sourceSnapshot, input } = validation.data const executionId = uuidv4() const [workflowRecord] = await db @@ -122,7 +123,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id: startTime: new Date().toISOString(), } - const snapshot = new ExecutionSnapshot(metadata, {}, {}, {}) + const snapshot = new ExecutionSnapshot(metadata, {}, input || {}, {}) try { const startTime = new Date() diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts index 7fd40b775..ec37906fa 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts @@ -1469,10 +1469,45 @@ export function useWorkflowExecution() { activeExecutionPath: [], } + // Extract mock payload for trigger blocks + let workflowInput: any + if (isTriggerBlock) { + const workflowBlocks = useWorkflowStore.getState().blocks + const mergedStates = mergeSubblockState(workflowBlocks, workflowId) + const candidates = resolveStartCandidates(mergedStates, { execution: 'manual' }) + const candidate = candidates.find((c) => c.blockId === blockId) + + if (candidate) { + if (triggerNeedsMockPayload(candidate)) { + workflowInput = extractTriggerMockPayload(candidate) + logger.info('Extracted mock payload for trigger block', { blockId, workflowInput }) + } else if ( + candidate.path === StartBlockPath.SPLIT_API || + candidate.path === StartBlockPath.SPLIT_INPUT || + candidate.path === StartBlockPath.UNIFIED + ) { + const inputFormatValue = candidate.block.subBlocks?.inputFormat?.value + if (Array.isArray(inputFormatValue)) { + const testInput: Record = {} + inputFormatValue.forEach((field: any) => { + if (field && typeof field === 'object' && field.name && field.value !== undefined) { + testInput[field.name] = coerceValue(field.type, field.value) + } + }) + if (Object.keys(testInput).length > 0) { + workflowInput = testInput + logger.info('Extracted test input for trigger block', { blockId, workflowInput }) + } + } + } + } + } + logger.info('Starting run-from-block execution', { workflowId, startBlockId: blockId, isTriggerBlock, + hasInput: !!workflowInput, }) setIsExecuting(true) @@ -1487,6 +1522,7 @@ export function useWorkflowExecution() { workflowId, startBlockId: blockId, sourceSnapshot: effectiveSnapshot, + input: workflowInput, callbacks: { onExecutionStarted: (data) => { logger.info('Run-from-block execution started:', data) diff --git a/apps/sim/hooks/use-execution-stream.ts b/apps/sim/hooks/use-execution-stream.ts index 0273165e4..08ca7164d 100644 --- a/apps/sim/hooks/use-execution-stream.ts +++ b/apps/sim/hooks/use-execution-stream.ts @@ -151,6 +151,7 @@ export interface ExecuteFromBlockOptions { workflowId: string startBlockId: string sourceSnapshot: SerializableExecutionState + input?: any callbacks?: ExecutionStreamCallbacks } @@ -222,7 +223,7 @@ export function useExecutionStream() { }, []) const executeFromBlock = useCallback(async (options: ExecuteFromBlockOptions) => { - const { workflowId, startBlockId, sourceSnapshot, callbacks = {} } = options + const { workflowId, startBlockId, sourceSnapshot, input, callbacks = {} } = options if (abortControllerRef.current) { abortControllerRef.current.abort() @@ -238,7 +239,7 @@ export function useExecutionStream() { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ startBlockId, sourceSnapshot }), + body: JSON.stringify({ startBlockId, sourceSnapshot, input }), signal: abortController.signal, })