@sema-agent/core
Version:
Stateless, task-oriented AI agent core
54 lines (53 loc) • 3.85 kB
TypeScript
/**
* The resume ladder's ADMISSION rung (E1) and the wake's shaping (E2), verbatim from
* `Runner.resumeStream`: the outcome container's domain, the one-read snapshots of the caller's config and
* the trusted internals bag, the store resolution, the row read and its terminal-status confirm, the
* same-process parent-constraint re-supply, then the wake pre-ladder (gate purity, pendingAction purity,
* the message's persist-time validation) and the one read of the outcome discriminant and the signal slot.
*
* Async (two store reads); every refusal throws a typed `CheckpointError` pre-CAS. It ends by handing what it
* admitted to the rung after it (`next`) in its LAST continuation — no suspension point between the
* registry read and the wake pre-ladder's first read of the row — and returns what that rung returns.
* The same seat shape the tool gate's fold uses to enter its lanes (gate-fold.ts `afterFold`).
*/
import { type Checkpoint, type CheckpointStore, type CheckpointToken, type PendingSteerEntry, type ResumeOutcome } from "../checkpoint-store.js";
import type { InheritedGate, ResumeTaskConfig, RunInternals, RunnerDepsSeat } from "./contracts.js";
/** What the admission rung was called with. */
export interface ResumeAdmissionInput<R> {
/** borrowed-readonly — the checkpoint token the caller is redeeming. */
token: CheckpointToken;
/** borrowed-readonly — the caller's outcome object, read exactly where the driver read it (the container test,
* the discriminant once, the wake message once); never stored, never handed on as itself. */
outcome: ResumeOutcome;
/** borrowed-readonly — the caller's config bag; snapshotted ONCE here (own enumerable fields), the snapshot is what
* every later rung and the resumed leg read. */
taskConfig: ResumeTaskConfig;
/** borrowed-readonly — the trusted run-internals bag as the caller supplied it; shallow-snapshotted here, the
* snapshot (with the parked chain re-supplied when the registry holds it) is what the ladder reads. */
internals: RunInternals | undefined;
/** borrowed-readonly — the Runner's deployment deps, read LIVE through the Runner (the store resolution reads `checkpointStore`); the one home of why it is a
* seat and not a captured object is {@link RunnerDepsSeat}. */
runner: RunnerDepsSeat;
/** borrowed-readonly — the Runner's same-process parked-constraint registry; read for this token (never written here). */
parentConstraintRegistry: ReadonlyMap<CheckpointToken, NonNullable<InheritedGate["parentConstraints"]>>;
/** borrowed-readonly — the rung after admission, entered in this rung's last continuation with what it admitted. */
next: (admitted: ResumeAdmissionResult) => Promise<R>;
}
/** What admission established — the constants every later rung reads. */
export interface ResumeAdmissionResult {
/** The caller's config, snapshotted once (own enumerable fields). */
config: ResumeTaskConfig;
/** The trusted internals snapshot, with the parked parent chain re-supplied when this Runner spawned the leg. */
internals: RunInternals | undefined;
/** The checkpoint store the row lives in. */
store: CheckpointStore;
/** The pending row, read once; a non-pending snapshot was refused before this result existed. */
cp: Checkpoint;
/** The ONE read of the outcome's discriminant. */
outcomeGate: ResumeOutcome["gate"];
/** The ONE read of the config's signal slot (`.aborted` stays a live read on this object). */
resumeSignal: AbortSignal | undefined;
/** The validated wake message (wake outcomes that carried one), never the caller's object. */
wakeMessage: Omit<PendingSteerEntry, "seq"> | undefined;
}
export declare function resumeAdmission<R>(input: ResumeAdmissionInput<R>): Promise<R>;