mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 21:14:31 +00:00
feat: allow inline env vars in config
This commit is contained in:
@@ -41,6 +41,7 @@ const SHELL_ENV_EXPECTED_KEYS = [
|
||||
"ANTHROPIC_OAUTH_TOKEN",
|
||||
"GEMINI_API_KEY",
|
||||
"ZAI_API_KEY",
|
||||
"OPENROUTER_API_KEY",
|
||||
"MINIMAX_API_KEY",
|
||||
"ELEVENLABS_API_KEY",
|
||||
"TELEGRAM_BOT_TOKEN",
|
||||
@@ -78,6 +79,34 @@ function warnOnConfigMiskeys(
|
||||
}
|
||||
}
|
||||
|
||||
function applyConfigEnv(
|
||||
cfg: ClawdbotConfig,
|
||||
env: NodeJS.ProcessEnv,
|
||||
): void {
|
||||
const envConfig = cfg.env;
|
||||
if (!envConfig) return;
|
||||
|
||||
const entries: Record<string, string> = {};
|
||||
|
||||
if (envConfig.vars) {
|
||||
for (const [key, value] of Object.entries(envConfig.vars)) {
|
||||
if (!value) continue;
|
||||
entries[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(envConfig)) {
|
||||
if (key === "shellEnv" || key === "vars") continue;
|
||||
if (typeof value !== "string" || !value.trim()) continue;
|
||||
entries[key] = value;
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(entries)) {
|
||||
if (env[key]?.trim()) continue;
|
||||
env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveConfigPathForDeps(deps: Required<ConfigIoDeps>): string {
|
||||
if (deps.configPath) return deps.configPath;
|
||||
return resolveConfigPath(deps.env, resolveStateDir(deps.env, deps.homedir));
|
||||
@@ -155,6 +184,8 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
|
||||
throw new DuplicateAgentDirError(duplicates);
|
||||
}
|
||||
|
||||
applyConfigEnv(cfg, deps.env);
|
||||
|
||||
const enabled =
|
||||
shouldEnableShellEnvFallback(deps.env) ||
|
||||
cfg.env?.shellEnv?.enabled === true;
|
||||
|
||||
Reference in New Issue
Block a user