mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
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:
@@ -5,10 +5,12 @@
|
||||
* Messages use i18n keys with interpolation params — callers must
|
||||
* translate them via t(key, params).
|
||||
*/
|
||||
import type { ModelProviderOption } from "@/api/models"
|
||||
|
||||
import {
|
||||
KNOWN_PROVIDER_KEYS,
|
||||
PROVIDER_ALIASES,
|
||||
findClosestProvider,
|
||||
getCanonicalProviderKey,
|
||||
getKnownProviderKeys,
|
||||
} from "./provider-registry"
|
||||
|
||||
export type ValidationLevel = "error" | "warning" | "success"
|
||||
@@ -27,9 +29,11 @@ export interface FieldValidation {
|
||||
export function validateModelField(
|
||||
input: string,
|
||||
selectedProvider?: string,
|
||||
backendOptions?: ModelProviderOption[],
|
||||
): FieldValidation {
|
||||
const trimmed = input.trim()
|
||||
if (!trimmed) return { level: "success", messageKey: "" }
|
||||
const knownProviderKeys = getKnownProviderKeys(backendOptions)
|
||||
|
||||
// Hard errors
|
||||
if (/\s/.test(trimmed)) {
|
||||
@@ -78,10 +82,10 @@ export function validateModelField(
|
||||
return { level: "error", messageKey: "models.validation.emptyModel" }
|
||||
}
|
||||
|
||||
if (!KNOWN_PROVIDER_KEYS.has(provider)) {
|
||||
if (!knownProviderKeys.has(provider)) {
|
||||
// Check aliases
|
||||
const alias = PROVIDER_ALIASES[provider]
|
||||
if (alias) {
|
||||
const alias = getCanonicalProviderKey(provider, backendOptions)
|
||||
if (alias && alias !== provider) {
|
||||
return {
|
||||
level: "warning",
|
||||
messageKey: "models.validation.shouldUse",
|
||||
@@ -90,7 +94,7 @@ export function validateModelField(
|
||||
}
|
||||
}
|
||||
// Typo check
|
||||
const closest = findClosestProvider(provider)
|
||||
const closest = findClosestProvider(provider, backendOptions)
|
||||
if (closest) {
|
||||
return {
|
||||
level: "warning",
|
||||
|
||||
Reference in New Issue
Block a user