Files
trading_bot_v3/app/api/automation/start/route.js
mindesbunister d5bf485e72 fix: Complete automation v2 page runtime error fixes
- 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
2025-07-27 12:38:32 +02:00

53 lines
1.6 KiB
JavaScript

import { NextResponse } from 'next/server';
// Import singleton automation manager
async function getAutomationInstance() {
try {
const { getAutomationInstance } = await import('../../../../lib/automation-singleton.js');
return await getAutomationInstance();
} catch (error) {
console.error('❌ Could not get automation instance:', error);
throw error;
}
}
export async function POST(request) {
try {
const config = await request.json();
console.log('🚀 AUTOMATION START: Received config:', JSON.stringify(config, null, 2));
console.log('🧠 LEARNING SYSTEM: Attempting to start with AI learning integration');
const automation = await getAutomationInstance();
const result = await automation.start(config);
// Add learning system status to response
const response = {
...result,
learningSystem: {
integrated: typeof automation.getLearningStatus === 'function',
type: automation.constructor.name
}
};
if (result.success) {
console.log('✅ AUTOMATION STARTED:', response.learningSystem.integrated ? 'With AI Learning' : 'Basic Mode');
return NextResponse.json(response);
} else {
return NextResponse.json(response, { status: 400 });
}
} catch (error) {
console.error('❌ Start automation error:', error);
return NextResponse.json({
success: false,
error: 'Internal server error',
message: error.message,
learningSystem: {
integrated: false,
error: 'Failed to initialize'
}
}, { status: 500 });
}
}