8900 commited on
Update setup-hf-config.mjs
Browse files- setup-hf-config.mjs +41 -32
setup-hf-config.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
#!/usr/bin/env node
|
| 2 |
/**
|
| 3 |
-
* OpenClaw HF Spaces 配置脚本 -
|
| 4 |
-
*
|
| 5 |
-
* 纯 HF Spaces 部署,不使用任何外部代理
|
| 6 |
*/
|
| 7 |
|
| 8 |
import fs from "node:fs";
|
|
@@ -12,7 +11,9 @@ const HOME = process.env.OPENCLAW_HOME || process.env.HOME || "/home/user";
|
|
| 12 |
const STATE_DIR = path.join(HOME, ".openclaw");
|
| 13 |
const CONFIG_PATH = path.join(STATE_DIR, "openclaw.json");
|
| 14 |
|
| 15 |
-
console.log("
|
|
|
|
|
|
|
| 16 |
|
| 17 |
// ====================== 工具函数 ======================
|
| 18 |
function readGatewayToken() {
|
|
@@ -24,7 +25,7 @@ function readGatewayToken() {
|
|
| 24 |
try {
|
| 25 |
return fs.readFileSync(filePath, "utf-8").trim();
|
| 26 |
} catch (e) {
|
| 27 |
-
console.warn("
|
| 28 |
}
|
| 29 |
}
|
| 30 |
return "";
|
|
@@ -40,15 +41,12 @@ const defaultModel = (process.env.OPENCLAW_HF_DEFAULT_MODEL || "").trim() || "go
|
|
| 40 |
const gatewayToken = readGatewayToken();
|
| 41 |
const gatewayPassword = (process.env.OPENCLAW_GATEWAY_PASSWORD || "").trim();
|
| 42 |
|
| 43 |
-
const
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
.length > 0
|
| 50 |
-
? parseList(process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES)
|
| 51 |
-
: DEFAULT_TRUSTED_PROXIES;
|
| 52 |
|
| 53 |
const allowedOrigins = parseList(process.env.OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS || "");
|
| 54 |
|
|
@@ -59,22 +57,22 @@ try {
|
|
| 59 |
config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
|
| 60 |
}
|
| 61 |
} catch (e) {
|
| 62 |
-
console.log("
|
| 63 |
}
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
| 68 |
config.agents.defaults.model.primary = defaultModel;
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
// Auth
|
| 73 |
const useToken = gatewayToken.length > 0;
|
| 74 |
const usePassword = gatewayPassword.length > 0 && !useToken;
|
| 75 |
|
| 76 |
if (useToken || usePassword) {
|
| 77 |
-
|
| 78 |
if (useToken) {
|
| 79 |
config.gateway.auth.mode = "token";
|
| 80 |
config.gateway.auth.token = gatewayToken;
|
|
@@ -84,34 +82,45 @@ if (useToken || usePassword) {
|
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
| 87 |
-
// Control UI
|
| 88 |
-
|
| 89 |
config.gateway.controlUi.dangerouslyDisableDeviceAuth = true;
|
| 90 |
config.gateway.controlUi.allowInsecureAuth = true;
|
| 91 |
-
config.gateway.controlUi.gatewayUrl = "wss://echo8900-hugging-claw.hf.space";
|
| 92 |
|
| 93 |
if (allowedOrigins.length > 0) {
|
| 94 |
config.gateway.controlUi.allowedOrigins = allowedOrigins;
|
| 95 |
}
|
| 96 |
|
| 97 |
-
// Trusted
|
| 98 |
config.gateway.trustedProxies = trustedProxies;
|
| 99 |
|
| 100 |
// ====================== 写入配置 ======================
|
| 101 |
try {
|
| 102 |
fs.mkdirSync(STATE_DIR, { recursive: true });
|
| 103 |
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
| 104 |
-
console.log(
|
| 105 |
} catch (e) {
|
| 106 |
-
console.error(
|
| 107 |
process.exit(1);
|
| 108 |
}
|
| 109 |
|
| 110 |
-
// ====================== 日志总结 ======================
|
| 111 |
const authKind = useToken ? "token" : (usePassword ? "password" : "none");
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
if (authKind === "none") {
|
| 114 |
-
console.warn("
|
| 115 |
}
|
| 116 |
|
| 117 |
-
console.log("
|
|
|
|
|
|
| 1 |
#!/usr/bin/env node
|
| 2 |
/**
|
| 3 |
+
* OpenClaw HF Spaces 配置脚本 - 最终优化版
|
| 4 |
+
* 日志输出清晰、专业、结构化
|
|
|
|
| 5 |
*/
|
| 6 |
|
| 7 |
import fs from "node:fs";
|
|
|
|
| 11 |
const STATE_DIR = path.join(HOME, ".openclaw");
|
| 12 |
const CONFIG_PATH = path.join(STATE_DIR, "openclaw.json");
|
| 13 |
|
| 14 |
+
console.log("=".repeat(60));
|
| 15 |
+
console.log("[openclaw-hf-setup] Starting configuration...");
|
| 16 |
+
console.log("=".repeat(60));
|
| 17 |
|
| 18 |
// ====================== 工具函数 ======================
|
| 19 |
function readGatewayToken() {
|
|
|
|
| 25 |
try {
|
| 26 |
return fs.readFileSync(filePath, "utf-8").trim();
|
| 27 |
} catch (e) {
|
| 28 |
+
console.warn(" ⚠️ Failed to read token file");
|
| 29 |
}
|
| 30 |
}
|
| 31 |
return "";
|
|
|
|
| 41 |
const gatewayToken = readGatewayToken();
|
| 42 |
const gatewayPassword = (process.env.OPENCLAW_GATEWAY_PASSWORD || "").trim();
|
| 43 |
|
| 44 |
+
const trustedProxies = parseList(process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES || "").length > 0
|
| 45 |
+
? parseList(process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES)
|
| 46 |
+
: [
|
| 47 |
+
"10.16.0.0/12", "10.20.0.0/12", "10.0.0.0/8",
|
| 48 |
+
"172.16.0.0/12", "192.168.0.0/16"
|
| 49 |
+
];
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
const allowedOrigins = parseList(process.env.OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS || "");
|
| 52 |
|
|
|
|
| 57 |
config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
|
| 58 |
}
|
| 59 |
} catch (e) {
|
| 60 |
+
console.log(" ⚠️ Config file broken, creating new one");
|
| 61 |
}
|
| 62 |
|
| 63 |
+
// Agents
|
| 64 |
+
config.agents = config.agents || {};
|
| 65 |
+
config.agents.defaults = config.agents.defaults || {};
|
| 66 |
+
config.agents.defaults.model = config.agents.defaults.model || {};
|
| 67 |
config.agents.defaults.model.primary = defaultModel;
|
| 68 |
|
| 69 |
+
// Gateway Auth
|
| 70 |
+
config.gateway = config.gateway || {};
|
|
|
|
| 71 |
const useToken = gatewayToken.length > 0;
|
| 72 |
const usePassword = gatewayPassword.length > 0 && !useToken;
|
| 73 |
|
| 74 |
if (useToken || usePassword) {
|
| 75 |
+
config.gateway.auth = config.gateway.auth || {};
|
| 76 |
if (useToken) {
|
| 77 |
config.gateway.auth.mode = "token";
|
| 78 |
config.gateway.auth.token = gatewayToken;
|
|
|
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
+
// Control UI
|
| 86 |
+
config.gateway.controlUi = config.gateway.controlUi || {};
|
| 87 |
config.gateway.controlUi.dangerouslyDisableDeviceAuth = true;
|
| 88 |
config.gateway.controlUi.allowInsecureAuth = true;
|
| 89 |
+
config.gateway.controlUi.gatewayUrl = "wss://echo8900-hugging-claw.hf.space";
|
| 90 |
|
| 91 |
if (allowedOrigins.length > 0) {
|
| 92 |
config.gateway.controlUi.allowedOrigins = allowedOrigins;
|
| 93 |
}
|
| 94 |
|
| 95 |
+
// Trusted Proxies
|
| 96 |
config.gateway.trustedProxies = trustedProxies;
|
| 97 |
|
| 98 |
// ====================== 写入配置 ======================
|
| 99 |
try {
|
| 100 |
fs.mkdirSync(STATE_DIR, { recursive: true });
|
| 101 |
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
| 102 |
+
console.log("✅ Config successfully written to " + CONFIG_PATH);
|
| 103 |
} catch (e) {
|
| 104 |
+
console.error("❌ Failed to write config: " + e.message);
|
| 105 |
process.exit(1);
|
| 106 |
}
|
| 107 |
|
| 108 |
+
// ====================== 美化日志总结 ======================
|
| 109 |
const authKind = useToken ? "token" : (usePassword ? "password" : "none");
|
| 110 |
+
|
| 111 |
+
console.log("\n" + "=".repeat(60));
|
| 112 |
+
console.log("📋 CONFIG SUMMARY");
|
| 113 |
+
console.log("=".repeat(60));
|
| 114 |
+
console.log(` Auth Mode : ${authKind}`);
|
| 115 |
+
console.log(` Trusted Proxies : ${trustedProxies.length} (${trustedProxies.join(", ")})`);
|
| 116 |
+
console.log(` Default Model : ${defaultModel}`);
|
| 117 |
+
console.log(` WebSocket URL : ${config.gateway.controlUi.gatewayUrl}`);
|
| 118 |
+
console.log(` Device Auth : ${config.gateway.controlUi.dangerouslyDisableDeviceAuth ? "Disabled" : "Enabled"}`);
|
| 119 |
+
console.log("=".repeat(60));
|
| 120 |
+
|
| 121 |
if (authKind === "none") {
|
| 122 |
+
console.warn("⚠️ WARNING: No auth set! Please add OPENCLAW_GATEWAY_TOKEN in Space Secrets.");
|
| 123 |
}
|
| 124 |
|
| 125 |
+
console.log("🚀 Gateway should start normally now.");
|
| 126 |
+
console.log("=".repeat(60));
|