feat(provider,web,asr): enhance model management with explicit provider metadata (#2701)

* feat(provider,web): enhance model management with provider options

* fix(asr): enhance compatibility for ElevenLabs transcription model

* fix(provider,web): align provider availability predicates and add flow gating

* fix(web,asr): preserve legacy elevenlabs transcription configs

* fix(provider,web,asr): normalize elevenlabs configs and gate default chat models

* fix: tighten provider catalog and elevenlabs compatibility
This commit is contained in:
LC authored and GitHub committed 2026-05-06 16:06:49 +08:00
1 parent 4d3070e849
commit 81a050555d
26 files changed
+2341 -193

No files matched your search

@@ -1,8 +1,13 @@
import { IconLoader2 } from "@tabler/icons-react"
import { useEffect, useState } from "react"
import { useEffect, useMemo, useState } from "react"
import { useTranslation } from "react-i18next"
import { type ModelInfo, setDefaultModel, updateModel } from "@/api/models"
import {
type ModelInfo,
type ModelProviderOption,
setDefaultModel,
updateModel,
} from "@/api/models"
import { ConfigChangeNotice } from "@/components/config-change-notice"
import { maskedSecretPlaceholder } from "@/components/secret-placeholder"
import {
@@ -13,6 +18,13 @@ import {
} from "@/components/shared-form"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import {
Sheet,
SheetContent,
@@ -25,6 +37,15 @@ import { Textarea } from "@/components/ui/textarea"
import { showSaveSuccessOrRestartToast } from "@/lib/restart-required"
import { refreshGatewayState } from "@/store/gateway"
import {
findProviderOption,
getProviderDefaultAPIBase,
getProviderDefaultAuthMethod,
getProviderLabel,
getSortedProviderOptions,
isProviderAuthMethodLocked,
} from "./provider-label"
interface EditForm {
provider: string
modelId: string
@@ -45,6 +66,7 @@ interface EditForm {
interface EditModelSheetProps {
model: ModelInfo | null
providerOptions: ModelProviderOption[]
open: boolean
onClose: () => void
onSaved: () => void
@@ -76,6 +98,7 @@ function buildInitialEditForm(model: ModelInfo): EditForm {
export function EditModelSheet({
model,
providerOptions,
open,
onClose,
onSaved,
@@ -102,26 +125,99 @@ export function EditModelSheet({
const [setAsDefault, setSetAsDefault] = useState(false)
const [error, setError] = useState("")
const initialForm = model ? buildInitialEditForm(model) : null
const sortedProviderOptions = useMemo(
() => getSortedProviderOptions(providerOptions),
[providerOptions],
)
const currentProviderID = model
? (findProviderOption(model.provider, providerOptions)?.id ??
model.provider?.trim().toLowerCase() ??
"")
: ""
const selectedProviderOption = findProviderOption(
form.provider,
providerOptions,
)
const authMethodLocked = isProviderAuthMethodLocked(
form.provider,
providerOptions,
)
const defaultAuthMethod = getProviderDefaultAuthMethod(
form.provider,
providerOptions,
)
const effectiveAuthMethod = (
authMethodLocked ? defaultAuthMethod : form.authMethod
)
.trim()
.toLowerCase()
const providerError = selectedProviderOption
? ""
: t("models.field.providerInvalid")
const defaultModelAllowed =
selectedProviderOption?.default_model_allowed !== false
const willClearDefaultOnSave =
model?.is_default === true && defaultModelAllowed === false
const apiBasePlaceholder =
getProviderDefaultAPIBase(form.provider, providerOptions) ||
"https://api.example.com/v1"
const isDirty =
model != null &&
(JSON.stringify(form) !== JSON.stringify(initialForm) ||
setAsDefault !== model.is_default)
useEffect(() => {
if (model) {
setForm(buildInitialEditForm(model))
setSetAsDefault(model.is_default)
setError("")
if (model) {
const initialForm = buildInitialEditForm(model)
const option = findProviderOption(initialForm.provider, providerOptions)
if (option?.auth_method_locked && !initialForm.authMethod) {
initialForm.authMethod = option.default_auth_method ?? ""
}
}, [model])
setForm(initialForm)
setSetAsDefault(model.is_default && model.default_model_allowed !== false)
setError("")
}
}, [model, providerOptions])
const setField =
(key: keyof EditForm) =>
(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>
(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
if (error) {
setError("")
}
setForm((f) => ({ ...f, [key]: e.target.value }))
}
const setProvider = (value: string) => {
if (error) {
setError("")
}
setForm((f) => {
const previousOption = findProviderOption(f.provider, providerOptions)
const nextOption = findProviderOption(value, providerOptions)
let authMethod = f.authMethod
if (nextOption?.auth_method_locked) {
authMethod = nextOption.default_auth_method ?? ""
} else if (
previousOption?.auth_method_locked &&
f.authMethod === (previousOption.default_auth_method ?? "")
) {
authMethod = ""
}
return { ...f, provider: value, authMethod }
})
const nextOption = findProviderOption(value, providerOptions)
if (nextOption?.default_model_allowed === false) {
setSetAsDefault(false)
}
}
const handleSave = async () => {
if (!model) return
if (!selectedProviderOption) {
setError(providerError)
return
}
if (!form.modelId.trim()) {
setError(t("models.add.errorRequired"))
return
@@ -136,7 +232,9 @@ export function EditModelSheet({
api_base: form.apiBase || undefined,
api_key: form.apiKey || undefined,
proxy: form.proxy || undefined,
auth_method: form.authMethod || undefined,
auth_method: authMethodLocked
? defaultAuthMethod || undefined
: form.authMethod || undefined,
connect_mode: form.connectMode || undefined,
workspace: form.workspace || undefined,
rpm: form.rpm ? Number(form.rpm) : undefined,
@@ -172,7 +270,7 @@ export function EditModelSheet({
}
}
const isOAuth = model?.auth_method === "oauth"
const isOAuth = effectiveAuthMethod === "oauth"
const hasSavedAPIKey = Boolean(model?.api_key)
const apiKeyPlaceholder = hasSavedAPIKey
? maskedSecretPlaceholder(
@@ -201,12 +299,36 @@ export function EditModelSheet({
<Field
label={t("models.field.provider")}
hint={t("models.field.providerHint")}
error={providerError}
required
>
<Input
value={form.provider}
onChange={setField("provider")}
placeholder={t("models.field.providerPlaceholder")}
/>
<Select
value={selectedProviderOption?.id}
onValueChange={setProvider}
>
<SelectTrigger
className="w-full"
aria-invalid={!!providerError}
>
<SelectValue
placeholder={t("models.field.providerPlaceholder")}
/>
</SelectTrigger>
<SelectContent>
{sortedProviderOptions.map((option) => (
<SelectItem
key={option.id}
value={option.id}
disabled={
!option.create_allowed &&
option.id !== currentProviderID
}
>
{getProviderLabel(option.id)}
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
<Field
@@ -241,16 +363,23 @@ export function EditModelSheet({
<Input
value={form.apiBase}
onChange={setField("apiBase")}
placeholder="https://api.example.com/v1"
placeholder={apiBasePlaceholder}
disabled={isOAuth}
/>
</Field>
<SwitchCardField
label={t("models.defaultOnSave.label")}
hint={t("models.defaultOnSave.description")}
hint={
willClearDefaultOnSave
? t("models.defaultOnSave.clearOnSave")
: defaultModelAllowed
? t("models.defaultOnSave.description")
: t("models.defaultOnSave.unsupportedProvider")
}
checked={setAsDefault}
onCheckedChange={setSetAsDefault}
disabled={!defaultModelAllowed}
/>
<AdvancedSection>
@@ -267,12 +396,17 @@ export function EditModelSheet({
<Field
label={t("models.field.authMethod")}
hint={t("models.field.authMethodHint")}
hint={
authMethodLocked
? t("models.field.authMethodManagedHint")
: t("models.field.authMethodHint")
}
>
<Input
value={form.authMethod}
value={authMethodLocked ? defaultAuthMethod : form.authMethod}
onChange={setField("authMethod")}
placeholder="oauth"
disabled={authMethodLocked}
/>
</Field>