import { useEffect, useMemo } from 'react'; import { ChevronLeft } from 'lucide-react'; import { Controller, useFormContext } from 'react-hook-form'; import type { AgentForm, AgentModelPanelProps } from '~/common'; import { SelectDropDown, ModelParameters } from '~/components/ui'; import { cn, cardStyle } from '~/utils'; import { useLocalize } from '~/hooks'; import { Panel } from '~/common'; export default function ModelPanel({ setActivePanel, providers, models: modelsData, }: AgentModelPanelProps) { const localize = useLocalize(); const { control, setValue, watch } = useFormContext(); const model = watch('model'); const providerOption = watch('provider'); const provider = useMemo(() => { if (!providerOption) { return ''; } return typeof providerOption === 'string' ? providerOption : providerOption.value; }, [providerOption]); const models = useMemo(() => (provider ? modelsData[provider] : []), [modelsData, provider]); useEffect(() => { if (provider && model) { const modelExists = models.includes(model); if (!modelExists) { const newModels = modelsData[provider]; setValue('model', newModels[0] ?? ''); } } }, [provider, models, modelsData, setValue, model]); return (
{localize('com_ui_model_parameters')}
{/* Endpoint aka Provider for Agents */}
( <> {error && ( {localize('com_ui_field_required')} )} )} />
{/* Model */}
( <> {provider && error && ( {localize('com_ui_field_required')} )} )} />
( <> )} />
( <> )} />
( <> )} />
( <> )} />
( <> )} />
( <> )} />
); }