import React, { useState, useEffect } from 'react';
import {
AppBar, Toolbar, Typography, Container, Box, Paper,
TextField, Button, List, ListItem, ListItemText,
CircularProgress, Chip, Grid, Card, CardContent,
Tabs, Tab, Divider, IconButton, Switch, FormControlLabel,
Alert, AlertTitle, Dialog, DialogTitle, DialogContent,
DialogActions, Rating, LinearProgress, Tooltip
} from '@mui/material';
import {
Send as SendIcon,
ThumbUp, ThumbDown, Warning as WarningIcon,
CheckCircle, Info, Shield, Speed, TrendingUp
} from '@mui/icons-material';
import axios from 'axios';
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000';
function App() {
const [activeTab, setActiveTab] = useState(0);
return (
Datacenter AI System - Auto-Remediation Enabled
setActiveTab(v)}>
{activeTab === 0 && }
{activeTab === 1 && }
{activeTab === 2 && }
{activeTab === 3 && }
);
}
// Ticket Submit Interface with Auto-Remediation Toggle
function TicketSubmitInterface() {
const [ticketData, setTicketData] = useState({
ticket_id: '',
title: '',
description: '',
priority: 'medium',
category: '',
enable_auto_remediation: false // DEFAULT: DISABLED
});
const [loading, setLoading] = useState(false);
const [result, setResult] = useState(null);
const [showWarning, setShowWarning] = useState(false);
const submitTicket = async () => {
setLoading(true);
try {
const response = await axios.post(`${API_URL}/api/v1/tickets`, ticketData);
setResult(response.data);
// Poll for updates
const ticketId = response.data.ticket_id;
const pollInterval = setInterval(async () => {
const statusResponse = await axios.get(`${API_URL}/api/v1/tickets/${ticketId}`);
setResult(statusResponse.data);
if (statusResponse.data.status === 'resolved' ||
statusResponse.data.status === 'failed') {
clearInterval(pollInterval);
setLoading(false);
}
}, 3000);
} catch (error) {
console.error('Error:', error);
setLoading(false);
}
};
return (
Submit Ticket for AI Resolution
setTicketData({...ticketData, ticket_id: e.target.value})}
margin="normal"
/>
setTicketData({...ticketData, title: e.target.value})}
margin="normal"
/>
setTicketData({...ticketData, description: e.target.value})}
margin="normal"
/>
setTicketData({...ticketData, category: e.target.value})}
margin="normal"
SelectProps={{ native: true }}
>
Auto-Remediation Control
{
setTicketData({
...ticketData,
enable_auto_remediation: e.target.checked
});
if (e.target.checked) setShowWarning(true);
}}
color="warning"
/>
}
label={
Enable Auto-Remediation (Write Operations)
}
/>
When enabled, AI can automatically execute fixes on your infrastructure.
Default: DISABLED for safety. Only enable if you trust AI decisions.
{result && }
{/* Warning Dialog */}
);
}
// Enhanced Ticket Result Display
function TicketResultDisplay({ result }) {
const getConfidenceColor = (level) => {
const colors = {
'very_high': 'success',
'high': 'info',
'medium': 'warning',
'low': 'error'
};
return colors[level] || 'default';
};
return (
Resolution & Analysis
{result.auto_remediation_enabled && (
}
label="Auto-Remediation Enabled"
color="warning"
size="small"
/>
)}
{/* Reliability Scores */}
AI Confidence & Reliability
AI Confidence
{(result.confidence_score * 100).toFixed(0)}%
{result.reliability_score && (
Reliability Score
= 85 ? 'success' : 'warning'}
/>
Based on: AI confidence, historical success, feedback, patterns
)}
{/* Resolution */}
Resolution:
{result.resolution}
{/* Suggested Actions */}
{result.suggested_actions?.length > 0 && (
<>
Suggested Actions:
{result.suggested_actions.map((action, idx) => (
))}
>
)}
{/* Auto-Remediation Status */}
{result.auto_remediation_enabled && (
{result.auto_remediation_executed ? 'Auto-Remediation Executed' : 'Auto-Remediation Status'}
{result.remediation_decision && (
{result.remediation_decision.allowed
? `✓ Actions approved for execution (${result.remediation_decision.action_type})`
: `✗ Actions require manual intervention: ${result.remediation_decision.reasoning.join(', ')}`
}
)}
)}
Processing Time: {result.processing_time?.toFixed(2)}s
);
}
// Ticket Status Interface
function TicketStatusInterface() {
const [ticketId, setTicketId] = useState('');
const [ticket, setTicket] = useState(null);
const [logs, setLogs] = useState([]);
const [loading, setLoading] = useState(false);
const fetchTicket = async () => {
setLoading(true);
try {
const response = await axios.get(`${API_URL}/api/v1/tickets/${ticketId}`);
setTicket(response.data);
// Fetch logs if auto-remediation was executed
if (response.data.auto_remediation_executed) {
const logsResponse = await axios.get(`${API_URL}/api/v1/tickets/${ticketId}/remediation-logs`);
setLogs(logsResponse.data.logs);
}
} catch (error) {
console.error('Error:', error);
}
setLoading(false);
};
return (
setTicketId(e.target.value)}
placeholder="Enter Ticket ID"
/>
{ticket && (
<>
>
)}
{logs.length > 0 && (
)}
);
}
// Feedback Form
function FeedbackForm({ ticketId }) {
const [feedback, setFeedback] = useState({
feedback_type: 'positive',
rating: 5,
was_helpful: true,
resolution_accurate: true,
actions_worked: true,
comment: ''
});
const [submitted, setSubmitted] = useState(false);
const submitFeedback = async () => {
try {
await axios.post(`${API_URL}/api/v1/feedback`, {
ticket_id: ticketId,
...feedback
});
setSubmitted(true);
} catch (error) {
console.error('Error:', error);
}
};
return (
Provide Feedback
{submitted ? (
Thank You!
Your feedback helps improve the AI system.
) : (
<>
Was this resolution helpful?
setFeedback({...feedback, rating: value})}
/>
setFeedback({
...feedback,
resolution_accurate: e.target.checked,
feedback_type: e.target.checked ? 'positive' : 'negative'
})}
/>
}
label="Resolution was accurate"
/>
setFeedback({...feedback, actions_worked: e.target.checked})}
/>
}
label="Suggested actions worked"
/>
setFeedback({...feedback, comment: e.target.value})}
margin="normal"
/>
>
)}
);
}
// Remediation Logs Display
function RemediationLogsDisplay({ logs }) {
return (
Auto-Remediation Execution Logs
{logs.map((log, idx) => (
{log.success ?
:
}
{log.action}
}
secondary={
<>
Target: {log.target_system} / {log.target_resource}
Executed: {new Date(log.executed_at).toLocaleString()}
{log.error && (
Error: {log.error}
)}
>
}
/>
))}
);
}
// Feedback Center
function FeedbackCenter() {
// Implementation for viewing all feedback and metrics
return (
Feedback Center
View all feedback, improve AI accuracy, and track pattern learning.
);
}
// Analytics Dashboard
function AnalyticsDashboard() {
const [stats, setStats] = useState(null);
const [autoRemStats, setAutoRemStats] = useState(null);
useEffect(() => {
fetchStats();
}, []);
const fetchStats = async () => {
try {
const [reliability, autoRem] = await Promise.all([
axios.get(`${API_URL}/api/v1/stats/reliability`),
axios.get(`${API_URL}/api/v1/stats/auto-remediation`)
]);
setStats(reliability.data);
setAutoRemStats(autoRem.data);
} catch (error) {
console.error('Error:', error);
}
};
return (
}
color="primary"
/>
}
color="success"
/>
}
color="info"
/>
}
color="warning"
/>
);
}
function StatCard({ title, value, icon, color }) {
return (
{title}
{value}
{icon}
);
}
export default App;