mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-07 00:32:28 +08:00
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
This commit is contained in:
@@ -261,7 +261,11 @@ export function ModelConfigDialog({
|
|||||||
|
|
||||||
// Handle adding a model to current provider
|
// Handle adding a model to current provider
|
||||||
const handleAddModel = (modelId: string) => {
|
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)
|
addModel(selectedProviderId, modelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1186,14 +1190,40 @@ export function ModelConfigDialog({
|
|||||||
onChange={(
|
onChange={(
|
||||||
e,
|
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(
|
updateModel(
|
||||||
selectedProviderId!,
|
selectedProviderId!,
|
||||||
model.id,
|
model.id,
|
||||||
{
|
{
|
||||||
modelId:
|
modelId:
|
||||||
e
|
newModelId,
|
||||||
.target
|
|
||||||
.value,
|
|
||||||
validated:
|
validated:
|
||||||
undefined,
|
undefined,
|
||||||
validationError:
|
validationError:
|
||||||
|
|||||||
Reference in New Issue
Block a user