UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

153 lines (152 loc) • 11.6 kB
import type { RunInternals } from "./runner/contracts.js"; import type { EngineNotice } from "./engine-notice.js"; import type { ModFrame, ModOrigin } from "./mods/kernel/index.js"; import type { AssertAllKeysHandled } from "./ask-origin.js"; export declare const INPUT_AUTHORS: readonly ["operator", "parent_model", "workflow", "peer", "observer", "engine", "extension"]; export type InputAuthor = (typeof INPUT_AUTHORS)[number]; /** Membership test for {@link InputAuthor}. */ export declare function isInputAuthor(v: unknown): v is InputAuthor; /** * Does this input text say nothing? The ONE reading of "empty" on the input path: the harness's no-op for an empty injection, * the steer verb's own bookkeeping of it, the three frames' blank passthrough and `$.prompt.submit`'s door all ask this, so the * person's steer and an extension's prompt are never judged by two definitions. A text is blank when it holds only whitespace * (`\s`) and control characters (`\p{Cc}`: C0, DEL, C1) — a text with any other code point says something, whatever else * surrounds it (a zero-width or format character included: only control characters and whitespace are read as nothing). */ export declare function isBlankInput(text: string): boolean; /** * HRD-APV-4: the char cap on a steering text — the last persisted, model-facing string on a checkpoint row that had none * (`validatePendingSteer` enforces it on a parked operator steer, a parked reply's answer and entered text meet it, and a live * `{ reply }` at the prompt screen's door meets the same one: {@link steeringTextDefect}). * * Sized as an INSTRUCTION budget, not a preview budget: the siblings above cap echo-only projections at * 200/512 chars, while a steer is prose a human wrote for the model to act on and is re-delivered on * every resume of the checkpoint. 16k chars (~4k tokens) holds any realistic operator instruction and * still bounds the durable row and the per-resume context cost. Exported (from the checkpoint store's module as before) so a BFF * can validate before it calls `CheckpointStore.setPendingSteer` rather than discovering the reject at persist time. */ export declare const MAX_PENDING_STEER_CHARS = 16000; /** The C0/DEL control-character class every persisted steering string is rejected on — ONE pattern home * for the text half and the actor labels (the in-memory backend stores a NUL fine, Postgres text/jsonb * refuses it, so a steer that persisted on one backend would fail on the other). Ordinary `\t`/`\n`/`\r` * whitespace is deliberately allowed. */ export declare const STEERING_CONTROL_CHARS_RE: RegExp; /** Why a steering text may not be persisted or entered: it carries a system-reminder break-out tag, a control character, or is * longer than {@link MAX_PENDING_STEER_CHARS}. */ export type SteeringTextDefect = "break_out_tag" | "control_chars" | "too_long"; /** * THE judgment of a steering text's content — the text half every persisted steering string meets (`validatePendingSteer`'s * text and a parked reply's answer and entered text) and a live `{ reply }` meets at the prompt screen's door: the same payload * is accepted or refused the same way whether the leg is running or parked. The first defect in the order the persist-time * checks run: a break-out tag (the canonical neutralizer changes the text IFF it carries one), a C0 / DEL control character * (ordinary `\t` `\n` `\r` allowed), a length over the bound. `undefined` = none. Blankness ({@link isBlankInput}) and type are * the caller's. Format characters (bidi marks, zero-width) are not defects: only control characters, the break-out tag and the bound. */ export declare function steeringTextDefect(text: string): SteeringTextDefect | undefined; /** The defect as a clause a refusal sentence reads ("a reply that contains …"). */ export declare function steeringTextDefectClause(defect: SteeringTextDefect): string; /** An author as read: a member of the set, or `unknown` for anything else. */ export type InputAuthorReading = InputAuthor | "unknown"; /** The one reader: a member reads as itself, anything else (`undefined` included) as `unknown`. */ export declare function readInputAuthor(raw: unknown): InputAuthorReading; /** How the model reads an input that arrives mid-run: `person` — the person's mid-turn frame (a trusted caller's reminder); * `extension` — the extension's frame, naming the extension; `verbatim` — the text as the relay hands it (an observer's * report already carries its own envelope). */ export type InputFrame = "person" | "extension" | "verbatim"; /** One word's row: the three facts the module header names. */ interface AuthorRow { readonly screened: boolean; readonly countsAsOperator: boolean; readonly frame: InputFrame; } /** The table, one row per member (a new word does not compile without its row). */ declare const AUTHOR_ROWS: { readonly [A in InputAuthor]: AuthorRow; }; /** The table's fence (docs/CLOSED-SETS.md): `never` while every author has a row. */ export type AuthorTableCoversEveryAuthor = AssertAllKeysHandled<Exclude<InputAuthor, keyof typeof AUTHOR_ROWS>>; /** The word a reading is judged as: a member as itself, `unknown` as the operator's (the row it reads). */ export declare function judgedAuthorOf(reading: InputAuthorReading): InputAuthor; /** Does this input count as the operator's — carried across a pause, on the person's undelivered-input account, past the hold * of a run a person stopped? Only the operator's words do (an unreadable word reads as theirs). */ export declare function countsAsOperator(reading: InputAuthorReading): boolean; /** Does the prompt screen judge this input at the door it enters? The operator's words and an extension's are screened. */ export declare function isScreened(reading: InputAuthorReading): boolean; /** How the model reads this input when it arrives mid-run ({@link InputFrame}). */ export declare function inputFrameOf(reading: InputAuthorReading): InputFrame; /** * The objective's author on a leg, from the trusted channel's word (`RunInternals.objectiveAuthor`): absent is the public * entry's own mint, `operator` — the host that called `runTask` wrote the objective or relays the person who did; a member is * itself; anything else is `unknown`, screened like the operator's, and its sentence is handed to `onUnreadable` (the caller * reports it once). */ export declare function objectiveAuthorOf(declared: unknown, onUnreadable: (error: Error) => void): InputAuthorReading; /** The trusted channel of a recipe's continuation leg — the one mint of `engine`: a fresh shallow copy of the internals the leg rides * otherwise, its objective the recipe's own words (the caller's request rode the recipe's first leg). A composition whose later legs * re-run the caller's objective (a cascade's rungs) does not call it. */ export declare function recipeContinuationLeg(internals: RunInternals | undefined): RunInternals; /** What the engine's relay is told beside the text, for an input an extension's `$.prompt.submit` call hands it: the call's * `frames` and `origin` (the prompt screen is raised under them, so the caller's own handlers stay out of it), the calling * registration's name (`extension`) and the call's cancel. Absent for the observer's report. */ export interface AuthoredRelayCall { readonly frames: readonly ModFrame[]; readonly origin: ModOrigin; readonly extension: string; /** The door's tier: an extension's prompt waits for the leg's would-otherwise-stop seat (CC `hWe = "later"`). */ readonly priority: "later"; readonly signal?: AbortSignal; } /** The relay's answer, decided when the input is taken (never when it is read): the text that entered the leg — the caller's, * or the prompt screen's rewrite of it —, the answer the prompt screen already gave it (`replied`: it entered, and the turn it * opens is that answer, no model asked), or why it did not enter. */ export type AuthoredRelayAnswer = { readonly entered: string; } | { readonly replied: string; } | { readonly drop: string; }; /** * The engine's own relay into a running stream's steer lane, under the author it states. The public `TaskStream.steer` mints * `operator` on every call; this seat is how the engine hands a stream an input someone else wrote (an observer's report, an * extension's prompt). It lives on the stream object the Runner minted — registered here, never on the package face — so no * caller can name an author. Every refusal the verb answers (the run not live, the hold of a stopped run, the screen's) is a * `drop`; a fault the verb does not answer rejects. */ export type AuthoredSteer = (author: InputAuthor, text: string, call?: AuthoredRelayCall) => Promise<AuthoredRelayAnswer>; /** Where a leg's loop stands for an input: `before` — the loop is not taking input and has not ended: the run is starting (an * injection would wait out the birth window), or, for an instant, the loop's last prompt has settled and its end is not yet * recorded (`open` reads `before` there, and an input finds no boundary); `open` — it takes input; `over` — it will take no more. */ export type InputWindow = "before" | "open" | "over"; /** The stream's relay as the leg's `$.prompt.submit` entry reaches it: the relay, and the one fact the relay's birth-window * wait reads ({@link InputWindow}) — the entry refuses a call that would wait on the leg it is called from. */ export interface PromptSubmitSeat { readonly relay: AuthoredSteer; readonly inputWindow: () => InputWindow; } /** `$.prompt.submit`'s binding, minted by the stream layer once per stream and filled with that stream's own relay; the leg's * entry reads it at call time (unfilled ⇒ the call is dropped). Handed down the leg's prepare as a parameter, never inside the * run's internals — those are copied into a child's snapshot, and a child's prompt is never its parent's. */ export interface PromptSubmitRef { seat?: PromptSubmitSeat; } /** Register the authored steer of a stream the Runner minted (the driver calls this once per stream). */ export declare function bindAuthoredSteer(stream: object, steer: AuthoredSteer): void; /** The authored steer of a stream the Runner minted; `undefined` for any other object. */ export declare function authoredSteerOf(stream: object): AuthoredSteer | undefined; /** The terminal account's sentence for inputs of other authors a run accepted and never delivered: they are dropped, never * carried across a pause and never counted as the person's (the caller hands it to `onError` once, `phase: "degraded"`). * This is the operator's face of the loss; {@link droppedInputsNotice} is the person's. */ export declare function droppedInputsDisclosure(authors: readonly InputAuthor[]): Error; /** The routing keys a dropped-input notice carries: the leg's notice address (`NoticeAddress`) and its run, and the leg's task. */ export interface DroppedInputsWhere { readonly sessionId: string; readonly sourceSessionId?: string; readonly agentId?: string; readonly taskId?: string; readonly runId: string; } /** The person's face of the same loss (`task.undelivered_input_dropped`): how many inputs each other author wrote that the leg * ended without reading. `detail.authors` counts per author; the keys are where the leg's notices go. */ export declare function droppedInputsNotice(authors: readonly InputAuthor[], where: DroppedInputsWhere): EngineNotice; export {};