Agent Zero AI framework
Add force refresh support and state management improvements to plugin installer and model config
frdelc7a983638eea
diff --git a/plugins/_model_config/webui/model-config-store.js b/plugins/_model_config/webui/model-config-store.jsindex 3882e69e6..64cd38df4 100644--- a/plugins/_model_config/webui/model-config-store.js+++ b/plugins/_model_config/webui/model-config-store.js@@ -1,4 +1,5 @@import { createStore } from "/js/AlpineStore.js";+import { store as pluginSettingsStore } from "/components/plugins/plugin-settings-store.js";export const MODEL_SECTIONS = [@@ -60,6 +61,12 @@ export const store = createStore("modelConfig", {globalPresets: [],_presetsLoaded: false,+ // Settings include summary state+ modelsSummary: [],+ modelsSummaryLoading: false,+ _modelsSummaryLoaded: false,+ _modelsSummaryPromise: null,+// Switcher stateswitcherAllowed: false,switcherOverride: null,@@ -464,6 +471,59 @@ export const store = createStore("modelConfig", {].map(s => ({ icon: s.icon, title: s.title, provider: label(s.pList, s.cfg?.provider), name: s.cfg?.name || '\u2014' }));},+ async refreshModelsSummary() {+ if (this._modelsSummaryPromise) return await this._modelsSummaryPromise;++ this.modelsSummaryLoading = true;+ this._modelsSummaryPromise = (async () => {+ try {+ const models = await this.loadModelsSummary();+ this.modelsSummary = models;+ this._modelsSummaryLoaded = true;+ return models;+ } catch (e) {+ console.error('Failed to load models summary:', e);+ this.modelsSummary = [];+ this._modelsSummaryLoaded = true;+ return [];+ }+ })();++ try {+ return await this._modelsSummaryPromise;+ } finally {+ this._modelsSummaryPromise = null;+ this.modelsSummaryLoading = false;+ }+ },++ async ensureModelsSummaryLoaded() {+ if (this._modelsSummaryLoaded) return this.modelsSummary;+ return await this.refreshModelsSummary();+ },++ async openConfigFromSummary() {+ try {+ await pluginSettingsStore.openConfig('_model_config');+ } finally {+ await this.refreshModelsSummary();+ }+ },++ async openPresetsFromSummary() {+ await window.openModal?.('/plugins/_model_config/webui/main.html');+ },++ async openApiKeysFromSummary() {+ try {+ await window.openModal?.('/plugins/_model_config/webui/api-keys.html');+ } finally {+ await this.refreshApiKeyStatus().catch((e) => {+ console.error('Failed to refresh API key status:', e);+ });+ }+ },+// Switcher high-level methodsasync refreshSwitcher(contextId) {this.switcherLoading = true;diff --git a/plugins/_model_config/webui/models-summary.html b/plugins/_model_config/webui/models-summary.htmlindex f5941260c..0c4bd6940 100644--- a/plugins/_model_config/webui/models-summary.html+++ b/plugins/_model_config/webui/models-summary.html@@ -7,7 +7,6 @@<body><script type="module">import { store } from "/plugins/_model_config/webui/model-config-store.js";- import { store as pluginListStore } from "/components/plugins/list/pluginListStore.js";</script><div x-data>@@ -19,21 +18,18 @@</div><!-- Read-only model config summary -->- <div x-data="{ loading: true, models: [] }" x-init="- models = await $store.modelConfig.loadModelsSummary().catch(() => []);- loading = false;- " class="model-summary">+ <div x-init="$store.modelConfig.refreshModelsSummary()" class="model-summary"><div class="model-summary-header"><div class="field-title">Current Models</div><div class="field-description">Active model configuration resolved from global, project, and agent profilescopes.</div></div>- <div x-show="loading" style="text-align:center; padding:12px;">+ <div x-show="$store.modelConfig.modelsSummaryLoading" style="text-align:center; padding:12px;"><span class="material-symbols-outlined spinning" style="font-size:18px;">progress_activity</span></div>- <template x-if="!loading && models.length">+ <template x-if="!$store.modelConfig.modelsSummaryLoading && $store.modelConfig.modelsSummary.length"><div class="model-summary-grid">- <template x-for="m in models" :key="m.title">+ <template x-for="m in $store.modelConfig.modelsSummary" :key="m.title"><div class="model-summary-row"><span class="material-symbols-outlined model-summary-icon" x-text="m.icon"></span><span class="model-summary-label" x-text="m.title"></span>@@ -49,13 +45,13 @@</div><div style="display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px;">- <button class="btn btn-field" @click="$store.pluginListStore.openPluginConfig({ name: '_model_config', has_config_screen: true })">+ <button class="btn btn-field" @click="$store.modelConfig.openConfigFromSummary()">Configure Models</button>- <button class="btn btn-field" @click="openModal('/plugins/_model_config/webui/main.html')">+ <button class="btn btn-field" @click="$store.modelConfig.openPresetsFromSummary()">Configure Presets</button>- <button class="btn btn-field" @click="openModal('/plugins/_model_config/webui/api-keys.html')">+ <button class="btn btn-field" @click="$store.modelConfig.openApiKeysFromSummary()">Configure API Keys</button></div>@@ -146,4 +142,4 @@</style></body>-</html>\ No newline at end of file+</html>diff --git a/plugins/_plugin_installer/api/plugin_install.py b/plugins/_plugin_installer/api/plugin_install.pyindex 80f08a13d..67a857f89 100644--- a/plugins/_plugin_installer/api/plugin_install.py+++ b/plugins/_plugin_installer/api/plugin_install.py@@ -56,4 +56,11 @@ class PluginInstall(ApiHandler):return update_from_git(input.get("plugin_name", ""))def _fetch_index(self, input: dict) -> dict:- return {"success": True, **get_plugin_hub_index()}+ force_raw = input.get("force", False)+ force = force_raw if isinstance(force_raw, bool) else str(force_raw).strip().lower() in {+ "1",+ "true",+ "yes",+ "on",+ }+ return {"success": True, **get_plugin_hub_index(force=force)}diff --git a/plugins/_plugin_installer/helpers/install.py b/plugins/_plugin_installer/helpers/install.pyindex 75ffb203d..3722cba61 100644--- a/plugins/_plugin_installer/helpers/install.py+++ b/plugins/_plugin_installer/helpers/install.py@@ -286,9 +286,9 @@ def run_install_hook(plugin_name: str):def run_pre_update_hook(plugin_name: str):return plugins.call_plugin_hook(plugin_name, "pre_update")-def get_plugin_hub_index() -> dict[str, Any]:+def get_plugin_hub_index(force: bool = False) -> dict[str, Any]:"""Return the plugin index plus installed Plugin Hub keys."""- index_data = fetch_plugin_index()+ index_data = fetch_plugin_index(force=force)if not isinstance(index_data, dict):raise ValueError("Plugin index response was not a JSON object")@@ -339,10 +339,19 @@ def get_plugin_hub_index() -> dict[str, Any]:return {"index": index_data, "installed_plugins": installed_keys}-def fetch_plugin_index() -> dict:+def fetch_plugin_index(force: bool = False) -> dict:"""Download the plugin index from GitHub releases."""index_url = "https://github.com/agent0ai/a0-plugins/releases/download/generated-index/index.json"- req = urllib.request.Request(index_url, headers={"User-Agent": "AgentZero"})+ if force:+ separator = "&" if "?" in index_url else "?"+ index_url = f"{index_url}{separator}ts={time.time_ns()}"++ headers = {"User-Agent": "AgentZero"}+ if force:+ headers["Cache-Control"] = "no-cache"+ headers["Pragma"] = "no-cache"++ req = urllib.request.Request(index_url, headers=headers)with urllib.request.urlopen(req, timeout=30) as resp:data = json.loads(resp.read().decode())return datadiff --git a/plugins/_plugin_installer/webui/install-index.html b/plugins/_plugin_installer/webui/install-index.htmlindex fd0698898..257dea535 100644--- a/plugins/_plugin_installer/webui/install-index.html+++ b/plugins/_plugin_installer/webui/install-index.html@@ -8,7 +8,7 @@<body><div x-data><template x-if="$store.pluginInstallStore">- <div class="pi-browse-shell">+ <div class="pi-browse-shell" x-create="$store.pluginInstallStore.openIndexView()"><section class="pi-browse-hero"><div class="pi-browse-copy">@@ -39,6 +39,15 @@<option value="name">Name</option></select></label>++ <button type="button"+ class="button icon-button pi-reload-button"+ aria-label="Reload Plugin Hub"+ title="Reload Plugin Hub"+ @click="$store.pluginInstallStore.reloadIndex()"+ :disabled="$store.pluginInstallStore.loading">+ <span class="material-symbols-outlined">refresh</span>+ </button></div><div class="pi-filter-row" x-show="$store.pluginInstallStore.browseFilters.length > 1">@@ -268,6 +277,20 @@justify-content: space-between;}+ .pi-reload-button {+ flex-shrink: 0;+ display: inline-flex;+ align-items: center;+ justify-content: center;+ min-width: 0;+ min-height: 0;+ padding: 0.45rem 0.6rem;+ }++ .pi-reload-button .material-symbols-outlined {+ font-size: 1.1rem;+ }+.pi-field-label {font-size: 0.8rem;font-weight: 600;diff --git a/plugins/_plugin_installer/webui/pluginInstallStore.js b/plugins/_plugin_installer/webui/pluginInstallStore.jsindex 3bfde045c..dde99b714 100644--- a/plugins/_plugin_installer/webui/pluginInstallStore.js+++ b/plugins/_plugin_installer/webui/pluginInstallStore.js@@ -36,6 +36,7 @@ const model = {// Index stateindex: { authors: {}, plugins: {} },indexLoadPromise: null,+ indexLoadSeq: 0,installedPlugins: [],installedPluginDetails: {},search: "",@@ -64,10 +65,6 @@ const model = {setTab(tab) {this.activeTab = tab;this.result = null;- if (tab === "store") {- this.resetIndex();- void this.fetchIndex();- }},setBrowseFilter(filter) {@@ -281,62 +278,91 @@ const model = {},async fetchIndex(options = {}) {+ const force = !!options?.force;const background = !!options?.background;const suppressErrors = !!options?.suppressErrors;- if (this.indexLoadPromise) {- return this.indexLoadPromise;+ if (!force && this.indexLoadPromise) {+ if (background) {+ return this.indexLoadPromise;+ }++ this.loading = true;+ this.loadingMessage = "Loading plugin index...";+ try {+ return await this.indexLoadPromise;+ } finally {+ this.loading = false;+ this.loadingMessage = "";+ }}+ const requestSeq = ++this.indexLoadSeq;const loadPromise = (async () => {- try {- if (!background) {- this.loading = true;- this.loadingMessage = "Loading plugin index...";- }+ try {+ if (!background) {+ this.loading = true;+ this.loadingMessage = "Loading plugin index...";+ }- const data = await api.callJsonApi(PLUGIN_API, {- action: "fetch_index",- });+ const data = await api.callJsonApi(PLUGIN_API, {+ action: "fetch_index",+ force,+ });- if (!data.success) {- if (!suppressErrors) {- void toastFrontendError(data.error || "Failed to load index", "Plugin Installer");+ if (!data.success) {+ if (!suppressErrors && requestSeq === this.indexLoadSeq) {+ void toastFrontendError(data.error || "Failed to load index", "Plugin Installer");+ }+ return false;}- return false;- }- this.index = data.index;- this.installedPlugins = data.installed_plugins || [];- const installedResponse = await api.callJsonApi("plugins_list", {- filter: { custom: true, builtin: false, search: "" },- });- const installedList = Array.isArray(installedResponse.plugins) ? installedResponse.plugins : [];- this.installedPluginDetails = Object.fromEntries(- installedList.map((plugin) => [plugin.name, plugin])- );- this.page = 1;- return true;- } catch (e) {- const message = e instanceof Error ? e.message : String(e);- if (!suppressErrors) {- void toastFrontendError(`Failed to load plugin index: ${message}`, "Plugin Installer");- }- return false;- } finally {- if (!background) {- this.loading = false;- this.loadingMessage = "";+ const installedResponse = await api.callJsonApi("plugins_list", {+ filter: { custom: true, builtin: false, search: "" },+ });+ const installedList = Array.isArray(installedResponse.plugins) ? installedResponse.plugins : [];++ if (requestSeq !== this.indexLoadSeq) {+ return false;+ }++ this.index = data.index;+ this.installedPlugins = data.installed_plugins || [];+ this.installedPluginDetails = Object.fromEntries(+ installedList.map((plugin) => [plugin.name, plugin])+ );+ this.page = 1;+ return true;+ } catch (e) {+ const message = e instanceof Error ? e.message : String(e);+ if (!suppressErrors && requestSeq === this.indexLoadSeq) {+ void toastFrontendError(`Failed to load plugin index: ${message}`, "Plugin Installer");+ }+ return false;+ } finally {+ if (!background && requestSeq === this.indexLoadSeq) {+ this.loading = false;+ this.loadingMessage = "";+ }}- }})();- this.indexLoadPromise = loadPromise.finally(() => {- if (this.indexLoadPromise === loadPromise) {+ const trackedPromise = loadPromise.finally(() => {+ if (this.indexLoadPromise === trackedPromise) {this.indexLoadPromise = null;}});+ this.indexLoadPromise = trackedPromise;++ return trackedPromise;+ },++ async openIndexView() {+ this.resetIndex();+ return this.fetchIndex({ force: true });+ },- return this.indexLoadPromise;+ async reloadIndex() {+ return this.fetchIndex({ force: true });},async ensureIndexLoaded(options = {}) {