@sema-agent/core
Version:
Stateless, task-oriented AI agent core
29 lines (28 loc) • 2.06 kB
TypeScript
/**
* The one LEG LABEL binder the compositions dispatch their legs through (the verify gate, the cascade).
*
* `RunInternals.onLegFrame` is handed every frame a drained leg offers, with the leg's address; the engine knows nothing
* about a composition's legs, so it never puts a label on that address — stamping one would be reading a fact off a run
* it cannot see. The dispatching composition knows, and is the only thing that does, so it says so the one way that
* cannot be forged: a per-dispatch copy of the internals whose seat closes over the label of the leg being dispatched
* with it. Nothing a caller can put ON the object produces a label, and a leg nobody labelled arrives without one —
* which is the honest reading of an unlabelled leg.
*/
import type { RunInternals } from "../core/runner/contracts.js";
import { type LegFrameEntry, type LegLabel } from "../core/runner/leg-frame.js";
/**
* Bind THIS leg's label into the caller's drained-leg frame seat, for one dispatch.
*
* The copy is made ONLY when the caller actually wired the seat, so a composition whose caller wired nothing dispatches
* exactly the object it dispatched before (identity forwarding, unchanged). When it is made, every other field still
* rides by the caller's own reference and the caller's object is never mutated — the same rule as the placement fixed
* point's copy, whose result this wraps.
*
* The caller's object is judged first, by the door's own judgment of a hidden seat ({@link refuseHiddenLegFrameSeat}):
* the placement copy would otherwise drop that seat before the door saw it and the leg would run with nobody listening.
*/
export declare function withLegIdentity(internals: RunInternals | undefined, leg: LegLabel,
/** The caller's own object — the seat's owner, whatever copy `internals` is (a placement copy is). */
caller: RunInternals | undefined,
/** The `Runner` entry this dispatch goes through, for the refusal's own words (a resumed leg: `"resumeStream"`). */
entry?: LegFrameEntry): RunInternals | undefined;