This commit is contained in:
Timothy Jaeryang Baek 2026-10-08 15:54:52 +04:00
parent 1e9dd6e330
commit ffce74fd29
3 changed files with 63 additions and 0 deletions

View file

@ -18,6 +18,7 @@
import {
createNewModel,
deleteAllModels,
deleteModelById,
getAllModels,
getModelById,
exportModels,
@ -97,6 +98,8 @@
let showManageModal = false;
let showResetModal = false;
let showDeleteModal = false;
let modelToDelete: ModelListItem | null = null;
let savingModelOrder = false;
let savingModelsSettings = false;
let modelOrderDirty = false;
@ -122,6 +125,8 @@
const isPresetModel = (model: any) =>
!!(model?.preset || model?.base_model_id || model?.info?.base_model_id);
const canResetModel = (model: ModelListItem | null) =>
!!model && !isPresetModel(model) && availableModelIds.has(model.id);
const modelTags = (model: any): string[] =>
(model?.meta?.tags ?? [])
.map((tag) => (typeof tag === 'string' ? tag : tag?.name))
@ -535,6 +540,29 @@
);
};
const deleteModelHandler = async (model: ModelListItem) => {
try {
// Read fresh records: visibility and access changes can create saved settings.
const savedModels = await getAllModels(localStorage.token);
if (savedModels.some((savedModel: ModelListItem) => savedModel.id === model.id)) {
const res = await deleteModelById(localStorage.token, model.id);
if (!res) {
toast.error($i18n.t('Failed to delete model'));
return;
}
}
toast.success(
canResetModel(model)
? $i18n.t('Model reset successfully')
: $i18n.t('Deleted {{name}}', { name: model.name })
);
await init();
} catch (error: any) {
toast.error(`${error?.detail ?? error}`);
}
};
const hideModelHandler = async (model) => {
const updatedModel = {
...model,
@ -704,6 +732,22 @@
});
</script>
<ConfirmDialog
title={canResetModel(modelToDelete) ? $i18n.t('Reset') : $i18n.t('Delete')}
message={canResetModel(modelToDelete)
? $i18n.t(
'This will reset the saved settings for this base model to their defaults. The model will remain available.'
)
: $i18n.t('Are you sure you want to delete **{{modelName}}**?', {
modelName: modelToDelete?.name
})}
confirmLabel={canResetModel(modelToDelete) ? $i18n.t('Reset') : $i18n.t('Delete')}
bind:show={showDeleteModal}
onConfirm={async () => {
if (modelToDelete) await deleteModelHandler(modelToDelete);
}}
/>
<ConfirmDialog
title={$i18n.t('Reset All Models')}
message={$i18n.t('This will delete all models including custom models and cannot be undone.')}
@ -1180,6 +1224,11 @@
<ModelMenu
user={$user}
{model}
deleteLabel={canResetModel(model) ? $i18n.t('Reset') : $i18n.t('Delete')}
deleteHandler={() => {
modelToDelete = model;
showDeleteModal = true;
}}
exportHandler={() => {
exportModelHandler(model);
}}

View file

@ -27,6 +27,8 @@
export let model;
export let exportHandler: Function;
export let deleteHandler: Function;
export let deleteLabel: string;
export let hideHandler: Function;
export let privacyHandler: Function;
export let isDefaultSelected = false;
@ -66,6 +68,15 @@
<div slot="content">
<DropdownMenu className="min-w-[10.625rem]">
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
type="button"
on:click={() => runAndClose(deleteHandler)}
>
<GarbageBin className="size-3.5" />
<div class="flex items-center">{deleteLabel}</div>
</button>
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
on:click={() => runAndClose(hideHandler)}

View file

@ -990,6 +990,7 @@
"Failed to create API Key.": "",
"Failed to create chat": "",
"Failed to delete calendar": "",
"Failed to delete model": "",
"Failed to delete note": "",
"Failed to delete webhook": "",
"Failed to disconnect": "",
@ -1443,6 +1444,7 @@
"Model providers": "",
"Model removed from pinned models": "",
"Model removed from selected models": "",
"Model reset successfully": "",
"Model responses or outputs": "",
"Model unloaded successfully": "",
"Model updated successfully": "",
@ -3318,6 +3320,7 @@
"This will delete the cached model and cannot be undone.": "",
"This will permanently delete the calendar \"{{name}}\" and all its events. This action cannot be undone.": "",
"This will remove all files and directories from this knowledge base. This action cannot be undone.": "",
"This will reset the saved settings for this base model to their defaults. The model will remain available.": "",
"This will revoke the current API key.": "",
"Thorough explanation": "",
"Thought": "",