/**
 * How the JSON API answers — success, refusal, and every failure in between.
 *
 * The viewer is the only client, and it runs on the same machine as the index,
 * so an error here is a message to a developer looking at their own project,
 * not information to withhold from a prober. Every failure therefore says what
 * went wrong and — where there is one — what to do about it, exactly the way
 * the CLI and the MCP tools do. What it never does is leak a stack trace.
 */
import type { IncomingMessage, ServerResponse } from 'http';
/**
 * Machine-readable failure reasons. The viewer switches on these rather than
 * on prose, so renaming a message never breaks a screen.
 */
export type ApiErrorCode = 'bad-request' | 'not-found' | 'refused' | 'no-index' | 'index-unusable' | 'internal';
/** An error that already carries a user-facing message and a status. */
export declare class ApiError extends Error {
    readonly code: ApiErrorCode;
    /** Optional second line: what the user can do about it. */
    readonly hint: string | undefined;
    constructor(code: ApiErrorCode, message: string, hint?: string);
}
export declare function badRequest(message: string, hint?: string): ApiError;
export declare function notFound(message: string, hint?: string): ApiError;
/** Send a successful payload. */
export declare function ok(res: ServerResponse, payload: unknown, method: string): true;
/** Send a failure. Anything that is not an {@link ApiError} becomes a 500. */
export declare function fail(res: ServerResponse, err: unknown, method: string): true;
/**
 * Bytes a request body may carry.
 *
 * The only body this server reads is a saved trail: a name and up to 64 node
 * ids. 64 KB is generous for that and small enough that a runaway client cannot
 * make the process hold a megabyte per socket.
 */
export declare const MAX_BODY_BYTES: number;
/**
 * Read a request body as JSON.
 *
 * Counts BYTES, not characters, and stops at the cap by destroying the socket
 * rather than draining a body nobody is going to parse — a `Content-Length`
 * header is a claim, and the only limit that holds is the one applied to what
 * actually arrives.
 *
 * @throws {ApiError} `bad-request` for a body that is too large or is not JSON.
 */
export declare function readJsonBody(req: IncomingMessage): Promise<unknown>;
/** A required, non-empty string parameter. */
export declare function requiredParam(query: URLSearchParams, name: string): string;
/**
 * A bounded integer parameter.
 *
 * Out-of-range values are an error rather than silently clamped: a viewer
 * asking for line 10 000 000 of a 200-line file has a bug, and answering it
 * with line 200 would hide that.
 */
export declare function intParam(query: URLSearchParams, name: string, opts: {
    min: number;
    max: number;
    default?: number;
}): number;
/**
 * Free-form text input, bounded.
 *
 * The same reasoning as the MCP tools' input ceiling: a huge string is never a
 * real query, and letting one through means a full-table LIKE scan or an FTS5
 * parse over megabytes.
 */
export declare const MAX_QUERY_LENGTH = 2000;
export declare function textParam(query: URLSearchParams, name: string): string;
/**
 * Text that must be PRESENT but may be empty — a search box the user has
 * cleared. Absent is still an error; empty is a legitimate state.
 */
export declare function optionalTextParam(query: URLSearchParams, name: string): string;
//# sourceMappingURL=respond.d.ts.map