Ff5372t's picture
Build ai Agnet for make ai app builder
dc1051f verified
Raw History Blame Contribute Delete
2.37 kB
// Shared JavaScript across all pages
console.log('AI Agentic App Builder Pro loaded');
// Theme management
function toggleTheme() {
const html = document.documentElement;
html.classList.toggle('dark');
localStorage.setItem('theme', html.classList.contains('dark') ? 'dark' : 'light');
}
// Initialize theme from localStorage
document.addEventListener('DOMContentLoaded', function() {
const savedTheme = localStorage.getItem('theme') || 'dark';
document.documentElement.classList.toggle('dark', savedTheme === 'dark');
});
// API integration for AI models
const AIService = {
async generateApp(template, config) {
try {
// Simulate API call to AI service
const response = await fetch('/api/generate-app', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
template,
config,
timestamp: new Date().toISOString()
})
});
return await response.json();
} catch (error) {
console.error('Error generating app:', error);
throw error;
}
},
async getTemplates() {
try {
const response = await fetch('/api/templates');
return await response.json();
} catch (error) {
console.error('Error fetching templates:', error);
return [];
}
}
};
// Utility functions
const Utils = {
debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
},
formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
};
// Export for use in other modules
window.AIService = AIService;
window.Utils = Utils;