Agent Zero AI framework
fix autoexpand, generation step info
frdel2edb3e511ac9
diff --git a/python/extensions/before_main_llm_call/_10_log_for_stream.py b/python/extensions/before_main_llm_call/_10_log_for_stream.pyindex fa86e1e18..60063dd5c 100644--- a/python/extensions/before_main_llm_call/_10_log_for_stream.py+++ b/python/extensions/before_main_llm_call/_10_log_for_stream.py@@ -25,4 +25,4 @@ def build_heading(agent, text: str, icon: str = "network_intelligence"):return f"{agent_prefix}{text}"def build_default_heading(agent):- return build_heading(agent, "Generating...")\ No newline at end of file+ return build_heading(agent, "Calling LLM...")\ No newline at end of filediff --git a/python/extensions/reasoning_stream/_10_log_from_stream.py b/python/extensions/reasoning_stream/_10_log_from_stream.pyindex b98da8374..eb954e5a8 100644--- a/python/extensions/reasoning_stream/_10_log_from_stream.py+++ b/python/extensions/reasoning_stream/_10_log_from_stream.py@@ -13,7 +13,7 @@ class LogFromStream(Extension):# thought length indicatorpipes = "|" * math.ceil(math.sqrt(len(text)))- heading = build_heading(self.agent, f"Reasoning.. {pipes}")+ heading = build_heading(self.agent, f"Reasoning... {pipes}")# create log message and store it in loop data temporary paramsif "log_item_generating" not in loop_data.params_temporary:@@ -21,9 +21,10 @@ class LogFromStream(Extension):self.agent.context.log.log(type="agent",heading=heading,+ step="Reasoning..."))# update log messagelog_item = loop_data.params_temporary["log_item_generating"]- log_item.update(heading=heading, reasoning=text)+ log_item.update(heading=heading, reasoning=text, step="Reasoning...")diff --git a/python/extensions/response_stream/_10_log_from_stream.py b/python/extensions/response_stream/_10_log_from_stream.pyindex 308263bbc..d9bb1170d 100644--- a/python/extensions/response_stream/_10_log_from_stream.py+++ b/python/extensions/response_stream/_10_log_from_stream.py@@ -24,7 +24,11 @@ class LogFromStream(Extension):elif "tool_name" in parsed:heading = build_heading(self.agent, f"Using {parsed['tool_name']}") # if the llm skipped headlineelif "thoughts" in parsed:- heading = build_default_heading(self.agent)+ # thought length indicator+ pipes = "|" * math.ceil(math.sqrt(len(text)))+ heading = build_heading(self.agent, f"Thinking... {pipes}")+ else:+ heading = build_heading(self.agent, "Receiving...")# create log message and store it in loop data temporary paramsif "log_item_generating" not in loop_data.params_temporary:@@ -48,12 +52,16 @@ class LogFromStream(Extension):kvps["step"] = f"Using {parsed['tool_name']}..." # using tool XYif parsed["tool_name"]=="code_execution_tool":if "tool_args" in parsed and "runtime" in parsed["tool_args"]:+ pipes = ""+ if "code" in parsed["tool_args"]:+ pipes = "|" * math.ceil(math.sqrt(len(parsed["tool_args"]["code"])))+ kvps["step"] = f"Writing code... {pipes}"if parsed["tool_args"]["runtime"] == "python":- kvps["step"] = "Writing Python code..."+ kvps["step"] = f"Writing Python code... {pipes}"elif parsed["tool_args"]["runtime"] == "nodejs":- kvps["step"] = "Writing Node.js code..."+ kvps["step"] = f"Writing Node.js code... {pipes}"elif parsed["tool_args"]["runtime"] == "terminal":- kvps["step"] = "Writing terminal command..."+ kvps["step"] = f"Writing terminal command... {pipes}"kvps.update(parsed)diff --git a/webui/index.js b/webui/index.jsindex 791e19248..33af35610 100644--- a/webui/index.js+++ b/webui/index.js@@ -11,7 +11,6 @@ import { store as chatsStore } from "/components/sidebar/chats/chats-store.js";import { store as tasksStore } from "/components/sidebar/tasks/tasks-store.js";import { store as chatTopStore } from "/components/chat/top-section/chat-top-store.js";import { store as _tooltipsStore } from "/components/tooltips/tooltip-store.js";-import { applyModeSteps } from "/components/messages/process-group/process-group-dom.js";globalThis.fetchApi = api.fetchApi; // TODO - backward compatibility for non-modular scripts, remove once refactored to alpine@@ -320,7 +319,6 @@ export async function poll() {updated = true;setMessages(response.logs);afterMessagesUpdate(response.logs);- applyModeSteps(preferencesStore.detailMode, preferencesStore.showUtils);}lastLogVersion = response.log_version;diff --git a/webui/js/messages.js b/webui/js/messages.jsindex 401ed57d4..baa01f500 100644--- a/webui/js/messages.js+++ b/webui/js/messages.js@@ -4,7 +4,10 @@ import { marked } from "../vendor/marked/marked.esm.js";import { store as _messageResizeStore } from "/components/messages/resize/message-resize-store.js"; // keep here, required in htmlimport { store as attachmentsStore } from "/components/chat/attachments/attachmentsStore.js";import { store as speechStore } from "/components/chat/speech/speech-store.js";-import { createActionButton, copyToClipboard } from "/components/messages/action-buttons/simple-action-buttons.js";+import {+ createActionButton,+ copyToClipboard,+} from "/components/messages/action-buttons/simple-action-buttons.js";import { store as stepDetailStore } from "/components/modals/process-step-detail/step-detail-store.js";import { store as preferencesStore } from "/components/sidebar/bottom/preferences/preferences-store.js";import { formatDuration } from "./time-utils.js";@@ -63,10 +66,8 @@ export function getMessageHandler(type) {*/function setActiveProcessGroup(group) {// if (!group) return;-// // Already active? Nothing to do// if (group.classList.contains("active")) return;-// // Clear active + shiny from all other groups// getChatHistoryEl()// .querySelectorAll(".process-group.active")@@ -78,7 +79,6 @@ function setActiveProcessGroup(group) {// );// }// });-// // Mark this group as active// group.classList.add("active");}@@ -288,25 +288,6 @@ function buildDetailPayload(stepData, extras = {}) {};}-function buildStepCopyContent(stepData) {- if (!stepData) return "";- const parts = [];- if (stepData.heading) parts.push(stepData.heading);- if (stepData.content) parts.push(stepData.content);- if (stepData.kvps) {- for (const [key, value] of Object.entries(stepData.kvps)) {- if (key === "reasoning" || key === "finished" || key === "attachments")- continue;- const valStr =- typeof value === "object"- ? JSON.stringify(value, null, 2)- : String(value);- parts.push(`${key}: ${valStr}`);- }- }- return parts.join("\n\n");-}-function drawProcessStep({id,title,@@ -371,16 +352,19 @@ function drawProcessStep({if (detailMode === "expanded") {step.classList.add("expanded");// expand current step and schedule collapse of previous- } else if (detailMode === "current" && !isMassRender() && !isGroupComplete) {- step.classList.add("expanded");- const allExpandedSteps = stepsContainer.querySelectorAll(- ".process-step.expanded",- );- allExpandedSteps.forEach((expandedStep) => {- if (expandedStep.id !== stepId) {+ } else if (+ detailMode === "current" &&+ !isMassRender() &&+ !isGroupComplete+ ) {+ stepsContainer+ .querySelectorAll(".process-step.expanded")+ .forEach((expandedStep) => {+ if (expandedStep.id !== stepId) {scheduleStepCollapse(expandedStep, STEP_COLLAPSE_DELAY_MS);}});+ step.classList.add("expanded");}}@@ -463,7 +447,6 @@ function drawProcessStep({// reapply scroll position (autoscroll if bottom) - only when expanded already and not mass renderingif (isExpanded && !isMassRender()) detailScroller.reApplyScroll();-// Render action buttons: get/create container, clear, appendconst stepActionBtns = ensureChild(stepDetail,@@ -477,15 +460,16 @@ function drawProcessStep({.filter(Boolean).forEach((button) => stepActionBtns.appendChild(button));-// update the process grop header by this stepupdateProcessGroupHeader(group);// remove shine from previous steps and add to this one if new and not completedif (isNewStep && !isGroupComplete) {- stepDetailScroll.querySelectorAll(".step-title.shiny-text").forEach((el) => {- el.classList.remove("shiny-text");- });+ stepDetailScroll+ .querySelectorAll(".step-title.shiny-text")+ .forEach((el) => {+ el.classList.remove("shiny-text");+ });titleEl.classList.add("shiny-text");}@@ -516,7 +500,6 @@ function drawStandaloneMessage({kvps = null,actionButtons = [],}) {-const container = getOrCreateMessageContainer(id,position,@@ -538,17 +521,29 @@ function drawStandaloneMessage({// Collapsible: show ~10 lines with fade, expand button reveals full contentmessageDiv.classList.add("message-collapsible");- const expandBtn = ensureChild(messageDiv, ".expand-btn", "button", "expand-btn");- expandBtn.textContent = messageDiv.classList.contains("expanded") ? "Show less" : "Show more";+ const expandBtn = ensureChild(+ messageDiv,+ ".expand-btn",+ "button",+ "expand-btn",+ );+ expandBtn.textContent = messageDiv.classList.contains("expanded")+ ? "Show less"+ : "Show more";expandBtn.onclick = () => {messageDiv.classList.toggle("expanded");- expandBtn.textContent = messageDiv.classList.contains("expanded") ? "Show less" : "Show more";+ expandBtn.textContent = messageDiv.classList.contains("expanded")+ ? "Show less"+ : "Show more";};// Detect overflow after render - CSS handles visibility based on .has-overflow classrequestAnimationFrame(() => {const body = messageDiv.querySelector(".message-body");- messageDiv.classList.toggle("has-overflow", body.scrollHeight > body.clientHeight);+ messageDiv.classList.toggle(+ "has-overflow",+ body.scrollHeight > body.clientHeight,+ );});// Render action buttons: get/create container, clear, append@@ -772,7 +767,9 @@ export function drawMessageAgent({const actionButtons = thoughtsText.trim()? [createActionButton("detail", "", () =>- stepDetailStore.showStepDetail(buildDetailPayload(arguments[0], { headerLabels })),+ stepDetailStore.showStepDetail(+ buildDetailPayload(arguments[0], { headerLabels }),+ ),),createActionButton("speak", "", () => speechStore.speak(thoughtsText)),createActionButton("copy", "", () => copyToClipboard(thoughtsText)),@@ -832,14 +829,18 @@ export function drawMessageResponse({const group = getLastProcessGroup();let container = null;- if (group)+ if (group) {container = ensureChild(group,".process-group-response","div","process-group-response",);- else container = getOrCreateMessageContainer(id, "left");+ //collapse all steps when response is ready+ group.querySelectorAll(".process-step").forEach((step) => {+ scheduleStepCollapse(step);+ });+ } else container = getOrCreateMessageContainer(id, "left");const messageDiv = _drawMessage({messageContainer: container,@@ -856,17 +857,29 @@ export function drawMessageResponse({// Collapsible: show ~10 lines with fade, expand button reveals full contentmessageDiv.classList.add("message-collapsible");- const expandBtn = ensureChild(messageDiv, ".expand-btn", "button", "expand-btn");- expandBtn.textContent = messageDiv.classList.contains("expanded") ? "Show less" : "Show more";+ const expandBtn = ensureChild(+ messageDiv,+ ".expand-btn",+ "button",+ "expand-btn",+ );+ expandBtn.textContent = messageDiv.classList.contains("expanded")+ ? "Show less"+ : "Show more";expandBtn.onclick = () => {messageDiv.classList.toggle("expanded");- expandBtn.textContent = messageDiv.classList.contains("expanded") ? "Show less" : "Show more";+ expandBtn.textContent = messageDiv.classList.contains("expanded")+ ? "Show less"+ : "Show more";};// Detect overflow after render - CSS handles visibility based on .has-overflow classrequestAnimationFrame(() => {const body = messageDiv.querySelector(".message-body");- messageDiv.classList.toggle("has-overflow", body.scrollHeight > body.clientHeight);+ messageDiv.classList.toggle(+ "has-overflow",+ body.scrollHeight > body.clientHeight,+ );});// Render action buttons: get/create container, clear, append@@ -1048,7 +1061,9 @@ export function drawMessageTool({const actionButtons = contentText.trim()? [createActionButton("detail", "", () =>- stepDetailStore.showStepDetail(buildDetailPayload(arguments[0], { headerLabels })),+ stepDetailStore.showStepDetail(+ buildDetailPayload(arguments[0], { headerLabels }),+ ),),createActionButton("speak", "", () => speechStore.speak(contentText)),createActionButton("copy", "", () => copyToClipboard(contentText)),@@ -1080,10 +1095,7 @@ export function drawMessageCodeExe({}) {let title = "Code Execution";// show command at the start and end- if (- kvps?.code &&- /done_all|code_execution_tool/.test(heading || "")- ) {+ if (kvps?.code && /done_all|code_execution_tool/.test(heading || "")) {const s = kvps.session ?? kvps.Session;title = `${s != null ? `[${s}] ` : ""}${kvps.runtime || "bash"}> ${kvps.code.trim()}`;} else {@@ -1098,7 +1110,10 @@ export function drawMessageCodeExe({const headerLabels = [kvps?.runtime && { label: kvps.runtime, class: "tool-name-badge" },- kvps?.session != null && { label: `Session ${kvps.session}`, class: "header-label" },+ kvps?.session != null && {+ label: `Session ${kvps.session}`,+ class: "header-label",+ },].filter(Boolean);// render the standard step@@ -1106,7 +1121,9 @@ export function drawMessageCodeExe({const outputText = String(content ?? "");const actionButtons = [createActionButton("detail", "", () =>- stepDetailStore.showStepDetail(buildDetailPayload(arguments[0], { headerLabels })),+ stepDetailStore.showStepDetail(+ buildDetailPayload(arguments[0], { headerLabels }),+ ),),commandText.trim()? createActionButton("copy", "Command", () =>@@ -1146,7 +1163,9 @@ export function drawMessageBrowser({const actionButtons = answerText.trim()? [createActionButton("detail", "", () =>- stepDetailStore.showStepDetail(buildDetailPayload(arguments[0], { headerLabels: [] })),+ stepDetailStore.showStepDetail(+ buildDetailPayload(arguments[0], { headerLabels: [] }),+ ),),createActionButton("speak", "", () => speechStore.speak(answerText)),createActionButton("copy", "", () => copyToClipboard(answerText)),@@ -1185,7 +1204,9 @@ export function drawMessageMcp({const actionButtons = contentText.trim()? [createActionButton("detail", "", () =>- stepDetailStore.showStepDetail(buildDetailPayload(arguments[0], { headerLabels })),+ stepDetailStore.showStepDetail(+ buildDetailPayload(arguments[0], { headerLabels }),+ ),),createActionButton("speak", "", () => speechStore.speak(contentText)),createActionButton("copy", "", () => copyToClipboard(contentText)),@@ -1224,7 +1245,9 @@ export function drawMessageSubagent({const actionButtons = contentText.trim()? [createActionButton("detail", "", () =>- stepDetailStore.showStepDetail(buildDetailPayload(arguments[0], { headerLabels })),+ stepDetailStore.showStepDetail(+ buildDetailPayload(arguments[0], { headerLabels }),+ ),),createActionButton("speak", "", () => speechStore.speak(contentText)),createActionButton("copy", "", () => copyToClipboard(contentText)),@@ -1418,7 +1441,9 @@ export function drawMessageError({const contentText = String(content ?? "");const actionButtons = [createActionButton("detail", "", () =>- stepDetailStore.showStepDetail(buildDetailPayload(arguments[0], { headerLabels: [] })),+ stepDetailStore.showStepDetail(+ buildDetailPayload(arguments[0], { headerLabels: [] }),+ ),),contentText.trim()? createActionButton("copy", "", () => copyToClipboard(contentText))@@ -1437,7 +1462,6 @@ export function drawMessageError({});}-function drawKvpsIncremental(container, kvps, latex) {// existing KVPS tablelet table = container.querySelector(".msg-kvps");@@ -1664,7 +1688,9 @@ const extractTableTSV = (table) =>[...table.rows].map((row) =>[...row.cells]- .map((cell) => cell.textContent.replace(/\t/g, " ").replace(/\n/g, " "))+ .map((cell) =>+ cell.textContent.replace(/\t/g, " ").replace(/\n/g, " "),+ ).join("\t"),).join("\n");@@ -1677,7 +1703,9 @@ function adjustMarkdownRender(element) {const actionsDiv = document.createElement("div");actionsDiv.className = "step-action-buttons";actionsDiv.appendChild(- createActionButton("copy", "", () => copyToClipboard(extractTableTSV(el)))+ createActionButton("copy", "", () =>+ copyToClipboard(extractTableTSV(el)),+ ),);wrapper.appendChild(actionsDiv);});@@ -1690,7 +1718,7 @@ function adjustMarkdownRender(element) {const actionsDiv = document.createElement("div");actionsDiv.className = "step-action-buttons";actionsDiv.appendChild(- createActionButton("copy", "", () => copyToClipboard(code.textContent))+ createActionButton("copy", "", () => copyToClipboard(code.textContent)),);wrapper.appendChild(actionsDiv);});@@ -1728,7 +1756,8 @@ export class Scroller {}reApplyScroll() {- if (this.wasAtBottom && !this.isAtBottom()) this.element.scrollTop = this.element.scrollHeight;+ if (this.wasAtBottom && !this.isAtBottom())+ this.element.scrollTop = this.element.scrollHeight;}}@@ -1905,7 +1934,6 @@ function findParentDelegationStep(group, agentno) {* Get a concise title for a process step*/function getStepTitle(heading, kvps, type) {-// Try to get a meaningful title from heading or kvpsif (heading && heading.trim()) {return cleanStepTitle(heading, 100);@@ -1966,7 +1994,6 @@ function cleanStepTitle(text, maxLength = 100) {return truncateText(cleaned, maxLength);}-/*** Update process group header with step count, status, and metrics*/@@ -2013,7 +2040,6 @@ function updateProcessGroupHeader(group) {const code = lastStep.getAttribute("data-step-code");badgeEl.outerHTML = `<span class="step-badge ${code}">${code}</span>`;}-}// Update step count in metrics - All GEN steps from all agents per process group@@ -2084,8 +2110,6 @@ function updateProcessGroupHeader(group) {notificationsEl.hidden = true;}}--}function isProcessGroupComplete(group) {@@ -2106,62 +2130,62 @@ function truncateText(text, maxLength) {/*** Mark a process group as complete (END state)*/-function markProcessGroupComplete(group, responseTitle) {- if (!group) return;-- // // Update status badge to END- // const statusEl = group.querySelector(".group-status");- // if (statusEl) {- // // statusEl.innerHTML = '<span class="badge-icon material-symbols-outlined">check</span>END';- // statusEl.innerHTML = "END";- // statusEl.className = "step-badge status-end group-status";- // }-- // // Update title if response title is available- // const titleEl = group.querySelector(".group-title");- // if (titleEl && responseTitle) {- // const cleanTitle = cleanStepTitle(responseTitle, 50);- // if (cleanTitle) {- // titleEl.textContent = cleanTitle;- // }- // }-- // Add completed class to group- group.classList.add("process-group-completed");-- // Collapse all expanded steps when processing is done (in "current" mode) with delay- const detailMode = preferencesStore.detailMode;- if (detailMode === "current") {- // Schedule collapse for all expanded steps (deterministic)- const allExpandedSteps = group.querySelectorAll(- ".process-step.expanded",- );- allExpandedSteps.forEach((expandedStep) => {- scheduleStepCollapse(expandedStep, FINAL_STEP_COLLAPSE_DELAY_MS);- });- }+// function markProcessGroupComplete(group, responseTitle) {+// if (!group) return;++// // Update status badge to END+// const statusEl = group.querySelector(".group-status");+// if (statusEl) {+// // statusEl.innerHTML = '<span class="badge-icon material-symbols-outlined">check</span>END';+// statusEl.innerHTML = "END";+// statusEl.className = "step-badge status-end group-status";+// }- // Calculate final duration from backend data (difference between first and last timestamps)- const steps = group.querySelectorAll(".process-step");- const firstTimestampMs = parseInt(- steps[0]?.getAttribute("data-timestamp") || "0",- 10,- );- const lastTimestampMs = parseInt(- steps[steps.length - 1]?.getAttribute("data-timestamp") || "0",- 10,- );- const totalDurationMs = Math.max(0, lastTimestampMs - firstTimestampMs);+// // Update title if response title is available+// const titleEl = group.querySelector(".group-title");+// if (titleEl && responseTitle) {+// const cleanTitle = cleanStepTitle(responseTitle, 50);+// if (cleanTitle) {+// titleEl.textContent = cleanTitle;+// }+// }- // Update duration metric with final value from backend- const metricsEl = group.querySelector(".group-metrics");- const durationMetricEl = metricsEl?.querySelector(- ".metric-duration .metric-value",- );- if (durationMetricEl && totalDurationMs > 0) {- durationMetricEl.textContent = formatDuration(totalDurationMs);- }-}+// // Add completed class to group+// group.classList.add("process-group-completed");++// // Collapse all expanded steps when processing is done (in "current" mode) with delay+// const detailMode = preferencesStore.detailMode;+// if (detailMode === "current") {+// // Schedule collapse for all expanded steps (deterministic)+// const allExpandedSteps = group.querySelectorAll(+// ".process-step.expanded",+// );+// allExpandedSteps.forEach((expandedStep) => {+// scheduleStepCollapse(expandedStep, FINAL_STEP_COLLAPSE_DELAY_MS);+// });+// }++// // Calculate final duration from backend data (difference between first and last timestamps)+// const steps = group.querySelectorAll(".process-step");+// const firstTimestampMs = parseInt(+// steps[0]?.getAttribute("data-timestamp") || "0",+// 10,+// );+// const lastTimestampMs = parseInt(+// steps[steps.length - 1]?.getAttribute("data-timestamp") || "0",+// 10,+// );+// const totalDurationMs = Math.max(0, lastTimestampMs - firstTimestampMs);++// // Update duration metric with final value from backend+// const metricsEl = group.querySelector(".group-metrics");+// const durationMetricEl = metricsEl?.querySelector(+// ".metric-duration .metric-value",+// );+// if (durationMetricEl && totalDurationMs > 0) {+// durationMetricEl.textContent = formatDuration(totalDurationMs);+// }+// }// gets or creates a child DOM elementfunction ensureChild(parent, selector, tagName, ...classNames) {