@claude-flow/swarm 3.0.0-alpha.8 → 3.0.0-alpha.9
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/dist/agent-pool.d.ts.map +1 -1
- package/dist/agent-pool.js +10 -2
- package/dist/agent-pool.js.map +1 -1
- package/dist/attention-coordinator.d.ts +5 -4
- package/dist/attention-coordinator.d.ts.map +1 -1
- package/dist/attention-coordinator.js +17 -10
- package/dist/attention-coordinator.js.map +1 -1
- package/dist/consensus/byzantine.d.ts +2 -1
- package/dist/consensus/byzantine.d.ts.map +1 -1
- package/dist/consensus/byzantine.js +34 -8
- package/dist/consensus/byzantine.js.map +1 -1
- package/dist/consensus/gossip.d.ts +2 -1
- package/dist/consensus/gossip.d.ts.map +1 -1
- package/dist/consensus/gossip.js +27 -8
- package/dist/consensus/gossip.js.map +1 -1
- package/dist/consensus/index.d.ts +1 -1
- package/dist/consensus/index.d.ts.map +1 -1
- package/dist/consensus/index.js +2 -30
- package/dist/consensus/index.js.map +1 -1
- package/dist/consensus/raft.d.ts +2 -1
- package/dist/consensus/raft.d.ts.map +1 -1
- package/dist/consensus/raft.js +25 -9
- package/dist/consensus/raft.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/message-bus.d.ts.map +1 -1
- package/dist/message-bus.js +13 -4
- package/dist/message-bus.js.map +1 -1
- package/dist/queen-coordinator.d.ts +1 -1
- package/dist/queen-coordinator.d.ts.map +1 -1
- package/dist/queen-coordinator.js +10 -3
- package/dist/queen-coordinator.js.map +1 -1
- package/dist/topology-manager.d.ts.map +1 -1
- package/dist/topology-manager.js +26 -1
- package/dist/topology-manager.js.map +1 -1
- package/dist/types.d.ts +3 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/unified-coordinator.d.ts +1 -1
- package/dist/unified-coordinator.d.ts.map +1 -1
- package/dist/unified-coordinator.js +85 -29
- package/dist/unified-coordinator.js.map +1 -1
- package/package.json +7 -2
- package/.claude-flow/data/pending-insights.jsonl +0 -15
- package/.claude-flow/hive-mind/state.json +0 -18
- package/__tests__/byzantine-transport.test.ts +0 -147
- package/__tests__/consensus-failure-injection.test.ts +0 -161
- package/__tests__/consensus-transport.test.ts +0 -200
- package/__tests__/consensus.test.ts +0 -577
- package/__tests__/coordinator.test.ts +0 -501
- package/__tests__/federation-transport.test.ts +0 -145
- package/__tests__/gossip-transport.test.ts +0 -81
- package/__tests__/queen-coordinator.test.ts +0 -1335
- package/__tests__/raft-transport.test.ts +0 -121
- package/__tests__/topology.test.ts +0 -621
- package/ruvector.db +0 -0
- package/src/agent-pool.ts +0 -476
- package/src/application/commands/create-task.command.ts +0 -124
- package/src/application/commands/spawn-agent.command.ts +0 -122
- package/src/application/index.ts +0 -30
- package/src/application/services/swarm-application-service.ts +0 -200
- package/src/attention-coordinator.ts +0 -1000
- package/src/consensus/byzantine.ts +0 -514
- package/src/consensus/federation-transport.ts +0 -185
- package/src/consensus/gossip.ts +0 -599
- package/src/consensus/index.ts +0 -326
- package/src/consensus/raft.ts +0 -561
- package/src/consensus/transport.ts +0 -284
- package/src/coordination/agent-registry.ts +0 -544
- package/src/coordination/index.ts +0 -23
- package/src/coordination/swarm-hub.ts +0 -776
- package/src/coordination/task-orchestrator.ts +0 -605
- package/src/domain/entities/agent.d.ts +0 -151
- package/src/domain/entities/agent.d.ts.map +0 -1
- package/src/domain/entities/agent.js +0 -280
- package/src/domain/entities/agent.js.map +0 -1
- package/src/domain/entities/agent.ts +0 -370
- package/src/domain/entities/task.d.ts +0 -133
- package/src/domain/entities/task.d.ts.map +0 -1
- package/src/domain/entities/task.js +0 -261
- package/src/domain/entities/task.js.map +0 -1
- package/src/domain/entities/task.ts +0 -319
- package/src/domain/index.ts +0 -41
- package/src/domain/repositories/agent-repository.interface.d.ts +0 -57
- package/src/domain/repositories/agent-repository.interface.d.ts.map +0 -1
- package/src/domain/repositories/agent-repository.interface.js +0 -9
- package/src/domain/repositories/agent-repository.interface.js.map +0 -1
- package/src/domain/repositories/agent-repository.interface.ts +0 -69
- package/src/domain/repositories/task-repository.interface.d.ts +0 -61
- package/src/domain/repositories/task-repository.interface.d.ts.map +0 -1
- package/src/domain/repositories/task-repository.interface.js +0 -9
- package/src/domain/repositories/task-repository.interface.js.map +0 -1
- package/src/domain/repositories/task-repository.interface.ts +0 -75
- package/src/domain/services/coordination-service.ts +0 -320
- package/src/federation-hub.d.ts +0 -284
- package/src/federation-hub.d.ts.map +0 -1
- package/src/federation-hub.js +0 -692
- package/src/federation-hub.js.map +0 -1
- package/src/federation-hub.ts +0 -979
- package/src/index.ts +0 -374
- package/src/message-bus.ts +0 -607
- package/src/queen-coordinator.ts +0 -2025
- package/src/shared/events.ts +0 -285
- package/src/shared/types.ts +0 -389
- package/src/topology-manager.ts +0 -656
- package/src/types.ts +0 -555
- package/src/unified-coordinator.ts +0 -1844
- package/src/workers/index.ts +0 -65
- package/src/workers/worker-dispatch.d.ts +0 -234
- package/src/workers/worker-dispatch.d.ts.map +0 -1
- package/src/workers/worker-dispatch.js +0 -842
- package/src/workers/worker-dispatch.js.map +0 -1
- package/src/workers/worker-dispatch.ts +0 -1076
- package/tmp.json +0 -0
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -20
package/src/types.ts
DELETED
|
@@ -1,555 +0,0 @@
|
|
|
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
|
-
* ADR-095 G2.2 — optional pluggable transport. When provided, the
|
|
209
|
-
* ConsensusEngine forwards it to the underlying Raft / Byzantine /
|
|
210
|
-
* Gossip implementation so their inter-node messaging actually
|
|
211
|
-
* crosses a process or host boundary. When omitted, protocols run
|
|
212
|
-
* in single-process mode (legacy behavior). Typed as `unknown` here
|
|
213
|
-
* to avoid forcing every consumer of `types.ts` to import the
|
|
214
|
-
* transport module; the engine narrows it via a structural check.
|
|
215
|
-
*/
|
|
216
|
-
transport?: unknown;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export interface ConsensusProposal {
|
|
220
|
-
id: string;
|
|
221
|
-
proposerId: string;
|
|
222
|
-
value: unknown;
|
|
223
|
-
term: number;
|
|
224
|
-
timestamp: Date;
|
|
225
|
-
votes: Map<string, ConsensusVote>;
|
|
226
|
-
status: 'pending' | 'accepted' | 'rejected' | 'expired';
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export interface ConsensusVote {
|
|
230
|
-
voterId: string;
|
|
231
|
-
approve: boolean;
|
|
232
|
-
confidence: number;
|
|
233
|
-
timestamp: Date;
|
|
234
|
-
reason?: string;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export interface ConsensusResult {
|
|
238
|
-
proposalId: string;
|
|
239
|
-
approved: boolean;
|
|
240
|
-
approvalRate: number;
|
|
241
|
-
participationRate: number;
|
|
242
|
-
finalValue: unknown;
|
|
243
|
-
rounds: number;
|
|
244
|
-
durationMs: number;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// ===== MESSAGE BUS TYPES =====
|
|
248
|
-
|
|
249
|
-
export type MessageType =
|
|
250
|
-
| 'task_assign'
|
|
251
|
-
| 'task_complete'
|
|
252
|
-
| 'task_fail'
|
|
253
|
-
| 'heartbeat'
|
|
254
|
-
| 'status_update'
|
|
255
|
-
| 'consensus_propose'
|
|
256
|
-
| 'consensus_vote'
|
|
257
|
-
| 'consensus_commit'
|
|
258
|
-
| 'topology_update'
|
|
259
|
-
| 'agent_join'
|
|
260
|
-
| 'agent_leave'
|
|
261
|
-
| 'broadcast'
|
|
262
|
-
| 'direct';
|
|
263
|
-
|
|
264
|
-
export interface Message {
|
|
265
|
-
id: string;
|
|
266
|
-
type: MessageType;
|
|
267
|
-
from: string;
|
|
268
|
-
to: string | 'broadcast';
|
|
269
|
-
payload: unknown;
|
|
270
|
-
timestamp: Date;
|
|
271
|
-
priority: 'urgent' | 'high' | 'normal' | 'low';
|
|
272
|
-
requiresAck: boolean;
|
|
273
|
-
ttlMs: number;
|
|
274
|
-
correlationId?: string;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export interface MessageAck {
|
|
278
|
-
messageId: string;
|
|
279
|
-
from: string;
|
|
280
|
-
received: boolean;
|
|
281
|
-
processedAt: Date;
|
|
282
|
-
error?: string;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export interface MessageBusConfig {
|
|
286
|
-
maxQueueSize: number;
|
|
287
|
-
processingIntervalMs: number;
|
|
288
|
-
ackTimeoutMs: number;
|
|
289
|
-
retryAttempts: number;
|
|
290
|
-
enablePersistence: boolean;
|
|
291
|
-
compressionEnabled: boolean;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export interface MessageBusStats {
|
|
295
|
-
totalMessages: number;
|
|
296
|
-
messagesPerSecond: number;
|
|
297
|
-
avgLatencyMs: number;
|
|
298
|
-
queueDepth: number;
|
|
299
|
-
ackRate: number;
|
|
300
|
-
errorRate: number;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// ===== COORDINATOR TYPES =====
|
|
304
|
-
|
|
305
|
-
export interface CoordinatorConfig {
|
|
306
|
-
topology: TopologyConfig;
|
|
307
|
-
consensus: ConsensusConfig;
|
|
308
|
-
messageBus: MessageBusConfig;
|
|
309
|
-
maxAgents: number;
|
|
310
|
-
maxTasks: number;
|
|
311
|
-
heartbeatIntervalMs: number;
|
|
312
|
-
healthCheckIntervalMs: number;
|
|
313
|
-
taskTimeoutMs: number;
|
|
314
|
-
autoScaling: boolean;
|
|
315
|
-
autoRecovery: boolean;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
export interface CoordinatorState {
|
|
319
|
-
id: SwarmId;
|
|
320
|
-
status: SwarmStatus;
|
|
321
|
-
topology: TopologyState;
|
|
322
|
-
agents: Map<string, AgentState>;
|
|
323
|
-
tasks: Map<string, TaskDefinition>;
|
|
324
|
-
metrics: CoordinatorMetrics;
|
|
325
|
-
startedAt?: Date;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
export type SwarmStatus =
|
|
329
|
-
| 'initializing'
|
|
330
|
-
| 'running'
|
|
331
|
-
| 'paused'
|
|
332
|
-
| 'recovering'
|
|
333
|
-
| 'shutting_down'
|
|
334
|
-
| 'stopped'
|
|
335
|
-
| 'failed';
|
|
336
|
-
|
|
337
|
-
export interface CoordinatorMetrics {
|
|
338
|
-
uptime: number;
|
|
339
|
-
activeAgents: number;
|
|
340
|
-
totalTasks: number;
|
|
341
|
-
completedTasks: number;
|
|
342
|
-
failedTasks: number;
|
|
343
|
-
avgTaskDurationMs: number;
|
|
344
|
-
messagesPerSecond: number;
|
|
345
|
-
consensusSuccessRate: number;
|
|
346
|
-
coordinationLatencyMs: number;
|
|
347
|
-
memoryUsageBytes: number;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// ===== EVENT TYPES =====
|
|
351
|
-
|
|
352
|
-
export type SwarmEventType =
|
|
353
|
-
| 'swarm.initialized'
|
|
354
|
-
| 'swarm.started'
|
|
355
|
-
| 'swarm.paused'
|
|
356
|
-
| 'swarm.resumed'
|
|
357
|
-
| 'swarm.stopped'
|
|
358
|
-
| 'swarm.failed'
|
|
359
|
-
| 'agent.joined'
|
|
360
|
-
| 'agent.left'
|
|
361
|
-
| 'agent.status_changed'
|
|
362
|
-
| 'agent.heartbeat'
|
|
363
|
-
| 'agent.domain_assigned'
|
|
364
|
-
| 'task.created'
|
|
365
|
-
| 'task.assigned'
|
|
366
|
-
| 'task.started'
|
|
367
|
-
| 'task.completed'
|
|
368
|
-
| 'task.failed'
|
|
369
|
-
| 'task.queued'
|
|
370
|
-
| 'topology.updated'
|
|
371
|
-
| 'topology.rebalanced'
|
|
372
|
-
| 'consensus.proposed'
|
|
373
|
-
| 'consensus.achieved'
|
|
374
|
-
| 'consensus.failed'
|
|
375
|
-
| 'message.sent'
|
|
376
|
-
| 'message.received'
|
|
377
|
-
| 'parallel.execution.completed'
|
|
378
|
-
| 'hierarchy.spawned';
|
|
379
|
-
|
|
380
|
-
export interface SwarmEvent {
|
|
381
|
-
id: string;
|
|
382
|
-
type: SwarmEventType;
|
|
383
|
-
source: string;
|
|
384
|
-
timestamp: Date;
|
|
385
|
-
data: Record<string, unknown>;
|
|
386
|
-
correlationId?: string;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// ===== POOL TYPES =====
|
|
390
|
-
|
|
391
|
-
export interface AgentPoolConfig {
|
|
392
|
-
name: string;
|
|
393
|
-
type: AgentType;
|
|
394
|
-
minSize: number;
|
|
395
|
-
maxSize: number;
|
|
396
|
-
scaleUpThreshold: number;
|
|
397
|
-
scaleDownThreshold: number;
|
|
398
|
-
cooldownMs: number;
|
|
399
|
-
healthCheckIntervalMs: number;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export interface AgentPoolState {
|
|
403
|
-
id: string;
|
|
404
|
-
config: AgentPoolConfig;
|
|
405
|
-
agents: Map<string, AgentState>;
|
|
406
|
-
availableAgents: string[];
|
|
407
|
-
busyAgents: string[];
|
|
408
|
-
pendingScale: number;
|
|
409
|
-
lastScaleOperation?: Date;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// ===== UTILITY TYPES =====
|
|
413
|
-
|
|
414
|
-
export interface HealthCheck {
|
|
415
|
-
agentId: string;
|
|
416
|
-
timestamp: Date;
|
|
417
|
-
healthy: boolean;
|
|
418
|
-
latencyMs: number;
|
|
419
|
-
details: Record<string, unknown>;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
export interface PerformanceReport {
|
|
423
|
-
timestamp: Date;
|
|
424
|
-
window: number;
|
|
425
|
-
coordinationLatencyP50: number;
|
|
426
|
-
coordinationLatencyP99: number;
|
|
427
|
-
messagesPerSecond: number;
|
|
428
|
-
taskThroughput: number;
|
|
429
|
-
agentUtilization: number;
|
|
430
|
-
consensusSuccessRate: number;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
// ===== CONSTANTS =====
|
|
434
|
-
|
|
435
|
-
export const SWARM_CONSTANTS = {
|
|
436
|
-
DEFAULT_HEARTBEAT_INTERVAL_MS: 5000,
|
|
437
|
-
DEFAULT_HEALTH_CHECK_INTERVAL_MS: 10000,
|
|
438
|
-
DEFAULT_TASK_TIMEOUT_MS: 300000,
|
|
439
|
-
DEFAULT_CONSENSUS_TIMEOUT_MS: 30000,
|
|
440
|
-
DEFAULT_MESSAGE_TTL_MS: 60000,
|
|
441
|
-
DEFAULT_MAX_AGENTS: 100,
|
|
442
|
-
DEFAULT_MAX_TASKS: 1000,
|
|
443
|
-
DEFAULT_CONSENSUS_THRESHOLD: 0.66,
|
|
444
|
-
MAX_QUEUE_SIZE: 10000,
|
|
445
|
-
MAX_RETRIES: 3,
|
|
446
|
-
COORDINATION_LATENCY_TARGET_MS: 100,
|
|
447
|
-
MESSAGES_PER_SECOND_TARGET: 1000,
|
|
448
|
-
} as const;
|
|
449
|
-
|
|
450
|
-
// ===== TYPE GUARDS =====
|
|
451
|
-
|
|
452
|
-
export function isAgentId(obj: unknown): obj is AgentId {
|
|
453
|
-
return (
|
|
454
|
-
typeof obj === 'object' &&
|
|
455
|
-
obj !== null &&
|
|
456
|
-
'id' in obj &&
|
|
457
|
-
'swarmId' in obj &&
|
|
458
|
-
'type' in obj
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
export function isTaskId(obj: unknown): obj is TaskId {
|
|
463
|
-
return (
|
|
464
|
-
typeof obj === 'object' &&
|
|
465
|
-
obj !== null &&
|
|
466
|
-
'id' in obj &&
|
|
467
|
-
'swarmId' in obj &&
|
|
468
|
-
'sequence' in obj
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
export function isMessage(obj: unknown): obj is Message {
|
|
473
|
-
return (
|
|
474
|
-
typeof obj === 'object' &&
|
|
475
|
-
obj !== null &&
|
|
476
|
-
'id' in obj &&
|
|
477
|
-
'type' in obj &&
|
|
478
|
-
'from' in obj &&
|
|
479
|
-
'to' in obj
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// ===== INTERFACES FOR COMPONENTS =====
|
|
484
|
-
|
|
485
|
-
export interface ITopologyManager {
|
|
486
|
-
initialize(config: TopologyConfig): Promise<void>;
|
|
487
|
-
getState(): TopologyState;
|
|
488
|
-
addNode(agentId: string, role: TopologyNode['role']): Promise<TopologyNode>;
|
|
489
|
-
removeNode(agentId: string): Promise<void>;
|
|
490
|
-
updateNode(agentId: string, updates: Partial<TopologyNode>): Promise<void>;
|
|
491
|
-
getLeader(): string | undefined;
|
|
492
|
-
electLeader(): Promise<string>;
|
|
493
|
-
rebalance(): Promise<void>;
|
|
494
|
-
getNeighbors(agentId: string): string[];
|
|
495
|
-
findOptimalPath(from: string, to: string): string[];
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
export interface IConsensusEngine {
|
|
499
|
-
initialize(config: ConsensusConfig): Promise<void>;
|
|
500
|
-
propose(value: unknown, proposerId: string): Promise<ConsensusProposal>;
|
|
501
|
-
vote(proposalId: string, vote: ConsensusVote): Promise<void>;
|
|
502
|
-
getProposal(proposalId: string): ConsensusProposal | undefined;
|
|
503
|
-
awaitConsensus(proposalId: string): Promise<ConsensusResult>;
|
|
504
|
-
getActiveProposals(): ConsensusProposal[];
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
export interface IMessageBus {
|
|
508
|
-
initialize(config: MessageBusConfig): Promise<void>;
|
|
509
|
-
send(message: Omit<Message, 'id' | 'timestamp'>): Promise<string>;
|
|
510
|
-
broadcast(message: Omit<Message, 'id' | 'timestamp' | 'to'>): Promise<string>;
|
|
511
|
-
subscribe(agentId: string, callback: (message: Message) => void): void;
|
|
512
|
-
unsubscribe(agentId: string): void;
|
|
513
|
-
acknowledge(ack: MessageAck): Promise<void>;
|
|
514
|
-
getStats(): MessageBusStats;
|
|
515
|
-
getQueueDepth(): number;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
export interface IAgentPool {
|
|
519
|
-
initialize(config: AgentPoolConfig): Promise<void>;
|
|
520
|
-
acquire(): Promise<AgentState | undefined>;
|
|
521
|
-
release(agentId: string): Promise<void>;
|
|
522
|
-
add(agent: AgentState): Promise<void>;
|
|
523
|
-
remove(agentId: string): Promise<void>;
|
|
524
|
-
scale(delta: number): Promise<void>;
|
|
525
|
-
getState(): AgentPoolState;
|
|
526
|
-
getAvailableCount(): number;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
export interface IUnifiedSwarmCoordinator {
|
|
530
|
-
initialize(): Promise<void>;
|
|
531
|
-
shutdown(): Promise<void>;
|
|
532
|
-
pause(): Promise<void>;
|
|
533
|
-
resume(): Promise<void>;
|
|
534
|
-
|
|
535
|
-
// Agent management
|
|
536
|
-
registerAgent(agent: Omit<AgentState, 'id'>): Promise<string>;
|
|
537
|
-
unregisterAgent(agentId: string): Promise<void>;
|
|
538
|
-
getAgent(agentId: string): AgentState | undefined;
|
|
539
|
-
getAllAgents(): AgentState[];
|
|
540
|
-
|
|
541
|
-
// Task management
|
|
542
|
-
submitTask(task: Omit<TaskDefinition, 'id' | 'status' | 'createdAt'>): Promise<string>;
|
|
543
|
-
cancelTask(taskId: string): Promise<void>;
|
|
544
|
-
getTask(taskId: string): TaskDefinition | undefined;
|
|
545
|
-
getAllTasks(): TaskDefinition[];
|
|
546
|
-
|
|
547
|
-
// Coordination
|
|
548
|
-
proposeConsensus(value: unknown): Promise<ConsensusResult>;
|
|
549
|
-
broadcastMessage(payload: unknown, priority?: Message['priority']): Promise<void>;
|
|
550
|
-
|
|
551
|
-
// Monitoring
|
|
552
|
-
getState(): CoordinatorState;
|
|
553
|
-
getMetrics(): CoordinatorMetrics;
|
|
554
|
-
getPerformanceReport(): PerformanceReport;
|
|
555
|
-
}
|