Skip to content

Commit 6f66d33

Browse files
committed
Fix mock payload
1 parent 2f504ce commit 6f66d33

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

apps/sim/app/api/workflows/[id]/execute-from-block/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const ExecuteFromBlockSchema = z.object({
3333
parallelBlockMapping: z.record(z.any()).optional(),
3434
activeExecutionPath: z.array(z.string()),
3535
}),
36+
input: z.any().optional(),
3637
})
3738

3839
export const runtime = 'nodejs'
@@ -71,7 +72,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
7172
)
7273
}
7374

74-
const { startBlockId, sourceSnapshot } = validation.data
75+
const { startBlockId, sourceSnapshot, input } = validation.data
7576
const executionId = uuidv4()
7677

7778
const [workflowRecord] = await db
@@ -122,7 +123,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
122123
startTime: new Date().toISOString(),
123124
}
124125

125-
const snapshot = new ExecutionSnapshot(metadata, {}, {}, {})
126+
const snapshot = new ExecutionSnapshot(metadata, {}, input || {}, {})
126127

127128
try {
128129
const startTime = new Date()

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,10 +1469,45 @@ export function useWorkflowExecution() {
14691469
activeExecutionPath: [],
14701470
}
14711471

1472+
// Extract mock payload for trigger blocks
1473+
let workflowInput: any
1474+
if (isTriggerBlock) {
1475+
const workflowBlocks = useWorkflowStore.getState().blocks
1476+
const mergedStates = mergeSubblockState(workflowBlocks, workflowId)
1477+
const candidates = resolveStartCandidates(mergedStates, { execution: 'manual' })
1478+
const candidate = candidates.find((c) => c.blockId === blockId)
1479+
1480+
if (candidate) {
1481+
if (triggerNeedsMockPayload(candidate)) {
1482+
workflowInput = extractTriggerMockPayload(candidate)
1483+
logger.info('Extracted mock payload for trigger block', { blockId, workflowInput })
1484+
} else if (
1485+
candidate.path === StartBlockPath.SPLIT_API ||
1486+
candidate.path === StartBlockPath.SPLIT_INPUT ||
1487+
candidate.path === StartBlockPath.UNIFIED
1488+
) {
1489+
const inputFormatValue = candidate.block.subBlocks?.inputFormat?.value
1490+
if (Array.isArray(inputFormatValue)) {
1491+
const testInput: Record<string, any> = {}
1492+
inputFormatValue.forEach((field: any) => {
1493+
if (field && typeof field === 'object' && field.name && field.value !== undefined) {
1494+
testInput[field.name] = coerceValue(field.type, field.value)
1495+
}
1496+
})
1497+
if (Object.keys(testInput).length > 0) {
1498+
workflowInput = testInput
1499+
logger.info('Extracted test input for trigger block', { blockId, workflowInput })
1500+
}
1501+
}
1502+
}
1503+
}
1504+
}
1505+
14721506
logger.info('Starting run-from-block execution', {
14731507
workflowId,
14741508
startBlockId: blockId,
14751509
isTriggerBlock,
1510+
hasInput: !!workflowInput,
14761511
})
14771512

14781513
setIsExecuting(true)
@@ -1487,6 +1522,7 @@ export function useWorkflowExecution() {
14871522
workflowId,
14881523
startBlockId: blockId,
14891524
sourceSnapshot: effectiveSnapshot,
1525+
input: workflowInput,
14901526
callbacks: {
14911527
onExecutionStarted: (data) => {
14921528
logger.info('Run-from-block execution started:', data)

apps/sim/hooks/use-execution-stream.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export interface ExecuteFromBlockOptions {
151151
workflowId: string
152152
startBlockId: string
153153
sourceSnapshot: SerializableExecutionState
154+
input?: any
154155
callbacks?: ExecutionStreamCallbacks
155156
}
156157

@@ -222,7 +223,7 @@ export function useExecutionStream() {
222223
}, [])
223224

224225
const executeFromBlock = useCallback(async (options: ExecuteFromBlockOptions) => {
225-
const { workflowId, startBlockId, sourceSnapshot, callbacks = {} } = options
226+
const { workflowId, startBlockId, sourceSnapshot, input, callbacks = {} } = options
226227

227228
if (abortControllerRef.current) {
228229
abortControllerRef.current.abort()
@@ -238,7 +239,7 @@ export function useExecutionStream() {
238239
headers: {
239240
'Content-Type': 'application/json',
240241
},
241-
body: JSON.stringify({ startBlockId, sourceSnapshot }),
242+
body: JSON.stringify({ startBlockId, sourceSnapshot, input }),
242243
signal: abortController.signal,
243244
})
244245

0 commit comments

Comments
 (0)