Agent Zero AI framework
Add scoped plugin config discovery and UI
frdelda20abc18441
diff --git a/plugins/memory/config.json b/plugins/memory/config.default.jsonsimilarity index 100%rename from plugins/memory/config.jsonrename to plugins/memory/config.default.jsondiff --git a/plugins/memory/plugin.json b/plugins/memory/plugin.jsonindex c4a671ee3..4063b918d 100644--- a/plugins/memory/plugin.json+++ b/plugins/memory/plugin.json@@ -4,5 +4,5 @@"version": "1.0.0","settings_sections": ["agent"],"per_project_config": true,- "per_agent_config": true+ "per_agent_config": false}diff --git a/python/api/plugins.py b/python/api/plugins.pyindex 97f4683c1..5c945eec4 100644--- a/python/api/plugins.py+++ b/python/api/plugins.py@@ -12,30 +12,44 @@ class Plugins(ApiHandler):action = input.get("action", "get_config")# Accept legacy aliases during migration.- if action in {"get_config", "get_settings"}:+ if action == "get_config":plugin_name = input.get("plugin_name", "")project_name = input.get("project_name", "")agent_profile = input.get("agent_profile", "")if not plugin_name:return Response(status=400, response="Missing plugin_name")- settings = None- if project_name or agent_profile:- file_path = plugins.determine_plugin_asset_path(- plugin_name,- project_name,- agent_profile,- plugins.CONFIG_FILE_NAME,+ result = plugins.find_plugin_assets(+ plugins.CONFIG_FILE_NAME,+ plugin_name=plugin_name,+ project_name=project_name,+ agent_profile=agent_profile,+ only_first=True,+ )+ if result:+ entry = result[0]+ path = entry.get("path", "")+ settings = files.read_file_json(path) if path else {}+ loaded_project_name = entry.get("project_name", "")+ loaded_agent_profile = entry.get("agent_profile", "")+ else:+ settings = plugins.get_plugin_config(plugin_name, agent=None) or {}+ default_path = files.get_abs_path(+ plugins.find_plugin_dir(plugin_name), plugins.CONFIG_DEFAULT_FILE_NAME)- if files.exists(file_path):- settings = files.read_file_json(file_path)+ path = default_path if files.exists(default_path) else ""+ loaded_project_name = ""+ loaded_agent_profile = ""- if settings is None:- settings = plugins.get_plugin_config(plugin_name, agent=None)+ return {+ "ok": True,+ "loaded_path": path,+ "loaded_project_name": loaded_project_name,+ "loaded_agent_profile": loaded_agent_profile,+ "data": settings,+ }- return {"ok": True, "data": settings or {}}-- if action in {"save_config", "save_settings"}:+ if action == "save_config":plugin_name = input.get("plugin_name", "")project_name = input.get("project_name", "")agent_profile = input.get("agent_profile", "")diff --git a/python/helpers/plugins.py b/python/helpers/plugins.pyindex 33d7be738..88b0dbba7 100644--- a/python/helpers/plugins.py+++ b/python/helpers/plugins.py@@ -18,6 +18,7 @@ _META_TARGET_RE = re.compile(META_FILE_NAME = "plugin.json"CONFIG_FILE_NAME = "config.json"+CONFIG_DEFAULT_FILE_NAME = "config.default.json"DISABLED_FILE_NAME = ".disabled"ENABLED_FILE_NAME = ".enabled"@@ -140,7 +141,8 @@ def get_plugin_paths(*subpaths: str) -> List[str]:)return paths-def get_enabled_plugin_paths(agent:Agent|None, *subpaths: str) -> List[str]:++def get_enabled_plugin_paths(agent: Agent | None, *subpaths: str) -> List[str]:enabled = get_enabled_plugins(agent)paths: list[str] = []@@ -167,7 +169,7 @@ def get_enabled_plugins(agent: Agent | None):if agent:from python.helpers import subagents-+for plugin in plugins:# plugins are toggled via .enabled / .disabled files# every plugin is on by default, unless disabled in usr dir@@ -175,29 +177,31 @@ def get_enabled_plugins(agent: Agent | None):if agent:agent_paths = subagents.get_paths(- agent,- files.PLUGINS_DIR,- plugin,- must_exist_completely=True,- include_default=False,- include_user=True,- include_plugins=False,- include_project=True- )+ agent,+ files.PLUGINS_DIR,+ plugin,+ must_exist_completely=True,+ include_default=False,+ include_user=True,+ include_plugins=False,+ include_project=True,+ )# go through agent paths in reverse order and determine the statefor agent_path in reversed(agent_paths):if enabled:- enabled = not files.exists(files.get_abs_path(agent_path, DISABLED_FILE_NAME))+ enabled = not files.exists(+ files.get_abs_path(agent_path, DISABLED_FILE_NAME)+ )else:- enabled = files.exists(files.get_abs_path(agent_path, ENABLED_FILE_NAME))-+ enabled = files.exists(+ files.get_abs_path(agent_path, ENABLED_FILE_NAME)+ )if enabled:active.append(plugin)-- return active+ return activedef get_webui_extensions(extension_point: str, filters: List[str] | None = None):@@ -213,9 +217,22 @@ def get_webui_extensions(extension_point: str, filters: List[str] | None = None)return entries-def get_plugin_config(plugin_name: str, agent: Agent | None):- file_path = find_plugin_asset(plugin_name, CONFIG_FILE_NAME, agent=agent)- if file_path:+def get_plugin_config(plugin_name: str, agent: Agent | None, project_name:str|None=None, agent_profile:str|None=None):++ if project_name is None and agent is not None:+ from python.helpers import projects+ project_name = projects.get_context_project_name(agent.context)+ if agent_profile is None and agent is not None:+ agent_profile = agent.config.profile++ # find config.json in all possible places+ file_path = find_plugin_asset(plugin_name, CONFIG_FILE_NAME, project_name=project_name, agent_profile=agent_profile)+ # use default config if not found+ if not file_path:+ file_path = files.get_abs_path(+ find_plugin_dir(plugin_name), CONFIG_DEFAULT_FILE_NAME+ )+ if file_path and files.exists(file_path):return json.loads(files.read_file(file_path))return None@@ -230,73 +247,108 @@ def save_plugin_config(files.write_file(file_path, json.dumps(settings))-def find_plugin_asset(plugin_name: str, *subpaths: str, agent: Agent | None = None):- project_name = ""+def find_plugin_asset(plugin_name: str, *subpaths: str, project_name="", agent_profile=""):+ result = find_plugin_assets(+ *subpaths,+ plugin_name=plugin_name,+ project_name=project_name,+ agent_profile=agent_profile,+ only_first=True+ )+ return result[0]["path"] if result else None- if agent:- profile_name = agent.config.profile if agent and agent.config.profile else ""- from python.helpers import projects+def find_plugin_assets(+ *subpaths: str,+ plugin_name: str = "*",+ project_name: str = "*",+ agent_profile: str = "*",+ only_first: bool = False,+) -> list[dict]:+ from python.helpers import projects, subagents- project_name = projects.get_context_project_name(agent.context) or ""+ results: list[dict] = []- if project_name and profile_name:- # project/.a0proj/agents/<profile>/plugins/<plugin_name>/...- project_agent_file = projects.get_project_meta(+ def _collect(path: str, proj: str, profile: str) -> bool:+ matched_paths = (+ files.find_existing_paths_by_pattern(path)+ if "*" in path+ else ([path] if files.exists(path) else [])+ )+ for matched in matched_paths:+ results.append(+ {"project_name": proj, "agent_profile": profile, "path": matched}+ )+ if only_first:+ return True++ # project/.a0proj/agents/<profile>/plugins/<plugin_name>/...+ if project_name:+ if agent_profile:+ path = projects.get_project_meta(project_name,files.AGENTS_DIR,- profile_name,+ agent_profile,files.PLUGINS_DIR,plugin_name,*subpaths,)- if files.exists(project_agent_file):- return project_agent_file-- if project_name:+ if _collect(path, project_name, agent_profile):+ return results+ else:# project/.a0proj/plugins/<plugin_name>/...- project_file = projects.get_project_meta(+ path = projects.get_project_meta(project_name, files.PLUGINS_DIR, plugin_name, *subpaths)- if files.exists(project_file):- return project_file-- if profile_name:- from python.helpers import subagents+ if _collect(path, project_name, ""):+ return results- # usr/agents/<profile>/plugins/<plugin_name>/...- path = files.get_abs_path(- subagents.USER_AGENTS_DIR,- profile_name,- files.PLUGINS_DIR,- plugin_name,- *subpaths,- )- if files.exists(path):- return path+ # usr/agents/<profile>/plugins/<plugin_name>/...+ if agent_profile:+ path = files.get_abs_path(+ subagents.USER_AGENTS_DIR,+ agent_profile,+ files.PLUGINS_DIR,+ plugin_name,+ *subpaths,+ )+ if _collect(path, "", agent_profile):+ return results- # agents/<profile>/plugins/<plugin_name>/...+ # usr?/plugins/<any_plugin>/agents/<profile>/plugins/<plugin_name>/...+ for plugin_base in get_enabled_plugin_paths(None):path = files.get_abs_path(- subagents.DEFAULT_AGENTS_DIR,- profile_name,+ plugin_base,+ files.AGENTS_DIR,+ agent_profile,files.PLUGINS_DIR,plugin_name,*subpaths,)- if files.exists(path):- return path+ if _collect(path, "", agent_profile):+ return results++ # agents/<profile>/plugins/<plugin_name>/...+ path = files.get_abs_path(+ subagents.DEFAULT_AGENTS_DIR,+ agent_profile,+ files.PLUGINS_DIR,+ plugin_name,+ *subpaths,+ )+ if _collect(path, "", agent_profile):+ return results# usr/plugins/<plugin_name>/...path = files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR, plugin_name, *subpaths)- if files.exists(path):- return path+ if _collect(path, "", ""):+ return results# plugins/<plugin_name>/...path = files.get_abs_path(files.PLUGINS_DIR, plugin_name, *subpaths)- if files.exists(path):- return path+ _collect(path, "", "")- return None+ return resultsdef determine_plugin_asset_path(diff --git a/webui/components/plugins/plugin-configs.html b/webui/components/plugins/plugin-configs.htmlnew file mode 100644index 000000000..f97eb7dbb--- /dev/null+++ b/webui/components/plugins/plugin-configs.html@@ -0,0 +1,112 @@+<html>+<head>+ <title>Plugin Configurations</title>+ <script type="module">+ import { store } from "/components/plugins/plugin-settings-store.js";+ </script>+</head>+<body>+ <div x-data>+ <template x-if="$store.pluginSettings">+ <div x-create="$store.pluginSettings.loadConfigList()">++ <div x-show="$store.pluginSettings.configsError" class="plugin-configs-error">+ <span class="material-symbols-outlined">error</span>+ <span x-text="$store.pluginSettings.configsError"></span>+ </div>++ <div x-show="$store.pluginSettings.isListingConfigs" class="plugin-configs-loading">+ <span class="material-symbols-outlined spinning">progress_activity</span>+ <span>Loading configurations...</span>+ </div>++ <div x-show="!$store.pluginSettings.isListingConfigs" class="plugin-configs-list">+ <template x-if="($store.pluginSettings.configs || []).length === 0">+ <div class="plugin-configs-empty">No configurations found.</div>+ </template>++ <template x-for="cfg in ($store.pluginSettings.configs || [])" :key="(cfg.project_name || '') + '|' + (cfg.agent_profile || '')">+ <div class="plugin-configs-row">+ <div class="plugin-configs-scope">+ <div class="plugin-configs-scope-title" x-text="$store.pluginSettings.projectLabel(cfg.project_name || '')"></div>+ <div class="plugin-configs-scope-sub" x-text="$store.pluginSettings.agentProfileLabel(cfg.agent_profile || '')"></div>+ </div>++ <div class="plugin-configs-actions">+ <button type="button" class="button" @click="$store.pluginSettings.switchToConfig(cfg.project_name || '', cfg.agent_profile || '')">+ <span class="icon material-symbols-outlined">list</span>+ Switch+ </button>+ <button type="button" class="button cancel" @click="$store.pluginSettings.deleteConfig(cfg.project_name || '', cfg.agent_profile || '')">+ <span class="icon material-symbols-outlined">delete</span>+ Delete+ </button>+ </div>+ </div>+ </template>+ </div>++ </div>+ </template>+ </div>++ <style>+ .plugin-configs-loading,+ .plugin-configs-error {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ padding: 0.5rem 0.75rem;+ margin-bottom: 0.75rem;+ font-size: var(--font-size-small);+ }++ .plugin-configs-error {+ color: var(--color-error);+ background: rgba(255, 0, 0, 0.07);+ border: 1px solid rgba(255, 0, 0, 0.2);+ border-radius: 4px;+ }++ .plugin-configs-list {+ display: flex;+ flex-direction: column;+ gap: 0.5rem;+ }++ .plugin-configs-row {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 0.75rem;+ padding: 0.75rem;+ border: 1px solid var(--color-border);+ border-radius: 6px;+ background: var(--color-surface);+ }++ .plugin-configs-scope-title {+ font-weight: 600;+ }++ .plugin-configs-scope-sub {+ font-size: var(--font-size-small);+ color: var(--color-text-secondary);+ margin-top: 0.2rem;+ }++ .plugin-configs-actions {+ display: flex;+ gap: 0.5rem;+ flex-wrap: wrap;+ justify-content: flex-end;+ }++ .plugin-configs-empty {+ padding: 0.75rem;+ color: var(--color-text-secondary);+ font-size: var(--font-size-small);+ }+ </style>+</body>+</html>diff --git a/webui/components/plugins/plugin-settings-store.js b/webui/components/plugins/plugin-settings-store.jsindex 5a47a0de3..0b0e261b5 100644--- a/webui/components/plugins/plugin-settings-store.js+++ b/webui/components/plugins/plugin-settings-store.js@@ -16,6 +16,75 @@ const model = {// plugin settings data (plugins bind their fields here)settings: {},+ // where the settings were actually loaded from+ loadedPath: "",+ loadedProjectName: "",+ loadedAgentProfile: "",++ projectLabel(key) {+ if (!key) return "Global";+ const found = (this.projects || []).find((p) => p.key === key);+ return found?.label || key;+ },++ agentProfileLabel(key) {+ if (!key) return "All profiles";+ const found = (this.agentProfiles || []).find((p) => p.key === key);+ return found?.label || key;+ },++ get scopeMismatchMessage() {+ const selectedProject = this.projectName || "";+ const selectedProfile = this.agentProfileKey || "";+ const loadedProject = this.loadedProjectName || "";+ const loadedProfile = this.loadedAgentProfile || "";++ if (!this.loadedPath) return "";+ if (selectedProject === loadedProject && selectedProfile === loadedProfile) return "";++ return `Settings do not yet exist for this combination, settings from ${this.projectLabel(loadedProject)}, ${this.agentProfileLabel(loadedProfile)} (${this.loadedPath}) will apply.`;+ },++ configs: [],+ isListingConfigs: false,+ configsError: null,++ async openConfigListModal() {+ await window.openModal?.("/components/plugins/plugin-configs.html");+ },++ async loadConfigList() {+ if (!this.pluginName) return;+ this.isListingConfigs = true;+ this.configsError = null;+ try {+ // TODO: list existing plugin config scopes without API calls+ this.configs = [];+ } catch (e) {+ this.configsError = e?.message || "Failed to load configurations";+ this.configs = [];+ } finally {+ this.isListingConfigs = false;+ }+ },++ async switchToConfig(projectName, agentProfile) {+ this.projectName = projectName || "";+ this.agentProfileKey = agentProfile || "";+ await this.loadSettings();+ await window.closeModal?.();+ },++ async deleteConfig(projectName, agentProfile) {+ if (!this.pluginName) return;+ try {+ // TODO: delete existing plugin config scope without API calls+ this.configsError = "Delete is not implemented yet";+ } catch (e) {+ this.configsError = e?.message || "Delete failed";+ }+ },+// 'plugin' = save to plugin settings API// 'core' = save via $store.settings.saveSettings() (for plugins that surface core settings)saveMode: 'plugin',@@ -33,6 +102,9 @@ const model = {this.saveMode = 'plugin';this.projectName = "";this.agentProfileKey = "";+ this.loadedPath = "";+ this.loadedProjectName = "";+ this.loadedAgentProfile = "";await Promise.all([this.loadProjects(), this.loadAgentProfiles()]);await this.loadSettings();},@@ -87,6 +159,9 @@ const model = {});const result = await response.json().catch(() => ({}));this.settings = result.ok ? (result.data || {}) : {};+ this.loadedPath = result.loaded_path || "";+ this.loadedProjectName = result.loaded_project_name || "";+ this.loadedAgentProfile = result.loaded_agent_profile || "";if (!result.ok) this.error = result.error || "Failed to load settings";} catch (e) {this.error = e?.message || "Failed to load settings";@@ -138,6 +213,9 @@ const model = {this.pluginName = null;this.pluginMeta = null;this.settings = {};+ this.loadedPath = "";+ this.loadedProjectName = "";+ this.loadedAgentProfile = "";this.error = null;},diff --git a/webui/components/plugins/plugin-settings.html b/webui/components/plugins/plugin-settings.htmlindex 938c9659c..9be0e4d3e 100644--- a/webui/components/plugins/plugin-settings.html+++ b/webui/components/plugins/plugin-settings.html@@ -42,8 +42,17 @@</select></label>+ <button type="button" class="button plugin-settings-toolbar-button" @click="$store.pluginSettings.openConfigListModal()">+ <span class="icon material-symbols-outlined">list</span>+ </button>+</div></div>++ <div x-show="$store.pluginSettings.scopeMismatchMessage" class="plugin-settings-scope-info">+ <span class="material-symbols-outlined">info</span>+ <span x-text="$store.pluginSettings.scopeMismatchMessage"></span>+ </div></div><!-- Error -->@@ -97,11 +106,17 @@display: flex;align-items: center;gap: 0.5rem;- flex: 1 1 18rem;+ flex: 0 1 18rem;min-width: 12rem;margin: 0;}+ .plugin-settings-toolbar-button {+ flex: 0 0 auto;+ padding: 0.5rem 0.75rem;+ height: 2.5rem;+ }+.plugin-settings-toolbar-label {font-weight: 600;color: var(--color-text-secondary);@@ -113,6 +128,15 @@min-width: 0;}+ .plugin-settings-scope-info {+ display: flex;+ align-items: flex-start;+ gap: 0.5rem;+ padding: 0 1rem 1rem 1rem;+ color: var(--color-text-secondary);+ font-size: var(--font-size-small);+ }+@media (max-width: 640px) {.plugin-settings-toolbar-item {flex-basis: 100%;