/**
 * ACP ServerAgent-Client Protocol server layer for qlogicagent.
 *
 * This module implements qlogicagent as an ACP Server, allowing any ACP-compliant
 * host (AionUI, Cursor, openclaw, etc.) to connect and interact with the agent.
 *
 * Protocol: ACP v1 over JSON-RPC 2.0 / stdio (line-delimited JSON).
 *
 * Responsibilities:
 * - Accepts ACP standard methods: initialize, session/new, session/prompt, session/close
 * - Accepts x/ extended methods: x/abort, x/dream, x/solo.*, x/product.*
 * - Emits ACP session/update notifications (standard + x_ extended)
 * - Translates host permission responses back to the agent
 *
 * Architecture: AcpServer wraps a Transport and delegates to an AcpRequestHandler
 * interface. The StdioServer implements this interface by routing ACP methods to
 * existing internal handlers.
 */
import type { Transport } from "./io-transport.js";
import { type AcpInitializeParams, type AcpInitializeResult, type AcpSessionNewParams, type AcpSessionLoadParams, type AcpSessionNewResult, type AcpSessionPromptParams, type AcpSessionPromptResult, type AcpSessionCloseParams, type AcpSessionSetConfigParams, type AcpSessionUpdateType, type AcpPermissionRequestParams, type AcpPermissionRequestResult } from "../protocol/wire/index.js";
export declare const ACP_ERROR_CODES: {
    readonly PARSE_ERROR: -32700;
    readonly INVALID_REQUEST: -32600;
    readonly METHOD_NOT_FOUND: -32601;
    readonly INVALID_PARAMS: -32602;
    readonly INTERNAL_ERROR: -32603;
    /** Protocol version mismatch */
    readonly PROTOCOL_MISMATCH: -32001;
    /** Session not found */
    readonly SESSION_NOT_FOUND: -32002;
    /** Agent busy (turn in progress) */
    readonly AGENT_BUSY: -32003;
};
/**
 * Interface that StdioServer (or any backend) implements to handle ACP requests.
 * Each method corresponds to an ACP protocol method.
 */
export interface AcpRequestHandler {
    handleAcpInitialize(params: AcpInitializeParams): Promise<AcpInitializeResult>;
    handleAcpSessionNew(params: AcpSessionNewParams): Promise<AcpSessionNewResult>;
    handleAcpSessionPrompt(params: AcpSessionPromptParams): Promise<AcpSessionPromptResult>;
    handleAcpSessionClose(params: AcpSessionCloseParams): Promise<void>;
    handleAcpSessionSetConfig(params: AcpSessionSetConfigParams): Promise<void>;
    handleAcpSessionSetModel(sessionId: string, model: string): Promise<void>;
    handleAcpSessionSetMode(sessionId: string, modeId: string): Promise<string>;
    handleAcpSessionLoad(params: AcpSessionLoadParams): Promise<{
        replay: Array<{
            type: "user_message_chunk" | "agent_message_chunk";
            content: string;
        }>;
    }>;
    /** Single source of truth for advertised slash commands (also summarized by /help). */
    buildAvailableCommands(): Array<{
        name: string;
        description?: string;
    }>;
    /** Pre-prompt slash-command intercept. Returns {handled,reply}; server emits + acks. */
    tryDispatchCommand(params: AcpSessionPromptParams): Promise<{
        handled: boolean;
        reply?: string;
    }>;
    handleAcpPermissionResponse(permissionId: string, optionId: string): void;
    handleAcpAbort(params: {
        sessionId: string;
        turnId?: string;
    }): Promise<void>;
    handleAcpDream(params: {
        sessionId: string;
        config?: Record<string, unknown>;
    }): Promise<{
        ok: boolean;
        summary?: string;
    }>;
    handleAcpAgentsList(): Promise<unknown>;
    handleAcpSoloStart(params: Record<string, unknown>): Promise<unknown>;
    handleAcpSoloStatus(params: Record<string, unknown>): Promise<unknown>;
    handleAcpSoloSelect(params: Record<string, unknown>): Promise<unknown>;
    handleAcpSoloCancel(params: Record<string, unknown>): Promise<unknown>;
    handleAcpSoloSubscribe(params: Record<string, unknown>): Promise<unknown>;
    handleAcpSoloMessage(params: Record<string, unknown>): Promise<unknown>;
    handleAcpSoloEvaluate(params: Record<string, unknown>): Promise<unknown>;
    handleAcpSoloSpecChat(params: Record<string, unknown>): Promise<unknown>;
    handleAcpWorkflowChat(params: Record<string, unknown>): Promise<unknown>;
    handleAcpWorkflowMatchIntent(params: Record<string, unknown>): Promise<unknown>;
    handleAcpSoloSpecJudge(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductCreate(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductPlan(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductConfirm(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductMessage(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductPause(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductResume(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductCancel(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductRollback(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductStatus(params: Record<string, unknown>): Promise<unknown>;
    handleAcpProductSubscribe(params: Record<string, unknown>): Promise<unknown>;
}
export interface AcpServerConfig {
    verbose?: boolean;
}
/**
 * AcpServermanages the ACP protocol state machine.
 *
 * Lifecycle:
 * 1. Host connects (stdio)
 * 2. Host sends `initialize` -> agent responds with capabilities
 * 3. Host sends `session/new` -> session created
 * 4. Host sends `session/prompt` -> agent runs turn, emits session/update notifications
 * 5. Host sends `session/close` -> session cleaned up
 */
export declare class AcpServer {
    private transport;
    private handler;
    private verbose;
    /** Host capabilities declared during initialize */
    private hostCapabilities;
    /** Whether the host supports x_ extended events */
    private hostSupportsExtendedEvents;
    /** Whether the host supports x/ extended RPC methods */
    private hostSupportsExtendedMethods;
    /** Sessions registered via session/new on this connection (multi-session per connection). */
    private registeredSessions;
    /** Pending permission requests (agent -> host) waiting for response */
    private pendingPermissions;
    /** Map from outbound JSON-RPC request id -> permissionId for response matching */
    private outboundRequestMap;
    constructor(transport: Transport, handler: AcpRequestHandler, config?: AcpServerConfig);
    /**
     * Route an incoming raw message through ACP protocol handling.
     * Called by the unified message dispatcher in StdioServer.
     * Returns true if the message was handled, false otherwise.
     */
    dispatchMessage(raw: unknown): boolean;
    /**
     * Emit an ACP session/update notification to the host.
     * Standard update types are always sent; x_ types only if the host declared
     * the qlogicagent capability with events enabled.
     */
    emitSessionUpdate(sessionId: string, type: AcpSessionUpdateType, payload: Record<string, unknown>): void;
    /**
     * Send a permission request to the host (agent -> host RPC).
     * Returns a promise that resolves with the host's chosen option.
     */
    requestPermission(params: AcpPermissionRequestParams): Promise<AcpPermissionRequestResult>;
    /** Whether the host supports extended events */
    get supportsExtendedEvents(): boolean;
    /** Whether the host supports extended methods */
    get supportsExtendedMethods(): boolean;
    /** Whether a session id has been registered via session/new on this connection. */
    hasSession(sessionId: string): boolean;
    private handleRequest;
    private handleNotification;
    private handleResponse;
    private onInitialize;
    private onSessionNew;
    private onSessionLoad;
    private onSessionPrompt;
    private onSessionClose;
    private onSessionSetConfig;
    private onSessionSetModel;
    private onSessionSetMode;
    private onAbort;
    private onSessionCancel;
    private onCancel;
    private onDream;
    private sendResult;
    private sendError;
    private isJsonRpcResponse;
    private log;
}
