UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

33 lines (32 loc) • 2.21 kB
/** * 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, `already_resolved` for a consumed one, with the * dead parked-constraint entry evicted). Winning is the SOLE trigger to execute the pending action. * * 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 } from "./contracts.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-mutable — the Runner's same-Runner claim marks: opened with the resolve attempt, released on a loss. */ locallyClaimedTokens: Set<CheckpointToken>; /** borrowed-mutable — the Runner's parked-constraint registry: a terminally consumed token's entry is evicted. */ parentConstraintRegistry: Map<CheckpointToken, NonNullable<InheritedGate["parentConstraints"]>>; /** 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>;