/** Shared runtime plumbing: the injectable Transformers.js implementation and * backend selection. Nothing here assumes a particular model host — where a * model comes from is always stated explicitly (see source.ts). */ export interface TransformersLike { pipeline: (task: string, model: string, opts?: Record) => Promise; env: any; TextStreamer?: new (tokenizer: any, opts: Record) => unknown; } export interface RuntimeOptions { /** Bring your own transformers implementation (full build, lite build, or a * custom one). Defaults to loading it from a CDN. */ transformers?: TransformersLike; } export declare function resolveTransformers(opts?: RuntimeOptions): Promise; export type Device = 'auto' | 'webgpu' | 'wasm' | 'cpu' | (string & {}); /** Pick the fastest available backend: WebGPU when the browser exposes a usable * adapter, otherwise WASM (CPU). Everything in this library works on both — * GPU is an accelerator, never a requirement. */ export declare function detectDevice(preferred?: Device): Promise; export declare const DTYPE_FILES: Record; export declare const DTYPE_ORDER: readonly ["q4", "q8", "fp16", "fp32"]; /** dtype to prefer on a given backend. * * q4 first on BOTH backends. WebGPU used to prefer fp16 — the conventional * choice, since a GPU has the memory bandwidth for it — and that made small * models unreliable at the one job they are good for. Measured on * Qwen2.5-0.5B-Instruct over three tool-calling questions * (`npm run test:models`): * * q4 3/3 called and answered from the result * fp16 3/3 called, 2/3 correct — it read 1096637 back as "109,663,700" * q8 0/3 — narrated ("I would need to use a specific tool") and never called * * A faster answer that silently corrupts a tool result is worse than a slower * correct one, so correctness picks the default and fp16 stays one explicit * option away. Larger models may well prefer fp16; state it when you know. */ export declare function preferredDtypeOrder(device: string): readonly string[]; /** Builds the location of one of a model's dtype files. Sources differ in * layout — a served folder puts them at `/onnx/…`, the Hub at * `/resolve//onnx/…` — so the source decides, not this * module. See `dtypeProbe` in source.ts. */ export type DtypeProbe = (file: string) => string; /** Probe which dtype variants exist for a model and return the best one for * this backend. Works for any host serving the standard onnx/ layout. * * Without a `probe`, falls back to the local-model base — correct for `base` * and `archive` sources, which point `env.localModelPath` at their files. A * `hub` source has no local base and must pass one. */ export declare function detectDtype(tjs: TransformersLike, modelId: string, device?: string, probe?: DtypeProbe): Promise; /** Every dtype variant the source actually serves, best-first. * * This answers "what is on the host", which is NOT the same question as "what * works". Availability is knowable from a HEAD request; whether a model can * call a tool at a given quantization is only knowable by running it — the two * come apart badly, and in both directions (Qwen2.5-0.5B calls tools at q4 and * not at q8; Qwen3-0.6B is the reverse). `detectDtype` takes the first of * these and hopes; {@link NexusChat.loadForTools} walks the whole list and * verifies. */ export declare function availableDtypes(tjs: TransformersLike, modelId: string, device?: string, probe?: DtypeProbe): Promise;