import type { DevToolsSys } from "@builder.io/dev-tools/core";
import { type RequestHandler as ProxyRequestHandler } from "http-proxy-middleware";
import type { DevCommandState, EnvironmentVariable, HttpServerState } from "$/ai-utils";
import EventEmitter from "events";
import { ChildProcess } from "node:child_process";
import type { FusionConfig, SetupCommandState } from "$/ai-utils";
export type DevServerState = Exclude<SetupCommandState | DevCommandState, "installed" | "starting">;
export interface SetupCommandResult {
    code: number | null;
    output: string;
}
export interface DevServerOrchestrator {
    devCommand: string;
    setupCommand: string | undefined;
    setupState: SetupCommandState;
    lastServerBody: string | undefined;
    lastServerStatus: number | undefined;
    devState: DevCommandState;
    httpServerState: HttpServerState;
    state: DevServerState;
    proxyTarget: string;
    proxyPort: number;
    environmentVariables: EnvironmentVariable[];
    envVars: Record<string, string>;
    proxyMiddleware: ProxyRequestHandler | undefined;
    pid: number | undefined;
    autoDetectedUrl: string | undefined;
    abortSetupCommand: () => void;
    clearEnvVariables: () => void;
    setEnvVariable: (key: string, value: string | undefined) => boolean;
    ensureDevCommand: (abortSignal?: AbortSignal) => Promise<boolean>;
    ensureSetupCommand: (abortSignal?: AbortSignal) => Promise<boolean>;
    setupCommandPromise: Promise<SetupCommandResult> | undefined;
    runSetupCommand: (signal?: AbortSignal) => Promise<SetupCommandResult>;
    setSetupCommand: (newCommand: string, forceRestart?: boolean, signal?: AbortSignal) => Promise<SetupCommandResult | null>;
    setDevCommand: (newCommand: string, forceRestart?: boolean, signal?: AbortSignal) => Promise<boolean>;
    setProxyServer: (newProxyServer: string) => Promise<boolean>;
    setPort: (newPort: number) => Promise<boolean>;
    addCheckpoint: () => void;
    getOpenPorts: () => Promise<number[]>;
    getCheckpoints: (n: number, mode: "all" | "out" | "err") => string;
    getAllStdout: () => string;
    getAllStderr: () => string;
    getOutput: () => string;
    getSetupOutput: () => string;
    waitUntilIdle: (initialWaitMs?: number, idleTimeMs?: number) => Promise<void>;
    onClose: (callback: (code: number | null) => void) => void;
    restart: (abortSignal?: AbortSignal) => Promise<void>;
    emitter: EventEmitter<{
        close: [number | null];
        stdout: [string];
        stderr: [string];
        installStdout: [string];
        installStderr: [string];
        setupState: [SetupCommandState];
        devState: [DevCommandState];
        httpServerState: [HttpServerState];
        urlDetected: [string];
    }>;
    close: () => Promise<void>;
}
export declare function devServerOrchestrator(sys: DevToolsSys, fusionConfig: FusionConfig, initialSetupState: "installed" | "not-installed" | "install-failed"): Promise<DevServerOrchestrator>;
export declare const checkPortsListenedByPid: (pid: number) => number[];
export declare function killProcess(sys: DevToolsSys, proc: ChildProcess | undefined, abortSignal?: AbortSignal, timeout?: number): Promise<boolean>;
