export class RpcEventBuffer {
    constructor(emit) {
        this.updates = new Map();
        this.emit = emit;
    }
    enqueue(event) {
        const key = event.type === "message_update"
            ? "message"
            : event.type === "tool_execution_update"
                ? `tool:${event.toolCallId}`
                : undefined;
        if (!key) {
            this.flush();
            this.emit(event);
            return;
        }
        this.updates.set(key, event);
        this.timer ??= setTimeout(() => this.flush(), 16);
    }
    flush() {
        if (this.timer)
            clearTimeout(this.timer);
        this.timer = undefined;
        for (const event of this.updates.values())
            this.emit(event);
        this.updates.clear();
    }
    dispose() { this.flush(); }
}
//# sourceMappingURL=rpc-event-buffer.js.map