/**
 * Operation Checkpoint Transformer
 *
 * Transforms expensive operations (API calls, LLM calls, etc.) to wrap them
 * with checkpoint logic for recovery from failures.
 *
 * Transforms:
 *   const user = await atp.api.github.getUser({ id: 123 });
 *
 * Into:
 *   const user = await __checkpoint.wrap(
 *     'op_L15_C8',
 *     async () => atp.api.github.getUser({ id: 123 }),
 *     { type: 'api', namespace: 'atp', group: 'api.github', method: 'getUser', params: { id: 123 } }
 *   );
 */
import * as t from '@babel/types';
import type { OperationType } from '../checkpoint/checkpoint-types.js';
/**
 * Patterns for operations that should be checkpointed
 */
export interface CheckpointablePattern {
    /** Namespace prefix to match (e.g., 'atp.api', 'atp.llm') */
    namespacePrefix: string;
    /** Operation type for metadata */
    operationType: OperationType;
}
/**
 * Default patterns for checkpointable operations
 *
 */
export declare const CHECKPOINTABLE_PATTERNS: CheckpointablePattern[];
/**
 * Result of transforming an operation
 */
export interface CheckpointTransformResult {
    /** Number of operations transformed */
    transformCount: number;
    /** List of checkpoint IDs generated */
    checkpointIds: string[];
}
/**
 * Transformer that wraps expensive operations with checkpoint logic
 */
export declare class OperationCheckpointTransformer {
    private transformCount;
    private checkpointIds;
    private patterns;
    /** Track loop locations that have been checkpointed (to skip individual ops inside) */
    private checkpointedLoopLocations;
    /** Track Promise.all locations that have been checkpointed (to skip individual ops inside) */
    private checkpointedPromiseAllLocations;
    constructor(patterns?: CheckpointablePattern[]);
    /**
     * Transform a top-level Promise.all to checkpoint its result
     * Only transforms Promise.all that are NOT nested inside loops or other Promise.all
     * @returns true if transformation was applied
     */
    transformTopLevelPromiseAll(path: any): boolean;
    /**
     * Transform a top-level loop to checkpoint its accumulated result
     * Only transforms loops that are NOT nested inside other loops
     * Inserts checkpoint AFTER the loop completes
     * @returns true if transformation was applied
     */
    transformTopLevelLoop(path: any): boolean;
    /**
     * Check if path is inside a loop or Promise.all (for Promise.all nesting detection)
     */
    private isInsideLoopOrPromiseAll;
    /**
     * Check if path is inside a loop that has been checkpointed
     */
    private isInsideCheckpointedLoop;
    /**
     * Check if path is inside a loop (for loop nesting detection)
     */
    private isInsideLoop;
    /**
     * Check if a loop contains checkpointable operations
     * This includes direct API/LLM calls AND Promise.all containing such calls
     */
    private loopContainsCheckpointableOps;
    /**
     * Find accumulator variables in a loop
     * These are arrays that are pushed to or variables that are assigned
     */
    private findLoopAccumulators;
    /**
     * Check if call expression is Promise.all
     */
    private isPromiseAllCall;
    /**
     * Find the variable names that a Promise.all result is assigned to
     * Handles both regular assignment and destructuring:
     *   const results = await Promise.all(...) -> ['results']
     *   const [a, b] = await Promise.all(...) -> ['a', 'b']
     */
    private findPromiseAllResultVariables;
    /**
     * Find the variable names that an await expression result is assigned to
     * Handles both regular assignment and destructuring:
     *   const result = await api.call(...) -> ['result']
     *   const [a, b] = await Promise.all(...) -> ['a', 'b']
     *   const { data, error } = await api.call(...) -> ['data', 'error']
     */
    private findResultVariables;
    /**
     * Find all API calls used within a loop or Promise.all
     * Returns array of API paths like ['api.slack.conversations_list', 'api.slack.users_info']
     */
    private findUsedAPIs;
    /**
     * Generate checkpoint ID for loops
     */
    private generateLoopCheckpointId;
    /**
     * Transform an await expression if it's a checkpointable operation
     * Skips operations inside top-level loops/Promise.all that are already checkpointed
     * @returns true if transformation was applied
     */
    transformAwaitExpression(path: any): boolean;
    /**
     * Find matching checkpointable pattern for a path
     */
    private findMatchingPattern;
    /**
     * Generate a deterministic checkpoint ID based on AST location
     */
    private generateCheckpointId;
    /**
     * Extract operation metadata from the call expression
     */
    private extractMetadata;
    /**
     * Extract params from call arguments
     * If it's a simple object, clone it. Otherwise, use empty object.
     */
    private extractParams;
    /**
     * Create an IIFE that buffers checkpoint after execution (no auto-restore)
     * This avoids passing functions across the isolated-vm boundary
     *
     * Generates:
     *   (async () => {
     *     const __result = await originalCall;
     *     __checkpoint.buffer('id', __result, metadata);
     *     return __result;
     *   })()
     *
     * Note: Checkpoints are buffered in memory (synchronously), not persisted immediately.
     * They are only persisted to cache when an error occurs (via flush()).
     * Auto-restore was removed to avoid conflicts with the LLM pause/resume mechanism.
     */
    private createCheckpointWrap;
    /**
     * Check if this path is inside a checkpoint wrapper IIFE
     * This prevents nested transformations when already-transformed code is re-processed
     */
    private isInsideCheckpointWrapper;
    /**
     * Check if an await expression is a checkpointable operation
     */
    isCheckpointable(node: t.AwaitExpression): boolean;
    /**
     * Get the number of transformations applied
     */
    getTransformCount(): number;
    /**
     * Get the list of checkpoint IDs generated
     */
    getCheckpointIds(): string[];
    /**
     * Reset transformer state
     */
    reset(): void;
    /**
     * Get transformation result
     */
    getResult(): CheckpointTransformResult;
}
/**
 * Utility: Check if a full path matches checkpointable patterns
 */
export declare function isCheckpointableCall(fullPath: string, patterns?: CheckpointablePattern[]): boolean;
/**
 * Utility: Get operation type for a path
 */
export declare function getOperationType(fullPath: string, patterns?: CheckpointablePattern[]): OperationType | null;
//# sourceMappingURL=checkpoint-transformer.d.ts.map