fix(providers): preserve alias when applying discovered models

ModelDiscoveryPanel now hands the full ModelInfo objects to onApply
instead of just the model names, and BaseProviderForm copies each
incoming alias into the new form.models row so suggestions from
endpoints that return alias metadata are no longer silently dropped.
This commit is contained in:
LTbinglingfeng
2026-05-25 01:54:58 +08:00
Unverified
parent fafc4b78e0
commit c23fd6975e
2 changed files with 16 additions and 10 deletions
@@ -15,6 +15,7 @@ import type {
OpenAIProviderConfig,
ProviderKeyConfig,
} from '@/types';
import type { ModelInfo } from '@/utils/models';
import { PROVIDER_DESCRIPTORS } from '../../descriptors';
import type {
ApiKeyEntryInput,
@@ -267,8 +268,8 @@ export function BaseProviderForm({
setDiscoveryOpen(false);
};
const applyDiscoveredModels = (names: string[]) => {
if (!names.length) return;
const applyDiscoveredModels = (incoming: ModelInfo[]) => {
if (!incoming.length) return;
setForm((prev) => {
const seen = new Set<string>();
const next: ModelEntryInput[] = [];
@@ -284,14 +285,17 @@ export function BaseProviderForm({
const placeholderIdx = next.findIndex(
(it) => !(it.name ?? '').trim() && !(it.alias ?? '').trim()
);
if (placeholderIdx !== -1 && names.length > 0) {
if (placeholderIdx !== -1) {
next.splice(placeholderIdx, 1);
}
names.forEach((name) => {
const trimmed = name.trim();
incoming.forEach((info) => {
const trimmed = info.name.trim();
if (!trimmed || seen.has(trimmed)) return;
seen.add(trimmed);
next.push({ name: trimmed, alias: '' });
next.push({
name: trimmed,
alias: (info.alias ?? '').trim(),
});
});
return { ...prev, models: next };
});
@@ -16,7 +16,7 @@ interface ModelDiscoveryPanelProps {
hasFetched: boolean;
existingNames: Set<string>;
mutating?: boolean;
onApply: (names: string[]) => void;
onApply: (picked: ModelInfo[]) => void;
onReload: () => void;
onClose: () => void;
}
@@ -70,9 +70,11 @@ export function ModelDiscoveryPanel({
};
const handleApply = () => {
const names = Array.from(selected).filter((n) => !existingNames.has(n));
if (!names.length) return;
onApply(names);
const picked = models.filter(
(m) => selected.has(m.name) && !existingNames.has(m.name)
);
if (!picked.length) return;
onApply(picked);
setSelected(new Set());
};