openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 2.96 kB
JavaScript
import{m as parseStrictPositiveInteger}from"./number-coercion-DIhBGkET.mjs";import{i as resolveProfileGatewayPort,r as normalizeProfileName,t as resolveStateDir}from"./state-dir-C22DK7p0.mjs";import{a as resolveUserPath,n as resolveHomeRelativePath,r as resolveRequiredHomeDir}from"./home-dir-C2A7IM0a.mjs";import fsSync from"node:fs";import path from"node:path";import os from"node:os";
//!src/infra/tcp-port.ts
const MAX_TCP_PORT=65535;function parseTcpPort(e){const t=parseStrictPositiveInteger(e);if(t===void 0||t>65535)return null;return t}
//!src/config/paths.ts
function resolveIsNixMode(e=process.env){return e.OPENCLAW_NIX_MODE===`1`}let isNixMode=resolveIsNixMode();const CONFIG_FILENAME=`openclaw.json`;function envHomedir(e){return()=>resolveRequiredHomeDir(e,os.homedir)}function normalizePathForComparison(e){const t=path.resolve(e);try{return fsSync.realpathSync.native(t)}catch{return t}}function resolveIncludeRoots(e=process.env,t=envHomedir(e)){const n=e.OPENCLAW_INCLUDE_ROOTS?.trim();if(!n)return[];const effectiveHomedir=()=>resolveRequiredHomeDir(e,t);const r=/* @__PURE__ */ new Set;const i=[];for(const t of n.split(path.delimiter)){const n=t.trim();if(!n)continue;const a=path.resolve(resolveHomeRelativePath(n,{env:e,homedir:effectiveHomedir}));if(r.has(a))continue;r.add(a);i.push(a)}return i}let STATE_DIR=resolveStateDir();function resolveConfigPathCandidate(e=process.env,t=envHomedir(e)){return resolveConfigPath(e,void 0,t)}function resolveConfigPath(e=process.env,t,n=envHomedir(e)){const r=e.OPENCLAW_CONFIG_PATH?.trim();if(r)return resolveUserPath(r,e,n);return path.join(t??resolveStateDir(e,n),CONFIG_FILENAME)}let CONFIG_PATH=resolveConfigPathCandidate();const DEFAULT_GATEWAY_PORT=18789;function resolveGatewayLockDir(e=resolveStateDir(),t=typeof process.getuid===`function`?process.getuid():void 0){return resolveGatewayLockDirForCanonicalStateDir(normalizePathForComparison(e),t)}function resolveGatewayLockDirForCanonicalStateDir(e,t=typeof process.getuid===`function`?process.getuid():void 0){const n=t!=null?`openclaw-${t}`:`openclaw`;return path.join(e,`tmp`,n)}function parseGatewayPortEnvValue(e){const t=e?.trim();if(!t)return null;if(/^\d+$/.test(t))return parseTcpPort(t);const n=t.match(/^\[[^\]]+\]:(\d+)$/);if(n?.[1])return parseTcpPort(n[1]);const r=t.indexOf(`:`);const i=t.lastIndexOf(`:`);if(r<=0||r!==i)return null;const a=t.slice(r+1);if(!/^\d+$/.test(a))return null;return parseTcpPort(a)}function resolveGatewayPort(e,t=process.env){const n=parseGatewayPortEnvValue(t.OPENCLAW_GATEWAY_PORT);if(n!==null)return n;const r=e?.gateway?.port;if(typeof r===`number`&&Number.isFinite(r)&&r>0)return r;const i=normalizeProfileName(t.OPENCLAW_PROFILE);return i?resolveProfileGatewayPort(i):DEFAULT_GATEWAY_PORT}export{resolveIncludeRoots as a,resolveGatewayPort as i,resolveGatewayLockDir as n,resolveIsNixMode as o,resolveGatewayLockDirForCanonicalStateDir as r,parseTcpPort as s,resolveConfigPath as t};