import { type AttachmentInput, type EnvVarInput, type McpServerUsageInput, type ResourceRef } from "@stigmer/sdk";
import type { HarnessOption } from "../models/harness";
import type { InteractionModeOption } from "./InteractionModePicker";
import { type AgentResolution } from "../agent/useAgentSetup";
import type { UseSessionVariablesReturn } from "../execution/useSessionVariables";
import type { UseWorkspaceEntriesReturn } from "../workspace/useWorkspaceEntries";
import type { UseGitHubConnectionReturn } from "../github/useGitHubConnection";
/**
 * Imperative handle exposed by {@link SessionComposer} via `ref`.
 *
 * Allows parent components to programmatically set the composer's
 * message text and focus the textarea. Used for features like
 * "Build from Plan" where a CTA outside the composer needs to
 * pre-fill and focus the input.
 *
 * @example
 * ```tsx
 * const composerRef = useRef<SessionComposerHandle>(null);
 *
 * function handleBuildFromPlan() {
 *   composerRef.current?.setMessage("Implement the plan above");
 *   composerRef.current?.focus();
 * }
 *
 * <SessionComposer ref={composerRef} onSubmit={handleSubmit} />
 * ```
 */
export interface SessionComposerHandle {
    /** Replace the composer's message text. */
    setMessage(message: string): void;
    /** Focus the composer's textarea. */
    focus(): void;
}
/**
 * Context provided to `onSubmit` at the moment of submission.
 *
 * Contains aggregated one-time environment variables from all setup
 * flows managed by the composer (agent, MCP servers, manual secrets).
 * The consumer passes `context.runtimeEnv` directly to execution
 * creation without needing to understand the individual sources.
 */
export interface SessionComposerSubmitContext {
    /**
     * Aggregated one-time environment variables from all setup flows.
     *
     * Merged from (in precedence order, last-write-wins):
     * 1. Agent one-time env vars (when agent resolution mode is `"oneTime"`)
     * 2. MCP server one-time env vars (collected with `saveForFuture: false`)
     * 3. Manual session variables (from {@link SessionVariablesInput})
     *
     * `undefined` when no runtime env vars were collected from any source.
     * Pass directly to execution creation as `runtimeEnv`.
     */
    readonly runtimeEnv?: Record<string, EnvVarInput>;
    /**
     * Pre-uploaded file attachments for the execution.
     *
     * Each entry contains a `storageKey` obtained from
     * `agentExecution.uploadAttachment()`. Only successfully uploaded
     * attachments are included. Pass directly to execution creation
     * as `attachments`.
     *
     * `undefined` when no files were attached.
     */
    readonly attachments?: AttachmentInput[];
    /**
     * Interaction mode selected by the user for this execution.
     *
     * - `"agent"` (default): full tool access — read, write, create, delete.
     * - `"plan"`: read-only analysis — read, search, list only.
     *
     * `undefined` when no mode picker is shown (defaults to `"agent"`).
     * Pass to execution creation as `execution_config.interaction_mode`.
     */
    readonly interactionMode?: InteractionModeOption;
    /**
     * Workspace-relative file paths the user referenced via drag-to-reference.
     *
     * These are lightweight "attention" signals — the agent reads the files
     * directly from the workspace filesystem. No upload, no injection.
     *
     * `undefined` when no file references are present.
     * Pass to execution creation as `workspaceFileRefs`.
     */
    readonly workspaceFileRefs?: string[];
}
/** Props for {@link SessionComposer}. */
export interface SessionComposerProps {
    /**
     * Called when the user submits a message.
     *
     * The optional `context` parameter carries aggregated runtime data
     * collected by the composer's setup flows. When present,
     * `context.runtimeEnv` should be passed to execution creation.
     */
    readonly onSubmit: (message: string, modelName?: string, context?: SessionComposerSubmitContext) => void;
    /** Shows loading indicator on the send button. */
    readonly isSubmitting?: boolean;
    /** Disables the entire composer (e.g., while an execution streams). */
    readonly disabled?: boolean;
    /**
     * Currently selected execution harness.
     *
     * Controls which models appear in the model selector and flows
     * through to session creation. When omitted, defaults to `"native"`.
     */
    readonly harness?: HarnessOption;
    /**
     * Called when the user switches the harness.
     *
     * Providing this callback enables the harness selector in the toolbar.
     */
    readonly onHarnessChange?: (harness: HarnessOption) => void;
    /** Show the harness selector in the toolbar. @default false */
    readonly showHarnessSelector?: boolean;
    /**
     * Currently selected interaction mode.
     *
     * When `onInteractionModeChange` is provided, renders a mode picker
     * in the toolbar. Defaults to `"agent"` when omitted.
     */
    readonly interactionMode?: InteractionModeOption;
    /**
     * Called when the user switches the interaction mode.
     *
     * Providing this callback enables the mode picker in the toolbar.
     */
    readonly onInteractionModeChange?: (mode: InteractionModeOption) => void;
    /** Show the interaction mode picker in the toolbar. @default false */
    readonly showInteractionModePicker?: boolean;
    /** Initial model ID for the model selector. */
    readonly defaultModelId?: string;
    /** Called when the user changes the selected model. */
    readonly onModelChange?: (modelId: string) => void;
    /** Show the model selector. @default true */
    readonly showModelSelector?: boolean;
    /**
     * Workspace state managed by {@link useWorkspaceEntries}.
     * When provided, renders a workspace trigger in the toolbar
     * that opens a popover with the workspace editor.
     */
    readonly workspace?: UseWorkspaceEntriesReturn;
    /** GitHub connection state for the repo picker. */
    readonly gitHubConnection?: UseGitHubConnectionReturn;
    /** Show the GitHub Repo source button. @default true */
    readonly enableGitHub?: boolean;
    /** Show the Local Folder source button. @default false */
    readonly enableLocal?: boolean;
    /**
     * Native folder picker callback passed through to {@link WorkspaceEditor}.
     * When provided, clicking "Local Folder" opens a native dialog instead
     * of the inline text input. See {@link WorkspaceEditorProps.onBrowseLocalFolder}.
     */
    readonly onBrowseLocalFolder?: () => Promise<string | null>;
    /**
     * Organization slug for agent, MCP server, and skill searches.
     * Required when agent, MCP, or skill pickers are enabled.
     */
    readonly org?: string;
    /**
     * Currently selected agent reference, or null if none.
     * When `onAgentRefChange` is provided, an agent trigger
     * appears in the toolbar (single-select).
     */
    readonly agentRef?: ResourceRef | null;
    /** Called when the agent selection changes. Providing this enables the agent trigger. */
    readonly onAgentRefChange?: (ref: ResourceRef | null) => void;
    /**
     * Called when the agent setup flow resolves how the agent should
     * be used for session creation.
     *
     * The {@link AgentResolution} discriminated union tells the caller
     * which session creation path to use:
     * - `"saved"` — use `agentInstanceId`
     * - `"oneTime"` — use `agentRef` + pass `runtimeEnv` to execution
     * - `"direct"` — use `agentRef` (no secrets needed)
     *
     * Set to `null` when the agent is deselected.
     */
    readonly onAgentResolutionChange?: (resolution: AgentResolution | null) => void;
    /**
     * Agent to auto-select when the composer mounts.
     *
     * When provided, the composer runs the full agent resolution flow
     * on mount — exactly as if the user had picked this agent in the
     * {@link AgentPicker}. If the agent requires credentials, the
     * environment form appears automatically.
     *
     * One-time: consumed on mount; subsequent changes are ignored.
     * To change the agent after mount, use the picker or
     * `onAgentRefChange` externally.
     *
     * Requires `org` and `onAgentRefChange` to be set (same
     * prerequisites as the agent picker).
     *
     * @example
     * ```tsx
     * <SessionComposer
     *   onSubmit={handleCreate}
     *   org="acme"
     *   agentRef={agentRef}
     *   onAgentRefChange={setAgentRef}
     *   onAgentResolutionChange={setResolution}
     *   initialAgentRef={{ org: "stigmer", slug: "agent-creator" }}
     * />
     * ```
     */
    readonly initialAgentRef?: ResourceRef;
    /**
     * Pre-bind the session to a specific, already-existing
     * `AgentInstance` when the composer mounts.
     *
     * Requires `initialAgentRef` (the agent the instance deploys). When
     * both are provided, the composer resolves the agent directly to this
     * instance — skipping the environment-collection flow entirely, since
     * the chosen instance already binds its own environment(s). The
     * resulting resolution is `{ mode: "saved", instanceId }`, so the
     * session is created against this exact configured deployment.
     *
     * This is the agent analog of running a specific WorkflowInstance: it
     * powers the "Start session" action on an instance in the Agent detail
     * page's Instances tab.
     *
     * One-time: consumed on mount; subsequent changes are ignored.
     */
    readonly initialInstanceId?: string;
    /**
     * When `true`, the agent chip renders without an X (remove) button.
     *
     * Used on the session page to indicate the session's default agent,
     * where removing it would just re-select the same agent (a
     * confusing no-op). The user can still switch agents via the
     * Configure menu.
     *
     * @default false
     */
    readonly isDefaultAgent?: boolean;
    /**
     * Currently selected MCP server usages.
     * When `onMcpServerUsagesChange` is provided, a MCP server trigger
     * appears in the toolbar.
     */
    readonly mcpServerUsages?: McpServerUsageInput[];
    /** Called when the MCP server selection changes. Providing this enables the MCP trigger. */
    readonly onMcpServerUsagesChange?: (usages: McpServerUsageInput[]) => void;
    /**
     * Currently selected skill references.
     * When `onSkillRefsChange` is provided, a skill trigger
     * appears in the toolbar.
     */
    readonly skillRefs?: ResourceRef[];
    /** Called when the skill selection changes. Providing this enables the skill trigger. */
    readonly onSkillRefsChange?: (refs: ResourceRef[]) => void;
    /**
     * Session variables state managed by {@link useSessionVariables}.
     * When provided, renders a "Session Variables" trigger in the toolbar
     * that opens a key-value editor for environment variables.
     *
     * Variables are ephemeral by default (single execution). Individual
     * entries can be marked `saveForFuture: true` to persist them to
     * the user's personal environment. The consumer should call
     * `sessionVariables.clear()` after submission.
     */
    readonly sessionVariables?: UseSessionVariablesReturn;
    /**
     * Enable file attachment support in the composer.
     *
     * When `true`, renders an attach button in the toolbar and enables
     * drag-and-drop file upload on the textarea. Attachments are uploaded
     * immediately via `agentExecution.uploadAttachment()` and included
     * in `context.attachments` on submit.
     *
     * @default true
     */
    readonly enableAttachments?: boolean;
    /**
     * Enable workspace file-reference support via drag-to-reference.
     *
     * When `true`, dragging a file from the workspace tree into the
     * composer creates a file-reference chip (no upload). Referenced
     * paths are included in `context.workspaceFileRefs` on submit.
     *
     * @default true
     */
    readonly enableFileReferences?: boolean;
    /**
     * Called when a file is rejected (e.g., exceeds the 10 MB limit).
     * Consumers can use this for toast notifications.
     */
    readonly onAttachmentValidationError?: (message: string) => void;
    /**
     * Files to attach programmatically when the composer mounts.
     *
     * When provided, the composer uploads these files via the same
     * attachment pipeline as user-selected files. Attachment chips
     * appear in the UI so the user sees what is attached.
     *
     * One-time: consumed when the value first becomes truthy.
     * Subsequent changes are ignored. This allows async resource
     * fetching — the effect waits for the files to be ready.
     *
     * Requires `enableAttachments` to be `true` (default).
     *
     * @example
     * ```tsx
     * const yaml = serializeAgentYaml(agent);
     * const file = new File([yaml], "my-agent.yaml", { type: "text/yaml" });
     *
     * <SessionComposer
     *   onSubmit={handleSubmit}
     *   initialAttachments={[file]}
     *   initialAgentRef={{ org: "stigmer", slug: "agent-creator" }}
     * />
     * ```
     */
    readonly initialAttachments?: File[];
    /** Placeholder text for the textarea. @default "Reply\u2026" */
    readonly placeholder?: string;
    /** Initial number of visible rows. @default 1 */
    readonly initialRows?: number;
    /** Auto-focus the textarea on mount. @default false */
    readonly autoFocus?: boolean;
    /** ARIA label for the composer region. @default "Send message" */
    readonly ariaLabel?: string;
    /** Additional CSS class names for the root container. */
    readonly className?: string;
}
export declare const SessionComposer: import("react").NamedExoticComponent<SessionComposerProps & import("react").RefAttributes<SessionComposerHandle>>;
//# sourceMappingURL=SessionComposer.d.ts.map