import { type ChildProcessWithoutNullStreams } from "node:child_process";
import type { ReadableStream as NodeReadableStream, WritableStream as NodeWritableStream } from "node:stream/web";
import { ClientSideConnection, type Client as ACPClient, type CreateTerminalRequest, type InitializeResponse, type KillTerminalRequest, type LoadSessionResponse, type NewSessionResponse, type ReadTextFileRequest, type RequestPermissionRequest, type RequestPermissionResponse, type ResumeSessionResponse, type SessionConfigOption, type SessionMode, type SessionModelState, type SessionNotification, type TerminalOutputRequest, type TerminalOutputResponse, type ToolCallContent, type ToolCallLocation, type ToolCallStatus, type ToolKind, type Usage, type WaitForTerminalExitRequest, type WriteTextFileRequest, type Stream as ACPStream } from "@agentclientprotocol/sdk";
import type { Logger } from "pino";
import { type AgentCapabilityFlags, type AgentClient, type AgentLaunchContext, type AgentMode, type AgentModelDefinition, type AgentPermissionRequest, type AgentPermissionResponse, type AgentPersistenceHandle, type AgentPromptInput, type AgentRunOptions, type AgentRunResult, type AgentRuntimeInfo, type AgentSession, type AgentSessionConfig, type AgentSlashCommand, type AgentStreamEvent, type AgentUsage, type ListModesOptions, type ListModelsOptions, type ListPersistedAgentsOptions, type PersistedAgentDescriptor } from "../agent-sdk-types.js";
import { type ProviderRuntimeSettings } from "../provider-launch-config.js";
export declare function createLoggedNdJsonStream(output: NodeWritableStream, input: NodeReadableStream, options: {
    logger: Logger;
    provider: string;
}): ACPStream;
interface ACPAgentClientOptions {
    provider: string;
    logger: Logger;
    runtimeSettings?: ProviderRuntimeSettings;
    defaultCommand: [string, ...string[]];
    defaultModes?: AgentMode[];
    modelTransformer?: (models: AgentModelDefinition[]) => AgentModelDefinition[];
    sessionResponseTransformer?: (response: SessionStateResponse) => SessionStateResponse;
    configOptionsTransformer?: (configOptions: SessionConfigOption[]) => SessionConfigOption[];
    modeIdTransformer?: (modeId: string) => string | null;
    toolSnapshotTransformer?: (snapshot: ACPToolSnapshot) => ACPToolSnapshot;
    providerModeWriter?: (context: ACPProviderModeWriterContext) => Promise<ACPProviderModeWriteResult>;
    beforeModeWriter?: (context: ACPProviderModeWriterContext) => Promise<ACPBeforeModeWriteResult>;
    thinkingOptionWriter?: (connection: ClientSideConnection, sessionId: string, thinkingOptionId: string) => Promise<void>;
    capabilities?: AgentCapabilityFlags;
    waitForInitialCommands?: boolean;
    initialCommandsWaitTimeoutMs?: number;
}
interface ACPAgentSessionOptions {
    provider: string;
    logger: Logger;
    runtimeSettings?: ProviderRuntimeSettings;
    defaultCommand: [string, ...string[]];
    defaultModes: AgentMode[];
    modelTransformer?: (models: AgentModelDefinition[]) => AgentModelDefinition[];
    sessionResponseTransformer?: (response: SessionStateResponse) => SessionStateResponse;
    configOptionsTransformer?: (configOptions: SessionConfigOption[]) => SessionConfigOption[];
    modeIdTransformer?: (modeId: string) => string | null;
    toolSnapshotTransformer?: (snapshot: ACPToolSnapshot) => ACPToolSnapshot;
    providerModeWriter?: (context: ACPProviderModeWriterContext) => Promise<ACPProviderModeWriteResult>;
    beforeModeWriter?: (context: ACPProviderModeWriterContext) => Promise<ACPBeforeModeWriteResult>;
    thinkingOptionWriter?: (connection: ClientSideConnection, sessionId: string, thinkingOptionId: string) => Promise<void>;
    capabilities: AgentCapabilityFlags;
    handle?: AgentPersistenceHandle;
    agentId?: string;
    launchEnv?: Record<string, string>;
    waitForInitialCommands?: boolean;
    initialCommandsWaitTimeoutMs?: number;
}
export interface SpawnedACPProcess {
    child: ChildProcessWithoutNullStreams;
    connection: ClientSideConnection;
    initialize: InitializeResponse;
}
export interface ACPToolSnapshot {
    toolCallId: string;
    title: string;
    kind?: ToolKind | null;
    status?: ToolCallStatus | null;
    content?: ToolCallContent[] | null;
    locations?: ToolCallLocation[] | null;
    rawInput?: unknown;
    rawOutput?: unknown;
}
export type SessionStateResponse = NewSessionResponse | LoadSessionResponse | ResumeSessionResponse;
interface TerminalExit {
    exitCode?: number | null;
    signal?: string | null;
}
type SelectConfigOption = Extract<SessionConfigOption, {
    type: "select";
}>;
interface SelectConfigChoice {
    value: string;
    name: string;
    description?: string | null;
    group?: string;
}
type AvailableACPModel = NonNullable<SessionModelState["availableModels"]>[number];
interface ACPModeSelection {
    availableMode: AgentMode | null;
    configOption: SelectConfigOption | null;
    configChoice: SelectConfigChoice | null;
    hasAvailableModes: boolean;
}
interface ACPModelSelection {
    availableModel: AvailableACPModel | null;
    configOption: SelectConfigOption | null;
    configChoice: SelectConfigChoice | null;
    hasAvailableModels: boolean;
}
export interface ACPProviderModeWriterContext {
    connection: ClientSideConnection;
    sessionId: string;
    requestedModeId: string;
    currentModeId: string | null;
    selection: ACPModeSelection;
    configOptions: SessionConfigOption[];
    logger: Logger;
}
export interface ACPProviderModeWriteResult {
    handled: boolean;
    currentModeId?: string;
    configOptions?: SessionConfigOption[];
}
export interface ACPBeforeModeWriteResult {
    configOptions?: SessionConfigOption[];
}
export declare function mapACPUsage(usage: Usage | null | undefined): AgentUsage | undefined;
export declare function resolveACPModeSelection({ modeId, availableModes, configOptions, }: {
    modeId: string;
    availableModes: AgentMode[];
    configOptions: SessionConfigOption[] | null | undefined;
}): ACPModeSelection;
export declare function resolveACPModelSelection({ modelId, availableModels, configOptions, }: {
    modelId: string;
    availableModels: AvailableACPModel[] | null | undefined;
    configOptions: SessionConfigOption[] | null | undefined;
}): ACPModelSelection;
export declare function deriveModesFromACP(fallbackModes: AgentMode[], modeState?: {
    availableModes?: SessionMode[] | null;
    currentModeId?: string | null;
} | null, configOptions?: SessionConfigOption[] | null): {
    modes: AgentMode[];
    currentModeId: string | null;
};
export declare function deriveModelDefinitionsFromACP(provider: string, models: SessionModelState | null | undefined, configOptions?: SessionConfigOption[] | null): AgentModelDefinition[];
export declare class ACPAgentClient implements AgentClient {
    readonly provider: string;
    readonly capabilities: AgentCapabilityFlags;
    protected readonly logger: Logger;
    protected readonly runtimeSettings?: ProviderRuntimeSettings;
    protected readonly defaultCommand: [string, ...string[]];
    protected readonly defaultModes: AgentMode[];
    private readonly modelTransformer?;
    private readonly sessionResponseTransformer?;
    private readonly configOptionsTransformer?;
    private readonly modeIdTransformer?;
    private readonly toolSnapshotTransformer?;
    private readonly providerModeWriter?;
    private readonly beforeModeWriter?;
    private readonly thinkingOptionWriter?;
    private readonly waitForInitialCommands;
    private readonly initialCommandsWaitTimeoutMs;
    constructor(options: ACPAgentClientOptions);
    createSession(config: AgentSessionConfig, launchContext?: AgentLaunchContext): Promise<AgentSession>;
    resumeSession(handle: AgentPersistenceHandle, overrides?: Partial<AgentSessionConfig>, launchContext?: AgentLaunchContext): Promise<AgentSession>;
    listModels(options: ListModelsOptions): Promise<AgentModelDefinition[]>;
    listModes(options: ListModesOptions): Promise<AgentMode[]>;
    listPersistedAgents(options?: ListPersistedAgentsOptions): Promise<PersistedAgentDescriptor[]>;
    isAvailable(): Promise<boolean>;
    protected spawnProcess(launchEnv?: Record<string, string>, options?: {
        initializeTimeoutMs?: number;
    }): Promise<SpawnedACPProcess>;
    protected buildProbeClient(): ACPClient;
    protected closeProbe(probe: SpawnedACPProcess): Promise<void>;
    protected resolveLaunchCommand(): Promise<{
        command: string;
        args: string[];
    }>;
    private assertProvider;
    protected transformSessionResponse(response: SessionStateResponse): SessionStateResponse;
}
export declare class ACPAgentSession implements AgentSession, ACPClient {
    readonly provider: string;
    readonly capabilities: AgentCapabilityFlags;
    private readonly logger;
    private readonly runtimeSettings?;
    private readonly defaultCommand;
    private readonly defaultModes;
    protected readonly modelTransformer?: (models: AgentModelDefinition[]) => AgentModelDefinition[];
    private readonly sessionResponseTransformer?;
    private readonly configOptionsTransformer?;
    private readonly modeIdTransformer?;
    private readonly toolSnapshotTransformer?;
    private readonly providerModeWriter?;
    private readonly beforeModeWriter?;
    private readonly thinkingOptionWriter?;
    private readonly agentId?;
    private readonly launchEnv?;
    private readonly subscribers;
    private readonly pendingPermissions;
    private readonly messageAssemblies;
    private readonly submittedUserMessageIds;
    private readonly toolCalls;
    private readonly terminalEntries;
    private readonly persistedHistory;
    private readonly initialHandle?;
    private readonly config;
    private child;
    private connection;
    private agentCapabilities;
    private sessionId;
    private currentMode;
    private availableModes;
    private currentModel;
    private availableModels;
    private thinkingOptionId;
    private currentTitle;
    private lastActivityAt;
    private configOptions;
    private cachedCommands;
    private commandsReadyDeferred;
    private commandsReadySettled;
    private waitForInitialCommands;
    private initialCommandsWaitTimeoutMs;
    private currentTurnUsage;
    private activeForegroundTurnId;
    private closed;
    private historyPending;
    private replayingHistory;
    private bootstrapThreadEventPending;
    constructor(config: AgentSessionConfig, options: ACPAgentSessionOptions);
    get id(): string | null;
    initializeNewSession(): Promise<void>;
    initializeResumedSession(): Promise<void>;
    run(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<AgentRunResult>;
    startTurn(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<{
        turnId: string;
    }>;
    subscribe(callback: (event: AgentStreamEvent) => void): () => void;
    streamHistory(): AsyncGenerator<AgentStreamEvent>;
    getRuntimeInfo(): Promise<AgentRuntimeInfo>;
    getAvailableModes(): Promise<AgentMode[]>;
    getCurrentMode(): Promise<string | null>;
    private ensureCommandsReadyDeferred;
    private settleCommandsReady;
    private waitForCommandsReady;
    listCommands(): Promise<AgentSlashCommand[]>;
    setMode(modeId: string): Promise<void>;
    private setModeWithSelection;
    private createProviderModeWriterContext;
    setModel(modelId: string | null): Promise<void>;
    private setModelWithSelection;
    setThinkingOption(thinkingOptionId: string | null): Promise<void>;
    private applyConfigOptionResponse;
    getPendingPermissions(): AgentPermissionRequest[];
    respondToPermission(requestId: string, response: AgentPermissionResponse): Promise<void>;
    describePersistence(): AgentPersistenceHandle | null;
    interrupt(): Promise<void>;
    close(): Promise<void>;
    requestPermission(params: RequestPermissionRequest): Promise<RequestPermissionResponse>;
    sessionUpdate(params: SessionNotification): Promise<void>;
    extNotification(method: string, params: Record<string, unknown>): Promise<void>;
    readTextFile(params: ReadTextFileRequest): Promise<{
        content: string;
    }>;
    writeTextFile(params: WriteTextFileRequest): Promise<Record<string, never>>;
    createTerminal(params: CreateTerminalRequest): Promise<{
        terminalId: string;
    }>;
    terminalOutput(params: TerminalOutputRequest): Promise<TerminalOutputResponse>;
    waitForTerminalExit(params: WaitForTerminalExitRequest): Promise<TerminalExit>;
    releaseTerminal(params: {
        sessionId: string;
        terminalId: string;
    }): Promise<void>;
    killTerminal(params: KillTerminalRequest): Promise<Record<string, never>>;
    private spawnProcess;
    private applySessionState;
    private transformConfigOptions;
    private transformModeId;
    private applyConfiguredOverrides;
    private warnInvalidSelection;
    private modelSelectionUnavailableMessage;
    private isModelSelectionUnavailableError;
    private translateSessionUpdate;
    private handleToolCallUpdate;
    private createMessageTimelineItem;
    private handleCurrentModeUpdate;
    private handleConfigOptionUpdate;
    private handleSessionInfoUpdate;
    private handleUsageUpdate;
    private handlePromptResponse;
    private wrapTimeline;
    private pushEvent;
    private emitSubmittedUserMessage;
    private runtimeInfo;
    private finishTurn;
    private emitBootstrapThreadEvent;
    private synthesizeCanceledToolCalls;
    private collectDiagnostic;
    private getTerminalEntry;
}
export {};
//# sourceMappingURL=acp-agent.d.ts.map