import type { ModelMessage } from "ai"; import type { AlsContext } from "#context/container.js"; import { type HarnessModelMessage } from "#harness/messages.js"; import { type Publish, type Transition } from "#harness/session-machine/commit.js"; import { type StepProjection } from "#harness/session-machine/current.js"; import { type SessionView, type TurnPosition } from "#harness/session-machine/view.js"; import type { HarnessEmitFn, HarnessSession, StepFn, StepInput, StepResult, ToolLoopHarnessConfig } from "#harness/types.js"; import type { InstrumentationStepScope } from "#instrumentation/runtime.js"; import type { createHistoryViewPreparer } from "#shared/history-view.js"; type HistoryViewPreparer = ReturnType; /** * One harness step: the session it changes, and the machine it changes the session through. * Every lifecycle change goes through `apply`, which publishes the transition's events and saves * what it changed; `position` reads where those events left the session. */ export interface Step { session: HarnessSession; frameworkToolNames: ReadonlySet; readonly config: ToolLoopHarnessConfig; /** The step's context; direct harness tests may run without one. */ readonly ctx: AlsContext | undefined; readonly runStep: StepFn; readonly publish: Publish; /** The caller's event handler. Without one, a failure throws instead of being reported. */ readonly emit: HarnessEmitFn | undefined; readonly instrumentation: InstrumentationStepScope | undefined; /** A child's caller or a schedule hears only the turn's real end. */ readonly hasDelegatedCaller: boolean; view(): SessionView; position(): TurnPosition; apply(transition: Transition, messages?: readonly ModelMessage[]): Promise; /** History as the model and hooks see it, under `state`, the session's by default. */ projectHistory(messages: readonly ModelMessage[], state?: HarnessSession["state"]): readonly ModelMessage[]; } export declare function createStep(input: { readonly config: ToolLoopHarnessConfig; readonly ctx: AlsContext | undefined; readonly emit: HarnessEmitFn | undefined; readonly instrumentation: InstrumentationStepScope | undefined; readonly live: StepProjection; readonly prepareHistory: HistoryViewPreparer; readonly publish: Publish; readonly runStep: StepFn; readonly session: HarnessSession; }): Step; /** * Opens the turn, or joins the open one, with the preamble its hooks prepare: memory recall and * dynamic instructions join history ahead of the turn's input. Returns the step's result when the * preamble failed the session. */ export declare function openTurn(step: Step, opened: { readonly input: readonly HarnessModelMessage[]; readonly message?: StepInput["message"]; }): Promise; /** * A lifecycle event failed to publish: a dynamic model selection failure ends the session, and a * dynamic connection resolver failure parks it. Anything else throws. */ export declare function failBoundaryEvent(step: Step, error: unknown): Promise; /** A dynamic connection resolver threw: the session parks so the next message can retry. */ export declare function failConnectionResolution(step: Step, error: unknown): Promise; /** No model can serve the turn: the session fails. */ export declare function failModelSelection(step: Step, error: unknown): Promise; export {};