Skip to content

Agent Zero AI framework

simplify plugin config modal opening

Alessandro5ed58fb10fde
diff --git a/AGENTS.md b/AGENTS.md
index 1fa912c1e..21b930bac 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -140,7 +140,7 @@ Key Files:
- Runtime hooks: Plugins may also expose hooks in hooks.py, callable by the framework through helpers.plugins.call_plugin_hook(...).
- Hook runtime: hooks.py executes inside the Agent Zero framework Python environment, so sys.executable -m pip installs dependencies into that same framework runtime.
- Environment targeting: If a plugin needs packages or binaries for the separate agent execution runtime or system environment, it must explicitly switch environments in a subprocess by targeting the correct interpreter, virtualenv, or package manager.
-- Settings: Use get_plugin_config(plugin_name, agent=agent) to retrieve settings. Plugins can expose a UI for settings via webui/config.html. Plugin settings modals instantiate a local context from $store.pluginSettingsPrototype; bind plugin fields to config.* and use context.* for modal-level state and actions. For plugins wrapping core settings, set context.saveMode = 'core' in x-init.
+- Settings: Use get_plugin_config(plugin_name, agent=agent) to retrieve settings. Plugins can expose a UI for settings via webui/config.html. Plugin settings modals instantiate a local context from $store.pluginSettingsPrototype; bind plugin fields to config.* and use context.* for modal-level state and actions.
- Activation: Global and scoped activation rules are stored as .toggle-1 (ON) and .toggle-0 (OFF). Scoped rules are handled via the plugin "Switch" modal.
- Cleanup rule: Plugins should not permanently modify the system in ways that outlive the plugin. Deleting a plugin should not leave behind symlinks, unmanaged services, or stray files outside plugin-owned paths unless the user explicitly requested that behavior.
diff --git a/plugins/_plugin_installer/webui/pluginInstallStore.js b/plugins/_plugin_installer/webui/pluginInstallStore.js
index 058e31b8d..7fbf5e963 100644
--- a/plugins/_plugin_installer/webui/pluginInstallStore.js
+++ b/plugins/_plugin_installer/webui/pluginInstallStore.js
@@ -7,6 +7,7 @@ import { showConfirmDialog } from "/js/confirmDialog.js";
import { store as imageViewerStore } from "/components/modals/image-viewer/image-viewer-store.js";
import { store as pluginListStore } from "/components/plugins/list/pluginListStore.js";
import { store as pluginExecuteStore } from "/components/plugins/list/plugin-execute-store.js";
+import { store as pluginSettingsStore } from "/components/plugins/plugin-settings-store.js";
const PLUGIN_API = "plugins/_plugin_installer/plugin_install";
const PER_PAGE = 20;
@@ -590,7 +591,12 @@ const model = {
async handleOpenConfig() {
if (this.installedPluginInfo) {
- await pluginListStore.openPluginConfig(this.installedPluginInfo);
+ try {
+ await pluginSettingsStore.openConfig(this.installedPluginInfo.name);
+ } catch (e) {
+ const message = e instanceof Error ? e.message : String(e);
+ void toastFrontendError(message, "Plugin Installer");
+ }
}
},
diff --git a/skills/a0-create-plugin/SKILL.md b/skills/a0-create-plugin/SKILL.md
index 57e88cd0e..6ea78849c 100644
--- a/skills/a0-create-plugin/SKILL.md
+++ b/skills/a0-create-plugin/SKILL.md
@@ -132,19 +132,6 @@ The modal provides Project + Agent profile context selectors. The plugin setting
The modal's Save button persists `config` to `config.json` in the correct scope (project/agent/global).
-### Surfacing core settings (e.g. memory pattern)
-
-If your plugin exposes existing core settings rather than plugin-specific ones, set `saveMode = 'core'` so Save delegates to the core settings API:
-
-```html
-<div x-data x-init="
- context.saveMode = 'core';
- if ($store.settings && !$store.settings.settings) $store.settings.onOpen();
-">
- <x-component path="settings/agent/memory.html"></x-component>
-</div>
-```
-
### Sidebar Button (sidebar entry point)
- Extension point: `sidebar-quick-actions-main-start`
- Class: `class="config-button"`
diff --git a/skills/a0-review-plugin/checklists.md b/skills/a0-review-plugin/checklists.md
index b77c4e15a..ba6418d02 100644
--- a/skills/a0-review-plugin/checklists.md
+++ b/skills/a0-review-plugin/checklists.md
@@ -188,13 +188,6 @@ save_plugin_config(
</html>
```
-Use `saveMode = 'core'` if exposing core settings instead of plugin-specific ones:
-```html
-<div x-data x-init="context.saveMode = 'core'">
- <!-- core settings component -->
-</div>
-```
-
---
## Sidebar Button (extension point)
diff --git a/webui/components/plugins/list/pluginListStore.js b/webui/components/plugins/list/pluginListStore.js
index e0bee2fe9..841b80f6b 100644
--- a/webui/components/plugins/list/pluginListStore.js
+++ b/webui/components/plugins/list/pluginListStore.js
@@ -79,21 +79,10 @@ const model = {
async openPluginConfig(plugin) {
if (!plugin?.name || !plugin?.has_config_screen) return;
try {
- // Initialize toggle store for activation state UI in settings modal
- if (pluginToggleStore?.open) await pluginToggleStore.open(plugin);
-
- if (!pluginSettingsStore?.open) {
+ if (!pluginSettingsStore?.openConfig) {
throw new Error("Plugin settings store is unavailable.");
}
- await pluginSettingsStore.open(plugin.name, {
- perProjectConfig: !!plugin.per_project_config,
- perAgentConfig: !!plugin.per_agent_config,
- });
- // Set saveMode after open() (open resets it to 'plugin')
- if (plugin.settings_sections?.includes('core')) {
- pluginSettingsStore.saveMode = 'core';
- }
- window.openModal?.("components/plugins/plugin-settings.html");
+ await pluginSettingsStore.openConfig(plugin.name);
} catch (e) {
showErrorNotification(e, "Failed to open plugin config");
}
diff --git a/webui/components/plugins/plugin-settings-store.js b/webui/components/plugins/plugin-settings-store.js
index dc73b260d..785c02ede 100644
--- a/webui/components/plugins/plugin-settings-store.js
+++ b/webui/components/plugins/plugin-settings-store.js
@@ -1,6 +1,6 @@
import { createStore } from "/js/AlpineStore.js";
+import * as api from "/js/api.js";
import { showConfirmDialog } from "/js/confirmDialog.js";
-import { store as settingsStore } from "/components/settings/settings-store.js";
import { store as pluginToggleStore } from "/components/plugins/toggle/plugin-toggle-store.js";
const fetchApi = globalThis.fetchApi;
@@ -41,6 +41,64 @@ const model = {
return window.confirm("You have unsaved changes that will be lost. Continue?");
},
+ async _loadPluginMeta(pluginName) {
+ const response = await api.callJsonApi("plugins_list", {
+ filter: { custom: true, builtin: true, search: "" },
+ });
+ const plugins = Array.isArray(response?.plugins) ? response.plugins : [];
+ return plugins.find((plugin) => plugin?.name === pluginName) || null;
+ },
+
+ _hasProject(projectName) {
+ if (!projectName) return false;
+ return (this.projects || []).some((project) => project?.key === projectName);
+ },
+
+ _hasAgentProfile(agentProfileKey) {
+ if (!agentProfileKey) return false;
+ return (this.agentProfiles || []).some((profile) => profile?.key === agentProfileKey);
+ },
+
+ _resolveScope(pluginMeta, projectName = "", agentProfileKey = "") {
+ const resolvedProjectName =
+ pluginMeta?.per_project_config && this._hasProject(projectName)
+ ? projectName
+ : "";
+ const resolvedAgentProfileKey =
+ pluginMeta?.per_agent_config && this._hasAgentProfile(agentProfileKey)
+ ? agentProfileKey
+ : "";
+
+ return {
+ projectName: resolvedProjectName,
+ agentProfileKey: resolvedAgentProfileKey,
+ };
+ },
+
+ _applyPluginState(pluginMeta, { projectName = "", agentProfileKey = "" } = {}) {
+ this.pluginName = pluginMeta?.name || null;
+ this.pluginMeta = pluginMeta || null;
+ this.settings = {};
+ this.settingsSnapshotJson = "";
+ this.error = null;
+ this.projectName = projectName;
+ this.agentProfileKey = agentProfileKey;
+ this.previousProjectName = projectName;
+ this.previousAgentProfileKey = agentProfileKey;
+ this.loadedPath = "";
+ this.loadedProjectName = "";
+ this.loadedAgentProfile = "";
+ this.perProjectConfig = !!pluginMeta?.per_project_config;
+ this.perAgentConfig = !!pluginMeta?.per_agent_config;
+ },
+
+ async _syncToggleScope(projectName = "", agentProfileKey = "") {
+ if (!pluginToggleStore?.loadToggleStatus) return;
+ pluginToggleStore.projectName = projectName;
+ pluginToggleStore.agentProfileKey = agentProfileKey;
+ await pluginToggleStore.loadToggleStatus();
+ },
+
async onScopeChanged() {
const nextProject = this.projectName || "";
const nextProfile = this.agentProfileKey || "";
@@ -56,13 +114,7 @@ const model = {
}
await this.loadSettings();
-
- // Mirror scope change to pluginToggle so activation state stays in sync
- if (pluginToggleStore?.loadToggleStatus) {
- pluginToggleStore.projectName = nextProject;
- pluginToggleStore.agentProfileKey = nextProfile;
- await pluginToggleStore.loadToggleStatus();
- }
+ await this._syncToggleScope(nextProject, nextProfile);
},
// where the settings were actually loaded from
@@ -131,6 +183,7 @@ const model = {
this.projectName = projectName || "";
this.agentProfileKey = agentProfile || "";
await this.loadSettings();
+ await this._syncToggleScope(this.projectName, this.agentProfileKey);
await window.closeModal?.();
},
@@ -168,10 +221,6 @@ const model = {
}
},
- // 'plugin' = save to plugin settings API
- // 'core' = save via $store.settings.saveSettings() (for plugins that surface core settings)
- saveMode: 'plugin',
-
perProjectConfig: true,
perAgentConfig: true,
@@ -179,32 +228,30 @@ const model = {
isSaving: false,
error: null,
- // Called by the subsection button before openModal()
- // Optional scope: { projectName, agentProfileKey } — skips redundant global loadSettings()
- // when the caller already knows which scope to open at.
- async open(pluginName, { projectName = "", agentProfileKey = "", perProjectConfig = true, perAgentConfig = true } = {}) {
- this.pluginName = pluginName;
- this.pluginMeta = null;
- this.settings = {};
- this.settingsSnapshotJson = "";
- this.error = null;
- this.saveMode = 'plugin';
- this.perProjectConfig = perProjectConfig;
- this.perAgentConfig = perAgentConfig;
- this.projectName = projectName;
- this.agentProfileKey = agentProfileKey;
- this.previousProjectName = projectName;
- this.previousAgentProfileKey = agentProfileKey;
- this.loadedPath = "";
- this.loadedProjectName = "";
- this.loadedAgentProfile = "";
+ async openConfig(pluginName, projectName = "", agentProfile = "") {
+ if (!pluginName) {
+ throw new Error("Missing plugin name.");
+ }
+
+ this.cleanup();
+ const pluginMeta = await this._loadPluginMeta(pluginName);
+ if (!pluginMeta) {
+ throw new Error(`Plugin "${pluginName}" not found.`);
+ }
+ if (!pluginMeta.has_config_screen) {
+ throw new Error(`Plugin "${pluginName}" has no config screen.`);
+ }
+
await Promise.all([this.loadProjects(), this.loadAgentProfiles()]);
+ const resolvedScope = this._resolveScope(pluginMeta, projectName || "", agentProfile || "");
+ this._applyPluginState(pluginMeta, resolvedScope);
await this.loadSettings();
- },
- // Called by x-create inside the modal on every open
- async onModalOpen() {
- if (this.pluginName) await this.loadSettings();
+ if (!pluginToggleStore?.open) {
+ throw new Error("Plugin toggle store is unavailable.");
+ }
+ await pluginToggleStore.open(pluginMeta, resolvedScope);
+ await window.openModal?.("/components/plugins/plugin-settings.html");
},
async loadAgentProfiles() {
@@ -290,17 +337,6 @@ const model = {
async save() {
if (!this.pluginName) return;
-
- // Core-backed plugins (e.g. memory) delegate to the settings store
- if (this.saveMode === 'core') {
- if (settingsStore?.saveSettings) {
- const ok = await settingsStore.saveSettings();
- if (ok) window.closeModal?.();
- }
- return;
- }
-
- // Plugin-specific settings: persist to plugin settings API
this.isSaving = true;
this.error = null;
try {
@@ -331,6 +367,10 @@ const model = {
cleanup() {
this.pluginName = null;
this.pluginMeta = null;
+ this.projects = [];
+ this.agentProfiles = [];
+ this.projectName = "";
+ this.agentProfileKey = "";
this.settings = {};
this.settingsSnapshotJson = "";
this.previousProjectName = "";
diff --git a/webui/components/plugins/plugin-settings.html b/webui/components/plugins/plugin-settings.html
index baf720998..2f21983fe 100644
--- a/webui/components/plugins/plugin-settings.html
+++ b/webui/components/plugins/plugin-settings.html
@@ -17,7 +17,7 @@
})()">
<template x-if="context">
<div>
- <div x-create="context.onModalOpen(); (() => { const modal = $el.closest('.modal'); if (modal) modal.__pluginSettingsContext = context; })()"
+ <div x-create="(() => { const modal = $el.closest('.modal'); if (modal) modal.__pluginSettingsContext = context; })()"
x-destroy="context.cleanup()">
<!-- Context toolbar: Project + Agent profile (only when at least one scope is configurable) -->
diff --git a/webui/components/plugins/toggle/plugin-toggle-store.js b/webui/components/plugins/toggle/plugin-toggle-store.js
index 55bee91d6..7332c90f3 100644
--- a/webui/components/plugins/toggle/plugin-toggle-store.js
+++ b/webui/components/plugins/toggle/plugin-toggle-store.js
@@ -32,13 +32,13 @@ const model = {
configs: [],
- async open(plugin) {
+ async open(plugin, { projectName = "", agentProfileKey = "" } = {}) {
this.isLoading = true;
this.error = null;
this.projects = [];
this.agentProfiles = [];
- this.projectName = "";
- this.agentProfileKey = "";
+ this.projectName = projectName || "";
+ this.agentProfileKey = agentProfileKey || "";
this.configs = [];
this.status = 'enabled';
this.hasExplicitRuleForScope = false;
@@ -172,19 +172,16 @@ const model = {
async openConfigWithScope() {
if (!this.pluginName) return;
-
- if (settingsStore.pluginName !== this.pluginName) {
- // Different plugin — full init with current scope
- await settingsStore.open(this.pluginName, {
- projectName: this.projectName || "",
- agentProfileKey: this.agentProfileKey || "",
- });
- } else {
- // Same plugin — push current scope explicitly.
- settingsStore.projectName = this.projectName || "";
- settingsStore.agentProfileKey = this.agentProfileKey || "";
+ this.error = null;
+ try {
+ await settingsStore.openConfig(
+ this.pluginName,
+ this.projectName || "",
+ this.agentProfileKey || ""
+ );
+ } catch (e) {
+ this.error = e?.message || "Failed to open plugin config";
}
- await window.openModal?.("/components/plugins/plugin-settings.html");
},
async openConfigListModal() {
diff --git a/webui/components/settings/plugins/plugins-subsection-store.js b/webui/components/settings/plugins/plugins-subsection-store.js
index 5d314a20e..ab2c0206c 100644
--- a/webui/components/settings/plugins/plugins-subsection-store.js
+++ b/webui/components/settings/plugins/plugins-subsection-store.js
@@ -1,6 +1,7 @@
import { createStore } from "/js/AlpineStore.js";
import * as api from "/js/api.js";
-import { store as pluginListStore } from "/components/plugins/list/pluginListStore.js";
+import { toastFrontendError } from "/components/notifications/notification-store.js";
+import { store as pluginSettingsStore } from "/components/plugins/plugin-settings-store.js";
const model = {
tab: "",
@@ -51,7 +52,13 @@ const model = {
},
async openPluginConfig(plugin) {
- await pluginListStore.openPluginConfig(plugin);
+ if (!plugin?.name) return;
+ try {
+ await pluginSettingsStore.openConfig(plugin.name);
+ } catch (e) {
+ const message = e instanceof Error ? e.message : String(e);
+ void toastFrontendError(message, "Plugin Settings");
+ }
},
};