openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 5.04 kB
JavaScript
import{h as e,o as t}from"./transcript-plugin-instance-invocation-7y9lfaeO.mjs";import{n}from"./transcript-string-coerce-DTk-8HSr.mjs";import{u as r}from"./transcript-service-child-group-ownership-MKIb00Qh.mjs";import{createRequire as i}from"node:module";import a from"node:path";import o from"node:fs";import{execFileSync as s}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 c=!1,l;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(!c){c=!0;try{let{readCurrentAppContainerSid:e}=i(import.meta.url)(`@openclaw/proc-safe/windows-token`),t=e(),n=process.versions.uv,r=Number(n.split(`.`)[0]),a=Number(n.split(`.`)[1]);t!==null&&(r<1||r===1&&a<53)&&(l=new AppContainerSpawnUnsupportedError(n))}catch(e){import(`./transcript-subsystem-D_W41y_d.mjs`).then(({createSubsystemLogger:t})=>{t(`process`).debug(`AppContainer token probe failed; allowing spawn`,{error:String(e)})}).catch(()=>{})}}if(l)throw l}}const u=`C:\\Windows`,d=5e3;let f=null;function locateWindowsRegExe(){let t=a.win32.join(u,`System32`,`reg.exe`);return e(t,o.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,n,i){let a=locateWindowsRegExe();if(!a)return null;for(let o of[[`/reg:64`],[]]){let c=i===void 0?d:Math.min(d,Math.ceil(i-performance.now()));if(c<=0)return null;assertAppContainerSpawnSupported();try{let i=s(a,[`query`,e,`/v`,n,...o],{env:r(),encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`],timeout:c,windowsHide:!0}),l=RegExp(`^\\s*${t(n)}\\s+REG_[A-Z0-9_]+\\s+(.+)$`,`im`),u=i.match(l)?.[1]?.trim();if(u)return u}catch{}}return null}function getRegistryProgramFilesRoots(){let readRoot=e=>normalizeWindowsInstallRoot(queryWindowsRegistryValue(`HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion`,e)??void 0)??void 0;return{programFiles:readRoot(`ProgramFilesDir`),programFilesX86:readRoot(`ProgramFilesDir (x86)`),programW6432:readRoot(`ProgramW6432Dir`)}}function buildWindowsInstallRoots(e,t={}){let n=normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`ProgramW6432`)),r=t.programW6432??n??null;return{systemRoot:t.systemRoot??resolveSystemRootFromEnv(e),programFiles:t.programFiles??normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`ProgramFiles`))??r??`C:\\Program Files`,programFilesX86:t.programFilesX86??normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`ProgramFiles(x86)`))??`C:\\Program Files (x86)`,programW6432:r}}function resolveSystemRootFromEnv(e){return normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`SystemRoot`))??normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`WINDIR`))??u}function getProcessRoots(e){if(!f){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;f=n}return f}function getWindowsSystemRoot(e,t){if(e!==process.env)return resolveSystemRootFromEnv(e);let n=getProcessRoots(t);return n.installRoots?.systemRoot??n.systemRoot}function getWindowsInstallRoots(e=process.env){if(e===process.env){let e=getProcessRoots();return e.installRoots??=buildWindowsInstallRoots(e.env,{...getRegistryProgramFilesRoots(),systemRoot:e.systemRoot}),e.installRoots}return buildWindowsInstallRoots(e)}function getWindowsProgramFilesRoots(e=process.env){let t=getWindowsInstallRoots(e),r=/* @__PURE__ */ new Set,i=[];for(let e of[t.programW6432,t.programFiles,t.programFilesX86]){if(!e)continue;let t=n(e);r.has(t)||(r.add(t),i.push(e))}return i}function getWindowsPowerShellExePath(e=process.env,t){return a.win32.join(getWindowsSystemRoot(e,t),`System32`,`WindowsPowerShell`,`v1.0`,`powershell.exe`)}export{getWindowsPowerShellExePath as n,getWindowsProgramFilesRoots as r,getWindowsInstallRoots as t};