import type { CallOptions } from "@boardwalk-labs/workflow/runtime"; import type { ChildCallOutput, ChildDispatcher, ChildResult, ScheduleOptions } from "./workflow_host.js"; import type { RunnerControlClient } from "./runner_control_client.js"; export interface BrokerChildDispatcherDeps { client: RunnerControlClient; /** Wait between polls. Injected so tests don't sleep on real time. Defaults to setTimeout. */ sleep?: (ms: number) => Promise; pollIntervalMs?: number; } export declare class BrokerChildDispatcher implements ChildDispatcher { private readonly deps; private readonly sleep; private readonly pollIntervalMs; /** How many children this run has already asked for per (target, input) — see {@link ordinalOf}. */ private readonly ordinals; constructor(deps: BrokerChildDispatcherDeps); /** * The position of this call within its run's calls to the SAME target with the SAME input. * * A child's identity is `(parent, target, input)` — that is what makes re-attach correct, because * a re-attached child provably ran the input this call asked for. The ordinal disambiguates * DUPLICATES within that group: fanning out five identical calls (best-of-N sampling, or a list * with repeats) must produce five children, not one shared by five awaits. Nothing depends on an * ordinal identifying the same *logical* call across a restart — only on the input matching — so * a concurrent fan-out whose calls arrive in a different order after a crash still re-attaches to * equivalent children. * * Assigned SYNCHRONOUSLY (before any await) so concurrent callers get distinct ordinals, and reset * with the process, which is exactly when the program re-executes from the top. */ private ordinalOf; /** Create (or re-attach to) the child, then hold + poll to terminal and return its output. An * abort (`signal`) stops the hold within one poll interval and throws RunAbortedError. */ call(slug: string, input: unknown, _opts: CallOptions | undefined, signal?: AbortSignal): Promise; /** Poll a child's current state (the freeze-wake path uses this to fetch the callee's output * schema); null = not this run's child. */ poll(childRunId: string): Promise; /** Start (or idempotently re-attach to) the child and resolve its CURRENT state — no hold. The * durable callWorkflow seam decides whether to suspend (non-terminal) or return (terminal). */ start(slug: string, input: unknown, _opts: CallOptions | undefined, signal?: AbortSignal): Promise; /** Fire-and-forget: create (or re-attach to) the child and return its id without holding. */ run(slug: string, input: unknown, _opts: CallOptions | undefined): Promise; /** Provision a durable schedule via the broker; returns the new schedule's id. A `Date` `at` is * normalized to an ISO string (the broker spec carries string | number, not Date). */ schedule(slug: string, input: unknown, opts: ScheduleOptions): Promise; private pollToCompletion; /** A completed child returns its output; a failed/cancelled child rejects the parent's await. */ private childOutput; }