Agent Zero AI framework
WIP: Add plugin toggle UI and helper stubs
frdelc41dfbaa66c8
diff --git a/plugins/memory/extensions/webui/set_messages_before_loop/testingext.js b/plugins/memory/extensions/webui/set_messages_before_loop/testingext.jsdeleted file mode 100644index 6de142e53..000000000--- a/plugins/memory/extensions/webui/set_messages_before_loop/testingext.js+++ /dev/null@@ -1,4 +0,0 @@--export default function extension(context){- console.log("set_messages_before_loop extension called - textingext.js - REMOVE ME", context);-}\ No newline at end of filediff --git a/python/api/plugins.py b/python/api/plugins.pyindex 1eb37cc10..b5b6b4248 100644--- a/python/api/plugins.py+++ b/python/api/plugins.py@@ -53,11 +53,12 @@ class Plugins(ApiHandler):if action == "list_configs":plugin_name = input.get("plugin_name", "")+ asset_type = input.get("asset_type", "config")if not plugin_name:return Response(status=400, response="Missing plugin_name")configs = plugins.find_plugin_assets(- plugins.CONFIG_FILE_NAME,+ plugins.CONFIG_FILE_NAME if asset_type == "config" else plugins.TOGGLE_FILE_PATTERN,plugin_name=plugin_name,project_name="*",agent_profile="*",diff --git a/python/helpers/plugins.py b/python/helpers/plugins.pyindex f8c89e4a6..6b2f809d8 100644--- a/python/helpers/plugins.py+++ b/python/helpers/plugins.py@@ -2,7 +2,7 @@ from __future__ import annotationsimport re, jsonfrom pathlib import Path-from typing import Any, Dict, List, Optional, TYPE_CHECKING+from typing import Any, Dict, List, Literal, Optional, TYPE_CHECKINGfrom python.helpers import files, print_stylefrom pydantic import BaseModel, Field@@ -16,11 +16,15 @@ _META_TARGET_RE = re.compile(re.IGNORECASE,)+type ToggleState = Literal["enabled", "disabled", "advanced"]++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"+TOGGLE_FILE_PATTERN = ".*abled"class PluginMetadata(BaseModel):@@ -30,6 +34,7 @@ class PluginMetadata(BaseModel):settings_sections: List[str] = Field(default_factory=list)per_project_config: bool = Falseper_agent_config: bool = False+ always_enabled: bool = Falseclass PluginListItem(BaseModel):@@ -86,6 +91,7 @@ def get_enhanced_plugins_list()has_main_screen = files.exists(str(d / "webui" / "main.html"))has_config_screen = files.exists(str(d / "webui" / "config.html"))+ toggle_state = get_toggle_state(meta.name)results.append(PluginListItem(name=d.name,@@ -167,15 +173,13 @@ def get_enabled_plugins(agent: Agent | None):plugins = get_plugins_list()active = []- 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 direnabled = Trueif agent:+ from python.helpers import subagentsagent_paths = subagents.get_paths(agent,files.PLUGINS_DIR,@@ -204,6 +208,14 @@ def get_enabled_plugins(agent: Agent | None):return active+def get_toggle_state(plugin_name: str) -> ToggleState:+ return "enabled"+++def toggle_plugin(plugin_name: str, enabled: bool, project_name: str = "", agent_profile: str = ""):+ pass++def get_webui_extensions(extension_point: str, filters: List[str] | None = None):entries: List[str] = []effective_filters = filters or ["*"]diff --git a/python/helpers/subagents.py b/python/helpers/subagents.pyindex 36b71f70a..54b3b2cc1 100644--- a/python/helpers/subagents.py+++ b/python/helpers/subagents.py@@ -388,8 +388,8 @@ def get_paths(# plugins/*/subpaths...from python.helpers import plugins- for plugin in plugins.get_enhanced_plugins_list():- path = files.get_abs_path(str(plugin.path), *subpaths)+ for plugin in plugins.get_plugins_list():+ path = files.get_abs_path(plugin, *subpaths)if (not must_exist_completely) or files.exists(path):if path not in paths:paths.append(path)diff --git a/webui/components/plugins/toggle/plugin-toggle-advanced.html b/webui/components/plugins/toggle/plugin-toggle-advanced.htmlnew file mode 100644index 000000000..51cf32106--- /dev/null+++ b/webui/components/plugins/toggle/plugin-toggle-advanced.html@@ -0,0 +1,208 @@+<html>+<head>+ <title>Plugin Settings</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.onModalOpen()"+ x-destroy="$store.pluginSettings.cleanup()">++ <!-- Context toolbar: Project + Agent profile (mirrors skills list) -->+ <div class="plugin-settings-scope-section">+ <div class="plugin-settings-scope-header">+ <div class="plugin-settings-scope-title">Settings scope</div>+ <div class="plugin-settings-scope-desc">This plugin supports settings per project or agent profile.</div>+ </div>+ <div class="plugin-settings-toolbar">+ <div class="plugin-settings-toolbar-row">++ <label class="plugin-settings-toolbar-item">+ <span class="plugin-settings-toolbar-label">Project</span>+ <select x-model="$store.pluginSettings.projectName"+ @change="$store.pluginSettings.onScopeChanged()">+ <option value="">Global</option>+ <template x-for="project in $store.pluginSettings.projects" :key="project.key">+ <option :value="project.key" x-text="project.label"></option>+ </template>+ </select>+ </label>++ <label class="plugin-settings-toolbar-item">+ <span class="plugin-settings-toolbar-label">Agent profile</span>+ <select x-model="$store.pluginSettings.agentProfileKey"+ @change="$store.pluginSettings.onScopeChanged()">+ <option value="">All profiles</option>+ <template x-for="profile in $store.pluginSettings.agentProfiles" :key="profile.key">+ <option :value="profile.key" x-text="profile.label"></option>+ </template>+ </select>+ </label>++ <button type="button" class="button plugin-settings-toolbar-button" title="Show existing configurations" @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 -->+ <div x-show="$store.pluginSettings.error" class="plugin-settings-error">+ <span class="material-symbols-outlined">error</span>+ <span x-text="$store.pluginSettings.error"></span>+ </div>++ <!-- Loading -->+ <div x-show="$store.pluginSettings.isLoading" class="plugin-settings-loading">+ <span class="material-symbols-outlined spinning">progress_activity</span>+ <span>Loading settings...</span>+ </div>++ <!-- Plugin settings body: plugin provides /plugins/<name>/webui/config.html -->+ <div x-show="!$store.pluginSettings.isLoading"+ class="plugin-settings-body"+ x-html="$store.pluginSettings.settingsComponentHtml">+ </div>++ </div>+ </template>+ </div>++ <!-- Footer (pinned outside scroll area) -->+ <div class="modal-footer" data-modal-footer>+ <button class="btn btn-ok"+ @click="$store.pluginSettings.save()"+ :disabled="$store.pluginSettings?.isSaving || $store.pluginSettings?.isLoading">+ Save+ </button>+ <button class="btn btn-cancel"+ @click="window.closeModal?.()">+ Cancel+ </button>+ </div>++ <style>+ .plugin-settings-toolbar, .plugin-settings-body {+ padding: 1rem;+ }++ .plugin-settings-toolbar-row {+ display: flex;+ align-items: center;+ gap: clamp(0.75rem, 2vw, 2rem);+ flex-wrap: wrap;+ }++ .plugin-settings-toolbar-item {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ flex: 1 1 0;+ 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);+ white-space: nowrap;+ }++ .plugin-settings-toolbar-item select {+ flex: 1 1 auto;+ 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%;+ min-width: 0;+ }+ }++ .plugin-settings-error {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ color: var(--color-error, #e74c3c);+ background: var(--color-error-bg, #fdecea);+ border-radius: 4px;+ padding: 0.5rem 0.75rem;+ margin-bottom: 0.75rem;+ font-size: var(--font-size-small);+ }++ .plugin-settings-loading {+ display: flex;+ align-items: center;+ justify-content: center;+ gap: 0.5rem;+ padding: 2rem;+ color: var(--color-text-secondary);+ }++ .plugin-settings-body {+ min-height: 4rem;+ }++ .spinning {+ animation: spin 1s linear infinite;+ }++ @keyframes spin {+ from { transform: rotate(0deg); }+ to { transform: rotate(360deg); }+ }++ .plugin-settings-scope-section {+ border: 1px solid var(--color-border);+ border-radius: 4px;+ margin: 1rem;+ padding: 0;+ overflow: hidden;+ }++ .plugin-settings-scope-header {+ padding: 0.75rem 1rem;+ border-bottom: 1px solid var(--color-border);+ background: var(--color-bg-secondary);+ }++ .plugin-settings-scope-title {+ font-weight: 600;+ font-size: var(--font-size-normal);+ color: var(--color-text-primary);+ }++ .plugin-settings-scope-desc {+ font-size: var(--font-size-small);+ color: var(--color-text-secondary);+ margin-top: 0.25rem;+ }+ </style>+</body>+</html>diff --git a/webui/components/plugins/toggle/plugin-toggle-store.js b/webui/components/plugins/toggle/plugin-toggle-store.jsnew file mode 100644index 000000000..6aa1e1c1b--- /dev/null+++ b/webui/components/plugins/toggle/plugin-toggle-store.js@@ -0,0 +1,318 @@+import { createStore } from "/js/AlpineStore.js";++const fetchApi = globalThis.fetchApi;++const model = {+ // which plugin this modal is showing+ pluginName: null,+ pluginMeta: null,++ // context selectors (mirrors skills list pattern)+ projects: [],+ agentProfiles: [],+ projectName: "",+ agentProfileKey: "",++ // plugin settings data (plugins bind their fields here)+ settings: {},++ settingsSnapshotJson: "",+ previousProjectName: "",+ previousAgentProfileKey: "",++ _toComparableJson(value) {+ try {+ return JSON.stringify(value ?? {});+ } catch {+ return "";+ }+ },++ get hasUnsavedChanges() {+ return this._toComparableJson(this.settings) !== (this.settingsSnapshotJson || "");+ },++ confirmDiscardUnsavedChanges() {+ if (!this.hasUnsavedChanges) return true;+ return window.confirm("You have unsaved changes that will be lost. Continue?");+ },++ async onScopeChanged() {+ const nextProject = this.projectName || "";+ const nextProfile = this.agentProfileKey || "";+ const prevProject = this.previousProjectName || "";+ const prevProfile = this.previousAgentProfileKey || "";++ if (nextProject === prevProject && nextProfile === prevProfile) return;++ if (!this.confirmDiscardUnsavedChanges()) {+ this.projectName = prevProject;+ this.agentProfileKey = prevProfile;+ return;+ }++ await this.loadSettings();+ },++ // 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 {+ const response = await fetchApi("/plugins", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ action: "list_configs",+ plugin_name: this.pluginName,+ }),+ });+ const result = await response.json().catch(() => ({}));+ this.configs = result.ok ? (result.data || []) : [];+ if (!result.ok) this.configsError = result.error || "Failed to load configurations";+ } catch (e) {+ this.configsError = e?.message || "Failed to load configurations";+ this.configs = [];+ } finally {+ this.isListingConfigs = false;+ }+ },++ async switchToConfig(projectName, agentProfile) {+ if (!this.confirmDiscardUnsavedChanges()) return;+ this.projectName = projectName || "";+ this.agentProfileKey = agentProfile || "";+ await this.loadSettings();+ await window.closeModal?.();+ },++ async deleteConfig(projectName, agentProfile) {+ if (!this.pluginName) return;+ try {+ const cfg = (this.configs || []).find(+ (c) => (c?.project_name || "") === (projectName || "") && (c?.agent_profile || "") === (agentProfile || "")+ );+ const path = cfg?.path || "";+ if (!path) {+ this.configsError = "Configuration path not found";+ return;+ }++ const response = await fetchApi("/plugins", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ action: "delete_config",+ plugin_name: this.pluginName,+ path,+ }),+ });+ const result = await response.json().catch(() => ({}));+ if (!result.ok) {+ this.configsError = result.error || "Delete failed";+ return;+ }++ this.configsError = null;+ await this.loadConfigList();+ } 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',++ isLoading: false,+ isSaving: false,+ error: null,++ // Called by the subsection button before openModal()+ async open(pluginName) {+ this.pluginName = pluginName;+ this.pluginMeta = null;+ this.settings = {};+ this.settingsSnapshotJson = "";+ this.error = null;+ this.saveMode = 'plugin';+ this.projectName = "";+ this.agentProfileKey = "";+ this.previousProjectName = "";+ this.previousAgentProfileKey = "";+ this.loadedPath = "";+ this.loadedProjectName = "";+ this.loadedAgentProfile = "";+ await Promise.all([this.loadProjects(), this.loadAgentProfiles()]);+ await this.loadSettings();+ },++ // Called by x-create inside the modal on every open+ async onModalOpen() {+ if (this.pluginName) await this.loadSettings();+ },++ async loadAgentProfiles() {+ try {+ const response = await fetchApi("/agents", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ action: "list" }),+ });+ const data = await response.json().catch(() => ({}));+ this.agentProfiles = data.ok ? (data.data || []) : [];+ } catch {+ this.agentProfiles = [];+ }+ },++ async loadProjects() {+ try {+ const response = await fetchApi("/projects", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ action: "list_options" }),+ });+ const data = await response.json().catch(() => ({}));+ this.projects = data.ok ? (data.data || []) : [];+ } catch {+ this.projects = [];+ }+ },++ async loadSettings() {+ if (!this.pluginName) return;+ this.isLoading = true;+ this.error = null;+ try {+ const response = await fetchApi("/plugins", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ action: "get_config",+ plugin_name: this.pluginName,+ project_name: this.projectName || "",+ agent_profile: this.agentProfileKey || "",+ }),+ });+ 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";+ this.settings = {};+ } finally {+ this.settingsSnapshotJson = this._toComparableJson(this.settings);+ this.previousProjectName = this.projectName || "";+ this.previousAgentProfileKey = this.agentProfileKey || "";+ this.isLoading = false;+ }+ },++ async save() {+ if (!this.pluginName) return;++ // Core-backed plugins (e.g. memory) delegate to the settings store+ if (this.saveMode === 'core') {+ const coreStore = Alpine.store('settings');+ if (coreStore?.saveSettings) {+ const ok = await coreStore.saveSettings();+ if (ok) window.closeModal?.();+ }+ return;+ }++ // Plugin-specific settings: persist to plugin settings API+ this.isSaving = true;+ this.error = null;+ try {+ const response = await fetchApi("/plugins", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ action: "save_config",+ plugin_name: this.pluginName,+ project_name: this.projectName || "",+ agent_profile: this.agentProfileKey || "",+ settings: this.settings,+ }),+ });+ const result = await response.json().catch(() => ({}));+ if (!result.ok) this.error = result.error || "Save failed";+ else {+ this.settingsSnapshotJson = this._toComparableJson(this.settings);+ window.closeModal?.();+ }+ } catch (e) {+ this.error = e?.message || "Save failed";+ } finally {+ this.isSaving = false;+ }+ },++ cleanup() {+ this.pluginName = null;+ this.pluginMeta = null;+ this.settings = {};+ this.settingsSnapshotJson = "";+ this.previousProjectName = "";+ this.previousAgentProfileKey = "";+ this.loadedPath = "";+ this.loadedProjectName = "";+ this.loadedAgentProfile = "";+ this.error = null;+ this.isLoading = false;+ this.isSaving = false;+ this.isListingConfigs = false;+ this.configsError = null;+ this.configs = [];+ },++ // Reactive URL for the plugin's settings component (used with x-html injection)+ get settingsComponentHtml() {+ if (!this.pluginName) return "";+ return `<x-component path="/plugins/${this.pluginName}/webui/config.html"></x-component>`;+ },+};++export const store = createStore("pluginSettings", model);diff --git a/webui/components/plugins/toggle/plugin-toggles.html b/webui/components/plugins/toggle/plugin-toggles.htmlnew file mode 100644index 000000000..4daac6641--- /dev/null+++ b/webui/components/plugins/toggle/plugin-toggles.html@@ -0,0 +1,148 @@+<html>+<head>+ <title>Existing 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()" class="plugin-configs-container">++ <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-top">+ <div class="plugin-configs-scope-line">+ <span class="plugin-configs-scope-key">Project:</span>+ <span x-text="$store.pluginSettings.projectLabel(cfg.project_name || '')"></span>+ </div>+ <div class="plugin-configs-scope-line">+ <span class="plugin-configs-scope-key">Agent profile:</span>+ <span x-text="$store.pluginSettings.agentProfileLabel(cfg.agent_profile || '')"></span>+ </div>+ </div>+ <div class="plugin-configs-scope-sub" x-text="cfg.path || ''"></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>+ Show+ </button>+ <button type="button" class="button cancel icon-button" title="Delete" @click="$confirmClick($event, () => $store.pluginSettings.deleteConfig(cfg.project_name || '', cfg.agent_profile || ''))">+ <span class="icon material-symbols-outlined">delete</span>+ </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-container {+ padding: 0.75rem;+ }++ .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 {+ flex: 1 1 auto;+ min-width: 0;+ }++ .plugin-configs-scope-top {+ display: flex;+ gap: 1rem;+ flex-wrap: wrap;+ align-items: baseline;+ }++ .plugin-configs-scope-line {+ display: flex;+ gap: 0.35rem;+ align-items: baseline;+ }++ .plugin-configs-scope-key {+ font-weight: 600;+ color: var(--color-text-secondary);+ white-space: nowrap;+ }++ .plugin-configs-scope-sub {+ font-size: var(--font-size-small);+ color: var(--color-text-secondary);+ margin-top: 0.2rem;+ white-space: normal;+ overflow-wrap: break-word;+ word-break: normal;+ }++ .plugin-configs-actions {+ display: flex;+ gap: 0.5rem;+ flex-wrap: nowrap;+ justify-content: flex-end;+ flex: 0 0 auto;+ }++ .plugin-configs-empty {+ padding: 0.75rem;+ color: var(--color-text-secondary);+ font-size: var(--font-size-small);+ }+ </style>+</body>+</html>