import type { Edge } from 'reactflow' import type { BlockLog, BlockState } from '@/executor/types' export interface ExecutionMetadata { requestId: string executionId: string workflowId: string workspaceId?: string userId: string triggerType: string triggerBlockId?: string useDraftState: boolean startTime: string pendingBlocks?: string[] resumeFromSnapshot?: boolean workflowStateOverride?: { blocks: Record edges: Edge[] loops?: Record parallels?: Record } } export interface ExecutionCallbacks { onStream?: (streamingExec: any) => Promise onBlockStart?: (blockId: string, blockName: string, blockType: string) => Promise onBlockComplete?: ( blockId: string, blockName: string, blockType: string, output: any ) => Promise onExecutorCreated?: (executor: any) => void } export interface SerializableExecutionState { blockStates: Record executedBlocks: string[] blockLogs: BlockLog[] decisions: { router: Record condition: Record } completedLoops: string[] loopExecutions?: Record parallelExecutions?: Record parallelBlockMapping?: Record activeExecutionPath: string[] pendingQueue?: string[] remainingEdges?: Edge[] dagIncomingEdges?: Record completedPauseContexts?: string[] } export class ExecutionSnapshot { constructor( public readonly metadata: ExecutionMetadata, public readonly workflow: any, public readonly input: any, public readonly environmentVariables: Record, public readonly workflowVariables: Record, public readonly selectedOutputs: string[] = [], public readonly state?: SerializableExecutionState ) {} toJSON(): string { return JSON.stringify({ metadata: this.metadata, workflow: this.workflow, input: this.input, environmentVariables: this.environmentVariables, workflowVariables: this.workflowVariables, selectedOutputs: this.selectedOutputs, state: this.state, }) } static fromJSON(json: string): ExecutionSnapshot { const data = JSON.parse(json) return new ExecutionSnapshot( data.metadata, data.workflow, data.input, data.environmentVariables, data.workflowVariables, data.selectedOutputs, data.state ) } }