UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

71 lines (70 loc) • 2.41 kB
import { n as OpenClawStateLeaseError } from "./openclaw-state-lease-error-Dq51JM59.mjs"; import { r as captureOpenClawStateWorkerContext } from "./openclaw-state-worker-context-DAKL_dnZ.mjs"; import { n as withOpenClawStateLeaseAsync } from "./openclaw-state-lease-Cn13CM0c.mjs"; import { resolve } from "node:path"; //#region 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}`; } //#endregion //#region src/state/claw-package-lifecycle-lease.ts /** Add holds this lease while it commits package references through the state worker. */ 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; } } /** Retain shared artifact ownership through asynchronous work and worker settlement. */ 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 }); }); } //#endregion export { withClawPackageLifecycleLease as n, acquireClawPackageLifecycleLease as t };