@sema-agent/core
Version:
Stateless, task-oriented AI agent core
95 lines (94 loc) • 5.99 kB
TypeScript
/**
* What a Skill card's approval is bound to, as ONE value: the skill the call names and the two lists approving it releases,
* in the rule grammar's canonical spelling (de-duplicated, sorted). Its hash is the `boundGrantDigest` a parked approval is
* judged by, so a reader holds the list a person approved and the binding that covers it as the same fact — the live
* `AskRequest`, the parked row, the inbox projection and the request a Runner hands a policy all carry it (minted by
* `skillGrantBindingMembers`; on a request through {@link requestGrantBinding}).
*
* A leaf on purpose: the checkpoint projection reads it at its boundary and may not import the module that mints it (it imports only
* the hash).
*/
export interface BoundSkillGrants {
/** The skill's name as the loaded table spells it, or `null` when the call names no loaded skill (it grants nothing). */
readonly skill: string | null;
/** The skill's `allowed-tools` entries — what approving the activation lets be used without asking. */
readonly allowedTools: readonly string[];
/** The skill's `disallowed-tools` entries — what activating it refuses for the rest of the run. */
readonly disallowedTools: readonly string[];
}
/**
* Why a card carries no binding digest — the closed set of `boundGrantAbsence`: `not_bindable` (the call is not an
* activation of the engine's `Skill` tool: it binds no grant) or `unreadable` (the card binds a grant and what it binds
* cannot be read: a stored row whose digest is not a string, or that says neither; a request copied over moved args whose
* digest the engine did not mint for that call, {@link withArgsBinding}).
*/
export declare const BOUND_GRANT_ABSENCES: readonly ["not_bindable", "unreadable"];
export type BoundGrantAbsence = (typeof BOUND_GRANT_ABSENCES)[number];
/**
* A stored value read as a {@link BoundSkillGrants}, whole or not at all: a fresh copy of the three members and nothing else,
* or `undefined` when any member is not of its type. Every member is read ONCE, so the value screened is the value published.
*/
export declare function readBoundSkillGrants(raw: unknown): BoundSkillGrants | undefined;
/** The card members every ask carries about its binding — exactly one arm: a call to the engine's `Skill` tool carries the
* digest and the value it hashes, every other call the absence word. */
export type SkillGrantBindingMembers = {
readonly boundGrantDigest: string;
readonly boundGrants: BoundSkillGrants;
readonly boundGrantAbsence?: never;
} | {
readonly boundGrantAbsence: BoundGrantAbsence;
readonly boundGrantDigest?: never;
readonly boundGrants?: never;
};
/** The members of a card that is not a `Skill` activation: the factory's other arm, and what a tool's own consent card (never a
* `Skill` call) spreads. */
export declare const NOT_BINDABLE: Readonly<{
readonly boundGrantAbsence: "not_bindable";
}>;
/** The leg's binding factory ({@link SkillGrantBindingMembers} for a call over `args`), the one every ask-mint site spreads. */
export type GrantBindingOf = (call: {
readonly toolName: string;
}, args: unknown) => SkillGrantBindingMembers;
/**
* The binding members of a stored parked row, as the inbox projection publishes them — exactly one of three: the digest when it
* is a string (and the lists only as the value that digest hashes — {@link readBoundSkillGrants} whole, and equal to the digest by
* hash; a pair that disagrees, or lists beside no digest, would show an approver one list while the approval binds another), else
* the row's absence word when it is a member of the set, else `unreadable` — the row does not say what it binds.
*/
export declare function readBoundBinding(row: {
readonly boundGrantDigest?: unknown;
readonly boundGrants?: unknown;
readonly boundGrantAbsence?: unknown;
}): {
boundGrantDigest: string;
boundGrants?: BoundSkillGrants;
} | {
boundGrantAbsence: BoundGrantAbsence;
};
/**
* The grant-binding words of a request a Runner hands a policy — the leg's card factory `of` over the request's own `args` (the members
* every card of the call carries, by the same function): the digest arm with its value frozen, or the factory's absence word. The digest
* arm carries a note of how the same call is minted over other args, so a copy of the request over moved args carries the answer for
* THOSE ({@link withArgsBinding}).
*/
export declare function requestGrantBinding(of: GrantBindingOf, call: {
readonly toolName: string;
}, args: unknown): SkillGrantBindingMembers;
/** A carrier of a call's binding words — a request or a row: its tool name, its args and the three members, as stored. */
export interface GrantBindingCarrier {
readonly toolName?: unknown;
readonly args: unknown;
readonly boundGrantDigest?: unknown;
readonly boundGrants?: unknown;
readonly boundGrantAbsence?: unknown;
}
/**
* The carrier moved to other args — a copy holding `args` and the binding for THEM (a carrier that holds none moves with none). The
* binding follows the args by ONE rule: a digest {@link requestGrantBinding} minted for this call is minted again over `args`; a digest
* with no such note (a clone, a host-built request, a note minted for another call or digest) holds over the same bytes and reads
* `unreadable` over moved ones — it binds a grant, and what it binds over these args cannot be read here; an absence word holds for any
* args of the call (args never make a call a `Skill` activation, nor an unreadable binding readable). Every member is read as
* {@link readBoundBinding} reads a row: a digest that is not a string, or a word outside the set, moves as `unreadable`; lists that do
* not hash to the digest are dropped (the digest alone holds over the same bytes). Lists a request carries are a frozen copy.
*/
export declare function withArgsBinding<R extends GrantBindingCarrier>(carrier: R, args: unknown): R;