UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

42 lines (41 loc) • 2.85 kB
/** * The abort-signal RACING vocabulary the park lane's synchronous-wait seats stand on — the per-call signal * composition, the value-mapping race and the tagged three-state race — moved whole out of the orchestrator so * the ask-lane phase (adjudicate / resolveAsk), the suspend-saga phase (the paused-VM compensation) and the * park-ask phase (the content-ask delivery race, the projection re-adjudication, the fence) reach DOWN for the * same three helpers instead of each carrying a copy. Pure: no engine state, no clock. */ /** * The per-call signal composition all three synchronous-wait seats share * (adjudicate / resolveAsk / resolveContentAsk): `AbortSignal.any([run, call])` when the gate * threaded a per-call signal, the bare run signal otherwise (host-driven gates and unthreaded emits * keep the historical binding byte for byte). The run signal is ALSO composed into the loop's turn * controller, so the double source is a belt, not a dependency — this layer must not assume the * loop's internal wiring. The composed product lives exactly as long as the one wait it bounds * (both sources outlive it), so nothing here retains across calls. */ export declare function composeCallSignal(runSignal: AbortSignal, callSignal: AbortSignal | undefined): AbortSignal; /** How a raced await ended. The generalized sibling of the ask-side * `raceAskWaitAgainstSignal` (tool-policy.ts): same three-state form over any value domain. * `aborted` means the SIGNAL settled the race — the promise may still be pending and stays the * caller's to detach. `threw` reports the rejection AS a rejection, never folded into the abort * arm: the value-mapping `raceAbort` below resolves `onAbort()` for a rejection too, which at a * DECISION seat would disguise a real failure as a concession (and feed the concession value into * whatever door consumes the raced result) — a decision seat must race with THIS form. */ export type RacedSettlement<T> = { tag: "value"; value: T; } | { tag: "threw"; error: unknown; } | { tag: "aborted"; }; /** Settle a raced await the moment `signal` aborts, WITHOUT waiting for the * promise to notice. Pre-aborted entry answers at once; the listener is removed on settle * whichever side wins (the `raceAbort` hygiene: `{once}` alone leaks a closure on the signal when * the promise settles first). The mapped promise attaches BOTH handlers up front, so an abort-arm * return never leaves an unhandled rejection behind. */ export declare function raceSettlementAgainstSignal<T>(p: Promise<T>, signal: AbortSignal): Promise<RacedSettlement<T>>; /** Race a promise against an abort signal; on abort, resolve with `onAbort()`. Cleans up its listener. */ export declare function raceAbort<T>(p: Promise<T>, signal: AbortSignal, onAbort: () => T): Promise<T>;