UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

101 lines (100 loc) • 7.89 kB
import { type ReceiptMode } from "./mods/kernel/receive.js"; /** How a refusal names the object being received. */ export interface OwnPropertyReceiptWords { /** The object, e.g. `RunnerDeps`. */ readonly subject: string; /** One of its properties, e.g. `seat`. */ readonly unit: string; /** When the one read happens, e.g. `at new Runner`. */ readonly moment: string; } /** The receipt's coded refusal. */ export declare function receiptRefusal(message: string): Error & { code: "config.invalid_argument"; }; /** The receipt's first look, before ANY reflection on the object (a door that must look at the caller's object before * the receipt — a retired-name door reading its prototype chain — calls this first): a Proxy is refused. */ export declare function refuseProxy(given: object, words: OwnPropertyReceiptWords): void; /** The configuration receipt's mode of the one receipt: the top record read, each getter once, its members as given (a declared list's * own read too: the list itself, each element once, the elements as given). */ export declare const CONFIG_RECEIPT_MODE: ReceiptMode; /** * The declaration receipt's mode of the one receipt — a declaration the engine judges and then holds (an MCP server's or an A2A peer's * entry, a `toolAxes` record, a lock declaration) received as plain data held to the engine's one depth for a caller's value, * {@link MODS_VALUE_DEPTH} levels of records and lists below the declaration itself (the bound a mods handler's answer is held to): every * own string-keyed member read once off its captured descriptor (a getter called once, enumerable or not), every level copied, anything * that is not data refused (a Proxy at any level, a function, a bigint, an object of another prototype, a structure that contains * itself, a container nested deeper — a shared one measured where it sits each time it is met), every copied container frozen. */ export declare const DECLARATION_RECEIPT_MODE: ReceiptMode; /** Only {@link optionKeys} mints an {@link OptionKeys}: a hand-written list carries no brand. */ declare const OPTION_KEYS: unique symbol; /** * A constructor's options table: the keys of the options interface `T`, exactly. The brand is a function over `keyof T` * in both positions, so a table for one interface is not a table for another (a narrower one, an `Omit` of it) in either * direction, and a plain string list is not one at all. */ export type OptionKeys<T> = readonly string[] & { readonly [OPTION_KEYS]: (key: keyof T) => keyof T; }; /** The keys of `K` outside `T`, taken arm by arm when `K` is a union (each arm's own keys, not only the keys all arms share). */ type SurplusKeys<K, T> = K extends unknown ? Exclude<keyof K, keyof T> : never; /** The minter {@link optionKeys} hands back: `never` — not callable — for an interface with an index signature, whose keys no * table can name. */ type OptionKeysMinter<T> = string extends keyof T ? never : number extends keyof T ? never : <K extends Record<keyof T, 0>>(table: K & Record<SurplusKeys<K, T>, never>) => OptionKeys<T>; /** * Mint the options table of interface `T` from a literal naming each of its keys once (`{ fsync: 0, lockWaitMs: 0 }`). * Curried so `T` is written and the literal inferred: a key of `T` the literal leaves out does not compile, and neither * does a key `T` lacks — whether the literal is fresh, a variable, a spread, or a union whose arms each carry one — since * every key outside `T` must be `never`. An interface with an index signature has no table (the minter is not callable). */ export declare function optionKeys<T extends object>(): OptionKeysMinter<T>; /** The OPTIONS DOOR — a constructor's options bag received by the receipt law, absent ⇒ an empty one: every option the constructor reads * is read off this frozen copy, once, and the caller's bag is never read again (a store keeps no hold of it). `owner` names the * constructor; `keys` is the table of the options it takes ({@link optionKeys}), and an option outside it is refused by name * ({@link receiveMembers}). */ export declare function receiveOptions<T extends object>(given: T | undefined, owner: string, keys: OptionKeys<T>): Readonly<T>; /** Read `given` by the receipt law (module note): the plain copy, every own member taken once from its captured descriptor. */ export declare function receiveOwnProperties<T extends object>(given: T, words: OwnPropertyReceiptWords): T; /** How a door whose family has its own code refuses its stray members: the one sentence, and the stray names it names * (a symbol as itself), for a refusal that also carries them as data. */ export type StrayMembersRefusal = (message: string, stray: readonly (string | symbol)[]) => Error; /** A record's members outside a door's table: their names (a symbol as itself) and the one sentence that names them. */ export interface StrayMembers { readonly names: readonly (string | symbol)[]; readonly sentence: string; } /** * THE NAME JUDGMENT of a door (module note): every own member of `given` that `keys` does not name — a string key, * enumerable or not, and a symbol key — with the one sentence that names them all (each with its nearest taken name within * two edits, then the members taken); `undefined` when there is none. It reads names only: no getter runs and no value is * looked at. On an admitted object (a plain record that is no Proxy, or a copy a receipt made) no caller code runs; a * reader whose own law reads the caller's live object judges the names that object answers (a Proxy's own-keys answer * included). A reader that answers a sentence instead of throwing takes this; a door that throws takes * {@link refuseStrayMembers} or {@link receiveMembers}. */ export declare function strayMembersOf(given: object, words: OwnPropertyReceiptWords, keys: readonly string[]): StrayMembers | undefined; /** * THE MEMBER'S PRESENCE (module note): `name` is a member of `record` exactly when its value there is not `undefined` — an * own key holding `undefined` and a missing key are one absence; `null`, `0`, `""` and `false` are values. The engine's one * reading of whether a record carries a member; the names a caller handed over are the name judgment's question * ({@link strayMembersOf}), not this one's. */ export declare function memberPresent(record: object, name: string): boolean; /** * THE NAME-ONLY DOOR — the receipt's admission (not a Proxy, a plain record), then {@link strayMembersOf}: every own member * `keys` does not name is refused, all of them in one sentence, and no getter runs. For an object the door must judge but * not copy (a face whose callbacks are later called with the object itself as `this`); a door that takes a copy takes * {@link receiveMembers}, which is this judgment followed by the receipt. */ export declare function refuseStrayMembers(given: object, words: OwnPropertyReceiptWords, keys: readonly string[], refusal?: StrayMembersRefusal): void; /** * Read `given` by the receipt law and refuse every own member `keys` does not name (module note): the members a door * takes, and nothing else, by one reading. The names are judged ({@link refuseStrayMembers}) before the receipt runs any * getter, and nothing of the caller's runs between that judgment and the receipt's one capture, so the names judged are * the names read. `refusal` codes the stray-member refusal for a door whose family has its own code (the receipt's own * refusals keep `config.invalid_argument`). The copy handed back is frozen: what was judged is what is held, and a * callback the door's owner later calls on it (its `this`) cannot change a member. */ export declare function receiveMembers<T extends object>(given: T, words: OwnPropertyReceiptWords, keys: readonly string[], refusal?: StrayMembersRefusal): Readonly<T>; export {};