UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 14.5 kB
import{H as e,Lt as t,Pt as n,R as r,Rt as i,nt as a}from"./sqlite-readonly-subsystem-C-VJT-xk.mjs";import{Y as o}from"./sqlite-readonly-runtime-process-manifest-CLhsN5hb.mjs";import{_n as s}from"./sqlite-readonly-node-sqlite-u3RAlsBE.mjs";import{t as c}from"./sqlite-readonly-openclaw-root-PLr-9gty.mjs";import"./sqlite-readonly-errors-bSzGfuz-.mjs";import{createRequire as l}from"node:module";import u from"node:path";import d from"node:fs";import{fileURLToPath as f}from"node:url";import{isUtf8 as p}from"node:buffer";function validateWindow(e,t){if(!Number.isSafeInteger(t)||t<0||!Number.isSafeInteger(t+e.length))throw RangeError(`read position and window end must be non-negative safe integers`)}function readFileWindowFullySync(e,t,n){validateWindow(t,n);let r=0;for(;r<t.length;){let i=d.readSync(e,t,r,Math.min(t.length-r,2147483647),n+r);if(i===0)break;r+=i}return r}const m=[`agent_deletion_journal`],h=/* @__PURE__ */ `sandbox_persistent_execs.user_profile_identities.user_background_images.local_workspace_projections.local_workspace_manifest_nodes.local_workspace_tree_packs.local_workspace_source_path_sets.update_runs.session_repository_workspaces.github_repository_publication_requests.github_publication_session_lifecycles.skill_library_entries.skill_library_revisions.skill_library_events.skill_library_uploads.github_personal_publication_requests.cron_job_runtime_authorities.cron_run_trigger_state_retirements.execution_identity_contexts.mcp_oauth_pending_authorizations.node_worker_launch_containers.node_worker_launch_boots.node_worker_launch_cleanup.node_worker_launch_process_scopes.node_worker_launches.node_worker_prepared_workspaces.node_worker_turns.operator_approval_execution_identities.operator_approval_standing_grants.operator_approval_standing_grant_generations.web_push_approval_deliveries.execution_decision_facts.execution_owner_lifecycle_bindings.outbound_message_execution_bindings.outbound_message_progress`.split(`.`),g=[`idx_sandbox_persistent_execs_container`,`idx_sandbox_persistent_execs_container_name`,`idx_sandbox_persistent_execs_source`,`idx_user_profile_identities_profile_id`,`idx_user_profile_identities_authorization`,`idx_update_runs_created`,`idx_update_runs_active`,`idx_github_repository_publication_shared_request`,`idx_github_repository_publication_personal_request`,`idx_github_personal_publication_owner_session`,`idx_github_personal_publication_pending`,`idx_node_worker_launches_terminal_completed`,`idx_node_worker_turns_terminal_completed`,`idx_node_worker_turns_active_owner`,`idx_operator_approval_standing_grants_binding`,`idx_web_push_approval_deliveries_subscription`,`execution_identity_contexts_run_created_idx`,`execution_decision_facts_cursor_id_idx`,`execution_decision_facts_context_occurred_idx`,`execution_decision_facts_run_occurred_idx`,`outbound_message_execution_bindings_execution_event_idx`,`outbound_message_progress_occurred_idx`,`outbound_message_progress_run_occurred_idx`],_=[...h,`agent_provenance`,`cron_run_receipts`,`config_revision_keys`,`secret_store_entries`,`projects`,`worktree_templates`,`user_preferences`,`device_pair_setup_completions`,`github_publication_requests`,`device_pairing_join_codes`,`skill_workshop_changes`,`worker_environment_ssh_fallback_ports`,`worker_session_placement_moves`],v=[...g,`cron_run_receipts_cursor_id_idx`,`idx_cron_run_receipts_active_job`,`idx_cron_run_receipts_job_history`,`idx_github_publication_requests_pending`,`secret_store_entries_live_idx`,`skill_workshop_changes_cursor_id_idx`,`idx_skill_workshop_changes_agent_time`],y=5e3,b=`https://docs.openclaw.ai/reference/database-schemas`,x=/^(?<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=x.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=u.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=u.dirname(r);if(t===r)break;r=t}return null}function readGitMetadataFile(e,t=1048576){let n=d.openSync(e,d.constants.O_RDONLY|(d.constants.O_NONBLOCK??0));try{let e=d.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{d.closeSync(n)}}function readGitDirectoryPointerTarget(e,t=``){let n=readGitMetadataFile(e),r=n.toString(`utf8`).replace(/[\r\n]+$/u,``);if(!p(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 u.isAbsolute(i)?i:`${u.dirname(e)}${u.sep}${i}`}function readGitDirectoryPointer(e,t=``){return d.realpathSync.native(readGitDirectoryPointerTarget(e,t))}function resolveGitDirFromMarker(e){let t=u.join(e,`.git`);try{let e=d.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?u.join(t,`HEAD`):null})}function readGitMetadataPrefix(e,t=256){let n=d.openSync(e,d.constants.O_RDONLY|(d.constants.O_NONBLOCK??0));try{if(!d.fstatSync(n).isFile())throw Error(`Git metadata is not a regular file`);let e=Buffer.alloc(t),r=readFileWindowFullySync(n,e,0);return e.subarray(0,r).toString(`utf-8`)}finally{d.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 t=u.dirname(e),n=u.join(t,`commondir`);try{return readGitDirectoryPointer(n)}catch(e){if(!a(e)||d.lstatSync(n,{throwIfNoEntry:!1}))throw e}return t}function readGitRefs(e,t){let n=new Map(t.map(e=>[e,null])),i=/* @__PURE__ */ new Set;for(let r of t){let t=resolveRefPath(e,r);if(t)try{n.set(r,readGitMetadataPrefix(t).trim())}catch(e){if(!a(e))throw e;i.add(r)}}if(i.size===0)return n;try{let t=readGitMetadataFile(u.join(e,`packed-refs`),2**53-1).toString(`utf8`),a=RegExp(`^(?![#^])[^\\S\\r\\n]*(\\S+)[^\\S\\r\\n]+(${[...i].map(r).join(`|`)})(?=\\s|$)`,`gm`);for(let[,e,r]of t.matchAll(a))i.delete(r)&&n.set(r,e)}catch(e){if(!a(e))throw e}return n}function resolveRefPath(e,t){if(!t.startsWith(`refs/`)||t.split(/[/]/).includes(`..`))return null;let n=u.resolve(e,t),r=u.relative(e,n);return!r||r.startsWith(`..`)||u.isAbsolute(r)?null:n}const formatCommit=e=>{let t=e?.match(/[0-9a-fA-F]{7,40}/);return t?n(t[0].slice(0,7)):null},S=new e(256),resolveCommitSearchDir=e=>{if(e.cwd)return u.resolve(e.cwd);if(e.moduleUrl)try{return u.dirname(f(e.moduleUrl))}catch{}return process.cwd()},cacheGitCommit=(e,t)=>(S.set(e,t),t),resolveGitLookupDepth=(e,t)=>{if(!t)return;let n=u.relative(t,e);if(!(n.startsWith(`..`)||u.isAbsolute(n)))return(n?n.split(u.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=l(import.meta.url)(`../../package.json`);return formatCommit(e.gitHead??e.githead??null)}catch{return null}},readCommitProbe=(e,t,n)=>{try{for(let r of t){let t=f(new URL(r,e)),o;try{o=readGitMetadataPrefix(t,1024)}catch(e){if(a(e))continue;return null}try{let e=i(JSON.parse(o))?.[n];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=S.get(i);if(a!==void 0)return a;let o=c({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 l=readCommitFromPackageJson();return l?cacheGitCommit(i,l):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 C=[`../package.json`,`../../package.json`,`../../../package.json`,`./package.json`],w=[`../build-info.json`,`../../build-info.json`,`./build-info.json`];function readStringFromJsonCandidates(e,n,r,i=!1){try{let a=l(e);for(let e of n)try{let n=a(e),o=t(n[r]);if(!o||i&&n.name!==`openclaw`)continue;return o}catch{}return null}catch{return null}}function firstNonEmpty(...e){for(let n of e){let e=t(n);if(e&&e.toLowerCase()!==`undefined`&&e.toLowerCase()!==`null`)return e}}function readVersionFromPackageJsonForModuleUrl(e){return readStringFromJsonCandidates(e,C,`version`,!0)}function readVersionFromBuildInfoForModuleUrl(e){return readStringFromJsonCandidates(e,w,`version`)}function readBuildProvenanceForModuleUrl(e){try{let n=l(e);for(let e of w)try{let r=n(e),i=t(r.buildId);if(i&&i.length<=96){let a={buildId:i};for(let e of[`version`,`commit`,`builtAt`]){let n=t(r[e]);n&&(a[e]=n)}try{a.buildInfoPath=n.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 T=resolveLoadedCommitHash({moduleUrl:import.meta.url});function resolveRuntimeServiceCommit(){return T}const E=resolveBinaryVersion({moduleUrl:import.meta.url,bundledVersion:process.env.OPENCLAW_BUNDLED_VERSION}),D={"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.maintenance_required`,this.name=`StartupMaintenanceRequiredError`}get reason(){return D[this.kind]}};const O=`SqliteSchemaVersionError`;var SqliteSchemaVersionError=class extends StartupMaintenanceRequiredError{constructor(e){super(`newer-schema`,e),this.name=O}};function isSqliteSchemaVersionError(e){return e instanceof SqliteSchemaVersionError||e instanceof Error&&e.name===O}function readSqliteUserVersion(e){let t=s(e,`PRAGMA user_version`,[],e=>e.get());return Number(t?.user_version??0)}function readSqliteWriterAppVersion(e){try{let t=s(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=c({moduleUrl:import.meta.url}),n=e?`OpenClaw ${E} (${e})`:`OpenClaw ${E}`;return t?`${n} installed at ${t}`:n}function isNewerSqliteWriterVersion(e){return(compareReleaseVersions(e??``,E)??0)>0}function createNewerSqliteSchemaVersionError(e,t,n,r,i,a=`runtime`){let o=isNewerSqliteWriterVersion(i),s=o?`; it is newer than this Gateway (${E}).`: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!==E)?`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 ${b}.`)}export{y as _,isSqliteSchemaVersionError as a,writeSqliteUserVersion as c,m as d,g as f,b as g,_ as h,isNewerSqliteWriterVersion as i,StartupMaintenanceRequiredError as l,v as m,createNewerSqliteSchemaVersionError as n,readSqliteUserVersion as o,h as p,describeRunningOpenClawBuild as r,readSqliteWriterAppVersion as s,SqliteSchemaVersionError as t,E as u,readFileWindowFullySync as v};