"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { analyzeDeploymentLogs } from "@/lib/actions/deployment"; // Server Action import { Loader2, Sparkles, Lightbulb } from "lucide-react"; import { ScrollArea } from "../ui/scroll-area"; interface AiLogAnalyzerProps { initialLogs?: string; } export function AiLogAnalyzer({ initialLogs = "" }: AiLogAnalyzerProps) { const [logsToAnalyze, setLogsToAnalyze] = useState(initialLogs); const [analysisResult, setAnalysisResult] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const handleAnalyze = async () => { if (!logsToAnalyze.trim()) { setError("Please paste some logs to analyze."); return; } setIsLoading(true); setError(null); setAnalysisResult(null); try { const result = await analyzeDeploymentLogs(logsToAnalyze); if (result.success && result.analysis) { setAnalysisResult(result.analysis); } else { setError(result.error || "Failed to get analysis."); } } catch (e) { setError("An unexpected error occurred during analysis."); console.error(e); } finally { setIsLoading(false); } }; return ( AI Log Analyzer Paste your deployment logs below and let AI help you find issues and suggest fixes.