UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

53 lines (52 loc) • 3.13 kB
/** * The run body's CLOCK and CONTENT seats (R6), verbatim from `Runner.runLocked`: the per-slice * walltime window and its MONOTONIC deadline anchored at task start, the hard-abort timer armed against that same * deadline (a suspendable task gets the backstop grace), the content-event push that also forwards a sub-agent's * events to the parent's display sink, the run's own committed-tail ref and the `message_committed` mint that * retires a settled tool call from the started set. */ import type { PushQueue } from "../push-queue.js"; import type { TaskEvent, TaskSpec } from "../types.js"; import { startTimeout } from "./clock-and-limits.js"; import type { Prepared, RunInternals, RunState } from "./contracts.js"; export interface RunClockAndContentInput { /** borrowed-readonly — the task spec: `limits.maxWalltimeMs`. */ spec: TaskSpec; /** borrowed-readonly — the leg's prepared seat: the harness and abort controller the timer is armed against, the * resource-suspend eligibility. */ prepared: Prepared; /** borrowed-mutable — the run's event queue: content events and `message_committed` frames. */ queue: PushQueue<TaskEvent>; /** borrowed-readonly — the trusted run-scoped channel: `onForwardEvent` (the parent's display sink). */ internals: RunInternals | undefined; /** borrowed-mutable — the run's mutable state: `counters.walltimeSyncBackstopFired` is zeroed here; the monotonic * task-start anchor is read. */ rs: RunState; /** borrowed-readonly — the run's event-identity mint (stamped on every committed frame). */ ident: () => { eventId: string; parentToolCallId?: string; sourceTaskId?: string; }; /** borrowed-readonly — the spawning tool call's id when this task runs AS A SUB-AGENT; forwarding is gated on it. */ parentToolCallId: string | undefined; /** borrowed-mutable — the tool-mount lane's started-call set: a committed toolResult retires its id here. */ startedToolCallIds: Set<string>; } export interface RunClockAndContentResult { /** The PER-SLICE active clock, or undefined (0 is a valid, exhausted window). */ effectiveTimeoutMs: number | undefined; /** The monotonic deadline every walltime enforcement decision reads, or undefined. */ walltimeMonotonicDeadline: number | undefined; /** The hard walltime backstop: its fired flag / lateness, and the clear the teardown calls. */ timeout: ReturnType<typeof startTimeout>; /** Push a content event to the run's queue and, for a sub-agent, to the parent's display sink. */ pushContent: (e: TaskEvent) => void; /** The id of the LAST entry this run committed — the settle-time seal's provenance anchor. */ ownCommittedTailRef: { current: string | undefined; }; /** The `message_committed` mint every persisted entry of this run flows through. */ emitCommitted: (entryId: string, role: "user" | "assistant" | "toolResult", toolCallId?: string) => void; } export declare function runClockAndContent(input: RunClockAndContentInput): RunClockAndContentResult;