openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.18 kB
JavaScript
import"./openclaw-state-read-cli-invocation-fIA_-Tg7.mjs";import{M as e,s as t}from"./openclaw-state-read-read-open-flags-CtNL1rJs.mjs";import{n}from"./openclaw-state-read-root-file-Dvko4xK2.mjs";import{n as r}from"./openclaw-state-read-runtime-process-bootstrap.generated-BKfT41K0.mjs";import{t as i}from"./openclaw-state-read-runtime-binary-Dgxk5ZBN.mjs";import a from"node:fs";import o from"node:path";import{fileURLToPath as s,pathToFileURL as c}from"node:url";import"node:crypto";function isRecord(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function resolveInvalidMessage(e,t){return typeof e==`function`?e(t):e??`${t} has an unexpected shape`}function readRootStructuredFileSyncInternal(r,i){let s,c,l,u;try{l=r.rootDir,c=r.relativePath,u=r.rootRealPath,e(l),e(c,`relative`),u!==void 0&&e(u),s=o.resolve(l,c),e(s)}catch(e){return{ok:!1,reason:`open`,failure:{ok:!1,reason:`validation`,error:e}}}let d=r.boundaryLabel,f=r.rejectHardlinks,p=r.maxBytes,m=n({absolutePath:s,rootPath:l,rootRealPath:u,boundaryLabel:d,rejectHardlinks:f,maxBytes:p,allowedType:`file`});if(!m.ok)return{ok:!1,reason:`open`,failure:m};try{let e=p===void 0?a.readFileSync(m.fd,`utf8`):t(m.fd,p).toString(`utf8`),n=i.parse,r=Reflect.apply(n,i,[e]),o=i.validate;return o&&!Reflect.apply(o,i,[r])?{ok:!1,reason:`invalid`,error:resolveInvalidMessage(i.invalidMessage,c)}:{ok:!0,value:r,stat:m.stat,path:m.path,rootRealPath:m.rootRealPath}}catch(e){return{ok:!1,reason:`parse`,error:`failed to parse ${c}: ${String(e)}`}}finally{a.closeSync(m.fd)}}function readRootJsonObjectSync(e){return readRootStructuredFileSyncInternal(e,{parse:e=>JSON.parse(e),validate:isRecord,invalidMessage:e=>`${e} must contain a JSON object`})}function resolveRuntimeWorkerUrl(e){if(e.root!==void 0)return c(o.join(e.root,`dist`,e.distWorkerPath));let t=s(e.currentModuleUrl),n=r(t);if(n!==void 0){let t=e.distWorkerPath;if(e.package){let r=o.resolve(n,`..`),i=readRootJsonObjectSync({rootDir:r,relativePath:`package.json`,boundaryLabel:`runtime worker package`,rejectHardlinks:!1});if(!i.ok)throw Error(`Cannot resolve runtime worker package: ${r}/package.json`);i.value.name===e.package.name&&(t=e.package.distWorkerPath)}return c(o.join(n,t))}let i=e.sourceExtension??(o.extname(t)||`.js`);return new URL(`./${e.sourceWorkerName}${i}`,e.currentModuleUrl)}function isBunTargetRuntime(e){return e===process.execPath?!!process.versions.bun:i(e)}function resolveRuntimeArgs(e=process.execPath){return isBunTargetRuntime(e)?[`--no-install`]:[]}function runtimeNeedsTypeScriptLoader(e,t=process.execPath){return/\.[cm]?ts$/.test(e)&&!isBunTargetRuntime(t)}function resolveRuntimeWorkerArgv(e,t=process.execPath){let n=s(e);return runtimeNeedsTypeScriptLoader(n,t)?[`--import`,import.meta.resolve(`tsx`),n]:[...resolveRuntimeArgs(t),n]}function resolveRuntimeWorkerThreadExecArgv(e,t=process.execPath){return typeof SEALED_RUNTIME_BUILD==`boolean`&&SEALED_RUNTIME_BUILD?[]:e.protocol===`file:`&&runtimeNeedsTypeScriptLoader(s(e),t)?[`--import`,import.meta.resolve(`tsx/esm`)]:[]}export{runtimeNeedsTypeScriptLoader as i,resolveRuntimeWorkerThreadExecArgv as n,resolveRuntimeWorkerUrl as r,resolveRuntimeWorkerArgv as t};