UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

79 lines (78 loc) • 5.69 kB
/** * THE RULE. `classic.Stop` / `classic.SubagentStop` and the teammate events (`classic.TaskCreated`, `classic.TaskCompleted`, * `classic.TeammateIdle`) take one answer form ({@link StopHookResult}) and one judge ({@link judgeStopFamily}): each seat in its own * pass, task then deployment; a deployment answer carrying a decision word (`end`, a non-empty `block`) decides alone, else the two * fold (`mergeStopAnswers`). A seat with no handler is not raised; a failing chain or a rejected dispatch leaves its seat silent; a * cancel ends the judgement. The teammate events are raised on the leg that acts (the reference's `teammateName` (cli321.js:293757)): * `classic.TaskCreated` once `TaskCreate`'s row landed, `classic.TaskCompleted` before `TaskUpdate` marks a task completed — in a * call only a non-empty `block` acts, refusing it ({@link createTaskStations}) — and, where a named teammate's stop event let it stop, * `classic.TaskCompleted` per task it holds in progress, then `classic.TeammateIdle` ({@link teammateStopPass}), answering as the stop * event would on its consecutive count and cap. */ import type { HookInvocationIdentity, StopHookResult } from "../hooks.js"; import type { PermissionMode } from "../ask-origin.js"; import type { ClassicEventMap } from "./classic-events.js"; import type { ModSeat } from "./kernel/index.js"; import { type LegModBus } from "./stations.js"; /** The events judged by {@link judgeStopFamily}. */ export type StopFamilyEvent = "classic.Stop" | "classic.SubagentStop" | "classic.TaskCreated" | "classic.TaskCompleted" | "classic.TeammateIdle"; /** One judgement: the folded answer, and — exactly when it carries `end` — the seat and registration whose answer carried it. * `taskContinueDropped`: the deployment seat's `end` decided alone while the task seat's own answer asked to continue (a * non-empty `block` or `additionalContext`) — that request was dropped. */ export interface StopFamilyVerdict { readonly answer: StopHookResult; readonly ended?: { readonly seat: ModSeat; readonly registration?: string; readonly taskContinueDropped?: true; }; } /** Judge one raise of a stop-family event over both seats ({@link StopFamilyVerdict}), or `"aborted"` once the leg is cancelled. */ export declare function judgeStopFamily<K extends StopFamilyEvent>(bus: LegModBus, event: K, e: ClassicEventMap[K]["e"], signal: AbortSignal | undefined, report: (err: Error) => void): Promise<StopFamilyVerdict | "aborted">; /** The word a stop-family event's texts name it by: the two stop events speak as `Stop` (CC's own stop feedback). */ export declare function stopFamilyWord(event: StopFamilyEvent): string; /** The model-readable text of a `block` (a push-back's reason, a task tool's refusal): the reference's one form for the * four events, `<event> hook feedback:` and the reason on the next line (`a$r` / `DOo`, cli321.js B[10650520,10650646)), * the reason's `<` written `&lt;` as the reference writes it there (#5315, measured on the reference's own binary; `>` stays), so a * reason cannot open or close a tag in the frame it rides. */ export declare function stopFamilyBlockText(event: StopFamilyEvent, reason: string): string; /** The model-readable text of an `additionalContext` fed back at a stop point. */ export declare function stopFamilyContextText(event: StopFamilyEvent, context: string): string; /** A task as the teammate events name it. */ export interface TaskHookFacts { readonly id: string; readonly subject: string; readonly description: string; } /** The leg's facts every teammate event is built from. */ export interface TeammateStationInput { readonly bus: LegModBus; readonly identity: HookInvocationIdentity | undefined; readonly permissionMode: () => PermissionMode | undefined; /** Where a rejected dispatch (an engine fault, never a handler's) is said. */ readonly report: (err: Error) => void; } /** The task tools' two events, as a task tool reads them (a Runner-filled seat, never a model argument). */ export interface TaskStations { /** Whether a handler of either seat hangs on the event (none ⇒ the tool raises nothing and awaits nothing). */ listens(event: "classic.TaskCreated" | "classic.TaskCompleted"): boolean; /** Raise the event over one task: the call's refusal text when the answer carries a non-empty `block` (or, for `TaskCompleted`, when * the leg was cancelled before an answer), else `undefined`. */ refusal(event: "classic.TaskCreated" | "classic.TaskCompleted", task: TaskHookFacts, signal: AbortSignal | undefined): Promise<string | undefined>; } /** The leg's task-tool stations over its bus. */ export declare function createTaskStations(input: TeammateStationInput): TaskStations; /** One teammate raise at the stop point, with its judgement. */ export interface TeammateRaise { readonly event: "classic.TaskCompleted" | "classic.TeammateIdle"; readonly verdict: StopFamilyVerdict; } /** * A named teammate's stop point: `classic.TaskCompleted` once per task it holds in progress (`held`, read only when a handler hangs * on the event), then `classic.TeammateIdle` — each judged by {@link judgeStopFamily}, in that order. `undefined` when the leg is no * named teammate or no handler hangs on either event (nothing is read and nothing raised); `"aborted"` once the leg is cancelled. */ export declare function teammateStopPass(input: TeammateStationInput & { readonly held: (owner: string) => Promise<readonly TaskHookFacts[]>; readonly signal: AbortSignal | undefined; }): Promise<readonly TeammateRaise[] | "aborted" | undefined>;