import * as WebSocket from 'ws';
import { TaskPayload, TaskResponse } from '../models/server-message.model';
import { MethodManager } from './method.manager';
import { WebSocketManager } from './websocket.manager';
export interface WorkerConnection {
    id: string;
    ws: WebSocket.WebSocket;
    activeTasks: {
        taskId: string;
        weight: number;
        method?: string;
        startedAt?: number;
        messageId?: number;
        userContext?: {
            id_user?: string;
            user?: string;
            id_ws?: string;
        };
    }[];
    workerIndex?: string;
    workerInstance?: string;
}
export declare class WorkerDispatcherManager {
    private _websocketManager;
    private _methodManager;
    private _workers;
    private _taskQueue;
    private _clientRequests;
    private _pendingTasks;
    private _debugNoWorkerTaskIds;
    private _debugCodexTaskIds;
    private _taskTimings;
    private _dispatchRetryTimer;
    private _dispatchRetryDelayMs;
    private _nonCodexReserve;
    private _publicationWorkerIndexes;
    private _publicationWorkerInstances;
    private _codexWorkerIndexes;
    private _codexWorkerInstances;
    private MAX_CONCURRENCY;
    private WORKER_TASK_LOG_THRESHOLD_MS;
    private WORKER_PUBLICATION_SLOW_MS;
    private _workerTaskDebug;
    private _aiWorkerDebug;
    constructor();
    static create(websocketManager: WebSocketManager, methodManager: MethodManager): WorkerDispatcherManager;
    initialize(websocketManager: WebSocketManager, methodManager: MethodManager): void;
    private parseDebugFlag;
    private parsePositiveInt;
    private parseWorkerSelector;
    private selectorToArray;
    private hasWorkerSelector;
    private workerMatchesSelector;
    private resolveTaskQueue;
    private summarizePublicationValue;
    private getPublicationLogInfo;
    isSafeShutdown(): boolean;
    addWorker(ws: WebSocket.WebSocket): void;
    private failActiveWorkerTask;
    disconnectWorker(workerId: string, reason?: string): void;
    hasWorkers(): boolean;
    getQueueSnapshot(): {
        queueDepth: number;
        pendingTasks: number;
        workerCount: number;
        activeTasks: number;
        workers: {
            id: string;
            index: string;
            instance: string;
            activeTasks: number;
        }[];
    };
    hasWorkersForMethod(methodName: string): boolean;
    /**
     * Add a new task to our in-memory queue and try to dispatch.
     */
    sendClientTask(messageId: number, method: string, params: any[], userContext?: {
        id_user?: string;
        user?: string;
        id_ws?: string;
    }): void;
    /**
     * Same as sendInternalTask but returns a Promise so you can `await` it.
     */
    sendInternalPromise(method: string, params?: any[]): Promise<any>;
    /**
     * Send a task internally and resolve with the raw TaskResponse (includes packedResult/meta).
     */
    sendInternalPromiseRaw(method: string, params?: any[]): Promise<TaskResponse>;
    /**
     * Send a task internally without returning a promise.
     */
    sendInternalTask(method: string, params?: any[]): void;
    /**
     * The main loop that assigns tasks from _taskQueue to any worker that has capacity.
     */
    private dispatchQueue;
    private scheduleDispatchRetry;
    /**
     * Returns the worker with the fewest activeTasks that is under maxConcurrency and per-method limit.
     */
    private findWorkerForTask;
    private logCodexSelection;
    private normalizeWorkerIndex;
    private isGeneralPurposeWorker;
    private filterGeneralPurposeWorkers;
    private getWorkerLoad;
    private isWorkerZero;
    private assignTaskToWorker;
    private logNoWorkerAvailability;
    private shouldDebug;
    private logWorkerEvent;
    private safeStringify;
    /**
     * Handle messages coming back from a worker (like 'taskComplete').
     */
    handleWorkerMessage(workerId: string, rawMessage: WebSocket.RawData): void;
    sendWorkerPayload(ws: WebSocket.WebSocket, payload: TaskPayload | string): void;
}
