@sema-agent/core
Version:
Stateless, task-oriented AI agent core
66 lines (65 loc) • 5.24 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 row's own verdict,
* the wake pre-ladder (gate purity, the message's persist-time validation), the one read of the outcome discriminant and the
* signal slot, then the resumed leg's parent constraint chain (`revivalParentConstraints`: handed live, registered live, or rebuilt).
*
* Async (two store reads, and the chain's rebuild when it rebuilds one); 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 — the chain's resolution is its last
* read — 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, CheckpointError, type CheckpointStore, type CheckpointToken, type PendingSteerEntry, type ResumeOutcome } from "../checkpoint-store.js";
import type { InheritedGate, ResumeTaskConfig, RunInternals, RunnerDepsSeat, SuspendReap } from "./contracts.js";
import type { SessionStore } from "../session.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 session store, fixed at its construction (unlike its deps): the retention capability door judges it. */
sessions: SessionStore;
/** borrowed-mutable — the Runner's same-process parked-constraint registry; read for this token, and evicted for it only by the expired-row duty. */
parentConstraintRegistry: Map<CheckpointToken, NonNullable<InheritedGate["parentConstraints"]>>;
/** borrowed-mutable — the Runner's suspended-env reap handles: a row the confirm reads `expired` has its duty run here (its record taken). */
suspendedEnvReaps: Map<CheckpointToken, SuspendReap>;
/** 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); its MCP / A2A lists are the doors' judged copies of THIS resume's (the row records none). */
config: ResumeTaskConfig;
/** The trusted internals snapshot, carrying the parent constraint chain the leg runs under (handed, registered or rebuilt). */
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;
/** The chain's refusal admission deferred — the row's own chain arm (`checkpointRowResumeRefusal`), else the chain function's (a layer
* it cannot rebuild, a row it reads differently) — returned by the checkpoint screen's chain rung and thrown by the ladder after
* the decision's own bindings and the run's identity, so a decision bound to another card or of another gate is refused for that. */
chainRefusal: CheckpointError | undefined;
/** The chain is the live one with its root task layer as registered (no root policy handed): the ladder tells
* `permission.revival_root_policy_unrestated` once the claim is won — never on an attempt a later rung refuses. */
rootLayerUnrestated: boolean;
}
export declare function resumeAdmission<R>(input: ResumeAdmissionInput<R>): Promise<R>;