openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.96 kB
JavaScript
import"./openclaw-state-read-openclaw-state-db-contract-DiFTYPe3.mjs";import{u as e}from"./openclaw-state-read-sqlite-post-commit-CEHMNIsB.mjs";import{a as t,c as n,t as r}from"./openclaw-state-read-kysely-sync-DQyYiAw5.mjs";import{o as i,t as a,w as o}from"./openclaw-state-read-sqlite-schema-facts-DxLfPKu-.mjs";import{t as s}from"./openclaw-state-read-sqlite-schema-issues-BBUCI22a.mjs";import{o as c}from"./openclaw-state-read-openclaw-state-db-schema-helpers-BkqUYEFY.mjs";import{d as l,i as u,o as d,u as f}from"./openclaw-state-read-openclaw-state-db-schema-migration-required-D_rQ-tLc.mjs";import{i as p,l as m}from"./openclaw-state-read-openclaw-state-db-admission--7YB7DUG.mjs";const h=`state.schema.contentVersion`;var PostgresSchemaAdmissionUnavailableError=class extends Error{};function requireStatePostgresPhysicalFacts(e){let t=o(e);if(!t)throw new PostgresSchemaAdmissionUnavailableError(`Missing PostgreSQL physical schema admission`);return t}const g=r(e=>n(e,()=>t(e).selectFrom(`config_machine_state`).select(`value_json`).where(`state_key`,`=`,h)));function readStateSchemaContentVersion(t,n,r=readStateSchemaContentVersionRow,a){if(e(t)){let e=p(t);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(n??e.userVersion,e.contentVersion)}let o=p(t);if(o)return Math.max(n??o.userVersion,o.contentVersion);let s=a??i(t)?.userVersion??f(t),l=parseStateSchemaContentVersion(c(t,`config_machine_state`)?r(t)?.value_json:void 0);return m(t,{userVersion:s,contentVersion:l}),Math.max(n??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,n,r=`runtime`){if(e(t))requireStatePostgresPhysicalFacts(t);else try{a(t,e=>assertSupportedStateSchemaVersion(t,n,{userVersion:e,contentVersion:e},void 0,r))}catch(e){let i;try{i=f(t)}catch{throw u(e,n)}throw i>40?d(`OpenClaw state database`,n,i,40,l(t),r):u(e,n)}}function assertSupportedStateSchemaVersion(t,n,r,a,o=`runtime`){if(e(t))return readStateSchemaContentVersion(t);try{let e=r?.userVersion??p(t)?.userVersion??i(t)?.userVersion??f(t),s=r?.contentVersion??(e>40?e:readStateSchemaContentVersion(t,e,a,e));if(s>40)throw d(`OpenClaw state database`,n,s,40,l(t),o);return e}catch(e){throw u(e,n)}}export{parseStateSchemaContentVersion as a,requireStatePostgresPhysicalFacts as c,assertSupportedStateSchemaVersion as i,PostgresSchemaAdmissionUnavailableError as n,readStateSchemaContentVersion as o,admitStateSchemaFacts as r,readStateSchemaContentVersionRow as s,h as t};