Remove python dependency; generate config via jq; bump 0.3.4
This commit is contained in:
@@ -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
|
||||||
|
|||||||
+49
-65
@@ -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" \
|
||||||
"agents": {
|
$ALLOW_FROM_ARG \
|
||||||
"defaults": {
|
'
|
||||||
"workspace": "/config/clawd",
|
def maybeAllowFrom: if (has("allowFrom") and (.allowFrom|type=="array") and (.allowFrom|length>0)) then {allowFrom: .allowFrom} else {} end;
|
||||||
"model": {"primary": os.environ["MODEL_PRIMARY"]},
|
def maybeToken: if (.token|length)>0 then {auth:{mode:"token", token:.token}} else {auth:{mode:"token"}} end;
|
||||||
"models": {os.environ["MODEL_PRIMARY"]: {}},
|
|
||||||
|
{
|
||||||
|
agents: {
|
||||||
|
defaults: {
|
||||||
|
model: {primary: $modelPrimary},
|
||||||
|
models: {($modelPrimary): {}},
|
||||||
|
workspace: "/config/clawd",
|
||||||
|
maxConcurrent: 4,
|
||||||
|
subagents: {maxConcurrent: 8}
|
||||||
|
},
|
||||||
|
list: [{id:"main"}]
|
||||||
},
|
},
|
||||||
"list": [{"id": "main"}],
|
commands: {native:"auto", nativeSkills:"auto"},
|
||||||
},
|
channels: {
|
||||||
"channels": {
|
telegram: (
|
||||||
"telegram": {
|
{enabled:true, botToken:$botToken, dmPolicy:$dmPolicy} + maybeAllowFrom
|
||||||
"enabled": True,
|
)
|
||||||
"botToken": os.environ["BOT_TOKEN"],
|
},
|
||||||
"dmPolicy": os.environ["DM_POLICY"],
|
gateway: (
|
||||||
}
|
{mode:"local", bind:$bind, port:$port, controlUi:{allowInsecureAuth:true}} + maybeToken
|
||||||
},
|
),
|
||||||
}
|
discovery: {wideArea:{enabled:false}}
|
||||||
|
}
|
||||||
allow_from_json = os.environ.get("ALLOW_FROM_JSON", "").strip()
|
' > /config/.clawdbot/clawdbot.json
|
||||||
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;' &
|
||||||
|
|||||||
Reference in New Issue
Block a user