/** * The stop switch of a live run: everything at once, or one subagent of it. * * A workflow already honours a `signal` - that is how a whole run is called * off. What it has no way of expressing is *this branch, not the others*: the * signal is shared by every subagent under it, and a combinator hands out no * handles. So the switch sits where the handles pass: it wraps `spawn`, keeps * what came out of it by id, and hands the workflow the signal it will obey. * * Both halves are ports, not globals: a script builds one, gives its `signal` * and its `spawn` to the workflow, and stops whatever it likes from outside. * The extension is the first caller, not the only possible one. */ import type { SpawnFn } from "./workflows/options.ts"; /** What a caller varies. Both default to the real thing. */ export type StopSwitchOptions = { /** An outer signal. Aborting it stops the run, exactly as {@link StopSwitch.all} does. */ signal?: AbortSignal; /** The `spawn` to wrap. Defaults to the real one. */ spawn?: SpawnFn; }; /** A live run's two halves: what it obeys, and what stops it. */ export type StopSwitch = { /** * Give this to the workflow as its `signal`. * * It aborts when {@link StopSwitch.all} is called, and when the outer signal * does. */ readonly signal: AbortSignal; /** * Give this to the workflow as its `spawn`. * * The subagents it produces are registered on the way out, which is what * makes {@link StopSwitch.one} possible at all. Delegated children arrive * here too, as long as the workflow passes the same `spawn` down. */ readonly spawn: SpawnFn; /** Stops one subagent. `false` when no subagent of that id came through here. */ one(id: string): boolean; /** Stops the run: the turns in flight, and the ones it was about to start. */ all(): void; }; /** * Builds the stop switch for one run. * * Stopping is one-way: a stopped subagent stays stopped, and a stopped run * refuses the turns the workflow has not started yet. Nothing here closes * anything - whoever opened a subagent still closes it, on this path like on * any other, which is what keeps an interrupted run exportable. */ export declare function stopSwitch(options?: StopSwitchOptions): StopSwitch; //# sourceMappingURL=stop.d.ts.map