Update setup-hf-config.mjs
Browse files- setup-hf-config.mjs +17 -2
setup-hf-config.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
#!/usr/bin/env node
|
| 2 |
/**
|
| 3 |
* One-time setup for OpenClaw on Hugging Face Spaces.
|
| 4 |
-
*
|
| 5 |
* - agents.defaults.model.primary uses Hugging Face Inference (from OPENCLAW_HF_DEFAULT_MODEL or default).
|
| 6 |
* - gateway.auth.token is set from OPENCLAW_GATEWAY_TOKEN if provided.
|
| 7 |
-
*
|
|
|
|
| 8 |
*/
|
| 9 |
import fs from "node:fs";
|
| 10 |
import path from "node:path";
|
|
@@ -16,6 +17,11 @@ const configPath = path.join(stateDir, "openclaw.json");
|
|
| 16 |
const defaultModel =
|
| 17 |
process.env.OPENCLAW_HF_DEFAULT_MODEL?.trim() || "huggingface/deepseek-ai/DeepSeek-R1";
|
| 18 |
const gatewayToken = process.env.OPENCLAW_GATEWAY_TOKEN?.trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
let config = {};
|
| 21 |
if (fs.existsSync(configPath)) {
|
|
@@ -36,5 +42,14 @@ if (gatewayToken && !config.gateway.auth) config.gateway.auth = {};
|
|
| 36 |
if (gatewayToken) config.gateway.auth.mode = "token";
|
| 37 |
if (gatewayToken) config.gateway.auth.token = gatewayToken;
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
fs.mkdirSync(stateDir, { recursive: true });
|
| 40 |
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
|
|
| 1 |
#!/usr/bin/env node
|
| 2 |
/**
|
| 3 |
* One-time setup for OpenClaw on Hugging Face Spaces.
|
| 4 |
+
* Runs at container startup; writes or merges openclaw.json so that:
|
| 5 |
* - agents.defaults.model.primary uses Hugging Face Inference (from OPENCLAW_HF_DEFAULT_MODEL or default).
|
| 6 |
* - gateway.auth.token is set from OPENCLAW_GATEWAY_TOKEN if provided.
|
| 7 |
+
* - gateway.trustedProxies is set from OPENCLAW_GATEWAY_TRUSTED_PROXIES (comma-separated IPs) if provided.
|
| 8 |
+
* HF_TOKEN is read by the gateway from the environment (Space Secrets); this script only sets the default model, optional token, and optional trusted proxies in config.
|
| 9 |
*/
|
| 10 |
import fs from "node:fs";
|
| 11 |
import path from "node:path";
|
|
|
|
| 17 |
const defaultModel =
|
| 18 |
process.env.OPENCLAW_HF_DEFAULT_MODEL?.trim() || "huggingface/deepseek-ai/DeepSeek-R1";
|
| 19 |
const gatewayToken = process.env.OPENCLAW_GATEWAY_TOKEN?.trim();
|
| 20 |
+
// Comma-separated list of proxy IPs (e.g. HF Space proxy); written into gateway.trustedProxies
|
| 21 |
+
const trustedProxiesRaw = process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES?.trim();
|
| 22 |
+
const trustedProxies = trustedProxiesRaw
|
| 23 |
+
? trustedProxiesRaw.split(",").map((s) => s.trim()).filter(Boolean)
|
| 24 |
+
: [];
|
| 25 |
|
| 26 |
let config = {};
|
| 27 |
if (fs.existsSync(configPath)) {
|
|
|
|
| 42 |
if (gatewayToken) config.gateway.auth.mode = "token";
|
| 43 |
if (gatewayToken) config.gateway.auth.token = gatewayToken;
|
| 44 |
|
| 45 |
+
// So Control UI can connect with token only (no device pairing); Spaces have no CLI for approve.
|
| 46 |
+
if (gatewayToken && !config.gateway.controlUi) config.gateway.controlUi = {};
|
| 47 |
+
if (gatewayToken) config.gateway.controlUi.dangerouslyDisableDeviceAuth = true;
|
| 48 |
+
|
| 49 |
+
if (trustedProxies.length > 0) {
|
| 50 |
+
if (!config.gateway) config.gateway = {};
|
| 51 |
+
config.gateway.trustedProxies = trustedProxies;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
fs.mkdirSync(stateDir, { recursive: true });
|
| 55 |
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|