openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
8 lines • 5.36 kB
JavaScript
import{o as OPENCLAW_DATABASE_SCHEMA_DOCS_URL}from"./openclaw-state-db-contract-lz-66XzZ.mjs";import{r as resolveRuntimeServiceCommit,t as VERSION}from"./version-D4mobxtZ.mjs";import{t as resolveOpenClawPackageRootSync}from"./openclaw-root-BKCLHFAM.mjs";import{o as executeWithCachedStatement}from"./kysely-sync-cache-state-CObqh5XE.mjs";
//!scripts/lib/release-version.mjs
const RELEASE_VERSION_REGEX=/^(?<year>\d{4})\.(?<month>[1-9]\d?)\.(?<patch>[1-9]\d*)(?:-(?:(?<channel>alpha|beta)\.(?<prerelease>[1-9]\d*)|(?<correction>[1-9]\d*)))?$/;function parseReleaseVersion(e){const t=e.trim();const n=RELEASE_VERSION_REGEX.exec(t)?.groups;if(!n)return null;const r=Number(n.year);const i=Number(n.month);const a=Number(n.patch);const o=n.prerelease===void 0?void 0:Number(n.prerelease);const s=n.correction===void 0?void 0:Number(n.correction);if(!Number.isSafeInteger(r)||!Number.isSafeInteger(i)||!Number.isSafeInteger(a)||i<1||i>12||a<1||o!==void 0&&!Number.isSafeInteger(o)||s!==void 0&&!Number.isSafeInteger(s))return null;const c=n.channel===`alpha`?`alpha`:n.channel===`beta`?`beta`:`stable`;return{version:t,baseVersion:`${r}.${i}.${a}`,channel:c,year:r,month:i,patch:a,alphaNumber:c===`alpha`?o:void 0,betaNumber:c===`beta`?o:void 0,...s===void 0?{}:{correctionNumber:s}}}function compareReleaseVersions(e,t){const n=parseReleaseVersion(e);const r=parseReleaseVersion(t);if(n===null||r===null)return null;if(n.year!==r.year)return Math.sign(n.year-r.year);if(n.month!==r.month)return Math.sign(n.month-r.month);if(n.patch!==r.patch)return Math.sign(n.patch-r.patch);if(n.channel!==r.channel){const e={alpha:0,beta:1,stable:2};return Math.sign(e[n.channel]-e[r.channel])}if(n.channel===`alpha`&&r.channel===`alpha`)return Math.sign((n.alphaNumber??0)-(r.alphaNumber??0));if(n.channel===`beta`&&r.channel===`beta`)return Math.sign((n.betaNumber??0)-(r.betaNumber??0));return Math.sign((n.correctionNumber??0)-(r.correctionNumber??0))}
//!src/infra/startup-maintenance-required.ts
const GATEWAY_STARTUP_MAINTENANCE_REQUIRED_REASON=`gateway.maintenance_required`;const maintenanceReasons={"state-migrations":`state migration`,"newer-schema":`a newer OpenClaw build`,"agent-media":`offline media migration`,"audit-events-v2":`state database schema migration`,"legacy-workshop-review-index":`state database schema migration`,"legacy-cron-run-logs":`cron run history migration`,"legacy-workspace":`workspace setup state migration`,"legacy-session-store":`session store migration`};var StartupMaintenanceRequiredError=class extends Error{constructor(e,t,n){super(t,n);this.kind=e;this.code=GATEWAY_STARTUP_MAINTENANCE_REQUIRED_REASON;this.name=`StartupMaintenanceRequiredError`}get reason(){return maintenanceReasons[this.kind]}};
//!src/infra/sqlite-user-version.ts
const SQLITE_SCHEMA_VERSION_ERROR_NAME=`SqliteSchemaVersionError`;var SqliteSchemaVersionError=class extends StartupMaintenanceRequiredError{constructor(e){super(`newer-schema`,e);this.name=SQLITE_SCHEMA_VERSION_ERROR_NAME}};function isSqliteSchemaVersionError(e){return e instanceof SqliteSchemaVersionError||e instanceof Error&&e.name===SQLITE_SCHEMA_VERSION_ERROR_NAME}function readSqliteUserVersion(e){const t=executeWithCachedStatement(e,`PRAGMA user_version`,[],e=>e.get());return Number(t?.user_version??0)}function readSqliteWriterAppVersion(e){try{const t=executeWithCachedStatement(e,`SELECT app_version FROM schema_meta WHERE meta_key = 'primary' LIMIT 1`,[],e=>e.get());return typeof t?.app_version===`string`&&t.app_version.length>0?t.app_version:void 0}catch{return}}function writeSqliteUserVersion(e,t){if(!Number.isInteger(t)||t<0||t>2147483647)throw new RangeError(`SQLite user_version must be an integer from 0 through 2147483647.`);e.exec(`PRAGMA user_version = ${t}`)}function describeRunningOpenClawBuild(){const e=resolveRuntimeServiceCommit();const t=resolveOpenClawPackageRootSync({moduleUrl:import.meta.url});const n=e?`OpenClaw ${VERSION} (${e})`:`OpenClaw ${VERSION}`;return t?`${n} installed at ${t}`:n}function isNewerSqliteWriterVersion(e){return(compareReleaseVersions(e??``,VERSION)??0)>0}function createNewerSqliteSchemaVersionError(e,t,n,r,i,a=`runtime`){const o=isNewerSqliteWriterVersion(i);const s=o?`; it is newer than this Gateway (${VERSION}).`:a===`runtime`?`; run openclaw doctor --fix to inspect this database.`:`.`;return new SqliteSchemaVersionError(`This OpenClaw build cannot open your existing data.
${e} ${t} uses newer schema version ${n}; this build supports ${r}.\n`+(i&&(a===`runtime`||i!==VERSION)?`It was written by OpenClaw ${i}${s}\n`:``)+`Refused by ${describeRunningOpenClawBuild()}.\n`+(o?`Use the newer install that supports schema ${n} or newer, or run openclaw update to update this Gateway service before restarting. To use an older build, restore your pre-update backup created with openclaw backup create.\n`:`Use a build that supports schema ${n} or newer with this state directory. To use an older build, restore your pre-update backup created with openclaw backup create.\n`)+`See ${OPENCLAW_DATABASE_SCHEMA_DOCS_URL}.`)}export{isSqliteSchemaVersionError as a,writeSqliteUserVersion as c,isNewerSqliteWriterVersion as i,StartupMaintenanceRequiredError as l,createNewerSqliteSchemaVersionError as n,readSqliteUserVersion as o,describeRunningOpenClawBuild as r,readSqliteWriterAppVersion as s,SqliteSchemaVersionError as t};