Skip to content

Agent Zero AI framework

fixing scrolling, markdown, subordinates

frdel0094aff20f4d
diff --git a/webui/components/chat/navigation/chat-navigation-store.js b/webui/components/chat/navigation/chat-navigation-store.js
index aa2745de4..cdfdcaac8 100644
--- a/webui/components/chat/navigation/chat-navigation-store.js
+++ b/webui/components/chat/navigation/chat-navigation-store.js
@@ -40,13 +40,13 @@ const model = {
if (currentIndex > 0) {
// Go to previous message
- positions[currentIndex - 1].el.scrollIntoView({ block: "start" });
+ positions[currentIndex - 1].el.scrollIntoView({ block: "start", behavior: "smooth" });
} else if (currentIndex === 0) {
// At the first message, scroll to top
scroller.scrollTo({ top: 0, behavior: "instant" });
} else if (currentIndex === -1 && positions.length > 0) {
// All messages are above the threshold (scrolled past), scroll to bottom
- positions[positions.length - 1].el.scrollIntoView({ block: "start" });
+ positions[positions.length - 1].el.scrollIntoView({ block: "start", behavior: "smooth" });
}
},
@@ -67,7 +67,7 @@ const model = {
if (targetIndex !== -1) {
// Go to that message
- positions[targetIndex].el.scrollIntoView({ block: "start" });
+ positions[targetIndex].el.scrollIntoView({ block: "start", behavior: "smooth" });
} else {
// No message found below threshold => scroll to bottom
this.scrollToBottom();
diff --git a/webui/components/messages/action-buttons/simple-action-buttons.css b/webui/components/messages/action-buttons/simple-action-buttons.css
index 682ece1a6..a5b197beb 100644
--- a/webui/components/messages/action-buttons/simple-action-buttons.css
+++ b/webui/components/messages/action-buttons/simple-action-buttons.css
@@ -126,26 +126,14 @@
width: 100%;
}
-.code-block-wrapper > .step-action-buttons,
-.message-markdown-table-wrap > .step-action-buttons {
- padding-top: 0;
-}
+
/* ===========================================
Hover behavior - Pointer devices
=========================================== */
-.device-pointer .message-user:hover > .step-action-buttons,
-.device-pointer .message-agent-response:hover > .step-action-buttons,
-.device-pointer .message.message-collapsible.expanded:hover > .step-action-buttons,
-.device-pointer .process-step:hover > .process-step-detail .step-action-buttons {
- opacity: 1;
- pointer-events: auto;
-}
-
-/* Code blocks and tables: show copy button on hover */
-.device-pointer .code-block-wrapper:hover > .step-action-buttons,
-.device-pointer .message-markdown-table-wrap:hover > .step-action-buttons {
+.device-pointer .step-action-buttons:hover,
+.device-pointer :hover > .step-action-buttons {
opacity: 1;
pointer-events: auto;
}
diff --git a/webui/components/messages/process-group/process-group.css b/webui/components/messages/process-group/process-group.css
index 78064ba0f..d576e3e3f 100644
--- a/webui/components/messages/process-group/process-group.css
+++ b/webui/components/messages/process-group/process-group.css
@@ -174,13 +174,19 @@
--step-accent: #b45309;
}
-/* SUB - subagent type (teal) */
+/* SUB and RES - subagent type and response (teal) */
.process-group .SUB {
--step-accent: #14b8a6;
}
.light-mode .process-group .SUB {
--step-accent: #0f766e;
}
+.process-group .RES {
+ --step-accent: #14b8a6;
+}
+.light-mode .process-group .RES {
+ --step-accent: #0f766e;
+}
/* EXE - code_exe type (magenta/purple) */
.process-group .EXE {
diff --git a/webui/components/sidebar/chats/chats-store.js b/webui/components/sidebar/chats/chats-store.js
index 722c8e660..a2f1cdcfa 100644
--- a/webui/components/sidebar/chats/chats-store.js
+++ b/webui/components/sidebar/chats/chats-store.js
@@ -4,7 +4,6 @@ import {
getContext,
setContext,
poll as triggerPoll,
- updateAfterScroll,
toastFetchError,
toast,
justToast,
@@ -57,9 +56,6 @@ const model = {
// Trigger immediate poll
triggerPoll();
-
- // Update scroll
- updateAfterScroll();
},
// Delete a chat
@@ -129,9 +125,7 @@ const model = {
// Increment reset counter
if (typeof globalThis.resetCounter === 'number') {
globalThis.resetCounter = globalThis.resetCounter + 1;
- }
-
- updateAfterScroll();
+ }
} catch (e) {
toastFetchError("Error resetting chat", e);
}
@@ -151,15 +145,6 @@ const model = {
return;
}
-
- // if (globalThis.newContext) {
- // globalThis.newContext();
- // }
- // if (globalThis.updateAfterScroll) {
- // globalThis.updateAfterScroll();
- // }
- // // UX: scroll-to-top
- // requestAnimationFrame(() => this._scrollChatsToTop());
} catch (e) {
toastFetchError("Error creating new chat", e);
}
diff --git a/webui/css/messages.css b/webui/css/messages.css
index abaa20013..695a56aed 100644
--- a/webui/css/messages.css
+++ b/webui/css/messages.css
@@ -244,11 +244,15 @@
color: #24292f;
}
+.message-body .markdown-block-wrap {
+ margin: 1em 0;
+}
+
.message-body .message-markdown-table-wrap {
display: block;
width: 100%;
overflow-x: auto;
- padding-bottom: 1em;
+ /* padding-bottom: 1em; */
}
.message-body .message-markdown-table-wrap table {
@@ -257,6 +261,18 @@
white-space: nowrap;
}
+.message-body .code-block-wrapper{
+ max-width: 100%;
+ overflow-x: auto;
+ padding: 0.5em;
+ border: 1px solid var(--color-border);
+ border-radius: var(--border-radius-sm);
+}
+
+.message-body .code-block-wrapper pre{
+ max-width: 100%;
+}
+
/* .message-body code {
white-space: break-spaces;
} */
@@ -581,7 +597,6 @@
.msg-content table {
width: 100%;
border-collapse: collapse;
- margin: 1em 0;
font-size: 0.98em;
background: transparent;
border-radius: var(--border-radius-sm);
@@ -613,11 +628,11 @@
box-shadow: none;
}
-.msg-content pre:has(code) {
+/* .msg-content pre:has(code) {
padding: 0.5em;
border: 1px solid var(--color-border);
border-radius: var(--border-radius-sm);
-}
+} */
.msg-content hr {
border: 0;
diff --git a/webui/index.js b/webui/index.js
index 0218c072f..0d4bc2b1d 100644
--- a/webui/index.js
+++ b/webui/index.js
@@ -578,28 +578,6 @@ export function toast(text, type = "info", timeout = 5000) {
}
globalThis.toast = toast;
-// OLD: hideToast function removed - now using new notification system
-
-function scrollChanged(isAtBottom) {
- // Reflect scroll state into preferences store; UI is bound via x-model
- preferencesStore.autoScroll = isAtBottom;
-}
-
-export function updateAfterScroll() {
- // const toleranceEm = 1; // Tolerance in em units
- // const tolerancePx = toleranceEm * parseFloat(getComputedStyle(document.documentElement).fontSize); // Convert em to pixels
- // Larger trigger zone near bottom for autoscroll
- const tolerancePx = 80;
- const chatHistory = document.getElementById("chat-history");
- if (!chatHistory) return;
-
- const isAtBottom =
- chatHistory.scrollHeight - chatHistory.scrollTop <=
- chatHistory.clientHeight + tolerancePx;
-
- scrollChanged(isAtBottom);
-}
-globalThis.updateAfterScroll = updateAfterScroll;
import { store as _chatNavigationStore } from "/components/chat/navigation/chat-navigation-store.js";
@@ -650,11 +628,6 @@ document.addEventListener("DOMContentLoaded", function () {
autoScrollSwitch = document.getElementById("auto-scroll-switch");
timeDate = document.getElementById("time-date-container");
- // Sidebar and input event listeners are now handled by their respective stores
-
- if (chatHistory) {
- chatHistory.addEventListener("scroll", updateAfterScroll);
- }
// Start polling for updates
startPolling();
diff --git a/webui/js/messages.js b/webui/js/messages.js
index 2621f9f6d..c8e54d84f 100644
--- a/webui/js/messages.js
+++ b/webui/js/messages.js
@@ -13,10 +13,12 @@ import { store as preferencesStore } from "/components/sidebar/bottom/preference
import { formatDuration } from "./time-utils.js";
// Delay before collapsing previous steps when a new step is added
-const STEP_COLLAPSE_DELAY_MS = 3000;
+const STEP_COLLAPSE_DELAY = {
+ "agent": 2000,
+ "other": 4000, // tools should stay longer as next gen step is placed quickly
+}
+// delay collapse when hovering
const STEP_COLLAPSE_HOVER_DELAY_MS = 5000;
-// Delay before collapsing the last step when processing completes
-const FINAL_STEP_COLLAPSE_DELAY_MS = 3000;
// dom references
let _chatHistory = null;
@@ -72,11 +74,8 @@ export function setMessages(messages) {
const cutoff = isLargeAppend ? Math.max(0, messages.length - 2) : 0;
const massRender = historyEmpty || isLargeAppend;
- let mainScroller;
- if (preferencesStore.autoScroll && history) {
- mainScroller = new Scroller(history, { smooth: !massRender });
- }
-
+ const mainScroller = new Scroller(history, { smooth: !massRender, toleranceRem: 6 });
+
// process messages
for (let i = 0; i < messages.length; i++) {
_massRender = historyEmpty || (isLargeAppend && i < cutoff);
@@ -86,7 +85,7 @@ export function setMessages(messages) {
// reset _massRender flag
_massRender = false;
- if (mainScroller) mainScroller.reApplyScroll();
+ mainScroller.reApplyScroll();
}
// entrypoint called from poll/WS communication, this is how all messages are rendered and updated
@@ -298,9 +297,9 @@ function drawProcessStep({
stepsContainer
.querySelectorAll(".process-step.expanded")
.forEach((expandedStep) => {
- if (expandedStep.id !== stepId) {
- scheduleStepCollapse(expandedStep, STEP_COLLAPSE_DELAY_MS);
- }
+ const delay = STEP_COLLAPSE_DELAY[expandedStep.getAttribute("data-log-type")] || STEP_COLLAPSE_DELAY.other;
+ console.log("collapsing", expandedStep.getAttribute("data-log-type"), delay);
+ scheduleStepCollapse(expandedStep, delay);
});
step.classList.add("expanded");
}
@@ -364,7 +363,7 @@ function drawProcessStep({
// auto-scroller of the step detail
const detailScroller = new Scroller(stepDetailScroll, {
- smooth: !isMassRender(),
+ smooth: !isMassRender(), toleranceRem: 4
}); // scroller for step detail content
// update KVPs of the step detail
@@ -725,15 +724,15 @@ export function drawMessageResponse({
return drawProcessStep({
id,
title,
- // statusClass,
- statusCode: "RSP",
- kvps,
+ code: "RES",
+ kvps: {},
type,
heading,
content,
timestamp,
agentno,
actionButtons,
+ log: arguments[0],
});
}
@@ -769,7 +768,7 @@ export function drawMessageResponse({
markdown: true,
latex: true,
mainClass: "message-agent-response",
- smoothStream: false,// !isMassRender(), // stream smoothly if not in mass render mode
+ smoothStream: false ,// smooth render disabled, not reliable yet !isMassRender(), // stream smoothly if not in mass render mode
});
// Collapsible with action buttons
@@ -1582,6 +1581,7 @@ function adjustMarkdownRender(element) {
const tables = element.querySelectorAll("table");
tables.forEach((el) => {
const wrapper = wrapElement(el, "message-markdown-table-wrap");
+ const outerWrapper = wrapElement(wrapper, "markdown-block-wrap");
const actionsDiv = document.createElement("div");
actionsDiv.className = "step-action-buttons";
actionsDiv.appendChild(
@@ -1589,7 +1589,7 @@ function adjustMarkdownRender(element) {
copyToClipboard(extractTableTSV(el)),
),
);
- wrapper.appendChild(actionsDiv);
+ outerWrapper.appendChild(actionsDiv);
});
// find all code blocks
@@ -1597,12 +1597,13 @@ function adjustMarkdownRender(element) {
codeElements.forEach((code) => {
const pre = code.parentNode;
const wrapper = wrapElement(pre, "code-block-wrapper");
+ const outerWrapper = wrapElement(wrapper, "markdown-block-wrap");
const actionsDiv = document.createElement("div");
actionsDiv.className = "step-action-buttons";
actionsDiv.appendChild(
createActionButton("copy", "", () => copyToClipboard(code.textContent)),
);
- wrapper.appendChild(actionsDiv);
+ outerWrapper.appendChild(actionsDiv);
});
// find all images
@@ -1624,22 +1625,64 @@ function adjustMarkdownRender(element) {
}
export class Scroller {
- constructor(element, { smooth = false } = {}) {
+ constructor(element, { smooth = false, toleranceRem = 2 } = {}) {
this.element = element;
this.smooth = smooth;
+ this.tolerance = toleranceRem * parseFloat(getComputedStyle(document.documentElement).fontSize);
this.wasAtBottom = this.isAtBottom();
+ this._scrollListener = null;
}
- isAtBottom(tolerance = 80) {
- const { scrollHeight, clientHeight, scrollTop } = this.element;
- return scrollHeight - scrollTop - clientHeight <= tolerance;
+ _getEffectiveScrollTop() {
+ const scrollingToRaw = this.element?.dataset?.scrollingTo;
+ const scrollingTo = scrollingToRaw == null ? null : Number(scrollingToRaw);
+ if (Number.isFinite(scrollingTo)) return scrollingTo;
+ return this.element.scrollTop;
+ }
+
+ _setScrollingTo(target) {
+ this.element.dataset.scrollingTo = String(target);
+
+ if (this._scrollListener) return;
+
+ this._scrollListener = () => {
+ const current = this.element.scrollTop;
+ const activeTargetRaw = this.element?.dataset?.scrollingTo;
+ const activeTarget = activeTargetRaw == null ? null : Number(activeTargetRaw);
+ if (!Number.isFinite(activeTarget)) {
+ this._clearScrollingTo();
+ return;
+ }
+
+ if (current >= activeTarget - 1) this._clearScrollingTo();
+ };
+
+ this.element.addEventListener("scroll", this._scrollListener, { passive: true });
+ }
+
+ _clearScrollingTo() {
+ delete this.element.dataset.scrollingTo;
+ if (this._scrollListener) {
+ this.element.removeEventListener("scroll", this._scrollListener);
+ this._scrollListener = null;
+ }
+ }
+
+ isAtBottom() {
+ const { scrollHeight, clientHeight } = this.element;
+ const scrollTop = this._getEffectiveScrollTop();
+ return scrollHeight - scrollTop - clientHeight <= this.tolerance;
}
scrollToBottom() {
- const target = this.element.scrollHeight;
- this.smooth
- ? this.element.scrollTo({ top: target, behavior: "smooth" })
- : (this.element.scrollTop = target);
+ const target = Math.max(0, this.element.scrollHeight - this.element.clientHeight);
+ if (this.smooth) {
+ this._setScrollingTo(target);
+ this.element.scrollTo({ top: target, behavior: "smooth" });
+ } else {
+ this._clearScrollingTo();
+ this.element.scrollTop = target;
+ }
}
reApplyScroll() {
@@ -1727,7 +1770,7 @@ function getNestedContainer(parentStep) {
* Schedule a step to collapse after a delay
* Automatically handles cancellation on click and reset on hover
*/
-function scheduleStepCollapse(stepElement, delayMs) {
+function scheduleStepCollapse(stepElement, delayMs=STEP_COLLAPSE_DELAY.other) {
// skip if any existing timeout for this step
if (stepElement.hasAttribute("data-collapse-timeout-id")) return;
// skip already collapsed steps