openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
34 lines (33 loc) • 1.52 kB
JavaScript
import { l as getAgentRunContext } from "./agent-run-registry-D7vkrqFT.mjs";
import { r as getAgentRunLifecycleGeneration, t as bumpAgentRunIndexVersion } from "./agent-run-registry-state-BFfw9a4W.mjs";
import { n as emitSessionLifecycleEvent } from "./session-lifecycle-events-DWKmeEvQ.mjs";
//#region src/infra/agent-run-capacity-wait.ts
function isAgentRunWaitingForCapacity(e) {
const t = getAgentRunContext(e);
return t !== void 0 && t.lifecycleGeneration === getAgentRunLifecycleGeneration() && (t.capacityWaits?.size ?? 0) > 0;
}
/** Records a scheduler-owned wait and releases only the exact captured run instance. */
function registerAgentRunCapacityWait(e, t) {
const n = getAgentRunContext(e);
if (!n || n.lifecycleGeneration !== t || t !== getAgentRunLifecycleGeneration()) return;
const r = n.capacityWaits ??= /* @__PURE__ */ new Set();
const i = Symbol("agent-run-capacity-wait");
const publish = () => {
bumpAgentRunIndexVersion(n);
if (n.sessionKey && n.projectSessionLifecycle !== false && n.projectSessionActive !== false) emitSessionLifecycleEvent({
sessionKey: n.sessionKey,
agentId: n.agentId,
reason: "run-capacity",
scope: "runtime"
});
};
r.add(i);
if (r.size === 1) publish();
return () => {
if (getAgentRunContext(e) !== n || n.lifecycleGeneration !== getAgentRunLifecycleGeneration() || !r.delete(i) || r.size > 0) return;
delete n.capacityWaits;
publish();
};
}
//#endregion
export { registerAgentRunCapacityWait as n, isAgentRunWaitingForCapacity as t };