const API_TOKEN = "scud_secret_token_2026"; const SESSION_ID = "web_session_main"; const STORAGE_KEY = 'scud_chat_input_history'; let currentFilter = 'ALL'; let allTasks = []; // === ИСТОРИЯ КОМАНД (LOCALSTORAGE + СТРЕЛКИ ВВЕРХ/ВНИЗ) === let inputHistory = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]'); let historyIndex = -1; document.addEventListener('DOMContentLoaded', () => { const userInputEl = document.getElementById('user-input'); if (userInputEl) { // Динамическое расширение высоты поля до 4 строк (~96px) userInputEl.addEventListener('input', function() { this.style.height = 'auto'; this.style.height = Math.min(this.scrollHeight, 96) + 'px'; }); userInputEl.addEventListener('keydown', function(e) { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); document.getElementById('chat-form').requestSubmit(); } else if (e.key === 'ArrowUp') { if (inputHistory.length > 0 && historyIndex < inputHistory.length - 1) { e.preventDefault(); if (historyIndex === -1) { this.dataset.draft = this.value; } historyIndex++; this.value = inputHistory[inputHistory.length - 1 - historyIndex]; this.dispatchEvent(new Event('input')); setTimeout(() => this.setSelectionRange(this.value.length, this.value.length), 0); } } else if (e.key === 'ArrowDown') { if (historyIndex !== -1) { e.preventDefault(); if (historyIndex > 0) { historyIndex--; this.value = inputHistory[inputHistory.length - 1 - historyIndex]; } else { historyIndex = -1; this.value = this.dataset.draft || ''; } this.dispatchEvent(new Event('input')); setTimeout(() => this.setSelectionRange(this.value.length, this.value.length), 0); } } }); } loadTasks(); }); function toggleDrawer() { const drawer = document.getElementById('task-drawer'); const backdrop = document.getElementById('drawer-backdrop'); const isHidden = drawer.classList.contains('translate-x-full'); if (isHidden) { drawer.classList.remove('translate-x-full'); backdrop.classList.remove('hidden'); } else { drawer.classList.add('translate-x-full'); backdrop.classList.add('hidden'); } } function setFilter(status) { currentFilter = status; ['ALL', 'IN_PROGRESS', 'BACKLOG', 'COMPLETED'].forEach(f => { const btn = document.getElementById(`filter-${f}`); if (f === status) { btn.className = "px-3 py-1.5 rounded-t-lg border-b-2 border-indigo-600 text-indigo-600 font-bold"; } else { btn.className = "px-3 py-1.5 rounded-t-lg border-b-2 border-transparent hover:text-slate-700"; } }); renderTasks(); } async function loadTasks() { try { const res = await fetch('/api/v1/tasks', { headers: { 'Authorization': `Bearer ${API_TOKEN}` } }); allTasks = await res.json(); document.getElementById('task-count-badge').innerText = allTasks.length; renderTasks(); } catch (err) { document.getElementById('tasks-container').innerHTML = `
ИИ-Ассистент
${data.reply}