Skip to content

Agent Zero AI framework

fix plugins deletion logic

Alessandrobb186c55c46b
diff --git a/python/api/plugins.py b/python/api/plugins.py
index e42439127..814e48e08 100644
--- a/python/api/plugins.py
+++ b/python/api/plugins.py
@@ -157,19 +157,14 @@ class Plugins(ApiHandler):
if action == "delete_plugin":
plugin_name = input.get("plugin_name", "")
- path = input.get("path", "")
if not plugin_name:
return Response(status=400, response="Missing plugin_name")
- if not path:
- return Response(status=400, response="Missing path")
-
- # Validate that the plugin is actually a custom plugin
- custom_plugins_dir = files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR)
- if not os.path.abspath(path).startswith(os.path.abspath(custom_plugins_dir)):
- return Response(status=400, response="Only custom plugins can be deleted")
-
try:
- files.delete_dir(path)
+ plugins.delete_plugin(plugin_name)
+ except FileNotFoundError as e:
+ return Response(status=404, response=str(e))
+ except ValueError as e:
+ return Response(status=400, response=str(e))
except Exception as e:
return Response(status=500, response=f"Failed to delete plugin: {str(e)}")
return {"ok": True}
diff --git a/python/helpers/plugins.py b/python/helpers/plugins.py
index a6393214e..dd3c1c9f0 100644
--- a/python/helpers/plugins.py
+++ b/python/helpers/plugins.py
@@ -181,6 +181,16 @@ def find_plugin_dir(plugin_name: str):
return None
+def delete_plugin(plugin_name: str):
+ plugin_dir = find_plugin_dir(plugin_name)
+ if not plugin_dir:
+ raise FileNotFoundError(f"Plugin '{plugin_name}' not found")
+ custom_plugins_dir = files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR)
+ if not files.is_in_dir(plugin_dir, custom_plugins_dir):
+ raise ValueError("Only custom plugins can be deleted")
+ files.delete_dir(plugin_dir)
+
+
def get_plugin_paths(*subpaths: str) -> List[str]:
sub = "*/" + "/".join(subpaths) if subpaths else "*"
paths: List[str] = []
diff --git a/webui/components/plugins/list/pluginListStore.js b/webui/components/plugins/list/pluginListStore.js
index e037f5e78..9b583fdfa 100644
--- a/webui/components/plugins/list/pluginListStore.js
+++ b/webui/components/plugins/list/pluginListStore.js
@@ -152,7 +152,7 @@ const model = {
},
async deletePlugin(plugin) {
- if (!plugin?.path) return;
+ if (!plugin?.name) return;
if (!plugin.is_custom) {
showErrorNotification(
@@ -166,7 +166,6 @@ const model = {
const response = await api.callJsonApi("plugins", {
action: "delete_plugin",
plugin_name: plugin.name,
- path: plugin.path,
});
if (response?.error) {
throw new Error(response.error);