const AUTH_TOKEN_KEY = "scud_api_auth_token"; const SESSION_ID = "web_session_main"; const STORAGE_KEY = 'scud_chat_input_history'; let API_TOKEN = localStorage.getItem(AUTH_TOKEN_KEY) || ""; let IS_GUEST = localStorage.getItem('scud_is_guest') === 'true'; let currentFilter = 'ALL'; let allTasks = []; let inputHistory = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]'); let historyIndex = -1; document.addEventListener('DOMContentLoaded', () => { const userInputEl = document.getElementById('user-input'); if (userInputEl) { userInputEl.addEventListener('input', function() { this.style.height = 'auto'; this.style.height = Math.min(this.scrollHeight, 80) + '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); } } }); } if (IS_GUEST) { hideAuthModal(); updateUIState(); } else if (API_TOKEN) { verifyToken(API_TOKEN).then(isValid => { if (isValid) { hideAuthModal(); updateUIState(); loadTasks(); } else { showAuthModal(); } }); } else { showAuthModal(); } });