import { Value } from '../utils'; export interface ExecutionStepInfo { nodeKey: string; variables: Record; result: Value; timestamp: number; } export interface ExecutionLog { message: string; nodeKey?: string; /** Parent block key — which top-level block produced this log */ blockKey?: string; timestamp: number; source?: 'log' | 'say' | string; } /** * Flow event — emitted during execution to track all flow elements. * Used for n8n-style real-time progress in the UI. * * Types: * block — do/enddo block lifecycle * branch — if/elseif/else branch selection * loop — for loop iteration progress * parallel — together block parallel execution * call — user function (def) invocation * event — on/endon event trigger */ export interface BlockEvent { /** Unique AST node key for this node */ nodeKey: string; /** Flow element type */ type: 'block' | 'branch' | 'loop' | 'parallel' | 'call' | 'event'; /** Block index among top-level statements (0-based) */ index: number; /** Total number of top-level blocks in the script */ total: number; /** Description from @desc decorator, or null */ description: string | null; /** Lifecycle status */ status: 'start' | 'complete' | 'error' | 'iteration' | 'branch_taken' | 'branch_skipped' | 'paused' | 'cancelled' | 'progress'; /** Execution duration in ms (on complete/error) */ durationMs?: number; /** Return value (on complete) */ result?: Value; /** Error message (on error) */ error?: string; /** Timestamp */ timestamp: number; /** Current iteration index (0-based, for loops) */ iteration?: number; /** Total iterations if known (for range loops) */ iterationTotal?: number; /** Current item value (for loops) */ iterationValue?: Value; /** Which branch was taken: 'if', 'elseif', 'else', or condition index */ branch?: string; /** The condition expression (for display) */ condition?: string; /** Number of parallel branches */ parallelCount?: number; /** Index of this parallel branch */ parallelIndex?: number; /** Function name being called */ functionName?: string; /** Event name that was triggered */ eventName?: string; /** Variables state after this block completed */ variables?: Record; /** Log messages produced inside this block */ logs?: string[]; /** Execution steps inside this block (command name → result) */ steps?: Array<{ nodeKey: string; result: Value; }>; /** Current progress value (e.g. 50) */ progressCurrent?: number; /** Total progress value (e.g. 100) */ progressTotal?: number; /** Progress message */ progressMessage?: string; /** Unique execution run ID */ executionId?: string; /** Parent block key (for log attribution) */ blockKey?: string; /** Retry attempt number (1-based, only if @retry) */ attempt?: number; /** Max retry attempts (only if @retry) */ maxAttempts?: number; } export type LogCallback = (log: ExecutionLog) => void; export type BlockCallback = (event: BlockEvent) => void; export declare class ExecutionStateTracker { private steps; private logs; private nodeStates; private indexedStates; private onLog; private onBlock; setLogCallback(callback: LogCallback | null): void; setBlockCallback(callback: BlockCallback | null): void; addStep(step: ExecutionStepInfo): void; addLog(log: ExecutionLog): void; emitBlock(event: BlockEvent): void; getSteps(): ExecutionStepInfo[]; getLogs(): ExecutionLog[]; getNodeState(nodeKey: string): ExecutionStepInfo | undefined; getState(index: number): any; setState(index: number, state: any): void; clear(): void; }