renminwansui1976 commited on
Commit
d4ca08a
·
unverified ·
1 Parent(s): ed38715

更新 start.sh

Browse files
Files changed (1) hide show
  1. start.sh +31 -6
start.sh CHANGED
@@ -3,6 +3,32 @@ set -euo pipefail
3
 
4
  LITELLM_PID=""
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # ── 1. Check if LiteLLM should be enabled ─────────────────────────────────────
7
  # Both LITELLM_API_KEY and LITELLM_MODEL must be set to enable the proxy.
8
  # If either is missing, OpenClaw starts without a pre-configured AI backend
@@ -10,15 +36,14 @@ LITELLM_PID=""
10
  if [ -z "${LITELLM_API_KEY:-}" ] || [ -z "${LITELLM_MODEL:-}" ]; then
11
  echo "[start.sh] LITELLM_API_KEY or LITELLM_MODEL not set — starting OpenClaw without LiteLLM proxy"
12
  echo "[start.sh] You can configure AI providers through OpenClaw's UI after startup"
13
- exec openclaw gateway --port 7860 --bind lan --allow-unconfigured
14
  fi
15
 
16
  # ── 2. Write LiteLLM proxy config ─────────────────────────────────────────────
17
  LITELLM_CONFIG=/tmp/litellm_config.yaml
18
 
19
- # OpenClaw's internally stored default model name we register it in LiteLLM
20
- # so any model name OpenClaw sends will be routed to the user's actual provider.
21
- # The wildcard entry ("*") catches any other model name OpenClaw might send.
22
  {
23
  echo "model_list:"
24
  echo " - model_name: \"*\""
@@ -56,7 +81,7 @@ WAITED=0
56
  until curl -sf http://127.0.0.1:4000/health/liveliness > /dev/null 2>&1; do
57
  if [ "$WAITED" -ge "$MAX_WAIT" ]; then
58
  echo "[start.sh] WARNING: LiteLLM not healthy after ${MAX_WAIT}s — starting OpenClaw without proxy"
59
- exec openclaw gateway --port 7860 --bind lan --allow-unconfigured
60
  fi
61
  sleep 1
62
  WAITED=$((WAITED + 1))
@@ -67,4 +92,4 @@ echo "[start.sh] LiteLLM healthy after ${WAITED}s"
67
  exec env \
68
  OPENAI_API_KEY=litellm-proxy \
69
  OPENAI_BASE_URL=http://127.0.0.1:4000 \
70
- openclaw gateway --port 7860 --bind lan --allow-unconfigured
 
3
 
4
  LITELLM_PID=""
5
 
6
+ # ── 0. Write openclaw.json before gateway starts ──────────────────────────────
7
+ # HF Space domains are dynamically assigned, so we can't hardcode allowedOrigins.
8
+ # dangerouslyAllowHostHeaderOriginFallback lets OpenClaw trust the Host header
9
+ # as the origin — the standard fix for dynamic-domain deployments (Zeabur, HF, etc.)
10
+ OPENCLAW_CONFIG_DIR="${HOME}/.openclaw"
11
+ OPENCLAW_CONFIG="${OPENCLAW_CONFIG_DIR}/openclaw.json"
12
+ mkdir -p "$OPENCLAW_CONFIG_DIR"
13
+
14
+ if [ ! -f "$OPENCLAW_CONFIG" ]; then
15
+ cat > "$OPENCLAW_CONFIG" << 'OPENCLAW_JSON'
16
+ {
17
+ "gateway": {
18
+ "bind": "lan",
19
+ "controlUi": {
20
+ "dangerouslyAllowHostHeaderOriginFallback": true
21
+ }
22
+ }
23
+ }
24
+ OPENCLAW_JSON
25
+ echo "[start.sh] openclaw.json written (dangerouslyAllowHostHeaderOriginFallback=true)"
26
+ else
27
+ echo "[start.sh] openclaw.json exists — patching bind and controlUi settings"
28
+ openclaw config set gateway.bind lan 2>/dev/null || true
29
+ openclaw config set gateway.controlUi.dangerouslyAllowHostHeaderOriginFallback true 2>/dev/null || true
30
+ fi
31
+
32
  # ── 1. Check if LiteLLM should be enabled ─────────────────────────────────────
33
  # Both LITELLM_API_KEY and LITELLM_MODEL must be set to enable the proxy.
34
  # If either is missing, OpenClaw starts without a pre-configured AI backend
 
36
  if [ -z "${LITELLM_API_KEY:-}" ] || [ -z "${LITELLM_MODEL:-}" ]; then
37
  echo "[start.sh] LITELLM_API_KEY or LITELLM_MODEL not set — starting OpenClaw without LiteLLM proxy"
38
  echo "[start.sh] You can configure AI providers through OpenClaw's UI after startup"
39
+ exec openclaw gateway --port 7860 --allow-unconfigured
40
  fi
41
 
42
  # ── 2. Write LiteLLM proxy config ─────────────────────────────────────────────
43
  LITELLM_CONFIG=/tmp/litellm_config.yaml
44
 
45
+ # The wildcard model_name ("*") catches any model name OpenClaw sends,
46
+ # routing it to the user's configured provider via LiteLLM.
 
47
  {
48
  echo "model_list:"
49
  echo " - model_name: \"*\""
 
81
  until curl -sf http://127.0.0.1:4000/health/liveliness > /dev/null 2>&1; do
82
  if [ "$WAITED" -ge "$MAX_WAIT" ]; then
83
  echo "[start.sh] WARNING: LiteLLM not healthy after ${MAX_WAIT}s — starting OpenClaw without proxy"
84
+ exec openclaw gateway --port 7860 --allow-unconfigured
85
  fi
86
  sleep 1
87
  WAITED=$((WAITED + 1))
 
92
  exec env \
93
  OPENAI_API_KEY=litellm-proxy \
94
  OPENAI_BASE_URL=http://127.0.0.1:4000 \
95
+ openclaw gateway --port 7860 --allow-unconfigured