openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 10.8 kB
JavaScript
import{Bt as e,Pt as t,_t as n,gn as r,pn as i,y as a}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{q as o}from"./openclaw-state-read-src-RL5xtYG2.mjs";import{n as s}from"./openclaw-state-read-positional-read-zdUE4ydg.mjs";import{o as c}from"./openclaw-state-read-openclaw-state-db-contract-vqwNsqc6.mjs";import{o as l}from"./openclaw-state-read-kysely-sync-cache-state-C7JSbWq6.mjs";import"./openclaw-state-read-errors-D4PLrhBz.mjs";import{n as u}from"./openclaw-state-read-openclaw-root-CbFTRFFl.mjs";import{n as d}from"./openclaw-state-read-startup-maintenance-required-DR0e3-Lc.mjs";import{createRequire as f}from"node:module";import p from"node:fs";import m from"node:path";import{fileURLToPath as h}from"node:url";import{isUtf8 as g}from"node:buffer";const _=/^(?<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){let t=e.trim(),n=_.exec(t)?.groups;if(!n)return null;let r=Number(n.year),i=Number(n.month),a=Number(n.patch),o=n.prerelease===void 0?void 0:Number(n.prerelease),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;let 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){let n=parseReleaseVersion(e),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){let e={alpha:0,beta:1,stable:2};return Math.sign(e[n.channel]-e[r.channel])}return n.channel===`alpha`&&r.channel===`alpha`?Math.sign((n.alphaNumber??0)-(r.alphaNumber??0)):n.channel===`beta`&&r.channel===`beta`?Math.sign((n.betaNumber??0)-(r.betaNumber??0)):Math.sign((n.correctionNumber??0)-(r.correctionNumber??0))}function walkUpFrom(e,t,n){let r=m.resolve(e);for(let e=0;t.maxDepth===void 0||e<t.maxDepth;e+=1){let e=n(r);if(e!=null)return e;let t=m.dirname(r);if(t===r)break;r=t}return null}function readGitMetadataFile(e,t=1048576){let n=p.openSync(e,p.constants.O_RDONLY|(p.constants.O_NONBLOCK??0));try{let e=p.fstatSync(n);if(!e.isFile()||e.size>t)throw Error(`Git metadata is not a bounded regular file`);let r=o(n,Math.min(e.size,t));if(r.length!==e.size)throw Error(`Git metadata changed during its read`);return r}finally{p.closeSync(n)}}function readGitDirectoryPointerTarget(e,t=``){let n=readGitMetadataFile(e),r=n.toString(`utf8`).replace(/[\r\n]+$/u,``);if(!g(n)||!r.startsWith(t)||r.length===t.length||r.includes(`\0`))throw Error(`Git directory pointer is incomplete or malformed`);let i=r.slice(t.length);return m.isAbsolute(i)?i:`${m.dirname(e)}${m.sep}${i}`}function readGitDirectoryPointer(e,t=``){return p.realpathSync.native(readGitDirectoryPointerTarget(e,t))}function resolveGitDirFromMarker(e){let t=m.join(e,`.git`);try{let e=p.statSync(t);return e.isDirectory()?t:e.isFile()?readGitDirectoryPointer(t,`gitdir: `):null}catch{return null}}function resolveGitHeadPath(e,t={}){return walkUpFrom(e,t,e=>{let t=resolveGitDirFromMarker(e);return t?m.join(t,`HEAD`):null})}function readGitMetadataPrefix(e,t=256){let n=p.openSync(e,p.constants.O_RDONLY|(p.constants.O_NONBLOCK??0));try{if(!p.fstatSync(n).isFile())throw Error(`Git metadata is not a regular file`);let e=Buffer.alloc(t),r=s(n,e,0);return e.subarray(0,r).toString(`utf-8`)}finally{p.closeSync(n)}}function readGitHead(e,t={}){let n=resolveGitHeadPath(e,t);if(!n)return;let r=readGitMetadataFile(n).toString(`utf8`).trim();if(!r.startsWith(`ref:`))return{headPath:n,ref:null,value:r||null};let i=r.replace(/^ref:\s*/i,``).trim(),a=resolveGitRefsBase(n);return{headPath:n,ref:i,value:readGitRefs(a,[i]).get(i)??null,refsBase:a}}function resolveGitRefsBase(e){let n=m.dirname(e),r=m.join(n,`commondir`);try{return readGitDirectoryPointer(r)}catch(e){if(!t(e)||p.lstatSync(r,{throwIfNoEntry:!1}))throw e}return n}function readGitRefs(e,n){let r=new Map(n.map(e=>[e,null])),i=/* @__PURE__ */ new Set;for(let a of n){let n=resolveRefPath(e,a);if(n)try{r.set(a,readGitMetadataPrefix(n).trim())}catch(e){if(!t(e))throw e;i.add(a)}}if(i.size===0)return r;try{let t=readGitMetadataFile(m.join(e,`packed-refs`),2**53-1).toString(`utf8`),n=RegExp(`^(?![#^])[^\\S\\r\\n]*(\\S+)[^\\S\\r\\n]+(${[...i].map(a).join(`|`)})(?=\\s|$)`,`gm`);for(let[,e,a]of t.matchAll(n))i.delete(a)&&r.set(a,e)}catch(e){if(!t(e))throw e}return r}function resolveRefPath(e,t){if(!t.startsWith(`refs/`)||t.split(/[/]/).includes(`..`))return null;let n=m.resolve(e,t),r=m.relative(e,n);return!r||r.startsWith(`..`)||m.isAbsolute(r)?null:n}const formatCommit=e=>{let t=e?.match(/[0-9a-fA-F]{7,40}/);return t?i(t[0].slice(0,7)):null},v=new e(256),resolveCommitSearchDir=e=>{if(e.cwd)return m.resolve(e.cwd);if(e.moduleUrl)try{return m.dirname(h(e.moduleUrl))}catch{}return process.cwd()},cacheGitCommit=(e,t)=>(v.set(e,t),t),resolveGitLookupDepth=(e,t)=>{if(!t)return;let n=m.relative(t,e);if(!(n.startsWith(`..`)||m.isAbsolute(n)))return(n?n.split(m.sep).filter(Boolean).length:0)+1},readCommitFromGit=(e,t)=>{let n=readGitHead(e,{maxDepth:resolveGitLookupDepth(e,t)});return n===void 0?void 0:formatCommit(n.value)},readCommitFromPackageJson=()=>{try{let e=f(import.meta.url)(`../../package.json`);return formatCommit(e.gitHead??e.githead??null)}catch{return null}},readCommitProbe=(e,r,i)=>{try{for(let a of r){let r=h(new URL(a,e)),o;try{o=readGitMetadataPrefix(r,1024)}catch(e){if(t(e))continue;return null}try{let e=n(JSON.parse(o))?.[i];return typeof e==`string`?formatCommit(e):null}catch{return null}}}catch{}},readCommitFromBuildInfo=(e=import.meta.url)=>readCommitProbe(e,[`../build-info.json`,`./build-info.json`],`commit`)??null,readLoadedCommit=e=>{let t=readCommitProbe(e,[`../.buildstamp`,`./.buildstamp`],`head`),n=readCommitProbe(e,[`../.runtime-postbuildstamp`,`./.runtime-postbuildstamp`],`head`);return t!==void 0||n!==void 0?t||n?t&&t===n?t:null:readCommitFromBuildInfo(e):readCommitProbe(e,[`../build-info.json`,`./build-info.json`],`commit`)},resolveCommitHash=(e={})=>{let t=e.env??process.env,n=t.GIT_COMMIT?.trim()||t.GIT_SHA?.trim(),r=formatCommit(n);if(r)return r;let i=resolveCommitSearchDir(e),a=v.get(i);if(a!==void 0)return a;let o=u({cwd:e.cwd,moduleUrl:e.moduleUrl});try{let e=readCommitFromGit(i,o);if(e!==void 0)return cacheGitCommit(i,e)}catch{}let s=readCommitFromBuildInfo();if(s)return cacheGitCommit(i,s);let c=readCommitFromPackageJson();return c?cacheGitCommit(i,c):cacheGitCommit(i,null)};function resolveLoadedCommitHash(e={}){let t=e.moduleUrl??import.meta.url,n=readLoadedCommit(t);return n===void 0?resolveCommitHash({moduleUrl:t,...e.env?{env:e.env}:{}}):n}const y=[`../package.json`,`../../package.json`,`../../../package.json`,`./package.json`],b=[`../build-info.json`,`../../build-info.json`,`./build-info.json`];function readStringFromJsonCandidates(e,t,n,i=!1){try{let a=f(e);for(let e of t)try{let t=a(e),o=r(t[n]);if(!o||i&&t.name!==`openclaw`)continue;return o}catch{}return null}catch{return null}}function firstNonEmpty(...e){for(let t of e){let e=r(t);if(e&&e.toLowerCase()!==`undefined`&&e.toLowerCase()!==`null`)return e}}function readVersionFromPackageJsonForModuleUrl(e){return readStringFromJsonCandidates(e,y,`version`,!0)}function readVersionFromBuildInfoForModuleUrl(e){return readStringFromJsonCandidates(e,b,`version`)}function readBuildProvenanceForModuleUrl(e){try{let t=f(e);for(let e of b)try{let n=t(e),i=r(n.buildId);if(i&&i.length<=96){let a={buildId:i};for(let e of[`version`,`commit`,`builtAt`]){let t=r(n[e]);t&&(a[e]=t)}try{a.buildInfoPath=t.resolve(e)}catch{}return a}}catch{}}catch{}return null}function resolveVersionFromModuleUrl(e){return readVersionFromBuildInfoForModuleUrl(e)||readVersionFromPackageJsonForModuleUrl(e)}function resolveBinaryVersion(e){return resolveVersionFromModuleUrl(e.moduleUrl)||firstNonEmpty(e.bundledVersion)||`0.0.0`}readBuildProvenanceForModuleUrl(import.meta.url);const x=resolveLoadedCommitHash({moduleUrl:import.meta.url});function resolveRuntimeServiceCommit(){return x}const S=resolveBinaryVersion({moduleUrl:import.meta.url,bundledVersion:process.env.OPENCLAW_BUNDLED_VERSION}),C=`SqliteSchemaVersionError`;var SqliteSchemaVersionError=class extends d{constructor(e){super(`newer-schema`,e),this.name=C}};function isSqliteSchemaVersionError(e){return e instanceof SqliteSchemaVersionError||e instanceof Error&&e.name===C}function readSqliteUserVersion(e){let t=l(e,`PRAGMA user_version`,[],e=>e.get());return Number(t?.user_version??0)}function readSqliteWriterAppVersion(e){try{let t=l(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 RangeError(`SQLite user_version must be an integer from 0 through 2147483647.`);e.exec(`PRAGMA user_version = ${t}`)}function describeRunningOpenClawBuild(){let e=resolveRuntimeServiceCommit(),t=u({moduleUrl:import.meta.url}),n=e?`OpenClaw ${S} (${e})`:`OpenClaw ${S}`;return t?`${n} installed at ${t}`:n}function isNewerSqliteWriterVersion(e){return(compareReleaseVersions(e??``,S)??0)>0}function createNewerSqliteSchemaVersionError(e,t,n,r,i,a=`runtime`){let o=isNewerSqliteWriterVersion(i),s=o?`; it is newer than this Gateway (${S}).`: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!==S)?`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 ${c}.`)}export{isSqliteSchemaVersionError as a,writeSqliteUserVersion as c,isNewerSqliteWriterVersion as i,S as l,createNewerSqliteSchemaVersionError as n,readSqliteUserVersion as o,describeRunningOpenClawBuild as r,readSqliteWriterAppVersion as s,SqliteSchemaVersionError as t};