@sema-agent/core
Version:
Stateless, task-oriented AI agent core
79 lines (78 loc) • 5.66 kB
TypeScript
/**
* The ONE reading of a task's ISOLATION SCOPE ({@link import("./task-spec.js").TaskSpec.isolationScope}): the member when it is set,
* else the principal. Every face that keys a run's working state on "which scope of this person's work" reads it here — the registry
* domain, the offload namespace, the checkpoint scope's last rung, the scheduler's keys, the delegation tree's domain, the MCP
* connection pool — and every face that keys on the PERSON keeps reading the principal.
*
* The empty string is absence, in either member and in a scope a context carries: the task door and every bucket resolver read a
* principal of `""` as no principal (`readPrincipal`), the read judge reads it as the anonymous identity (`ownerIdentityOf`), and so a
* task whose principal is `""` and a task with none are one identity with one scope — no scope, which every face then fills with its own
* absence answer (its mounted scope, or {@link ANONYMOUS_SCOPE}). No `""` becomes a scope here — a member's, a context's or a mount's.
*
* Import-free: the tool modules reach it without pulling the runner in.
*/
/** The holder of the two identity members: a task spec, a spec seat, a resume config, a scheduler context. */
export interface IsolationScopeHolder {
readonly isolationScope?: string;
readonly principal?: string;
}
/** The isolation scope of `holder`: its member when set, else its principal; `undefined` when neither is a non-empty string. */
export declare function isolationScopeOf(holder: IsolationScopeHolder): string | undefined;
/**
* The working scope of work done for nobody — the ONE spelling of it, minted here and nowhere else. Identity has two axes: on WHO,
* no identity is no one (the engine spells no name for it — a rule owner, a result owner, a session owner stay absent); on WHERE the
* work is filed, no identity is this scope. A deployment that has several people and also admits anonymous calls refuses, at its own
* door, a real person named `default`; the engine does not know a deployment's shape and refuses no name. The key a root address
* records is a storage key: the `default` an anonymous root records is nobody's identity, so the engine does not name this scope's
* declared entries to a delegated leg's notice (`noticeReaderScope`).
*/
export declare const ANONYMOUS_SCOPE = "default";
/**
* The scope key of `holder`'s working state: its isolation scope ({@link isolationScopeOf}: the member when set, else the principal),
* else {@link ANONYMOUS_SCOPE}. Every face that keys working state for a holder with no identity reads this, never a literal.
*/
export declare function scopeKeyOf(holder: IsolationScopeHolder): string;
/**
* The two identity members `holder` STATES, each read once and carried exactly as stated, left out only when absent (`undefined`): the
* identity a leg is admitted under, member for member — never synthesized (unlike {@link legIdentityOf}, the isolation scope stays absent
* when only the principal is set) and never judged here (`""` stays `""`, which every door reads as absence; a value that names no one
* stays too, for the door that refuses it), so a later leg handed it meets the same doors its first leg met.
*/
export declare function identityMembersOf(holder: IsolationScopeHolder): {
principal?: string;
isolationScope?: string;
};
/**
* The identity a leg acts as — the person and the scope of their work — read once from the task: `principal` the task's member when it
* names someone (the empty string names no one and is left out, as an absent principal is), `isolationScope` {@link isolationScopeOf}. The
* one derivation of "who is this leg": the tool-execution context's two trusted members are this value, and the identity the leg's
* tool-result view records on every write and reads as (`ownerIdentityOf` in `owner-identity.ts`, the canonical identity every "is this
* yours" judgment compares) is projected from it.
*/
export interface LegIdentity {
readonly principal?: string;
readonly isolationScope?: string;
}
/** The {@link LegIdentity} of `holder` (a task spec, a spec seat). A member is left out when it reads absent. */
export declare function legIdentityOf(holder: IsolationScopeHolder): LegIdentity;
/**
* The isolation-scope member a parked row RECORDS, spread into the row: present only when the task set one that differs from its
* principal — the one case the principal alone does not restate. A row that records it carries a reader requirement (a reader that
* cannot read it would resume the leg in the principal's scope); every other row stays exactly the row it was.
*/
export declare function isolationScopeRecordOf(holder: IsolationScopeHolder): {
isolationScope?: string;
};
/**
* The scope a registry-facing tool acts in: the identity of the work first — the running task's isolation scope the Runner put on
* the tool's context, else (a delegation lane) the isolation scope of the seat it hands its children ({@link isolationScopeOf}) —
* and only then the scope the tool was mounted with, which speaks for work that has no identity. The context's `principal` is the
* person and is never read here — a tool handed a context outside a Runner task names its scope on `isolationScope` (or mounts with
* one). An empty string is no scope, on the context and on the mount alike, as everywhere above: a tool mounted with `scope: ""`
* acts as one mounted with none.
*/
export declare function callScopeOf(ctx: {
readonly isolationScope?: string;
} | undefined, mounted: {
readonly scope?: string;
}, seat?: IsolationScopeHolder): string | undefined;