The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
models: delete image and video models from the Model Hub
purpleee382f02cc0e
diff --git a/src-tauri/src/commands/download.rs b/src-tauri/src/commands/download.rsindex cba569f6..c8692199 100644--- a/src-tauri/src/commands/download.rs+++ b/src-tauri/src/commands/download.rs@@ -64,6 +64,84 @@ mod download_security_tests {assert!(safe_subfolder("/abs/path").is_err());assert!(safe_subfolder("C:/x").is_err());}++ #[test]+ fn split_model_ref_handles_nested_and_plain_names() {+ assert_eq!(super::split_model_ref("model.safetensors"), (String::new(), "model.safetensors".into()));+ assert_eq!(super::split_model_ref("wan/model.gguf"), ("wan".into(), "model.gguf".into()));+ assert_eq!(super::split_model_ref("a\\b\\m.pt"), ("a/b".into(), "m.pt".into()));+ // Traversal segments survive the split and then die in safe_subfolder.+ let (dir, _) = super::split_model_ref("../../evil.bin");+ assert!(safe_subfolder(&dir).is_err());+ }+}++/// Split a ComfyUI enum name ("wan/x.safetensors" or plain "x.safetensors")+/// into its relative dir + basename so both halves can go through the same+/// jail checks the downloader uses.+fn split_model_ref(name: &str) -> (String, String) {+ let norm = name.replace('\\', "/");+ match norm.rsplit_once('/') {+ Some((dir, base)) => (dir.to_string(), base.to_string()),+ None => (String::new(), norm),+ }+}++/// The model subdirs LU downloads into / ComfyUI enumerates from. Delete+/// searches exactly these — never custom_nodes, never arbitrary paths.+const MODEL_SUBDIRS: &[&str] = &[+ "checkpoints", "diffusion_models", "unet", "vae", "loras",+ "text_encoders", "clip", "clip_vision", "audio_encoders",+ "controlnet", "upscale_models",+];++/// Delete one installed model file from the ComfyUI models tree (the Model+/// Hub's trash action — cpl.sardinas7489, Discord 2026-07-19: a 27 GB video+/// model his PC couldn't run had no in-app way back out). The name is the+/// ComfyUI enum entry; we jail-check it and look for the single file match+/// across the known model subdirs.+#[tauri::command]+pub fn delete_comfy_model(filename: String, state: State<'_, AppState>) -> Result<serde_json::Value, String> {+ let comfy_path = state+ .comfy_path+ .lock()+ .unwrap()+ .clone()+ .ok_or("ComfyUI path not set. Please set it in settings or install ComfyUI first.")?;+ let (sub, base) = split_model_ref(&filename);+ if !sub.is_empty() {+ safe_subfolder(&sub)?;+ }+ let base = sanitize_filename(&base);+ let models_root = PathBuf::from(&comfy_path).join("models");+ let mut hits: Vec<PathBuf> = Vec::new();+ for d in MODEL_SUBDIRS {+ let cand = if sub.is_empty() {+ models_root.join(d).join(&base)+ } else {+ models_root.join(d).join(&sub).join(&base)+ };+ if cand.is_file() {+ hits.push(cand);+ }+ }+ match hits.len() {+ 0 => Err(format!("{} was not found in the ComfyUI models folders", filename)),+ 1 => {+ let f = &hits[0];+ let bytes = fs::metadata(f).map(|m| m.len()).unwrap_or(0);+ fs::remove_file(f).map_err(|e| format!("Delete failed: {}", e))?;+ // Sweep a stale resume-partial next to it (the timeout/abort case+ // leaves both the file and its .download twin behind).+ let _ = fs::remove_file(f.with_extension("download"));+ println!("[Models] Deleted {} ({} bytes)", f.display(), bytes);+ Ok(serde_json::json!({"status": "deleted", "bytes": bytes}))+ }+ _ => Err(format!(+ "{} exists in more than one models folder — remove it from the ComfyUI folder itself so the right copy goes",+ filename+ )),+ }}fn models_dir(comfy_path: &Option<String>, subfolder: &str) -> Result<PathBuf, String> {diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex fe46964b..c9cc7a97 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -192,6 +192,7 @@ fn main() {commands::download::resume_download,commands::download::detect_model_path,commands::download::check_model_sizes,+ commands::download::delete_comfy_model,// Built-in inference engine (bundled llama-server, P1)commands::engine::start_bundled_engine,commands::engine::stop_bundled_engine,diff --git a/src/api/backend.ts b/src/api/backend.tsindex 78d0d159..e7c4be87 100644--- a/src/api/backend.ts+++ b/src/api/backend.ts@@ -405,6 +405,7 @@ export async function backendCall<T = any>(download_model_to_path: { path: "/local-api/download-model-to-path", method: "POST" },detect_model_path: { path: "/local-api/detect-model-path", method: "POST" },check_model_sizes: { path: "/local-api/check-model-sizes", method: "POST" },+ delete_comfy_model: { path: "/local-api/delete-comfy-model", method: "POST" },download_progress: { path: "/local-api/download-progress" },pause_download: { path: "/local-api/pause-download", method: "POST" },cancel_download: { path: "/local-api/cancel-download", method: "POST" },diff --git a/src/components/models/ModelManager.tsx b/src/components/models/ModelManager.tsxindex a06e9b55..938400c5 100644--- a/src/components/models/ModelManager.tsx+++ b/src/components/models/ModelManager.tsx@@ -13,7 +13,8 @@ import { DiscoverModels } from './DiscoverModels'import { Modal } from '../ui/Modal'import { GlowButton } from '../ui/GlowButton'import { showModel } from '../../api/ollama'-import { checkComfyConnection } from '../../api/comfyui'+import { checkComfyConnection, refreshComfyModels } from '../../api/comfyui'+import { backendCall } from '../../api/backend'import type { ModelCategory, AIModel } from '../../types/models'// One category drives BOTH views (Discover + Installed) — the old split@@ -72,9 +73,24 @@ export function ModelManager() {}}+ const [deleteError, setDeleteError] = useState<string | null>(null)const handleDelete = async (name: string) => {- await removeModel(name)- setConfirmDelete(null)+ try {+ const model = models.find((m: AIModel) => m.name === name)+ if (model && (model.type === 'image' || model.type === 'video')) {+ // ComfyUI file model (cpl.sardinas7489, Discord): delete the file from+ // the models tree, then rescan so the enum and the list drop it.+ await backendCall('delete_comfy_model', { filename: name })+ await refreshComfyModels().catch(() => { /* rescan is best-effort */ })+ await fetchModels()+ } else {+ await removeModel(name)+ }+ setConfirmDelete(null)+ } catch (e) {+ setDeleteError(e instanceof Error ? e.message : String(e))+ setConfirmDelete(null)+ }}const filteredModels = models.filter((m: AIModel) => m.type === mode)@@ -317,7 +333,12 @@ export function ModelManager() {onSelect={() => setActiveModel(model.name)}onDelete={() => setConfirmDelete(model.name)}onInfo={() => handleInfo(model.name)}- canDelete={ollamaEnabled && model.type === 'text' && (!('provider' in model) || model.provider === 'ollama')}+ canDelete={+ // Ollama text models via the Ollama API; image/video+ // models are ComfyUI files we can delete from disk.+ (ollamaEnabled && model.type === 'text' && (!('provider' in model) || model.provider === 'ollama'))+ || model.type === 'image' || model.type === 'video'+ }/></motion.div>))}@@ -347,6 +368,7 @@ export function ModelManager() {<Modal open={!!confirmDelete} onClose={() => setConfirmDelete(null)} title="Delete Model"><p className="text-[0.7rem] text-gray-600 dark:text-gray-300 mb-3">Are you sure you want to delete <span className="text-gray-900 dark:text-white font-mono">{confirmDelete}</span>?+ This removes the model file from your disk and frees the space.</p><div className="flex gap-2"><GlowButton variant="secondary" onClick={() => setConfirmDelete(null)} className="flex-1">@@ -358,6 +380,13 @@ export function ModelManager() {</div></Modal>+ <Modal open={!!deleteError} onClose={() => setDeleteError(null)} title="Delete failed">+ <p className="text-[0.7rem] text-red-500 dark:text-red-400 mb-3">{deleteError}</p>+ <GlowButton variant="secondary" onClick={() => setDeleteError(null)} className="w-full">+ Close+ </GlowButton>+ </Modal>+<Modal open={infoOpen} onClose={() => setInfoOpen(false)} title={modelInfo?.name || 'Model Info'}>{modelInfo && (<pre className="text-[0.6rem] text-gray-600 dark:text-gray-300 bg-gray-100 dark:bg-black/30 rounded-lg p-3 overflow-auto max-h-80 scrollbar-thin font-mono">