UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

50 lines (49 loc) • 3.07 kB
import { type EngineNotice } from "../engine-notice.js"; import type { ExecutionEnv } from "../../internal/harness.js"; import type { RemoteEnvFailureNote } from "../types.js"; /** What a leg hands {@link legWorkspaceSync}. */ export interface LegWorkspaceSyncInput { /** The env the leg works in: its own (`ownedEnv`) or the deployment's static one. */ env: ExecutionEnv | undefined; sessionId: string; runId?: string; /** The deployment's notice seat (`RunnerDeps.onNotice`). */ onNotice: ((notice: EngineNotice) => void) | undefined; /** The run's lifecycle failure record (`TaskResult.remoteEnvFailures`), written while the run's result is still open. */ remoteEnvFailures: RemoteEnvFailureNote[]; /** The run's cut: a turn's end waits no longer than it stays unaborted. */ runSignal: AbortSignal; } /** The leg's sync seat, reached by the harness's turn watch, the park points and the leg's teardown. */ export interface LegWorkspaceSync { /** A turn opened (the harness's `noteTurnOpened`): the stretch since the last sync has work in it. */ turnOpened(): void; /** * The agent would otherwise stop (drain point B): `turn_end`, once per stretch — a second arrival with no turn between is not a * call. A sync the adapter did not answer (its bound, the run's cut, not made — a run already cut on arrival makes no call) * leaves the stretch owed to the leg's end. */ turnEnded(): Promise<void>; /** A durable park is about to suspend the workspace or capture its identity: `turn_end`, waited for no longer than `cut`. */ parking(cut: AbortSignal): Promise<void>; /** * The leg's end, after its result was handed out (so a failure is told, not recorded): `destroy` before its env is destroyed * (`destroying`), else `turn_end` when the stretch is not synced (a turn ran since the last sync, or that sync was not answered). * Not called for a parked leg (its park synced). Waits `boundMs` at most and never for the run's cut (the run is over): the * adapter gets one whole chance, so on an env the engine does not destroy, `result()` and the session lock can come that much * after `done`. */ legEnded(destroying: boolean, boundMs: number): Promise<void>; } /** The sync seat of a leg whose env is `input.env`, or `undefined` when that env carries none (nothing is installed, nothing called). */ export declare function legWorkspaceSync(input: LegWorkspaceSyncInput): LegWorkspaceSync | undefined; /** * `Runner.rewindFiles`' sync of the env it rewrote (a rewind that moved a file), at its end — the rewind is one stretch of work, * read as a leg's end is: `destroy` when the env is destroyed next, else `turn_end`. Waited for at most `boundMs`; a failure is * told. Out of any run: there is no result to record it on. */ export declare function syncAtRewindEnd(env: ExecutionEnv, destroying: boolean, input: { sessionId: string; onNotice: ((notice: EngineNotice) => void) | undefined; boundMs: number; }): Promise<void>;