8900 commited on
Commit ·
2dc6956
1
Parent(s): d5943c7
Update setup-hf-config.mjs
Browse files- setup-hf-config.mjs +57 -57
setup-hf-config.mjs
CHANGED
|
@@ -18,91 +18,97 @@ var gatewayToken = (process.env.OPENCLAW_GATEWAY_TOKEN || "").trim();
|
|
| 18 |
var gatewayPassword = (process.env.OPENCLAW_GATEWAY_PASSWORD || "").trim();
|
| 19 |
|
| 20 |
if (!gatewayToken && !gatewayPassword) {
|
| 21 |
-
console.error("[setup] ERROR:
|
| 22 |
process.exit(1);
|
| 23 |
}
|
| 24 |
|
| 25 |
// ---- default model ----
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
// ---- dynamic
|
| 29 |
-
//
|
| 30 |
-
// We also write them into env.vars so OpenClaw injects them into its runtime.
|
| 31 |
-
// Exclude internal/system vars, include only provider-shaped keys.
|
| 32 |
var EXCLUDE_PREFIXES = [
|
| 33 |
-
"OPENCLAW_", "SPACE_", "SYSTEM_", "
|
| 34 |
"NODE_", "PATH", "HOME", "USER", "PWD", "LANG", "LC_"
|
| 35 |
];
|
|
|
|
| 36 |
var INCLUDE_SUFFIXES = [
|
| 37 |
"_API_KEY", "_SECRET_KEY", "_ACCESS_TOKEN",
|
| 38 |
-
"_BOT_TOKEN", "_AUTH_TOKEN", "_APP_KEY"
|
| 39 |
];
|
| 40 |
|
| 41 |
function isProviderKey(k) {
|
| 42 |
-
for (var
|
| 43 |
-
|
| 44 |
-
}
|
| 45 |
-
for (var j = 0; j < INCLUDE_SUFFIXES.length; j++) {
|
| 46 |
-
var s = INCLUDE_SUFFIXES[j];
|
| 47 |
-
if (k.length > s.length && k.indexOf(s) === k.length - s.length) return true;
|
| 48 |
-
}
|
| 49 |
return false;
|
| 50 |
}
|
| 51 |
|
|
|
|
| 52 |
var detectedKeys = Object.keys(process.env)
|
| 53 |
-
.filter(
|
| 54 |
.sort();
|
| 55 |
|
| 56 |
console.log("[setup] Detected provider keys (" + detectedKeys.length + "):");
|
| 57 |
detectedKeys.forEach(function(k) { console.log(" + " + k); });
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
// ---- proxies ----
|
| 60 |
-
var
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
"10.16.1.206",
|
| 72 |
-
"10.16.37.110",
|
| 73 |
-
"10.16.43.246",
|
| 74 |
-
"10.20.1.9",
|
| 75 |
-
"10.20.1.222",
|
| 76 |
-
"10.20.26.157",
|
| 77 |
-
"10.20.31.87",
|
| 78 |
-
"10.20.0.1"
|
| 79 |
-
];
|
| 80 |
|
| 81 |
// ---- build config ----
|
| 82 |
var config = {
|
| 83 |
gateway: {
|
| 84 |
-
auth: gatewayToken
|
| 85 |
-
? { mode: "token", token: gatewayToken }
|
| 86 |
-
: { mode: "password", password: gatewayPassword },
|
| 87 |
controlUi: {
|
| 88 |
-
dangerousDisableDeviceAuth: true,
|
| 89 |
allowInsecureAuth: true,
|
|
|
|
|
|
|
| 90 |
dangerouslyAllowHostHeaderOriginFallback: true
|
| 91 |
},
|
| 92 |
trustedProxies: trustedProxies
|
| 93 |
},
|
| 94 |
agents: {
|
| 95 |
-
defaults: {
|
| 96 |
-
|
| 97 |
-
}
|
| 98 |
},
|
| 99 |
-
// Write detected keys into env.vars so OpenClaw injects them into its runtime.
|
| 100 |
-
// This is the official OpenClaw mechanism for env-based provider auth.
|
| 101 |
env: { vars: {} }
|
| 102 |
};
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
});
|
| 107 |
|
| 108 |
// ---- Telegram - auto detect best reachable node ----
|
|
@@ -119,7 +125,6 @@ async function detectTelegramNode(nodes, token) {
|
|
| 119 |
req.setTimeout(4000, function() { req.destroy(); reject(new Error("Timeout")); });
|
| 120 |
});
|
| 121 |
console.log("[setup] Telegram node reachable: " + node);
|
| 122 |
-
// Strip trailing slash
|
| 123 |
return node.replace(/\/$/, "");
|
| 124 |
} catch (e) {
|
| 125 |
console.log("[setup] Telegram node unreachable: " + node + " (" + e.message + ")");
|
|
@@ -149,26 +154,21 @@ async function setupTelegram() {
|
|
| 149 |
}
|
| 150 |
|
| 151 |
// ---- main ----
|
| 152 |
-
async function
|
| 153 |
await setupTelegram();
|
| 154 |
-
|
| 155 |
try {
|
| 156 |
fs.mkdirSync(STATE_DIR, { recursive: true });
|
| 157 |
if (fs.existsSync(CONFIG_PATH)) {
|
| 158 |
fs.copyFileSync(CONFIG_PATH, CONFIG_PATH + ".bak");
|
| 159 |
}
|
| 160 |
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
|
|
| 161 |
} catch (e) {
|
| 162 |
console.error("[setup] Write failed: " + e.message);
|
| 163 |
process.exit(1);
|
| 164 |
}
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
" model=" + defaultModel + " proxies=" + trustedProxies.length +
|
| 168 |
-
" env.vars=" + detectedKeys.length);
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
main().then(() => process.exit(0)).catch(function(e) {
|
| 172 |
console.error("[setup] Fatal: " + e.message);
|
| 173 |
process.exit(1);
|
| 174 |
});
|
|
|
|
| 18 |
var gatewayPassword = (process.env.OPENCLAW_GATEWAY_PASSWORD || "").trim();
|
| 19 |
|
| 20 |
if (!gatewayToken && !gatewayPassword) {
|
| 21 |
+
console.error("[setup] ERROR: Auth required. Set OPENCLAW_GATEWAY_TOKEN or OPENCLAW_GATEWAY_PASSWORD.");
|
| 22 |
process.exit(1);
|
| 23 |
}
|
| 24 |
|
| 25 |
// ---- default model ----
|
| 26 |
+
// 已改为 DeepSeek-R1(你最想要的)
|
| 27 |
+
var defaultModel = (process.env.OPENCLAW_HF_DEFAULT_MODEL || "").trim() || "deepseek/deepseek-reasoner";
|
| 28 |
|
| 29 |
+
// ---- dynamic key detection ----
|
| 30 |
+
// Exclude internal system/platform vars, include only provider credentials.
|
|
|
|
|
|
|
| 31 |
var EXCLUDE_PREFIXES = [
|
| 32 |
+
"OPENCLAW_", "SPACE_", "SYSTEM_", "HF_",
|
| 33 |
"NODE_", "PATH", "HOME", "USER", "PWD", "LANG", "LC_"
|
| 34 |
];
|
| 35 |
+
|
| 36 |
var INCLUDE_SUFFIXES = [
|
| 37 |
"_API_KEY", "_SECRET_KEY", "_ACCESS_TOKEN",
|
| 38 |
+
"_BOT_TOKEN", "_AUTH_TOKEN", "_APP_KEY"
|
| 39 |
];
|
| 40 |
|
| 41 |
function isProviderKey(k) {
|
| 42 |
+
for (var prefix of EXCLUDE_PREFIXES) if (k.startsWith(prefix)) return false;
|
| 43 |
+
for (var suffix of INCLUDE_SUFFIXES) if (k.endsWith(suffix)) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
return false;
|
| 45 |
}
|
| 46 |
|
| 47 |
+
// Scan ALL env vars to detect keys based on suffixes.
|
| 48 |
var detectedKeys = Object.keys(process.env)
|
| 49 |
+
.filter(k => isProviderKey(k) && process.env[k])
|
| 50 |
.sort();
|
| 51 |
|
| 52 |
console.log("[setup] Detected provider keys (" + detectedKeys.length + "):");
|
| 53 |
detectedKeys.forEach(function(k) { console.log(" + " + k); });
|
| 54 |
|
| 55 |
+
// Separately capture Telegram token
|
| 56 |
+
var telegramBotToken = detectedKeys.includes("TELEGRAM_BOT_TOKEN") ? (process.env.TELEGRAM_BOT_TOKEN || "").trim() : null;
|
| 57 |
+
|
| 58 |
+
var providerKeys = detectedKeys.filter(k => k !== "TELEGRAM_BOT_TOKEN");
|
| 59 |
+
|
| 60 |
// ---- proxies ----
|
| 61 |
+
var trustedProxies = parseList(process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES);
|
| 62 |
+
if (trustedProxies.length === 0) {
|
| 63 |
+
trustedProxies = [
|
| 64 |
+
"10.16.4.123", "10.16.7.92", "10.16.18.232",
|
| 65 |
+
"10.16.34.155", "10.16.43.133", "10.16.1.206",
|
| 66 |
+
"10.16.37.110", "10.16.43.246",
|
| 67 |
+
"10.20.1.9", "10.20.1.222",
|
| 68 |
+
"10.20.26.157", "10.20.31.87",
|
| 69 |
+
"10.20.0.1", "172.17.0.1"
|
| 70 |
+
];
|
| 71 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
// ---- build config ----
|
| 74 |
var config = {
|
| 75 |
gateway: {
|
| 76 |
+
auth: gatewayToken ? { mode: "token", token: gatewayToken } : { mode: "password", password: gatewayPassword },
|
|
|
|
|
|
|
| 77 |
controlUi: {
|
|
|
|
| 78 |
allowInsecureAuth: true,
|
| 79 |
+
allowedOrigins: ["*"],
|
| 80 |
+
dangerouslyDisableDeviceAuth: true,
|
| 81 |
dangerouslyAllowHostHeaderOriginFallback: true
|
| 82 |
},
|
| 83 |
trustedProxies: trustedProxies
|
| 84 |
},
|
| 85 |
agents: {
|
| 86 |
+
defaults: { model: defaultModel },
|
| 87 |
+
providers: {}
|
|
|
|
| 88 |
},
|
|
|
|
|
|
|
| 89 |
env: { vars: {} }
|
| 90 |
};
|
| 91 |
|
| 92 |
+
// Fixed logic for fully dynamic key detection + 新增 DeepSeek 和 SiliconFlow 支持
|
| 93 |
+
providerKeys.forEach(function(k) {
|
| 94 |
+
config.env.vars[k] = process.env[k].trim();
|
| 95 |
+
var suffixMatched = INCLUDE_SUFFIXES.find(function(s) { return k.endsWith(s); });
|
| 96 |
+
if (suffixMatched) {
|
| 97 |
+
var prefix = k.slice(0, -(suffixMatched.length + 1)).toUpperCase();
|
| 98 |
+
if (prefix) {
|
| 99 |
+
var providerId = prefix.toLowerCase();
|
| 100 |
+
// 新增:支持 DeepSeek 和 SiliconFlow
|
| 101 |
+
if (providerId === "deepseek") providerId = "deepseek";
|
| 102 |
+
if (providerId === "siliconflow") providerId = "siliconflow";
|
| 103 |
+
if (providerId === "gemini") providerId = "google";
|
| 104 |
+
if (providerId === "claude") providerId = "anthropic";
|
| 105 |
+
|
| 106 |
+
if (!config.agents.providers[providerId]) {
|
| 107 |
+
config.agents.providers[providerId] = { enabled: true };
|
| 108 |
+
console.log(`[setup] Auto-enabled provider agent: ${providerId}`);
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
});
|
| 113 |
|
| 114 |
// ---- Telegram - auto detect best reachable node ----
|
|
|
|
| 125 |
req.setTimeout(4000, function() { req.destroy(); reject(new Error("Timeout")); });
|
| 126 |
});
|
| 127 |
console.log("[setup] Telegram node reachable: " + node);
|
|
|
|
| 128 |
return node.replace(/\/$/, "");
|
| 129 |
} catch (e) {
|
| 130 |
console.log("[setup] Telegram node unreachable: " + node + " (" + e.message + ")");
|
|
|
|
| 154 |
}
|
| 155 |
|
| 156 |
// ---- main ----
|
| 157 |
+
(async function() {
|
| 158 |
await setupTelegram();
|
|
|
|
| 159 |
try {
|
| 160 |
fs.mkdirSync(STATE_DIR, { recursive: true });
|
| 161 |
if (fs.existsSync(CONFIG_PATH)) {
|
| 162 |
fs.copyFileSync(CONFIG_PATH, CONFIG_PATH + ".bak");
|
| 163 |
}
|
| 164 |
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
| 165 |
+
console.log("[setup] Config generated at " + CONFIG_PATH + " with " + Object.keys(config.agents.providers).length + " dynamic provider agent(s)");
|
| 166 |
} catch (e) {
|
| 167 |
console.error("[setup] Write failed: " + e.message);
|
| 168 |
process.exit(1);
|
| 169 |
}
|
| 170 |
+
console.log("[setup] Done.");
|
| 171 |
+
})().catch(function(e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
console.error("[setup] Fatal: " + e.message);
|
| 173 |
process.exit(1);
|
| 174 |
});
|