/** * Module code will be copied into worker. * * Messages between main <==> worker: * * From main thread to worker: * - Send direction: { verb, args, callbackId } * - Result direction: { callbackId, result } or { callbackId, err } * * Signal from worker to main: * - Unidirection: { verb, args } */ import type { GlueMsg } from './glue/messages'; interface Logger { debug: typeof console.debug; log: typeof console.log; warn: typeof console.warn; error: typeof console.error; } interface TaskParam { verb: 'module.init' | 'fs.alloc' | 'fs.opfs-alloc' | 'fs.write' | 'wllama.start' | 'wllama.action' | 'wllama.exit' | 'wllama.debug'; args: any[]; callbackId: number; } interface Task { resolve: any; reject: any; param: TaskParam; buffers?: ArrayBuffer[] | undefined; } export declare class ProxyToWorker { logger: Logger; suppressNativeLog: boolean; taskQueue: Task[]; taskId: number; resultQueue: Task[]; busy: boolean; worker?: Worker; pathConfig: any; multiThread: boolean; nbThread: number; constructor(pathConfig: any, nbThread: number | undefined, suppressNativeLog: boolean, logger: Logger); moduleInit(ggufFiles: { name: string; blob?: Blob; opfsCacheName?: string; }[]): Promise; wllamaStart(): Promise; wllamaAction(name: string, body: GlueMsg): Promise; wllamaExit(): Promise; wllamaDebug(): Promise; /** * Open an OPFS sync handle for a cached model file and register it in MEMFS. * No data is streamed to the WASM heap; reads are served from disk. */ private opfsFileAlloc; /** * Allocate + write a Blob to the wasm FS in one call. The file lands at * `/models/` (visible to llama.cpp via standard POSIX FS APIs) * and is backed by heapfs (mmap-friendly, no copy on read). * * This is the public surface for non-LLM auxiliary files (e.g. mmproj * GGUFs that mtmd_init_from_file() needs to open by path). */ writeFileToFs(fileName: string, blob: Blob): Promise; /** * Register an already-cached OPFS file under `/models/` in the * running worker without copying it into the WASM heap. */ registerOpfsFile(fileName: string, opfsCacheName: string): Promise; /** * Allocate a new file in heapfs * @returns fileId, to be used by fileWrite() */ private fileAlloc; /** * Write a Blob to heapfs */ private fileWrite; /** * Parse JSON result returned by cpp code. * Throw new Error if "__exception" is present in the response * * TODO: get rid of this function once everything is migrated to Glue */ private parseResult; /** * Push a new task to taskQueue */ private pushTask; /** * Main loop for processing tasks */ private runTaskLoop; /** * Handle messages from worker */ private onRecvMsg; private abort; } export {};