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
This commit is contained in:
@@ -4,7 +4,7 @@ let automationInstance = null;
|
||||
async function createAutomationInstance() {
|
||||
try {
|
||||
// Try to import the learning-enhanced automation first
|
||||
const AutomationWithLearning = require('./automation-with-learning-v2.js');
|
||||
const AutomationWithLearning = (await import('./automation-with-learning-v2.js')).default;
|
||||
console.log('✅ Creating automation instance with AI learning system');
|
||||
return new AutomationWithLearning();
|
||||
} catch (error) {
|
||||
@@ -23,24 +23,24 @@ async function createAutomationInstance() {
|
||||
}
|
||||
}
|
||||
|
||||
function getAutomationInstance() {
|
||||
async function getAutomationInstance() {
|
||||
if (!automationInstance) {
|
||||
automationInstance = createAutomationInstance();
|
||||
automationInstance = await createAutomationInstance();
|
||||
}
|
||||
return automationInstance;
|
||||
}
|
||||
|
||||
function resetAutomationInstance() {
|
||||
async function resetAutomationInstance() {
|
||||
if (automationInstance) {
|
||||
console.log('🔄 Resetting automation instance');
|
||||
if (typeof automationInstance.stop === 'function') {
|
||||
automationInstance.stop();
|
||||
await automationInstance.stop();
|
||||
}
|
||||
}
|
||||
automationInstance = null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
getAutomationInstance,
|
||||
resetAutomationInstance
|
||||
};
|
||||
|
||||
@@ -445,4 +445,4 @@ class AutomationWithLearning {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AutomationWithLearning;
|
||||
export default AutomationWithLearning;
|
||||
|
||||
42
lib/db.js
42
lib/db.js
@@ -1,46 +1,12 @@
|
||||
/**
|
||||
* Database utility for Prisma client
|
||||
*
|
||||
* Provides a global Prisma instance to avoid connection issues
|
||||
*/
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
let prisma;
|
||||
|
||||
// Global Prisma instance
|
||||
let prisma = null;
|
||||
|
||||
/**
|
||||
* Get the global Prisma database instance
|
||||
*/
|
||||
async function getDB() {
|
||||
function getDB() {
|
||||
if (!prisma) {
|
||||
prisma = new PrismaClient();
|
||||
|
||||
// Test the connection
|
||||
try {
|
||||
await prisma.$connect();
|
||||
console.log('✅ Database connection established');
|
||||
} catch (error) {
|
||||
console.error('❌ Database connection failed:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return prisma;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the database connection
|
||||
*/
|
||||
async function closeDB() {
|
||||
if (prisma) {
|
||||
await prisma.$disconnect();
|
||||
prisma = null;
|
||||
console.log('✅ Database connection closed');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDB,
|
||||
closeDB
|
||||
};
|
||||
export { getDB };
|
||||
@@ -5,8 +5,8 @@
|
||||
* without complex statistical analysis.
|
||||
*/
|
||||
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const getDB = require('./database-util');
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { getDB } from './db.js';
|
||||
|
||||
class SimplifiedStopLossLearner {
|
||||
constructor() {
|
||||
@@ -527,4 +527,4 @@ class SimplifiedStopLossLearner {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SimplifiedStopLossLearner;
|
||||
export { SimplifiedStopLossLearner };
|
||||
|
||||
Reference in New Issue
Block a user