import type { Subprocess } from "bun";
import type { TinyTitleProgressEvent, TinyTitleWorkerInbound, TinyTitleWorkerOutbound } from "./title-protocol";
/**
 * Abstraction over the tiny-model subprocess. Modelled as a worker interface
 * so existing callers (titles, memory completions, downloads) compose the
 * same way; the runtime implementation is a Bun child process so
 * `onnxruntime-node`'s NAPI finalizer never runs inside the main agent
 * address space — that destructor segfaults Bun on Windows during shutdown
 * (issue #1606).
 */
interface WorkerHandle {
    send(message: TinyTitleWorkerInbound): void;
    onMessage(handler: (message: TinyTitleWorkerOutbound) => void): () => void;
    onError(handler: (error: Error) => void): () => void;
    terminate(): Promise<void>;
}
export interface TinyTitleDownloadOptions {
    signal?: AbortSignal;
    onProgress?: (event: TinyTitleProgressEvent) => void;
}
/**
 * Per-request controls for {@link TinyTitleClient.generate}.
 *
 * Carries the optional abort signal and title-system-prompt override used by
 * callers that customize automatic session-title generation.
 */
export interface TinyTitleGenerateOptions {
    signal?: AbortSignal;
    systemPrompt?: string;
}
/**
 * Hidden subcommand on the main CLI that boots the tiny-model worker in the
 * spawned subprocess. Kept in sync with the dispatch in `cli.ts`.
 */
export declare const TINY_WORKER_ARG = "__omp_worker_tiny_inference";
/**
 * Decide which `PI_TINY_DEVICE` / `PI_TINY_DTYPE` vars to overlay onto the worker
 * env. A present env var wins (left untouched); otherwise the mapped persisted
 * setting is used. Returns only the keys to add — never the default sentinel.
 * Pure for testability; see {@link tinyWorkerEnv} for the spawn-time glue.
 * @internal
 */
export declare function tinyWorkerEnvOverlay(env: Record<string, string | undefined>, deviceSetting: string | undefined, dtypeSetting: string | undefined): Record<string, string>;
interface SpawnedSubprocess {
    proc: Subprocess<"ignore", "ignore", "ignore">;
    inbound: Set<(message: TinyTitleWorkerOutbound) => void>;
    errors: Set<(error: Error) => void>;
    /**
     * Flipped to `true` by {@link wrapSubprocess}'s `terminate()` right
     * before it SIGKILLs the child so `onExit` can distinguish the
     * expected hard-kill from a crash/OOM/external signal. Only the
     * latter is surfaced as a worker error.
     */
    intentionalExit: {
        value: boolean;
    };
}
/**
 * Spawn the tiny-model worker as a subprocess. Exported for tests and the
 * smoke probe; production callers go through {@link spawnTinyTitleWorker}
 * which wraps the result in a {@link WorkerHandle}.
 */
export declare function createTinyTitleSubprocess(): SpawnedSubprocess;
export declare class TinyTitleClient {
    #private;
    constructor(spawnWorker?: () => WorkerHandle);
    onProgress(listener: (event: TinyTitleProgressEvent) => void): () => void;
    generate(modelKey: string, message: string, signal?: AbortSignal): Promise<string | null>;
    generate(modelKey: string, message: string, options?: TinyTitleGenerateOptions): Promise<string | null>;
    complete(modelKey: string, prompt: string, options?: {
        maxTokens?: number;
        signal?: AbortSignal;
    }): Promise<string | null>;
    downloadModel(modelKey: string, options?: TinyTitleDownloadOptions): Promise<boolean>;
    terminate(): Promise<void>;
}
export declare const tinyTitleClient: TinyTitleClient;
/** Alias for the shared tiny-model worker client (titles + memory completions). */
export declare const tinyModelClient: TinyTitleClient;
export declare function shutdownTinyTitleClient(): Promise<void>;
export declare function smokeTestTinyTitleWorker({ timeoutMs, }?: {
    timeoutMs?: number;
}): Promise<void>;
export {};
