import type { ActionArgs, ActionFunction, EventObject, MachineContext, MachineEvent, MachineSnapshot, ResolvedMachineImplementations } from "../types/index.js"; import type { MachineModel, MachineState, ModelGuard, Transition } from "./model.js"; /** A custom (named or inline) action handed to the executor. The executor calls `exec(args, params)`. */ export interface ExecutableCustomAction { /** Action name, `fn.name` or `"(anonymous)"`. */ readonly type: string; readonly exec: ActionFunction, unknown>; /** `{ context, event }` with the context as of this action (earlier assigns applied). */ readonly args: ActionArgs>; readonly params: unknown; } export interface ScheduleRequest { readonly event: MachineEvent; /** Milliseconds, already resolved (named delays and delay functions applied). */ readonly delay: number; /** `raise` / `after` id for `cancel`; `undefined` means "not cancellable by id". */ readonly id: string | undefined; } /** * Side-effect boundary of the core. The engine (`Statechart`) implements it; * unit tests use a recording executor. */ export interface ActionExecutor { custom(action: ExecutableCustomAction): void; /** Delayed `raise` (including `after`). */ schedule(request: ScheduleRequest): void; /** `cancel(id)` builtin and the synthesized `after` cancels. */ cancel(id: string): void; /** `log` builtin; `label` is `undefined` when absent. */ log(value: unknown, label: string | undefined): void; } export interface InterpreterScope { readonly implementations: ResolvedMachineImplementations; readonly executor: ActionExecutor; /** Throws `Error("Infinite loop detected: ...")` when a macrostep exceeds it. */ readonly maxMicrosteps: number; } export interface StepResult { /** The same object as the input state when nothing changed. */ readonly state: MachineState; } /** * XState `evaluateGuard`: names resolve through `implementations.guards` * (recursively — an implementation may itself be a builtin), `{ type, params }` * resolves dynamic params, builtins `and` / `or` / `not` / `stateIn` are * evaluated structurally. Throws `Error("Guard '' is not implemented.")`. */ export declare function evaluateGuard(guard: ModelGuard, args: ActionArgs>, model: MachineModel, state: MachineState, scope: InterpreterScope): boolean; /** * XState `getTransitionData` + `next`: the enabled transitions for `event` * (guards evaluated, first match per node, descendants shadow ancestors, * parallel regions concatenated). Empty when nothing is enabled. */ export declare function selectTransitions(model: MachineModel, state: MachineState, event: MachineEvent, scope: InterpreterScope): readonly Transition[]; /** * Initial macrostep: pre-initial state (`context` factory, root only) -> * initial microstep (`reenter: true` into the initial nodes, no exits) -> * `macrostep` with the `xstate.init` event draining the internal queue. * Port of `StateMachine.getInitialSnapshot` + `initialMicrostep`. */ export declare function initialize(model: MachineModel, scope: InterpreterScope): StepResult; /** * One full macrostep for `event` (XState `macrostep`): select transitions, * microstep, then loop over `always` transitions and the internal queue until * stable or `status !== "active"`. `xstate.stop` -> `status: "stopped"` * without running any action. Throws whatever an action/guard/delay threw * (guard errors wrapped like XState); the caller commits the error status. * * A state that is no longer `active` (done / error / stopped) is returned * unchanged for any event: XState never lets a finished actor transition. */ export declare function step(model: MachineModel, state: MachineState, event: MachineEvent, scope: InterpreterScope): StepResult; /** * XState `snapshot.can`: some selected transition has a target or actions * (a "forbidden" transition alone does not count). Always `false` when the * state is not `active`. */ export declare function canHandle(model: MachineModel, state: MachineState, event: MachineEvent, scope: InterpreterScope): boolean; /** Builds the public, frozen snapshot of a state (value, tags, status, context, output, error). */ export declare function createSnapshot(model: MachineModel, state: MachineState): MachineSnapshot;