/** * Replay Executor - Core execution engine for command sequences */ import type { CommandRecorder, RecordedCommand, CommandSequence, ActiveSequenceState } from '../command-recorder.js'; import { ClickValidationConfig } from '../config.js'; export { injectReplayCursor, showClickEffect, showKeyPress, removeReplayCursor } from '../replay-cursor.js'; interface ReplayCursorCallbacks { onClickBefore?: (x: number, y: number, isRightClick: boolean) => Promise; onKeyPress?: (key: string) => Promise; } export declare function setReplayCursorCallbacks(callbacks: ReplayCursorCallbacks): void; export interface ExecutionContext { executeToolCall: (toolName: string, params: Record) => Promise; commandRecorder: CommandRecorder; connectionReason: string; logPrefix?: string; /** Current nesting depth for conditional commands (used for recursion protection) */ conditionalDepth?: number; /** Call stack of sequence names for circular reference detection */ conditionalCallStack?: string[]; } export interface StepResult { step: number; tool: string; success: boolean; error?: string; substeps?: StepResult[]; sequenceName?: string; conditionMet?: boolean; } export interface BreakpointHitInfo { url: string; lineNumber: number; columnNumber?: number; functionName?: string; } export interface ClickValidationFailure { step: number; selector: string; errors: string[]; warnings: string[]; info: string[]; } export interface ExecutionResult { results: StepResult[]; totalCommands: number; durationMs: number; pausedAtStep?: number; activeSequenceState?: ActiveSequenceState; breakpointHit?: BreakpointHitInfo; /** Click validation failure - sequence paused for inspection/retry */ clickValidationFailure?: ClickValidationFailure; } export interface ConnectionAnalysis { launchChromeIndex: number; firstConnectionToolIndex: number; hasLaunchBeforeConnection: boolean; } export declare const TOOLS_NEEDING_CONNECTION: string[]; /** * Result of condition evaluation * - met: true - condition matched * - met: false, isError: undefined - condition legitimately not met * - met: false, isError: true - evaluation FAILED (should stop sequence) */ export type ConditionResult = { met: true; } | { met: false; reason?: string; } | { met: false; reason: string; isError: true; }; /** * Evaluate a handlebar-style condition * Supported patterns: * {{selector:CSS_SELECTOR}} - true if element exists * {{!selector:CSS_SELECTOR}} - true if element does NOT exist * {{url:contains:STRING}} - true if URL contains string * {{url:matches:REGEX}} - true if URL matches regex * {{cookie:NAME}} - true if cookie exists * {{!cookie:NAME}} - true if cookie does NOT exist * {{localStorage:KEY}} - true if localStorage key exists * {{!localStorage:KEY}} - true if localStorage key does NOT exist */ export declare function evaluateCondition(condition: string, ctx: ExecutionContext): Promise; export interface ConditionalFlowResult { success: boolean; executed: boolean; sequenceName: string; substeps?: StepResult[]; error?: string; durationMs?: number; } /** * Execute a conditional flow - runs a sequence if condition is met */ export declare function executeConditionalFlow(condition: string, sequenceName: string, ctx: ExecutionContext, recorder: CommandRecorder): Promise; export interface LoadSequenceArgs { name?: string; sequenceId?: string; } export type LoadSequenceResult = { success: true; sequence: CommandSequence; } | { success: false; error: string; errorCode: string; /** Template variables for error response (e.g., action, missing for MISSING_PARAMETER) */ templateVars?: Record; }; /** * Load a sequence from memory (by sequenceId) or disk (by name) */ export declare function loadSequence(args: LoadSequenceArgs, recorder: CommandRecorder): Promise; /** * Analyze sequence commands to find launchChrome and determine connection requirements */ export declare function analyzeSequenceConnections(commands: RecordedCommand[]): ConnectionAnalysis; /** * Extract connectionReason from sequence's launchChrome command if present */ export declare function extractConnectionFromSequence(commands: RecordedCommand[], analysis: ConnectionAnalysis): string | undefined; /** * Check if sequence needs a connection */ export declare function sequenceNeedsConnection(commands: RecordedCommand[]): boolean; /** * Check if debugger is paused and return breakpoint info if so */ export declare function checkIfPaused(ctx: ExecutionContext): Promise; /** * Check if debugger is paused and auto-resume if so */ export declare function resumeIfPaused(ctx: ExecutionContext): Promise; export type AutoLaunchResult = { success: true; } | { success: false; error: string; errorType: 'INVALID_REFERENCE' | 'LAUNCH_FAILED'; }; /** * Validate reference and auto-launch Chrome if needed. * This is the shared helper for all auto-launch scenarios. */ export declare function autoLaunchChrome(executeToolCall: (toolName: string, params: Record) => Promise, connectionReason: string, logPrefix?: string): Promise; /** * Ensure a connection is available, auto-launching Chrome if needed */ export declare function ensureConnection(ctx: ExecutionContext, needsConnection: boolean, hasLaunchBeforeConnection: boolean): Promise<{ success: true; didAutoLaunch: boolean; } | { success: false; error: string; }>; /** * Check if a URL's port is open (for localhost URLs only) * Returns success if port is open or URL is not localhost */ export declare function checkPortBeforeNavigation(url: string, logPrefix?: string): Promise<{ success: true; } | { success: false; error: string; }>; /** * Navigate to startUrl if sequence has one and doesn't start with navigate */ export declare function navigateToStartUrl(ctx: ExecutionContext, sequence: CommandSequence, analysis: ConnectionAnalysis): Promise<{ success: true; } | { success: false; error: string; }>; /** * Execute a single command with retry logic for element not found errors */ export declare function executeCommandWithRetry(executeToolCall: (toolName: string, params: Record) => Promise, tool: string, params: Record, logPrefix?: string): Promise<{ success: boolean; result?: any; error?: string; }>; /** * Validate that navigation succeeded (page loaded correctly) */ export declare function validateNavigation(ctx: ExecutionContext, expectedUrl?: string): Promise<{ success: boolean; error?: string; }>; /** * Wait for an element to appear */ export declare function waitForElement(ctx: ExecutionContext, selector: string): Promise; /** * Validate typed text was entered correctly */ export declare function validateTypedText(ctx: ExecutionContext, selector: string, expectedText: string, append?: boolean): Promise; export interface PreClickState { consoleErrorCount: number; consoleWarnCount: number; consoleTotalCount: number; networkRequestCount: number; url: string; } export interface ClickValidationResult { valid: boolean; errors: string[]; warnings: string[]; info: string[]; } /** * Capture pre-click state for delta comparison */ export declare function capturePreClickState(ctx: ExecutionContext): Promise; /** * Validate click action results */ export declare function validateClickAction(ctx: ExecutionContext, preState: PreClickState, clickResult: any, config: ClickValidationConfig): Promise; export interface ExecuteStepsOptions { sequence: CommandSequence; startStep: number; endStep?: number; ctx: ExecutionContext; variables?: Record; record?: boolean; stepTimeout?: number; totalTimeout?: number; overrideConnectionReason?: string; abortSignal?: AbortSignal; } /** * Execute a range of steps from a sequence */ export declare function executeSteps(options: ExecuteStepsOptions): Promise; /** * Execute a sequence with pause support (stepTo) */ export declare function executeSequenceWithPause(options: ExecuteStepsOptions & { stepTo?: number; }): Promise; export interface DebugState { isPaused: boolean; pauseLocation?: string; breakpointCount: number; } /** * Get current debug state (breakpoints, pause status) */ export declare function getDebugState(ctx: ExecutionContext): Promise; //# sourceMappingURL=replay-executor.d.ts.map