import { type BijouContext } from '@flyingrobots/bijou'; import type { App, RunOptions } from '@flyingrobots/bijou-tui'; import type { RunWorkerOptions, WorkerHandle } from './worker-options.js'; export type { RunWorkerOptions, WorkerHandle } from './worker-options.js'; interface WorkerInstance { postMessage(message: unknown): void; on(event: 'message', handler: (value: MainMessage) => void): void; on(event: 'error', handler: (value: Error) => void): void; on(event: 'exit', handler: (value: number) => void): void; terminate(): Promise; } interface WorkerParentPort { on(event: 'message', listener: (msg: unknown) => void): void; off(event: 'message', listener: (msg: unknown) => void): void; postMessage(message: unknown): void; } interface WorkerThreadBindings { isMainThread: boolean; parentPort: WorkerParentPort | null; workerData: unknown; createWorker(entry: string, options: Record): WorkerInstance; createNodeContext(): BijouContext; runApp(app: App, options: RunOptions): Promise; scheduleTimeout(callback: () => void, ms: number): ReturnType; } export type WorkerMessage = { type: 'io:data'; data: string; } | { type: 'io:resize'; columns: number; rows: number; } | { type: 'data'; payload: unknown; } | { type: 'quit'; }; export type MainMessage = { type: 'render:frame'; output: string; } | { type: 'error'; message: string; } | { type: 'data'; payload: unknown; } | { type: 'quit'; }; /** * Checks if the current environment is running inside a Bijou Worker. */ export declare function isBijouWorker(): boolean; /** * Sends a custom data message from the worker to the main thread. * This will be received via the `onMessage` callback in `runInWorker`. */ export declare function sendToMain(payload: unknown): void; /** * Spawns a background worker thread to run the TEA application. * The main thread delegates all logic to the worker, only handling raw I/O * and frame rendering (to keep the TTY responsive). * * @param options - Configuration including the path to the worker entry file. * @returns A handle to the running worker. */ export declare function runInWorker(options: RunWorkerOptions, bindings?: WorkerThreadBindings): WorkerHandle; /** * The entry point for the worker thread. Must be called in the file * specified by `options.entry` in `runInWorker()`. * * Intercepts the normal `run()` execution, redirecting I/O to the parent port. * * @param app - The TEA app to run. */ export declare function startWorkerApp(app: App, bindings?: WorkerThreadBindings): Promise; //# sourceMappingURL=worker.d.ts.map