// Lightweight health server and dashboard on port 7861 const http = require("http"); const fs = require("fs"); const PORT = process.env.HEALTH_PORT || 7861; const startTime = Date.now(); const LLM_MODEL = process.env.LLM_MODEL || "Not Set"; const GATEWAY_TOKEN = process.env.GATEWAY_TOKEN || "huggingclaw"; const TELEGRAM_ENABLED = !!process.env.TELEGRAM_BOT_TOKEN; const server = http.createServer((req, res) => { const uptime = Math.floor((Date.now() - startTime) / 1000); const uptimeHuman = `${Math.floor(uptime / 3600)}h ${Math.floor((uptime % 3600) / 60)}m`; if (req.url === "/health") { res.writeHead(200, { "Content-Type": "application/json" }); res.end( JSON.stringify({ status: "ok", uptime: uptime, uptimeHuman: uptimeHuman, timestamp: new Date().toISOString(), }), ); return; } if (req.url === "/status") { let syncStatus = { status: "unknown", message: "No sync data yet" }; try { if (fs.existsSync("/tmp/sync-status.json")) { syncStatus = JSON.parse( fs.readFileSync("/tmp/sync-status.json", "utf8"), ); } } catch (e) {} res.writeHead(200, { "Content-Type": "application/json" }); res.end( JSON.stringify({ model: LLM_MODEL, whatsapp: true, telegram: TELEGRAM_ENABLED, sync: syncStatus, uptime: uptimeHuman, token: GATEWAY_TOKEN, }), ); return; } if (req.url === "/") { res.writeHead(200, { "Content-Type": "text/html" }); res.end(` HuggingClaw Dashboard

🦞 HuggingClaw

Space Control Panel

Model Loading...
Uptime Loading...
WhatsApp Loading...
Telegram Loading...
🚀 Open Control UI
Workspace Sync Status
Last Sync Activity: Never Initializing synchronization...
`); return; } res.writeHead(404); res.end(); }); server.listen(PORT, "0.0.0.0", () => { console.log(`🏥 Health server & Dashboard listening on port ${PORT}`); });