import { useMemo, useState } from "react" import { Brain, Gauge, Globe, Lightbulb, MessageSquare, Mic, RefreshCw, Server, type LucideIcon, } from "lucide-react" import { VIEW_GROUPS } from "@/App" import type { AdminConfig, AdminSection } from "@/lib/types" import { cn } from "@/lib/utils" import { FieldRow } from "./FieldControl" import { Badge } from "./ui/badge" import { Button } from "./ui/button" import { Card, CardContent } from "./ui/card" const SECTION_ICONS: Record = { providers: Server, runtime: Gauge, models: Brain, reasoning: Lightbulb, web_tools: Globe, messaging: MessageSquare, voice: Mic, } interface ConfigViewProps { config: AdminConfig values: Record onValuesChange: (values: Record) => void modelOptions: string[] onRefreshModels: (providerId: string, done: () => void) => void focusedView: string } export function ConfigView({ config, values, onValuesChange, modelOptions, onRefreshModels, focusedView, }: ConfigViewProps) { const group = VIEW_GROUPS.find((view) => view.id === focusedView) ?? VIEW_GROUPS[0] const sectionIds = new Set(group.sections) const sections = useMemo( () => config.sections .filter((section) => sectionIds.has(section.id)) .map((section) => ({ section, fields: config.fields.filter((field) => field.section === section.id), })) .filter((entry) => entry.fields.length > 0), [config, sectionIds], ) return ( <> {sections.map(({ section, fields }) => ( ))} ) } interface SettingsSectionProps { section: AdminSection fields: AdminConfig["fields"] values: Record onValuesChange: (values: Record) => void modelOptions: string[] onRefreshModels: (providerId: string, done: () => void) => void } function SettingsSection({ section, fields, values, onValuesChange, modelOptions, onRefreshModels, }: SettingsSectionProps) { const hasAdvanced = fields.some((field) => field.advanced) const [advancedOpen, setAdvancedOpen] = useState(false) const [refreshing, setRefreshing] = useState(false) const isModelSection = section.id === "models" const SectionIcon = SECTION_ICONS[section.id] ?? Server const fieldRows = (showAdvanced: boolean) => fields .filter((field) => !field.advanced || showAdvanced) .map((field, index) => ( onValuesChange({ ...values, [key]: value })} onMessage={() => undefined} className={cn(isModelSection && index === 0 && "md:col-span-2")} /> )) return (

{section.label}

{section.description ? (

{section.description}

) : null}
{isModelSection ? (
{modelOptions.length > 0 ? ( {modelOptions.length} model {modelOptions.length === 1 ? "" : "s"} ) : null}
) : null}
{fieldRows(advancedOpen)}
{hasAdvanced ? ( ) : null}
) }