import React, { useState, useEffect } from "react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Brain, Zap, Star, Cpu, FlaskConical } from "lucide-react"; import { api } from "@/lib/api"; export type MethodType = "production" | string; // Allow for baseline method names interface MethodOption { id: string; name: string; description: string; method_type: "production" | "baseline"; schema_type: "reference_based" | "direct_based"; supported_features: string[]; processing_type: "async_crew" | "direct_call"; recommended?: boolean; } interface MethodSelectionModalProps { open: boolean; onOpenChange: (open: boolean) => void; onConfirm: (methodName: string) => void; onBack: () => void; isLoading?: boolean; selectedSplitter: string; } export function MethodSelectionModal({ open, onOpenChange, onConfirm, onBack, isLoading = false, selectedSplitter, }: MethodSelectionModalProps) { const [selectedMethod, setSelectedMethod] = useState("production"); const [methods, setMethods] = useState([]); const [loadingMethods, setLoadingMethods] = useState(false); // Fetch available methods when modal opens useEffect(() => { if (open) { fetchMethods(); } }, [open]); const fetchMethods = async () => { setLoadingMethods(true); try { const response = await api.methods.getAvailable(); const methodList = Object.entries(response.methods).map( ([id, method]: [string, any]) => ({ id, ...method, recommended: id === "production", }) ); setMethods(methodList); } catch (error) { console.error("Failed to fetch methods:", error); // Fallback to default production method setMethods([ { id: "production", name: "Multi-Agent Knowledge Extractor", description: "Production CrewAI-based multi-agent system with content reference resolution", method_type: "production", schema_type: "reference_based", supported_features: [ "content_references", "line_numbers", "failure_detection", ], processing_type: "async_crew", recommended: true, }, ]); } finally { setLoadingMethods(false); } }; const handleConfirm = () => { const finalMethodName = selectedMethod || "production"; console.log("MethodSelectionModal: selectedMethod state:", selectedMethod); console.log("MethodSelectionModal: finalMethodName:", finalMethodName); console.log( "MethodSelectionModal: About to call onConfirm with:", finalMethodName ); onConfirm(finalMethodName); }; const getMethodIcon = (method: MethodOption) => { if (method.method_type === "production") { return Brain; } if (method.supported_features.includes("clustering")) { return Cpu; } if (method.supported_features.includes("llm")) { return Zap; } return FlaskConical; }; const getSplitterDisplayName = (splitterType: string) => { switch (splitterType) { case "agent_semantic": return "Agent Semantic Splitter"; case "json": return "JSON Splitter"; case "prompt_interaction": return "Prompt Interaction Splitter"; default: return splitterType; } }; if (loadingMethods) { return (
Loading extraction methods...
); } // Group methods by type const productionMethods = methods.filter( (m) => m.method_type === "production" ); const baselineMethods = methods.filter((m) => m.method_type === "baseline"); return ( Select Extraction Method Using {getSplitterDisplayName(selectedSplitter)}{" "} for chunking.
Now choose the extraction method for knowledge graph generation:
{/* Production Methods */} {productionMethods.length > 0 && (

Production Methods

{productionMethods.map((method) => { const Icon = getMethodIcon(method); const isSelected = selectedMethod === method.id; return ( { console.log( "MethodSelectionModal: Clicking baseline method:", method.id, method.name ); setSelectedMethod(method.id); }} >

{method.name}

{method.recommended && ( Recommended )}

{method.description}

{method.supported_features.map((feature) => ( {feature.replace(/_/g, " ")} ))}
); })}
)} {/* Baseline Methods */} {baselineMethods.length > 0 && (

Baseline Methods (For Comparison)

{baselineMethods.map((method) => { const Icon = getMethodIcon(method); const isSelected = selectedMethod === method.id; return ( { console.log( "MethodSelectionModal: Clicking method:", method.id, method.name ); setSelectedMethod(method.id); }} >

{method.name}

{method.description}

{method.supported_features .slice(0, 2) .map((feature) => ( {feature.replace(/_/g, " ")} ))}
); })}
)}
); }