UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.82 kB
import{u as e}from"./openclaw-state-read-sqlite-post-commit-CsXPYVOo.mjs";import"./openclaw-state-read-openclaw-state-db-contract-vqwNsqc6.mjs";import{o as t,t as n,w as r}from"./openclaw-state-read-sqlite-schema-facts-Dtolu7-X.mjs";import{a as i,c as a,t as o}from"./openclaw-state-read-kysely-sync-Bcu0Qb7F.mjs";import{l as s,o as c}from"./openclaw-state-read-openclaw-state-db-schema-helpers-QFZd8aJI.mjs";import{n as l,o as u,s as d}from"./openclaw-state-read-sqlite-user-version-B2KxorOy.mjs";import{i as f}from"./openclaw-state-read-openclaw-state-db-schema-migration-required-Depq2M2O.mjs";import{c as p,i as m}from"./openclaw-state-read-openclaw-state-db-admission-CIm9HKal.mjs";const h=`state.schema.contentVersion`;var PostgresSchemaAdmissionUnavailableError=class extends Error{};const g=o(e=>a(e,()=>i(e).selectFrom(`config_machine_state`).select(`value_json`).where(`state_key`,`=`,h)));function readStateSchemaContentVersion(n,r,i=readStateSchemaContentVersionRow,a){if(e(n)){let e=m(n);if(!e)throw new PostgresSchemaAdmissionUnavailableError(`Missing PostgreSQL state schema admission; use the matching OpenClaw version or restore the matching PostgreSQL schema and anchor.`);return Math.max(r??e.userVersion,e.contentVersion)}let o=m(n);if(o)return Math.max(r??o.userVersion,o.contentVersion);let s=a??t(n)?.userVersion??u(n),l=parseStateSchemaContentVersion(c(n,`config_machine_state`)?i(n)?.value_json:void 0);return p(n,{userVersion:s,contentVersion:l}),Math.max(r??s,l)}function readStateSchemaContentVersionRow(e){return g(e)().rows[0]}function parseStateSchemaContentVersion(e){if(e===void 0)return 0;let t;try{t=e===null?null:JSON.parse(e)}catch(e){throw new s(`Invalid shared state schema content version in ${h}.`,{cause:e})}if(typeof t!=`number`||!Number.isSafeInteger(t)||t<0)throw new s(`Invalid shared state schema content version in ${h}.`);return t}function admitStateSchemaFacts(t,i,a=`runtime`){if(e(t)){if(!r(t))throw new PostgresSchemaAdmissionUnavailableError(`Missing PostgreSQL physical schema admission`)}else try{n(t,e=>assertSupportedStateSchemaVersion(t,i,{userVersion:e,contentVersion:e},void 0,a))}catch(e){let n;try{n=u(t)}catch{throw f(e,i)}throw n>36?l(`OpenClaw state database`,i,n,36,d(t),a):f(e,i)}}function assertSupportedStateSchemaVersion(n,r,i,a,o=`runtime`){if(e(n))return readStateSchemaContentVersion(n);try{let e=i?.userVersion??m(n)?.userVersion??t(n)?.userVersion??u(n),s=i?.contentVersion??(e>36?e:readStateSchemaContentVersion(n,e,a,e));if(s>36)throw l(`OpenClaw state database`,r,s,36,d(n),o);return e}catch(e){throw f(e,r)}}export{parseStateSchemaContentVersion as a,assertSupportedStateSchemaVersion as i,PostgresSchemaAdmissionUnavailableError as n,readStateSchemaContentVersion as o,admitStateSchemaFacts as r,readStateSchemaContentVersionRow as s,h as t};