tao-shen commited on
Commit
e6c8a11
·
1 Parent(s): 04264a9

fix: remove empty apiKey (config invalid), add HF origins to CSP allowedOrigins

Browse files
Files changed (2) hide show
  1. openclaw.json +3 -1
  2. scripts/sync_hf.py +18 -7
openclaw.json CHANGED
@@ -12,7 +12,9 @@
12
  "controlUi": {
13
  "allowInsecureAuth": true,
14
  "allowedOrigins": [
15
- "https://huggingface.co"
 
 
16
  ]
17
  }
18
  },
 
12
  "controlUi": {
13
  "allowInsecureAuth": true,
14
  "allowedOrigins": [
15
+ "https://huggingface.co",
16
+ "https://*.hf.space",
17
+ "https://tao-shen-huggingclaw.hf.space"
18
  ]
19
  }
20
  },
scripts/sync_hf.py CHANGED
@@ -252,14 +252,23 @@ class OpenClawFullSync:
252
  default_src = Path(__file__).parent / "openclaw.json.default"
253
  if default_src.exists():
254
  shutil.copy2(str(default_src), str(config_path))
255
- # Replace placeholder with actual env var value
256
- text = config_path.read_text()
257
- if "__OPENROUTER_API_KEY__" in text:
 
258
  if OPENROUTER_API_KEY:
259
- text = text.replace("__OPENROUTER_API_KEY__", OPENROUTER_API_KEY)
 
 
260
  else:
261
- text = text.replace("__OPENROUTER_API_KEY__", "")
262
- config_path.write_text(text)
 
 
 
 
 
 
263
  print("[SYNC] Created openclaw.json from default template")
264
  else:
265
  with open(config_path, "w") as f:
@@ -323,7 +332,9 @@ class OpenClawFullSync:
323
  "controlUi": {
324
  "allowInsecureAuth": True,
325
  "allowedOrigins": [
326
- "https://huggingface.co"
 
 
327
  ]
328
  }
329
  }
 
252
  default_src = Path(__file__).parent / "openclaw.json.default"
253
  if default_src.exists():
254
  shutil.copy2(str(default_src), str(config_path))
255
+ # Replace placeholder or remove provider if no API key
256
+ try:
257
+ with open(config_path, "r") as f:
258
+ cfg = json.load(f)
259
  if OPENROUTER_API_KEY:
260
+ # Replace placeholder with actual key
261
+ if "models" in cfg and "providers" in cfg["models"] and "openrouter" in cfg["models"]["providers"]:
262
+ cfg["models"]["providers"]["openrouter"]["apiKey"] = OPENROUTER_API_KEY
263
  else:
264
+ # No API key: remove provider entirely to avoid config validation error
265
+ if "models" in cfg and "providers" in cfg["models"]:
266
+ cfg["models"]["providers"].pop("openrouter", None)
267
+ print("[SYNC] No OPENROUTER_API_KEY — removed openrouter provider from config")
268
+ with open(config_path, "w") as f:
269
+ json.dump(cfg, f, indent=2)
270
+ except Exception as e:
271
+ print(f"[SYNC] Warning: failed to patch default config: {e}")
272
  print("[SYNC] Created openclaw.json from default template")
273
  else:
274
  with open(config_path, "w") as f:
 
332
  "controlUi": {
333
  "allowInsecureAuth": True,
334
  "allowedOrigins": [
335
+ "https://huggingface.co",
336
+ "https://*.hf.space",
337
+ "https://tao-shen-huggingclaw.hf.space"
338
  ]
339
  }
340
  }