import type { ModelMessage, UserContent } from "ai"; import type { SubagentAuthorizationEventHookPayload, SubagentInputRequestHookPayload } from "#channel/types.js"; import type { AuthorizationChallenge } from "#harness/authorization.js"; import { type TurnWaitingOn, createSessionCompletedEvent, createSessionFailedEvent, type InputResolution, type RuntimeIdentity, type RuntimeTraceContext, type SessionPredecessor, type TaskCancelReason, type TaskStartedStreamEvent, type UnstampedMessageStreamEvent } from "#protocol/message.js"; import type { RuntimeActionResult } from "#shared/action-types.js"; import type { InputRequest } from "#shared/input.js"; import type { JsonObject, JsonValue } from "#shared/json.js"; import type { TokenUsage } from "#shared/token-usage.js"; import type { Transition } from "./commit.js"; import type { StepCoordinates, SuspendedStep, TurnState } from "./state.js"; import { type SessionView } from "./view.js"; type ToolResponsePart = Extract["content"][number]; export type ToolResultPart = Extract; /** * Input arrives: the session starts once, a turn opens unless one is open (steering joins it), * and a message is received. */ export declare function receive(view: SessionView, input: { readonly message?: string | UserContent; /** The session this one replaced, when eve started it in place of a stranded one. */ readonly predecessor?: SessionPredecessor; readonly runtime?: RuntimeIdentity; readonly trace?: RuntimeTraceContext; }): Transition; /** The open turn calls the model. */ export declare function startStep(view: SessionView, input: { readonly modelId: string; }): Transition; /** * The open turn parks: on `"tasks"` while work it started runs, on `"input"` while a person must * act on a sign-in, approval, or question. It resumes in the same turn. */ export declare function hold(view: SessionView, input: { readonly on: TurnWaitingOn; }): Transition; /** Nothing is left to run: the turn completes, with its structured result when it has one. */ export declare function finishTurn(view: SessionView, input?: { readonly result?: JsonValue; }): Transition; /** * The step failed. A recoverable failure parks the session for the user to retry; a terminal * one ends it. */ export declare function fail(view: SessionView, failure: { readonly code: string; readonly details?: JsonObject; readonly message: string; readonly terminal?: { readonly sessionId: string; }; }): Transition; /** The session waits for its next delivery. */ export declare function idle(view: SessionView): Transition; export declare function sessionCompleted(usage: TokenUsage | undefined): ReturnType; export declare function sessionFailed(input: { readonly code: string; readonly details?: JsonObject; readonly message: string; readonly sessionId: string; readonly usage: TokenUsage | undefined; }): ReturnType; /** One call's result, ready for its step's transcript. */ export interface SettledCall { readonly part: ToolResultPart; /** A runtime result, reported at the coordinates of the step that made the call. */ readonly result?: RuntimeActionResult; } /** * Results reach the steps that made their calls. A step whose every call now has a result * commits to history, where the model reads it. */ export declare function settle(view: SessionView, input: { readonly results: readonly SettledCall[]; }): { commit: ModelMessage[]; events: UnstampedMessageStreamEvent[]; turn: { queued?: import("../types.ts").StepInput; grants: readonly string[]; suspended: SuspendedStep[]; }; }; /** A call a discarded model-call attempt announced without a result. */ export interface DiscardedCall { readonly callId: string; readonly toolName: string; } /** * A model-call attempt failed and the step retries it. The calls the attempt announced never * ran, so each settles as failed before the replacement attempt streams. Nothing reaches * history: the discarded response was never committed. */ export declare function discardAttempt(view: SessionView, input: { readonly calls: readonly DiscardedCall[]; }): Transition; /** * A model response made calls the runtime runs. The response waits in a suspended step until * every call it made has a result, so a call never reaches the model without its result. */ export declare function suspendStep(view: SessionView, step: Pick): Transition; /** The step without the approved calls in `callIds`, which have run or joined the runtime. */ export declare function withoutApproved(step: SuspendedStep, callIds: ReadonlySet): SuspendedStep; /** Approved calls of suspended steps that haven't run. */ export declare function approvedCalls(turn: TurnState): readonly InputRequest[]; export declare function suspend(turn: TurnState, step: SuspendedStep): TurnState; /** The ids of the calls a step's response made, except provider-executed ones. */ export declare function stepCallIds(step: Pick): ReadonlySet; /** * Places a result right after the message that made its call, under the call's name: a call * made through `eve__tool` or `eve__skill` keeps that name in history, whatever entry it ran. */ export declare function withResult(messages: readonly ModelMessage[], result: ToolResultPart): ModelMessage[]; /** A call started or reached a task. */ export declare function startTask(view: SessionView, task: TaskStartedStreamEvent["data"]): Transition; export type TaskCallOutcome = { readonly status: "completed"; readonly output?: JsonValue; } | { readonly status: "failed"; readonly error: string; } | { readonly status: "cancelled"; readonly reason?: TaskCancelReason; }; /** A task's run settled calls: each reports its outcome, naming the task as it started. */ export declare function settleTask(view: SessionView, input: { readonly task: { readonly id: string; readonly kind?: TaskStartedStreamEvent["data"]["kind"]; readonly name?: string; }; readonly calls: readonly { readonly callId: string; readonly turnId: string; }[]; readonly outcome: TaskCallOutcome; }): Transition; /** * A task or workflow run ended, on its own or cancelled: nobody can answer what it relayed, so * each request still open is withdrawn. */ export declare function finishRun(view: SessionView, run: { readonly taskId?: string; readonly requestIds?: Iterable; }): Transition; /** * A child session or workflow run asks a question or for a sign-in. The session passes it up * with its original coordinates, and the open turn waits on the call it serves. * A child's fresh batch replaces its earlier one, whose open requests are withdrawn. */ export declare function relay(view: SessionView, input: { readonly payload: SubagentInputRequestHookPayload | SubagentAuthorizationEventHookPayload; readonly replacedRequestIds?: Iterable; }): Transition; /** * Answers to relayed requests are on their way to the asker: each request resolves here. */ export declare function receiveRelayedAnswer(input: { readonly message: string | UserContent; readonly sequence: number; readonly turnId: string; }): import("#protocol/message.js").MessageReceivedStreamEvent; export declare function routeAnswer(view: SessionView, input: { readonly children: readonly { readonly event: StepCoordinates; readonly resolutions: readonly InputResolution[]; }[]; }): Transition; /** * A workflow run's sign-in, reported to the session that owns the run, which relays it. Built * where the run asks, at the coordinates of the call it serves. */ export declare function runSignIn(from: { readonly sequence: number; readonly stepIndex: number; readonly taskId?: string; readonly turnId: string; }, challenge: AuthorizationChallenge, outcome?: "authorized" | "failed"): import("#protocol/message.js").AuthorizationCompletedStreamEvent | import("#protocol/message.js").AuthorizationRequiredStreamEvent; /** Sign-in callbacks arrived: each completion is reported at the coordinates of the turn that asked. */ export declare function completeSignIn(view: SessionView, input: { readonly completions: readonly AuthorizationChallenge[]; }): Transition; /** Requests this session asked itself and still awaits; relayed requests answer elsewhere. */ export declare function ownOpenRequestIds(view: Omit): ReadonlySet; /** What the model reads for a call its turn's cancellation stopped before the call settled. */ export declare const CANCELLED_CALL_RESULT = "The turn was cancelled before this call finished."; /** * `session.cancel()`: the open turn ends cancelled. Its requests, its sign-ins, and every * relayed request are withdrawn, since the cancel stops the work that asked them; its unsettled * calls are stopped. The steps it ran commit to history, each unfinished call answered as * cancelled, so the model sees that the work started and stopped. */ export declare function cancel(view: SessionView): Transition; /** * `session.clear()`: everything the cleared history asked for is withdrawn, its approvals and * the session-limit prompt and every sign-in, and the calls awaiting them stop. Requests relayed * from live tasks stay: clearing doesn't stop the work that asked them. */ export declare function clear(view: SessionView, input: { readonly sessionId: string; }): Transition; export {};