fix: fallback and auth issues when configuring a duplicate model id

This commit is contained in:
mingholy.lmh 2026-01-07 20:05:33 +08:00
parent afe6ba255e
commit ded1ebcdff
4 changed files with 47 additions and 49 deletions

View file

@ -255,26 +255,10 @@ export function ModelDialog({ onClose }: ModelDialogProps): React.JSX.Element {
);
} catch (e) {
const baseErrorMessage = e instanceof Error ? e.message : String(e);
// Some auth types (notably openai without modelProviders configured) can present
// env-based "raw" model IDs in the list. These are not registry-backed and will
// fail switchModel(). Fall back to setModel() to keep UX functional.
const isNotFound =
baseErrorMessage.includes('not found for authType') ||
(baseErrorMessage.includes('Model') &&
baseErrorMessage.includes('not found'));
if (!isNotFound) {
setErrorMessage(
`Failed to switch model to '${modelId}'.\n\n${baseErrorMessage}`,
);
// Keep the dialog open so the user can choose another model.
return;
}
await config.setModel(modelId, {
reason: 'user_manual',
context: 'Model set via /model dialog (raw)',
});
setErrorMessage(
`Failed to switch model to '${modelId}'.\n\n${baseErrorMessage}`,
);
return;
}
const event = new ModelSlashCommandEvent(modelId);
logModelSlashCommand(config, event);