Agent Zero AI framework
Optimize plugin reload notifications to check for webui extensions
frdel999a14e31fac
diff --git a/api/plugins.py b/api/plugins.pyindex 2243f7319..0b84b4865 100644--- a/api/plugins.py+++ b/api/plugins.py@@ -15,7 +15,7 @@ class Plugins(ApiHandler):"""async def process(self, input: dict, request: Request) -> dict | Response:- action = input.get("action", "get_config")+ action = input.get("action", "")# Accept legacy aliases during migration.if action == "get_config":diff --git a/helpers/plugins.py b/helpers/plugins.pyindex d00ca1d82..006d9125f 100644--- a/helpers/plugins.py+++ b/helpers/plugins.py@@ -1,5 +1,6 @@from __future__ import annotations+import asyncioimport re, json, globimport timefrom pathlib import Path@@ -17,6 +18,8 @@ from typing import (from helpers import files, notification, print_style, yaml as yaml_helper, cachefrom pydantic import BaseModel, Field+from helpers.defer import DeferredTask+if TYPE_CHECKING:from agent import Agent@@ -73,9 +76,9 @@ class PluginListItem(BaseModel):toggle_state: ToggleState = "disabled"-def after_plugin_change():+def after_plugin_change(plugin_names: list[str] | None = None):clear_plugin_cache()- send_frontend_reload_notification()+ send_frontend_reload_notification(plugin_names)def clear_plugin_cache():@@ -195,8 +198,9 @@ def delete_plugin(plugin_name: str):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")+ send_frontend_reload_notification([plugin_name]) # send before deletion to properly check the extensions, second notification will be skipped automaticallyfiles.delete_dir(plugin_dir)- after_plugin_change()+ after_plugin_change([plugin_name])def get_plugin_paths(*subpaths: str) -> List[str]:@@ -355,7 +359,7 @@ def toggle_plugin(files.write_file(enabled_file, "")else:files.write_file(disabled_file, "")- after_plugin_change()+ after_plugin_change([plugin_name])def get_plugin_config(@@ -412,7 +416,7 @@ def save_plugin_config()if file_path:files.write_file(file_path, json.dumps(settings))- after_plugin_change()+ after_plugin_change([plugin_name])def find_plugin_asset(@@ -559,7 +563,8 @@ def determine_plugin_asset_path(return files.get_abs_path(base_path, files.PLUGINS_DIR, plugin_name, *subpaths)-def send_frontend_reload_notification():+def send_frontend_reload_notification(plugin_names: list[str] | None = None):+ """If the plugin changed has webui extensions, notify frontend to reload the page"""global _last_frontend_reload_notification_atdisplay_time = 3@@ -567,15 +572,34 @@ def send_frontend_reload_notification():if now - _last_frontend_reload_notification_at < display_time:return- _last_frontend_reload_notification_at = now-- notification.NotificationManager.send_notification(- type=notification.NotificationType.INFO,- priority=notification.NotificationPriority.NORMAL,- title="Plugins updated, page reload recommended",- message="""<button type="button" class="button confirm" onclick="window.location.reload()"><span class="icon material-symbols-outlined">refresh</span>Reload page</button>""",- detail="",- display_time=display_time,- group="plugins_changed",- id="plugins_frontend_reload",- )+ if plugin_names:+ has_webui_extension = False+ for plugin_name in plugin_names:+ plugin_dir = find_plugin_dir(plugin_name)+ if plugin_dir and files.exists(+ files.get_abs_path(plugin_dir, "extensions", "webui")+ ):+ has_webui_extension = True+ break+ if not has_webui_extension:+ return++ async def _send_later():+ global _last_frontend_reload_notification_at++ await asyncio.sleep(1)++ _last_frontend_reload_notification_at = time.monotonic()++ notification.NotificationManager.send_notification(+ type=notification.NotificationType.INFO,+ priority=notification.NotificationPriority.NORMAL,+ title="Plugins with frontend extensions updated, page reload recommended",+ message="""<button type="button" class="button confirm" onclick="window.location.reload()"><span class="icon material-symbols-outlined">refresh</span>Reload page</button>""",+ detail="",+ display_time=display_time,+ group="plugins_changed",+ id="plugins_frontend_reload",+ )++ DeferredTask().start_task(_send_later)diff --git a/plugins/plugin_installer/helpers/install.py b/plugins/plugin_installer/helpers/install.pyindex 744ec1422..f751b773e 100644--- a/plugins/plugin_installer/helpers/install.py+++ b/plugins/plugin_installer/helpers/install.py@@ -138,7 +138,7 @@ def install_from_zip(zip_path: str, original_filename: str | None = None) -> dicdest = os.path.join(_get_user_plugins_dir(), plugin_name)os.makedirs(os.path.dirname(dest), exist_ok=True)shutil.move(plugin_root, dest)- after_plugin_change()+ after_plugin_change([plugin_name])return {"success": True,@@ -181,7 +181,7 @@ def install_from_git(url: str, token: Optional[str] = None) -> dict:shutil.rmtree(dest, ignore_errors=True)raise- after_plugin_change()+ after_plugin_change([repo_name])return {"success": True,diff --git a/plugins/plugin_installer/webui/install-index.html b/plugins/plugin_installer/webui/install-index.htmlindex 74ae2ee5b..ae16be980 100644--- a/plugins/plugin_installer/webui/install-index.html+++ b/plugins/plugin_installer/webui/install-index.html@@ -386,7 +386,7 @@align-items: center;justify-content: center;height: 148px;- padding: 1rem;+ padding: 0.5rem;background:radial-gradient(circle at top, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0)),var(--color-panel);diff --git a/plugins/plugin_installer/webui/main.html b/plugins/plugin_installer/webui/main.htmlindex 71336d4c2..30413d077 100644--- a/plugins/plugin_installer/webui/main.html+++ b/plugins/plugin_installer/webui/main.html@@ -511,7 +511,7 @@height: 148px;padding: 1rem;background:- radial-gradient(circle at top, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0)),+ radial-gradient(circle at top, rgba(255, 255, 255, 0.16) 0%, var(--color-panel) 100%),var(--color-panel);border-bottom: 1px solid var(--color-border);}diff --git a/usr/plugins/agent0ai__a0_example_plugin b/usr/plugins/agent0ai__a0_example_pluginnew file mode 160000index 000000000..0c41e0941--- /dev/null+++ b/usr/plugins/agent0ai__a0_example_plugin@@ -0,0 +1 @@+Subproject commit 0c41e09418a13f97bc4dd8f53d7fa9a69383d82f