@vfarcic/dot-ai
Version:
AI-powered development productivity platform that enhances software development workflows through intelligent automation and AI-driven assistance
52 lines (51 loc) • 1.53 kB
JavaScript
;
/**
* Session Event Bus - Real-time event infrastructure for session lifecycle changes
*
* Interface-based event bus that broadcasts session state changes for any tool.
* Default implementation uses in-memory Node.js EventEmitter.
* Can be swapped to NATS or another external bus via setSessionEventBus().
*
* PRD #425: Session List API and SSE Streaming for Remediation Events
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SESSION_EVENTS = void 0;
exports.getSessionEventBus = getSessionEventBus;
exports.setSessionEventBus = setSessionEventBus;
const events_1 = require("events");
/**
* Event name constants
*/
exports.SESSION_EVENTS = {
SESSION_CREATED: 'session-created',
SESSION_UPDATED: 'session-updated',
};
/**
* In-memory implementation using Node.js EventEmitter.
* Suitable for single-process deployments.
*/
class InMemorySessionEventBus {
emitter = new events_1.EventEmitter();
publish(eventType, event) {
this.emitter.emit(eventType, event);
}
subscribe(eventType, handler) {
this.emitter.on(eventType, handler);
}
unsubscribe(eventType, handler) {
this.emitter.off(eventType, handler);
}
}
let instance = new InMemorySessionEventBus();
/**
* Get the active session event bus singleton
*/
function getSessionEventBus() {
return instance;
}
/**
* Replace the session event bus implementation (for testing or switching to external bus)
*/
function setSessionEventBus(bus) {
instance = bus;
}