UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 4.04 kB
import{Dt as e,y as t}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{n}from"./openclaw-state-read-process-env-DgVwfN3Y.mjs";import{createRequire as r}from"node:module";import i from"node:fs";import a from"node:path";import{execFileSync as o}from"node:child_process";var AppContainerSpawnUnsupportedError=class extends Error{constructor(e){super(`AppContainer: libuv ${e} cannot create child pipes; 1.53.0+ required. Run OpenClaw outside the AppContainer or use a Node build with libuv >= 1.53.0.`),this.code=`APPCONTAINER_SPAWN_UNSUPPORTED`,this.name=`AppContainerSpawnUnsupportedError`}};let s=!1,c;function assertAppContainerSpawnSupported(e){if(process.platform===`win32`&&!(e===`ignore`||e===`inherit`||Array.isArray(e)&&e.length>=3&&e.every(e=>e!=null&&e!==`pipe`&&e!==`overlapped`&&e!==`ipc`&&!(typeof e==`number`&&e<0)))){if(!s){s=!0;try{let{readCurrentAppContainerSid:e}=r(import.meta.url)(`@openclaw/proc-safe/windows-token`),t=e(),n=process.versions.uv,i=Number(n.split(`.`)[0]),a=Number(n.split(`.`)[1]);t!==null&&(i<1||i===1&&a<53)&&(c=new AppContainerSpawnUnsupportedError(n))}catch(e){import(`./openclaw-state-read-subsystem-Dwoo5bcz.mjs`).then(e=>e.n).then(({createSubsystemLogger:t})=>{t(`process`).debug(`AppContainer token probe failed; allowing spawn`,{error:String(e)})}).catch(()=>{})}}if(c)throw c}}const l=`C:\\Windows`,u=5e3;let d=null;function locateWindowsRegExe(){let t=a.win32.join(l,`System32`,`reg.exe`);return e(t,i.constants.R_OK)?t:null}function trimTrailingSeparators(e){let t=a.win32.parse(e),n=e;for(;n.length>t.root.length&&/[\\/]/.test(n.at(-1)??``);)n=n.slice(0,-1);return n}function normalizeWindowsInstallRoot(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t||t.includes(`\0`)||t.includes(`\r`)||t.includes(` `)||t.includes(`;`))return null;let n=trimTrailingSeparators(a.win32.normalize(t));if(!a.win32.isAbsolute(n)||n.startsWith(`\\\\`))return null;let r=a.win32.parse(n);return!/^[A-Za-z]:\\$/.test(r.root)||n.length<=r.root.length?null:n}function getEnvValueCaseInsensitive(e,t){let n=e[t];if(n!==void 0)return n;let r=t.toUpperCase(),i=Object.keys(e).find(e=>e.toUpperCase()===r);return i?e[i]:void 0}function queryWindowsRegistryValue(e,r,i){let a=locateWindowsRegExe();if(!a)return null;for(let s of[[`/reg:64`],[]]){let c=i===void 0?u:Math.min(u,Math.ceil(i-performance.now()));if(c<=0)return null;assertAppContainerSpawnSupported();try{let i=o(a,[`query`,e,`/v`,r,...s],{env:n(),encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`],timeout:c,windowsHide:!0}),l=RegExp(`^\\s*${t(r)}\\s+REG_[A-Z0-9_]+\\s+(.+)$`,`im`),u=i.match(l)?.[1]?.trim();if(u)return u}catch{}}return null}function resolveSystemRootFromEnv(e){return normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`SystemRoot`))??normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`WINDIR`))??l}function getProcessRoots(e){if(!d){let t={};for(let e of[`SystemRoot`,`WINDIR`,`ProgramFiles`,`ProgramFiles(x86)`,`ProgramW6432`])t[e]=getEnvValueCaseInsensitive(process.env,e);let n={env:t,systemRoot:normalizeWindowsInstallRoot(queryWindowsRegistryValue(`HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion`,`SystemRoot`,e)??void 0)??resolveSystemRootFromEnv(t)};if(e!==void 0&&performance.now()>=e)return n;d=n}return d}function getWindowsSystemRoot(e,t){if(e!==process.env)return resolveSystemRootFromEnv(e);let n=getProcessRoots(t);return n.installRoots?.systemRoot??n.systemRoot}function getWindowsCmdExePath(e=process.env){return getWindowsSystem32ExePath(`cmd.exe`,e)}function getWindowsSystem32ExePath(e,t=process.env){if(a.win32.basename(e)!==e||!/^[A-Za-z0-9_.-]+\.exe$/u.test(e))throw Error(`Invalid Windows System32 executable name: ${e}`);return a.win32.join(getWindowsSystemRoot(t),`System32`,e)}function getWindowsPowerShellExePath(e=process.env,t){return a.win32.join(getWindowsSystemRoot(e,t),`System32`,`WindowsPowerShell`,`v1.0`,`powershell.exe`)}export{assertAppContainerSpawnSupported as i,getWindowsPowerShellExePath as n,getWindowsSystem32ExePath as r,getWindowsCmdExePath as t};