openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 1.26 kB
JavaScript
import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
//#region extensions/reef/src/runtime.ts
const { setRuntime: setReefRuntime, tryGetRuntime: getOptionalReefRuntime, getRuntime: getReefRuntime } = createPluginRuntimeStore({
pluginId: "reef",
errorMessage: "Reef runtime unavailable"
});
const activeReefStore = createPluginRuntimeStore({
key: "plugin-runtime:reef:active",
errorMessage: "Reef channel is not running"
});
function createReefRuntimeAuthority(e) {
const t = new AbortController();
const n = e ? AbortSignal.any([e, t.signal]) : t.signal;
let r = null;
return {
signal: n,
activate(e) {
n.throwIfAborted();
const i = activeReefStore.tryGetRuntime();
r = {
value: e,
controller: t,
signal: n
};
activeReefStore.setRuntime(r);
i?.controller.abort();
},
release() {
t.abort();
if (activeReefStore.tryGetRuntime() === r) activeReefStore.clearRuntime();
}
};
}
function getActiveReef() {
const e = activeReefStore.getRuntime();
if (e.signal.aborted) throw new Error("Reef channel is not running");
return e.value;
}
//#endregion
export { setReefRuntime as a, getReefRuntime as i, getActiveReef as n, getOptionalReefRuntime as r, createReefRuntimeAuthority as t };