Spaces:
Sleeping
Sleeping
Update templates/chat-bot.html
Browse files- templates/chat-bot.html +553 -178
templates/chat-bot.html
CHANGED
|
@@ -1,136 +1,371 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html lang="
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 7 |
-
|
| 8 |
-
<
|
| 9 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
| 10 |
-
|
| 11 |
<style>
|
| 12 |
-
/* Estilos base para scrollbar y compatibilidad */
|
| 13 |
-
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
| 14 |
-
body { font-family: 'Inter', sans-serif; -webkit-font-smoothing: antialiased; }
|
| 15 |
-
#chat-messages::-webkit-scrollbar { width: 8px; }
|
| 16 |
-
#chat-messages::-webkit-scrollbar-track { background: #f1f5f9; }
|
| 17 |
-
#chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
|
| 18 |
-
#chat-messages::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
|
| 19 |
-
|
| 20 |
-
/* Variables para los modales y tema oscuro */
|
| 21 |
:root {
|
|
|
|
|
|
|
| 22 |
--bg-secondary: #ffffff;
|
| 23 |
--text-primary: #2c3e50;
|
| 24 |
--text-secondary: #6c757d;
|
|
|
|
|
|
|
|
|
|
| 25 |
--accent-color: #3498db;
|
| 26 |
--border-color: #dee2e6;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
[data-theme="dark"] {
|
|
|
|
|
|
|
| 29 |
--bg-secondary: #2c2c2c;
|
| 30 |
--text-primary: #e0e0e0;
|
| 31 |
--text-secondary: #a0a0a0;
|
|
|
|
|
|
|
|
|
|
| 32 |
--accent-color: #87CEEB;
|
| 33 |
--border-color: #444;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
.modal-overlay {
|
| 36 |
-
position: fixed;
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
-
.modal-overlay.visible { opacity: 1; visibility: visible; }
|
| 42 |
.modal-content {
|
| 43 |
-
background: var(--bg-secondary);
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
-
.modal-overlay.visible .modal-content { transform: scale(1); }
|
| 50 |
.modal-close-button {
|
| 51 |
-
position: absolute;
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
.
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
</style>
|
| 66 |
</head>
|
| 67 |
-
|
| 68 |
-
<
|
| 69 |
-
|
| 70 |
-
<
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
<
|
| 74 |
</div>
|
| 75 |
-
<div class="w-10 h-10 bg-slate-300 text-slate-600 rounded-full flex items-center justify-center flex-shrink-0"><i class="fas fa-user"></i></div>
|
| 76 |
</div>
|
| 77 |
-
|
| 78 |
-
<
|
| 79 |
-
|
| 80 |
-
<
|
| 81 |
-
<div class="bg-white p-4 rounded-xl rounded-tl-none shadow-md max-w-2xl border border-slate-200">
|
| 82 |
-
<p class="text-sm text-slate-700 message-text-placeholder"></p>
|
| 83 |
-
</div>
|
| 84 |
</div>
|
| 85 |
-
</template>
|
| 86 |
-
|
| 87 |
-
<div class="relative w-full h-screen flex flex-col">
|
| 88 |
-
<header class="bg-blue-600 text-white shadow-md w-full flex-shrink-0 z-10 p-4 flex justify-between items-center">
|
| 89 |
-
<div class="flex items-center gap-3">
|
| 90 |
-
<i class="fas fa-tooth text-2xl"></i>
|
| 91 |
-
<h2 class="font-bold text-xl">EndoBot Asistente</h2>
|
| 92 |
-
</div>
|
| 93 |
-
<div class="flex items-center gap-2">
|
| 94 |
-
<button id="admin-panel-button" class="text-white hover:bg-blue-700 p-2 rounded-full transition-colors" title="Admin Panel"><i class="fas fa-shield-halved"></i></button>
|
| 95 |
-
<button id="theme-toggle" class="text-white hover:bg-blue-700 p-2 rounded-full transition-colors" title="Toggle Theme"><i class="fas fa-moon"></i></button>
|
| 96 |
-
</div>
|
| 97 |
-
</header>
|
| 98 |
-
|
| 99 |
-
<main class="w-full flex-1 flex flex-col overflow-hidden">
|
| 100 |
-
<div id="chat-messages" class="flex-1 p-6 overflow-y-auto space-y-6">
|
| 101 |
-
</div>
|
| 102 |
-
|
| 103 |
-
<div class="bg-white p-4 border-t border-slate-200 flex-shrink-0">
|
| 104 |
-
<form id="chat-form" class="flex items-center gap-3">
|
| 105 |
-
<textarea id="user-input" class="flex-1 bg-slate-100 rounded-lg p-3 border border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500 transition" placeholder="Escribe tu consulta aquí..." rows="1" disabled></textarea>
|
| 106 |
-
<button type="submit" id="send-button" class="bg-blue-500 hover:bg-blue-600 text-white rounded-full w-12 h-12 flex items-center justify-center flex-shrink-0 transition-colors shadow-md hover:shadow-lg disabled:bg-slate-400" disabled><i class="fas fa-paper-plane"></i></button>
|
| 107 |
-
</form>
|
| 108 |
-
</div>
|
| 109 |
-
</main>
|
| 110 |
</div>
|
| 111 |
-
|
| 112 |
<div class="modal-overlay" id="admin-modal-overlay">
|
| 113 |
-
<div class="modal-content">
|
| 114 |
<button class="modal-close-button" id="modal-close-btn">×</button>
|
| 115 |
<h3><i class="fas fa-cogs"></i> System Control Panel</h3>
|
| 116 |
<div class="admin-section">
|
|
|
|
| 117 |
<div class="admin-buttons-grid">
|
| 118 |
-
<button class="admin-button" id="rebuild-index-button">Rebuild Index</button>
|
| 119 |
-
<button class="admin-button" id="
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
</div>
|
| 122 |
</div>
|
| 123 |
</div>
|
| 124 |
<div class="modal-overlay" id="credentials-modal">
|
| 125 |
-
<div class="modal-content"
|
| 126 |
<h3 id="credentials-title">Authentication Required</h3>
|
| 127 |
<div class="form-group">
|
| 128 |
<label for="username-input">Username</label>
|
| 129 |
-
<input type="text" id="username-input">
|
| 130 |
</div>
|
| 131 |
<div class="form-group">
|
| 132 |
<label for="password-input">Password</label>
|
| 133 |
-
<input type="password" id="password-input">
|
| 134 |
</div>
|
| 135 |
<div class="modal-actions">
|
| 136 |
<button id="credentials-cancel-btn" class="modal-button secondary">Cancel</button>
|
|
@@ -138,103 +373,243 @@
|
|
| 138 |
</div>
|
| 139 |
</div>
|
| 140 |
</div>
|
| 141 |
-
|
| 142 |
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
| 143 |
<script src="https://unpkg.com/autosize@4.0.2/dist/autosize.min.js"></script>
|
| 144 |
-
|
| 145 |
<script>
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
ui.themeToggle.addEventListener('click', toggleTheme);
|
| 212 |
-
}
|
| 213 |
-
if (ui.adminPanelButton) {
|
| 214 |
ui.adminPanelButton.addEventListener('click', () => toggleModal(ui.adminModal.overlay, true));
|
| 215 |
-
}
|
| 216 |
-
if (ui.adminModal.closeBtn) {
|
| 217 |
ui.adminModal.closeBtn.addEventListener('click', () => toggleModal(ui.adminModal.overlay, false));
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
ui.adminModal.
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
});
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
function initializeApp() {
|
| 227 |
-
console.log("Inicializando la aplicación...");
|
| 228 |
-
autosize(ui.userInput);
|
| 229 |
-
applyTheme(localStorage.getItem('chatTheme') || 'light');
|
| 230 |
-
ui.userInput.disabled = false;
|
| 231 |
-
ui.sendButton.disabled = false;
|
| 232 |
-
appendMessage({ sender: 'bot', text: 'Hola! Soy tu asistente personal experto en endodoncia. ¿En qué te puedo ayudar hoy?' });
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
initializeApp();
|
| 236 |
-
|
| 237 |
</script>
|
| 238 |
-
|
| 239 |
</body>
|
| 240 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<html lang="en" data-theme="light">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Personal Assistant</title>
|
| 7 |
+
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700" rel="stylesheet">
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
|
|
|
|
|
| 9 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
:root {
|
| 11 |
+
/* Light Theme (Default) */
|
| 12 |
+
--bg-primary: #f4f7f9;
|
| 13 |
--bg-secondary: #ffffff;
|
| 14 |
--text-primary: #2c3e50;
|
| 15 |
--text-secondary: #6c757d;
|
| 16 |
+
--header-bg: #2c3e50;
|
| 17 |
+
--bot-message-bg: #e9ecef;
|
| 18 |
+
--user-message-bg: #d1e7fd;
|
| 19 |
--accent-color: #3498db;
|
| 20 |
--border-color: #dee2e6;
|
| 21 |
+
--shadow-color: rgba(0, 0, 0, 0.05);
|
| 22 |
+
--success-color: #28a745;
|
| 23 |
+
--error-color: #dc3545;
|
| 24 |
+
--info-color: #17a2b8;
|
| 25 |
}
|
| 26 |
[data-theme="dark"] {
|
| 27 |
+
/* Dark Theme */
|
| 28 |
+
--bg-primary: #1a1a1a;
|
| 29 |
--bg-secondary: #2c2c2c;
|
| 30 |
--text-primary: #e0e0e0;
|
| 31 |
--text-secondary: #a0a0a0;
|
| 32 |
+
--header-bg: #1f1f1f;
|
| 33 |
+
--bot-message-bg: #3a3f44;
|
| 34 |
+
--user-message-bg: #004a7c;
|
| 35 |
--accent-color: #87CEEB;
|
| 36 |
--border-color: #444;
|
| 37 |
+
--shadow-color: rgba(0, 0, 0, 0.2);
|
| 38 |
+
--success-color: #20c997;
|
| 39 |
+
--error-color: #ff6b6b;
|
| 40 |
+
--info-color: #63e6be;
|
| 41 |
}
|
| 42 |
+
* {
|
| 43 |
+
box-sizing: border-box;
|
| 44 |
+
}
|
| 45 |
+
body {
|
| 46 |
+
background-color: var(--bg-primary);
|
| 47 |
+
font-family: 'Roboto', sans-serif;
|
| 48 |
+
margin: 0;
|
| 49 |
+
padding: 0;
|
| 50 |
+
color: var(--text-primary);
|
| 51 |
+
transition: background-color 0.3s, color 0.3s;
|
| 52 |
+
}
|
| 53 |
+
.chat-container {
|
| 54 |
+
width: 100vw;
|
| 55 |
+
height: 100vh;
|
| 56 |
+
display: flex;
|
| 57 |
+
flex-direction: column;
|
| 58 |
+
overflow: hidden;
|
| 59 |
+
}
|
| 60 |
+
.chat-header {
|
| 61 |
+
background: var(--header-bg);
|
| 62 |
+
color: #fff;
|
| 63 |
+
padding: 15px 20px;
|
| 64 |
+
display: flex;
|
| 65 |
+
justify-content: space-between;
|
| 66 |
+
align-items: center;
|
| 67 |
+
flex-shrink: 0;
|
| 68 |
+
box-shadow: 0 2px 5px var(--shadow-color);
|
| 69 |
+
z-index: 10;
|
| 70 |
+
}
|
| 71 |
+
.chat-header h2 {
|
| 72 |
+
margin: 0;
|
| 73 |
+
font-size: 22px;
|
| 74 |
+
}
|
| 75 |
+
.header-buttons {
|
| 76 |
+
display: flex;
|
| 77 |
+
gap: 10px;
|
| 78 |
+
}
|
| 79 |
+
.header-buttons .icon-button {
|
| 80 |
+
background: transparent;
|
| 81 |
+
border: 1px solid rgba(255, 255, 255, 0.5);
|
| 82 |
+
color: #fff;
|
| 83 |
+
width: 38px;
|
| 84 |
+
height: 38px;
|
| 85 |
+
border-radius: 50%;
|
| 86 |
+
cursor: pointer;
|
| 87 |
+
font-size: 16px;
|
| 88 |
+
transition: background 0.3s, transform 0.3s;
|
| 89 |
+
display: flex;
|
| 90 |
+
justify-content: center;
|
| 91 |
+
align-items: center;
|
| 92 |
+
}
|
| 93 |
+
.header-buttons .icon-button:hover {
|
| 94 |
+
background: rgba(255, 255, 255, 0.15);
|
| 95 |
+
transform: scale(1.1);
|
| 96 |
+
}
|
| 97 |
+
.chat-messages {
|
| 98 |
+
flex: 1;
|
| 99 |
+
padding: 20px;
|
| 100 |
+
overflow-y: auto;
|
| 101 |
+
background-color: var(--bg-secondary);
|
| 102 |
+
}
|
| 103 |
+
.message {
|
| 104 |
+
margin-bottom: 20px;
|
| 105 |
+
display: flex;
|
| 106 |
+
align-items: flex-start;
|
| 107 |
+
max-width: 85%;
|
| 108 |
+
}
|
| 109 |
+
.message.user {
|
| 110 |
+
justify-content: flex-end;
|
| 111 |
+
margin-left: auto;
|
| 112 |
+
}
|
| 113 |
+
.message.bot {
|
| 114 |
+
margin-right: auto;
|
| 115 |
+
}
|
| 116 |
+
.message-content {
|
| 117 |
+
padding: 12px 18px;
|
| 118 |
+
border-radius: 18px;
|
| 119 |
+
box-shadow: 0 2px 4px var(--shadow-color);
|
| 120 |
+
word-wrap: break-word;
|
| 121 |
+
line-height: 1.6;
|
| 122 |
+
}
|
| 123 |
+
.message.user .message-content {
|
| 124 |
+
background-color: var(--user-message-bg);
|
| 125 |
+
color: var(--text-primary);
|
| 126 |
+
border-bottom-right-radius: 4px;
|
| 127 |
+
}
|
| 128 |
+
.message.bot .message-content {
|
| 129 |
+
background-color: var(--bot-message-bg);
|
| 130 |
+
border-bottom-left-radius: 4px;
|
| 131 |
+
}
|
| 132 |
+
.message.bot .typing-indicator {
|
| 133 |
+
display: flex;
|
| 134 |
+
align-items: center;
|
| 135 |
+
gap: 5px;
|
| 136 |
+
padding: 5px 0;
|
| 137 |
+
}
|
| 138 |
+
.message.bot .typing-indicator span {
|
| 139 |
+
height: 8px;
|
| 140 |
+
width: 8px;
|
| 141 |
+
background: var(--accent-color);
|
| 142 |
+
border-radius: 50%;
|
| 143 |
+
animation: bounce 1.3s linear infinite;
|
| 144 |
+
}
|
| 145 |
+
@keyframes bounce {
|
| 146 |
+
0%, 60%, 100% { transform: translateY(0); }
|
| 147 |
+
30% { transform: translateY(-8px); }
|
| 148 |
+
}
|
| 149 |
+
.chat-input {
|
| 150 |
+
display: flex;
|
| 151 |
+
padding: 15px;
|
| 152 |
+
background: var(--bg-secondary);
|
| 153 |
+
border-top: 1px solid var(--border-color);
|
| 154 |
+
flex-shrink: 0;
|
| 155 |
+
}
|
| 156 |
+
.chat-input textarea {
|
| 157 |
+
flex: 1;
|
| 158 |
+
padding: 12px 15px;
|
| 159 |
+
border: 1px solid var(--border-color);
|
| 160 |
+
border-radius: 22px;
|
| 161 |
+
resize: none;
|
| 162 |
+
font-size: 16px;
|
| 163 |
+
margin-right: 10px;
|
| 164 |
+
background-color: var(--bg-primary);
|
| 165 |
+
color: var(--text-primary);
|
| 166 |
+
transition: border-color 0.3s;
|
| 167 |
+
}
|
| 168 |
+
.chat-input textarea:focus {
|
| 169 |
+
border-color: var(--accent-color);
|
| 170 |
+
outline: none;
|
| 171 |
+
}
|
| 172 |
+
.chat-input button {
|
| 173 |
+
background-color: var(--accent-color);
|
| 174 |
+
color: #fff;
|
| 175 |
+
border: none;
|
| 176 |
+
width: 44px;
|
| 177 |
+
height: 44px;
|
| 178 |
+
border-radius: 50%;
|
| 179 |
+
cursor: pointer;
|
| 180 |
+
transition: background-color 0.3s;
|
| 181 |
+
font-size: 18px;
|
| 182 |
+
}
|
| 183 |
+
/* Modal Styles */
|
| 184 |
.modal-overlay {
|
| 185 |
+
position: fixed;
|
| 186 |
+
top: 0;
|
| 187 |
+
left: 0;
|
| 188 |
+
width: 100%;
|
| 189 |
+
height: 100%;
|
| 190 |
+
background: rgba(0, 0, 0, 0.6);
|
| 191 |
+
display: flex;
|
| 192 |
+
justify-content: center;
|
| 193 |
+
align-items: center;
|
| 194 |
+
z-index: 1000;
|
| 195 |
+
opacity: 0;
|
| 196 |
+
visibility: hidden;
|
| 197 |
+
transition: opacity 0.3s, visibility 0.3s;
|
| 198 |
+
}
|
| 199 |
+
.modal-overlay.visible {
|
| 200 |
+
opacity: 1;
|
| 201 |
+
visibility: visible;
|
| 202 |
}
|
|
|
|
| 203 |
.modal-content {
|
| 204 |
+
background: var(--bg-secondary);
|
| 205 |
+
padding: 25px;
|
| 206 |
+
border-radius: 12px;
|
| 207 |
+
width: 90%;
|
| 208 |
+
box-shadow: 0 5px 20px rgba(0,0,0,0.2);
|
| 209 |
+
transform: scale(0.95);
|
| 210 |
+
transition: transform 0.3s;
|
| 211 |
+
}
|
| 212 |
+
.modal-overlay.visible .modal-content {
|
| 213 |
+
transform: scale(1);
|
| 214 |
+
}
|
| 215 |
+
.modal-content h3 {
|
| 216 |
+
margin-top: 0;
|
| 217 |
+
margin-bottom: 20px;
|
| 218 |
+
border-bottom: 1px solid var(--border-color);
|
| 219 |
+
padding-bottom: 10px;
|
| 220 |
+
color: var(--accent-color);
|
| 221 |
}
|
|
|
|
| 222 |
.modal-close-button {
|
| 223 |
+
position: absolute;
|
| 224 |
+
top: 15px;
|
| 225 |
+
right: 15px;
|
| 226 |
+
background: none;
|
| 227 |
+
border: none;
|
| 228 |
+
font-size: 24px;
|
| 229 |
+
color: var(--text-secondary);
|
| 230 |
+
cursor: pointer;
|
| 231 |
+
}
|
| 232 |
+
/* Admin Panel */
|
| 233 |
+
.admin-panel {
|
| 234 |
+
max-width: 700px;
|
| 235 |
+
max-height: 90vh;
|
| 236 |
+
overflow-y: auto;
|
| 237 |
+
}
|
| 238 |
+
.admin-section {
|
| 239 |
+
margin-bottom: 25px;
|
| 240 |
+
}
|
| 241 |
+
.admin-buttons-grid {
|
| 242 |
+
display: grid;
|
| 243 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
| 244 |
+
gap: 15px;
|
| 245 |
+
}
|
| 246 |
+
.admin-button {
|
| 247 |
+
background-color: var(--bg-primary);
|
| 248 |
+
border: 1px solid var(--border-color);
|
| 249 |
+
color: var(--text-primary);
|
| 250 |
+
padding: 12px;
|
| 251 |
+
border-radius: 8px;
|
| 252 |
+
cursor: pointer;
|
| 253 |
+
font-size: 15px;
|
| 254 |
+
font-weight: 500;
|
| 255 |
+
text-align: left;
|
| 256 |
+
display: flex;
|
| 257 |
+
align-items: center;
|
| 258 |
+
gap: 10px;
|
| 259 |
+
transition: background-color 0.3s, color 0.3s, transform 0.2s;
|
| 260 |
+
}
|
| 261 |
+
.admin-button:hover {
|
| 262 |
+
background-color: var(--accent-color);
|
| 263 |
+
color: #fff;
|
| 264 |
+
border-color: var(--accent-color);
|
| 265 |
+
transform: translateY(-2px);
|
| 266 |
+
}
|
| 267 |
+
.admin-button .fa-fw {
|
| 268 |
+
font-size: 18px;
|
| 269 |
+
}
|
| 270 |
+
.status-display {
|
| 271 |
+
background: var(--bg-primary);
|
| 272 |
+
padding: 15px;
|
| 273 |
+
border-radius: 8px;
|
| 274 |
+
font-family: monospace;
|
| 275 |
+
font-size: 13px;
|
| 276 |
+
white-space: pre-wrap;
|
| 277 |
+
word-wrap: break-word;
|
| 278 |
+
border: 1px solid var(--border-color);
|
| 279 |
+
}
|
| 280 |
+
/* Credentials Modal */
|
| 281 |
+
#credentials-modal .modal-content {
|
| 282 |
+
max-width: 400px;
|
| 283 |
+
}
|
| 284 |
+
.form-group {
|
| 285 |
+
margin-bottom: 15px;
|
| 286 |
+
}
|
| 287 |
+
.form-group label {
|
| 288 |
+
display: block;
|
| 289 |
+
margin-bottom: 5px;
|
| 290 |
+
font-weight: 500;
|
| 291 |
+
}
|
| 292 |
+
.form-group input {
|
| 293 |
+
width: 100%;
|
| 294 |
+
padding: 10px;
|
| 295 |
+
border: 1px solid var(--border-color);
|
| 296 |
+
border-radius: 6px;
|
| 297 |
+
background: var(--bg-primary);
|
| 298 |
+
color: var(--text-primary);
|
| 299 |
+
}
|
| 300 |
+
.modal-actions {
|
| 301 |
+
display: flex;
|
| 302 |
+
justify-content: flex-end;
|
| 303 |
+
gap: 10px;
|
| 304 |
+
margin-top: 20px;
|
| 305 |
+
}
|
| 306 |
+
.modal-button {
|
| 307 |
+
padding: 10px 20px;
|
| 308 |
+
border-radius: 6px;
|
| 309 |
+
border: none;
|
| 310 |
+
cursor: pointer;
|
| 311 |
+
}
|
| 312 |
+
.modal-button.primary {
|
| 313 |
+
background: var(--accent-color);
|
| 314 |
+
color: #fff;
|
| 315 |
+
}
|
| 316 |
+
.modal-button.secondary {
|
| 317 |
+
background: var(--border-color);
|
| 318 |
+
color: var(--text-primary);
|
| 319 |
+
}
|
| 320 |
</style>
|
| 321 |
</head>
|
| 322 |
+
<body>
|
| 323 |
+
<div class="chat-container">
|
| 324 |
+
<div class="chat-header">
|
| 325 |
+
<h2>EndoBot Prueba</h2>
|
| 326 |
+
<div class="header-buttons">
|
| 327 |
+
<button id="admin-panel-button" class="icon-button" title="Admin Panel"><i class="fas fa-shield-halved"></i></button>
|
| 328 |
+
<button id="theme-toggle" class="icon-button" title="Toggle Theme"><i class="fas fa-moon"></i></button>
|
| 329 |
</div>
|
|
|
|
| 330 |
</div>
|
| 331 |
+
<div class="chat-messages" id="chat-messages"></div>
|
| 332 |
+
<div class="chat-input">
|
| 333 |
+
<textarea id="user-input" placeholder="Type your message here..." rows="1" disabled></textarea>
|
| 334 |
+
<button id="send-button" disabled><i class="fas fa-paper-plane"></i></button>
|
|
|
|
|
|
|
|
|
|
| 335 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
</div>
|
|
|
|
| 337 |
<div class="modal-overlay" id="admin-modal-overlay">
|
| 338 |
+
<div class="modal-content admin-panel">
|
| 339 |
<button class="modal-close-button" id="modal-close-btn">×</button>
|
| 340 |
<h3><i class="fas fa-cogs"></i> System Control Panel</h3>
|
| 341 |
<div class="admin-section">
|
| 342 |
+
<h4><i class="fas fa-bolt"></i> Actions</h4>
|
| 343 |
<div class="admin-buttons-grid">
|
| 344 |
+
<button class="admin-button" id="rebuild-index-button"><i class="fas fa-fw fa-sync-alt"></i> Rebuild Document Index</button>
|
| 345 |
+
<button class="admin-button" id="download-db-button"><i class="fas fa-fw fa-database"></i> Download QA Database</button>
|
| 346 |
+
<button class="admin-button" id="download-log-button"><i class="fas fa-fw fa-file-csv"></i> Download Chat Log</button>
|
| 347 |
+
<button class="admin-button" id="clear-history-button"><i class="fas fa-fw fa-trash"></i> Clear Current Chat</button>
|
| 348 |
+
<button class="admin-button" id="change-credentials-button"><i class="fas fa-fw fa-key"></i> Change Credentials</button>
|
| 349 |
+
</div>
|
| 350 |
+
</div>
|
| 351 |
+
<div class="admin-section">
|
| 352 |
+
<h4><i class="fas fa-chart-line"></i> System Status <button id="refresh-status-button" style="margin-left: 10px; font-size: 12px; padding: 4px 8px; cursor: pointer;">Refresh</button></h4>
|
| 353 |
+
<div id="status-container">
|
| 354 |
+
<div class="status-display" id="rag-status-display">Enter credentials to view status...</div>
|
| 355 |
+
</div>
|
| 356 |
</div>
|
| 357 |
</div>
|
| 358 |
</div>
|
| 359 |
<div class="modal-overlay" id="credentials-modal">
|
| 360 |
+
<div class="modal-content">
|
| 361 |
<h3 id="credentials-title">Authentication Required</h3>
|
| 362 |
<div class="form-group">
|
| 363 |
<label for="username-input">Username</label>
|
| 364 |
+
<input type="text" id="username-input" autocomplete="username">
|
| 365 |
</div>
|
| 366 |
<div class="form-group">
|
| 367 |
<label for="password-input">Password</label>
|
| 368 |
+
<input type="password" id="password-input" autocomplete="current-password">
|
| 369 |
</div>
|
| 370 |
<div class="modal-actions">
|
| 371 |
<button id="credentials-cancel-btn" class="modal-button secondary">Cancel</button>
|
|
|
|
| 373 |
</div>
|
| 374 |
</div>
|
| 375 |
</div>
|
|
|
|
| 376 |
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
| 377 |
<script src="https://unpkg.com/autosize@4.0.2/dist/autosize.min.js"></script>
|
|
|
|
| 378 |
<script>
|
| 379 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 380 |
+
// --- STATE MANAGEMENT ---
|
| 381 |
+
let sessionId = null;
|
| 382 |
+
let sessionAuth = {
|
| 383 |
+
admin: null, // { username, password }
|
| 384 |
+
report: null // { username, password }
|
| 385 |
+
};
|
| 386 |
+
// --- ELEMENT SELECTORS ---
|
| 387 |
+
const ui = {
|
| 388 |
+
sendButton: document.getElementById('send-button'),
|
| 389 |
+
userInput: document.getElementById('user-input'),
|
| 390 |
+
chatMessages: document.getElementById('chat-messages'),
|
| 391 |
+
themeToggle: document.getElementById('theme-toggle'),
|
| 392 |
+
adminPanelButton: document.getElementById('admin-panel-button'),
|
| 393 |
+
adminModal: {
|
| 394 |
+
overlay: document.getElementById('admin-modal-overlay'),
|
| 395 |
+
closeBtn: document.getElementById('modal-close-btn'),
|
| 396 |
+
rebuildIndexBtn: document.getElementById('rebuild-index-button'),
|
| 397 |
+
clearHistoryBtn: document.getElementById('clear-history-button'),
|
| 398 |
+
downloadDbBtn: document.getElementById('download-db-button'),
|
| 399 |
+
downloadLogBtn: document.getElementById('download-log-button'),
|
| 400 |
+
refreshStatusBtn: document.getElementById('refresh-status-button'),
|
| 401 |
+
changeCredsBtn: document.getElementById('change-credentials-button'),
|
| 402 |
+
statusDisplay: document.getElementById('rag-status-display')
|
| 403 |
+
},
|
| 404 |
+
credsModal: {
|
| 405 |
+
overlay: document.getElementById('credentials-modal'),
|
| 406 |
+
title: document.getElementById('credentials-title'),
|
| 407 |
+
usernameInput: document.getElementById('username-input'),
|
| 408 |
+
passwordInput: document.getElementById('password-input'),
|
| 409 |
+
cancelBtn: document.getElementById('credentials-cancel-btn'),
|
| 410 |
+
submitBtn: document.getElementById('credentials-submit-btn')
|
| 411 |
+
}
|
| 412 |
+
};
|
| 413 |
+
autosize(ui.userInput);
|
| 414 |
+
// --- THEME MANAGEMENT ---
|
| 415 |
+
const applyTheme = (theme) => {
|
| 416 |
+
document.documentElement.setAttribute('data-theme', theme);
|
| 417 |
+
localStorage.setItem('chatTheme', theme);
|
| 418 |
+
ui.themeToggle.innerHTML = `<i class="fas ${theme === 'dark' ? 'fa-sun' : 'fa-moon'}"></i>`;
|
| 419 |
+
};
|
| 420 |
+
const toggleTheme = () => applyTheme(document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark');
|
| 421 |
+
// --- MODAL MANAGEMENT ---
|
| 422 |
+
const toggleModal = (modalOverlay, show) => modalOverlay.classList.toggle('visible', show);
|
| 423 |
+
// --- CHAT MESSAGING ---
|
| 424 |
+
const initializeChat = async () => {
|
| 425 |
+
applyTheme(localStorage.getItem('chatTheme') || 'light');
|
| 426 |
+
try {
|
| 427 |
+
const response = await axios.post('/create-session');
|
| 428 |
+
sessionId = response.data.session_id;
|
| 429 |
+
ui.userInput.disabled = false;
|
| 430 |
+
ui.sendButton.disabled = false;
|
| 431 |
+
appendMessage({sender: 'bot', text: 'Hola! Soy tu asistente personal experto en endodoncia. En que te puedo ayudar hoy?'});
|
| 432 |
+
} catch (error) {
|
| 433 |
+
console.error('Error creating session:', error);
|
| 434 |
+
appendMessage({sender: 'bot', text: 'Problema al inicial la sesión. Por favor refresca la pagina.'});
|
| 435 |
+
}
|
| 436 |
+
};
|
| 437 |
+
const appendMessage = ({ sender, text, isHtml = false }) => {
|
| 438 |
+
const typingIndicator = ui.chatMessages.querySelector('.typing-indicator-wrapper');
|
| 439 |
+
if (typingIndicator) typingIndicator.remove();
|
| 440 |
+
const messageElement = document.createElement('div');
|
| 441 |
+
messageElement.className = `message ${sender}`;
|
| 442 |
+
messageElement.innerHTML = `<div class="message-content">${isHtml ? text : `<p>${text.replace(/</g, "<").replace(/>/g, ">")}</p>`}</div>`;
|
| 443 |
+
ui.chatMessages.appendChild(messageElement);
|
| 444 |
+
ui.chatMessages.scrollTop = ui.chatMessages.scrollHeight;
|
| 445 |
+
};
|
| 446 |
+
const showTypingIndicator = () => {
|
| 447 |
+
if (ui.chatMessages.querySelector('.typing-indicator-wrapper')) return;
|
| 448 |
+
const indicatorWrapper = document.createElement('div');
|
| 449 |
+
indicatorWrapper.className = 'message bot typing-indicator-wrapper';
|
| 450 |
+
indicatorWrapper.innerHTML = `
|
| 451 |
+
<div class="message-content">
|
| 452 |
+
<div class="typing-indicator">
|
| 453 |
+
<span></span><span style="animation-delay: 0.2s"></span><span style="animation-delay: 0.4s"></span>
|
| 454 |
+
</div>
|
| 455 |
+
</div>`;
|
| 456 |
+
ui.chatMessages.appendChild(indicatorWrapper);
|
| 457 |
+
ui.chatMessages.scrollTop = ui.chatMessages.scrollHeight;
|
| 458 |
+
};
|
| 459 |
+
const sendMessage = async () => {
|
| 460 |
+
if (!sessionId) return;
|
| 461 |
+
const message = ui.userInput.value.trim();
|
| 462 |
+
if (message === '') return;
|
| 463 |
+
appendMessage({sender: 'user', text: message});
|
| 464 |
+
ui.userInput.value = '';
|
| 465 |
+
autosize.update(ui.userInput);
|
| 466 |
+
showTypingIndicator();
|
| 467 |
+
try {
|
| 468 |
+
const response = await axios.post('/chat-bot', { query: message, session_id: sessionId });
|
| 469 |
+
const rawResponse = response.data?.answer || 'Perdona, no puedo procesar eso.';
|
| 470 |
+
const cleanResponse = rawResponse.replace(/<think>[\s\S]*?<\/think>/, '').trim();
|
| 471 |
+
if (cleanResponse) {
|
| 472 |
+
appendMessage({sender: 'bot', text: cleanResponse});
|
| 473 |
+
} else {
|
| 474 |
+
appendMessage({sender: 'bot', text: 'Perdona, he recibido una respuesta vacia.'});
|
| 475 |
+
}
|
| 476 |
+
} catch (error) {
|
| 477 |
+
console.error('Error sending message:', error);
|
| 478 |
+
appendMessage({sender: 'bot', text: 'A critical error occurred. Please check the server logs.'});
|
| 479 |
+
}
|
| 480 |
+
};
|
| 481 |
+
// --- CREDENTIALS MANAGEMENT ---
|
| 482 |
+
const getCredentials = (type) => {
|
| 483 |
+
return new Promise((resolve, reject) => {
|
| 484 |
+
if (sessionAuth[type]) {
|
| 485 |
+
return resolve(sessionAuth[type]);
|
| 486 |
+
}
|
| 487 |
+
ui.credsModal.title.textContent = `${type.charAt(0).toUpperCase() + type.slice(1)} Authentication`;
|
| 488 |
+
ui.credsModal.usernameInput.value = '';
|
| 489 |
+
ui.credsModal.passwordInput.value = '';
|
| 490 |
+
toggleModal(ui.credsModal.overlay, true);
|
| 491 |
+
ui.credsModal.usernameInput.focus();
|
| 492 |
+
const handleSubmit = () => {
|
| 493 |
+
const username = ui.credsModal.usernameInput.value;
|
| 494 |
+
const password = ui.credsModal.passwordInput.value;
|
| 495 |
+
cleanup();
|
| 496 |
+
if (username && password) {
|
| 497 |
+
resolve({ username, password });
|
| 498 |
+
} else {
|
| 499 |
+
reject(new Error('Credentials not provided.'));
|
| 500 |
+
}
|
| 501 |
+
};
|
| 502 |
+
const handleCancel = () => {
|
| 503 |
+
cleanup();
|
| 504 |
+
reject(new Error('Authentication cancelled.'));
|
| 505 |
+
};
|
| 506 |
+
const cleanup = () => {
|
| 507 |
+
ui.credsModal.submitBtn.removeEventListener('click', handleSubmit);
|
| 508 |
+
ui.credsModal.cancelBtn.removeEventListener('click', handleCancel);
|
| 509 |
+
toggleModal(ui.credsModal.overlay, false);
|
| 510 |
+
};
|
| 511 |
+
ui.credsModal.submitBtn.addEventListener('click', handleSubmit);
|
| 512 |
+
ui.credsModal.cancelBtn.addEventListener('click', handleCancel);
|
| 513 |
+
});
|
| 514 |
+
};
|
| 515 |
+
// --- ADMIN FUNCTIONS ---
|
| 516 |
+
const handleApiError = (error, type) => {
|
| 517 |
+
if (error.response?.status === 401) {
|
| 518 |
+
sessionAuth[type] = null;
|
| 519 |
+
alert(`${type.charAt(0).toUpperCase() + type.slice(1)} authentication failed. Please try again.`);
|
| 520 |
+
} else {
|
| 521 |
+
alert(`An operation failed. Status: ${error.response?.status}. Check server logs.`);
|
| 522 |
+
}
|
| 523 |
+
};
|
| 524 |
+
const forceRebuildIndex = async () => {
|
| 525 |
+
if (!confirm('This will trigger a full re-index. This can take several minutes. Continue?')) return;
|
| 526 |
+
try {
|
| 527 |
+
const auth = await getCredentials('admin');
|
| 528 |
+
appendMessage({sender: 'bot', text: 'System re-index process started...'});
|
| 529 |
+
toggleModal(ui.adminModal.overlay, false);
|
| 530 |
+
const response = await axios.post('/admin/rebuild_faiss_index', {}, { auth });
|
| 531 |
+
sessionAuth.admin = auth;
|
| 532 |
+
appendMessage({sender: 'bot', text: `✅ SUCCESS: ${response.data.message}`});
|
| 533 |
+
} catch (error) {
|
| 534 |
+
if (error.message !== 'Authentication cancelled.') {
|
| 535 |
+
appendMessage({ sender: 'bot', text: `❌ ERROR: Re-index process failed.` });
|
| 536 |
+
handleApiError(error, 'admin');
|
| 537 |
+
} else {
|
| 538 |
+
console.log("Admin action cancelled by user.");
|
| 539 |
+
}
|
| 540 |
+
}
|
| 541 |
+
};
|
| 542 |
+
const downloadFile = async (url, type, defaultFilename) => {
|
| 543 |
+
try {
|
| 544 |
+
const auth = await getCredentials(type);
|
| 545 |
+
const response = await axios.get(url, { auth, responseType: 'blob' });
|
| 546 |
+
sessionAuth[type] = auth;
|
| 547 |
+
const blobUrl = window.URL.createObjectURL(new Blob([response.data]));
|
| 548 |
+
const link = document.createElement('a');
|
| 549 |
+
link.href = blobUrl;
|
| 550 |
+
const disposition = response.headers['content-disposition'];
|
| 551 |
+
link.download = disposition?.match(/filename="(.+)"/)?.[1] || defaultFilename;
|
| 552 |
+
document.body.appendChild(link);
|
| 553 |
+
link.click();
|
| 554 |
+
link.remove();
|
| 555 |
+
window.URL.revokeObjectURL(blobUrl);
|
| 556 |
+
} catch (error) {
|
| 557 |
+
if (error.message !== 'Authentication cancelled.') handleApiError(error, type);
|
| 558 |
+
}
|
| 559 |
+
};
|
| 560 |
+
const clearHistory = async () => {
|
| 561 |
+
if (!confirm('Clear the current chat on screen and on the server? This cannot be undone.')) return;
|
| 562 |
+
try {
|
| 563 |
+
await axios.post('/clear-history', { session_id: sessionId });
|
| 564 |
+
ui.chatMessages.innerHTML = '';
|
| 565 |
+
appendMessage({sender: 'bot', text: 'El historial de chat de esta sesión se ha borrado.'});
|
| 566 |
+
toggleModal(ui.adminModal.overlay, false);
|
| 567 |
+
} catch (error) {
|
| 568 |
+
alert('Failed to clear history on the server.');
|
| 569 |
+
}
|
| 570 |
+
};
|
| 571 |
+
const refreshAdminStatus = async () => {
|
| 572 |
+
ui.adminModal.statusDisplay.textContent = 'Authenticating and fetching status...';
|
| 573 |
+
try {
|
| 574 |
+
const auth = await getCredentials('admin');
|
| 575 |
+
const [ragStatusRes, dbStatusRes] = await Promise.all([
|
| 576 |
+
axios.get('/admin/faiss_rag_status', { auth }),
|
| 577 |
+
axios.get('/db/status', { auth })
|
| 578 |
+
]);
|
| 579 |
+
sessionAuth.admin = auth;
|
| 580 |
+
let statusText = `--- RAG System ---\n${JSON.stringify(ragStatusRes.data, null, 2)}`;
|
| 581 |
+
statusText += `\n\n--- Personal DB Monitor ---\n${JSON.stringify(dbStatusRes.data, null, 2)}`;
|
| 582 |
+
ui.adminModal.statusDisplay.textContent = statusText;
|
| 583 |
+
} catch (error) {
|
| 584 |
+
if (error.message !== 'Authentication cancelled.') {
|
| 585 |
+
handleApiError(error, 'admin');
|
| 586 |
+
ui.adminModal.statusDisplay.textContent = 'Failed to fetch status. Please try again.';
|
| 587 |
+
} else {
|
| 588 |
+
ui.adminModal.statusDisplay.textContent = 'Authentication cancelled. Please provide credentials to see status.';
|
| 589 |
+
}
|
| 590 |
+
}
|
| 591 |
+
};
|
| 592 |
+
// --- EVENT LISTENERS ---
|
| 593 |
+
ui.sendButton.addEventListener('click', sendMessage);
|
| 594 |
+
ui.userInput.addEventListener('keypress', (e) => e.key === 'Enter' && !e.shiftKey && (e.preventDefault(), sendMessage()));
|
| 595 |
ui.themeToggle.addEventListener('click', toggleTheme);
|
|
|
|
|
|
|
| 596 |
ui.adminPanelButton.addEventListener('click', () => toggleModal(ui.adminModal.overlay, true));
|
|
|
|
|
|
|
| 597 |
ui.adminModal.closeBtn.addEventListener('click', () => toggleModal(ui.adminModal.overlay, false));
|
| 598 |
+
ui.adminModal.overlay.addEventListener('click', (e) => e.target === ui.adminModal.overlay && toggleModal(ui.adminModal.overlay, false));
|
| 599 |
+
ui.adminModal.rebuildIndexBtn.addEventListener('click', forceRebuildIndex);
|
| 600 |
+
ui.adminModal.downloadDbBtn.addEventListener('click', () => downloadFile('/admin/download_qa_database', 'admin', 'qa_database.xlsx'));
|
| 601 |
+
ui.adminModal.downloadLogBtn.addEventListener('click', () => downloadFile('/report', 'report', 'chat_history.csv'));
|
| 602 |
+
ui.adminModal.clearHistoryBtn.addEventListener('click', clearHistory);
|
| 603 |
+
ui.adminModal.refreshStatusBtn.addEventListener('click', refreshAdminStatus);
|
| 604 |
+
ui.adminModal.changeCredsBtn.addEventListener('click', () => {
|
| 605 |
+
sessionAuth.admin = null;
|
| 606 |
+
sessionAuth.report = null;
|
| 607 |
+
alert('Stored credentials have been cleared.');
|
| 608 |
+
ui.adminModal.statusDisplay.textContent = 'Credentials cleared. Refresh status to re-enter.';
|
| 609 |
});
|
| 610 |
+
// --- STARTUP ---
|
| 611 |
+
initializeChat();
|
| 612 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 613 |
</script>
|
|
|
|
| 614 |
</body>
|
| 615 |
</html>
|