"use client"; import { motion } from "framer-motion"; import { AlertCircle, Bot, Brain, CheckCircle, Zap } from "lucide-react"; import { useEffect, useState } from "react"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { useLLMConfigs, useLLMPreferences } from "@/hooks/use-llm-configs"; 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", }, 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", }, 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", }, }; interface AssignRolesStepProps { onPreferencesUpdated?: () => Promise; } export function AssignRolesStep({ onPreferencesUpdated }: AssignRolesStepProps) { const { llmConfigs } = useLLMConfigs(); const { preferences, updatePreferences } = 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 || "", }); useEffect(() => { setAssignments({ long_context_llm_id: preferences.long_context_llm_id || "", fast_llm_id: preferences.fast_llm_id || "", strategic_llm_id: preferences.strategic_llm_id || "", }); }, [preferences]); const handleRoleAssignment = async (role: string, configId: string) => { const newAssignments = { ...assignments, [role]: configId === "" ? "" : parseInt(configId), }; setAssignments(newAssignments); // Auto-save if this assignment completes all roles const hasAllAssignments = newAssignments.long_context_llm_id && newAssignments.fast_llm_id && newAssignments.strategic_llm_id; if (hasAllAssignments) { const numericAssignments = { long_context_llm_id: typeof newAssignments.long_context_llm_id === "string" ? parseInt(newAssignments.long_context_llm_id) : newAssignments.long_context_llm_id, fast_llm_id: typeof newAssignments.fast_llm_id === "string" ? parseInt(newAssignments.fast_llm_id) : newAssignments.fast_llm_id, strategic_llm_id: typeof newAssignments.strategic_llm_id === "string" ? parseInt(newAssignments.strategic_llm_id) : newAssignments.strategic_llm_id, }; const success = await updatePreferences(numericAssignments); // Refresh parent preferences state if (success && onPreferencesUpdated) { await onPreferencesUpdated(); } } }; const isAssignmentComplete = assignments.long_context_llm_id && assignments.fast_llm_id && assignments.strategic_llm_id; if (llmConfigs.length === 0) { return (

No LLM Configurations Found

Please add at least one LLM provider in the previous step before assigning roles.

); } return (
{/* Info Alert */} Assign your LLM configurations to specific roles. Each role serves different purposes in your workflow. {/* Role Assignment Cards */}
{Object.entries(ROLE_DESCRIPTIONS).map(([key, role]) => { const IconComponent = role.icon; const currentAssignment = assignments[`${key}_llm_id` as keyof typeof assignments]; const assignedConfig = llmConfigs.find((config) => config.id === currentAssignment); return (
{role.title} {role.description}
{currentAssignment && }
Use cases: {role.examples}
{assignedConfig && (
Assigned: {assignedConfig.provider} {assignedConfig.name}
Model: {assignedConfig.model_name}
)}
); })}
{/* Status Indicator */} {isAssignmentComplete && (
All roles assigned and saved!
)} {/* Progress Indicator */}
Progress:
{Object.keys(ROLE_DESCRIPTIONS).map((key, _index) => (
))}
{Object.values(assignments).filter(Boolean).length} of{" "} {Object.keys(ROLE_DESCRIPTIONS).length} roles assigned
); }