import { type AgentInfoResult, type ConnectionAuthorizationOutcome, type InputRequest, Client, ClientSession } from "#client/index.js";
import type { AssistantResponseStatsMode, TerminalPartDisplayMode, TuiDisplayOptions } from "./types.js";
import { type TerminalInput, type TerminalOutput } from "./terminal-renderer.js";
export type AgentTUIStreamResult = {
    events: AsyncIterable<AgentTUIStreamEvent> | ReadableStream<AgentTUIStreamEvent>;
    abort?: () => void;
    turnState?: AgentTUITurnState;
};
export type AgentTUIStreamUsage = {
    inputTokens?: number;
    outputTokens?: number;
};
export type AgentTUIStreamEvent = {
    type: "step-start";
} | {
    type: "step-finish";
    usage?: AgentTUIStreamUsage;
} | {
    type: "assistant-delta";
    id: string;
    delta: string;
} | {
    type: "assistant-complete";
    id: string;
    text?: string | null;
} | {
    type: "reasoning-delta";
    id: string;
    delta: string;
} | {
    type: "reasoning-complete";
    id: string;
} | {
    type: "tool-call";
    toolCallId: string;
    toolName: string;
    input: unknown;
} | {
    type: "tool-approval-request";
    approvalId: string;
    toolCallId: string;
} | {
    type: "tool-result";
    toolCallId: string;
    output: unknown;
} | {
    type: "tool-error";
    toolCallId: string;
    errorText: string;
} | {
    type: "error";
    errorText: string;
    detail?: string;
} | {
    type: "finish";
    usage?: AgentTUIStreamUsage;
};
export type AgentTUITurnState = {
    boundaryEvent?: "session.completed" | "session.failed" | "session.waiting";
    pendingApprovals: AgentTUIToolApprovalRequest[];
    pendingQuestions: InputRequest[];
    sawSessionFailure: boolean;
};
export type AgentTUISessionOptions = {
    title?: string;
    submittedPrompt?: string;
    continueSession?: boolean;
    tools?: TerminalPartDisplayMode;
    reasoning?: TerminalPartDisplayMode;
    subagents?: TerminalPartDisplayMode;
    connectionAuth?: TerminalPartDisplayMode;
    assistantResponseStats?: AssistantResponseStatsMode;
    contextSize?: number;
};
export type AgentTUIToolApprovalRequest = {
    approvalId: string;
    toolCallId: string;
    toolName: string;
    title?: string;
    input: unknown;
};
export type AgentTUIToolApprovalResponse = {
    approved: boolean;
    reason?: string;
};
export type AgentTUIInputOption = {
    id: string;
    label: string;
    description?: string;
    style?: "primary" | "danger" | "default";
};
export type AgentTUIInputQuestion = {
    requestId: string;
    prompt: string;
    display: "select" | "text";
    options?: ReadonlyArray<AgentTUIInputOption>;
    allowFreeform?: boolean;
};
export type AgentTUIInputQuestionResponse = {
    optionId?: string;
    text?: string;
};
export type AgentTUIAgentHeader = {
    name: string;
    serverUrl: string;
    info?: AgentInfoResult;
};
export type AgentTUIRenderer = {
    /**
     * Commits a startup header describing the connected agent (brand mark,
     * model, instructions, tools, skills, subagents) to the transcript before
     * the first prompt, and refreshes it after local dev artifact changes.
     * Optional — renderers without a header simply skip it.
     */
    renderAgentHeader?(header: AgentTUIAgentHeader): void;
    /**
     * Commits a single dim informational line to the transcript. Used to
     * announce session recovery after a terminal server failure. Optional.
     */
    renderNotice?(text: string): void;
    readPrompt?(options?: AgentTUISessionOptions): Promise<string | undefined>;
    readToolApproval?(request: AgentTUIToolApprovalRequest, options?: AgentTUISessionOptions): Promise<AgentTUIToolApprovalResponse>;
    readInputQuestion?(question: AgentTUIInputQuestion, options?: AgentTUISessionOptions): Promise<AgentTUIInputQuestionResponse | undefined>;
    renderStream(result: AgentTUIStreamResult, options?: AgentTUISessionOptions): Promise<void>;
    /**
     * Out-of-band update for one child step (reasoning + message text) of a
     * subagent dispatch. Called by the runner as child-session stream events
     * arrive. The renderer renders this as a body section colored by the
     * subagent palette.
     */
    upsertSubagentStep?(update: SubagentStepUpdate): void;
    /**
     * Out-of-band update for one child tool call of a subagent dispatch.
     */
    upsertSubagentTool?(update: SubagentToolUpdate): void;
    /**
     * Registers a tool call id as originating from a subagent's child
     * session. The renderer must skip or remove parent-level tool blocks for
     * these ids — they are surfaced via {@link upsertSubagentTool} instead.
     */
    markChildToolCallId?(callId: string): void;
    /**
     * Out-of-band update for one MCP connection authorization lifecycle.
     * Called by the runner as `authorization.*` events arrive.
     * The renderer renders this as a persistent body section per
     * connection that transitions through `required` → `pending` →
     * one of the terminal `ConnectionAuthorizationOutcome` states.
     */
    upsertConnectionAuth?(update: ConnectionAuthUpdate): void;
    /**
     * Sets the number of connections currently awaiting an OAuth
     * callback. The renderer overrides its bottom status bar with a
     * "waiting for connection authorization" hint while this is > 0,
     * so the user understands the agent is parked, not hung.
     */
    setConnectionAuthPendingCount?(count: number): void;
    /**
     * Clears the rendered transcript and resets per-conversation display
     * state, leaving the UI interactive on a fresh screen. Used by the
     * `/new` command to start a new session with a clean slate.
     */
    reset?(): void;
    /**
     * Tears down interactive mode and restores the terminal, as if the user
     * pressed Ctrl+C. Used by the `/exit` command.
     */
    shutdown?(): void;
};
export type EveTUIRunnerOptions = TuiDisplayOptions & {
    session: ClientSession;
    /**
     * Optional client used to attach to child sessions for live subagent
     * stream observation. When omitted, the TUI still shows the subagent
     * section but cannot surface the subagent's reasoning / response /
     * intermediate events — only the parent-stream `called` and
     * `completed` transitions.
     */
    client?: Client;
    renderer?: AgentTUIRenderer;
    screen?: TerminalOutput;
    userInput?: TerminalInput;
    /**
     * Formats an error thrown while dispatching a turn (the initial
     * `session.send()` POST — e.g. a transport failure or a Vercel
     * Deployment Protection challenge) into the text rendered in the
     * inline error region. Defaults to the error's message. Callers that
     * know about transport-specific challenges (the `eve dev` glue) inject
     * a richer formatter here.
     */
    formatTransportError?: (error: unknown) => string;
    /**
     * Local `eve dev` server URL. When present, normal prompts refresh the
     * active session after HMR so the next prompt uses the latest authored
     * artifacts; input-response resumes keep the current session.
     */
    serverUrl?: string;
};
export declare class EveTUIRunner {
    #private;
    constructor(options: EveTUIRunnerOptions);
    run(): Promise<void>;
}
type SubagentChildStep = {
    reasoning: string;
    message: string;
    finalized: boolean;
};
type SubagentToolState = {
    toolName: string;
    input: unknown;
    status: "approval-requested" | "executing" | "done" | "failed";
    output?: unknown;
    errorText?: string;
};
export type SubagentRun = {
    name: string;
    /**
     * One entry per logical "child message" — independent of the child's
     * `stepIndex` field, which the harness can reuse across multiple
     * assistant messages within a turn (e.g. a message before a tool call
     * and another message after the tool result both arrive under
     * `stepIndex: 0`). The key is a monotonic counter so each
     * `message.completed` opens a new box on the next inbound delta.
     */
    steps: Map<number, SubagentChildStep>;
    /**
     * Section currently accepting reasoning/message deltas. `null` means
     * the next delta opens a new section.
     */
    currentSectionKey: number | null;
    /** Monotonic counter for new section keys. */
    nextSectionKey: number;
    tools: Map<string, SubagentToolState>;
};
export type SubagentStepUpdate = {
    callId: string;
    subagentName: string;
    sectionKey: number;
    reasoning: string;
    message: string;
    finalized: boolean;
};
export type SubagentToolUpdate = {
    callId: string;
    subagentName: string;
    childCallId: string;
    toolName: string;
    input: unknown;
    status: "approval-requested" | "executing" | "done" | "failed";
    output?: unknown;
    errorText?: string;
};
export type ConnectionAuthChallenge = {
    url?: string;
    userCode?: string;
    expiresAt?: string;
    instructions?: string;
};
export type ConnectionAuthState = "required" | "pending" | ConnectionAuthorizationOutcome;
export type ConnectionAuthUpdate = {
    name: string;
    description: string;
    state: ConnectionAuthState;
    challenge?: ConnectionAuthChallenge;
    reason?: string;
};
export {};
