openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.19 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as parseJsonWithJson5Fallback}from"./parse-json-compat-BEbcOl-a.mjs";import{g as setConfigResolutionFacts}from"./resolution-facts-DYKtoyes.mjs";import{u as resolveConfigIncludes}from"./includes-gwK90iIZ.mjs";import{m as resolveConfigPath,x as resolveIncludeRoots}from"./paths-D_FOvGon.mjs";import{u as resolveConfigForRead}from"./io.read-helpers-B0XuPBY2.mjs";import fs from"node:fs";import path from"node:path";
//!src/config/gateway-dispatch-config.ts
const GATEWAY_DISPATCH_SHELL_ENV_EXPECTED_KEYS=[`OPENCLAW_GATEWAY_TOKEN`,`OPENCLAW_GATEWAY_PASSWORD`];const GATEWAY_DISPATCH_TOP_LEVEL_KEYS=[`agents`,`database`,`env`,`gateway`,`plugins`,`secrets`,`session`];function resolveGatewayDispatchConfig(e,t){if(!isRecord(e))return{};const n={};for(const t of GATEWAY_DISPATCH_TOP_LEVEL_KEYS)if(Object.hasOwn(e,t))n[t]=e[t];const{resolvedConfigRaw:r,resolutionFacts:i}=resolveConfigForRead(n,t);const a=r;if(a.session?.mainKey!==void 0)a.session.mainKey=`main`;setConfigResolutionFacts(a,i);return a}function readRawGatewayDispatchConfig(e={}){const t=e.env??process.env;const n=e.configPath??resolveConfigPath(t);if(!fs.existsSync(n))return{config:{},configPath:n};const r=fs.readFileSync(n,`utf-8`);const i=parseJsonWithJson5Fallback(r);return{config:resolveGatewayDispatchConfig(resolveConfigIncludes(i,n,void 0,{allowedRoots:resolveIncludeRoots(t)}),t),configPath:n}}function readGatewayDispatchConfig(e={}){return readRawGatewayDispatchConfig(e).config}async function readGatewayDispatchConfigWithShellEnvFallback(e={}){const t=e.env??process.env;const n=readRawGatewayDispatchConfig(e);const{loadShellEnvFallback:r,resolveShellEnvFallbackTimeoutMs:i,shouldDeferShellEnvFallback:a,shouldEnableShellEnvFallback:o}=await import(`./shell-env-DdGYkfL-.mjs`);if((o(t)||n.config.env?.shellEnv?.enabled===true)&&!a(t)){if(r({env:t,expectedKeys:[...GATEWAY_DISPATCH_SHELL_ENV_EXPECTED_KEYS],timeoutMs:n.config.env?.shellEnv?.timeoutMs??i(t)}).length>0)return readGatewayDispatchConfig({...e,configPath:path.resolve(n.configPath)})}return n.config}export{readGatewayDispatchConfigWithShellEnvFallback as n,readGatewayDispatchConfig as t};