gen / index.html
AnesKAM's picture
Update index.html
2a51ba7 verified
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kimi Reasoning Interface</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
:root {
--bg: #0d1117;
--sidebar: #161b22;
--surface: #21262d;
--border: #30363d;
--text: #e6edf3;
--text-secondary: #8b949e;
--accent-think: #a371f7; /* بنفسجي للتفكير */
--accent-fast: #238636; /* أخضر للسريع */
--reasoning-bg: #1f242c; /* خلفية صندوق التفكير */
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: var(--bg);
color: var(--text);
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
display: flex;
height: 100vh;
overflow: hidden;
line-height: 1.6;
}
.sidebar {
width: 300px;
background: var(--sidebar);
border-left: 1px solid var(--border);
padding: 24px;
display: flex;
flex-direction: column;
}
.brand {
font-size: 20px;
font-weight: 700;
margin-bottom: 32px;
display: flex;
align-items: center;
gap: 12px;
color: white;
}
.mode-selector {
display: flex;
gap: 8px;
background: var(--bg);
padding: 4px;
border-radius: 8px;
border: 1px solid var(--border);
margin-bottom: 24px;
}
.mode-btn {
flex: 1;
padding: 10px 14px;
border: none;
border-radius: 6px;
background: transparent;
color: var(--text-secondary);
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
.mode-btn.active.think {
background: rgba(163, 113, 247, 0.15);
color: var(--accent-think);
box-shadow: 0 0 0 1px rgba(163, 113, 247, 0.3);
}
.mode-btn.active.fast {
background: rgba(35, 134, 54, 0.15);
color: var(--accent-fast);
box-shadow: 0 0 0 1px rgba(35, 134, 54, 0.3);
}
.info-card {
background: rgba(163, 113, 247, 0.08);
border: 1px solid rgba(163, 113, 247, 0.2);
border-radius: 12px;
padding: 16px;
font-size: 13px;
color: var(--text-secondary);
line-height: 1.6;
}
.info-card h4 {
color: var(--accent-think);
margin-bottom: 8px;
font-size: 14px;
display: flex;
align-items: center;
gap: 8px;
}
.chat-container {
flex: 1;
display: flex;
flex-direction: column;
position: relative;
background: var(--bg);
}
#chat-flow {
flex: 1;
padding: 40px 10% 140px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 32px;
}
.message {
display: flex;
gap: 16px;
max-width: 90%;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.ai { align-self: flex-start; width: 100%; }
.avatar {
width: 36px; height: 36px;
border-radius: 8px;
display: flex; align-items: center; justify-content: center;
flex-shrink: 0;
font-size: 16px;
}
.user .avatar { background: #1f6feb; color: white; }
.ai.think .avatar {
background: var(--accent-think);
color: white;
box-shadow: 0 0 0 2px rgba(163, 113, 247, 0.3);
}
.ai.fast .avatar { background: var(--accent-fast); color: white; }
/* ✅ صندوق التفكير (Reasoning Box) */
.reasoning-container {
background: var(--reasoning-bg);
border: 1px solid var(--border);
border-radius: 12px;
margin-bottom: 12px;
overflow: hidden;
font-family: 'JetBrains Mono', monospace;
font-size: 13px;
}
.reasoning-header {
padding: 12px 16px;
background: rgba(163, 113, 247, 0.1);
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
user-select: none;
transition: background 0.2s;
}
.reasoning-header:hover {
background: rgba(163, 113, 247, 0.15);
}
.reasoning-title {
display: flex;
align-items: center;
gap: 10px;
color: var(--accent-think);
font-weight: 600;
font-family: 'Inter', sans-serif;
}
.reasoning-icon {
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.reasoning-toggle {
color: var(--text-secondary);
transition: transform 0.3s;
font-size: 12px;
}
.reasoning-container.expanded .reasoning-toggle {
transform: rotate(180deg);
}
.reasoning-content {
padding: 16px;
color: var(--text-secondary);
line-height: 1.7;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease, padding 0.3s;
white-space: pre-wrap;
overflow-y: auto;
}
.reasoning-container.expanded .reasoning-content {
max-height: 400px;
padding: 16px;
}
.reasoning-content.streaming {
max-height: 400px;
padding: 16px;
}
/* ✅ فقاعة الجواب النهائي */
.answer-bubble {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 12px;
padding: 20px;
line-height: 1.8;
font-size: 15px;
position: relative;
}
.answer-bubble::before {
content: "الإجابة النهائية";
position: absolute;
top: -10px;
right: 16px;
background: var(--bg);
padding: 0 8px;
font-size: 11px;
color: var(--accent-think);
font-weight: 600;
border: 1px solid var(--border);
border-radius: 4px;
}
.bubble.user {
background: var(--surface);
border: 1px solid var(--border);
padding: 14px 18px;
border-radius: 12px;
}
/* Input */
.input-wrapper {
position: absolute;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
width: 80%;
max-width: 900px;
background: var(--sidebar);
border: 1px solid var(--border);
border-radius: 16px;
padding: 14px;
display: flex;
align-items: center;
gap: 12px;
box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
#userInput {
flex: 1;
background: transparent;
border: none;
color: white;
padding: 10px;
font-size: 16px;
outline: none;
font-family: inherit;
}
.send-btn {
width: 36px; height: 36px;
border-radius: 8px;
border: none;
cursor: pointer;
color: white;
transition: all 0.2s;
display: flex; align-items: center; justify-content: center;
}
.send-btn.think { background: var(--accent-think); }
.send-btn.fast { background: var(--accent-fast); }
.send-btn:disabled {
background: #30363d !important;
cursor: not-allowed;
opacity: 0.6;
}
.typing-cursor {
display: inline-block;
width: 2px;
height: 18px;
background: var(--accent-think);
animation: blink 1s infinite;
vertical-align: middle;
margin-right: 4px;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
/* Markdown Styles */
.answer-bubble pre {
background: #161b22;
padding: 16px;
border-radius: 8px;
overflow-x: auto;
margin: 12px 0;
border: 1px solid var(--border);
font-family: 'JetBrains Mono', monospace;
font-size: 13px;
}
.answer-bubble code {
font-family: 'JetBrains Mono', monospace;
background: rgba(255,255,255,0.1);
padding: 2px 6px;
border-radius: 4px;
font-size: 13px;
}
.answer-bubble p { margin-bottom: 12px; }
.answer-bubble p:last-child { margin-bottom: 0; }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }
</style>
</head>
<body>
<aside class="sidebar">
<div class="brand">
<i class="fas fa-brain"></i>
<span>Kimi Reasoning</span>
</div>
<div class="mode-selector">
<button class="mode-btn think active" onclick="setMode('think')">
<i class="fas fa-brain"></i>
<span>وضيف التفكير</span>
</button>
<button class="mode-btn fast" onclick="setMode('fast')">
<i class="fas fa-bolt"></i>
<span>سريع</span>
</button>
</div>
<div class="info-card">
<h4><i class="fas fa-lightbulb"></i> مميزات وضيف التفكير</h4>
• يعرض خطوات التفكير المنطقي<br>
• يحل المسائل المعقدة خطوة بخطوة<br>
• يُظهر صندوق "🧠 عرض التفكير" قابل للطي
</div>
</aside>
<main class="chat-container">
<div id="chat-flow">
<div class="message ai think">
<div class="avatar"><i class="fas fa-robot"></i></div>
<div style="flex: 1;">
<!-- ✅ مثال على صندوق التفكير -->
<div class="reasoning-container expanded">
<div class="reasoning-header" onclick="toggleReasoning(this)">
<div class="reasoning-title">
<i class="fas fa-circle-notch reasoning-icon fa-spin"></i>
<span>جاري التفكير...</span>
</div>
<i class="fas fa-chevron-down reasoning-toggle"></i>
</div>
<div class="reasoning-content streaming">
انتظر رسالتك لأبدأ التفكير فيها خطوة بخطوة...
</div>
</div>
<div class="answer-bubble">
مرحباً! أنا Kimi K2.5 في وضيف التفكير. سأُظهر لك كيف أفكر قبل أن أُعطيك الإجابة النهائية.
</div>
</div>
</div>
</div>
<div class="input-wrapper">
<input type="text" id="userInput" placeholder="اكتب سؤالاً يحتاج تفكيراً عميقاً..." autocomplete="off">
<button class="send-btn think" id="sendBtn" onclick="handleSend()">
<i class="fas fa-paper-plane"></i>
</button>
</div>
</main>
<script>
let currentMode = 'think';
function setMode(mode) {
currentMode = mode;
document.querySelectorAll('.mode-btn').forEach(btn => btn.classList.remove('active'));
document.querySelector(`.mode-btn.${mode}`).classList.add('active');
const btn = document.getElementById('sendBtn');
const input = document.getElementById('userInput');
if (mode === 'think') {
btn.className = 'send-btn think';
input.placeholder = "اكتب سؤالاً يحتاج تفكيراً عميقاً...";
} else {
btn.className = 'send-btn fast';
input.placeholder = "اكتب رسالتك السريعة...";
}
}
function toggleReasoning(header) {
const container = header.parentElement;
container.classList.toggle('expanded');
}
async function handleSend() {
const input = document.getElementById('userInput');
const btn = document.getElementById('sendBtn');
const text = input.value.trim();
if (!text) return;
addMessage(text, 'user');
input.value = '';
input.disabled = true;
btn.disabled = true;
if (currentMode === 'think') {
await sendWithReasoning(text);
} else {
await sendFast(text);
}
input.disabled = false;
btn.disabled = false;
input.focus();
}
// ✅ الوضيف المتقدم: عرض التفكير + الإجابة
async function sendWithReasoning(text) {
const msgId = 'msg-' + Date.now();
const html = `
<div class="message ai think" id="${msgId}">
<div class="avatar"><i class="fas fa-robot"></i></div>
<div style="flex: 1;">
<div class="reasoning-container expanded" id="reasoning-${msgId}">
<div class="reasoning-header" onclick="toggleReasoning(this)">
<div class="reasoning-title">
<i class="fas fa-circle-notch reasoning-icon fa-spin" id="icon-${msgId}"></i>
<span id="title-${msgId}">جاري التفكير...</span>
</div>
<i class="fas fa-chevron-down reasoning-toggle"></i>
</div>
<div class="reasoning-content streaming" id="reasoning-content-${msgId}">
<span class="typing-cursor"></span>
</div>
</div>
<div class="answer-bubble" id="answer-${msgId}" style="display: none;">
<span class="typing-cursor"></span>
</div>
</div>
</div>
`;
document.getElementById('chat-flow').insertAdjacentHTML('beforeend', html);
scrollToBottom();
const reasoningContent = document.getElementById(`reasoning-content-${msgId}`);
const answerBubble = document.getElementById(`answer-${msgId}`);
const titleText = document.getElementById(`title-${msgId}`);
const icon = document.getElementById(`icon-${msgId}`);
try {
const res = await fetch('/api/think', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: text })
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
let reasoningText = "";
let answerText = "";
let isAnswering = false;
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (!line.startsWith('data: ')) continue;
const data = line.replace('data: ', '').trim();
if (data === '[DONE]') break;
try {
const json = JSON.parse(data);
if (json.type === 'reasoning') {
// ✅ عرض نص التفكير
reasoningText += json.content;
reasoningContent.innerHTML = reasoningText + '<span class="typing-cursor"></span>';
scrollToBottom();
}
else if (json.type === 'content') {
// ✅ الانتقال للإجابة النهائية
if (!isAnswering) {
isAnswering = true;
titleText.textContent = "اكتمل التفكير";
icon.className = "fas fa-check reasoning-icon";
icon.style.color = "var(--accent-think)";
// إخفاء صندوق التفكير تلقائياً بعد ثانية (اختياري)
setTimeout(() => {
document.getElementById(`reasoning-${msgId}`).classList.remove('expanded');
}, 1000);
answerBubble.style.display = 'block';
}
answerText += json.content;
answerBubble.innerHTML = marked.parse(answerText) + '<span class="typing-cursor"></span>';
scrollToBottom();
}
else if (json.type === 'error') {
answerBubble.style.display = 'block';
answerBubble.innerHTML = `<span style="color:#f85149">${json.error}</span>`;
}
} catch (e) {}
}
}
// إزالة المؤشر النهائي
const cursor = answerBubble.querySelector('.typing-cursor');
if (cursor) cursor.remove();
} catch (err) {
answerBubble.style.display = 'block';
answerBubble.innerHTML = `<span style="color:#f85149">فشل الاتصال: ${err.message}</span>`;
}
}
// ⚡ الوضع السريع (بدون تفكير مرئي)
async function sendFast(text) {
const msgId = 'msg-' + Date.now();
const html = `
<div class="message ai fast" id="${msgId}">
<div class="avatar"><i class="fas fa-robot"></i></div>
<div style="flex: 1;">
<div class="answer-bubble" id="answer-${msgId}">
<span class="typing-cursor"></span>
</div>
</div>
</div>
`;
document.getElementById('chat-flow').insertAdjacentHTML('beforeend', html);
const bubble = document.getElementById(`answer-${msgId}`);
try {
const res = await fetch('/api/fast', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: text })
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
let fullText = "";
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (!line.startsWith('data: ')) continue;
const data = line.replace('data: ', '').trim();
if (data === '[DONE]') break;
try {
const json = JSON.parse(data);
if (json.type === 'content') {
fullText += json.content;
bubble.innerHTML = marked.parse(fullText) + '<span class="typing-cursor"></span>';
scrollToBottom();
}
} catch (e) {}
}
}
const cursor = bubble.querySelector('.typing-cursor');
if (cursor) cursor.remove();
} catch (err) {
bubble.innerHTML = `<span style="color:#f85149">خطأ: ${err.message}</span>`;
}
}
function addMessage(text, role) {
const html = `
<div class="message ${role}">
<div class="avatar">
<i class="fas ${role === 'user' ? 'fa-user' : 'fa-robot'}"></i>
</div>
<div class="bubble ${role}">${text}</div>
</div>
`;
document.getElementById('chat-flow').insertAdjacentHTML('beforeend', html);
scrollToBottom();
}
function scrollToBottom() {
const flow = document.getElementById('chat-flow');
flow.scrollTop = flow.scrollHeight;
}
document.getElementById('userInput').addEventListener('keypress', (e) => {
if (e.key === 'Enter') handleSend();
});
</script>
</body>
</html>