Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | /** * V3 Event Interfaces * Domain-Driven Design - Event Sourcing Pattern (ADR-007) */ /** * Event priority levels */ export type EventPriority = 'critical' | 'high' | 'normal' | 'low'; /** * Core event structure */ export interface IEvent<T = unknown> { readonly id: string; readonly type: string; readonly timestamp: Date; readonly source: string; payload: T; priority?: EventPriority; correlationId?: string; causationId?: string; metadata?: { version?: number; userId?: string; sessionId?: string; [key: string]: unknown; }; } /** * Event creation parameters */ export interface IEventCreate<T = unknown> { type: string; payload: T; source?: string; priority?: EventPriority; correlationId?: string; causationId?: string; metadata?: IEvent['metadata']; } /** * Event handler function type */ export type IEventHandler<T = unknown> = (event: IEvent<T>) => void | Promise<void>; /** * Event filter for subscriptions */ export interface IEventFilter { types?: string[]; sources?: string[]; priority?: EventPriority[]; correlationId?: string; } /** * Event subscription handle */ export interface IEventSubscription { readonly id: string; readonly filter: IEventFilter; /** * Unsubscribe from events */ unsubscribe(): void; /** * Pause subscription */ pause(): void; /** * Resume subscription */ resume(): void; /** * Check if subscription is active */ isActive(): boolean; } /** * Event bus interface for pub/sub communication */ export interface IEventBus { /** * Emit an event to all subscribers */ emit<T = unknown>(type: string, payload: T, options?: Partial<IEventCreate<T>>): void; /** * Emit an event and wait for all handlers */ emitAsync<T = unknown>(type: string, payload: T, options?: Partial<IEventCreate<T>>): Promise<void>; /** * Subscribe to events matching a type pattern */ on<T = unknown>(type: string, handler: IEventHandler<T>): IEventSubscription; /** * Subscribe to events with filter */ subscribe<T = unknown>(filter: IEventFilter, handler: IEventHandler<T>): IEventSubscription; /** * Subscribe to a single event occurrence */ once<T = unknown>(type: string, handler: IEventHandler<T>): IEventSubscription; /** * Remove a specific handler */ off(type: string, handler: IEventHandler): void; /** * Remove all handlers for a type */ removeAllListeners(type?: string): void; /** * Get count of listeners for a type */ listenerCount(type: string): number; /** * Get all event types with active listeners */ eventNames(): string[]; } /** * System event types enumeration */ export const SystemEventTypes = { // System lifecycle SYSTEM_READY: 'system:ready', SYSTEM_SHUTDOWN: 'system:shutdown', SYSTEM_ERROR: 'system:error', SYSTEM_HEALTHCHECK: 'system:healthcheck', // Agent lifecycle AGENT_SPAWNED: 'agent:spawned', AGENT_TERMINATED: 'agent:terminated', AGENT_ERROR: 'agent:error', AGENT_IDLE: 'agent:idle', AGENT_BUSY: 'agent:busy', AGENT_HEALTH_CHANGED: 'agent:health:changed', // Task lifecycle TASK_CREATED: 'task:created', TASK_ASSIGNED: 'task:assigned', TASK_STARTED: 'task:started', TASK_COMPLETED: 'task:completed', TASK_FAILED: 'task:failed', TASK_CANCELLED: 'task:cancelled', TASK_TIMEOUT: 'task:timeout', TASK_RETRY: 'task:retry', // Session lifecycle SESSION_CREATED: 'session:created', SESSION_RESTORED: 'session:restored', SESSION_TERMINATED: 'session:terminated', SESSION_PERSISTED: 'session:persisted', // Memory events MEMORY_STORED: 'memory:stored', MEMORY_RETRIEVED: 'memory:retrieved', MEMORY_CLEARED: 'memory:cleared', // Coordination events COORDINATION_STARTED: 'coordination:started', COORDINATION_COMPLETED: 'coordination:completed', DEADLOCK_DETECTED: 'coordination:deadlock', // Metrics events METRICS_COLLECTED: 'metrics:collected', } as const; export type SystemEventType = typeof SystemEventTypes[keyof typeof SystemEventTypes]; /** * Event store interface for event sourcing */ export interface IEventStore { /** * Append an event to the store */ append(event: IEvent): Promise<void>; /** * Get events by aggregate ID */ getByAggregateId(aggregateId: string, fromVersion?: number): Promise<IEvent[]>; /** * Get events by type */ getByType(type: string, options?: { limit?: number; offset?: number }): Promise<IEvent[]>; /** * Get events in time range */ getByTimeRange(start: Date, end: Date): Promise<IEvent[]>; /** * Get events by correlation ID */ getByCorrelationId(correlationId: string): Promise<IEvent[]>; /** * Get all events (paginated) */ getAll(options?: { limit?: number; offset?: number }): Promise<IEvent[]>; /** * Get event count */ count(filter?: IEventFilter): Promise<number>; /** * Clear old events */ prune(olderThan: Date): Promise<number>; } /** * Event coordinator for routing and orchestration */ export interface IEventCoordinator { /** * Initialize the coordinator */ initialize(): Promise<void>; /** * Shutdown the coordinator */ shutdown(): Promise<void>; /** * Route an event to appropriate handlers */ route(event: IEvent): Promise<void>; /** * Register a handler for event routing */ registerHandler(type: string, handler: IEventHandler): void; /** * Unregister a handler */ unregisterHandler(type: string, handler: IEventHandler): void; /** * Get event bus instance */ getEventBus(): IEventBus; } |