UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

53 lines (52 loc) • 1.87 kB
import "./src-H3RMXyFL.mjs"; import { t as expectDefined } from "./expect-DDakjvvQ.mjs"; import { n as executeExistingOpenClawStateRead } from "./openclaw-state-db-readonly-B6YHb1oF.mjs"; import { t as readConfigMachineState } from "./config-machine-state-DzLVE1Wy.mjs"; import { r as updateConfigMachineState } from "./config-machine-state-write-DanSUxEP.mjs"; //#region src/hooks/installs.ts function readHookInstalls(e = {}) { return readConfigMachineState("hooks.internal.installs", e) ?? {}; } async function readHookInstallsAsync(e = {}) { const t = await executeExistingOpenClawStateRead(e, { type: "hooks.internal.installs" }); if (!t) return {}; return t.row ? JSON.parse(t.row.value_json) : {}; } function recordHookInstall(e, t = {}) { const { hookId: n, ...r } = e; let i; updateConfigMachineState("hooks.internal.installs", (e) => { const t = e && Object.hasOwn(e, n) ? e[n] : void 0; const a = { ...t, ...r, installedAt: r.installedAt ?? (/* @__PURE__ */ new Date()).toISOString() }; i = { hookId: n, previous: t, writtenJson: JSON.stringify(a), bucketExisted: e !== void 0 }; return { ...e, [n]: a }; }, t); return expectDefined(i, "hook install write receipt"); } /** Undo only this install's record, preserving unrelated or newer writers. */ function restoreHookInstallIfCurrent(e, t = {}) { let n = false; updateConfigMachineState("hooks.internal.installs", (t) => { if (!t || !Object.hasOwn(t, e.hookId) || JSON.stringify(t[e.hookId]) !== e.writtenJson) return t; const r = { ...t }; if (e.previous) r[e.hookId] = e.previous; else delete r[e.hookId]; n = true; return !e.bucketExisted && Object.keys(r).length === 0 ? void 0 : r; }, t); return n; } //#endregion export { restoreHookInstallIfCurrent as i, readHookInstallsAsync as n, recordHookInstall as r, readHookInstalls as t };