AnesKAM commited on
Commit
c67c626
·
verified ·
1 Parent(s): 8cabf75

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +145 -205
index.html CHANGED
@@ -3,11 +3,9 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Genisi AI | Next-Gen Interface</title>
7
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
8
- <!-- مكتبة Markdown -->
9
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
10
- <!-- مكتبة تلوين الأكواد -->
11
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
12
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
13
 
@@ -21,7 +19,7 @@
21
  --text-secondary: #8b949e;
22
  --user-msg: #21262d;
23
  --border: #30363d;
24
- --reasoning-bg: #1f242c;
25
  }
26
 
27
  * { box-sizing: border-box; margin: 0; padding: 0; }
@@ -34,9 +32,8 @@
34
  overflow: hidden;
35
  }
36
 
37
- /* Sidebar */
38
  .sidebar {
39
- width: 300px;
40
  background: var(--sidebar);
41
  border-left: 1px solid var(--border);
42
  display: flex;
@@ -62,10 +59,9 @@
62
  margin-bottom: 8px;
63
  font-weight: 600;
64
  text-transform: uppercase;
65
- letter-spacing: 0.5px;
66
  }
67
 
68
- select, .toggle-btn {
69
  width: 100%;
70
  padding: 12px;
71
  background: var(--bg);
@@ -75,68 +71,23 @@
75
  cursor: pointer;
76
  outline: none;
77
  font-size: 14px;
78
- transition: all 0.2s;
79
  }
80
-
81
- select:hover, .toggle-btn:hover { border-color: var(--accent); }
82
-
83
- /* Reasoning Toggle (يظهر فقط للـ Chat) */
84
- .reasoning-container {
85
- display: none;
86
- animation: fadeIn 0.3s ease;
87
- }
88
-
89
- .reasoning-container.active { display: block; }
90
 
91
- .toggle-switch {
92
- display: flex;
93
- align-items: center;
94
- justify-content: space-between;
95
- background: var(--bg);
96
- padding: 12px;
97
  border-radius: 8px;
98
- border: 1px solid var(--border);
99
- cursor: pointer;
100
- transition: all 0.2s;
101
- }
102
-
103
- .toggle-switch:hover { border-color: var(--accent); }
104
-
105
- .toggle-switch input { display: none; }
106
-
107
- .slider {
108
- width: 44px;
109
- height: 24px;
110
- background: var(--border);
111
- border-radius: 12px;
112
- position: relative;
113
- transition: 0.3s;
114
- }
115
-
116
- .slider::before {
117
- content: "";
118
- position: absolute;
119
- width: 18px;
120
- height: 18px;
121
- background: white;
122
- border-radius: 50%;
123
- top: 3px;
124
- right: 3px;
125
- transition: 0.3s;
126
- }
127
-
128
- input:checked + .slider {
129
- background: var(--accent);
130
- }
131
-
132
- input:checked + .slider::before {
133
- transform: translateX(-20px);
134
  }
135
 
136
- .toggle-label { font-size: 14px; }
137
- .toggle-sublabel { font-size: 11px; color: var(--text-secondary); display: block; margin-top: 4px; }
138
 
139
- /* Chat Area */
140
  .chat-container {
141
  flex: 1;
142
  display: flex;
@@ -147,7 +98,7 @@
147
 
148
  #chat-flow {
149
  flex: 1;
150
- padding: 40px 10% 120px;
151
  overflow-y: auto;
152
  display: flex;
153
  flex-direction: column;
@@ -181,6 +132,17 @@
181
  }
182
  .user .avatar { background: #1f6feb; color: white; }
183
  .ai .avatar { background: var(--accent); color: white; }
 
 
 
 
 
 
 
 
 
 
 
184
 
185
  .bubble {
186
  padding: 16px;
@@ -202,36 +164,41 @@
202
  border-color: var(--border);
203
  color: var(--text);
204
  }
 
 
 
 
 
 
 
 
205
 
206
- /* Markdown Styles */
207
- .bubble pre {
208
- background: #161b22;
209
- padding: 16px;
210
- border-radius: 8px;
211
- overflow-x: auto;
212
- margin: 12px 0;
213
- border: 1px solid var(--border);
214
  }
215
 
216
- .bubble code {
217
- font-family: 'JetBrains Mono', 'Fira Code', monospace;
218
- font-size: 13px;
 
 
 
 
 
 
219
  }
220
 
221
- .bubble p { margin-bottom: 12px; }
222
- .bubble p:last-child { margin-bottom: 0; }
223
 
224
- .bubble h1, .bubble h2, .bubble h3 {
225
- color: white;
226
- margin: 16px 0 8px;
227
- border-bottom: 1px solid var(--border);
228
- padding-bottom: 8px;
229
- }
230
 
231
- .bubble ul, .bubble ol { margin: 8px 0; padding-right: 20px; }
232
- .bubble li { margin: 4px 0; }
233
 
234
- /* Input Area */
235
  .input-wrapper {
236
  position: absolute;
237
  bottom: 30px;
@@ -247,7 +214,6 @@
247
  align-items: center;
248
  gap: 12px;
249
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
250
- transition: border-color 0.2s;
251
  }
252
 
253
  .input-wrapper:focus-within { border-color: var(--accent); }
@@ -277,63 +243,43 @@
277
  justify-content: center;
278
  }
279
  .send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
280
- .send-btn:disabled {
281
- background: #30363d;
282
- cursor: not-allowed;
283
- transform: none;
284
- }
285
 
286
- /* Typing Indicator */
287
- .typing-indicator {
288
- display: none;
289
- align-items: center;
290
- gap: 4px;
291
- padding: 12px 16px;
 
 
292
  }
293
 
294
- .typing-indicator.active { display: flex; }
295
-
296
- .dot {
297
- width: 8px;
298
- height: 8px;
299
- background: var(--text-secondary);
300
- border-radius: 50%;
301
- animation: bounce 1.4s infinite ease-in-out both;
302
  }
303
 
304
- .dot:nth-child(1) { animation-delay: -0.32s; }
305
- .dot:nth-child(2) { animation-delay: -0.16s; }
306
 
307
- @keyframes bounce {
308
- 0%, 80%, 100% { transform: scale(0); }
309
- 40% { transform: scale(1); }
310
- }
311
-
312
- /* Model Badge */
313
- .model-badge {
314
- display: inline-block;
315
- font-size: 11px;
316
- padding: 2px 8px;
317
- background: rgba(35, 134, 54, 0.2);
318
- color: var(--accent);
319
- border-radius: 12px;
320
- margin-bottom: 8px;
321
- font-weight: 600;
322
  }
323
 
324
- .reasoning-badge {
325
- display: inline-block;
326
- font-size: 11px;
327
- padding: 2px 8px;
328
- background: rgba(139, 148, 158, 0.2);
329
- color: var(--text-secondary);
330
- border-radius: 12px;
331
- margin-right: 8px;
332
  }
333
 
334
- img { max-width: 100%; border-radius: 8px; margin-top: 10px; border: 1px solid var(--border); }
335
-
336
- /* Scrollbar */
337
  ::-webkit-scrollbar { width: 8px; }
338
  ::-webkit-scrollbar-track { background: var(--bg); }
339
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
@@ -347,26 +293,17 @@
347
 
348
  <div class="config-group">
349
  <label>وضع التشغيل</label>
350
- <select id="actionType" onchange="handleModeChange()">
351
- <option value="chat">💬 الدردشة الذكية (Kimi)</option>
352
- <option value="code">⚡ البرمجة السريعة (Gemma)</option>
353
- <option value="image">🎨 توليد الصور (Flux)</option>
354
  </select>
355
  </div>
356
 
357
- <!-- خيار التفكير يظهر فقط للـ Chat -->
358
- <div class="config-group reasoning-container" id="reasoningContainer">
359
- <label>إعدادات التفكير</label>
360
- <label class="toggle-switch">
361
- <div>
362
- <span class="toggle-label">🧠 وضع التفكير العميق</span>
363
- <span class="toggle-sublabel">يفكر قبل الإجابة (بطيء لكن دقيق)</span>
364
- </div>
365
- <div>
366
- <input type="checkbox" id="reasoningToggle">
367
- <span class="slider"></span>
368
- </div>
369
- </label>
370
  </div>
371
 
372
  <div style="margin-top: auto; border-top: 1px solid var(--border); padding-top: 20px;">
@@ -374,7 +311,7 @@
374
  المطور: <span style="color: white; font-weight: 600;">AnesNT</span>
375
  </p>
376
  <p style="font-size: 11px; color: #484f58; margin-top: 6px;">
377
- Genisi v4.0 | Streaming + Reasoning Control
378
  </p>
379
  </div>
380
  </aside>
@@ -384,20 +321,25 @@
384
  <div class="message ai">
385
  <div class="avatar"><i class="fas fa-robot"></i></div>
386
  <div>
387
- <span class="model-badge">Kimi Ready</span>
 
 
 
388
  <div class="bubble">
389
- مرحباً أنس! نظام Genisi جاهز. اختر الوضع المناسب:
390
  <br><br>
391
- 💬 <strong>Kimi:</strong> للأسئلة العامة مع خيار التفكير العميق<br>
392
- • ⚡ <strong>Gemma:</strong> للأكواد والمهام السريعة (بدون تأخير)<br>
393
- • 🎨 <strong>Flux:</strong> لتوليد الصور
 
 
394
  </div>
395
  </div>
396
  </div>
397
  </div>
398
 
399
  <div class="input-wrapper">
400
- <input type="text" id="userInput" placeholder="اكتب رسالتك هنا..." autocomplete="off">
401
  <button class="send-btn" id="sendBtn" onclick="handleSend()">
402
  <i class="fas fa-paper-plane"></i>
403
  </button>
@@ -405,21 +347,16 @@
405
  </main>
406
 
407
  <script>
408
- // تغيير الوضع (إظهار/إخفاء خيار التفكير)
409
- function handleModeChange() {
410
  const action = document.getElementById('actionType').value;
411
- const reasoningContainer = document.getElementById('reasoningContainer');
412
- const badge = document.querySelector('.model-badge');
413
 
414
  if (action === 'chat') {
415
- reasoningContainer.classList.add('active');
416
- badge.textContent = 'Kimi Ready';
417
  } else if (action === 'code') {
418
- reasoningContainer.classList.remove('active');
419
- badge.textContent = 'Gemma Fast';
420
  } else {
421
- reasoningContainer.classList.remove('active');
422
- badge.textContent = 'Flux Image';
423
  }
424
  }
425
 
@@ -427,13 +364,11 @@
427
  const input = document.getElementById('userInput');
428
  const chatFlow = document.getElementById('chat-flow');
429
  const action = document.getElementById('actionType').value;
430
- const reasoning = document.getElementById('reasoningToggle')?.checked || false;
431
  const btn = document.getElementById('sendBtn');
432
  const text = input.value.trim();
433
 
434
  if (!text) return;
435
 
436
- // UI State: Loading
437
  input.value = "";
438
  input.disabled = true;
439
  btn.disabled = true;
@@ -441,40 +376,33 @@
441
  // إضافة رسالة المستخدم
442
  addMessage(text, 'user', action);
443
 
444
- // إنشاء رسالة AI فارغة
445
- const aiMsgId = addMessage("", 'ai', action, reasoning);
446
- const aiBubble = document.getElementById(aiMsgId).querySelector('.bubble');
447
-
448
- // إظهار مؤشر الكتابة
449
- const typingId = 'typing-' + Date.now();
450
- aiBubble.innerHTML = `<div class="typing-indicator active" id="${typingId}">
451
- <div class="dot"></div><div class="dot"></div><div class="dot"></div>
452
- </div>`;
453
 
454
  try {
455
  const response = await fetch('/api/genisi', {
456
  method: 'POST',
457
  headers: { 'Content-Type': 'application/json' },
458
- body: JSON.stringify({
459
- action,
460
- message: text,
461
- reasoning: action === 'chat' ? reasoning : false // نرسله فقط للـ Chat
462
- })
463
  });
464
 
465
  if (action === 'image') {
466
- // معالجة الصور
467
  const data = await response.json();
468
  if (data.success) {
469
- aiBubble.innerHTML = `<img src="data:image/png;base64,${data.data}" alt="Generated Image">`;
470
  } else {
471
  aiBubble.innerHTML = `<span style="color: #f85149;">خطأ: ${data.error}</span>`;
472
  }
 
473
  } else {
474
- // معالجة الـ Streaming
475
  const reader = response.body.getReader();
476
  const decoder = new TextDecoder();
477
  let fullText = "";
 
478
  let isFirstChunk = true;
479
 
480
  while (true) {
@@ -491,31 +419,42 @@
491
 
492
  try {
493
  const parsed = JSON.parse(jsonStr);
494
- if (parsed.content) {
 
 
 
 
 
 
 
 
495
  if (isFirstChunk) {
496
- aiBubble.innerHTML = ""; // إزالة typing indicator
497
  isFirstChunk = false;
498
  }
499
  fullText += parsed.content;
500
- // تحديث النص مع Markdown
501
  aiBubble.innerHTML = marked.parse(fullText);
502
- // تلوين الأكواد إذا وجدت
503
- aiBubble.querySelectorAll('pre code').forEach((block) => {
504
  hljs.highlightElement(block);
505
  });
506
  chatFlow.scrollTop = chatFlow.scrollHeight;
507
- } else if (parsed.error) {
 
 
508
  aiBubble.innerHTML = `<span style="color: #f85149;">خطأ: ${parsed.error}</span>`;
509
  }
510
- } catch (e) {
511
- // تجاهل أخطاء JSON parsing للسطرغير المكتمل
512
- }
513
  }
514
  }
515
  }
 
 
 
 
516
  }
517
  } catch (error) {
518
  aiBubble.innerHTML = `<span style="color: #f85149;">فشل الاتصال: ${error.message}</span>`;
 
519
  } finally {
520
  input.disabled = false;
521
  btn.disabled = false;
@@ -523,7 +462,7 @@
523
  }
524
  }
525
 
526
- function addMessage(text, role, action = 'chat', reasoning = false) {
527
  const chatFlow = document.getElementById('chat-flow');
528
  const msgId = 'msg-' + Date.now();
529
  const icon = role === 'user' ? 'fa-user' : 'fa-robot';
@@ -532,16 +471,18 @@
532
  if (role === 'ai') {
533
  const modelName = action === 'chat' ? 'Kimi' : action === 'code' ? 'Gemma' : 'Flux';
534
  badges += `<span class="model-badge">${modelName}</span>`;
535
- if (action === 'chat' && reasoning) {
536
- badges += `<span class="reasoning-badge"><i class="fas fa-brain"></i> Reasoning ON</span>`;
 
 
537
  }
538
  }
539
 
540
  const html = `
541
- <div class="message ${role}" id="${msgId}">
542
  <div class="avatar"><i class="fas ${icon}"></i></div>
543
  <div style="max-width: 100%;">
544
- ${badges}
545
  <div class="bubble">${role === 'user' ? escapeHtml(text) : text}</div>
546
  </div>
547
  </div>
@@ -558,13 +499,12 @@
558
  return div.innerHTML;
559
  }
560
 
561
- // Enter لإرسال
562
  document.getElementById('userInput').addEventListener('keypress', (e) => {
563
  if (e.key === 'Enter') handleSend();
564
  });
565
 
566
- // تهيئة أولية
567
- handleModeChange();
568
  </script>
569
  </body>
570
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Genisi AI | Auto-Reasoning</title>
7
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
 
8
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
 
9
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
10
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
11
 
 
19
  --text-secondary: #8b949e;
20
  --user-msg: #21262d;
21
  --border: #30363d;
22
+ --reasoning-color: #a371f7; /* بنفسجي للتفكير */
23
  }
24
 
25
  * { box-sizing: border-box; margin: 0; padding: 0; }
 
32
  overflow: hidden;
33
  }
34
 
 
35
  .sidebar {
36
+ width: 280px;
37
  background: var(--sidebar);
38
  border-left: 1px solid var(--border);
39
  display: flex;
 
59
  margin-bottom: 8px;
60
  font-weight: 600;
61
  text-transform: uppercase;
 
62
  }
63
 
64
+ select {
65
  width: 100%;
66
  padding: 12px;
67
  background: var(--bg);
 
71
  cursor: pointer;
72
  outline: none;
73
  font-size: 14px;
 
74
  }
 
 
 
 
 
 
 
 
 
 
75
 
76
+ select:hover { border-color: var(--accent); }
77
+
78
+ /* مؤشر الوضع الذكي */
79
+ .auto-mode-info {
80
+ background: rgba(35, 134, 54, 0.1);
81
+ border: 1px solid rgba(35, 134, 54, 0.3);
82
  border-radius: 8px;
83
+ padding: 12px;
84
+ margin-top: 16px;
85
+ font-size: 13px;
86
+ line-height: 1.5;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  }
88
 
89
+ .auto-mode-info i { color: var(--accent); margin-left: 6px; }
 
90
 
 
91
  .chat-container {
92
  flex: 1;
93
  display: flex;
 
98
 
99
  #chat-flow {
100
  flex: 1;
101
+ padding: 40px 12% 120px;
102
  overflow-y: auto;
103
  display: flex;
104
  flex-direction: column;
 
132
  }
133
  .user .avatar { background: #1f6feb; color: white; }
134
  .ai .avatar { background: var(--accent); color: white; }
135
+
136
+ /* تغيير لون الأفاتار عند التفكير */
137
+ .ai.thinking .avatar {
138
+ background: var(--reasoning-color);
139
+ animation: pulse 2s infinite;
140
+ }
141
+
142
+ @keyframes pulse {
143
+ 0%, 100% { box-shadow: 0 0 0 0 rgba(163, 113, 247, 0.4); }
144
+ 50% { box-shadow: 0 0 0 10px rgba(163, 113, 247, 0); }
145
+ }
146
 
147
  .bubble {
148
  padding: 16px;
 
164
  border-color: var(--border);
165
  color: var(--text);
166
  }
167
+
168
+ /* شارات الحالة */
169
+ .badges-container {
170
+ display: flex;
171
+ gap: 8px;
172
+ margin-bottom: 6px;
173
+ align-items: center;
174
+ }
175
 
176
+ .model-badge {
177
+ font-size: 11px;
178
+ padding: 3px 10px;
179
+ background: rgba(35, 134, 54, 0.15);
180
+ color: var(--accent);
181
+ border-radius: 12px;
182
+ font-weight: 600;
 
183
  }
184
 
185
+ .thinking-badge {
186
+ font-size: 11px;
187
+ padding: 3px 10px;
188
+ background: rgba(163, 113, 247, 0.15);
189
+ color: var(--reasoning-color);
190
+ border-radius: 12px;
191
+ font-weight: 600;
192
+ display: none;
193
+ animation: fadeIn 0.3s ease;
194
  }
195
 
196
+ .thinking-badge.active { display: inline-block; }
 
197
 
198
+ .thinking-badge i { margin-left: 4px; animation: spin 1s linear infinite; }
 
 
 
 
 
199
 
200
+ @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
 
201
 
 
202
  .input-wrapper {
203
  position: absolute;
204
  bottom: 30px;
 
214
  align-items: center;
215
  gap: 12px;
216
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
 
217
  }
218
 
219
  .input-wrapper:focus-within { border-color: var(--accent); }
 
243
  justify-content: center;
244
  }
245
  .send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
246
+ .send-btn:disabled { background: #30363d; cursor: not-allowed; transform: none; }
 
 
 
 
247
 
248
+ /* Markdown & Code */
249
+ .bubble pre {
250
+ background: #161b22;
251
+ padding: 16px;
252
+ border-radius: 8px;
253
+ overflow-x: auto;
254
+ margin: 12px 0;
255
+ border: 1px solid var(--border);
256
  }
257
 
258
+ .bubble code {
259
+ font-family: 'JetBrains Mono', 'Fira Code', monospace;
260
+ font-size: 13px;
 
 
 
 
 
261
  }
262
 
263
+ .bubble p { margin-bottom: 12px; }
264
+ .bubble p:last-child { margin-bottom: 0; }
265
 
266
+ .bubble h1, .bubble h2, .bubble h3 {
267
+ color: white;
268
+ margin: 16px 0 8px;
269
+ border-bottom: 1px solid var(--border);
270
+ padding-bottom: 8px;
 
 
 
 
 
 
 
 
 
 
271
  }
272
 
273
+ .bubble ul, .bubble ol { margin: 8px 0; padding-right: 20px; }
274
+ .bubble li { margin: 4px 0; }
275
+
276
+ img {
277
+ max-width: 100%;
278
+ border-radius: 8px;
279
+ margin-top: 10px;
280
+ border: 1px solid var(--border);
281
  }
282
 
 
 
 
283
  ::-webkit-scrollbar { width: 8px; }
284
  ::-webkit-scrollbar-track { background: var(--bg); }
285
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
 
293
 
294
  <div class="config-group">
295
  <label>وضع التشغيل</label>
296
+ <select id="actionType" onchange="updateModeInfo()">
297
+ <option value="chat">🧠 Kimi (Auto-Reasoning)</option>
298
+ <option value="code">⚡ Gemma (Fast Code)</option>
299
+ <option value="image">🎨 Flux (Image Gen)</option>
300
  </select>
301
  </div>
302
 
303
+ <div class="auto-mode-info" id="modeInfo">
304
+ <i class="fas fa-brain"></i>
305
+ <strongلوضع الذكي:</strong><br>
306
+ Kimi يختار تلقائياً بين الرد السريع أو التفكير العميق بناءً على نوع سؤالك.
 
 
 
 
 
 
 
 
 
307
  </div>
308
 
309
  <div style="margin-top: auto; border-top: 1px solid var(--border); padding-top: 20px;">
 
311
  المطور: <span style="color: white; font-weight: 600;">AnesNT</span>
312
  </p>
313
  <p style="font-size: 11px; color: #484f58; margin-top: 6px;">
314
+ Genisi v4.1 | Auto-Reasoning Engine
315
  </p>
316
  </div>
317
  </aside>
 
321
  <div class="message ai">
322
  <div class="avatar"><i class="fas fa-robot"></i></div>
323
  <div>
324
+ <div class="badges-container">
325
+ <span class="model-badge">Kimi Auto-Mode</span>
326
+ <span class="thinking-badge" id="welcomeThinking"><i class="fas fa-circle-notch"></i> يفكر...</span>
327
+ </div>
328
  <div class="bubble">
329
+ مرحباً أنس! أنا Kimi بنظام Auto-Reasoning.
330
  <br><br>
331
+ جرب أسألني:
332
+ <ul style="margin-top: 8px;">
333
+ <li>"احسب 15 × 23" ← سأفكر 🧮</li>
334
+ <li>"كيف حالك؟" ← رد فوري ⚡</li>
335
+ </ul>
336
  </div>
337
  </div>
338
  </div>
339
  </div>
340
 
341
  <div class="input-wrapper">
342
+ <input type="text" id="userInput" placeholder="اكتب سؤالك هنا..." autocomplete="off">
343
  <button class="send-btn" id="sendBtn" onclick="handleSend()">
344
  <i class="fas fa-paper-plane"></i>
345
  </button>
 
347
  </main>
348
 
349
  <script>
350
+ function updateModeInfo() {
 
351
  const action = document.getElementById('actionType').value;
352
+ const info = document.getElementById('modeInfo');
 
353
 
354
  if (action === 'chat') {
355
+ info.innerHTML = `<i class="fas fa-brain"></i><strong>الوضع الذكي:</strong><br>Kimi يختار تلقائياً بين الرد السريع أو التفكير العميق بناءً على نوع سؤالك.`;
 
356
  } else if (action === 'code') {
357
+ info.innerHTML = `<i class="fas fa-code"></i><strong>وضع البرمجة:</strong><br>Gemma مُحسّن للسرعة. لا يوجد تأخير في التفكير، مثالي للأكواد والتصحيح السريع.`;
 
358
  } else {
359
+ info.innerHTML = `<i class="fas fa-image"></i><strong>توليد الصور:</strong><br>Flux ينشئ صوراً عالية الجودة من وصفك النصي.`;
 
360
  }
361
  }
362
 
 
364
  const input = document.getElementById('userInput');
365
  const chatFlow = document.getElementById('chat-flow');
366
  const action = document.getElementById('actionType').value;
 
367
  const btn = document.getElementById('sendBtn');
368
  const text = input.value.trim();
369
 
370
  if (!text) return;
371
 
 
372
  input.value = "";
373
  input.disabled = true;
374
  btn.disabled = true;
 
376
  // إضافة رسالة المستخدم
377
  addMessage(text, 'user', action);
378
 
379
+ // إنشاء رسالة AI
380
+ const aiMsgId = addMessage("", 'ai', action, false, true); // true = show thinking placeholder
381
+ const msgElement = document.getElementById(aiMsgId);
382
+ const aiBubble = msgElement.querySelector('.bubble');
383
+ const thinkingBadge = msgElement.querySelector('.thinking-badge');
 
 
 
 
384
 
385
  try {
386
  const response = await fetch('/api/genisi', {
387
  method: 'POST',
388
  headers: { 'Content-Type': 'application/json' },
389
+ body: JSON.stringify({ action, message: text })
 
 
 
 
390
  });
391
 
392
  if (action === 'image') {
 
393
  const data = await response.json();
394
  if (data.success) {
395
+ aiBubble.innerHTML = `<img src="data:image/png;base64,${data.data}" alt="Generated">`;
396
  } else {
397
  aiBubble.innerHTML = `<span style="color: #f85149;">خطأ: ${data.error}</span>`;
398
  }
399
+ thinkingBadge.classList.remove('active');
400
  } else {
401
+ // معالجة Streaming
402
  const reader = response.body.getReader();
403
  const decoder = new TextDecoder();
404
  let fullText = "";
405
+ let isReasoning = false;
406
  let isFirstChunk = true;
407
 
408
  while (true) {
 
419
 
420
  try {
421
  const parsed = JSON.parse(jsonStr);
422
+
423
+ // ✅ استلام معلومة أن النموذج يفكر
424
+ if (parsed.meta?.reasoning) {
425
+ isReasoning = true;
426
+ thinkingBadge.classList.add('active');
427
+ msgElement.classList.add('thinking');
428
+ }
429
+
430
+ else if (parsed.content) {
431
  if (isFirstChunk) {
432
+ aiBubble.innerHTML = "";
433
  isFirstChunk = false;
434
  }
435
  fullText += parsed.content;
 
436
  aiBubble.innerHTML = marked.parse(fullText);
437
+ aiBubble.querySelectorAll('pre code').forEach(block => {
 
438
  hljs.highlightElement(block);
439
  });
440
  chatFlow.scrollTop = chatFlow.scrollHeight;
441
+ }
442
+
443
+ else if (parsed.error) {
444
  aiBubble.innerHTML = `<span style="color: #f85149;">خطأ: ${parsed.error}</span>`;
445
  }
446
+ } catch (e) {}
 
 
447
  }
448
  }
449
  }
450
+
451
+ // إخفاء شارة "يفكر" عند الانتهاء
452
+ thinkingBadge.classList.remove('active');
453
+ msgElement.classList.remove('thinking');
454
  }
455
  } catch (error) {
456
  aiBubble.innerHTML = `<span style="color: #f85149;">فشل الاتصال: ${error.message}</span>`;
457
+ thinkingBadge.classList.remove('active');
458
  } finally {
459
  input.disabled = false;
460
  btn.disabled = false;
 
462
  }
463
  }
464
 
465
+ function addMessage(text, role, action = 'chat', isReasoning = false, showThinkingPlaceholder = false) {
466
  const chatFlow = document.getElementById('chat-flow');
467
  const msgId = 'msg-' + Date.now();
468
  const icon = role === 'user' ? 'fa-user' : 'fa-robot';
 
471
  if (role === 'ai') {
472
  const modelName = action === 'chat' ? 'Kimi' : action === 'code' ? 'Gemma' : 'Flux';
473
  badges += `<span class="model-badge">${modelName}</span>`;
474
+ if (action === 'chat') {
475
+ badges += `<span class="thinking-badge ${isReasoning ? 'active' : ''}" id="badge-${msgId}">
476
+ <i class="fas fa-circle-notch"></i> يفكر...
477
+ </span>`;
478
  }
479
  }
480
 
481
  const html = `
482
+ <div class="message ${role} ${isReasoning ? 'thinking' : ''}" id="${msgId}">
483
  <div class="avatar"><i class="fas ${icon}"></i></div>
484
  <div style="max-width: 100%;">
485
+ ${role === 'ai' ? `<div class="badges-container">${badges}</div>` : ''}
486
  <div class="bubble">${role === 'user' ? escapeHtml(text) : text}</div>
487
  </div>
488
  </div>
 
499
  return div.innerHTML;
500
  }
501
 
 
502
  document.getElementById('userInput').addEventListener('keypress', (e) => {
503
  if (e.key === 'Enter') handleSend();
504
  });
505
 
506
+ // تهيئة
507
+ updateModeInfo();
508
  </script>
509
  </body>
510
  </html>