/** * Agent Graphs Section Component * * Displays and manages agent graphs for a trace, extracted from TraceKnowledgeGraphView */ import React from "react"; import { Button } from "@/components/ui/button"; import { CardTitle } from "@/components/ui/card"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import { FileText, Activity, AlertCircle, Plus } from "lucide-react"; import { Trace, KnowledgeGraph } from "@/types"; import { KnowledgeGraphTree } from "@/components/features/traces/KnowledgeGraphTree"; // import { useKGDisplayMode } from "@/context/KGDisplayModeContext"; // import { getDisplayModeDescription } from "@/lib/kg-selection"; import { api } from "@/lib/api"; import { useModal } from "@/context/ModalContext"; import { useNotification } from "@/context/NotificationContext"; import { useNavigation } from "@/context/NavigationContext"; import { useAgentGraph } from "@/context/AgentGraphContext"; interface AgentGraphsSectionProps { trace: Trace; kgData: KnowledgeGraph[]; loading: boolean; error: string | null; isGenerating: boolean; isPolling: boolean; generationProgress: number; onGenerateKG: () => void; onRefreshKnowledgeGraphs: () => void; onOpenContextDocuments: () => void; } export function AgentGraphsSection({ trace, kgData, loading, error, isGenerating, isPolling, generationProgress, onGenerateKG, onRefreshKnowledgeGraphs, onOpenContextDocuments, }: AgentGraphsSectionProps) { // const { mode: kgDisplayMode } = useKGDisplayMode(); const { openModal } = useModal(); const { showNotification } = useNotification(); const { actions: navigationActions } = useNavigation(); const { actions } = useAgentGraph(); // Helper to show both toast and persistent notifications const showSystemNotification = React.useCallback( (notification: { type: "success" | "error" | "warning" | "info"; title: string; message: string; }) => { showNotification(notification); navigationActions.addNotification({ type: notification.type, title: notification.title, message: notification.message, }); }, [showNotification, navigationActions] ); const handleViewKnowledgeGraph = (kgId: string) => { const kg = kgData.find((k) => k.kg_id === kgId || k.id === kgId); if (!kg) return; console.log("Selected KG:", kg); actions.setSelectedKnowledgeGraph(kg); actions.setActiveView("kg-visualizer"); }; return (
{/* Agent Graphs Section */}
Agent Graphs
{/* Action buttons in top right */}
{/* Context Documents Button */}

Context Documents

Manage domain knowledge, schemas, and guidelines to improve extraction quality.

{/* Generate Button */}

Generate New Agent Graph

Create a new agent graph with different chunking strategies. You can generate multiple graphs to compare approaches and insights.

{/* Subtitle */}

Generated knowledge graphs from this trace

{loading ? (
) : error ? (
{error}
) : kgData.length > 0 ? ( <> {/* Display mode indicator
{getDisplayModeDescription(kgDisplayMode)}
*/} { const confirmMessage = `Are you sure you want to delete the knowledge graph "${name}"? This will permanently remove: - All extracted entities and relationships - Generated insights and analysis - Historical comparison data This action cannot be undone.`; if (!confirm(confirmMessage)) { return; } try { const response = await fetch( `/api/knowledge-graphs/${kgId}`, { method: "DELETE", headers: { "Content-Type": "application/json", }, } ); if (!response.ok) { throw new Error( `API error: ${response.status} ${response.statusText}` ); } const data = await response.json(); console.log("Knowledge graph deleted:", data); // Refresh the knowledge graphs list onRefreshKnowledgeGraphs(); } catch (error) { console.error("Error deleting knowledge graph:", error); alert( `Error deleting knowledge graph: ${ error instanceof Error ? error.message : String(error) }` ); } }} onReplayKg={async (kgId, traceId, runId) => { try { // Import the temporal API functions const { fetchTemporalGraphData, validateTemporalData } = await import("@/lib/temporal-api"); // Validate temporal data availability const isValid = await validateTemporalData(traceId, runId); if (!isValid) { showSystemNotification({ type: "error", title: "Insufficient Data", message: "Need at least 2 window knowledge graphs for temporal replay.", }); return; } // Fetch temporal data const temporalData = await fetchTemporalGraphData( traceId, runId ); // Set temporal data and navigate to visualizer actions.setSelectedTemporalData(temporalData); actions.setActiveView("temporal-visualizer"); showSystemNotification({ type: "success", title: "Temporal Visualization", message: "Loading temporal knowledge graph visualization...", }); } catch (error) { console.error("Error starting temporal replay:", error); showSystemNotification({ type: "error", title: "Replay Error", message: "Failed to load temporal data for replay.", }); } }} onViewSegment={async (traceId, start, end, window) => { try { const segmentData = await api.traces.extractSegment( traceId, start, end ); openModal( "trace-segment", `Trace Segment - Window ${window}`, { trace: trace, segment: { content: segmentData.content, startChar: start, endChar: end, windowIndex: window, }, }, { size: "xl", closable: true, } ); } catch (error) { console.error("Error loading trace segment:", error); showSystemNotification({ type: "error", title: "Failed to Load Segment", message: "Could not load the trace segment. Please try again.", }); } }} currentTraceId={trace.trace_id} /> ) : (

No Agent Graphs Yet

Generate your first agent graph to start analyzing this trace

)}
); }