@sema-agent/core
Version:
Stateless, task-oriented AI agent core
53 lines (52 loc) • 3.96 kB
TypeScript
import type { HolderJudge, HolderStoreKind } from "../checkpoint-generation.js";
/**
* The grant fixture a store contract binding hands the kit's holder cells (`grants`): holders minted against the SAME judge the
* binding's `composed` store was built with. A host mints them with its real encoding and run rows it controls (a run whose current
* leg it can move, a run it can end, a run row it can give a status word outside its live set); the in-tree bindings use
* {@link inMemoryGrantTable}.
* - `current()` — a grant naming its run's current leg, the run live: every write carrying it lands;
* - `replaced()` — the same run moved to another leg since the grant was given;
* - `ended()` — the grant's leg is still the run's last, but the run has ended;
* - `unknownStatus()` — the run row's status is a word outside the judge's live set (the judge must answer `false`: fail-closed);
* - `malformed` — a value no grant is encoded as (the judge throws; the write throws with it).
* Each function mints a fresh grant on each call (a run of its own), so cells never share a run.
*/
export interface ContractGrants {
current(): string;
replaced(): string;
ended(): string;
unknownStatus(): string;
readonly malformed: string;
/** Optional: end the run a `current()` holder named (as the host's own grant table would — a leg handed on, a run ended). Given, the
* kit proves the judgement is made afresh on every write: a holder that wrote while current is refused once retired (a store that
* remembers a holder's first answer passes every other cell). */
retire?(holder: string): void;
}
/** The three dead grants every holder cell runs over, each freshly minted, labelled for the cell's sentence. */
export declare function deadGrants(grants: ContractGrants): Array<readonly [label: string, holder: string]>;
/**
* THE reference grant table of the in-tree bindings: an in-memory run table and the judge over it, by the one sentence of
* {@link HolderJudge} — a holder is current exactly when it decodes ({@link decodeGrantHolder}; a value that does not throws
* `holder.malformed`), names a run the table holds, names that run's current leg, and the run's status is a live word (`running` or
* `parked`); a status outside that set answers `false`. Build the store under test with `holderIsCurrent`, and hand the kit `grants`.
*/
export declare function inMemoryGrantTable(): {
readonly holderIsCurrent: HolderJudge;
readonly grants: ContractGrants;
};
/** The refusal a holder cell expects of a create-shaped write with a dead grant: `holder.superseded` (`isHolderSuperseded`). */
export declare function rejectsSuperseded(fn: () => unknown, what: string): Promise<void>;
/** A write carrying a malformed holder: the judge throws, and the write throws with it — anything but `holder.superseded` (a value no
* grant is encoded as is not a grant that ended; a layer that turns the judge's throw into a refusal hides a wiring fault). */
export declare function rejectsMalformed(fn: () => unknown, what: string): Promise<void>;
/**
* The holder binding of a store kit, judged before any holder cell runs: `undefined` when the binding judges no holder (no `composed`,
* no `grants`, and the bare store declares no `fence`); otherwise both must be given and the composed store must declare
* `{ holder: "writes" }` ({@link readStoreFence}: the retired `{ holder: true }` and every malformed form fail the cell, never skip it).
* A bare store declaring a fence beside no `composed` fails too: the holder cells are proven on the store as the deployment composes
* it — every wrapper included — because a wrapper is what silently drops a holder.
*/
export declare function holderBinding<S>(kind: HolderStoreKind, bareDeclares: boolean, composed: (() => S) | undefined, grants: ContractGrants | undefined): {
composed: () => S;
grants: ContractGrants;
} | undefined;