UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.52 kB
import"./src-0ci69Prg.mjs";import{t as expectDefined}from"./expect-DkJCbmLj.mjs";import{n as executeExistingOpenClawStateRead}from"./openclaw-state-db-readonly-Cd5_cxBs.mjs";import{t as readConfigMachineState}from"./config-machine-state-XW0lvLg7.mjs";import{r as updateConfigMachineState}from"./config-machine-state-write-y_DUumZ_.mjs"; //!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`)}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}export{restoreHookInstallIfCurrent as i,readHookInstallsAsync as n,recordHookInstall as r,readHookInstalls as t};