import { StateMachineNode } from '@holoscript/core'; export interface StateMachineInstance { definition: StateMachineNode; currentState: string; context: Record; } /** Hook executor function type — evaluates an onEntry/onExit code block */ export type HookExecutor = (code: string, context: Record) => any; /** * Guard evaluator function type — evaluates a transition condition expression. * Must return a truthy/falsy value. If no guard evaluator is registered, transitions * with conditions are treated as ungated (condition ignored, logged once). */ export type GuardEvaluator = (expression: string, context: Record) => unknown; /** * StateMachineInterpreter - Handles runtime execution of spatial state machines. * * The interpreter is pure: it owns state-machine definitions, current state, entry/exit * dispatch, and transition resolution. Code execution (onEntry/onExit bodies) and guard * expressions are delegated to executor hooks injected by the host runtime. This keeps * the interpreter free of any dependency on the expression evaluator. * * Wiring (done once by HoloScriptRuntime during init): * stateMachineInterpreter.setHookExecutor((code, ctx) => runtime.evaluateExpression(code)); * stateMachineInterpreter.setGuardEvaluator((expr, ctx) => runtime.evaluateExpression(expr)); * * Per-instance lifecycle: * createInstance(id, definition, ctx) -> registers, fires initial onEntry * sendEvent(id, event) -> finds transition, checks guard, dispatches * transitionTo(id, targetState) -> runs exit -> change -> entry * removeInstance(id) -> discards (no teardown hook yet) */ export declare class StateMachineInterpreter { private instances; private hookExecutor; private guardEvaluator; private guardMissingWarned; /** * Set the hook executor function (called by runtime during initialization). * The executor evaluates onEntry/onExit code blocks in the runtime's expression * evaluator scope, augmented with the instance's context. */ setHookExecutor(executor: HookExecutor): void; /** * Set the guard evaluator function (called by runtime during initialization). * The evaluator returns a truthy/falsy value for a transition's optional * condition expression. Without it, conditional transitions are treated as * ungated (the condition is ignored and a single warning is logged). */ setGuardEvaluator(evaluator: GuardEvaluator): void; /** * Initialize a new state machine instance */ createInstance(id: string, definition: StateMachineNode, context: Record): StateMachineInstance; /** * Process an event and trigger transitions. * * Resolution: * 1. Find transitions matching (currentState, event). * 2. For each match, evaluate optional `condition` via the registered guard * evaluator; take the first whose guard is truthy (or that has no guard). * 3. If a transition fires, dispatch to transitionTo() which runs * exit-hook -> state change -> entry-hook in that order. * 4. If no transition matches (or all guards fail), return false silently — * unmatched events are tolerated, not an error. */ sendEvent(id: string, event: string): boolean; /** * Evaluate a transition guard. Returns truthy/falsy. * If no guard evaluator is registered, logs once and treats the guard as passing * (condition becomes a no-op) so machines still advance during early-boot/tests. */ private evaluateGuard; /** * Force transition to a specific state */ transitionTo(id: string, targetStateName: string): void; /** * Execute code block using the registered hook executor */ private executeHook; getInstance(id: string): StateMachineInstance | undefined; removeInstance(id: string): void; } export declare const stateMachineInterpreter: StateMachineInterpreter; //# sourceMappingURL=StateMachineInterpreter.d.ts.map