Agent Zero AI framework
active groups use DOM; mode bugfix
3clyp502c8eeda6b4ca
diff --git a/webui/components/messages/process-group/process-group-store.js b/webui/components/messages/process-group/process-group-store.jsindex 5905ad045..ad940513a 100644--- a/webui/components/messages/process-group/process-group-store.js+++ b/webui/components/messages/process-group/process-group-store.js@@ -40,84 +40,20 @@ const DISPLAY_CODES = {};const model = {- // Default collapsed state for new process groups- defaultCollapsed: true,+ init() {},- init() {- try {- // Load persisted default collapsed state only- const stored = localStorage.getItem("processGroupState");- if (stored) {- const parsed = JSON.parse(stored);- this.defaultCollapsed = parsed.defaultCollapsed ?? true;- }- } catch (e) {- console.error("Failed to load process group state", e);- }- },-- _persist() {- try {- // Only persist the default collapsed preference- // DOM is the source of truth for actual state- localStorage.setItem("processGroupState", JSON.stringify({- defaultCollapsed: this.defaultCollapsed- }));- } catch (e) {- console.error("Failed to persist process group state", e);- }- },-- // Check if a process group is expanded- isGroupExpanded(groupId) {- const groupElement = document.getElementById(groupId);- if (groupElement) {- return groupElement.classList.contains("expanded");- }- return !this.defaultCollapsed;- },-- // Toggle process group expansion+ // Toggle process group expansion (called from click handler in messages.js)toggleGroup(groupId) {const groupElement = document.getElementById(groupId);if (!groupElement) return;-- const currentState = groupElement.classList.contains("expanded");- groupElement.classList.toggle("expanded", !currentState);+ groupElement.classList.toggle("expanded");},- // Expand a specific group- expandGroup(groupId) {- const groupElement = document.getElementById(groupId);- if (groupElement) {- groupElement.classList.add("expanded");- }- },-- // Collapse a specific group- collapseGroup(groupId) {- const groupElement = document.getElementById(groupId);- if (groupElement) {- groupElement.classList.remove("expanded");- }- },-- // Check if a step within a group is expanded- isStepExpanded(groupId, stepId) {- const stepElement = document.getElementById(`process-step-${stepId}`);- if (stepElement) {- return stepElement.classList.contains("step-expanded");- }- return false;- },-- // Toggle step expansion+ // Toggle step expansion (called from click handler in messages.js)toggleStep(groupId, stepId) {const stepElement = document.getElementById(`process-step-${stepId}`);if (!stepElement) return;-- const currentState = stepElement.classList.contains("step-expanded");- stepElement.classList.toggle("step-expanded", !currentState);+ stepElement.classList.toggle("step-expanded");},// Status code (3-4 letter) for backend log types@@ -164,30 +100,15 @@ const model = {return colors[type] || 'status-gen';},- // Clear state for a specific context (when chat is reset)- clearContext(contextPrefix) {- },-// Get current detail mode from preferences_getDetailMode() {return preferencesStore.detailMode || "current";},- shouldExpandGroup(groupId, isActiveAndGenerating = false) {+ shouldExpandGroup() {const mode = this._getDetailMode();- if (mode === "collapsed") {- return false;- }- if (mode === "current" || mode === "expanded") return true;- return !this.defaultCollapsed;- },-- expandStep(groupId, stepId, isActive = false) {- const mode = this._getDetailMode();- if (mode === "collapsed") return false;- if (mode === "expanded") return true;- if (mode === "current") return isActive;- return this.isStepExpanded(groupId, stepId);+ // Groups expand in "current" and "expanded" modes, collapse only in "collapsed" mode+ return mode !== "collapsed";},// Apply current mode to all existing DOM elements@@ -196,15 +117,18 @@ const model = {const showUtils = preferencesStore.showUtils || false;const allGroups = document.querySelectorAll(".process-group");- // Find the last visible step in an active (not completed) group only- const stepSelector = showUtils- ? ".process-group:not(.process-group-completed) .process-step"- : ".process-group:not(.process-group-completed) .process-step:not(.message-util)";- const visibleSteps = document.querySelectorAll(stepSelector);- const lastActiveStep = visibleSteps.length > 0 ? visibleSteps[visibleSteps.length - 1] : null;+ // Find the active group (currently streaming) - DOM is source of truth+ const activeGroup = document.querySelector(".process-group.active");- // Get all steps for applying expansion- const allSteps = document.querySelectorAll(".process-step");+ // Find the last visible step in the ACTIVE group only (for "current" mode)+ let lastActiveStep = null;+ if (activeGroup && !activeGroup.classList.contains("process-group-completed")) {+ const stepSelector = showUtils+ ? ".process-step"+ : ".process-step:not(.message-util)";+ const stepsInActiveGroup = activeGroup.querySelectorAll(stepSelector);+ lastActiveStep = stepsInActiveGroup.length > 0 ? stepsInActiveGroup[stepsInActiveGroup.length - 1] : null;+ }// Apply to groupsallGroups.forEach(group => {@@ -212,27 +136,38 @@ const model = {group.classList.toggle("expanded", shouldExpandGroup);});- // Apply to steps- allSteps.forEach(step => {- let shouldExpand = false;- if (mode === "expanded") {- shouldExpand = true;- } else if (mode === "current") {- // Only expand the last step in an active group- shouldExpand = step === lastActiveStep || step.contains(lastActiveStep);- }+ // Apply to steps - different logic for active vs non-active groups+ allGroups.forEach(group => {+ const isActiveGroup = group.classList.contains("active");+ const steps = group.querySelectorAll(".process-step");- // IMPORTANT: Only EXPAND steps here, never collapse them during streaming.- // Collapsing is handled by the timeout mechanism in messages.js to avoid- // fighting with the scheduled delays. We only force-collapse when mode is "collapsed".- if (shouldExpand) {- step.classList.add("step-expanded");- } else if (mode === "collapsed") {- // In collapsed mode, force all steps closed- step.classList.remove("step-expanded");- step.removeAttribute("data-user-pinned");- }- // In "current" mode: don't remove step-expanded - let timeout handle it+ steps.forEach(step => {+ let shouldExpand = false;++ if (mode === "expanded") {+ shouldExpand = true;+ } else if (mode === "current") {+ if (isActiveGroup) {+ // Active group: only expand the last step+ shouldExpand = step === lastActiveStep;+ }+ // Non-active groups: shouldExpand stays false → all steps collapsed+ }+ // In "collapsed" mode: shouldExpand stays false++ if (shouldExpand) {+ step.classList.add("step-expanded");+ } else {+ // For non-active groups or collapsed mode, immediately collapse+ // Only defer to timeout for active group in "current" mode when there's an active step+ // (lastActiveStep is null if group is completed - no deferral needed)+ const shouldDefer = mode === "current" && isActiveGroup && lastActiveStep && step !== lastActiveStep;+ if (!shouldDefer) {+ step.classList.remove("step-expanded");+ step.removeAttribute("data-user-pinned");+ }+ }+ });});// Apply to error groupsdiff --git a/webui/js/messages.js b/webui/js/messages.jsindex e3ce54397..2db604dd4 100644--- a/webui/js/messages.js+++ b/webui/js/messages.js@@ -25,38 +25,30 @@ const chatHistory = document.getElementById("chat-history");let messageGroup = null;let currentProcessGroup = null; // Track current process group for collapsible UIlet currentDelegationSteps = {}; // Track delegation steps by agent number for nesting-let activeProcessGroupId = null; // Only one process group should show "running" indicators at a time-let activeProcessGroupEl = null;-let activeStepTitleEl = null;--// Expose activeProcessGroupId for store access-window.activeProcessGroupId = null;/**- * Mark current process group as active and clear active badges.+ * Mark a process group as the active one (via .active class)*/function setActiveProcessGroup(group) {- if (!group || !group.id) return;- if (activeProcessGroupId === group.id) return;-- // Clear shiny effect from the previous active step title if we moved to a new group- if (activeStepTitleEl && activeProcessGroupEl && activeProcessGroupEl !== group && activeProcessGroupEl.contains(activeStepTitleEl)) {- activeStepTitleEl.classList.remove("shiny-text");- activeStepTitleEl = null;- }-- activeProcessGroupId = group.id;- activeProcessGroupEl = group;- window.activeProcessGroupId = group.id; // Keep window copy in sync for store access-+ if (!group) return;++ // Already active? Nothing to do+ if (group.classList.contains("active")) return;++ // Clear active + shiny from all other groups+ document.querySelectorAll(".process-group.active").forEach(g => {+ if (g !== group) {+ g.classList.remove("active");+ g.querySelectorAll(".step-title.shiny-text").forEach(el => el.classList.remove("shiny-text"));+ }+ });++ // Mark this group as active+ group.classList.add("active");}export function clearActiveStepShine() {- if (activeStepTitleEl) {- activeStepTitleEl.classList.remove("shiny-text");- activeStepTitleEl = null;- }- // clear any lingering shine in process steps+ // Clear all shiny step titles in process stepsdocument.querySelectorAll(".process-step .step-title.shiny-text").forEach((el) => {el.classList.remove("shiny-text");});@@ -1308,7 +1300,7 @@ function createProcessGroup(id) {group.setAttribute("data-group-id", groupId);// Determine initial expansion state from current detail mode- const initiallyExpanded = processGroupStore.shouldExpandGroup(groupId, true); // true = is active+ const initiallyExpanded = processGroupStore.shouldExpandGroup();if (initiallyExpanded) {group.classList.add('expanded');}@@ -1448,9 +1440,6 @@ function addStepCollapseInteractionHandlers(stepElement) {* Add a step to a process group*/function addProcessStep(group, id, type, heading, content, kvps, timestamp = null, durationMs = null, agentNumber = 0) {- // group with newest step becomes the active one- setActiveProcessGroup(group);-const groupId = group.getAttribute("data-group-id");let stepsContainer = group.querySelector(".process-steps");const isGroupCompleted = group.classList.contains("process-group-completed");@@ -1513,22 +1502,27 @@ function addProcessStep(group, id, type, heading, content, kvps, timestamp = nul// Determine if this new step should be expandedconst detailMode = preferencesStore.detailMode;+ const isActiveGroup = group.classList.contains("active");let shouldExpand = false;if (detailMode === "expanded") {shouldExpand = true;- } else if (detailMode === "current" && !isGroupCompleted) {- // In "current" mode: expand new step, delay-collapse all previous steps- shouldExpand = true;-- // Schedule collapse for ALL previously expanded steps- const allExpandedSteps = stepsContainer.querySelectorAll(".process-step.step-expanded");- allExpandedSteps.forEach(expandedStep => {- // Don't schedule collapse for the newly added step (the current one)- if (expandedStep.id !== `process-step-${id}`) {- scheduleStepCollapse(expandedStep, STEP_COLLAPSE_DELAY_MS);- }- });+ } else if (detailMode === "current") {+ // Only expand and schedule timeouts for the ACTIVE group (currently streaming)+ // For non-active groups (historical data), render steps collapsed immediately+ if (isActiveGroup && !isGroupCompleted) {+ shouldExpand = true;++ // Schedule collapse for ALL previously expanded steps+ const allExpandedSteps = stepsContainer.querySelectorAll(".process-step.step-expanded");+ allExpandedSteps.forEach(expandedStep => {+ // Don't schedule collapse for the newly added step (the current one)+ if (expandedStep.id !== `process-step-${id}`) {+ scheduleStepCollapse(expandedStep, STEP_COLLAPSE_DELAY_MS);+ }+ });+ }+ // Non-active groups: shouldExpand stays false → steps render collapsed}// In "collapsed" mode: shouldExpand stays false@@ -1619,11 +1613,10 @@ function addProcessStep(group, id, type, heading, content, kvps, timestamp = nulstep.classList.add("nested-step");}- // Remove shiny effect from the previously active step title (O(1))- if (activeStepTitleEl) {- activeStepTitleEl.classList.remove("shiny-text");- activeStepTitleEl = null;- }+ // Clear shiny effect from all previous steps in this group+ group.querySelectorAll(".process-step .step-title.shiny-text").forEach(el => {+ el.classList.remove("shiny-text");+ });appendTarget.appendChild(step);@@ -1639,12 +1632,11 @@ function addProcessStep(group, id, type, heading, content, kvps, timestamp = nul// Update group headerupdateProcessGroupHeader(group);- // Apply shiny effect to the active step title- if (!isGroupCompleted && group.id === activeProcessGroupId) {+ // Apply shiny effect to the new step's title if group is still active+ if (!isGroupCompleted) {const titleEl = step.querySelector(".process-step-header .step-title");if (titleEl) {titleEl.classList.add("shiny-text");- activeStepTitleEl = titleEl;}}@@ -2301,13 +2293,9 @@ export function resetProcessGroups() {currentProcessGroup = null;currentDelegationSteps = {};messageGroup = null;- activeProcessGroupId = null;- activeProcessGroupEl = null;- window.activeProcessGroupId = null; // Keep window copy in sync- if (activeStepTitleEl) {- activeStepTitleEl.classList.remove("shiny-text");- }- activeStepTitleEl = null;++ // Clear shiny effect from DOM (source of truth)+ clearActiveStepShine();// Clear all pending collapse timeoutsstepCollapseTimeouts.forEach(timeoutId => clearTimeout(timeoutId));