Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/sim/app/api/workflows/[id]/execute/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,8 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
const onChildWorkflowInstanceReady = (
blockId: string,
childWorkflowInstanceId: string,
iterationContext?: IterationContext
iterationContext?: IterationContext,
executionOrder?: number
) => {
sendEvent({
type: 'block:childWorkflowStarted',
Expand All @@ -1001,6 +1002,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
iterationCurrent: iterationContext.iterationCurrent,
iterationContainerId: iterationContext.iterationContainerId,
}),
...(executionOrder !== undefined && { executionOrder }),
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ export function useWorkflowExecution() {
childWorkflowInstanceId: string
iterationCurrent?: number
iterationContainerId?: string
executionOrder?: number
}) => {
if (isStaleExecution()) return
updateConsole(
Expand All @@ -564,6 +565,7 @@ export function useWorkflowExecution() {
...(data.iterationContainerId !== undefined && {
iterationContainerId: data.iterationContainerId,
}),
...(data.executionOrder !== undefined && { executionOrder: data.executionOrder }),
},
executionIdRef.current
)
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/executor/execution/block-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export class BlockExecutor {
const startTime = performance.now()
let resolvedInputs: Record<string, any> = {}

const nodeMetadata = this.buildNodeMetadata(node)
const nodeMetadata = {
...this.buildNodeMetadata(node),
executionOrder: blockLog?.executionOrder,
}
let cleanupSelfReference: (() => void) | undefined

if (block.metadata?.id === BlockType.HUMAN_IN_THE_LOOP) {
Expand Down
6 changes: 4 additions & 2 deletions apps/sim/executor/execution/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export interface ExecutionCallbacks {
onChildWorkflowInstanceReady?: (
blockId: string,
childWorkflowInstanceId: string,
iterationContext?: IterationContext
iterationContext?: IterationContext,
executionOrder?: number
) => void
}

Expand Down Expand Up @@ -155,7 +156,8 @@ export interface ContextExtensions {
onChildWorkflowInstanceReady?: (
blockId: string,
childWorkflowInstanceId: string,
iterationContext?: IterationContext
iterationContext?: IterationContext,
executionOrder?: number
) => void

/**
Expand Down
9 changes: 8 additions & 1 deletion apps/sim/executor/handlers/workflow/workflow-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class WorkflowBlockHandler implements BlockHandler {
branchTotal?: number
originalBlockId?: string
isLoopNode?: boolean
executionOrder?: number
}
): Promise<BlockOutput | StreamingExecution> {
return this._executeCore(ctx, block, inputs, nodeMetadata)
Expand All @@ -79,6 +80,7 @@ export class WorkflowBlockHandler implements BlockHandler {
branchTotal?: number
originalBlockId?: string
isLoopNode?: boolean
executionOrder?: number
}
): Promise<BlockOutput | StreamingExecution> {
logger.info(`Executing workflow block: ${block.id}`)
Expand Down Expand Up @@ -169,7 +171,12 @@ export class WorkflowBlockHandler implements BlockHandler {
const iterationContext = nodeMetadata
? this.getIterationContext(ctx, nodeMetadata)
: undefined
ctx.onChildWorkflowInstanceReady?.(effectiveBlockId, instanceId, iterationContext)
ctx.onChildWorkflowInstanceReady?.(
effectiveBlockId,
instanceId,
iterationContext,
nodeMetadata?.executionOrder
)
}

const subExecutor = new Executor({
Expand Down
4 changes: 3 additions & 1 deletion apps/sim/executor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ export interface ExecutionContext {
onChildWorkflowInstanceReady?: (
blockId: string,
childWorkflowInstanceId: string,
iterationContext?: IterationContext
iterationContext?: IterationContext,
executionOrder?: number
) => void

/**
Expand Down Expand Up @@ -377,6 +378,7 @@ export interface BlockHandler {
branchTotal?: number
originalBlockId?: string
isLoopNode?: boolean
executionOrder?: number
}
) => Promise<BlockOutput | StreamingExecution>
}
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/lib/workflows/executor/execution-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export interface BlockChildWorkflowStartedEvent extends BaseExecutionEvent {
childWorkflowInstanceId: string
iterationCurrent?: number
iterationContainerId?: string
executionOrder?: number
}
}

Expand Down Expand Up @@ -396,7 +397,8 @@ export function createSSECallbacks(options: SSECallbackOptions) {
const onChildWorkflowInstanceReady = (
blockId: string,
childWorkflowInstanceId: string,
iterationContext?: IterationContext
iterationContext?: IterationContext,
executionOrder?: number
) => {
sendEvent({
type: 'block:childWorkflowStarted',
Expand All @@ -410,6 +412,7 @@ export function createSSECallbacks(options: SSECallbackOptions) {
iterationCurrent: iterationContext.iterationCurrent,
iterationContainerId: iterationContext.iterationContainerId,
}),
...(executionOrder !== undefined && { executionOrder }),
},
})
}
Expand Down