UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.6 kB
import{a as captureGatewayStateOwner}from"./gateway-state-owner-D_klysuh.mjs";import{i as ErrorCodes}from"./missing-scope-error-CkgBgh6d.mjs";import{p as errorShape}from"./error-codes-CQNGhXT-.mjs";import{i as withChannelReadAuthority}from"./channel-read-authority-BheGEIiJ.mjs";import{l as resolveGatewayLockPaths}from"./gateway-lock-CQoO1usb.mjs";import{statSync}from"node:fs";import path from"node:path"; //!src/gateway/server-methods/local-state-owner.ts function captureLocalStateMutationGuard(e,t,n){const{stateDir:r}=resolveGatewayLockPaths(process.env);const i=captureGatewayStateOwner(path.join(r,`state`,`openclaw.sqlite`));const a=t.context.getRuntimeConfig();const assertCurrent=()=>{t.signal?.throwIfAborted();t.sessionMutationCommitGuard?.();if(!i||i.role!==`gateway`||i.ownerId!==e||t.hasCurrentClientAuthority?.()===false||t.context.getRuntimeConfig()!==a)throw new Error(`Gateway state owner or requester changed; rerun against the current owner.`);i.assertCurrent();if(n){const e=statSync(n.path,{bigint:true});if(`${e.dev}:${e.ino}`!==n.identity)throw new Error(`Source repository changed; rerun worktrees create.`)}};assertCurrent();return assertCurrent}function localStateOwnerChangedError(e){return errorShape(ErrorCodes.UNAVAILABLE,String(e),{details:{reason:`STATE_OWNER_CHANGED`,mutationAccepted:false},retryable:false})}function runWithLocalStateMutationOwner(e,t,n){const r=captureLocalStateMutationGuard(e,t);return withChannelReadAuthority(r,()=>n(r),t.signal)}export{localStateOwnerChangedError as n,runWithLocalStateMutationOwner as r,captureLocalStateMutationGuard as t};