AnesKAM commited on
Commit
ab53fb2
·
verified ·
1 Parent(s): 8acca2e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +342 -61
index.html CHANGED
@@ -5,14 +5,23 @@
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
  <style>
9
  :root {
10
  --bg: #0d1117;
11
  --sidebar: #161b22;
12
- --accent: #238636; /* أخضر هادئ احترافي */
 
13
  --text: #c9d1d9;
 
14
  --user-msg: #21262d;
15
  --border: #30363d;
 
16
  }
17
 
18
  * { box-sizing: border-box; margin: 0; padding: 0; }
@@ -22,53 +31,123 @@
22
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
23
  display: flex;
24
  height: 100vh;
 
25
  }
26
 
27
- /* القائمة الجانبية */
28
  .sidebar {
29
- width: 280px;
30
  background: var(--sidebar);
31
  border-left: 1px solid var(--border);
32
  display: flex;
33
  flex-direction: column;
34
- padding: 20px;
35
  }
36
 
37
  .brand {
38
- font-size: 22px;
39
  font-weight: 800;
40
  color: white;
41
- margin-bottom: 30px;
42
  display: flex;
43
  align-items: center;
44
  gap: 12px;
45
  }
46
 
47
- .config-group { margin-bottom: 20px; }
48
- .config-group label { display: block; font-size: 13px; color: #8b949e; margin-bottom: 8px; }
 
 
 
 
 
 
 
 
49
 
50
- select {
51
  width: 100%;
52
- padding: 10px;
53
  background: var(--bg);
54
  color: white;
55
  border: 1px solid var(--border);
56
- border-radius: 6px;
57
  cursor: pointer;
58
  outline: none;
 
 
59
  }
60
 
61
- /* مساحة الدردشة */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  .chat-container {
63
  flex: 1;
64
  display: flex;
65
  flex-direction: column;
66
  position: relative;
 
67
  }
68
 
69
  #chat-flow {
70
  flex: 1;
71
- padding: 40px 15% 100px;
72
  overflow-y: auto;
73
  display: flex;
74
  flex-direction: column;
@@ -77,62 +156,111 @@
77
 
78
  .message {
79
  display: flex;
80
- gap: 15px;
81
- max-width: 90%;
82
  animation: fadeIn 0.3s ease;
83
  }
84
 
85
- @keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
 
 
 
86
 
87
  .message.user { align-self: flex-end; flex-direction: row-reverse; }
88
  .message.ai { align-self: flex-start; }
89
 
90
  .avatar {
91
- width: 35px;
92
- height: 35px;
93
- border-radius: 6px;
94
  display: flex;
95
  align-items: center;
96
  justify-content: center;
97
  flex-shrink: 0;
 
98
  }
99
- .user .avatar { background: #1f6feb; }
100
- .ai .avatar { background: var(--accent); }
101
 
102
  .bubble {
103
- padding: 12px 16px;
104
  border-radius: 12px;
105
  line-height: 1.6;
106
  font-size: 15px;
107
- white-space: pre-wrap; /* للحفاظ على تنسيق الأسطر */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  }
109
- .user .bubble { background: var(--user-msg); border: 1px solid var(--border); }
110
- .ai .bubble { background: transparent; }
 
 
 
 
 
 
 
 
 
 
 
111
 
112
- /* منطقة الإدخال العائمة */
113
  .input-wrapper {
114
  position: absolute;
115
  bottom: 30px;
116
  left: 50%;
117
  transform: translateX(-50%);
118
- width: 70%;
 
119
  background: var(--sidebar);
120
  border: 1px solid var(--border);
121
- border-radius: 12px;
122
- padding: 10px;
123
  display: flex;
124
  align-items: center;
125
- box-shadow: 0 8px 24px rgba(0,0,0,0.5);
 
 
126
  }
 
 
127
 
128
  #userInput {
129
  flex: 1;
130
  background: transparent;
131
  border: none;
132
  color: white;
133
- padding: 10px;
134
  font-size: 16px;
135
  outline: none;
 
136
  }
137
 
138
  .send-btn {
@@ -141,14 +269,75 @@
141
  border: none;
142
  width: 40px;
143
  height: 40px;
144
- border-radius: 8px;
145
  cursor: pointer;
146
- transition: 0.2s;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  }
148
- .send-btn:hover { filter: brightness(1.2); }
149
- .send-btn:disabled { background: #30363d; cursor: not-allowed; }
150
 
151
  img { max-width: 100%; border-radius: 8px; margin-top: 10px; border: 1px solid var(--border); }
 
 
 
 
 
 
152
  </style>
153
  </head>
154
  <body>
@@ -157,17 +346,36 @@
157
  <div class="brand"><i class="fas fa-bolt"></i> Genisi AI</div>
158
 
159
  <div class="config-group">
160
- <label>الموديل الحالي</label>
161
- <select id="actionType">
162
- <option value="chat">الدردشة الذكية (Kimi)</option>
163
- <option value="code">مساعد الكود (Gemma)</option>
164
- <option value="image">توليد الصور (Flux)</option>
165
  </select>
166
  </div>
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  <div style="margin-top: auto; border-top: 1px solid var(--border); padding-top: 20px;">
169
- <p style="font-size: 12px; color: #8b949e;">المطور: <span style="color: white;">AnesNT</span></p>
170
- <p style="font-size: 11px; color: #484f58; margin-top: 5px;">Project Genisi v3.5 (Streaming Active)</p>
 
 
 
 
171
  </div>
172
  </aside>
173
 
@@ -175,64 +383,105 @@
175
  <div id="chat-flow">
176
  <div class="message ai">
177
  <div class="avatar"><i class="fas fa-robot"></i></div>
178
- <div class="bubble">مرحباً أنس! نظام Genisi المتطور جاهز. اسألني أي شيء وسأجيبك فوراً بتقنية الـ Stream.</div>
 
 
 
 
 
 
 
 
 
179
  </div>
180
  </div>
181
 
182
  <div class="input-wrapper">
183
  <input type="text" id="userInput" placeholder="اكتب رسالتك هنا..." autocomplete="off">
184
- <button class="send-btn" id="sendBtn" onclick="handleSend()"><i class="fas fa-paper-plane"></i></button>
 
 
185
  </div>
186
  </main>
187
 
188
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  async function handleSend() {
190
  const input = document.getElementById('userInput');
191
  const chatFlow = document.getElementById('chat-flow');
192
  const action = document.getElementById('actionType').value;
 
193
  const btn = document.getElementById('sendBtn');
194
  const text = input.value.trim();
195
 
196
  if (!text) return;
197
 
198
- // تعطيل الإدخال أثناء المعالجة
199
  input.value = "";
200
  input.disabled = true;
201
  btn.disabled = true;
202
 
203
  // إضافة رسالة المستخدم
204
- addMessage(text, 'user');
205
 
206
- // إنشاء مكان لرد الذكاء الاصطناعي
207
- const aiMsgId = addMessage("", 'ai');
208
  const aiBubble = document.getElementById(aiMsgId).querySelector('.bubble');
 
 
 
 
 
 
209
 
210
  try {
211
  const response = await fetch('/api/genisi', {
212
  method: 'POST',
213
  headers: { 'Content-Type': 'application/json' },
214
- body: JSON.stringify({ action, message: text })
 
 
 
 
215
  });
216
 
217
  if (action === 'image') {
218
- // معالجة الصور (لا تدعم الاستريم)
219
  const data = await response.json();
220
  if (data.success) {
221
- aiBubble.innerHTML = `<img src="data:image/png;base64,${data.data}">`;
222
  } else {
223
- aiBubble.textContent = "خطأ: " + data.error;
224
  }
225
  } else {
226
- // معالجة النصوص بتقنية الـ Streaming
227
  const reader = response.body.getReader();
228
  const decoder = new TextDecoder();
229
  let fullText = "";
 
230
 
231
  while (true) {
232
  const { done, value } = await reader.read();
233
  if (done) break;
234
 
235
- const chunk = decoder.decode(value);
236
  const lines = chunk.split('\n');
237
 
238
  for (const line of lines) {
@@ -243,19 +492,30 @@
243
  try {
244
  const parsed = JSON.parse(jsonStr);
245
  if (parsed.content) {
 
 
 
 
246
  fullText += parsed.content;
247
- aiBubble.textContent = fullText; // تحديث النص فوراً
 
 
 
 
 
248
  chatFlow.scrollTop = chatFlow.scrollHeight;
249
  } else if (parsed.error) {
250
- aiBubble.textContent = "خطأ: " + parsed.error;
251
  }
252
- } catch (e) {}
 
 
253
  }
254
  }
255
  }
256
  }
257
  } catch (error) {
258
- aiBubble.textContent = "فشل الاتصال بالسيرفر. تأكد من عمل Backend.";
259
  } finally {
260
  input.disabled = false;
261
  btn.disabled = false;
@@ -263,15 +523,27 @@
263
  }
264
  }
265
 
266
- function addMessage(text, role) {
267
  const chatFlow = document.getElementById('chat-flow');
268
  const msgId = 'msg-' + Date.now();
269
  const icon = role === 'user' ? 'fa-user' : 'fa-robot';
270
 
 
 
 
 
 
 
 
 
 
271
  const html = `
272
  <div class="message ${role}" id="${msgId}">
273
  <div class="avatar"><i class="fas ${icon}"></i></div>
274
- <div class="bubble">${text}</div>
 
 
 
275
  </div>
276
  `;
277
 
@@ -280,10 +552,19 @@
280
  return msgId;
281
  }
282
 
283
- // دعم زر Enter
 
 
 
 
 
 
284
  document.getElementById('userInput').addEventListener('keypress', (e) => {
285
  if (e.key === 'Enter') handleSend();
286
  });
 
 
 
287
  </script>
288
  </body>
289
  </html>
 
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
+
14
  <style>
15
  :root {
16
  --bg: #0d1117;
17
  --sidebar: #161b22;
18
+ --accent: #238636;
19
+ --accent-hover: #2ea043;
20
  --text: #c9d1d9;
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; }
 
31
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
32
  display: flex;
33
  height: 100vh;
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;
43
  flex-direction: column;
44
+ padding: 24px;
45
  }
46
 
47
  .brand {
48
+ font-size: 24px;
49
  font-weight: 800;
50
  color: white;
51
+ margin-bottom: 32px;
52
  display: flex;
53
  align-items: center;
54
  gap: 12px;
55
  }
56
 
57
+ .config-group { margin-bottom: 24px; }
58
+ .config-group label {
59
+ display: block;
60
+ font-size: 12px;
61
+ color: var(--text-secondary);
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);
72
  color: white;
73
  border: 1px solid var(--border);
74
+ border-radius: 8px;
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;
143
  flex-direction: column;
144
  position: relative;
145
+ background: var(--bg);
146
  }
147
 
148
  #chat-flow {
149
  flex: 1;
150
+ padding: 40px 10% 120px;
151
  overflow-y: auto;
152
  display: flex;
153
  flex-direction: column;
 
156
 
157
  .message {
158
  display: flex;
159
+ gap: 16px;
160
+ max-width: 85%;
161
  animation: fadeIn 0.3s ease;
162
  }
163
 
164
+ @keyframes fadeIn {
165
+ from { opacity: 0; transform: translateY(10px); }
166
+ to { opacity: 1; transform: translateY(0); }
167
+ }
168
 
169
  .message.user { align-self: flex-end; flex-direction: row-reverse; }
170
  .message.ai { align-self: flex-start; }
171
 
172
  .avatar {
173
+ width: 36px;
174
+ height: 36px;
175
+ border-radius: 8px;
176
  display: flex;
177
  align-items: center;
178
  justify-content: center;
179
  flex-shrink: 0;
180
+ font-size: 16px;
181
  }
182
+ .user .avatar { background: #1f6feb; color: white; }
183
+ .ai .avatar { background: var(--accent); color: white; }
184
 
185
  .bubble {
186
+ padding: 16px;
187
  border-radius: 12px;
188
  line-height: 1.6;
189
  font-size: 15px;
190
+ border: 1px solid transparent;
191
+ word-wrap: break-word;
192
+ }
193
+
194
+ .user .bubble {
195
+ background: var(--user-msg);
196
+ border-color: var(--border);
197
+ color: white;
198
+ }
199
+
200
+ .ai .bubble {
201
+ background: transparent;
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;
238
  left: 50%;
239
  transform: translateX(-50%);
240
+ width: 80%;
241
+ max-width: 900px;
242
  background: var(--sidebar);
243
  border: 1px solid var(--border);
244
+ border-radius: 16px;
245
+ padding: 12px;
246
  display: flex;
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); }
254
 
255
  #userInput {
256
  flex: 1;
257
  background: transparent;
258
  border: none;
259
  color: white;
260
+ padding: 12px;
261
  font-size: 16px;
262
  outline: none;
263
+ font-family: inherit;
264
  }
265
 
266
  .send-btn {
 
269
  border: none;
270
  width: 40px;
271
  height: 40px;
272
+ border-radius: 10px;
273
  cursor: pointer;
274
+ transition: all 0.2s;
275
+ display: flex;
276
+ align-items: center;
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; }
340
+ ::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
341
  </style>
342
  </head>
343
  <body>
 
346
  <div class="brand"><i class="fas fa-bolt"></i> Genisi AI</div>
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;">
373
+ <p style="font-size: 12px; color: var(--text-secondary);">
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>
381
 
 
383
  <div id="chat-flow">
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>
404
  </div>
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
+
426
  async function handleSend() {
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;
440
 
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) {
481
  const { done, value } = await reader.read();
482
  if (done) break;
483
 
484
+ const chunk = decoder.decode(value, { stream: true });
485
  const lines = chunk.split('\n');
486
 
487
  for (const line of lines) {
 
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
  }
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';
530
 
531
+ let badges = '';
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>
548
  `;
549
 
 
552
  return msgId;
553
  }
554
 
555
+ function escapeHtml(text) {
556
+ const div = document.createElement('div');
557
+ div.textContent = text;
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>