File size: 1,957 Bytes
53451c9
963abcf
 
 
 
 
53451c9
 
 
963abcf
53451c9
 
 
 
 
 
 
 
 
963abcf
53451c9
 
963abcf
53451c9
 
 
 
 
 
 
 
 
 
 
 
 
 
963abcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
# OpenClaw Gateway entrypoint for Hugging Face Spaces
# - Persistent storage
# - Onboarding with HF
# - Force OpenRouter search
# - Disable Brave completely

set -e

# 1️⃣ Persistence
if mkdir -p /data/.openclaw 2>/dev/null; then
  export OPENCLAW_HOME=/data
else
  export OPENCLAW_HOME=/home/user
  mkdir -p /home/user/.openclaw
fi

CONFIG_FILE="${OPENCLAW_HOME}/.openclaw/openclaw.json"

# 2️⃣ Run onboarding if needed
if [ -n "${HF_TOKEN}" ] && [ ! -f "$CONFIG_FILE" ]; then
  export HF_TOKEN

  if [ -n "${OPENCLAW_GATEWAY_TOKEN}" ]; then
    node /app/openclaw.mjs onboard --non-interactive --mode local \
      --auth-choice huggingface-api-key --huggingface-api-key "$HF_TOKEN" \
      --no-install-daemon --skip-health \
      --gateway-port 7860 --gateway-bind lan \
      --gateway-token "$OPENCLAW_GATEWAY_TOKEN"
  else
    node /app/openclaw.mjs onboard --non-interactive --mode local \
      --auth-choice huggingface-api-key --huggingface-api-key "$HF_TOKEN" \
      --no-install-daemon --skip-health \
      --gateway-port 7860 --gateway-bind lan
  fi
fi

# 3️⃣ 🔥 Force OpenRouter & Remove Brave

if [ -n "${OPENROUTER_API_KEY}" ]; then
  echo "[setup.sh] Forcing OpenRouter (Perplexity) as web search..."

  cat > "$CONFIG_FILE" <<EOF
{
  "agents": {
    "defaults": {
      "model": {
        "primary": "huggingface/deepseek-ai/DeepSeek-R1"
      }
    }
  },
  "tools": {
    "web": {
      "enabled": true,
      "search": {
        "provider": "perplexity",
        "perplexity": {
          "apiKey": "${OPENROUTER_API_KEY}",
          "baseUrl": "https://openrouter.ai/api/v1",
          "model": "perplexity/sonar-pro"
        }
      }
    }
  }
}
EOF

  echo "[setup.sh] OpenRouter configured. Brave disabled."
else
  echo "[setup.sh] WARNING: OPENROUTER_API_KEY not set. Web search disabled."
fi

# 4️⃣ Start Gateway
exec node /app/openclaw.mjs gateway --allow-unconfigured --bind lan --port 7860 "$@"