@sparkleideas/swarm 3.0.0-alpha.7
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.
- package/MIGRATION.md +472 -0
- package/README.md +634 -0
- package/__tests__/consensus.test.ts +577 -0
- package/__tests__/coordinator.test.ts +501 -0
- package/__tests__/queen-coordinator.test.ts +1335 -0
- package/__tests__/topology.test.ts +621 -0
- package/package.json +32 -0
- package/src/agent-pool.ts +476 -0
- package/src/application/commands/create-task.command.ts +124 -0
- package/src/application/commands/spawn-agent.command.ts +122 -0
- package/src/application/index.ts +30 -0
- package/src/application/services/swarm-application-service.ts +200 -0
- package/src/attention-coordinator.ts +1000 -0
- package/src/consensus/byzantine.ts +431 -0
- package/src/consensus/gossip.ts +513 -0
- package/src/consensus/index.ts +267 -0
- package/src/consensus/raft.ts +443 -0
- package/src/coordination/agent-registry.ts +544 -0
- package/src/coordination/index.ts +23 -0
- package/src/coordination/swarm-hub.ts +776 -0
- package/src/coordination/task-orchestrator.ts +605 -0
- package/src/domain/entities/agent.d.ts +151 -0
- package/src/domain/entities/agent.d.ts.map +1 -0
- package/src/domain/entities/agent.js +280 -0
- package/src/domain/entities/agent.js.map +1 -0
- package/src/domain/entities/agent.ts +370 -0
- package/src/domain/entities/task.d.ts +133 -0
- package/src/domain/entities/task.d.ts.map +1 -0
- package/src/domain/entities/task.js +261 -0
- package/src/domain/entities/task.js.map +1 -0
- package/src/domain/entities/task.ts +319 -0
- package/src/domain/index.ts +41 -0
- package/src/domain/repositories/agent-repository.interface.d.ts +57 -0
- package/src/domain/repositories/agent-repository.interface.d.ts.map +1 -0
- package/src/domain/repositories/agent-repository.interface.js +9 -0
- package/src/domain/repositories/agent-repository.interface.js.map +1 -0
- package/src/domain/repositories/agent-repository.interface.ts +69 -0
- package/src/domain/repositories/task-repository.interface.d.ts +61 -0
- package/src/domain/repositories/task-repository.interface.d.ts.map +1 -0
- package/src/domain/repositories/task-repository.interface.js +9 -0
- package/src/domain/repositories/task-repository.interface.js.map +1 -0
- package/src/domain/repositories/task-repository.interface.ts +75 -0
- package/src/domain/services/coordination-service.ts +320 -0
- package/src/federation-hub.d.ts +284 -0
- package/src/federation-hub.d.ts.map +1 -0
- package/src/federation-hub.js +692 -0
- package/src/federation-hub.js.map +1 -0
- package/src/federation-hub.ts +979 -0
- package/src/index.ts +348 -0
- package/src/message-bus.ts +607 -0
- package/src/queen-coordinator.ts +2025 -0
- package/src/shared/events.ts +285 -0
- package/src/shared/types.ts +389 -0
- package/src/topology-manager.ts +656 -0
- package/src/types.ts +545 -0
- package/src/unified-coordinator.ts +1844 -0
- package/src/workers/index.ts +65 -0
- package/src/workers/worker-dispatch.d.ts +234 -0
- package/src/workers/worker-dispatch.d.ts.map +1 -0
- package/src/workers/worker-dispatch.js +842 -0
- package/src/workers/worker-dispatch.js.map +1 -0
- package/src/workers/worker-dispatch.ts +1076 -0
- package/tmp.json +0 -0
- package/tsconfig.json +9 -0
- package/vitest.config.ts +20 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Unified Swarm Coordinator Types
|
|
3
|
+
* Consolidated type definitions for the unified swarm coordination system
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { EventEmitter } from 'events';
|
|
7
|
+
|
|
8
|
+
// ===== CORE IDENTIFIERS =====
|
|
9
|
+
|
|
10
|
+
export interface SwarmId {
|
|
11
|
+
id: string;
|
|
12
|
+
namespace: string;
|
|
13
|
+
version: string;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AgentId {
|
|
18
|
+
id: string;
|
|
19
|
+
swarmId: string;
|
|
20
|
+
type: AgentType;
|
|
21
|
+
instance: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface TaskId {
|
|
25
|
+
id: string;
|
|
26
|
+
swarmId: string;
|
|
27
|
+
sequence: number;
|
|
28
|
+
priority: TaskPriority;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ===== TOPOLOGY TYPES =====
|
|
32
|
+
|
|
33
|
+
export type TopologyType = 'mesh' | 'hierarchical' | 'centralized' | 'hybrid';
|
|
34
|
+
|
|
35
|
+
export interface TopologyConfig {
|
|
36
|
+
type: TopologyType;
|
|
37
|
+
maxAgents: number;
|
|
38
|
+
replicationFactor?: number;
|
|
39
|
+
partitionStrategy?: 'hash' | 'range' | 'round-robin';
|
|
40
|
+
failoverEnabled?: boolean;
|
|
41
|
+
autoRebalance?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface TopologyState {
|
|
45
|
+
type: TopologyType;
|
|
46
|
+
nodes: TopologyNode[];
|
|
47
|
+
edges: TopologyEdge[];
|
|
48
|
+
leader?: string;
|
|
49
|
+
partitions: TopologyPartition[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface TopologyNode {
|
|
53
|
+
id: string;
|
|
54
|
+
agentId: string;
|
|
55
|
+
role: 'queen' | 'worker' | 'coordinator' | 'peer';
|
|
56
|
+
status: 'active' | 'inactive' | 'syncing' | 'failed';
|
|
57
|
+
connections: string[];
|
|
58
|
+
metadata: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface TopologyEdge {
|
|
62
|
+
from: string;
|
|
63
|
+
to: string;
|
|
64
|
+
weight: number;
|
|
65
|
+
bidirectional: boolean;
|
|
66
|
+
latencyMs?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface TopologyPartition {
|
|
70
|
+
id: string;
|
|
71
|
+
nodes: string[];
|
|
72
|
+
leader: string;
|
|
73
|
+
replicaCount: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ===== AGENT TYPES =====
|
|
77
|
+
|
|
78
|
+
export type AgentType =
|
|
79
|
+
| 'coordinator'
|
|
80
|
+
| 'researcher'
|
|
81
|
+
| 'coder'
|
|
82
|
+
| 'analyst'
|
|
83
|
+
| 'architect'
|
|
84
|
+
| 'tester'
|
|
85
|
+
| 'reviewer'
|
|
86
|
+
| 'optimizer'
|
|
87
|
+
| 'documenter'
|
|
88
|
+
| 'monitor'
|
|
89
|
+
| 'specialist'
|
|
90
|
+
| 'queen'
|
|
91
|
+
| 'worker';
|
|
92
|
+
|
|
93
|
+
export type AgentStatus =
|
|
94
|
+
| 'initializing'
|
|
95
|
+
| 'idle'
|
|
96
|
+
| 'busy'
|
|
97
|
+
| 'paused'
|
|
98
|
+
| 'error'
|
|
99
|
+
| 'offline'
|
|
100
|
+
| 'terminating'
|
|
101
|
+
| 'terminated';
|
|
102
|
+
|
|
103
|
+
export interface AgentCapabilities {
|
|
104
|
+
codeGeneration: boolean;
|
|
105
|
+
codeReview: boolean;
|
|
106
|
+
testing: boolean;
|
|
107
|
+
documentation: boolean;
|
|
108
|
+
research: boolean;
|
|
109
|
+
analysis: boolean;
|
|
110
|
+
coordination: boolean;
|
|
111
|
+
languages: string[];
|
|
112
|
+
frameworks: string[];
|
|
113
|
+
domains: string[];
|
|
114
|
+
tools: string[];
|
|
115
|
+
maxConcurrentTasks: number;
|
|
116
|
+
maxMemoryUsage: number;
|
|
117
|
+
maxExecutionTime: number;
|
|
118
|
+
reliability: number;
|
|
119
|
+
speed: number;
|
|
120
|
+
quality: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface AgentMetrics {
|
|
124
|
+
tasksCompleted: number;
|
|
125
|
+
tasksFailed: number;
|
|
126
|
+
averageExecutionTime: number;
|
|
127
|
+
successRate: number;
|
|
128
|
+
cpuUsage: number;
|
|
129
|
+
memoryUsage: number;
|
|
130
|
+
messagesProcessed: number;
|
|
131
|
+
lastActivity: Date;
|
|
132
|
+
responseTime: number;
|
|
133
|
+
health: number;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface AgentState {
|
|
137
|
+
id: AgentId;
|
|
138
|
+
name: string;
|
|
139
|
+
type: AgentType;
|
|
140
|
+
status: AgentStatus;
|
|
141
|
+
capabilities: AgentCapabilities;
|
|
142
|
+
metrics: AgentMetrics;
|
|
143
|
+
currentTask?: TaskId;
|
|
144
|
+
workload: number;
|
|
145
|
+
health: number;
|
|
146
|
+
lastHeartbeat: Date;
|
|
147
|
+
topologyRole?: TopologyNode['role'];
|
|
148
|
+
connections: string[];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ===== TASK TYPES =====
|
|
152
|
+
|
|
153
|
+
export type TaskType =
|
|
154
|
+
| 'research'
|
|
155
|
+
| 'analysis'
|
|
156
|
+
| 'coding'
|
|
157
|
+
| 'testing'
|
|
158
|
+
| 'review'
|
|
159
|
+
| 'documentation'
|
|
160
|
+
| 'coordination'
|
|
161
|
+
| 'consensus'
|
|
162
|
+
| 'custom';
|
|
163
|
+
|
|
164
|
+
export type TaskStatus =
|
|
165
|
+
| 'created'
|
|
166
|
+
| 'queued'
|
|
167
|
+
| 'assigned'
|
|
168
|
+
| 'running'
|
|
169
|
+
| 'paused'
|
|
170
|
+
| 'completed'
|
|
171
|
+
| 'failed'
|
|
172
|
+
| 'cancelled'
|
|
173
|
+
| 'timeout';
|
|
174
|
+
|
|
175
|
+
export type TaskPriority = 'critical' | 'high' | 'normal' | 'low' | 'background';
|
|
176
|
+
|
|
177
|
+
export interface TaskDefinition {
|
|
178
|
+
id: TaskId;
|
|
179
|
+
type: TaskType;
|
|
180
|
+
name: string;
|
|
181
|
+
description: string;
|
|
182
|
+
priority: TaskPriority;
|
|
183
|
+
status: TaskStatus;
|
|
184
|
+
assignedTo?: AgentId;
|
|
185
|
+
dependencies: TaskId[];
|
|
186
|
+
input: unknown;
|
|
187
|
+
output?: unknown;
|
|
188
|
+
createdAt: Date;
|
|
189
|
+
startedAt?: Date;
|
|
190
|
+
completedAt?: Date;
|
|
191
|
+
timeoutMs: number;
|
|
192
|
+
retries: number;
|
|
193
|
+
maxRetries: number;
|
|
194
|
+
metadata: Record<string, unknown>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// ===== CONSENSUS TYPES =====
|
|
198
|
+
|
|
199
|
+
export type ConsensusAlgorithm = 'raft' | 'byzantine' | 'gossip' | 'paxos';
|
|
200
|
+
|
|
201
|
+
export interface ConsensusConfig {
|
|
202
|
+
algorithm: ConsensusAlgorithm;
|
|
203
|
+
threshold: number;
|
|
204
|
+
timeoutMs: number;
|
|
205
|
+
maxRounds: number;
|
|
206
|
+
requireQuorum: boolean;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface ConsensusProposal {
|
|
210
|
+
id: string;
|
|
211
|
+
proposerId: string;
|
|
212
|
+
value: unknown;
|
|
213
|
+
term: number;
|
|
214
|
+
timestamp: Date;
|
|
215
|
+
votes: Map<string, ConsensusVote>;
|
|
216
|
+
status: 'pending' | 'accepted' | 'rejected' | 'expired';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface ConsensusVote {
|
|
220
|
+
voterId: string;
|
|
221
|
+
approve: boolean;
|
|
222
|
+
confidence: number;
|
|
223
|
+
timestamp: Date;
|
|
224
|
+
reason?: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface ConsensusResult {
|
|
228
|
+
proposalId: string;
|
|
229
|
+
approved: boolean;
|
|
230
|
+
approvalRate: number;
|
|
231
|
+
participationRate: number;
|
|
232
|
+
finalValue: unknown;
|
|
233
|
+
rounds: number;
|
|
234
|
+
durationMs: number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ===== MESSAGE BUS TYPES =====
|
|
238
|
+
|
|
239
|
+
export type MessageType =
|
|
240
|
+
| 'task_assign'
|
|
241
|
+
| 'task_complete'
|
|
242
|
+
| 'task_fail'
|
|
243
|
+
| 'heartbeat'
|
|
244
|
+
| 'status_update'
|
|
245
|
+
| 'consensus_propose'
|
|
246
|
+
| 'consensus_vote'
|
|
247
|
+
| 'consensus_commit'
|
|
248
|
+
| 'topology_update'
|
|
249
|
+
| 'agent_join'
|
|
250
|
+
| 'agent_leave'
|
|
251
|
+
| 'broadcast'
|
|
252
|
+
| 'direct';
|
|
253
|
+
|
|
254
|
+
export interface Message {
|
|
255
|
+
id: string;
|
|
256
|
+
type: MessageType;
|
|
257
|
+
from: string;
|
|
258
|
+
to: string | 'broadcast';
|
|
259
|
+
payload: unknown;
|
|
260
|
+
timestamp: Date;
|
|
261
|
+
priority: 'urgent' | 'high' | 'normal' | 'low';
|
|
262
|
+
requiresAck: boolean;
|
|
263
|
+
ttlMs: number;
|
|
264
|
+
correlationId?: string;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface MessageAck {
|
|
268
|
+
messageId: string;
|
|
269
|
+
from: string;
|
|
270
|
+
received: boolean;
|
|
271
|
+
processedAt: Date;
|
|
272
|
+
error?: string;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export interface MessageBusConfig {
|
|
276
|
+
maxQueueSize: number;
|
|
277
|
+
processingIntervalMs: number;
|
|
278
|
+
ackTimeoutMs: number;
|
|
279
|
+
retryAttempts: number;
|
|
280
|
+
enablePersistence: boolean;
|
|
281
|
+
compressionEnabled: boolean;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export interface MessageBusStats {
|
|
285
|
+
totalMessages: number;
|
|
286
|
+
messagesPerSecond: number;
|
|
287
|
+
avgLatencyMs: number;
|
|
288
|
+
queueDepth: number;
|
|
289
|
+
ackRate: number;
|
|
290
|
+
errorRate: number;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ===== COORDINATOR TYPES =====
|
|
294
|
+
|
|
295
|
+
export interface CoordinatorConfig {
|
|
296
|
+
topology: TopologyConfig;
|
|
297
|
+
consensus: ConsensusConfig;
|
|
298
|
+
messageBus: MessageBusConfig;
|
|
299
|
+
maxAgents: number;
|
|
300
|
+
maxTasks: number;
|
|
301
|
+
heartbeatIntervalMs: number;
|
|
302
|
+
healthCheckIntervalMs: number;
|
|
303
|
+
taskTimeoutMs: number;
|
|
304
|
+
autoScaling: boolean;
|
|
305
|
+
autoRecovery: boolean;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export interface CoordinatorState {
|
|
309
|
+
id: SwarmId;
|
|
310
|
+
status: SwarmStatus;
|
|
311
|
+
topology: TopologyState;
|
|
312
|
+
agents: Map<string, AgentState>;
|
|
313
|
+
tasks: Map<string, TaskDefinition>;
|
|
314
|
+
metrics: CoordinatorMetrics;
|
|
315
|
+
startedAt?: Date;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export type SwarmStatus =
|
|
319
|
+
| 'initializing'
|
|
320
|
+
| 'running'
|
|
321
|
+
| 'paused'
|
|
322
|
+
| 'recovering'
|
|
323
|
+
| 'shutting_down'
|
|
324
|
+
| 'stopped'
|
|
325
|
+
| 'failed';
|
|
326
|
+
|
|
327
|
+
export interface CoordinatorMetrics {
|
|
328
|
+
uptime: number;
|
|
329
|
+
activeAgents: number;
|
|
330
|
+
totalTasks: number;
|
|
331
|
+
completedTasks: number;
|
|
332
|
+
failedTasks: number;
|
|
333
|
+
avgTaskDurationMs: number;
|
|
334
|
+
messagesPerSecond: number;
|
|
335
|
+
consensusSuccessRate: number;
|
|
336
|
+
coordinationLatencyMs: number;
|
|
337
|
+
memoryUsageBytes: number;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ===== EVENT TYPES =====
|
|
341
|
+
|
|
342
|
+
export type SwarmEventType =
|
|
343
|
+
| 'swarm.initialized'
|
|
344
|
+
| 'swarm.started'
|
|
345
|
+
| 'swarm.paused'
|
|
346
|
+
| 'swarm.resumed'
|
|
347
|
+
| 'swarm.stopped'
|
|
348
|
+
| 'swarm.failed'
|
|
349
|
+
| 'agent.joined'
|
|
350
|
+
| 'agent.left'
|
|
351
|
+
| 'agent.status_changed'
|
|
352
|
+
| 'agent.heartbeat'
|
|
353
|
+
| 'agent.domain_assigned'
|
|
354
|
+
| 'task.created'
|
|
355
|
+
| 'task.assigned'
|
|
356
|
+
| 'task.started'
|
|
357
|
+
| 'task.completed'
|
|
358
|
+
| 'task.failed'
|
|
359
|
+
| 'task.queued'
|
|
360
|
+
| 'topology.updated'
|
|
361
|
+
| 'topology.rebalanced'
|
|
362
|
+
| 'consensus.proposed'
|
|
363
|
+
| 'consensus.achieved'
|
|
364
|
+
| 'consensus.failed'
|
|
365
|
+
| 'message.sent'
|
|
366
|
+
| 'message.received'
|
|
367
|
+
| 'parallel.execution.completed'
|
|
368
|
+
| 'hierarchy.spawned';
|
|
369
|
+
|
|
370
|
+
export interface SwarmEvent {
|
|
371
|
+
id: string;
|
|
372
|
+
type: SwarmEventType;
|
|
373
|
+
source: string;
|
|
374
|
+
timestamp: Date;
|
|
375
|
+
data: Record<string, unknown>;
|
|
376
|
+
correlationId?: string;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ===== POOL TYPES =====
|
|
380
|
+
|
|
381
|
+
export interface AgentPoolConfig {
|
|
382
|
+
name: string;
|
|
383
|
+
type: AgentType;
|
|
384
|
+
minSize: number;
|
|
385
|
+
maxSize: number;
|
|
386
|
+
scaleUpThreshold: number;
|
|
387
|
+
scaleDownThreshold: number;
|
|
388
|
+
cooldownMs: number;
|
|
389
|
+
healthCheckIntervalMs: number;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface AgentPoolState {
|
|
393
|
+
id: string;
|
|
394
|
+
config: AgentPoolConfig;
|
|
395
|
+
agents: Map<string, AgentState>;
|
|
396
|
+
availableAgents: string[];
|
|
397
|
+
busyAgents: string[];
|
|
398
|
+
pendingScale: number;
|
|
399
|
+
lastScaleOperation?: Date;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ===== UTILITY TYPES =====
|
|
403
|
+
|
|
404
|
+
export interface HealthCheck {
|
|
405
|
+
agentId: string;
|
|
406
|
+
timestamp: Date;
|
|
407
|
+
healthy: boolean;
|
|
408
|
+
latencyMs: number;
|
|
409
|
+
details: Record<string, unknown>;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export interface PerformanceReport {
|
|
413
|
+
timestamp: Date;
|
|
414
|
+
window: number;
|
|
415
|
+
coordinationLatencyP50: number;
|
|
416
|
+
coordinationLatencyP99: number;
|
|
417
|
+
messagesPerSecond: number;
|
|
418
|
+
taskThroughput: number;
|
|
419
|
+
agentUtilization: number;
|
|
420
|
+
consensusSuccessRate: number;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// ===== CONSTANTS =====
|
|
424
|
+
|
|
425
|
+
export const SWARM_CONSTANTS = {
|
|
426
|
+
DEFAULT_HEARTBEAT_INTERVAL_MS: 5000,
|
|
427
|
+
DEFAULT_HEALTH_CHECK_INTERVAL_MS: 10000,
|
|
428
|
+
DEFAULT_TASK_TIMEOUT_MS: 300000,
|
|
429
|
+
DEFAULT_CONSENSUS_TIMEOUT_MS: 30000,
|
|
430
|
+
DEFAULT_MESSAGE_TTL_MS: 60000,
|
|
431
|
+
DEFAULT_MAX_AGENTS: 100,
|
|
432
|
+
DEFAULT_MAX_TASKS: 1000,
|
|
433
|
+
DEFAULT_CONSENSUS_THRESHOLD: 0.66,
|
|
434
|
+
MAX_QUEUE_SIZE: 10000,
|
|
435
|
+
MAX_RETRIES: 3,
|
|
436
|
+
COORDINATION_LATENCY_TARGET_MS: 100,
|
|
437
|
+
MESSAGES_PER_SECOND_TARGET: 1000,
|
|
438
|
+
} as const;
|
|
439
|
+
|
|
440
|
+
// ===== TYPE GUARDS =====
|
|
441
|
+
|
|
442
|
+
export function isAgentId(obj: unknown): obj is AgentId {
|
|
443
|
+
return (
|
|
444
|
+
typeof obj === 'object' &&
|
|
445
|
+
obj !== null &&
|
|
446
|
+
'id' in obj &&
|
|
447
|
+
'swarmId' in obj &&
|
|
448
|
+
'type' in obj
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export function isTaskId(obj: unknown): obj is TaskId {
|
|
453
|
+
return (
|
|
454
|
+
typeof obj === 'object' &&
|
|
455
|
+
obj !== null &&
|
|
456
|
+
'id' in obj &&
|
|
457
|
+
'swarmId' in obj &&
|
|
458
|
+
'sequence' in obj
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function isMessage(obj: unknown): obj is Message {
|
|
463
|
+
return (
|
|
464
|
+
typeof obj === 'object' &&
|
|
465
|
+
obj !== null &&
|
|
466
|
+
'id' in obj &&
|
|
467
|
+
'type' in obj &&
|
|
468
|
+
'from' in obj &&
|
|
469
|
+
'to' in obj
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// ===== INTERFACES FOR COMPONENTS =====
|
|
474
|
+
|
|
475
|
+
export interface ITopologyManager {
|
|
476
|
+
initialize(config: TopologyConfig): Promise<void>;
|
|
477
|
+
getState(): TopologyState;
|
|
478
|
+
addNode(agentId: string, role: TopologyNode['role']): Promise<TopologyNode>;
|
|
479
|
+
removeNode(agentId: string): Promise<void>;
|
|
480
|
+
updateNode(agentId: string, updates: Partial<TopologyNode>): Promise<void>;
|
|
481
|
+
getLeader(): string | undefined;
|
|
482
|
+
electLeader(): Promise<string>;
|
|
483
|
+
rebalance(): Promise<void>;
|
|
484
|
+
getNeighbors(agentId: string): string[];
|
|
485
|
+
findOptimalPath(from: string, to: string): string[];
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export interface IConsensusEngine {
|
|
489
|
+
initialize(config: ConsensusConfig): Promise<void>;
|
|
490
|
+
propose(value: unknown, proposerId: string): Promise<ConsensusProposal>;
|
|
491
|
+
vote(proposalId: string, vote: ConsensusVote): Promise<void>;
|
|
492
|
+
getProposal(proposalId: string): ConsensusProposal | undefined;
|
|
493
|
+
awaitConsensus(proposalId: string): Promise<ConsensusResult>;
|
|
494
|
+
getActiveProposals(): ConsensusProposal[];
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export interface IMessageBus {
|
|
498
|
+
initialize(config: MessageBusConfig): Promise<void>;
|
|
499
|
+
send(message: Omit<Message, 'id' | 'timestamp'>): Promise<string>;
|
|
500
|
+
broadcast(message: Omit<Message, 'id' | 'timestamp' | 'to'>): Promise<string>;
|
|
501
|
+
subscribe(agentId: string, callback: (message: Message) => void): void;
|
|
502
|
+
unsubscribe(agentId: string): void;
|
|
503
|
+
acknowledge(ack: MessageAck): Promise<void>;
|
|
504
|
+
getStats(): MessageBusStats;
|
|
505
|
+
getQueueDepth(): number;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
export interface IAgentPool {
|
|
509
|
+
initialize(config: AgentPoolConfig): Promise<void>;
|
|
510
|
+
acquire(): Promise<AgentState | undefined>;
|
|
511
|
+
release(agentId: string): Promise<void>;
|
|
512
|
+
add(agent: AgentState): Promise<void>;
|
|
513
|
+
remove(agentId: string): Promise<void>;
|
|
514
|
+
scale(delta: number): Promise<void>;
|
|
515
|
+
getState(): AgentPoolState;
|
|
516
|
+
getAvailableCount(): number;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export interface IUnifiedSwarmCoordinator {
|
|
520
|
+
initialize(): Promise<void>;
|
|
521
|
+
shutdown(): Promise<void>;
|
|
522
|
+
pause(): Promise<void>;
|
|
523
|
+
resume(): Promise<void>;
|
|
524
|
+
|
|
525
|
+
// Agent management
|
|
526
|
+
registerAgent(agent: Omit<AgentState, 'id'>): Promise<string>;
|
|
527
|
+
unregisterAgent(agentId: string): Promise<void>;
|
|
528
|
+
getAgent(agentId: string): AgentState | undefined;
|
|
529
|
+
getAllAgents(): AgentState[];
|
|
530
|
+
|
|
531
|
+
// Task management
|
|
532
|
+
submitTask(task: Omit<TaskDefinition, 'id' | 'status' | 'createdAt'>): Promise<string>;
|
|
533
|
+
cancelTask(taskId: string): Promise<void>;
|
|
534
|
+
getTask(taskId: string): TaskDefinition | undefined;
|
|
535
|
+
getAllTasks(): TaskDefinition[];
|
|
536
|
+
|
|
537
|
+
// Coordination
|
|
538
|
+
proposeConsensus(value: unknown): Promise<ConsensusResult>;
|
|
539
|
+
broadcastMessage(payload: unknown, priority?: Message['priority']): Promise<void>;
|
|
540
|
+
|
|
541
|
+
// Monitoring
|
|
542
|
+
getState(): CoordinatorState;
|
|
543
|
+
getMetrics(): CoordinatorMetrics;
|
|
544
|
+
getPerformanceReport(): PerformanceReport;
|
|
545
|
+
}
|