openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.17 kB
JavaScript
import{Bt as e,Y as t,u as n}from"./sqlite-readonly-runtime-process-manifest-CLhsN5hb.mjs";import"./sqlite-readonly-cli-invocation-xwXCxqwu.mjs";import{t as r}from"./sqlite-readonly-runtime-binary-BIdoCQkJ.mjs";import i from"node:path";import"node:crypto";import a from"node:fs";import{fileURLToPath as o,pathToFileURL as s}from"node:url";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,o){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=i.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=o.parse,r=Reflect.apply(n,o,[e]),i=o.validate;return i&&!Reflect.apply(i,o,[r])?{ok:!1,reason:`invalid`,error:resolveInvalidMessage(o.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`})}resolveRuntimeProcessDistRoot(o(import.meta.url));function resolveRuntimeProcessDistRoot(e){let t=e.replaceAll(i.sep,`/`).lastIndexOf(`/dist/`);return t>=0?e.slice(0,t+6):void 0}function resolveRuntimeWorkerUrl(e){if(e.root!==void 0)return s(i.join(e.root,`dist`,e.distWorkerPath));let t=o(e.currentModuleUrl),n=resolveRuntimeProcessDistRoot(t);if(n!==void 0){let t=e.distWorkerPath;if(e.package){let r=i.resolve(n,`..`),a=readRootJsonObjectSync({rootDir:r,relativePath:`package.json`,boundaryLabel:`runtime worker package`,rejectHardlinks:!1});if(!a.ok)throw Error(`Cannot resolve runtime worker package: ${r}/package.json`);a.value.name===e.package.name&&(t=e.package.distWorkerPath)}return s(i.join(n,t))}let r=e.sourceExtension??(i.extname(t)||`.js`);return new URL(`./${e.sourceWorkerName}${r}`,e.currentModuleUrl)}function isBunTargetRuntime(e){return e===process.execPath?!!process.versions.bun:r(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=o(e);return runtimeNeedsTypeScriptLoader(n,t)?[`--import`,import.meta.resolve(`tsx`),n]:[...resolveRuntimeArgs(t),n]}function resolveRuntimeWorkerThreadExecArgv(e,t=process.execPath){return e.protocol===`file:`&&runtimeNeedsTypeScriptLoader(o(e),t)?[`--import`,import.meta.resolve(`tsx/esm`)]:[]}export{runtimeNeedsTypeScriptLoader as i,resolveRuntimeWorkerThreadExecArgv as n,resolveRuntimeWorkerUrl as r,resolveRuntimeWorkerArgv as t};