"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMemorySink = exports.MEMORY_SINK_MAX_EVENTS = void 0;
/** Default ring-buffer capacity. Keeps latest N events; oldest are dropped. */
exports.MEMORY_SINK_MAX_EVENTS = 1000;
/**
 * In-memory ring buffer sink. Used for diagnose-failure analysis after a flow ends.
 * Caps at MAX_EVENTS to bound memory; oldest are dropped when full.
 * `droppedCount` tracks how many events were discarded so callers know data loss occurred.
 */
function createMemorySink(maxEvents = exports.MEMORY_SINK_MAX_EVENTS) {
    const events = [];
    let dropped = 0;
    return {
        write(event) {
            if (events.length >= maxEvents) {
                events.shift();
                dropped++;
            }
            events.push(event);
        },
        snapshot() {
            return events.slice();
        },
        droppedCount() {
            return dropped;
        },
    };
}
exports.createMemorySink = createMemorySink;
//# sourceMappingURL=sink-memory.js.map