Skip to content

Agent Zero AI framework

smooth response rendering

frdel25ed7714b08a
diff --git a/webui/css/messages.css b/webui/css/messages.css
index 8d74b0b55..f16826137 100644
--- a/webui/css/messages.css
+++ b/webui/css/messages.css
@@ -11,7 +11,7 @@
overflow-x: hidden;
scroll-behavior: auto !important; /* avoid infinite scrolling! */
padding-left: var(--spacing-sm) !important;
- padding-right: var(--spacing-md) !important;
+ padding-right: var(--spacing-md) !important;
padding-top: 4rem !important;
padding-bottom: 4rem !important;
-webkit-transition: all 0.3s ease;
@@ -109,7 +109,6 @@
color: var(--color-text);
}
-
/* .light-mode .message-user .message-text pre {
color: #2e2e2e;
} */
@@ -430,12 +429,12 @@
width: 100%;
}
-.kvps-val{
+.kvps-val {
font-size: 0.75rem;
}
-.kvps-val p{
- margin:0;
+.kvps-val p {
+ margin: 0;
}
.kvps-val pre {
@@ -519,7 +518,7 @@
text-align: right;
}
-.kvps-key .material-symbols-outlined{
+.kvps-key .material-symbols-outlined {
font-size: var(--font-size-smaller);
}
@@ -542,14 +541,12 @@
width: 100%;
}
-
.msg-content {
margin-bottom: 0;
padding: 0;
overflow: hidden;
}
-
/* Math (KaTeX) */
.katex {
line-height: 1.2 !important;
@@ -573,11 +570,11 @@
@media (max-width: 1024px) {
#chat-history {
- padding-left: var(--spacing-sm) !important;
- padding-right: var(--spacing-md) !important;
- padding-top: 4rem !important;
- padding-bottom: 2rem !important;
-}
+ padding-left: var(--spacing-sm) !important;
+ padding-right: var(--spacing-md) !important;
+ padding-top: 4rem !important;
+ padding-bottom: 3rem !important;
+ }
}
@media (max-width: 640px) {
@@ -700,25 +697,25 @@
margin: 1em 0;
font-size: 0.98em;
background: transparent;
- border-radius: 8px;
+ border-radius: var(--border-radius-sm);
overflow: hidden;
}
.msg-content th,
.msg-content td {
padding: 0.55em 1em;
- border: 1px solid rgba(142, 142, 142, 0.1);
+ border: 1px solid var(--color-border);
text-align: left;
background: transparent;
}
.msg-content th {
font-weight: 600;
- background: rgba(142, 142, 142, 0.1);
+ background: var(--color-table-row);
}
.msg-content tr:nth-child(even) {
- background: rgba(142, 142, 142, 0.1);
+ background: var(--color-table-row);
}
.msg-content tr:nth-child(odd) {
@@ -731,8 +728,8 @@
.msg-content pre:has(code) {
padding: 0.5em;
- border: 1px solid rgba(142, 142, 142, 0.1);
- border-radius: 0.3em;
+ border: 1px solid var(--color-border);
+ border-radius: var(--border-radius-sm);
}
.msg-content hr {
@@ -846,3 +843,40 @@
opacity: 0;
}
+/* Smooth Render */
+.smooth-render-visible,
+.smooth-render-invisible {
+ position: absolute;
+ width:100%;
+ inset: 0;
+ opacity: 0;
+}
+
+.smooth-render-visible {
+ z-index: 2;
+ animation: smoothFadeIn 200ms ease-out forwards;
+}
+
+.smooth-render-invisible {
+ z-index: 1;
+ opacity: 1;
+ animation: smoothFadeOut 70ms ease-out forwards;
+ animation-delay: 100ms;
+}
+
+@keyframes smoothFadeIn {
+ from {
+ opacity: 0;
+ }
+ to {
+ opacity: 1;
+ }
+}
+@keyframes smoothFadeOut {
+ from {
+ opacity: 1;
+ }
+ to {
+ opacity: 0;
+ }
+}
diff --git a/webui/index.css b/webui/index.css
index 2c453324b..e3286b9a3 100644
--- a/webui/index.css
+++ b/webui/index.css
@@ -24,6 +24,7 @@
--color-input-focus-dark: #101010;
--color-chat-background-dark: #212121;
--color-error-text-dark:#e72323;
+ --color-table-row-dark: #272727;
/* Light mode */
--color-background-light: #fafafa;
@@ -39,8 +40,9 @@
--color-border-light: #bdbdbdcf;
--color-input-light: #e4e4e4;
--color-input-focus-light: #dadada;
- --color-chat-background-light: #fafafaf3;
+ --color-chat-background-light: #fafafa;
--color-error-text-light:#920000;
+ --color-table-row-light: #edededf3;
/* Default to dark mode */
@@ -60,6 +62,7 @@
--color-background-hover: color-mix(in srgb, var(--color-border) 50%, transparent);
--color-chat-background: var(--color-chat-background-dark);
--color-error-text:var(--color-error-text-dark);
+ --color-table-row: var(--color-table-row-dark);
/* Spacing variables */
--spacing-xxs: 0.15rem;
@@ -105,7 +108,8 @@
--color-background-hover: color-mix(in srgb, var(--color-border) 50%, transparent);
--color-chat-background: var(--color-chat-background-light);
--color-error-text:var(--color-error-text-light);
- }
+ --color-table-row: var(--color-table-row-light);
+}
/* Reset and Base Styles */
diff --git a/webui/js/messages.js b/webui/js/messages.js
index e38eae143..74faaaebc 100644
--- a/webui/js/messages.js
+++ b/webui/js/messages.js
@@ -14,6 +14,7 @@ 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_HOVER_DELAY_MS = 5000;
// Delay before collapsing the last step when processing completes
const FINAL_STEP_COLLAPSE_DELAY_MS = 3000;
@@ -131,7 +132,6 @@ function getOrCreateMessageContainer(
return container;
}
-
function getChatHistoryEl() {
if (!_chatHistory) _chatHistory = document.getElementById("chat-history");
return _chatHistory;
@@ -169,8 +169,7 @@ function getLastProcessGroup(allowCompleted = true) {
const groups = lastContainer.querySelectorAll(".process-group");
if (groups.length === 0) return null;
const group = groups[groups.length - 1];
- if (!allowCompleted && group.classList.contains("process-group-completed"))
- return null;
+ if (!allowCompleted && isProcessGroupComplete(group)) return null;
return group;
}
@@ -223,11 +222,14 @@ function drawProcessStep({
...additional
}) {
// group and steps DOM elements
- const group = getOrCreateProcessGroup(id, allowCompletedGroup);
- const stepsContainer = group.querySelector(".process-steps");
const stepId = `process-step-${id}`;
let step = document.getElementById(stepId);
+ const group =
+ getStepProcessGroup(step) ||
+ getOrCreateProcessGroup(id, allowCompletedGroup);
+ const stepsContainer = group.querySelector(".process-steps");
+
const isNewStep = !step;
const isGroupComplete = isProcessGroupComplete(group);
@@ -262,9 +264,6 @@ function drawProcessStep({
// insert step
appendTarget.appendChild(step);
- // add interaction handlers - don't collapse when user interacts
- addStepCollapseInteractionHandlers(step); // TODO? cleanup listeners?
-
// expand all or current step based on settings
const detailMode = preferencesStore.detailMode;
// const isActiveGroup = group.classList.contains("active");
@@ -287,6 +286,14 @@ function drawProcessStep({
});
step.classList.add("expanded");
}
+
+ // create step header
+ const stepHeader = ensureChild(
+ step,
+ ".process-step-header",
+ "div",
+ "process-step-header",
+ );
}
// is step expanded?
@@ -314,20 +321,8 @@ function drawProcessStep({
"process-step-detail-scroll",
);
- // expand/collapse handler for step header
- if (!stepHeader.hasAttribute("data-expand-handler")) {
- stepHeader.setAttribute("data-expand-handler", "true");
- stepHeader.addEventListener("click", (e) => {
- e.stopPropagation();
- cancelStepCollapse(step);
- step.classList.toggle("expanded");
- if (step.classList.contains("expanded")) {
- step.setAttribute("data-user-pinned", "true");
- } else {
- step.removeAttribute("data-user-pinned");
- }
- });
- }
+ // set click handlers
+ setupProcessStepHandlers(step, stepHeader);
// header row - expand icon
ensureChild(stepHeader, ".step-expand-icon", "span", "step-expand-icon");
@@ -421,6 +416,9 @@ function drawStandaloneMessage({
kvps = null,
actionButtons = [],
}) {
+ // end last process group on any standalone messge
+ completeLastProcessGroup();
+
const container = getOrCreateMessageContainer(
id,
position,
@@ -456,6 +454,7 @@ export function _drawMessage({
markdown = false,
latex = false,
mainClass = "",
+ smoothStream = false,
}) {
// Find existing message div or create new one
let messageDiv = messageContainer.querySelector(".message");
@@ -467,7 +466,8 @@ export function _drawMessage({
// Update message classes (preserve collapsible state)
const preserve = ["message-collapsible", "expanded", "has-overflow"]
- .filter((c) => messageDiv.classList.contains(c)).join(" ");
+ .filter((c) => messageDiv.classList.contains(c))
+ .join(" ");
messageDiv.className = `message ${mainClass} ${messageClasses.join(" ")} ${preserve}`;
// Handle heading (important for error/rate_limit messages that show context)
@@ -517,11 +517,11 @@ export function _drawMessage({
}
contentDiv.className = `msg-content ${contentClasses.join(" ")}`;
- let spanElement = contentDiv.querySelector("span");
- if (!spanElement) {
- spanElement = document.createElement("span");
- contentDiv.appendChild(spanElement);
- }
+ // let spanElement = contentDiv.querySelector("span");
+ // if (!spanElement) {
+ // spanElement = document.createElement("span");
+ // contentDiv.appendChild(spanElement);
+ // }
let processedContent = content;
processedContent = convertImageTags(processedContent);
@@ -531,11 +531,13 @@ export function _drawMessage({
processedContent = convertPathsToLinks(processedContent);
processedContent = addBlankTargetsToLinks(processedContent);
- spanElement.innerHTML = processedContent;
+ // do a smooth stream if requested
+ if (smoothStream) smoothRender(contentDiv, processedContent);
+ else contentDiv.innerHTML = processedContent;
// KaTeX rendering for markdown
if (latex) {
- spanElement.querySelectorAll("latex").forEach((element) => {
+ contentDiv.querySelectorAll("latex").forEach((element) => {
katex.render(element.innerHTML, element, {
throwOnError: false,
});
@@ -556,13 +558,14 @@ export function _drawMessage({
preElement.className = `msg-content ${contentClasses.join(" ")}`;
}
- let spanElement = preElement.querySelector("span");
- if (!spanElement) {
- spanElement = document.createElement("span");
- preElement.appendChild(spanElement);
- }
+ // let spanElement = preElement.querySelector("span");
+ // if (!spanElement) {
+ // spanElement = document.createElement("span");
+ // preElement.appendChild(spanElement);
+ // }
- spanElement.innerHTML = convertHTML(content);
+ if (smoothStream) smoothRender(preElement, convertHTML(content));
+ else preElement.innerHTML = convertHTML(content);
}
} else {
// Remove content if it exists but content is empty
@@ -650,17 +653,22 @@ export function drawMessageAgent({
const headerLabels = [
kvps?.tool_name && { label: kvps.tool_name, class: "tool-name-badge" },
].filter(Boolean);
- const actionButtons = thoughtsText.trim()
- ? [
- createActionButton("detail", "", () =>
- stepDetailStore.showStepDetail(
- buildDetailPayload(arguments[0], { headerLabels }),
- ),
- ),
- createActionButton("speak", "", () => speechStore.speak(thoughtsText)),
- createActionButton("copy", "", () => copyToClipboard(thoughtsText)),
- ].filter(Boolean)
- : [];
+ const actionButtons = [
+ createActionButton("detail", "", () =>
+ stepDetailStore.showStepDetail(
+ buildDetailPayload(arguments[0], { headerLabels }),
+ ),
+ ),
+ ];
+
+ if (thoughtsText.trim()) {
+ actionButtons.push(
+ createActionButton("speak", "", () => speechStore.speak(thoughtsText)),
+ );
+ actionButtons.push(
+ createActionButton("copy", "", () => copyToClipboard(thoughtsText)),
+ );
+ }
return drawProcessStep({
id,
@@ -714,17 +722,20 @@ export function drawMessageResponse({
let container = null;
if (group) {
+ // new response, collapse all previous steps once
+ if (!group.querySelector(".process-group-response")) {
+ if (preferencesStore.detailMode == "current")
+ group.querySelectorAll(".process-step").forEach((step) => {
+ scheduleStepCollapse(step);
+ });
+ }
+
container = ensureChild(
group,
".process-group-response",
"div",
"process-group-response",
);
- //collapse all steps when response is ready
- if(preferencesStore.detailMode!=="expanded")
- group.querySelectorAll(".process-step").forEach((step) => {
- scheduleStepCollapse(step);
- });
} else container = getOrCreateMessageContainer(id, "left");
const messageDiv = _drawMessage({
@@ -737,6 +748,7 @@ export function drawMessageResponse({
markdown: true,
latex: true,
mainClass: "message-agent-response",
+ smoothStream: !isMassRender(), // stream smoothly if not in mass render mode
});
// Collapsible with action buttons
@@ -747,7 +759,12 @@ export function drawMessageResponse({
createActionButton("copy", "", () => copyToClipboard(responseText)),
].filter(Boolean)
: [];
- setupCollapsible(messageDiv, ":scope > .step-action-buttons", !isMassRender(), responseActionButtons);
+ setupCollapsible(
+ messageDiv,
+ ":scope > .step-action-buttons",
+ !isMassRender(),
+ responseActionButtons,
+ );
if (group) updateProcessGroupHeader(group);
@@ -768,6 +785,9 @@ export function drawMessageUser({
true,
);
+ // end last process group on any user message
+ completeLastProcessGroup();
+
// Find existing message div or create new one
let messageDiv = messageContainer.querySelector(".message");
if (!messageDiv) {
@@ -1121,7 +1141,7 @@ export function drawMessageInfo({
kvps = null,
...additional
}) {
- const title = cleanStepTitle(heading);
+ const title = cleanStepTitle(heading || content);
let displayKvps = { ...kvps };
const contentText = String(content ?? "");
const actionButtons = contentText.trim()
@@ -1154,7 +1174,7 @@ export function drawMessageUtil({
agentno = 0,
...additional
}) {
- const title = cleanStepTitle(heading);
+ const title = cleanStepTitle(heading || content);
const contentText = String(content ?? "");
const actionButtons = contentText.trim()
? [
@@ -1220,7 +1240,7 @@ export function drawMessageProgress({
agentno = 0,
...additional
}) {
- const title = cleanStepTitle(heading);
+ const title = cleanStepTitle(heading || content);
let displayKvps = { ...kvps };
return drawProcessStep({
@@ -1243,7 +1263,7 @@ export function drawMessageWarning({
kvps = null,
...additional
}) {
- const title = cleanStepTitle(heading);
+ const title = cleanStepTitle(heading || content);
let displayKvps = { ...kvps };
const contentText = String(content ?? "");
const actionButtons = contentText.trim()
@@ -1544,15 +1564,15 @@ function adjustMarkdownRender(element) {
// find all tables in the element
const tables = element.querySelectorAll("table");
tables.forEach((el) => {
- const wrapper = wrapElement(el, "message-markdown-table-wrap");
- const actionsDiv = document.createElement("div");
- actionsDiv.className = "step-action-buttons";
- actionsDiv.appendChild(
- createActionButton("copy", "", () =>
- copyToClipboard(extractTableTSV(el)),
- ),
- );
- wrapper.appendChild(actionsDiv);
+ // const wrapper = wrapElement(el, "message-markdown-table-wrap");
+ // const actionsDiv = document.createElement("div");
+ // actionsDiv.className = "step-action-buttons";
+ // actionsDiv.appendChild(
+ // createActionButton("copy", "", () =>
+ // copyToClipboard(extractTableTSV(el)),
+ // ),
+ // );
+ // wrapper.appendChild(actionsDiv);
});
// find all code blocks
@@ -1560,12 +1580,12 @@ function adjustMarkdownRender(element) {
codeElements.forEach((code) => {
const pre = code.parentNode;
const wrapper = wrapElement(pre, "code-block-wrapper");
- const actionsDiv = document.createElement("div");
- actionsDiv.className = "step-action-buttons";
- actionsDiv.appendChild(
- createActionButton("copy", "", () => copyToClipboard(code.textContent)),
- );
- wrapper.appendChild(actionsDiv);
+ // const actionsDiv = document.createElement("div");
+ // actionsDiv.className = "step-action-buttons";
+ // actionsDiv.appendChild(
+ // createActionButton("copy", "", () => copyToClipboard(code.textContent)),
+ // );
+ // wrapper.appendChild(actionsDiv);
});
// find all images
@@ -1689,22 +1709,58 @@ function getNestedContainer(parentStep) {
*/
function scheduleStepCollapse(stepElement, delayMs) {
// skip if any existing timeout for this step
- if (stepElement.hasAttribute("data-collapse-timeout-id")) {
- return;
- }
+ if (stepElement.hasAttribute("data-collapse-timeout-id")) return;
+ // skip already collapsed steps
+ if (!stepElement.classList.contains("expanded")) return;
// Schedule the collapse
const timeoutId = setTimeout(() => {
- stepElement.classList.remove("expanded");
stepElement.removeAttribute("data-collapse-timeout-id");
- // Clear user-pinned flag when auto-collapsing
- stepElement.removeAttribute("data-user-pinned");
+
+ if (stepElement.dataset.clicked === "true") {
+ console.log(`Skip clicked collapse: ${stepElement.id}`);
+ return;
+ }
+
+ if (stepElement.matches(":hover")) {
+ console.log(`Delay hover collapse: ${stepElement.id}`);
+ scheduleStepCollapse(stepElement, STEP_COLLAPSE_HOVER_DELAY_MS);
+ return;
+ }
+
+ console.log(`Collapse step: ${stepElement.id}`);
+ stepElement.classList.remove("expanded");
}, delayMs);
// Store the timeout ID
stepElement.setAttribute("data-collapse-timeout-id", String(timeoutId));
}
+function setupProcessStepHandlers(stepElement, stepHeader) {
+ if (!stepElement.hasAttribute("data-step-handlers")) {
+ stepElement.setAttribute("data-step-handlers", "true");
+
+ stepElement.addEventListener(
+ "click",
+ function handler() {
+ stepElement.dataset.clicked = "true";
+ console.log(`Step clicked: ${stepElement.id}`);
+ },
+ { once: true },
+ );
+ }
+
+ if (stepHeader && !stepHeader.hasAttribute("data-expand-handler")) {
+ stepHeader.setAttribute("data-expand-handler", "true");
+ stepHeader.addEventListener("click", (e) => {
+ e.stopPropagation();
+ cancelStepCollapse(stepElement);
+ stepElement.dataset.clicked = "true";
+ stepElement.classList.toggle("expanded");
+ });
+ }
+}
+
/**
* Cancel a scheduled collapse for a step
*/
@@ -1716,46 +1772,6 @@ function cancelStepCollapse(stepElement) {
stepElement.removeAttribute("data-collapse-timeout-id");
}
-/**
- * Add interaction handlers to prevent fighting with user
- * - Hover: cancels the collapse timeout (keeps step open while reading)
- * - Leave: starts a new timeout ONLY if user hasn't clicked (no explicit interaction)
- * - Click anywhere on step: permanently cancels auto-collapse (user wants it open)
- */
-function addStepCollapseInteractionHandlers(stepElement) {
- // On hover, cancel the timeout to keep it open while user is reading
- stepElement.addEventListener("mouseenter", () => {
- if (stepElement.classList.contains("expanded")) {
- cancelStepCollapse(stepElement);
- }
- });
-
- // On leave, start a new timeout ONLY if user hasn't explicitly clicked
- // and only in "current" mode (in "expanded" mode, everything stays open)
- stepElement.addEventListener("mouseleave", () => {
- const detailMode = preferencesStore.detailMode;
- // Don't schedule collapse in "expanded" mode - user wants everything open
- if (detailMode === "expanded") return;
-
- // Don't restart timeout if user has explicitly interacted (clicked)
- if (
- stepElement.classList.contains("expanded") &&
- !stepElement.hasAttribute("data-user-pinned")
- ) {
- scheduleStepCollapse(stepElement, STEP_COLLAPSE_DELAY_MS);
- }
- });
-
- // On click anywhere on step, permanently cancel auto-collapse
- stepElement.addEventListener("click", () => {
- if (stepElement.classList.contains("expanded")) {
- cancelStepCollapse(stepElement);
- // Mark as user-pinned so mouseleave won't restart timeout
- stepElement.setAttribute("data-user-pinned", "true");
- }
- });
-}
-
/**
* Find parent delegation step for nested agents (DOM-first, reverse scan).
*/
@@ -1958,10 +1974,25 @@ function updateProcessGroupHeader(group) {
}
function isProcessGroupComplete(group) {
+ // manually closed group
+ if (group?.hasAttribute?.("data-group-complete")) return true;
+ // naturally completed group
const response = group.querySelector(".process-group-response");
return !!response;
}
+// manually complete last process group
+export function completeLastProcessGroup() {
+ const group = getLastProcessGroup();
+ if (!group || isProcessGroupComplete(group)) return;
+ group.setAttribute("data-group-complete", "true");
+ updateProcessGroupHeader(group);
+}
+
+function getStepProcessGroup(step) {
+ return step?.closest(".process-group");
+}
+
/**
* Truncate text to a maximum length
*/
@@ -1972,66 +2003,6 @@ function truncateText(text, maxLength) {
return text.substring(0, maxLength - 3) + "...";
}
-/**
- * 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);
-// });
-// }
-
-// // 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 element
function ensureChild(parent, selector, tagName, ...classNames) {
let el = parent.querySelector(selector);
@@ -2044,11 +2015,21 @@ function ensureChild(parent, selector, tagName, ...classNames) {
}
// Setup collapsible message with expand button and action buttons
-function setupCollapsible(messageDiv, containerSelector, initialExpanded, actionButtons = []) {
+function setupCollapsible(
+ messageDiv,
+ containerSelector,
+ initialExpanded,
+ actionButtons = [],
+) {
messageDiv.classList.add("message-collapsible");
messageDiv.classList.toggle("expanded", initialExpanded);
- const container = ensureChild(messageDiv, containerSelector, "div", "step-action-buttons");
+ const container = ensureChild(
+ messageDiv,
+ containerSelector,
+ "div",
+ "step-action-buttons",
+ );
container.textContent = "";
const btn = ensureChild(container, ".expand-btn", "button", "expand-btn");
@@ -2059,7 +2040,10 @@ function setupCollapsible(messageDiv, containerSelector, initialExpanded, action
btn.classList.toggle("show-more-btn", !exp);
};
syncBtn();
- btn.onclick = () => { messageDiv.classList.toggle("expanded"); syncBtn(); };
+ btn.onclick = () => {
+ messageDiv.classList.toggle("expanded");
+ syncBtn();
+ };
actionButtons.filter(Boolean).forEach((b) => container.appendChild(b));
@@ -2069,7 +2053,10 @@ function setupCollapsible(messageDiv, containerSelector, initialExpanded, action
const body = messageDiv.querySelector(".message-body");
const wasExp = messageDiv.classList.contains("expanded");
messageDiv.classList.remove("expanded");
- messageDiv.classList.toggle("has-overflow", body?.scrollHeight > body?.clientHeight);
+ messageDiv.classList.toggle(
+ "has-overflow",
+ body?.scrollHeight > body?.clientHeight,
+ );
messageDiv.classList.toggle("expanded", wasExp);
});
}
@@ -2080,3 +2067,44 @@ function setupCollapsible(messageDiv, containerSelector, initialExpanded, action
function isMassRender() {
return _massRender;
}
+
+// smooth fade in animation for new chunks when streaming
+function smoothRender(element, newContent, delay = 350) {
+ // skip on mass render
+ if (isMassRender()) {
+ element.innerHTML = newContent;
+ return;
+ }
+
+ element.dataset.smoothPendingHtml = newContent;
+
+ if (element.dataset.smoothTimeoutId) return;
+
+ const timeoutId = window.setTimeout(() => {
+ const pending = element.dataset.smoothPendingHtml || "";
+ delete element.dataset.smoothPendingHtml;
+ delete element.dataset.smoothTimeoutId;
+
+ const existing = element.querySelector(
+ ":scope > div.smooth-render-visible",
+ );
+ if (existing) {
+ existing.classList.remove("smooth-render-visible");
+ existing.classList.add("smooth-render-invisible");
+
+ existing.addEventListener("animationend", () => existing.remove(), {
+ once: true,
+ });
+ }
+
+ const nextLayer = document.createElement("div");
+ nextLayer.className = "smooth-render-visible";
+ nextLayer.innerHTML = pending;
+ element.appendChild(nextLayer);
+
+ // Keep container height stable while layers are absolute
+ element.style.height = `${nextLayer.scrollHeight}px`;
+ }, delay);
+
+ element.dataset.smoothTimeoutId = String(timeoutId);
+}