@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/index.ts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sparkleideas/swarm
|
|
3
|
+
* V3 Unified Swarm Coordination Module (ADR-003)
|
|
4
|
+
*
|
|
5
|
+
* ADR-003 IMPLEMENTATION:
|
|
6
|
+
* This module provides ONE CANONICAL coordination engine: UnifiedSwarmCoordinator
|
|
7
|
+
* SwarmHub is maintained ONLY as a compatibility layer for existing code.
|
|
8
|
+
*
|
|
9
|
+
* Provides 15-agent hierarchical mesh coordination with consensus algorithms.
|
|
10
|
+
*
|
|
11
|
+
* Features:
|
|
12
|
+
* - Unified SwarmCoordinator consolidating 4 legacy systems
|
|
13
|
+
* - Multiple topology support: mesh, hierarchical, centralized, hybrid
|
|
14
|
+
* - Consensus algorithms: raft, byzantine, gossip
|
|
15
|
+
* - Agent pool management with workload balancing
|
|
16
|
+
* - Message bus for inter-agent communication
|
|
17
|
+
*
|
|
18
|
+
* Performance Targets:
|
|
19
|
+
* - Agent coordination: <100ms for 15 agents
|
|
20
|
+
* - Consensus: <100ms
|
|
21
|
+
* - Message throughput: 1000+ msgs/sec
|
|
22
|
+
*
|
|
23
|
+
* Recommended Usage:
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { createUnifiedSwarmCoordinator } from '@sparkleideas/swarm';
|
|
26
|
+
*
|
|
27
|
+
* const coordinator = createUnifiedSwarmCoordinator({
|
|
28
|
+
* topology: { type: 'hierarchical', maxAgents: 15 },
|
|
29
|
+
* consensus: { algorithm: 'raft', threshold: 0.66 },
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* await coordinator.initialize();
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @module @sparkleideas/swarm
|
|
36
|
+
* @version 3.0.0-alpha.1
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// =============================================================================
|
|
40
|
+
// Types
|
|
41
|
+
// =============================================================================
|
|
42
|
+
|
|
43
|
+
export * from './types.js';
|
|
44
|
+
|
|
45
|
+
// Re-export commonly used types for convenience
|
|
46
|
+
export type {
|
|
47
|
+
SwarmId,
|
|
48
|
+
AgentId,
|
|
49
|
+
TaskId,
|
|
50
|
+
AgentState,
|
|
51
|
+
AgentType,
|
|
52
|
+
AgentStatus,
|
|
53
|
+
AgentCapabilities,
|
|
54
|
+
AgentMetrics,
|
|
55
|
+
TaskDefinition,
|
|
56
|
+
TaskType,
|
|
57
|
+
TaskStatus,
|
|
58
|
+
TaskPriority,
|
|
59
|
+
TopologyType,
|
|
60
|
+
TopologyConfig,
|
|
61
|
+
TopologyState,
|
|
62
|
+
TopologyNode,
|
|
63
|
+
ConsensusAlgorithm,
|
|
64
|
+
ConsensusConfig,
|
|
65
|
+
ConsensusProposal,
|
|
66
|
+
ConsensusVote,
|
|
67
|
+
ConsensusResult,
|
|
68
|
+
Message,
|
|
69
|
+
MessageType,
|
|
70
|
+
MessageBusConfig,
|
|
71
|
+
MessageBusStats,
|
|
72
|
+
CoordinatorConfig,
|
|
73
|
+
CoordinatorState,
|
|
74
|
+
CoordinatorMetrics,
|
|
75
|
+
SwarmStatus,
|
|
76
|
+
SwarmEvent,
|
|
77
|
+
SwarmEventType,
|
|
78
|
+
PerformanceReport,
|
|
79
|
+
AgentPoolConfig,
|
|
80
|
+
AgentPoolState,
|
|
81
|
+
} from './types.js';
|
|
82
|
+
|
|
83
|
+
// =============================================================================
|
|
84
|
+
// Unified Coordinator
|
|
85
|
+
// =============================================================================
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
UnifiedSwarmCoordinator,
|
|
89
|
+
createUnifiedSwarmCoordinator,
|
|
90
|
+
} from './unified-coordinator.js';
|
|
91
|
+
|
|
92
|
+
// Domain types for 15-agent hierarchy
|
|
93
|
+
export type {
|
|
94
|
+
AgentDomain,
|
|
95
|
+
DomainConfig,
|
|
96
|
+
TaskAssignment,
|
|
97
|
+
ParallelExecutionResult,
|
|
98
|
+
DomainStatus,
|
|
99
|
+
} from './unified-coordinator.js';
|
|
100
|
+
|
|
101
|
+
// =============================================================================
|
|
102
|
+
// Queen Coordinator (Hive-Mind Central Orchestrator)
|
|
103
|
+
// =============================================================================
|
|
104
|
+
|
|
105
|
+
export {
|
|
106
|
+
QueenCoordinator,
|
|
107
|
+
createQueenCoordinator,
|
|
108
|
+
} from './queen-coordinator.js';
|
|
109
|
+
|
|
110
|
+
// Queen Coordinator types
|
|
111
|
+
export type {
|
|
112
|
+
// Configuration
|
|
113
|
+
QueenCoordinatorConfig,
|
|
114
|
+
|
|
115
|
+
// Task Analysis
|
|
116
|
+
TaskAnalysis,
|
|
117
|
+
SubTask,
|
|
118
|
+
MatchedPattern,
|
|
119
|
+
ResourceRequirements,
|
|
120
|
+
|
|
121
|
+
// Delegation
|
|
122
|
+
DelegationPlan,
|
|
123
|
+
AgentAssignment,
|
|
124
|
+
ParallelAssignment,
|
|
125
|
+
ExecutionStrategy,
|
|
126
|
+
AgentScore,
|
|
127
|
+
|
|
128
|
+
// Health Monitoring
|
|
129
|
+
HealthReport,
|
|
130
|
+
DomainHealthStatus,
|
|
131
|
+
AgentHealthEntry,
|
|
132
|
+
Bottleneck,
|
|
133
|
+
HealthAlert,
|
|
134
|
+
HealthMetrics,
|
|
135
|
+
|
|
136
|
+
// Consensus
|
|
137
|
+
Decision,
|
|
138
|
+
DecisionType,
|
|
139
|
+
ConsensusType,
|
|
140
|
+
|
|
141
|
+
// Learning
|
|
142
|
+
TaskResult,
|
|
143
|
+
TaskMetrics,
|
|
144
|
+
|
|
145
|
+
// Interfaces
|
|
146
|
+
ISwarmCoordinator,
|
|
147
|
+
INeuralLearningSystem,
|
|
148
|
+
IMemoryService,
|
|
149
|
+
PatternMatchResult,
|
|
150
|
+
MemoryRetrievalResult,
|
|
151
|
+
SearchResultEntry,
|
|
152
|
+
MemoryStoreEntry,
|
|
153
|
+
} from './queen-coordinator.js';
|
|
154
|
+
|
|
155
|
+
// =============================================================================
|
|
156
|
+
// Topology Manager
|
|
157
|
+
// =============================================================================
|
|
158
|
+
|
|
159
|
+
export {
|
|
160
|
+
TopologyManager,
|
|
161
|
+
createTopologyManager,
|
|
162
|
+
} from './topology-manager.js';
|
|
163
|
+
|
|
164
|
+
// =============================================================================
|
|
165
|
+
// Message Bus
|
|
166
|
+
// =============================================================================
|
|
167
|
+
|
|
168
|
+
export {
|
|
169
|
+
MessageBus,
|
|
170
|
+
createMessageBus,
|
|
171
|
+
} from './message-bus.js';
|
|
172
|
+
|
|
173
|
+
// =============================================================================
|
|
174
|
+
// Agent Pool
|
|
175
|
+
// =============================================================================
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
AgentPool,
|
|
179
|
+
createAgentPool,
|
|
180
|
+
} from './agent-pool.js';
|
|
181
|
+
|
|
182
|
+
// =============================================================================
|
|
183
|
+
// Consensus Engines
|
|
184
|
+
// =============================================================================
|
|
185
|
+
|
|
186
|
+
export {
|
|
187
|
+
ConsensusEngine,
|
|
188
|
+
createConsensusEngine,
|
|
189
|
+
selectOptimalAlgorithm,
|
|
190
|
+
RaftConsensus,
|
|
191
|
+
ByzantineConsensus,
|
|
192
|
+
GossipConsensus,
|
|
193
|
+
} from './consensus/index.js';
|
|
194
|
+
|
|
195
|
+
export type {
|
|
196
|
+
RaftConfig,
|
|
197
|
+
ByzantineConfig,
|
|
198
|
+
GossipConfig,
|
|
199
|
+
} from './consensus/index.js';
|
|
200
|
+
|
|
201
|
+
// =============================================================================
|
|
202
|
+
// Coordination Components
|
|
203
|
+
// =============================================================================
|
|
204
|
+
|
|
205
|
+
export {
|
|
206
|
+
AgentRegistry,
|
|
207
|
+
createAgentRegistry,
|
|
208
|
+
type IAgentRegistry,
|
|
209
|
+
} from './coordination/agent-registry.js';
|
|
210
|
+
|
|
211
|
+
export {
|
|
212
|
+
TaskOrchestrator,
|
|
213
|
+
createTaskOrchestrator,
|
|
214
|
+
type ITaskOrchestrator,
|
|
215
|
+
type TaskSpec,
|
|
216
|
+
} from './coordination/task-orchestrator.js';
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @deprecated SwarmHub is a compatibility layer. Use UnifiedSwarmCoordinator directly.
|
|
220
|
+
*
|
|
221
|
+
* Migration:
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // OLD:
|
|
224
|
+
* import { createSwarmHub } from '@sparkleideas/swarm';
|
|
225
|
+
* const hub = createSwarmHub();
|
|
226
|
+
*
|
|
227
|
+
* // NEW:
|
|
228
|
+
* import { createUnifiedSwarmCoordinator } from '@sparkleideas/swarm';
|
|
229
|
+
* const coordinator = createUnifiedSwarmCoordinator();
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export {
|
|
233
|
+
SwarmHub,
|
|
234
|
+
createSwarmHub,
|
|
235
|
+
type ISwarmHub,
|
|
236
|
+
} from './coordination/swarm-hub.js';
|
|
237
|
+
|
|
238
|
+
// =============================================================================
|
|
239
|
+
// Worker Dispatch (@sparkleideas/agentic-flow@alpha compatible)
|
|
240
|
+
// =============================================================================
|
|
241
|
+
|
|
242
|
+
export {
|
|
243
|
+
WorkerDispatchService,
|
|
244
|
+
getWorkerDispatchService,
|
|
245
|
+
type WorkerTrigger,
|
|
246
|
+
type WorkerStatus,
|
|
247
|
+
type WorkerInstance,
|
|
248
|
+
type WorkerResult,
|
|
249
|
+
type DispatchOptions,
|
|
250
|
+
type TriggerDetectionResult,
|
|
251
|
+
type WorkerConfig,
|
|
252
|
+
type WorkerMetrics,
|
|
253
|
+
type WorkerArtifact,
|
|
254
|
+
} from './workers/worker-dispatch.js';
|
|
255
|
+
|
|
256
|
+
// =============================================================================
|
|
257
|
+
// Attention Coordinator (Flash/MoE/GraphRoPE)
|
|
258
|
+
// =============================================================================
|
|
259
|
+
|
|
260
|
+
export {
|
|
261
|
+
AttentionCoordinator,
|
|
262
|
+
createAttentionCoordinator,
|
|
263
|
+
type AttentionType,
|
|
264
|
+
type AttentionCoordinatorConfig,
|
|
265
|
+
type CoordinationResult,
|
|
266
|
+
type ExpertRoutingResult,
|
|
267
|
+
type AgentOutput,
|
|
268
|
+
type Task as AttentionTask,
|
|
269
|
+
type SpecializedAgent,
|
|
270
|
+
type SwarmTopology,
|
|
271
|
+
type GraphContext,
|
|
272
|
+
} from './attention-coordinator.js';
|
|
273
|
+
|
|
274
|
+
// =============================================================================
|
|
275
|
+
// Federation Hub (Ephemeral Agent Coordination)
|
|
276
|
+
// =============================================================================
|
|
277
|
+
|
|
278
|
+
export {
|
|
279
|
+
FederationHub,
|
|
280
|
+
createFederationHub,
|
|
281
|
+
getDefaultFederationHub,
|
|
282
|
+
resetDefaultFederationHub,
|
|
283
|
+
type FederationId,
|
|
284
|
+
type SwarmId as FederationSwarmId,
|
|
285
|
+
type EphemeralAgentId,
|
|
286
|
+
type FederationConfig,
|
|
287
|
+
type SwarmRegistration,
|
|
288
|
+
type EphemeralAgent,
|
|
289
|
+
type SpawnEphemeralOptions,
|
|
290
|
+
type SpawnResult,
|
|
291
|
+
type FederationMessage,
|
|
292
|
+
type ConsensusProposal as FederationConsensusProposal,
|
|
293
|
+
type FederationStats,
|
|
294
|
+
type FederationEvent,
|
|
295
|
+
type FederationEventType,
|
|
296
|
+
} from './federation-hub.js';
|
|
297
|
+
|
|
298
|
+
// =============================================================================
|
|
299
|
+
// Default Export
|
|
300
|
+
// =============================================================================
|
|
301
|
+
|
|
302
|
+
import { UnifiedSwarmCoordinator, createUnifiedSwarmCoordinator } from './unified-coordinator.js';
|
|
303
|
+
export default UnifiedSwarmCoordinator;
|
|
304
|
+
|
|
305
|
+
// =============================================================================
|
|
306
|
+
// Constants
|
|
307
|
+
// =============================================================================
|
|
308
|
+
|
|
309
|
+
/** Module version */
|
|
310
|
+
export const VERSION = '3.0.0-alpha.1';
|
|
311
|
+
|
|
312
|
+
/** Performance targets for swarm operations */
|
|
313
|
+
export const PERFORMANCE_TARGETS = {
|
|
314
|
+
/** Maximum latency for coordinating 15 agents */
|
|
315
|
+
COORDINATION_LATENCY_MS: 100,
|
|
316
|
+
/** Maximum latency for consensus operations */
|
|
317
|
+
CONSENSUS_LATENCY_MS: 100,
|
|
318
|
+
/** Minimum message throughput */
|
|
319
|
+
MESSAGE_THROUGHPUT: 1000,
|
|
320
|
+
} as const;
|
|
321
|
+
|
|
322
|
+
/** Supported topology types */
|
|
323
|
+
export const TOPOLOGY_TYPES = ['mesh', 'hierarchical', 'centralized', 'hybrid'] as const;
|
|
324
|
+
|
|
325
|
+
/** Supported consensus algorithms */
|
|
326
|
+
export const CONSENSUS_ALGORITHMS = ['raft', 'byzantine', 'gossip', 'paxos'] as const;
|
|
327
|
+
|
|
328
|
+
/** Default swarm configuration */
|
|
329
|
+
export const DEFAULT_CONFIG = {
|
|
330
|
+
topology: {
|
|
331
|
+
type: 'hierarchical' as const,
|
|
332
|
+
maxAgents: 15,
|
|
333
|
+
},
|
|
334
|
+
consensus: {
|
|
335
|
+
algorithm: 'raft' as const,
|
|
336
|
+
threshold: 0.66,
|
|
337
|
+
timeoutMs: 5000,
|
|
338
|
+
},
|
|
339
|
+
messageBus: {
|
|
340
|
+
maxQueueSize: 10000,
|
|
341
|
+
batchSize: 100,
|
|
342
|
+
},
|
|
343
|
+
agentPool: {
|
|
344
|
+
minAgents: 1,
|
|
345
|
+
maxAgents: 15,
|
|
346
|
+
idleTimeoutMs: 300000,
|
|
347
|
+
},
|
|
348
|
+
} as const;
|