type ControlLoopContinuingRoute = { to: TTarget; returns: readonly TReturn[]; terminal?: false; }; type ControlLoopTerminalRoute = { to: TTarget; terminal: true; returns?: never; }; export type ControlLoopRoute = ControlLoopContinuingRoute | ControlLoopTerminalRoute; export type ControlLoopRoutes = Record; export type ControlLoopDefinition = { decide: TDecide; returnTo: TReturnTo; routes: TRoutes; }; type ControlLoopCases = { [TRoute in keyof TRoutes]: TRoutes[TRoute]["to"]; }; type ControlLoopReturnReference = { [TRoute in keyof TRoutes]: TRoutes[TRoute] extends { returns: readonly (infer TReturn extends string)[]; } ? TReturn : never; }[keyof TRoutes]; export type ControlLoopEdge = { from: TDecide; switch: { on: "$.route"; cases: ControlLoopCases; }; } | { from: ControlLoopReturnReference; to: TReturnTo; }; export type ControlLoopGraph = { choices: readonly (keyof TRoutes & string)[]; edges: ControlLoopEdge[]; }; /** * Build the decision and return edges for a control loop from a typed route map. * The returned graph uses only ordinary workflow edges. */ export declare function controlLoop(definition: ControlLoopDefinition): ControlLoopGraph; export {};