refactor(models): unify provider metadata around backend catalog (#2896)

* feat(models): unify provider metadata around backend catalog

- Move shared provider metadata and alias normalization into backend-owned provider catalog
- Expose display, fetch, auth, and default model metadata through /api/models provider_options
- Replace frontend static provider registry with catalog-driven selection, validation, grouping, and fallback rendering
- Treat provider default api_base as placeholder and effective fetch/test base while keep submitted api_base separate from derived defaults
- Add model page retry handling, touched locale updates, and provider metadata assertions in backend tests

* fix(models): canonicalize backend provider aliases and common models

* fix(models): restore deepseek common model recommendations
This commit is contained in:
LC authored and GitHub committed 2026-05-20 11:50:34 +08:00
1 parent 639b32703a
commit 548dc15acd
28 files changed
+1441 -1084

No files matched your search

@@ -11,7 +11,6 @@ import {
CommandItem,
CommandList,
} from "@/components/ui/command"
import { Input } from "@/components/ui/input"
import {
Popover,
PopoverContent,
@@ -21,9 +20,9 @@ import { cn } from "@/lib/utils"
import { ProviderIcon } from "./provider-icon"
import {
type MergedProvider,
PROVIDERS,
mergeWithBackendOptions,
getCanonicalProviderKey,
type ProviderCatalogEntry,
getProviderCatalog,
} from "./provider-registry"
import type { ModelProviderOption } from "@/api/models"
@@ -48,47 +47,23 @@ export function ProviderCombobox({
}: ProviderComboboxProps) {
const { t } = useTranslation()
const [open, setOpen] = useState(false)
const [customMode, setCustomMode] = useState(false)
const [customValue, setCustomValue] = useState("")
const [containerEl, setContainerEl] = useState<HTMLElement | null>(null)
useEffect(() => {
setContainerEl(containerRef?.current ?? null)
}, [containerRef])
const allProviders: MergedProvider[] = backendOptions
? mergeWithBackendOptions(backendOptions)
: [...PROVIDERS]
.sort((a, b) => b.priority - a.priority)
.map((p) => ({
...p,
createAllowed: true,
defaultModelAllowed: false,
}))
const canonicalValue = getCanonicalProviderKey(value, backendOptions)
const allProviders: ProviderCatalogEntry[] = getProviderCatalog(backendOptions)
const visible = filterCreateAllowed
? allProviders.filter((p) => p.createAllowed)
? allProviders.filter((p) => p.createAllowed || p.key === canonicalValue)
: allProviders
const allKeys = new Set(allProviders.map((p) => p.key))
const selected = allProviders.find((p) => p.key === value)
const isCustom = value && !allKeys.has(value)
const selected = allProviders.find((p) => p.key === canonicalValue)
const showUnknownValue = value && !allKeys.has(canonicalValue)
const handleSelect = (currentValue: string) => {
if (currentValue === "__custom__") {
setCustomMode(true)
setCustomValue(isCustom ? value : "")
return
}
onChange(currentValue === value ? "" : currentValue)
setCustomMode(false)
setOpen(false)
}
const handleCustomConfirm = () => {
const trimmed = customValue.trim()
if (trimmed) {
onChange(trimmed)
}
setCustomMode(false)
onChange(currentValue === canonicalValue ? "" : currentValue)
setOpen(false)
}
@@ -97,7 +72,6 @@ export function ProviderCombobox({
open={open}
onOpenChange={(isOpen: boolean) => {
setOpen(isOpen)
if (!isOpen) setCustomMode(false)
}}
>
<PopoverTrigger asChild>
@@ -110,12 +84,11 @@ export function ProviderCombobox({
{selected ? (
<span className="flex items-center gap-2">
<ProviderIcon
providerKey={selected.key}
providerLabel={selected.label}
provider={selected}
/>
{selected.labelZh || selected.label}
{selected.label}
</span>
) : isCustom ? (
) : showUnknownValue ? (
<span className="flex items-center gap-2 font-mono text-sm">
{value}
</span>
@@ -128,97 +101,52 @@ export function ProviderCombobox({
</Button>
</PopoverTrigger>
<PopoverContent className="w-[--radix-popover-trigger-width] p-0" container={containerEl}>
{customMode ? (
<div className="flex flex-col gap-2 p-2">
<Input
value={customValue}
onChange={(e) => setCustomValue(e.target.value)}
placeholder={t("models.combobox.customPlaceholder")}
className="h-8 font-mono text-sm"
autoFocus
onKeyDown={(e) => {
if (e.key === "Enter") handleCustomConfirm()
if (e.key === "Escape") {
setCustomMode(false)
setOpen(false)
}
}}
/>
<div className="flex gap-1">
<Button
variant="ghost"
size="sm"
className="h-7 flex-1 text-xs"
onClick={() => {
setCustomMode(false)
setOpen(false)
}}
>
{t("common.cancel")}
</Button>
<Button
size="sm"
className="h-7 flex-1 text-xs"
onClick={handleCustomConfirm}
disabled={!customValue.trim()}
>
{t("common.confirm")}
</Button>
</div>
</div>
) : (
<Command>
<CommandInput placeholder={t("models.combobox.searchProvider")} />
<CommandList>
<CommandEmpty>{t("models.combobox.noProvider")}</CommandEmpty>
<CommandGroup>
{visible.map((provider) => (
<Command>
<CommandInput placeholder={t("models.combobox.searchProvider")} />
<CommandList>
<CommandEmpty>
{backendOptions && backendOptions.length > 0
? t("models.combobox.noProvider")
: t("models.combobox.noCatalog")}
</CommandEmpty>
<CommandGroup>
{visible.map((provider) => {
const disabled = !provider.createAllowed && provider.key !== value
return (
<CommandItem
key={provider.key}
value={provider.key}
keywords={[
provider.label,
provider.labelZh || "",
...(provider.aliases || []),
...provider.aliases,
]}
onSelect={handleSelect}
disabled={disabled}
>
<span className="flex items-center gap-2">
<ProviderIcon
providerKey={provider.key}
providerLabel={provider.label}
provider={provider}
/>
<span>{provider.labelZh || provider.label}</span>
<span>{provider.label}</span>
{provider.isLocal && (
<span className="text-muted-foreground text-xs">
{t("models.combobox.local")}
</span>
<span className="text-muted-foreground text-xs">
{t("models.combobox.local")}
</span>
)}
</span>
<IconCheck
className={cn(
"ml-auto size-4",
value === provider.key ? "opacity-100" : "opacity-0",
canonicalValue === provider.key ? "opacity-100" : "opacity-0",
)}
/>
</CommandItem>
))}
<CommandItem
value="__custom__"
keywords={["custom", "自定义"]}
onSelect={handleSelect}
>
<span className="text-muted-foreground italic">
{t("models.combobox.custom")}
</span>
{isCustom && (
<IconCheck className="ml-auto size-4 opacity-100" />
)}
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
)}
)
})}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
)