fix: store env vars in cfg[env][vars] not cfg[gateway][env]

This commit is contained in:
macm1
2026-02-23 05:55:59 +03:00
parent 30d95b8798
commit 47631c1968
+18 -5
View File
@@ -64,7 +64,7 @@ def set_gateway_setting(key, value):
def apply_gateway_settings(mode: str, bind_mode: str, port: int, enable_openai_api: bool, allow_insecure_auth: bool, env_vars: str = "{}"):
"""
Apply gateway settings to OpenClaw config.
Apply gateway settings and environment variables to OpenClaw config.
Args:
mode: "local" or "remote"
@@ -73,6 +73,7 @@ def apply_gateway_settings(mode: str, bind_mode: str, port: int, enable_openai_a
enable_openai_api: Enable OpenAI-compatible Chat Completions endpoint
allow_insecure_auth: Allow insecure HTTP authentication
env_vars: JSON string with environment variables as key-value pairs (e.g., '{"VAR1":"value1","VAR2":"value2"}')
These are stored in cfg["env"]["vars"] and exported to the gateway process
"""
# Validate gateway mode
if mode not in ["local", "remote"]:
@@ -113,12 +114,24 @@ def apply_gateway_settings(mode: str, bind_mode: str, port: int, enable_openai_a
control_ui = gateway["controlUi"]
chat_completions = gateway["http"]["endpoints"]["chatCompletions"]
# Ensure env structure exists at root level
if "env" not in cfg:
cfg["env"] = {
"shellEnv": {
"enabled": True
},
"vars": {}
}
if "vars" not in cfg["env"]:
cfg["env"]["vars"] = {}
current_mode = gateway.get("mode", "")
current_bind = gateway.get("bind", "")
current_port = gateway.get("port", 18789)
current_openai_api = chat_completions.get("enabled", False)
current_insecure = control_ui.get("allowInsecureAuth", False)
current_env_vars = gateway.get("env", {})
current_env_vars = cfg["env"]["vars"]
changes = []
@@ -187,12 +200,12 @@ def apply_gateway_settings(mode: str, bind_mode: str, port: int, enable_openai_a
return False
if new_env_vars != current_env_vars:
gateway["env"] = new_env_vars
cfg["env"]["vars"] = new_env_vars
if new_env_vars:
var_names = ', '.join(sorted(new_env_vars.keys()))
changes.append(f"env: {var_names}")
changes.append(f"env.vars: {var_names}")
else:
changes.append("env: cleared")
changes.append("env.vars: cleared")
if changes:
if write_config(cfg):