AnesKAM commited on
Commit
90451b3
ยท
verified ยท
1 Parent(s): 6826fd7

Update frontend/index.html

Browse files
Files changed (1) hide show
  1. frontend/index.html +104 -66
frontend/index.html CHANGED
@@ -14,7 +14,6 @@
14
  --text: #e8eaf2; --text2: #9aa3be; --text3: #5c6480;
15
  --user-bubble: #1a2340; --bot-bubble: #161920;
16
  --danger: #f75f5f;
17
- /* ุงู„ุญูˆุงู ุงู„ุฏุงุฆุฑูŠุฉ ุงู„ู†ุงุนู…ุฉ ุฌุฏุงู‹ */
18
  --radius: 28px; --radius-sm: 18px; --radius-pill: 50px;
19
  --sidebar-w: 280px; --tr: 0.3s cubic-bezier(.4,0,.2,1);
20
  }
@@ -45,7 +44,7 @@
45
  .btn-new{margin:12px 16px;padding:12px 16px;background:linear-gradient(135deg,var(--accent),var(--accent2));
46
  color:#fff;border:none;border-radius:var(--radius-pill);cursor:pointer;font-family:'Cairo',sans-serif;
47
  font-size:.95rem;font-weight:600;display:flex;align-items:center;gap:8px; justify-content:center;
48
- transition:opacity var(--tr),transform var(--tr); box-shadow: 0 4px 15px var(--accent-soft);}
49
  .btn-new:hover{opacity:.9;transform:translateY(-2px)}
50
  .s-label{padding:10px 20px;font-size:.75rem;font-weight:700;color:var(--text3);letter-spacing:.08em;text-transform:uppercase}
51
  .chats-list{flex:1;overflow-y:auto;padding:4px 12px;display:flex;flex-direction:column;gap:6px}
@@ -84,16 +83,10 @@
84
  font-size:.9rem;color:var(--text);cursor:pointer;transition:all var(--tr); box-shadow: 0 4px 12px rgba(0,0,0,0.05);}
85
  .chip:hover{background:var(--accent-soft);border-color:var(--accent);color:var(--accent); transform:translateY(-2px);}
86
 
87
- /* MESSAGES & ANIMATIONS */
88
  .msg-row{display:flex;padding:8px 30px;gap:16px; animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;}
89
- @keyframes popIn {
90
- from { opacity: 0; transform: translateY(15px) scale(0.98); filter: blur(4px); }
91
- to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
92
- }
93
- @keyframes fadeSlideUp {
94
- from { opacity: 0; transform: translateY(20px); }
95
- to { opacity: 1; transform: translateY(0); }
96
- }
97
  .msg-row.user{flex-direction:row-reverse}
98
  .msg-av{width:38px;height:38px;border-radius:14px;flex-shrink:0;display:flex;align-items:center;
99
  justify-content:center;font-size:1.1rem;font-weight:700;margin-top:2px;overflow:hidden;
@@ -104,36 +97,17 @@
104
 
105
  .bubble{max-width:min(700px,80vw);padding:16px 22px;border-radius:var(--radius);
106
  font-size:.98rem;line-height:1.75;word-break:break-word; box-shadow: 0 4px 15px rgba(0,0,0,0.03);}
107
- .msg-row.bot .bubble{background:var(--bot-bubble);border:1px solid var(--border);border-top-left-radius:6px}
108
- [dir="rtl"] .msg-row.bot .bubble { border-top-left-radius:var(--radius); border-top-right-radius:6px; }
109
  .msg-row.user .bubble{background:var(--user-bubble);border:none; border-top-right-radius:6px}
110
  [dir="rtl"] .msg-row.user .bubble { border-top-right-radius:var(--radius); border-top-left-radius:6px; }
111
 
112
- /* GEMINI STREAMING EFFECT */
113
- .gemini-cursor {
114
- display: inline-block;
115
- width: 14px; height: 14px;
116
- margin-inline-start: 6px;
117
- background: linear-gradient(135deg, var(--accent), var(--accent2));
118
- mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 0l2.5 9.5L24 12l-9.5 2.5L12 24l-2.5-9.5L0 12l9.5-2.5z"/></svg>');
119
- -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 0l2.5 9.5L24 12l-9.5 2.5L12 24l-2.5-9.5L0 12l9.5-2.5z"/></svg>');
120
- mask-size: cover; -webkit-mask-size: cover;
121
- animation: spinPulse 1s infinite linear;
122
- transform-origin: center;
123
- vertical-align: middle;
124
- }
125
- @keyframes spinPulse {
126
- 0% { transform: scale(0.8) rotate(0deg); opacity: 0.5; }
127
- 50% { transform: scale(1.2) rotate(90deg); opacity: 1; filter: drop-shadow(0 0 5px var(--accent)); }
128
- 100% { transform: scale(0.8) rotate(180deg); opacity: 0.5; }
129
- }
130
 
131
  /* MARKDOWN STYLES */
132
  .bubble p{margin-bottom:12px}.bubble p:last-child{margin-bottom:0}
133
  .bubble ul,.bubble ol{padding-inline-start:24px;margin:12px 0}
134
  .bubble li {margin-bottom: 6px;}
135
-
136
- /* Tables */
137
  .bubble table {width:100%;border-collapse:hidden;margin:16px 0; border-radius: var(--radius-sm); overflow:hidden; border: 1px solid var(--border);}
138
  .bubble th, .bubble td {border:1px solid var(--border);padding:10px 14px;text-align:start;}
139
  .bubble th {background:var(--surface3);font-weight:600;}
@@ -146,16 +120,26 @@
146
  .code-container pre {margin:0; padding:16px; overflow-x:auto; font-family:'JetBrains Mono',monospace; font-size:0.85rem;}
147
  .bubble code:not(pre code) {font-family:'JetBrains Mono',monospace;font-size:.85rem;background:var(--surface3);padding:3px 6px;border-radius:6px; color:var(--accent);}
148
 
149
- /* memory badge */
 
 
 
 
 
150
  .mem-badge{font-size:.75rem;color:var(--text3);padding:4px 30px 10px;display:flex;align-items:center;gap:6px; font-weight: 600;}
151
 
152
- /* INPUT - FLOATING PILL DESIGN */
153
- .input-area{padding:0 24px 30px; display:flex; justify-content:center; flex-shrink:0;}
154
  .input-wrapper{width:100%; max-width:850px; position:relative;}
 
155
  .input-box{display:flex;align-items:flex-end;gap:12px;background:var(--surface);
156
- border:1px solid var(--border);border-radius:32px;padding:12px 16px 12px 24px;
157
- transition:all var(--tr); box-shadow: 0 8px 30px rgba(0,0,0,0.15);}[dir="rtl"] .input-box {padding:12px 24px 12px 16px;}
158
  .input-box:focus-within{border-color:var(--accent); box-shadow: 0 8px 30px var(--accent-soft), 0 0 0 3px var(--accent-soft);}
 
 
 
 
159
  .input-box textarea{flex:1;background:none;border:none;outline:none;color:var(--text);
160
  font-family:'Cairo',sans-serif;font-size:.98rem;resize:none;max-height:160px;line-height:1.6; padding: 6px 0;}
161
  .input-box textarea::placeholder{color:var(--text3)}
@@ -163,8 +147,7 @@
163
  .btn-send{width:42px;height:42px;background:linear-gradient(135deg,var(--accent),var(--accent2));
164
  border:none;border-radius:50%;cursor:pointer;color:#fff;display:flex;align-items:center;
165
  justify-content:center;font-size:1.1rem;transition:all var(--tr); flex-shrink:0; margin-bottom: 2px;}
166
- .btn-send:hover{opacity:.9;transform:scale(1.08) rotate(-10deg);}
167
- [dir="rtl"] .btn-send:hover{transform:scale(1.08) rotate(10deg);}
168
  .btn-send:disabled{opacity:.4;cursor:not-allowed;transform:none;}
169
 
170
  /* MODAL */
@@ -228,8 +211,11 @@
228
  <div class="chat-area" id="chat-area"></div>
229
 
230
  <div class="input-area">
 
231
  <div class="input-wrapper">
232
  <div class="input-box">
 
 
233
  <textarea id="msg-input" rows="1" onkeydown="handleKey(event)" oninput="autoResize(this)" placeholder="Type a message..."></textarea>
234
  <button class="btn-send" id="send-btn" onclick="sendMessage()">โžค</button>
235
  </div>
@@ -302,26 +288,29 @@ function applyI18n() {
302
  if(!activeChatId) renderWelcome();
303
  renderChatList();
304
  }
305
-
306
  function changeLanguage(val) { currentLang = val; localStorage.setItem('genisi_lang', val); applyI18n(); }
307
 
308
  // โ•โ•๏ฟฝ๏ฟฝ๏ฟฝโ•โ•โ•โ•โ• STATE & CONFIG โ•โ•โ•โ•โ•โ•โ•โ•
309
  let chats = JSON.parse(localStorage.getItem('genisi_chats') || '[]');
310
  let activeChatId = null;
311
  let isGenerating = false;
 
312
 
313
- // โ•โ•โ•โ•โ•โ•โ•โ• MARKDOWN PARSER (marked.js) โ•โ•โ•โ•โ•โ•โ•โ•
314
  const renderer = new marked.Renderer();
315
- renderer.code = function(code, language) {
316
- const validLang = language || 'text';
317
- const escapedCode = code.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
 
 
 
318
  return `
319
  <div class="code-container">
320
  <div class="code-header">
321
- <span>${validLang}</span>
322
- <button class="copy-btn" onclick="copyCode(this, '${encodeURIComponent(code)}')">๐Ÿ“‹ Copy</button>
323
  </div>
324
- <pre><code class="language-${validLang}">${escapedCode}</code></pre>
325
  </div>`;
326
  };
327
  marked.setOptions({ renderer: renderer, breaks: true, gfm: true });
@@ -334,17 +323,46 @@ function copyCode(btn, encodedCode) {
334
  });
335
  }
336
 
337
- // โ•โ•โ•โ•โ•โ•โ•โ• UTILS โ•โ•โ•โ•โ•โ•โ•โ•
338
  const genId = () => Date.now().toString(36);
339
  const saveChats = () => localStorage.setItem('genisi_chats', JSON.stringify(chats));
340
  const getChat = (id) => chats.find(c => c.id === (id ?? activeChatId));
341
  function esc(t){ return String(t).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
342
- // Auto scroll smoothly to bottom
343
  function scrollToBottom() {
344
  const area = document.getElementById('chat-area');
345
  area.scrollTop = area.scrollHeight;
346
  }
347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  // โ•โ•โ•โ•โ•โ•โ•โ• THEME โ•โ•โ•โ•โ•โ•โ•โ•
349
  function applyTheme(t){
350
  document.documentElement.setAttribute('data-theme',t);
@@ -390,7 +408,7 @@ function renderWelcome(){
390
  </div>`;
391
  }
392
 
393
- function newChat(){ activeChatId=null; document.getElementById('msg-input').value=''; renderWelcome(); renderChatList(); }
394
 
395
  function loadChat(id){
396
  activeChatId=id;
@@ -399,7 +417,7 @@ function loadChat(id){
399
  const area=document.getElementById('chat-area');
400
  area.innerHTML='';
401
  chat.history.forEach((entry, idx)=>{
402
- appendBubble('user', entry.user, false);
403
  appendBubble('bot', entry.bot, true);
404
  appendMemBadge(idx+1, chat.history.length);
405
  });
@@ -421,8 +439,9 @@ function autoResize(el){ el.style.height='auto'; el.style.height=Math.min(el.scr
421
  async function sendMessage(){
422
  if(isGenerating) return;
423
  const input=document.getElementById('msg-input');
424
- const text=input.value.trim();
425
- if(!text) return;
 
426
 
427
  const welcome=document.getElementById('welcome');
428
  if(welcome) welcome.remove();
@@ -431,24 +450,39 @@ async function sendMessage(){
431
 
432
  if(!activeChatId){
433
  activeChatId=genId();
434
- chats.push({id:activeChatId, title:text.slice(0,35)+'...', history:[]});
435
- document.getElementById('topbar-title').textContent=text.slice(0,35)+'...';
 
436
  }
437
 
438
  const chat = getChat();
439
- appendBubble('user', text, false);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
440
 
441
  isGenerating=true;
442
  document.getElementById('send-btn').disabled=true;
443
 
444
- // ุฅู†ุดุงุก ุนู†ุตุฑ ุงู„ู…ุญุงุฏุซุฉ ู…ุน ุฅุธู‡ุงุฑู‡ ุจุฃู†ูŠู…ูŠุดู†
445
  const botContentDiv = appendBubble('bot', '', true);
446
 
447
  try {
448
  const response = await fetch('/chat', {
449
  method: 'POST',
450
  headers: {'Content-Type':'application/json'},
451
- body: JSON.stringify({ message: text, history: chat.history })
452
  });
453
 
454
  if(!response.ok) throw new Error("Server Error");
@@ -464,17 +498,14 @@ async function sendMessage(){
464
  const chunk = decoder.decode(value, {stream: true});
465
  fullBotResponse += chunk;
466
 
467
- // ุฏู…ุฌ ุงู„ู…ุงุฑูƒุฏุงูˆู† ู…ุน "ู…ุคุดุฑ ุฌูŠู…ูŠู†ูŠ ุงู„ู„ุงู…ุน"
468
  botContentDiv.innerHTML = marked.parse(fullBotResponse) + '<span class="gemini-cursor"></span>';
469
-
470
  scrollToBottom();
471
  }
472
 
473
- // ุจุนุฏ ุงู„ุงู†ุชู‡ุงุกุŒ ู†ุญุฐู ุงู„ู…ุคุดุฑ ุงู„ู„ุงู…ุน ูˆู†ุถุน ุงู„ู†ุต ุงู„ู†ู‡ุงุฆูŠ
474
  botContentDiv.innerHTML = marked.parse(fullBotResponse);
475
 
476
- // Save to history
477
- chat.history.push({ user: text, bot: fullBotResponse });
478
  saveChats();
479
  appendMemBadge(chat.history.length, chat.history.length);
480
 
@@ -487,7 +518,7 @@ async function sendMessage(){
487
  renderChatList();
488
  }
489
 
490
- function appendBubble(role, text, isMarkdown){
491
  const area=document.getElementById('chat-area');
492
  const row=document.createElement('div'); row.className=`msg-row ${role}`;
493
  const av=document.createElement('div'); av.className='msg-av';
@@ -498,8 +529,15 @@ function appendBubble(role, text, isMarkdown){
498
 
499
  const bub=document.createElement('div'); bub.className='bubble';
500
 
 
 
 
 
 
 
 
501
  const contentDiv = document.createElement('div');
502
- if(text) contentDiv.innerHTML = isMarkdown ? marked.parse(text) : esc(text);
503
  bub.appendChild(contentDiv);
504
 
505
  row.appendChild(av); row.appendChild(bub);
 
14
  --text: #e8eaf2; --text2: #9aa3be; --text3: #5c6480;
15
  --user-bubble: #1a2340; --bot-bubble: #161920;
16
  --danger: #f75f5f;
 
17
  --radius: 28px; --radius-sm: 18px; --radius-pill: 50px;
18
  --sidebar-w: 280px; --tr: 0.3s cubic-bezier(.4,0,.2,1);
19
  }
 
44
  .btn-new{margin:12px 16px;padding:12px 16px;background:linear-gradient(135deg,var(--accent),var(--accent2));
45
  color:#fff;border:none;border-radius:var(--radius-pill);cursor:pointer;font-family:'Cairo',sans-serif;
46
  font-size:.95rem;font-weight:600;display:flex;align-items:center;gap:8px; justify-content:center;
47
+ transition:all var(--tr); box-shadow: 0 4px 15px var(--accent-soft);}
48
  .btn-new:hover{opacity:.9;transform:translateY(-2px)}
49
  .s-label{padding:10px 20px;font-size:.75rem;font-weight:700;color:var(--text3);letter-spacing:.08em;text-transform:uppercase}
50
  .chats-list{flex:1;overflow-y:auto;padding:4px 12px;display:flex;flex-direction:column;gap:6px}
 
83
  font-size:.9rem;color:var(--text);cursor:pointer;transition:all var(--tr); box-shadow: 0 4px 12px rgba(0,0,0,0.05);}
84
  .chip:hover{background:var(--accent-soft);border-color:var(--accent);color:var(--accent); transform:translateY(-2px);}
85
 
86
+ /* MESSAGES */
87
  .msg-row{display:flex;padding:8px 30px;gap:16px; animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;}
88
+ @keyframes popIn { from { opacity: 0; transform: translateY(15px) scale(0.98); filter: blur(4px); } to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); } }
89
+ @keyframes fadeSlideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
 
 
 
 
 
 
90
  .msg-row.user{flex-direction:row-reverse}
91
  .msg-av{width:38px;height:38px;border-radius:14px;flex-shrink:0;display:flex;align-items:center;
92
  justify-content:center;font-size:1.1rem;font-weight:700;margin-top:2px;overflow:hidden;
 
97
 
98
  .bubble{max-width:min(700px,80vw);padding:16px 22px;border-radius:var(--radius);
99
  font-size:.98rem;line-height:1.75;word-break:break-word; box-shadow: 0 4px 15px rgba(0,0,0,0.03);}
100
+ .msg-row.bot .bubble{background:var(--bot-bubble);border:1px solid var(--border);border-top-left-radius:6px}[dir="rtl"] .msg-row.bot .bubble { border-top-left-radius:var(--radius); border-top-right-radius:6px; }
 
101
  .msg-row.user .bubble{background:var(--user-bubble);border:none; border-top-right-radius:6px}
102
  [dir="rtl"] .msg-row.user .bubble { border-top-right-radius:var(--radius); border-top-left-radius:6px; }
103
 
104
+ .gemini-cursor { display: inline-block; width: 14px; height: 14px; margin-inline-start: 6px; background: linear-gradient(135deg, var(--accent), var(--accent2)); mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 0l2.5 9.5L24 12l-9.5 2.5L12 24l-2.5-9.5L0 12l9.5-2.5z"/></svg>'); -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 0l2.5 9.5L24 12l-9.5 2.5L12 24l-2.5-9.5L0 12l9.5-2.5z"/></svg>'); mask-size: cover; -webkit-mask-size: cover; animation: spinPulse 1s infinite linear; transform-origin: center; vertical-align: middle; }
105
+ @keyframes spinPulse { 0% { transform: scale(0.8) rotate(0deg); opacity: 0.5; } 50% { transform: scale(1.2) rotate(90deg); opacity: 1; filter: drop-shadow(0 0 5px var(--accent)); } 100% { transform: scale(0.8) rotate(180deg); opacity: 0.5; } }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
  /* MARKDOWN STYLES */
108
  .bubble p{margin-bottom:12px}.bubble p:last-child{margin-bottom:0}
109
  .bubble ul,.bubble ol{padding-inline-start:24px;margin:12px 0}
110
  .bubble li {margin-bottom: 6px;}
 
 
111
  .bubble table {width:100%;border-collapse:hidden;margin:16px 0; border-radius: var(--radius-sm); overflow:hidden; border: 1px solid var(--border);}
112
  .bubble th, .bubble td {border:1px solid var(--border);padding:10px 14px;text-align:start;}
113
  .bubble th {background:var(--surface3);font-weight:600;}
 
120
  .code-container pre {margin:0; padding:16px; overflow-x:auto; font-family:'JetBrains Mono',monospace; font-size:0.85rem;}
121
  .bubble code:not(pre code) {font-family:'JetBrains Mono',monospace;font-size:.85rem;background:var(--surface3);padding:3px 6px;border-radius:6px; color:var(--accent);}
122
 
123
+ /* Files */
124
+ .file-chip {display:inline-flex; align-items:center; gap:6px; background:var(--surface2); border:1px solid var(--border); border-radius:var(--radius-pill); padding:4px 12px; font-size:0.85rem; margin:0 4px 8px 0; color:var(--text);}
125
+ .file-chip button {background:none; border:none; color:var(--danger); cursor:pointer; font-size:1rem; padding:0; margin-left:4px; transition:transform 0.2s;}
126
+ .file-chip button:hover {transform:scale(1.2);}
127
+ .file-prev {display:flex; align-items:center; gap:8px; background:var(--surface3); padding:8px 12px; border-radius:8px; margin-bottom:8px; font-size:0.85rem;}
128
+
129
  .mem-badge{font-size:.75rem;color:var(--text3);padding:4px 30px 10px;display:flex;align-items:center;gap:6px; font-weight: 600;}
130
 
131
+ /* INPUT */
132
+ .input-area{padding:0 24px 30px; display:flex; flex-direction:column; align-items:center; flex-shrink:0;}
133
  .input-wrapper{width:100%; max-width:850px; position:relative;}
134
+ .file-chips-container {width:100%; max-width:850px; display:flex; flex-wrap:wrap; margin-bottom:8px;}
135
  .input-box{display:flex;align-items:flex-end;gap:12px;background:var(--surface);
136
+ border:1px solid var(--border);border-radius:32px;padding:12px 16px 12px 16px;
137
+ transition:all var(--tr); box-shadow: 0 8px 30px rgba(0,0,0,0.15);}
138
  .input-box:focus-within{border-color:var(--accent); box-shadow: 0 8px 30px var(--accent-soft), 0 0 0 3px var(--accent-soft);}
139
+
140
+ .btn-attach{background:none; border:none; color:var(--text3); cursor:pointer; font-size:1.3rem; padding:6px; border-radius:50%; transition:all var(--tr); display:flex; align-items:center; justify-content:center;}
141
+ .btn-attach:hover{color:var(--accent); background:var(--surface2);}
142
+
143
  .input-box textarea{flex:1;background:none;border:none;outline:none;color:var(--text);
144
  font-family:'Cairo',sans-serif;font-size:.98rem;resize:none;max-height:160px;line-height:1.6; padding: 6px 0;}
145
  .input-box textarea::placeholder{color:var(--text3)}
 
147
  .btn-send{width:42px;height:42px;background:linear-gradient(135deg,var(--accent),var(--accent2));
148
  border:none;border-radius:50%;cursor:pointer;color:#fff;display:flex;align-items:center;
149
  justify-content:center;font-size:1.1rem;transition:all var(--tr); flex-shrink:0; margin-bottom: 2px;}
150
+ .btn-send:hover{opacity:.9;transform:scale(1.08) rotate(-10deg);}[dir="rtl"] .btn-send:hover{transform:scale(1.08) rotate(10deg);}
 
151
  .btn-send:disabled{opacity:.4;cursor:not-allowed;transform:none;}
152
 
153
  /* MODAL */
 
211
  <div class="chat-area" id="chat-area"></div>
212
 
213
  <div class="input-area">
214
+ <div class="file-chips-container" id="file-chips"></div>
215
  <div class="input-wrapper">
216
  <div class="input-box">
217
+ <input type="file" id="file-input" multiple hidden onchange="handleFiles(this.files)" />
218
+ <button class="btn-attach" onclick="document.getElementById('file-input').click()">๐Ÿ“Ž</button>
219
  <textarea id="msg-input" rows="1" onkeydown="handleKey(event)" oninput="autoResize(this)" placeholder="Type a message..."></textarea>
220
  <button class="btn-send" id="send-btn" onclick="sendMessage()">โžค</button>
221
  </div>
 
288
  if(!activeChatId) renderWelcome();
289
  renderChatList();
290
  }
 
291
  function changeLanguage(val) { currentLang = val; localStorage.setItem('genisi_lang', val); applyI18n(); }
292
 
293
  // โ•โ•๏ฟฝ๏ฟฝ๏ฟฝโ•โ•โ•โ•โ• STATE & CONFIG โ•โ•โ•โ•โ•โ•โ•โ•
294
  let chats = JSON.parse(localStorage.getItem('genisi_chats') || '[]');
295
  let activeChatId = null;
296
  let isGenerating = false;
297
+ let pendingFiles =[];
298
 
299
+ // โ•โ•โ•โ•โ•โ•โ•โ• MARKDOWN PARSER (FIXED) โ•โ•โ•โ•โ•โ•โ•โ•
300
  const renderer = new marked.Renderer();
301
+ renderer.code = function(token) {
302
+ // Fix for newer marked.js versions that pass an object instead of string
303
+ const codeText = typeof token === 'string' ? token : token.text || '';
304
+ const lang = typeof token === 'string' ? arguments[1] : token.lang || 'text';
305
+
306
+ const escapedCode = String(codeText).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
307
  return `
308
  <div class="code-container">
309
  <div class="code-header">
310
+ <span>${lang}</span>
311
+ <button class="copy-btn" onclick="copyCode(this, '${encodeURIComponent(codeText)}')">๐Ÿ“‹ Copy</button>
312
  </div>
313
+ <pre><code class="language-${lang}">${escapedCode}</code></pre>
314
  </div>`;
315
  };
316
  marked.setOptions({ renderer: renderer, breaks: true, gfm: true });
 
323
  });
324
  }
325
 
326
+ // โ•โ•โ•โ•โ•โ•โ•โ• UTILS & FILES โ•โ•โ•โ•โ•โ•โ•โ•
327
  const genId = () => Date.now().toString(36);
328
  const saveChats = () => localStorage.setItem('genisi_chats', JSON.stringify(chats));
329
  const getChat = (id) => chats.find(c => c.id === (id ?? activeChatId));
330
  function esc(t){ return String(t).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
 
331
  function scrollToBottom() {
332
  const area = document.getElementById('chat-area');
333
  area.scrollTop = area.scrollHeight;
334
  }
335
 
336
+ // File Handling
337
+ async function handleFiles(files) {
338
+ for (let f of files) {
339
+ // ุงู„ุชุญู‚ู‚ ู…ู…ุง ุฅุฐุง ูƒุงู† ุงู„ู…ู„ู ู†ุตูŠุงู‹ ุฃูˆ ูƒูˆุฏ ุจุฑู…ุฌูŠ
340
+ const isText = f.type.startsWith('text/') || f.name.match(/\.(py|js|html|css|json|md|txt|csv|cpp|java)$/i);
341
+
342
+ const reader = new FileReader();
343
+ reader.onload = (e) => {
344
+ let data = e.target.result;
345
+ if (!isText) data = data.split(',')[1]; // ุงุณุชุฎุฑุงุฌ Base64 ูู‚ุท ู„ู„ุตูˆุฑ ูˆุงู„ู…ู„ูุงุช ุงู„ุซู†ุงุฆูŠุฉ
346
+
347
+ pendingFiles.push({ name: f.name, type: f.type || 'application/octet-stream', data: data, isText: isText });
348
+ renderFileChips();
349
+ };
350
+ if (isText) reader.readAsText(f);
351
+ else reader.readAsDataURL(f);
352
+ }
353
+ document.getElementById('file-input').value = ''; // Reset
354
+ }
355
+
356
+ function renderFileChips() {
357
+ const container = document.getElementById('file-chips');
358
+ container.innerHTML = '';
359
+ pendingFiles.forEach((f, idx) => {
360
+ const icon = f.isText ? '๐Ÿ“„' : '๐Ÿ–ผ๏ธ';
361
+ container.innerHTML += `<div class="file-chip">${icon} ${f.name} <button onclick="removeFile(${idx})">ร—</button></div>`;
362
+ });
363
+ }
364
+ function removeFile(idx) { pendingFiles.splice(idx, 1); renderFileChips(); }
365
+
366
  // โ•โ•โ•โ•โ•โ•โ•โ• THEME โ•โ•โ•โ•โ•โ•โ•โ•
367
  function applyTheme(t){
368
  document.documentElement.setAttribute('data-theme',t);
 
408
  </div>`;
409
  }
410
 
411
+ function newChat(){ activeChatId=null; pendingFiles=[]; renderFileChips(); document.getElementById('msg-input').value=''; renderWelcome(); renderChatList(); }
412
 
413
  function loadChat(id){
414
  activeChatId=id;
 
417
  const area=document.getElementById('chat-area');
418
  area.innerHTML='';
419
  chat.history.forEach((entry, idx)=>{
420
+ appendBubble('user', entry.user, false, entry.uiFiles);
421
  appendBubble('bot', entry.bot, true);
422
  appendMemBadge(idx+1, chat.history.length);
423
  });
 
439
  async function sendMessage(){
440
  if(isGenerating) return;
441
  const input=document.getElementById('msg-input');
442
+ let text = input.value.trim();
443
+
444
+ if(!text && pendingFiles.length === 0) return;
445
 
446
  const welcome=document.getElementById('welcome');
447
  if(welcome) welcome.remove();
 
450
 
451
  if(!activeChatId){
452
  activeChatId=genId();
453
+ const chatTitle = text ? text.slice(0,35)+'...' : pendingFiles[0].name;
454
+ chats.push({id:activeChatId, title:chatTitle, history:[]});
455
+ document.getElementById('topbar-title').textContent=chatTitle;
456
  }
457
 
458
  const chat = getChat();
459
+
460
+ // ุชุฌู‡ูŠุฒ ุงู„ู…ู„ูุงุช ู„ู„ุฅุฑุณุงู„
461
+ const uiFiles = pendingFiles.map(f => f.name); // ู„ู„ุนุฑุถ ููŠ ุงู„ูˆุงุฌู‡ุฉ ูู‚ุท
462
+ const binaryFiles =[]; // ู„ู„ุฅุฑุณุงู„ ู„ู„ุจุงูƒ ุงู†ุฏ
463
+
464
+ // ุฏู…ุฌ ุงู„ู†ุตูˆุต ุงู„ุจุฑู…ุฌูŠุฉ/ุงู„ู†ุตูŠุฉ ู…ุน ู†ุต ุงู„ุฑุณุงู„ุฉ
465
+ pendingFiles.forEach(f => {
466
+ if(f.isText) {
467
+ text += `\n\n\`\`\`${f.name.split('.').pop()}\n// File: ${f.name}\n${f.data}\n\`\`\``;
468
+ } else {
469
+ binaryFiles.push({ name: f.name, mime_type: f.type, data: f.data });
470
+ }
471
+ });
472
+
473
+ appendBubble('user', text, false, uiFiles);
474
+ pendingFiles =[]; renderFileChips();
475
 
476
  isGenerating=true;
477
  document.getElementById('send-btn').disabled=true;
478
 
 
479
  const botContentDiv = appendBubble('bot', '', true);
480
 
481
  try {
482
  const response = await fetch('/chat', {
483
  method: 'POST',
484
  headers: {'Content-Type':'application/json'},
485
+ body: JSON.stringify({ message: text, history: chat.history, files: binaryFiles })
486
  });
487
 
488
  if(!response.ok) throw new Error("Server Error");
 
498
  const chunk = decoder.decode(value, {stream: true});
499
  fullBotResponse += chunk;
500
 
 
501
  botContentDiv.innerHTML = marked.parse(fullBotResponse) + '<span class="gemini-cursor"></span>';
 
502
  scrollToBottom();
503
  }
504
 
 
505
  botContentDiv.innerHTML = marked.parse(fullBotResponse);
506
 
507
+ // ุญูุธ ุงู„ู…ุญุงุฏุซุฉ
508
+ chat.history.push({ user: text, bot: fullBotResponse, uiFiles: uiFiles });
509
  saveChats();
510
  appendMemBadge(chat.history.length, chat.history.length);
511
 
 
518
  renderChatList();
519
  }
520
 
521
+ function appendBubble(role, text, isMarkdown, filesList =[]){
522
  const area=document.getElementById('chat-area');
523
  const row=document.createElement('div'); row.className=`msg-row ${role}`;
524
  const av=document.createElement('div'); av.className='msg-av';
 
529
 
530
  const bub=document.createElement('div'); bub.className='bubble';
531
 
532
+ // ุนุฑุถ ุงู„ู…ู„ูุงุช ูƒุฑู‚ุงุฆู‚ ุฏุงุฎู„ ุฑุณุงู„ุฉ ุงู„ู…ุณุชุฎุฏู…
533
+ if(filesList && filesList.length > 0) {
534
+ filesList.forEach(name => {
535
+ bub.innerHTML += `<div class="file-prev">๐Ÿ“Ž ${esc(name)}</div>`;
536
+ });
537
+ }
538
+
539
  const contentDiv = document.createElement('div');
540
+ if(text) contentDiv.innerHTML = isMarkdown ? marked.parse(text) : esc(text).replace(/\n/g, '<br/>');
541
  bub.appendChild(contentDiv);
542
 
543
  row.appendChild(av); row.appendChild(bub);