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("openai_structured"); 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 === "openai_structured", }) ); // HuggingFace UI: hide all baseline methods from selection const productionOnly = methodList.filter( (m: any) => m.method_type === "production" ); setMethods(productionOnly); } catch (error) { console.error("Failed to fetch methods:", error); // Fallback to default method setMethods([ { id: "openai_structured", name: "OpenAI Structured Outputs", description: "Simple OpenAI structured outputs extractor using Pydantic models", method_type: "production", schema_type: "reference_based", supported_features: ["structured_outputs", "direct_extraction"], processing_type: "direct_call", recommended: true, }, ]); } finally { setLoadingMethods(false); } }; const handleConfirm = () => { const finalMethodName = selectedMethod || "openai_structured"; 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" ); // Ensure display order: recommended (openai_structured) first const sortedProductionMethods = [...productionMethods].sort((a, b) => { if (!!a.recommended === !!b.recommended) return 0; return a.recommended ? -1 : 1; }); // Hide baseline methods in the HuggingFace version const baselineMethods: MethodOption[] = []; return ( Select Extraction Method Choose the extraction method for knowledge graph generation:
{/* Production Methods */} {productionMethods.length > 0 && (

Production Methods

{sortedProductionMethods.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, " ")} ))}
); })}
)}
); }