"use client"; import React, { useState, useEffect } from 'react'; import { motion } from 'framer-motion'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Brain, Zap, Bot, AlertCircle, CheckCircle, Settings2, RefreshCw, Save, RotateCcw, Loader2 } from 'lucide-react'; import { useLLMConfigs, useLLMPreferences } from '@/hooks/use-llm-configs'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { toast } from 'sonner'; const ROLE_DESCRIPTIONS = { long_context: { icon: Brain, title: 'Long Context LLM', description: 'Handles complex tasks requiring extensive context understanding and reasoning', color: 'bg-blue-100 text-blue-800 border-blue-200', examples: 'Document analysis, research synthesis, complex Q&A', characteristics: ['Large context window', 'Deep reasoning', 'Complex analysis'] }, fast: { icon: Zap, title: 'Fast LLM', description: 'Optimized for quick responses and real-time interactions', color: 'bg-green-100 text-green-800 border-green-200', examples: 'Quick searches, simple questions, instant responses', characteristics: ['Low latency', 'Quick responses', 'Real-time chat'] }, strategic: { icon: Bot, title: 'Strategic LLM', description: 'Advanced reasoning for planning and strategic decision making', color: 'bg-purple-100 text-purple-800 border-purple-200', examples: 'Planning workflows, strategic analysis, complex problem solving', characteristics: ['Strategic thinking', 'Long-term planning', 'Complex reasoning'] } }; export function LLMRoleManager() { const { llmConfigs, loading: configsLoading, error: configsError, refreshConfigs } = useLLMConfigs(); const { preferences, loading: preferencesLoading, error: preferencesError, updatePreferences, refreshPreferences } = useLLMPreferences(); const [assignments, setAssignments] = useState({ long_context_llm_id: preferences.long_context_llm_id || '', fast_llm_id: preferences.fast_llm_id || '', strategic_llm_id: preferences.strategic_llm_id || '' }); const [hasChanges, setHasChanges] = useState(false); const [isSaving, setIsSaving] = useState(false); useEffect(() => { const newAssignments = { long_context_llm_id: preferences.long_context_llm_id || '', fast_llm_id: preferences.fast_llm_id || '', strategic_llm_id: preferences.strategic_llm_id || '' }; setAssignments(newAssignments); setHasChanges(false); }, [preferences]); const handleRoleAssignment = (role: string, configId: string) => { const newAssignments = { ...assignments, [role]: configId === 'unassigned' ? '' : parseInt(configId) }; setAssignments(newAssignments); // Check if there are changes compared to current preferences const currentPrefs = { long_context_llm_id: preferences.long_context_llm_id || '', fast_llm_id: preferences.fast_llm_id || '', strategic_llm_id: preferences.strategic_llm_id || '' }; const hasChangesNow = Object.keys(newAssignments).some( key => newAssignments[key as keyof typeof newAssignments] !== currentPrefs[key as keyof typeof currentPrefs] ); setHasChanges(hasChangesNow); }; const handleSave = async () => { setIsSaving(true); const numericAssignments = { long_context_llm_id: typeof assignments.long_context_llm_id === 'string' ? (assignments.long_context_llm_id ? parseInt(assignments.long_context_llm_id) : undefined) : assignments.long_context_llm_id, fast_llm_id: typeof assignments.fast_llm_id === 'string' ? (assignments.fast_llm_id ? parseInt(assignments.fast_llm_id) : undefined) : assignments.fast_llm_id, strategic_llm_id: typeof assignments.strategic_llm_id === 'string' ? (assignments.strategic_llm_id ? parseInt(assignments.strategic_llm_id) : undefined) : assignments.strategic_llm_id, }; const success = await updatePreferences(numericAssignments); if (success) { setHasChanges(false); toast.success('LLM role assignments saved successfully!'); } setIsSaving(false); }; const handleReset = () => { setAssignments({ long_context_llm_id: preferences.long_context_llm_id || '', fast_llm_id: preferences.fast_llm_id || '', strategic_llm_id: preferences.strategic_llm_id || '' }); setHasChanges(false); }; const isAssignmentComplete = assignments.long_context_llm_id && assignments.fast_llm_id && assignments.strategic_llm_id; const assignedConfigIds = Object.values(assignments).filter(id => id !== ''); const availableConfigs = llmConfigs.filter(config => config.id && config.id.toString().trim() !== ''); const isLoading = configsLoading || preferencesLoading; const hasError = configsError || preferencesError; return (
Assign your LLM configurations to specific roles for different purposes.
{availableConfigs.length}
Available Models
{assignedConfigIds.length}
Assigned Roles
{Math.round((assignedConfigIds.length / 3) * 100)}%
Completion
{isAssignmentComplete ? 'Ready' : 'Setup'}
Status