Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -160,12 +160,16 @@ const IterationNodeRow = memo(function IterationNodeRow({
onSelectEntry,
isExpanded,
onToggle,
expandedNodes,
onToggleNode,
}: {
node: EntryNode
selectedEntryId: string | null
onSelectEntry: (entry: ConsoleEntry) => void
isExpanded: boolean
onToggle: () => void
expandedNodes: Set<string>
onToggleNode: (nodeId: string) => void
}) {
const { entry, children, iterationInfo } = node
const hasError = Boolean(entry.error) || children.some((c) => c.entry.error)
Expand Down Expand Up @@ -226,11 +230,13 @@ const IterationNodeRow = memo(function IterationNodeRow({
{isExpanded && hasChildren && (
<div className={ROW_STYLES.nested}>
{children.map((child) => (
<BlockRow
<EntryNodeRow
key={child.entry.id}
entry={child.entry}
isSelected={selectedEntryId === child.entry.id}
onSelect={onSelectEntry}
node={child}
selectedEntryId={selectedEntryId}
onSelectEntry={onSelectEntry}
expandedNodes={expandedNodes}
onToggleNode={onToggleNode}
/>
))}
</div>
Expand Down Expand Up @@ -346,6 +352,8 @@ const SubflowNodeRow = memo(function SubflowNodeRow({
onSelectEntry={onSelectEntry}
isExpanded={expandedNodes.has(iterNode.entry.id)}
onToggle={() => onToggleNode(iterNode.entry.id)}
expandedNodes={expandedNodes}
onToggleNode={onToggleNode}
/>
))}
</div>
Expand Down Expand Up @@ -520,6 +528,8 @@ const EntryNodeRow = memo(function EntryNodeRow({
onSelectEntry={onSelectEntry}
isExpanded={expandedNodes.has(node.entry.id)}
onToggle={() => onToggleNode(node.entry.id)}
expandedNodes={expandedNodes}
onToggleNode={onToggleNode}
/>
)
}
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
7 changes: 7 additions & 0 deletions apps/sim/stores/terminal/console/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ const matchesEntryForUpdate = (
return false
}

if (
update.childWorkflowBlockId !== undefined &&
entry.childWorkflowBlockId !== update.childWorkflowBlockId
) {
return false
}

return true
}

Expand Down