Skip to content

Agent Zero AI framework

chat rendering refactor - work in progress

frdelf63df9f4ebbb
diff --git a/agent.py b/agent.py
index 312400c1e..df2c8925b 100644
--- a/agent.py
+++ b/agent.py
@@ -831,8 +831,8 @@ class Agent:
tool_request = extract_tools.json_parse_dirty(msg)
if tool_request is not None:
- raw_tool_name = tool_request.get("tool_name", "") # Get the raw tool name
- tool_args = tool_request.get("tool_args", {})
+ raw_tool_name = tool_request.get("tool_name", tool_request.get("tool","")) # Get the raw tool name
+ tool_args = tool_request.get("tool_args", tool_request.get("args", {}))
tool_name = raw_tool_name # Initialize tool_name with raw_tool_name
tool_method = None # Initialize tool_method
diff --git a/models.py b/models.py
index 4676352c2..c8c3af9fc 100644
--- a/models.py
+++ b/models.py
@@ -115,8 +115,8 @@ class ChatGenerationResult:
# if the model outputs thinking tags, we ned to parse them manually as reasoning
processed_chunk = self._process_thinking_chunk(chunk)
- self.reasoning += processed_chunk["reasoning_delta"]
- self.response += processed_chunk["response_delta"]
+ self.reasoning += processed_chunk.get("reasoning_delta", "")
+ self.response += processed_chunk.get("response_delta", "")
return processed_chunk
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.py
index 6618a0a47..fa86e1e18 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
@@ -22,7 +22,7 @@ class LogForStream(Extension):
def build_heading(agent, text: str, icon: str = "network_intelligence"):
# Include agent identifier for all agents (A0:, A1:, A2:, etc.)
agent_prefix = f"{agent.agent_name}: "
- return f"icon://{icon} {agent_prefix}{text}"
+ return f"{agent_prefix}{text}"
def build_default_heading(agent):
return build_heading(agent, "Generating...")
\ No newline at end of file
diff --git a/python/extensions/response_stream/_10_log_from_stream.py b/python/extensions/response_stream/_10_log_from_stream.py
index 375b96c03..308263bbc 100644
--- a/python/extensions/response_stream/_10_log_from_stream.py
+++ b/python/extensions/response_stream/_10_log_from_stream.py
@@ -42,7 +42,21 @@ class LogFromStream(Extension):
kvps = {}
if log_item.kvps is not None and "reasoning" in log_item.kvps:
kvps["reasoning"] = log_item.kvps["reasoning"]
+
+ # step description for UI - using tool XY, writing Python code, etc.
+ if parsed is not None and "tool_name" in parsed and parsed["tool_name"]:
+ kvps["step"] = f"Using {parsed['tool_name']}..." # using tool XY
+ if parsed["tool_name"]=="code_execution_tool":
+ if "tool_args" in parsed and "runtime" in parsed["tool_args"]:
+ if parsed["tool_args"]["runtime"] == "python":
+ kvps["step"] = "Writing Python code..."
+ elif parsed["tool_args"]["runtime"] == "nodejs":
+ kvps["step"] = "Writing Node.js code..."
+ elif parsed["tool_args"]["runtime"] == "terminal":
+ kvps["step"] = "Writing terminal command..."
kvps.update(parsed)
+
+
# update the log item
log_item.update(heading=heading, content=text, kvps=kvps)
\ No newline at end of file
diff --git a/python/extensions/response_stream_end/_15_log_from_stream_end.py b/python/extensions/response_stream_end/_15_log_from_stream_end.py
new file mode 100644
index 000000000..3208834d1
--- /dev/null
+++ b/python/extensions/response_stream_end/_15_log_from_stream_end.py
@@ -0,0 +1,31 @@
+from python.helpers import persist_chat, tokens
+from python.helpers.extension import Extension
+from agent import LoopData
+import asyncio
+from python.helpers.log import LogItem
+from python.helpers import log
+import math
+from python.extensions.before_main_llm_call._10_log_for_stream import build_heading, build_default_heading
+
+
+class LogFromStream(Extension):
+
+ async def execute(
+ self,
+ loop_data: LoopData = LoopData(),
+ text: str = "",
+ parsed: dict = {},
+ **kwargs,
+ ):
+
+ # get log item from loop data temporary params
+ log_item = loop_data.params_temporary["log_item_generating"]
+ if log_item is None:
+ return
+
+ # remove step parameter when done
+ if log_item.kvps is not None and "step" in log_item.kvps:
+ del log_item.kvps["step"]
+
+ # update the log item
+ log_item.update(kvps=log_item.kvps)
\ No newline at end of file
diff --git a/python/helpers/log.py b/python/helpers/log.py
index a59919dd9..808e8fa4c 100644
--- a/python/helpers/log.py
+++ b/python/helpers/log.py
@@ -21,6 +21,7 @@ Type = Literal[
"agent",
"browser",
"code_exe",
+ "subagent",
"error",
"hint",
"info",
diff --git a/python/tools/call_subordinate.py b/python/tools/call_subordinate.py
index dd19b40ce..7f0976022 100644
--- a/python/tools/call_subordinate.py
+++ b/python/tools/call_subordinate.py
@@ -45,7 +45,7 @@ class Delegation(Tool):
def get_log_object(self):
return self.agent.context.log.log(
- type="tool",
+ type="subagent",
heading=f"icon://communication {self.agent.agent_name}: Calling Subordinate Agent",
content="",
kvps=self.args,
diff --git a/webui/components/messages/process-group/process-group.css b/webui/components/messages/process-group/process-group.css
index 5d5b0725d..54d9fd4c6 100644
--- a/webui/components/messages/process-group/process-group.css
+++ b/webui/components/messages/process-group/process-group.css
@@ -88,7 +88,7 @@
flex: 0 1 auto;
font-size: var(--font-size-medium);
font-weight: 500;
- color: var(--color-text);
+ color: var(--color-text-muted);
opacity: 0.9;
white-space: nowrap;
overflow: hidden;
@@ -111,7 +111,7 @@
=========================================== */
/* Base status badge */
-.status-badge {
+.step-badge {
display: inline-flex;
align-items: center;
gap: 3px;
@@ -127,97 +127,132 @@
}
/* Status badge with icon */
-.status-badge .material-symbols-outlined {
+.step-badge .material-symbols-outlined {
font-size: 0.8rem;
line-height: 1;
}
/* Badge icon styling */
-.status-badge .badge-icon {
- font-size: 0.7rem;
+.step-badge .badge-icon {
+ font-size: var(--font-size-xs);
margin-right: 2px;
opacity: 0.9;
}
-/* Status colors - mapped from backend types via store */
+/* Status colors */
/* Each status defines --step-accent for cascading to internal icons */
/* GEN - agent type (blue/cyan) */
-.status-gen {
+.process-group .GEN {
--step-accent: #38bdf8;
}
+.light-mode .process-group .GEN {
+ --step-accent: #0284c7;
+}
/* END - response/done type (green) */
-.status-end {
+.process-group .END {
--step-accent: #22c55e;
}
+.light-mode .process-group .END {
+ --step-accent: #15803d;
+}
/* USE - tool usage (amber/yellow) */
-.status-tool {
+.process-group .USE {
--step-accent: #fbbf24;
}
+.light-mode .process-group .USE {
+ --step-accent: #b45309;
+}
/* MCP - mcp type (amber/yellow) */
-.status-mcp {
+.process-group .MCP {
--step-accent: #fbbf24;
}
+.light-mode .process-group .MCP {
+ --step-accent: #b45309;
+}
/* SUB - subagent type (teal) */
-.status-sub {
+.process-group .SUB {
--step-accent: #14b8a6;
}
+.light-mode .process-group .SUB {
+ --step-accent: #0f766e;
+}
/* EXE - code_exe type (magenta/purple) */
-.status-exe {
+.process-group .EXE {
--step-accent: #ba68c8;
}
+.light-mode .process-group .EXE {
+ --step-accent: #7c3aed;
+}
/* WWW - browser type (indigo) */
-.status-www {
+.process-group .WWW {
--step-accent: #818cf8;
}
+.light-mode .process-group .WWW {
+ --step-accent: #4f46e5;
+}
/* WAIT - progress type (slate) */
-.status-wait {
+.process-group .HDL {
--step-accent: #94a3b8;
}
+.light-mode .process-group .HDL {
+ --step-accent: #475569;
+}
/* INF - info type (gray) */
-.status-inf {
+.process-group .INF {
--step-accent: #94a3b8;
}
+.light-mode .process-group .INF {
+ --step-accent: #475569;
+}
/* HNT - hint type (yellow-green) */
-.status-hnt {
+.process-group .HNT {
--step-accent: #a3e635;
}
+.light-mode .process-group .HNT {
+ --step-accent: #65a30d;
+}
/* WRN - warning type (orange) */
-.status-wrn {
+.process-group .WRN {
--step-accent: #f97316;
}
+.light-mode .process-group .WRN {
+ --step-accent: #c2410c;
+}
+
/* ERR - error type (red) */
-.status-err {
+.process-group .ERR {
+ --step-accent: var(--color-error-text);
+}
+.light-mode .process-group .ERR {
--step-accent: var(--color-error-text);
}
/* UTL - util type (gray-blue) */
-.status-utl {
+.process-group .UTL {
--step-accent: #64748b;
}
-
-/* USR - user type (sky) */
-.status-usr {
- --step-accent: #38bdf8;
+.light-mode .process-group .UTL {
+ --step-accent: #334155;
}
-.process-step .status-badge{
+.process-group .step-badge{
color: var(--step-accent);
}
-.process-step .kvps-key{
+.process-group .kvps-key{
color: var(--step-accent);
}
@@ -255,7 +290,7 @@
}
.process-group-header .group-metrics .material-symbols-outlined {
- font-size: 0.75rem;
+ font-size: var(--font-size-xs);
opacity: 0.7;
}
@@ -287,7 +322,7 @@
}
.process-group-header .group-duration {
- font-size: 0.7rem;
+ font-size: var(--font-size-xs);
color: #81c784;
flex-shrink: 0;
font-family: var(--font-family-code);
@@ -298,7 +333,7 @@
/* Process Group Content - Animated expand/collapse */
.process-group-content {
- /* display: grid; */
+ display: grid;
grid-template-rows: 0fr;
opacity: 0;
margin-top: 0;
@@ -310,6 +345,7 @@
padding-top 0.25s ease-out,
border-color 0.2s ease-out;
overflow: hidden;
+ color: var(--color-text-muted);
}
.process-group-content > .process-steps {
@@ -317,7 +353,7 @@
}
.process-group.expanded .process-group-content {
- /* grid-template-rows: 1fr; */
+ grid-template-rows: 1fr;
opacity: 1;
margin-top: var(--spacing-xs);
padding-top: var(--spacing-xs);
@@ -374,7 +410,7 @@
.process-step-header .step-title {
flex: 1;
font-size: 0.8rem;
- color: var(--color-text);
+ /* color: var(--color-text-muted); */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@@ -407,7 +443,7 @@
/* Step Detail Content - Animated expand/collapse */
.process-step-detail {
- display: grid;
+ /* display: grid; */
grid-template-rows: 0fr;
opacity: 0;
margin-top: 0;
@@ -423,7 +459,7 @@
margin-top: 0;
}
-.process-step:not(.step-expanded) > .process-step-detail > .process-step-detail-content {
+.process-step:not(.step-expanded) > .process-step-detail > .process-step-detail-scroll {
padding: 0;
margin-top: 0;
max-height: 0;
@@ -436,36 +472,39 @@
height: 0;
}
-.process-step-detail-content::-webkit-scrollbar {
+.process-step-detail-scroll::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
}
-.process-step-detail > .process-step-detail-content {
+.process-step-detail > .process-step-detail-scroll {
min-height: 0;
}
/* Use direct child selector (>) to prevent cascading to nested steps */
.process-step.step-expanded > .process-step-detail {
- grid-template-rows: 1fr;
+ /* grid-template-rows: 1fr; */
opacity: 1;
overflow: visible;
margin-top: var(--spacing-xs);
}
-.process-step.step-expanded > .process-step-detail > .process-step-detail-content {
- max-height: 350px;
+.process-step.step-expanded > .process-step-detail > .process-step-detail-scroll {
+ max-height: 40em;
overflow-y: auto;
}
-.process-step-detail-content {
+.process-step.step-expanded > .process-step-detail > .process-step-detail-scroll > .process-step-detail-scroll {
+}
+
+.process-step-detail-scroll {
transition: max-height 0.2s ease-out, padding 0.2s ease-out, margin-top 0.2s ease-out;
padding: var(--spacing-xs) 0;
margin-top: var(--spacing-xxs);
- margin-left: 28px; /* Align with icon */
+ /* margin-left: 28px; */
background-color: transparent;
- font-size: 0.7rem;
+ font-size: var(--font-size-xs);
line-height: 1.5;
overflow-y: auto;
-webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
@@ -474,29 +513,29 @@
overscroll-behavior-x: contain; /* avoid scroll chaining */
}
-.process-step-detail-content pre {
+/* .process-step-detail-scroll pre {
margin: 0;
white-space: pre-wrap;
word-break: break-word;
font-family: var(--font-family-code);
- font-size: 0.7rem;
+ font-size: var(--font-size-xs);
color: var(--color-text);
- /* opacity: 0.8; */
-}
+ opacity: 0.8;
+} */
/* KVPs in step detail - CSS Grid for aligned columns */
-.process-step-detail-content .step-kvps {
+.process-step-detail-scroll .step-kvps {
display: grid;
grid-template-columns: auto 1fr;
gap: var(--spacing-xs) var(--spacing-sm);
align-items: start;
}
-.process-step-detail-content .step-kvp {
+.process-step-detail-scroll .step-kvp {
display: contents; /* Children participate in parent grid */
}
-.process-step-detail-content .step-kvp-key {
+.process-step-detail-scroll .step-kvp-key {
color: var(--step-accent, var(--color-primary));
font-weight: 500;
opacity: 0.8;
@@ -505,13 +544,13 @@
justify-content: end;
}
-.process-step-detail-content .step-kvp-key .material-symbols-outlined {
+.process-step-detail-scroll .step-kvp-key .material-symbols-outlined {
font-size: 0.9rem;
color: var(--step-accent, var(--color-primary)) !important;
}
-.process-step-detail-content .step-kvp-value {
- color: var(--color-text);
+.process-step-detail-scroll .step-kvp-value {
+ /* color: var(--color-text); */
opacity: 0.85;
word-break: break-word;
white-space: pre-wrap;
@@ -519,111 +558,77 @@
line-height: 1.5;
}
-/* Thoughts styling - single icon with plain text */
-.process-step-detail-content .step-thoughts {
- display: flex;
- align-items: flex-start;
- gap: var(--spacing-sm);
- margin: var(--spacing-xs) 0;
-}
-
-.process-step-detail-content .thought-icon {
- font-size: 0.85rem;
- color: var(--step-accent, #38bdf8);
- flex-shrink: 0;
- margin-top: 2px;
-}
-
-.process-step-detail-content .thought-text {
- font-size: 0.7rem;
- font-weight: 300;
- color: var(--color-text);
- opacity: 0.65;
- line-height: 1.5;
- white-space: pre-wrap;
- word-break: break-word;
-}
-
-/* Light mode thoughts - uses step accent if available */
-.light-mode .process-step-detail-content .thought-icon {
- color: var(--step-accent, #b45309);
-}
/* Tool arguments - CSS Grid for aligned columns */
-.process-step-detail-content .step-tool-args {
+/* .process-step-detail-scroll .step-tool-args {
display: grid;
grid-template-columns: auto 1fr;
gap: 4px 8px;
margin: var(--spacing-xs) 0;
align-items: baseline;
-}
+} */
-.process-step-detail-content .tool-arg-row {
- display: contents; /* Children participate in parent grid */
-}
+/* .process-step-detail-scroll .tool-arg-row {
+ display: contents;
+} */
-.process-step-detail-content .tool-arg-label {
+/* .process-step-detail-scroll .tool-arg-label {
font-size: 0.68rem;
font-weight: 600;
color: var(--step-accent, var(--color-primary));
display: flex;
align-items: center;
justify-content: end;
-}
+} */
-.process-step-detail-content .tool-arg-label .material-symbols-outlined {
+/* .process-step-detail-scroll .tool-arg-label .material-symbols-outlined {
font-size: 0.9rem;
opacity: 0.85;
color: var(--step-accent, var(--color-primary));
-}
+} */
-.process-step-detail-content .tool-arg-value {
- font-size: 0.7rem;
+/* .process-step-detail-scroll .tool-arg-value {
+ font-size: var(--font-size-xs);
color: var(--color-text);
opacity: 0.85;
word-break: break-word;
font-family: var(--font-family-code);
-}
+} */
/* Light mode tool args - transparent like dark mode */
-.light-mode .process-step-detail-content .step-tool-args {
+/* .light-mode .process-step-detail-scroll .step-tool-args {
background: transparent;
border-left-color: transparent;
-}
+} */
-.process-step-detail-content .step-tool-header .tool-icon {
+/* .process-step-detail-scroll .step-tool-header .tool-icon {
font-size: 0.85rem;
color: var(--step-accent, var(--color-warning));
opacity: 0.85;
-}
+} */
-.process-step-detail-content .step-tool-header .tool-label {
+/* .process-step-detail-scroll .step-tool-header .tool-label {
font-size: 0.68rem;
font-weight: 600;
color: var(--step-accent, var(--color-warning));
opacity: 0.85;
-}
+} */
-.process-step-detail-content .step-tool-header .tool-name {
+/* .process-step-detail-scroll .step-tool-header .tool-name {
font-size: 0.72rem;
color: var(--color-text);
opacity: 0.85;
-}
+} */
-/* Terminal-style output for code_exe */
-.process-step-detail-content .step-terminal {
- margin: var(--spacing-xs) 0;
- font-family: var(--font-family-code);
- font-size: 0.72rem;
-}
-.process-step-detail-content .terminal-output {
+.process-step-detail .terminal-output {
margin: var(--spacing-xs) 0 0 0;
padding: var(--spacing-xs);
background: rgba(0, 0, 0, 0.8);
border-radius: 8px;
color: #c9d1d9;
white-space: pre;
+ font-family: monospace;
max-width: fit-content;
max-height: 300px;
overflow: auto;
@@ -633,36 +638,36 @@
overscroll-behavior-x: contain;
}
-.process-step-detail-content .terminal-output::-webkit-scrollbar {
+.process-step-detail .terminal-output::-webkit-scrollbar {
width: 4px;
height: 4px;
}
-.process-step-detail-content .terminal-output::-webkit-scrollbar-track {
+.process-step-detail .terminal-output::-webkit-scrollbar-track {
background: transparent;
}
-.process-step-detail-content .terminal-output::-webkit-scrollbar-thumb {
+.process-step-detail .terminal-output::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.2);
border-radius: 2px;
}
-.process-step-detail-content .terminal-output::-webkit-scrollbar-thumb:hover {
+.process-step-detail .terminal-output::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.35);
}
/* Light mode terminal */
-.light-mode .process-step-detail-content .terminal-output {
+.light-mode .process-step-detail .terminal-output {
background: rgba(0, 0, 0, 0.05);
color: black;
scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}
-.light-mode .process-step-detail-content .terminal-output::-webkit-scrollbar-thumb {
+.light-mode .process-step-detail .terminal-output::-webkit-scrollbar-thumb {
background: rgba(0, 0, 0, 0.15);
}
-.light-mode .process-step-detail-content .terminal-output::-webkit-scrollbar-thumb:hover {
+.light-mode .process-step-detail .terminal-output::-webkit-scrollbar-thumb:hover {
background: rgba(0, 0, 0, 0.3);
}
@@ -671,87 +676,17 @@
border-top-color: rgba(0, 0, 0, 0.06);
}
-.light-mode .process-step-detail-content {
+.light-mode .process-step-detail-scroll {
background-color: transparent;
}
/* Light mode text colors for process group */
.light-mode .process-group-header .group-title,
.light-mode .process-step-header .step-title {
- color: var(--color-text);
+ color: var(--color-text-muted);
}
-/* Light mode status badge adjustments for better contrast */
-/* Override --step-accent for cascading to internal icons */
-.light-mode .status-gen {
- --step-accent: #0284c7;
- color: var(--step-accent);
-}
-.light-mode .status-end {
- --step-accent: #15803d;
- color: var(--step-accent);
-}
-
-.light-mode .status-tool {
- --step-accent: #b45309;
- color: var(--step-accent);
-}
-
-.light-mode .status-mcp {
- --step-accent: #b45309;
- color: var(--step-accent);
-}
-
-.light-mode .status-sub {
- --step-accent: #0f766e;
- color: var(--step-accent);
-}
-
-.light-mode .status-exe {
- --step-accent: #7c3aed;
- color: var(--step-accent);
-}
-
-.light-mode .status-www {
- --step-accent: #4f46e5;
- color: var(--step-accent);
-}
-
-.light-mode .status-wait {
- --step-accent: #475569;
- color: var(--step-accent);
-}
-
-.light-mode .status-inf {
- --step-accent: #475569;
- color: var(--step-accent);
-}
-
-.light-mode .status-hnt {
- --step-accent: #65a30d;
- color: var(--step-accent);
-}
-
-.light-mode .status-wrn {
- --step-accent: #c2410c;
- color: var(--step-accent);
-}
-
-.light-mode .status-err {
- --step-accent: var(--color-error-text);
- color: var(--step-accent);
-}
-
-.light-mode .status-utl {
- --step-accent: #334155;
- color: var(--step-accent);
-}
-
-.light-mode .status-usr {
- --step-accent: #0284c7;
- color: var(--step-accent);
-}
/* Animation for loading state */
@keyframes pulse-step {
@@ -769,10 +704,10 @@
}
.process-step-header .step-title {
- font-size: 0.7rem;
+ font-size: var(--font-size-xs);
}
- .process-step-detail-content {
+ .process-step-detail-scroll {
margin-left: 0;
}
}
@@ -782,20 +717,17 @@
These rules work with preferences-store toggles
=========================================== */
-/* Utility steps - default hidden (controlled by showUtils) */
-.process-step.message-util {
+/* .process-step.message-util {
display: none;
}
-/* Thoughts KVP row */
.step-kvp.msg-thoughts {
display: none;
}
-/* JSON pre content - default hidden */
-.process-step-detail-content pre.msg-json {
+.process-step-detail-scroll pre.msg-json {
display: none;
-}
+} */
/* Nested Process Steps (Subordinate Agents) */
@@ -830,7 +762,7 @@
}
/* Response content in process steps */
-.process-step-detail-content .step-response-content {
+.process-step-detail-scroll .step-response-content {
font-size: 0.75rem;
line-height: 1.6;
color: var(--color-text);
@@ -838,18 +770,18 @@
margin: var(--spacing-xs) 0;
}
-.process-step-detail-content .step-response-content p {
+.process-step-detail-scroll .step-response-content p {
margin: 0.5em 0;
}
-.process-step-detail-content .step-response-content ul,
-.process-step-detail-content .step-response-content ol {
+.process-step-detail-scroll .step-response-content ul,
+.process-step-detail-scroll .step-response-content ol {
margin: 0.5em 0;
padding-left: 1.5em;
}
/* Warning/error content in process steps */
-.process-step-detail-content .step-warning-content {
+.process-step-detail-scroll .step-warning-content {
font-size: 0.72rem;
line-height: 1.5;
color: var(--color-warning);
@@ -861,7 +793,7 @@
}
/* Browser screenshot content in process steps */
-.process-step-detail-content .screenshot-img {
+.process-step-detail-scroll .screenshot-img {
max-width: 100%;
max-height: 400px;
border-radius: 4px;
@@ -871,18 +803,18 @@
object-fit: contain;
}
-.process-step-detail-content .screenshot-img:hover {
+.process-step-detail-scroll .screenshot-img:hover {
transform: scale(1.02);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
/* Light mode screenshot border */
-.light-mode .process-step-detail-content .screenshot-img {
+.light-mode .process-step-detail-scroll .screenshot-img {
border: 1px solid rgba(0, 0, 0, 0.15);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
-.light-mode .process-step-detail-content .screenshot-img:hover {
+.light-mode .process-step-detail-scroll .screenshot-img:hover {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
diff --git a/webui/components/modals/process-step-detail/process-step-detail.html b/webui/components/modals/process-step-detail/process-step-detail.html
index c3bd02983..a49daeb71 100644
--- a/webui/components/modals/process-step-detail/process-step-detail.html
+++ b/webui/components/modals/process-step-detail/process-step-detail.html
@@ -245,7 +245,7 @@
flex-wrap: wrap;
}
- .status-badge {
+ .step-badge {
padding: 0.25rem 0.5rem;
border-radius: 8px;
font-size: 0.75rem;
diff --git a/webui/components/sidebar/bottom/preferences/preferences-store.js b/webui/components/sidebar/bottom/preferences/preferences-store.js
index 00ebce4ab..f1329cb77 100644
--- a/webui/components/sidebar/bottom/preferences/preferences-store.js
+++ b/webui/components/sidebar/bottom/preferences/preferences-store.js
@@ -115,6 +115,14 @@ const model = {
this._detailMode = "current"; // Default
}
+ // load utility messages preference
+ try{
+ const storedShowUtils = localStorage.getItem("showUtils");
+ this._showUtils = storedShowUtils === "true";
+ } catch {
+ this._showUtils = false; // Default to speech off if localStorage is unavailable
+ }
+
// Apply all preferences
this._applyDarkMode(this._darkMode);
this._applyAutoScroll(this._autoScroll);
@@ -149,36 +157,12 @@ const model = {
_applyShowUtils(value) {
- // For original messages
+ localStorage.setItem("showUtils", value);
css.toggleCssProperty(
- ".message-util",
+ ".process-step.message-util",
"display",
value ? undefined : "none"
);
- // For process steps - toggle class on all existing elements
- const chatHistory = document.getElementById("chat-history");
- if (chatHistory) {
- const groups = chatHistory.children;
- for (let gi = groups.length - 1; gi >= 0; gi -= 1) {
- const messageGroup = groups[gi];
- const containers = messageGroup.children;
- for (let ci = containers.length - 1; ci >= 0; ci -= 1) {
- const container = containers[ci];
- if (!container.classList.contains("has-process-group")) continue;
- const processGroup = container.querySelector(".process-group");
- if (!processGroup) continue;
- const steps = processGroup.getElementsByClassName("process-step");
- for (let si = 0; si < steps.length; si += 1) {
- const step = steps[si];
- if (step.classList.contains("message-util")) {
- step.classList.toggle("show-util", value);
- }
- }
- }
- }
- }
- // Re-apply detail mode to reset current visible step
- applyModeSteps(this._detailMode, this._showUtils);
},
_applyChatWidth(value) {
diff --git a/webui/css/messages.css b/webui/css/messages.css
index 9fc8d6437..176ae987d 100644
--- a/webui/css/messages.css
+++ b/webui/css/messages.css
@@ -72,8 +72,9 @@
.message.message-user {
text-align: end;
- margin-bottom: var(--spacing-md);
+ /* margin-bottom: var(--spacing-md); */
width: 100%;
+ margin-bottom: -2.5rem; /* compensate for action buttons */
}
.message-user .message-user-heading {
@@ -112,6 +113,7 @@
color: var(--color-text);
}
+
/* .light-mode .message-user .message-text pre {
color: #2e2e2e;
} */
@@ -511,9 +513,9 @@
/* Utility Classes */
.kvps-key {
font-weight: 500;
- font-size: var(--font-size-small);
+ font-size: var(--font-size-xs);
/* min-width: 7em; */
- max-width: 10em;
+ width: 4em;
text-align: right;
}
@@ -524,7 +526,7 @@
.kvps-val {
/* margin: 0.65rem 0 0.65rem 0.4rem; */
white-space: pre-wrap;
- font-size: var(--font-size-small);
+ font-size: var(--font-size-xs);
}
.kvps-img {
diff --git a/webui/index.css b/webui/index.css
index 46574b8f2..9b38e05d0 100644
--- a/webui/index.css
+++ b/webui/index.css
@@ -69,6 +69,7 @@
--spacing-lg: 2rem;
/* Font sizes */
+ --font-size-xs: 0.7rem;
--font-size-small: 0.8rem;
--font-size-smaller: 0.9rem;
--font-size-normal: 1rem;
diff --git a/webui/index.js b/webui/index.js
index 3f11e9e9b..811b0a9d3 100644
--- a/webui/index.js
+++ b/webui/index.js
@@ -66,9 +66,9 @@ export async function sendMessage() {
: "";
// Render user message with attachments
- setMessage({ id: messageId, type: "user", heading, content: message, kvps: {
+ setMessages([{ id: messageId, type: "user", heading, content: message, kvps: {
// attachments: attachmentsWithUrls, // skip here, let the backend properly log them
- }});
+ }}]);
// sleep one frame to render the message before upload starts - better UX
sleep(0);
@@ -200,8 +200,8 @@ async function updateUserTime() {
updateUserTime();
setInterval(updateUserTime, 1000);
-function setMessage(...params) {
- const result = msgs.setMessage(...params);
+function setMessages(logs) {
+ const result = msgs.setMessages(logs);
const chatHistoryEl = document.getElementById("chat-history");
if (preferencesStore.autoScroll && chatHistoryEl) {
chatHistoryEl.scrollTop = chatHistoryEl.scrollHeight;
@@ -316,9 +316,8 @@ export async function poll() {
if (lastLogVersion != response.log_version) {
updated = true;
- for (const log of response.logs) {
- setMessage(log);
- }
+ setMessages(response.logs);
+
afterMessagesUpdate(response.logs);
applyModeSteps(preferencesStore.detailMode, preferencesStore.showUtils);
}
diff --git a/webui/js/messages.js b/webui/js/messages.js
index fc5fa1217..73f247058 100644
--- a/webui/js/messages.js
+++ b/webui/js/messages.js
@@ -15,65 +15,66 @@ const STEP_COLLAPSE_DELAY_MS = 3000;
// Delay before collapsing the last step when processing completes
const FINAL_STEP_COLLAPSE_DELAY_MS = 3000;
-// Tool-specific status codes (fallback for tool steps)
-const TOOL_STATUS_CODES = {
- call_subordinate: "SUB",
- search_engine: "WEB",
- a2a_chat: "A2A",
- behaviour_adjustment: "ADJ",
- document_query: "DOC",
- vision_load: "EYE",
- notify_user: "NTF",
- scheduler: "SCH",
- unknown: "UNK",
- memory_save: "MEM",
- memory_load: "MEM",
- memory_forget: "MEM",
- memory_delete: "MEM"
-};
+// // Tool-specific status codes (fallback for tool steps)
+// const TOOL_STATUS_CODES = {
+// call_subordinate: "SUB",
+// search_engine: "WEB",
+// a2a_chat: "A2A",
+// behaviour_adjustment: "ADJ",
+// document_query: "DOC",
+// vision_load: "EYE",
+// notify_user: "NTF",
+// scheduler: "SCH",
+// unknown: "UNK",
+// memory_save: "MEM",
+// memory_load: "MEM",
+// memory_forget: "MEM",
+// memory_delete: "MEM",
+// };
// Tool-specific status classes (fallback for tool steps)
-const TOOL_STATUS_CLASSES = {
- call_subordinate: "status-sub"
-};
+// const TOOL_STATUS_CLASSES = {
+// call_subordinate: "status-sub",
+// };
const TYPE_STATUS_CODES = {
- agent: "GEN",
+ // agent: "GEN",
response: "END",
- tool: "USE",
- code_exe: "EXE",
- browser: "WWW",
- progress: "HLD",
- mcp: "MCP",
- subagent: "SUB",
+ // tool: "USE",
+ // code_exe: "EXE",
+ // browser: "WWW",
+ // progress: "HLD",
+ // mcp: "MCP",
+ // subagent: "SUB",
info: "INF",
hint: "HNT",
- warning: "WRN",
+ // warning: "WRN",
rate_limit: "WRN",
- error: "ERR",
- util: "UTL",
- done: "END"
+ // error: "ERR",
+ // util: "UTL",
+ done: "END",
};
const TYPE_STATUS_CLASSES = {
- agent: "status-gen",
+ // agent: "status-gen",
response: "status-end",
- tool: "status-tool",
- code_exe: "status-exe",
- browser: "status-www",
- progress: "status-wait",
- mcp: "status-mcp",
- subagent: "status-sub",
+ // tool: "status-tool",
+ // code_exe: "status-exe",
+ // browser: "status-www",
+ // progress: "status-wait",
+ // mcp: "status-mcp",
+ // subagent: "status-sub",
info: "status-inf",
hint: "status-hnt",
- warning: "status-wrn",
+ // warning: "status-wrn",
rate_limit: "status-wrn",
- error: "status-err",
- util: "status-utl",
- done: "status-end"
+ // error: "status-err",
+ // util: "status-utl",
+ done: "status-end",
};
-let chatHistory = null;
+let _chatHistory = null;
+let _massRender = false;
// handlers for log message rendering
export function getMessageHandler(type) {
@@ -113,49 +114,62 @@ export function getMessageHandler(type) {
}
}
-
/**
* Mark a process group as the active one (via .active class)
*/
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").forEach(g => {
- if (g !== group) {
- g.classList.remove("active");
- g.querySelectorAll(".step-title.shiny-text").forEach(el => el.classList.remove("shiny-text"));
- }
- });
-
+ getChatHistoryEl()
+ .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() {
// Clear all shiny step titles in process steps
- getChatHistoryEl().querySelectorAll(".process-step .step-title.shiny-text").forEach((el) => {
- el.classList.remove("shiny-text");
- });
+ getChatHistoryEl()
+ .querySelectorAll(".process-step .step-title.shiny-text")
+ .forEach((el) => {
+ el.classList.remove("shiny-text");
+ });
}
function getChatHistoryEl() {
- if(!chatHistory) chatHistory = document.getElementById("chat-history");
- return chatHistory;
+ if (!_chatHistory) _chatHistory = document.getElementById("chat-history");
+ return _chatHistory;
}
-function getLastMessageContainer() {
- const chatHistoryEl = getChatHistoryEl();
- if (!chatHistoryEl) return null;
- const lastGroup = chatHistoryEl.lastElementChild;
- if (!lastGroup) return null;
- return lastGroup.lastElementChild;
+function getLastMessageGroup() {
+ return getChatHistoryEl()?.lastElementChild;
}
-function appendToMessageGroup(messageContainer, position, forceNewGroup = false) {
+// function getLastMessageContainer() {
+// const chatHistoryEl = getChatHistoryEl();
+// if (!chatHistoryEl) return null;
+// const lastGroup = chatHistoryEl.lastElementChild;
+// if (!lastGroup) return null;
+// return lastGroup.lastElementChild;
+// }
+
+function appendToMessageGroup(
+ messageContainer,
+ position,
+ forceNewGroup = false,
+) {
const chatHistoryEl = getChatHistoryEl();
if (!chatHistoryEl) return;
@@ -164,75 +178,108 @@ function appendToMessageGroup(messageContainer, position, forceNewGroup = false)
if (!forceNewGroup && lastGroup && lastGroupType === position) {
lastGroup.appendChild(messageContainer);
- return;
+ } else {
+ const group = document.createElement("div");
+ group.classList.add("message-group", `message-group-${position}`);
+ group.setAttribute("data-group-type", position);
+ group.appendChild(messageContainer);
+ chatHistoryEl.appendChild(group);
}
-
- const group = document.createElement("div");
- group.classList.add("message-group", `message-group-${position}`);
- group.setAttribute("data-group-type", position);
- group.appendChild(messageContainer);
- chatHistoryEl.appendChild(group);
}
-function getStatusCode(type, toolName = null) {
- if (type === "tool" && toolName && TOOL_STATUS_CODES[toolName]) {
- return TOOL_STATUS_CODES[toolName];
- }
- return TYPE_STATUS_CODES[type] || type?.toUpperCase()?.slice(0, 4) || "GEN";
-}
+// function getStatusCode(type, toolName = null) {
+// if (type === "tool" && toolName && TOOL_STATUS_CODES[toolName]) {
+// return TOOL_STATUS_CODES[toolName];
+// }
+// return TYPE_STATUS_CODES[type] || type?.toUpperCase()?.slice(0, 4) || "GEN";
+// }
+
+// function getStatusClass(type, toolName = null) {
+// if (type === "tool" && toolName && TOOL_STATUS_CLASSES[toolName]) {
+// return TOOL_STATUS_CLASSES[toolName];
+// }
+// return TYPE_STATUS_CLASSES[type] || "status-gen";
+// }
+
+// /**
+// * Resolve tool name from kvps, existing attribute, or previous siblings
+// * For 'tool' type steps, inherits from preceding step if not directly available
+// */
+// function resolveToolName(type, kvps, stepElement) {
+// // Direct from kvps
+// if (kvps?.tool_name) return kvps.tool_name;
+
+// // Keep existing if present (for non-tool types during updates)
+// if (type !== "tool" && stepElement?.hasAttribute("data-tool-name")) {
+// return stepElement.getAttribute("data-tool-name");
+// }
+
+// // // Inherit from previous sibling (for tool steps)
+// // if (type === 'tool' && stepElement) {
+// // let prev = stepElement.previousElementSibling;
+// // while (prev) {
+// // if (prev.hasAttribute('data-tool-name')) {
+// // return prev.getAttribute('data-tool-name');
+// // }
+// // prev = prev.previousElementSibling;
+// // }
+// // }
+
+// return null;
+// }
-function getStatusClass(type, toolName = null) {
- if (type === "tool" && toolName && TOOL_STATUS_CLASSES[toolName]) {
- return TOOL_STATUS_CLASSES[toolName];
- }
- return TYPE_STATUS_CLASSES[type] || "status-gen";
-}
+// entrypoint called from poll/WS communication, this is how all messages are rendered and updated
+// input is raw log format
+export function setMessages(messages) {
+ // set _massRender flag for handlers to know how to behave
+ const history = getChatHistoryEl();
+ const historyEmpty = !history || history.childElementCount === 0;
+ const isLargeAppend = !historyEmpty && messages.length > 10;
+ const cutoff = isLargeAppend ? Math.max(0, messages.length - 2) : 0;
-/**
- * Resolve tool name from kvps, existing attribute, or previous siblings
- * For 'tool' type steps, inherits from preceding step if not directly available
- */
-function resolveToolName(type, kvps, stepElement) {
- // Direct from kvps
- if (kvps?.tool_name) return kvps.tool_name;
-
- // Keep existing if present (for non-tool types during updates)
- if (type !== 'tool' && stepElement?.hasAttribute('data-tool-name')) {
- return stepElement.getAttribute('data-tool-name');
+ // process messages
+ for (let i = 0; i < messages.length; i++) {
+ _massRender = historyEmpty || (isLargeAppend && i < cutoff);
+ setMessage(messages[i]);
}
-
- // // Inherit from previous sibling (for tool steps)
- // if (type === 'tool' && stepElement) {
- // let prev = stepElement.previousElementSibling;
- // while (prev) {
- // if (prev.hasAttribute('data-tool-name')) {
- // return prev.getAttribute('data-tool-name');
- // }
- // prev = prev.previousElementSibling;
- // }
- // }
-
- return null;
-}
-/**
- * Update status badge text content
- */
-function updateBadgeText(badge, newCode) {
- if (!badge) return;
- badge.textContent = newCode;
+ // reset _massRender flag
+ _massRender = false;
}
-
// entrypoint called from poll/WS communication, this is how all messages are rendered and updated
// input is raw log format
-export function setMessage({ no, id, type, heading, content, kvps, timestamp, agentno, ...additional }) {
+export function setMessage({
+ no,
+ id,
+ type,
+ heading,
+ content,
+ kvps,
+ timestamp,
+ agentno,
+ ...additional
+}) {
const handler = getMessageHandler(type);
- // prefer log ID if set to match user message created on frontend with backend updates
- return handler({ id: id || no, type, heading, content, kvps, timestamp, agentno, ...additional });
+ // prefer log ID if set to match user message created on frontend with backend updates
+ return handler({
+ id: id || no,
+ type,
+ heading,
+ content,
+ kvps,
+ timestamp,
+ agentno,
+ ...additional,
+ });
}
-function getOrCreateMessageContainer(id, position, containerClasses = [], forceNewGroup = false) {
+function getOrCreateMessageContainer(
+ id,
+ position,
+ containerClasses = [],
+ forceNewGroup = false,
+) {
let container = document.getElementById(`message-${id}`);
if (!container) {
container = document.createElement("div");
@@ -251,27 +298,35 @@ function getOrCreateMessageContainer(id, position, containerClasses = [], forceN
return container;
}
-function getLastProcessGroup() {
- const lastContainer = getLastMessageContainer();
+function getLastProcessGroup(allowCompleted = true) {
+ const lastContainer = getLastMessageGroup();
if (!lastContainer) return null;
- if (!lastContainer.classList.contains("has-process-group")) return null;
- const group = lastContainer.querySelector(".process-group");
- if (!group || group.classList.contains("process-group-completed")) {
+ 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;
- }
+
return group;
}
-function getOrCreateProcessGroup(id) {
- const existing = getLastProcessGroup();
- if (existing) {
- setActiveProcessGroup(existing);
- return existing;
- }
+function getOrCreateProcessGroup(id, allowCompleted = true) {
+ // first try direct match by ID
+ const byId = document.getElementById(`process-group-${id}`);
+ if (byId) return byId;
+ // if not found, try to find the last process group
+ const existing = getLastProcessGroup(allowCompleted);
+ if (existing) return existing;
+
+ // lastly create new
const messageContainer = document.createElement("div");
- messageContainer.id = `message-${id}`;
- messageContainer.classList.add("message-container", "ai-container", "has-process-group");
+ messageContainer.id = `process-group-${id}`;
+ messageContainer.classList.add(
+ "message-container",
+ "ai-container",
+ "has-process-group",
+ );
const group = createProcessGroup(id);
group.classList.add("embedded");
@@ -293,7 +348,7 @@ function buildDetailPayload(stepData) {
agentno: stepData.agentno,
toolName: stepData.toolName,
statusCode: stepData.statusCode,
- statusClass: stepData.statusClass
+ statusClass: stepData.statusClass,
};
}
@@ -304,8 +359,12 @@ function buildStepCopyContent(stepData) {
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);
+ if (key === "reasoning" || key === "finished" || key === "attachments")
+ continue;
+ const valStr =
+ typeof value === "object"
+ ? JSON.stringify(value, null, 2)
+ : String(value);
parts.push(`${key}: ${valStr}`);
}
}
@@ -315,48 +374,281 @@ function buildStepCopyContent(stepData) {
function drawProcessStep({
id,
title,
- statusClass,
- statusCode,
- kvps = null,
- detailHandler = null,
- copyContent = null,
- speakContent = null,
- type = "agent",
- heading = null,
- content = null,
- timestamp = null,
- agentno = 0,
- toolName = null,
- detailPayload = null,
+ code,
+ classes,
+ kvps,
+ content,
+ contentClasses,
+ copyText,
+ speakText,
+ log,
+ allowCompletedGroup = false,
...additional
}) {
-
- const group = getOrCreateProcessGroup(id);
+ // group and steps DOM elements
+ const group = getOrCreateProcessGroup(id, allowCompletedGroup);
+ const stepsContainer = group.querySelector(".process-steps");
const stepId = `process-step-${id}`;
- const stepData = {
- id,
- type,
- title,
- heading,
- content,
- kvps,
- timestamp,
- agentno,
- toolName,
- statusCode,
- statusClass
- };
-
let step = document.getElementById(stepId);
- const detailData = detailPayload || buildDetailPayload(stepData);
- const copyText = copyContent ?? buildStepCopyContent(stepData);
- const speakText = speakContent ?? copyText;
- if (step)
- updateProcessStep(step, stepData, detailData, copyText, speakText, detailHandler);
- else
- step = addProcessStep(group, stepData, detailData, copyText, speakText, detailHandler);
- return step;
+ const isNewStep = !step;
+ const isGroupCompleted = group.classList.contains("process-group-completed");
+
+ // const detailData = buildDetailPayload(stepData);
+ // const speakText = speakContent ?? copyText;
+ // const speakText = speakContent ?? copyText;
+
+ if (isNewStep) {
+ // create the base DOM element for the step
+ step = document.createElement("div");
+ step.id = stepId;
+ step.classList.add("process-step");
+
+ // set data attributes of the step
+ step.setAttribute("data-log-type", log.type);
+ step.setAttribute("data-step-id", id);
+ step.setAttribute("data-agent-number", log.agentno);
+
+ // apply step classes
+ if (classes) step.classList.add(...classes);
+
+ // if (toolName) {
+ // step.setAttribute("data-tool-name", toolName);
+ // }
+ // timestamp data
+ // if (log.timestamp) {
+ // step.setAttribute("data-timestamp", log.timestamp);
+
+ // if (!group.getAttribute("data-start-timestamp")) {
+ // group.setAttribute("data-start-timestamp", log.timestamp);
+ // const timeMetricEl = group.querySelector(".metric-time .metric-value");
+ // if (timeMetricEl) {
+ // const date = new Date(parseFloat(timestamp) * 1000);
+ // const hours = String(date.getHours()).padStart(2, "0");
+ // const minutes = String(date.getMinutes()).padStart(2, "0");
+ // timeMetricEl.textContent = `${hours}:${minutes}`;
+ // }
+ // }
+ // }
+
+ // // create step detail container
+ // detail = document.createElement("div");
+ // detail.classList.add("process-step-detail");
+ // detailContent = document.createElement("div")
+ // detailContent.classList.add("process-step-detail-content")
+
+ // const stepActionBtns = document.createElement("div");
+ // stepActionBtns.classList.add("step-detail-actions");
+ // detail.appendChild(stepActionBtns);
+ // step.appendChild(detail);
+
+ let appendTarget = stepsContainer;
+ const parentStep = findParentDelegationStep(group, log.agentno);
+ if (parentStep) {
+ appendTarget = getNestedContainer(parentStep);
+ step.classList.add("nested-step");
+ }
+
+ // remove any existing shiny-text from group
+ group
+ .querySelectorAll(".process-step .step-title.shiny-text")
+ .forEach((el) => {
+ el.classList.remove("shiny-text");
+ });
+
+ // 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");
+
+ //expand all
+ if (detailMode === "expanded") {
+ step.classList.add("step-expanded");
+ // expand current step and schedule collapse of previous
+ } else if (detailMode === "current") {
+ if (isActiveGroup && !isGroupCompleted) {
+ step.classList.add("step-expanded");
+ const allExpandedSteps = stepsContainer.querySelectorAll(
+ ".process-step.step-expanded",
+ );
+ allExpandedSteps.forEach((expandedStep) => {
+ if (expandedStep.id !== stepId) {
+ scheduleStepCollapse(expandedStep, STEP_COLLAPSE_DELAY_MS);
+ }
+ });
+ }
+ }
+ }
+
+ // is step expanded?
+ const isExpanded = step.classList.contains("step-expanded");
+
+ // create step header
+ const stepHeader = ensureChild(
+ step,
+ ".process-step-header",
+ "div",
+ "process-step-header",
+ );
+
+ // create step detail
+ const stepDetail = ensureChild(
+ step,
+ ".process-step-detail",
+ "div",
+ "process-step-detail",
+ );
+ const stepDetailScroll = ensureChild(
+ stepDetail,
+ ".process-step-detail-scroll",
+ "div",
+ "process-step-detail-scroll",
+ );
+
+ // create action buttons
+ const stepActionBtns = ensureChild(
+ stepDetail,
+ ".step-detail-actions",
+ "div",
+ "step-detail-actions",
+ );
+
+ // else {
+ // if (timestamp && !step.hasAttribute("data-timestamp")) {
+ // step.setAttribute("data-timestamp", timestamp);
+ // }
+ // if (agentno !== undefined) {
+ // step.setAttribute("data-agent-number", agentno);
+ // }
+ // }
+
+ // const toolNameToUse = resolveToolName(type, kvps, step) || toolName;
+ // if (toolNameToUse) {
+ // step.setAttribute("data-tool-name", toolNameToUse);
+ // }
+
+ if (!stepHeader.hasAttribute("data-expand-handler")) {
+ stepHeader.setAttribute("data-expand-handler", "true");
+ stepHeader.addEventListener("click", (e) => {
+ e.stopPropagation();
+ cancelStepCollapse(step);
+ step.classList.toggle("step-expanded");
+ if (step.classList.contains("step-expanded")) {
+ step.setAttribute("data-user-pinned", "true");
+ } else {
+ step.removeAttribute("data-user-pinned");
+ }
+ });
+ }
+
+ // header row - expand icon
+ ensureChild(stepHeader, ".step-expand-icon", "span", "step-expand-icon");
+
+ // header row - status badge
+ const badge = ensureChild(stepHeader, ".step-badge", "span", "step-badge");
+
+ // set code class if changed
+ const prevCode = step.getAttribute("data-step-code");
+ if (prevCode !== code) {
+ if (prevCode) step.classList.remove(prevCode);
+ step.setAttribute("data-step-code", code);
+ step.classList.add(code);
+ step.querySelector(".step-badge").textContent = code;
+ badge.innerText = code;
+ }
+
+ // header row - title
+ const titleEl = ensureChild(stepHeader, ".step-title", "span", "step-title");
+ titleEl.textContent = title;
+
+ // const detail = ensureChild(step, ".process-step-detail", "div", "process-step-detail");
+ // const detailContent = ensureChild(
+ // detail,
+ // ".process-step-detail-content",
+ // "div",
+ // "process-step-detail-content",
+ // );
+
+ // let skipFullRender = false;
+
+ // const terminal = stepDetailContent.querySelector(".terminal-output");
+ // const scroller = terminal ? new Scroller(terminal) : null;
+
+ // if (type === "browser" && kvps?.screenshot) {
+ // const existingImg = detailContent.querySelector(".screenshot-img");
+ // const newSrc = kvps.screenshot.replace("img://", "/image_get?path=");
+ // if (existingImg) {
+ // if (!existingImg.src.endsWith(newSrc.split("?path=")[1])) {
+ // existingImg.src = newSrc;
+ // }
+ // skipFullRender = true;
+ // }
+ // }
+
+ // if (!skipFullRender) {
+ // renderStepDetailContent(detailContent, content, kvps, type);
+
+ // const newTerminal = detailContent.querySelector(".terminal-output");
+ // if (newTerminal && scroller?.wasAtBottom) {
+ // newTerminal.scrollTop = newTerminal.scrollHeight;
+ // }
+ // }
+
+ const detailScroller = new Scroller(stepDetailScroll); // scroller for step detail content
+
+ // update KVPs of the step detail
+ const kvpsTable = drawKvpsIncremental(stepDetailScroll, kvps);
+
+ // update content
+ const stepDetailContent = ensureChild(
+ stepDetailScroll,
+ ".process-step-detail-content",
+ "p",
+ "process-step-detail-content",
+ ...(contentClasses || []),
+ );
+ stepDetailContent.textContent = content;
+
+ // const detailDataToUse =
+ // detailData ||
+ // buildDetailPayload({
+ // ...stepData,
+ // toolName: toolNameToUse,
+ // statusCode: resolvedStatusCode,
+ // statusClass: resolvedStatusClass,
+ // });
+
+ // const stepActions = ensureChild(detail, ".step-detail-actions", "div", "step-detail-actions");
+ addActionButtonsToElement(stepActionBtns, {
+ detailPayload: {}, // detailDataToUse,
+ onViewDetails: null,
+ copyContent: copyText,
+ speakContent: speakText,
+ });
+
+ if (isExpanded && !isMassRender()) detailScroller.reApplyScroll(); // reapply scroll position (autoscroll if bottom) - only when expanded already and not
+
+ updateProcessGroupHeader(group);
+
+ if (isNewStep && !isGroupCompleted) {
+ titleEl.classList.add("shiny-text");
+ }
+
+ // return anything useful
+ return {
+ step,
+ detail: stepDetail,
+ content: stepDetailContent,
+ contentScroller: detailScroller,
+ kvpsTable,
+ actionButtons: stepActionBtns,
+ isExpanded,
+ };
}
function drawStandaloneMessage(id, heading, content, options = {}) {
@@ -371,22 +663,39 @@ function drawStandaloneMessage(id, heading, content, options = {}) {
latex = false,
kvps = null,
copyContent = null,
- speakContent = null
+ speakContent = null,
} = options;
- const container = getOrCreateMessageContainer(id, position, containerClasses, forceNewGroup);
- const messageDiv = _drawMessage(container, heading, content, kvps, messageClasses, contentClasses, markdown, latex, mainClass);
+ const container = getOrCreateMessageContainer(
+ id,
+ position,
+ containerClasses,
+ forceNewGroup,
+ );
+ const messageDiv = _drawMessage({
+ messageContainer: container,
+ heading,
+ content,
+ kvps,
+ messageClasses,
+ contentClasses,
+ markdown,
+ latex,
+ mainClass,
+ });
const copyText = copyContent ?? content ?? "";
const speakText = speakContent ?? copyText;
- addActionButtonsToElement(messageDiv, { copyContent: copyText, speakContent: speakText });
+ addActionButtonsToElement(messageDiv, {
+ copyContent: copyText,
+ speakContent: speakText,
+ });
return container;
}
-
// draw a message with a specific type
-export function _drawMessage(
+export function _drawMessage({
messageContainer,
heading,
content,
@@ -395,8 +704,8 @@ export function _drawMessage(
contentClasses = [],
markdown = false,
latex = false,
- mainClass = ""
-) {
+ mainClass = "",
+}) {
// Find existing message div or create new one
let messageDiv = messageContainer.querySelector(".message");
if (!messageDiv) {
@@ -481,7 +790,6 @@ export function _drawMessage(
}
adjustMarkdownRender(contentDiv);
-
} else {
let preElement = bodyDiv.querySelector(".msg-content");
if (!preElement) {
@@ -502,7 +810,6 @@ export function _drawMessage(
}
spanElement.innerHTML = convertHTML(content);
-
}
} else {
// Remove content if it exists but content is empty
@@ -543,40 +850,62 @@ export function addBlankTargetsToLinks(str) {
return doc.body.innerHTML;
}
-export function drawMessageDefault({ id, heading, content, kvps = null, ...additional }) {
+export function drawMessageDefault({
+ id,
+ heading,
+ content,
+ kvps = null,
+ ...additional
+}) {
return drawStandaloneMessage(id, heading, content, {
position: "left",
containerClasses: ["ai-container"],
mainClass: "message-default",
messageClasses: ["message-ai"],
contentClasses: ["msg-json"],
- kvps
+ kvps,
});
}
-export function drawMessageAgent({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
- const title = getStepTitle(heading, kvps, type);
- const statusCode = getStatusCode(type);
- const statusClass = getStatusClass(type);
- const toolName = kvps?.tool_name || null;
- let displayKvps = { "icon://lightbulb": kvps?.thoughts, "icon://step": heading, "icon school":"dummy" }
+export function drawMessageAgent({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
+ const title = cleanStepTitle(heading);
+ let displayKvps = {};
+ if (kvps?.thoughts) displayKvps["icon://lightbulb"] = kvps.thoughts;
+ if (kvps?.step) displayKvps["icon://step"] = kvps.step;
return drawProcessStep({
id,
title,
- statusClass,
- statusCode,
+ code: "GEN",
+ codeClass: "status-gen",
+ classes: null,
kvps: displayKvps,
- type,
- heading,
- content,
- timestamp,
- agentno,
- toolName
+ copyText: kvps?.thoughts,
+ speakText: kvps?.thoughts,
+ log: arguments[0],
});
}
-export function drawMessageResponse({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
+export function drawMessageResponse({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
+ // response of subordinate agent - render as process step
if (agentno && agentno > 0) {
const title = getStepTitle(heading, kvps, type);
const statusCode = getStatusCode(type);
@@ -591,29 +920,61 @@ export function drawMessageResponse({ id, type, heading, content, kvps = null, t
heading,
content,
timestamp,
- agentno
+ agentno,
});
}
+ // response of agent 0, render as response to user
+ // get last process group or create new container (if first message)
const group = getLastProcessGroup();
- if (group) {
- markProcessGroupComplete(group, heading);
- }
-
- return drawStandaloneMessage(id, heading, content, {
- position: "left",
- forceNewGroup: true,
- containerClasses: ["ai-container"],
- mainClass: "message-agent-response",
- messageClasses: ["message-ai"],
+ let container = null;
+
+ if (group)
+ container = ensureChild(
+ group,
+ ".process-group-response",
+ "div",
+ "process-group-response",
+ );
+ else container = getOrCreateMessageContainer(id, "left");
+
+ const messageDiv = _drawMessage({
+ messageContainer: container,
+ heading: null,
+ content,
+ kvps: null,
+ messageClasses: [],
+ contentClasses: [],
markdown: true,
- latex: true
+ latex: true,
+ mainClass: "message-agent-response",
});
-}
+ // const copyText = copyContent ?? content ?? "";
+ // const speakText = speakContent ?? copyText;
+ // addActionButtonsToElement(messageDiv, {
+ // copyContent: copyText,
+ // speakContent: speakText,
+ // });
+
+ if (group) updateProcessGroupHeader(group);
+
+ return container;
+}
-export function drawMessageUser({ id, heading, content, kvps = null, ...additional }) {
- const messageContainer = getOrCreateMessageContainer(id, "right", ["user-container"], true);
+export function drawMessageUser({
+ id,
+ heading,
+ content,
+ kvps = null,
+ ...additional
+}) {
+ const messageContainer = getOrCreateMessageContainer(
+ id,
+ "right",
+ ["user-container"],
+ true,
+ );
// Find existing message div or create new one
let messageDiv = messageContainer.querySelector(".message");
@@ -653,7 +1014,7 @@ export function drawMessageUser({ id, heading, content, kvps = null, ...addition
messageDiv.appendChild(attachmentsContainer);
}
// Important: Clear existing attachments to re-render, preventing duplicates on update
- attachmentsContainer.innerHTML = "";
+ attachmentsContainer.innerHTML = "";
kvps.attachments.forEach((attachment) => {
const attachmentDiv = document.createElement("div");
@@ -717,138 +1078,220 @@ export function drawMessageUser({ id, heading, content, kvps = null, ...addition
}
// Add action buttons below text and attachments (hover for pointer, always for touch - via CSS)
- addActionButtonsToElement(messageDiv, { copyContent: content || "", speakContent: content || "" });
+ addActionButtonsToElement(messageDiv, {
+ copyContent: content || "",
+ speakContent: content || "",
+ });
}
-export function drawMessageTool({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
- const toolName = kvps?.tool_name || null;
- const title = getStepTitle(heading, kvps, type);
- const statusCode = getStatusCode(type, toolName);
- const statusClass = getStatusClass(type, toolName);
+export function drawMessageTool({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
+ const title = cleanStepTitle(heading);
+ let displayKvps = { ...kvps };
return drawProcessStep({
id,
title,
- statusClass,
- statusCode,
- kvps,
- type,
- heading,
+ code: "USE",
+ codeClass: "status-tool",
+ classes: null,
+ kvps: displayKvps,
content,
- timestamp,
- agentno,
- toolName
+ // contentClasses: [],
+ copyText: content,
+ speakText: content,
+ log: arguments[0],
});
}
-export function drawMessageCodeExe({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
- const title = getStepTitle(heading, kvps, type);
- const statusCode = getStatusCode(type);
- const statusClass = getStatusClass(type);
+export function drawMessageCodeExe({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
+ let title = "Code Execution";
+ // show command at the start and end
+ if (
+ type === "code_exe" &&
+ 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 {
+ // during execution show the original heading (current step)
+ title = cleanStepTitle(heading);
+ }
- return drawProcessStep({
+ // KVPS to show
+ const displayKvps = {};
+ if (kvps?.runtime) displayKvps.runtime = kvps.runtime;
+ if (kvps?.session) displayKvps.session = kvps.session;
+
+ // render the standard step
+ const stepData = drawProcessStep({
id,
title,
- statusClass,
- statusCode,
- kvps,
- type,
- heading,
+ code: "EXE",
+ codeClass: "status-exe",
+ classes: null,
+ kvps: displayKvps,
content,
- timestamp,
- agentno
+ contentClasses: ["terminal-output"],
+ copyText: content,
+ speakText: null,
+ log: arguments[0],
});
}
-export function drawMessageBrowser({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
- const title = getStepTitle(heading, kvps, type);
- const statusCode = getStatusCode(type);
- const statusClass = getStatusClass(type);
-
- return drawProcessStep({
- id,
- title,
- statusClass,
- statusCode,
- kvps,
- type,
- heading,
+export function drawMessageBrowser({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
+ const title = cleanStepTitle(heading);
+ let displayKvps = { ...kvps };
+
+ return drawProcessStep({
+ id,
+ title,
+ code: "HDL",
+ codeClass: "status-hdl",
+ classes: null,
+ kvps: displayKvps,
content,
- timestamp,
- agentno
+ // contentClasses: [],
+ copyText: content,
+ speakText: content,
+ log: arguments[0],
});
}
-export function drawMessageMcp({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
- const toolName = kvps?.tool_name || null;
- const title = getStepTitle(heading, kvps, type);
- const statusCode = getStatusCode(type, toolName);
- const statusClass = getStatusClass(type, toolName);
+export function drawMessageMcp({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
+ const title = cleanStepTitle(heading);
+ let displayKvps = { ...kvps };
return drawProcessStep({
id,
title,
- statusClass,
- statusCode,
- kvps,
- type,
- heading,
+ code: "MCP",
+ codeClass: "status-mcp",
+ classes: null,
+ kvps: displayKvps,
content,
- timestamp,
- agentno,
- toolName
+ // contentClasses: [],
+ copyText: content,
+ speakText: content,
+ log: arguments[0],
});
}
-export function drawMessageSubagent({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
- const title = getStepTitle(heading, kvps, type);
- const statusCode = getStatusCode(type);
- const statusClass = getStatusClass(type);
+export function drawMessageSubagent({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
+ const title = cleanStepTitle(heading);
+ let displayKvps = { ...kvps };
return drawProcessStep({
id,
title,
- statusClass,
- statusCode,
- kvps,
- type,
- heading,
+ code: "SUB",
+ codeClass: "status-sub",
+ classes: null,
+ kvps: displayKvps,
content,
- timestamp,
- agentno
+ // contentClasses: [],
+ copyText: content,
+ speakText: content,
+ log: arguments[0],
});
}
-
-export function drawMessageInfo({ id, heading, content, kvps = null, ...additional }) {
+export function drawMessageInfo({
+ id,
+ heading,
+ content,
+ kvps = null,
+ ...additional
+}) {
return drawStandaloneMessage(id, heading, content, {
position: "mid",
containerClasses: ["ai-container", "center-container"],
mainClass: "message-info",
- kvps
+ kvps,
});
}
-export function drawMessageUtil({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
- const title = getStepTitle(heading, kvps, type);
- const statusCode = getStatusCode(type);
- const statusClass = getStatusClass(type);
+export function drawMessageUtil({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
+ const title = cleanStepTitle(heading);
return drawProcessStep({
id,
title,
- statusClass,
- statusCode,
+ code: "UTL",
+ codeClass: "status-utl",
+ classes: ["message-util"],
kvps,
- type,
- heading,
- content,
- timestamp,
- agentno
+ copyText: null,
+ speakText: null,
+ log: arguments[0],
+ allowCompletedGroup: true,
});
}
-export function drawMessageHint({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
+export function drawMessageHint({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
const title = getStepTitle(heading, kvps, type);
const statusCode = getStatusCode(type);
const statusClass = getStatusClass(type);
@@ -863,167 +1306,227 @@ export function drawMessageHint({ id, type, heading, content, kvps = null, times
heading,
content,
timestamp,
- agentno
+ agentno,
});
}
-export function drawMessageProgress({ id, type, heading, content, kvps = null, timestamp = null, agentno = 0, ...additional }) {
- const title = getStepTitle(heading, kvps, type);
- const statusCode = getStatusCode(type);
- const statusClass = getStatusClass(type);
+export function drawMessageProgress({
+ id,
+ type,
+ heading,
+ content,
+ kvps = null,
+ timestamp = null,
+ agentno = 0,
+ ...additional
+}) {
+ const title = cleanStepTitle(heading);
+ let displayKvps = { ...kvps };
return drawProcessStep({
id,
title,
- statusClass,
- statusCode,
- kvps,
- type,
- heading,
+ code: "HDL",
+ codeClass: "status-hdl",
+ classes: null,
+ kvps: displayKvps,
content,
- timestamp,
- agentno
+ // contentClasses: [],
+ // copyText: kvps?.thoughts,
+ // speakText: kvps?.thoughts,
+ log: arguments[0],
});
}
-export function drawMessageWarning({ id, heading, content, kvps = null, ...additional }) {
+export function drawMessageWarning({
+ id,
+ heading,
+ content,
+ kvps = null,
+ ...additional
+}) {
+ const title = cleanStepTitle(heading);
+ let displayKvps = { ...kvps };
+
+ //TODO: if process group is running, append there instead
+ // return drawProcessStep({
+ // id,
+ // title,
+ // code: "WRN",
+ // codeClass: "status-wrn",
+ // classes: null,
+ // kvps: displayKvps,
+ // content,
+ // // contentClasses: [],
+ // copyText: content,
+ // speakText: content,
+ // log: arguments[0],
+ // });
return drawStandaloneMessage(id, heading, content, {
position: "mid",
containerClasses: ["ai-container", "center-container"],
mainClass: "message-warning",
- kvps
+ kvps,
});
}
-export function drawMessageError({ id, heading, content, kvps = null, ...additional }) {
- const messageContainer = getOrCreateMessageContainer(id, "mid", ["ai-container", "center-container"]);
-
- // Create or get the message div
- let messageDiv = messageContainer.querySelector(".message");
- if (!messageDiv) {
- messageDiv = document.createElement("div");
- messageDiv.classList.add("message", "message-error-group");
- messageContainer.appendChild(messageDiv);
- }
-
- // Check if error group already exists
- let errorGroup = messageDiv.querySelector(".error-group");
- if (!errorGroup) {
- errorGroup = document.createElement("div");
- errorGroup.classList.add("error-group");
- errorGroup.setAttribute("data-error-id", id);
-
- // Create header (clickable for expand/collapse)
- const header = document.createElement("div");
- header.classList.add("error-group-header");
-
- // Expand icon (triangle)
- const expandIcon = document.createElement("span");
- expandIcon.classList.add("expand-icon");
- header.appendChild(expandIcon);
-
- // Status badge (before title)
- const badge = document.createElement("span");
- badge.classList.add("status-badge", "status-err");
- badge.textContent = "ERR";
- header.appendChild(badge);
-
- // Title
- const title = document.createElement("span");
- title.classList.add("error-title");
- title.textContent = "Error";
- header.appendChild(title);
-
- // Subtitle (short error description)
- const subtitle = document.createElement("span");
- subtitle.classList.add("error-subtitle");
- header.appendChild(subtitle);
-
- // Click handler for expand/collapse
- header.addEventListener("click", () => {
- errorGroup.classList.toggle("expanded");
- });
-
- errorGroup.appendChild(header);
-
- // Create content container (collapsible)
- const contentWrapper = document.createElement("div");
- contentWrapper.classList.add("error-group-content");
-
- const contentInner = document.createElement("div");
- contentInner.classList.add("error-content-inner");
- contentWrapper.appendChild(contentInner);
-
- errorGroup.appendChild(contentWrapper);
- messageDiv.appendChild(errorGroup);
-
- // Check detail mode and expand if needed
- const detailMode = preferencesStore.detailMode || "current";
- if (detailMode === "current" || detailMode === "expanded") {
- errorGroup.classList.add("expanded");
- }
- }
-
- // Update subtitle with short error description
- const subtitle = errorGroup.querySelector(".error-subtitle");
- if (subtitle) {
- // Extract short description from heading or content
- let shortDesc = "";
- // Skip if heading is just "Error" (redundant with title)
- if (heading && heading.trim() && heading.trim().toLowerCase() !== "error") {
- shortDesc = heading.trim();
- }
- // If no useful heading, try to extract from content
- if (!shortDesc && content && content.trim()) {
- const lines = content.trim().split("\n");
- // Look for the error line (usually last meaningful line or one matching ErrorType: pattern)
- for (let i = lines.length - 1; i >= 0; i--) {
- const line = lines[i].trim();
- if (line && /^[\w\.]+Error[:\s]/.test(line)) {
- shortDesc = line;
- break;
- }
- }
- // Fallback to first non-empty line if no error pattern found
- if (!shortDesc) {
- for (const line of lines) {
- if (line.trim() && !line.startsWith("Traceback")) {
- shortDesc = line.trim();
- break;
- }
- }
- }
- }
- // Truncate if too long
- if (shortDesc.length > 100) {
- shortDesc = shortDesc.substring(0, 97) + "...";
- }
- subtitle.textContent = shortDesc;
- subtitle.title = shortDesc; // Full text on hover
- }
-
- // Update content (full callstack)
- const contentInner = errorGroup.querySelector(".error-content-inner");
- if (contentInner && content) {
- contentInner.innerHTML = "";
-
- // Create pre element for callstack/content
- const pre = document.createElement("pre");
- pre.classList.add("error-callstack");
- pre.textContent = content;
- contentInner.appendChild(pre);
-
- // Add action buttons for copy functionality
- addActionButtonsToElement(contentInner, { copyContent: content, speakContent: content });
- }
-
- messageContainer.classList.add("center-container");
+export function drawMessageError({
+ id,
+ heading,
+ content,
+ kvps = null,
+ ...additional
+}) {
+ return drawStandaloneMessage(id, heading, content, {
+ position: "mid",
+ containerClasses: ["ai-container", "center-container"],
+ mainClass: "message-error",
+ kvps,
+ });
}
+// export function drawMessageError({
+// id,
+// heading,
+// content,
+// kvps = null,
+// ...additional
+// }) {
+// const messageContainer = getOrCreateMessageContainer(id, "mid", [
+// "ai-container",
+// "center-container",
+// ]);
+
+// // Create or get the message div
+// let messageDiv = messageContainer.querySelector(".message");
+// if (!messageDiv) {
+// messageDiv = document.createElement("div");
+// messageDiv.classList.add("message", "message-error-group");
+// messageContainer.appendChild(messageDiv);
+// }
+
+// // Check if error group already exists
+// let errorGroup = messageDiv.querySelector(".error-group");
+// if (!errorGroup) {
+// errorGroup = document.createElement("div");
+// errorGroup.classList.add("error-group");
+// errorGroup.setAttribute("data-error-id", id);
+
+// // Create header (clickable for expand/collapse)
+// const header = document.createElement("div");
+// header.classList.add("error-group-header");
+
+// // Expand icon (triangle)
+// const expandIcon = document.createElement("span");
+// expandIcon.classList.add("expand-icon");
+// header.appendChild(expandIcon);
+
+// // Status badge (before title)
+// const badge = document.createElement("span");
+// badge.classList.add("step-badge", "status-err");
+// badge.textContent = "ERR";
+// header.appendChild(badge);
+
+// // Title
+// const title = document.createElement("span");
+// title.classList.add("error-title");
+// title.textContent = "Error";
+// header.appendChild(title);
+
+// // Subtitle (short error description)
+// const subtitle = document.createElement("span");
+// subtitle.classList.add("error-subtitle");
+// header.appendChild(subtitle);
+
+// // Click handler for expand/collapse
+// header.addEventListener("click", () => {
+// errorGroup.classList.toggle("expanded");
+// });
+
+// errorGroup.appendChild(header);
+
+// // Create content container (collapsible)
+// const contentWrapper = document.createElement("div");
+// contentWrapper.classList.add("error-group-content");
+
+// const contentInner = document.createElement("div");
+// contentInner.classList.add("error-content-inner");
+// contentWrapper.appendChild(contentInner);
+
+// errorGroup.appendChild(contentWrapper);
+// messageDiv.appendChild(errorGroup);
+
+// // Check detail mode and expand if needed
+// const detailMode = preferencesStore.detailMode || "current";
+// if (detailMode === "current" || detailMode === "expanded") {
+// errorGroup.classList.add("expanded");
+// }
+// }
+
+// // Update subtitle with short error description
+// const subtitle = errorGroup.querySelector(".error-subtitle");
+// if (subtitle) {
+// // Extract short description from heading or content
+// let shortDesc = "";
+// // Skip if heading is just "Error" (redundant with title)
+// if (heading && heading.trim() && heading.trim().toLowerCase() !== "error") {
+// shortDesc = heading.trim();
+// }
+// // If no useful heading, try to extract from content
+// if (!shortDesc && content && content.trim()) {
+// const lines = content.trim().split("\n");
+// // Look for the error line (usually last meaningful line or one matching ErrorType: pattern)
+// for (let i = lines.length - 1; i >= 0; i--) {
+// const line = lines[i].trim();
+// if (line && /^[\w\.]+Error[:\s]/.test(line)) {
+// shortDesc = line;
+// break;
+// }
+// }
+// // Fallback to first non-empty line if no error pattern found
+// if (!shortDesc) {
+// for (const line of lines) {
+// if (line.trim() && !line.startsWith("Traceback")) {
+// shortDesc = line.trim();
+// break;
+// }
+// }
+// }
+// }
+// // Truncate if too long
+// if (shortDesc.length > 100) {
+// shortDesc = shortDesc.substring(0, 97) + "...";
+// }
+// subtitle.textContent = shortDesc;
+// subtitle.title = shortDesc; // Full text on hover
+// }
+
+// // Update content (full callstack)
+// const contentInner = errorGroup.querySelector(".error-content-inner");
+// if (contentInner && content) {
+// contentInner.innerHTML = "";
+
+// // Create pre element for callstack/content
+// const pre = document.createElement("pre");
+// pre.classList.add("error-callstack");
+// pre.textContent = content;
+// contentInner.appendChild(pre);
+
+// // Add action buttons for copy functionality
+// addActionButtonsToElement(contentInner, {
+// copyContent: content,
+// speakContent: content,
+// });
+// }
+
+// messageContainer.classList.add("center-container");
+// }
+
function drawKvpsIncremental(container, kvps, latex) {
+ // existing KVPS table
+ let table = container.querySelector(".msg-kvps");
if (kvps) {
- // Find existing table or create new one
- let table = container.querySelector(".msg-kvps");
+ // create table if not found
if (!table) {
table = document.createElement("table");
table.classList.add("msg-kvps");
@@ -1033,7 +1536,9 @@ function drawKvpsIncremental(container, kvps, latex) {
// Get all current rows for comparison
let existingRows = table.querySelectorAll(".kvps-row");
// Filter out reasoning
- const kvpEntries = Object.entries(kvps).filter(([key]) => key !== "reasoning");
+ const kvpEntries = Object.entries(kvps).filter(
+ ([key]) => key !== "reasoning",
+ );
// Update or create rows as needed
kvpEntries.forEach(([key, value], index) => {
@@ -1065,33 +1570,26 @@ function drawKvpsIncremental(container, kvps, latex) {
let td = row.cells[1];
if (!td) {
td = row.insertCell(1);
- }
-
- let tdiv = td.querySelector(".kvps-val");
- if (!tdiv) {
- tdiv = document.createElement("div");
- tdiv.classList.add("kvps-val");
- td.appendChild(tdiv);
+ td.classList.add("kvps-val");
}
// reapply scroll position or autoscroll
- const scroller = new Scroller(tdiv);
+ // no inner scrolling for kvps anymore
+ // const scroller = new Scroller(td);
// Clear and rebuild content (for now - could be optimized further)
- tdiv.innerHTML = "";
-
- // addActionButtonsToElement(tdiv);
+ td.innerHTML = "";
if (Array.isArray(value)) {
for (const item of value) {
- addValue(item, tdiv);
+ addValue(item, td);
}
} else {
- addValue(value, tdiv);
+ addValue(value, td);
}
// reapply scroll position or autoscroll
- scroller.reApplyScroll();
+ // scroller.reApplyScroll();
});
// Remove extra rows if we have fewer kvps now
@@ -1117,18 +1615,9 @@ function drawKvpsIncremental(container, kvps, latex) {
imageViewerStore.open(imgElement.src, { refreshInterval: 1000 });
});
} else {
- // const pre = document.createElement("pre");
const span = document.createElement("span");
span.innerHTML = convertHTML(value);
- // pre.appendChild(span);
- // tdiv.appendChild(pre);
- tdiv.appendChild(span)
-
- // Add action buttons to the row
- // const row = tdiv.closest(".kvps-row");
- // if (row) {
- // addActionButtonsToElement(pre);
- // }
+ tdiv.appendChild(span);
// KaTeX rendering for markdown
if (latex) {
@@ -1142,11 +1631,10 @@ function drawKvpsIncremental(container, kvps, latex) {
}
} else {
// Remove table if kvps is null/empty
- const existingTable = container.querySelector(".msg-kvps");
- if (existingTable) {
- existingTable.remove();
- }
+ if (table) existingTable.remove();
+ return null;
}
+ return table;
}
function convertToTitleCase(str) {
@@ -1162,17 +1650,22 @@ function convertToTitleCase(str) {
* Clean text value by removing standalone bracket lines and trimming
* Handles both strings and arrays (filters out bracket-only items)
*/
-function cleanTextValue(value) {
- if (Array.isArray(value)) {
- return value
- .filter(item => item && String(item).trim() && !/^[\[\]]$/.test(String(item).trim()))
- .join("\n");
- }
- if (typeof value === "object" && value !== null) {
- return JSON.stringify(value, null, 2);
- }
- return String(value).replace(/^\s*[\[\]]\s*$/gm, "").trim();
-}
+// function cleanTextValue(value) {
+// if (Array.isArray(value)) {
+// return value
+// .filter(
+// (item) =>
+// item && String(item).trim() && !/^[\[\]]$/.test(String(item).trim()),
+// )
+// .join("\n");
+// }
+// if (typeof value === "object" && value !== null) {
+// return JSON.stringify(value, null, 2);
+// }
+// return String(value)
+// .replace(/^\s*[\[\]]\s*$/gm, "")
+// .trim();
+// }
function convertImageTags(content) {
// Regular expression to match <image> tags and extract base64 content
@@ -1183,7 +1676,7 @@ function convertImageTags(content) {
imageTagRegex,
(match, base64Content) => {
return `<img src="data:image/jpeg;base64,${base64Content}" alt="Image Attachment" style="max-width: 250px !important;"/>`;
- }
+ },
);
return updatedContent;
@@ -1209,7 +1702,7 @@ function convertFilePaths(str) {
export function convertIcons(str) {
return str.replace(
/icon:\/\/([a-zA-Z0-9_]+)/g,
- '<span class="icon material-symbols-outlined">$1</span>'
+ '<span class="icon material-symbols-outlined">$1</span>',
);
}
@@ -1243,7 +1736,7 @@ function convertPathsToLinks(str) {
const suffix = `(?<!\\.)`;
const pathRegex = new RegExp(
`(?<=${prefix})\\/${folder}*${file}${suffix}`,
- "g"
+ "g",
);
// skip paths inside html tags, like <img src="/path/to/image">
@@ -1283,7 +1776,10 @@ function adjustMarkdownRender(element) {
link.href = img.src;
img.parentNode.insertBefore(link, img);
link.appendChild(img);
- link.onclick = (e) => (e.preventDefault(), imageViewerStore.open(img.src, { name: img.alt || "Image" }));
+ link.onclick = (e) => (
+ e.preventDefault(),
+ imageViewerStore.open(img.src, { name: img.alt || "Image" })
+ );
});
}
@@ -1306,14 +1802,6 @@ class Scroller {
}
}
-// ============================================
-// Process Group Embedding Functions
-// ============================================
-
-// ============================================
-// Process Group Functions
-// ============================================
-
/**
* Create a new collapsible process group
*/
@@ -1323,20 +1811,20 @@ function createProcessGroup(id) {
group.id = groupId;
group.classList.add("process-group");
group.setAttribute("data-group-id", groupId);
-
+
// Determine initial expansion state from current detail mode
const initiallyExpanded = preferencesStore.detailMode !== "collapsed";
if (initiallyExpanded) {
- group.classList.add('expanded');
+ group.classList.add("expanded");
}
-
+
// Create header
const header = document.createElement("div");
header.classList.add("process-group-header");
header.innerHTML = `
<span class="expand-icon"></span>
<span class="group-title">Processing...</span>
- <span class="status-badge status-gen group-status">GEN</span>
+ <span class="step-badge GEN">GEN</span>
<span class="group-metrics">
<span class="metric-time" title="Start time"><span class="material-symbols-outlined">schedule</span><span class="metric-value">--:--</span></span>
<span class="metric-steps" title="Steps"><span class="material-symbols-outlined">footprint</span><span class="metric-value">0</span></span>
@@ -1344,25 +1832,25 @@ function createProcessGroup(id) {
<span class="metric-duration" title="Duration"><span class="material-symbols-outlined">timer</span><span class="metric-value">0s</span></span>
</span>
`;
-
+
// Add click handler for expansion
header.addEventListener("click", () => {
group.classList.toggle("expanded");
});
-
+
group.appendChild(header);
-
+
// Create content container
const content = document.createElement("div");
content.classList.add("process-group-content");
-
+
// Create steps container
const steps = document.createElement("div");
steps.classList.add("process-steps");
content.appendChild(steps);
-
+
group.appendChild(content);
-
+
return group;
}
@@ -1371,21 +1859,21 @@ function createProcessGroup(id) {
*/
function getNestedContainer(parentStep) {
let nestedContainer = parentStep.querySelector(".process-nested-container");
-
+
if (!nestedContainer) {
// Create new container
nestedContainer = document.createElement("div");
nestedContainer.classList.add("process-nested-container");
-
+
// Create inner wrapper for animation support
const innerWrapper = document.createElement("div");
innerWrapper.classList.add("process-nested-inner");
nestedContainer.appendChild(innerWrapper);
-
+
parentStep.appendChild(nestedContainer);
parentStep.classList.add("has-nested-steps");
}
-
+
// Return the inner wrapper for appending steps
const innerWrapper = nestedContainer.querySelector(".process-nested-inner");
return innerWrapper || nestedContainer; // Fallback to container if wrapper missing
@@ -1400,7 +1888,7 @@ function scheduleStepCollapse(stepElement, delayMs) {
if (stepElement.hasAttribute("data-collapse-timeout-id")) {
return;
}
-
+
// Schedule the collapse
const timeoutId = setTimeout(() => {
stepElement.classList.remove("step-expanded");
@@ -1437,21 +1925,23 @@ function addStepCollapseInteractionHandlers(stepElement) {
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("step-expanded") &&
- !stepElement.hasAttribute("data-user-pinned")) {
+ if (
+ stepElement.classList.contains("step-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("step-expanded")) {
@@ -1466,353 +1956,51 @@ function addStepCollapseInteractionHandlers(stepElement) {
* Find parent delegation step for nested agents (DOM-first, reverse scan).
*/
function findParentDelegationStep(group, agentno) {
- if (!group || agentno <= 0) return null;
+ if (!group || !agentno || agentno <= 0) return null;
const steps = group.querySelectorAll(".process-step");
for (let i = steps.length - 1; i >= 0; i -= 1) {
const step = steps[i];
const stepAgent = Number(step.getAttribute("data-agent-number"));
- if (stepAgent === agentno - 1 && step.getAttribute("data-tool-name") === "call_subordinate") {
+ if (
+ stepAgent === agentno - 1 &&
+ step.getAttribute("data-log-type") === "tool" // map to the last tool call of superior agent
+ ) {
return step;
}
}
return null;
}
-/**
- * Add a step to a process group
- */
-function addProcessStep(group, stepData, detailPayload, copyContent, speakContent, detailHandler) {
- const {
- id,
- type,
- title,
- heading,
- content,
- kvps,
- timestamp,
- agentno,
- toolName,
- statusCode,
- statusClass
- } = stepData;
-
- const stepsContainer = group.querySelector(".process-steps");
- const isGroupCompleted = group.classList.contains("process-group-completed");
-
- // Create step element
- const step = document.createElement("div");
- step.id = `process-step-${id}`;
- step.classList.add("process-step");
- step.setAttribute("data-type", type);
- step.setAttribute("data-step-id", id);
- step.setAttribute("data-agent-number", agentno);
-
- if (toolName) {
- step.setAttribute("data-tool-name", toolName);
- }
-
- // Store timestamp for duration calculation
- if (timestamp) {
- step.setAttribute("data-timestamp", timestamp);
-
- // Set group start time from first log item
- if (!group.getAttribute("data-start-timestamp")) {
- group.setAttribute("data-start-timestamp", timestamp);
- // Update header time metric immediately
- const timeMetricEl = group.querySelector(".metric-time .metric-value");
- if (timeMetricEl) {
- const date = new Date(parseFloat(timestamp) * 1000);
- const hours = String(date.getHours()).padStart(2, "0");
- const minutes = String(date.getMinutes()).padStart(2, "0");
- timeMetricEl.textContent = `${hours}:${minutes}`;
- }
- }
- }
-
- // // Add message-util class for utility/info types (controlled by showUtils preference)
- // if (type === "util" || type === "info" || type === "hint") {
- // step.classList.add("message-util");
- // // Apply current preference state
- // if (preferencesStore.showUtils) {
- // step.classList.add("show-util");
- // }
- // }
-
- // Determine if this new step should be expanded
- const detailMode = preferencesStore.detailMode;
- const isActiveGroup = group.classList.contains("active");
- let shouldExpand = false;
-
- if (detailMode === "expanded") {
- shouldExpand = true;
- } 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
-
- if (shouldExpand) {
- step.classList.add("step-expanded");
- }
-
- // Create step header
- const stepHeader = document.createElement("div");
- stepHeader.classList.add("process-step-header");
-
- const resolvedTitle = title || getStepTitle(heading, kvps, type);
- const resolvedStatusCode = statusCode || getStatusCode(type, toolName);
- const resolvedStatusClass = statusClass || getStatusClass(type, toolName);
-
- // Add status color class to step for cascading --step-accent to internal icons
- step.classList.add(resolvedStatusClass);
- step.setAttribute("data-status-code", resolvedStatusCode);
- step.setAttribute("data-status-class", resolvedStatusClass);
-
- stepHeader.innerHTML = `
- <span class="step-expand-icon"></span>
- <span class="status-badge ${resolvedStatusClass}">${resolvedStatusCode}</span>
- <span class="step-title">${escapeHTML(resolvedTitle)}</span>
- `;
-
- // Add click handler for step expansion
- stepHeader.addEventListener("click", (e) => {
- e.stopPropagation();
-
- // Cancel any scheduled auto-collapse (user is manually toggling)
- cancelStepCollapse(step);
-
- // Toggle step
- step.classList.toggle("step-expanded");
-
- // If manually expanded, set pinned flag to prevent auto-collapse
- // If collapsed, remove it
- if (step.classList.contains("step-expanded")) {
- step.setAttribute("data-user-pinned", "true");
- } else {
- step.removeAttribute("data-user-pinned");
- }
- });
-
- step.appendChild(stepHeader);
-
- // Create step detail container
- const detail = document.createElement("div");
- detail.classList.add("process-step-detail");
-
- const detailContent = document.createElement("div");
- detailContent.classList.add("process-step-detail-content");
-
- // Add content to detail
- renderStepDetailContent(detailContent, content, kvps, type);
-
- detail.appendChild(detailContent);
-
- // Add step action buttons (view details, copy, speak)
- const stepActionBtns = document.createElement("div");
- stepActionBtns.classList.add("step-detail-actions");
- addActionButtonsToElement(stepActionBtns, {
- detailPayload,
- onViewDetails: detailHandler,
- copyContent,
- speakContent
- });
- detail.appendChild(stepActionBtns);
-
- step.appendChild(detail);
-
- // Determine where to append the step (main list or nested in parent)
- let appendTarget = stepsContainer;
-
- // Check if this step belongs to a subordinate agent
- const parentStep = findParentDelegationStep(group, agentno);
- if (parentStep) {
- appendTarget = getNestedContainer(parentStep);
- step.classList.add("nested-step");
- }
-
- // 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);
-
- // Add interaction handlers to prevent fighting with user during auto-collapse
- addStepCollapseInteractionHandlers(step);
-
- // Scroll terminal to bottom on initial render (including page refresh)
- const initialTerminal = step.querySelector(".terminal-output");
- if (initialTerminal) {
- initialTerminal.scrollTop = initialTerminal.scrollHeight;
- }
-
- // Update group header
- updateProcessGroupHeader(group);
-
- // 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");
- }
- }
-
- return step;
-}
-
-/**
- * Update an existing process step
- */
-function updateProcessStep(stepElement, stepData, detailPayload, copyContent, speakContent, detailHandler) {
- const {
- type,
- title,
- heading,
- content,
- kvps,
- timestamp,
- agentno,
- toolName,
- statusCode,
- statusClass
- } = stepData;
-
- const titleEl = stepElement.querySelector(".step-title");
- if (titleEl) {
- const resolvedTitle = title || getStepTitle(heading, kvps, type);
- titleEl.textContent = resolvedTitle;
- }
-
- if (timestamp && !stepElement.hasAttribute("data-timestamp")) {
- stepElement.setAttribute("data-timestamp", timestamp);
- }
-
- if (agentno !== undefined) {
- stepElement.setAttribute("data-agent-number", agentno);
- }
-
- const toolNameToUse = resolveToolName(type, kvps, stepElement) || toolName;
- if (toolNameToUse) {
- stepElement.setAttribute("data-tool-name", toolNameToUse);
- }
-
- const resolvedStatusCode = statusCode || getStatusCode(type, toolNameToUse);
- const resolvedStatusClass = statusClass || getStatusClass(type, toolNameToUse);
- const badge = stepElement.querySelector(".status-badge");
- if (badge) {
- updateBadgeText(badge, resolvedStatusCode);
- badge.className = `status-badge ${resolvedStatusClass}`;
- }
-
- const previousStatusClass = stepElement.getAttribute("data-status-class");
- if (previousStatusClass) {
- stepElement.classList.remove(previousStatusClass);
- }
- stepElement.classList.add(resolvedStatusClass);
- stepElement.setAttribute("data-status-code", resolvedStatusCode);
- stepElement.setAttribute("data-status-class", resolvedStatusClass);
-
- // Update detail content
- const detailContent = stepElement.querySelector(".process-step-detail-content");
- let skipFullRender = false;
-
- if (detailContent) {
- // Capture scroll state before re-render (uses existing Scroller pattern)
- const terminal = detailContent.querySelector(".terminal-output");
- const scroller = terminal ? new Scroller(terminal) : null;
-
- // For browser, update image src incrementally to avoid flashing
- if (type === "browser" && kvps?.screenshot) {
- const existingImg = detailContent.querySelector(".screenshot-img");
- const newSrc = kvps.screenshot.replace("img://", "/image_get?path=");
- if (existingImg) {
- // Only update if src actually changed
- if (!existingImg.src.endsWith(newSrc.split("?path=")[1])) {
- existingImg.src = newSrc;
- }
- // Skip full re-render to avoid flashing, but still update group header
- skipFullRender = true;
- }
- }
-
- if (!skipFullRender) {
- renderStepDetailContent(detailContent, content, kvps, type);
-
- // Re-apply scroll (stays at bottom if was at bottom)
- const newTerminal = detailContent.querySelector(".terminal-output");
- if (newTerminal && scroller?.wasAtBottom) {
- newTerminal.scrollTop = newTerminal.scrollHeight;
- }
- }
- }
-
- const detailData = detailPayload || buildDetailPayload({
- ...stepData,
- toolName: toolNameToUse,
- statusCode: resolvedStatusCode,
- statusClass: resolvedStatusClass
- });
-
- const stepActions = stepElement.querySelector(".step-detail-actions") || document.createElement("div");
- if (!stepActions.classList.contains("step-detail-actions")) {
- stepActions.classList.add("step-detail-actions");
- stepElement.querySelector(".process-step-detail")?.appendChild(stepActions);
- }
- addActionButtonsToElement(stepActions, {
- detailPayload: detailData,
- onViewDetails: detailHandler,
- copyContent,
- speakContent
- });
-
- // Update parent group header
- const group = stepElement.closest(".process-group");
- if (group) {
- updateProcessGroupHeader(group);
- }
-}
-
/**
* Get a concise title for a process step
*/
function getStepTitle(heading, kvps, type) {
// code_exe: show command when finished
- const showCommand = type === "code_exe" && kvps?.code &&
- /done_all|code_execution_tool/.test(heading || "");
- if (showCommand) {
- const s = kvps.session ?? kvps.Session;
- return `${s != null ? `[${s}] ` : ""}${kvps.runtime || "bash"}> ${kvps.code.trim()}`;
- }
+ // const showCommand =
+ // type === "code_exe" &&
+ // kvps?.code &&
+ // /done_all|code_execution_tool/.test(heading || "");
+ // if (showCommand) {
+ // const s = kvps.session ?? kvps.Session;
+ // return `${s != null ? `[${s}] ` : ""}${kvps.runtime || "bash"}> ${kvps.code.trim()}`;
+ // }
// Try to get a meaningful title from heading or kvps
if (heading && heading.trim()) {
return cleanStepTitle(heading, 100);
}
-
+
// For warnings/errors without heading, use content preview as title
- if ((type === "warning" || type === "error")) {
+ if (type === "warning" || type === "error") {
// We'll show full content in detail, so just use type as title
return type === "warning" ? "Warning" : "Error";
}
-
+
if (kvps) {
// Try common fields for title
if (kvps.tool_name) {
- const headline = kvps.headline ? cleanStepTitle(kvps.headline, 60) : '';
- return `${kvps.tool_name}${headline ? ': ' + headline : ''}`;
+ const headline = kvps.headline ? cleanStepTitle(kvps.headline, 60) : "";
+ return `${kvps.tool_name}${headline ? ": " + headline : ""}`;
}
if (kvps.headline) {
return cleanStepTitle(kvps.headline, 100);
@@ -1824,9 +2012,11 @@ function getStepTitle(heading, kvps, type) {
return truncateText(String(kvps.thoughts), 100);
}
}
-
+
// Fallback: capitalize type (backend is source of truth)
- return type ? type.charAt(0).toUpperCase() + type.slice(1).replace(/_/g, ' ') : 'Process';
+ return type
+ ? type.charAt(0).toUpperCase() + type.slice(1).replace(/_/g, " ")
+ : "Process";
}
/**
@@ -1842,282 +2032,259 @@ function extractIconFromKey(key) {
* Clean step title by removing icon:// prefixes and status phrases
* Preserves agent markers (A1:, A2:, etc.) so users can see which subordinate agent is executing
*/
-function cleanStepTitle(text, maxLength) {
+function cleanStepTitle(text, maxLength = 100) {
if (!text) return "";
let cleaned = String(text);
-
+
// Remove icon:// patterns (e.g., "icon://network_intelligence")
cleaned = cleaned.replace(/icon:\/\/[a-zA-Z0-9_]+\s*/g, "");
-
+
// Trim whitespace
cleaned = cleaned.trim();
-
+
return truncateText(cleaned, maxLength);
}
/**
* Render content for step detail panel
*/
-function renderStepDetailContent(container, content, kvps, type = null) {
- container.innerHTML = "";
-
- drawKvpsIncremental(container, kvps)
-
- // Special handling for response type - show content as markdown (for subordinate responses)
- if (type === "response" && content && content.trim()) {
- const responseDiv = document.createElement("div");
- responseDiv.classList.add("step-response-content");
-
- // Parse markdown
- let processedContent = content;
- processedContent = convertImageTags(processedContent);
- processedContent = convertImgFilePaths(processedContent);
- processedContent = convertFilePaths(processedContent);
- processedContent = marked.parse(processedContent, { breaks: true });
- processedContent = convertPathsToLinks(processedContent);
- processedContent = addBlankTargetsToLinks(processedContent);
-
- responseDiv.innerHTML = processedContent;
- container.appendChild(responseDiv);
- return;
- }
-
- // Special handling for warning/error types - always show content prominently
- if ((type === "warning" || type === "error") && content && content.trim()) {
- const warningDiv = document.createElement("div");
- warningDiv.classList.add("step-warning-content");
- warningDiv.textContent = content;
- container.appendChild(warningDiv);
- // Don't return - also show kvps if present
- }
-
- // Special handling for code_exe type - render as terminal-style output
- if (type === "code_exe" && kvps) {
- const runtime = kvps.runtime || kvps.Runtime || "bash";
- const code = kvps.code || kvps.Code || "";
- const output = content || "";
-
- if (code || output) {
- const terminalDiv = document.createElement("div");
- terminalDiv.classList.add("step-terminal");
-
- // Show output if present (no truncation - CSS handles max-height)
- if (output && output.trim()) {
- const outputPre = document.createElement("pre");
- outputPre.classList.add("terminal-output");
- // Escape HTML first, then convert paths to clickable links
- let processedOutput = escapeHTML(output);
- processedOutput = convertPathsToLinks(processedOutput);
- outputPre.innerHTML = processedOutput;
- terminalDiv.appendChild(outputPre);
- }
-
- container.appendChild(terminalDiv);
- }
-
- // Still render thoughts if present (but not reasoning - that's native model thinking, not structured output)
- if (kvps.thoughts || kvps.thinking) {
- const thoughtKey = kvps.thoughts ? "thoughts" : "thinking";
- const thoughtValue = kvps[thoughtKey];
- renderThoughts(container, thoughtValue);
- }
-
- return;
- }
-
- // Add KVPs if present
- if (kvps && Object.keys(kvps).length > 0) {
- const kvpsDiv = document.createElement("div");
- kvpsDiv.classList.add("step-kvps");
-
- for (const [key, value] of Object.entries(kvps)) {
- // Skip internal/display keys
- if (key === "finished" || key === "attachments") continue;
-
- // Skip code_exe specific keys that we handle specially above
- if (type === "code_exe" && (key.toLowerCase() === "runtime" || key.toLowerCase() === "session" || key.toLowerCase() === "code")) {
- continue;
- }
-
- const lowerKey = key.toLowerCase();
-
- // Skip headline and tool_name - they're shown elsewhere
- if (lowerKey === "headline" || lowerKey === "tool_name") continue;
-
- // Skip query in agent steps - it's shown in the tool call step
- if (type === "agent" && lowerKey === "query") continue;
-
- // Special handling for thoughts - render with single lightbulb icon
- // Skip reasoning
- if (lowerKey === "reasoning") continue;
- if (lowerKey === "thoughts" || lowerKey === "thinking" || lowerKey === "reflection") {
- renderThoughts(kvpsDiv, value);
- continue;
- }
-
- // Special handling for tool_args - render only for tool/mcp types (skip for agent)
- if (lowerKey === "tool_args") {
- // Skip tool_args for agent steps - it's shown in the tool call step
- if (type === "agent") continue;
-
- if (typeof value !== "object" || value === null) continue;
- const argsDiv = document.createElement("div");
- argsDiv.classList.add("step-tool-args");
-
- for (const [argKey, argValue] of Object.entries(value)) {
- const argRow = document.createElement("div");
- argRow.classList.add("tool-arg-row");
-
- const argLabel = document.createElement("span");
- argLabel.classList.add("tool-arg-label");
-
- const iconName = extractIconFromKey(argKey);
- if (iconName) {
- argLabel.innerHTML = `<span class="material-symbols-outlined">${iconName}</span>`;
- } else {
- argLabel.textContent = convertToTitleCase(argKey) + ":";
- }
-
- const argVal = document.createElement("span");
- argVal.classList.add("tool-arg-value");
-
- const argText = cleanTextValue(argValue);
-
- argVal.textContent = truncateText(argText, 300);
-
- argRow.appendChild(argLabel);
- argRow.appendChild(argVal);
- argsDiv.appendChild(argRow);
- }
-
- kvpsDiv.appendChild(argsDiv);
- continue;
- }
-
- const kvpDiv = document.createElement("div");
- kvpDiv.classList.add("step-kvp");
-
- const keySpan = document.createElement("span");
- keySpan.classList.add("step-kvp-key");
-
- const iconName = extractIconFromKey(key);
- if (iconName) {
- keySpan.innerHTML = `<span class="material-symbols-outlined">${iconName}</span>`;
- } else {
- keySpan.textContent = convertToTitleCase(key) + ":";
- }
-
- const valueSpan = document.createElement("div");
- valueSpan.classList.add("step-kvp-value");
-
- if (typeof value === "string" && value.startsWith("img://")) {
- const imgElement = document.createElement("img");
- imgElement.classList.add("screenshot-img");
- imgElement.src = value.replace("img://", "/image_get?path=");
- imgElement.alt = "Image Attachment";
- imgElement.style.cursor = "pointer";
- imgElement.style.maxWidth = "100%";
- imgElement.style.display = "block";
- imgElement.style.marginTop = "4px";
-
- // Add click handler and cursor change
- imgElement.addEventListener("click", () => {
- imageViewerStore.open(imgElement.src, { name: "Image Attachment" });
- });
-
- valueSpan.appendChild(imgElement);
- } else {
- const valueText = cleanTextValue(value);
- valueSpan.textContent = truncateText(valueText, 1000);
- }
-
- kvpDiv.appendChild(keySpan);
- kvpDiv.appendChild(valueSpan);
- kvpsDiv.appendChild(kvpDiv);
- }
-
- container.appendChild(kvpsDiv);
- }
-
- // Add main content if present (JSON content)
- if (content && content.trim()) {
- const pre = document.createElement("pre");
- pre.classList.add("msg-json");
- pre.textContent = truncateText(content, 1000);
- container.appendChild(pre);
- }
-}
+// function renderStepDetailContent(container, content, kvps, type = null) {
+// container.innerHTML = "";
+
+// drawKvpsIncremental(container, kvps);
+
+// // Special handling for response type - show content as markdown (for subordinate responses)
+// if (type === "response" && content && content.trim()) {
+// const responseDiv = document.createElement("div");
+// responseDiv.classList.add("step-response-content");
+
+// // Parse markdown
+// let processedContent = content;
+// processedContent = convertImageTags(processedContent);
+// processedContent = convertImgFilePaths(processedContent);
+// processedContent = convertFilePaths(processedContent);
+// processedContent = marked.parse(processedContent, { breaks: true });
+// processedContent = convertPathsToLinks(processedContent);
+// processedContent = addBlankTargetsToLinks(processedContent);
+
+// responseDiv.innerHTML = processedContent;
+// container.appendChild(responseDiv);
+// return;
+// }
+
+// // Special handling for warning/error types - always show content prominently
+// if ((type === "warning" || type === "error") && content && content.trim()) {
+// const warningDiv = document.createElement("div");
+// warningDiv.classList.add("step-warning-content");
+// warningDiv.textContent = content;
+// container.appendChild(warningDiv);
+// // Don't return - also show kvps if present
+// }
+
+// // Special handling for code_exe type - render as terminal-style output
+// if (type === "code_exe" && kvps) {
+// const runtime = kvps.runtime || kvps.Runtime || "bash";
+// const code = kvps.code || kvps.Code || "";
+// const output = content || "";
+
+// if (code || output) {
+// const terminalDiv = document.createElement("div");
+// terminalDiv.classList.add("step-terminal");
+
+// // Show output if present (no truncation - CSS handles max-height)
+// if (output && output.trim()) {
+// const outputPre = document.createElement("pre");
+// outputPre.classList.add("terminal-output");
+// // Escape HTML first, then convert paths to clickable links
+// let processedOutput = escapeHTML(output);
+// processedOutput = convertPathsToLinks(processedOutput);
+// outputPre.innerHTML = processedOutput;
+// terminalDiv.appendChild(outputPre);
+// }
+
+// container.appendChild(terminalDiv);
+// }
+
+// // Still render thoughts if present (but not reasoning - that's native model thinking, not structured output)
+// if (kvps.thoughts || kvps.thinking) {
+// const thoughtKey = kvps.thoughts ? "thoughts" : "thinking";
+// const thoughtValue = kvps[thoughtKey];
+// renderThoughts(container, thoughtValue);
+// }
+
+// return;
+// }
+
+// // Add KVPs if present
+// if (kvps && Object.keys(kvps).length > 0) {
+// const kvpsDiv = document.createElement("div");
+// kvpsDiv.classList.add("step-kvps");
+
+// for (const [key, value] of Object.entries(kvps)) {
+// // Skip internal/display keys
+// if (key === "finished" || key === "attachments") continue;
+
+// // Skip code_exe specific keys that we handle specially above
+// if (
+// type === "code_exe" &&
+// (key.toLowerCase() === "runtime" ||
+// key.toLowerCase() === "session" ||
+// key.toLowerCase() === "code")
+// ) {
+// continue;
+// }
+
+// const lowerKey = key.toLowerCase();
+
+// // Skip headline and tool_name - they're shown elsewhere
+// if (lowerKey === "headline" || lowerKey === "tool_name") continue;
+
+// // Skip query in agent steps - it's shown in the tool call step
+// if (type === "agent" && lowerKey === "query") continue;
+
+// // Special handling for thoughts - render with single lightbulb icon
+// // Skip reasoning
+// if (lowerKey === "reasoning") continue;
+// if (
+// lowerKey === "thoughts" ||
+// lowerKey === "thinking" ||
+// lowerKey === "reflection"
+// ) {
+// renderThoughts(kvpsDiv, value);
+// continue;
+// }
+
+// // Special handling for tool_args - render only for tool/mcp types (skip for agent)
+// if (lowerKey === "tool_args") {
+// // Skip tool_args for agent steps - it's shown in the tool call step
+// if (type === "agent") continue;
+
+// if (typeof value !== "object" || value === null) continue;
+// const argsDiv = document.createElement("div");
+// argsDiv.classList.add("step-tool-args");
+
+// for (const [argKey, argValue] of Object.entries(value)) {
+// const argRow = document.createElement("div");
+// argRow.classList.add("tool-arg-row");
+
+// const argLabel = document.createElement("span");
+// argLabel.classList.add("tool-arg-label");
+
+// const iconName = extractIconFromKey(argKey);
+// if (iconName) {
+// argLabel.innerHTML = `<span class="material-symbols-outlined">${iconName}</span>`;
+// } else {
+// argLabel.textContent = convertToTitleCase(argKey) + ":";
+// }
+
+// const argVal = document.createElement("span");
+// argVal.classList.add("tool-arg-value");
+
+// const argText = cleanTextValue(argValue);
+
+// argVal.textContent = truncateText(argText, 300);
+
+// argRow.appendChild(argLabel);
+// argRow.appendChild(argVal);
+// argsDiv.appendChild(argRow);
+// }
+
+// kvpsDiv.appendChild(argsDiv);
+// continue;
+// }
+
+// const kvpDiv = document.createElement("div");
+// kvpDiv.classList.add("step-kvp");
+
+// const keySpan = document.createElement("span");
+// keySpan.classList.add("step-kvp-key");
+
+// const iconName = extractIconFromKey(key);
+// if (iconName) {
+// keySpan.innerHTML = `<span class="material-symbols-outlined">${iconName}</span>`;
+// } else {
+// keySpan.textContent = convertToTitleCase(key) + ":";
+// }
+
+// const valueSpan = document.createElement("div");
+// valueSpan.classList.add("step-kvp-value");
+
+// if (typeof value === "string" && value.startsWith("img://")) {
+// const imgElement = document.createElement("img");
+// imgElement.classList.add("screenshot-img");
+// imgElement.src = value.replace("img://", "/image_get?path=");
+// imgElement.alt = "Image Attachment";
+// imgElement.style.cursor = "pointer";
+// imgElement.style.maxWidth = "100%";
+// imgElement.style.display = "block";
+// imgElement.style.marginTop = "4px";
+
+// // Add click handler and cursor change
+// imgElement.addEventListener("click", () => {
+// imageViewerStore.open(imgElement.src, { name: "Image Attachment" });
+// });
+
+// valueSpan.appendChild(imgElement);
+// } else {
+// const valueText = cleanTextValue(value);
+// valueSpan.textContent = truncateText(valueText, 1000);
+// }
+
+// kvpDiv.appendChild(keySpan);
+// kvpDiv.appendChild(valueSpan);
+// kvpsDiv.appendChild(kvpDiv);
+// }
+
+// container.appendChild(kvpsDiv);
+// }
+
+// // Add main content if present (JSON content)
+// if (content && content.trim()) {
+// const pre = document.createElement("pre");
+// pre.classList.add("msg-json");
+// pre.textContent = truncateText(content, 1000);
+// container.appendChild(pre);
+// }
+// }
/**
* Helper to render thoughts/reasoning with lightbulb icon
*/
-function renderThoughts(container, value) {
- const thoughtsDiv = document.createElement("div");
- thoughtsDiv.classList.add("step-thoughts", "msg-thoughts");
-
- const thoughtText = cleanTextValue(value);
-
- if (thoughtText) {
- thoughtsDiv.innerHTML = `<span class="thought-icon material-symbols-outlined">lightbulb</span><span class="thought-text">${escapeHTML(thoughtText)}</span>`;
- container.appendChild(thoughtsDiv);
- }
-}
+// function renderThoughts(container, value) {
+// const thoughtsDiv = document.createElement("div");
+// thoughtsDiv.classList.add("step-thoughts", "msg-thoughts");
+// const thoughtText = cleanTextValue(value);
+
+// if (thoughtText) {
+// thoughtsDiv.innerHTML = `<span class="thought-icon material-symbols-outlined">lightbulb</span><span class="thought-text">${escapeHTML(thoughtText)}</span>`;
+// container.appendChild(thoughtsDiv);
+// }
+// }
/**
* Update process group header with step count, status, and metrics
*/
function updateProcessGroupHeader(group) {
+ const header = group.querySelector(".process-group-header");
const steps = group.querySelectorAll(".process-step");
- const titleEl = group.querySelector(".group-title");
- const statusEl = group.querySelector(".group-status");
- const metricsEl = group.querySelector(".group-metrics");
- const isCompleted = group.classList.contains("process-group-completed");
-
+ const titleEl = header.querySelector(".group-title");
+ const badgeEl = header.querySelector(".step-badge");
+ const metricsEl = header.querySelector(".group-metrics");
+ const response = group.querySelector(".process-group-response");
+ const isCompleted = !!response;
const notificationsEl = metricsEl?.querySelector(".metric-notifications");
- if (notificationsEl) {
- const counts = { warning: 0, info: 0, hint: 0 };
- steps.forEach((step) => {
- const stepType = step.getAttribute("data-type");
- if (Object.prototype.hasOwnProperty.call(counts, stepType)) {
- counts[stepType] += 1;
- }
- });
-
- const totalNotifications = counts.warning + counts.info + counts.hint;
- const countEl = notificationsEl.querySelector(".metric-value");
- notificationsEl.classList.remove("status-wrn", "status-inf", "status-hnt");
- if (totalNotifications > 0) {
- if (countEl) {
- countEl.textContent = totalNotifications.toString();
- }
- if (counts.warning > 0) {
- notificationsEl.classList.add("status-wrn");
- } else if (counts.info > 0) {
- notificationsEl.classList.add("status-inf");
- } else {
- notificationsEl.classList.add("status-hnt");
- }
- notificationsEl.hidden = false;
- notificationsEl.title = `Warnings: ${counts.warning}, Info: ${counts.info}, Hints: ${counts.hint}`;
- } else {
- notificationsEl.hidden = true;
- }
- }
-
- // If completed, don't update metrics
- if (isCompleted) {
- return;
- }
-
// Update group title with the latest agent step heading
if (titleEl) {
// Find the last "agent" type step
- const agentSteps = Array.from(steps).filter(step => step.getAttribute("data-type") === "agent");
+ const agentSteps = Array.from(steps).filter(
+ (step) => step.getAttribute("data-log-type") === "agent",
+ );
if (agentSteps.length > 0) {
const lastAgentStep = agentSteps[agentSteps.length - 1];
- const lastHeading = lastAgentStep.querySelector(".step-title")?.textContent;
+ const lastHeading =
+ lastAgentStep.querySelector(".step-title")?.textContent;
if (lastHeading) {
const cleanTitle = cleanStepTitle(lastHeading, 50);
if (cleanTitle) {
@@ -2126,14 +2293,26 @@ function updateProcessGroupHeader(group) {
}
}
}
-
+
+ // If completed, set badge to END
+ if (isCompleted) {
+ badgeEl.outerHTML = `<span class="step-badge END">END</span>`;
+ } else {
+ // if not complete, clone the last step badge
+ if (badgeEl && steps.length > 0) {
+ const lastStep = steps[steps.length - 1];
+ 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
const stepsMetricEl = metricsEl?.querySelector(".metric-steps .metric-value");
if (stepsMetricEl) {
const genSteps = group.querySelectorAll('.process-step[data-type="agent"]');
stepsMetricEl.textContent = genSteps.length.toString();
}
-
+
// Update time metric
const timeMetricEl = metricsEl?.querySelector(".metric-time .metric-value");
const startTimestamp = group.getAttribute("data-start-timestamp");
@@ -2143,56 +2322,95 @@ function updateProcessGroupHeader(group) {
const minutes = String(date.getMinutes()).padStart(2, "0");
timeMetricEl.textContent = `${hours}:${minutes}`;
}
-
+
// Update duration metric
- const durationMetricEl = metricsEl?.querySelector(".metric-duration .metric-value");
+ const durationMetricEl = metricsEl?.querySelector(
+ ".metric-duration .metric-value",
+ );
if (durationMetricEl && steps.length > 0) {
- const firstTimestampMs = parseInt(steps[0]?.getAttribute("data-timestamp") || "0", 10);
+ const firstTimestampMs = parseInt(
+ steps[0]?.getAttribute("data-timestamp") || "0",
+ 10,
+ );
const lastStep = steps[steps.length - 1];
- const lastTimestampMs = parseInt(lastStep.getAttribute("data-timestamp") || "0", 10);
+ const lastTimestampMs = parseInt(
+ lastStep.getAttribute("data-timestamp") || "0",
+ 10,
+ );
const totalDurationMs = Math.max(0, lastTimestampMs - firstTimestampMs);
durationMetricEl.textContent = formatDuration(totalDurationMs);
}
-
- if (steps.length > 0) {
- // Get the last step's type for status
- const lastStep = steps[steps.length - 1];
- const lastType = lastStep.getAttribute("data-type");
- const lastToolName = lastStep.getAttribute("data-tool-name");
- const lastTitle = lastStep.querySelector(".step-title")?.textContent || "";
-
- // Update status badge
- if (statusEl) {
- const statusCode = getStatusCode(lastType, lastToolName);
- const statusColorClass = getStatusClass(lastType, lastToolName);
- statusEl.textContent = statusCode;
- statusEl.className = `status-badge ${statusColorClass} group-status`;
- }
-
- // Update title
- if (titleEl) {
- // Prefer agent type steps for the group title as they contain thinking/planning info
- if (lastType === "agent" && lastTitle) {
- titleEl.textContent = cleanStepTitle(lastTitle, 50);
+ if (notificationsEl) {
+ const counts = { warning: 0, info: 0, hint: 0 };
+ steps.forEach((step) => {
+ const stepType = step.getAttribute("data-type");
+ if (Object.prototype.hasOwnProperty.call(counts, stepType)) {
+ counts[stepType] += 1;
+ }
+ });
+
+ const totalNotifications = counts.warning + counts.info + counts.hint;
+ const countEl = notificationsEl.querySelector(".metric-value");
+ notificationsEl.classList.remove("status-wrn", "status-inf", "status-hnt");
+
+ if (totalNotifications > 0) {
+ if (countEl) {
+ countEl.textContent = totalNotifications.toString();
+ }
+ if (counts.warning > 0) {
+ notificationsEl.classList.add("status-wrn");
+ } else if (counts.info > 0) {
+ notificationsEl.classList.add("status-inf");
} else {
- // Try to find the most recent agent step for a better title
- const agentSteps = group.querySelectorAll('.process-step[data-type="agent"]');
- if (agentSteps.length > 0) {
- const lastAgentStep = agentSteps[agentSteps.length - 1];
- const agentTitle = lastAgentStep.querySelector(".step-title")?.textContent || "";
- if (agentTitle) {
- titleEl.textContent = cleanStepTitle(agentTitle, 50);
- return;
- }
- }
- titleEl.textContent = cleanStepTitle(lastTitle, 50) || `Processing...`;
+ notificationsEl.classList.add("status-hnt");
}
+ notificationsEl.hidden = false;
+ notificationsEl.title = `Warnings: ${counts.warning}, Info: ${counts.info}, Hints: ${counts.hint}`;
+ } else {
+ notificationsEl.hidden = true;
}
}
+
+ if (steps.length > 0) {
+ // Get the last step's type for status
+ // const lastStep = steps[steps.length - 1];
+ // const lastType = lastStep.getAttribute("data-type");
+ // const lastToolName = lastStep.getAttribute("data-tool-name");
+ // const lastTitle = lastStep.querySelector(".step-title")?.textContent || "";
+ // Update status badge
+ // if (statusEl) {
+ // const statusCode = getStatusCode(lastType, lastToolName);
+ // const statusColorClass = getStatusClass(lastType, lastToolName);
+ // statusEl.textContent = statusCode;
+ // statusEl.className = `step-badge ${statusColorClass} group-status`;
+ // }
+ // Update title
+ // if (titleEl) {
+ // // Prefer agent type steps for the group title as they contain thinking/planning info
+ // if (lastType === "agent" && lastTitle) {
+ // titleEl.textContent = cleanStepTitle(lastTitle, 50);
+ // } else {
+ // // Try to find the most recent agent step for a better title
+ // const agentSteps = group.querySelectorAll(
+ // '.process-step[data-type="agent"]',
+ // );
+ // if (agentSteps.length > 0) {
+ // const lastAgentStep = agentSteps[agentSteps.length - 1];
+ // const agentTitle =
+ // lastAgentStep.querySelector(".step-title")?.textContent || "";
+ // if (agentTitle) {
+ // titleEl.textContent = cleanStepTitle(agentTitle, 50);
+ // return;
+ // }
+ // }
+ // titleEl.textContent = cleanStepTitle(lastTitle, 50) || `Processing...`;
+ // }
+ // }
+ }
}
/**
@@ -2210,49 +2428,74 @@ function truncateText(text, maxLength) {
*/
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 = "status-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;
- }
- }
-
+
+ // // 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.step-expanded");
- allExpandedSteps.forEach(expandedStep => {
+ const allExpandedSteps = group.querySelectorAll(
+ ".process-step.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 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");
+ 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);
+ if (!el) {
+ el = document.createElement(tagName);
+ if (classNames.length) el.classList.add(...classNames);
+ parent.appendChild(el);
+ }
+ return el;
+}
+// returns true if this is the initial render of a chat eg. when reloading window, switching chat or catching up after a break
+// returns false when already in a rendered chat and adding messages regurarly
+function isMassRender() {
+ return _massRender;
+}