UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

47 lines (46 loc) • 2.64 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 { onMessageUpdate: (event: Extract<AgentHarnessEvent, { type: "message_update"; }>) => void; onMessageEnd: (event: Extract<AgentHarnessEvent, { type: "message_end"; }>) => void; onToolStart: (event: Extract<AgentHarnessEvent, { type: "tool_execution_start"; }>) => void; onToolEnd: (event: Extract<AgentHarnessEvent, { type: "tool_execution_end"; }>) => void; onTurnEnd: () => void; /** The single workspace_changed mint (cwd diff vs the closure's dedupe state); 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 处)。`lastWorkspaceCwd` 是纯 R5 局部(读写全在 onToolEnd 内,零段外 * 读者),声明随迁进工厂体——调用点放在原声明位之后,初值 `prepared.cwdRef?.current` 的求值时机不变 * (中间只有声明无执行)。*/ export declare function createHarnessHandlers(input: RunHarnessHandlersInput): RunHarnessHandlersResult;