// src/sessions/actor.ts
var SessionActor = class {
  constructor(sessionId) {
    this.sessionId = sessionId;
  }
  sessionId;
  tail = Promise.resolve();
  enqueue(fn) {
    const run = this.tail.then(fn, fn);
    this.tail = run.catch(() => {
    });
    return run;
  }
};
function registry() {
  const g = globalThis;
  if (!g.__caActors) g.__caActors = /* @__PURE__ */ new Map();
  return g.__caActors;
}
function getActor(sessionId) {
  const reg = registry();
  let actor = reg.get(sessionId);
  if (!actor) {
    actor = new SessionActor(sessionId);
    reg.set(sessionId, actor);
  }
  return actor;
}
function dropActor(sessionId) {
  registry().delete(sessionId);
}
function allActorIds() {
  return Array.from(registry().keys());
}

export {
  SessionActor,
  getActor,
  dropActor,
  allActorIds
};
