/**
 * The `codegraph ui` server.
 *
 * A loopback-only `node:http` server that hands the browser the built viewer
 * (`dist/viewer/`) and, through the JSON API mounted on the `api` seam below
 * (`./api`), a view of one indexed project. No framework, no new dependency: it
 * answers GET, serves files, and refuses everything else.
 *
 * It is a reader with one exception, added deliberately and scoped as narrowly
 * as it could be: `POST`/`DELETE /api/trails` saves and removes the reader's own
 * named trails, as JSON files under `.codegraph/ui/trails/`. Nothing else it
 * serves has a side effect, no other path accepts a write, and `--read-only`
 * turns even that one off. See `security.ts` for what a write has to carry.
 *
 * The interesting part is not the routing, it is the boundary in `security.ts`.
 * Read that first.
 */
import * as http from 'http';
export { ViewerMissingError } from './assets';
export { BROWSER_ENV, DEFAULT_PORT_ATTEMPTS, DEFAULT_UI_PORT, LOOPBACK_ADDRESS, VIEWER_PATH_ENV, } from './constants';
export { ALLOWED_METHODS, READ_METHODS, WRITE_HEADER, WRITE_METHODS, PathRefusalError, isAllowedHost, isAllowedOrigin, isSafeRequestPath, isWriteMethod, isWriteRequest, resolveProjectFile, resolveStaticAsset, } from './security';
export { browserOpenCommand, openBrowser } from './open-browser';
export { contentTypeFor, cacheControlFor } from './static';
export { createGraphApi, GraphSession, ApiError } from './api';
export type { GraphApi, GraphApiOptions } from './api';
/**
 * Everything a request handler needs, already validated.
 */
export interface UiRequestContext {
    /** Percent-decoded path portion of the request URL, always starting with `/`. */
    pathname: string;
    /** Parsed query string. */
    query: URLSearchParams;
    /** Absolute path of the indexed project this server is reading. */
    projectRoot: string;
    /**
     * The request method. `GET` or `HEAD` for every read; `POST` or `DELETE`
     * only for a request that already passed {@link isWriteRequest}, which is
     * `/api/trails` and nothing else.
     */
    method: string;
}
/**
 * A handler mounted under `/api/`. Returns `true` when it answered the request
 * (i.e. wrote a response), `false` to fall through to a 404.
 *
 * This is the seam the JSON API plugs into. Everything it reads out of — or
 * writes into — the user's repository must go through `resolveProjectFile`;
 * see `security.ts`.
 */
export type UiApiHandler = (req: http.IncomingMessage, res: http.ServerResponse, ctx: UiRequestContext) => boolean | Promise<boolean>;
export interface UiServerOptions {
    /** Absolute path of the indexed project to read. */
    projectRoot: string;
    /**
     * Port to bind. `0` lets the OS choose. Defaults to {@link DEFAULT_UI_PORT}.
     */
    port?: number;
    /**
     * Try the next port when the requested one is taken (default `true`).
     *
     * The CLI turns this OFF for an explicit `--port`: a scripted invocation that
     * silently lands somewhere else is worse than one that says the port is busy.
     */
    portFallback?: boolean;
    /** How many ports to try in total. Defaults to {@link DEFAULT_PORT_ATTEMPTS}. */
    maxPortAttempts?: number;
    /** Directory of built viewer assets. Defaults to the shipped `dist/viewer/`. */
    viewerDir?: string;
    /** Optional read-only JSON API mounted under `/api/`. */
    api?: UiApiHandler;
}
export interface UiServerHandle {
    /** The port actually bound (may differ from the requested one — see fallback). */
    port: number;
    /** The URL to open. */
    url: string;
    /** Directory being served as the viewer. */
    viewerDir: string;
    /** The underlying server, for tests and for callers that want raw events. */
    server: http.Server;
    /** Stop listening and drop live connections. Idempotent. */
    close(): Promise<void>;
}
/**
 * Start the viewer server.
 *
 * Resolves once the socket is bound, so the caller can print a URL that is
 * already answering.
 */
export declare function startUiServer(options: UiServerOptions): Promise<UiServerHandle>;
//# sourceMappingURL=index.d.ts.map