// Main application script document.addEventListener('DOMContentLoaded', () => { // Auto-expanding textarea const textarea = document.querySelector('textarea'); if (textarea) { textarea.addEventListener('input', function() { this.style.height = 'auto'; this.style.height = (this.scrollHeight) + 'px'; }); } // Tooltip functionality document.querySelectorAll('[data-tooltip]').forEach(el => { el.addEventListener('mouseenter', () => { const tooltip = document.createElement('div'); tooltip.className = 'absolute z-50 px-2 py-1 text-xs text-white bg-gray-800 rounded-md shadow-lg'; tooltip.textContent = el.dataset.tooltip; document.body.appendChild(tooltip); const rect = el.getBoundingClientRect(); tooltip.style.top = `${rect.top - tooltip.offsetHeight - 5}px`; tooltip.style.left = `${rect.left + rect.width / 2 - tooltip.offsetWidth / 2}px`; el._tooltip = tooltip; }); el.addEventListener('mouseleave', () => { if (el._tooltip) { el._tooltip.remove(); delete el._tooltip; } }); }); }); // Example API call function async function callAITool(toolName, inputData) { try { // In a real app, this would call your backend API console.log(`Calling ${toolName} with:`, inputData); // Simulate API delay return new Promise(resolve => { setTimeout(() => { resolve({ success: true, result: `This is a simulated response from ${toolName} tool` }); }, 1000); }); } catch (error) { console.error('Tool calling error:', error); return { success: false, error: error.message }; } }