openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
31 lines (30 loc) • 1.58 kB
JavaScript
import { c as getAgentRunContext, d as getAgentRunLifecycleGeneration } from "./agent-run-registry-CKYKdfNd.js";
import { f as emitSessionLifecycleEvent } from "./session-history-eviction-C4srftLJ.js";
//#region src/infra/agent-run-capacity-wait.ts
function isAgentRunWaitingForCapacity(runId) {
const context = getAgentRunContext(runId);
return context !== void 0 && context.lifecycleGeneration === getAgentRunLifecycleGeneration() && (context.capacityWaits?.size ?? 0) > 0;
}
/** Records a scheduler-owned wait and releases only the exact captured run instance. */
function registerAgentRunCapacityWait(runId, lifecycleGeneration) {
const context = getAgentRunContext(runId);
if (!context || context.lifecycleGeneration !== lifecycleGeneration || lifecycleGeneration !== getAgentRunLifecycleGeneration()) return;
const waits = context.capacityWaits ??= /* @__PURE__ */ new Set();
const token = Symbol("agent-run-capacity-wait");
const publish = () => {
if (context.sessionKey && context.projectSessionLifecycle !== false && context.projectSessionActive !== false) emitSessionLifecycleEvent({
sessionKey: context.sessionKey,
agentId: context.agentId,
reason: "run-capacity"
});
};
waits.add(token);
if (waits.size === 1) publish();
return () => {
if (getAgentRunContext(runId) !== context || context.lifecycleGeneration !== getAgentRunLifecycleGeneration() || !waits.delete(token) || waits.size > 0) return;
delete context.capacityWaits;
publish();
};
}
//#endregion
export { registerAgentRunCapacityWait as n, isAgentRunWaitingForCapacity as t };