donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
47 lines • 1.57 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlowLogBuffer = void 0;
const DEFAULT_MAX_BYTES = 2 * 1024 * 1024; // 2 MB
/**
* A bounded, per-flow ring buffer that accumulates log entries in memory.
*
* When the buffer exceeds its byte budget, the oldest entries are evicted
* first. Eviction counts are tracked per source so the UI can inform the
* user how many entries were dropped.
*/
class FlowLogBuffer {
constructor(maxBytes = DEFAULT_MAX_BYTES) {
this.maxBytes = maxBytes;
this.entries = [];
this.currentBytes = 0;
this.evicted = {
donobu: 0,
browser: 0,
network: 0,
};
}
push(entry) {
const entryBytes = this.estimateBytes(entry);
while (this.entries.length > 0 &&
this.currentBytes + entryBytes > this.maxBytes) {
const removed = this.entries.shift();
this.currentBytes -= this.estimateBytes(removed);
this.evicted[removed.source]++;
}
this.entries.push(entry);
this.currentBytes += entryBytes;
}
snapshot() {
return {
entries: [...this.entries],
evicted: { ...this.evicted },
};
}
estimateBytes(entry) {
// Fast estimate: stringify once. This slightly overestimates due to JSON
// overhead but is consistent for both add and remove.
return JSON.stringify(entry).length;
}
}
exports.FlowLogBuffer = FlowLogBuffer;
//# sourceMappingURL=FlowLogBuffer.js.map