@wavequery/conductor
Version:
Modular LLM orchestration framework
43 lines • 1.24 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventStream = void 0;
const events_1 = require("events");
class EventStream extends events_1.EventEmitter {
constructor(options = {}) {
super();
this.buffer = [];
this.throttleTimeout = null;
this.bufferSize = options.bufferSize || 1000;
this.throttleInterval = options.throttleInterval || 100;
}
push(event) {
this.buffer.push({
...event,
timestamp: new Date(),
});
if (this.buffer.length > this.bufferSize) {
this.buffer.shift();
}
this.scheduleEmit();
}
scheduleEmit() {
if (this.throttleTimeout)
return;
this.throttleTimeout = setTimeout(() => {
this.emit("events", this.buffer);
this.throttleTimeout = null;
}, this.throttleInterval);
}
getBuffer() {
return [...this.buffer];
}
clear() {
this.buffer = [];
if (this.throttleTimeout) {
clearTimeout(this.throttleTimeout);
this.throttleTimeout = null;
}
}
}
exports.EventStream = EventStream;
//# sourceMappingURL=event-stream.js.map