"use client"; import { AlertCircle, Bot, Brain, CheckCircle, Zap } from "lucide-react"; import { motion } from "motion/react"; import { useTranslations } from "next-intl"; 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"; interface AssignRolesStepProps { searchSpaceId: number; onPreferencesUpdated?: () => Promise; } export function AssignRolesStep({ searchSpaceId, onPreferencesUpdated }: AssignRolesStepProps) { const t = useTranslations("onboard"); const { llmConfigs } = useLLMConfigs(searchSpaceId); const { preferences, updatePreferences } = useLLMPreferences(searchSpaceId); const ROLE_DESCRIPTIONS = { long_context: { icon: Brain, title: t("long_context_llm_title"), description: t("long_context_llm_desc"), color: "bg-blue-100 text-blue-800 border-blue-200", examples: t("long_context_llm_examples"), }, fast: { icon: Zap, title: t("fast_llm_title"), description: t("fast_llm_desc"), color: "bg-green-100 text-green-800 border-green-200", examples: t("fast_llm_examples"), }, strategic: { icon: Bot, title: t("strategic_llm_title"), description: t("strategic_llm_desc"), color: "bg-purple-100 text-purple-800 border-purple-200", examples: t("strategic_llm_examples"), }, }; 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 (

{t("no_llm_configs_found")}

{t("add_provider_before_roles")}

); } return (
{/* Info Alert */} {t("assign_roles_instruction")} {/* 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 && }
{t("use_cases")}: {role.examples}
{assignedConfig && (
{t("assigned")}: {assignedConfig.provider} {assignedConfig.name}
{t("model")}: {assignedConfig.model_name}
)}
); })}
{/* Status Indicator */} {isAssignmentComplete && (
{t("all_roles_assigned_saved")}
)} {/* Progress Indicator */}
{t("progress")}:
{Object.keys(ROLE_DESCRIPTIONS).map((key, _index) => (
))}
{t("roles_assigned", { assigned: Object.values(assignments).filter(Boolean).length, total: Object.keys(ROLE_DESCRIPTIONS).length, })}
); }