import { type SharedWorkerLaunch } from "../subprocess/shared-worker.js"; import { type RefCountedWorkerHandle } from "../subprocess/worker-client.js"; import { type TinyLocalModelKey } from "./models.js"; import { type TinyChatMessage, type TinyTitleProgressEvent, type TinyWorkerBackend, type TinyWorkerRequest, type TinyWorkerResponse } from "./title-protocol.js"; type WorkerHandle = RefCountedWorkerHandle; export interface TinyTitleDownloadResult { ok: boolean; error?: string; } 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; } export interface TinyModelChatOptions { maxTokens?: number; signal?: AbortSignal; } export interface TinyModelCompletionOptions extends TinyModelChatOptions { systemPrompt?: string; } /** * Map the resolved `providers.tinyModelDevice` / `providers.tinyModelDtype` * values onto the `PI_TINY_DEVICE` / `PI_TINY_DTYPE` vars a worker should run * with. Only resolved keys are returned — never the default sentinel — so the * worker's built-in defaults apply for anything absent. Pure for testability; * see {@link tinyModelEnv} for the settings glue. * @internal */ export declare function tinyWorkerEnvOverlay(deviceSetting: string | undefined, dtypeSetting: string | undefined): Record; /** Identity of the resolved device/dtype; a worker started under a different key is stale. */ export declare function tinyModelEnvKey(): string; /** * Env for an ONNX inference subprocess with the resolved device/dtype — * used for the tiny worker and reused verbatim by the STT and TTS workers, * which share the same device/dtype resolution. */ export declare function tinyWorkerEnv(): Record; /** Whether a worker started now would run the MLX backend (device resolves to `mlx` on Apple silicon). */ export declare function tinyWorkerUsesMlx(): boolean; /** How to start one tiny worker: a shared-worker launch plus the backend that names its endpoint. */ export interface TinyWorkerLaunch extends SharedWorkerLaunch { backend: TinyWorkerBackend; } /** How to start the ONNX worker for `modelKey` with the resolved device/dtype env. @internal */ export declare function onnxLaunch(modelKey: TinyLocalModelKey, modelEnv: Record): TinyWorkerLaunch; /** Connect to the machine-shared worker serving `modelKey` on `launch.backend`, spawning or replacing it as needed. */ export declare function connectTinyWorker(launch: TinyWorkerLaunch, modelKey: TinyLocalModelKey, runtimeDir?: string): Promise; /** * Per-model worker connections. Device/dtype settings are read at use time: a * connection made under a different device/dtype is replaced on its next idle * use, and the launch-tag probe then swaps the machine-wide worker. */ export declare class TinyTitleClient { #private; constructor(connect?: (modelKey: TinyLocalModelKey) => Promise); onProgress(listener: (event: TinyTitleProgressEvent) => void): () => void; /** * Reach the model's worker ahead of first use without loading anything, so * the first {@link generate} finds a live connection instead of paying the * probe/spawn latency on the submit hot path (issue #6462). No-ops for * online / non-local keys and for models already marked failed. */ prewarm(modelKey: string): void; generate(modelKey: string, message: string, signal?: AbortSignal): Promise; generate(modelKey: string, message: string, options?: TinyTitleGenerateOptions): Promise; chat(modelKey: string, messages: readonly TinyChatMessage[], options?: TinyModelChatOptions): Promise; complete(modelKey: string, promptText: string, options?: TinyModelCompletionOptions): Promise; downloadModel(modelKey: string, options?: TinyTitleDownloadOptions): Promise; terminate(): Promise; } export declare const tinyTitleClient: TinyTitleClient; /** Alias for the shared tiny-model worker client (titles + generic chat completions). */ export declare const tinyModelClient: TinyTitleClient; /** Drop this process's worker connections; the workers themselves keep serving others until idle. */ export declare function shutdownTinyTitleClient(): Promise; /** Exercise ONNX worker startup and the tagged ping handshake for distribution smoke tests. */ export declare function smokeTestTinyTitleWorker({ timeoutMs, }?: { timeoutMs?: number; }): Promise; export {};