/**
 * ACode SDK Adapter
 *
 * 主流程：直接加载随 aws-runtime-bridge 内置发布的 ACode headless runtime，
 * 不依赖外部 CLI 安装；将 ACode 的结构化事件映射为 runtime-bridge 统一事件流。
 */
import { EventEmitter } from "node:events";
import type { AdapterSessionConfig, BaseProviderAdapter, ConversationMessage, SessionStatus } from "./types.js";
type ACodeEvent = {
    type: string;
    sessionId: string;
    timestamp: string;
    data: Record<string, unknown>;
};
type ACodeRuntimeInstance = {
    on(eventName: "event", listener: (event: ACodeEvent) => void): void;
    start(): Promise<void>;
    submit(message: string): Promise<void>;
    abort(): Promise<void>;
    resetContext?(): Promise<void>;
    stop(): Promise<void>;
};
type ACodeRuntimeConstructor = new (config: {
    sessionId: string;
    workingDirectory: string;
    configPath?: string;
    skillsDir?: string;
    initialPrompt?: string;
    model?: string;
    systemPrompt?: string;
    env?: Record<string, string>;
}) => ACodeRuntimeInstance;
export declare function toAcodeEsmImportSpecifier(modulePath: string): string;
/**
 * Check whether an ACode turn_complete event represents a failed turn.
 * Main flow: only explicit failed=true prevents error status from being reset to waiting_input.
 */
export declare function isFailedAcodeTurnComplete(data: Record<string, unknown>): boolean;
export declare class AcodeSdkAdapter extends EventEmitter implements BaseProviderAdapter {
    readonly providerId = "acode";
    readonly displayName = "ACode";
    private sessions;
    private runtimeConstructor?;
    startSession(sessionId: string, config: AdapterSessionConfig): Promise<void>;
    sendMessage(sessionId: string, message: string): Promise<void>;
    sendConfirmation(_sessionId: string, _accept: boolean): Promise<void>;
    abortCurrentTurn(sessionId: string): Promise<void>;
    resetContext(sessionId: string): Promise<void>;
    terminateSession(sessionId: string): Promise<void>;
    getConversation(sessionId: string): ConversationMessage[];
    hasSession(sessionId: string): boolean;
    getProviderSessionId(sessionId: string): string | undefined;
    getSessionStatus(sessionId: string): SessionStatus | undefined;
    cleanup(): void;
    setIdleCommands(sessionId: string, commands: {
        idleInputCommand: string;
        nonInputCommand: string;
    }): void;
    /** Injects a runtime constructor for adapter tests without loading the packaged ACode module. */
    setRuntimeConstructorForTest(runtimeConstructor: ACodeRuntimeConstructor): void;
    private createRuntime;
    private loadRuntimeConstructor;
    private requireSession;
    /**
     * Run the startup prompt after the HTTP launch has already completed.
     * Main flow: mark the session busy -> submit the prompt in the background ->
     * rely on normal ACode events to publish turn completion or errors.
     */
    private startInitialPromptTurn;
    private forwardAcodeEvent;
    private emitProviderEvent;
    /**
     * After a completed turn, prefer the configured IdlePollLoop (set via setIdleCommands).
     * Fall back to the legacy auto-poll mechanism when no idle commands are configured.
     */
    private armIdleLoopOrAutoPoll;
    private getIdlePollLoop;
    private submitAutoPollPrompt;
    /**
     * Continue ACode's headless agent loop after a completed turn.
     * Main flow: debounce duplicate scheduling -> mark busy -> submit an internal
     * poll instruction -> let normal ACode events publish MCP/tool/turn states.
     *
     * @param delayMs Optional override for the default 250ms backoff. The R2
     *   recovery path uses ACODE_AUTO_POLL_FAILURE_DELAY_MS (2s) to avoid
     *   busy-looping when the same failure recurs on every retry.
     */
    private scheduleAutoPoll;
    private cancelScheduledAutoPoll;
    private isTerminalStatus;
    private emitRuntimeError;
    private emitRuntimeErrorEvent;
    private recoverTurnFailure;
    /**
     * Recover turns where runtime.submit() resolved but no terminal turn event arrived.
     *
     * Main flow: ACode should normally emit turn_complete/session_complete/error before
     * submit resolves. Some edge paths can emit only intermediate events (for example
     * command_status or tool_result), then resolve. At that point there is no active
     * turn anymore, so keeping the adapter at thinking/tool_using makes the dashboard
     * look permanently stuck. Recover to waiting_input and arm the listening loop.
     */
    private recoverResolvedTurnWithoutTerminalEvent;
}
export {};
//# sourceMappingURL=AcodeSdkAdapter.d.ts.map