Update templates/index.html
Browse files- templates/index.html +330 -773
templates/index.html
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html lang="fr">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
@@ -8,10 +8,10 @@
|
|
| 8 |
<script src="https://cdn.tailwindcss.com?plugins=forms,typography"></script>
|
| 9 |
<!-- Font Awesome pour les icônes -->
|
| 10 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 11 |
-
<!-- Google Fonts -->
|
| 12 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 13 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 14 |
-
<link href="https://fonts.googleapis.com/css2?family=
|
| 15 |
<!-- Favicon (Emoji amélioré) -->
|
| 16 |
<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>">
|
| 17 |
<script>
|
|
@@ -20,7 +20,8 @@
|
|
| 20 |
theme: {
|
| 21 |
extend: {
|
| 22 |
fontFamily: {
|
| 23 |
-
|
|
|
|
| 24 |
mono: ['"JetBrains Mono"', 'monospace']
|
| 25 |
},
|
| 26 |
colors: {
|
|
@@ -28,8 +29,12 @@
|
|
| 28 |
secondary: { 50: '#f8fafc', 100: '#f1f5f9', 200: '#e2e8f0', 300: '#cbd5e1', 400: '#94a3b8', 500: '#64748b', 600: '#475569', 700: '#334155', 800: '#1e293b', 900: '#0f172a' },
|
| 29 |
accent: { 50: '#fdf4ff', 100: '#fae8ff', 200: '#f5d0fe', 300: '#f0abfc', 400: '#e879f9', 500: '#d946ef', 600: '#c026d3', 700: '#a21caf', 800: '#86198f', 900: '#701a75' }
|
| 30 |
},
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
}
|
| 34 |
}
|
| 35 |
}
|
|
@@ -37,538 +42,272 @@
|
|
| 37 |
<style>
|
| 38 |
html {
|
| 39 |
scroll-behavior: smooth;
|
| 40 |
-
overflow-x: hidden; /* Empêche le scroll horizontal global */
|
| 41 |
}
|
| 42 |
body {
|
| 43 |
-
font-family: '
|
| 44 |
transition: background-color 0.3s ease, color 0.3s ease;
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
.chat-layout {
|
| 48 |
-
min-height: calc(100vh - 64px);
|
| 49 |
-
display: grid;
|
| 50 |
-
grid-template-rows: 1fr auto;
|
| 51 |
-
}
|
| 52 |
-
::-webkit-scrollbar {
|
| 53 |
-
width: 5px;
|
| 54 |
-
height: 5px;
|
| 55 |
-
}
|
| 56 |
-
::-webkit-scrollbar-track {
|
| 57 |
-
background: transparent;
|
| 58 |
-
}
|
| 59 |
-
::-webkit-scrollbar-thumb {
|
| 60 |
-
background: #cbd5e1;
|
| 61 |
-
border-radius: 5px;
|
| 62 |
-
}
|
| 63 |
-
.dark ::-webkit-scrollbar-thumb {
|
| 64 |
-
background: #475569;
|
| 65 |
}
|
| 66 |
-
|
| 67 |
-
background: #
|
|
|
|
| 68 |
}
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
.message-bubble {
|
| 73 |
-
position: relative;
|
| 74 |
max-width: 85%;
|
| 75 |
-
border-radius:
|
| 76 |
-
padding: 0.
|
| 77 |
-
line-height: 1.
|
| 78 |
animation: message-fade-in 0.3s ease-out;
|
| 79 |
-
box-shadow: 0
|
| 80 |
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
| 81 |
}
|
| 82 |
-
.message-bubble:
|
| 83 |
-
|
| 84 |
-
}
|
| 85 |
-
.dark .message-bubble {
|
| 86 |
-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
| 87 |
-
}
|
| 88 |
-
.dark .message-bubble:hover {
|
| 89 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2), 0 1px 3px rgba(0, 0, 0, 0.3);
|
| 90 |
-
}
|
| 91 |
.user-message {
|
| 92 |
-
|
| 93 |
-
align-self: flex-end;
|
| 94 |
-
background: linear-gradient(to bottom right, #3b82f6, #2563eb);
|
| 95 |
color: white;
|
| 96 |
}
|
| 97 |
.assistant-message {
|
| 98 |
-
|
| 99 |
-
|
| 100 |
}
|
| 101 |
.dark .assistant-message {
|
| 102 |
background-color: #1e293b;
|
| 103 |
color: #e2e8f0;
|
| 104 |
-
border-color: #334155;
|
| 105 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
@keyframes message-fade-in {
|
| 107 |
-
from { opacity: 0; transform: translateY(10px); }
|
| 108 |
-
to { opacity: 1; transform: translateY(0); }
|
| 109 |
}
|
| 110 |
@keyframes pulse-fade {
|
| 111 |
0%, 100% { opacity: 0.5; }
|
| 112 |
50% { opacity: 1; }
|
| 113 |
}
|
| 114 |
-
.typing-indicator {
|
| 115 |
-
|
| 116 |
-
align-items: center;
|
| 117 |
-
margin-left: 0.5rem;
|
| 118 |
-
}
|
| 119 |
-
.typing-dot {
|
| 120 |
-
width: 0.5rem;
|
| 121 |
-
height: 0.5rem;
|
| 122 |
-
border-radius: 50%;
|
| 123 |
-
background-color: currentColor;
|
| 124 |
-
opacity: 0.7;
|
| 125 |
-
margin: 0 0.1rem;
|
| 126 |
-
}
|
| 127 |
.typing-dot:nth-child(1) { animation: pulse-fade 1.2s 0s infinite; }
|
| 128 |
.typing-dot:nth-child(2) { animation: pulse-fade 1.2s 0.2s infinite; }
|
| 129 |
.typing-dot:nth-child(3) { animation: pulse-fade 1.2s 0.4s infinite; }
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
}
|
| 134 |
-
.tooltip {
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
text-align: center;
|
| 144 |
-
border-radius: 6px;
|
| 145 |
-
padding: 0.375rem 0.625rem;
|
| 146 |
-
position: absolute;
|
| 147 |
-
z-index: 1;
|
| 148 |
-
bottom: 125%;
|
| 149 |
-
left: 50%;
|
| 150 |
-
transform: translateX(-50%);
|
| 151 |
-
opacity: 0;
|
| 152 |
-
transition: opacity 0.3s, visibility 0.3s;
|
| 153 |
-
font-size: 0.75rem;
|
| 154 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 155 |
-
pointer-events: none;
|
| 156 |
-
}
|
| 157 |
-
.dark .tooltip .tooltip-text {
|
| 158 |
-
background-color: #475569;
|
| 159 |
-
color: #f1f5f9;
|
| 160 |
-
}
|
| 161 |
-
.tooltip .tooltip-text::after {
|
| 162 |
-
content: "";
|
| 163 |
-
position: absolute;
|
| 164 |
-
top: 100%;
|
| 165 |
-
left: 50%;
|
| 166 |
-
margin-left: -5px;
|
| 167 |
-
border-width: 5px;
|
| 168 |
-
border-style: solid;
|
| 169 |
-
border-color: #1e293b transparent transparent transparent;
|
| 170 |
-
}
|
| 171 |
-
.dark .tooltip .tooltip-text::after {
|
| 172 |
-
border-color: #475569 transparent transparent transparent;
|
| 173 |
-
}
|
| 174 |
-
.tooltip:hover .tooltip-text {
|
| 175 |
-
visibility: visible;
|
| 176 |
-
opacity: 1;
|
| 177 |
-
}
|
| 178 |
-
.copy-btn {
|
| 179 |
-
position: absolute;
|
| 180 |
-
top: 0.5rem;
|
| 181 |
-
right: 0.5rem;
|
| 182 |
-
opacity: 0;
|
| 183 |
-
transition: opacity 0.2s ease, background-color 0.2s ease;
|
| 184 |
-
z-index: 2;
|
| 185 |
-
}
|
| 186 |
-
.message-bubble:hover .copy-btn {
|
| 187 |
-
opacity: 1;
|
| 188 |
-
}
|
| 189 |
-
.file-preview {
|
| 190 |
-
max-width: 300px;
|
| 191 |
-
margin: 0.5rem auto;
|
| 192 |
-
position: relative;
|
| 193 |
-
overflow: hidden;
|
| 194 |
-
border-radius: 0.5rem;
|
| 195 |
-
transition: transform 0.2s ease;
|
| 196 |
-
}
|
| 197 |
-
.file-preview:hover {
|
| 198 |
-
transform: scale(1.02);
|
| 199 |
-
}
|
| 200 |
-
.file-preview img {
|
| 201 |
-
width: 100%;
|
| 202 |
-
height: auto;
|
| 203 |
-
display: block;
|
| 204 |
-
object-fit: cover;
|
| 205 |
-
}
|
| 206 |
-
.chip {
|
| 207 |
-
display: inline-flex;
|
| 208 |
-
align-items: center;
|
| 209 |
-
background: #e0f2fe;
|
| 210 |
-
border-radius: 9999px;
|
| 211 |
-
padding: 0.25rem 0.75rem;
|
| 212 |
-
font-size: 0.75rem;
|
| 213 |
-
font-weight: 500;
|
| 214 |
-
color: #0369a1;
|
| 215 |
-
transition: all 0.2s ease;
|
| 216 |
-
}
|
| 217 |
-
.chip .chip-icon { margin-right: 0.25rem; }
|
| 218 |
-
.chip .chip-close {
|
| 219 |
-
margin-left: 0.25rem;
|
| 220 |
-
cursor: pointer;
|
| 221 |
-
opacity: 0.7;
|
| 222 |
-
transition: opacity 0.2s ease;
|
| 223 |
-
}
|
| 224 |
-
.chip .chip-close:hover { opacity: 1; }
|
| 225 |
-
.dark .chip {
|
| 226 |
-
background: #0c4a6e;
|
| 227 |
-
color: #7dd3fc;
|
| 228 |
-
}
|
| 229 |
-
.toggle-switch {
|
| 230 |
-
position: relative;
|
| 231 |
-
display: inline-block;
|
| 232 |
-
width: 2.5rem;
|
| 233 |
-
height: 1.25rem;
|
| 234 |
-
}
|
| 235 |
-
.toggle-switch input {
|
| 236 |
-
opacity: 0;
|
| 237 |
-
width: 0;
|
| 238 |
-
height: 0;
|
| 239 |
-
}
|
| 240 |
-
.toggle-slider {
|
| 241 |
-
position: absolute;
|
| 242 |
-
cursor: pointer;
|
| 243 |
-
top: 0;
|
| 244 |
-
left: 0;
|
| 245 |
-
right: 0;
|
| 246 |
-
bottom: 0;
|
| 247 |
-
background-color: #cbd5e1;
|
| 248 |
-
transition: .4s;
|
| 249 |
-
border-radius: 1.25rem;
|
| 250 |
-
}
|
| 251 |
-
.toggle-slider:before {
|
| 252 |
-
position: absolute;
|
| 253 |
-
content: "";
|
| 254 |
-
height: 0.875rem;
|
| 255 |
-
width: 0.875rem;
|
| 256 |
-
left: 0.25rem;
|
| 257 |
-
bottom: 0.1875rem;
|
| 258 |
background-color: white;
|
| 259 |
-
|
| 260 |
-
border-
|
| 261 |
-
}
|
| 262 |
-
input:checked + .toggle-slider {
|
| 263 |
-
background-color: #0ea5e9;
|
| 264 |
-
}
|
| 265 |
-
input:focus + .toggle-slider {
|
| 266 |
-
box-shadow: 0 0 1px #0ea5e9;
|
| 267 |
-
}
|
| 268 |
-
input:checked + .toggle-slider:before {
|
| 269 |
-
transform: translateX(1.125rem);
|
| 270 |
-
}
|
| 271 |
-
.dark .toggle-slider {
|
| 272 |
-
background-color: #475569;
|
| 273 |
-
}
|
| 274 |
-
.dark input:checked + .toggle-slider {
|
| 275 |
-
background-color: #38bdf8;
|
| 276 |
-
}
|
| 277 |
-
.chat-input {
|
| 278 |
-
transition: all 0.3s ease;
|
| 279 |
-
border-color: #e2e8f0;
|
| 280 |
-
}
|
| 281 |
-
.chat-input:focus {
|
| 282 |
-
border-color: #38bdf8;
|
| 283 |
-
box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
|
| 284 |
-
}
|
| 285 |
-
.dark .chat-input {
|
| 286 |
-
background-color: #1e293b;
|
| 287 |
-
color: #f1f5f9;
|
| 288 |
-
border-color: #334155;
|
| 289 |
-
}
|
| 290 |
-
.dark .chat-input:focus {
|
| 291 |
-
border-color: #38bdf8;
|
| 292 |
-
box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
|
| 293 |
-
}
|
| 294 |
-
pre {
|
| 295 |
-
position: relative;
|
| 296 |
-
background-color: #f8fafc;
|
| 297 |
-
border-radius: 0.5rem;
|
| 298 |
-
margin: 1rem 0;
|
| 299 |
-
padding: 1.25rem 1rem;
|
| 300 |
-
overflow-x: auto;
|
| 301 |
-
}
|
| 302 |
-
.dark pre {
|
| 303 |
-
background-color: #1e293b;
|
| 304 |
-
color: #e2e8f0;
|
| 305 |
-
}
|
| 306 |
-
code {
|
| 307 |
-
font-family: 'JetBrains Mono', monospace;
|
| 308 |
-
font-size: 0.875rem;
|
| 309 |
-
}
|
| 310 |
-
.code-copy-btn {
|
| 311 |
-
position: absolute;
|
| 312 |
-
top: 0.5rem;
|
| 313 |
-
right: 0.5rem;
|
| 314 |
-
opacity: 0;
|
| 315 |
-
transition: opacity 0.2s ease;
|
| 316 |
-
}
|
| 317 |
-
pre:hover .code-copy-btn {
|
| 318 |
-
opacity: 0.7;
|
| 319 |
-
}
|
| 320 |
-
/* Amélioration de l'affichage des tableaux Markdown */
|
| 321 |
-
.table-wrapper {
|
| 322 |
-
width: 100%;
|
| 323 |
-
overflow-x: auto;
|
| 324 |
-
margin: 1rem 0;
|
| 325 |
-
border: 1px solid #e2e8f0;
|
| 326 |
-
border-radius: 0.5rem;
|
| 327 |
-
}
|
| 328 |
-
.dark .table-wrapper {
|
| 329 |
-
border-color: #334155;
|
| 330 |
}
|
| 331 |
-
.
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
border-collapse: collapse;
|
| 335 |
-
margin: 0;
|
| 336 |
-
}
|
| 337 |
-
.prose table th,
|
| 338 |
-
.prose table td {
|
| 339 |
-
border: 1px solid #e2e8f0;
|
| 340 |
-
padding: 0.5rem 0.75rem;
|
| 341 |
-
text-align: left;
|
| 342 |
-
border-top: none;
|
| 343 |
-
border-left: none;
|
| 344 |
-
border-right: none;
|
| 345 |
-
}
|
| 346 |
-
.prose table th {
|
| 347 |
-
border-bottom-width: 2px;
|
| 348 |
-
}
|
| 349 |
-
.dark .prose table th,
|
| 350 |
-
.dark .prose table td {
|
| 351 |
-
border-color: #334155;
|
| 352 |
-
}
|
| 353 |
-
.prose table thead {
|
| 354 |
-
background-color: #f8fafc;
|
| 355 |
-
font-weight: 600;
|
| 356 |
-
}
|
| 357 |
-
.dark .prose table thead {
|
| 358 |
-
background-color: #1e293b;
|
| 359 |
-
}
|
| 360 |
-
.prose table tbody tr:nth-child(even) {
|
| 361 |
-
background-color: #f8fafc;
|
| 362 |
-
}
|
| 363 |
-
.dark .prose table tbody tr:nth-child(even) {
|
| 364 |
-
background-color: #1e293b;
|
| 365 |
}
|
| 366 |
-
/* Pour le textarea qui s'adapte au contenu */
|
| 367 |
.chat-textarea {
|
| 368 |
-
resize: none;
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
/* Ajustements responsive */
|
| 382 |
@media (max-width: 640px) {
|
| 383 |
-
.message-bubble {
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
}
|
| 387 |
-
.chat-textarea {
|
| 388 |
-
max-height: 120px;
|
| 389 |
-
font-size: 0.95rem;
|
| 390 |
-
min-height: 40px;
|
| 391 |
-
padding-top: 0.5rem;
|
| 392 |
-
padding-bottom: 0.5rem;
|
| 393 |
-
}
|
| 394 |
-
.prose table {
|
| 395 |
-
min-width: 0;
|
| 396 |
-
font-size: 0.85rem;
|
| 397 |
-
}
|
| 398 |
-
.prose table th,
|
| 399 |
-
.prose table td {
|
| 400 |
-
padding: 0.375rem 0.5rem;
|
| 401 |
-
}
|
| 402 |
-
.send-button-wrapper {
|
| 403 |
-
padding-right: 0.25rem;
|
| 404 |
-
}
|
| 405 |
-
.chat-textarea {
|
| 406 |
-
padding-right: 2.75rem;
|
| 407 |
-
}
|
| 408 |
-
#send-button {
|
| 409 |
-
width: 32px;
|
| 410 |
-
height: 32px;
|
| 411 |
-
padding: 0;
|
| 412 |
-
display: inline-flex;
|
| 413 |
-
align-items: center;
|
| 414 |
-
justify-content: center;
|
| 415 |
-
}
|
| 416 |
-
#send-button i {
|
| 417 |
-
font-size: 0.9rem;
|
| 418 |
-
}
|
| 419 |
-
}
|
| 420 |
-
/* Container pour le textarea et le bouton */
|
| 421 |
-
.input-wrapper {
|
| 422 |
-
position: relative;
|
| 423 |
-
display: flex;
|
| 424 |
-
align-items: flex-end;
|
| 425 |
-
}
|
| 426 |
-
.send-button-wrapper {
|
| 427 |
-
position: absolute;
|
| 428 |
-
right: 0.5rem;
|
| 429 |
-
bottom: 0.5rem;
|
| 430 |
}
|
| 431 |
</style>
|
| 432 |
</head>
|
| 433 |
-
<body class="
|
| 434 |
-
|
| 435 |
-
<
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
<div class="flex items-center
|
| 439 |
-
|
| 440 |
-
<
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
<
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
<button type="submit" class="flex items-center bg-red-500 hover:bg-red-600 text-white text-xs font-semibold py-1.5 px-3 rounded-full transition duration-200 focus:outline-none focus:ring-2 focus:ring-red-400 focus:ring-opacity-75 tooltip">
|
| 451 |
-
<i class="fa-solid fa-trash-can mr-1.5"></i>
|
| 452 |
-
<span class="hidden sm:inline">Effacer</span>
|
| 453 |
-
<span class="tooltip-text">Effacer la conversation</span>
|
| 454 |
</button>
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
<!-- Conteneur des messages -->
|
| 462 |
-
<section id="chat-messages" class="flex flex-col space-y-6 p-4 overflow-y-auto">
|
| 463 |
-
<!-- Chargement de l'historique -->
|
| 464 |
-
<div id="history-loading" class="text-center py-10">
|
| 465 |
-
<div class="inline-flex items-center px-4 py-2 bg-primary-50 text-primary-700 rounded-lg dark:bg-primary-900/30 dark:text-primary-300">
|
| 466 |
-
<svg class="animate-spin h-5 w-5 mr-3" viewBox="0 0 24 24">
|
| 467 |
-
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
| 468 |
-
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
| 469 |
-
</svg>
|
| 470 |
-
<span>Chargement de la conversation...</span>
|
| 471 |
</div>
|
| 472 |
</div>
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
</div>
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
</div>
|
| 485 |
</div>
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
<div class="border-t border-gray-200 dark:border-gray-700">
|
| 490 |
-
<!-- Zone d'erreur -->
|
| 491 |
-
<div id="error-message" class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 dark:bg-red-900/30 dark:text-red-300 dark:border-red-600 hidden" role="alert">
|
| 492 |
-
<div class="flex">
|
| 493 |
-
<div class="flex-shrink-0"><i class="fa-solid fa-circle-exclamation"></i></div>
|
| 494 |
-
<div class="ml-3"><p class="text-sm font-medium" id="error-text">Le message d'erreur détaillé ira ici.</p></div>
|
| 495 |
-
<button class="ml-auto" id="dismiss-error"><i class="fa-solid fa-xmark"></i></button>
|
| 496 |
</div>
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
<span class="toggle-slider"></span>
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
</label>
|
| 513 |
-
<label class="flex items-center cursor-pointer tooltip">
|
| 514 |
-
<span class="mr-2 text-xs sm:text-sm font-medium text-accent-700 dark:text-accent-300">
|
| 515 |
-
<i class="fa-solid fa-brain mr-1.5"></i>
|
| 516 |
-
<span class="hidden sm:inline">Avancé</span>
|
| 517 |
-
<span id="advanced-cooldown-timer" class="text-xs ml-1 hidden"></span>
|
| 518 |
-
</span>
|
| 519 |
-
<span class="toggle-switch">
|
| 520 |
-
<input type="checkbox" id="advanced_reasoning_toggle" name="advanced_reasoning" value="true">
|
| 521 |
-
<span class="toggle-slider"></span>
|
| 522 |
-
</span>
|
| 523 |
-
<span class="tooltip-text">Raisonnement avancé (1 fois/min)</span>
|
| 524 |
-
</label>
|
| 525 |
-
</div>
|
| 526 |
-
<div class="flex items-center space-x-2">
|
| 527 |
-
<label for="file_upload" class="cursor-pointer flex items-center text-primary-600 hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300 tooltip">
|
| 528 |
-
<i class="fa-solid fa-paperclip"></i>
|
| 529 |
-
<span class="ml-1.5 hidden sm:inline">Fichier</span>
|
| 530 |
-
<input type="file" id="file_upload" name="file" class="hidden" accept=".txt,.pdf,.png,.jpg,.jpeg">
|
| 531 |
-
<span class="tooltip-text">Joindre (txt, pdf, image)</span>
|
| 532 |
-
</label>
|
| 533 |
-
<div id="file-chip" class="chip hidden">
|
| 534 |
-
<i class="fa-solid fa-file chip-icon"></i>
|
| 535 |
-
<span id="file-name" class="truncate max-w-[100px] sm:max-w-[120px]"></span>
|
| 536 |
-
<i id="clear-file" class="fa-solid fa-xmark chip-close"></i>
|
| 537 |
</div>
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
<button
|
| 552 |
type="submit"
|
| 553 |
id="send-button"
|
| 554 |
-
class="bg-primary-500 hover:bg-primary-600 disabled:bg-primary-300 text-white rounded-full
|
| 555 |
-
title="Envoyer
|
| 556 |
<i class="fa-solid fa-paper-plane text-sm"></i>
|
| 557 |
</button>
|
| 558 |
</div>
|
| 559 |
-
</
|
| 560 |
-
|
| 561 |
-
Appuyez sur <kbd class="px-1.5 py-0.5 bg-gray-100 dark:bg-gray-800 rounded border border-gray-300 dark:border-gray-700">Entrée</kbd>
|
| 562 |
-
<span class="hidden sm:inline"> pour envoyer</span>
|
| 563 |
-
<span class="sm:hidden"> pour une nouvelle ligne</span>
|
| 564 |
-
•
|
| 565 |
-
<kbd class="px-1.5 py-0.5 bg-gray-100 dark:bg-gray-800 rounded border border-gray-300 dark:border-gray-700">Shift+Entrée</kbd>
|
| 566 |
-
<span class="hidden sm:inline"> pour une nouvelle ligne</span>
|
| 567 |
-
<span class="sm:hidden"> pour envoyer</span>
|
| 568 |
-
</div>
|
| 569 |
-
</form>
|
| 570 |
</div>
|
| 571 |
-
</
|
|
|
|
| 572 |
<!-- Scripts -->
|
| 573 |
<script>
|
| 574 |
document.addEventListener('DOMContentLoaded', () => {
|
|
@@ -610,13 +349,8 @@
|
|
| 610 |
}
|
| 611 |
}
|
| 612 |
function toggleTheme() {
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
localStorage.theme = 'light';
|
| 616 |
-
} else {
|
| 617 |
-
document.documentElement.classList.add('dark');
|
| 618 |
-
localStorage.theme = 'dark';
|
| 619 |
-
}
|
| 620 |
}
|
| 621 |
themeToggleBtn.addEventListener('click', toggleTheme);
|
| 622 |
initializeTheme();
|
|
@@ -639,23 +373,16 @@
|
|
| 639 |
|
| 640 |
// Affichage de l'indicateur de chargement
|
| 641 |
function showLoading(show) {
|
|
|
|
| 642 |
if (show) {
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
scrollToBottom();
|
| 646 |
-
} else {
|
| 647 |
-
loadingIndicator.classList.add('hidden');
|
| 648 |
}
|
| 649 |
sendButton.disabled = show;
|
| 650 |
promptInput.disabled = show;
|
| 651 |
fileUpload.disabled = show;
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
clearFileButton.style.opacity = '0.5';
|
| 655 |
-
} else {
|
| 656 |
-
clearFileButton.style.pointerEvents = 'auto';
|
| 657 |
-
clearFileButton.style.opacity = '0.7';
|
| 658 |
-
}
|
| 659 |
}
|
| 660 |
|
| 661 |
// Affichage des erreurs
|
|
@@ -669,67 +396,54 @@
|
|
| 669 |
function addMessageToChat(role, content, isHtml = false) {
|
| 670 |
errorMessageDiv.classList.add('hidden');
|
| 671 |
const messageWrapper = document.createElement('div');
|
| 672 |
-
messageWrapper.
|
|
|
|
|
|
|
| 673 |
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
} else {
|
| 678 |
-
messageContentHtml = `<p class="text-sm sm:text-base whitespace-pre-wrap">${escapeHtml(content)}</p>`;
|
| 679 |
-
}
|
| 680 |
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
<div class="message-bubble user-message">
|
| 685 |
-
${messageContentHtml}
|
| 686 |
-
</div>
|
| 687 |
-
`;
|
| 688 |
-
} else {
|
| 689 |
-
bubbleHtml = `
|
| 690 |
-
<div class="flex items-start space-x-2 max-w-[85%]">
|
| 691 |
-
<div class="w-8 h-8 rounded-full bg-primary-100 flex items-center justify-center flex-shrink-0 dark:bg-primary-900/50">
|
| 692 |
-
<span class="text-lg">✨</span>
|
| 693 |
-
</div>
|
| 694 |
-
<div class="message-bubble assistant-message bg-secondary-50 text-secondary-900 border border-secondary-200 relative">
|
| 695 |
<div class="prose prose-sm sm:prose-base max-w-none dark:prose-invert">
|
| 696 |
-
|
| 697 |
</div>
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
</div>
|
| 703 |
-
|
| 704 |
-
|
| 705 |
messageWrapper.innerHTML = bubbleHtml;
|
| 706 |
|
| 707 |
-
// Activation du bouton de copie
|
| 708 |
-
const
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
const textToCopy = this.closest('.message-bubble').querySelector('.prose').innerText
|
| 712 |
navigator.clipboard.writeText(textToCopy).then(() => {
|
| 713 |
const originalText = this.innerHTML;
|
| 714 |
-
this.innerHTML = '<i class="fa-solid fa-check mr-1"></i> Copié';
|
| 715 |
setTimeout(() => { this.innerHTML = originalText; }, 2000);
|
| 716 |
}).catch(err => console.error('Copy failed:', err));
|
| 717 |
});
|
| 718 |
-
}
|
| 719 |
-
|
| 720 |
// Activation de la copie pour les blocs de code
|
| 721 |
const codeBlocks = messageWrapper.querySelectorAll('pre');
|
| 722 |
codeBlocks.forEach(pre => {
|
| 723 |
const code = pre.querySelector('code');
|
| 724 |
-
if (!code) return;
|
| 725 |
-
if (pre.querySelector('.code-copy-btn')) return;
|
| 726 |
const copyButton = document.createElement('button');
|
| 727 |
copyButton.innerHTML = '<i class="fa-regular fa-copy"></i>';
|
| 728 |
-
copyButton.className = 'code-copy-btn p-1.5 bg-gray-200/50 dark:bg-gray-700/50 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-300/70 dark:hover:bg-gray-600/70 tooltip';
|
| 729 |
copyButton.setAttribute('aria-label', 'Copier le code');
|
| 730 |
const tooltipText = document.createElement('span');
|
| 731 |
tooltipText.className = 'tooltip-text !text-xs';
|
| 732 |
-
tooltipText.textContent = 'Copier
|
| 733 |
copyButton.appendChild(tooltipText);
|
| 734 |
copyButton.addEventListener('click', () => {
|
| 735 |
navigator.clipboard.writeText(code.innerText).then(() => {
|
|
@@ -738,12 +452,8 @@
|
|
| 738 |
setTimeout(() => {
|
| 739 |
copyButton.innerHTML = '<i class="fa-regular fa-copy"></i>';
|
| 740 |
copyButton.appendChild(tooltipText);
|
| 741 |
-
tooltipText.textContent = 'Copier
|
| 742 |
}, 2000);
|
| 743 |
-
}).catch(err => {
|
| 744 |
-
tooltipText.textContent = 'Erreur copie';
|
| 745 |
-
console.error('Failed to copy code: ', err);
|
| 746 |
-
setTimeout(() => { tooltipText.textContent = 'Copier le code'; }, 2000);
|
| 747 |
});
|
| 748 |
});
|
| 749 |
pre.appendChild(copyButton);
|
|
@@ -753,12 +463,7 @@
|
|
| 753 |
scrollToBottom();
|
| 754 |
}
|
| 755 |
function escapeHtml(unsafe) {
|
| 756 |
-
return unsafe
|
| 757 |
-
.replace(/&/g, "&")
|
| 758 |
-
.replace(/</g, "<")
|
| 759 |
-
.replace(/>/g, ">")
|
| 760 |
-
.replace(/"/g, """)
|
| 761 |
-
.replace(/'/g, "'");
|
| 762 |
}
|
| 763 |
|
| 764 |
// Gestion du cooldown pour le raisonnement avancé
|
|
@@ -778,36 +483,22 @@
|
|
| 778 |
advancedCooldownTimerSpan.classList.remove('hidden');
|
| 779 |
}
|
| 780 |
}, 1000);
|
| 781 |
-
const remainingSeconds = Math.ceil((advancedToggleCooldownEndTime - Date.now()) / 1000);
|
| 782 |
-
advancedCooldownTimerSpan.textContent = `(${remainingSeconds}s)`;
|
| 783 |
-
advancedCooldownTimerSpan.classList.remove('hidden');
|
| 784 |
}
|
| 785 |
-
|
| 786 |
// Chargement de l'historique du chat
|
| 787 |
async function loadChatHistory() {
|
| 788 |
historyLoadingIndicator.style.display = 'flex';
|
| 789 |
try {
|
| 790 |
const response = await fetch(API_HISTORY_ENDPOINT);
|
| 791 |
-
if (!response.ok) {
|
| 792 |
-
let errorMsg = `Erreur serveur (${response.status})`;
|
| 793 |
-
try {
|
| 794 |
-
const errData = await response.json();
|
| 795 |
-
errorMsg = errData.error || errorMsg;
|
| 796 |
-
} catch (e) {}
|
| 797 |
-
throw new Error(errorMsg);
|
| 798 |
-
}
|
| 799 |
const data = await response.json();
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
loadingIndicator.classList.add('hidden');
|
| 803 |
if (data.success && Array.isArray(data.history)) {
|
| 804 |
if (data.history.length === 0) {
|
| 805 |
addMessageToChat('assistant', "Bonjour ! Je suis Mariam, votre assistant IA. Comment puis-je vous aider aujourd'hui ?", true);
|
| 806 |
} else {
|
| 807 |
-
data.history.forEach(message =>
|
| 808 |
-
const isAssistantHtml = message.role === 'assistant';
|
| 809 |
-
addMessageToChat(message.role, message.text, isAssistantHtml);
|
| 810 |
-
});
|
| 811 |
}
|
| 812 |
scrollToBottom(false);
|
| 813 |
} else {
|
|
@@ -815,8 +506,8 @@
|
|
| 815 |
}
|
| 816 |
} catch (error) {
|
| 817 |
displayError(`Impossible de charger l'historique: ${error.message}`);
|
| 818 |
-
if (chatMessages.querySelectorAll('
|
| 819 |
-
addMessageToChat('assistant', "Bonjour ! Je suis Mariam. Je n'ai pas pu charger notre conversation précédente.
|
| 820 |
}
|
| 821 |
} finally {
|
| 822 |
historyLoadingIndicator.remove();
|
|
@@ -825,268 +516,134 @@
|
|
| 825 |
}
|
| 826 |
}
|
| 827 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 828 |
// Gestion des fichiers
|
| 829 |
function clearFileInput() {
|
| 830 |
-
fileUpload.value = '';
|
| 831 |
-
fileChip.classList.add('hidden');
|
| 832 |
-
fileNameSpan.textContent = '';
|
| 833 |
-
fileNameSpan.title = '';
|
| 834 |
-
filePreview.innerHTML = '';
|
| 835 |
-
filePreview.classList.add('hidden');
|
| 836 |
-
previewArea.classList.add('hidden');
|
| 837 |
}
|
| 838 |
fileUpload.addEventListener('change', () => {
|
| 839 |
if (fileUpload.files.length > 0) {
|
| 840 |
-
const file = fileUpload.files[0];
|
| 841 |
-
const name = file.name;
|
| 842 |
-
fileNameSpan.textContent = name;
|
| 843 |
-
fileNameSpan.title = name;
|
| 844 |
-
fileChip.classList.remove('hidden');
|
| 845 |
-
filePreview.innerHTML = '';
|
| 846 |
if (file.type.startsWith('image/')) {
|
| 847 |
const reader = new FileReader();
|
| 848 |
-
reader.onload = (e) => {
|
| 849 |
-
filePreview.innerHTML = `
|
| 850 |
-
<div class="file-preview">
|
| 851 |
-
<img src="${e.target.result}" alt="Prévisualisation: ${escapeHtml(name)}">
|
| 852 |
-
</div>`;
|
| 853 |
-
filePreview.classList.remove('hidden');
|
| 854 |
-
previewArea.classList.remove('hidden');
|
| 855 |
-
};
|
| 856 |
-
reader.onerror = () => {
|
| 857 |
-
filePreview.innerHTML = `<p class="text-red-500 text-xs text-center p-2">Erreur lecture image</p>`;
|
| 858 |
-
filePreview.classList.remove('hidden');
|
| 859 |
-
previewArea.classList.remove('hidden');
|
| 860 |
-
};
|
| 861 |
reader.readAsDataURL(file);
|
| 862 |
} else {
|
| 863 |
-
filePreview.innerHTML =
|
| 864 |
-
|
| 865 |
-
<div class="bg-gray-100 dark:bg-gray-800 p-3 rounded-lg text-center">
|
| 866 |
-
<i class="fa-solid ${getFileIcon(file.type)} text-3xl text-gray-500 dark:text-gray-400 mb-2"></i>
|
| 867 |
-
<p class="text-xs text-gray-500 dark:text-gray-400">${formatFileSize(file.size)}</p>
|
| 868 |
-
</div>
|
| 869 |
-
</div>`;
|
| 870 |
-
filePreview.classList.remove('hidden');
|
| 871 |
-
previewArea.classList.remove('hidden');
|
| 872 |
}
|
| 873 |
-
} else {
|
| 874 |
-
clearFileInput();
|
| 875 |
-
}
|
| 876 |
});
|
| 877 |
-
function getFileIcon(fileType) {
|
| 878 |
-
if (!fileType) return 'fa-file';
|
| 879 |
-
if (fileType.includes('pdf')) return 'fa-file-pdf';
|
| 880 |
-
if (fileType.includes('text')) return 'fa-file-lines';
|
| 881 |
-
return 'fa-file';
|
| 882 |
-
}
|
| 883 |
-
function formatFileSize(bytes) {
|
| 884 |
-
if (bytes === 0) return '0 octets';
|
| 885 |
-
const k = 1024;
|
| 886 |
-
const sizes = ['octets', 'Ko', 'Mo', 'Go', 'To'];
|
| 887 |
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 888 |
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
|
| 889 |
-
}
|
| 890 |
clearFileButton.addEventListener('click', clearFileInput);
|
| 891 |
-
|
| 892 |
// Événements pour le textarea
|
| 893 |
-
promptInput.addEventListener('input', () =>
|
| 894 |
-
adjustTextareaHeight(promptInput);
|
| 895 |
-
});
|
| 896 |
promptInput.addEventListener('keydown', (e) => {
|
| 897 |
if (isComposing) return;
|
| 898 |
const isMobile = window.innerWidth < MOBILE_BREAKPOINT;
|
| 899 |
-
if (e.key === 'Enter') {
|
| 900 |
-
if (isMobile && !e.shiftKey) {
|
| 901 |
-
setTimeout(() => adjustTextareaHeight(promptInput), 0);
|
| 902 |
-
} else if (!isMobile && !e.shiftKey) {
|
| 903 |
e.preventDefault();
|
| 904 |
-
|
| 905 |
-
chatForm.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
|
| 906 |
-
}
|
| 907 |
-
} else if (e.shiftKey) {
|
| 908 |
-
setTimeout(() => adjustTextareaHeight(promptInput), 0);
|
| 909 |
-
if (isMobile) {
|
| 910 |
-
e.preventDefault();
|
| 911 |
-
if (!sendButton.disabled && (promptInput.value.trim() || fileUpload.files.length > 0)) {
|
| 912 |
-
chatForm.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
|
| 913 |
-
}
|
| 914 |
-
}
|
| 915 |
-
}
|
| 916 |
}
|
| 917 |
});
|
| 918 |
promptInput.addEventListener('compositionstart', () => { isComposing = true; });
|
| 919 |
-
promptInput.addEventListener('compositionend', () => {
|
| 920 |
-
isComposing = false;
|
| 921 |
-
setTimeout(() => adjustTextareaHeight(promptInput), 0);
|
| 922 |
-
});
|
| 923 |
adjustTextareaHeight(promptInput);
|
| 924 |
|
| 925 |
// Soumission du formulaire
|
| 926 |
chatForm.addEventListener('submit', async (e) => {
|
| 927 |
e.preventDefault();
|
| 928 |
-
const prompt = promptInput.value.trim();
|
| 929 |
-
|
| 930 |
-
const useWebSearch = webSearchToggle.checked;
|
| 931 |
-
const useAdvanced = advancedToggle.checked;
|
| 932 |
-
if (sendButton.disabled) return;
|
| 933 |
-
if (!prompt && !file) {
|
| 934 |
-
promptInput.focus();
|
| 935 |
-
return;
|
| 936 |
-
}
|
| 937 |
errorMessageDiv.classList.add('hidden');
|
| 938 |
-
if (
|
| 939 |
-
const
|
| 940 |
-
|
| 941 |
-
const remainingSeconds = Math.ceil((advancedToggleCooldownEndTime - now) / 1000);
|
| 942 |
-
displayError(`Le raisonnement avancé est disponible dans ${remainingSeconds} seconde(s).`);
|
| 943 |
-
return;
|
| 944 |
-
}
|
| 945 |
}
|
| 946 |
let userMessageText = prompt;
|
| 947 |
-
if (file && file.name) {
|
| 948 |
-
userMessageText = prompt ? `${prompt}\n[Fichier: ${file.name}]` : `[Fichier joint: ${file.name}]`;
|
| 949 |
-
}
|
| 950 |
addMessageToChat('user', userMessageText);
|
| 951 |
const formData = new FormData();
|
| 952 |
-
formData.append('prompt', prompt);
|
| 953 |
-
formData.append('
|
| 954 |
-
|
| 955 |
-
if (
|
| 956 |
-
|
| 957 |
-
}
|
| 958 |
-
promptInput.value = '';
|
| 959 |
-
adjustTextareaHeight(promptInput);
|
| 960 |
-
clearFileInput();
|
| 961 |
-
if (useAdvanced) {
|
| 962 |
-
startAdvancedCooldownTimer();
|
| 963 |
-
advancedToggle.checked = false;
|
| 964 |
-
}
|
| 965 |
-
webSearchToggle.checked = false;
|
| 966 |
-
showLoading(true);
|
| 967 |
try {
|
| 968 |
const response = await fetch(API_CHAT_ENDPOINT, { method: 'POST', body: formData });
|
| 969 |
const data = await response.json();
|
| 970 |
-
if (!response.ok) {
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
if (data.success && data.message) {
|
| 974 |
-
addMessageToChat('assistant', data.message, true);
|
| 975 |
-
} else {
|
| 976 |
-
throw new Error(data.error || "Réponse invalide ou vide du serveur.");
|
| 977 |
-
}
|
| 978 |
} catch (error) {
|
| 979 |
console.error("Chat Error:", error);
|
| 980 |
addMessageToChat('assistant', `<p class="text-red-600 dark:text-red-400">Désolé, une erreur est survenue :<br>${escapeHtml(error.message)}</p>`, true);
|
| 981 |
} finally {
|
| 982 |
-
showLoading(false);
|
| 983 |
-
promptInput.focus();
|
| 984 |
}
|
| 985 |
});
|
| 986 |
|
| 987 |
// Effacement de la conversation
|
| 988 |
-
clearForm.addEventListener('submit',
|
| 989 |
e.preventDefault();
|
| 990 |
const confirmDialog = document.createElement('div');
|
| 991 |
confirmDialog.className = 'fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4';
|
| 992 |
-
confirmDialog.innerHTML =
|
| 993 |
-
|
| 994 |
-
<h3 class="text-lg font-semibold mb-3 text-gray-900 dark:text-gray-100">Confirmer l'effacement</h3>
|
| 995 |
-
<p class="text-sm text-gray-600 dark:text-gray-300 mb-5">Êtes-vous sûr de vouloir effacer toute la conversation ? Cette action est irréversible.</p>
|
| 996 |
-
<div class="flex justify-end space-x-3">
|
| 997 |
-
<button type="button" id="cancel-clear" class="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-400">
|
| 998 |
-
Annuler
|
| 999 |
-
</button>
|
| 1000 |
-
<button type="button" id="confirm-clear" class="px-4 py-2 text-sm font-medium text-white bg-red-600 rounded hover:bg-red-700 transition-colors focus:outline-none focus:ring-2 focus:ring-red-500">
|
| 1001 |
-
Effacer
|
| 1002 |
-
</button>
|
| 1003 |
-
</div>
|
| 1004 |
-
</div>
|
| 1005 |
-
`;
|
| 1006 |
-
const closeModal = () => {
|
| 1007 |
-
if (document.body.contains(confirmDialog)) {
|
| 1008 |
-
document.body.removeChild(confirmDialog);
|
| 1009 |
-
document.body.style.overflow = '';
|
| 1010 |
-
}
|
| 1011 |
-
};
|
| 1012 |
confirmDialog.querySelector('#cancel-clear').addEventListener('click', closeModal);
|
| 1013 |
confirmDialog.querySelector('#confirm-clear').addEventListener('click', async () => {
|
| 1014 |
closeModal();
|
| 1015 |
const clearButton = e.target.querySelector('button[type="submit"]');
|
| 1016 |
-
const originalButtonContent = clearButton.innerHTML;
|
| 1017 |
clearButton.disabled = true;
|
| 1018 |
-
clearButton.innerHTML = '<i class="fa-solid fa-spinner fa-spin mr-1.5"></i><span class="hidden sm:inline">Effacement...</span>';
|
| 1019 |
try {
|
| 1020 |
-
const response = await fetch(CLEAR_ENDPOINT, {
|
| 1021 |
-
method: 'POST',
|
| 1022 |
-
headers: {
|
| 1023 |
-
'X-Requested-With': 'XMLHttpRequest'
|
| 1024 |
-
}
|
| 1025 |
-
});
|
| 1026 |
const data = await response.json();
|
| 1027 |
if (response.ok && data.success) {
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
addMessageToChat('assistant', "Conversation effacée. Comment puis-je vous aider maintenant ?", true);
|
| 1031 |
-
errorMessageDiv.classList.add('hidden');
|
| 1032 |
} else {
|
| 1033 |
-
throw new Error(data.error || "Impossible d'effacer
|
| 1034 |
}
|
| 1035 |
-
} catch (error) {
|
| 1036 |
-
|
| 1037 |
-
displayError(`Erreur lors de l'effacement: ${error.message}`);
|
| 1038 |
-
} finally {
|
| 1039 |
-
clearButton.innerHTML = originalButtonContent;
|
| 1040 |
-
clearButton.disabled = false;
|
| 1041 |
-
promptInput.focus();
|
| 1042 |
-
}
|
| 1043 |
});
|
| 1044 |
document.body.appendChild(confirmDialog);
|
| 1045 |
-
document.body.style.overflow = 'hidden';
|
| 1046 |
-
confirmDialog.querySelector('#cancel-clear').focus();
|
| 1047 |
});
|
| 1048 |
-
|
| 1049 |
// Initialisation
|
| 1050 |
loadChatHistory();
|
| 1051 |
|
| 1052 |
// Observer pour les tableaux Markdown
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
-
|
| 1064 |
-
|
| 1065 |
-
|
| 1066 |
-
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
|
| 1070 |
-
}
|
| 1071 |
-
});
|
| 1072 |
});
|
| 1073 |
-
|
| 1074 |
-
};
|
| 1075 |
-
observeMarkdownTables();
|
| 1076 |
|
| 1077 |
-
// Gestion du
|
| 1078 |
-
|
| 1079 |
-
const handleSchemeChange = (e) => {
|
| 1080 |
if (!localStorage.getItem('theme')) {
|
| 1081 |
-
|
| 1082 |
-
document.documentElement.classList.add('dark');
|
| 1083 |
-
} else {
|
| 1084 |
-
document.documentElement.classList.remove('dark');
|
| 1085 |
-
}
|
| 1086 |
}
|
| 1087 |
-
};
|
| 1088 |
-
prefersDarkScheme.addEventListener('change', handleSchemeChange);
|
| 1089 |
});
|
| 1090 |
</script>
|
| 1091 |
</body>
|
| 1092 |
-
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<html lang="fr" class="">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
| 8 |
<script src="https://cdn.tailwindcss.com?plugins=forms,typography"></script>
|
| 9 |
<!-- Font Awesome pour les icônes -->
|
| 10 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 11 |
+
<!-- Google Fonts (Lexend pour le corps, JetBrains Mono pour le code) -->
|
| 12 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 13 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 14 |
+
<link href="https://fonts.googleapis.com/css2?family=Lexend:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
| 15 |
<!-- Favicon (Emoji amélioré) -->
|
| 16 |
<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>">
|
| 17 |
<script>
|
|
|
|
| 20 |
theme: {
|
| 21 |
extend: {
|
| 22 |
fontFamily: {
|
| 23 |
+
// Utilisation de la nouvelle police Lexend
|
| 24 |
+
sans: ['Lexend', 'system-ui', 'sans-serif'],
|
| 25 |
mono: ['"JetBrains Mono"', 'monospace']
|
| 26 |
},
|
| 27 |
colors: {
|
|
|
|
| 29 |
secondary: { 50: '#f8fafc', 100: '#f1f5f9', 200: '#e2e8f0', 300: '#cbd5e1', 400: '#94a3b8', 500: '#64748b', 600: '#475569', 700: '#334155', 800: '#1e293b', 900: '#0f172a' },
|
| 30 |
accent: { 50: '#fdf4ff', 100: '#fae8ff', 200: '#f5d0fe', 300: '#f0abfc', 400: '#e879f9', 500: '#d946ef', 600: '#c026d3', 700: '#a21caf', 800: '#86198f', 900: '#701a75' }
|
| 31 |
},
|
| 32 |
+
// Ajout d'une animation pour le modal
|
| 33 |
+
animation: { 'bounce-slow': 'bounce 2s infinite', 'pulse-slow': 'pulse 3s infinite', 'typing': 'typing 1.2s steps(3) infinite', 'dialog-show': 'dialog-show 0.2s ease-out forwards' },
|
| 34 |
+
keyframes: {
|
| 35 |
+
typing: { '0%': { width: '0.15em' }, '50%': { width: '0.7em' }, '100%': { width: '0.15em' } },
|
| 36 |
+
'dialog-show': { from: { opacity: 0, transform: 'scale(0.95)' }, to: { opacity: 1, transform: 'scale(1)' } }
|
| 37 |
+
}
|
| 38 |
}
|
| 39 |
}
|
| 40 |
}
|
|
|
|
| 42 |
<style>
|
| 43 |
html {
|
| 44 |
scroll-behavior: smooth;
|
|
|
|
| 45 |
}
|
| 46 |
body {
|
| 47 |
+
font-family: 'Lexend', sans-serif;
|
| 48 |
transition: background-color 0.3s ease, color 0.3s ease;
|
| 49 |
+
background-color: #f8fafc;
|
| 50 |
+
color: #1e293b;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
+
.dark body {
|
| 53 |
+
background-color: #020617; /* Fond plus sombre pour un meilleur contraste */
|
| 54 |
+
color: #e2e8f0;
|
| 55 |
}
|
| 56 |
+
/* Nouvelle structure de layout pour le chat */
|
| 57 |
+
.chat-container {
|
| 58 |
+
display: flex;
|
| 59 |
+
flex-direction: column;
|
| 60 |
+
height: 100vh;
|
| 61 |
+
width: 100%;
|
| 62 |
}
|
| 63 |
+
.chat-messages {
|
| 64 |
+
flex-grow: 1;
|
| 65 |
+
overflow-y: auto;
|
| 66 |
+
padding-bottom: 1rem; /* Espace pour ne pas être collé au composer */
|
| 67 |
+
}
|
| 68 |
+
::-webkit-scrollbar { width: 6px; height: 6px; }
|
| 69 |
+
::-webkit-scrollbar-track { background: transparent; }
|
| 70 |
+
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 6px; }
|
| 71 |
+
.dark ::-webkit-scrollbar-thumb { background: #475569; }
|
| 72 |
+
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
|
| 73 |
+
.dark ::-webkit-scrollbar-thumb:hover { background: #64748b; }
|
| 74 |
+
|
| 75 |
+
/* Bulles de message améliorées */
|
| 76 |
.message-bubble {
|
|
|
|
| 77 |
max-width: 85%;
|
| 78 |
+
border-radius: 1.25rem; /* Coins plus arrondis */
|
| 79 |
+
padding: 0.75rem 1.125rem;
|
| 80 |
+
line-height: 1.6;
|
| 81 |
animation: message-fade-in 0.3s ease-out;
|
| 82 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
|
| 83 |
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
| 84 |
}
|
| 85 |
+
.dark .message-bubble { box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15); }
|
| 86 |
+
.message-wrapper { display: flex; max-width: 100%; gap: 0.75rem; }
|
| 87 |
+
.user-message-wrapper { justify-content: flex-end; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
.user-message {
|
| 89 |
+
background-color: #0ea5e9; /* Couleur primaire solide */
|
|
|
|
|
|
|
| 90 |
color: white;
|
| 91 |
}
|
| 92 |
.assistant-message {
|
| 93 |
+
background-color: #e2e8f0;
|
| 94 |
+
color: #1e293b;
|
| 95 |
}
|
| 96 |
.dark .assistant-message {
|
| 97 |
background-color: #1e293b;
|
| 98 |
color: #e2e8f0;
|
|
|
|
| 99 |
}
|
| 100 |
+
/* Avatars pour les messages */
|
| 101 |
+
.avatar {
|
| 102 |
+
width: 2rem;
|
| 103 |
+
height: 2rem;
|
| 104 |
+
border-radius: 9999px;
|
| 105 |
+
display: flex;
|
| 106 |
+
align-items: center;
|
| 107 |
+
justify-content: center;
|
| 108 |
+
flex-shrink: 0;
|
| 109 |
+
font-size: 1.125rem;
|
| 110 |
+
}
|
| 111 |
+
.assistant-avatar { background-color: #e0f2fe; color: #0284c7; }
|
| 112 |
+
.dark .assistant-avatar { background-color: #0c4a6e; color: #7dd3fc; }
|
| 113 |
+
.user-avatar { background-color: #dbeafe; color: #1d4ed8; }
|
| 114 |
+
.dark .user-avatar { background-color: #1e3a8a; color: #93c5fd; }
|
| 115 |
+
|
| 116 |
@keyframes message-fade-in {
|
| 117 |
+
from { opacity: 0; transform: translateY(10px) scale(0.98); }
|
| 118 |
+
to { opacity: 1; transform: translateY(0) scale(1); }
|
| 119 |
}
|
| 120 |
@keyframes pulse-fade {
|
| 121 |
0%, 100% { opacity: 0.5; }
|
| 122 |
50% { opacity: 1; }
|
| 123 |
}
|
| 124 |
+
.typing-indicator { display: inline-flex; align-items: center; }
|
| 125 |
+
.typing-dot { width: 0.4rem; height: 0.4rem; border-radius: 50%; background-color: currentColor; opacity: 0.7; margin: 0 0.1rem; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
.typing-dot:nth-child(1) { animation: pulse-fade 1.2s 0s infinite; }
|
| 127 |
.typing-dot:nth-child(2) { animation: pulse-fade 1.2s 0.2s infinite; }
|
| 128 |
.typing-dot:nth-child(3) { animation: pulse-fade 1.2s 0.4s infinite; }
|
| 129 |
+
|
| 130 |
+
/* Tooltip amélioré */
|
| 131 |
+
.tooltip { position: relative; }
|
| 132 |
+
.tooltip .tooltip-text { visibility: hidden; width: max-content; background-color: #1e293b; color: #f8fafc; text-align: center; border-radius: 6px; padding: 0.375rem 0.625rem; position: absolute; z-index: 10; bottom: 125%; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity 0.3s, visibility 0.3s; font-size: 0.75rem; font-weight: 500; pointer-events: none; }
|
| 133 |
+
.dark .tooltip .tooltip-text { background-color: #e2e8f0; color: #1e293b; }
|
| 134 |
+
.tooltip:hover .tooltip-text { visibility: visible; opacity: 1; }
|
| 135 |
+
|
| 136 |
+
/* Bouton de copie amélioré */
|
| 137 |
+
.copy-btn { position: absolute; top: 0.5rem; right: 0.5rem; opacity: 0; transition: all 0.2s ease; z-index: 2; transform: scale(0.9); }
|
| 138 |
+
.message-bubble:hover .copy-btn { opacity: 1; transform: scale(1); }
|
| 139 |
+
|
| 140 |
+
/* Composer (zone de saisie) */
|
| 141 |
+
.chat-composer {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
background-color: white;
|
| 143 |
+
border-top: 1px solid #e2e8f0;
|
| 144 |
+
transition: background-color 0.3s ease, border-color 0.3s ease;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
}
|
| 146 |
+
.dark .chat-composer {
|
| 147 |
+
background-color: #0f172a;
|
| 148 |
+
border-top-color: #1e293b;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
|
|
|
| 150 |
.chat-textarea {
|
| 151 |
+
resize: none; min-height: 48px; max-height: 200px; line-height: 1.5;
|
| 152 |
+
background-color: transparent; border: none;
|
| 153 |
+
}
|
| 154 |
+
.chat-textarea:focus { box-shadow: none; ring: 0; }
|
| 155 |
+
|
| 156 |
+
/* Toggle Switch */
|
| 157 |
+
.toggle-switch { position: relative; display: inline-block; width: 2.5rem; height: 1.25rem; }
|
| 158 |
+
.toggle-switch input { opacity: 0; width: 0; height: 0; }
|
| 159 |
+
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .4s; border-radius: 1.25rem; }
|
| 160 |
+
.toggle-slider:before { position: absolute; content: ""; height: 0.875rem; width: 0.875rem; left: 0.25rem; bottom: 0.1875rem; background-color: white; transition: .4s; border-radius: 50%; }
|
| 161 |
+
input:checked + .toggle-slider { background-color: #0ea5e9; }
|
| 162 |
+
.dark .toggle-slider { background-color: #475569; }
|
| 163 |
+
.dark input:checked + .toggle-slider { background-color: #38bdf8; }
|
| 164 |
+
input:checked + .toggle-slider:before { transform: translateX(1.125rem); }
|
| 165 |
+
|
| 166 |
+
/* Styles pour le code et les tableaux */
|
| 167 |
+
pre { position: relative; background-color: #f1f5f9; border-radius: 0.5rem; margin: 1rem 0; padding: 1.25rem 1rem; overflow-x: auto; }
|
| 168 |
+
.dark pre { background-color: #0f172a; }
|
| 169 |
+
code { font-family: 'JetBrains Mono', monospace; font-size: 0.875rem; }
|
| 170 |
+
.code-copy-btn { position: absolute; top: 0.5rem; right: 0.5rem; opacity: 0; transition: opacity 0.2s ease; }
|
| 171 |
+
pre:hover .code-copy-btn { opacity: 0.7; }
|
| 172 |
+
.table-wrapper { width: 100%; overflow-x: auto; margin: 1rem 0; border: 1px solid #e2e8f0; border-radius: 0.5rem; }
|
| 173 |
+
.dark .table-wrapper { border-color: #334155; }
|
| 174 |
+
.prose table { width: 100%; min-width: 100%; border-collapse: collapse; margin: 0; }
|
| 175 |
+
.prose table th, .prose table td { border: 1px solid #e2e8f0; padding: 0.5rem 0.75rem; text-align: left; }
|
| 176 |
+
.prose table th { border-bottom-width: 2px; }
|
| 177 |
+
.dark .prose table th, .dark .prose table td { border-color: #334155; }
|
| 178 |
+
.prose table thead { background-color: #f8fafc; font-weight: 600; }
|
| 179 |
+
.dark .prose table thead { background-color: #1e293b; }
|
| 180 |
+
|
| 181 |
/* Ajustements responsive */
|
| 182 |
@media (max-width: 640px) {
|
| 183 |
+
.message-bubble { padding: 0.625rem 1rem; }
|
| 184 |
+
.chat-textarea { max-height: 120px; font-size: 1rem; min-height: 44px; }
|
| 185 |
+
.prose table { font-size: 0.85rem; }
|
| 186 |
+
.prose table th, .prose table td { padding: 0.375rem 0.5rem; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
}
|
| 188 |
</style>
|
| 189 |
</head>
|
| 190 |
+
<body class="antialiased">
|
| 191 |
+
|
| 192 |
+
<div class="chat-container max-w-4xl mx-auto">
|
| 193 |
+
<!-- Header amélioré -->
|
| 194 |
+
<header class="bg-white/80 dark:bg-secondary-900/80 backdrop-blur-sm py-3 px-4 border-b border-secondary-200 dark:border-secondary-800 sticky top-0 z-20">
|
| 195 |
+
<div class="flex justify-between items-center">
|
| 196 |
+
<!-- Logo & Titre -->
|
| 197 |
+
<div class="flex items-center space-x-3">
|
| 198 |
+
<img src="https://mariam-241.vercel.app/static/image/logoboma.png" alt="Logo Mariam AI" class="h-8 sm:h-9 object-contain">
|
| 199 |
+
<h1 class="text-xl font-bold text-secondary-800 dark:text-secondary-100">Mariam AI</h1>
|
| 200 |
+
</div>
|
| 201 |
+
<!-- Actions -->
|
| 202 |
+
<div class="flex items-center space-x-1 sm:space-x-2">
|
| 203 |
+
<button id="theme-toggle" class="p-2 w-10 h-10 rounded-full text-secondary-600 dark:text-secondary-300 hover:bg-secondary-100 dark:hover:bg-secondary-800 transition-colors duration-200 tooltip" aria-label="Changer de thème">
|
| 204 |
+
<i class="fa-solid fa-moon dark:hidden"></i>
|
| 205 |
+
<i class="fa-solid fa-sun hidden dark:inline"></i>
|
| 206 |
+
<span class="tooltip-text">Thème</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
</button>
|
| 208 |
+
<form action="/clear" method="POST" id="clear-form">
|
| 209 |
+
<button type="submit" class="p-2 w-10 h-10 rounded-full text-red-500 hover:bg-red-500/10 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-red-400 focus:ring-opacity-50 tooltip">
|
| 210 |
+
<i class="fa-solid fa-trash-can"></i>
|
| 211 |
+
<span class="tooltip-text">Effacer</span>
|
| 212 |
+
</button>
|
| 213 |
+
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
</div>
|
| 215 |
</div>
|
| 216 |
+
</header>
|
| 217 |
+
|
| 218 |
+
<!-- Main Content -->
|
| 219 |
+
<main class="flex-grow flex flex-col">
|
| 220 |
+
<!-- Conteneur des messages -->
|
| 221 |
+
<section id="chat-messages" class="chat-messages flex flex-col space-y-5 p-4">
|
| 222 |
+
<!-- Chargement de l'historique -->
|
| 223 |
+
<div id="history-loading" class="text-center py-10">
|
| 224 |
+
<div class="inline-flex items-center px-4 py-2 bg-primary-50 text-primary-700 rounded-lg dark:bg-primary-900/30 dark:text-primary-300">
|
| 225 |
+
<svg class="animate-spin h-5 w-5 mr-3" viewBox="0 0 24 24">
|
| 226 |
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
| 227 |
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
| 228 |
+
</svg>
|
| 229 |
+
<span>Chargement de la conversation...</span>
|
| 230 |
+
</div>
|
| 231 |
+
</div>
|
| 232 |
+
<!-- Indicateur de chargement pour les réponses -->
|
| 233 |
+
<div id="loading-indicator" class="message-wrapper hidden">
|
| 234 |
+
<div class="avatar assistant-avatar">✨</div>
|
| 235 |
+
<div class="message-bubble assistant-message flex items-center">
|
| 236 |
+
<div class="typing-indicator">
|
| 237 |
+
<span class="typing-dot"></span>
|
| 238 |
+
<span class="typing-dot"></span>
|
| 239 |
+
<span class="typing-dot"></span>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
</div>
|
| 243 |
+
</section>
|
| 244 |
+
</main>
|
| 245 |
+
|
| 246 |
+
<!-- Nouveau "Composer" unifié et sticky -->
|
| 247 |
+
<div class="chat-composer sticky bottom-0 z-10 w-full">
|
| 248 |
+
<div class="max-w-4xl mx-auto">
|
| 249 |
+
<!-- Zone d'erreur -->
|
| 250 |
+
<div id="error-message" class="bg-red-100 border-t-4 border-red-500 text-red-700 px-4 py-3 dark:bg-red-900/30 dark:text-red-300 dark:border-red-600 hidden" role="alert">
|
| 251 |
+
<div class="flex items-center">
|
| 252 |
+
<div class="flex-shrink-0"><i class="fa-solid fa-circle-exclamation mr-2"></i></div>
|
| 253 |
+
<p class="text-sm font-medium" id="error-text">Le message d'erreur détaillé ira ici.</p>
|
| 254 |
+
<button class="ml-auto -mr-1 p-1" id="dismiss-error"><i class="fa-solid fa-xmark"></i></button>
|
| 255 |
</div>
|
| 256 |
</div>
|
| 257 |
+
<!-- Zone de prévisualisation -->
|
| 258 |
+
<div id="preview-area" class="px-4 py-2 hidden">
|
| 259 |
+
<div id="file-preview" class="hidden"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
</div>
|
| 261 |
+
<!-- Barre d'options -->
|
| 262 |
+
<div class="flex items-center justify-between flex-wrap gap-y-2 px-4 py-2 text-sm text-gray-600 dark:text-gray-300">
|
| 263 |
+
<div class="flex items-center space-x-4 flex-wrap gap-y-2">
|
| 264 |
+
<label class="flex items-center cursor-pointer tooltip">
|
| 265 |
+
<span class="mr-2 text-xs sm:text-sm font-medium"><i class="fa-solid fa-globe mr-1.5 opacity-70"></i><span class="hidden sm:inline">Web</span></span>
|
| 266 |
+
<span class="toggle-switch"><input type="checkbox" id="web_search_toggle"><span class="toggle-slider"></span></span>
|
| 267 |
+
<span class="tooltip-text">Recherche Web</span>
|
| 268 |
+
</label>
|
| 269 |
+
<label class="flex items-center cursor-pointer tooltip">
|
| 270 |
+
<span class="mr-2 text-xs sm:text-sm font-medium text-accent-700 dark:text-accent-300">
|
| 271 |
+
<i class="fa-solid fa-brain mr-1.5"></i><span class="hidden sm:inline">Avancé</span><span id="advanced-cooldown-timer" class="text-xs ml-1 hidden"></span>
|
| 272 |
+
</span>
|
| 273 |
+
<span class="toggle-switch"><input type="checkbox" id="advanced_reasoning_toggle"><span class="toggle-slider"></span></span>
|
| 274 |
+
<span class="tooltip-text">Raisonnement Avancé (1 fois/min)</span>
|
| 275 |
+
</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
</div>
|
| 277 |
+
<div class="flex items-center space-x-2">
|
| 278 |
+
<label for="file_upload" class="cursor-pointer flex items-center text-primary-600 hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300 tooltip">
|
| 279 |
+
<i class="fa-solid fa-paperclip text-lg"></i>
|
| 280 |
+
<input type="file" id="file_upload" name="file" class="hidden" accept=".txt,.pdf,.png,.jpg,.jpeg">
|
| 281 |
+
<span class="tooltip-text">Joindre un fichier</span>
|
| 282 |
+
</label>
|
| 283 |
+
<div id="file-chip" class="chip hidden">
|
| 284 |
+
<i class="fa-solid fa-file chip-icon"></i><span id="file-name" class="truncate max-w-[100px] sm:max-w-[120px]"></span><i id="clear-file" class="fa-solid fa-xmark chip-close"></i>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
<!-- Formulaire de chat -->
|
| 289 |
+
<form id="chat-form" class="p-3 sm:p-4">
|
| 290 |
+
<div class="relative flex items-end bg-secondary-100 dark:bg-secondary-800 rounded-2xl">
|
| 291 |
+
<textarea
|
| 292 |
+
id="prompt"
|
| 293 |
+
name="prompt"
|
| 294 |
+
class="chat-textarea w-full pl-4 pr-12 focus:outline-none text-sm sm:text-base text-secondary-800 dark:text-secondary-100 placeholder-secondary-500 dark:placeholder-secondary-400"
|
| 295 |
+
placeholder="Posez votre question à Mariam..."
|
| 296 |
+
autocomplete="off"
|
| 297 |
+
rows="1"></textarea>
|
| 298 |
<button
|
| 299 |
type="submit"
|
| 300 |
id="send-button"
|
| 301 |
+
class="absolute right-2 bottom-2 bg-primary-500 hover:bg-primary-600 disabled:bg-primary-300 disabled:cursor-not-allowed text-white rounded-full w-9 h-9 flex items-center justify-center transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-primary-400"
|
| 302 |
+
title="Envoyer">
|
| 303 |
<i class="fa-solid fa-paper-plane text-sm"></i>
|
| 304 |
</button>
|
| 305 |
</div>
|
| 306 |
+
</form>
|
| 307 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
</div>
|
| 309 |
+
</div>
|
| 310 |
+
|
| 311 |
<!-- Scripts -->
|
| 312 |
<script>
|
| 313 |
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
| 349 |
}
|
| 350 |
}
|
| 351 |
function toggleTheme() {
|
| 352 |
+
document.documentElement.classList.toggle('dark');
|
| 353 |
+
localStorage.theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
}
|
| 355 |
themeToggleBtn.addEventListener('click', toggleTheme);
|
| 356 |
initializeTheme();
|
|
|
|
| 373 |
|
| 374 |
// Affichage de l'indicateur de chargement
|
| 375 |
function showLoading(show) {
|
| 376 |
+
loadingIndicator.classList.toggle('hidden', !show);
|
| 377 |
if (show) {
|
| 378 |
+
chatMessages.appendChild(loadingIndicator);
|
| 379 |
+
scrollToBottom();
|
|
|
|
|
|
|
|
|
|
| 380 |
}
|
| 381 |
sendButton.disabled = show;
|
| 382 |
promptInput.disabled = show;
|
| 383 |
fileUpload.disabled = show;
|
| 384 |
+
clearFileButton.style.pointerEvents = show ? 'none' : 'auto';
|
| 385 |
+
clearFileButton.style.opacity = show ? '0.5' : '0.7';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
}
|
| 387 |
|
| 388 |
// Affichage des erreurs
|
|
|
|
| 396 |
function addMessageToChat(role, content, isHtml = false) {
|
| 397 |
errorMessageDiv.classList.add('hidden');
|
| 398 |
const messageWrapper = document.createElement('div');
|
| 399 |
+
messageWrapper.className = `message-wrapper ${role === 'user' ? 'user-message-wrapper' : ''}`;
|
| 400 |
+
|
| 401 |
+
let messageContentHtml = isHtml ? content : `<p class="whitespace-pre-wrap">${escapeHtml(content)}</p>`;
|
| 402 |
|
| 403 |
+
const avatarClass = role === 'user' ? 'user-avatar' : 'assistant-avatar';
|
| 404 |
+
const avatarIcon = role === 'user' ? '<i class="fa-regular fa-user"></i>' : '✨';
|
| 405 |
+
const messageBubbleClass = role === 'user' ? 'user-message' : 'assistant-message';
|
|
|
|
|
|
|
|
|
|
| 406 |
|
| 407 |
+
const bubbleHtml = `
|
| 408 |
+
<div class="avatar ${avatarClass}">${avatarIcon}</div>
|
| 409 |
+
<div class="message-bubble ${messageBubbleClass} relative">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
<div class="prose prose-sm sm:prose-base max-w-none dark:prose-invert">
|
| 411 |
+
${messageContentHtml}
|
| 412 |
</div>
|
| 413 |
+
${role === 'assistant' ? `
|
| 414 |
+
<button class="copy-btn text-xs bg-white/70 dark:bg-gray-800/70 backdrop-blur-sm hover:bg-gray-200/70 dark:hover:bg-gray-700/70 py-1 px-2 rounded-full text-gray-600 dark:text-gray-300 flex items-center shadow">
|
| 415 |
+
<i class="fa-regular fa-copy mr-1.5"></i> Copier
|
| 416 |
+
</button>` : ''}
|
| 417 |
</div>
|
| 418 |
+
`;
|
| 419 |
+
|
| 420 |
messageWrapper.innerHTML = bubbleHtml;
|
| 421 |
|
| 422 |
+
// Activation du bouton de copie (si assistant)
|
| 423 |
+
const copyBtn = messageWrapper.querySelector('.copy-btn');
|
| 424 |
+
if (copyBtn) {
|
| 425 |
+
copyBtn.addEventListener('click', function() {
|
| 426 |
+
const textToCopy = this.closest('.message-bubble').querySelector('.prose').innerText;
|
| 427 |
navigator.clipboard.writeText(textToCopy).then(() => {
|
| 428 |
const originalText = this.innerHTML;
|
| 429 |
+
this.innerHTML = '<i class="fa-solid fa-check mr-1.5"></i> Copié';
|
| 430 |
setTimeout(() => { this.innerHTML = originalText; }, 2000);
|
| 431 |
}).catch(err => console.error('Copy failed:', err));
|
| 432 |
});
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
// Activation de la copie pour les blocs de code
|
| 436 |
const codeBlocks = messageWrapper.querySelectorAll('pre');
|
| 437 |
codeBlocks.forEach(pre => {
|
| 438 |
const code = pre.querySelector('code');
|
| 439 |
+
if (!code || pre.querySelector('.code-copy-btn')) return;
|
|
|
|
| 440 |
const copyButton = document.createElement('button');
|
| 441 |
copyButton.innerHTML = '<i class="fa-regular fa-copy"></i>';
|
| 442 |
+
copyButton.className = 'code-copy-btn p-1.5 bg-gray-200/50 dark:bg-gray-700/50 rounded-lg text-gray-600 dark:text-gray-300 hover:bg-gray-300/70 dark:hover:bg-gray-600/70 tooltip';
|
| 443 |
copyButton.setAttribute('aria-label', 'Copier le code');
|
| 444 |
const tooltipText = document.createElement('span');
|
| 445 |
tooltipText.className = 'tooltip-text !text-xs';
|
| 446 |
+
tooltipText.textContent = 'Copier';
|
| 447 |
copyButton.appendChild(tooltipText);
|
| 448 |
copyButton.addEventListener('click', () => {
|
| 449 |
navigator.clipboard.writeText(code.innerText).then(() => {
|
|
|
|
| 452 |
setTimeout(() => {
|
| 453 |
copyButton.innerHTML = '<i class="fa-regular fa-copy"></i>';
|
| 454 |
copyButton.appendChild(tooltipText);
|
| 455 |
+
tooltipText.textContent = 'Copier';
|
| 456 |
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
});
|
| 458 |
});
|
| 459 |
pre.appendChild(copyButton);
|
|
|
|
| 463 |
scrollToBottom();
|
| 464 |
}
|
| 465 |
function escapeHtml(unsafe) {
|
| 466 |
+
return unsafe.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
}
|
| 468 |
|
| 469 |
// Gestion du cooldown pour le raisonnement avancé
|
|
|
|
| 483 |
advancedCooldownTimerSpan.classList.remove('hidden');
|
| 484 |
}
|
| 485 |
}, 1000);
|
|
|
|
|
|
|
|
|
|
| 486 |
}
|
| 487 |
+
|
| 488 |
// Chargement de l'historique du chat
|
| 489 |
async function loadChatHistory() {
|
| 490 |
historyLoadingIndicator.style.display = 'flex';
|
| 491 |
try {
|
| 492 |
const response = await fetch(API_HISTORY_ENDPOINT);
|
| 493 |
+
if (!response.ok) throw new Error(`Erreur serveur (${response.status})`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
const data = await response.json();
|
| 495 |
+
chatMessages.innerHTML = ''; // Clear everything including loading indicator template
|
| 496 |
+
chatMessages.appendChild(loadingIndicator);
|
|
|
|
| 497 |
if (data.success && Array.isArray(data.history)) {
|
| 498 |
if (data.history.length === 0) {
|
| 499 |
addMessageToChat('assistant', "Bonjour ! Je suis Mariam, votre assistant IA. Comment puis-je vous aider aujourd'hui ?", true);
|
| 500 |
} else {
|
| 501 |
+
data.history.forEach(message => addMessageToChat(message.role, message.text, message.role === 'assistant'));
|
|
|
|
|
|
|
|
|
|
| 502 |
}
|
| 503 |
scrollToBottom(false);
|
| 504 |
} else {
|
|
|
|
| 506 |
}
|
| 507 |
} catch (error) {
|
| 508 |
displayError(`Impossible de charger l'historique: ${error.message}`);
|
| 509 |
+
if (chatMessages.querySelectorAll('.message-wrapper').length === 0) {
|
| 510 |
+
addMessageToChat('assistant', "Bonjour ! Je suis Mariam. Je n'ai pas pu charger notre conversation précédente.", true);
|
| 511 |
}
|
| 512 |
} finally {
|
| 513 |
historyLoadingIndicator.remove();
|
|
|
|
| 516 |
}
|
| 517 |
}
|
| 518 |
|
| 519 |
+
// ... le reste du JS pour la gestion des fichiers, la soumission du formulaire, etc. reste très similaire
|
| 520 |
+
// et fonctionnera avec la nouvelle structure. Je vais juste recopier la partie pertinente du script original
|
| 521 |
+
// en m'assurant que les sélecteurs sont toujours corrects.
|
| 522 |
+
|
| 523 |
// Gestion des fichiers
|
| 524 |
function clearFileInput() {
|
| 525 |
+
fileUpload.value = ''; fileChip.classList.add('hidden'); fileNameSpan.textContent = ''; fileNameSpan.title = ''; filePreview.innerHTML = ''; filePreview.classList.add('hidden'); previewArea.classList.add('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
}
|
| 527 |
fileUpload.addEventListener('change', () => {
|
| 528 |
if (fileUpload.files.length > 0) {
|
| 529 |
+
const file = fileUpload.files[0]; const name = file.name; fileNameSpan.textContent = name; fileNameSpan.title = name; fileChip.classList.remove('hidden'); filePreview.innerHTML = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
if (file.type.startsWith('image/')) {
|
| 531 |
const reader = new FileReader();
|
| 532 |
+
reader.onload = (e) => { filePreview.innerHTML = `<div class="file-preview"><img src="${e.target.result}" alt="Prévisualisation: ${escapeHtml(name)}"></div>`; filePreview.classList.remove('hidden'); previewArea.classList.remove('hidden'); };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
reader.readAsDataURL(file);
|
| 534 |
} else {
|
| 535 |
+
filePreview.innerHTML = `<div class="flex items-center justify-center p-3"><div class="bg-gray-100 dark:bg-gray-800 p-3 rounded-lg text-center"><i class="fa-solid fa-file text-3xl text-gray-500 dark:text-gray-400 mb-2"></i><p class="text-xs text-gray-500 dark:text-gray-400">${name}</p></div></div>`;
|
| 536 |
+
filePreview.classList.remove('hidden'); previewArea.classList.remove('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
}
|
| 538 |
+
} else { clearFileInput(); }
|
|
|
|
|
|
|
| 539 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
clearFileButton.addEventListener('click', clearFileInput);
|
| 541 |
+
|
| 542 |
// Événements pour le textarea
|
| 543 |
+
promptInput.addEventListener('input', () => adjustTextareaHeight(promptInput));
|
|
|
|
|
|
|
| 544 |
promptInput.addEventListener('keydown', (e) => {
|
| 545 |
if (isComposing) return;
|
| 546 |
const isMobile = window.innerWidth < MOBILE_BREAKPOINT;
|
| 547 |
+
if (e.key === 'Enter' && !e.shiftKey && !isMobile) {
|
|
|
|
|
|
|
|
|
|
| 548 |
e.preventDefault();
|
| 549 |
+
chatForm.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
}
|
| 551 |
});
|
| 552 |
promptInput.addEventListener('compositionstart', () => { isComposing = true; });
|
| 553 |
+
promptInput.addEventListener('compositionend', () => { isComposing = false; setTimeout(() => adjustTextareaHeight(promptInput), 0); });
|
|
|
|
|
|
|
|
|
|
| 554 |
adjustTextareaHeight(promptInput);
|
| 555 |
|
| 556 |
// Soumission du formulaire
|
| 557 |
chatForm.addEventListener('submit', async (e) => {
|
| 558 |
e.preventDefault();
|
| 559 |
+
const prompt = promptInput.value.trim(); const file = fileUpload.files[0];
|
| 560 |
+
if (sendButton.disabled || (!prompt && !file)) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
errorMessageDiv.classList.add('hidden');
|
| 562 |
+
if (advancedToggle.checked && advancedToggleCooldownEndTime > 0 && Date.now() < advancedToggleCooldownEndTime) {
|
| 563 |
+
const remaining = Math.ceil((advancedToggleCooldownEndTime - Date.now()) / 1000);
|
| 564 |
+
displayError(`Le raisonnement avancé est disponible dans ${remaining}s.`); return;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
}
|
| 566 |
let userMessageText = prompt;
|
| 567 |
+
if (file && file.name) { userMessageText = prompt ? `${prompt}\n[Fichier: ${file.name}]` : `[Fichier joint: ${file.name}]`; }
|
|
|
|
|
|
|
| 568 |
addMessageToChat('user', userMessageText);
|
| 569 |
const formData = new FormData();
|
| 570 |
+
formData.append('prompt', prompt); formData.append('web_search', webSearchToggle.checked); formData.append('advanced_reasoning', advancedToggle.checked);
|
| 571 |
+
if (file) formData.append('file', file);
|
| 572 |
+
promptInput.value = ''; adjustTextareaHeight(promptInput); clearFileInput();
|
| 573 |
+
if (advancedToggle.checked) { startAdvancedCooldownTimer(); advancedToggle.checked = false; }
|
| 574 |
+
webSearchToggle.checked = false; showLoading(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
try {
|
| 576 |
const response = await fetch(API_CHAT_ENDPOINT, { method: 'POST', body: formData });
|
| 577 |
const data = await response.json();
|
| 578 |
+
if (!response.ok) throw new Error(data.error || `Erreur serveur: ${response.status}`);
|
| 579 |
+
if (data.success && data.message) addMessageToChat('assistant', data.message, true);
|
| 580 |
+
else throw new Error(data.error || "Réponse invalide du serveur.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
} catch (error) {
|
| 582 |
console.error("Chat Error:", error);
|
| 583 |
addMessageToChat('assistant', `<p class="text-red-600 dark:text-red-400">Désolé, une erreur est survenue :<br>${escapeHtml(error.message)}</p>`, true);
|
| 584 |
} finally {
|
| 585 |
+
showLoading(false); promptInput.focus();
|
|
|
|
| 586 |
}
|
| 587 |
});
|
| 588 |
|
| 589 |
// Effacement de la conversation
|
| 590 |
+
clearForm.addEventListener('submit', (e) => {
|
| 591 |
e.preventDefault();
|
| 592 |
const confirmDialog = document.createElement('div');
|
| 593 |
confirmDialog.className = 'fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4';
|
| 594 |
+
confirmDialog.innerHTML = `<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-xl max-w-sm w-full animate-dialog-show"><h3 class="text-lg font-semibold mb-3">Confirmer l'effacement</h3><p class="text-sm text-gray-600 dark:text-gray-300 mb-5">Voulez-vous vraiment effacer toute la conversation ?</p><div class="flex justify-end space-x-3"><button id="cancel-clear" class="px-4 py-2 text-sm font-medium bg-gray-100 dark:bg-gray-700 rounded hover:bg-gray-200 dark:hover:bg-gray-600">Annuler</button><button id="confirm-clear" class="px-4 py-2 text-sm font-medium text-white bg-red-600 rounded hover:bg-red-700">Effacer</button></div></div>`;
|
| 595 |
+
const closeModal = () => document.body.contains(confirmDialog) && document.body.removeChild(confirmDialog);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 596 |
confirmDialog.querySelector('#cancel-clear').addEventListener('click', closeModal);
|
| 597 |
confirmDialog.querySelector('#confirm-clear').addEventListener('click', async () => {
|
| 598 |
closeModal();
|
| 599 |
const clearButton = e.target.querySelector('button[type="submit"]');
|
|
|
|
| 600 |
clearButton.disabled = true;
|
|
|
|
| 601 |
try {
|
| 602 |
+
const response = await fetch(CLEAR_ENDPOINT, { method: 'POST', headers: { 'X-Requested-With': 'XMLHttpRequest' } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
const data = await response.json();
|
| 604 |
if (response.ok && data.success) {
|
| 605 |
+
chatMessages.innerHTML = ''; chatMessages.appendChild(loadingIndicator);
|
| 606 |
+
addMessageToChat('assistant', "Conversation effacée. Comment puis-je vous aider ?", true);
|
|
|
|
|
|
|
| 607 |
} else {
|
| 608 |
+
throw new Error(data.error || "Impossible d'effacer.");
|
| 609 |
}
|
| 610 |
+
} catch (error) { displayError(`Erreur: ${error.message}`);
|
| 611 |
+
} finally { clearButton.disabled = false; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 612 |
});
|
| 613 |
document.body.appendChild(confirmDialog);
|
|
|
|
|
|
|
| 614 |
});
|
| 615 |
+
|
| 616 |
// Initialisation
|
| 617 |
loadChatHistory();
|
| 618 |
|
| 619 |
// Observer pour les tableaux Markdown
|
| 620 |
+
new MutationObserver(mutations => {
|
| 621 |
+
mutations.forEach(mutation => {
|
| 622 |
+
if (mutation.addedNodes.length) {
|
| 623 |
+
mutation.addedNodes.forEach(node => {
|
| 624 |
+
if (node.nodeType === 1) {
|
| 625 |
+
const tables = node.matches('.prose table') ? [node] : node.querySelectorAll('.prose table');
|
| 626 |
+
tables.forEach(table => {
|
| 627 |
+
if (!table.closest('.table-wrapper')) {
|
| 628 |
+
const wrapper = document.createElement('div');
|
| 629 |
+
wrapper.className = 'table-wrapper';
|
| 630 |
+
table.parentNode.insertBefore(wrapper, table);
|
| 631 |
+
wrapper.appendChild(table);
|
| 632 |
+
}
|
| 633 |
+
});
|
| 634 |
+
}
|
| 635 |
+
});
|
| 636 |
+
}
|
|
|
|
|
|
|
| 637 |
});
|
| 638 |
+
}).observe(chatMessages, { childList: true, subtree: true });
|
|
|
|
|
|
|
| 639 |
|
| 640 |
+
// Gestion du thème système
|
| 641 |
+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
|
|
|
|
| 642 |
if (!localStorage.getItem('theme')) {
|
| 643 |
+
document.documentElement.classList.toggle('dark', e.matches);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
}
|
| 645 |
+
});
|
|
|
|
| 646 |
});
|
| 647 |
</script>
|
| 648 |
</body>
|
| 649 |
+
</html>
|