@sparkleideas/shared 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/README.md +323 -0
- package/__tests__/hooks/bash-safety.test.ts +289 -0
- package/__tests__/hooks/file-organization.test.ts +335 -0
- package/__tests__/hooks/git-commit.test.ts +336 -0
- package/__tests__/hooks/index.ts +23 -0
- package/__tests__/hooks/session-hooks.test.ts +357 -0
- package/__tests__/hooks/task-hooks.test.ts +193 -0
- package/docs/EVENTS_IMPLEMENTATION_SUMMARY.md +388 -0
- package/docs/EVENTS_QUICK_REFERENCE.md +470 -0
- package/docs/EVENTS_README.md +352 -0
- package/package.json +39 -0
- package/src/core/config/defaults.ts +207 -0
- package/src/core/config/index.ts +15 -0
- package/src/core/config/loader.ts +271 -0
- package/src/core/config/schema.ts +188 -0
- package/src/core/config/validator.ts +209 -0
- package/src/core/event-bus.ts +236 -0
- package/src/core/index.ts +22 -0
- package/src/core/interfaces/agent.interface.ts +251 -0
- package/src/core/interfaces/coordinator.interface.ts +363 -0
- package/src/core/interfaces/event.interface.ts +267 -0
- package/src/core/interfaces/index.ts +19 -0
- package/src/core/interfaces/memory.interface.ts +332 -0
- package/src/core/interfaces/task.interface.ts +223 -0
- package/src/core/orchestrator/event-coordinator.ts +122 -0
- package/src/core/orchestrator/health-monitor.ts +214 -0
- package/src/core/orchestrator/index.ts +89 -0
- package/src/core/orchestrator/lifecycle-manager.ts +263 -0
- package/src/core/orchestrator/session-manager.ts +279 -0
- package/src/core/orchestrator/task-manager.ts +317 -0
- package/src/events/domain-events.ts +584 -0
- package/src/events/event-store.test.ts +387 -0
- package/src/events/event-store.ts +588 -0
- package/src/events/example-usage.ts +293 -0
- package/src/events/index.ts +90 -0
- package/src/events/projections.ts +561 -0
- package/src/events/state-reconstructor.ts +349 -0
- package/src/events.ts +367 -0
- package/src/hooks/INTEGRATION.md +658 -0
- package/src/hooks/README.md +532 -0
- package/src/hooks/example-usage.ts +499 -0
- package/src/hooks/executor.ts +379 -0
- package/src/hooks/hooks.test.ts +421 -0
- package/src/hooks/index.ts +131 -0
- package/src/hooks/registry.ts +333 -0
- package/src/hooks/safety/bash-safety.ts +604 -0
- package/src/hooks/safety/file-organization.ts +473 -0
- package/src/hooks/safety/git-commit.ts +623 -0
- package/src/hooks/safety/index.ts +46 -0
- package/src/hooks/session-hooks.ts +559 -0
- package/src/hooks/task-hooks.ts +513 -0
- package/src/hooks/types.ts +357 -0
- package/src/hooks/verify-exports.test.ts +125 -0
- package/src/index.ts +195 -0
- package/src/mcp/connection-pool.ts +438 -0
- package/src/mcp/index.ts +183 -0
- package/src/mcp/server.ts +774 -0
- package/src/mcp/session-manager.ts +428 -0
- package/src/mcp/tool-registry.ts +566 -0
- package/src/mcp/transport/http.ts +557 -0
- package/src/mcp/transport/index.ts +294 -0
- package/src/mcp/transport/stdio.ts +324 -0
- package/src/mcp/transport/websocket.ts +484 -0
- package/src/mcp/types.ts +565 -0
- package/src/plugin-interface.ts +663 -0
- package/src/plugin-loader.ts +638 -0
- package/src/plugin-registry.ts +604 -0
- package/src/plugins/index.ts +34 -0
- package/src/plugins/official/hive-mind-plugin.ts +330 -0
- package/src/plugins/official/index.ts +24 -0
- package/src/plugins/official/maestro-plugin.ts +508 -0
- package/src/plugins/types.ts +108 -0
- package/src/resilience/bulkhead.ts +277 -0
- package/src/resilience/circuit-breaker.ts +326 -0
- package/src/resilience/index.ts +26 -0
- package/src/resilience/rate-limiter.ts +420 -0
- package/src/resilience/retry.ts +224 -0
- package/src/security/index.ts +39 -0
- package/src/security/input-validation.ts +265 -0
- package/src/security/secure-random.ts +159 -0
- package/src/services/index.ts +16 -0
- package/src/services/v3-progress.service.ts +505 -0
- package/src/types/agent.types.ts +144 -0
- package/src/types/index.ts +22 -0
- package/src/types/mcp.types.ts +300 -0
- package/src/types/memory.types.ts +263 -0
- package/src/types/swarm.types.ts +255 -0
- package/src/types/task.types.ts +205 -0
- package/src/types.ts +367 -0
- package/src/utils/secure-logger.d.ts +69 -0
- package/src/utils/secure-logger.d.ts.map +1 -0
- package/src/utils/secure-logger.js +208 -0
- package/src/utils/secure-logger.js.map +1 -0
- package/src/utils/secure-logger.ts +257 -0
- package/tmp.json +0 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Coordinator Interfaces
|
|
3
|
+
* Domain-Driven Design - Coordination Bounded Context
|
|
4
|
+
* Aligned with ADR-003 (Single Coordination Engine)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ITask, ITaskResult } from './task.interface.js';
|
|
8
|
+
import type { IAgent, IAgentConfig } from './agent.interface.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Swarm topology types
|
|
12
|
+
*/
|
|
13
|
+
export type SwarmTopology =
|
|
14
|
+
| 'hierarchical'
|
|
15
|
+
| 'mesh'
|
|
16
|
+
| 'ring'
|
|
17
|
+
| 'star'
|
|
18
|
+
| 'adaptive'
|
|
19
|
+
| 'hierarchical-mesh';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Coordination status
|
|
23
|
+
*/
|
|
24
|
+
export type CoordinationStatus =
|
|
25
|
+
| 'initializing'
|
|
26
|
+
| 'ready'
|
|
27
|
+
| 'coordinating'
|
|
28
|
+
| 'degraded'
|
|
29
|
+
| 'error'
|
|
30
|
+
| 'shutdown';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Swarm configuration
|
|
34
|
+
*/
|
|
35
|
+
export interface ISwarmConfig {
|
|
36
|
+
topology: SwarmTopology;
|
|
37
|
+
maxAgents: number;
|
|
38
|
+
|
|
39
|
+
autoScale?: {
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
minAgents: number;
|
|
42
|
+
maxAgents: number;
|
|
43
|
+
scaleUpThreshold: number;
|
|
44
|
+
scaleDownThreshold: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
coordination?: {
|
|
48
|
+
consensusRequired: boolean;
|
|
49
|
+
timeoutMs: number;
|
|
50
|
+
retryPolicy: {
|
|
51
|
+
maxRetries: number;
|
|
52
|
+
backoffMs: number;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
communication?: {
|
|
57
|
+
protocol: 'events' | 'messages' | 'shared-memory';
|
|
58
|
+
batchSize: number;
|
|
59
|
+
flushIntervalMs: number;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
metadata?: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Swarm state
|
|
67
|
+
*/
|
|
68
|
+
export interface ISwarmState {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly topology: SwarmTopology;
|
|
71
|
+
readonly createdAt: Date;
|
|
72
|
+
|
|
73
|
+
status: CoordinationStatus;
|
|
74
|
+
agentCount: number;
|
|
75
|
+
taskCount: number;
|
|
76
|
+
|
|
77
|
+
metrics?: {
|
|
78
|
+
throughput: number;
|
|
79
|
+
latencyMs: number;
|
|
80
|
+
successRate: number;
|
|
81
|
+
resourceUtilization: number;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Coordinator interface - unified coordination engine
|
|
87
|
+
*/
|
|
88
|
+
export interface ICoordinator {
|
|
89
|
+
/**
|
|
90
|
+
* Initialize the coordinator
|
|
91
|
+
*/
|
|
92
|
+
initialize(): Promise<void>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Shutdown the coordinator
|
|
96
|
+
*/
|
|
97
|
+
shutdown(): Promise<void>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Initialize a swarm with configuration
|
|
101
|
+
*/
|
|
102
|
+
initializeSwarm(config: ISwarmConfig): Promise<ISwarmState>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get swarm state
|
|
106
|
+
*/
|
|
107
|
+
getSwarmState(): ISwarmState | undefined;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Assign a task to an agent
|
|
111
|
+
*/
|
|
112
|
+
assignTask(task: ITask, agentId: string): Promise<void>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get tasks assigned to an agent
|
|
116
|
+
*/
|
|
117
|
+
getAgentTasks(agentId: string): Promise<ITask[]>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get task count for an agent
|
|
121
|
+
*/
|
|
122
|
+
getAgentTaskCount(agentId: string): Promise<number>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Cancel a task
|
|
126
|
+
*/
|
|
127
|
+
cancelTask(taskId: string): Promise<void>;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Report task completion
|
|
131
|
+
*/
|
|
132
|
+
reportTaskComplete(taskId: string, result: ITaskResult): Promise<void>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get coordination health status
|
|
136
|
+
*/
|
|
137
|
+
getHealthStatus(): Promise<{ healthy: boolean; error?: string; metrics?: Record<string, number> }>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Perform maintenance tasks
|
|
141
|
+
*/
|
|
142
|
+
performMaintenance(): Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Coordination manager interface - higher-level orchestration
|
|
147
|
+
*/
|
|
148
|
+
export interface ICoordinationManager extends ICoordinator {
|
|
149
|
+
/**
|
|
150
|
+
* Register an agent with the coordinator
|
|
151
|
+
*/
|
|
152
|
+
registerAgent(agent: IAgent): Promise<void>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Unregister an agent
|
|
156
|
+
*/
|
|
157
|
+
unregisterAgent(agentId: string): Promise<void>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Get all registered agents
|
|
161
|
+
*/
|
|
162
|
+
getRegisteredAgents(): IAgent[];
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Request agent consensus on a decision
|
|
166
|
+
*/
|
|
167
|
+
requestConsensus(topic: string, options: unknown[], timeout?: number): Promise<unknown>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Broadcast message to all agents
|
|
171
|
+
*/
|
|
172
|
+
broadcast(message: unknown): Promise<void>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Send message to specific agent
|
|
176
|
+
*/
|
|
177
|
+
sendToAgent(agentId: string, message: unknown): Promise<void>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Acquire a distributed lock
|
|
181
|
+
*/
|
|
182
|
+
acquireLock(resourceId: string, agentId: string, timeout?: number): Promise<boolean>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Release a distributed lock
|
|
186
|
+
*/
|
|
187
|
+
releaseLock(resourceId: string, agentId: string): Promise<void>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Check for deadlocks
|
|
191
|
+
*/
|
|
192
|
+
detectDeadlocks(): Promise<{ detected: boolean; agents?: string[]; resources?: string[] }>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Health status for components
|
|
197
|
+
*/
|
|
198
|
+
export interface IHealthStatus {
|
|
199
|
+
status: 'healthy' | 'degraded' | 'unhealthy';
|
|
200
|
+
components: Record<string, IComponentHealth>;
|
|
201
|
+
timestamp: Date;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Component health details
|
|
206
|
+
*/
|
|
207
|
+
export interface IComponentHealth {
|
|
208
|
+
name: string;
|
|
209
|
+
status: 'healthy' | 'degraded' | 'unhealthy';
|
|
210
|
+
lastCheck: Date;
|
|
211
|
+
error?: string;
|
|
212
|
+
metrics?: Record<string, number>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Health monitor interface
|
|
217
|
+
*/
|
|
218
|
+
export interface IHealthMonitor {
|
|
219
|
+
/**
|
|
220
|
+
* Start health monitoring
|
|
221
|
+
*/
|
|
222
|
+
start(): void;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Stop health monitoring
|
|
226
|
+
*/
|
|
227
|
+
stop(): void;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Get current health status
|
|
231
|
+
*/
|
|
232
|
+
getStatus(): Promise<IHealthStatus>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Register a health check
|
|
236
|
+
*/
|
|
237
|
+
registerCheck(
|
|
238
|
+
name: string,
|
|
239
|
+
check: () => Promise<{ healthy: boolean; error?: string; metrics?: Record<string, number> }>
|
|
240
|
+
): void;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Unregister a health check
|
|
244
|
+
*/
|
|
245
|
+
unregisterCheck(name: string): void;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Get health history
|
|
249
|
+
*/
|
|
250
|
+
getHistory(limit?: number): IHealthStatus[];
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Subscribe to health changes
|
|
254
|
+
*/
|
|
255
|
+
onHealthChange(callback: (status: IHealthStatus) => void): () => void;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Metrics collector interface
|
|
260
|
+
*/
|
|
261
|
+
export interface IMetricsCollector {
|
|
262
|
+
/**
|
|
263
|
+
* Start metrics collection
|
|
264
|
+
*/
|
|
265
|
+
start(): void;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Stop metrics collection
|
|
269
|
+
*/
|
|
270
|
+
stop(): void;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Record a metric value
|
|
274
|
+
*/
|
|
275
|
+
record(name: string, value: number, tags?: Record<string, string>): void;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Increment a counter
|
|
279
|
+
*/
|
|
280
|
+
increment(name: string, value?: number, tags?: Record<string, string>): void;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Record a timing
|
|
284
|
+
*/
|
|
285
|
+
timing(name: string, durationMs: number, tags?: Record<string, string>): void;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Get current metrics
|
|
289
|
+
*/
|
|
290
|
+
getMetrics(): Record<string, { value: number; count: number; avg: number; min: number; max: number }>;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Reset all metrics
|
|
294
|
+
*/
|
|
295
|
+
reset(): void;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Orchestrator metrics structure
|
|
300
|
+
*/
|
|
301
|
+
export interface IOrchestratorMetrics {
|
|
302
|
+
uptime: number;
|
|
303
|
+
totalAgents: number;
|
|
304
|
+
activeAgents: number;
|
|
305
|
+
totalTasks: number;
|
|
306
|
+
completedTasks: number;
|
|
307
|
+
failedTasks: number;
|
|
308
|
+
queuedTasks: number;
|
|
309
|
+
avgTaskDuration: number;
|
|
310
|
+
memoryUsage: NodeJS.MemoryUsage;
|
|
311
|
+
cpuUsage: NodeJS.CpuUsage;
|
|
312
|
+
timestamp: Date;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Main orchestrator interface - facade for all orchestration capabilities
|
|
317
|
+
*/
|
|
318
|
+
export interface IOrchestrator {
|
|
319
|
+
/**
|
|
320
|
+
* Initialize the orchestrator
|
|
321
|
+
*/
|
|
322
|
+
initialize(): Promise<void>;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Shutdown the orchestrator
|
|
326
|
+
*/
|
|
327
|
+
shutdown(): Promise<void>;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Get health status
|
|
331
|
+
*/
|
|
332
|
+
getHealthStatus(): Promise<IHealthStatus>;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Get orchestrator metrics
|
|
336
|
+
*/
|
|
337
|
+
getMetrics(): Promise<IOrchestratorMetrics>;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Spawn a new agent
|
|
341
|
+
*/
|
|
342
|
+
spawnAgent(config: IAgentConfig): Promise<IAgent>;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Terminate an agent
|
|
346
|
+
*/
|
|
347
|
+
terminateAgent(agentId: string, reason?: string): Promise<void>;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Submit a task
|
|
351
|
+
*/
|
|
352
|
+
submitTask(task: ITask): Promise<ITaskResult>;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Get task by ID
|
|
356
|
+
*/
|
|
357
|
+
getTask(taskId: string): Promise<ITask | undefined>;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Cancel a task
|
|
361
|
+
*/
|
|
362
|
+
cancelTask(taskId: string): Promise<void>;
|
|
363
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Event Interfaces
|
|
3
|
+
* Domain-Driven Design - Event Sourcing Pattern (ADR-007)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Event priority levels
|
|
8
|
+
*/
|
|
9
|
+
export type EventPriority = 'critical' | 'high' | 'normal' | 'low';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Core event structure
|
|
13
|
+
*/
|
|
14
|
+
export interface IEvent<T = unknown> {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly type: string;
|
|
17
|
+
readonly timestamp: Date;
|
|
18
|
+
readonly source: string;
|
|
19
|
+
|
|
20
|
+
payload: T;
|
|
21
|
+
priority?: EventPriority;
|
|
22
|
+
correlationId?: string;
|
|
23
|
+
causationId?: string;
|
|
24
|
+
|
|
25
|
+
metadata?: {
|
|
26
|
+
version?: number;
|
|
27
|
+
userId?: string;
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Event creation parameters
|
|
35
|
+
*/
|
|
36
|
+
export interface IEventCreate<T = unknown> {
|
|
37
|
+
type: string;
|
|
38
|
+
payload: T;
|
|
39
|
+
source?: string;
|
|
40
|
+
priority?: EventPriority;
|
|
41
|
+
correlationId?: string;
|
|
42
|
+
causationId?: string;
|
|
43
|
+
metadata?: IEvent['metadata'];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Event handler function type
|
|
48
|
+
*/
|
|
49
|
+
export type IEventHandler<T = unknown> = (event: IEvent<T>) => void | Promise<void>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Event filter for subscriptions
|
|
53
|
+
*/
|
|
54
|
+
export interface IEventFilter {
|
|
55
|
+
types?: string[];
|
|
56
|
+
sources?: string[];
|
|
57
|
+
priority?: EventPriority[];
|
|
58
|
+
correlationId?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Event subscription handle
|
|
63
|
+
*/
|
|
64
|
+
export interface IEventSubscription {
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly filter: IEventFilter;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Unsubscribe from events
|
|
70
|
+
*/
|
|
71
|
+
unsubscribe(): void;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Pause subscription
|
|
75
|
+
*/
|
|
76
|
+
pause(): void;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Resume subscription
|
|
80
|
+
*/
|
|
81
|
+
resume(): void;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Check if subscription is active
|
|
85
|
+
*/
|
|
86
|
+
isActive(): boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Event bus interface for pub/sub communication
|
|
91
|
+
*/
|
|
92
|
+
export interface IEventBus {
|
|
93
|
+
/**
|
|
94
|
+
* Emit an event to all subscribers
|
|
95
|
+
*/
|
|
96
|
+
emit<T = unknown>(type: string, payload: T, options?: Partial<IEventCreate<T>>): void;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Emit an event and wait for all handlers
|
|
100
|
+
*/
|
|
101
|
+
emitAsync<T = unknown>(type: string, payload: T, options?: Partial<IEventCreate<T>>): Promise<void>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Subscribe to events matching a type pattern
|
|
105
|
+
*/
|
|
106
|
+
on<T = unknown>(type: string, handler: IEventHandler<T>): IEventSubscription;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Subscribe to events with filter
|
|
110
|
+
*/
|
|
111
|
+
subscribe<T = unknown>(filter: IEventFilter, handler: IEventHandler<T>): IEventSubscription;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe to a single event occurrence
|
|
115
|
+
*/
|
|
116
|
+
once<T = unknown>(type: string, handler: IEventHandler<T>): IEventSubscription;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Remove a specific handler
|
|
120
|
+
*/
|
|
121
|
+
off(type: string, handler: IEventHandler): void;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Remove all handlers for a type
|
|
125
|
+
*/
|
|
126
|
+
removeAllListeners(type?: string): void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get count of listeners for a type
|
|
130
|
+
*/
|
|
131
|
+
listenerCount(type: string): number;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Get all event types with active listeners
|
|
135
|
+
*/
|
|
136
|
+
eventNames(): string[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* System event types enumeration
|
|
141
|
+
*/
|
|
142
|
+
export const SystemEventTypes = {
|
|
143
|
+
// System lifecycle
|
|
144
|
+
SYSTEM_READY: 'system:ready',
|
|
145
|
+
SYSTEM_SHUTDOWN: 'system:shutdown',
|
|
146
|
+
SYSTEM_ERROR: 'system:error',
|
|
147
|
+
SYSTEM_HEALTHCHECK: 'system:healthcheck',
|
|
148
|
+
|
|
149
|
+
// Agent lifecycle
|
|
150
|
+
AGENT_SPAWNED: 'agent:spawned',
|
|
151
|
+
AGENT_TERMINATED: 'agent:terminated',
|
|
152
|
+
AGENT_ERROR: 'agent:error',
|
|
153
|
+
AGENT_IDLE: 'agent:idle',
|
|
154
|
+
AGENT_BUSY: 'agent:busy',
|
|
155
|
+
AGENT_HEALTH_CHANGED: 'agent:health:changed',
|
|
156
|
+
|
|
157
|
+
// Task lifecycle
|
|
158
|
+
TASK_CREATED: 'task:created',
|
|
159
|
+
TASK_ASSIGNED: 'task:assigned',
|
|
160
|
+
TASK_STARTED: 'task:started',
|
|
161
|
+
TASK_COMPLETED: 'task:completed',
|
|
162
|
+
TASK_FAILED: 'task:failed',
|
|
163
|
+
TASK_CANCELLED: 'task:cancelled',
|
|
164
|
+
TASK_TIMEOUT: 'task:timeout',
|
|
165
|
+
TASK_RETRY: 'task:retry',
|
|
166
|
+
|
|
167
|
+
// Session lifecycle
|
|
168
|
+
SESSION_CREATED: 'session:created',
|
|
169
|
+
SESSION_RESTORED: 'session:restored',
|
|
170
|
+
SESSION_TERMINATED: 'session:terminated',
|
|
171
|
+
SESSION_PERSISTED: 'session:persisted',
|
|
172
|
+
|
|
173
|
+
// Memory events
|
|
174
|
+
MEMORY_STORED: 'memory:stored',
|
|
175
|
+
MEMORY_RETRIEVED: 'memory:retrieved',
|
|
176
|
+
MEMORY_CLEARED: 'memory:cleared',
|
|
177
|
+
|
|
178
|
+
// Coordination events
|
|
179
|
+
COORDINATION_STARTED: 'coordination:started',
|
|
180
|
+
COORDINATION_COMPLETED: 'coordination:completed',
|
|
181
|
+
DEADLOCK_DETECTED: 'coordination:deadlock',
|
|
182
|
+
|
|
183
|
+
// Metrics events
|
|
184
|
+
METRICS_COLLECTED: 'metrics:collected',
|
|
185
|
+
} as const;
|
|
186
|
+
|
|
187
|
+
export type SystemEventType = typeof SystemEventTypes[keyof typeof SystemEventTypes];
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Event store interface for event sourcing
|
|
191
|
+
*/
|
|
192
|
+
export interface IEventStore {
|
|
193
|
+
/**
|
|
194
|
+
* Append an event to the store
|
|
195
|
+
*/
|
|
196
|
+
append(event: IEvent): Promise<void>;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Get events by aggregate ID
|
|
200
|
+
*/
|
|
201
|
+
getByAggregateId(aggregateId: string, fromVersion?: number): Promise<IEvent[]>;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Get events by type
|
|
205
|
+
*/
|
|
206
|
+
getByType(type: string, options?: { limit?: number; offset?: number }): Promise<IEvent[]>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Get events in time range
|
|
210
|
+
*/
|
|
211
|
+
getByTimeRange(start: Date, end: Date): Promise<IEvent[]>;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Get events by correlation ID
|
|
215
|
+
*/
|
|
216
|
+
getByCorrelationId(correlationId: string): Promise<IEvent[]>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Get all events (paginated)
|
|
220
|
+
*/
|
|
221
|
+
getAll(options?: { limit?: number; offset?: number }): Promise<IEvent[]>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Get event count
|
|
225
|
+
*/
|
|
226
|
+
count(filter?: IEventFilter): Promise<number>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Clear old events
|
|
230
|
+
*/
|
|
231
|
+
prune(olderThan: Date): Promise<number>;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Event coordinator for routing and orchestration
|
|
236
|
+
*/
|
|
237
|
+
export interface IEventCoordinator {
|
|
238
|
+
/**
|
|
239
|
+
* Initialize the coordinator
|
|
240
|
+
*/
|
|
241
|
+
initialize(): Promise<void>;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Shutdown the coordinator
|
|
245
|
+
*/
|
|
246
|
+
shutdown(): Promise<void>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Route an event to appropriate handlers
|
|
250
|
+
*/
|
|
251
|
+
route(event: IEvent): Promise<void>;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Register a handler for event routing
|
|
255
|
+
*/
|
|
256
|
+
registerHandler(type: string, handler: IEventHandler): void;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Unregister a handler
|
|
260
|
+
*/
|
|
261
|
+
unregisterHandler(type: string, handler: IEventHandler): void;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Get event bus instance
|
|
265
|
+
*/
|
|
266
|
+
getEventBus(): IEventBus;
|
|
267
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Core Interfaces - Public API
|
|
3
|
+
* Domain-Driven Design with Clean Architecture
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Task interfaces
|
|
7
|
+
export * from './task.interface.js';
|
|
8
|
+
|
|
9
|
+
// Agent interfaces
|
|
10
|
+
export * from './agent.interface.js';
|
|
11
|
+
|
|
12
|
+
// Event interfaces
|
|
13
|
+
export * from './event.interface.js';
|
|
14
|
+
|
|
15
|
+
// Memory interfaces
|
|
16
|
+
export * from './memory.interface.js';
|
|
17
|
+
|
|
18
|
+
// Coordinator interfaces
|
|
19
|
+
export * from './coordinator.interface.js';
|