Remove python dependency; generate config via jq; bump 0.3.4

This commit is contained in:
root
2026-01-29 18:36:54 +02:00
parent a4381dd7fc
commit 6bebc0de82
2 changed files with 50 additions and 66 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
name: Moltbot Assistant name: Moltbot Assistant
version: "0.3.3" version: "0.3.4"
slug: moltbot_assistant slug: moltbot_assistant
description: Run Moltbot Assistant (Clawdbot-compatible) as a Home Assistant add-on. description: Run Moltbot Assistant (Clawdbot-compatible) as a Home Assistant add-on.
url: https://github.com/techartdev/ClawdHAAddOn url: https://github.com/techartdev/ClawdHAAddOn
+46 -62
View File
@@ -131,63 +131,53 @@ if [ "$GW_BIND" = "lan" ] && [ -z "$GW_TOKEN" ]; then
exit 1 exit 1
fi fi
GW_AUTH_BLOCK="auth: { mode: \"token\", token: \"${GW_TOKEN}\" }" # Build auth JSON: prefer fixed token (required for ingress proxy to work reliably)
if [ -z "$GW_TOKEN" ]; then AUTH_TOKEN="$GW_TOKEN"
# Let doctor generate one (loopback-only is still protected by local access)
GW_AUTH_BLOCK="auth: { mode: \"token\" }"
fi
# Write Clawdbot gateway config (strict JSON) into the expected location. # Write Clawdbot gateway config (strict JSON) into the expected location.
# We generate JSON with python to avoid JSON5-only syntax and comma edge cases. # Use jq (available in the image) to avoid JSON5 syntax.
GW_BIND="$GW_BIND" GW_PORT="$GW_PORT" MODEL_PRIMARY="$MODEL_PRIMARY" \ if [ -n "${ALLOW_FROM_JSON:-}" ]; then
BOT_TOKEN="$BOT_TOKEN" DM_POLICY="$DM_POLICY" ALLOW_FROM_JSON='${ALLOW_FROM_JSON:-}' \ ALLOW_FROM_ARG="--argjson allowFrom ${ALLOW_FROM_JSON}"
python3 - <<'PY' else
import json, os ALLOW_FROM_ARG=""
from pathlib import Path fi
cfg = { # shellcheck disable=SC2086
"discovery": {"wideArea": {"enabled": False}}, jq -n \
"gateway": { --arg modelPrimary "$MODEL_PRIMARY" \
"mode": "local", --arg botToken "$BOT_TOKEN" \
"bind": os.environ["GW_BIND"], --arg dmPolicy "$DM_POLICY" \
"port": int(os.environ["GW_PORT"]), --arg bind "$GW_BIND" \
"controlUi": {"allowInsecureAuth": True}, --argjson port "$GW_PORT" \
--arg token "$AUTH_TOKEN" \
$ALLOW_FROM_ARG \
'
def maybeAllowFrom: if (has("allowFrom") and (.allowFrom|type=="array") and (.allowFrom|length>0)) then {allowFrom: .allowFrom} else {} end;
def maybeToken: if (.token|length)>0 then {auth:{mode:"token", token:.token}} else {auth:{mode:"token"}} end;
{
agents: {
defaults: {
model: {primary: $modelPrimary},
models: {($modelPrimary): {}},
workspace: "/config/clawd",
maxConcurrent: 4,
subagents: {maxConcurrent: 8}
}, },
"agents": { list: [{id:"main"}]
"defaults": {
"workspace": "/config/clawd",
"model": {"primary": os.environ["MODEL_PRIMARY"]},
"models": {os.environ["MODEL_PRIMARY"]: {}},
}, },
"list": [{"id": "main"}], commands: {native:"auto", nativeSkills:"auto"},
channels: {
telegram: (
{enabled:true, botToken:$botToken, dmPolicy:$dmPolicy} + maybeAllowFrom
)
}, },
"channels": { gateway: (
"telegram": { {mode:"local", bind:$bind, port:$port, controlUi:{allowInsecureAuth:true}} + maybeToken
"enabled": True, ),
"botToken": os.environ["BOT_TOKEN"], discovery: {wideArea:{enabled:false}}
"dmPolicy": os.environ["DM_POLICY"],
} }
}, ' > /config/.clawdbot/clawdbot.json
}
allow_from_json = os.environ.get("ALLOW_FROM_JSON", "").strip()
if allow_from_json:
try:
allow_from = json.loads(allow_from_json)
if isinstance(allow_from, list) and allow_from:
cfg["channels"]["telegram"]["allowFrom"] = allow_from
except Exception:
pass
# Auth block: embed token when provided, otherwise keep mode=token (auto-generate).
token = os.environ.get("GW_TOKEN", "").strip()
if token:
cfg["gateway"]["auth"] = {"mode": "token", "token": token}
else:
cfg["gateway"]["auth"] = {"mode": "token"}
Path('/config/.clawdbot/clawdbot.json').write_text(json.dumps(cfg, indent=2) + "\n")
PY
echo "Model primary=${MODEL_PRIMARY}" echo "Model primary=${MODEL_PRIMARY}"
echo "Gateway bind=${GW_BIND} port=${GW_PORT} token=${GW_TOKEN:+(set)}${GW_TOKEN:-(auto)}" echo "Gateway bind=${GW_BIND} port=${GW_PORT} token=${GW_TOKEN:+(set)}${GW_TOKEN:-(auto)}"
@@ -296,18 +286,12 @@ fi
# Render nginx config from template with the gateway token. # Render nginx config from template with the gateway token.
# NOTE: This intentionally exposes the token in the browser URL via a redirect. # NOTE: This intentionally exposes the token in the browser URL via a redirect.
# This matches Clawdbot Control UI's current expectations. # This matches Clawdbot Control UI's current expectations.
GW_TOKEN="$GW_TOKEN" python3 - <<'PY' if [ -z "$GW_TOKEN" ]; then
import os echo "WARN: gateway_token is empty; ingress UI will redirect with an empty token and Control UI will not authenticate."
from pathlib import Path fi
# Escape token for sed replacement
tpl = Path('/etc/nginx/nginx.conf.tpl').read_text() ESC_TOKEN=$(printf '%s' "$GW_TOKEN" | sed -e 's/[\\&|]/\\\\&/g')
token = os.environ.get('GW_TOKEN','') sed -e "s|__GATEWAY_TOKEN__|${ESC_TOKEN}|g" /etc/nginx/nginx.conf.tpl > /etc/nginx/nginx.conf
if not token:
print('WARN: gateway_token is empty; ingress UI will redirect with an empty token and Control UI will not authenticate.')
conf = tpl.replace('__GATEWAY_TOKEN__', token)
Path('/etc/nginx/nginx.conf').write_text(conf)
PY
echo "Starting ingress proxy (nginx) on :8099 ..." echo "Starting ingress proxy (nginx) on :8099 ..."
nginx -g 'daemon off;' & nginx -g 'daemon off;' &