import React, { useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Brain, Code, MessageSquare, Star, Database, ArrowRightLeft, Settings, } from "lucide-react"; import { MethodSelectionModal } from "./MethodSelectionModal"; import { useModelPreferences } from "@/hooks/useModelPreferences"; export type SplitterType = "agent_semantic" | "json" | "prompt_interaction"; export interface ChunkingConfig { min_chunk_size?: number; max_chunk_size?: number; } interface SplitterOption { id: SplitterType; name: string; description: string; icon: React.ElementType; badge?: { text: string; icon: React.ElementType; }; recommended?: boolean; } interface SplitterSelectionModalProps { open: boolean; onOpenChange: (open: boolean) => void; onConfirm: ( splitterType: SplitterType, methodName?: string, modelName?: string, chunkingConfig?: ChunkingConfig ) => void; isLoading?: boolean; } // HF Spaces variant: only expose the Agent Semantic Splitter const SPLITTER_OPTIONS: SplitterOption[] = [ { id: "agent_semantic", name: "Agent Semantic Splitter", description: "Intelligently splits content based on semantic meaning and agent interactions. Best for conversational traces and complex content.", icon: Brain, badge: { text: "Recommended", icon: Star, }, recommended: true, }, ]; export function SplitterSelectionModal({ open, onOpenChange, onConfirm, isLoading = false, }: SplitterSelectionModalProps) { const [selectedSplitter, setSelectedSplitter] = useState("agent_semantic"); const [showMethodSelection, setShowMethodSelection] = useState(false); const [chunkingConfig, setChunkingConfig] = useState({ min_chunk_size: 100000, // 100K chars default max_chunk_size: 300000, // 300K chars default }); const { selectedModel } = useModelPreferences(); const handleSplitterConfirm = () => { setShowMethodSelection(true); }; const handleMethodConfirm = (methodName: string) => { const finalMethodName = methodName || "production"; console.log("SplitterSelectionModal: Final method name:", finalMethodName); console.log("SplitterSelectionModal: Selected model:", selectedModel); console.log("SplitterSelectionModal: Chunking config:", chunkingConfig); // Close the modal immediately when user clicks Generate Agent Graph setShowMethodSelection(false); onOpenChange(false); // Then trigger the generation process with model parameter and chunking config onConfirm(selectedSplitter, finalMethodName, selectedModel, chunkingConfig); }; const handleMethodBack = () => { setShowMethodSelection(false); }; const handleCancel = () => { setShowMethodSelection(false); onOpenChange(false); }; // Reset state when modal closes const handleOpenChange = (open: boolean) => { if (!open) { setShowMethodSelection(false); } onOpenChange(open); }; return ( <> Select Chunking Strategy Choose how you want to split your trace content for knowledge graph generation:
{SPLITTER_OPTIONS.map((option) => { const Icon = option.icon; const BadgeIcon = option.badge?.icon; const isSelected = selectedSplitter === option.id; return ( setSelectedSplitter(option.id)} >

{option.name}

{option.badge && ( {BadgeIcon && ( )} {option.badge.text} )}

{option.description}

); })}
{/* Configuration for Agent Semantic Splitter */} {selectedSplitter === "agent_semantic" && (

Configuration

setChunkingConfig((prev) => ({ ...prev, min_chunk_size: parseInt(e.target.value) || 100000, })) } placeholder="100000" className="text-sm" />

Minimum chunk size in characters

setChunkingConfig((prev) => ({ ...prev, max_chunk_size: parseInt(e.target.value) || 300000, })) } placeholder="300000" className="text-sm" />

Maximum chunk size in characters

Smart Chunking: {" "} Balance context preservation with processing speed - defaults optimized for most traces.

)}
); }