import { AnyActor, Context, ErrorInfo, InternalEvent, Snapshot, TransitionInfo } from "@mantaq/core"; /** * Type guard for untyped transition-handler results. The single sanctioned * `as` site for graph invocation: handler output crosses the untyped boundary. */ interface HandlerResult { state?: { name?: string; }; emit?: Array<{ type?: string; }>; } /** Synthetic event object for graph introspection — matches minimal InternalEvent shape */ interface SyntheticEvent { type: string; payload?: unknown; } type TransitionHandler = (event: SyntheticEvent, options: { context: Context>; actor: AnyActor; }) => HandlerResult | undefined; /** Map of state/Any → event → handler */ type TransitionDispatchMap = Record>; /** State definition — matches AnyActor.options.states element type */ type StateDef = { name: string; isFinal: boolean; }; interface GraphNode { id: string; label: string; isActive: boolean; isFinal: boolean; isInitial?: boolean; /** The `*` source of `onAny` edges: any non-final state. */ isAny?: boolean; } /** An effect a state runs on entry. `sends`: declared event types; null = not declared. */ interface GraphEffect { name: string; sends: string[] | null; } interface GraphEdge { id: string; source: string; target: string; label: string; isActive: boolean; isInternal?: boolean; isUndetermined?: boolean; /** Handled without a state change: the registration declares no `to`. */ isStay?: boolean; /** Target comes from the builder's `to` list, not from running the handler. */ isDeclared?: boolean; payload?: { action?: string; }; contexts: string[]; /** Effect self-loops only: the effects the state runs on entry, in registration order. */ effects?: GraphEffect[]; } interface ActorGraph { nodes: GraphNode[]; edges: GraphEdge[]; } interface StateVisit { stateName: string; } interface TransitionRecord { from: string; event: string; to: string | undefined; } interface EffectRecord { stateName: string; effectName: string; } type SendRecord = { event: string; }; interface HistoryEntry { type: "state_visit" | "transition" | "effect" | "send"; data: StateVisit | TransitionRecord | EffectRecord | SendRecord; } interface History { append(entry: HistoryEntry): void; entries(): readonly HistoryEntry[]; stateVisits(): StateVisit[]; transitions(): TransitionRecord[]; effects(): EffectRecord[]; sends(): SendRecord[]; visitedStates(): Set; firedTransitions(): Set; reset(): void; } /** * History records the runtime trace of an instrumented actor. A closure over * the entry list keeps the recorder mutable without exposing the raw array. */ export declare function createHistory(): History; export declare const INITIAL_NODE_ID = "__initial__"; /** Source of `onAny` edges: any non-final state of the machine (`region.*` inside a region). */ export declare const ANY_NODE_NAME = "*"; export declare function isAnyNode(id: string): boolean; export declare function collectActiveStates(snapshot: Snapshot, options: { prefix: string; activeSet: Set; }): void; export declare function buildGraph(actor: AnyActor, options?: { internalIds?: Set; sampleContext?: Record; sampleContexts?: Record>; }): ActorGraph; export declare function parseStates(options: unknown): ReadonlyArray; export declare function parseTransitionMap(source: unknown): TransitionDispatchMap; export declare function parseInitialName(options: unknown): string | undefined; export declare function parseContextRecord(context: unknown): Record; export declare function parseInternalEventIds(options: unknown): Set; type SubscriberEventName = "change" | "done" | "transition" | "error" | "output"; type SubscriberHandler = E extends "change" ? (snapshot: Snapshot, prev: Snapshot) => void : E extends "done" ? () => void : E extends "transition" ? (info: TransitionInfo) => void : E extends "error" ? (info: ErrorInfo) => void : E extends "output" ? (event: InternalEvent) => void : never; interface InstrumentedActor> { history: History; send(event: InternalEvent): void; state: AnyActor["state"]; snapshot(): Snapshot; regions: Record; context?: C; clock?: AnyActor["clock"]; on(event: E, options: { fn: SubscriberHandler; }): () => void; recover(target: { state: AnyActor["state"]; context: C; }): void; settled(): Promise; options?: AnyActor["options"]; inject(event: InternalEvent): void; dispose(): void; } export declare function instrument(actor: AnyActor): InstrumentedActor; export declare function reachable(graph: ActorGraph, endpoints: { fromId: string; toId: string; }): boolean; export declare function allPaths(graph: ActorGraph, endpoints: { fromId: string; toId: string; }): string[][]; export declare function findCycles(graph: ActorGraph): string[][]; export declare function unreachableNodes(graph: ActorGraph, options: { fromId: string; }): string[]; export declare function shortestPath(graph: ActorGraph, endpoints: { fromId: string; toId: string; }): string[] | undefined; export type { ActorGraph, EffectRecord, GraphEdge, GraphNode, History, HistoryEntry, InstrumentedActor, SendRecord, StateDef, StateVisit, SyntheticEvent, TransitionDispatchMap, TransitionHandler, TransitionRecord };