diff --git a/DOCS.md b/DOCS.md index c3c306b..8586068 100644 --- a/DOCS.md +++ b/DOCS.md @@ -204,6 +204,7 @@ All options are set via **Settings → Apps/Add-ons → OpenClaw Assistant → C | `enable_openai_api` | bool | `false` | Enable the OpenAI-compatible `/v1/chat/completions` endpoint. Required for [Assist pipeline integration](#6c-assist-pipeline-integration-openai-api) | | `allow_insecure_auth` | bool | `false` | Allow HTTP (non-HTTPS) authentication on LAN. **Required** for browser access over plain HTTP | | `force_ipv4_dns` | bool | `false` | Force IPv4-first DNS ordering for Node network calls. Useful if IPv6 DNS resolves but IPv6 egress is broken (can affect Telegram API polling). | +| `gateway_env_vars` | map(string) | `{}` | Environment variables exported to the gateway process at startup. Use YAML map format (for example `OPENAI_API_KEY: "sk-..."`). Limits: max 50 vars, key length 255, value length 10000. | ### Terminal diff --git a/openclaw_assistant/CHANGELOG.md b/openclaw_assistant/CHANGELOG.md index 3ffc263..f18263c 100644 --- a/openclaw_assistant/CHANGELOG.md +++ b/openclaw_assistant/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to the OpenClaw Assistant Home Assistant Add-on will be documented in this file. +## [0.5.50] - 2026-02-23 + +### Added +- New add-on option `gateway_env_vars` that accepts a YAML map; values are exported verbatim to the gateway process at startup with limits (50 vars, key ≤255 chars, value ≤10000 chars). + ## [0.5.49] - 2026-02-22 ### Added diff --git a/openclaw_assistant/config.yaml b/openclaw_assistant/config.yaml index d37c5d9..1e5f72c 100644 --- a/openclaw_assistant/config.yaml +++ b/openclaw_assistant/config.yaml @@ -1,5 +1,5 @@ name: OpenClaw Assistant -version: "0.5.49" +version: "0.5.50" slug: openclaw_assistant description: Run OpenClaw Assistant (OpenClaw-compatible) as a Home Assistant add-on. url: https://github.com/techartdev/OpenClawHomeAssistant diff --git a/openclaw_assistant/run.sh b/openclaw_assistant/run.sh index 77dbc7d..9c8ef5f 100644 --- a/openclaw_assistant/run.sh +++ b/openclaw_assistant/run.sh @@ -151,46 +151,53 @@ export PATH="${PNPM_HOME}:${PATH}" # Export gateway environment variables from add-on config # These are user-defined variables that should be available to the gateway process if [ "$GW_ENV_VARS" != "{}" ] && [ -n "$GW_ENV_VARS" ]; then - echo "INFO: Setting gateway environment variables from add-on config..." - env_count=0 - max_env_vars=50 - max_var_name_size=255 - - # Parse JSON object and export each key=value pair - while IFS='=' read -r key value; do - # Skip empty lines and trim whitespace - key=$(echo "$key" | xargs) - value=$(echo "$value" | xargs) - - if [ -z "$key" ]; then - continue + if printf '%s' "$GW_ENV_VARS" | jq -e 'type == "object"' >/dev/null 2>&1; then + echo "INFO: Setting gateway environment variables from add-on config..." + env_count=0 + max_env_vars=50 + max_var_name_size=255 + max_var_value_size=10000 + + # Use null-delimited key/value pairs to preserve spaces and special chars. + while IFS= read -r -d '' key && IFS= read -r -d '' value; do + if [ -z "$key" ]; then + continue + fi + + # Validate variable name format + if ! [[ "$key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then + echo "WARN: Invalid environment variable name: '$key' (must start with letter/underscore, skip)" + continue + fi + + # Enforce max variable name length + if [ ${#key} -gt $max_var_name_size ]; then + echo "WARN: Environment variable name too long: '$key' (max $max_var_name_size chars, skip)" + continue + fi + + # Enforce max variable value length + if [ ${#value} -gt $max_var_value_size ]; then + echo "WARN: Environment variable value too long for '$key' (max $max_var_value_size chars, skip)" + continue + fi + + # Enforce limit on number of variables + if [ $env_count -ge $max_env_vars ]; then + echo "WARN: Maximum environment variables limit ($max_env_vars) reached (skip)" + continue + fi + + export "$key=$value" + ((env_count++)) + echo "INFO: Exported gateway env var: $key" + done < <(printf '%s' "$GW_ENV_VARS" | jq -j 'to_entries[] | .key, "\u0000", (.value | tostring), "\u0000"') + + if [ $env_count -gt 0 ]; then + echo "INFO: Successfully exported $env_count gateway environment variable(s)" fi - - # Validate variable name format - if ! [[ "$key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then - echo "WARN: Invalid environment variable name: '$key' (must start with letter/underscore, skip)" - continue - fi - - # Enforce max variable name length - if [ ${#key} -gt $max_var_name_size ]; then - echo "WARN: Environment variable name too long: '$key' (max $max_var_name_size chars, skip)" - continue - fi - - # Enforce limit on number of variables - if [ $env_count -ge $max_env_vars ]; then - echo "WARN: Maximum environment variables limit ($max_env_vars) reached (skip)" - continue - fi - - export "$key=$value" - ((env_count++)) - echo "INFO: Exported gateway env var: $key" - done < <(echo "$GW_ENV_VARS" | jq -r 'to_entries[] | "\(.key)=\(.value)"') - - if [ $env_count -gt 0 ]; then - echo "INFO: Successfully exported $env_count gateway environment variable(s)" + else + echo "WARN: Invalid gateway_env_vars format in add-on options (expected JSON object), skipping" fi fi