/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ export declare class WorkerManager { private workers; private readyWorkers; /** Function names registered on each worker, populated from the ready message. */ private workerFunctions; private workerStreamFunctions; private workerPreviewFunctions; /** Persistent factories for workers that can be recreated after termination. */ private workerFactories; /** Idle timeout configuration per registered worker. */ private idleTimeouts; /** Single-flight init promise per name (lazy path). */ private lazyInitPromises; /** In-flight call count per worker name. */ private activeCallCounts; /** Scheduled idle termination timer per worker name. */ private idleTimers; /** In-flight termination promise per worker name. */ private terminationPromises; registerWorker(name: string, workerOrFactory: Worker | (() => Worker), options?: { idleTimeoutMs?: number; }): void; private attachWorkerInstance; /** * Ensures a lazy worker is constructed and ready. No-op if already * registered eagerly. */ private ensureWorkerReady; getWorker(name: string): Worker; private beginWorkerActivity; private endWorkerActivity; private clearIdleTimer; private scheduleIdleTermination; private cleanupFailedInitialization; private terminateWorkerInstance; callWorkerFunction(workerName: string, functionName: string, args: any[], options?: { signal?: AbortSignal; onProgress?: (progress: number, message?: string, details?: any) => void; }): Promise; /** * Call a preview function on a worker. Returns undefined (rather than throwing) * if the worker has no preview function registered for the given name, so callers * can treat the result as an optional preview. * * @param workerName - Registered worker name * @param functionName - Name of the preview function registered on the worker * @param args - Arguments to pass: [input, output, model] * @returns The preview result, or undefined if not registered / on error */ callWorkerPreviewFunction(workerName: string, functionName: string, args: any[]): Promise; /** * Terminate a single worker and clean up all associated state. */ terminateWorker(name: string): Promise; /** * Terminate all workers and release resources. */ dispose(): Promise; [Symbol.asyncDispose](): Promise; /** * Call a streaming function on a worker and return an AsyncGenerator that * yields each stream chunk sent by the worker. The worker sends `stream_chunk` * messages for each yielded event and a `complete` message when the generator * finishes. An `error` message from the worker causes the iterator to throw. * * @param workerName - Registered worker name * @param functionName - Name of the stream function registered on the worker * @param args - Arguments to pass to the stream function * @param options - Optional abort signal * @returns AsyncGenerator yielding stream events from the worker */ callWorkerStreamFunction(workerName: string, functionName: string, args: any[], options?: { signal?: AbortSignal; }): AsyncGenerator; /** * Calls a new-shape run function on a registered worker. Returns * `Promise`; the run-fn's emitted events arrive via the caller-supplied * `emit` callback (passed via `options.emit`). The Promise resolves on the * worker's terminal `result` message and rejects on `error`. * * Wire protocol: same `stream_chunk` messages as {@link callWorkerStreamFunction} * for events; the terminal `complete` message carries `data: undefined` and * signals completion. `postMessage` ordering on the same port guarantees all * `stream_chunk` messages arrive before the terminal `complete`, so the local * message handler drains them before resolving. */ callWorkerRunFunction(workerName: string, functionName: string, args: unknown[], options: { signal?: AbortSignal; emit: (event: T) => void; }): Promise; } export declare const WORKER_MANAGER: import("../di").ServiceToken; /** * Registers the WorkerManager default factory on the given registry. * Called by `bootstrapWorkglow` and `createOrchestrationContext`. */ export declare function registerWorkerManagerDefaults(registry?: import("../di/ServiceRegistry").ServiceRegistry): void; //# sourceMappingURL=WorkerManager.d.ts.map