Spaces:
Running
Running
Update setup-hf-config.mjs
Browse files- setup-hf-config.mjs +47 -12
setup-hf-config.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
* - agents.defaults.model.primary from OPENCLAW_HF_DEFAULT_MODEL (default: DeepSeek-R1).
|
| 6 |
* - gateway.auth: OPENCLAW_GATEWAY_TOKEN (token) or OPENCLAW_GATEWAY_PASSWORD (password); token wins if both set.
|
| 7 |
* - gateway.controlUi.dangerouslyDisableDeviceAuth when auth is set (no device pairing in Spaces).
|
| 8 |
-
* - gateway.trustedProxies from OPENCLAW_GATEWAY_TRUSTED_PROXIES
|
| 9 |
* - gateway.controlUi.allowedOrigins from OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS (comma-separated origins).
|
| 10 |
* HF_TOKEN is read by the gateway at runtime; this script only writes the above into config.
|
| 11 |
*/
|
|
@@ -16,15 +16,40 @@ const home = process.env.OPENCLAW_HOME || process.env.HOME || "/home/user";
|
|
| 16 |
const stateDir = path.join(home, ".openclaw");
|
| 17 |
const configPath = path.join(stateDir, "openclaw.json");
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
const defaultModel =
|
| 20 |
process.env.OPENCLAW_HF_DEFAULT_MODEL?.trim() || "huggingface/deepseek-ai/DeepSeek-R1";
|
| 21 |
-
const gatewayToken =
|
| 22 |
const gatewayPassword = process.env.OPENCLAW_GATEWAY_PASSWORD?.trim();
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
const trustedProxiesRaw = process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES?.trim();
|
| 25 |
-
const trustedProxies =
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
// Comma-separated origins allowed for Control UI/WebSocket (e.g. https://your-space.hf.space)
|
| 29 |
const allowedOriginsRaw = process.env.OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS?.trim();
|
| 30 |
const allowedOrigins = allowedOriginsRaw
|
|
@@ -66,10 +91,9 @@ if (useTokenAuth || usePasswordAuth) {
|
|
| 66 |
config.gateway.controlUi.dangerouslyDisableDeviceAuth = true;
|
| 67 |
}
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
}
|
| 73 |
|
| 74 |
if (allowedOrigins.length > 0) {
|
| 75 |
if (!config.gateway) config.gateway = {};
|
|
@@ -80,7 +104,18 @@ if (allowedOrigins.length > 0) {
|
|
| 80 |
fs.mkdirSync(stateDir, { recursive: true });
|
| 81 |
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
| 82 |
|
| 83 |
-
//
|
| 84 |
const authKind = useTokenAuth ? "token" : usePasswordAuth ? "password" : "none";
|
| 85 |
-
const parts = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
console.log(`[openclaw-hf-setup] ${parts.join(" ")} -> ${configPath}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
* - agents.defaults.model.primary from OPENCLAW_HF_DEFAULT_MODEL (default: DeepSeek-R1).
|
| 6 |
* - gateway.auth: OPENCLAW_GATEWAY_TOKEN (token) or OPENCLAW_GATEWAY_PASSWORD (password); token wins if both set.
|
| 7 |
* - gateway.controlUi.dangerouslyDisableDeviceAuth when auth is set (no device pairing in Spaces).
|
| 8 |
+
* - gateway.trustedProxies from OPENCLAW_GATEWAY_TRUSTED_PROXIES, or default HF proxy IPs so the UI works without extra config.
|
| 9 |
* - gateway.controlUi.allowedOrigins from OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS (comma-separated origins).
|
| 10 |
* HF_TOKEN is read by the gateway at runtime; this script only writes the above into config.
|
| 11 |
*/
|
|
|
|
| 16 |
const stateDir = path.join(home, ".openclaw");
|
| 17 |
const configPath = path.join(stateDir, "openclaw.json");
|
| 18 |
|
| 19 |
+
// Token: env var, or read from file if OPENCLAW_GATEWAY_TOKEN_FILE is set (for platforms that mount secrets as files)
|
| 20 |
+
function readGatewayToken() {
|
| 21 |
+
const fromEnv = process.env.OPENCLAW_GATEWAY_TOKEN?.trim();
|
| 22 |
+
if (fromEnv) return fromEnv;
|
| 23 |
+
const filePath = process.env.OPENCLAW_GATEWAY_TOKEN_FILE?.trim();
|
| 24 |
+
if (filePath && fs.existsSync(filePath)) {
|
| 25 |
+
try {
|
| 26 |
+
return fs.readFileSync(filePath, "utf-8").trim();
|
| 27 |
+
} catch {
|
| 28 |
+
return "";
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
return "";
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
const defaultModel =
|
| 35 |
process.env.OPENCLAW_HF_DEFAULT_MODEL?.trim() || "huggingface/deepseek-ai/DeepSeek-R1";
|
| 36 |
+
const gatewayToken = readGatewayToken();
|
| 37 |
const gatewayPassword = process.env.OPENCLAW_GATEWAY_PASSWORD?.trim();
|
| 38 |
+
|
| 39 |
+
// Trusted proxies: from env, or default HF Space proxy IPs so the Control UI works without setting OPENCLAW_GATEWAY_TRUSTED_PROXIES
|
| 40 |
+
const DEFAULT_HF_TRUSTED_PROXY_IPS = [
|
| 41 |
+
"10.16.4.123",
|
| 42 |
+
"10.16.34.155",
|
| 43 |
+
"10.20.1.9",
|
| 44 |
+
"10.20.1.222",
|
| 45 |
+
"10.20.26.157",
|
| 46 |
+
"10.20.31.87",
|
| 47 |
+
];
|
| 48 |
const trustedProxiesRaw = process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES?.trim();
|
| 49 |
+
const trustedProxies =
|
| 50 |
+
trustedProxiesRaw && trustedProxiesRaw.length > 0
|
| 51 |
+
? trustedProxiesRaw.split(",").map((s) => s.trim()).filter(Boolean)
|
| 52 |
+
: DEFAULT_HF_TRUSTED_PROXY_IPS;
|
| 53 |
// Comma-separated origins allowed for Control UI/WebSocket (e.g. https://your-space.hf.space)
|
| 54 |
const allowedOriginsRaw = process.env.OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS?.trim();
|
| 55 |
const allowedOrigins = allowedOriginsRaw
|
|
|
|
| 91 |
config.gateway.controlUi.dangerouslyDisableDeviceAuth = true;
|
| 92 |
}
|
| 93 |
|
| 94 |
+
// Always set trustedProxies (we have a default for HF so the Control UI works behind the HF proxy)
|
| 95 |
+
if (!config.gateway) config.gateway = {};
|
| 96 |
+
config.gateway.trustedProxies = trustedProxies;
|
|
|
|
| 97 |
|
| 98 |
if (allowedOrigins.length > 0) {
|
| 99 |
if (!config.gateway) config.gateway = {};
|
|
|
|
| 104 |
fs.mkdirSync(stateDir, { recursive: true });
|
| 105 |
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
| 106 |
|
| 107 |
+
// Startup log: confirm env was applied (check token_present=1 and auth=token so the UI can connect)
|
| 108 |
const authKind = useTokenAuth ? "token" : usePasswordAuth ? "password" : "none";
|
| 109 |
+
const parts = [
|
| 110 |
+
`token_present=${useTokenAuth ? "1" : "0"}`,
|
| 111 |
+
`password_present=${usePasswordAuth ? "1" : "0"}`,
|
| 112 |
+
`auth=${authKind}`,
|
| 113 |
+
`trustedProxies=${trustedProxies.length}`,
|
| 114 |
+
`allowedOrigins=${allowedOrigins.length}`,
|
| 115 |
+
];
|
| 116 |
console.log(`[openclaw-hf-setup] ${parts.join(" ")} -> ${configPath}`);
|
| 117 |
+
if (authKind === "none") {
|
| 118 |
+
console.warn(
|
| 119 |
+
"[openclaw-hf-setup] No auth set. Add OPENCLAW_GATEWAY_TOKEN or OPENCLAW_GATEWAY_PASSWORD in Space Secrets, then restart.",
|
| 120 |
+
);
|
| 121 |
+
}
|