UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

49 lines (48 loc) • 3.77 kB
import { type ModBottomContext, type ModBus } from "./kernel/index.js"; import type { ExtensionRequester } from "../task-event.js"; /** Which `$` call made the record: the door the extension came through. */ export type ExtensionDoor = "tool.call" | "agent.spawn"; /** One extension's call while it runs. */ export interface ExtensionCall { /** The leg bus the call was made on (the one {@link legBusOf} returned). */ readonly bus: ModBus; readonly toolCallId: string; /** The door: an extension's spawn is a record made by `$.agent.spawn` — a tool an extension calls through `$.tool.call` that * runs the delegation inside its own body hands the delegation a tool call's record, and the delegation runs as it would * for the model. */ readonly door: ExtensionDoor; /** The `$` call's context: the frames its pipeline's events are raised under, and its origin. */ readonly caller: ModBottomContext; /** Cleared when the call's pipeline settles — the one reading of "this call is still running". */ readonly live: boolean; /** The call's end projection refused it (its latest gate record is a refusal) — written once, by the leg's tool_end station. */ readonly denied: boolean; /** The subagent the call started (`$.agent.spawn`): its id and the model it was let start on — written once, by the delegation * tool where it lets the subagent run; absent ⇒ none started (the call's result is never read for it). */ readonly launched?: { readonly agentId: string; readonly model: string; }; } /** The running extension call this chain carries for `bus`, when it is the call `toolCallId` names (or any, unnamed). */ export declare function extensionCallOf(bus: object, toolCallId?: string): ExtensionCall | undefined; /** Does `toolCallId` have a park route on its leg: the leg's park closure exists and the call is not the running extension call (its * caller is an `await` a park would outlive). Read by the gate station (it hands the closure only then) and a delegated leg's fold. */ export declare function callParkRoute(legParks: boolean, bus: object, toolCallId: string): boolean; /** Who asked for the call `toolCallId` names, when it is the running extension call: the one projection every carrier of * `requestedBy` reads (the occurrence the frames are projected from, the approval card). */ export declare function requesterOf(bus: object, toolCallId: string): { readonly requestedBy?: ExtensionRequester; }; /** The leg's tool_end station says the call it is closing was refused (a no-op for any call that is not the running extension call). */ export declare function noteExtensionCallDenied(bus: object, toolCallId: string): void; /** The delegation tool says the extension's spawn it is running started its subagent (a no-op for any other call). */ export declare function noteExtensionCallLaunched(bus: object, toolCallId: string, launched: NonNullable<ExtensionCall["launched"]>): void; /** Run an extension's call: `pipeline` runs with the call's record in scope; the record stops being live when it settles. */ export declare function runExtensionCall<T>(bus: ModBus, toolCallId: string, door: ExtensionDoor, caller: ModBottomContext, pipeline: (call: ExtensionCall) => Promise<T>): Promise<T>; /** * The leg bus every station raises on: a dispatch inside a running extension call made on it is raised under that call's * frames and origin (a raiser that names its own frames keeps them — they extend the call's); one raised under a call * that has settled is refused, `failed` by the engine and said once on `report`; any other dispatch is the bus's own. */ export declare function legBusOf(bus: ModBus, report: (err: Error) => void): ModBus;