import { EventEmitter } from 'events'; import { EnhancedError } from '../utils/enhanced-errors.js'; import { Result } from './unified-lifecycle-manager.js'; import { AtomicTask, TaskPriority } from '../types/task.js'; export type OrchestrationId = string & { readonly __brand: 'OrchestrationId'; }; export type WorkflowId = string & { readonly __brand: 'WorkflowId'; }; export type AgentId = string & { readonly __brand: 'AgentId'; }; export type ExecutionId = string & { readonly __brand: 'ExecutionId'; }; export type ScheduleId = string & { readonly __brand: 'ScheduleId'; }; export declare function createOrchestrationId(id: string): OrchestrationId; export declare function createWorkflowId(id: string): WorkflowId; export declare function createAgentId(id: string): AgentId; export declare function createExecutionId(id: string): ExecutionId; export declare function createScheduleId(id: string): ScheduleId; export type AgentStatus = 'online' | 'offline' | 'busy' | 'idle' | 'error' | 'maintenance'; export type AgentCapability = 'task_execution' | 'code_generation' | 'testing' | 'documentation' | 'research' | 'analysis' | 'deployment' | 'monitoring' | 'debugging'; export type WorkflowPhase = 'initialization' | 'decomposition' | 'planning' | 'assignment' | 'execution' | 'monitoring' | 'validation' | 'completion' | 'error_recovery'; export type AssignmentStrategy = 'round_robin' | 'least_loaded' | 'capability_first' | 'performance_based' | 'intelligent_hybrid'; export type ExecutionStatus = 'pending' | 'scheduled' | 'running' | 'paused' | 'completed' | 'failed' | 'cancelled' | 'timeout' | 'error'; export interface AgentInfo { id: AgentId; name: string; status: AgentStatus; capabilities: AgentCapability[]; currentLoad: number; maxConcurrentTasks: number; currentTasks: string[]; performance: { averageTaskTime: number; successRate: number; errorRate: number; lastActivity: Date; }; metadata: { version: string; endpoint?: string; heartbeatInterval: number; lastHeartbeat: Date; registeredAt: Date; }; } export interface WorkflowState { id: WorkflowId; phase: WorkflowPhase; status: ExecutionStatus; projectId: string; sessionId: string; tasks: string[]; assignedAgents: AgentId[]; startTime: Date; endTime?: Date; progress: { totalTasks: number; completedTasks: number; failedTasks: number; percentage: number; }; metadata: { initiator: string; priority: TaskPriority; estimatedDuration: number; actualDuration?: number; }; } export interface TaskAssignment { id: string; taskId: string; agentId: AgentId; workflowId: WorkflowId; assignedAt: Date; startedAt?: Date; completedAt?: Date; status: ExecutionStatus; priority: TaskPriority; estimatedDuration: number; actualDuration?: number; retryCount: number; maxRetries: number; metadata: Record; } export interface ExecutionContext { id: ExecutionId; workflowId: WorkflowId; taskId: string; agentId: AgentId; status: ExecutionStatus; startTime: Date; endTime?: Date; progress: number; logs: string[]; errors: string[]; metrics: { memoryUsage: number; cpuUsage: number; responseTime: number; }; watchdog: { enabled: boolean; timeoutMs: number; lastCheck: Date; violations: number; }; } export interface ScheduleEntry { id: ScheduleId; taskId: string; workflowId: WorkflowId; scheduledAt: Date; priority: TaskPriority; dependencies: string[]; constraints: { requiredCapabilities: AgentCapability[]; preferredAgents: AgentId[]; excludedAgents: AgentId[]; maxRetries: number; timeoutMs: number; }; status: 'pending' | 'scheduled' | 'assigned' | 'completed' | 'failed'; assignedAgent?: AgentId; createdAt: Date; updatedAt: Date; } export interface UnifiedOrchestrationEngineConfig { enabled: boolean; maxConcurrentWorkflows: number; maxConcurrentExecutions: number; defaultTimeout: number; heartbeatInterval: number; agentManagement: { maxAgents: number; heartbeatTimeout: number; offlineThreshold: number; autoRecovery: boolean; loadBalancing: boolean; }; workflowManagement: { persistState: boolean; stateBackupInterval: number; maxWorkflowDuration: number; autoCleanup: boolean; cleanupInterval: number; }; taskScheduling: { strategy: AssignmentStrategy; batchSize: number; schedulingInterval: number; priorityWeights: Record; dependencyResolution: boolean; }; executionMonitoring: { watchdogEnabled: boolean; watchdogInterval: number; performanceTracking: boolean; metricsCollection: boolean; alertThresholds: { errorRate: number; responseTime: number; memoryUsage: number; }; }; recovery: { autoRetry: boolean; maxRetries: number; retryDelay: number; failureEscalation: boolean; deadlockDetection: boolean; }; } export interface OrchestrationStatistics { agents: { total: number; online: number; busy: number; idle: number; offline: number; averageLoad: number; }; workflows: { active: number; completed: number; failed: number; averageDuration: number; }; tasks: { scheduled: number; running: number; completed: number; failed: number; averageExecutionTime: number; }; performance: { throughput: number; successRate: number; errorRate: number; averageResponseTime: number; }; } export declare class UnifiedOrchestrationEngine extends EventEmitter { private static instance; private readonly config; private readonly dataDirectory; private initialized; private readonly agents; private readonly workflows; private readonly assignments; private readonly executions; private readonly schedule; private orchestrationCount; private workflowCount; private taskExecutionCount; private totalExecutionTime; private errorCount; private heartbeatTimer; private schedulerTimer; private watchdogTimer; private cleanupTimer; private metricsTimer; private constructor(); static getInstance(config?: UnifiedOrchestrationEngineConfig): UnifiedOrchestrationEngine; static resetInstance(): void; initialize(): Promise>; private createDataDirectories; private loadPersistedState; private startBackgroundProcesses; registerAgent(agentInfo: Omit): Promise>; updateAgentStatus(agentId: AgentId, status: AgentStatus): Promise>; getAvailableAgents(requiredCapabilities?: AgentCapability[]): Promise>; createWorkflow(projectId: string, sessionId: string, tasks: string[], priority?: TaskPriority): Promise>; updateWorkflowPhase(workflowId: WorkflowId, phase: WorkflowPhase): Promise>; scheduleTask(task: AtomicTask, workflowId: WorkflowId, constraints?: Partial): Promise>; assignTask(scheduleId: ScheduleId, agentId: AgentId): Promise>; startExecution(assignmentId: string): Promise>; updateExecutionProgress(executionId: ExecutionId, progress: number, logs?: string[]): Promise>; completeExecution(executionId: ExecutionId, success: boolean, result?: unknown): Promise>; private checkAgentHeartbeats; private processScheduledTasks; private runExecutionWatchdog; private cleanupCompletedWorkflows; private collectMetrics; private selectAgentByStrategy; private calculateAgentScore; private handleAgentRecovery; private handleExecutionTimeout; private fileExists; getStatistics(): OrchestrationStatistics; dispose(): void; } export declare function createDefaultOrchestrationConfig(): UnifiedOrchestrationEngineConfig; //# sourceMappingURL=unified-orchestration-engine.d.ts.map