RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Fix: dedup model name (#20167)
Lynne651d8f7a444
diff --git a/internal/handler/providers.go b/internal/handler/providers.goindex 5495aba401..e1af43f0b0 100644--- a/internal/handler/providers.go+++ b/internal/handler/providers.go@@ -245,13 +245,13 @@ func (h *ProviderHandler) ListModels(c *gin.Context) {remoteNames := make(map[string]struct{}, len(remoteModels))for _, model := range remoteModels {if name, ok := model["name"].(string); ok {- remoteNames[name] = struct{}{}+ remoteNames[providerModelKey(name)] = struct{}{}}}filtered := staticModels[:0]for _, model := range staticModels {if name, ok := model["name"].(string); ok {- if _, exists := remoteNames[name]; exists {+ if _, exists := remoteNames[providerModelKey(name)]; exists {filtered = append(filtered, model)}}@@ -265,47 +265,82 @@ func (h *ProviderHandler) ListModels(c *gin.Context) {return}- // 4. Merge: static as base, remote overrides on name conflicts- merged := make(map[string]map[string]interface{})+ // 4. Merge: static as base, remote overrides on name conflicts.+ result := mergeProviderModels(staticModels, remoteModels)++ // 5. Fill missing model types using only the merged list.+ fillProviderModelMapTypes(result)++ common.SuccessWithData(c, result, "success")+}++// mergeProviderModels collapses the bundled catalog listing and a live upstream+// listing into a single entry per model, sorted by name.+//+// Names are matched case-insensitively and trimmed — an upstream listing can+// spell a model differently from the catalog (e.g. "GPT-4o" vs "gpt-4o"), and+// both must collapse instead of showing up as two rows. The first spelling seen+// wins, so a model already saved under the catalog's name keeps it.+//+// Remote entries override the catalog entry, with two exceptions: a remote+// entry that carries no model types inherits the catalog's types, and+// `max_tokens` always comes from the catalog when the catalog declares one —+// an upstream listing reports the provider's ceiling, which is not the value+// RAGFlow is configured to send.+func mergeProviderModels(staticModels, remoteModels []map[string]interface{}) []map[string]interface{} {+ merged := make(map[string]map[string]interface{}, len(staticModels)+len(remoteModels))for _, m := range staticModels {if maxTokens, ok := m["max_tokens"]; !ok || maxTokens == nil {if maxOutput, ok := m["max_output"]; ok && maxOutput != nil {m["max_tokens"] = maxOutput}}- if name, ok := m["name"].(string); ok {- merged[name] = m+ name, ok := m["name"].(string)+ if !ok {+ continue}+ key := providerModelKey(name)+ if key == "" {+ continue+ }+ m["name"] = strings.TrimSpace(name)+ merged[key] = m}for _, m := range remoteModels {- if name, ok := m["name"].(string); ok {- if existing, exists := merged[name]; exists {- if len(providerModelMapTypes(m)) == 0 && len(providerModelMapTypes(existing)) > 0 {- m["model_types"] = existing["model_types"]- }- if maxTokens, ok := existing["max_tokens"]; ok && maxTokens != nil {- m["max_tokens"] = maxTokens- }+ name, ok := m["name"].(string)+ if !ok {+ continue+ }+ key := providerModelKey(name)+ if key == "" {+ continue+ }+ name = strings.TrimSpace(name)+ if existing, exists := merged[key]; exists {+ if len(providerModelMapTypes(m)) == 0 && len(providerModelMapTypes(existing)) > 0 {+ m["model_types"] = existing["model_types"]+ }+ if maxTokens, ok := existing["max_tokens"]; ok && maxTokens != nil {+ m["max_tokens"] = maxTokens+ }+ if existingName, ok := existing["name"].(string); ok {+ name = existingName}- merged[name] = m}+ m["name"] = name+ merged[key] = m}- // 5. Fill missing model types using only the merged list.result := make([]map[string]interface{}, 0, len(merged))for _, m := range merged {result = append(result, m)}- fillProviderModelMapTypes(result)-- // 6. Sort by namesort.Slice(result, func(i, j int) bool {ni, _ := result[i]["name"].(string)nj, _ := result[j]["name"].(string)- return ni < nj+ return providerModelKey(ni) < providerModelKey(nj)})-- common.SuccessWithData(c, result, "success")+ return result}func fillProviderModelMapTypes(result []map[string]interface{}) {@@ -329,6 +364,13 @@ func fillProviderModelMapTypes(result []map[string]interface{}) {}}+// providerModelKey is the identity of a model name. Upstream listings and the+// bundled catalog can spell the same model with different case or padding, so+// everything that merges or matches models compares this normalized form.+func providerModelKey(name string) string {+ return strings.ToLower(strings.TrimSpace(name))+}+func providerModelMapTypes(model map[string]interface{}) []string {switch modelTypes := model["model_types"].(type) {case []string:diff --git a/internal/handler/providers_test.go b/internal/handler/providers_test.goindex e0f6e3baef..0bbff94125 100644--- a/internal/handler/providers_test.go+++ b/internal/handler/providers_test.go@@ -135,6 +135,75 @@ func TestFilterUnsupportedProviders(t *testing.T) {}}+// indexProviderModels keys a merged list by its normalized name.+func indexProviderModels(t *testing.T, list []map[string]interface{}) map[string]map[string]interface{} {+ t.Helper()+ indexed := make(map[string]map[string]interface{}, len(list))+ for _, m := range list {+ name, ok := m["name"].(string)+ if !ok {+ t.Fatalf("model without name: %v", m)+ }+ key := providerModelKey(name)+ if _, dup := indexed[key]; dup {+ t.Fatalf("duplicate model %q in merged list", name)+ }+ indexed[key] = m+ }+ return indexed+}++func TestMergeProviderModelsMatchesNamesCaseInsensitively(t *testing.T) {+ static := []map[string]interface{}{+ {"name": "gpt-4o", "model_types": []string{"chat"}, "max_tokens": 4096},+ {"name": "text-embedding", "model_types": []string{"embedding"}},+ }+ remote := []map[string]interface{}{+ {"name": "GPT-4o", "model_types": []string{"chat"}, "max_tokens": 128000},+ {"name": "gpt-4o-mini ", "model_types": []string{"chat"}, "max_tokens": 16384},+ }++ got := indexProviderModels(t, mergeProviderModels(static, remote))+ if len(got) != 3 {+ t.Fatalf("merged %d models, want 3: %v", len(got), got)+ }++ merged := got["gpt-4o"]+ if name := merged["name"]; name != "gpt-4o" {+ t.Errorf("name = %v, want the catalog spelling gpt-4o", name)+ }+ if maxTokens := merged["max_tokens"]; maxTokens != 4096 {+ t.Errorf("max_tokens = %v, want the catalog value 4096", maxTokens)+ }++ trimmed, ok := got["gpt-4o-mini"]+ if !ok {+ t.Fatalf("remote-only model not kept: %v", got)+ }+ if name := trimmed["name"]; name != "gpt-4o-mini" {+ t.Errorf("name = %v, want trimmed gpt-4o-mini", name)+ }+}++func TestMergeProviderModelsInheritsCatalogTypesOnConflict(t *testing.T) {+ static := []map[string]interface{}{+ {"name": "rerank-1", "model_types": []string{"rerank"}, "max_tokens": 1024},+ }+ remote := []map[string]interface{}{{"name": "Rerank-1"}}++ got := indexProviderModels(t, mergeProviderModels(static, remote))+ merged, ok := got["rerank-1"]+ if !ok {+ t.Fatalf("merged = %v, want a single rerank-1 entry", got)+ }+ if types := providerModelMapTypes(merged); !reflect.DeepEqual(types, []string{"rerank"}) {+ t.Errorf("model_types = %v, want [rerank]", types)+ }+ if maxTokens := merged["max_tokens"]; maxTokens != 1024 {+ t.Errorf("max_tokens = %v, want 1024", maxTokens)+ }+}+func TestValidateInstanceName(t *testing.T) {tests := []struct {name stringdiff --git a/web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx b/web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsxindex 47c603229b..25402111c0 100644--- a/web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx+++ b/web/src/pages/user-setting/setting-model/instance-card/add-custom-model-dialog.tsx@@ -34,6 +34,7 @@ import { Label } from '@/components/ui/label';import { Switch } from '@/components/ui/switch';import { useTranslate } from '@/hooks/common-hooks';import { IProviderModelItem } from '@/interfaces/request/llm';+import { modelNameKey } from '@/utils/llm-util';import { Loader2 } from 'lucide-react';import { useCallback, useEffect, useMemo, useRef } from 'react';import { z } from 'zod';@@ -255,7 +256,9 @@ export const AddCustomModelDialog = ({if (typeof value === 'string' &&value &&- existingNames.includes(value)+ existingNames.some(+ (n) => modelNameKey(n) === modelNameKey(value),+ )) {return t('modelNameDuplicate');}diff --git a/web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.test.tsx b/web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.test.tsxindex 15f7b862c6..e95f2bd704 100644--- a/web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.test.tsx+++ b/web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.test.tsx@@ -18,6 +18,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { act, renderHook, waitFor } from '@testing-library/react';import { useRef } from 'react';+import { modelNameKey } from '@/utils/llm-util';import { useInstanceSaveState } from '../hooks';import {DRAFT_INSTANCE_SENTINEL,@@ -197,7 +198,7 @@ describe('Bedrock model credentials', () => {instance,instanceItems: [],filteredModels: [model],- addedSet: new Set(),+ isModelAdded: () => false,setCatalog: jest.fn(),clearCatalogOverride: jest.fn(),});@@ -364,7 +365,8 @@ describe('saved instance model baseline', () => {useModelEdit({providerName,instanceName,- addedSet: new Set([persistedModel.name]),+ isModelAdded: (name: string) =>+ modelNameKey(name) === modelNameKey(persistedModel.name),updateCatalogModel: jest.fn(),clearCatalogOverride: jest.fn(),}),@@ -429,3 +431,45 @@ describe('saved instance model baseline', () => {]);});});++describe('model name matching', () => {+ it('collapses instance and catalog entries that differ only in case', () => {+ const { result } = renderHook(() =>+ useModelsDerived({+ catalog: [+ {+ name: 'gpt-4o',+ model_types: ['chat'],+ max_tokens: 4096,+ features: [],+ },+ {+ name: 'embedding-1',+ model_types: ['embedding'],+ max_tokens: 512,+ features: [],+ },+ ],+ instanceModels: [+ {+ name: 'GPT-4O',+ model_type: ['chat'],+ max_tokens: 2048,+ status: 'active',+ },+ ],+ instanceModelsLoading: false,+ instanceModelsSucceeded: true,+ draftModels: [],+ isDraftInstance: false,+ onInstanceModelsChange: jest.fn(),+ }),+ );++ expect(result.current.models.map((m) => m.name)).toEqual([+ 'GPT-4O',+ 'embedding-1',+ ]);+ expect(result.current.isModelAdded('gpt-4o')).toBe(true);+ });+});diff --git a/web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts b/web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.tsindex a89de1315e..df154fc6ff 100644--- a/web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts+++ b/web/src/pages/user-setting/setting-model/instance-card/models-section/hooks.ts@@ -28,6 +28,7 @@ import {import { IInstanceModel, IProviderInstance } from '@/interfaces/database/llm';import { IModelInfo, IProviderModelItem } from '@/interfaces/request/llm';import llmService from '@/services/llm-service';+import { modelNameKey } from '@/utils/llm-util';import {Dispatch,SetStateAction,@@ -157,14 +158,15 @@ export function useModelsCatalog({const applyCatalogOverrides = useCallback((items: IProviderModelItem[]) => {const overrides = catalogOverridesRef.current;- const names = new Set<string>();+ const keys = new Set<string>();const merged = items.map((item) => {- names.add(item.name);- const override = overrides[item.name];+ const key = modelNameKey(item.name);+ keys.add(key);+ const override = overrides[key];return override ? { ...item, ...override, name: item.name } : item;});- Object.entries(overrides).forEach(([name, override]) => {- if (!names.has(name)) {+ Object.entries(overrides).forEach(([key, override]) => {+ if (!keys.has(key)) {merged.push(override);}});@@ -173,29 +175,33 @@ export function useModelsCatalog({const updateCatalogModel = useCallback((name: string, item: IProviderModelItem) => {+ const key = modelNameKey(name);setCatalogOverrides((prev) => {const next = {...prev,- [name]: { ...(prev[name] ?? {}), ...item, name },+ [key]: { ...(prev[key] ?? {}), ...item, name },};catalogOverridesRef.current = next;return next;});setCatalog((prev) => {- if (!prev.some((m) => m.name === name)) {+ if (!prev.some((m) => modelNameKey(m.name) === key)) {return [...prev, { ...item, name }];}- return prev.map((m) => (m.name === name ? { ...m, ...item, name } : m));+ return prev.map((m) =>+ modelNameKey(m.name) === key ? { ...m, ...item, name } : m,+ );});},[],);const clearCatalogOverride = useCallback((name: string) => {+ const key = modelNameKey(name);setCatalogOverrides((prev) => {- if (!prev[name]) return prev;+ if (!prev[key]) return prev;const next = { ...prev };- delete next[name];+ delete next[key];catalogOverridesRef.current = next;return next;});@@ -330,7 +336,7 @@ interface UseModelsDerivedArgs {/*** True when this card represents a draft instance (no backend id yet).* Picks between `instanceModels` (saved) and `draftModels` (draft) as- * the source for `instanceItems` / `addedSet`.+ * the source for `instanceItems` / `isModelAdded`.*/isDraftInstance: boolean;onInstanceModelsChange: ModelsSectionProps['onInstanceModelsChange'];@@ -351,7 +357,7 @@ export function useModelsDerived({const map = new Map<string, string[]>();catalog.forEach((m) => {if (Array.isArray(m.features) && m.features.length > 0) {- map.set(m.name, m.features);+ map.set(modelNameKey(m.name), m.features);}});return map;@@ -374,7 +380,8 @@ export function useModelsDerived({const model_types = normalizeModelTypes(im.model_types ?? im.model_type ?? [],);- const catalogFeats = catalogFeatures.get(im.name) ?? im.features ?? null;+ const catalogFeats =+ catalogFeatures.get(modelNameKey(im.name)) ?? im.features ?? null;const features =im.is_tools && !hasToolFeature(catalogFeats)? [...(catalogFeats ?? []), 'is_tools']@@ -389,18 +396,21 @@ export function useModelsDerived({});}, [sourceItems, catalogFeatures]);- // Union of instance models + catalog, keyed by `name`. Instance entries- // win on conflict so that editing an already-added model loads the+ // Union of instance models + catalog, keyed by the normalized name (see+ // `modelNameKey`) — the catalog and an upstream listing can spell the same+ // model with different case, and both must collapse into one row. Instance+ // entries win on conflict so that editing an already-added model loads the// instance-specific values (e.g. a user-customised `max_tokens`) rather// than the upstream catalog defaults; catalog entries are only used to// fill in models that have not been added yet. Instance set is listed// first so already-added models stay at the top on the initial render.const models: IProviderModelItem[] = useMemo(() => {const byName = new Map<string, IProviderModelItem>();- instanceItems.forEach((m) => byName.set(m.name, m));+ instanceItems.forEach((m) => byName.set(modelNameKey(m.name), m));catalog.forEach((m) => {- if (!byName.has(m.name)) {- byName.set(m.name, m);+ const key = modelNameKey(m.name);+ if (!byName.has(key)) {+ byName.set(key, m);}});return Array.from(byName.values());@@ -408,12 +418,19 @@ export function useModelsDerived({// Mirror of `instanceItems` names - drives the +/- toggle on each row// and the batch-toggle button. For drafts this is the local "added"- // set; for saved cards it tracks what the backend has persisted.+ // set; for saved cards it tracks what the backend has persisted. Keyed+ // by normalized name so a row the catalog spells differently from the+ // saved model still reads as added.const addedSet = useMemo(- () => new Set(sourceItems.map((m: any) => m.name)),+ () => new Set(sourceItems.map((m: any) => modelNameKey(m.name))),[sourceItems],);+ const isModelAdded = useCallback(+ (name: string) => addedSet.has(modelNameKey(name)),+ [addedSet],+ );+// Keep the latest callbacks in refs so the effect below only fires// when `instanceItems` actually changes — not on every parent// re-render that passes a new arrow for the callbacks. The previous@@ -452,7 +469,7 @@ export function useModelsDerived({isDraftInstance,]);- return { instanceItems, models, addedSet };+ return { instanceItems, models, isModelAdded };}// ---------------------------------------------------------------------------@@ -675,7 +692,7 @@ interface UseModelMutationsArgs {instance: IProviderInstance | undefined;instanceItems: IProviderModelItem[];filteredModels: IProviderModelItem[];- addedSet: Set<string>;+ isModelAdded: (name: string) => boolean;setCatalog: Dispatch<SetStateAction<IProviderModelItem[]>>;clearCatalogOverride: (name: string) => void;/**@@ -698,7 +715,7 @@ export function useModelMutations({instance,instanceItems,filteredModels,- addedSet,+ isModelAdded,setCatalog,clearCatalogOverride,addDraftModel,@@ -715,8 +732,8 @@ export function useModelMutations({const allFilteredAdded = useMemo(() =>filteredModels.length > 0 &&- filteredModels.every((m) => addedSet.has(m.name)),- [filteredModels, addedSet],+ filteredModels.every((m) => isModelAdded(m.name)),+ [filteredModels, isModelAdded],);const handleAddModel = async (model: IProviderModelItem) => {@@ -758,7 +775,9 @@ export function useModelMutations({// unioned `models` list immediately. Server-side persistence happens// via `addInstanceModel` below (when there is a real instance).setCatalog((prev) =>- prev.some((m) => m.name === item.name) ? prev : [...prev, item],+ prev.some((m) => modelNameKey(m.name) === modelNameKey(item.name))+ ? prev+ : [...prev, item],);if (hideActions || isDraftInstance) {// For drafts the catalog entry alone is not enough — we also need@@ -792,21 +811,23 @@ export function useModelMutations({if (filteredModels.length === 0) return;const byName = new Map<string, IProviderModelItem>();- instanceItems.forEach((m) => byName.set(m.name, m));+ instanceItems.forEach((m) => byName.set(modelNameKey(m.name), m));let nextModels: IProviderModelItem[];if (allFilteredAdded) {- const drop = new Set(filteredModels.map((m) => m.name));- nextModels = Array.from(byName.values()).filter((m) => !drop.has(m.name));+ const drop = new Set(filteredModels.map((m) => modelNameKey(m.name)));+ nextModels = Array.from(byName.values()).filter(+ (m) => !drop.has(modelNameKey(m.name)),+ );} else {- filteredModels.forEach((m) => byName.set(m.name, m));+ filteredModels.forEach((m) => byName.set(modelNameKey(m.name), m));nextModels = Array.from(byName.values());}if (isDraftInstance) {setDraftModelsList?.(nextModels);filteredModels.forEach((m) => {- if (!addedSet.has(m.name)) {+ if (!isModelAdded(m.name)) {clearCatalogOverride(m.name);}});@@ -824,7 +845,7 @@ export function useModelMutations({model_info: buildModelInfo(nextModels),});filteredModels.forEach((m) => {- if (!addedSet.has(m.name)) {+ if (!isModelAdded(m.name)) {clearCatalogOverride(m.name);}});@@ -847,7 +868,7 @@ export function useModelMutations({interface UseModelEditArgs {providerName: string;instanceName: string;- addedSet: Set<string>;+ isModelAdded: (name: string) => boolean;isDraftInstance?: boolean;updateCatalogModel: (name: string, item: IProviderModelItem) => void;clearCatalogOverride: (name: string) => void;@@ -857,7 +878,7 @@ interface UseModelEditArgs {export function useModelEdit({providerName,instanceName,- addedSet,+ isModelAdded,isDraftInstance,updateCatalogModel,clearCatalogOverride,@@ -942,13 +963,13 @@ export function useModelEdit({if (!editingModel) return;const targetName = editingModel.name;- if (isDraftInstance && updateDraftModel && addedSet.has(targetName)) {+ if (isDraftInstance && updateDraftModel && isModelAdded(targetName)) {updateDraftModel(item);setEditingModel(null);return;}- if (!addedSet.has(targetName)) {+ if (!isModelAdded(targetName)) {updateCatalogModel(targetName, item);setEditingModel(null);return;@@ -967,7 +988,9 @@ export function useModelEdit({LlmKeys.instanceModels(providerName, instanceName),(prev) => {if (!prev) return prev;- const idx = prev.findIndex((m) => m.name === targetName);+ const idx = prev.findIndex(+ (m) => modelNameKey(m.name) === modelNameKey(targetName),+ );if (idx === -1) return prev;const next = [...prev];const existing = next[idx];diff --git a/web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx b/web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsxindex 55c1a9dcf3..2f150ba7e3 100644--- a/web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx+++ b/web/src/pages/user-setting/setting-model/instance-card/models-section/index.tsx@@ -29,6 +29,7 @@ import {useState,} from 'react';import { useTranslation } from 'react-i18next';+import { modelNameKey } from '@/utils/llm-util';import { AddCustomModelDialog } from '../add-custom-model-dialog';import { mapModelKey } from '../available-models';import { ModelRow } from './components/model-row';@@ -149,27 +150,38 @@ export function ModelsSection(props: ModelsSectionProps) {if (catalog.length === 0) return;hasAutoPopulatedDraftRef.current = true;setDraftModels((prev) => {- const existing = new Set(prev.map((m) => m.name));- return [...prev, ...catalog.filter((m) => !existing.has(m.name))];+ const existing = new Set(prev.map((m) => modelNameKey(m.name)));+ return [+ ...prev,+ ...catalog.filter((m) => !existing.has(modelNameKey(m.name))),+ ];});}, [isDraftInstance, catalog]);const addDraftModel = useCallback((model: IProviderModelItem) => {setDraftModels((prev) =>- prev.some((m) => m.name === model.name) ? prev : [...prev, model],+ prev.some((m) => modelNameKey(m.name) === modelNameKey(model.name))+ ? prev+ : [...prev, model],);}, []);const removeDraftModel = useCallback((name: string) => {- setDraftModels((prev) => prev.filter((m) => m.name !== name));+ setDraftModels((prev) =>+ prev.filter((m) => modelNameKey(m.name) !== modelNameKey(name)),+ );}, []);const updateDraftModel = useCallback((item: IProviderModelItem) => {setDraftModels((prev) =>- prev.map((m) => (m.name === item.name ? { ...m, ...item } : m)),+ prev.map((m) =>+ modelNameKey(m.name) === modelNameKey(item.name)+ ? { ...m, ...item }+ : m,+ ),);}, []);// 4. Derived union list (instance ∪ catalog) + push to host.- const { instanceItems, models, addedSet } = useModelsDerived({+ const { instanceItems, models, isModelAdded } = useModelsDerived({catalog,instanceModels,instanceModelsLoading,@@ -227,7 +239,7 @@ export function ModelsSection(props: ModelsSectionProps) {instance,instanceItems,filteredModels,- addedSet,+ isModelAdded,setCatalog,clearCatalogOverride,addDraftModel,@@ -248,7 +260,7 @@ export function ModelsSection(props: ModelsSectionProps) {} = useModelEdit({providerName,instanceName,- addedSet,+ isModelAdded,isDraftInstance,updateCatalogModel,clearCatalogOverride,@@ -390,7 +402,7 @@ export function ModelsSection(props: ModelsSectionProps) {<ModelRowkey={model.name}model={model}- isAdded={addedSet.has(model.name)}+ isAdded={isModelAdded(model.name)}verifyStatus={verify[model.name] ?? 'idle'}hideActions={hideActions}onVerify={() => handleVerify(model)}@@ -428,7 +440,11 @@ export function ModelsSection(props: ModelsSectionProps) {title={tSetting('editModel')}fields={editModelDialogFields}existingNames={models- .filter((m) => m.name !== editingModel?.name)+ .filter(+ (m) =>+ editingModel === null ||+ modelNameKey(m.name) !== modelNameKey(editingModel.name),+ ).map((m) => m.name)}providerFeatureKeys={providerFeatureKeys}defaultValues={editDefaultValues}diff --git a/web/src/pages/user-setting/setting-model/provider-schema/hooks/use-list-models-picker.ts b/web/src/pages/user-setting/setting-model/provider-schema/hooks/use-list-models-picker.tsindex b0ed65488e..4227df725b 100644--- a/web/src/pages/user-setting/setting-model/provider-schema/hooks/use-list-models-picker.ts+++ b/web/src/pages/user-setting/setting-model/provider-schema/hooks/use-list-models-picker.ts@@ -25,6 +25,7 @@ import {useRef,useState,} from 'react';+import { modelNameKey } from '@/utils/llm-util';import type { ProviderConfig } from '../types';// Derive is_tools from a model descriptor's `features` array. A model is@@ -207,7 +208,7 @@ export const useListModelsPicker = ({const matched = res.data.filter((m: IProviderModelItem) =>seed.some((s) =>- s.model_name === m.name &&+ modelNameKey(s.model_name) === modelNameKey(m.name) &&modelTypesMatch(s.model_type, m.model_types),),);@@ -243,7 +244,9 @@ export const useListModelsPicker = ({if (selectionLockRef.current) return;selectionLockRef.current = true;setSelectedModelItemsState((prev) => {- const idx = prev.findIndex((p) => p.name === model.name);+ const idx = prev.findIndex(+ (p) => modelNameKey(p.name) === modelNameKey(model.name),+ );if (idx >= 0) {const next = prev.slice();next.splice(idx, 1);@@ -326,7 +329,9 @@ export const useListModelsPicker = ({const oldName = editingModel?.name;if (!oldName) return;const replace = (items: IProviderModelItem[]) =>- items.map((m) => (m.name === oldName ? updated : m));+ items.map((m) =>+ modelNameKey(m.name) === modelNameKey(oldName) ? updated : m,+ );setModelsState(replace);setSelectedModelItemsState(replace);setEditDialogOpen(false);diff --git a/web/src/utils/llm-util.ts b/web/src/utils/llm-util.tsindex 6e1e9fc43d..a9495b7ed4 100644--- a/web/src/utils/llm-util.ts+++ b/web/src/utils/llm-util.ts@@ -60,6 +60,16 @@ export function buildModelValue(model: {return `${model.model_name}@${model.model_instance}@${model.model_provider}`;}+/**+ * Identity of a provider model name. The bundled catalog and a live upstream+ * listing can spell the same model with different case or padding, so every+ * merge, lookup and duplicate check compares this normalized form instead of+ * the raw name. Mirrors the backend's `providerModelKey`.+ */+export function modelNameKey(name: string): string {+ return name.trim().toLowerCase();+}+/*** Collects every id under which an added model can be referenced — both the* model_id form and the legacy "modelName@instanceName@providerName" form —