Skip to content

Agent Zero AI framework

generic markdown modal and plugins wiring

Alessandro59ed70d8c191
diff --git a/python/api/plugins.py b/python/api/plugins.py
index 0ed8b280d..aad05266c 100644
--- a/python/api/plugins.py
+++ b/python/api/plugins.py
@@ -132,4 +132,23 @@ class Plugins(ApiHandler):
)
return {"ok": True}
+ if action == "get_doc":
+ plugin_name = input.get("plugin_name", "")
+ doc = input.get("doc", "") # "readme" or "license"
+ if not plugin_name:
+ return Response(status=400, response="Missing plugin_name")
+ if doc not in ("readme", "license"):
+ return Response(status=400, response="doc must be 'readme' or 'license'")
+
+ plugin_dir = plugins.find_plugin_dir(plugin_name)
+ if not plugin_dir:
+ return Response(status=404, response="Plugin not found")
+
+ filename = "README.md" if doc == "readme" else "LICENSE"
+ file_path = files.get_abs_path(plugin_dir, filename)
+ if not files.exists(file_path):
+ return Response(status=404, response=f"{filename} not found")
+
+ return {"ok": True, "content": files.read_file(file_path), "filename": filename}
+
return Response(status=400, response=f"Unknown action: {action}")
diff --git a/python/helpers/plugins.py b/python/helpers/plugins.py
index 55086f0d1..82bc39ae9 100644
--- a/python/helpers/plugins.py
+++ b/python/helpers/plugins.py
@@ -53,6 +53,8 @@ class PluginListItem(BaseModel):
is_custom: bool = False
has_main_screen: bool = False
has_config_screen: bool = False
+ has_readme: bool = False
+ has_license: bool = False
toggle_state: ToggleState = "disabled"
@@ -96,6 +98,8 @@ 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"))
+ has_readme = files.exists(str(d / "README.md"))
+ has_license = files.exists(str(d / "LICENSE"))
toggle_state = get_toggle_state(d.name)
results.append(
PluginListItem(
@@ -111,6 +115,8 @@ def get_enhanced_plugins_list(
is_custom=is_custom,
has_main_screen=has_main_screen,
has_config_screen=has_config_screen,
+ has_readme=has_readme,
+ has_license=has_license,
toggle_state=toggle_state,
)
)
diff --git a/webui/components/modals/markdown/markdown-modal.html b/webui/components/modals/markdown/markdown-modal.html
new file mode 100644
index 000000000..7262672a7
--- /dev/null
+++ b/webui/components/modals/markdown/markdown-modal.html
@@ -0,0 +1,54 @@
+<html>
+<head>
+ <title>Document</title>
+ <script type="module">
+ import { store } from "/components/modals/markdown/markdown-store.js";
+ </script>
+</head>
+<body>
+ <div x-data>
+ <template x-if="$store.markdownModal">
+ <div x-create="$el.closest('.modal')?.querySelector('.modal-title') && ($el.closest('.modal').querySelector('.modal-title').textContent = $store.markdownModal.title)"
+ x-destroy="$store.markdownModal.cleanup()"
+ class="md-modal-root">
+
+ <div x-show="$store.markdownModal.error" class="md-modal-error">
+ <span class="material-symbols-outlined">error</span>
+ <span x-text="$store.markdownModal.error"></span>
+ </div>
+
+ <div class="md-modal-body msg-content"
+ x-show="!$store.markdownModal.error"
+ x-html="$store.markdownModal.renderedHtml">
+ </div>
+ </div>
+ </template>
+ </div>
+
+ <div class="modal-footer" data-modal-footer>
+ <button class="btn btn-cancel" @click="window.closeModal?.()">Close</button>
+ </div>
+
+ <style>
+ .md-modal-root {
+ display: flex;
+ flex-direction: column;
+ width: 100%;
+ }
+
+ .md-modal-body {
+ padding: 1.25rem 1.5rem;
+ overflow-y: auto;
+ max-height: 72vh;
+ }
+
+ .md-modal-error {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ color: var(--color-error, #e74c3c);
+ padding: 1rem 1.5rem;
+ }
+ </style>
+</body>
+</html>
diff --git a/webui/components/modals/markdown/markdown-store.js b/webui/components/modals/markdown/markdown-store.js
new file mode 100644
index 000000000..571d52cee
--- /dev/null
+++ b/webui/components/modals/markdown/markdown-store.js
@@ -0,0 +1,25 @@
+import { marked } from "/vendor/marked/marked.esm.js";
+import { createStore } from "/js/AlpineStore.js";
+
+export const store = createStore("markdownModal", {
+ title: "",
+ content: "",
+ error: null,
+
+ open(title, content) {
+ this.title = title;
+ this.content = content;
+ this.error = null;
+ },
+
+ get renderedHtml() {
+ if (!this.content) return "";
+ return marked.parse(this.content, { breaks: true });
+ },
+
+ cleanup() {
+ this.title = "";
+ this.content = "";
+ this.error = null;
+ },
+});
diff --git a/webui/components/plugins/list/plugin-list.html b/webui/components/plugins/list/plugin-list.html
index 9f286bed3..d810905ee 100644
--- a/webui/components/plugins/list/plugin-list.html
+++ b/webui/components/plugins/list/plugin-list.html
@@ -79,6 +79,22 @@
<span class="icon material-symbols-outlined">settings</span> Config
</button>
</template>
+ <template x-if="plugin.has_readme">
+ <button type="button"
+ class="button"
+ title="README"
+ @click="$store.pluginListStore.openPluginDoc(plugin, 'readme')">
+ <span class="icon material-symbols-outlined">description</span> README
+ </button>
+ </template>
+ <template x-if="plugin.has_license">
+ <button type="button"
+ class="button"
+ title="LICENSE"
+ @click="$store.pluginListStore.openPluginDoc(plugin, 'license')">
+ <span class="icon material-symbols-outlined">gavel</span> License
+ </button>
+ </template>
<button type="button"
class="button"
title="Info"
diff --git a/webui/components/plugins/list/pluginListStore.js b/webui/components/plugins/list/pluginListStore.js
index b1f3790a0..0a1e5dfd6 100644
--- a/webui/components/plugins/list/pluginListStore.js
+++ b/webui/components/plugins/list/pluginListStore.js
@@ -2,6 +2,7 @@ import { createStore } from "/js/AlpineStore.js";
import * as api from "/js/api.js";
import "/components/plugins/plugin-settings-store.js";
import "/components/plugins/toggle/plugin-toggle-store.js";
+import "/components/modals/markdown/markdown-store.js";
import {
store as notificationStore,
defaultPriority,
@@ -126,6 +127,23 @@ const model = {
}
},
+ async openPluginDoc(plugin, doc) {
+ try {
+ const response = await api.callJsonApi("plugins", {
+ action: "get_doc",
+ plugin_name: plugin.name,
+ doc,
+ });
+ if (response?.error) throw new Error(response.error);
+ const markdownModal = Alpine.store("markdownModal");
+ if (!markdownModal) throw new Error("Markdown modal store unavailable.");
+ markdownModal.open(response.filename, response.content);
+ window.openModal?.("components/modals/markdown/markdown-modal.html");
+ } catch (e) {
+ showErrorNotification(e, "Failed to open document");
+ }
+ },
+
openPluginInfo(plugin) {
if (!plugin) return;
this.selectedPlugin = plugin;