import React from 'react'; import { Box, Typography, Button, Divider, Alert, Paper } from '@mui/material'; import CheckIcon from '@mui/icons-material/Check'; import CloseIcon from '@mui/icons-material/Close'; import AddIcon from '@mui/icons-material/Add'; import SmartToyIcon from '@mui/icons-material/SmartToy'; import AssignmentIcon from '@mui/icons-material/Assignment'; import ChatBubbleOutlineIcon from '@mui/icons-material/ChatBubbleOutline'; import AccessTimeIcon from '@mui/icons-material/AccessTime'; import InputIcon from '@mui/icons-material/Input'; import OutputIcon from '@mui/icons-material/Output'; import FormatListNumberedIcon from '@mui/icons-material/FormatListNumbered'; import { FinalStep, AgentTrace, AgentStep } from '@/types/agent'; import { DownloadGifButton } from './DownloadGifButton'; import { DownloadJsonButton } from './DownloadJsonButton'; interface CompletionViewProps { finalStep: FinalStep; trace?: AgentTrace; steps?: AgentStep[]; finalAnswer?: string | null; isGenerating: boolean; gifError: string | null; onGenerateGif: () => void; onDownloadJson: () => void; onBackToHome: () => void; } /** * Component displaying the completion status (success or failure) of a task */ export const CompletionView: React.FC = ({ finalStep, trace, steps, finalAnswer, isGenerating, gifError, onGenerateGif, onDownloadJson, onBackToHome, }) => { const isSuccess = finalStep.type === 'success'; const statusColor = isSuccess ? 'success.main' : 'error.main'; // Format model name for display const formatModelName = (modelId: string) => { const parts = modelId.split('/'); return parts.length > 1 ? parts[1] : modelId; }; return ( {/* Status Header - Compact */} isSuccess ? `0 2px 8px ${theme.palette.mode === 'dark' ? 'rgba(102, 187, 106, 0.3)' : 'rgba(102, 187, 106, 0.2)'}` : `0 2px 8px ${theme.palette.mode === 'dark' ? 'rgba(244, 67, 54, 0.3)' : 'rgba(244, 67, 54, 0.2)'}`, }} > {isSuccess ? ( ) : ( )} {isSuccess ? 'Task Completed' : 'Task Failed'} {/* Single Report Box - Task + Agent + Response + Metrics */} theme.palette.mode === 'dark' ? 'rgba(255,255,255,0.03)' : 'rgba(0,0,0,0.03)', borderRadius: 1.5, border: '1px solid', borderColor: 'divider', }} > {/* Task */} {trace?.instruction && ( Task {trace.instruction} )} {/* Agent Response */} {finalAnswer && ( Agent Response {finalAnswer} )} {/* Divider before metrics */} {/* Metrics */} {/* Agent */} {trace?.modelId && ( <> {formatModelName(trace.modelId)} {/* Divider */} )} {/* Steps Count */} {finalStep.metadata.numberOfSteps} {finalStep.metadata.numberOfSteps === 1 ? 'Step' : 'Steps'} {/* Divider */} {/* Duration */} {finalStep.metadata.duration.toFixed(1)}s {/* Divider */} {/* Input Tokens */} {finalStep.metadata.inputTokensUsed.toLocaleString()} {/* Divider */} {/* Output Tokens */} {finalStep.metadata.outputTokensUsed.toLocaleString()} {/* GIF Error Alert */} {gifError && ( {gifError} )} {/* Action Buttons */} {/* Download buttons */} {/* New Task button - larger and below */} ); };