openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
27 lines (26 loc) • 1.13 kB
JavaScript
import { i as resolveGlobalSingleton } from "./global-singleton-Dc_stLtU.js";
import { AsyncLocalStorage } from "node:async_hooks";
//#region src/cli/runtime-cleanup-scope.ts
const scope = resolveGlobalSingleton(Symbol.for("openclaw.cliRuntimeCleanup"), () => new AsyncLocalStorage());
function withCliProcessScope(run) {
return scope.run("process", run);
}
function withCliCommandCleanup(gatewayRun, run) {
if (gatewayRun) return scope.run(void 0, () => run());
if (scope.getStore() !== "process") return run();
const cleanup = {
harnesses: /* @__PURE__ */ new Map(),
registries: /* @__PURE__ */ new Set()
};
return scope.run(cleanup, () => run(cleanup));
}
function retainCliRegistryHarnesses(registry, dispose) {
const current = scope.getStore();
if (!current || current === "process") return;
for (const { harness } of registry.agentHarnesses) {
current.registries.add(registry);
if (!current.harnesses.has(harness)) current.harnesses.set(harness, AsyncLocalStorage.bind(() => dispose(harness)));
}
}
//#endregion
export { withCliCommandCleanup as n, withCliProcessScope as r, retainCliRegistryHarnesses as t };