type WebAIPrecision = "fp32" | "fp16" | "q8" | "int8" | "uint8" | "q4" | "bnb4" | "q4f16"; type WebAIDevice = "wasm" | "webgpu"; /** Runtime settings passed to model workers. No telemetry is collected. */ type WebAIWorkerConfig = { /** Repository identifier understood by Transformers.js. */ modelId?: string; /** Optional immutable Hugging Face commit/revision. */ modelRevision?: string; /** Optional custom model host, for example https://huggingface.co. */ remoteHost?: string; /** Path template appended to remoteHost by Transformers.js. */ remotePathTemplate?: string; /** Local model root used when allowLocalModels is enabled. */ localModelPath?: string; allowRemoteModels?: boolean; allowLocalModels?: boolean; useBrowserCache?: boolean; }; type WebAIOptions = { modelId: string; /** Defaults to /workers/{modelId}.worker.js on the application's origin. */ workerPath?: string; workerConfig?: WebAIWorkerConfig; /** Maximum time to wait for the worker boot handshake. */ workerInitTimeoutMs?: number; }; type ProgressType = { file?: string; name?: string; loaded?: number; total?: number; status?: string; progress?: number; }; type WebAIRuntime = { /** Total execution time after leaving the queue, including worker messaging. */ durationMs: number; }; type WebAIResult = { /** The model-specific output, unchanged by the core runtime. */ result: T; runtime: WebAIRuntime; }; type WebAIWorkerField = { name: string; type: string; description: string; required?: boolean; default?: unknown; enum?: unknown[]; minimum?: number; maximum?: number; }; type WebAIWorkerManifest = { contractVersion: "1.0"; model: { id: string; displayName: string; /** Original model creator, not the ONNX conversion publisher. */ provider: string; /** Authoritative homepage for the original model provider. */ providerUrl: string; /** SPDX license identifier, or LicenseRef-* for a non-standard license. */ license: string; /** Authoritative license text for the original model. */ licenseUrl: string; /** ISO timestamp from the authoritative original model repository. */ lastUpdated: string; sourceRepository: string; repository: string; artifactRevision: string; artifactLastUpdated?: string; task: string; description: string; intendedUses: string[]; limitations: string[]; }; runtime: { precisions: SupportedPrecisionsDevicesMapType; }; input: { description: string; alternatives: Array<{ name: string; description: string; fields: WebAIWorkerField[]; }>; }; config: { model: WebAIWorkerField[]; generation: WebAIWorkerField[]; }; output: { description: string; fields: WebAIWorkerField[]; example: unknown; }; benchmark?: { report: string; testedAt: string; fixture: { file: string; url: string; size: number; sha1: string; durationSeconds: number; }; note?: string; environment: string; invalidatedBy: string[]; results: Array<{ precision: WebAIPrecision; device: WebAIDevice; status: "pass" | "fail"; runtime: { loadMs: number | null; inferenceMs: number | null; totalMs: number; grade: string; realTimeFactor?: number; loadGrade?: string; }; quality?: { grade: string; wordErrorRate: number; gibberish: boolean; }; failure?: string; }>; }; operations: Array<"checkModelSupports" | "init" | "download" | "generate" | "generateStream" | "clearMemory">; }; type WhisperTimestamp = [startSeconds: number, endSeconds: number | null]; type WhisperTranscriptionChunk = { text: string; timestamp: WhisperTimestamp; }; type WhisperTranscriptionResult = { result: string; /** Present when return_timestamps is "word" or true. */ chunks?: WhisperTranscriptionChunk[]; }; type WhisperModelConfig = { language?: string; task?: "transcribe" | "translate"; /** "word" returns word-level timestamps; true returns segment timestamps. */ return_timestamps?: "word" | boolean; condition_on_prev_tokens?: boolean; no_speech_threshold?: number; num_beams?: number; }; type WhisperGenerationConfig = { chunk_length_s?: number; stride_length_s?: number; }; type PriorityConfig = { precision: WebAIPrecision; device: WebAIDevice; }; type WebAIPriorities = PriorityConfig[]; type SupportedPrecisionsDevicesMapType = Partial; }>>; declare class WebAI { #private; private _modelId; private _workerPath?; private _workerManager; private _modelManager; private _queueManager; private _isWebGPUAvailable; private _storageQuota; private _isInitialized; private _isInitializing; private constructor(); static create(options: WebAIOptions): Promise; init({ precision, device, priorities, onDownloadProgress, callbackThrottle }?: { precision?: WebAIPrecision; device?: WebAIDevice; priorities?: WebAIPriorities; onDownloadProgress?: (progress: ProgressType) => void; callbackThrottle?: number; }): Promise; generate(data: { userInput?: any; modelConfig?: object; generateConfig?: object; } | any): Promise>; generateStream(data: { userInput: any; modelConfig?: object; generateConfig?: object; onStream: (chunk: any) => void; }): Promise; clearQueue({ interrupt }?: { interrupt?: boolean; }): Promise; deleteDownloadedModel({ precision }?: { precision?: WebAIPrecision; }): Promise; terminate(): Promise; interrupt({ clearQueue }?: { clearQueue?: boolean; }): Promise; private _handleWorkerInterrupt; clearMemory(): Promise; checkIsModelDownloaded({ precision }: { precision: WebAIPrecision; }): Promise; downloadModel({ precision, onDownloadProgress, callbackThrottle }: { precision: WebAIPrecision; onDownloadProgress?: (progress: ProgressType) => void; callbackThrottle?: number; }): Promise; get modelId(): string; get precision(): WebAIPrecision | null; get device(): WebAIDevice | null; get isWebGPUAvailable(): boolean | null; get deviceStorageQuota(): StorageEstimate | null; get modelSupportedPrecisionsDevicesMap(): Partial; }>> | null; get modelSupportedPrecisions(): WebAIPrecision[] | null; get doesSupportStreamGeneration(): boolean | null; get externalInterrupt(): boolean | null; /** Self-described input, configuration, output, and operation contract. */ get modelManifest(): WebAIWorkerManifest | null; get isGenerating(): boolean; get queueLength(): number; get isInitialized(): boolean; } declare enum ErrorCategory { VALIDATION = "ValidationError", NETWORK = "NetworkError", SYSTEM = "SystemError", WORKER = "WorkerError", UNEXPECTED = "UnexpectedError", RESOURCE = "ResourceError" } declare function createError(message: string, category: ErrorCategory, type: string, details?: Record): Error; declare function identifyError(error: any): { category: string; type: string; } | null; type WorkerErrorType = 'initialization_failed' | 'runtime_error' | 'message_error' | 'worker_terminated' | 'resource_limit_exceeded' | 'worker_timeout' | 'interrupted' | 'security_error'; declare function createWorkerError(message: string, type: WorkerErrorType, details?: Record): Error; type NetworkErrorType = 'request_timeout' | 'connection_failed' | 'api_error' | 'rate_limited' | 'server_error' | 'client_error'; declare function createNetworkError(message: string, type: NetworkErrorType, details?: Record): Error; declare function isErrorOf(error: any, category?: ErrorCategory, type?: string): boolean; declare function isWorkerError(error: any): boolean; declare function isNetworkError(error: any): boolean; declare function checkIsWebGPUAvailable(): Promise; declare function checkStorageQuota(): Promise; declare function checkIsModelDownloaded(precision: string, modelKeys: string[], modelId: string): Promise; declare function clearModelCache(modelId: string): Promise; declare function isLocalPath(path: string): boolean; export { ErrorCategory, type NetworkErrorType, type PriorityConfig, type ProgressType, type SupportedPrecisionsDevicesMapType, WebAI, type WebAIDevice, type WebAIOptions, type WebAIPrecision, type WebAIPriorities, type WebAIResult, type WebAIRuntime, type WebAIWorkerConfig, type WebAIWorkerField, type WebAIWorkerManifest, type WhisperGenerationConfig, type WhisperModelConfig, type WhisperTimestamp, type WhisperTranscriptionChunk, type WhisperTranscriptionResult, type WorkerErrorType, checkIsModelDownloaded, checkIsWebGPUAvailable, checkStorageQuota, clearModelCache, createError, createNetworkError, createWorkerError, WebAI as default, identifyError, isErrorOf, isLocalPath, isNetworkError, isWorkerError };