Agent Zero AI framework
Refine settings accordion and API examples modal
Alessandro36c2e3d6b8f9
diff --git a/webui/components/settings/external/api-examples.html b/webui/components/settings/external/api-examples.htmlindex 8c577ffcf..814a992c3 100644--- a/webui/components/settings/external/api-examples.html+++ b/webui/components/settings/external/api-examples.html@@ -5,7 +5,11 @@</head><body>- <div x-data>+ <div+ x-data+ x-init="window.initExternalApiExamples && window.initExternalApiExamples($el)"+ x-destroy="window.destroyExternalApiExamples && window.destroyExternalApiExamples($el)"+ ><p>Agent Zero provides external API endpoints for integration with other applications.</p><p>These endpoints use API key authentication and support text messages and file attachments.</p>@@ -193,7 +197,51 @@<script type="module">import * as API from "/js/api.js";- setTimeout(async () => {+ const mountedEditors = new WeakMap();++ function scheduleEditorResize(root, editors) {+ const state = {+ editors,+ frameId: null,+ timeoutIds: [],+ };+ const resize = () => {+ if (mountedEditors.get(root) !== state) return;+ editors.forEach((editor) => editor.resize(true));+ };+ state.frameId = requestAnimationFrame(() => {+ state.frameId = null;+ resize();+ state.timeoutIds = [+ setTimeout(resize, 80),+ setTimeout(resize, 240),+ ];+ });+ mountedEditors.set(root, state);+ }++ function destroyEditors(root) {+ const state = mountedEditors.get(root);+ if (!state) return;++ if (state.frameId) {+ cancelAnimationFrame(state.frameId);+ }+ state.timeoutIds.forEach((timeoutId) => clearTimeout(timeoutId));++ state.editors.forEach((editor) => {+ try {+ editor.destroy();+ editor.container.removeAttribute("data-ace-editor-id");+ editor.container.textContent = "";+ } catch (error) {+ console.warn("Failed to destroy API example editor:", error);+ }+ });+ mountedEditors.delete(root);+ }++ async function buildExamples() {const url = window.location.origin;// Fetch token from settings API@@ -670,8 +718,7 @@ async function sendMessageWithProject() {// Call the functionsendMessageWithProject();`;- // Initialize ACE editors- const editors = [+ return [{ id: "api-basic-example", content: basicExample },{ id: "api-continuation-example", content: continuationExample },{ id: "api-attachment-example", content: attachmentExample },@@ -682,9 +729,25 @@ sendMessageWithProject();`;{ id: "api-reset-example", content: resetExample },{ id: "api-files-get-example", content: filesGetExample }];+ }++ window.destroyExternalApiExamples = destroyEditors;++ window.initExternalApiExamples = async (root) => {+ if (!root || !window.ace) return;- editors.forEach(({ id, content }) => {- const editor = ace.edit(id);+ destroyEditors(root);+ const examples = await buildExamples();+ if (!root.isConnected) return;++ const editors = [];++ examples.forEach(({ id, content }) => {+ const container = root.querySelector(`#${id}`);+ if (!container) return;+ container.textContent = "";++ const editor = ace.edit(container);const dark = localStorage.getItem("darkMode");if (dark != "false") {editor.setTheme("ace/theme/github_dark");@@ -692,11 +755,15 @@ sendMessageWithProject();`;editor.setTheme("ace/theme/tomorrow");}editor.session.setMode("ace/mode/javascript");- editor.setValue(content);- editor.clearSelection();+ editor.setValue(content, -1);editor.setReadOnly(true);+ editor.renderer.setShowGutter(true);+ editor.renderer.setPadding(8);+ editors.push(editor);});- }, 0);++ scheduleEditorResize(root, editors);+ };</script></div>diff --git a/webui/components/settings/settings-store.js b/webui/components/settings/settings-store.jsindex d05976720..2f1f28193 100644--- a/webui/components/settings/settings-store.js+++ b/webui/components/settings/settings-store.js@@ -6,6 +6,8 @@ import { store as notificationStore } from "/components/notifications/notificaticonst VIEW_MODE_STORAGE_KEY = "settingsActiveTab";const DEFAULT_TAB = "agent";const UPDATE_STATUS_REFRESH_COOLDOWN_MS = 60 * 1000;+// Match the modal header/padding breathing room before promoting a section link.+const SECTION_ACTIVATION_OFFSET = 56;const TAB_ITEMS = Object.freeze([{@@ -93,7 +95,10 @@ const model = {settings: null,additional: null,workdirFileStructureTestOutput: "",- navMode: "categories",+ _activeSection: null,+ _paneScrollHandler: null,+ _paneScrollPane: null,+ _scrollSyncFrame: null,_updateStatusRefreshedAt: 0,// Tab state@@ -103,8 +108,12 @@ const model = {},set activeTab(value) {const previous = this._activeTab;- this._activeTab = value;- this.applyActiveTab(previous, value);+ this._activeTab = this.normalizeTabId(value);+ this.applyActiveTab(previous, this._activeTab);+ },++ get activeSection() {+ return this._activeSection || this.getFirstSectionId(this.activeTab);},// Lifecycle@@ -112,8 +121,9 @@ const model = {// Restore persisted tabtry {const saved = localStorage.getItem(VIEW_MODE_STORAGE_KEY);- if (saved) this._activeTab = saved;+ if (saved) this._activeTab = this.normalizeTabId(saved);} catch {}+ this._activeSection = this.getFirstSectionId(this._activeTab);},async onOpen() {@@ -138,30 +148,51 @@ const model = {this.refreshUpdateStatus();+ const hashSectionId = this.getHashSectionId();+ const openedHashSection = hashSectionId+ ? this.activateSection(hashSectionId, { persist: false })+ : false;+// Trigger tab activation for current tab+ this._activeTab = this.normalizeTabId(this._activeTab);this.applyActiveTab(null, this._activeTab);+ this.bindPaneScroll();++ if (openedHashSection) {+ this.scrollToSection(hashSectionId);+ }},cleanup() {+ this.unbindPaneScroll();this.settings = null;this.additional = null;this.error = null;this.isLoading = false;- this.navMode = "categories";},// Tab managementapplyActiveTab(previous, current) {+ if (!this.sectionBelongsToTab(this._activeSection, current)) {+ this._activeSection = this.getFirstSectionId(current);+ }+// Persisttry {localStorage.setItem(VIEW_MODE_STORAGE_KEY, current);} catch {}++ this.bindPaneScroll();},switchTab(tabName) {this.activeTab = tabName;},+ normalizeTabId(tabName) {+ return TAB_ITEMS.some((item) => item.id === tabName) ? tabName : DEFAULT_TAB;+ },+get navItems() {return TAB_ITEMS;},@@ -174,21 +205,62 @@ const model = {return this.activeTabItem?.sections || [];},+ getFirstSectionId(tabName = this.activeTab) {+ const tab = TAB_ITEMS.find((item) => item.id === tabName) || TAB_ITEMS[0];+ return tab?.sections?.[0]?.id || null;+ },++ getTabIdForSection(sectionId) {+ if (!sectionId) return null;+ const tab = TAB_ITEMS.find((item) =>+ item.sections?.some((section) => section.id === sectionId)+ );+ return tab?.id || null;+ },++ sectionBelongsToTab(sectionId, tabName = this.activeTab) {+ if (!sectionId) return false;+ return this.getTabIdForSection(sectionId) === tabName;+ },++ getHashSectionId() {+ const rawHash = window.location.hash || "";+ if (!rawHash.startsWith("#section-")) return null;+ try {+ return decodeURIComponent(rawHash.slice(1));+ } catch {+ return rawHash.slice(1);+ }+ },++ activateSection(sectionId, { persist = true } = {}) {+ const tabId = this.getTabIdForSection(sectionId);+ if (!tabId) return false;++ const previous = this._activeTab;+ this._activeTab = tabId;+ this._activeSection = sectionId;+ if (persist) {+ this.applyActiveTab(previous, tabId);+ }+ if (tabId === "backup") this.refreshUpdateStatus();+ return true;+ },+enterTab(tabName) {this.activeTab = tabName;- this.navMode = "sections";+ this._activeSection = this.getFirstSectionId(this.activeTab);this.resetPaneScroll();if (tabName === "backup") this.refreshUpdateStatus();},- backToCategories() {- this.navMode = "categories";- },-resetPaneScroll() {requestAnimationFrame(() => {const pane = this.getSettingsPane();- if (pane) pane.scrollTop = 0;+ if (pane) {+ pane.scrollTop = 0;+ this.updateActiveSectionFromScroll();+ }});},@@ -196,6 +268,57 @@ const model = {return document.querySelector(".modal-inner.settings-modal .settings-pane");},+ bindPaneScroll() {+ requestAnimationFrame(() => {+ const pane = this.getSettingsPane();+ if (!pane || this._paneScrollPane === pane) {+ if (pane) this.updateActiveSectionFromScroll();+ return;+ }++ this.unbindPaneScroll();+ this._paneScrollPane = pane;+ this._paneScrollHandler = () => this.updateActiveSectionFromScroll();+ pane.addEventListener("scroll", this._paneScrollHandler, { passive: true });+ this.updateActiveSectionFromScroll();+ });+ },++ unbindPaneScroll() {+ if (this._paneScrollPane && this._paneScrollHandler) {+ this._paneScrollPane.removeEventListener("scroll", this._paneScrollHandler);+ }+ if (this._scrollSyncFrame) {+ cancelAnimationFrame(this._scrollSyncFrame);+ }+ this._paneScrollPane = null;+ this._paneScrollHandler = null;+ this._scrollSyncFrame = null;+ },++ updateActiveSectionFromScroll() {+ if (this._scrollSyncFrame) return;+ this._scrollSyncFrame = requestAnimationFrame(() => {+ this._scrollSyncFrame = null;+ const pane = this.getSettingsPane();+ if (!pane) return;++ const paneRect = pane.getBoundingClientRect();+ const activationTop = paneRect.top + SECTION_ACTIVATION_OFFSET;+ let activeId = this.getFirstSectionId(this.activeTab);++ for (const section of this.sectionItems) {+ const target = this.getSectionTarget(section.id, pane);+ if (!target || target.offsetParent === null) continue;+ if (target.getBoundingClientRect().top <= activationTop) {+ activeId = section.id;+ }+ }++ this._activeSection = activeId;+ });+ },+get selfUpdate() {return globalThis.Alpine?.store?.("selfUpdateStore") || null;},@@ -210,7 +333,9 @@ const model = {scrollToSection(sectionId, event = null) {event?.preventDefault?.();- this.navMode = "sections";+ if (!this.activateSection(sectionId)) {+ this._activeSection = sectionId;+ }const performScroll = () => {const pane = this.getSettingsPane();@@ -231,6 +356,7 @@ const model = {behavior: "smooth",});history.replaceState(null, "", `#${sectionId}`);+ this.updateActiveSectionFromScroll();};requestAnimationFrame(() => requestAnimationFrame(performScroll));diff --git a/webui/components/settings/settings.html b/webui/components/settings/settings.htmlindex ac6b74d51..fde99bf38 100644--- a/webui/components/settings/settings.html+++ b/webui/components/settings/settings.html@@ -29,45 +29,52 @@<div x-show="$store.settings.settings" class="settings-content"><!-- Tab Navigation --><aside class="settings-tabs-container" aria-label="Settings categories">- <div class="settings-tabs no-scrollbar" role="tablist" aria-orientation="vertical" x-show="$store.settings.navMode === 'categories'">+ <div class="settings-tabs no-scrollbar" role="tablist" aria-orientation="vertical"><template x-for="item in $store.settings.navItems" :key="item.id">- <button type="button"- class="settings-tab"- role="tab"- :aria-selected="$store.settings.activeTab === item.id"- :class="{- 'active': $store.settings.activeTab === item.id,- 'settings-tab-attention': $store.settings.navItemHasAttention(item)- }"- @click="$store.settings.enterTab(item.id)">- <span class="material-symbols-outlined" aria-hidden="true" x-text="item.icon"></span>- <span class="settings-tab-label" x-text="item.label"></span>- <span class="settings-attention-dot"- x-show="$store.settings.navItemHasAttention(item)"- aria-hidden="true"></span>- </button>- </template>- </div>+ <div class="settings-nav-group"+ :class="{'settings-nav-group-active': $store.settings.activeTab === item.id}">+ <button type="button"+ class="settings-tab settings-parent-tab"+ role="tab"+ :aria-selected="$store.settings.activeTab === item.id"+ :aria-expanded="$store.settings.activeTab === item.id"+ :class="{+ 'active': $store.settings.activeTab === item.id,+ 'settings-tab-attention': $store.settings.navItemHasAttention(item)+ }"+ @click="$store.settings.enterTab(item.id)">+ <span class="material-symbols-outlined" aria-hidden="true" x-text="item.icon"></span>+ <span class="settings-tab-label" x-text="item.label"></span>+ <span class="settings-tab-meta">+ <span class="settings-attention-dot"+ x-show="$store.settings.navItemHasAttention(item)"+ aria-hidden="true"></span>+ <span class="material-symbols-outlined settings-tab-chevron"+ aria-hidden="true">expand_more</span>+ </span>+ </button>- <div class="settings-tabs no-scrollbar settings-section-tabs" x-show="$store.settings.navMode === 'sections'" style="display: none;">- <button type="button"- class="settings-tab settings-back-tab"- @click="$store.settings.backToCategories()">- <span class="material-symbols-outlined" aria-hidden="true">arrow_back</span>- <span class="settings-tab-label">< Back</span>- </button>- <div class="settings-tabs-heading" x-text="$store.settings.activeTabItem?.label || 'Settings'"></div>- <template x-for="item in $store.settings.sectionItems" :key="item.id">- <a class="settings-tab settings-section-link"- :class="{'settings-tab-attention': $store.settings.sectionItemHasAttention(item)}"- :href="`#${item.id}`"- @click="$store.settings.scrollToSection(item.id, $event)">- <span class="material-symbols-outlined" aria-hidden="true" x-text="item.icon"></span>- <span class="settings-tab-label" x-text="item.label"></span>- <span class="settings-attention-dot"- x-show="$store.settings.sectionItemHasAttention(item)"- aria-hidden="true"></span>- </a>+ <div class="settings-section-list"+ x-show="$store.settings.activeTab === item.id"+ x-transition.opacity.duration.120ms>+ <template x-for="section in item.sections" :key="section.id">+ <a class="settings-section-link"+ :class="{+ 'active': $store.settings.activeSection === section.id,+ 'settings-tab-attention': $store.settings.sectionItemHasAttention(section)+ }"+ :aria-current="$store.settings.activeSection === section.id ? 'true' : null"+ :href="`#${section.id}`"+ @click="$store.settings.scrollToSection(section.id, $event)">+ <span class="material-symbols-outlined" aria-hidden="true" x-text="section.icon"></span>+ <span class="settings-tab-label" x-text="section.label"></span>+ <span class="settings-attention-dot"+ x-show="$store.settings.sectionItemHasAttention(section)"+ aria-hidden="true"></span>+ </a>+ </template>+ </div>+ </div></template></div></aside>@@ -118,9 +125,13 @@.settings-loading,.settings-error {display: flex;+ flex: 1 1 auto;align-items: center;justify-content: center;+ align-self: stretch;gap: 0.75rem;+ width: 100%;+ min-height: 0;padding: 2rem;color: var(--color-text-secondary, #999);font-size: 1rem;diff --git a/webui/css/settings.css b/webui/css/settings.cssindex 07e1bde5e..f19ebe5c3 100644--- a/webui/css/settings.css+++ b/webui/css/settings.css@@ -150,8 +150,17 @@ select:disabled {/* Settings modal shell */.modal-inner.settings-modal {+ right: auto;+ bottom: auto;+ z-index: 2;+ display: flex;+ align-items: stretch;+ justify-content: flex-start;width: min(92vw, 1180px);height: min(88vh, 900px);+ padding: 0;+ overflow: hidden;+ background: color-mix(in srgb, var(--color-background) 94%, #000 6%);}.modal-inner.settings-modal .modal-scroll,@@ -209,6 +218,13 @@ select:disabled {overflow-y: auto;}+.settings-nav-group {+ display: flex;+ flex-direction: column;+ gap: 3px;+ min-width: 0;+}+.settings-tab {display: grid;grid-template-columns: 22px minmax(0, 1fr) auto;@@ -217,8 +233,8 @@ select:disabled {width: 100%;min-height: 38px;padding: 0 10px;- border: 1px solid transparent;- border-radius: 7px;+ border: 0;+ border-radius: 0;appearance: none;background: transparent;color: var(--color-text);@@ -227,9 +243,27 @@ select:disabled {font-size: 0.83rem;font-weight: 560;line-height: 1.1;+ opacity: 0.68;text-align: left;text-decoration: none;- transition: background-color 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;+ transition: color 0.16s ease, opacity 0.16s ease;+}++.settings-tab-meta {+ display: inline-flex;+ align-items: center;+ justify-content: flex-end;+ gap: 6px;+ min-width: 18px;+}++.settings-tab-chevron {+ transform: rotate(-90deg);+ transition: transform 0.16s ease;+}++.settings-nav-group-active .settings-tab-chevron {+ transform: rotate(0deg);}.settings-tab-label {@@ -239,34 +273,32 @@ select:disabled {white-space: nowrap;}-.settings-tab .material-symbols-outlined {+.settings-tab .material-symbols-outlined,+.settings-section-link .material-symbols-outlined {color: var(--color-text-muted);font-size: 18px;}.settings-tab:hover,-.settings-tab.active {- border-color: color-mix(in srgb, var(--color-primary) 25%, var(--color-border));- background: color-mix(in srgb, var(--color-background-hover) 56%, transparent);+.settings-tab.active,+.settings-section-link:hover,+.settings-section-link.active {opacity: 1;}-.settings-tab.active {+.settings-tab.active,+.settings-section-link.active {color: var(--color-text);font-weight: 750;}-.settings-tab.active .material-symbols-outlined {+.settings-tab.active .material-symbols-outlined,+.settings-section-link.active .material-symbols-outlined {color: var(--color-primary);}.settings-tab-attention {- border-color: color-mix(in srgb, #f2bf4b 42%, var(--color-border));- background: linear-gradient(- 90deg,- color-mix(in srgb, #f2bf4b 13%, transparent),- transparent 62%- );+ opacity: 1;}.settings-tab-attention .material-symbols-outlined {@@ -276,27 +308,49 @@ select:disabled {.settings-attention-dot {width: 7px;height: 7px;+ flex: 0 0 auto;border-radius: 999px;background: #f2bf4b;box-shadow: 0 0 0 3px color-mix(in srgb, #f2bf4b 18%, transparent);}-.settings-back-tab {- margin-bottom: 4px;- color: var(--color-text-muted);-}--.settings-tabs-heading {- margin: 8px 8px 6px;- color: var(--color-primary);- font-size: 0.72rem;- font-weight: 750;- letter-spacing: 0;- text-transform: uppercase;+.settings-section-list {+ display: flex;+ flex-direction: column;+ gap: 2px;+ min-width: 0;+ margin: 0 0 6px 30px;+ padding-left: 10px;+ border-left: 1px solid color-mix(in srgb, var(--color-border) 54%, transparent);}.settings-section-link {+ display: grid;+ grid-template-columns: 20px minmax(0, 1fr) auto;+ align-items: center;+ gap: 7px;+ min-height: 32px;+ padding: 0 9px;+ border: 0;+ border-radius: 0;+ background: transparent;color: var(--color-text);+ font-size: 0.78rem;+ font-weight: 560;+ line-height: 1.12;+ opacity: 0.72;+ text-align: left;+ text-decoration: none;+ transition: color 0.16s ease, opacity 0.16s ease;+}++.settings-section-link .material-symbols-outlined {+ font-size: 17px;+}++.settings-section-link:hover,+.settings-section-link.active {+ opacity: 1;}.settings-pane {@@ -599,25 +653,30 @@ select:disabled {top: 0;z-index: 3;height: auto;+ max-height: min(42vh, 300px);padding: 7px 8px;- overflow-x: auto;+ overflow: hidden;border-right: 0;border-bottom: 1px solid color-mix(in srgb, var(--color-border) 58%, transparent);}.settings-tabs {- flex-direction: row;- width: max-content;+ flex-direction: column;+ width: 100%;min-width: 100%;- overflow-y: hidden;+ overflow-y: auto;}.settings-tab {- width: auto;- min-width: max-content;+ width: 100%;+ min-width: 0;padding: 0 9px;}+ .settings-section-list {+ margin-left: 28px;+ }+.settings-pane {padding: 14px 16px 24px;}diff --git a/webui/js/modals.js b/webui/js/modals.jsindex 5507d6d1d..43bf16013 100644--- a/webui/js/modals.js+++ b/webui/js/modals.js@@ -250,9 +250,10 @@ export async function openModal(modalPath, beforeClose = null) {.then(async (doc) => {// Set the title from the documentmodal.title.innerHTML = doc.title || modalPath;- if (doc.html && doc.html.classList) {+ const htmlElement = doc.documentElement;+ if (htmlElement && htmlElement.classList) {const inner = modal.element.querySelector(".modal-inner");- if (inner) inner.classList.add(...doc.html.classList);+ if (inner) inner.classList.add(...htmlElement.classList);}if (doc.body && doc.body.classList) {modal.body.classList.add(...doc.body.classList);