UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

65 lines (64 loc) • 2.49 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { t as parseJsonWithJson5Fallback } from "./parse-json-compat-DoWUfD79.mjs"; import { u as resolveConfigIncludes } from "./includes-wjVi5Ymt.mjs"; import { m as resolveConfigPath, x as resolveIncludeRoots } from "./paths-DAcAg5aV.mjs"; import { g as setConfigResolutionFacts } from "./resolution-facts-xaIKuREs.mjs"; import { u as resolveConfigForRead } from "./io.read-helpers-qAcqsRC0.mjs"; import fs from "node:fs"; import path from "node:path"; //#region 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-UGXWdL1m.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; } //#endregion export { readGatewayDispatchConfigWithShellEnvFallback as n, readGatewayDispatchConfig as t };