UNPKG

tlnt

Version:

TLNT - HMS-Powered Multi-Agent Platform with Government Agency Analysis, Deep Research, and Enterprise-Ready Deployment. Self-optimizing multi-domain AI agent with continuous learning and enterprise-grade performance monitoring.

91 lines 2.71 kB
import { EventEmitter } from 'events'; import { Subject, filter } from 'rxjs'; export class EventBus extends EventEmitter { eventStream = new Subject(); static instance; constructor() { super(); this.setMaxListeners(0); } static getInstance() { if (!EventBus.instance) { EventBus.instance = new EventBus(); } return EventBus.instance; } publish(event) { this.eventStream.next(event); this.emit('event', event); this.emit(event.type, event); } subscribe(eventType) { let stream = this.eventStream.asObservable(); if (eventType) { stream = stream.pipe(filter(event => event.type === eventType)); } return stream; } subscribeToAgentEvents() { return this.subscribe().pipe(filter(event => event.type.startsWith('agent.') || event.type.startsWith('hub.'))); } subscribeToDealEvents() { return this.subscribe().pipe(filter(event => event.type.startsWith('deal.'))); } subscribeToMetrics() { return this.subscribe().pipe(filter(event => event.type.startsWith('metric.'))); } publishAgentStarted(agentId, metadata = {}) { this.publish({ type: 'agent.started', timestamp: Date.now(), source: agentId, data: { agentId, ...metadata } }); } publishAgentStopped(agentId, metadata = {}) { this.publish({ type: 'agent.stopped', timestamp: Date.now(), source: agentId, data: { agentId, ...metadata } }); } publishDealCreated(dealId, deal) { this.publish({ type: 'deal.created', timestamp: Date.now(), source: 'hub', data: { dealId, deal } }); } publishDealUpdated(dealId, updates) { this.publish({ type: 'deal.updated', timestamp: Date.now(), source: 'hub', data: { dealId, updates } }); } publishMetric(name, value, unit, tags = {}) { this.publish({ type: 'metric.recorded', timestamp: Date.now(), source: 'telemetry', data: { name, value, unit, tags } }); } getEventStats() { const stats = {}; this.eventNames().forEach(eventName => { stats[String(eventName)] = this.listenerCount(eventName); }); return stats; } reset() { this.removeAllListeners(); this.eventStream = new Subject(); } } export const eventBus = EventBus.getInstance(); //# sourceMappingURL=eventBus.js.map