8900 commited on
Update setup-hf-config.mjs
Browse files- setup-hf-config.mjs +10 -5
setup-hf-config.mjs
CHANGED
|
@@ -51,6 +51,11 @@ const envVars = {
|
|
| 51 |
TELEGRAM_BOT_TOKEN: process.env.TELEGRAM_BOT_TOKEN?.trim(),
|
| 52 |
};
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
// ====================== proxies ======================
|
| 55 |
const envProxies = parseList(process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES);
|
| 56 |
const trustedProxies = envProxies.length > 0 ? envProxies : [
|
|
@@ -83,7 +88,6 @@ if (gatewayToken) {
|
|
| 83 |
config.gateway.controlUi = config.gateway.controlUi || {};
|
| 84 |
config.gateway.controlUi.dangerouslyDisableDeviceAuth = true;
|
| 85 |
|
| 86 |
-
// allowedOrigins
|
| 87 |
const allowedOriginsEnv = parseList(process.env.OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS);
|
| 88 |
config.gateway.controlUi.allowedOrigins = allowedOriginsEnv.length > 0 ? allowedOriginsEnv : ["*"];
|
| 89 |
config.gateway.trustedProxies = trustedProxies;
|
|
@@ -104,7 +108,7 @@ Object.assign(
|
|
| 104 |
)
|
| 105 |
);
|
| 106 |
|
| 107 |
-
// ====================== Telegram
|
| 108 |
async function detectTelegramNode(nodes) {
|
| 109 |
for (const node of nodes) {
|
| 110 |
try {
|
|
@@ -116,7 +120,7 @@ async function detectTelegramNode(nodes) {
|
|
| 116 |
req.on("error", reject);
|
| 117 |
req.setTimeout(3000, () => req.destroy(new Error("Timeout")));
|
| 118 |
});
|
| 119 |
-
return node.replace(/\/$/, "");
|
| 120 |
} catch {}
|
| 121 |
}
|
| 122 |
return null;
|
|
@@ -146,10 +150,11 @@ async function setupTelegram() {
|
|
| 146 |
console.log(`[openclaw-hf-setup] Telegram enabled with apiRoot: ${apiRoot}`);
|
| 147 |
}
|
| 148 |
|
|
|
|
| 149 |
(async () => {
|
| 150 |
await setupTelegram();
|
| 151 |
|
| 152 |
-
//
|
| 153 |
try {
|
| 154 |
fs.mkdirSync(STATE_DIR, { recursive: true });
|
| 155 |
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
@@ -158,7 +163,7 @@ async function setupTelegram() {
|
|
| 158 |
process.exit(1);
|
| 159 |
}
|
| 160 |
|
| 161 |
-
//
|
| 162 |
console.log("[openclaw-hf-setup] ✅ Ready");
|
| 163 |
console.log(`[openclaw-hf-setup] Auth: ${gatewayToken ? "token" : "password"}`);
|
| 164 |
console.log(`[openclaw-hf-setup] Model: ${defaultModel}`);
|
|
|
|
| 51 |
TELEGRAM_BOT_TOKEN: process.env.TELEGRAM_BOT_TOKEN?.trim(),
|
| 52 |
};
|
| 53 |
|
| 54 |
+
// TELEGRAM_API_ROOT 默认
|
| 55 |
+
let telegramApiRoot = (process.env.TELEGRAM_API_ROOT || "https://api.telegram.org").trim();
|
| 56 |
+
if (telegramApiRoot.endsWith("/bot")) telegramApiRoot = telegramApiRoot.slice(0, -4);
|
| 57 |
+
telegramApiRoot = telegramApiRoot.replace(/\/$/, "");
|
| 58 |
+
|
| 59 |
// ====================== proxies ======================
|
| 60 |
const envProxies = parseList(process.env.OPENCLAW_GATEWAY_TRUSTED_PROXIES);
|
| 61 |
const trustedProxies = envProxies.length > 0 ? envProxies : [
|
|
|
|
| 88 |
config.gateway.controlUi = config.gateway.controlUi || {};
|
| 89 |
config.gateway.controlUi.dangerouslyDisableDeviceAuth = true;
|
| 90 |
|
|
|
|
| 91 |
const allowedOriginsEnv = parseList(process.env.OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS);
|
| 92 |
config.gateway.controlUi.allowedOrigins = allowedOriginsEnv.length > 0 ? allowedOriginsEnv : ["*"];
|
| 93 |
config.gateway.trustedProxies = trustedProxies;
|
|
|
|
| 108 |
)
|
| 109 |
);
|
| 110 |
|
| 111 |
+
// ====================== Telegram B方案升级 ======================
|
| 112 |
async function detectTelegramNode(nodes) {
|
| 113 |
for (const node of nodes) {
|
| 114 |
try {
|
|
|
|
| 120 |
req.on("error", reject);
|
| 121 |
req.setTimeout(3000, () => req.destroy(new Error("Timeout")));
|
| 122 |
});
|
| 123 |
+
return node.replace(/\/$/, "");
|
| 124 |
} catch {}
|
| 125 |
}
|
| 126 |
return null;
|
|
|
|
| 150 |
console.log(`[openclaw-hf-setup] Telegram enabled with apiRoot: ${apiRoot}`);
|
| 151 |
}
|
| 152 |
|
| 153 |
+
// ====================== 主执行 ======================
|
| 154 |
(async () => {
|
| 155 |
await setupTelegram();
|
| 156 |
|
| 157 |
+
// 写入配置
|
| 158 |
try {
|
| 159 |
fs.mkdirSync(STATE_DIR, { recursive: true });
|
| 160 |
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
|
|
| 163 |
process.exit(1);
|
| 164 |
}
|
| 165 |
|
| 166 |
+
// 日志
|
| 167 |
console.log("[openclaw-hf-setup] ✅ Ready");
|
| 168 |
console.log(`[openclaw-hf-setup] Auth: ${gatewayToken ? "token" : "password"}`);
|
| 169 |
console.log(`[openclaw-hf-setup] Model: ${defaultModel}`);
|