Spaces:
Running
Running
File size: 1,934 Bytes
3899d68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | // 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 };
}
} |