// src/graph-events.ts
import { EventEmitter } from "events";
var buses = /* @__PURE__ */ new Map();
function getGraphEventBus(memoryDir) {
  let bus = buses.get(memoryDir);
  if (!bus) {
    bus = new EventEmitter();
    bus.setMaxListeners(200);
    buses.set(memoryDir, bus);
  }
  return bus;
}
function emitGraphEvent(memoryDir, type, payload) {
  const event = {
    type,
    memoryDir,
    ts: (/* @__PURE__ */ new Date()).toISOString(),
    payload
  };
  const bus = getGraphEventBus(memoryDir);
  try {
    bus.emit("graph-event", event);
  } catch {
  }
}
function subscribeGraphEvents(memoryDir, listener) {
  const bus = getGraphEventBus(memoryDir);
  bus.on("graph-event", listener);
  return () => bus.off("graph-event", listener);
}
function destroyGraphEventBus(memoryDir) {
  const bus = buses.get(memoryDir);
  if (bus) {
    bus.removeAllListeners();
    buses.delete(memoryDir);
  }
}

export {
  getGraphEventBus,
  emitGraphEvent,
  subscribeGraphEvents,
  destroyGraphEventBus
};
//# sourceMappingURL=chunk-WIICJPET.js.map