'use client' import { useId, useState } from 'react' import { useTranslation } from 'react-i18next' import ProviderIcon from '@/components/common/ProviderIcon' import { formatProviderLabel } from '@/lib/provider-branding' import type { ApiFormat, ServiceName } from '@/lib/model-catalog-types' import { SERVICE_TITLES } from '@/lib/provider-registry' import { inputClass, selectClass, subPanelClass } from './shared' import { registryButton, registryPrimary } from './RegistryControls' export type ProviderCatalogOption = { value: string; label: string; services: ServiceName[] } export type CustomProviderInput = { name: string; base_url: string } const FILTERS = [ 'all', 'multi', 'llm', 'embedding', 'voice', 'search', 'imagegen', 'videogen', 'custom', ] as const const PROTOCOLS = { openai_chat: 'OpenAI Chat Completions', openai_responses: 'OpenAI Responses', anthropic: 'Anthropic Messages', } as const export function ProviderProtocol({ value, onChange, formats, }: { value: ApiFormat onChange: (value: ApiFormat) => void formats?: readonly string[] }) { const { t } = useTranslation() return ( ) } export function AddProviderPanel({ options, vendor, onVendor, onCreate, onCancel, }: { options: ProviderCatalogOption[] vendor: string onVendor: (value: string) => void onCreate: (custom?: CustomProviderInput) => void onCancel: () => void }) { const { t, i18n } = useTranslation() const uiLanguage = i18n?.resolvedLanguage ?? i18n?.language ?? 'en' const radioName = useId() const [filter, setFilter] = useState('all') const [query, setQuery] = useState('') const [name, setName] = useState('') const [url, setUrl] = useState('') const custom = vendor === 'custom' const visible = options.map(option => ({ ...option, label: formatProviderLabel(option.value, option.label, uiLanguage), })).filter(option => { const category = filter === 'all' || (filter === 'custom' ? option.value === 'custom' : option.value !== 'custom' && (filter === 'multi' ? option.services.length > 1 : filter === 'voice' ? option.services.some(s => s === 'tts' || s === 'stt') : option.services.includes(filter as ServiceName))) return ( category && `${option.label} ${option.value}`.toLowerCase().includes(query.trim().toLowerCase()) ) }) let validUrl = false try { const parsed = new URL(url) validUrl = ['https:', 'http:'].includes(parsed.protocol) && !parsed.username && !parsed.password && Boolean(parsed.hostname) } catch {} return (

{t('Add provider')}

setQuery(e.target.value)} />
{FILTERS.map(item => ( ))}
{visible.map(option => ( ))}
{!visible.length && (

{t('settings.providerServices.noMatch')}

)} {custom && (
{url && !validUrl && (

{t('Enter a valid HTTP or HTTPS provider address.')}

)}

{t('settings.providerServices.customDescription')}

)}

{t('settings.providerServices.addHint')}

) }