@sema-agent/core
Version:
Stateless, task-oriented AI agent core
27 lines (26 loc) • 2.17 kB
TypeScript
import type { HookProgressSubject, TaskEvent, TaskEventIdentity } from "../task-event.js";
import type { UserPromptSubmitEvent } from "../hooks.js";
import type { ToolOccurrenceTable } from "./tool-occurrence.js";
/** The leg's lane: minted at prepare, bound to the run's content pusher by the run body, closed at the leg's end. */
export interface HookProgressLane {
/** Run `screen` as one screening of `subject`: its `start` frame once it has lasted one interval and the lane is bound, its
* `end` when it settles (only after a `start`). Returns `screen`'s own value, settled the same way. */
screened<T>(subject: HookProgressSubject, screen: () => Promise<T>): Promise<T>;
/** The run body's content pusher and identity now exist: every screen already due and still running is announced now. */
bind(push: (e: TaskEvent) => void, ident: () => TaskEventIdentity): void;
/** The leg ends: every screen whose `start` went out and that has not settled is ended now, and the lane frames nothing more. */
close(): void;
}
export declare function createHookProgressLane(): HookProgressLane;
/** The prompt screen's subject at one entrance: its `source`, and the input's id when the entrance has one. */
export type PromptScreenSubject = Pick<UserPromptSubmitEvent, "source" | "inputId">;
/** The leg's one seat for its two decision screens. Built at prepare — where the gate and the prompt entrances are wired — over
* the leg's lane, which the run body binds later (a screen that comes due before the bind is announced at it). */
export interface HookScreenSeat {
/** A `classic.PreToolUse` screening of `toolCallId`: the call is held at its gate (`tool_progress.gate: "hook"`) and the
* screen framed, for as long as `screen` runs. */
call<T>(toolCallId: string, screen: () => Promise<T>): Promise<T>;
/** A prompt's screen at one entrance (nothing to hold: there is no call), framed for as long as `screen` runs. */
prompt<T>(subject: PromptScreenSubject, screen: () => Promise<T>): Promise<T>;
}
export declare function createHookScreenSeat(occurrences: ToolOccurrenceTable, lane: HookProgressLane): HookScreenSeat;