🚀 Initial deploy to Gitea with fixes and dashboard enhancements
This commit is contained in:
787
templates/index.html
Normal file
787
templates/index.html
Normal file
@@ -0,0 +1,787 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-BR" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>VPS AI Dashboard</title>
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🤖</text></svg>">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-base: #0f172a;
|
||||
--bg-card: rgba(30, 41, 59, 0.8);
|
||||
--bg-input: rgba(15, 23, 42, 0.5);
|
||||
--border: rgba(255, 255, 255, 0.08);
|
||||
--accent: #3b82f6;
|
||||
--accent-hover: #60a5fa;
|
||||
--accent-glow: rgba(59, 130, 246, 0.25);
|
||||
--text-main: #f8fafc;
|
||||
--text-muted: #94a3b8;
|
||||
--danger: #ef4444;
|
||||
--danger-bg: rgba(239, 68, 68, 0.15);
|
||||
--success: #10b981;
|
||||
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
|
||||
--radius: 12px;
|
||||
--transition: 0.25s ease;
|
||||
}
|
||||
|
||||
[data-theme="light"] {
|
||||
--bg-base: #f1f5f9;
|
||||
--bg-card: #ffffff;
|
||||
--bg-input: #e2e8f0;
|
||||
--border: rgba(0, 0, 0, 0.08);
|
||||
--accent: #2563eb;
|
||||
--accent-hover: #1d4ed8;
|
||||
--accent-glow: rgba(37, 99, 235, 0.2);
|
||||
--text-main: #1e3a5f;
|
||||
--text-muted: #64748b;
|
||||
--shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
background-color: var(--bg-base);
|
||||
color: var(--text-main);
|
||||
min-height: 100vh;
|
||||
transition: background-color var(--transition), color var(--transition);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1rem 0;
|
||||
margin-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.logo svg {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
background: linear-gradient(135deg, var(--accent), #8b5cf6);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.4rem 0.75rem;
|
||||
background: rgba(16, 185, 129, 0.15);
|
||||
color: var(--success);
|
||||
border-radius: 20px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status-badge::before {
|
||||
content: '';
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
background: var(--success);
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 0 6px var(--success);
|
||||
}
|
||||
|
||||
.status-badge.offline {
|
||||
background: var(--danger-bg);
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.status-badge.offline::before {
|
||||
background: var(--danger);
|
||||
box-shadow: 0 0 6px var(--danger);
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition);
|
||||
color: var(--text-main);
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.theme-toggle svg {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
/* Cards */
|
||||
.card {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1rem;
|
||||
box-shadow: var(--shadow);
|
||||
transition: all var(--transition);
|
||||
}
|
||||
|
||||
/* Stats Grid */
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.stat-card h3 {
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.progress-bar-bg {
|
||||
height: 6px;
|
||||
background: var(--bg-input);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 100%;
|
||||
background: var(--accent);
|
||||
border-radius: 3px;
|
||||
transition: width 0.5s ease;
|
||||
}
|
||||
|
||||
.progress-bar.warning {
|
||||
background: #f59e0b;
|
||||
}
|
||||
|
||||
.progress-bar.danger {
|
||||
background: var(--danger);
|
||||
}
|
||||
|
||||
/* Section Title */
|
||||
.section-title {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-muted);
|
||||
margin: 1.25rem 0 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
/* Actions Grid */
|
||||
.actions-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.65rem 1rem;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--text-main);
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition);
|
||||
}
|
||||
|
||||
.btn svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 12px var(--accent-glow);
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
border-color: rgba(239, 68, 68, 0.3);
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: var(--danger);
|
||||
border-color: var(--danger);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: var(--accent-hover);
|
||||
}
|
||||
|
||||
/* Config Form */
|
||||
.config-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 0.35rem;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
width: 100%;
|
||||
padding: 0.6rem 0.75rem;
|
||||
background: var(--bg-input);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--text-main);
|
||||
font-size: 0.85rem;
|
||||
transition: border-color var(--transition);
|
||||
}
|
||||
|
||||
.form-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
select.form-input {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Chat */
|
||||
.chat-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: min(350px, 45vh);
|
||||
}
|
||||
|
||||
.chat-messages {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 0.75rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.chat-bubble {
|
||||
max-width: 80%;
|
||||
padding: 0.6rem 0.9rem;
|
||||
border-radius: 12px;
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.bubble-ai {
|
||||
background: rgba(59, 130, 246, 0.1);
|
||||
border: 1px solid rgba(59, 130, 246, 0.2);
|
||||
align-self: flex-start;
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
|
||||
.bubble-user {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
align-self: flex-end;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
|
||||
.chat-input-area {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.chat-input {
|
||||
flex: 1;
|
||||
padding: 0.6rem 0.75rem;
|
||||
background: var(--bg-input);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--text-main);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.chat-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.chat-input::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
/* Toast */
|
||||
#toast {
|
||||
position: fixed;
|
||||
bottom: 1rem;
|
||||
right: 1rem;
|
||||
padding: 0.75rem 1.25rem;
|
||||
background: var(--success);
|
||||
color: white;
|
||||
border-radius: 8px;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 500;
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
transition: all 0.3s ease;
|
||||
pointer-events: none;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
#toast.show {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
#toast.error {
|
||||
background: var(--danger);
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 640px) {
|
||||
.container {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
header {
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.actions-grid {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
|
||||
.config-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.chat-wrapper {
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
.chat-bubble {
|
||||
max-width: 90%;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 0.6rem 0.75rem;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 380px) {
|
||||
.actions-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<div class="logo">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
|
||||
</svg>
|
||||
<h1>VPS AI Dashboard</h1>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<div class="status-badge" id="bot-status">Online</div>
|
||||
<button class="theme-toggle" onclick="toggleTheme()" aria-label="Alternar tema">
|
||||
<svg id="icon-sun" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="display: none;">
|
||||
<circle cx="12" cy="12" r="5"/>
|
||||
<path d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/>
|
||||
</svg>
|
||||
<svg id="icon-moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="stats-grid">
|
||||
<div class="card stat-card">
|
||||
<h3>CPU</h3>
|
||||
<div class="stat-value" id="cpu-val">--%</div>
|
||||
<div class="progress-bar-bg">
|
||||
<div class="progress-bar" id="cpu-bar" style="width: 0%"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card stat-card">
|
||||
<h3>RAM</h3>
|
||||
<div class="stat-value" id="ram-val">-- / -- GB</div>
|
||||
<div class="progress-bar-bg">
|
||||
<div class="progress-bar" id="ram-bar" style="width: 0%"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card stat-card">
|
||||
<h3>Disk</h3>
|
||||
<div class="stat-value" id="disk-val">--%</div>
|
||||
<div class="progress-bar-bg">
|
||||
<div class="progress-bar" id="disk-bar" style="width: 0%"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-title">Ações Rápidas</div>
|
||||
<div class="actions-grid">
|
||||
<button class="btn" onclick="executeAction('ping')">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>
|
||||
</svg>
|
||||
Ping
|
||||
</button>
|
||||
<button class="btn" id="btn-test-llm" onclick="testLLMSpeed()">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M12 2a10 10 0 1 0 10 10H12V2z"/>
|
||||
<path d="M12 2a10 10 0 0 1 10 10h-2a8 8 0 0 0-8-8V2z"/>
|
||||
<path d="M12 12V2.5l5.5 5.5"/>
|
||||
</svg>
|
||||
Testar LLM
|
||||
</button>
|
||||
<button class="btn" onclick="executeAction('restart_bot')">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M23 4v6h-6M1 20v-6h6"/>
|
||||
<path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/>
|
||||
</svg>
|
||||
Reiniciar
|
||||
</button>
|
||||
<button class="btn" onclick="executeAction('clear_cache')">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
|
||||
</svg>
|
||||
Limpar Cache
|
||||
</button>
|
||||
<button class="btn btn-danger" onclick="executeAction('reboot_vps')">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/>
|
||||
</svg>
|
||||
Reboot VPS
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="section-title">Configuração AI</div>
|
||||
<div class="card">
|
||||
<div class="config-grid">
|
||||
<div class="form-group">
|
||||
<label>Provider Ativo</label>
|
||||
<select id="active_provider" class="form-input">
|
||||
<option value="ollama">Ollama (Local)</option>
|
||||
<option value="gemini">Gemini Pro (Google)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Gemini API Key</label>
|
||||
<input type="password" id="gemini_api_key" class="form-input" placeholder="AIzaSy...">
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-primary" onclick="saveConfiguration()">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/>
|
||||
<polyline points="17 21 17 13 7 13 7 21"/>
|
||||
<polyline points="7 3 7 8 15 8"/>
|
||||
</svg>
|
||||
Salvar
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="section-title">Chat AI</div>
|
||||
<div class="card chat-wrapper">
|
||||
<div class="chat-messages" id="chat-box">
|
||||
<div class="chat-bubble bubble-ai">
|
||||
Olá! Sou o VPS Agent. Como posso ajudar com seu servidor?
|
||||
</div>
|
||||
</div>
|
||||
<div class="chat-input-area">
|
||||
<input type="text" id="chat-input" class="chat-input" placeholder="Digite seu comando..." onkeypress="handleKeyPress(event)">
|
||||
<button class="btn btn-primary" onclick="sendMessage()">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<line x1="22" y1="2" x2="11" y2="13"/>
|
||||
<polygon points="22 2 15 22 11 13 2 9 22 2"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="toast">Ação executada!</div>
|
||||
|
||||
<script>
|
||||
function toggleTheme() {
|
||||
const html = document.documentElement;
|
||||
const isDark = html.dataset.theme !== 'light';
|
||||
html.dataset.theme = isDark ? 'light' : 'dark';
|
||||
localStorage.setItem('theme', html.dataset.theme);
|
||||
updateThemeIcon(!isDark);
|
||||
}
|
||||
|
||||
function updateThemeIcon(isDark) {
|
||||
document.getElementById('icon-sun').style.display = isDark ? 'block' : 'none';
|
||||
document.getElementById('icon-moon').style.display = isDark ? 'none' : 'block';
|
||||
}
|
||||
|
||||
const savedTheme = localStorage.getItem('theme');
|
||||
if (savedTheme) {
|
||||
document.documentElement.dataset.theme = savedTheme;
|
||||
updateThemeIcon(savedTheme === 'light');
|
||||
}
|
||||
|
||||
async function fetchStats() {
|
||||
try {
|
||||
const res = await fetch('/api/status');
|
||||
if (!res.ok) throw new Error();
|
||||
const data = await res.json();
|
||||
|
||||
const cpuVal = document.getElementById('cpu-val');
|
||||
const cpuBar = document.getElementById('cpu-bar');
|
||||
if (cpuVal) cpuVal.textContent = data.cpu + '%';
|
||||
if (cpuBar) {
|
||||
cpuBar.style.width = data.cpu + '%';
|
||||
cpuBar.className = 'progress-bar' + (data.cpu > 80 ? ' danger' : data.cpu > 60 ? ' warning' : '');
|
||||
}
|
||||
|
||||
const ramVal = document.getElementById('ram-val');
|
||||
const ramBar = document.getElementById('ram-bar');
|
||||
if (ramVal) ramVal.textContent = data.ram.used + ' / ' + data.ram.total + ' GB';
|
||||
if (ramBar) ramBar.style.width = data.ram.percent + '%';
|
||||
|
||||
const diskVal = document.getElementById('disk-val');
|
||||
const diskBar = document.getElementById('disk-bar');
|
||||
if (diskVal) diskVal.textContent = data.disk.percent + '%';
|
||||
if (diskBar) {
|
||||
diskBar.style.width = data.disk.percent + '%';
|
||||
diskBar.className = 'progress-bar' + (data.disk.percent > 90 ? ' danger' : data.disk.percent > 75 ? ' warning' : '');
|
||||
}
|
||||
|
||||
const status = document.getElementById('bot-status');
|
||||
if (status) {
|
||||
status.textContent = 'Online';
|
||||
status.classList.remove('offline');
|
||||
}
|
||||
} catch (e) {
|
||||
const status = document.getElementById('bot-status');
|
||||
if (status) {
|
||||
status.textContent = 'Offline';
|
||||
status.classList.add('offline');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(fetchStats, 3000);
|
||||
fetchStats();
|
||||
|
||||
async function executeAction(type) {
|
||||
const messages = {
|
||||
reboot_vps: '⚠️ Confirma reboot da VPS?',
|
||||
clear_cache: 'Limpar cache do servidor?',
|
||||
restart_bot: 'Reiniciar o agente AI?'
|
||||
};
|
||||
|
||||
if (messages[type] && !confirm(messages[type])) return;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/action', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ type })
|
||||
});
|
||||
const data = await res.json();
|
||||
showToast(data.message || 'Ação executada!');
|
||||
} catch (e) {
|
||||
showToast('Erro ao executar.', true);
|
||||
}
|
||||
}
|
||||
|
||||
function showToast(msg, isError = false) {
|
||||
const toast = document.getElementById('toast');
|
||||
toast.textContent = msg;
|
||||
toast.className = isError ? 'error show' : 'show';
|
||||
setTimeout(() => toast.classList.remove('show'), 3000);
|
||||
}
|
||||
|
||||
async function sendChat() {
|
||||
const input = document.getElementById('chat-input');
|
||||
const text = input.value.trim();
|
||||
if (!text) return;
|
||||
|
||||
addBubble(text, 'user');
|
||||
input.value = '';
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/chat', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ text })
|
||||
});
|
||||
const data = await res.json();
|
||||
addBubble(data.reply, 'ai');
|
||||
} catch (e) {
|
||||
addBubble('Erro ao contatar servidor.', 'ai');
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeyPress(e) {
|
||||
if (e.key === 'Enter') sendChat();
|
||||
}
|
||||
|
||||
function addBubble(text, sender) {
|
||||
const box = document.getElementById('chat-box');
|
||||
const div = document.createElement('div');
|
||||
div.className = 'chat-bubble bubble-' + sender;
|
||||
div.textContent = text;
|
||||
box.appendChild(div);
|
||||
box.scrollTop = box.scrollHeight;
|
||||
}
|
||||
|
||||
async function loadConfig() {
|
||||
try {
|
||||
const res = await fetch('/api/config');
|
||||
const data = await res.json();
|
||||
const provider = document.getElementById('active_provider');
|
||||
const key = document.getElementById('gemini_api_key');
|
||||
if (provider) provider.value = data.active_provider || 'ollama';
|
||||
if (key) key.value = data.gemini_api_key || '';
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
async function saveConfig() {
|
||||
const provider = document.getElementById('active_provider').value;
|
||||
const key = document.getElementById('gemini_api_key').value.trim();
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ active_provider: provider, gemini_api_key: key })
|
||||
});
|
||||
if (res.ok) {
|
||||
showToast('Configurações salvas!');
|
||||
loadConfig();
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
} catch (e) {
|
||||
showToast('Erro ao salvar.', true);
|
||||
}
|
||||
}
|
||||
|
||||
window.saveConfiguration = saveConfig;
|
||||
window.sendMessage = sendChat;
|
||||
async function testLLMSpeed() {
|
||||
const btn = document.getElementById('btn-test-llm');
|
||||
const originalContent = btn.innerHTML;
|
||||
btn.innerHTML = '⚡ Testando...';
|
||||
btn.disabled = true;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/test_llm');
|
||||
const data = await res.json();
|
||||
if(data.status === 'success') {
|
||||
showToast(`✅ LLM Online! Resposta em ${data.latency}s`);
|
||||
btn.innerHTML = `✅ ${data.latency}s`;
|
||||
setTimeout(() => { btn.innerHTML = originalContent; btn.disabled = false; }, 5000);
|
||||
} else {
|
||||
throw new Error(data.message);
|
||||
}
|
||||
} catch(e) {
|
||||
showToast("❌ Erro no Teste LLM: " + e.message, true);
|
||||
btn.innerHTML = '❌ Falhou';
|
||||
btn.classList.add('btn-danger');
|
||||
setTimeout(() => {
|
||||
btn.innerHTML = originalContent;
|
||||
btn.disabled = false;
|
||||
btn.classList.remove('btn-danger');
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
window.executeAction = executeAction;
|
||||
window.testLLMSpeed = testLLMSpeed;
|
||||
|
||||
loadConfig();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user