fix: resolve the issue same id component

This commit is contained in:
2026-07-11 22:01:01 +07:00
parent 4e3e46c1af
commit 5c1b06df1a
2 changed files with 19 additions and 2 deletions
@@ -21,8 +21,14 @@ function groupModelsByProvider(models) {
groups[key] = {
provider: model.provider,
models: [],
modelIds: new Set(),
};
}
// The API normally supplies unique models. Ignore a duplicate defensively
// so a malformed response cannot produce duplicate React keys.
if (groups[key].modelIds.has(model.fullModel)) return groups;
groups[key].modelIds.add(model.fullModel);
groups[key].models.push(model);
return groups;
}, {});
+13 -2
View File
@@ -32,9 +32,20 @@ export function isValidModel(aliasOrId, modelId) {
return models.some(m => m.id === modelId);
}
// Legacy AI_MODELS for backward compatibility
// Legacy AI_MODELS for backward compatibility. A model can be declared under
// multiple service kinds (for example, Gemini chat and speech-to-text), but
// this flat catalog has no kind field. Keep its provider/model identity unique.
const seenModelIds = new Set();
export const AI_MODELS = Object.entries(MODELS).flatMap(([alias, models]) =>
models.map(m => ({ provider: alias, model: m.id, name: m.name }))
models
.filter((model) => {
const modelKey = `${alias}/${model.id}`;
if (seenModelIds.has(modelKey)) return false;
seenModelIds.add(modelKey);
return true;
})
.map((model) => ({ provider: alias, model: model.id, name: model.name }))
);
export const getModelKind = (m, fallback = null) => m?.kind || m?.type || fallback;