/** * APIClaw Chain Executor * * Orchestrates multi-step API chains with: * - Sequential execution * - Parallel batches * - Conditional branching * - ForEach loops * - Error handling and retry * - Full execution trace */ import type { ChainStep, ChainStepUnion } from './chainResolver.js'; export interface ChainDefinition { id?: string; name?: string; description?: string; steps: ChainStepUnion[]; inputs?: Record; errorPolicy?: ErrorPolicy; limits?: ChainLimits; timeout?: number; } export interface InputDefinition { type: 'string' | 'number' | 'boolean' | 'array' | 'object'; required?: boolean; default?: any; description?: string; } export interface ErrorPolicy { mode: 'fail-fast' | 'best-effort' | 'transactional'; rollback?: RollbackStep[]; } export interface RollbackStep { if: string; do: ChainStep; } export interface ChainLimits { maxSteps?: number; maxParallel?: number; maxCost?: { cents: number; }; } export interface Credentials { userId?: string; customerKeys?: Record; } export interface ChainOptions { dryRun?: boolean; verbose?: boolean; onStepComplete?: (step: StepTrace) => void; onStepStart?: (stepId: string, stepIndex: number) => void; /** Caller-owned key for the whole chain. Each provider attempt derives a stable child key. */ operationKey?: string; executeCall?: (provider: string, action: string, params: Record, operation: { idempotencyKey?: string; stepId: string; attempt: number; }) => Promise<{ success: boolean; data?: any; error?: string; code?: string; outcomeUnknown?: boolean; retryable?: boolean; idempotencyKey?: string; requestId?: string; cost?: number; }>; } export declare function deriveChainStepIdempotencyKey(operationKey: string, stepId: string, attempt: number): string; export interface ChainResult { success: boolean; chainId: string; startedAt: string; completedAt: string; totalLatencyMs: number; totalCost: { cents: number; }; finalResult?: any; results: Record; error?: ChainError; completedSteps: string[]; failedStep?: StepTrace; trace: StepTrace[]; canResume: boolean; resumeToken?: string; } export interface ChainError { stepId: string; code: string; message: string; retryAfter?: number; } export interface StepTrace { stepId: string; stepIndex: number; provider: string; action: string; startedAt: string; completedAt: string; latencyMs: number; success: boolean; input: Record; output?: any; error?: string; errorCode?: string; cost?: { cents: number; }; retries?: number; idempotencyKey?: string; requestId?: string; } /** * Execute a chain of API calls */ export declare function executeChain(chain: ChainDefinition, credentials: Credentials, inputs?: Record, options?: ChainOptions): Promise; export declare class StepError extends Error { code: string; retryAfter?: number; nonRepeatable: boolean; idempotencyKey?: string; requestId?: string; constructor(message: string, code: string, retryAfter?: number, options?: { nonRepeatable?: boolean; idempotencyKey?: string; requestId?: string; }); } export declare class TimeoutError extends Error { code: string; constructor(message: string); } /** * Get status of a running or completed chain */ export declare function getChainStatus(chainId: string): Promise<{ chainId: string; status: 'running' | 'completed' | 'failed' | 'not_found'; result?: ChainResult; }>; /** * Resume a failed chain from a resume token */ export declare function resumeChain(resumeToken: string, chain: ChainDefinition, credentials: Credentials, inputs?: Record, overrides?: Record>, options?: ChainOptions): Promise; export type { ChainContext, ChainStep, ChainStepUnion, } from './chainResolver.js'; export { resolveReferences, validateReferences, evaluateCondition, } from './chainResolver.js'; //# sourceMappingURL=chainExecutor.d.ts.map