import type { ProviderInfo } from '~/types/model'; import { useEffect } from 'react'; import type { ModelInfo } from '~/lib/modules/llm/types'; interface ModelSelectorProps { model?: string; setModel?: (model: string) => void; provider?: ProviderInfo; setProvider?: (provider: ProviderInfo) => void; modelList: ModelInfo[]; providerList: ProviderInfo[]; apiKeys: Record; modelLoading?: string; } export const ModelSelector = ({ model, setModel, provider, setProvider, modelList, providerList, modelLoading, }: ModelSelectorProps) => { // Load enabled providers from cookies // Update enabled providers when cookies change useEffect(() => { // If current provider is disabled, switch to first enabled provider if (providerList.length == 0) { return; } if (provider && !providerList.map((p) => p.name).includes(provider.name)) { const firstEnabledProvider = providerList[0]; setProvider?.(firstEnabledProvider); // Also update the model to the first available one for the new provider const firstModel = modelList.find((m) => m.provider === firstEnabledProvider.name); if (firstModel) { setModel?.(firstModel.name); } } }, [providerList, provider, setProvider, modelList, setModel]); if (providerList.length === 0) { return (

No providers are currently enabled. Please enable at least one provider in the settings to start using the chat.

); } return (
); };