claude-flow-novice 1.5.12 → 1.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.claude-flow-novice/dist/mcp/auth.js +347 -0
  2. package/.claude-flow-novice/dist/mcp/claude-code-wrapper.js +717 -0
  3. package/.claude-flow-novice/dist/mcp/claude-flow-tools.js +1365 -0
  4. package/.claude-flow-novice/dist/mcp/client.js +201 -0
  5. package/.claude-flow-novice/dist/mcp/index.js +192 -0
  6. package/.claude-flow-novice/dist/mcp/integrate-wrapper.js +85 -0
  7. package/.claude-flow-novice/dist/mcp/lifecycle-manager.js +348 -0
  8. package/.claude-flow-novice/dist/mcp/load-balancer.js +386 -0
  9. package/.claude-flow-novice/dist/mcp/mcp-config-manager.js +1362 -0
  10. package/.claude-flow-novice/dist/mcp/mcp-server-novice-simplified.js +583 -0
  11. package/.claude-flow-novice/dist/mcp/mcp-server-novice.js +723 -0
  12. package/.claude-flow-novice/dist/mcp/mcp-server-sdk.js +649 -0
  13. package/.claude-flow-novice/dist/mcp/mcp-server.js +2256 -0
  14. package/.claude-flow-novice/dist/mcp/orchestration-integration.js +800 -0
  15. package/.claude-flow-novice/dist/mcp/performance-monitor.js +489 -0
  16. package/.claude-flow-novice/dist/mcp/protocol-manager.js +376 -0
  17. package/.claude-flow-novice/dist/mcp/router.js +220 -0
  18. package/.claude-flow-novice/dist/mcp/ruv-swarm-tools.js +671 -0
  19. package/.claude-flow-novice/dist/mcp/ruv-swarm-wrapper.js +254 -0
  20. package/.claude-flow-novice/dist/mcp/server-with-wrapper.js +32 -0
  21. package/.claude-flow-novice/dist/mcp/server-wrapper-mode.js +26 -0
  22. package/.claude-flow-novice/dist/mcp/server.js +539 -0
  23. package/.claude-flow-novice/dist/mcp/session-manager.js +338 -0
  24. package/.claude-flow-novice/dist/mcp/sparc-modes.js +455 -0
  25. package/.claude-flow-novice/dist/mcp/swarm-tools.js +903 -0
  26. package/.claude-flow-novice/dist/mcp/tools.js +426 -0
  27. package/.claude-flow-novice/dist/src/cli/commands/swarm.js +23 -1
  28. package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
  29. package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +40 -101
  30. package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js +36 -0
  31. package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js.map +1 -0
  32. package/.claude-flow-novice/dist/src/validators/index.js +12 -0
  33. package/.claude-flow-novice/dist/src/validators/index.js.map +1 -0
  34. package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js +261 -0
  35. package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js.map +1 -0
  36. package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js +204 -0
  37. package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js.map +1 -0
  38. package/.claude-flow-novice/dist/src/validators/todowrite-integration.js +189 -0
  39. package/.claude-flow-novice/dist/src/validators/todowrite-integration.js.map +1 -0
  40. package/package.json +2 -2
@@ -0,0 +1,800 @@
1
+ /**
2
+ * MCP Integration with Claude-Flow Orchestration System
3
+ * Provides seamless integration between MCP servers and the broader orchestration components
4
+ */ import { EventEmitter } from 'node:events';
5
+ import { SystemEvents } from '../utils/types.js';
6
+ import { MCPError } from '../utils/errors.js';
7
+ import { MCPServer } from './server.js';
8
+ import { MCPLifecycleManager, LifecycleState } from './lifecycle-manager.js';
9
+ import { MCPPerformanceMonitor } from './performance-monitor.js';
10
+ import { MCPProtocolManager } from './protocol-manager.js';
11
+ /**
12
+ * MCP Orchestration Integration Manager
13
+ * Manages the integration between MCP servers and orchestration components
14
+ */ export class MCPOrchestrationIntegration extends EventEmitter {
15
+ mcpConfig;
16
+ orchestrationConfig;
17
+ components;
18
+ logger;
19
+ server;
20
+ lifecycleManager;
21
+ performanceMonitor;
22
+ protocolManager;
23
+ integrationStatus = new Map();
24
+ healthCheckTimer;
25
+ reconnectTimers = new Map();
26
+ defaultConfig = {
27
+ enabledIntegrations: {
28
+ orchestrator: true,
29
+ swarm: true,
30
+ agents: true,
31
+ resources: true,
32
+ memory: true,
33
+ monitoring: true,
34
+ terminals: true
35
+ },
36
+ autoStart: true,
37
+ healthCheckInterval: 30000,
38
+ reconnectAttempts: 3,
39
+ reconnectDelay: 5000,
40
+ enableMetrics: true,
41
+ enableAlerts: true
42
+ };
43
+ constructor(mcpConfig, orchestrationConfig, components, logger){
44
+ super(), this.mcpConfig = mcpConfig, this.orchestrationConfig = orchestrationConfig, this.components = components, this.logger = logger;
45
+ this.orchestrationConfig = {
46
+ ...this.defaultConfig,
47
+ ...orchestrationConfig
48
+ };
49
+ this.initializeIntegration();
50
+ }
51
+ /**
52
+ * Start the MCP orchestration integration
53
+ */ async start() {
54
+ this.logger.info('Starting MCP orchestration integration');
55
+ try {
56
+ // Initialize protocol manager
57
+ this.protocolManager = new MCPProtocolManager(this.logger);
58
+ // Initialize performance monitor
59
+ if (this.orchestrationConfig.enableMetrics) {
60
+ this.performanceMonitor = new MCPPerformanceMonitor(this.logger);
61
+ this.setupPerformanceMonitoring();
62
+ }
63
+ // Create MCP server
64
+ this.server = new MCPServer(this.mcpConfig, this.components.eventBus || new EventEmitter(), this.logger, this.components.orchestrator, this.components.swarmCoordinator, this.components.agentManager, this.components.resourceManager, this.components.messageBus, this.components.monitor);
65
+ // Initialize lifecycle manager
66
+ this.lifecycleManager = new MCPLifecycleManager(this.mcpConfig, this.logger, ()=>this.server);
67
+ // Setup lifecycle event handlers
68
+ this.setupLifecycleHandlers();
69
+ // Register orchestration tools
70
+ this.registerOrchestrationTools();
71
+ // Start the server
72
+ if (this.orchestrationConfig.autoStart) {
73
+ await this.lifecycleManager.start();
74
+ }
75
+ // Start health monitoring
76
+ this.startHealthMonitoring();
77
+ // Setup component integrations
78
+ await this.setupComponentIntegrations();
79
+ this.logger.info('MCP orchestration integration started successfully');
80
+ this.emit('integrationStarted');
81
+ } catch (error) {
82
+ this.logger.error('Failed to start MCP orchestration integration', error);
83
+ throw error;
84
+ }
85
+ }
86
+ /**
87
+ * Stop the MCP orchestration integration
88
+ */ async stop() {
89
+ this.logger.info('Stopping MCP orchestration integration');
90
+ try {
91
+ // Stop health monitoring
92
+ this.stopHealthMonitoring();
93
+ // Stop lifecycle manager
94
+ if (this.lifecycleManager) {
95
+ await this.lifecycleManager.stop();
96
+ }
97
+ // Stop performance monitor
98
+ if (this.performanceMonitor) {
99
+ this.performanceMonitor.stop();
100
+ }
101
+ // Clear reconnect timers
102
+ for (const timer of this.reconnectTimers.values()){
103
+ clearTimeout(timer);
104
+ }
105
+ this.reconnectTimers.clear();
106
+ this.logger.info('MCP orchestration integration stopped');
107
+ this.emit('integrationStopped');
108
+ } catch (error) {
109
+ this.logger.error('Error stopping MCP orchestration integration', error);
110
+ throw error;
111
+ }
112
+ }
113
+ /**
114
+ * Get integration status for all components
115
+ */ getIntegrationStatus() {
116
+ return Array.from(this.integrationStatus.values());
117
+ }
118
+ /**
119
+ * Get status for a specific component
120
+ */ getComponentStatus(component) {
121
+ return this.integrationStatus.get(component);
122
+ }
123
+ /**
124
+ * Get MCP server instance
125
+ */ getServer() {
126
+ return this.server;
127
+ }
128
+ /**
129
+ * Get lifecycle manager
130
+ */ getLifecycleManager() {
131
+ return this.lifecycleManager;
132
+ }
133
+ /**
134
+ * Get performance monitor
135
+ */ getPerformanceMonitor() {
136
+ return this.performanceMonitor;
137
+ }
138
+ /**
139
+ * Get protocol manager
140
+ */ getProtocolManager() {
141
+ return this.protocolManager;
142
+ }
143
+ /**
144
+ * Force reconnection to a component
145
+ */ async reconnectComponent(component) {
146
+ const status = this.integrationStatus.get(component);
147
+ if (!status || !status.enabled) {
148
+ throw new MCPError(`Component ${component} is not enabled`);
149
+ }
150
+ this.logger.info('Reconnecting to component', {
151
+ component
152
+ });
153
+ try {
154
+ await this.connectComponent(component);
155
+ this.logger.info('Successfully reconnected to component', {
156
+ component
157
+ });
158
+ } catch (error) {
159
+ this.logger.error('Failed to reconnect to component', {
160
+ component,
161
+ error
162
+ });
163
+ throw error;
164
+ }
165
+ }
166
+ /**
167
+ * Enable/disable component integration
168
+ */ async setComponentEnabled(component, enabled) {
169
+ const status = this.integrationStatus.get(component);
170
+ if (!status) {
171
+ throw new MCPError(`Unknown component: ${component}`);
172
+ }
173
+ status.enabled = enabled;
174
+ if (enabled) {
175
+ await this.connectComponent(component);
176
+ } else {
177
+ await this.disconnectComponent(component);
178
+ }
179
+ this.logger.info('Component integration updated', {
180
+ component,
181
+ enabled
182
+ });
183
+ this.emit('componentToggled', {
184
+ component,
185
+ enabled
186
+ });
187
+ }
188
+ initializeIntegration() {
189
+ const components = [
190
+ 'orchestrator',
191
+ 'swarm',
192
+ 'agents',
193
+ 'resources',
194
+ 'memory',
195
+ 'monitoring',
196
+ 'terminals'
197
+ ];
198
+ for (const component of components){
199
+ this.integrationStatus.set(component, {
200
+ component,
201
+ enabled: this.orchestrationConfig.enabledIntegrations[component],
202
+ connected: false,
203
+ healthy: false,
204
+ lastCheck: new Date()
205
+ });
206
+ }
207
+ }
208
+ setupLifecycleHandlers() {
209
+ if (!this.lifecycleManager) return;
210
+ this.lifecycleManager.on('stateChange', (event)=>{
211
+ this.logger.info('MCP server state changed', {
212
+ from: event.previousState,
213
+ to: event.state,
214
+ error: event.error?.message
215
+ });
216
+ // Emit to orchestration event bus
217
+ if (this.components.eventBus) {
218
+ this.components.eventBus.emit(SystemEvents.SYSTEM_HEALTHCHECK, {
219
+ status: event.state === LifecycleState.RUNNING ? 'healthy' : 'unhealthy',
220
+ component: 'mcp-server',
221
+ timestamp: event.timestamp
222
+ });
223
+ }
224
+ this.emit('lifecycleStateChanged', event);
225
+ });
226
+ }
227
+ setupPerformanceMonitoring() {
228
+ if (!this.performanceMonitor) return;
229
+ this.performanceMonitor.on('metricsCollected', (metrics)=>{
230
+ // Forward metrics to orchestration monitor
231
+ if (this.components.monitor && typeof this.components.monitor.recordMetrics === 'function') {
232
+ this.components.monitor.recordMetrics('mcp', metrics);
233
+ }
234
+ this.emit('metricsCollected', metrics);
235
+ });
236
+ this.performanceMonitor.on('alertTriggered', (alert)=>{
237
+ this.logger.warn('MCP performance alert triggered', {
238
+ alertId: alert.id,
239
+ ruleName: alert.ruleName,
240
+ severity: alert.severity,
241
+ message: alert.message
242
+ });
243
+ // Forward to orchestration alert system
244
+ if (this.orchestrationConfig.enableAlerts && this.components.monitor) {
245
+ if (typeof this.components.monitor.sendAlert === 'function') {
246
+ this.components.monitor.sendAlert({
247
+ source: 'mcp',
248
+ severity: alert.severity,
249
+ message: alert.message,
250
+ metadata: alert
251
+ });
252
+ }
253
+ }
254
+ this.emit('performanceAlert', alert);
255
+ });
256
+ this.performanceMonitor.on('optimizationSuggestion', (suggestion)=>{
257
+ this.logger.info('MCP optimization suggestion', {
258
+ type: suggestion.type,
259
+ priority: suggestion.priority,
260
+ title: suggestion.title
261
+ });
262
+ this.emit('optimizationSuggestion', suggestion);
263
+ });
264
+ }
265
+ registerOrchestrationTools() {
266
+ if (!this.server) return;
267
+ // Register orchestrator tools
268
+ if (this.orchestrationConfig.enabledIntegrations.orchestrator && this.components.orchestrator) {
269
+ this.registerOrchestratorTools();
270
+ }
271
+ // Register swarm tools
272
+ if (this.orchestrationConfig.enabledIntegrations.swarm && this.components.swarmCoordinator) {
273
+ this.registerSwarmTools();
274
+ }
275
+ // Register agent tools
276
+ if (this.orchestrationConfig.enabledIntegrations.agents && this.components.agentManager) {
277
+ this.registerAgentTools();
278
+ }
279
+ // Register resource tools
280
+ if (this.orchestrationConfig.enabledIntegrations.resources && this.components.resourceManager) {
281
+ this.registerResourceTools();
282
+ }
283
+ // Register memory tools
284
+ if (this.orchestrationConfig.enabledIntegrations.memory && this.components.memoryManager) {
285
+ this.registerMemoryTools();
286
+ }
287
+ // Register monitoring tools
288
+ if (this.orchestrationConfig.enabledIntegrations.monitoring && this.components.monitor) {
289
+ this.registerMonitoringTools();
290
+ }
291
+ // Register terminal tools
292
+ if (this.orchestrationConfig.enabledIntegrations.terminals && this.components.terminalManager) {
293
+ this.registerTerminalTools();
294
+ }
295
+ }
296
+ registerOrchestratorTools() {
297
+ const tools = [
298
+ {
299
+ name: 'orchestrator/status',
300
+ description: 'Get orchestrator status and metrics',
301
+ inputSchema: {
302
+ type: 'object',
303
+ properties: {}
304
+ },
305
+ handler: async ()=>{
306
+ if (typeof this.components.orchestrator?.getStatus === 'function') {
307
+ return await this.components.orchestrator.getStatus();
308
+ }
309
+ throw new MCPError('Orchestrator status not available');
310
+ }
311
+ },
312
+ {
313
+ name: 'orchestrator/tasks',
314
+ description: 'List all tasks in the orchestrator',
315
+ inputSchema: {
316
+ type: 'object',
317
+ properties: {
318
+ status: {
319
+ type: 'string',
320
+ enum: [
321
+ 'pending',
322
+ 'running',
323
+ 'completed',
324
+ 'failed'
325
+ ]
326
+ },
327
+ limit: {
328
+ type: 'number',
329
+ minimum: 1,
330
+ maximum: 100
331
+ }
332
+ }
333
+ },
334
+ handler: async (input)=>{
335
+ if (typeof this.components.orchestrator?.listTasks === 'function') {
336
+ return await this.components.orchestrator.listTasks(input);
337
+ }
338
+ throw new MCPError('Orchestrator task listing not available');
339
+ }
340
+ }
341
+ ];
342
+ for (const tool of tools){
343
+ this.server.registerTool(tool);
344
+ }
345
+ }
346
+ registerSwarmTools() {
347
+ const tools = [
348
+ {
349
+ name: 'swarm/status',
350
+ description: 'Get swarm coordinator status',
351
+ inputSchema: {
352
+ type: 'object',
353
+ properties: {}
354
+ },
355
+ handler: async ()=>{
356
+ if (typeof this.components.swarmCoordinator?.getStatus === 'function') {
357
+ return await this.components.swarmCoordinator.getStatus();
358
+ }
359
+ throw new MCPError('Swarm coordinator status not available');
360
+ }
361
+ },
362
+ {
363
+ name: 'swarm/agents',
364
+ description: 'List active swarm agents',
365
+ inputSchema: {
366
+ type: 'object',
367
+ properties: {}
368
+ },
369
+ handler: async ()=>{
370
+ if (typeof this.components.swarmCoordinator?.listAgents === 'function') {
371
+ return await this.components.swarmCoordinator.listAgents();
372
+ }
373
+ throw new MCPError('Swarm agent listing not available');
374
+ }
375
+ }
376
+ ];
377
+ for (const tool of tools){
378
+ this.server.registerTool(tool);
379
+ }
380
+ }
381
+ registerAgentTools() {
382
+ const tools = [
383
+ {
384
+ name: 'agents/list',
385
+ description: 'List all managed agents',
386
+ inputSchema: {
387
+ type: 'object',
388
+ properties: {}
389
+ },
390
+ handler: async ()=>{
391
+ if (typeof this.components.agentManager?.listAgents === 'function') {
392
+ return await this.components.agentManager.listAgents();
393
+ }
394
+ throw new MCPError('Agent listing not available');
395
+ }
396
+ },
397
+ {
398
+ name: 'agents/spawn',
399
+ description: 'Spawn a new agent',
400
+ inputSchema: {
401
+ type: 'object',
402
+ properties: {
403
+ profile: {
404
+ type: 'object'
405
+ },
406
+ config: {
407
+ type: 'object'
408
+ }
409
+ },
410
+ required: [
411
+ 'profile'
412
+ ]
413
+ },
414
+ handler: async (input)=>{
415
+ if (typeof this.components.agentManager?.spawnAgent === 'function') {
416
+ return await this.components.agentManager.spawnAgent(input.profile, input.config);
417
+ }
418
+ throw new MCPError('Agent spawning not available');
419
+ }
420
+ }
421
+ ];
422
+ for (const tool of tools){
423
+ this.server.registerTool(tool);
424
+ }
425
+ }
426
+ registerResourceTools() {
427
+ const tools = [
428
+ {
429
+ name: 'resources/list',
430
+ description: 'List available resources',
431
+ inputSchema: {
432
+ type: 'object',
433
+ properties: {}
434
+ },
435
+ handler: async ()=>{
436
+ if (typeof this.components.resourceManager?.listResources === 'function') {
437
+ return await this.components.resourceManager.listResources();
438
+ }
439
+ throw new MCPError('Resource listing not available');
440
+ }
441
+ },
442
+ {
443
+ name: 'resources/status',
444
+ description: 'Get resource manager status',
445
+ inputSchema: {
446
+ type: 'object',
447
+ properties: {}
448
+ },
449
+ handler: async ()=>{
450
+ if (typeof this.components.resourceManager?.getStatus === 'function') {
451
+ return await this.components.resourceManager.getStatus();
452
+ }
453
+ throw new MCPError('Resource manager status not available');
454
+ }
455
+ }
456
+ ];
457
+ for (const tool of tools){
458
+ this.server.registerTool(tool);
459
+ }
460
+ }
461
+ registerMemoryTools() {
462
+ const tools = [
463
+ {
464
+ name: 'memory/query',
465
+ description: 'Query memory bank',
466
+ inputSchema: {
467
+ type: 'object',
468
+ properties: {
469
+ query: {
470
+ type: 'string'
471
+ },
472
+ namespace: {
473
+ type: 'string'
474
+ },
475
+ limit: {
476
+ type: 'number'
477
+ }
478
+ },
479
+ required: [
480
+ 'query'
481
+ ]
482
+ },
483
+ handler: async (input)=>{
484
+ if (typeof this.components.memoryManager?.query === 'function') {
485
+ return await this.components.memoryManager.query(input);
486
+ }
487
+ throw new MCPError('Memory query not available');
488
+ }
489
+ },
490
+ {
491
+ name: 'memory/store',
492
+ description: 'Store data in memory bank',
493
+ inputSchema: {
494
+ type: 'object',
495
+ properties: {
496
+ data: {
497
+ type: 'object'
498
+ },
499
+ namespace: {
500
+ type: 'string'
501
+ },
502
+ tags: {
503
+ type: 'array',
504
+ items: {
505
+ type: 'string'
506
+ }
507
+ }
508
+ },
509
+ required: [
510
+ 'data'
511
+ ]
512
+ },
513
+ handler: async (input)=>{
514
+ if (typeof this.components.memoryManager?.store === 'function') {
515
+ return await this.components.memoryManager.store(input);
516
+ }
517
+ throw new MCPError('Memory storage not available');
518
+ }
519
+ }
520
+ ];
521
+ for (const tool of tools){
522
+ this.server.registerTool(tool);
523
+ }
524
+ }
525
+ registerMonitoringTools() {
526
+ const tools = [
527
+ {
528
+ name: 'monitoring/metrics',
529
+ description: 'Get system monitoring metrics',
530
+ inputSchema: {
531
+ type: 'object',
532
+ properties: {}
533
+ },
534
+ handler: async ()=>{
535
+ if (typeof this.components.monitor?.getMetrics === 'function') {
536
+ return await this.components.monitor.getMetrics();
537
+ }
538
+ throw new MCPError('Monitoring metrics not available');
539
+ }
540
+ },
541
+ {
542
+ name: 'monitoring/alerts',
543
+ description: 'List active alerts',
544
+ inputSchema: {
545
+ type: 'object',
546
+ properties: {}
547
+ },
548
+ handler: async ()=>{
549
+ if (typeof this.components.monitor?.getAlerts === 'function') {
550
+ return await this.components.monitor.getAlerts();
551
+ }
552
+ throw new MCPError('Alert listing not available');
553
+ }
554
+ }
555
+ ];
556
+ for (const tool of tools){
557
+ this.server.registerTool(tool);
558
+ }
559
+ }
560
+ registerTerminalTools() {
561
+ const tools = [
562
+ {
563
+ name: 'terminals/list',
564
+ description: 'List active terminal sessions',
565
+ inputSchema: {
566
+ type: 'object',
567
+ properties: {}
568
+ },
569
+ handler: async ()=>{
570
+ if (typeof this.components.terminalManager?.listSessions === 'function') {
571
+ return await this.components.terminalManager.listSessions();
572
+ }
573
+ throw new MCPError('Terminal session listing not available');
574
+ }
575
+ },
576
+ {
577
+ name: 'terminals/execute',
578
+ description: 'Execute command in terminal',
579
+ inputSchema: {
580
+ type: 'object',
581
+ properties: {
582
+ command: {
583
+ type: 'string'
584
+ },
585
+ sessionId: {
586
+ type: 'string'
587
+ }
588
+ },
589
+ required: [
590
+ 'command'
591
+ ]
592
+ },
593
+ handler: async (input)=>{
594
+ if (typeof this.components.terminalManager?.execute === 'function') {
595
+ return await this.components.terminalManager.execute(input.command, input.sessionId);
596
+ }
597
+ throw new MCPError('Terminal execution not available');
598
+ }
599
+ }
600
+ ];
601
+ for (const tool of tools){
602
+ this.server.registerTool(tool);
603
+ }
604
+ }
605
+ async setupComponentIntegrations() {
606
+ const promises = [];
607
+ for (const [component, status] of this.integrationStatus.entries()){
608
+ if (status.enabled) {
609
+ promises.push(this.connectComponent(component));
610
+ }
611
+ }
612
+ await Promise.allSettled(promises);
613
+ }
614
+ async connectComponent(component) {
615
+ const status = this.integrationStatus.get(component);
616
+ if (!status) return;
617
+ try {
618
+ // Component-specific connection logic
619
+ switch(component){
620
+ case 'orchestrator':
621
+ await this.connectOrchestrator();
622
+ break;
623
+ case 'swarm':
624
+ await this.connectSwarmCoordinator();
625
+ break;
626
+ case 'agents':
627
+ await this.connectAgentManager();
628
+ break;
629
+ case 'resources':
630
+ await this.connectResourceManager();
631
+ break;
632
+ case 'memory':
633
+ await this.connectMemoryManager();
634
+ break;
635
+ case 'monitoring':
636
+ await this.connectMonitor();
637
+ break;
638
+ case 'terminals':
639
+ await this.connectTerminalManager();
640
+ break;
641
+ }
642
+ status.connected = true;
643
+ status.healthy = true;
644
+ status.lastCheck = new Date();
645
+ status.error = undefined;
646
+ this.logger.info('Component connected', {
647
+ component
648
+ });
649
+ this.emit('componentConnected', {
650
+ component
651
+ });
652
+ } catch (error) {
653
+ status.connected = false;
654
+ status.healthy = false;
655
+ status.error = error instanceof Error ? error.message : 'Unknown error';
656
+ this.logger.error('Failed to connect component', {
657
+ component,
658
+ error
659
+ });
660
+ this.scheduleReconnect(component);
661
+ }
662
+ }
663
+ async disconnectComponent(component) {
664
+ const status = this.integrationStatus.get(component);
665
+ if (!status) return;
666
+ status.connected = false;
667
+ status.healthy = false;
668
+ status.lastCheck = new Date();
669
+ // Clear any reconnect timers
670
+ const timer = this.reconnectTimers.get(component);
671
+ if (timer) {
672
+ clearTimeout(timer);
673
+ this.reconnectTimers.delete(component);
674
+ }
675
+ this.logger.info('Component disconnected', {
676
+ component
677
+ });
678
+ this.emit('componentDisconnected', {
679
+ component
680
+ });
681
+ }
682
+ scheduleReconnect(component) {
683
+ const timer = this.reconnectTimers.get(component);
684
+ if (timer) return; // Already scheduled
685
+ const reconnectTimer = setTimeout(async ()=>{
686
+ this.reconnectTimers.delete(component);
687
+ try {
688
+ await this.connectComponent(component);
689
+ } catch (error) {
690
+ // Will be handled by connectComponent
691
+ }
692
+ }, this.orchestrationConfig.reconnectDelay);
693
+ this.reconnectTimers.set(component, reconnectTimer);
694
+ }
695
+ startHealthMonitoring() {
696
+ this.healthCheckTimer = setInterval(async ()=>{
697
+ await this.performHealthChecks();
698
+ }, this.orchestrationConfig.healthCheckInterval);
699
+ }
700
+ stopHealthMonitoring() {
701
+ if (this.healthCheckTimer) {
702
+ clearInterval(this.healthCheckTimer);
703
+ this.healthCheckTimer = undefined;
704
+ }
705
+ }
706
+ async performHealthChecks() {
707
+ for (const [component, status] of this.integrationStatus.entries()){
708
+ if (!status.enabled || !status.connected) continue;
709
+ try {
710
+ const healthy = await this.checkComponentHealth(component);
711
+ status.healthy = healthy;
712
+ status.lastCheck = new Date();
713
+ status.error = undefined;
714
+ } catch (error) {
715
+ status.healthy = false;
716
+ status.error = error instanceof Error ? error instanceof Error ? error.message : String(error) : 'Health check failed';
717
+ this.logger.warn('Component health check failed', {
718
+ component,
719
+ error
720
+ });
721
+ }
722
+ }
723
+ }
724
+ async checkComponentHealth(component) {
725
+ const componentInstance = this.getComponentInstance(component);
726
+ if (!componentInstance) return false;
727
+ // Check if component has health check method
728
+ if (typeof componentInstance.healthCheck === 'function') {
729
+ const result = await componentInstance.healthCheck();
730
+ return result === true || typeof result === 'object' && result.healthy === true;
731
+ }
732
+ // Basic check - component exists and is not null
733
+ return true;
734
+ }
735
+ getComponentInstance(component) {
736
+ switch(component){
737
+ case 'orchestrator':
738
+ return this.components.orchestrator;
739
+ case 'swarm':
740
+ return this.components.swarmCoordinator;
741
+ case 'agents':
742
+ return this.components.agentManager;
743
+ case 'resources':
744
+ return this.components.resourceManager;
745
+ case 'memory':
746
+ return this.components.memoryManager;
747
+ case 'monitoring':
748
+ return this.components.monitor;
749
+ case 'terminals':
750
+ return this.components.terminalManager;
751
+ default:
752
+ return null;
753
+ }
754
+ }
755
+ // Component-specific connection methods
756
+ async connectOrchestrator() {
757
+ if (!this.components.orchestrator) {
758
+ throw new MCPError('Orchestrator component not available');
759
+ }
760
+ // Add orchestrator-specific connection logic here
761
+ }
762
+ async connectSwarmCoordinator() {
763
+ if (!this.components.swarmCoordinator) {
764
+ throw new MCPError('Swarm coordinator component not available');
765
+ }
766
+ // Add swarm coordinator-specific connection logic here
767
+ }
768
+ async connectAgentManager() {
769
+ if (!this.components.agentManager) {
770
+ throw new MCPError('Agent manager component not available');
771
+ }
772
+ // Add agent manager-specific connection logic here
773
+ }
774
+ async connectResourceManager() {
775
+ if (!this.components.resourceManager) {
776
+ throw new MCPError('Resource manager component not available');
777
+ }
778
+ // Add resource manager-specific connection logic here
779
+ }
780
+ async connectMemoryManager() {
781
+ if (!this.components.memoryManager) {
782
+ throw new MCPError('Memory manager component not available');
783
+ }
784
+ // Add memory manager-specific connection logic here
785
+ }
786
+ async connectMonitor() {
787
+ if (!this.components.monitor) {
788
+ throw new MCPError('Monitor component not available');
789
+ }
790
+ // Add monitor-specific connection logic here
791
+ }
792
+ async connectTerminalManager() {
793
+ if (!this.components.terminalManager) {
794
+ throw new MCPError('Terminal manager component not available');
795
+ }
796
+ // Add terminal manager-specific connection logic here
797
+ }
798
+ }
799
+
800
+ //# sourceMappingURL=orchestration-integration.js.map