import type { RunStats, StopReason, TranscriptMessage } from "../contracts/turn.js"; import type { ToolLoopState } from "./tool-loop.js"; /** A stopped invocation cannot be represented as a settled checkpoint. */ export declare class UnsettledLoopBoundaryError extends Error { constructor(); } /** A continuation point after the loop has finished all step bookkeeping. */ export type LoopPosition = { kind: "ready"; } | { kind: "waiting"; reason: "waiting_for_reply" | "resuming_later"; } | { kind: "finished"; reason: "done" | "iteration_limit" | "aborted"; }; export interface LoopBoundary { position: LoopPosition; iterationsUsed: number; state: ToolLoopState; /** Cumulative since invocation start, not a delta since the previous boundary. */ stats: RunStats; } /** * Persistence is awaited before more model/tool I/O. The state is borrowed: * capture a detached value before storing it. Throwing stops the driver. * Unsettled failures do not emit a boundary; reconcile effects before retrying. */ export interface LoopControl { iterationsUsed: number; onBoundary(boundary: LoopBoundary): Promise<"continue" | "checkpoint">; } export declare function positionForStop(reason: StopReason): LoopPosition; /** * An ordered protocol check, shared by initial history and checkpoint restore. * A waiting checkpoint may leave precisely its suspended call unanswered. * History is not provider input: a trailing assistant needs no synthetic turn. */ export declare function assertCheckpointTranscript(messages: readonly TranscriptMessage[], openCall: string | null): void;