Spaces:
Paused
Paused
Anurag commited on
Commit Β·
df97c33
1
Parent(s): d5203bf
Fix browser launch/detection and gateway port handling issues
Browse filesFiles changed (6)
- .env.example+2-9
- Dockerfile+2
- README.md+3-3
- env-builder.js+11-30
- iframe-fix.cjs+3-2
- start.sh+73-14
247 unmodified lines24824925025125225325425532 unmodified lines288289290291292293294295296297298299300301247 unmodified linesGATEWAY_TOKEN=your_gateway_token_here# [OPTIONAL] JupyterLab terminal token for /terminal/# Defaults to "huggingface" if unset. Set a strong token for private deployments.JUPYTER_TOKEN=huggingface# (Optional) Password auth β simpler alternative to token for casual users# If set, users can log in with this password instead of the token32 unmodified lines# Default: huggingclaw-backupBACKUP_DATASET_NAME=huggingclaw-backup# Git commit identity for workspace syncsWORKSPACE_GIT_USER=openclaw@example.comWORKSPACE_GIT_NAME=OpenClaw Bot# ββ OPTIONAL: Background Services ββ# Keep-alive ping interval (seconds). Default: 300. Set 0 to disable.KEEP_ALIVE_INTERVAL=300# Workspace auto-sync interval (seconds). Default: 180.SYNC_INTERVAL=180247 unmodified lines24824925025125225325425532 unmodified lines288289290291292293294247 unmodified linesGATEWAY_TOKEN=your_gateway_token_here# [OPTIONAL] JupyterLab terminal token for /terminal/# Set a strong token for private deployments. Must NOT be "huggingface".JUPYTER_TOKEN=run: openssl rand -hex 32# (Optional) Password auth β simpler alternative to token for casual users# If set, users can log in with this password instead of the token32 unmodified lines# Default: huggingclaw-backupBACKUP_DATASET_NAME=huggingclaw-backup# ββ OPTIONAL: Background Services ββ# Workspace auto-sync interval (seconds). Default: 180.SYNC_INTERVAL=180
23 unmodified lines24252627282923 unmodified linesca-certificates \jq \curl \python3 \python3-pip \chromium \23 unmodified lines242526272829303123 unmodified linesca-certificates \jq \curl \dbus \dbus-x11 \python3 \python3-pip \chromium \
103 unmodified lines104105106107108109110255 unmodified lines366367368369370371372373374375376377103 unmodified lines> [!TIP]> HuggingClaw is completely flexible! You only need these three secrets to get started. You can set other secrets later.Optional: set `DEV_MODE=true` (Variable) to enable JupyterLab support and install Jupyter dependencies at build time. You can also set `JUPYTER_TOKEN` as a Secret to replace the default terminal token (`huggingface`). If you want to pin a specific OpenClaw release instead of `latest`, add `OPENCLAW_VERSION` under **Variables** in your Space settings. For Docker Spaces, HF passes Variables as build args during image build, so these should be Variables, not Secrets (except tokens).### Step 3: Deploy & Run255 unmodified lines| :--- | :--- | :--- | :--- || `/` | HuggingClaw dashboard | `7861` | Public HF Spaces entrypoint || `/app/` | OpenClaw Control UI | `7860` | Mounted behind the local reverse proxy || `/terminal/` | JupyterLab terminal (DEV_MODE only) | `8888` | Available only when `DEV_MODE=true`; token login uses `JUPYTER_TOKEN` (default `huggingface`) |When enabled, the terminal notebook root is `/home/node`, so you can inspect HuggingClaw files, logs, workspace state, and runtime scripts from the browser.> [!IMPORTANT]> For real deployments, set a strong `JUPYTER_TOKEN` secret. The `huggingface` default exists only to match the duplicateable Hugging Face JupyterLab template.## π Merge Comparison103 unmodified lines104105106107108109110255 unmodified lines366367368369370371372373374375376377103 unmodified lines> [!TIP]> HuggingClaw is completely flexible! You only need these three secrets to get started. You can set other secrets later.Optional: set `DEV_MODE=true` (Variable) to enable JupyterLab support and install Jupyter dependencies at build time. You can also set `JUPYTER_TOKEN` as a Secret to set a strong terminal token (must not be `huggingface`). If you want to pin a specific OpenClaw release instead of `latest`, add `OPENCLAW_VERSION` under **Variables** in your Space settings. For Docker Spaces, HF passes Variables as build args during image build, so these should be Variables, not Secrets (except tokens).### Step 3: Deploy & Run255 unmodified lines| :--- | :--- | :--- | :--- || `/` | HuggingClaw dashboard | `7861` | Public HF Spaces entrypoint || `/app/` | OpenClaw Control UI | `7860` | Mounted behind the local reverse proxy || `/terminal/` | JupyterLab terminal (DEV_MODE only) | `8888` | Available only when `DEV_MODE=true`; token login uses `JUPYTER_TOKEN` (set a strong value) |When enabled, the terminal notebook root is `/home/node`, so you can inspect HuggingClaw files, logs, workspace state, and runtime scripts from the browser.> [!IMPORTANT]> For real deployments, set a strong `JUPYTER_TOKEN` secret. Do not use `huggingface`; generate a strong token with `openssl rand -hex 32`.## π Merge Comparison
481 unmodified lines482483484485486487354 unmodified lines842843844845846847848849850851852853854855856857858859860861862863102 unmodified lines966967968969970971972973974975976977978979980981982983984985986987988989481 unmodified lines"common": 1,"tag": "build"},{"g": "Startup","icon": "β‘",354 unmodified lines"g": "Core","icon": "β‘","k": "JUPYTER_TOKEN","lbl": "Jupyter access token","type": "password","ph": "huggingface","common": 1,"tag": "credential"},{"g": "Core","icon": "β‘","k": "KEEP_ALIVE_INTERVAL","lbl": "Keep-alive ping interval (seconds)","type": "number","ph": "300","common": 1,"tag": "advanced"},{"g": "Core","icon": "β‘",102 unmodified lines"ph": "/home/node","tag": "advanced"},{"g": "Backup","icon": "πΎ","k": "WORKSPACE_GIT_USER","lbl": "Workspace git author email","type": "text","ph": "openclaw@example.com","tag": "optional"},{"g": "Backup","icon": "πΎ","k": "WORKSPACE_GIT_NAME","lbl": "Workspace git author name","type": "text","ph": "OpenClaw Bot","tag": "optional"},{"g": "Provider Keys","icon": "π",481 unmodified lines482483484485486487488489490491492493494495496354 unmodified lines851852853854855856857858859860861862102 unmodified lines965966967968969970481 unmodified lines"common": 1,"tag": "build"},{"g": "Startup","icon": "π©Ί","k": "AUTO_DOCTOR","lbl": "Auto-fix config on boot (openclaw doctor --fix)","type": "toggle","ph": "false","tag": "advanced"},{"g": "Startup","icon": "β‘",354 unmodified lines"g": "Core","icon": "β‘","k": "JUPYTER_TOKEN","lbl": "Jupyter access token (Must NOT be 'huggingface'. Run: openssl rand -hex 32)","type": "password","ph": "change_this_to_a_strong_token","common": 1,"tag": "credential"},{"g": "Core","icon": "β‘",102 unmodified lines"ph": "/home/node","tag": "advanced"},{"g": "Provider Keys","icon": "π",
18 unmodified lines19202122232425262718 unmodified linesif (event === "request") {const [, res] = args;// Only intercept on the main OpenClaw server (port 7860)const serverPort = this.address && this.address() && this.address().port;if (serverPort && serverPort !== 7860) {return origEmit.apply(this, [event, ...args]);}18 unmodified lines1920212223242526272818 unmodified linesif (event === "request") {const [, res] = args;// Only intercept on the main OpenClaw server (respects GATEWAY_PORT env var)const expectedPort = Number(process.env.GATEWAY_PORT || 7860);const serverPort = this.address && this.address() && this.address().port;if (serverPort && serverPort !== expectedPort) {return origEmit.apply(this, [event, ...args]);}
98 unmodified lines99100101102103104401 unmodified lines50650750850951051151251351451551651751 unmodified lines569570571572573574575182 unmodified lines75875976076176276376452 unmodified lines817818819820821822823824825826827828829830831832833834835836601 unmodified lines1438143914401441144214431444111 unmodified lines15561557155815591560156119 unmodified lines158115821583158415851586158715881589159012 unmodified lines16031604160516061607160816098 unmodified lines16181619162016211622162316241625162698 unmodified linesif ! hc_is_true "$DEVDATA_NORMALIZED"; thenDEVDATA_ENABLED=falsefiif [ -n "${SPACE_HOST:-}" ]; thenOPENCLAW_CONSOLE_LOG_LEVEL="${OPENCLAW_CONSOLE_LOG_LEVEL:-warn}"OPENCLAW_FILE_LOG_LEVEL="${OPENCLAW_FILE_LOG_LEVEL:-info}"401 unmodified lines# Browser configuration (managed local Chromium in HF/Docker)BROWSER_EXECUTABLE_PATH=""for candidate in /usr/bin/chromium /usr/bin/chromium-browser /snap/bin/chromium; doif [ -x "$candidate" ]; thenBROWSER_EXECUTABLE_PATH="$candidate"breakfidoneBROWSER_SHOULD_ENABLE=falseif [ "$BROWSER_PLUGIN_MODE" = "enabled" ] && [ -n "$BROWSER_EXECUTABLE_PATH" ] && [ -x "$BROWSER_EXECUTABLE_PATH" ]; then51 unmodified lines"defaultProfile": "openclaw","headless": true,"noSandbox": true,"executablePath": $execPath}| .agents.defaults.sandbox.browser.allowHostControl = true' <<<"$CONFIG_JSON")fi182 unmodified linesif [ -n "${CLOUDFLARE_PROXY_URL:-}" ]; thenecho "Proxy : ${CLOUDFLARE_PROXY_URL}"fiRUNTIME_JUPYTER_ENABLED="$DEV_MODE_ENABLED"# Add user bin to PATH for jupyter-lab (installed in Dockerfile when DEV_MODE=true)export PATH="$HOME/.local/bin:$PATH"52 unmodified lines}trap graceful_shutdown SIGTERM SIGINTwarmup_browser() {[ "$BROWSER_SHOULD_ENABLE" = "true" ] || return 0(sleep 5local attemptfor attempt in 1 2 3 4 5; doif openclaw browser --browser-profile openclaw start >/dev/null 2>&1; thenopenclaw browser --browser-profile openclaw open about:blank >/dev/null 2>&1 || trueecho "Managed browser ready."return 0fisleep 2doneecho "Warning: managed browser warm-up did not complete; first browser action may need a retry."601 unmodified linesfi# ββ Fix config before running startup commands ββopenclaw doctor --fix || true# ββ Arbitrary startup commands from HF Variables/Secrets ββ# Recommended: use one variable, HUGGINGCLAW_RUN, as a full bash script. If the111 unmodified linesecho "WhatsApp Guardian started (PID: $GUARDIAN_PID)"}while true; do# Check health-server process - restart if died unexpectedlyif [ -n "${HEALTH_PID:-}" ] && ! kill -0 "$HEALTH_PID" 2>/dev/null; then19 unmodified linesfifiopenclaw doctor --fix || trueecho "Launching OpenClaw gateway on port 7860..."GATEWAY_ARGS=(gateway run --port 7860 --bind lan)if [ "${GATEWAY_VERBOSE:-0}" = "1" ]; thenGATEWAY_ARGS+=(--verbose)echo "Gateway verbose logging enabled (GATEWAY_VERBOSE=1)"12 unmodified linesGATEWAY_READY_TIMEOUT="${GATEWAY_READY_TIMEOUT:-90}"ready=falsefor ((i=0; i<GATEWAY_READY_TIMEOUT; i++)); doif (echo > /dev/tcp/127.0.0.1/7860) 2>/dev/null; thenready=truebreakfi8 unmodified linesecho "Gateway failed to start. Last 30 lines of log:"echo "ββββββββββββββββββββββββββββββββββββββββββββ"tail -30 /home/node/.openclaw/gateway.logecho "Gateway failed β JupyterLab and env-builder still running. Retrying in 10s..."sleep 10continuefi# 11. Start WhatsApp Guardian after the gateway is accepting connections98 unmodified lines99100101102103104105106107401 unmodified lines50951051151251351451551651751851952052152252352452552652752852953053153251 unmodified lines584585586587588589590591592593594595596597598599600601602603604605182 unmodified lines78878979079179279379479579679779879980052 unmodified lines853854855856857858859860861862863864865866867868869870871872873874875876601 unmodified lines147814791480148114821483148414851486111 unmodified lines159815991600160116021603160416051606160716081609161016111612161319 unmodified lines16331634163516361637163816391640164116421643164412 unmodified lines16571658165916601661166216638 unmodified lines1672167316741675167616771678167916801681168216831684168598 unmodified linesif ! hc_is_true "$DEVDATA_NORMALIZED"; thenDEVDATA_ENABLED=falsefi# On HF Spaces, browser is disabled by default (no display server).# To enable: set BROWSER_PLUGIN_MODE=enabled as an HF Space secret.# WARNING: requires at least CPU Upgrade tier (2 vCPU / 16GB RAM).if [ -n "${SPACE_HOST:-}" ]; thenOPENCLAW_CONSOLE_LOG_LEVEL="${OPENCLAW_CONSOLE_LOG_LEVEL:-warn}"OPENCLAW_FILE_LOG_LEVEL="${OPENCLAW_FILE_LOG_LEVEL:-info}"401 unmodified lines# Browser configuration (managed local Chromium in HF/Docker)BROWSER_EXECUTABLE_PATH=""# On Debian/Ubuntu, /usr/bin/chromium is a shell wrapper; the real ELF binary# lives at /usr/lib/chromium/chromium. Check the real binary first, then fall# back to wrapper scripts (which are also valid executablePath values for# Playwright/OpenClaw β they re-exec the real binary internally).for candidate in \/usr/lib/chromium/chromium \/usr/lib/chromium-browser/chromium-browser \/usr/bin/chromium \/usr/bin/chromium-browser \/snap/bin/chromium; doif [ -x "$candidate" ]; thenBROWSER_EXECUTABLE_PATH="$candidate"breakfidoneif [ -z "$BROWSER_EXECUTABLE_PATH" ]; thenecho "Warning: No real Chromium binary found. Browser plugin will be disabled."fiBROWSER_SHOULD_ENABLE=falseif [ "$BROWSER_PLUGIN_MODE" = "enabled" ] && [ -n "$BROWSER_EXECUTABLE_PATH" ] && [ -x "$BROWSER_EXECUTABLE_PATH" ]; then51 unmodified lines"defaultProfile": "openclaw","headless": true,"noSandbox": true,"executablePath": $execPath,"localLaunchTimeoutMs": 45000,"localCdpReadyTimeoutMs": 30000,"extraArgs": ["--no-sandbox","--disable-setuid-sandbox","--no-zygote","--disable-dev-shm-usage","--disable-gpu","--no-first-run","--disable-background-networking","--disable-sync","--disable-translate","--disable-notifications","--disable-speech-api"]}| .agents.defaults.sandbox.browser.allowHostControl = true' <<<"$CONFIG_JSON")fi182 unmodified linesif [ -n "${CLOUDFLARE_PROXY_URL:-}" ]; thenecho "Proxy : ${CLOUDFLARE_PROXY_URL}"fi# HUGGINGCLAW_JUPYTER_ENABLED env var se override allow karo# (env-builder "Enable Jupyter terminal" toggle yahi set karta hai)if hc_is_true "${HUGGINGCLAW_JUPYTER_ENABLED:-false}"; thenRUNTIME_JUPYTER_ENABLED=trueelseRUNTIME_JUPYTER_ENABLED="$DEV_MODE_ENABLED"fi# Add user bin to PATH for jupyter-lab (installed in Dockerfile when DEV_MODE=true)export PATH="$HOME/.local/bin:$PATH"52 unmodified lines}trap graceful_shutdown SIGTERM SIGINTBROWSER_WARMED_UP=falsewarmup_browser() {[ "$BROWSER_SHOULD_ENABLE" = "true" ] || return 0# Only warm up once β gateway restarts should not re-spawn new warmup jobs.[ "$BROWSER_WARMED_UP" = "false" ] || return 0BROWSER_WARMED_UP=true(sleep 8local attemptfor attempt in 1 2 3 4 5 6; doif openclaw browser --browser-profile openclaw start >/dev/null 2>&1; thenopenclaw browser --browser-profile openclaw open about:blank >/dev/null 2>&1 || trueecho "Managed browser ready."return 0fisleep 5doneecho "Warning: managed browser warm-up did not complete; first browser action may need a retry."601 unmodified linesfi# ββ Fix config before running startup commands ββif [ "${AUTO_DOCTOR:-false}" = "true" ]; thenopenclaw doctor --fix || truefi# ββ Arbitrary startup commands from HF Variables/Secrets ββ# Recommended: use one variable, HUGGINGCLAW_RUN, as a full bash script. If the111 unmodified linesecho "WhatsApp Guardian started (PID: $GUARDIAN_PID)"}# ββ Start D-Bus session (once, before gateway loop) ββif [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ]; thenif command -v dbus-launch >/dev/null 2>&1; theneval "$(dbus-launch --sh-syntax 2>/dev/null)" || trueexport DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-disabled:}"elseexport DBUS_SESSION_BUS_ADDRESS="disabled:"fifiwhile true; do# Check health-server process - restart if died unexpectedlyif [ -n "${HEALTH_PID:-}" ] && ! kill -0 "$HEALTH_PID" 2>/dev/null; then19 unmodified linesfifiif [ "${AUTO_DOCTOR:-false}" = "true" ]; thenopenclaw doctor --fix || truefiecho "Launching OpenClaw gateway on port ${GATEWAY_PORT}..."GATEWAY_ARGS=(gateway run --port "${GATEWAY_PORT}" --bind lan)if [ "${GATEWAY_VERBOSE:-0}" = "1" ]; thenGATEWAY_ARGS+=(--verbose)echo "Gateway verbose logging enabled (GATEWAY_VERBOSE=1)"12 unmodified linesGATEWAY_READY_TIMEOUT="${GATEWAY_READY_TIMEOUT:-90}"ready=falsefor ((i=0; i<GATEWAY_READY_TIMEOUT; i++)); doif (echo > /dev/tcp/127.0.0.1/${GATEWAY_PORT}) 2>/dev/null; thenready=truebreakfi8 unmodified linesecho "Gateway failed to start. Last 30 lines of log:"echo "ββββββββββββββββββββββββββββββββββββββββββββ"tail -30 /home/node/.openclaw/gateway.logif [ "$DEV_MODE_ENABLED" = "true" ]; thenecho "Gateway failed β DEV_MODE active, retrying in 10s..."sleep 10continueelseecho "Gateway failed β exiting."exit 1fifi# 11. Start WhatsApp Guardian after the gateway is accepting connections
.env.example+2-9
Dockerfile+2
README.md+3-3
env-builder.js+11-30
iframe-fix.cjs+3-2
start.sh+73-14