Update templates/index.html
Browse files- templates/index.html +568 -385
templates/index.html
CHANGED
|
@@ -3,442 +3,625 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 7 |
-
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
-
<script>
|
| 9 |
-
tailwind.config = {
|
| 10 |
-
darkMode: 'class',
|
| 11 |
-
theme: {
|
| 12 |
-
extend: {
|
| 13 |
-
colors: {
|
| 14 |
-
dark: {
|
| 15 |
-
50: '#f8fafc',
|
| 16 |
-
100: '#f1f5f9',
|
| 17 |
-
200: '#e2e8f0',
|
| 18 |
-
300: '#cbd5e1',
|
| 19 |
-
400: '#94a3b8',
|
| 20 |
-
500: '#64748b',
|
| 21 |
-
600: '#475569',
|
| 22 |
-
700: '#334155',
|
| 23 |
-
800: '#1e293b',
|
| 24 |
-
900: '#0f172a',
|
| 25 |
-
}
|
| 26 |
-
}
|
| 27 |
-
}
|
| 28 |
-
}
|
| 29 |
-
}
|
| 30 |
-
</script>
|
| 31 |
<style>
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
}
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
display: inline-block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
}
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
}
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
}
|
| 66 |
</style>
|
| 67 |
</head>
|
| 68 |
-
<body
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
<
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
</div>
|
| 81 |
-
|
| 82 |
-
<div class="flex items-center space-x-4">
|
| 83 |
-
<button id="refreshBtn" class="px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded-lg transition-colors duration-200 flex items-center space-x-2">
|
| 84 |
-
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 85 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
|
| 86 |
-
</svg>
|
| 87 |
-
<span>Actualiser</span>
|
| 88 |
-
</button>
|
| 89 |
-
</div>
|
| 90 |
-
</div>
|
| 91 |
-
</div>
|
| 92 |
-
</header>
|
| 93 |
-
|
| 94 |
-
<!-- Stats Bar -->
|
| 95 |
-
<div class="bg-slate-800/30 border-b border-slate-700/30">
|
| 96 |
-
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
| 97 |
-
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
|
| 98 |
-
<div class="bg-gradient-to-r from-blue-500/20 to-blue-600/20 rounded-lg p-4 border border-blue-500/30">
|
| 99 |
-
<div class="flex items-center">
|
| 100 |
-
<div class="p-2 bg-blue-500/30 rounded-lg">
|
| 101 |
-
<svg class="w-6 h-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 102 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/>
|
| 103 |
-
</svg>
|
| 104 |
-
</div>
|
| 105 |
-
<div class="ml-4">
|
| 106 |
-
<p class="text-sm text-slate-400">Conversations</p>
|
| 107 |
-
<p class="text-2xl font-bold text-white" id="totalConversations">0</p>
|
| 108 |
-
</div>
|
| 109 |
-
</div>
|
| 110 |
-
</div>
|
| 111 |
-
|
| 112 |
-
<div class="bg-gradient-to-r from-green-500/20 to-green-600/20 rounded-lg p-4 border border-green-500/30">
|
| 113 |
-
<div class="flex items-center">
|
| 114 |
-
<div class="p-2 bg-green-500/30 rounded-lg">
|
| 115 |
-
<svg class="w-6 h-6 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 116 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8h2a2 2 0 012 2v6a2 2 0 01-2 2h-2v4l-4-4H9a1.994 1.994 0 01-1.414-.586m0 0L11 14h4a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2v4l.586-.586z"/>
|
| 117 |
-
</svg>
|
| 118 |
-
</div>
|
| 119 |
-
<div class="ml-4">
|
| 120 |
-
<p class="text-sm text-slate-400">Messages</p>
|
| 121 |
-
<p class="text-2xl font-bold text-white" id="totalMessages">0</p>
|
| 122 |
-
</div>
|
| 123 |
-
</div>
|
| 124 |
-
</div>
|
| 125 |
-
|
| 126 |
-
<div class="bg-gradient-to-r from-purple-500/20 to-purple-600/20 rounded-lg p-4 border border-purple-500/30">
|
| 127 |
-
<div class="flex items-center">
|
| 128 |
-
<div class="p-2 bg-purple-500/30 rounded-lg">
|
| 129 |
-
<svg class="w-6 h-6 text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 130 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
| 131 |
-
</svg>
|
| 132 |
-
</div>
|
| 133 |
-
<div class="ml-4">
|
| 134 |
-
<p class="text-sm text-slate-400">Actives</p>
|
| 135 |
-
<p class="text-2xl font-bold text-white" id="activeConversations">0</p>
|
| 136 |
-
</div>
|
| 137 |
-
</div>
|
| 138 |
-
</div>
|
| 139 |
-
|
| 140 |
-
<div class="bg-gradient-to-r from-orange-500/20 to-orange-600/20 rounded-lg p-4 border border-orange-500/30">
|
| 141 |
-
<div class="flex items-center">
|
| 142 |
-
<div class="p-2 bg-orange-500/30 rounded-lg">
|
| 143 |
-
<svg class="w-6 h-6 text-orange-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 144 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v4a2 2 0 01-2 2h-2a2 2 0 00-2-2z"/>
|
| 145 |
-
</svg>
|
| 146 |
-
</div>
|
| 147 |
-
<div class="ml-4">
|
| 148 |
-
<p class="text-sm text-slate-400">Avec fichiers</p>
|
| 149 |
-
<p class="text-2xl font-bold text-white" id="fileConversations">0</p>
|
| 150 |
-
</div>
|
| 151 |
-
</div>
|
| 152 |
</div>
|
|
|
|
|
|
|
|
|
|
| 153 |
</div>
|
| 154 |
</div>
|
| 155 |
-
</div>
|
| 156 |
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
<div class="mb-6">
|
| 161 |
-
<div class="flex flex-col sm:flex-row gap-4 items-center justify-between">
|
| 162 |
-
<div class="relative flex-1 max-w-md">
|
| 163 |
-
<svg class="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-slate-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 164 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
|
| 165 |
-
</svg>
|
| 166 |
-
<input
|
| 167 |
-
type="text"
|
| 168 |
-
id="searchInput"
|
| 169 |
-
placeholder="Rechercher dans les conversations..."
|
| 170 |
-
class="w-full pl-10 pr-4 py-2 bg-slate-800/50 border border-slate-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-white placeholder-slate-400"
|
| 171 |
-
>
|
| 172 |
-
</div>
|
| 173 |
|
| 174 |
-
|
| 175 |
-
<select id="sortSelect" class="px-4 py-2 bg-slate-800/50 border border-slate-600 rounded-lg text-white focus:ring-2 focus:ring-blue-500">
|
| 176 |
-
<option value="newest">Plus récentes</option>
|
| 177 |
-
<option value="oldest">Plus anciennes</option>
|
| 178 |
-
<option value="messages">Plus de messages</option>
|
| 179 |
-
</select>
|
| 180 |
-
</div>
|
| 181 |
-
</div>
|
| 182 |
-
</div>
|
| 183 |
-
|
| 184 |
-
<!-- Loading State -->
|
| 185 |
-
<div id="loadingState" class="text-center py-12">
|
| 186 |
-
<div class="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500"></div>
|
| 187 |
-
<p class="mt-4 text-slate-400">Chargement des conversations<span class="loading-dots"></span></p>
|
| 188 |
</div>
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
<div class="
|
| 193 |
-
<
|
| 194 |
-
|
| 195 |
-
|
| 196 |
</div>
|
| 197 |
-
<h3 class="text-lg font-medium text-white mb-2">Aucune conversation</h3>
|
| 198 |
-
<p class="text-slate-400">Aucune conversation n'a été trouvée.</p>
|
| 199 |
</div>
|
| 200 |
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
</div>
|
| 221 |
</div>
|
| 222 |
</div>
|
| 223 |
</div>
|
| 224 |
-
</
|
| 225 |
|
|
|
|
| 226 |
<script>
|
| 227 |
-
let
|
| 228 |
-
let
|
| 229 |
-
|
| 230 |
-
// Initialisation
|
| 231 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 232 |
-
loadConversations();
|
| 233 |
-
setupEventListeners();
|
| 234 |
-
});
|
| 235 |
|
| 236 |
-
function
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
document.getElementById('sortSelect').addEventListener('change', sortConversations);
|
| 240 |
-
document.getElementById('closeModal').addEventListener('click', closeModal);
|
| 241 |
-
|
| 242 |
-
// Fermer modal avec Escape
|
| 243 |
-
document.addEventListener('keydown', function(e) {
|
| 244 |
-
if (e.key === 'Escape') closeModal();
|
| 245 |
-
});
|
| 246 |
}
|
| 247 |
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
const response = await fetch('/admin/conversations');
|
| 253 |
-
const data = await response.json();
|
| 254 |
-
|
| 255 |
-
conversations = data.conversations || [];
|
| 256 |
-
filteredConversations = [...conversations];
|
| 257 |
-
|
| 258 |
-
updateStats(data.stats || {});
|
| 259 |
-
displayConversations();
|
| 260 |
-
|
| 261 |
-
} catch (error) {
|
| 262 |
-
console.error('Erreur lors du chargement:', error);
|
| 263 |
-
showError('Erreur lors du chargement des conversations');
|
| 264 |
}
|
| 265 |
}
|
| 266 |
|
| 267 |
-
function
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
document.getElementById('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
}
|
| 273 |
|
| 274 |
-
function
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
-
|
|
|
|
| 280 |
|
| 281 |
-
if (
|
| 282 |
-
|
| 283 |
-
empty.classList.remove('hidden');
|
| 284 |
-
return;
|
| 285 |
}
|
| 286 |
|
| 287 |
-
|
| 288 |
-
grid.classList.remove('hidden');
|
| 289 |
|
| 290 |
-
|
| 291 |
-
|
| 292 |
|
| 293 |
-
|
| 294 |
-
const
|
| 295 |
-
const
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
}
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
}
|
| 353 |
|
| 354 |
-
function
|
| 355 |
-
const
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
<div class="message-bubble mb-4 ${msg.role === 'user' ? 'ml-8' : 'mr-8'}">
|
| 363 |
-
<div class="flex items-start space-x-3">
|
| 364 |
-
<div class="flex-shrink-0">
|
| 365 |
-
<div class="w-8 h-8 rounded-full flex items-center justify-center ${
|
| 366 |
-
msg.role === 'user'
|
| 367 |
-
? 'bg-blue-500/20 text-blue-400'
|
| 368 |
-
: 'bg-green-500/20 text-green-400'
|
| 369 |
-
}">
|
| 370 |
-
${msg.role === 'user' ? '👤' : '🤖'}
|
| 371 |
-
</div>
|
| 372 |
-
</div>
|
| 373 |
-
<div class="flex-1">
|
| 374 |
-
<div class="flex items-center space-x-2 mb-1">
|
| 375 |
-
<span class="text-sm font-medium ${msg.role === 'user' ? 'text-blue-400' : 'text-green-400'}">
|
| 376 |
-
${msg.role === 'user' ? 'Utilisateur' : 'Assistant'}
|
| 377 |
-
</span>
|
| 378 |
-
${msg.timestamp ? `
|
| 379 |
-
<span class="text-xs text-slate-500">
|
| 380 |
-
${new Date(msg.timestamp).toLocaleString('fr-FR')}
|
| 381 |
-
</span>
|
| 382 |
-
` : ''}
|
| 383 |
-
${msg.hasFile ? '<span class="text-xs bg-orange-500/20 text-orange-400 px-2 py-1 rounded">📎 Fichier</span>' : ''}
|
| 384 |
-
</div>
|
| 385 |
-
<div class="bg-slate-700/50 rounded-lg p-3 text-sm text-slate-200">
|
| 386 |
-
${msg.content || 'Message vide'}
|
| 387 |
-
</div>
|
| 388 |
-
</div>
|
| 389 |
-
</div>
|
| 390 |
-
</div>
|
| 391 |
-
`).join('');
|
| 392 |
-
|
| 393 |
-
document.getElementById('conversationModal').classList.remove('hidden');
|
| 394 |
}
|
| 395 |
|
| 396 |
-
function
|
| 397 |
-
document.getElementById('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
}
|
| 399 |
-
|
| 400 |
-
function
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
);
|
| 408 |
-
});
|
| 409 |
-
|
| 410 |
-
displayConversations();
|
| 411 |
}
|
| 412 |
|
| 413 |
-
function
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
filteredConversations.sort((a, b) => {
|
| 417 |
-
switch(sortBy) {
|
| 418 |
-
case 'newest':
|
| 419 |
-
return new Date(b.lastActivity || 0) - new Date(a.lastActivity || 0);
|
| 420 |
-
case 'oldest':
|
| 421 |
-
return new Date(a.lastActivity || 0) - new Date(b.lastActivity || 0);
|
| 422 |
-
case 'messages':
|
| 423 |
-
return b.messages.length - a.messages.length;
|
| 424 |
-
default:
|
| 425 |
-
return 0;
|
| 426 |
-
}
|
| 427 |
-
});
|
| 428 |
-
|
| 429 |
-
displayConversations();
|
| 430 |
}
|
| 431 |
|
| 432 |
-
function
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
}
|
| 437 |
|
|
|
|
| 438 |
function showError(message) {
|
| 439 |
-
|
| 440 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
</script>
|
| 443 |
</body>
|
| 444 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title> AI Assistant - Flat Black & White</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
<style>
|
| 8 |
+
/* --- RESET ET CONFIGURATION GLOBALE --- */
|
| 9 |
+
* {
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
box-sizing: border-box;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
html {
|
| 16 |
+
scroll-behavior: smooth;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
body {
|
| 20 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
| 21 |
+
background-color: #121212; /* Fond sombre principal */
|
| 22 |
+
color: #f1f1f1; /* Couleur de texte par défaut */
|
| 23 |
+
min-height: 100vh;
|
| 24 |
+
display: flex;
|
| 25 |
+
justify-content: center;
|
| 26 |
+
align-items: center;
|
| 27 |
+
padding: 0; /* Pas de padding sur le body pour le mobile */
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/* --- CONTENEUR PRINCIPAL DU CHAT --- */
|
| 31 |
+
.chat-container {
|
| 32 |
+
width: 100%;
|
| 33 |
+
max-width: 800px;
|
| 34 |
+
height: 100vh; /* Prend toute la hauteur par défaut (mobile-first) */
|
| 35 |
+
background-color: #1e1e1e; /* Fond du conteneur légèrement plus clair */
|
| 36 |
+
display: flex;
|
| 37 |
+
flex-direction: column;
|
| 38 |
+
overflow: hidden;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/* --- EN-TÊTE --- */
|
| 42 |
+
.header {
|
| 43 |
+
background-color: #1e1e1e;
|
| 44 |
+
color: #ffffff;
|
| 45 |
+
padding: 20px;
|
| 46 |
+
text-align: center;
|
| 47 |
+
border-bottom: 1px solid #333; /* Séparateur plat */
|
| 48 |
+
flex-shrink: 0;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.header h1 {
|
| 52 |
+
font-size: 22px;
|
| 53 |
+
font-weight: 600;
|
| 54 |
+
margin-bottom: 5px;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.header p {
|
| 58 |
+
font-size: 14px;
|
| 59 |
+
color: #aaa;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.controls {
|
| 63 |
+
display: flex;
|
| 64 |
+
justify-content: center;
|
| 65 |
+
align-items: center;
|
| 66 |
+
gap: 20px;
|
| 67 |
+
margin-top: 15px;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.thinking-toggle {
|
| 71 |
+
display: flex;
|
| 72 |
+
align-items: center;
|
| 73 |
+
gap: 10px;
|
| 74 |
+
font-size: 14px;
|
| 75 |
+
color: #ccc;
|
| 76 |
}
|
| 77 |
+
|
| 78 |
+
.switch {
|
| 79 |
+
position: relative;
|
| 80 |
display: inline-block;
|
| 81 |
+
width: 50px;
|
| 82 |
+
height: 28px;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.switch input { opacity: 0; width: 0; height: 0; }
|
| 86 |
+
|
| 87 |
+
.slider {
|
| 88 |
+
position: absolute;
|
| 89 |
+
cursor: pointer;
|
| 90 |
+
top: 0;
|
| 91 |
+
left: 0;
|
| 92 |
+
right: 0;
|
| 93 |
+
bottom: 0;
|
| 94 |
+
background-color: #444;
|
| 95 |
+
transition: .2s;
|
| 96 |
+
border-radius: 28px;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.slider:before {
|
| 100 |
+
position: absolute;
|
| 101 |
+
content: "";
|
| 102 |
+
height: 20px;
|
| 103 |
+
width: 20px;
|
| 104 |
+
left: 4px;
|
| 105 |
+
bottom: 4px;
|
| 106 |
+
background-color: #f1f1f1;
|
| 107 |
+
transition: .2s;
|
| 108 |
+
border-radius: 50%;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
input:checked + .slider { background-color: #777; }
|
| 112 |
+
input:checked + .slider:before { transform: translateX(22px); }
|
| 113 |
+
|
| 114 |
+
.btn-reset {
|
| 115 |
+
background: transparent;
|
| 116 |
+
border: 1px solid #555;
|
| 117 |
+
color: #ccc;
|
| 118 |
+
padding: 8px 16px;
|
| 119 |
+
border-radius: 20px;
|
| 120 |
+
cursor: pointer;
|
| 121 |
+
font-size: 14px;
|
| 122 |
+
transition: background-color 0.2s ease;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
.btn-reset:hover { background-color: #333; }
|
| 126 |
+
|
| 127 |
+
/* --- ZONE DES MESSAGES --- */
|
| 128 |
+
.messages {
|
| 129 |
+
flex: 1;
|
| 130 |
+
overflow-y: auto;
|
| 131 |
+
padding: 20px 15px;
|
| 132 |
+
display: flex;
|
| 133 |
+
flex-direction: column;
|
| 134 |
+
gap: 15px;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.message {
|
| 138 |
+
max-width: 85%;
|
| 139 |
+
padding: 12px 18px;
|
| 140 |
+
border-radius: 18px;
|
| 141 |
+
font-size: 16px;
|
| 142 |
+
line-height: 1.5;
|
| 143 |
+
animation: fadeIn 0.3s ease;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.message.user {
|
| 147 |
+
background-color: #3a3a3a; /* Couleur message utilisateur */
|
| 148 |
+
color: #f1f1f1;
|
| 149 |
+
align-self: flex-end;
|
| 150 |
+
border-bottom-right-radius: 4px;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
.message.assistant {
|
| 154 |
+
background-color: #2c2c2c; /* Couleur message assistant */
|
| 155 |
+
color: #e0e0e0;
|
| 156 |
+
align-self: flex-start;
|
| 157 |
+
border-bottom-left-radius: 4px;
|
| 158 |
}
|
| 159 |
+
|
| 160 |
+
.message ul { margin-top: 10px; padding-left: 20px; }
|
| 161 |
+
|
| 162 |
+
.thoughts {
|
| 163 |
+
background: #252525;
|
| 164 |
+
color: #aaa;
|
| 165 |
+
border-left: 3px solid #666; /* Indicateur visuel plat */
|
| 166 |
+
margin: 10px 0;
|
| 167 |
+
padding: 15px;
|
| 168 |
+
border-radius: 8px;
|
| 169 |
+
font-style: italic;
|
| 170 |
+
font-size: 14px;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
.thoughts-header {
|
| 174 |
+
font-weight: 600;
|
| 175 |
+
margin-bottom: 8px;
|
| 176 |
+
display: flex;
|
| 177 |
+
align-items: center;
|
| 178 |
+
gap: 8px;
|
| 179 |
+
color: #ccc;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
/* --- ZONE DE SAISIE --- */
|
| 183 |
+
.input-container {
|
| 184 |
+
padding: 15px;
|
| 185 |
+
background-color: #1e1e1e;
|
| 186 |
+
border-top: 1px solid #333;
|
| 187 |
+
flex-shrink: 0;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.input-row { display: flex; gap: 10px; align-items: flex-end; }
|
| 191 |
+
.input-wrapper { flex: 1; position: relative; }
|
| 192 |
+
|
| 193 |
+
.message-input {
|
| 194 |
+
width: 100%;
|
| 195 |
+
min-height: 48px;
|
| 196 |
+
padding: 12px 55px 12px 20px;
|
| 197 |
+
border: 1px solid #444;
|
| 198 |
+
border-radius: 24px;
|
| 199 |
+
font-size: 16px;
|
| 200 |
+
resize: none;
|
| 201 |
+
outline: none;
|
| 202 |
+
transition: border-color 0.2s ease;
|
| 203 |
+
font-family: inherit;
|
| 204 |
+
background-color: #2c2c2c;
|
| 205 |
+
color: #f1f1f1;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.message-input::placeholder { color: #777; }
|
| 209 |
+
.message-input:focus { border-color: #888; }
|
| 210 |
+
|
| 211 |
+
.send-button {
|
| 212 |
+
position: absolute;
|
| 213 |
+
right: 4px;
|
| 214 |
+
top: 50%;
|
| 215 |
+
transform: translateY(-50%);
|
| 216 |
+
background-color: #333;
|
| 217 |
+
border: none;
|
| 218 |
+
border-radius: 50%;
|
| 219 |
+
width: 40px;
|
| 220 |
+
height: 40px;
|
| 221 |
+
color: #f1f1f1;
|
| 222 |
+
cursor: pointer;
|
| 223 |
+
transition: background-color 0.2s ease;
|
| 224 |
+
display: flex;
|
| 225 |
+
align-items: center;
|
| 226 |
+
justify-content: center;
|
| 227 |
+
font-size: 20px; /* Taille de l'icône */
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
.send-button:hover:not(:disabled) { background-color: #444; }
|
| 231 |
+
.send-button:disabled { background: #252525; color: #555; cursor: not-allowed; }
|
| 232 |
+
|
| 233 |
+
.file-input { display: none; }
|
| 234 |
+
|
| 235 |
+
.file-button {
|
| 236 |
+
background: #333;
|
| 237 |
+
border: none;
|
| 238 |
+
color: #f1f1f1;
|
| 239 |
+
height: 48px;
|
| 240 |
+
width: 48px;
|
| 241 |
+
border-radius: 50%;
|
| 242 |
+
cursor: pointer;
|
| 243 |
+
font-size: 20px; /* Taille de l'icône */
|
| 244 |
+
transition: background-color 0.2s ease;
|
| 245 |
+
flex-shrink: 0;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
.file-button:hover { background-color: #444; }
|
| 249 |
+
|
| 250 |
+
.file-preview {
|
| 251 |
+
margin-bottom: 10px;
|
| 252 |
+
padding: 10px;
|
| 253 |
+
background: #2c2c2c;
|
| 254 |
+
border-radius: 10px;
|
| 255 |
+
font-size: 14px;
|
| 256 |
+
display: none;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
/* --- INDICATEURS ET NOTIFICATIONS --- */
|
| 260 |
+
.typing-indicator {
|
| 261 |
+
display: none;
|
| 262 |
+
align-items: center;
|
| 263 |
+
gap: 8px;
|
| 264 |
+
color: #999;
|
| 265 |
+
font-style: italic;
|
| 266 |
+
padding: 0 15px 10px;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
.typing-dots span {
|
| 270 |
+
width: 8px; height: 8px; border-radius: 50%;
|
| 271 |
+
background: #666;
|
| 272 |
+
animation: typing 1.4s infinite ease-in-out;
|
| 273 |
}
|
| 274 |
+
.typing-dots span:nth-child(1) { animation-delay: 0s; }
|
| 275 |
+
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
|
| 276 |
+
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
|
| 277 |
+
|
| 278 |
+
.error {
|
| 279 |
+
background: #4d1c20; color: #ffacb6;
|
| 280 |
+
border-left: 3px solid #e53935;
|
| 281 |
+
padding: 15px; border-radius: 8px; margin: 10px 0;
|
| 282 |
+
}
|
| 283 |
+
.success {
|
| 284 |
+
background: #1a4331; color: #a6f1c4;
|
| 285 |
+
border-left: 3px solid #2e7d32;
|
| 286 |
+
padding: 15px; border-radius: 8px; margin: 10px 0;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
/* --- STYLE DE LA SCROLLBAR (THÈME SOMBRE) --- */
|
| 290 |
+
.messages::-webkit-scrollbar { width: 8px; }
|
| 291 |
+
.messages::-webkit-scrollbar-track { background: #1e1e1e; }
|
| 292 |
+
.messages::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
|
| 293 |
+
.messages::-webkit-scrollbar-thumb:hover { background: #777; }
|
| 294 |
+
|
| 295 |
+
/* --- ANIMATIONS --- */
|
| 296 |
+
@keyframes typing {
|
| 297 |
+
0%, 60%, 100% { transform: scale(0.8); opacity: 0.5; }
|
| 298 |
+
30% { transform: scale(1.2); opacity: 1; }
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
@keyframes fadeIn {
|
| 302 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 303 |
+
to { opacity: 1; transform: translateY(0); }
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
/* --- RESPONSIVE DESIGN (pour les écrans plus larges) --- */
|
| 307 |
+
@media (min-width: 768px) {
|
| 308 |
+
body {
|
| 309 |
+
padding: 20px; /* Ajoute de l'espace autour sur grand écran */
|
| 310 |
+
}
|
| 311 |
+
.chat-container {
|
| 312 |
+
height: 90vh; /* Hauteur limitée sur grand écran */
|
| 313 |
+
border-radius: 12px;
|
| 314 |
+
border: 1px solid #333;
|
| 315 |
+
}
|
| 316 |
}
|
| 317 |
</style>
|
| 318 |
</head>
|
| 319 |
+
<body>
|
| 320 |
+
<div class="chat-container">
|
| 321 |
+
<div class="header">
|
| 322 |
+
<h1>Mariam AI Assistant</h1>
|
| 323 |
+
<p>❤️</p>
|
| 324 |
+
<div class="controls">
|
| 325 |
+
<div class="thinking-toggle">
|
| 326 |
+
<span>réflexion Mode:</span>
|
| 327 |
+
<label class="switch">
|
| 328 |
+
<input type="checkbox" id="thinkingToggle" checked>
|
| 329 |
+
<span class="slider"></span>
|
| 330 |
+
</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
</div>
|
| 332 |
+
<button class="btn-reset" onclick="resetConversation()">
|
| 333 |
+
🔄 Reset
|
| 334 |
+
</button>
|
| 335 |
</div>
|
| 336 |
</div>
|
|
|
|
| 337 |
|
| 338 |
+
<div class="messages" id="messages">
|
| 339 |
+
<div class="message assistant">
|
| 340 |
+
<div>👋 bonjour, sur quoi allons nous travailler aujourdhui ?</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
</div>
|
| 344 |
|
| 345 |
+
<div class="typing-indicator" id="typingIndicator">
|
| 346 |
+
<span>L'assistant réfléchit</span>
|
| 347 |
+
<div class="typing-dots">
|
| 348 |
+
<span></span>
|
| 349 |
+
<span></span>
|
| 350 |
+
<span></span>
|
| 351 |
</div>
|
|
|
|
|
|
|
| 352 |
</div>
|
| 353 |
|
| 354 |
+
<div class="input-container">
|
| 355 |
+
<div class="file-preview" id="filePreview"></div>
|
| 356 |
+
<div class="input-row">
|
| 357 |
+
<input type="file" id="fileInput" class="file-input" accept="image/*,video/*,.pdf,.txt,.csv,.json" onchange="handleFileSelect(event)">
|
| 358 |
+
<button class="file-button" onclick="document.getElementById('fileInput').click()" title="Joindre un fichier">
|
| 359 |
+
📎
|
| 360 |
+
</button>
|
| 361 |
+
<div class="input-wrapper">
|
| 362 |
+
<textarea
|
| 363 |
+
id="messageInput"
|
| 364 |
+
class="message-input"
|
| 365 |
+
placeholder="Tapez votre message ici..."
|
| 366 |
+
rows="1"
|
| 367 |
+
onkeydown="handleKeyDown(event)"
|
| 368 |
+
oninput="autoResize(this)"
|
| 369 |
+
></textarea>
|
| 370 |
+
<button class="send-button" id="sendButton" onclick="sendMessage()" title="Envoyer">
|
| 371 |
+
➤
|
| 372 |
+
</button>
|
|
|
|
| 373 |
</div>
|
| 374 |
</div>
|
| 375 |
</div>
|
| 376 |
+
</div>
|
| 377 |
|
| 378 |
+
<!-- SCRIPT ORIGINAL ET FONCTIONNEL -->
|
| 379 |
<script>
|
| 380 |
+
let currentFile = null;
|
| 381 |
+
let conversationId = 'session_' + Date.now();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
|
| 383 |
+
function autoResize(textarea) {
|
| 384 |
+
textarea.style.height = 'auto';
|
| 385 |
+
textarea.style.height = Math.min(textarea.scrollHeight, 150) + 'px';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
}
|
| 387 |
|
| 388 |
+
function handleKeyDown(event) {
|
| 389 |
+
if (event.key === 'Enter' && !event.shiftKey) {
|
| 390 |
+
event.preventDefault();
|
| 391 |
+
sendMessage();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
}
|
| 393 |
}
|
| 394 |
|
| 395 |
+
function handleFileSelect(event) {
|
| 396 |
+
const file = event.target.files[0];
|
| 397 |
+
if (!file) return;
|
| 398 |
+
|
| 399 |
+
const filePreview = document.getElementById('filePreview');
|
| 400 |
+
const formData = new FormData();
|
| 401 |
+
formData.append('file', file);
|
| 402 |
+
|
| 403 |
+
fetch('/upload', {
|
| 404 |
+
method: 'POST',
|
| 405 |
+
body: formData
|
| 406 |
+
})
|
| 407 |
+
.then(response => response.json())
|
| 408 |
+
.then(data => {
|
| 409 |
+
if (data.success) {
|
| 410 |
+
currentFile = data;
|
| 411 |
+
filePreview.innerHTML = `
|
| 412 |
+
<div style="display: flex; justify-content: space-between; align-items: center;">
|
| 413 |
+
<span>📎 ${data.filename}</span>
|
| 414 |
+
<button onclick="removeFile()" style="background: #555; color: white; border: none; padding: 5px 10px; border-radius: 5px; cursor: pointer;">✕</button>
|
| 415 |
+
</div>
|
| 416 |
+
`;
|
| 417 |
+
filePreview.style.display = 'block';
|
| 418 |
+
} else {
|
| 419 |
+
showError('Erreur lors du téléchargement: ' + data.error);
|
| 420 |
+
}
|
| 421 |
+
})
|
| 422 |
+
.catch(error => {
|
| 423 |
+
showError('Erreur lors du téléchargement: ' + error.message);
|
| 424 |
+
});
|
| 425 |
}
|
| 426 |
|
| 427 |
+
function removeFile() {
|
| 428 |
+
currentFile = null;
|
| 429 |
+
document.getElementById('filePreview').style.display = 'none';
|
| 430 |
+
document.getElementById('fileInput').value = '';
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
function sendMessage() {
|
| 434 |
+
const messageInput = document.getElementById('messageInput');
|
| 435 |
+
const message = messageInput.value.trim();
|
| 436 |
+
|
| 437 |
+
if (!message && !currentFile) return;
|
| 438 |
+
|
| 439 |
+
const sendButton = document.getElementById('sendButton');
|
| 440 |
+
const typingIndicator = document.getElementById('typingIndicator');
|
| 441 |
|
| 442 |
+
messageInput.disabled = true;
|
| 443 |
+
sendButton.disabled = true;
|
| 444 |
|
| 445 |
+
if (message) {
|
| 446 |
+
addMessage('user', message);
|
|
|
|
|
|
|
| 447 |
}
|
| 448 |
|
| 449 |
+
typingIndicator.style.display = 'flex';
|
|
|
|
| 450 |
|
| 451 |
+
messageInput.value = '';
|
| 452 |
+
autoResize(messageInput);
|
| 453 |
|
| 454 |
+
const thinkingEnabled = document.getElementById('thinkingToggle').checked;
|
| 455 |
+
const endpoint = currentFile ? '/chat_with_file' : '/chat';
|
| 456 |
+
const payload = {
|
| 457 |
+
message: message || 'Analyse ce fichier',
|
| 458 |
+
thinking_enabled: thinkingEnabled,
|
| 459 |
+
conversation_id: conversationId
|
| 460 |
+
};
|
| 461 |
+
|
| 462 |
+
if (currentFile) {
|
| 463 |
+
payload.file_data = currentFile;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
fetch(endpoint, {
|
| 467 |
+
method: 'POST',
|
| 468 |
+
headers: { 'Content-Type': 'application/json' },
|
| 469 |
+
body: JSON.stringify(payload)
|
| 470 |
+
})
|
| 471 |
+
.then(response => {
|
| 472 |
+
if (!response.ok) {
|
| 473 |
+
throw new Error(`Erreur réseau: ${response.status} ${response.statusText}`);
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
const reader = response.body.getReader();
|
| 477 |
+
const decoder = new TextDecoder();
|
| 478 |
+
let buffer = '';
|
| 479 |
+
let messageElement = null;
|
| 480 |
+
let thoughtsElement = null;
|
| 481 |
+
|
| 482 |
+
function processStream() {
|
| 483 |
+
return reader.read().then(({ done, value }) => {
|
| 484 |
+
if (done) {
|
| 485 |
+
// La fin du stream est gérée par le message 'end'
|
| 486 |
+
return;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
buffer += decoder.decode(value, { stream: true });
|
| 490 |
+
const lines = buffer.split('\n');
|
| 491 |
+
buffer = lines.pop() || '';
|
| 492 |
+
|
| 493 |
+
for (const line of lines) {
|
| 494 |
+
if (line.startsWith('data: ')) {
|
| 495 |
+
try {
|
| 496 |
+
const data = JSON.parse(line.substring(6));
|
| 497 |
+
|
| 498 |
+
if (data.type === 'text') {
|
| 499 |
+
if (!messageElement) {
|
| 500 |
+
messageElement = addMessage('assistant', '');
|
| 501 |
+
}
|
| 502 |
+
messageElement.innerHTML += formatChunk(data.content);
|
| 503 |
+
} else if (data.type === 'thought' && thinkingEnabled) {
|
| 504 |
+
if (!thoughtsElement) {
|
| 505 |
+
thoughtsElement = addThoughts('');
|
| 506 |
+
thoughtsElement.innerHTML = `<div class="thoughts-header">🧠 Réflexion de l'assistant:</div><div class="thought-content"></div>`;
|
| 507 |
+
}
|
| 508 |
+
thoughtsElement.querySelector('.thought-content').innerHTML += formatChunk(data.content);
|
| 509 |
+
} else if (data.type === 'error') {
|
| 510 |
+
showError(data.content);
|
| 511 |
+
} else if (data.type === 'end') {
|
| 512 |
+
typingIndicator.style.display = 'none';
|
| 513 |
+
messageInput.disabled = false;
|
| 514 |
+
sendButton.disabled = false;
|
| 515 |
+
messageInput.focus();
|
| 516 |
+
removeFile();
|
| 517 |
+
return; // Fin du traitement du stream
|
| 518 |
+
}
|
| 519 |
+
// Scroll vers le bas à chaque nouveau chunk
|
| 520 |
+
const messagesContainer = document.getElementById('messages');
|
| 521 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
| 522 |
+
|
| 523 |
+
} catch (e) {
|
| 524 |
+
console.error('Erreur parsing JSON:', e, "Ligne reçue:", line);
|
| 525 |
+
}
|
| 526 |
}
|
| 527 |
+
}
|
| 528 |
+
return processStream();
|
| 529 |
+
});
|
| 530 |
+
}
|
| 531 |
+
return processStream();
|
| 532 |
+
})
|
| 533 |
+
.catch(error => {
|
| 534 |
+
typingIndicator.style.display = 'none';
|
| 535 |
+
messageInput.disabled = false;
|
| 536 |
+
sendButton.disabled = false;
|
| 537 |
+
showError('Erreur: ' + error.message);
|
| 538 |
+
messageInput.focus();
|
| 539 |
+
});
|
| 540 |
}
|
| 541 |
|
| 542 |
+
function addMessage(role, content) {
|
| 543 |
+
const messagesContainer = document.getElementById('messages');
|
| 544 |
+
const messageDiv = document.createElement('div');
|
| 545 |
+
messageDiv.className = `message ${role}`;
|
| 546 |
+
messageDiv.innerHTML = formatMessage(content);
|
| 547 |
+
messagesContainer.appendChild(messageDiv);
|
| 548 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
| 549 |
+
return messageDiv;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
}
|
| 551 |
|
| 552 |
+
function addThoughts(content) {
|
| 553 |
+
const messagesContainer = document.getElementById('messages');
|
| 554 |
+
const thoughtsDiv = document.createElement('div');
|
| 555 |
+
thoughtsDiv.className = 'thoughts';
|
| 556 |
+
thoughtsDiv.innerHTML = content;
|
| 557 |
+
messagesContainer.appendChild(thoughtsDiv);
|
| 558 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
| 559 |
+
return thoughtsDiv;
|
| 560 |
}
|
| 561 |
+
|
| 562 |
+
function escapeHtml(unsafe) {
|
| 563 |
+
return unsafe
|
| 564 |
+
.replace(/&/g, "&")
|
| 565 |
+
.replace(/</g, "<")
|
| 566 |
+
.replace(/>/g, ">")
|
| 567 |
+
.replace(/"/g, """)
|
| 568 |
+
.replace(/'/g, "'");
|
|
|
|
|
|
|
|
|
|
|
|
|
| 569 |
}
|
| 570 |
|
| 571 |
+
function formatChunk(chunk) {
|
| 572 |
+
// Pour le streaming, on échappe le HTML et on remplace juste les sauts de ligne
|
| 573 |
+
return escapeHtml(chunk).replace(/\n/g, '<br>');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 574 |
}
|
| 575 |
|
| 576 |
+
function formatMessage(content) {
|
| 577 |
+
// Cette fonction est utilisée pour le message initial de l'utilisateur
|
| 578 |
+
// Elle peut gérer plus de markdown car elle traite le message en une seule fois
|
| 579 |
+
return escapeHtml(content)
|
| 580 |
+
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
| 581 |
+
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 582 |
+
.replace(/`(.*?)`/g, '<code style="background: #444; padding: 2px 5px; border-radius: 4px; font-family: monospace;">$1</code>')
|
| 583 |
+
.replace(/\n/g, '<br>');
|
| 584 |
}
|
| 585 |
|
| 586 |
+
|
| 587 |
function showError(message) {
|
| 588 |
+
const messagesContainer = document.getElementById('messages');
|
| 589 |
+
const errorDiv = document.createElement('div');
|
| 590 |
+
errorDiv.className = 'error';
|
| 591 |
+
errorDiv.textContent = message;
|
| 592 |
+
messagesContainer.appendChild(errorDiv);
|
| 593 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
function resetConversation() {
|
| 597 |
+
if (confirm('Êtes-vous sûr de vouloir réinitialiser la conversation ?')) {
|
| 598 |
+
fetch('/reset_conversation', {
|
| 599 |
+
method: 'POST',
|
| 600 |
+
headers: { 'Content-Type': 'application/json' },
|
| 601 |
+
body: JSON.stringify({ conversation_id: conversationId })
|
| 602 |
+
})
|
| 603 |
+
.then(response => {
|
| 604 |
+
if (response.ok) {
|
| 605 |
+
document.getElementById('messages').innerHTML = `
|
| 606 |
+
<div class="message assistant">
|
| 607 |
+
<div>👋 Conversation réinitialisée ! Comment puis-je vous aider ?</div>
|
| 608 |
+
</div>
|
| 609 |
+
`;
|
| 610 |
+
conversationId = 'session_' + Date.now();
|
| 611 |
+
removeFile();
|
| 612 |
+
} else {
|
| 613 |
+
showError('La réinitialisation a échoué.');
|
| 614 |
+
}
|
| 615 |
+
})
|
| 616 |
+
.catch(error => {
|
| 617 |
+
showError('Erreur lors de la réinitialisation: ' + error.message);
|
| 618 |
+
});
|
| 619 |
+
}
|
| 620 |
}
|
| 621 |
+
|
| 622 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 623 |
+
document.getElementById('messageInput').focus();
|
| 624 |
+
});
|
| 625 |
</script>
|
| 626 |
</body>
|
| 627 |
</html>
|