UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 4.31 kB
import{Cn as e,xt as t}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{tt as n}from"./openclaw-state-read-sqlite-database-admission-CrkztOzk.mjs";import{d as r,s as i}from"./openclaw-state-read-sqlite-post-commit-CsXPYVOo.mjs";import{serialize as a}from"node:v8";import{AsyncLocalStorage as o}from"node:async_hooks";function createGatewayStateProcessOwnerRetiredError(){return/* @__PURE__ */ Error(`OpenClaw state process owner is no longer current`)}var StateDatabaseAccessError=class extends Error{constructor(...e){super(...e),this.name=`StateDatabaseAccessError`}};const s=e(Symbol.for(`openclaw.gatewayStateOwnerContentionError`),()=>class extends Error{constructor(e,t,n,r){super(`OpenClaw state database is busy at ${e}. ${n?`${n} `:``}Wait for the other OpenClaw process to finish, then retry. If it persists, run \`openclaw gateway status\` and check for other OpenClaw processes using the same state directory. A running Gateway can hold this ownership until it stops; stop it through its service manager or original terminal before retrying.`),this.databasePath=e,this.cause=t,this.holderDetail=n,this.holder=r,this.name=`GatewayStateOwnerContentionError`}}),c=e(Symbol.for(`openclaw.stateDatabaseMaintenanceScopeError`),()=>class extends StateDatabaseAccessError{constructor(e){super(`Internal state ownership error at ${e}: this process holds maintenance ownership without an active schema lease or maintenance scope. Retry the command; if it persists, report this error.`),this.name=`StateDatabaseMaintenanceScopeError`}}),l=e(Symbol.for(`openclaw.stateDatabaseAdmissionPendingError`),()=>class extends StateDatabaseAccessError{constructor(e,t){super(t),this.databasePath=e}}),u=e(Symbol.for(`openclaw.stateDatabaseOfflineMaintenanceError`),()=>class extends StateDatabaseAccessError{constructor(e,t){super(t),this.databasePath=e}}),d=process.hrtime;function readSqliteWorkerMonotonicNs(){return d.bigint()}const f=33554432,p=e(Symbol.for(`openclaw.sqliteWorkerOpenRefusedError`),()=>class extends Error{constructor(e){super(`SQLite worker admission was refused before agent open`,{cause:e}),this.originalError=e,this.name=`SqliteWorkerOpenRefusedError`}}),m=e(Symbol.for(`openclaw.sqliteWorkerAdmissionTimeoutError`),()=>class extends Error{constructor(){super(`SQLite host admission timed out; retry after transaction rollback`),this.code=`admission-timeout`,this.name=`SqliteWorkerAdmissionTimeoutError`}});function isNativeCommitReceipt(e){return t(e)&&e.version===1&&typeof e.sequence==`number`&&Number.isSafeInteger(e.sequence)&&e.sequence>=1&&Object.hasOwn(e,`facts`)}const h=e(Symbol.for(`openclaw.sqliteWorkerNativeCommitReceipts`),()=>/* @__PURE__ */ new WeakMap);function resolveSqliteWorkerFinishSettlement(e,t,n){return e??(n===`not-entered`&&!t?{kind:`completed`}:void 0)}function captureSqliteWorkerCommitReceipt(e){let t=a(e),n=t.byteLength;return n>33554432?{kind:`oversized`,serialized:t}:{kind:`inline`,facts:structuredClone(e),payloadBytes:n}}function deferSqliteWorkerNativeCommitReceipt(e,t,a,o){if(a.kind===`oversized`)throw new n(`SQLite worker commit receipt exceeds the transport limit`,`overloaded`);let{facts:s,payloadBytes:c}=a,l=r(t),u=e.pendingReceipts??=/* @__PURE__ */ new Map,pending=e=>{let t=(u.get(l)??0)+e;t===0?u.delete(l):u.set(l,t)};if(!i(l,{stage:()=>pending(1),rollback:()=>pending(-1),commit(){pending(-1);let t={version:1,sequence:(h.get(e)?.receipt.sequence??0)+1,facts:s},n={receipt:t,payloadBytes:c,delivered:!1};h.set(e,n),e.committed={facts:s},o===`commit`&&(e.port.postMessage({kind:`native-commit`,committed:t,payloadBytes:c},[]),n.delivered=!0)}}))throw Error(`SQLite worker receipt requires a transaction publication owner`)}const g=e(Symbol.for(`openclaw.sqliteWorkerOperationAdmission`),()=>new o);function deferSqliteWorkerCommitReceipt(e,t,r=`commit`){let i=g.getStore();if(!i?.active)throw new n(`SQLite receipt requires its retained admission`,`unavailable`);deferSqliteWorkerNativeCommitReceipt(i.owner,e,captureSqliteWorkerCommitReceipt(t),r)}export{f as a,readSqliteWorkerMonotonicNs as c,l as d,c as f,resolveSqliteWorkerFinishSettlement as i,s as l,createGatewayStateProcessOwnerRetiredError as m,deferSqliteWorkerCommitReceipt as n,m as o,u as p,isNativeCommitReceipt as r,p as s,g as t,StateDatabaseAccessError as u};