UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 8.75 kB
import{t as e}from"./fs-safe-copy.worker-path-existence-DvAA8vT7.mjs";import{m as t}from"./fs-safe-copy.worker-number-coercion-1FVMw2ic.mjs";import{n}from"./fs-safe-copy.worker-regexp-ixTN3SDS.mjs";import{t as r}from"./fs-safe-copy.worker-home-dir-CeEbrKea.mjs";import"./fs-safe-copy.worker-cli-invocation-fIA_-Tg7.mjs";import"./fs-safe-copy.worker-runtime-process-manifest-BlrvoYG_.mjs";import{t as i}from"./fs-safe-copy.worker-runtime-process-bootstrap.generated-BKfT41K0.mjs";import{r as a}from"./fs-safe-copy.worker-process-env-DgVwfN3Y.mjs";import{i as o,n as s,t as c}from"./fs-safe-copy.worker-windows-install-roots-BA2Oy9MH.mjs";import"node:module";import l from"node:fs";import"node:fs/promises";import u from"node:path";import{safeStatSync as d}from"@openclaw/fs-safe/path";import{fileURLToPath as f}from"node:url";import p from"node:process";const m=[`/usr/bin`,`/bin`,`/usr/sbin`,`/sbin`],h=[`/opt/homebrew/bin`,`/usr/local/bin`],g=[`/usr/local/bin`],_=[`.exe`,`.cmd`,`.bat`,`.com`],v=[`ImageMagick-`,`GraphicsMagick-`],y=[`ImageMagick`,`GraphicsMagick`],b=/* @__PURE__ */ new Map,x=/* @__PURE__ */ new Map;function cacheResolvedSystemBin(e,t,r){e.set(t,r),n(e,512)}function collectWindowsProgramFilesToolDirs(e){let t=y.map(t=>u.win32.join(e,t));try{for(let n of l.readdirSync(e,{withFileTypes:!0}))n.isDirectory()&&v.some(e=>n.name.startsWith(e))&&t.push(u.win32.join(e,n.name))}catch{}return t}function buildWindowsTrustedDirs(){let e=[],{systemRoot:t}=s();e.push(u.win32.join(t,`System32`)),e.push(u.win32.join(t,`SysWOW64`)),e.push(u.win32.join(t,`System32`,`WindowsPowerShell`,`v1.0`));for(let t of o())e.push(u.win32.join(t,`OpenSSL-Win64`,`bin`)),e.push(u.win32.join(t,`OpenSSL`,`bin`)),e.push(u.win32.join(t,`ffmpeg`,`bin`));return e}function buildWindowsStandardDirs(){let{systemRoot:e}=s(),t=u.win32.parse(e).root,n=[u.win32.join(t,`ProgramData`,`chocolatey`,`bin`)];for(let e of o())n.push(...collectWindowsProgramFilesToolDirs(e));return n}function buildUnixTrustedDirs(e){let t=[...m],n=process.platform;return n===`linux`&&(t.push(`/run/current-system/sw/bin`),t.push(`/snap/bin`)),e===`standard`&&(n===`darwin`?t.push(...h):n===`linux`&&t.push(...g)),t}const S={};function getTrustedDirs(e){return S[e]??=process.platform===`win32`?e===`strict`?buildWindowsTrustedDirs():[...getTrustedDirs(`strict`),...buildWindowsStandardDirs()]:buildUnixTrustedDirs(e)}function resolveSystemBin(t,n){let r=n?.trust??`strict`,i=(n?.extraDirs?.length??0)>0,a=r===`standard`?x:b;if(!i){let e=a.get(t);if(e!==void 0)return a.delete(t),a.set(t,e),e}let o=[...getTrustedDirs(r),...n?.extraDirs??[]],s=process.platform===`win32`,c=s&&u.win32.extname(t).length>0;for(let n of o){let r=s&&!c?_.map(e=>u.win32.join(n,t+e)):[u.join(n,t)];for(let n of r)if(e(n,s?l.constants.R_OK:l.constants.X_OK))return i||cacheResolvedSystemBin(a,t,n),n}return null}function prepareAgentCoreDumpLimit(e,t,n){if(process.platform!==`linux`||n!==`agent-tool`)return{command:e,args:t};let r=resolveSystemBin(`prlimit`);if(!r)throw Error(`Linux agent execution requires prlimit; install util-linux in a system directory.`);return{command:r,args:[`--core=0:0`,`--`,e,...t]}}function resolveExecutablePathCandidate(e,t){let n=e.startsWith(`~`)?r(e,{env:t?.env}):e;if(process.platform===`win32`&&/^:[\\/]/.test(n))return;let i=n.includes(`/`)||n.includes(`\\`);if(t?.requirePathSeparator&&!i)return;if(!i)return n;if(u.isAbsolute(n))return u.resolve(n);let a=t?.cwd&&t.cwd.trim()?t.cwd:process.cwd();return u.resolve(a,n)}function resolveWindowsExecutableExtensions(e,t,n=!0){if(process.platform!==`win32`||u.extname(e).length>0)return[``];let r=[...resolveWindowsExecutableExtSet(t)];return n?[``,...r]:r}function resolveWindowsExecutableExtSet(e){return new Set((a(e,`PATHEXT`)??a(process.env,`PATHEXT`)??`.EXE;.CMD;.BAT;.COM`).split(`;`).map(e=>t(e)).filter(Boolean))}function isRegularFile(e){return d(e)?.isFile()??!1}const C=/* @__PURE__ */ new Set([`.com`,`.exe`,`.bat`,`.cmd`]);function isWindowsExecutable(e,n){let r=t(u.extname(e));return!r||C.has(r)||resolveWindowsExecutableExtSet(n).has(r)}function isExecutableFile(e,t){if(!isRegularFile(e))return!1;try{return process.platform===`win32`?isWindowsExecutable(e,t?.env):(l.accessSync(e,l.constants.X_OK),!0)}catch{return!1}}const w=6e4;let T=/* @__PURE__ */ new Map;function cacheExecutablePath(e,t,r){e.set(t,{expiresAt:Date.now()+w,resolved:r??null}),n(e,128)}function*executablePathProbes(e,t,n,r){let i=T,o=r?.cwd?.trim()?u.resolve(r.cwd):void 0,s=r?.useCache!==!1,c=a(n,`PATHEXT`)??a(process.env,`PATHEXT`)??``,l=``;try{l=o??process.cwd()}catch{}let d=`${process.platform}\0${e}\0${JSON.stringify(t)}\0${c}\0${r?.includeExtensionless!==!1}\0${l}\0${o!==void 0}`,f=s?i.get(d):void 0,p=Date.now();if(f&&f.expiresAt>p)return f.expiresAt=p+w,i.delete(d),i.set(d,f),f.resolved??void 0;f&&i.delete(d);let m=process.platform===`win32`?`;`:u.delimiter,h=(typeof t==`string`?t.split(m):t).filter(e=>!!e||o!==void 0&&process.platform!==`win32`),g=resolveWindowsExecutableExtensions(e,n,r?.includeExtensionless);for(let t of h){let n=process.platform!==`win32`&&t.split(`/`).includes(`..`),r=o!==void 0&&!u.isAbsolute(t)?`${o}${u.sep}${t}`:t;for(let a of g){let c=n?`${r}${u.sep}${e}${a}`:u.join(o===void 0?t:u.resolve(o,t),e+a);if(yield c)return s&&cacheExecutablePath(i,d,c),c}}s&&cacheExecutablePath(i,d,void 0)}function resolveExecutableFromPathEnv(...e){let t=executablePathProbes(...e),n=t.next();for(;!n.done;)n=t.next(isExecutableFile(n.value,{env:e[2]}));return n.value}const E=/[&|<>%\r\n]/;function resolveNpmArgvForWindows(e){if(p.platform!==`win32`||e.length===0)return null;let n=e[0]??``,r=t(n).replace(/\.(cmd|bat)$/,``),a=r===`npx`?`npx`:r===`npm`?`npm`:null;if(!a)return null;let o=f(i(a,u.join(u.dirname(p.execPath),`node_modules`,`npm`,`bin`)));return l.existsSync(o)?[p.execPath,o,...e.slice(1)]:[t(u.extname(n))?n:`${n}.cmd`,...e.slice(1)]}function createWindowsCommandNotFoundError(e){let t=/* @__PURE__ */ Error(`spawn ${e} ENOENT`);return t.code=`ENOENT`,t.path=e,t.syscall=`spawn ${e}`,t}function resolveWindowsCommandFromCwdOrPath(e){if(e.command.includes(`/`)||e.command.includes(`\\`)){let t=resolveExecutablePathCandidate(e.command,{cwd:e.cwd,env:e.env});return t?u.extname(t)?isRegularFile(t)?t:void 0:resolveExecutableFromPathEnv(u.basename(t),u.dirname(t),e.env,{includeExtensionless:!1}):void 0}let t=e.cwd&&e.cwd.trim()?e.cwd:p.cwd(),n=(a(e.env,`PATH`)??a(p.env,`PATH`)??``).split(`;`).map(e=>e.replace(/^"(.*)"$/,`$1`).trim()).filter(Boolean).map(e=>u.isAbsolute(e)?e:u.resolve(t,e));return resolveExecutableFromPathEnv(e.command,n.join(`;`),e.env,{includeExtensionless:!1})}function resolveSupportedWindowsCommand(e){if(p.platform!==`win32`)return e.command;let n=resolveWindowsCommandFromCwdOrPath(e),r=resolveWindowsCommandShim({command:e.command,cmdCommands:[`corepack`,`pnpm`,`yarn`]});if(!n&&r!==e.command&&(n=resolveWindowsCommandFromCwdOrPath({...e,command:r})),!n)throw createWindowsCommandNotFoundError(e.command);let i=t(u.extname(n));if([`.exe`,`.com`,`.cmd`,`.bat`].includes(i))return n;throw Error(`Unsupported Windows command extension ${JSON.stringify(i||`<none>`)} for ${JSON.stringify(e.command)}; use an explicit executable or shell wrapper.`)}function resolveSafeChildProcessInvocation(e){let t=resolveNpmArgvForWindows(e.argv)??e.argv,n=e.cwd instanceof URL?f(e.cwd):e.cwd,r=resolveSupportedWindowsCommand({command:t[0]??``,cwd:n,env:e.env}),i=isWindowsBatchCommand(r);return{command:i?resolveSupportedWindowsCommand({command:resolveTrustedWindowsCmdExe(),cwd:n,env:e.env}):r,args:i?[`/d`,`/s`,`/c`,buildWindowsCmdExeCommandLine(r,t.slice(1))]:t.slice(1),usesWindowsExitCodeShim:p.platform===`win32`&&(i||t!==e.argv),windowsHide:!0,windowsVerbatimArguments:i?!0:e.windowsVerbatimArguments}}function isWindowsBatchCommand(e,n=p.platform){if(n!==`win32`)return!1;let r=t(u.extname(e));return r===`.cmd`||r===`.bat`}function buildWindowsCmdExeCommandLine(e,t){return`"${[e,...t].map(e=>{if(E.test(e))throw Error(`Unsafe Windows cmd.exe argument detected: ${JSON.stringify(e)}. Pass an explicit shell-wrapper argv at the call site instead.`);return`"${e.replace(/\\+/g,(t,n)=>{let r=e[n+t.length];return r===`"`||r===void 0?t.repeat(2):t}).replace(/"/g,`""`)}"`}).join(` `)}"`}function resolveTrustedWindowsCmdExe(e=p.platform){return e===`win32`?c():`cmd.exe`}function resolveWindowsCommandShim(e){if(p.platform!==`win32`)return e.command;let n=t(u.basename(e.command));return u.extname(n)?e.command:e.cmdCommands.includes(n)?`${e.command}.cmd`:e.command}export{resolveWindowsCommandShim as a,resolveTrustedWindowsCmdExe as i,isWindowsBatchCommand as n,prepareAgentCoreDumpLimit as o,resolveSafeChildProcessInvocation as r,buildWindowsCmdExeCommandLine as t};