export declare const stateMachinePackage = "@runx/state-machine"; export type StepStatus = "pending" | "admitted" | "running" | "succeeded" | "failed"; export type ChainStatus = "pending" | "running" | "succeeded" | "failed"; export type ChainStepStatus = "pending" | "running" | "succeeded" | "failed"; export type FanoutSyncStrategy = "all" | "any" | "quorum"; export type FanoutBranchFailurePolicy = "halt" | "continue"; export type FanoutGateAction = "pause" | "escalate"; export interface SingleStepState { readonly stepId: string; readonly status: StepStatus; readonly startedAt?: string; readonly completedAt?: string; readonly error?: string; } export interface SequentialChainStepDefinition { readonly id: string; readonly contextFrom?: readonly string[]; readonly retry?: { readonly maxAttempts: number; }; readonly fanoutGroup?: string; } export interface FanoutThresholdGate { readonly step: string; readonly field: string; readonly above: number; readonly action: FanoutGateAction; } export interface FanoutConflictGate { readonly field: string; readonly steps: readonly string[]; readonly action: FanoutGateAction; } export interface FanoutGroupPolicy { readonly groupId: string; readonly strategy: FanoutSyncStrategy; readonly minSuccess?: number; readonly onBranchFailure: FanoutBranchFailurePolicy; readonly thresholdGates?: readonly FanoutThresholdGate[]; readonly conflictGates?: readonly FanoutConflictGate[]; } export interface FanoutBranchResult { readonly stepId: string; readonly status: ChainStepStatus; readonly outputs?: Readonly>; } export interface FanoutSyncDecision { readonly groupId: string; readonly decision: "proceed" | "halt" | "pause" | "escalate"; readonly strategy: FanoutSyncStrategy; readonly ruleFired: string; readonly reason: string; readonly branchCount: number; readonly successCount: number; readonly failureCount: number; readonly requiredSuccesses: number; readonly gate?: { readonly type: "threshold" | "conflict"; readonly stepId?: string; readonly field: string; readonly value?: unknown; readonly comparedTo?: number; readonly values?: Readonly>; readonly action: FanoutGateAction; }; } export interface SequentialChainStepState { readonly stepId: string; readonly status: ChainStepStatus; readonly attempts: number; readonly startedAt?: string; readonly completedAt?: string; readonly receiptId?: string; readonly outputs?: Readonly>; readonly error?: string; } export interface SequentialChainState { readonly chainId: string; readonly status: ChainStatus; readonly steps: readonly SequentialChainStepState[]; } export type SequentialChainEvent = { readonly type: "start_step"; readonly stepId: string; readonly at: string; } | { readonly type: "step_succeeded"; readonly stepId: string; readonly at: string; readonly receiptId: string; readonly outputs?: Readonly>; } | { readonly type: "step_failed"; readonly stepId: string; readonly at: string; readonly error: string; } | { readonly type: "complete"; } | { readonly type: "fail_chain"; readonly error: string; }; export type SequentialChainPlan = { readonly type: "run_step"; readonly stepId: string; readonly attempt: number; readonly contextFrom: readonly string[]; } | { readonly type: "run_fanout"; readonly groupId: string; readonly stepIds: readonly string[]; readonly attempts: Readonly>; readonly contextFrom: Readonly>; } | { readonly type: "complete"; } | { readonly type: "failed"; readonly stepId: string; readonly reason: string; readonly syncDecision?: FanoutSyncDecision; } | { readonly type: "blocked"; readonly stepId: string; readonly reason: string; readonly syncDecision?: FanoutSyncDecision; }; export type SingleStepEvent = { readonly type: "admit"; } | { readonly type: "start"; readonly at: string; } | { readonly type: "succeed"; readonly at: string; } | { readonly type: "fail"; readonly at: string; readonly error: string; }; export declare function createSingleStepState(stepId: string): SingleStepState; export declare function transitionSingleStep(state: SingleStepState, event: SingleStepEvent): SingleStepState; export declare function createSequentialChainState(chainId: string, steps: readonly SequentialChainStepDefinition[]): SequentialChainState; export declare function planSequentialChainTransition(state: SequentialChainState, steps: readonly SequentialChainStepDefinition[], fanoutPolicies?: Readonly>): SequentialChainPlan; export declare function transitionSequentialChain(state: SequentialChainState, event: SequentialChainEvent): SequentialChainState; export declare function evaluateFanoutSync(policy: FanoutGroupPolicy, results: readonly FanoutBranchResult[]): FanoutSyncDecision;