diff --git a/api/chat.php b/api/chat.php index 1a5bacb..6bce988 100644 --- a/api/chat.php +++ b/api/chat.php @@ -20,7 +20,7 @@ try { // 1. Create chat if not exists if (!$chatId) { $stmt = db()->prepare("INSERT INTO chats (mode, title) VALUES (?, ?)"); - $title = substr($userMsg, 0, 30) . '...'; + $title = mb_substr($userMsg, 0, 50) . (mb_strlen($userMsg) > 50 ? '...' : ''); $stmt->execute([$mode, $title]); $chatId = db()->lastInsertId(); } @@ -30,19 +30,26 @@ try { $stmt->execute([$chatId, $userMsg]); // 3. Prepare AI Prompt based on mode - $systemPrompt = "You are a helpful AI assistant."; + $systemPrompt = "You are a helpful, intelligent AI assistant."; + if ($mode === 'coding') { - $systemPrompt = "You are an expert software engineer. Provide clean, efficient, and well-documented code."; + $systemPrompt = "You are an elite senior software engineer and architect. Provide clean, secure, efficient, and perfectly documented code. Explain your reasoning briefly."; } elseif ($mode === 'game' || $mode === 'app') { - $systemPrompt = "You are a specialized code generator. Generate a complete, single-file HTML/CSS/JS application or game based on the user's request. Always include the full code within a single message. Use modern techniques."; + $systemPrompt = "You are a world-class single-file application developer. Your goal is to generate a complete, functional, and visually stunning HTML/CSS/JS application or game in a SINGLE message. + Always wrap the code in a triple-backtick block starting with ```html. + Ensure the app is self-contained (no external assets unless they are from reliable CDNs). + Include CSS in ${codeToLaunch}`; + } const blob = new Blob([codeToLaunch], { type: 'text/html' }); const url = URL.createObjectURL(blob); window.open(url, '_blank'); }; + + // Append to the last message div chatWindow.lastElementChild.appendChild(btn); } } function toggleLoading(isLoading) { sendBtn.disabled = isLoading; + chatInput.disabled = isLoading; if (isLoading) { sendBtn.innerHTML = ''; } else { sendBtn.innerHTML = ''; + chatInput.focus(); } } @@ -185,6 +209,9 @@ document.addEventListener('DOMContentLoaded', () => { limits_off: limitsToggle.checked ? '1' : '0' }; + saveSettingsBtn.disabled = true; + saveSettingsBtn.innerHTML = ' Saving...'; + try { const resp = await fetch('api/settings.php', { method: 'POST', @@ -193,22 +220,35 @@ document.addEventListener('DOMContentLoaded', () => { }); const data = await resp.json(); if (data.success) { - bootstrap.Modal.getInstance(document.getElementById('settingsModal')).hide(); - // Minimal toast notification - const toast = document.createElement('div'); - toast.className = 'position-fixed bottom-0 start-50 translate-middle-x mb-3 bg-success text-white px-3 py-2 rounded shadow-lg'; - toast.style.zIndex = '2000'; - toast.textContent = 'Settings saved!'; - document.body.appendChild(toast); - setTimeout(() => toast.remove(), 2000); + const modal = bootstrap.Modal.getInstance(document.getElementById('settingsModal')); + if (modal) modal.hide(); + + showToast('Settings saved successfully!'); } } catch (e) { console.error(e); + showToast('Failed to save settings', 'danger'); + } finally { + saveSettingsBtn.disabled = false; + saveSettingsBtn.textContent = 'Save changes'; } }); + function showToast(message, type = 'success') { + const toast = document.createElement('div'); + toast.className = `position-fixed bottom-0 start-50 translate-middle-x mb-4 bg-${type} text-white px-4 py-2 rounded-pill shadow-lg animate-fade-in`; + toast.style.zIndex = '2050'; + toast.innerHTML = ` ${message}`; + document.body.appendChild(toast); + setTimeout(() => { + toast.style.opacity = '0'; + toast.style.transition = 'opacity 0.5s ease'; + setTimeout(() => toast.remove(), 500); + }, 3000); + } + // Set active theme swatch on load const currentTheme = document.documentElement.getAttribute('data-theme'); const activeSwatch = document.querySelector(`.theme-swatch[data-theme="${currentTheme}"]`); if (activeSwatch) activeSwatch.classList.add('active'); -}); \ No newline at end of file +}); diff --git a/db/migrations/01_init.sql b/db/migrations/01_init.sql index 3a83b36..c6e81bb 100644 --- a/db/migrations/01_init.sql +++ b/db/migrations/01_init.sql @@ -23,5 +23,5 @@ CREATE TABLE IF NOT EXISTS user_settings ( -- Default settings INSERT IGNORE INTO user_settings (setting_key, setting_value) VALUES ('creativity', '0.7'); -INSERT IGNORE INTO user_settings (setting_key, setting_value) VALUES ('theme', 'dark-modern'); -INSERT IGNORE INTO user_settings (setting_key, setting_value) VALUES ('limits_off', '0'); +INSERT IGNORE INTO user_settings (setting_key, setting_value) VALUES ('theme', 'theme-dark-modern'); +INSERT IGNORE INTO user_settings (setting_key, setting_value) VALUES ('limits_off', '0'); \ No newline at end of file