@sema-agent/core
Version:
Stateless, task-oriented AI agent core
40 lines (39 loc) • 2.95 kB
TypeScript
/**
* The resume ladder's CLAIM rung (E10), verbatim from `Runner.resumeStream`: the atomic
* CAS (`claimTerminal` when the store provides it — one round trip carrying the loser's truth — else the
* two-step `resolve` + diagnostic read), the same-Runner claim mark around it, and the loss classification
* (`reopened_concurrently` for a live row whose rev moved, `holder.superseded` — `holderSupersededError`, not a `CheckpointError` — for the
* validated row a carried claim holder lost, `already_resolved` for a consumed one, with the dead parked-constraint entry evicted). Winning is the SOLE trigger to execute.
*
* Async (the CAS). It ends by handing off to the driver's post-claim rung (`next`) in its LAST continuation
* — the post-consume hook fires on the tick the win was read — and returns what that rung returns.
*/
import { type Checkpoint, type CheckpointStore, type CheckpointToken } from "../checkpoint-store.js";
import type { InheritedGate, InstallingPhaseResult, ResumeRun, SuspendReap } from "./contracts.js";
import type { LocalClaims } from "./local-claims.js";
export interface ResumeClaimInput<R> {
/** borrowed-readonly — the checkpoint token being claimed. */
token: CheckpointToken;
/** borrowed-readonly — the pending row (scope and the rev the ladder validated against). */
cp: Checkpoint;
/** borrowed-readonly — the store the CAS runs against. */
store: CheckpointStore;
/** borrowed-readonly — the twin the store persists as the resolved outcome. */
outcomeForStore: ResumeRun["outcome"];
/** borrowed-readonly — the deployment's claim holder the resume acts under (`RunInternals.holder`), carried into the CAS. */
holder?: string | undefined;
/** borrowed-mutable — the Runner's same-Runner claims: this attempt opens its own with the resolve, closes it on a loss or a throw. */
locallyClaimedTokens: LocalClaims;
/** borrowed-mutable — the Runner's parked-constraint registry: a terminally consumed token's entry is evicted. */
parentConstraintRegistry: Map<CheckpointToken, NonNullable<InheritedGate["parentConstraints"]>>;
/** borrowed-mutable — the Runner's suspended-env reap handles: a loss to an `expired` row runs that row's duty (its record taken). */
suspendedEnvReaps: Map<CheckpointToken, SuspendReap>;
/** borrowed-readonly — where the expired duty's bounded destroy failure is said (the Runner's `onError`); never thrown. */
onDestroyError: (err: unknown, sessionId: string) => void;
/** borrowed-readonly — the driver's post-claim rung, entered in this rung's last continuation. */
next: (claimed: ResumeClaimResult) => Promise<R>;
}
/** The claim's completion is its whole result: a lost CAS throws, so reaching `next` IS the win. */
export interface ResumeClaimResult extends InstallingPhaseResult {
}
export declare function resumeClaim<R>(input: ResumeClaimInput<R>): Promise<R>;