Skip to content

Agent Zero AI framework

Add plugin config listing/deletion + UI improvements

frdela1589c27f54f
diff --git a/python/api/plugins.py b/python/api/plugins.py
index 5c945eec4..1eb37cc10 100644
--- a/python/api/plugins.py
+++ b/python/api/plugins.py
@@ -1,3 +1,5 @@
+import os
+
from python.helpers.api import ApiHandler, Request, Response
from python.helpers import plugins, files
@@ -49,6 +51,50 @@ class Plugins(ApiHandler):
"data": settings,
}
+ if action == "list_configs":
+ plugin_name = input.get("plugin_name", "")
+ if not plugin_name:
+ return Response(status=400, response="Missing plugin_name")
+
+ configs = plugins.find_plugin_assets(
+ plugins.CONFIG_FILE_NAME,
+ plugin_name=plugin_name,
+ project_name="*",
+ agent_profile="*",
+ only_first=False,
+ )
+
+ return {"ok": True, "data": configs}
+
+ if action == "delete_config":
+ 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")
+
+ configs = plugins.find_plugin_assets(
+ plugins.CONFIG_FILE_NAME,
+ plugin_name=plugin_name,
+ project_name="*",
+ agent_profile="*",
+ only_first=False,
+ )
+ allowed_paths = {c.get("path", "") for c in configs}
+ if path not in allowed_paths:
+ return Response(status=400, response="Invalid path")
+
+ if not files.exists(path):
+ return {"ok": True}
+
+ try:
+ os.remove(path)
+ except Exception as e:
+ return Response(status=500, response=f"Failed to delete config: {str(e)}")
+
+ return {"ok": True}
+
if action == "save_config":
plugin_name = input.get("plugin_name", "")
project_name = input.get("project_name", "")
diff --git a/python/helpers/plugins.py b/python/helpers/plugins.py
index 88b0dbba7..dafa7b455 100644
--- a/python/helpers/plugins.py
+++ b/python/helpers/plugins.py
@@ -275,12 +275,31 @@ def find_plugin_assets(
if "*" in path
else ([path] if files.exists(path) else [])
)
+
+ need_proj = proj == "*"
+ need_prof = profile == "*"
+
+ def _after(s: str, marker: str, last: bool = False) -> str:
+ i = s.rfind(marker) if last else s.find(marker)
+ if i == -1:
+ return ""
+ start = i + len(marker)
+ end = s.find("/", start)
+ return s[start:] if end == -1 else s[start:end]
+
for matched in matched_paths:
+ inferred_proj = _after(matched, "/projects/") if need_proj else proj
+ inferred_prof = _after(matched, "/agents/", last=True) if need_prof else profile
results.append(
- {"project_name": proj, "agent_profile": profile, "path": matched}
+ {
+ "project_name": inferred_proj,
+ "agent_profile": inferred_prof,
+ "path": matched,
+ }
)
if only_first:
return True
+ return False
# project/.a0proj/agents/<profile>/plugins/<plugin_name>/...
if project_name:
@@ -295,7 +314,7 @@ def find_plugin_assets(
)
if _collect(path, project_name, agent_profile):
return results
- else:
+ if not agent_profile or agent_profile == "*":
# project/.a0proj/plugins/<plugin_name>/...
path = projects.get_project_meta(
project_name, files.PLUGINS_DIR, plugin_name, *subpaths
diff --git a/webui/components/modals/file-browser/file-browser-store.js b/webui/components/modals/file-browser/file-browser-store.js
index 8f4cc35cc..4d7cd458b 100644
--- a/webui/components/modals/file-browser/file-browser-store.js
+++ b/webui/components/modals/file-browser/file-browser-store.js
@@ -453,7 +453,7 @@ const model = {
downloadFile(file) {
const link = document.createElement("a");
- link.href = `/download_work_dir_file?path=${encodeURIComponent(file.path)}`;
+ link.href = `/api/download_work_dir_file?path=${encodeURIComponent(file.path)}`;
link.download = file.name;
document.body.appendChild(link);
link.click();
diff --git a/webui/components/plugins/plugin-configs.html b/webui/components/plugins/plugin-configs.html
index f97eb7dbb..4daac6641 100644
--- a/webui/components/plugins/plugin-configs.html
+++ b/webui/components/plugins/plugin-configs.html
@@ -1,6 +1,6 @@
<html>
<head>
- <title>Plugin Configurations</title>
+ <title>Existing plugin configurations</title>
<script type="module">
import { store } from "/components/plugins/plugin-settings-store.js";
</script>
@@ -8,7 +8,7 @@
<body>
<div x-data>
<template x-if="$store.pluginSettings">
- <div x-create="$store.pluginSettings.loadConfigList()">
+ <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>
@@ -28,18 +28,26 @@
<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 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>
- Switch
+ Show
</button>
- <button type="button" class="button cancel" @click="$store.pluginSettings.deleteConfig(cfg.project_name || '', cfg.agent_profile || '')">
+ <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>
- Delete
</button>
</div>
</div>
@@ -61,6 +69,10 @@
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);
@@ -85,21 +97,45 @@
background: var(--color-surface);
}
- .plugin-configs-scope-title {
+ .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: wrap;
+ flex-wrap: nowrap;
justify-content: flex-end;
+ flex: 0 0 auto;
}
.plugin-configs-empty {
diff --git a/webui/components/plugins/plugin-settings-store.js b/webui/components/plugins/plugin-settings-store.js
index 0b0e261b5..a055aea2f 100644
--- a/webui/components/plugins/plugin-settings-store.js
+++ b/webui/components/plugins/plugin-settings-store.js
@@ -16,6 +16,44 @@ const model = {
// 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: "",
@@ -58,8 +96,17 @@ const model = {
this.isListingConfigs = true;
this.configsError = null;
try {
- // TODO: list existing plugin config scopes without API calls
- this.configs = [];
+ 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 = [];
@@ -69,6 +116,7 @@ const model = {
},
async switchToConfig(projectName, agentProfile) {
+ if (!this.confirmDiscardUnsavedChanges()) return;
this.projectName = projectName || "";
this.agentProfileKey = agentProfile || "";
await this.loadSettings();
@@ -78,8 +126,32 @@ const model = {
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";
+ 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";
}
@@ -98,10 +170,13 @@ const model = {
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 = "";
@@ -167,6 +242,9 @@ const model = {
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;
}
},
@@ -201,7 +279,10 @@ const model = {
});
const result = await response.json().catch(() => ({}));
if (!result.ok) this.error = result.error || "Save failed";
- else window.closeModal?.();
+ else {
+ this.settingsSnapshotJson = this._toComparableJson(this.settings);
+ window.closeModal?.();
+ }
} catch (e) {
this.error = e?.message || "Save failed";
} finally {
@@ -213,6 +294,9 @@ const model = {
this.pluginName = null;
this.pluginMeta = null;
this.settings = {};
+ this.settingsSnapshotJson = "";
+ this.previousProjectName = "";
+ this.previousAgentProfileKey = "";
this.loadedPath = "";
this.loadedProjectName = "";
this.loadedAgentProfile = "";
diff --git a/webui/components/plugins/plugin-settings.html b/webui/components/plugins/plugin-settings.html
index 9be0e4d3e..51cf32106 100644
--- a/webui/components/plugins/plugin-settings.html
+++ b/webui/components/plugins/plugin-settings.html
@@ -23,7 +23,7 @@
<label class="plugin-settings-toolbar-item">
<span class="plugin-settings-toolbar-label">Project</span>
<select x-model="$store.pluginSettings.projectName"
- @change="$store.pluginSettings.loadSettings()">
+ @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>
@@ -34,7 +34,7 @@
<label class="plugin-settings-toolbar-item">
<span class="plugin-settings-toolbar-label">Agent profile</span>
<select x-model="$store.pluginSettings.agentProfileKey"
- @change="$store.pluginSettings.loadSettings()">
+ @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>
@@ -42,7 +42,7 @@
</select>
</label>
- <button type="button" class="button plugin-settings-toolbar-button" @click="$store.pluginSettings.openConfigListModal()">
+ <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>
@@ -98,7 +98,7 @@
.plugin-settings-toolbar-row {
display: flex;
align-items: center;
- gap: 0.75rem;
+ gap: clamp(0.75rem, 2vw, 2rem);
flex-wrap: wrap;
}
@@ -106,7 +106,7 @@
display: flex;
align-items: center;
gap: 0.5rem;
- flex: 0 1 18rem;
+ flex: 1 1 0;
min-width: 12rem;
margin: 0;
}
diff --git a/webui/js/messages.js b/webui/js/messages.js
index b910b5dce..758fad830 100644
--- a/webui/js/messages.js
+++ b/webui/js/messages.js
@@ -1642,7 +1642,7 @@ function convertImgFilePaths(str) {
}
function convertFilePaths(str) {
- return str.replace(/file:\/\//g, "/download_work_dir_file?path=");
+ return str.replace(/file:\/\//g, "/api/download_work_dir_file?path=");
}
function escapeHTML(str) {