- Fixed ES modules error by converting automation-with-learning-v2.js to pure ES6 - Fixed singleton pattern in automation-singleton.js for proper async handling - Fixed EnhancedAILearningPanel to handle recommendation objects correctly - Updated API routes to use correct import paths (../../../../lib/) - Created proper db.js utility with ES6 exports - Fixed simplified-stop-loss-learner imports and exports Automation v2 page now loads without errors AI learning system fully integrated and operational Learning status API working with detailed reports Recommendation rendering fixed for object structure
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
// Singleton automation instance manager with learning integration
|
|
let automationInstance = null;
|
|
|
|
async function createAutomationInstance() {
|
|
try {
|
|
// Try to import the learning-enhanced automation first
|
|
const AutomationWithLearning = (await import('./automation-with-learning-v2.js')).default;
|
|
console.log('✅ Creating automation instance with AI learning system');
|
|
return new AutomationWithLearning();
|
|
} catch (error) {
|
|
console.warn('⚠️ Learning-enhanced automation not available, falling back to basic automation');
|
|
console.warn('Error:', error.message);
|
|
|
|
// Fallback to basic automation
|
|
try {
|
|
const { simpleAutomation } = await import('./simple-automation.js');
|
|
console.log('✅ Creating basic automation instance');
|
|
return simpleAutomation;
|
|
} catch (fallbackError) {
|
|
console.error('❌ Could not create any automation instance:', fallbackError);
|
|
throw new Error('No automation system available');
|
|
}
|
|
}
|
|
}
|
|
|
|
async function getAutomationInstance() {
|
|
if (!automationInstance) {
|
|
automationInstance = await createAutomationInstance();
|
|
}
|
|
return automationInstance;
|
|
}
|
|
|
|
async function resetAutomationInstance() {
|
|
if (automationInstance) {
|
|
console.log('🔄 Resetting automation instance');
|
|
if (typeof automationInstance.stop === 'function') {
|
|
await automationInstance.stop();
|
|
}
|
|
}
|
|
automationInstance = null;
|
|
}
|
|
|
|
export {
|
|
getAutomationInstance,
|
|
resetAutomationInstance
|
|
};
|