UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 5.5 kB
import{c as e,p as t}from"./git-operation.worker-subsystem-DibpW_lB.mjs";import{createRequire as n}from"node:module";import r from"node:path";import i from"node:fs";import{execFileSync as a}from"node:child_process";function resolveEnvironmentValue(e,t,n=process.platform){if(!e)return;if(n!==`win32`)return e[t]??(t===`PATH`?e.Path:void 0);let r=t.toUpperCase(),i=Object.keys(e).toSorted().find(e=>e.toUpperCase()===r);return i===void 0?void 0:e[i]}function mergeProcessEnv(e,t=process.platform){let n=Object.create(null),r=/* @__PURE__ */ new Map;for(let i of e){if(!i)continue;let e=Object.keys(i),a=/* @__PURE__ */ new Set;for(let o of t===`win32`?e.toSorted():e){let e=t===`win32`?o.toUpperCase():void 0;if(e!==void 0){if(a.has(e))continue;a.add(e);let t=r.get(e);t!==void 0&&delete n[t],r.delete(e)}let s=i[o];s===void 0?delete n[o]:(n[o]=s,e!==void 0&&Object.hasOwn(n,o)&&r.set(e,o))}}return n}const o=/* @__PURE__ */ new Set(/* @__PURE__ */ `PATH.Path.HOME.USER.LOGNAME.TMPDIR.TMP.TEMP.LANG.LANGUAGE.TZ.LC_ALL.LC_COLLATE.LC_CTYPE.LC_MESSAGES.LC_MONETARY.LC_NUMERIC.LC_TIME.LC_ADDRESS.LC_IDENTIFICATION.LC_MEASUREMENT.LC_NAME.LC_PAPER.LC_TELEPHONE.SYSTEMROOT.WINDIR.COMSPEC.PATHEXT.SYSTEMDRIVE.USERPROFILE.HOMEDRIVE.HOMEPATH.USERNAME.USERDOMAIN.APPDATA.LOCALAPPDATA.PROGRAMDATA.ALLUSERSPROFILE.PROGRAMFILES.PROGRAMFILES(X86).PROGRAMW6432.COMMONPROGRAMFILES.COMMONPROGRAMFILES(X86).COMMONPROGRAMW6432.PSMODULEANALYSISCACHEPATH`.split(`.`));function resolveDiagnosticProcessEnv(e=process.env,t=process.platform){return Object.fromEntries(Object.entries(mergeProcessEnv([e],t)).filter(([e])=>o.has(t===`win32`?e.toUpperCase():e)))}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}=n(import.meta.url)(`@openclaw/proc-safe/windows-token`),t=e(),r=process.versions.uv,i=Number(r.split(`.`)[0]),a=Number(r.split(`.`)[1]);t!==null&&(i<1||i===1&&a<53)&&(c=new AppContainerSpawnUnsupportedError(r))}catch(e){import(`./git-operation.worker-subsystem-DibpW_lB.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 e=r.win32.join(l,`System32`,`reg.exe`);return t(e,i.constants.R_OK)?e:null}function trimTrailingSeparators(e){let t=r.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(r.win32.normalize(t));if(!r.win32.isAbsolute(n)||n.startsWith(`\\\\`))return null;let i=r.win32.parse(n);return!/^[A-Za-z]:\\$/.test(i.root)||n.length<=i.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(t,n,r){let i=locateWindowsRegExe();if(!i)return null;for(let o of[[`/reg:64`],[]]){let s=r===void 0?u:Math.min(u,Math.ceil(r-performance.now()));if(s<=0)return null;assertAppContainerSpawnSupported();try{let r=a(i,[`query`,t,`/v`,n,...o],{env:resolveDiagnosticProcessEnv(),encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`],timeout:s,windowsHide:!0}),c=RegExp(`^\\s*${e(n)}\\s+REG_[A-Z0-9_]+\\s+(.+)$`,`im`),l=r.match(c)?.[1]?.trim();if(l)return l}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(r.win32.basename(e)!==e||!/^[A-Za-z0-9_.-]+\.exe$/u.test(e))throw Error(`Invalid Windows System32 executable name: ${e}`);return r.win32.join(getWindowsSystemRoot(t),`System32`,e)}function getWindowsPowerShellExePath(e=process.env,t){return r.win32.join(getWindowsSystemRoot(e,t),`System32`,`WindowsPowerShell`,`v1.0`,`powershell.exe`)}export{mergeProcessEnv as a,assertAppContainerSpawnSupported as i,getWindowsPowerShellExePath as n,resolveDiagnosticProcessEnv as o,getWindowsSystem32ExePath as r,resolveEnvironmentValue as s,getWindowsCmdExePath as t};