Agent Zero AI framework
add extensible plugin list dropdown with marketplace links
Alessandro32bc95da3963
diff --git a/plugins/_plugin_installer/extensions/webui/plugins-list-dropdown-end/marketplace-button.html b/plugins/_plugin_installer/extensions/webui/plugins-list-dropdown-end/marketplace-button.htmlnew file mode 100644index 000000000..b0cc6ba11--- /dev/null+++ b/plugins/_plugin_installer/extensions/webui/plugins-list-dropdown-end/marketplace-button.html@@ -0,0 +1,11 @@+<div x-data>+ <template x-if="$store.pluginInstallStore && plugin.marketplace?.key">+ <button type="button"+ class="dropdown-item"+ title="Open in Marketplace"+ @click="$store.pluginInstallStore.openMarketplaceDetailByKey(plugin.marketplace.key); actionsOpen = false">+ <span class="material-symbols-outlined">storefront</span>+ <span>Marketplace</span>+ </button>+ </template>+</div>diff --git a/plugins/_plugin_installer/extensions/webui/plugins_list_after_load/annotate-marketplace-links.js b/plugins/_plugin_installer/extensions/webui/plugins_list_after_load/annotate-marketplace-links.jsnew file mode 100644index 000000000..c1d0944f9--- /dev/null+++ b/plugins/_plugin_installer/extensions/webui/plugins_list_after_load/annotate-marketplace-links.js@@ -0,0 +1,46 @@+import { store as pluginInstallStore } from "../../../webui/pluginInstallStore.js";++function getPluginName(plugin) {+ return typeof plugin?.name === "string" ? plugin.name.trim() : "";+}++function getMarketplaceMatch(plugin, marketplacePlugins) {+ const pluginName = getPluginName(plugin);+ if (!pluginName || !marketplacePlugins?.[pluginName]) {+ return null;+ }++ return {+ key: pluginName,+ title: marketplacePlugins[pluginName]?.title || pluginName,+ };+}++export default async function annotateMarketplaceLinks(context) {+ const plugins = Array.isArray(context?.plugins) ? context.plugins : null;+ const store = context?.store;+ if (!plugins?.length) return;++ const loaded = await pluginInstallStore.ensureIndexLoaded({ background: true });+ if (!loaded) return;++ const marketplacePlugins = pluginInstallStore.index?.plugins;+ if (!marketplacePlugins || typeof marketplacePlugins !== "object") return;++ let changed = false;+ for (const plugin of plugins) {+ if (!plugin || typeof plugin !== "object") continue;++ const nextMarketplace = getMarketplaceMatch(plugin, marketplacePlugins);+ const currentKey = plugin?.marketplace?.key || "";+ const nextKey = nextMarketplace?.key || "";+ if (currentKey === nextKey) continue;++ plugin.marketplace = nextMarketplace;+ changed = true;+ }++ if (changed && store?.plugins === plugins) {+ store.plugins = [...plugins];+ }+}diff --git a/plugins/_plugin_installer/webui/pluginInstallStore.js b/plugins/_plugin_installer/webui/pluginInstallStore.jsindex 141962db5..347aece2f 100644--- a/plugins/_plugin_installer/webui/pluginInstallStore.js+++ b/plugins/_plugin_installer/webui/pluginInstallStore.js@@ -38,6 +38,7 @@ const model = {// Index stateindex: { authors: {}, plugins: {} },+ indexLoadPromise: null,installedPlugins: [],installedPluginDetails: {},search: "",@@ -227,18 +228,34 @@ const model = {// ── Index Browse ─────────────────────────────- async fetchIndex() {+ hasIndexData() {+ const plugins = this.index?.plugins;+ return !!plugins && typeof plugins === "object" && Object.keys(plugins).length > 0;+ },++ async fetchIndex(options = {}) {+ const background = !!options?.background;+ const suppressErrors = !!options?.suppressErrors;+ if (this.indexLoadPromise) {+ return this.indexLoadPromise;+ }++ const loadPromise = (async () => {try {- this.loading = true;- this.loadingMessage = "Loading plugin index...";+ if (!background) {+ this.loading = true;+ this.loadingMessage = "Loading plugin index...";+ }const data = await api.callJsonApi(PLUGIN_API, {action: "fetch_index",});if (!data.success) {- void toastFrontendError(data.error || "Failed to load index", "Plugin Installer");- return;+ if (!suppressErrors) {+ void toastFrontendError(data.error || "Failed to load index", "Plugin Installer");+ }+ return false;}this.index = data.index;@@ -251,13 +268,40 @@ const model = {installedList.map((plugin) => [plugin.name, plugin]));this.page = 1;+ return true;} catch (e) {const message = e instanceof Error ? e.message : String(e);- void toastFrontendError(`Failed to load plugin index: ${message}`, "Plugin Installer");+ if (!suppressErrors) {+ void toastFrontendError(`Failed to load plugin index: ${message}`, "Plugin Installer");+ }+ return false;} finally {- this.loading = false;- this.loadingMessage = "";+ if (!background) {+ this.loading = false;+ this.loadingMessage = "";+ }+ }+ })();++ this.indexLoadPromise = loadPromise.finally(() => {+ if (this.indexLoadPromise === loadPromise) {+ this.indexLoadPromise = null;+ }+ });++ return this.indexLoadPromise;+ },++ async ensureIndexLoaded(options = {}) {+ if (this.hasIndexData()) {+ return true;}++ await this.fetchIndex({+ background: !!options?.background,+ suppressErrors: !!options?.background,+ });+ return this.hasIndexData();},get pluginsList() {@@ -380,6 +424,32 @@ const model = {this.page = Math.max(1, Math.min(p, this.totalPages));},+ getMarketplacePluginByKey(pluginKey) {+ const key = typeof pluginKey === "string" ? pluginKey.trim() : "";+ if (!key) return null;+ return this.pluginsList.find((plugin) => plugin.key === key) || null;+ },++ async openMarketplaceDetailByKey(pluginKey) {+ const key = typeof pluginKey === "string" ? pluginKey.trim() : "";+ if (!key) return false;++ const loaded = await this.ensureIndexLoaded();+ if (!loaded) return false;++ const plugin = this.getMarketplacePluginByKey(key);+ if (!plugin) {+ void toastFrontendError(+ `Plugin "${key}" is not available in the marketplace index`,+ "Plugin Installer"+ );+ return false;+ }++ this.openDetail(plugin);+ return true;+ },+openDetail(plugin) {this.selectedPlugin = { ...plugin, name: plugin?.key || "" };this.result = null;diff --git a/tests/test_webui_extension_surfaces.py b/tests/test_webui_extension_surfaces.pyindex 28b5f24e0..3872c89c3 100644--- a/tests/test_webui_extension_surfaces.py+++ b/tests/test_webui_extension_surfaces.py@@ -48,6 +48,8 @@ SURFACE_SCENARIOS: list[tuple[str, str]] = [("welcome-actions-end", "webui/components/welcome/welcome-screen.html"),("welcome-banners-start", "webui/components/welcome/welcome-screen.html"),("welcome-banners-end", "webui/components/welcome/welcome-screen.html"),+ ("plugins-list-dropdown-start", "webui/components/plugins/list/plugin-list.html"),+ ("plugins-list-dropdown-end", "webui/components/plugins/list/plugin-list.html"),("modal-shell-start", "webui/js/modals.js"),("modal-shell-end", "webui/js/modals.js"),]diff --git a/webui/components/plugins/list/plugin-list.html b/webui/components/plugins/list/plugin-list.htmlindex 3bba312c2..598371ea9 100644--- a/webui/components/plugins/list/plugin-list.html+++ b/webui/components/plugins/list/plugin-list.html@@ -90,7 +90,7 @@<div class="plugin-title" x-text="plugin.display_name || plugin.name || '(unnamed plugin)'"></div><code class="plugin-path" x-text="plugin.path"></code></div>- <div class="plugin-actions">+ <div class="plugin-actions" x-data="{ actionsOpen: false }"><template x-if="plugin.has_main_screen"><button type="button"class="button"@@ -107,44 +107,67 @@<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><template x-if="plugin.has_init_script"><button type="button"class="button"- title="Run initializer script"+ title="Execute"@click="$store.pluginListStore.openPluginInit(plugin)">- <span class="icon material-symbols-outlined">terminal</span> Init+ <span class="icon material-symbols-outlined">terminal</span> Execute</button></template><button type="button"- class="button"+ class="button icon-button"title="Info"+ aria-label="Info"@click="$store.pluginListStore.openPluginInfo(plugin)"><span class="icon material-symbols-outlined">info</span></button>- <template x-if="plugin.is_custom">+ <div class="dropdown plugin-actions-dropdown"+ @click.outside="actionsOpen = false"+ @keydown.escape.window="if (actionsOpen) actionsOpen = false"><button type="button"- class="button cancel icon-button"- title="Delete"- @click="$confirmClick($event, () => $store.pluginListStore.deletePlugin(plugin))">- <span class="icon material-symbols-outlined">delete</span>+ class="btn-icon-action dropdown-trigger"+ title="More actions"+ aria-label="More actions"+ @click.stop="actionsOpen = !actionsOpen"+ :aria-expanded="actionsOpen.toString()">+ <span class="material-symbols-outlined">more_vert</span></button>- </template>+ <div class="dropdown-menu"+ x-show="actionsOpen"+ x-transition+ style="display: none;">+ <x-extension id="plugins-list-dropdown-start"></x-extension>+ <template x-if="plugin.has_readme">+ <button type="button"+ class="dropdown-item"+ title="README"+ @click="$store.pluginListStore.openPluginDoc(plugin, 'readme'); actionsOpen = false">+ <span class="material-symbols-outlined">description</span>+ <span>README</span>+ </button>+ </template>+ <template x-if="plugin.has_license">+ <button type="button"+ class="dropdown-item"+ title="License"+ @click="$store.pluginListStore.openPluginDoc(plugin, 'license'); actionsOpen = false">+ <span class="material-symbols-outlined">gavel</span>+ <span>License</span>+ </button>+ </template>+ <template x-if="plugin.is_custom">+ <button type="button"+ class="dropdown-item"+ title="Delete"+ @click="$confirmClick($event, () => { $store.pluginListStore.deletePlugin(plugin); actionsOpen = false; })">+ <span class="material-symbols-outlined">delete</span>+ <span>Delete</span>+ </button>+ </template>+ <x-extension id="plugins-list-dropdown-end"></x-extension>+ </div>+ </div></div></div>@@ -312,6 +335,19 @@font-size: 1.1rem;}+ .plugin-actions-dropdown {+ flex: 0 0 auto;+ }++ .plugin-actions-dropdown:not(:has(.dropdown-menu .dropdown-item)) {+ display: none;+ }++ .plugin-actions-dropdown .dropdown-menu {+ margin-top: 0;+ top: calc(100% - 1px);+ }+.plugin-footer-row {display: flex;align-items: center;diff --git a/webui/components/plugins/list/pluginListStore.js b/webui/components/plugins/list/pluginListStore.jsindex 21717db12..3ae9f8c25 100644--- a/webui/components/plugins/list/pluginListStore.js+++ b/webui/components/plugins/list/pluginListStore.js@@ -4,6 +4,7 @@ import { store as pluginSettingsStore } from "/components/plugins/plugin-settingimport { store as pluginToggleStore } from "/components/plugins/toggle/plugin-toggle-store.js";import { store as pluginInitStore } from "/components/plugins/list/plugin-init-store.js";import { store as markdownModalStore } from "/components/modals/markdown/markdown-store.js";+import { callJsExtensions } from "/js/extensions.js";import {store as notificationStore,defaultPriority,@@ -30,6 +31,11 @@ const model = {try {const response = await api.callJsonApi("plugins_list", { filter });this.plugins = Array.isArray(response.plugins) ? response.plugins : [];+ void callJsExtensions("plugins_list_after_load", {+ filter: filter ? { ...filter } : null,+ plugins: this.plugins,+ store: this,+ });} catch (e) {this.plugins = [];showErrorNotification(e, "Failed to load plugins list");