Docfile commited on
Commit
fee7ac4
·
verified ·
1 Parent(s): 4946ffa

Delete templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +0 -1221
templates/index.html DELETED
@@ -1,1221 +0,0 @@
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.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=Inter: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>
18
- tailwind.config = {
19
- darkMode: 'class',
20
- theme: {
21
- extend: {
22
- fontFamily: {
23
- sans: ['Inter', 'system-ui', 'sans-serif'],
24
- mono: ['"JetBrains Mono"', 'monospace']
25
- },
26
- colors: {
27
- primary: { 50: '#f0f9ff', 100: '#e0f2fe', 200: '#bae6fd', 300: '#7dd3fc', 400: '#38bdf8', 500: '#0ea5e9', 600: '#0284c7', 700: '#0369a1', 800: '#075985', 900: '#0c4a6e' },
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
- animation: { 'bounce-slow': 'bounce 2s infinite', 'pulse-slow': 'pulse 3s infinite', 'typing': 'typing 1.2s steps(3) infinite' },
32
- keyframes: { typing: { '0%': { width: '0.15em' }, '50%': { width: '0.7em' }, '100%': { width: '0.15em' } } }
33
- }
34
- }
35
- }
36
- </script>
37
- <style>
38
- html {
39
- scroll-behavior: smooth;
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 .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
- border-bottom-right-radius: 0.125rem;
93
- align-self: flex-end;
94
- background: linear-gradient(to bottom right, #3b82f6, #2563eb);
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-color: #0f172a;
132
- color: #e2e8f0;
133
- }
134
- .tooltip {
135
- position: relative;
136
- }
137
- .tooltip .tooltip-text {
138
- visibility: hidden;
139
- width: max-content;
140
- max-width: 200px;
141
- background-color: #1e293b;
142
- color: #f8fafc;
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
- /* START: CSS for multi-file preview */
190
- .file-preview {
191
- max-height: 200px; /* Adjusted max-height for multi previews */
192
- overflow-y: auto;
193
- scrollbar-width: thin;
194
- padding: 0.5rem; /* Add some padding */
195
- background-color: rgba(243, 244, 246, 0.5); /* Light background */
196
- border-radius: 0.5rem;
197
- margin-top: 0.5rem;
198
- }
199
- .dark .file-preview {
200
- background-color: rgba(30, 41, 59, 0.5); /* Darker background for dark mode */
201
- }
202
-
203
- .file-preview-item {
204
- background-color: rgba(255, 255, 255, 0.7);
205
- transition: all 0.2s ease-in-out;
206
- margin-bottom: 0.5rem;
207
- padding: 0.5rem;
208
- border: 1px solid #e5e7eb;
209
- border-radius: 0.375rem;
210
- display: flex;
211
- align-items: center;
212
- }
213
-
214
- .dark .file-preview-item {
215
- background-color: rgba(51, 65, 85, 0.5);
216
- border-color: rgba(71, 85, 105, 0.5);
217
- }
218
-
219
- .file-preview-item:hover {
220
- background-color: rgba(255, 255, 255, 1);
221
- }
222
-
223
- .dark .file-preview-item:hover {
224
- background-color: rgba(51, 65, 85, 0.8);
225
- }
226
-
227
- #file-preview::-webkit-scrollbar {
228
- width: 5px;
229
- }
230
-
231
- #file-preview::-webkit-scrollbar-thumb {
232
- background-color: rgba(156, 163, 175, 0.5);
233
- border-radius: 3px;
234
- }
235
-
236
- #file-preview::-webkit-scrollbar-track {
237
- background-color: rgba(229, 231, 235, 0.3);
238
- }
239
-
240
- .dark #file-preview::-webkit-scrollbar-thumb {
241
- background-color: rgba(75, 85, 99, 0.5);
242
- }
243
-
244
- .dark #file-preview::-webkit-scrollbar-track {
245
- background-color: rgba(31, 41, 55, 0.3);
246
- }
247
- /* END: CSS for multi-file preview */
248
-
249
- .chip {
250
- display: inline-flex;
251
- align-items: center;
252
- background: #e0f2fe;
253
- border-radius: 9999px;
254
- padding: 0.25rem 0.75rem;
255
- font-size: 0.75rem;
256
- font-weight: 500;
257
- color: #0369a1;
258
- transition: all 0.2s ease;
259
- }
260
- .chip .chip-icon { margin-right: 0.25rem; }
261
- .chip .chip-close {
262
- margin-left: 0.25rem;
263
- cursor: pointer;
264
- opacity: 0.7;
265
- transition: opacity 0.2s ease;
266
- }
267
- .chip .chip-close:hover { opacity: 1; }
268
- .dark .chip {
269
- background: #0c4a6e;
270
- color: #7dd3fc;
271
- }
272
- .toggle-switch {
273
- position: relative;
274
- display: inline-block;
275
- width: 2.5rem;
276
- height: 1.25rem;
277
- }
278
- .toggle-switch input {
279
- opacity: 0;
280
- width: 0;
281
- height: 0;
282
- }
283
- .toggle-slider {
284
- position: absolute;
285
- cursor: pointer;
286
- top: 0;
287
- left: 0;
288
- right: 0;
289
- bottom: 0;
290
- background-color: #cbd5e1;
291
- transition: .4s;
292
- border-radius: 1.25rem;
293
- }
294
- .toggle-slider:before {
295
- position: absolute;
296
- content: "";
297
- height: 0.875rem;
298
- width: 0.875rem;
299
- left: 0.25rem;
300
- bottom: 0.1875rem;
301
- background-color: white;
302
- transition: .4s;
303
- border-radius: 50%;
304
- }
305
- input:checked + .toggle-slider {
306
- background-color: #0ea5e9;
307
- }
308
- input:focus + .toggle-slider {
309
- box-shadow: 0 0 1px #0ea5e9;
310
- }
311
- input:checked + .toggle-slider:before {
312
- transform: translateX(1.125rem);
313
- }
314
- .dark .toggle-slider {
315
- background-color: #475569;
316
- }
317
- .dark input:checked + .toggle-slider {
318
- background-color: #38bdf8;
319
- }
320
- .chat-input {
321
- transition: all 0.3s ease;
322
- border-color: #e2e8f0;
323
- }
324
- .chat-input:focus {
325
- border-color: #38bdf8;
326
- box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
327
- }
328
- .dark .chat-input {
329
- background-color: #1e293b;
330
- color: #f1f5f9;
331
- border-color: #334155;
332
- }
333
- .dark .chat-input:focus {
334
- border-color: #38bdf8;
335
- box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
336
- }
337
- pre {
338
- position: relative;
339
- background-color: #f8fafc;
340
- border-radius: 0.5rem;
341
- margin: 1rem 0;
342
- padding: 1.25rem 1rem;
343
- overflow-x: auto;
344
- }
345
- .dark pre {
346
- background-color: #1e293b;
347
- color: #e2e8f0;
348
- }
349
- code {
350
- font-family: 'JetBrains Mono', monospace;
351
- font-size: 0.875rem;
352
- }
353
- .code-copy-btn {
354
- position: absolute;
355
- top: 0.5rem;
356
- right: 0.5rem;
357
- opacity: 0;
358
- transition: opacity 0.2s ease;
359
- }
360
- pre:hover .code-copy-btn {
361
- opacity: 0.7;
362
- }
363
- /* Amélioration de l'affichage des tableaux Markdown */
364
- .table-wrapper {
365
- width: 100%;
366
- overflow-x: auto;
367
- margin: 1rem 0;
368
- border: 1px solid #e2e8f0;
369
- border-radius: 0.5rem;
370
- }
371
- .dark .table-wrapper {
372
- border-color: #334155;
373
- }
374
- .prose table {
375
- width: 100%;
376
- min-width: 100%;
377
- border-collapse: collapse;
378
- margin: 0;
379
- }
380
- .prose table th,
381
- .prose table td {
382
- border: 1px solid #e2e8f0;
383
- padding: 0.5rem 0.75rem;
384
- text-align: left;
385
- border-top: none;
386
- border-left: none;
387
- border-right: none;
388
- }
389
- .prose table th {
390
- border-bottom-width: 2px;
391
- }
392
- .dark .prose table th,
393
- .dark .prose table td {
394
- border-color: #334155;
395
- }
396
- .prose table thead {
397
- background-color: #f8fafc;
398
- font-weight: 600;
399
- }
400
- .dark .prose table thead {
401
- background-color: #1e293b;
402
- }
403
- .prose table tbody tr:nth-child(even) {
404
- background-color: #f8fafc;
405
- }
406
- .dark .prose table tbody tr:nth-child(even) {
407
- background-color: #1e293b;
408
- }
409
- /* Pour le textarea qui s'adapte au contenu */
410
- .chat-textarea {
411
- resize: none;
412
- min-height: 44px;
413
- max-height: 200px;
414
- overflow-y: auto;
415
- line-height: 1.5;
416
- width: 100%;
417
- border-radius: 9999px;
418
- padding-top: 0.625rem;
419
- padding-bottom: 0.625rem;
420
- padding-left: 1rem;
421
- padding-right: 3rem;
422
- box-sizing: border-box;
423
- }
424
- /* Ajustements responsive */
425
- @media (max-width: 640px) {
426
- .message-bubble {
427
- max-width: 90%;
428
- padding: 0.75rem 0.875rem;
429
- }
430
- .chat-textarea {
431
- max-height: 120px;
432
- font-size: 0.95rem;
433
- min-height: 40px;
434
- padding-top: 0.5rem;
435
- padding-bottom: 0.5rem;
436
- }
437
- .prose table {
438
- min-width: 0;
439
- font-size: 0.85rem;
440
- }
441
- .prose table th,
442
- .prose table td {
443
- padding: 0.375rem 0.5rem;
444
- }
445
- .send-button-wrapper {
446
- padding-right: 0.25rem;
447
- }
448
- .chat-textarea {
449
- padding-right: 2.75rem;
450
- }
451
- #send-button {
452
- width: 32px;
453
- height: 32px;
454
- padding: 0;
455
- display: inline-flex;
456
- align-items: center;
457
- justify-content: center;
458
- }
459
- #send-button i {
460
- font-size: 0.9rem;
461
- }
462
- /* Smaller file previews on mobile */
463
- .file-preview-item {
464
- padding: 0.375rem;
465
- }
466
- .file-preview-item .w-12 { width: 2.5rem; }
467
- .file-preview-item .h-12 { height: 2.5rem; }
468
- .file-preview-item .w-10 { width: 2rem; }
469
- .file-preview-item .h-10 { height: 2rem; }
470
- .file-preview-item .text-xs { font-size: 0.7rem; }
471
- .file-preview { max-height: 150px; }
472
-
473
- }
474
- /* Container pour le textarea et le bouton */
475
- .input-wrapper {
476
- position: relative;
477
- display: flex;
478
- align-items: flex-end;
479
- }
480
- .send-button-wrapper {
481
- position: absolute;
482
- right: 0.5rem;
483
- bottom: 0.5rem;
484
- }
485
- </style>
486
- </head>
487
- <body class="bg-gray-50 text-gray-900 antialiased">
488
- <!-- Header -->
489
- <header class="bg-gradient-to-r from-primary-600 to-primary-800 text-white py-3 px-4 shadow-md sticky top-0 z-10">
490
- <div class="max-w-4xl mx-auto flex justify-between items-center">
491
- <!-- Logo & Titre -->
492
- <div class="flex items-center space-x-2">
493
- <img src="https://mariam-241.vercel.app/static/image/logoboma.png" alt="Logo Mariam AI" class="h-8 sm:h-10 object-contain">
494
- <h1 class="text-xl font-bold">Mariam AI</h1>
495
- </div>
496
- <!-- Actions -->
497
- <div class="flex items-center space-x-2 sm:space-x-4">
498
- <button id="theme-toggle" class="p-2 rounded-full hover:bg-primary-700/50 transition-colors duration-200 tooltip" aria-label="Changer de thème">
499
- <i class="fa-solid fa-moon dark:hidden"></i>
500
- <i class="fa-solid fa-sun hidden dark:inline"></i>
501
- <span class="tooltip-text">Mode clair/sombre</span>
502
- </button>
503
- <form action="/clear" method="POST" id="clear-form">
504
- <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">
505
- <i class="fa-solid fa-trash-can mr-1.5"></i>
506
- <span class="hidden sm:inline">Effacer</span>
507
- <span class="tooltip-text">Effacer la conversation</span>
508
- </button>
509
- </form>
510
- </div>
511
- </div>
512
- </header>
513
- <!-- Main Container -->
514
- <main class="max-w-4xl mx-auto chat-layout">
515
- <!-- Conteneur des messages -->
516
- <section id="chat-messages" class="flex flex-col space-y-6 p-4 overflow-y-auto">
517
- <!-- Chargement de l'historique -->
518
- <div id="history-loading" class="text-center py-10">
519
- <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">
520
- <svg class="animate-spin h-5 w-5 mr-3" viewBox="0 0 24 24">
521
- <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
522
- <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>
523
- </svg>
524
- <span>Chargement de la conversation...</span>
525
- </div>
526
- </div>
527
- <!-- Indicateur de chargement pour les réponses -->
528
- <div id="loading-indicator" class="flex items-start space-x-2 hidden">
529
- <div class="w-8 h-8 rounded-full bg-primary-100 flex items-center justify-center flex-shrink-0 dark:bg-primary-900/50">
530
- <span class="text-lg">✨</span>
531
- </div>
532
- <div class="message-bubble assistant-message bg-secondary-50 text-secondary-900 border border-secondary-200 flex items-center">
533
- <span>Mariam réfléchit</span>
534
- <div class="typing-indicator">
535
- <span class="typing-dot"></span>
536
- <span class="typing-dot"></span>
537
- <span class="typing-dot"></span>
538
- </div>
539
- </div>
540
- </div>
541
- </section>
542
- <!-- Conteneur du bas -->
543
- <div class="border-t border-gray-200 dark:border-gray-700">
544
- <!-- Zone d'erreur -->
545
- <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">
546
- <div class="flex">
547
- <div class="flex-shrink-0"><i class="fa-solid fa-circle-exclamation"></i></div>
548
- <div class="ml-3"><p class="text-sm font-medium" id="error-text">Le message d'erreur détaillé ira ici.</p></div>
549
- <button class="ml-auto" id="dismiss-error"><i class="fa-solid fa-xmark"></i></button>
550
- </div>
551
- </div>
552
- <!-- Zone de prévisualisation -->
553
- <div id="preview-area" class="px-4 py-2 bg-gray-50 dark:bg-gray-800/50 hidden">
554
- <div id="file-preview" class="hidden"></div> <!-- Container for multiple previews -->
555
- </div>
556
- <!-- Barre d'options -->
557
- <div class="flex items-center justify-between flex-wrap gap-y-2 px-4 py-2 bg-gray-100 dark:bg-gray-800/80 text-sm text-gray-600 dark:text-gray-300">
558
- <div class="flex items-center space-x-4 flex-wrap gap-y-2">
559
- <label class="flex items-center cursor-pointer tooltip">
560
- <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>
561
- <span class="toggle-switch">
562
- <input type="checkbox" id="web_search_toggle" name="web_search" value="true">
563
- <span class="toggle-slider"></span>
564
- </span>
565
- <span class="tooltip-text">Activer la recherche web</span>
566
- </label>
567
- <label class="flex items-center cursor-pointer tooltip">
568
- <span class="mr-2 text-xs sm:text-sm font-medium text-accent-700 dark:text-accent-300">
569
- <i class="fa-solid fa-brain mr-1.5"></i>
570
- <span class="hidden sm:inline">Avancé</span>
571
- <span id="advanced-cooldown-timer" class="text-xs ml-1 hidden"></span>
572
- </span>
573
- <span class="toggle-switch">
574
- <input type="checkbox" id="advanced_reasoning_toggle" name="advanced_reasoning" value="true">
575
- <span class="toggle-slider"></span>
576
- </span>
577
- <span class="tooltip-text">Raisonnement avancé (1 fois/min)</span>
578
- </label>
579
- </div>
580
- <!-- START: Modified HTML for file input and chip -->
581
- <div class="flex items-center space-x-2">
582
- <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">
583
- <i class="fa-solid fa-paperclip"></i>
584
- <span class="ml-1.5 hidden sm:inline">Fichiers</span>
585
- <input type="file" id="file_upload" name="file[]" class="hidden" accept=".txt,.pdf,.png,.jpg,.jpeg" multiple>
586
- <span class="tooltip-text">Joindre plusieurs fichiers (txt, pdf, image)</span>
587
- </label>
588
-
589
- <div id="file-chip" class="chip hidden">
590
- <i class="fa-solid fa-files chip-icon"></i> <!-- Changed icon to fa-files -->
591
- <span id="file-name" class="truncate max-w-[100px] sm:max-w-[120px]"></span>
592
- <i id="clear-file" class="fa-solid fa-xmark chip-close"></i>
593
- </div>
594
- </div>
595
- <!-- END: Modified HTML for file input and chip -->
596
- </div>
597
- <!-- Formulaire de chat -->
598
- <form id="chat-form" class="p-3 sm:p-4 bg-white dark:bg-gray-900">
599
- <div class="input-wrapper">
600
- <textarea
601
- id="prompt"
602
- name="prompt"
603
- class="chat-input chat-textarea w-full border focus:outline-none text-sm sm:text-base"
604
- placeholder="Posez votre question à Mariam..."
605
- autocomplete="off"
606
- rows="1"></textarea>
607
- <div class="send-button-wrapper">
608
- <button
609
- type="submit"
610
- id="send-button"
611
- 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"
612
- title="Envoyer le message">
613
- <i class="fa-solid fa-paper-plane text-sm"></i>
614
- </button>
615
- </div>
616
- </div>
617
- <div class="text-xs text-center mt-2 text-gray-400 dark:text-gray-500">
618
- 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>
619
- <span class="hidden sm:inline"> pour envoyer</span>
620
- <span class="sm:hidden"> pour une nouvelle ligne</span>
621
-
622
- <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>
623
- <span class="hidden sm:inline"> pour une nouvelle ligne</span>
624
- <span class="sm:hidden"> pour envoyer</span>
625
- </div>
626
- </form>
627
- </div>
628
- </main>
629
- <!-- Scripts -->
630
- <script>
631
- document.addEventListener('DOMContentLoaded', () => {
632
- // Sélection des éléments
633
- const chatForm = document.getElementById('chat-form');
634
- const promptInput = document.getElementById('prompt');
635
- const chatMessages = document.getElementById('chat-messages');
636
- const loadingIndicator = document.getElementById('loading-indicator');
637
- const historyLoadingIndicator = document.getElementById('history-loading');
638
- const errorMessageDiv = document.getElementById('error-message');
639
- const errorTextP = document.getElementById('error-text');
640
- const dismissErrorBtn = document.getElementById('dismiss-error');
641
- const webSearchToggle = document.getElementById('web_search_toggle');
642
- const fileUpload = document.getElementById('file_upload');
643
- const fileChip = document.getElementById('file-chip');
644
- const fileNameSpan = document.getElementById('file-name');
645
- const clearFileButton = document.getElementById('clear-file');
646
- const filePreview = document.getElementById('file-preview');
647
- const previewArea = document.getElementById('preview-area');
648
- const sendButton = document.getElementById('send-button');
649
- const clearForm = document.getElementById('clear-form');
650
- const advancedToggle = document.getElementById('advanced_reasoning_toggle');
651
- const advancedCooldownTimerSpan = document.getElementById('advanced-cooldown-timer');
652
- const themeToggleBtn = document.getElementById('theme-toggle');
653
- const API_CHAT_ENDPOINT = '/api/chat';
654
- const API_HISTORY_ENDPOINT = '/api/history';
655
- const CLEAR_ENDPOINT = '/clear';
656
- const COOLDOWN_DURATION = 60 * 1000;
657
- const MOBILE_BREAKPOINT = 640;
658
- let advancedToggleCooldownEndTime = 0;
659
- let isComposing = false;
660
- const filesList = []; // Pour stocker les fichiers sélectionnés
661
-
662
- // Gestion du thème
663
- function initializeTheme() {
664
- if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
665
- document.documentElement.classList.add('dark');
666
- } else {
667
- document.documentElement.classList.remove('dark');
668
- }
669
- }
670
- function toggleTheme() {
671
- if (document.documentElement.classList.contains('dark')) {
672
- document.documentElement.classList.remove('dark');
673
- localStorage.theme = 'light';
674
- } else {
675
- document.documentElement.classList.add('dark');
676
- localStorage.theme = 'dark';
677
- }
678
- }
679
- themeToggleBtn.addEventListener('click', toggleTheme);
680
- initializeTheme();
681
-
682
- // Ajuster la hauteur du textarea
683
- function adjustTextareaHeight(textarea) {
684
- textarea.style.height = 'auto';
685
- const style = window.getComputedStyle(textarea);
686
- const maxHeight = parseInt(style.maxHeight, 10);
687
- const newHeight = Math.min(maxHeight || 200, textarea.scrollHeight);
688
- textarea.style.height = newHeight + 'px';
689
- }
690
-
691
- // Défilement vers le bas
692
- function scrollToBottom(smooth = true) {
693
- setTimeout(() => {
694
- chatMessages.scrollTo({ top: chatMessages.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });
695
- }, 50);
696
- }
697
-
698
- // Affichage de l'indicateur de chargement
699
- function showLoading(show) {
700
- if (show) {
701
- loadingIndicator.classList.remove('hidden');
702
- chatMessages.appendChild(loadingIndicator);
703
- scrollToBottom();
704
- } else {
705
- loadingIndicator.classList.add('hidden');
706
- }
707
- sendButton.disabled = show;
708
- promptInput.disabled = show;
709
- fileUpload.disabled = show;
710
- if (show) {
711
- clearFileButton.style.pointerEvents = 'none';
712
- clearFileButton.style.opacity = '0.5';
713
- } else {
714
- clearFileButton.style.pointerEvents = 'auto';
715
- clearFileButton.style.opacity = '0.7';
716
- }
717
- }
718
-
719
- // Affichage des erreurs
720
- function displayError(message) {
721
- errorTextP.textContent = message || "Une erreur inconnue est survenue.";
722
- errorMessageDiv.classList.remove('hidden');
723
- }
724
- dismissErrorBtn.addEventListener('click', () => { errorMessageDiv.classList.add('hidden'); });
725
-
726
- // Ajout d'un message dans le chat
727
- function addMessageToChat(role, content, isHtml = false) {
728
- errorMessageDiv.classList.add('hidden');
729
- const messageWrapper = document.createElement('div');
730
- messageWrapper.classList.add('flex', 'w-full', role === 'user' ? 'justify-end' : 'justify-start');
731
-
732
- let messageContentHtml = '';
733
- if (isHtml) {
734
- messageContentHtml = content;
735
- } else {
736
- messageContentHtml = `<p class="text-sm sm:text-base whitespace-pre-wrap">${escapeHtml(content)}</p>`;
737
- }
738
-
739
- let bubbleHtml = '';
740
- if (role === 'user') {
741
- bubbleHtml = `
742
- <div class="message-bubble user-message">
743
- ${messageContentHtml}
744
- </div>
745
- `;
746
- } else {
747
- bubbleHtml = `
748
- <div class="flex items-start space-x-2 max-w-[85%]">
749
- <div class="w-8 h-8 rounded-full bg-primary-100 flex items-center justify-center flex-shrink-0 dark:bg-primary-900/50">
750
- <span class="text-lg">✨</span>
751
- </div>
752
- <div class="message-bubble assistant-message bg-secondary-50 text-secondary-900 border border-secondary-200 relative">
753
- <div class="prose prose-sm sm:prose-base max-w-none dark:prose-invert">
754
- ${messageContentHtml}
755
- </div>
756
- <button class="copy-btn text-xs bg-white/90 dark:bg-gray-800/90 hover:bg-gray-100 dark:hover:bg-gray-700 py-1 px-2 rounded text-gray-600 dark:text-gray-300 flex items-center">
757
- <i class="fa-regular fa-copy mr-1"></i> Copier
758
- </button>
759
- </div>
760
- </div>
761
- `;
762
- }
763
- messageWrapper.innerHTML = bubbleHtml;
764
-
765
- // Activation du bouton de copie
766
- const copyBtns = messageWrapper.querySelectorAll('.copy-btn');
767
- copyBtns.forEach(btn => {
768
- btn.addEventListener('click', function() {
769
- const textToCopy = this.closest('.message-bubble').querySelector('.prose').innerText || this.closest('.message-bubble').innerText;
770
- navigator.clipboard.writeText(textToCopy).then(() => {
771
- const originalText = this.innerHTML;
772
- this.innerHTML = '<i class="fa-solid fa-check mr-1"></i> Copié';
773
- setTimeout(() => { this.innerHTML = originalText; }, 2000);
774
- }).catch(err => console.error('Copy failed:', err));
775
- });
776
- });
777
-
778
- // Activation de la copie pour les blocs de code
779
- const codeBlocks = messageWrapper.querySelectorAll('pre');
780
- codeBlocks.forEach(pre => {
781
- const code = pre.querySelector('code');
782
- if (!code) return;
783
- if (pre.querySelector('.code-copy-btn')) return;
784
- const copyButton = document.createElement('button');
785
- copyButton.innerHTML = '<i class="fa-regular fa-copy"></i>';
786
- 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';
787
- copyButton.setAttribute('aria-label', 'Copier le code');
788
- const tooltipText = document.createElement('span');
789
- tooltipText.className = 'tooltip-text !text-xs';
790
- tooltipText.textContent = 'Copier le code';
791
- copyButton.appendChild(tooltipText);
792
- copyButton.addEventListener('click', () => {
793
- navigator.clipboard.writeText(code.innerText).then(() => {
794
- tooltipText.textContent = 'Copié!';
795
- copyButton.innerHTML = '<i class="fa-solid fa-check"></i>';
796
- setTimeout(() => {
797
- copyButton.innerHTML = '<i class="fa-regular fa-copy"></i>';
798
- copyButton.appendChild(tooltipText);
799
- tooltipText.textContent = 'Copier le code';
800
- }, 2000);
801
- }).catch(err => {
802
- tooltipText.textContent = 'Erreur copie';
803
- console.error('Failed to copy code: ', err);
804
- setTimeout(() => { tooltipText.textContent = 'Copier le code'; }, 2000);
805
- });
806
- });
807
- pre.appendChild(copyButton);
808
- });
809
-
810
- chatMessages.insertBefore(messageWrapper, loadingIndicator);
811
- scrollToBottom();
812
- }
813
- function escapeHtml(unsafe) {
814
- if (typeof unsafe !== 'string') return '';
815
- return unsafe
816
- .replace(/&/g, "&")
817
- .replace(/</g, "<")
818
- .replace(/>/g, ">")
819
- .replace(/"/g, """)
820
- .replace(/'/g, "'");
821
- }
822
-
823
- // Gestion du cooldown pour le raisonnement avancé
824
- function startAdvancedCooldownTimer() {
825
- advancedToggle.disabled = true;
826
- advancedToggleCooldownEndTime = Date.now() + COOLDOWN_DURATION;
827
- const intervalId = setInterval(() => {
828
- const now = Date.now();
829
- if (now >= advancedToggleCooldownEndTime) {
830
- clearInterval(intervalId);
831
- advancedCooldownTimerSpan.classList.add('hidden');
832
- advancedToggle.disabled = false;
833
- advancedToggleCooldownEndTime = 0;
834
- } else {
835
- const remainingSeconds = Math.ceil((advancedToggleCooldownEndTime - now) / 1000);
836
- advancedCooldownTimerSpan.textContent = `(${remainingSeconds}s)`;
837
- advancedCooldownTimerSpan.classList.remove('hidden');
838
- }
839
- }, 1000);
840
- const remainingSeconds = Math.ceil((advancedToggleCooldownEndTime - Date.now()) / 1000);
841
- advancedCooldownTimerSpan.textContent = `(${remainingSeconds}s)`;
842
- advancedCooldownTimerSpan.classList.remove('hidden');
843
- }
844
-
845
- // Chargement de l'historique du chat
846
- async function loadChatHistory() {
847
- historyLoadingIndicator.style.display = 'flex';
848
- try {
849
- const response = await fetch(API_HISTORY_ENDPOINT);
850
- if (!response.ok) {
851
- let errorMsg = `Erreur serveur (${response.status})`;
852
- try {
853
- const errData = await response.json();
854
- errorMsg = errData.error || errorMsg;
855
- } catch (e) {}
856
- throw new Error(errorMsg);
857
- }
858
- const data = await response.json();
859
- const messagesToRemove = chatMessages.querySelectorAll(':scope > *:not(#loading-indicator)');
860
- messagesToRemove.forEach(el => el.remove());
861
- loadingIndicator.classList.add('hidden');
862
- if (data.success && Array.isArray(data.history)) {
863
- if (data.history.length === 0) {
864
- addMessageToChat('assistant', "Bonjour ! Je suis Mariam, votre assistant IA. Comment puis-je vous aider aujourd'hui ?", true);
865
- } else {
866
- data.history.forEach(message => {
867
- const isAssistantHtml = message.role === 'assistant';
868
- addMessageToChat(message.role, message.text, isAssistantHtml);
869
- });
870
- }
871
- scrollToBottom(false);
872
- } else {
873
- throw new Error(data.error || "Format de réponse invalide pour l'historique.");
874
- }
875
- } catch (error) {
876
- displayError(`Impossible de charger l'historique: ${error.message}`);
877
- if (chatMessages.querySelectorAll(':scope > *:not(#loading-indicator):not(#history-loading)').length === 0) {
878
- addMessageToChat('assistant', "Bonjour ! Je suis Mariam. Je n'ai pas pu charger notre conversation précédente. Comment puis-je vous aider ?", true);
879
- }
880
- } finally {
881
- historyLoadingIndicator.remove();
882
- promptInput.focus();
883
- adjustTextareaHeight(promptInput);
884
- }
885
- }
886
-
887
- // START: Modified clearFileInput function
888
- function clearFileInput() {
889
- fileUpload.value = ''; // Clear the input element
890
- fileChip.classList.add('hidden');
891
- fileNameSpan.textContent = '';
892
- fileNameSpan.title = '';
893
- filePreview.innerHTML = ''; // Clear previews
894
- filePreview.classList.add('hidden');
895
- previewArea.classList.add('hidden');
896
- filesList.length = 0; // Vider la liste des fichiers
897
- }
898
- // END: Modified clearFileInput function
899
-
900
- // START: Replaced fileUpload event listener for multiple files
901
- fileUpload.addEventListener('change', () => {
902
- if (fileUpload.files.length > 0) {
903
- // Vider les prévisualisations précédentes et la liste
904
- filePreview.innerHTML = '';
905
- fileChip.classList.add('hidden'); // Hide chip initially
906
- filesList.length = 0;
907
-
908
- // Mettre à jour la liste des fichiers
909
- for (let i = 0; i < fileUpload.files.length; i++) {
910
- filesList.push(fileUpload.files[i]);
911
- }
912
-
913
- // Afficher le nombre total de fichiers dans la puce
914
- fileNameSpan.textContent = `${filesList.length} fichier${filesList.length > 1 ? 's' : ''}`;
915
- fileNameSpan.title = filesList.map(f => f.name).join(', ');
916
- fileChip.classList.remove('hidden');
917
-
918
- // Créer des prévisualisations pour chaque fichier (jusqu'à un maximum raisonnable)
919
- const maxPreviews = 5;
920
- const filesToPreview = filesList.slice(0, maxPreviews);
921
-
922
- filesToPreview.forEach(file => {
923
- const previewItem = document.createElement('div');
924
- // Added dark mode classes and adjusted structure
925
- previewItem.className = 'file-preview-item mb-2 p-2 border rounded dark:border-gray-600 bg-white dark:bg-gray-700';
926
-
927
- if (file.type.startsWith('image/')) {
928
- const reader = new FileReader();
929
- reader.onload = (e) => {
930
- previewItem.innerHTML = `
931
- <div class="flex items-center w-full">
932
- <div class="w-12 h-12 flex-shrink-0 mr-2">
933
- <img src="${e.target.result}" alt="Aperçu" class="h-full w-full object-cover rounded">
934
- </div>
935
- <div class="overflow-hidden flex-grow">
936
- <p class="text-xs font-medium truncate text-gray-800 dark:text-gray-200">${escapeHtml(file.name)}</p>
937
- <p class="text-xs text-gray-500 dark:text-gray-400">${formatFileSize(file.size)}</p>
938
- </div>
939
- </div>`;
940
- filePreview.appendChild(previewItem);
941
- };
942
- reader.onerror = () => {
943
- previewItem.innerHTML = `<p class="text-red-500 dark:text-red-400 text-xs p-2">Erreur lecture image: ${escapeHtml(file.name)}</p>`;
944
- filePreview.appendChild(previewItem);
945
- };
946
- reader.readAsDataURL(file);
947
- } else {
948
- previewItem.innerHTML = `
949
- <div class="flex items-center w-full">
950
- <div class="w-10 h-10 flex-shrink-0 mr-2 bg-gray-100 dark:bg-gray-800 rounded flex items-center justify-center">
951
- <i class="fa-solid ${getFileIcon(file.type)} text-gray-500 dark:text-gray-400 text-lg"></i>
952
- </div>
953
- <div class="overflow-hidden flex-grow">
954
- <p class="text-xs font-medium truncate text-gray-800 dark:text-gray-200">${escapeHtml(file.name)}</p>
955
- <p class="text-xs text-gray-500 dark:text-gray-400">${formatFileSize(file.size)}</p>
956
- </div>
957
- </div>`;
958
- filePreview.appendChild(previewItem);
959
- }
960
- });
961
-
962
- // Afficher un message si d'autres fichiers ne sont pas prévisualisés
963
- if (filesList.length > maxPreviews) {
964
- const moreInfo = document.createElement('p');
965
- moreInfo.className = 'text-xs text-gray-500 dark:text-gray-400 text-center mt-1 px-2';
966
- moreInfo.textContent = `+ ${filesList.length - maxPreviews} autre${filesList.length - maxPreviews > 1 ? 's' : ''} fichier${filesList.length - maxPreviews > 1 ? 's' : ''}`;
967
- filePreview.appendChild(moreInfo);
968
- }
969
-
970
- filePreview.classList.remove('hidden');
971
- previewArea.classList.remove('hidden');
972
- } else {
973
- clearFileInput();
974
- }
975
- });
976
- // END: Replaced fileUpload event listener
977
-
978
- function getFileIcon(fileType) {
979
- if (!fileType) return 'fa-file';
980
- if (fileType.includes('pdf')) return 'fa-file-pdf';
981
- if (fileType.includes('text')) return 'fa-file-lines';
982
- return 'fa-file';
983
- }
984
- function formatFileSize(bytes) {
985
- if (bytes === 0) return '0 octets';
986
- const k = 1024;
987
- const sizes = ['octets', 'Ko', 'Mo', 'Go', 'To'];
988
- const i = Math.floor(Math.log(bytes) / Math.log(k));
989
- return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
990
- }
991
- clearFileButton.addEventListener('click', clearFileInput);
992
-
993
- // Événements pour le textarea
994
- promptInput.addEventListener('input', () => {
995
- adjustTextareaHeight(promptInput);
996
- });
997
- promptInput.addEventListener('keydown', (e) => {
998
- if (isComposing) return;
999
- const isMobile = window.innerWidth < MOBILE_BREAKPOINT;
1000
- if (e.key === 'Enter') {
1001
- if (isMobile && !e.shiftKey) {
1002
- setTimeout(() => adjustTextareaHeight(promptInput), 0);
1003
- } else if (!isMobile && !e.shiftKey) {
1004
- e.preventDefault();
1005
- // Modified condition to check filesList
1006
- if (!sendButton.disabled && (promptInput.value.trim() || filesList.length > 0)) {
1007
- chatForm.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
1008
- }
1009
- } else if (e.shiftKey) {
1010
- setTimeout(() => adjustTextareaHeight(promptInput), 0);
1011
- if (isMobile) {
1012
- e.preventDefault();
1013
- // Modified condition to check filesList
1014
- if (!sendButton.disabled && (promptInput.value.trim() || filesList.length > 0)) {
1015
- chatForm.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
1016
- }
1017
- }
1018
- }
1019
- }
1020
- });
1021
- promptInput.addEventListener('compositionstart', () => { isComposing = true; });
1022
- promptInput.addEventListener('compositionend', () => {
1023
- isComposing = false;
1024
- setTimeout(() => adjustTextareaHeight(promptInput), 0);
1025
- });
1026
- adjustTextareaHeight(promptInput);
1027
-
1028
- // START: Modified chatForm submit listener
1029
- chatForm.addEventListener('submit', async (e) => {
1030
- e.preventDefault();
1031
- const prompt = promptInput.value.trim();
1032
- const useWebSearch = webSearchToggle.checked;
1033
- const useAdvanced = advancedToggle.checked;
1034
-
1035
- if (sendButton.disabled) return;
1036
- // Check against filesList instead of fileUpload.files
1037
- if (!prompt && filesList.length === 0) {
1038
- promptInput.focus();
1039
- return;
1040
- }
1041
-
1042
- errorMessageDiv.classList.add('hidden');
1043
-
1044
- // Vérification du cooldown pour le raisonnement avancé
1045
- if (useAdvanced) {
1046
- const now = Date.now();
1047
- if (advancedToggleCooldownEndTime > 0 && now < advancedToggleCooldownEndTime) {
1048
- const remainingSeconds = Math.ceil((advancedToggleCooldownEndTime - now) / 1000);
1049
- displayError(`Le raisonnement avancé est disponible dans ${remainingSeconds} seconde(s).`);
1050
- return;
1051
- }
1052
- }
1053
-
1054
- // Création du message utilisateur avec potentiellement plusieurs fichiers
1055
- let userMessageText = prompt;
1056
- if (filesList.length > 0) {
1057
- const fileNames = filesList.map(f => f.name).join(', ');
1058
- const filesText = filesList.length === 1
1059
- ? `[Fichier joint: ${escapeHtml(fileNames)}]`
1060
- : `[${filesList.length} fichiers joints: ${escapeHtml(fileNames)}]`;
1061
-
1062
- userMessageText = prompt ? `${prompt}\n${filesText}` : filesText;
1063
- }
1064
-
1065
- addMessageToChat('user', userMessageText);
1066
-
1067
- // Préparation des données à envoyer
1068
- const formData = new FormData();
1069
- formData.append('prompt', prompt);
1070
- formData.append('web_search', useWebSearch);
1071
- formData.append('advanced_reasoning', useAdvanced);
1072
-
1073
- // Ajout de tous les fichiers au formData avec la clé 'file[]'
1074
- filesList.forEach(file => {
1075
- formData.append('file[]', file);
1076
- });
1077
-
1078
- // Réinitialisation des champs et gestion des paramètres
1079
- promptInput.value = '';
1080
- adjustTextareaHeight(promptInput);
1081
- clearFileInput(); // Clears filesList as well now
1082
-
1083
- if (useAdvanced) {
1084
- startAdvancedCooldownTimer();
1085
- advancedToggle.checked = false;
1086
- }
1087
- webSearchToggle.checked = false;
1088
- showLoading(true);
1089
-
1090
- // Envoi de la requête et gestion de la réponse (aucun changement nécessaire ici)
1091
- try {
1092
- const response = await fetch(API_CHAT_ENDPOINT, { method: 'POST', body: formData });
1093
- const data = await response.json();
1094
- if (!response.ok) {
1095
- throw new Error(data.error || `Erreur serveur (${response.status}): ${response.statusText}`);
1096
- }
1097
- if (data.success && data.message) {
1098
- addMessageToChat('assistant', data.message, true);
1099
- } else if (data.error) {
1100
- throw new Error(data.error);
1101
- }
1102
- else {
1103
- throw new Error("Réponse invalide ou vide du serveur.");
1104
- }
1105
- } catch (error) {
1106
- console.error("Chat Error:", error);
1107
- addMessageToChat('assistant', `<p class="text-red-600 dark:text-red-400">Désolé, une erreur est survenue :<br>${escapeHtml(error.message)}</p>`, true);
1108
- } finally {
1109
- showLoading(false);
1110
- promptInput.focus();
1111
- }
1112
- });
1113
- // END: Modified chatForm submit listener
1114
-
1115
- // Effacement de la conversation
1116
- clearForm.addEventListener('submit', async (e) => {
1117
- e.preventDefault();
1118
- const confirmDialog = document.createElement('div');
1119
- confirmDialog.className = 'fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4';
1120
- confirmDialog.innerHTML = `
1121
- <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]">
1122
- <h3 class="text-lg font-semibold mb-3 text-gray-900 dark:text-gray-100">Confirmer l'effacement</h3>
1123
- <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>
1124
- <div class="flex justify-end space-x-3">
1125
- <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">
1126
- Annuler
1127
- </button>
1128
- <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">
1129
- Effacer
1130
- </button>
1131
- </div>
1132
- </div>
1133
- `;
1134
- const closeModal = () => {
1135
- if (document.body.contains(confirmDialog)) {
1136
- document.body.removeChild(confirmDialog);
1137
- document.body.style.overflow = '';
1138
- }
1139
- };
1140
- confirmDialog.querySelector('#cancel-clear').addEventListener('click', closeModal);
1141
- confirmDialog.querySelector('#confirm-clear').addEventListener('click', async () => {
1142
- closeModal();
1143
- const clearButton = e.target.querySelector('button[type="submit"]');
1144
- const originalButtonContent = clearButton.innerHTML;
1145
- clearButton.disabled = true;
1146
- clearButton.innerHTML = '<i class="fa-solid fa-spinner fa-spin mr-1.5"></i><span class="hidden sm:inline">Effacement...</span>';
1147
- try {
1148
- const response = await fetch(CLEAR_ENDPOINT, {
1149
- method: 'POST',
1150
- headers: {
1151
- 'X-Requested-With': 'XMLHttpRequest'
1152
- }
1153
- });
1154
- const data = await response.json();
1155
- if (response.ok && data.success) {
1156
- const messagesToRemove = chatMessages.querySelectorAll(':scope > *:not(#loading-indicator)');
1157
- messagesToRemove.forEach(el => el.remove());
1158
- addMessageToChat('assistant', "Conversation effacée. Comment puis-je vous aider maintenant ?", true);
1159
- errorMessageDiv.classList.add('hidden');
1160
- clearFileInput(); // Also clear any lingering file selections
1161
- } else {
1162
- throw new Error(data.error || "Impossible d'effacer la conversation.");
1163
- }
1164
- } catch (error) {
1165
- console.error("Clear Error:", error);
1166
- displayError(`Erreur lors de l'effacement: ${error.message}`);
1167
- } finally {
1168
- clearButton.innerHTML = originalButtonContent;
1169
- clearButton.disabled = false;
1170
- promptInput.focus();
1171
- }
1172
- });
1173
- document.body.appendChild(confirmDialog);
1174
- document.body.style.overflow = 'hidden';
1175
- confirmDialog.querySelector('#cancel-clear').focus();
1176
- });
1177
-
1178
- // Initialisation
1179
- loadChatHistory();
1180
-
1181
- // Observer pour les tableaux Markdown
1182
- const observeMarkdownTables = () => {
1183
- const observer = new MutationObserver(mutations => {
1184
- mutations.forEach(mutation => {
1185
- if (mutation.addedNodes.length) {
1186
- mutation.addedNodes.forEach(node => {
1187
- if (node.nodeType === 1) {
1188
- const tables = node.matches('.prose table') ? [node] : node.querySelectorAll('.prose table');
1189
- tables.forEach(table => {
1190
- if (!table.closest('.table-wrapper')) {
1191
- const wrapper = document.createElement('div');
1192
- wrapper.className = 'table-wrapper';
1193
- table.parentNode.insertBefore(wrapper, table);
1194
- wrapper.appendChild(table);
1195
- }
1196
- });
1197
- }
1198
- });
1199
- }
1200
- });
1201
- });
1202
- observer.observe(chatMessages, { childList: true, subtree: true });
1203
- };
1204
- observeMarkdownTables();
1205
-
1206
- // Gestion du changement de thème selon le système
1207
- const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
1208
- const handleSchemeChange = (e) => {
1209
- if (!localStorage.getItem('theme')) {
1210
- if (e.matches) {
1211
- document.documentElement.classList.add('dark');
1212
- } else {
1213
- document.documentElement.classList.remove('dark');
1214
- }
1215
- }
1216
- };
1217
- prefersDarkScheme.addEventListener('change', handleSchemeChange);
1218
- });
1219
- </script>
1220
- </body>
1221
- </html>