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:
@@ -17,7 +17,11 @@ interface LearningData {
|
||||
thresholds?: any;
|
||||
confidenceLevel?: number;
|
||||
};
|
||||
recommendations?: string[];
|
||||
recommendations?: Array<{
|
||||
type: string;
|
||||
message: string;
|
||||
priority: string;
|
||||
} | string>;
|
||||
};
|
||||
};
|
||||
visibility?: {
|
||||
@@ -47,15 +51,43 @@ const EnhancedAILearningPanel = () => {
|
||||
const learningData = await learningResponse.json();
|
||||
const statusData = await statusResponse.json();
|
||||
|
||||
setLearningData({
|
||||
...learningData,
|
||||
// Ensure we have a proper data structure even if APIs return errors
|
||||
const safeData = {
|
||||
learningSystem: learningData.learningSystem || {
|
||||
enabled: false,
|
||||
message: learningData.message || 'Learning system not available',
|
||||
activeDecisions: 0
|
||||
},
|
||||
visibility: learningData.visibility || {
|
||||
decisionTrackingActive: false,
|
||||
learningDatabaseConnected: false,
|
||||
aiEnhancementsActive: false,
|
||||
lastUpdateTime: new Date().toISOString()
|
||||
},
|
||||
automationStatus: statusData
|
||||
});
|
||||
};
|
||||
|
||||
setLearningData(safeData);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
console.error('Error fetching learning status:', err);
|
||||
setError(err instanceof Error ? err.message : 'Unknown error');
|
||||
|
||||
// Set default data structure on error
|
||||
setLearningData({
|
||||
learningSystem: {
|
||||
enabled: false,
|
||||
message: 'Failed to fetch learning status',
|
||||
activeDecisions: 0
|
||||
},
|
||||
visibility: {
|
||||
decisionTrackingActive: false,
|
||||
learningDatabaseConnected: false,
|
||||
aiEnhancementsActive: false,
|
||||
lastUpdateTime: new Date().toISOString()
|
||||
},
|
||||
automationStatus: null
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -109,8 +141,23 @@ const EnhancedAILearningPanel = () => {
|
||||
|
||||
const { learningSystem, visibility } = learningData;
|
||||
|
||||
// Safety check for learningSystem
|
||||
if (!learningSystem) {
|
||||
return (
|
||||
<div className="bg-gradient-to-br from-gray-900/20 to-gray-800/20 rounded-xl p-6 border border-gray-500/30">
|
||||
<div className="flex items-center space-x-3 mb-4">
|
||||
<div className="w-3 h-3 bg-gray-500 rounded-full"></div>
|
||||
<h3 className="text-lg font-semibold bg-gradient-to-r from-purple-400 to-blue-400 bg-clip-text text-transparent">
|
||||
🧠 AI Learning System
|
||||
</h3>
|
||||
</div>
|
||||
<div className="text-gray-400">Loading learning system data...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const renderLearningStatus = () => {
|
||||
if (!learningSystem.enabled) {
|
||||
if (!learningSystem || !learningSystem.enabled) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center space-x-2">
|
||||
@@ -120,9 +167,9 @@ const EnhancedAILearningPanel = () => {
|
||||
|
||||
<div className="bg-yellow-900/20 rounded-lg p-4 border border-yellow-500/30">
|
||||
<div className="text-yellow-300 text-sm">
|
||||
{learningSystem.message || 'The AI learning system is not currently integrated with the automation.'}
|
||||
{learningSystem?.message || 'The AI learning system is not currently integrated with the automation.'}
|
||||
</div>
|
||||
{learningSystem.recommendation && (
|
||||
{learningSystem?.recommendation && (
|
||||
<div className="text-yellow-400 text-sm mt-2 font-medium">
|
||||
💡 {learningSystem.recommendation}
|
||||
</div>
|
||||
@@ -145,7 +192,7 @@ const EnhancedAILearningPanel = () => {
|
||||
<span className="text-green-400 font-medium">AI Learning Active</span>
|
||||
</div>
|
||||
|
||||
{learningSystem.report && (
|
||||
{learningSystem?.report && (
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div className="bg-blue-900/20 rounded-lg p-4 border border-blue-500/30">
|
||||
<div className="text-blue-300 text-sm font-medium">Total Decisions</div>
|
||||
@@ -192,15 +239,15 @@ const EnhancedAILearningPanel = () => {
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<div className={`w-2 h-2 rounded-full ${(learningSystem.activeDecisions || 0) > 0 ? 'bg-blue-500' : 'bg-gray-500'}`}></div>
|
||||
<span className={(learningSystem.activeDecisions || 0) > 0 ? 'text-blue-400' : 'text-gray-400'}>
|
||||
Active Decisions ({learningSystem.activeDecisions || 0})
|
||||
<div className={`w-2 h-2 rounded-full ${(learningSystem?.activeDecisions || 0) > 0 ? 'bg-blue-500' : 'bg-gray-500'}`}></div>
|
||||
<span className={(learningSystem?.activeDecisions || 0) > 0 ? 'text-blue-400' : 'text-gray-400'}>
|
||||
Active Decisions ({learningSystem?.activeDecisions || 0})
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{learningSystem.report?.insights && (
|
||||
{learningSystem?.report?.insights && (
|
||||
<div className="bg-purple-900/20 rounded-lg p-4 border border-purple-500/30">
|
||||
<div className="text-purple-300 text-sm font-medium mb-2">🎯 Learning Insights</div>
|
||||
<div className="text-sm text-gray-300">
|
||||
@@ -214,13 +261,13 @@ const EnhancedAILearningPanel = () => {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{learningSystem.report?.recommendations && learningSystem.report.recommendations.length > 0 && (
|
||||
{learningSystem?.report?.recommendations && learningSystem.report.recommendations.length > 0 && (
|
||||
<div className="bg-yellow-900/20 rounded-lg p-4 border border-yellow-500/30">
|
||||
<div className="text-yellow-300 text-sm font-medium mb-2">💡 AI Recommendations</div>
|
||||
<div className="space-y-1">
|
||||
{learningSystem.report.recommendations.map((rec: string, index: number) => (
|
||||
{learningSystem.report.recommendations.map((rec: any, index: number) => (
|
||||
<div key={index} className="text-sm text-yellow-400">
|
||||
• {rec}
|
||||
• {typeof rec === 'string' ? rec : rec.message || rec.type || 'No message'}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -234,7 +281,7 @@ const EnhancedAILearningPanel = () => {
|
||||
<div className="bg-gradient-to-br from-purple-900/20 to-blue-900/20 rounded-xl p-6 border border-purple-500/30">
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className={`w-3 h-3 rounded-full ${learningSystem.enabled ? 'bg-green-500 animate-pulse' : 'bg-yellow-500'}`}></div>
|
||||
<div className={`w-3 h-3 rounded-full ${learningSystem?.enabled ? 'bg-green-500 animate-pulse' : 'bg-yellow-500'}`}></div>
|
||||
<h3 className="text-lg font-semibold bg-gradient-to-r from-purple-400 to-blue-400 bg-clip-text text-transparent">
|
||||
🧠 AI Learning System
|
||||
</h3>
|
||||
|
||||
Reference in New Issue
Block a user