UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 3.21 kB
import{o as e}from"./openclaw-state-read-openclaw-state-db-cache-BVY8IYkn.mjs";import{l as t,u as n}from"./openclaw-state-read-sqlite-lifecycle-errors-3AcFJUep.mjs";import{u as r}from"./openclaw-state-read-sqlite-post-commit-CEHMNIsB.mjs";import{a as i,p as a,r as o}from"./openclaw-state-read-kysely-sync-DQyYiAw5.mjs";import{c as s}from"./openclaw-state-read-sqlite-schema-sql-BnVx4b5A.mjs";import{n as c,r as l}from"./openclaw-state-read-open-pprz0Grj.mjs";import{o as u}from"./openclaw-state-read-openclaw-state-db-schema-helpers-BkqUYEFY.mjs";import{r as d}from"./openclaw-state-read-openclaw-state-db-handle-D9nuaODy.mjs";import{Ct as f,Et as p,Kt as m,Nt as h,Rt as g,Tt as _,Ut as v,r as y,wt as b}from"./openclaw-state-read.worker.js";function inspectPostgresGatewayOwnerLease(r,i,a){(r.location!==r.databasePath||r.snapshotRoot)&&h();let o=d(r.databasePath,{existingOnly:!0,expectedIdentity:r.expectedIdentity}),u;return t({release:()=>n(e.closeUnpublishedOpenClawStateDatabaseHandle({db:u??o,path:r.databasePath}),`Gateway owner lease reader cleanup failed`)},`PostgreSQL Gateway owner lease inspection`,()=>{let e=c(o,`identity`,!0),t=e?.[0];if(e?.length!==1||t?.engine!==`postgres`||typeof t.store_id!=`string`||typeof t.schema!=`string`||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.schema))throw Error(`Invalid PostgreSQL anchor identity during Gateway owner lease inspection`);let{store_id:n,schema:r}=t,d=l.postgres.openConnection({anchor:o,input:i,schema:g,storeId:n,namespace:r,openSqlite:()=>{}});return u=d,d.runTransaction(()=>{let e=d.prepare(`SELECT version, store_id FROM ${s(r)}.openclaw_schema_meta WHERE store = 'state' LIMIT 2`).all();if(e.length!==1||e[0]?.store_id!==n||typeof e[0]?.version!=`number`||!Number.isInteger(e[0].version)||e[0].version<1)throw Error(`PostgreSQL state identity could not be verified for Gateway owner lease inspection`);return b(d.prepare(f).all(r)),a(),readGatewayOwnerLeaseRows(d,r)},void 0,!0)})}function inspectGatewayOwnerLease(e,n,r){let i=r?v():void 0;if(i)return inspectPostgresGatewayOwnerLease(e,i,n);let a=y(e.databasePath,e.location,e.expectedIdentity,e.snapshotRoot);return t({release:()=>{a.close()}},`Gateway owner lease inspection`,()=>{let e=a.database.db,i;return r&&(i=m(e)),t({release:()=>i?.()},`Gateway owner lease schema read admission`,()=>{if(n(),u(e,`state_leases`))return readGatewayOwnerLeaseRows(e)})})}function readGatewayOwnerLeaseRows(e,t){let n=i(e),s=r(e)?(t?n.withSchema(t):n).selectFrom(`state_leases`).select([`owner`,`created_at as createdAt`,`expires_at as expiresAt`,`heartbeat_at as heartbeatAt`,`payload_json as payloadJson`]).where(`scope`,`=`,p.scope).where(`lease_key`,`=`,p.key).limit(2):{compile:()=>a`SELECT owner, created_at AS createdAt, expires_at AS expiresAt, heartbeat_at AS heartbeatAt, payload_json AS payloadJson FROM ${a`state_leases NOT INDEXED`} WHERE scope = ${p.scope} AND lease_key = ${p.key} LIMIT 2`.compile(n)},{rows:c}=o(e,s);if(c.length>1)throw Error(`Gateway owner lease identity is ambiguous during maintenance; stop OpenClaw processes and restore a verified state backup before retrying`);return _(c[0])}export{inspectGatewayOwnerLease};