ui: radio buttons show click without waiting for agent to reload (#2108)
This commit is contained in:
@@ -78,7 +78,6 @@ export function BaseModelsList({
|
|||||||
await changeModel({ model: model, writeToConfig: upsert, getExtensions, addExtension });
|
await changeModel({ model: model, writeToConfig: upsert, getExtensions, addExtension });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Updated to work with CustomRadio
|
|
||||||
const handleRadioChange = async (model: Model) => {
|
const handleRadioChange = async (model: Model) => {
|
||||||
// Check if the selected model is already active
|
// Check if the selected model is already active
|
||||||
if (
|
if (
|
||||||
@@ -90,18 +89,40 @@ export function BaseModelsList({
|
|||||||
title: 'No change',
|
title: 'No change',
|
||||||
msg: `Model "${model.name}" is already active.`,
|
msg: `Model "${model.name}" is already active.`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// OPTIMISTIC UPDATE: Update the UI immediately
|
||||||
// Fix: First save the model to config, then update local state
|
setSelectedModel(model);
|
||||||
await handleModelSelection(model);
|
|
||||||
|
|
||||||
// Update local state after successful save
|
try {
|
||||||
setSelectedModel(model);
|
// Then perform the actual model change
|
||||||
|
await handleModelSelection(model);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error selecting model:', error);
|
console.error('Error selecting model:', error);
|
||||||
|
|
||||||
|
// If the operation fails, revert to the previous state by simply
|
||||||
|
// re-calling the getCurrentModelAndProvider function
|
||||||
|
try {
|
||||||
|
const result = await getCurrentModelAndProvider({
|
||||||
|
readFromConfig: read,
|
||||||
|
writeToConfig: upsert,
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentModel = modelList.find(
|
||||||
|
(m) => m.name === result.model && m.provider === result.provider
|
||||||
|
) || { name: result.model, provider: result.provider };
|
||||||
|
|
||||||
|
setSelectedModel(currentModel);
|
||||||
|
} catch (secondError) {
|
||||||
|
console.error('Failed to restore previous model:', secondError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show an error toast
|
||||||
|
toastInfo({
|
||||||
|
title: 'Error',
|
||||||
|
msg: `Failed to switch to model "${model.name}".`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user