import type { EditorSocketDiagnostics } from "../client/socketDiagnostics";
import type { AgentDiagnosticsResponse, AgentDiagnosticsEvent } from "../services/agentService";
export interface AgentTerminalRecentEvent {
    timestamp: string;
    direction?: "incoming" | "outgoing" | null;
    type: string;
    seq?: number | null;
    detail?: string | null;
    rawMessage?: string | null;
    payloadBytes?: number | null;
}
export interface AgentTerminalRunDiagnosticsSnapshot {
    agentId: string;
    isSubmitting: boolean;
    isConnecting: boolean;
    isWaitingForResponse: boolean;
    isAgentThinking: boolean;
    isExecuting: boolean;
    lastStatusReason: string | null;
    lastStatusMessage: string | null;
    hasActiveStreaming: boolean;
    isSubscribed: boolean;
    lastSeq: number;
    lastEventType: string | null;
    lastEventAt: string | null;
    recentEvents: AgentTerminalRecentEvent[];
    currentRunReceivedSeqs: number[];
    currentRunMissingSeqs: number[];
    currentRunTotalEventCount: number;
    assistantMessageCount: number;
    assistantGroupCount: number;
    assistantGroupsWithRenderableToolCalls: number;
    messagesWithToolCalls: number;
    totalToolCallCount: number;
    incompleteToolCallCount: number;
    recentToolUiEvents: AgentTerminalRecentEvent[];
}
export interface BuildAgentTerminalRunDiagnosticsSnapshotInput {
    agentId: string;
    isSubmitting: boolean;
    isConnecting: boolean;
    isWaitingForResponse: boolean;
    isAgentThinking: boolean;
    isExecuting: boolean;
    lastStatusReason: string | null;
    lastStatusMessage: string | null;
    hasActiveStreaming: boolean;
    isSubscribed: boolean;
    lastSeq: number;
    recentEvents: AgentTerminalRecentEvent[];
    currentRunReceivedSeqs: number[];
    currentRunMissingSeqs: number[];
    currentRunTotalEventCount: number;
    assistantMessageCount: number;
    assistantGroupCount: number;
    assistantGroupsWithRenderableToolCalls: number;
    messagesWithToolCalls: number;
    totalToolCallCount: number;
    incompleteToolCallCount: number;
    recentToolUiEvents: AgentTerminalRecentEvent[];
}
export interface AgentDiagnosticsSummary {
    code: "healthy" | "client-disconnected" | "subscription-lost" | "server-failed" | "waiting-for-capacity" | "client-lagging" | "stream-stalled" | "run-finished" | "waiting";
    title: string;
    detail: string;
}
export declare function buildAgentTerminalRunDiagnosticsSnapshot(input: BuildAgentTerminalRunDiagnosticsSnapshotInput): AgentTerminalRunDiagnosticsSnapshot;
export declare function isServerExecutionActive(diagnostics?: AgentDiagnosticsResponse | null): boolean;
export declare function getBackendLatestSeq(diagnostics?: AgentDiagnosticsResponse | null): number | null;
export declare function interpretAgentRunDiagnostics(params: {
    socketDiagnostics: EditorSocketDiagnostics;
    localSnapshot: AgentTerminalRunDiagnosticsSnapshot;
    serverDiagnostics?: AgentDiagnosticsResponse | null;
    now?: Date;
    stalledAfterMs?: number;
}): AgentDiagnosticsSummary;
export declare function formatSeqRanges(seqs: number[]): string;
export declare const STREAM_STALLED_AFTER_MS = 15000;
/**
 * Watchdog rule: while the terminal locally believes the run is active and is visible,
 * if no non-heartbeat run update has arrived for `stalledAfterMs`, treat the stream as
 * stalled and ask the backend whether it has advanced beyond what we've applied.
 *
 * Suppressed while a stop is pending or the run is queued for machine capacity — those
 * states can legitimately be quiet.
 */
export declare function isStreamStalled(params: {
    isExecuting: boolean;
    isVisible: boolean;
    isStopping: boolean;
    isWaitingForCapacity: boolean;
    lastUpdateAt: number;
    now: number;
    stalledAfterMs?: number;
}): boolean;
/**
 * Reload only when the backend has produced sequence numbers we have not applied. If
 * we don't have a backend seq, or the backend is at-or-behind the client, do nothing —
 * the silence is something else (idle run, server-side lag, etc.) and a reload would
 * just be churn.
 */
export declare function shouldReloadAfterDiagnostics(params: {
    localSeq: number;
    backendSeq: number | null;
}): boolean;
export declare function formatAgentDiagnosticsEvent(event: AgentDiagnosticsEvent | AgentTerminalRecentEvent): string;
