feat(console): add AI assistant panel /api/ai/ask v0.7.9

This commit is contained in:
Naeel
2026-04-20 14:45:00 +03:00
parent 411de75b27
commit 80c05e57fd
2 changed files with 175 additions and 1 deletions
+70
View File
@@ -852,5 +852,75 @@
checkAuth();
</script>
<!-- ================================================================
ai/ask feature — удалить весь блок до "end ai/ask feature"
================================================================ -->
<div id="assistant-panel" style="
position:fixed; bottom:0; right:24px;
width:360px; background:#1e1e2e; border:1px solid #3a3a5c;
border-bottom:none; border-radius:8px 8px 0 0;
font-family:inherit; z-index:900; box-shadow:0 -2px 12px rgba(0,0,0,.4);
">
<div id="assistant-header" onclick="toggleAssistant()" style="
display:flex; align-items:center; justify-content:space-between;
padding:8px 12px; cursor:pointer; background:#2a2a42; border-radius:8px 8px 0 0;
user-select:none;
">
<span style="font-weight:600; font-size:.85rem;">💬 Ассистент</span>
<span id="assistant-toggle-icon" style="font-size:.75rem; opacity:.7;"></span>
</div>
<div id="assistant-body" style="padding:10px; display:flex; flex-direction:column; gap:8px;">
<div id="assistant-messages" style="
min-height:80px; max-height:260px; overflow-y:auto;
font-size:.82rem; line-height:1.5; color:#cdd6f4;
background:#13131f; border-radius:4px; padding:8px;
white-space:pre-wrap; word-break:break-word;
">Привет! Задай любой вопрос про Fission или программирование.</div>
<div style="display:flex; gap:6px;">
<input id="assistant-input" type="text" placeholder="Введи вопрос..."
style="flex:1; background:#2a2a42; border:1px solid #3a3a5c; border-radius:4px;
color:#cdd6f4; padding:6px 8px; font-size:.82rem; outline:none;"
onkeydown="if(event.key==='Enter')askAssistant()" />
<button onclick="askAssistant()" style="
background:#7c3aed; color:#fff; border:none; border-radius:4px;
padding:6px 12px; cursor:pointer; font-size:.82rem; white-space:nowrap;
"></button>
</div>
</div>
</div>
<script>
// ai/ask feature
var _assistantOpen = true;
function toggleAssistant() {
_assistantOpen = !_assistantOpen;
document.getElementById('assistant-body').style.display = _assistantOpen ? 'flex' : 'none';
document.getElementById('assistant-toggle-icon').textContent = _assistantOpen ? '▲' : '▼';
}
async function askAssistant() {
var inp = document.getElementById('assistant-input');
var msgs = document.getElementById('assistant-messages');
var q = inp.value.trim();
if (!q) return;
inp.value = '';
msgs.textContent += '\n\n👤 ' + q + '\n⏳ ...';
msgs.scrollTop = msgs.scrollHeight;
try {
var r = await fetch('/console/api/ai/ask', {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...authHeaders() },
body: JSON.stringify({ question: q })
});
var d = await r.json();
msgs.textContent = msgs.textContent.replace('⏳ ...', '🤖 ' + (d.answer || d.error || 'Нет ответа'));
} catch(e) {
msgs.textContent = msgs.textContent.replace('⏳ ...', '❌ Ошибка: ' + e.message);
}
msgs.scrollTop = msgs.scrollHeight;
}
// end ai/ask feature
</script>
<!-- end ai/ask feature -->
</body>
</html>