8900 commited on
Update setup-hf-config.mjs
Browse files- setup-hf-config.mjs +77 -54
setup-hf-config.mjs
CHANGED
|
@@ -2,73 +2,96 @@
|
|
| 2 |
import fs from "fs";
|
| 3 |
import path from "path";
|
| 4 |
|
| 5 |
-
const
|
| 6 |
-
const
|
| 7 |
-
const
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
const
|
| 12 |
-
|
| 13 |
-
const
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
if (v) return v;
|
| 17 |
}
|
| 18 |
return "";
|
| 19 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
let config = {};
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
//
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
(env("GROQ_API_KEY") && "groq/llama-3.3-70b-versatile") ||
|
| 29 |
-
"huggingface/deepseek-ai/DeepSeek-R1";
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
//
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
mode: "token",
|
| 43 |
-
token: token || "123456"
|
| 44 |
-
},
|
| 45 |
-
trustedProxies: ["*"],
|
| 46 |
-
controlUi: {
|
| 47 |
-
dangerouslyDisableDeviceAuth: true
|
| 48 |
-
}
|
| 49 |
-
};
|
| 50 |
|
| 51 |
-
//
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
config.channels = {
|
| 55 |
-
telegram: {
|
| 56 |
-
enabled: true,
|
| 57 |
-
botToken: tg
|
| 58 |
-
}
|
| 59 |
-
};
|
| 60 |
}
|
| 61 |
|
| 62 |
-
//
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
};
|
| 71 |
|
| 72 |
-
fs.
|
|
|
|
| 73 |
|
| 74 |
console.log("🔥 OpenClaw HF 生产级配置完成");
|
|
|
|
| 2 |
import fs from "fs";
|
| 3 |
import path from "path";
|
| 4 |
|
| 5 |
+
const home = process.env.OPENCLAW_HOME || process.env.HOME || "/home/user";
|
| 6 |
+
const stateDir = path.join(home, ".openclaw");
|
| 7 |
+
const configPath = path.join(stateDir, "openclaw.json");
|
| 8 |
|
| 9 |
+
// 读取 token/password
|
| 10 |
+
function readGatewayToken() {
|
| 11 |
+
const fromEnv = process.env.OPENCLAW_GATEWAY_TOKEN?.trim();
|
| 12 |
+
if (fromEnv) return fromEnv;
|
| 13 |
+
const filePath = process.env.OPENCLAW_GATEWAY_TOKEN_FILE?.trim();
|
| 14 |
+
if (filePath && fs.existsSync(filePath)) {
|
| 15 |
+
try { return fs.readFileSync(filePath, "utf-8").trim(); } catch { return ""; }
|
|
|
|
| 16 |
}
|
| 17 |
return "";
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
const defaultModel =
|
| 21 |
+
process.env.OPENCLAW_HF_DEFAULT_MODEL?.trim() || "huggingface/deepseek-ai/DeepSeek-R1";
|
| 22 |
+
const gatewayToken = readGatewayToken();
|
| 23 |
+
const gatewayPassword = process.env.OPENCLAW_GATEWAY_PASSWORD?.trim();
|
| 24 |
+
|
| 25 |
+
// Trusted proxies for HF
|
| 26 |
+
const DEFAULT_HF_TRUSTED_PROXY_IPS = [
|
| 27 |
+
"10.16.4.123","10.16.34.155","10.20.1.9","10.20.1.222","10.20.26.157","10.20.31.87"
|
| 28 |
+
];
|
| 29 |
+
const trustedProxiesRaw = process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES?.trim();
|
| 30 |
+
const trustedProxies = trustedProxiesRaw
|
| 31 |
+
? trustedProxiesRaw.split(",").map(s=>s.trim()).filter(Boolean)
|
| 32 |
+
: DEFAULT_HF_TRUSTED_PROXY_IPS;
|
| 33 |
+
|
| 34 |
+
// Control UI origins
|
| 35 |
+
const allowedOriginsRaw = process.env.OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS?.trim();
|
| 36 |
+
const allowedOrigins = allowedOriginsRaw
|
| 37 |
+
? allowedOriginsRaw.split(",").map(s=>s.trim()).filter(Boolean)
|
| 38 |
+
: [];
|
| 39 |
|
| 40 |
let config = {};
|
| 41 |
+
if (fs.existsSync(configPath)) {
|
| 42 |
+
try { config = JSON.parse(fs.readFileSync(configPath,"utf-8")); } catch {}
|
| 43 |
+
}
|
| 44 |
|
| 45 |
+
// Agents / model
|
| 46 |
+
config.agents ??= {};
|
| 47 |
+
config.agents.defaults ??= {};
|
| 48 |
+
config.agents.defaults.model ??= {};
|
| 49 |
+
config.agents.defaults.model.primary = defaultModel;
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
// Auth
|
| 52 |
+
const useTokenAuth = Boolean(gatewayToken);
|
| 53 |
+
const usePasswordAuth = Boolean(gatewayPassword) && !useTokenAuth;
|
| 54 |
+
config.gateway ??= {};
|
| 55 |
+
config.gateway.auth ??= {};
|
| 56 |
+
if (useTokenAuth) {
|
| 57 |
+
config.gateway.auth.mode = "token";
|
| 58 |
+
config.gateway.auth.token = gatewayToken;
|
| 59 |
+
} else if (usePasswordAuth) {
|
| 60 |
+
config.gateway.auth.mode = "password";
|
| 61 |
+
config.gateway.auth.password = gatewayPassword;
|
| 62 |
+
}
|
| 63 |
|
| 64 |
+
// Disable device pairing (HF Spaces)
|
| 65 |
+
config.gateway.controlUi ??= {};
|
| 66 |
+
config.gateway.controlUi.dangerouslyDisableDeviceAuth = true;
|
| 67 |
|
| 68 |
+
// Trusted proxies
|
| 69 |
+
config.gateway.trustedProxies = trustedProxies;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
// Allowed origins
|
| 72 |
+
if (allowedOrigins.length>0){
|
| 73 |
+
config.gateway.controlUi.allowedOrigins = allowedOrigins;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
+
// Telegram
|
| 77 |
+
const tg = process.env.TELEGRAM_BOT_TOKEN?.trim();
|
| 78 |
+
if(tg){
|
| 79 |
+
config.channels ??= {};
|
| 80 |
+
config.channels.telegram ??= {};
|
| 81 |
+
config.channels.telegram.enabled = true;
|
| 82 |
+
config.channels.telegram.botToken = tg;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// Inject env for providers
|
| 86 |
+
config.env ??= {};
|
| 87 |
+
config.env.vars = {
|
| 88 |
+
GEMINI_API_KEY: process.env.GEMINI_API_KEY,
|
| 89 |
+
GROQ_API_KEY: process.env.GROQ_API_KEY,
|
| 90 |
+
HF_TOKEN: process.env.HF_TOKEN,
|
| 91 |
+
TELEGRAM_BOT_TOKEN: tg,
|
| 92 |
};
|
| 93 |
|
| 94 |
+
fs.mkdirSync(stateDir,{recursive:true});
|
| 95 |
+
fs.writeFileSync(configPath, JSON.stringify(config,null,2),"utf-8");
|
| 96 |
|
| 97 |
console.log("🔥 OpenClaw HF 生产级配置完成");
|