UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 1.88 kB
import{n as OpenClawStateLeaseError}from"./openclaw-state-lease-error-DCUL0v5x.mjs";import{r as captureOpenClawStateWorkerContext}from"./openclaw-state-worker-context-Dx8YjqO2.mjs";import{n as withOpenClawStateLeaseAsync}from"./openclaw-state-lease-B5EAG_56.mjs";import{resolve}from"node:path"; //!src/state/claw-package-lifecycle-lease-key.ts const CLAW_PACKAGE_LIFECYCLE_LEASE_SCOPE=`claw-package-lifecycle`;function clawPackageLifecycleLeaseKey(e){return e.kind===`skill`?`skill:${e.source}:workspace:${resolve(e.workspace)}`:`${e.kind}:${e.source}:${e.ref}`} //!src/state/claw-package-lifecycle-lease.ts async function acquireClawPackageLifecycleLease(e,t={}){const n=Promise.withResolvers();const r=Promise.withResolvers();let i=true;const a=withClawPackageLifecycleLease(e,async(e,t)=>{n.resolve({identity:t,assertCurrent:()=>{if(!i)throw new Error(`Package lifecycle lease has been released.`);e.assertCurrent()},assertOwned:async()=>{if(!i)throw new Error(`Package lifecycle lease has been released.`);await e.assertOwned();if(!i)throw new Error(`Package lifecycle lease has been released.`)},release:async()=>{if(i){i=false;r.resolve()}await a}});await r.promise},t);a.catch(e=>n.reject(e));try{return await n.promise}catch(e){if(t.required||e instanceof OpenClawStateLeaseError&&e.code===`OPENCLAW_STATE_LEASE_HELD`)throw e;return null}}function withClawPackageLifecycleLease(e,t,n={}){const r=captureOpenClawStateWorkerContext({env:n.env,path:n.database?.path??n.path});return withOpenClawStateLeaseAsync({scope:CLAW_PACKAGE_LIFECYCLE_LEASE_SCOPE,key:clawPackageLifecycleLeaseKey(e),leaseMs:3e5,waitMs:0,signal:n.signal,leaseLabel:`Claw package lifecycle`,operationLabel:`claw.package.lifecycle`},r,(e,n)=>{return t(e,{scope:CLAW_PACKAGE_LIFECYCLE_LEASE_SCOPE,key:n.key,owner:n.owner})})}export{withClawPackageLifecycleLease as n,acquireClawPackageLifecycleLease as t};