openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
29 lines (28 loc) • 1.27 kB
JavaScript
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs";
import { t as acpSessionActorKey } from "./manager.utils-CiSXdCbv.mjs";
//#region src/acp/control-plane/active-turns.ts
/** Process-local active-turn registry for restart draining and ACP child admission. */
const state = resolveGlobalSingleton(Symbol.for("openclaw.acp.activeTurns"), () => ({ activeTurnKeys: /* @__PURE__ */ new Map() }));
/** Registers the current turn and returns its ownership-checked release callback. */
function markAcpTurnActive(e) {
if (!e.sessionKey) return;
const t = acpSessionActorKey(e);
const n = Symbol("acp-active-turn");
state.activeTurnKeys.set(t, {
token: n,
sessionKey: e.sessionKey,
ownerSessionKey: e.ownerSessionKey
});
return () => {
if (state.activeTurnKeys.get(t)?.token === n) state.activeTurnKeys.delete(t);
};
}
/** Number of currently owned ACP turns that must settle before restart. */
function getActiveAcpTurnCount() {
return state.activeTurnKeys.size;
}
function listActiveAcpSessionsForOwner(e) {
return [...state.activeTurnKeys.values()].filter((t) => t.ownerSessionKey === e).map((e) => e.sessionKey);
}
//#endregion
export { listActiveAcpSessionsForOwner as n, markAcpTurnActive as r, getActiveAcpTurnCount as t };