import type { AgentExecution } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
import type { AgentMessage, ToolCall } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
import type { SubAgentExecution } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/subagent_pb";
import type { PendingApproval } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/approval_pb";
import type { FileChangeSet } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/filereview_pb";
import type { ExecutionArtifact } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/artifact_pb";
import type { TodoItem } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/todo_pb";
import { ApprovalAction, ExecutionPhase, InteractionMode } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
import type { WorkspaceEntry } from "@stigmer/protos/ai/stigmer/agentic/session/v1/workspace_pb";
import type { SummarizationEventView } from "./useContextWindow.js";
import type { ResolvedPathAction } from "./file-path-resolver.js";
/** Props for {@link MessageThread}. */
export interface MessageThreadProps {
    /** Completed executions in chronological order. */
    readonly executions: readonly AgentExecution[];
    /**
     * The currently streaming execution. Appended after `executions` to
     * form a continuous thread. Pass `null` or `undefined` when no
     * execution is actively streaming.
     */
    readonly activeStreamExecution?: AgentExecution | null;
    /**
     * Optimistic user message shown at the end of the thread before the
     * stream delivers the real message. Rendered as a human message with
     * a sending indicator. Clear this prop once the stream delivers its
     * first snapshot.
     */
    readonly pendingUserMessage?: string | null;
    /**
     * Marks the pending user message as failed-to-send. The optimistic
     * bubble renders an inline "Couldn't send — Retry" affordance instead
     * of the sending indicator, so a failed follow-up never silently
     * vanishes. Pair with {@link onRetrySend}.
     *
     * @default false
     */
    readonly pendingMessageFailed?: boolean;
    /**
     * Retry handler for a failed pending message. Wired to the inline
     * "Retry" control when {@link pendingMessageFailed} is `true`.
     */
    readonly onRetrySend?: () => void;
    /**
     * When provided, the in-flight human turn (the active execution's prompt)
     * shows a hover "Edit" affordance. Clicking it invokes this callback with
     * the message text — the session chat stops the running execution and
     * pre-fills the composer for an edit-and-resubmit.
     *
     * Provide this only while the active execution is stoppable; the SDK marks
     * exactly the active-stream human turn editable. When omitted, no edit
     * control is shown (backward compatible).
     */
    readonly onEditMessage?: (text: string) => void;
    /**
     * Retry handler for a terminal-failed execution that exposed a server
     * error reason. Receives the originating message; the consumer typically
     * resends it as a new execution. When omitted, no Retry control is shown
     * beside the surfaced failure reason.
     */
    readonly onRetryExecution?: (message: string) => void;
    /** Additional CSS class names for the root container. */
    readonly className?: string;
    /**
     * Custom formatter for tool call summary labels. Passed through to
     * each {@link ToolCallGroup}.
     */
    readonly formatToolCallSummary?: (toolCalls: readonly ToolCall[]) => string;
    /**
     * Callback for approval actions. When provided and the active
     * execution has pending approvals, {@link ApprovalCard}s are
     * rendered as thread items. When omitted, no approval UI is
     * shown (backward compatible).
     */
    readonly onApprovalSubmit?: (toolCallId: string, action: ApprovalAction, comment?: string) => void;
    /**
     * Set of tool call IDs currently being submitted for approval.
     * Drives per-card loading state. Only meaningful when
     * `onApprovalSubmit` is provided.
     */
    readonly submittingApprovalIds?: ReadonlySet<string>;
    /**
     * Per-tool-call approval failures, keyed by `toolCallId` — surfaced in-card
     * beside the gate that failed (an inline tool row or the bottom backstop
     * card). Supply {@link useSubmitApproval}'s `errorsByToolCallId`. Only
     * meaningful when `onApprovalSubmit` is provided.
     */
    readonly approvalErrors?: ReadonlyMap<string, Error>;
    /**
     * Render each *settled* captured change set as a read-only record card at
     * its anchor in the thread (after the set's last stamped edit row) — the
     * durable history of what changed and how it was decided. This is the only
     * in-thread trace for a set with no stamped rows (e.g. changes made by shell
     * commands), so the surface that owns the session history should enable it.
     *
     * The thread never renders *decision* controls: a pending (AWAITING_REVIEW)
     * set on a live execution is deliberately NOT emitted here — its decision
     * surface is the composer-docked {@link FileReviewDock}, which cannot scroll
     * out of view. The stamped rows' badges carry the pending state in-thread.
     *
     * Opt-in with a backward-compatible default (DD-011); `SessionViewer`
     * enables it.
     *
     * @default false
     */
    readonly showFileReviewRecords?: boolean;
    /**
     * Workspace entries from the session spec. When provided, file
     * paths in tool call rendering become interactive — git-sourced
     * paths open on GitHub, local paths offer copy-to-clipboard.
     *
     * Passed to {@link FilePathContext} for consumption by
     * {@link FilePathLink} components deep in the tree.
     */
    readonly workspaceEntries?: readonly WorkspaceEntry[];
    /**
     * Optional override for file path click behavior. Platform
     * builders use this to integrate their own file viewer or
     * navigation instead of the default open-URL / copy-to-clipboard.
     */
    readonly onFilePathClick?: (path: string, resolved: ResolvedPathAction) => boolean | void;
    /**
     * Absolute sandbox workspace root (e.g. `/home/daytona/workspace`).
     * When provided, shell commands and tool output normalize absolute
     * sandbox paths to workspace-relative display paths.
     *
     * Pass an empty string or omit for local sessions where paths are
     * the user's own filesystem (no normalization needed).
     */
    readonly sandboxWorkspaceRoot?: string;
    /**
     * Summarization events from context window tracking. When provided,
     * "Context compacted" cards are interleaved into the thread at the
     * correct chronological position based on event timestamps.
     *
     * Obtain from {@link useContextWindow}.summarizationEvents.
     */
    readonly summarizationEvents?: readonly SummarizationEventView[];
    /**
     * Enable virtualized rendering for long conversations. Requires
     * `react-virtuoso` to be installed as a peer dependency. When
     * enabled, only visible items are rendered in the DOM, improving
     * performance for threads with 100+ items.
     *
     * @default false
     */
    readonly virtualized?: boolean;
    /**
     * Called when the user clicks "Implement" on a completed Plan-mode
     * execution's {@link PlanCompletionCard}.
     *
     * When provided, a CTA card is rendered at the end of the thread
     * after a Plan-mode execution completes successfully. The consumer
     * typically wires this to switch the interaction mode to Agent,
     * pre-fill the composer, and focus it.
     *
     * When omitted, no plan completion card is rendered. Backward
     * compatible — existing consumers see no change.
     */
    readonly onBuildFromPlan?: () => void;
    /**
     * Opens a plan in the session panel's plan document tab — the side-by-side
     * review/refine surface. Wired to EVERY plan card: the latest opens
     * editable/buildable, a superseded plan opens read-only (the host decides
     * from the execution id). When omitted, cards fall back to the "Open full"
     * preview modal (hosts without a panel).
     *
     * Providing this also opts the thread into LIVE plan collapse: while a
     * Plan-mode turn streams its plan (detected via `findStreamingPlan`), the
     * plan message is suppressed behind a compact {@link PlanStreamingCard}
     * whose "Open plan" routes here — the host is expected to render the
     * streaming document in its plan surface. Hosts without one (this prop
     * omitted) keep the plan streaming inline, where it stays readable.
     */
    readonly onOpenPlan?: (executionId: string) => void;
    /**
     * Organization slug. Required for the plan completion card's
     * "Review plan" action, which opens the shared artifact preview
     * modal (the modal needs `org` for its detection/apply pipeline).
     */
    readonly org?: string;
    /**
     * Disables the plan completion card's actions (Implement / Review).
     * Defense in depth for the brief windows where a follow-up cannot be
     * sent (e.g. an execution is streaming); the composer also no-ops a
     * disabled submit.
     */
    readonly planActionsDisabled?: boolean;
    /** True while the approved plan is being uploaded ahead of the build turn. */
    readonly planBuildPending?: boolean;
    /**
     * Constrain thread content to a max-width reading column
     * (`max-w-3xl`, 768 px) inside the full-width scroll container —
     * the scrollbar stays at the viewport edge.
     *
     * - `"center"` — column horizontally centered (classic chat reading view).
     * - `"start"` — column anchored to the left edge, so the thread's left
     *   edge stays put when a sibling panel opens/closes beside it.
     *
     * When omitted, content spans the full width. Opt-in per DD-011 —
     * existing consumers see no layout change.
     */
    readonly contentColumn?: ThreadContentColumn;
}
/** Reading-column alignment for {@link MessageThread} content. */
export type ThreadContentColumn = "center" | "start";
/**
 * Class set for the optional reading column — one definition shared by both
 * render paths (non-virtualized and virtualized) so their geometry can never
 * drift.
 *
 * @internal
 */
export declare function threadContentColumnClass(column: ThreadContentColumn | undefined): string | false;
/**
 * Flattened representation of one renderable item in the thread.
 *
 * Discriminated union keeps the render loop a simple switch with no
 * type narrowing gymnastics.
 *
 * @internal Exported for internal use by `VirtualizedThread` — not
 * part of the public API.
 */
export type ThreadItem = {
    readonly kind: "message";
    readonly message: AgentMessage;
    readonly key: string;
    readonly isPending?: boolean;
    readonly isFailed?: boolean;
    readonly isEditable?: boolean;
    readonly isPlanDocument?: boolean;
    readonly interactionMode?: InteractionMode;
} | {
    readonly kind: "tool-group";
    readonly toolCalls: readonly ToolCall[];
    readonly subAgentExecutions: readonly SubAgentExecution[];
    readonly key: string;
} | {
    readonly kind: "sub-agent";
    readonly subAgentExecution: SubAgentExecution;
    readonly key: string;
} | {
    readonly kind: "phase-badge";
    readonly phase: ExecutionPhase;
    readonly key: string;
} | {
    readonly kind: "execution-error";
    readonly error: string;
    readonly retryMessage?: string;
    readonly key: string;
} | {
    readonly kind: "approval-request";
    readonly pendingApproval: PendingApproval;
    readonly key: string;
} | {
    readonly kind: "file-review-record";
    readonly fileChangeSet: FileChangeSet;
    readonly key: string;
} | {
    readonly kind: "setup-progress";
    readonly workspaceEntries: readonly WorkspaceEntry[];
    readonly serverPhase?: string;
    readonly isAwaitingResponse?: boolean;
    readonly key: string;
} | {
    readonly kind: "context-compacted";
    readonly event: SummarizationEventView;
    readonly key: string;
} | {
    readonly kind: "todos";
    readonly key: string;
    readonly executionId: string;
    readonly todos: {
        readonly [id: string]: TodoItem;
    };
} | {
    readonly kind: "plan-completion";
    readonly key: string;
    readonly executionId: string;
    readonly planArtifact?: ExecutionArtifact;
    /**
     * The plan's title (its leading `# H1`), lifted from the plan message at
     * build time — no fetch. Present only when the turn published an
     * artifact (the collapsed-card path); the card falls back to "Plan".
     */
    readonly planTitle?: string;
    /**
     * True for the most recent completed Plan execution in the thread — the
     * only plan whose card carries the primary "Build" action. Superseded
     * plans keep their review actions (open/download) but never a build
     * CTA, so a stale plan can't be implemented by accident.
     */
    readonly isLatestPlan: boolean;
} | {
    /**
     * A plan the active Plan-mode execution is writing RIGHT NOW: the
     * streaming plan message is suppressed and this compact card stands in
     * while the document renders live in the panel's plan tab. On
     * completion the item becomes `plan-completion` — a different kind
     * under the SAME key, so the card holds one thread position and the
     * swap reads as the card settling.
     */
    readonly kind: "plan-writing";
    readonly key: string;
    readonly executionId: string;
    /** Live title (the plan's leading `# H1`), growing as it streams. */
    readonly planTitle?: string;
    /** Length of the plan text streamed so far (drives the live size). */
    readonly planSize: number;
};
/**
 * Builds a flat list of renderable thread items from execution data.
 *
 * Keys use stable execution IDs (not array indices) so React can
 * reconcile items across renders without unnecessary remounts.
 *
 * @internal Exported for testing — not part of the public API.
 */
export declare function buildThreadItems(executions: readonly AgentExecution[], activeStreamExecution: AgentExecution | null | undefined, pendingUserMessage: string | null | undefined, includeApprovals: boolean, workspaceEntries: readonly WorkspaceEntry[] | undefined, summarizationEvents?: readonly SummarizationEventView[], pendingMessageFailed?: boolean, editableActiveTurn?: boolean, includeFileReviewRecords?: boolean, collapseStreamingPlan?: boolean): ThreadItem[];
/**
 * Renders a continuous conversation thread from one or more
 * {@link AgentExecution} snapshots.
 *
 * Composes {@link MessageEntry}, {@link ToolCallGroup}, and
 * {@link ExecutionPhaseBadge} into a scrollable, auto-scrolling log
 * that follows new content when the user is near the bottom.
 *
 * Renders nothing when no executions are provided.
 *
 * All visual properties flow through `--stgm-*` tokens.
 *
 * @example
 * ```tsx
 * const { executions } = useSessionExecutions(sessionId);
 * const stream = useExecutionStream(activeId);
 *
 * <MessageThread
 *   executions={executions ?? []}
 *   activeStreamExecution={stream.execution}
 * />
 * ```
 */
export declare function MessageThread({ executions, activeStreamExecution, pendingUserMessage, pendingMessageFailed, onRetrySend, onRetryExecution, onEditMessage, className, formatToolCallSummary, onApprovalSubmit, submittingApprovalIds, approvalErrors, showFileReviewRecords, workspaceEntries, onFilePathClick, sandboxWorkspaceRoot, summarizationEvents, virtualized, onBuildFromPlan, onOpenPlan, org, planActionsDisabled, planBuildPending, contentColumn, }: MessageThreadProps): import("react/jsx-runtime").JSX.Element;
/**
 * Props for {@link ThreadItemRenderer}.
 *
 * @internal Exported for internal use by `VirtualizedThread` — not
 * part of the public API.
 */
export interface ThreadItemRendererProps {
    readonly item: ThreadItem;
    readonly formatToolCallSummary?: (toolCalls: readonly ToolCall[]) => string;
    readonly onApprovalSubmit?: (toolCallId: string, action: ApprovalAction, comment?: string) => void;
    readonly submittingApprovalIds?: ReadonlySet<string>;
    readonly approvalErrors?: ReadonlyMap<string, Error>;
    readonly onBuildFromPlan?: () => void;
    readonly onOpenPlan?: (executionId: string) => void;
    readonly org?: string;
    readonly planActionsDisabled?: boolean;
    /** True while the approved plan is being uploaded ahead of the build turn. */
    readonly planBuildPending?: boolean;
    readonly onRetrySend?: () => void;
    readonly onRetryExecution?: (message: string) => void;
    readonly onEditMessage?: (text: string) => void;
}
/**
 * Renders a single thread item by discriminated `kind`. Used by both
 * the non-virtualized `items.map()` path and the virtualized
 * `Virtuoso.itemContent` callback.
 *
 * Does not receive a `key` prop — the caller is responsible for
 * keying (either via `items.map` or `computeItemKey`).
 *
 * @internal Exported for internal use by `VirtualizedThread` — not
 * part of the public API.
 */
export declare function ThreadItemRenderer({ item, formatToolCallSummary, onApprovalSubmit, submittingApprovalIds, approvalErrors, onBuildFromPlan, onOpenPlan, org, planActionsDisabled, planBuildPending, onRetrySend, onRetryExecution, onEditMessage, }: ThreadItemRendererProps): import("react/jsx-runtime").JSX.Element;
//# sourceMappingURL=MessageThread.d.ts.map