Update templates/index.html
Browse files- templates/index.html +480 -973
templates/index.html
CHANGED
@@ -1,18 +1,18 @@
|
|
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">
|
6 |
-
<title>Mariam AI</title>
|
7 |
<!-- Tailwind CSS via CDN -->
|
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.
|
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=Inter:wght@
|
15 |
-
<!-- Favicon
|
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>
|
18 |
tailwind.config = {
|
@@ -24,1069 +24,576 @@
|
|
24 |
mono: ['"JetBrains Mono"', 'monospace']
|
25 |
},
|
26 |
colors: {
|
27 |
-
primary: { 50: '#
|
28 |
-
|
29 |
-
accent: { 50: '#fdf4ff', 100: '#fae8ff', 200: '#f5d0fe', 300: '#f0abfc', 400: '#e879f9', 500: '#d946ef', 600: '#c026d3', 700: '#a21caf', 800: '#86198f', 900: '#701a75' }
|
30 |
},
|
31 |
-
animation: {
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
}
|
34 |
}
|
35 |
}
|
36 |
</script>
|
37 |
<style>
|
38 |
-
|
39 |
-
|
40 |
-
overflow-x: hidden; /* Empêche le scroll horizontal global */
|
41 |
-
}
|
42 |
-
body {
|
43 |
-
font-family: 'Inter', sans-serif;
|
44 |
-
transition: background-color 0.3s ease, color 0.3s ease;
|
45 |
-
overflow-x: hidden; /* Empêche le scroll horizontal du body */
|
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 |
-
::-webkit-scrollbar-thumb:hover {
|
67 |
-
background: #94a3b8;
|
68 |
-
}
|
69 |
-
.dark ::-webkit-scrollbar-thumb:hover {
|
70 |
-
background: #64748b;
|
71 |
-
}
|
72 |
-
.message-bubble {
|
73 |
-
position: relative;
|
74 |
-
max-width: 85%;
|
75 |
-
border-radius: 1rem;
|
76 |
-
padding: 0.875rem 1rem;
|
77 |
-
line-height: 1.5;
|
78 |
-
animation: message-fade-in 0.3s ease-out;
|
79 |
-
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
80 |
-
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
81 |
-
}
|
82 |
-
.message-bubble:hover {
|
83 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.1);
|
84 |
}
|
85 |
-
.dark
|
86 |
-
|
87 |
}
|
88 |
-
|
89 |
-
|
|
|
90 |
}
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
color: white;
|
96 |
-
}
|
97 |
-
.assistant-message {
|
98 |
-
border-bottom-left-radius: 0.125rem;
|
99 |
-
align-self: flex-start;
|
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 |
-
display: inline-flex;
|
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 |
.dark body {
|
131 |
-
background
|
132 |
-
color: #
|
133 |
-
}
|
134 |
-
|
135 |
-
|
136 |
-
}
|
137 |
-
.
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
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 |
-
.
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
}
|
235 |
-
.
|
236 |
-
|
237 |
-
|
238 |
-
height: 0;
|
239 |
}
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
right: 0;
|
246 |
-
bottom: 0;
|
247 |
-
background-color: #cbd5e1;
|
248 |
-
transition: .4s;
|
249 |
border-radius: 1.25rem;
|
|
|
250 |
}
|
251 |
-
.
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
width: 0.875rem;
|
256 |
-
left: 0.25rem;
|
257 |
-
bottom: 0.1875rem;
|
258 |
-
background-color: white;
|
259 |
-
transition: .4s;
|
260 |
-
border-radius: 50%;
|
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 |
-
.prose table {
|
332 |
-
width: 100%;
|
333 |
-
min-width: 100%;
|
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 |
-
.
|
358 |
-
background-color: #
|
|
|
|
|
|
|
359 |
}
|
360 |
-
.
|
361 |
-
background-color: #
|
|
|
|
|
362 |
}
|
363 |
-
.
|
364 |
-
background
|
365 |
}
|
366 |
-
|
367 |
-
|
|
|
368 |
resize: none;
|
369 |
-
min-height:
|
370 |
-
max-height: 200px;
|
371 |
-
overflow-y: auto;
|
372 |
-
line-height: 1.5;
|
373 |
-
width: 100%;
|
374 |
-
border-radius: 9999px;
|
375 |
-
padding-top: 0.625rem;
|
376 |
-
padding-bottom: 0.625rem;
|
377 |
-
padding-left: 1rem;
|
378 |
-
padding-right: 3rem;
|
379 |
-
box-sizing: border-box;
|
380 |
-
}
|
381 |
-
/* Ajustements responsive */
|
382 |
-
@media (max-width: 640px) {
|
383 |
-
.message-bubble {
|
384 |
-
max-width: 90%;
|
385 |
-
padding: 0.75rem 0.875rem;
|
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 |
-
|
421 |
-
|
422 |
-
position: relative;
|
423 |
-
display: flex;
|
424 |
-
align-items: flex-end;
|
425 |
}
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
bottom: 0.5rem;
|
430 |
}
|
|
|
|
|
431 |
</style>
|
432 |
</head>
|
433 |
-
<body class="
|
434 |
-
|
435 |
-
<
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
|
|
|
|
|
|
448 |
</button>
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
<span class="hidden sm:inline">Effacer</span>
|
453 |
-
<span class="tooltip-text">Effacer la conversation</span>
|
454 |
-
</button>
|
455 |
-
</form>
|
456 |
-
</div>
|
457 |
-
</div>
|
458 |
-
</header>
|
459 |
-
<!-- Main Container -->
|
460 |
-
<main class="max-w-4xl mx-auto chat-layout">
|
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 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
|
|
|
|
477 |
</div>
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
</div>
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
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 |
-
<label class="flex items-center cursor-pointer tooltip">
|
506 |
-
<span class="mr-2 text-xs sm:text-sm font-medium"><i class="fa-solid fa-globe mr-1.5"></i><span class="hidden sm:inline">Recherche Web</span></span>
|
507 |
-
<span class="toggle-switch">
|
508 |
-
<input type="checkbox" id="web_search_toggle" name="web_search" value="true">
|
509 |
-
<span class="toggle-slider"></span>
|
510 |
-
</span>
|
511 |
-
<span class="tooltip-text">Activer la recherche web</span>
|
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 |
-
</div>
|
539 |
-
</div>
|
540 |
-
<!-- Formulaire de chat -->
|
541 |
-
<form id="chat-form" class="p-3 sm:p-4 bg-white dark:bg-gray-900">
|
542 |
-
<div class="input-wrapper">
|
543 |
-
<textarea
|
544 |
-
id="prompt"
|
545 |
-
name="prompt"
|
546 |
-
class="chat-input chat-textarea w-full border focus:outline-none text-sm sm:text-base"
|
547 |
-
placeholder="Posez votre question à Mariam..."
|
548 |
-
autocomplete="off"
|
549 |
-
rows="1"></textarea>
|
550 |
-
<div class="send-button-wrapper">
|
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 p-2 transition focus:outline-none focus:ring-2 focus:ring-primary-400 flex items-center justify-center"
|
555 |
-
title="Envoyer le message">
|
556 |
-
<i class="fa-solid fa-paper-plane text-sm"></i>
|
557 |
-
</button>
|
558 |
-
</div>
|
559 |
</div>
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
<
|
566 |
-
<
|
567 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
568 |
</div>
|
569 |
-
</
|
570 |
-
</
|
571 |
-
</
|
572 |
-
|
|
|
|
|
|
|
|
|
573 |
<script>
|
574 |
document.addEventListener('DOMContentLoaded', () => {
|
575 |
-
//
|
576 |
-
const
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
const API_CHAT_ENDPOINT = '/api/chat';
|
597 |
const API_HISTORY_ENDPOINT = '/api/history';
|
598 |
const CLEAR_ENDPOINT = '/clear';
|
599 |
-
const COOLDOWN_DURATION = 60 * 1000;
|
600 |
-
const MOBILE_BREAKPOINT = 640;
|
601 |
-
let advancedToggleCooldownEndTime = 0;
|
602 |
-
let isComposing = false;
|
603 |
|
604 |
-
//
|
605 |
-
|
606 |
-
|
607 |
-
|
|
|
|
|
|
|
|
|
608 |
} else {
|
609 |
-
|
610 |
}
|
611 |
-
}
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
|
|
|
|
|
|
|
|
616 |
} else {
|
617 |
-
|
618 |
-
localStorage.theme = 'dark';
|
619 |
}
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
const newHeight = Math.min(maxHeight || 200, textarea.scrollHeight);
|
630 |
-
textarea.style.height = newHeight + 'px';
|
631 |
-
}
|
632 |
|
633 |
-
|
634 |
-
function scrollToBottom(smooth = true) {
|
635 |
setTimeout(() => {
|
636 |
-
chatMessages.scrollTo({ top: chatMessages.scrollHeight, behavior
|
637 |
}, 50);
|
638 |
-
}
|
639 |
|
640 |
-
|
641 |
-
|
642 |
-
|
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 |
-
if (show) {
|
653 |
-
clearFileButton.style.pointerEvents = 'none';
|
654 |
-
clearFileButton.style.opacity = '0.5';
|
655 |
-
} else {
|
656 |
-
clearFileButton.style.pointerEvents = 'auto';
|
657 |
-
clearFileButton.style.opacity = '0.7';
|
658 |
-
}
|
659 |
-
}
|
660 |
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
}
|
666 |
-
dismissErrorBtn.addEventListener('click', () => { errorMessageDiv.classList.add('hidden'); });
|
667 |
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
messageWrapper.classList.add('flex', 'w-full', role === 'user' ? 'justify-end' : 'justify-start');
|
673 |
|
674 |
-
|
675 |
-
if (
|
676 |
-
|
677 |
} else {
|
678 |
-
|
679 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
680 |
|
681 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
682 |
if (role === 'user') {
|
683 |
-
|
684 |
-
|
685 |
-
${messageContentHtml}
|
686 |
-
</div>
|
687 |
-
`;
|
688 |
} else {
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
${messageContentHtml}
|
697 |
</div>
|
698 |
-
|
699 |
-
<i class="fa-regular fa-copy mr-1"></i> Copier
|
700 |
-
</button>
|
701 |
-
</div>
|
702 |
-
</div>
|
703 |
-
`;
|
704 |
}
|
705 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
706 |
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
setTimeout(() => { this.innerHTML = originalText; }, 2000);
|
716 |
-
}).catch(err => console.error('Copy failed:', err));
|
717 |
});
|
718 |
-
|
|
|
|
|
|
|
|
|
719 |
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
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 le code';
|
733 |
-
copyButton.appendChild(tooltipText);
|
734 |
-
copyButton.addEventListener('click', () => {
|
735 |
-
navigator.clipboard.writeText(code.innerText).then(() => {
|
736 |
-
tooltipText.textContent = 'Copié!';
|
737 |
-
copyButton.innerHTML = '<i class="fa-solid fa-check"></i>';
|
738 |
-
setTimeout(() => {
|
739 |
-
copyButton.innerHTML = '<i class="fa-regular fa-copy"></i>';
|
740 |
-
copyButton.appendChild(tooltipText);
|
741 |
-
tooltipText.textContent = 'Copier le code';
|
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);
|
750 |
-
});
|
751 |
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
|
|
779 |
}
|
780 |
-
|
781 |
-
const remainingSeconds = Math.ceil((advancedToggleCooldownEndTime - Date.now()) / 1000);
|
782 |
-
advancedCooldownTimerSpan.textContent = `(${remainingSeconds}s)`;
|
783 |
-
advancedCooldownTimerSpan.classList.remove('hidden');
|
784 |
-
}
|
785 |
|
786 |
-
//
|
787 |
-
async
|
788 |
-
|
|
|
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 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
});
|
811 |
-
}
|
812 |
-
scrollToBottom(false);
|
813 |
} else {
|
814 |
-
|
815 |
}
|
816 |
} catch (error) {
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
}
|
821 |
} finally {
|
822 |
-
|
823 |
-
promptInput.focus();
|
824 |
-
adjustTextareaHeight(promptInput);
|
825 |
}
|
826 |
-
}
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
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 |
-
<div class="flex items-center justify-center p-3">
|
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 |
-
}
|
874 |
-
|
|
|
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 |
-
//
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
897 |
if (isComposing) return;
|
898 |
-
|
899 |
-
|
900 |
-
if (
|
901 |
-
|
902 |
-
} else if (!isMobile && !e.shiftKey) {
|
903 |
-
e.preventDefault();
|
904 |
-
if (!sendButton.disabled && (promptInput.value.trim() || fileUpload.files.length > 0)) {
|
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 |
-
|
921 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
922 |
});
|
923 |
-
adjustTextareaHeight(promptInput);
|
924 |
|
925 |
-
|
926 |
-
chatForm.addEventListener('submit', async (e) => {
|
927 |
e.preventDefault();
|
928 |
-
const prompt = promptInput.value.trim();
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
if
|
933 |
-
if (
|
934 |
-
|
935 |
-
return;
|
936 |
-
}
|
937 |
-
errorMessageDiv.classList.add('hidden');
|
938 |
-
if (useAdvanced) {
|
939 |
-
const now = Date.now();
|
940 |
-
if (advancedToggleCooldownEndTime > 0 && now < advancedToggleCooldownEndTime) {
|
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',
|
|
|
951 |
const formData = new FormData();
|
952 |
-
formData.append('prompt', prompt);
|
953 |
-
formData.append('web_search',
|
954 |
-
|
955 |
-
|
956 |
-
formData.append('file', file);
|
957 |
-
}
|
958 |
-
promptInput.value = '';
|
959 |
-
adjustTextareaHeight(promptInput);
|
960 |
-
clearFileInput();
|
961 |
-
if (useAdvanced) {
|
962 |
-
startAdvancedCooldownTimer();
|
963 |
-
advancedToggle.checked = false;
|
964 |
}
|
965 |
-
|
966 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
|
|
|
|
977 |
}
|
|
|
|
|
978 |
} catch (error) {
|
979 |
-
console.error("
|
980 |
-
|
|
|
981 |
} finally {
|
982 |
-
|
983 |
-
promptInput.focus();
|
984 |
}
|
985 |
});
|
986 |
-
|
987 |
-
//
|
988 |
-
|
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 |
-
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-xl max-w-sm w-full animate-[message-fade-in_0.2s_ease-out]">
|
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 |
-
const messagesToRemove = chatMessages.querySelectorAll(':scope > *:not(#loading-indicator)');
|
1029 |
-
messagesToRemove.forEach(el => el.remove());
|
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 la conversation.");
|
1034 |
-
}
|
1035 |
-
} catch (error) {
|
1036 |
-
console.error("Clear Error:", error);
|
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 |
-
//
|
1053 |
-
const observeMarkdownTables = () => {
|
1054 |
-
const observer = new MutationObserver(mutations => {
|
1055 |
-
mutations.forEach(mutation => {
|
1056 |
-
if (mutation.addedNodes.length) {
|
1057 |
-
mutation.addedNodes.forEach(node => {
|
1058 |
-
if (node.nodeType === 1) {
|
1059 |
-
const tables = node.matches('.prose table') ? [node] : node.querySelectorAll('.prose table');
|
1060 |
-
tables.forEach(table => {
|
1061 |
-
if (!table.closest('.table-wrapper')) {
|
1062 |
-
const wrapper = document.createElement('div');
|
1063 |
-
wrapper.className = 'table-wrapper';
|
1064 |
-
table.parentNode.insertBefore(wrapper, table);
|
1065 |
-
wrapper.appendChild(table);
|
1066 |
-
}
|
1067 |
-
});
|
1068 |
-
}
|
1069 |
-
});
|
1070 |
-
}
|
1071 |
-
});
|
1072 |
-
});
|
1073 |
-
observer.observe(chatMessages, { childList: true, subtree: true });
|
1074 |
-
};
|
1075 |
-
observeMarkdownTables();
|
1076 |
-
|
1077 |
-
// Gestion du changement de thème selon le système
|
1078 |
-
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
|
1079 |
-
const handleSchemeChange = (e) => {
|
1080 |
-
if (!localStorage.getItem('theme')) {
|
1081 |
-
if (e.matches) {
|
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">
|
6 |
+
<title>Mariam AI - Assistant Personnel</title>
|
7 |
<!-- Tailwind CSS via CDN -->
|
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.5.1/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=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
15 |
+
<!-- Favicon -->
|
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>
|
18 |
tailwind.config = {
|
|
|
24 |
mono: ['"JetBrains Mono"', 'monospace']
|
25 |
},
|
26 |
colors: {
|
27 |
+
primary: { 50: '#eff6ff', 100: '#dbeafe', 200: '#bfdbfe', 300: '#93c5fd', 400: '#60a5fa', 500: '#3b82f6', 600: '#2563eb', 700: '#1d4ed8', 800: '#1e40af', 900: '#1e3a8a' },
|
28 |
+
slate: { 50: '#f8fafc', 100: '#f1f5f9', 200: '#e2e8f0', 300: '#cbd5e1', 400: '#94a3b8', 500: '#64748b', 600: '#475569', 700: '#334155', 800: '#1e293b', 900: '#0f172a', 950: '#020617' }
|
|
|
29 |
},
|
30 |
+
animation: {
|
31 |
+
'fade-in': 'fadeIn 0.5s ease-out forwards',
|
32 |
+
'fade-in-up': 'fadeInUp 0.5s ease-out forwards',
|
33 |
+
'pulse-subtle': 'pulse 2.5s cubic-bezier(0.4, 0, 0.6, 1) infinite',
|
34 |
+
},
|
35 |
+
keyframes: {
|
36 |
+
fadeIn: { '0%': { opacity: 0 }, '100%': { opacity: 1 } },
|
37 |
+
fadeInUp: { '0%': { opacity: 0, transform: 'translateY(10px)' }, '100%': { opacity: 1, transform: 'translateY(0)' } },
|
38 |
+
}
|
39 |
}
|
40 |
}
|
41 |
}
|
42 |
</script>
|
43 |
<style>
|
44 |
+
:root {
|
45 |
+
color-scheme: light;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
}
|
47 |
+
:root.dark {
|
48 |
+
color-scheme: dark;
|
49 |
}
|
50 |
+
html, body {
|
51 |
+
height: 100%;
|
52 |
+
overflow: hidden; /* Prevent scrollbars on body due to fixed elements */
|
53 |
}
|
54 |
+
body {
|
55 |
+
font-family: 'Inter', sans-serif;
|
56 |
+
background: #f8fafc; /* light mode body bg */
|
57 |
+
color: #0f172a; /* light mode text */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
}
|
|
|
|
|
|
|
59 |
.dark body {
|
60 |
+
background: #0f172a; /* dark mode body bg */
|
61 |
+
color: #f1f5f9; /* dark mode text */
|
62 |
+
}
|
63 |
+
::-webkit-scrollbar { width: 6px; height: 6px; }
|
64 |
+
::-webkit-scrollbar-track { background: transparent; }
|
65 |
+
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 6px; }
|
66 |
+
.dark ::-webkit-scrollbar-thumb { background: #475569; }
|
67 |
+
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
|
68 |
+
.dark ::-webkit-scrollbar-thumb:hover { background: #64748b; }
|
69 |
+
|
70 |
+
/* Layout */
|
71 |
+
.main-layout { display: flex; height: 100vh; }
|
72 |
+
/* sidebar width for mobile is w-64, for desktop min-w-[260px] */
|
73 |
+
.chat-container { display: flex; flex-direction: column; height: 100%; }
|
74 |
+
|
75 |
+
/* Welcome Screen */
|
76 |
+
.suggestion-card {
|
77 |
+
transition: all 0.2s ease-in-out;
|
78 |
+
border: 1px solid #e2e8f0; /* light: border-slate-200 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
}
|
80 |
+
.dark .suggestion-card { border-color: #334155; } /* dark: border-slate-700 */
|
81 |
+
.suggestion-card:hover {
|
82 |
+
transform: translateY(-4px);
|
83 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.05);
|
84 |
+
border-color: #93c5fd; /* light: border-primary-300 */
|
85 |
}
|
86 |
+
.dark .suggestion-card:hover {
|
87 |
+
box-shadow: 0 4px 20px rgba(0,0,0,0.2);
|
88 |
+
border-color: #3b82f6; /* dark: border-primary-500 */
|
|
|
89 |
}
|
90 |
+
|
91 |
+
/* Messages */
|
92 |
+
.message-bubble {
|
93 |
+
max-width: 80%; /* Max width for bubbles on mobile and desktop */
|
94 |
+
padding: 0.75rem 1.125rem;
|
|
|
|
|
|
|
|
|
95 |
border-radius: 1.25rem;
|
96 |
+
animation: fadeInUp 0.4s ease-out;
|
97 |
}
|
98 |
+
.user-message .message-bubble {
|
99 |
+
background-color: #2563eb; /* primary-600 */
|
100 |
+
color: white;
|
101 |
+
border-bottom-right-radius: 0.25rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
+
.assistant-message .message-bubble {
|
104 |
+
background-color: #ffffff; /* light: white */
|
105 |
+
color: #1e293b; /* light: slate-800 */
|
106 |
+
border: 1px solid #e2e8f0; /* light: slate-200 */
|
107 |
+
border-bottom-left-radius: 0.25rem;
|
108 |
}
|
109 |
+
.dark .assistant-message .message-bubble {
|
110 |
+
background-color: #1e293b; /* dark: slate-800 */
|
111 |
+
color: #e2e8f0; /* dark: slate-200 */
|
112 |
+
border-color: #334155; /* dark: slate-700 */
|
113 |
}
|
114 |
+
.assistant-avatar {
|
115 |
+
background: linear-gradient(135deg, #3b82f6, #9333ea);
|
116 |
}
|
117 |
+
|
118 |
+
/* Input Area */
|
119 |
+
.chat-input-area {
|
120 |
resize: none;
|
121 |
+
min-height: 52px; /* Fixed based on py-3 and text size */
|
122 |
+
max-height: 200px; /* Reduced max height slightly */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
}
|
124 |
+
.toast {
|
125 |
+
animation: toast-in-out 5s ease-in-out forwards;
|
|
|
|
|
|
|
126 |
}
|
127 |
+
@keyframes toast-in-out {
|
128 |
+
0%, 100% { transform: translateY(200%); opacity: 0; }
|
129 |
+
10%, 90% { transform: translateY(0); opacity: 1; }
|
|
|
130 |
}
|
131 |
+
pre code.hljs{padding:1em;border-radius:.5rem}
|
132 |
+
.prose table{width:100%;border-collapse:collapse}.prose td,.prose th{border:1px solid #e2e8f0;padding:.5rem .75rem;text-align:left}.dark .prose td,.dark .prose th{border-color:#334155}.prose thead{background-color:#f8fafc;font-weight:600}.dark .prose thead{background-color:#1e293b}.prose tbody tr:nth-child(2n){background-color:#f8fafc}.dark .prose tbody tr:nth-child(2n){background-color:#1e293b}
|
133 |
</style>
|
134 |
</head>
|
135 |
+
<body class="antialiased">
|
136 |
+
|
137 |
+
<div class="main-layout bg-slate-50 dark:bg-slate-950">
|
138 |
+
<!-- Sidebar -->
|
139 |
+
<aside id="sidebar" class="fixed inset-y-0 left-0 z-40 w-64 bg-slate-100 dark:bg-slate-900/70 backdrop-blur-md dark:backdrop-blur-sm border-r border-slate-200 dark:border-slate-800 flex flex-col p-4 transform -translate-x-full transition-transform duration-300 ease-in-out md:relative md:translate-x-0 md:w-auto md:min-w-[260px] md:z-auto md:backdrop-blur-none">
|
140 |
+
<div class="flex items-center justify-between mb-6">
|
141 |
+
<div class="flex items-center gap-2">
|
142 |
+
<img src="https://mariam-241.vercel.app/static/image/logoboma.png" alt="Logo" class="h-8">
|
143 |
+
<h1 class="text-xl font-bold text-slate-800 dark:text-slate-100">Mariam AI</h1>
|
144 |
+
</div>
|
145 |
+
<button id="close-sidebar-btn" class="p-1 rounded-md md:hidden text-slate-500 hover:text-slate-700 dark:text-slate-400 dark:hover:text-slate-200">
|
146 |
+
<i class="fa-solid fa-times text-xl"></i>
|
147 |
+
</button>
|
148 |
+
</div>
|
149 |
+
|
150 |
+
<button id="new-chat-btn" class="w-full flex items-center justify-center gap-2 px-4 py-2.5 mb-4 text-sm font-semibold text-white bg-primary-600 rounded-lg hover:bg-primary-700 transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 dark:focus:ring-offset-slate-900">
|
151 |
+
<i class="fa-solid fa-plus"></i>
|
152 |
+
Nouvelle Conversation
|
153 |
</button>
|
154 |
+
|
155 |
+
<div class="flex-grow overflow-y-auto">
|
156 |
+
<!-- Future chat history list -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
</div>
|
158 |
+
|
159 |
+
<div class="border-t border-slate-200 dark:border-slate-800 pt-4 mt-auto space-y-2">
|
160 |
+
<button id="theme-toggle" class="w-full flex items-center gap-3 px-3 py-2 text-sm font-medium text-slate-600 dark:text-slate-400 hover:bg-slate-200 dark:hover:bg-slate-800 rounded-md transition-colors">
|
161 |
+
<i class="fa-solid fa-sun w-4 text-center dark:hidden"></i>
|
162 |
+
<i class="fa-solid fa-moon w-4 text-center hidden dark:inline-block"></i>
|
163 |
+
<span>Changer de thème</span>
|
164 |
+
</button>
|
165 |
</div>
|
166 |
+
</aside>
|
167 |
+
<!-- Overlay for mobile sidebar -->
|
168 |
+
<div id="sidebar-overlay" class="fixed inset-0 z-30 bg-black/30 backdrop-blur-sm hidden md:hidden"></div>
|
169 |
+
|
170 |
+
<!-- Main Chat Area -->
|
171 |
+
<main class="flex-1 chat-container">
|
172 |
+
<!-- Chat Header -->
|
173 |
+
<header class="flex items-center justify-between p-3 sm:p-4 border-b border-slate-200 dark:border-slate-800">
|
174 |
+
<button id="sidebar-toggle" class="p-2 rounded-md md:hidden hover:bg-slate-100 dark:hover:bg-slate-800">
|
175 |
+
<i class="fa-solid fa-bars text-slate-600 dark:text-slate-400"></i>
|
176 |
+
</button>
|
177 |
+
<h2 class="text-base sm:text-lg font-semibold text-slate-700 dark:text-slate-300 mx-auto md:mx-0">Conversation Actuelle</h2>
|
178 |
+
<div class="flex items-center gap-2">
|
179 |
+
<label class="flex items-center cursor-pointer group">
|
180 |
+
<span class="mr-1.5 sm:mr-2 text-xs sm:text-sm font-medium text-slate-600 dark:text-slate-400">Web</span>
|
181 |
+
<div class="relative">
|
182 |
+
<input type="checkbox" id="web_search_toggle" class="sr-only peer">
|
183 |
+
<div class="w-9 h-5 sm:w-10 sm:h-5 bg-slate-300 dark:bg-slate-700 rounded-full peer peer-checked:after:translate-x-[calc(100%-2px)] peer-checked:after:border-white after:content-[''] after:absolute after:top-[1px] sm:after:top-0.5 after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-primary-500"></div>
|
184 |
+
</div>
|
185 |
+
</label>
|
186 |
</div>
|
187 |
+
</header>
|
188 |
+
|
189 |
+
<!-- Messages -->
|
190 |
+
<div id="chat-messages" class="flex-1 overflow-y-auto p-4 sm:p-6 space-y-4 sm:space-y-6">
|
191 |
+
<!-- Welcome Screen -->
|
192 |
+
<div id="welcome-screen" class="flex flex-col items-center justify-center h-full text-center animate-fade-in">
|
193 |
+
<div class="assistant-avatar w-16 h-16 sm:w-20 sm:h-20 rounded-full flex items-center justify-center mb-4 text-3xl sm:text-4xl text-white animate-pulse-subtle">✨</div>
|
194 |
+
<h1 class="text-2xl sm:text-3xl font-bold text-slate-800 dark:text-slate-100 mb-2">Comment puis-je vous aider ?</h1>
|
195 |
+
<p class="text-slate-500 dark:text-slate-400 mb-8 sm:mb-10 max-w-md text-sm sm:text-base">Je suis Mariam, un assistant IA capable de répondre à vos questions, de générer du code, et bien plus encore.</p>
|
196 |
+
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4 w-full max-w-2xl">
|
197 |
+
<div class="suggestion-card bg-white dark:bg-slate-800 p-3 sm:p-4 rounded-lg cursor-pointer" data-prompt="Donne-moi 3 idées de recettes rapides pour le dîner de ce soir.">
|
198 |
+
<p class="font-semibold text-slate-700 dark:text-slate-200 text-sm sm:text-base">Idées de recettes</p>
|
199 |
+
<p class="text-xs sm:text-sm text-slate-500 dark:text-slate-400">Pour un repas rapide et délicieux</p>
|
200 |
+
</div>
|
201 |
+
<div class="suggestion-card bg-white dark:bg-slate-800 p-3 sm:p-4 rounded-lg cursor-pointer" data-prompt="Écris un e-mail professionnel pour demander un jour de congé.">
|
202 |
+
<p class="font-semibold text-slate-700 dark:text-slate-200 text-sm sm:text-base">Rédiger un e-mail</p>
|
203 |
+
<p class="text-xs sm:text-sm text-slate-500 dark:text-slate-400">Pour une demande de congé</p>
|
204 |
+
</div>
|
205 |
+
<div class="suggestion-card bg-white dark:bg-slate-800 p-3 sm:p-4 rounded-lg cursor-pointer" data-prompt="Explique le concept de 'machine learning' en termes simples.">
|
206 |
+
<p class="font-semibold text-slate-700 dark:text-slate-200 text-sm sm:text-base">Expliquer un concept</p>
|
207 |
+
<p class="text-xs sm:text-sm text-slate-500 dark:text-slate-400">Le machine learning pour les débutants</p>
|
208 |
+
</div>
|
209 |
+
<div class="suggestion-card bg-white dark:bg-slate-800 p-3 sm:p-4 rounded-lg cursor-pointer" data-prompt="Écris une fonction Python qui inverse une chaîne de caractères.">
|
210 |
+
<p class="font-semibold text-slate-700 dark:text-slate-200 text-sm sm:text-base">Générer du code</p>
|
211 |
+
<p class="text-xs sm:text-sm text-slate-500 dark:text-slate-400">Pour inverser une chaîne en Python</p>
|
212 |
+
</div>
|
213 |
+
</div>
|
214 |
</div>
|
215 |
+
|
216 |
+
<!-- Dynamic messages will be injected here -->
|
217 |
+
<div id="history-loading" class="text-center py-10 hidden">
|
218 |
+
<i class="fa-solid fa-spinner fa-spin text-2xl text-primary-500"></i>
|
219 |
+
<p class="mt-2 text-sm text-slate-500">Chargement de la conversation...</p>
|
|
|
|
|
|
|
|
|
|
|
220 |
</div>
|
221 |
+
|
222 |
+
<div id="loading-indicator" class="assistant-message flex items-start gap-3 hidden">
|
223 |
+
<div class="assistant-avatar w-8 h-8 sm:w-9 sm:h-9 rounded-full flex items-center justify-center flex-shrink-0 text-lg sm:text-xl text-white">✨</div>
|
224 |
+
<div class="message-bubble flex items-center gap-2">
|
225 |
+
<div class="h-2 w-2 bg-slate-400 rounded-full animate-bounce [animation-delay:-0.3s]"></div>
|
226 |
+
<div class="h-2 w-2 bg-slate-400 rounded-full animate-bounce [animation-delay:-0.15s]"></div>
|
227 |
+
<div class="h-2 w-2 bg-slate-400 rounded-full animate-bounce"></div>
|
228 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
</div>
|
230 |
+
</div>
|
231 |
+
|
232 |
+
<!-- Chat Input Area -->
|
233 |
+
<footer class="p-3 sm:p-4 bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm">
|
234 |
+
<div class="max-w-4xl mx-auto">
|
235 |
+
<div id="preview-area" class="px-2 py-1.5 sm:px-4 sm:py-2 hidden"></div>
|
236 |
+
<form id="chat-form" class="relative">
|
237 |
+
<textarea id="prompt" name="prompt" rows="1" class="chat-input-area w-full bg-slate-100 dark:bg-slate-800 border-2 border-transparent focus:border-primary-500 focus:ring-0 rounded-xl py-3 pl-10 pr-[48px] sm:pl-12 sm:pr-[56px] text-sm sm:text-base text-slate-800 dark:text-slate-100 transition-colors duration-200" placeholder="Envoyez un message..."></textarea>
|
238 |
+
<div class="absolute left-2 sm:left-3 top-1/2 -translate-y-1/2 flex items-center">
|
239 |
+
<label for="file_upload" class="cursor-pointer text-slate-500 hover:text-primary-500 transition-colors p-1">
|
240 |
+
<i class="fa-solid fa-paperclip text-base sm:text-lg"></i>
|
241 |
+
<input type="file" id="file_upload" name="file" class="hidden" accept=".txt,.pdf,.png,.jpg,.jpeg,.md,.py,.js,.html,.css,.json">
|
242 |
+
</label>
|
243 |
+
</div>
|
244 |
+
<button type="submit" id="send-button" class="absolute right-2 sm:right-3 top-1/2 -translate-y-1/2 w-8 h-8 sm:w-9 sm:h-9 bg-primary-600 text-white rounded-full flex items-center justify-center hover:bg-primary-700 disabled:bg-slate-300 dark:disabled:bg-slate-700 disabled:cursor-not-allowed transition-all">
|
245 |
+
<i class="fa-solid fa-arrow-up text-sm sm:text-base"></i>
|
246 |
+
</button>
|
247 |
+
</form>
|
248 |
+
<p class="text-xs text-center text-slate-400 dark:text-slate-500 mt-2">
|
249 |
+
Mariam AI peut faire des erreurs. Vérifiez les informations importantes.
|
250 |
+
</p>
|
251 |
</div>
|
252 |
+
</footer>
|
253 |
+
</main>
|
254 |
+
</div>
|
255 |
+
|
256 |
+
<!-- Toast/Error Notification Area -->
|
257 |
+
<div id="toast-container" class="fixed bottom-4 right-4 sm:bottom-5 sm:right-5 z-50 w-[calc(100%-2rem)] max-w-xs sm:max-w-sm"></div>
|
258 |
+
|
259 |
+
|
260 |
<script>
|
261 |
document.addEventListener('DOMContentLoaded', () => {
|
262 |
+
// --- DOM Elements ---
|
263 |
+
const dom = {
|
264 |
+
sidebar: document.getElementById('sidebar'),
|
265 |
+
sidebarToggle: document.getElementById('sidebar-toggle'),
|
266 |
+
closeSidebarBtn: document.getElementById('close-sidebar-btn'),
|
267 |
+
sidebarOverlay: document.getElementById('sidebar-overlay'),
|
268 |
+
themeToggle: document.getElementById('theme-toggle'),
|
269 |
+
newChatBtn: document.getElementById('new-chat-btn'),
|
270 |
+
chatForm: document.getElementById('chat-form'),
|
271 |
+
promptInput: document.getElementById('prompt'),
|
272 |
+
sendButton: document.getElementById('send-button'),
|
273 |
+
chatMessages: document.getElementById('chat-messages'),
|
274 |
+
welcomeScreen: document.getElementById('welcome-screen'),
|
275 |
+
historyLoading: document.getElementById('history-loading'),
|
276 |
+
loadingIndicator: document.getElementById('loading-indicator'),
|
277 |
+
webSearchToggle: document.getElementById('web_search_toggle'),
|
278 |
+
fileUpload: document.getElementById('file_upload'),
|
279 |
+
previewArea: document.getElementById('preview-area'),
|
280 |
+
toastContainer: document.getElementById('toast-container'),
|
281 |
+
suggestionCards: document.querySelectorAll('.suggestion-card')
|
282 |
+
};
|
283 |
+
|
284 |
+
// --- State ---
|
285 |
+
let isComposing = false;
|
286 |
+
let currentFile = null;
|
287 |
+
|
288 |
+
// --- API Endpoints ---
|
289 |
const API_CHAT_ENDPOINT = '/api/chat';
|
290 |
const API_HISTORY_ENDPOINT = '/api/history';
|
291 |
const CLEAR_ENDPOINT = '/clear';
|
|
|
|
|
|
|
|
|
292 |
|
293 |
+
// --- UI Functions ---
|
294 |
+
const setUIState = (isLoading) => {
|
295 |
+
dom.promptInput.disabled = isLoading;
|
296 |
+
dom.sendButton.disabled = isLoading || (!dom.promptInput.value.trim() && !currentFile);
|
297 |
+
dom.fileUpload.disabled = isLoading;
|
298 |
+
if (isLoading) {
|
299 |
+
dom.loadingIndicator.classList.remove('hidden');
|
300 |
+
scrollToBottom();
|
301 |
} else {
|
302 |
+
dom.loadingIndicator.classList.add('hidden');
|
303 |
}
|
304 |
+
};
|
305 |
+
|
306 |
+
const adjustTextareaHeight = () => {
|
307 |
+
dom.promptInput.style.height = 'auto';
|
308 |
+
let newHeight = dom.promptInput.scrollHeight;
|
309 |
+
const maxHeight = parseInt(window.getComputedStyle(dom.promptInput).maxHeight, 10);
|
310 |
+
if (newHeight > maxHeight) {
|
311 |
+
newHeight = maxHeight;
|
312 |
+
dom.promptInput.style.overflowY = 'auto';
|
313 |
} else {
|
314 |
+
dom.promptInput.style.overflowY = 'hidden';
|
|
|
315 |
}
|
316 |
+
dom.promptInput.style.height = `${newHeight}px`;
|
317 |
+
updateSendButtonState();
|
318 |
+
};
|
319 |
+
|
320 |
+
const updateSendButtonState = () => {
|
321 |
+
const hasText = dom.promptInput.value.trim().length > 0;
|
322 |
+
const hasFile = !!currentFile;
|
323 |
+
dom.sendButton.disabled = !hasText && !hasFile;
|
324 |
+
};
|
|
|
|
|
|
|
325 |
|
326 |
+
const scrollToBottom = (behavior = 'smooth') => {
|
|
|
327 |
setTimeout(() => {
|
328 |
+
dom.chatMessages.scrollTo({ top: dom.chatMessages.scrollHeight, behavior });
|
329 |
}, 50);
|
330 |
+
};
|
331 |
|
332 |
+
const openMobileSidebar = () => {
|
333 |
+
dom.sidebar.classList.remove('-translate-x-full');
|
334 |
+
dom.sidebarOverlay.classList.remove('hidden');
|
335 |
+
document.body.style.overflow = 'hidden'; // Prevent body scroll when sidebar is open
|
336 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
|
338 |
+
const closeMobileSidebar = () => {
|
339 |
+
dom.sidebar.classList.add('-translate-x-full');
|
340 |
+
dom.sidebarOverlay.classList.add('hidden');
|
341 |
+
document.body.style.overflow = ''; // Restore body scroll
|
342 |
+
};
|
|
|
343 |
|
344 |
+
const toggleTheme = () => {
|
345 |
+
document.documentElement.classList.toggle('dark');
|
346 |
+
localStorage.theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light';
|
347 |
+
};
|
|
|
348 |
|
349 |
+
const initializeTheme = () => {
|
350 |
+
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
351 |
+
document.documentElement.classList.add('dark');
|
352 |
} else {
|
353 |
+
document.documentElement.classList.remove('dark');
|
354 |
}
|
355 |
+
};
|
356 |
+
|
357 |
+
const showToast = (message, type = 'error') => {
|
358 |
+
const colors = {
|
359 |
+
error: 'bg-red-500',
|
360 |
+
success: 'bg-green-500',
|
361 |
+
info: 'bg-blue-500'
|
362 |
+
};
|
363 |
+
const icon = {
|
364 |
+
error: 'fa-circle-xmark',
|
365 |
+
success: 'fa-circle-check',
|
366 |
+
info: 'fa-circle-info'
|
367 |
+
}
|
368 |
+
const toast = document.createElement('div');
|
369 |
+
toast.className = `toast flex items-center gap-2 sm:gap-3 ${colors[type]} text-white text-xs sm:text-sm font-semibold px-3 py-2 sm:px-4 sm:py-3 rounded-lg shadow-lg mb-2`;
|
370 |
+
toast.innerHTML = `<i class="fa-solid ${icon[type]} text-base sm:text-lg"></i> <p>${message}</p>`;
|
371 |
+
dom.toastContainer.appendChild(toast);
|
372 |
+
setTimeout(() => toast.remove(), 5000);
|
373 |
+
};
|
374 |
|
375 |
+
const addMessageToChat = (role, content, isHtml = false) => {
|
376 |
+
dom.welcomeScreen.classList.add('hidden');
|
377 |
+
dom.historyLoading.classList.add('hidden');
|
378 |
+
|
379 |
+
const messageContainer = document.createElement('div');
|
380 |
+
messageContainer.className = `flex items-start gap-2 sm:gap-3 w-full animate-fade-in-up ${role === 'user' ? 'user-message justify-end' : 'assistant-message'}`;
|
381 |
+
|
382 |
+
let messageHtml = '';
|
383 |
if (role === 'user') {
|
384 |
+
const escapedContent = escapeHtml(content);
|
385 |
+
messageHtml = `<div class="message-bubble"><p class="text-sm sm:text-base">${escapedContent}</p></div>`;
|
|
|
|
|
|
|
386 |
} else {
|
387 |
+
const avatar = `<div class="assistant-avatar w-8 h-8 sm:w-9 sm:h-9 rounded-full flex items-center justify-center flex-shrink-0 text-lg sm:text-xl text-white">✨</div>`;
|
388 |
+
// Ensure prose styles apply correctly to potentially complex HTML from assistant
|
389 |
+
const bubbleContent = isHtml ? `<div class="prose prose-sm sm:prose-base max-w-none dark:prose-invert">${content}</div>` : `<p class="text-sm sm:text-base">${escapeHtml(content)}</p>`;
|
390 |
+
messageHtml = `
|
391 |
+
${avatar}
|
392 |
+
<div class="message-bubble">
|
393 |
+
${bubbleContent}
|
|
|
394 |
</div>
|
395 |
+
`;
|
|
|
|
|
|
|
|
|
|
|
396 |
}
|
397 |
+
|
398 |
+
messageContainer.innerHTML = messageHtml;
|
399 |
+
dom.chatMessages.insertBefore(messageContainer, dom.loadingIndicator);
|
400 |
+
scrollToBottom();
|
401 |
+
};
|
402 |
+
|
403 |
+
const escapeHtml = (unsafe) => unsafe.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
404 |
|
405 |
+
const resetChat = () => {
|
406 |
+
dom.welcomeScreen.classList.remove('hidden');
|
407 |
+
// Remove all previous messages except the templates
|
408 |
+
const messages = dom.chatMessages.querySelectorAll('.user-message, .assistant-message:not(#loading-indicator)');
|
409 |
+
messages.forEach(msg => {
|
410 |
+
if (msg.id !== 'loading-indicator') { // Ensure we don't remove the template itself
|
411 |
+
msg.remove();
|
412 |
+
}
|
|
|
|
|
413 |
});
|
414 |
+
dom.promptInput.value = '';
|
415 |
+
clearFileInput();
|
416 |
+
adjustTextareaHeight();
|
417 |
+
dom.promptInput.focus();
|
418 |
+
};
|
419 |
|
420 |
+
// --- File Handling ---
|
421 |
+
const clearFileInput = () => {
|
422 |
+
currentFile = null;
|
423 |
+
dom.fileUpload.value = ''; // Reset file input
|
424 |
+
dom.previewArea.innerHTML = '';
|
425 |
+
dom.previewArea.classList.add('hidden');
|
426 |
+
updateSendButtonState();
|
427 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
|
429 |
+
const handleFileChange = () => {
|
430 |
+
if (dom.fileUpload.files.length > 0) {
|
431 |
+
currentFile = dom.fileUpload.files[0];
|
432 |
+
|
433 |
+
// Validate file size (e.g., 5MB limit)
|
434 |
+
const maxSize = 5 * 1024 * 1024; // 5MB
|
435 |
+
if (currentFile.size > maxSize) {
|
436 |
+
showToast('Le fichier est trop volumineux (max 5MB).', 'error');
|
437 |
+
clearFileInput();
|
438 |
+
return;
|
439 |
+
}
|
440 |
|
441 |
+
dom.previewArea.classList.remove('hidden');
|
442 |
+
|
443 |
+
const fileChip = document.createElement('div');
|
444 |
+
fileChip.className = "inline-flex items-center bg-primary-100 dark:bg-primary-900/50 text-primary-700 dark:text-primary-200 text-xs sm:text-sm font-medium pl-2 pr-1 py-1 sm:pl-3 sm:pr-2 sm:py-1 rounded-full";
|
445 |
+
fileChip.innerHTML = `
|
446 |
+
<i class="fa-solid fa-file mr-1.5 sm:mr-2"></i>
|
447 |
+
<span class="max-w-[150px] sm:max-w-[200px] truncate" title="${escapeHtml(currentFile.name)}">${escapeHtml(currentFile.name)}</span>
|
448 |
+
<button type="button" class="ml-1.5 sm:ml-2 text-primary-500 hover:text-primary-700 dark:text-primary-300 dark:hover:text-primary-100 p-0.5 rounded-full hover:bg-primary-200 dark:hover:bg-primary-700/50">
|
449 |
+
<i class="fa-solid fa-xmark text-xs sm:text-sm"></i>
|
450 |
+
</button>
|
451 |
+
`;
|
452 |
+
|
453 |
+
dom.previewArea.innerHTML = ''; // Clear previous preview
|
454 |
+
dom.previewArea.appendChild(fileChip);
|
455 |
+
fileChip.querySelector('button').addEventListener('click', clearFileInput);
|
456 |
+
updateSendButtonState();
|
457 |
}
|
458 |
+
};
|
|
|
|
|
|
|
|
|
459 |
|
460 |
+
// --- API Calls ---
|
461 |
+
const loadChatHistory = async () => {
|
462 |
+
dom.historyLoading.classList.remove('hidden');
|
463 |
+
dom.welcomeScreen.classList.add('hidden');
|
464 |
try {
|
465 |
const response = await fetch(API_HISTORY_ENDPOINT);
|
466 |
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
const data = await response.json();
|
468 |
+
if (!data.success) throw new Error(data.error || 'Failed to load history');
|
469 |
+
|
470 |
+
if (data.history.length > 0) {
|
471 |
+
dom.welcomeScreen.classList.add('hidden');
|
472 |
+
// Clear any existing messages before loading history to prevent duplicates
|
473 |
+
const messages = dom.chatMessages.querySelectorAll('.user-message, .assistant-message:not(#loading-indicator)');
|
474 |
+
messages.forEach(msg => msg.id !== 'loading-indicator' && msg.remove());
|
475 |
+
|
476 |
+
data.history.forEach(msg => addMessageToChat(msg.role, msg.text, msg.role === 'assistant'));
|
477 |
+
scrollToBottom('auto');
|
|
|
|
|
|
|
478 |
} else {
|
479 |
+
dom.welcomeScreen.classList.remove('hidden');
|
480 |
}
|
481 |
} catch (error) {
|
482 |
+
console.error("Error loading chat history:", error);
|
483 |
+
showToast(`Erreur de chargement de l'historique: ${error.message}`, 'error');
|
484 |
+
dom.welcomeScreen.classList.remove('hidden'); // Show welcome if history fails
|
|
|
485 |
} finally {
|
486 |
+
dom.historyLoading.classList.add('hidden');
|
|
|
|
|
487 |
}
|
488 |
+
};
|
489 |
+
|
490 |
+
const clearChatHistory = async () => {
|
491 |
+
try {
|
492 |
+
const response = await fetch(CLEAR_ENDPOINT, { method: 'POST' });
|
493 |
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
494 |
+
const data = await response.json();
|
495 |
+
if (!data.success) throw new Error(data.error || 'Failed to clear chat');
|
496 |
+
resetChat();
|
497 |
+
showToast('Conversation effacée.', 'success');
|
498 |
+
if (window.innerWidth < 768) { // md breakpoint
|
499 |
+
closeMobileSidebar();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
500 |
}
|
501 |
+
} catch(error) {
|
502 |
+
console.error("Error clearing chat history:", error);
|
503 |
+
showToast(`Erreur lors de l'effacement: ${error.message}`, 'error');
|
504 |
}
|
505 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
|
507 |
+
// --- Event Listeners ---
|
508 |
+
dom.themeToggle.addEventListener('click', toggleTheme);
|
509 |
+
|
510 |
+
// Sidebar Mobile Listeners
|
511 |
+
dom.sidebarToggle.addEventListener('click', openMobileSidebar);
|
512 |
+
dom.closeSidebarBtn.addEventListener('click', closeMobileSidebar);
|
513 |
+
dom.sidebarOverlay.addEventListener('click', closeMobileSidebar);
|
514 |
+
|
515 |
+
dom.newChatBtn.addEventListener('click', clearChatHistory);
|
516 |
+
|
517 |
+
dom.promptInput.addEventListener('input', adjustTextareaHeight);
|
518 |
+
dom.promptInput.addEventListener('keydown', (e) => {
|
519 |
if (isComposing) return;
|
520 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
521 |
+
e.preventDefault();
|
522 |
+
if (!dom.sendButton.disabled) {
|
523 |
+
dom.chatForm.requestSubmit();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
}
|
525 |
}
|
526 |
});
|
527 |
+
dom.promptInput.addEventListener('compositionstart', () => { isComposing = true; });
|
528 |
+
dom.promptInput.addEventListener('compositionend', () => { isComposing = false; adjustTextareaHeight(); });
|
529 |
+
|
530 |
+
dom.fileUpload.addEventListener('change', handleFileChange);
|
531 |
+
|
532 |
+
dom.suggestionCards.forEach(card => {
|
533 |
+
card.addEventListener('click', () => {
|
534 |
+
dom.promptInput.value = card.dataset.prompt;
|
535 |
+
dom.promptInput.focus();
|
536 |
+
adjustTextareaHeight(); // Ensure height is correct
|
537 |
+
updateSendButtonState(); // Ensure button state is correct
|
538 |
+
// Small delay to allow UI update before submitting
|
539 |
+
setTimeout(() => dom.chatForm.requestSubmit(), 50);
|
540 |
+
});
|
541 |
});
|
|
|
542 |
|
543 |
+
dom.chatForm.addEventListener('submit', async (e) => {
|
|
|
544 |
e.preventDefault();
|
545 |
+
const prompt = dom.promptInput.value.trim();
|
546 |
+
if (!prompt && !currentFile) return;
|
547 |
+
|
548 |
+
let userMessageContent = prompt;
|
549 |
+
// Construct a message that indicates a file is attached, if any
|
550 |
+
if (currentFile) {
|
551 |
+
userMessageContent = prompt ? `${prompt}\n\n[Fichier attaché: ${currentFile.name}]` : `[Fichier attaché: ${currentFile.name}]`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
552 |
}
|
553 |
+
addMessageToChat('user', userMessageContent);
|
554 |
+
|
555 |
const formData = new FormData();
|
556 |
+
formData.append('prompt', prompt); // Send original prompt text
|
557 |
+
formData.append('web_search', dom.webSearchToggle.checked);
|
558 |
+
if (currentFile) {
|
559 |
+
formData.append('file', currentFile, currentFile.name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
}
|
561 |
+
|
562 |
+
dom.promptInput.value = '';
|
563 |
+
clearFileInput(); // This also calls updateSendButtonState
|
564 |
+
adjustTextareaHeight();
|
565 |
+
setUIState(true);
|
566 |
+
|
567 |
try {
|
568 |
const response = await fetch(API_CHAT_ENDPOINT, { method: 'POST', body: formData });
|
|
|
569 |
if (!response.ok) {
|
570 |
+
let errorData;
|
571 |
+
try {
|
572 |
+
errorData = await response.json();
|
573 |
+
} catch (jsonError) {
|
574 |
+
// If response is not JSON, use status text
|
575 |
+
throw new Error(response.statusText || `Erreur serveur: ${response.status}`);
|
576 |
+
}
|
577 |
+
throw new Error(errorData.error || `Erreur serveur: ${response.status}`);
|
578 |
}
|
579 |
+
const data = await response.json();
|
580 |
+
addMessageToChat('assistant', data.message, true); // Assume assistant message can be HTML
|
581 |
} catch (error) {
|
582 |
+
console.error("Error submitting chat:", error);
|
583 |
+
const errorMessage = `<p class="text-red-600 dark:text-red-400">Désolé, une erreur est survenue :<br>${escapeHtml(error.message)}</p>`;
|
584 |
+
addMessageToChat('assistant', errorMessage, true);
|
585 |
} finally {
|
586 |
+
setUIState(false);
|
587 |
+
dom.promptInput.focus();
|
588 |
}
|
589 |
});
|
590 |
+
|
591 |
+
// --- Initialization ---
|
592 |
+
initializeTheme();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
593 |
loadChatHistory();
|
594 |
+
adjustTextareaHeight(); // Initial height adjustment
|
595 |
+
updateSendButtonState(); // Initial button state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
});
|
597 |
</script>
|
598 |
</body>
|
599 |
+
</html>
|