From 41c450516c11a435028452fa185a6c3be95a500c Mon Sep 17 00:00:00 2001 From: "dayuan.jiang" Date: Mon, 22 Dec 2025 21:53:56 +0900 Subject: [PATCH] fix: prevent duplicate model IDs within same provider - Block adding model if ID already exists in provider - Block editing model ID to match existing model in provider --- components/model-config-dialog.tsx | 38 ++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/components/model-config-dialog.tsx b/components/model-config-dialog.tsx index 5ea5860..0fd28c3 100644 --- a/components/model-config-dialog.tsx +++ b/components/model-config-dialog.tsx @@ -261,7 +261,11 @@ export function ModelConfigDialog({ // Handle adding a model to current provider const handleAddModel = (modelId: string) => { - if (!selectedProviderId) return + if (!selectedProviderId || !selectedProvider) return + // Prevent duplicate model IDs + if (existingModelIds.includes(modelId)) { + return // Model already exists, don't add + } addModel(selectedProviderId, modelId) } @@ -1186,14 +1190,40 @@ export function ModelConfigDialog({ onChange={( e, ) => { + const newModelId = + e + .target + .value + // Check if new ID would be duplicate (excluding current model) + const otherModelIds = + selectedProvider?.models + .filter( + ( + m, + ) => + m.id !== + model.id, + ) + .map( + ( + m, + ) => + m.modelId, + ) || + [] + if ( + otherModelIds.includes( + newModelId, + ) + ) { + return // Don't allow duplicate + } updateModel( selectedProviderId!, model.id, { modelId: - e - .target - .value, + newModelId, validated: undefined, validationError: