@sema-agent/core
Version:
Stateless, task-oriented AI agent core
22 lines (21 loc) • 1.81 kB
TypeScript
/** Mint the completion identity of `target` ONCE, fill-once (first writer wins): every terminal-transition site calls
* this instead of writing `completionId` directly, so however many sites a lane has (settle / TaskStop circumvention /
* backfill / a store-side terminal write), the value is minted exactly once and every later caller — including an
* idempotent re-call from a path that already ran — gets back the SAME id. The parameter is any object with an
* optional `completionId`, so one helper serves a registry handle, a `WorkflowRun` and a durable
* `BackgroundAgentRecord` alike (no shared base type, same fill-once shape). */
export declare function mintCompletionId(target: {
completionId?: string;
}): string;
/** A completion identity chosen BEFORE it is safe to commit — for a caller whose terminal write is a CAS not yet known to
* win. The value goes into the durable payload at once (that write only takes effect if its own CAS wins) and onto the
* live object only through {@link commitCompletionIdIfEmpty}, from the call that already knows the CAS won. */
export declare function completionIdCandidate(): string;
/** Sibling of {@link mintCompletionId} for the CAS caller above: fill-once with an EXTERNALLY-chosen value (from
* {@link completionIdCandidate}) instead of generating a fresh one. Exists because committing a candidate onto a live
* handle before its durable CAS was confirmed left a losing attempt's id on a non-terminal ("parked") handle that nothing
* ever cleared, and a later legitimate parked→running flip then carried it into an unrelated real completion through
* {@link mintCompletionId}'s own fill-once guard. */
export declare function commitCompletionIdIfEmpty(target: {
completionId?: string;
}, value: string): string;