UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

53 lines (52 loc) • 2.99 kB
import type { AgentHarnessEvent } from "../../internal/harness.js"; import type { Stats } from "./assemble-result.js"; import type { HarnessHandlersDeps, Prepared, RunState } from "./contracts.js"; /** * What the driver hands the harness-handlers lane, once per leg — the four positional parameters the * factory used to take, as one carrier of REFERENCES (the handlers read the seats live on every event). */ export interface RunHarnessHandlersInput { /** borrowed-mutable — the leg's prepared seat. Read throughout; written only into one per-run ref cell * (`callIssuedAtRef.current`, cleared when the model's turn ends). */ prepared: Prepared; /** borrowed-mutable — the run's usage counters. This lane is their WRITER: the turn's usage lands on * them in onMessageEnd, tool calls and turns are counted in onToolStart / onTurnEnd. */ stats: Stats; /** borrowed-mutable — the run's mutable state; the handlers write the turn / counters / limits / * budget groups, per the writer table on the type. */ rs: RunState; /** borrowed-readonly — the driver-declared const seats + the runner's onError, see * {@link HarnessHandlersDeps}. */ deps: HarnessHandlersDeps; } /** The five harness event handlers + the workspace-move mint, as the driver destructures them. */ export interface RunHarnessHandlersResult { onMessageStart: (event: Extract<AgentHarnessEvent, { type: "message_start"; }>) => void; onMessageUpdate: (event: Extract<AgentHarnessEvent, { type: "message_update"; }>) => void; onMessageEnd: (event: Extract<AgentHarnessEvent, { type: "message_end"; }>) => Promise<void> | undefined; onToolStart: (event: Extract<AgentHarnessEvent, { type: "tool_execution_start"; }>) => void; onToolEnd: (event: Extract<AgentHarnessEvent, { type: "tool_execution_end"; }>) => void; onTurnEnd: (event: Extract<AgentHarnessEvent, { type: "turn_end"; }>) => void; /** A model turn began: `turn.start` (the loop awaits it before the turn's first request); `undefined` when unheard. */ onTurnStart: () => Promise<void> | undefined; /** What a settled call may owe the leg — its workspace-frame observation (`Prepared.workspaceFrame.observe`) and the relay of the environment's * late-declaration notice; the run body calls it after a resume's approved-call resolution, which bypasses onToolEnd. */ announceWorkspaceMove: () => void; } /** R5 抽取:runLocked 的五个 harness 事件处理器(onMessageUpdate/onMessageEnd/ * onToolStart/onToolEnd/onTurnEnd,~530 行)整块搬迁。正文逐字;唯一字面变化 = this.deps.onError → * deps.runnerHooks.onError(1 处)。工作区帧的去重状态住在腿的帧座(`Prepared.workspaceFrame`), * 工厂体不持有、也不在调用时读 cwd。*/ export declare function createHarnessHandlers(input: RunHarnessHandlersInput): RunHarnessHandlersResult;