Skip to content

Agent Zero AI framework

msg redesign wip

frdele15b959eee71
diff --git a/prompts/default/fw.msg_truncated.md b/prompts/default/fw.msg_truncated.md
index cc8597fee..ab87f83ca 100644
--- a/prompts/default/fw.msg_truncated.md
+++ b/prompts/default/fw.msg_truncated.md
@@ -1 +1,3 @@
-<< {{length}} CHARACTERS REMOVED TO SAVE SPACE >>
\ No newline at end of file
+<<
+{{length}} CHARACTERS REMOVED TO SAVE SPACE
+>>
\ No newline at end of file
diff --git a/python/helpers/strings.py b/python/helpers/strings.py
index e4040caf9..ceef3167f 100644
--- a/python/helpers/strings.py
+++ b/python/helpers/strings.py
@@ -119,4 +119,14 @@ def dict_to_text(d: dict) -> str:
parts.append(f"{value}")
parts.append("") # Add empty line between entries
- return "\n".join(parts).rstrip() # rstrip to remove trailing newline
\ No newline at end of file
+ return "\n".join(parts).rstrip() # rstrip to remove trailing newline
+
+def truncate_text(text: str, length: int, at_end: bool = True, replacement: str = "...") -> str:
+ orig_length = len(text)
+ if orig_length <= length:
+ return text
+ if at_end:
+ return text[:length] + replacement
+ else:
+ return replacement + text[-length:]
+
\ No newline at end of file
diff --git a/python/tools/code_execution_tool.py b/python/tools/code_execution_tool.py
index 8a65a45d6..657381092 100644
--- a/python/tools/code_execution_tool.py
+++ b/python/tools/code_execution_tool.py
@@ -8,7 +8,8 @@ from python.helpers.print_style import PrintStyle
from python.helpers.shell_local import LocalInteractiveSession
from python.helpers.shell_ssh import SSHInteractiveSession
from python.helpers.docker import DockerContainerManager
-from python.helpers.messages import truncate_text
+from python.helpers.strings import truncate_text as truncate_text_string
+from python.helpers.messages import truncate_text as truncate_text_agent
import re
@@ -63,11 +64,17 @@ class CodeExecution(Tool):
def get_log_object(self):
return self.agent.context.log.log(
type="code_exe",
- heading=f"{self.agent.agent_name}: Using tool '{self.name}'",
+ heading=self.get_heading(),
content="",
kvps=self.args,
)
+ def get_heading(self, text: str = ""):
+ if not text:
+ text = f"{self.name} - {self.args['runtime']}"
+ text = truncate_text_string(text, 60)
+ return f"icon://terminal {text}"
+
async def after_execution(self, response, **kwargs):
self.agent.hist_add_tool_result(self.name, response.message)
@@ -229,10 +236,9 @@ class CodeExecution(Tool):
if partial_output:
PrintStyle(font_color="#85C1E9").stream(partial_output)
# full_output += partial_output # Append new output
- truncated_output = truncate_text(
- agent=self.agent, output=full_output, threshold=10000
- )
- self.log.update(content=truncated_output)
+ truncated_output = self.fix_full_output(full_output)
+ heading = self.get_heading_from_output(truncated_output, 0)
+ self.log.update(content=truncated_output, heading=heading)
last_output_time = now
got_output = True
@@ -240,12 +246,18 @@ class CodeExecution(Tool):
last_lines = (
truncated_output.splitlines()[-3:] if truncated_output else []
)
- for line in last_lines:
+ last_lines.reverse()
+ for idx, line in enumerate(last_lines):
for pat in prompt_patterns:
if pat.search(line.strip()):
PrintStyle.info(
"Detected shell prompt, returning output early."
)
+ last_lines.reverse()
+ heading = self.get_heading_from_output(
+ "\n".join(last_lines), idx + 1, True
+ )
+ self.log.update(heading=heading)
return truncated_output
# Check for max execution time
@@ -257,7 +269,8 @@ class CodeExecution(Tool):
if truncated_output:
response = truncated_output + "\n\n" + response
PrintStyle.warning(sysinfo)
- self.log.update(content=response)
+ heading = self.get_heading_from_output(truncated_output, 0)
+ self.log.update(content=response, heading=heading)
return response
# Waiting for first output
@@ -280,7 +293,8 @@ class CodeExecution(Tool):
if truncated_output:
response = truncated_output + "\n\n" + response
PrintStyle.warning(sysinfo)
- self.log.update(content=response)
+ heading = self.get_heading_from_output(truncated_output, 0)
+ self.log.update(content=response, heading=heading)
return response
# potential dialog detection
@@ -305,7 +319,10 @@ class CodeExecution(Tool):
if truncated_output:
response = truncated_output + "\n\n" + response
PrintStyle.warning(sysinfo)
- self.log.update(content=response)
+ heading = self.get_heading_from_output(
+ truncated_output, 0
+ )
+ self.log.update(content=response, heading=heading)
return response
async def reset_terminal(self, session=0, reason: str | None = None):
@@ -326,3 +343,28 @@ class CodeExecution(Tool):
)
self.log.update(content=response)
return response
+
+ def get_heading_from_output(self, output: str, skip_lines=0, done=False):
+ done_icon = " icon://done_all" if done else ""
+
+ if not output:
+ return self.get_heading() + done_icon
+
+ # find last non-empty line with skip
+ lines = output.splitlines()
+ # Start from len(lines) - skip_lines - 1 down to 0
+ for i in range(len(lines) - skip_lines - 1, -1, -1):
+ line = lines[i].strip()
+ if not line:
+ continue
+ return self.get_heading(line) + done_icon
+
+ return self.get_heading() + done_icon
+
+ def fix_full_output(self, output: str):
+ # remove any single byte \xXX escapes
+ output = re.sub(r'(?<!\\)\\x[0-9A-Fa-f]{2}', '', output)
+ # Strip every line of output before truncation
+ output = "\n".join(line.strip() for line in output.splitlines())
+ output = truncate_text_agent(agent=self.agent, output=output, threshold=10000)
+ return output
diff --git a/webui/css/messages.css b/webui/css/messages.css
new file mode 100644
index 000000000..35d260b32
--- /dev/null
+++ b/webui/css/messages.css
@@ -0,0 +1,656 @@
+/* Chat History */
+#chat-history {
+ display: -webkit-flex;
+ display: flex;
+ flex-direction: column;
+ flex-grow: 1;
+ width: 100%;
+ overflow-y: scroll;
+ overflow-x: hidden;
+ scroll-behavior: auto !important; /* avoid infinite scrolling! */
+ padding: var(--spacing-md) var(--spacing-sm) 0;
+ -webkit-transition: all 0.3s ease;
+ transition: all 0.3s ease;
+ scrollbar-width: thin;
+ scrollbar-color: #555 transparent;
+ }
+
+ #chat-history > *:first-child {
+ margin-top: 4.4em;
+ }
+
+ /* Scrollbar styling for Firefox */
+ #chat-history::-webkit-scrollbar {
+ width: 5px;
+ }
+
+ #chat-history::-webkit-scrollbar-track {
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3);
+ border-radius: 3px;
+ }
+
+ #chat-history::-webkit-scrollbar-thumb {
+ border-radius: 3px;
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3);
+ background-color: #555;
+ -webkit-transition: background-color var(--transition-speed) ease-in-out;
+ transition: background-color var(--transition-speed) ease-in-out;
+ }
+
+ #chat-history::-webkit-scrollbar-thumb:hover {
+ background-color: #666;
+ }
+
+ #chat-history::-webkit-scrollbar-thumb:active {
+ background-color: #888;
+ }
+
+
+/* Message Styles */
+
+
+ .user-container {
+ align-self: flex-end;
+ /* margin: var(--spacing-sm) var(--spacing-md); */
+ /* margin-bottom: var(--spacing-lg); */
+ /* margin-top: var(--spacing-sm); */
+ display: flex;
+ justify-content: flex-end;
+ width: 100%;
+ }
+
+ .ai-container {
+ align-self: flex-start;
+ }
+
+ .center-container {
+ align-self: center;
+ max-width: 80%;
+ margin: 0;
+ }
+
+ .center-container .message {
+ margin-bottom: var(--spacing-sm);
+ }
+
+ .message-user {
+ background-color: #4a4a4a;
+ /* border-bottom-right-radius: var(--spacing-xxs); */
+ min-width: 195px;
+ text-align: end;
+ }
+
+ .message-user > div {
+ padding-top: var(--spacing-xs);
+ font-family: "Roboto Mono", monospace;
+ font-optical-sizing: auto;
+ -webkit-font-optical-sizing: auto;
+ font-size: var(--font-size-small);
+ }
+
+ .message-ai {
+ /* border-bottom-left-radius: var(--spacing-xxs); */
+ }
+
+ .message-center {
+ align-self: center;
+ /* border-bottom-left-radius: unset; */
+ }
+
+ .message-followup {
+ /* margin-left: var(--spacing-lg); */
+ /* margin-bottom: var(--spacing-lg); */
+ }
+
+ .message-followup .message {
+ border-radius: 1.125em; /* 18px */
+ /* border-top-left-radius: var(--spacing-xxs); */
+ }
+
+ .message-followup + .message-followup {
+ margin-bottom: 0;
+ }
+
+ /* Update message types for dark mode */
+ .message-default,
+ .message-agent,
+ .message-agent-response,
+ .message-agent-delegation,
+ .message-tool,
+ .message-code-exe,
+ .message-browser,
+ .message-info,
+ .message-util,
+ .message-warning,
+ .message-error {
+ color: #e0e0e0;
+ }
+
+ .message-default {
+ background-color: #1a242f;
+ }
+
+ .message-agent {
+ background-color: #34506b;
+ }
+
+ .message-agent-response {
+ min-width: 255px;
+ background-color: #1f3c1e;
+ }
+
+ .message-agent-delegation {
+ background-color: #12685e;
+ }
+
+ .message-tool {
+ background-color: #2a4170;
+ }
+
+ .message-code-exe {
+ background-color: #4b3a69;
+ }
+
+ .message-code-exe .message-body {
+ min-height: 5em;
+ width: 100%;
+ background-color: var(--color-panel);
+ border-radius: 0.5em;
+ margin-top: 0.5em;
+ padding: 0.3em;
+ }
+
+ .light-mode .message-code-exe .message-body {
+ border: 1px solid var(--color-border);
+ }
+
+ .message-browser {
+ background-color: #4b3a69;
+ }
+
+ .message-info {
+ background-color: var(--color-panel);
+ }
+
+ .message-util {
+ background-color: #23211a;
+ display: none;
+ }
+
+ .message-warning {
+ background-color: #bc8036;
+ }
+
+ .message-error {
+ background-color: #af2222;
+ }
+
+ /* Agent and AI Info */
+ .agent-start {
+ color: var(--color-text);
+ font-size: var(--font-size-small);
+ margin-bottom: var(--spacing-xs);
+ opacity: 0.7;
+ }
+
+ .msg-kvps {
+ font-size: 0.9em;
+ margin: 0.5rem 0 0.55rem 0;
+ border-collapse: collapse;
+ width: 100%;
+ }
+
+ .kvps-val pre {
+ white-space: pre-wrap; /* keep \n, collapse no spaces, allow wrapping */
+ word-break: break-word; /* optional – forces really long “words” to break */
+ }
+
+ .msg-kvps th,
+ .msg-kvps td {
+ align-content: center;
+ padding: 0.25rem;
+ padding-left: 0;
+ text-align: left;
+ }
+
+ .msg-kvps th {
+ color: var(--color-primary);
+ width: 40%;
+ }
+
+ .msg-kvps tr {
+ border-bottom: 1px solid rgba(255, 255, 255, 0.15);
+ }
+
+ .msg-heading {
+ margin: 0;
+ position: relative;
+ display: block;
+ white-space: nowrap;
+ }
+
+ .msg-heading h4 {
+ margin: 0;
+ /* width: calc(100% - 4em); */
+ margin-right: 4em;
+ overflow-y: hidden;
+ text-overflow: ellipsis;
+ }
+
+ /* Message Actions */
+ .message-actions {
+ color: var(--color-text);
+ font-size: var(--font-size-small);
+ margin-top: var(--spacing-xs);
+ }
+
+ .message-action {
+ cursor: pointer;
+ opacity: 0.7;
+ -webkit-transition: opacity var(--transition-speed) ease-in-out;
+ transition: opacity var(--transition-speed) ease-in-out;
+ }
+
+ .message-action:hover {
+ opacity: 1;
+ }
+
+
+/* Copy button styles */
+.copy-button {
+ position: absolute;
+ right: 0;
+ top: var(--spacing-sm);
+ background: none;
+ border: none;
+ padding: var(--spacing-xs) var(--spacing-sm);
+ padding-right: 0;
+ cursor: pointer;
+ text-decoration: underline;
+ text-wrap: nowrap;
+ opacity: 0;
+ -webkit-transition: opacity var(--transition-speed) ease-in-out;
+ transition: opacity var(--transition-speed) ease-in-out;
+ color: inherit;
+ font-size: 12px;
+ font-family: "Rubik", Arial, Helvetica, sans-serif;
+ }
+
+ .copy-button:hover {
+ opacity: 0.8 !important;
+ }
+
+ .msg-content:hover .copy-button,
+ .kvps-row:hover .copy-button,
+ .message-text:hover .copy-button {
+ opacity: 0.6;
+ }
+
+ .copy-button.copied {
+ font-family: "Rubik", Arial, Helvetica, sans-serif !important;
+ opacity: 1 !important;
+ }
+
+ .msg-thoughts .copy-button {
+ top: -12px !important;
+ }
+
+ .message-user .copy-button {
+ top: -15px !important;
+ left: -13px !important;
+ right: 99% !important;
+ }
+
+ .message-agent-response .copy-button {
+ top: -22px !important;
+ right: 0 !important;
+ padding-right: 0px !important;
+ }
+
+ .message-info .copy-button {
+ top: -22px !important;
+ right: 0 !important;
+ padding-right: 0px !important;
+ }
+
+ .message-tool .copy-button {
+ top: -12px !important;
+ right: 0 !important;
+ }
+
+ .msg-output .copy-button {
+ top: -6px !important;
+ right: 0 !important;
+ }
+
+ /* Make message containers relative for absolute positioning of copy buttons */
+ .msg-content,
+ .kvps-row,
+ .message-text {
+ position: relative;
+ }
+
+ .message-text pre {
+ margin: 0;
+ }
+
+/* Utility Classes */
+.kvps-key {
+ font-weight: 500;
+ font-size: var(--font-size-small);
+ }
+
+ .kvps-val {
+ margin: 0.65rem 0 0.65rem 0.4rem;
+ white-space: pre-wrap;
+ }
+
+ .kvps-img {
+ width: 8em;
+ height: 8em;
+ object-fit: cover;
+ object-position: top left;
+ border-radius: 10%;
+ border: 1px solid rgba(255, 255, 255, 0.15);
+ }
+
+ .image-viewer-img {
+ width: 100%;
+ }
+
+ .msg-json {
+ display: none;
+ }
+
+ .msg-thoughts {
+ display: auto;
+ }
+
+ .msg-thoughts .kvps-val {
+ max-height: 20em;
+ overflow: auto;
+ }
+
+ .msg-content {
+ margin-bottom: 0;
+ }
+
+ .message-temp {
+ display: none;
+ }
+
+ .message-temp:not([style*="display: none"]):last-of-type {
+ display: block; /* or any style you want for visibility */
+ }
+
+/* Math (KaTeX) */
+.katex {
+ line-height: 1.2 !important;
+ font-size: 1.1em;
+ }
+
+/* Media Queries */
+@media (max-width: 640px) {
+ /* New styles for mobile messages */
+
+ .message-followup {
+ /* margin-left: var(--spacing-md); */
+ margin-bottom: var(--spacing-md);
+ }
+
+ .msg-kvps {
+ display: flex;
+ flex-direction: column;
+ border-collapse: separate;
+ border-spacing: 0 0.5rem;
+ }
+
+ .msg-kvps tr {
+ display: flex;
+ flex-direction: column;
+ margin-top: 0.3rem;
+ padding-bottom: 0;
+ }
+
+ .msg-kvps th,
+ .msg-kvps td {
+ display: block;
+ width: 100%;
+ text-align: left;
+ border-bottom: none;
+ padding: 0.25rem 0;
+ padding-left: 0 !important;
+ }
+
+ .msg-kvps th {
+ color: var(--color-primary);
+ margin-bottom: 0.25rem;
+ }
+
+ .kvps-val {
+ margin: 0 0 0.4rem 0;
+ white-space: pre-wrap;
+ word-break: break-word;
+ overflow-wrap: anywhere;
+ }
+ }
+
+.light-mode .msg-kvps tr {
+ border-bottom: 1px solid rgb(192 192 192 / 50%);
+ }
+
+ .light-mode .message-default {
+ background-color: #f3f3f3;
+ color: #1a242f;
+ }
+
+ .light-mode .message-agent {
+ background-color: #f3f3f3;
+ color: #356ca3;
+ }
+
+ .light-mode .message-agent-response {
+ background-color: #f3f3f3;
+ color: #188216;
+ }
+
+ .light-mode .message-agent-delegation {
+ background-color: #f3f3f3;
+ color: #12685e;
+ }
+
+ .light-mode .message-tool {
+ background-color: #f3f3f3;
+ color: #1c3c88;
+ }
+
+ .light-mode .message-code-exe {
+ background-color: #f3f3f3;
+ color: #6c43b0;
+ }
+
+ .light-mode .message-browser {
+ background-color: #ffffff;
+ color: #6c43b0;
+ }
+
+ .light-mode .message-info {
+ background-color: #f3f3f3;
+ color: #3f3f3f;
+ }
+
+ .light-mode .message-util {
+ background-color: #f3f3f3;
+ color: #5b5540;
+ }
+
+ .light-mode .message-warning {
+ background-color: #f3f3f3;
+ color: #8f4800;
+ }
+
+ .light-mode .message-error {
+ background-color: #f3f3f3;
+ color: #8f1010;
+ }
+
+ .light-mode .message-user {
+ background-color: #f3f3f3;
+ color: #4e4e4e;
+ }
+
+/* Markdown in messages */
+.msg-content {
+ font-size: var(--font-size-small);
+ }
+
+ .message-agent-response .msg-content {
+ font-size: var(--font-size-smaller);
+ }
+
+ .msg-content h1 {
+ font-size: 1.25em;
+ font-weight: 800;
+ margin-bottom: 0.2em;
+ }
+
+ .msg-content h2 {
+ font-size: 1.2em;
+ font-weight: 700;
+ margin-bottom: 0.2em;
+ }
+
+ .msg-content h3 {
+ font-size: 1.15em;
+ font-weight: 600;
+ margin-bottom: 0.2em;
+ }
+
+ .msg-content h4 {
+ font-size: 1.1em;
+ font-weight: 500;
+ margin-bottom: 0.2em;
+ }
+
+ .msg-content h5 {
+ font-size: 1.05em;
+ font-weight: 500;
+ margin-bottom: 0.2em;
+ }
+
+ .msg-content h6 {
+ font-size: 1em;
+ font-weight: 500;
+ margin-bottom: 0.2em;
+ }
+
+ .msg-content table {
+ width: 100%;
+ border-collapse: collapse;
+ margin: 1em 0;
+ font-size: 0.98em;
+ background: transparent;
+ border-radius: 8px;
+ overflow: hidden;
+ }
+
+ .msg-content th,
+ .msg-content td {
+ padding: 0.55em 1em;
+ border: 1px solid rgba(142, 142, 142, 0.1);
+ text-align: left;
+ background: transparent;
+ }
+
+ .msg-content th {
+ font-weight: 600;
+ background: rgba(142, 142, 142, 0.1);
+ }
+
+ .msg-content tr:nth-child(even) {
+ background: rgba(142, 142, 142, 0.1);
+ }
+
+ .msg-content tr:nth-child(odd) {
+ background: transparent;
+ }
+
+ .msg-content table {
+ box-shadow: none;
+ }
+
+ .msg-content pre:has(code) {
+ padding: 0.5em;
+ border: 1px solid rgba(142, 142, 142, 0.1);
+ border-radius: 0.3em;
+ }
+
+ .msg-min-max-btns {
+ opacity: 40%;
+ position: absolute;
+ top: -0.2em;
+ right: -0.2em;
+ display: flex;
+ gap: 0.3em;
+ z-index: 1;
+ }
+
+.message-group {
+ margin-top: 1em;
+ margin-bottom: 1em;
+ display: inline-grid;
+ grid-template-columns: minmax(0, max-content);
+ grid-auto-rows: auto;
+ max-width: 100%;
+ width: fit-content;
+ }
+
+ .message-group > * {
+ grid-column: 1;
+ } /* both children sit in the same column */
+
+ .message-group-right {
+ justify-content: end;
+ }
+
+ .message-group-mid {
+ justify-content: center;
+ }
+
+ /* 1. FIRST child’s .message – clear ONLY bottom corners */
+ .message-group > *:first-child:not(:last-child) > .message {
+ border-bottom-left-radius: var(--spacing-xxs);;
+ border-bottom-right-radius: var(--spacing-xxs);;
+ }
+
+ /* 2. MIDDLE children’s .message – clear ALL corners */
+ .message-group > *:not(:first-child):not(:last-child) > .message {
+ border-radius: var(--spacing-xxs);
+ }
+
+ /* 3. LAST child’s .message – clear ONLY top corners */
+ .message-group > *:last-child:not(:first-child) > .message {
+ border-top-left-radius: var(--spacing-xxs);;
+ border-top-right-radius: var(--spacing-xxs);;
+ }
+
+ .message-container {
+ animation: fadeIn 0.5s;
+ -webkit-animation: fadeIn 0.5s;
+ margin-bottom: var(--spacing-sm);
+ width: 100%;
+ max-width: 100%;
+ }
+
+ .message {
+ /* background-color: var(--color-message-bg); */
+ border-radius: var(--border-radius);
+ padding: 0.9rem var(--spacing-sm) 0.7rem var(--spacing-sm);
+ overflow-x: auto;
+ width: auto;
+ max-width: 100%;
+ box-sizing: border-box;
+ display: block;
+ word-break: break-word;
+ overflow-wrap: anywhere;
+ }
\ No newline at end of file
diff --git a/webui/index.css b/webui/index.css
index 6b92cc658..d76dbc7ac 100644
--- a/webui/index.css
+++ b/webui/index.css
@@ -48,6 +48,7 @@
--color-input-focus: var(--color-input-focus-dark);
/* Spacing variables */
+ --spacing-xxs: 0.15rem;
--spacing-xs: 0.3125rem;
--spacing-sm: 0.625rem;
--spacing-md: 1.25rem;
@@ -90,6 +91,10 @@ body {
-webkit-overscroll-behavior: none;
}
+p:last-child {
+ margin-bottom: 0;
+}
+
body,
#left-panel,
#chat-input,
@@ -441,51 +446,6 @@ pre {
font-size: 0.75rem;
}
-/* Chat History */
-#chat-history {
- display: -webkit-flex;
- display: flex;
- flex-direction: column;
- flex-grow: 1;
- overflow-y: scroll;
- overflow-x: hidden;
- scroll-behavior: auto !important; /* avoid infinite scrolling! */
- padding: var(--spacing-md) var(--spacing-md) 0;
- -webkit-transition: all 0.3s ease;
- transition: all 0.3s ease;
- scrollbar-width: thin;
- scrollbar-color: #555 transparent;
-}
-
-#chat-history > *:first-child {
- margin-top: 4.4em;
-}
-
-/* Scrollbar styling for Firefox */
-#chat-history::-webkit-scrollbar {
- width: 5px;
-}
-
-#chat-history::-webkit-scrollbar-track {
- box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3);
- border-radius: 3px;
-}
-
-#chat-history::-webkit-scrollbar-thumb {
- border-radius: 3px;
- box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.3);
- background-color: #555;
- -webkit-transition: background-color var(--transition-speed) ease-in-out;
- transition: background-color var(--transition-speed) ease-in-out;
-}
-
-#chat-history::-webkit-scrollbar-thumb:hover {
- background-color: #666;
-}
-
-#chat-history::-webkit-scrollbar-thumb:active {
- background-color: #888;
-}
/* Logo Container */
#logo-container {
@@ -569,220 +529,7 @@ pre {
margin-left: 4.6rem;
}
-/* Message Styles */
-.message-container {
- animation: fadeIn 0.5s;
- -webkit-animation: fadeIn 0.5s;
- margin-bottom: var(--spacing-sm);
- width: 100%;
- max-width: 100%;
-}
-
-.message {
- background-color: var(--color-message-bg);
- border-radius: var(--border-radius);
- padding: 0.9rem var(--spacing-md) 0.7rem var(--spacing-md);
- overflow-x: auto;
- width: fit-content;
- max-width: 100%;
- box-sizing: border-box;
- display: block;
-}
-
-.user-container {
- align-self: flex-end;
- margin: var(--spacing-sm) var(--spacing-md);
- display: flex;
- justify-content: flex-end;
- width: 100%;
-}
-
-.ai-container {
- align-self: flex-start;
-}
-
-.center-container {
- align-self: center;
- max-width: 80%;
- margin: 0;
-}
-
-.center-container .message {
- margin-bottom: var(--spacing-sm);
-}
-
-.message-user {
- background-color: #4a4a4a;
- border-bottom-right-radius: var(--spacing-xs);
- min-width: 195px;
- text-align: end;
-}
-
-.message-user > div {
- padding-top: var(--spacing-xs);
- font-family: "Roboto Mono", monospace;
- font-optical-sizing: auto;
- -webkit-font-optical-sizing: auto;
- font-size: var(--font-size-small);
-}
-
-.message-ai {
- border-bottom-left-radius: var(--spacing-xs);
-}
-
-.message-center {
- align-self: center;
- border-bottom-left-radius: unset;
-}
-
-.message-followup {
- margin-left: var(--spacing-lg);
- margin-bottom: var(--spacing-lg);
-}
-
-.message-followup .message {
- border-radius: 1.125em; /* 18px */
- border-top-left-radius: 0.3125em; /* 5px */
-}
-
-.message-followup + .message-followup {
- margin-bottom: 0;
-}
-
-/* Update message types for dark mode */
-.message-default,
-.message-agent,
-.message-agent-response,
-.message-agent-delegation,
-.message-tool,
-.message-code-exe,
-.message-browser,
-.message-info,
-.message-util,
-.message-warning,
-.message-error {
- color: #e0e0e0;
-}
-
-.message-default {
- background-color: #1a242f;
-}
-
-.message-agent {
- background-color: #34506b;
-}
-
-.message-agent-response {
- min-width: 255px;
- background-color: #1f3c1e;
-}
-
-.message-agent-delegation {
- background-color: #12685e;
-}
-
-.message-tool {
- background-color: #2a4170;
-}
-
-.message-code-exe {
- background-color: #4b3a69;
-}
-
-.message-code-exe .message-body {
- min-height: 5em;
- background-color: var(--color-panel);
- border-radius: 0.5em;
- margin: 0.3em;
- padding: 0.3em;
-}
-
-.light-mode .message-code-exe .message-body {
- border: 1px solid var(--color-border);
-}
-
-.message-browser {
- background-color: #4b3a69;
-}
-
-.message-info {
- background-color: var(--color-panel);
-}
-
-.message-util {
- background-color: #23211a;
- display: none;
-}
-
-.message-warning {
- background-color: #bc8036;
-}
-
-.message-error {
- background-color: #af2222;
-}
-
-/* Agent and AI Info */
-.agent-start {
- color: var(--color-text);
- font-size: var(--font-size-small);
- margin-bottom: var(--spacing-xs);
- opacity: 0.7;
-}
-
-.msg-kvps {
- font-size: 0.9em;
- margin: 0.5rem 0 0.55rem 0;
- border-collapse: collapse;
- width: 100%;
-}
-
-.kvps-val pre {
- white-space: pre-wrap; /* keep \n, collapse no spaces, allow wrapping */
- word-break: break-word; /* optional – forces really long “words” to break */
-}
-
-.msg-kvps th,
-.msg-kvps td {
- align-content: center;
- padding: 0.25rem;
- padding-left: 0;
- text-align: left;
-}
-.msg-kvps th {
- color: var(--color-primary);
- width: 40%;
-}
-
-.msg-kvps tr {
- border-bottom: 1px solid rgba(255, 255, 255, 0.15);
-}
-
-.msg-heading {
- margin: 0;
- padding-right: 5.5em; /* space for buttons */
- position: relative;
- display: block;
-}
-
-/* Message Actions */
-.message-actions {
- color: var(--color-text);
- font-size: var(--font-size-small);
- margin-top: var(--spacing-xs);
-}
-
-.message-action {
- cursor: pointer;
- opacity: 0.7;
- -webkit-transition: opacity var(--transition-speed) ease-in-out;
- transition: opacity var(--transition-speed) ease-in-out;
-}
-
-.message-action:hover {
- opacity: 1;
-}
/* Input Section */
#input-section {
@@ -1486,128 +1233,9 @@ input:checked + .slider:before {
/* Already defined above */
}
-/* Copy button styles */
-.copy-button {
- position: absolute;
- right: 0;
- top: var(--spacing-sm);
- background: none;
- border: none;
- padding: var(--spacing-xs) var(--spacing-sm);
- padding-right: 0;
- cursor: pointer;
- text-decoration: underline;
- text-wrap: nowrap;
- opacity: 0;
- -webkit-transition: opacity var(--transition-speed) ease-in-out;
- transition: opacity var(--transition-speed) ease-in-out;
- color: inherit;
- font-size: 12px;
- font-family: "Rubik", Arial, Helvetica, sans-serif;
-}
-
-.copy-button:hover {
- opacity: 0.8 !important;
-}
-
-.msg-content:hover .copy-button,
-.kvps-row:hover .copy-button,
-.message-text:hover .copy-button {
- opacity: 0.6;
-}
-
-.copy-button.copied {
- font-family: "Rubik", Arial, Helvetica, sans-serif !important;
- opacity: 1 !important;
-}
-
-.msg-thoughts .copy-button {
- top: -12px !important;
-}
-
-.message-user .copy-button {
- top: -15px !important;
- left: -13px !important;
- right: 99% !important;
-}
-
-.message-agent-response .copy-button {
- top: -22px !important;
- right: 0 !important;
- padding-right: 0px !important;
-}
-
-.message-info .copy-button {
- top: -22px !important;
- right: 0 !important;
- padding-right: 0px !important;
-}
-
-.message-tool .copy-button {
- top: -12px !important;
- right: 0 !important;
-}
-
-.msg-output .copy-button {
- top: -6px !important;
- right: 0 !important;
-}
-
-/* Make message containers relative for absolute positioning of copy buttons */
-.msg-content,
-.kvps-row,
-.message-text {
- position: relative;
-}
-
-/* Utility Classes */
-.kvps-key {
- font-weight: 500;
- font-size: var(--font-size-small);
-}
-
-.kvps-val {
- margin: 0.65rem 0 0.65rem 0.4rem;
- white-space: pre-wrap;
-}
-
-.kvps-img {
- width: 8em;
- height: 8em;
- object-fit: cover;
- object-position: top left;
- border-radius: 10%;
- border: 1px solid rgba(255, 255, 255, 0.15);
-}
-
-.image-viewer-img {
- width: 100%;
-}
-
-.msg-json {
- display: none;
-}
-
-.msg-thoughts {
- display: auto;
-}
-
-.msg-thoughts .kvps-val {
- max-height: 20em;
- overflow: auto;
-}
-.msg-content {
- margin-bottom: 0;
-}
-.message-temp {
- display: none;
-}
-.message-temp:not([style*="display: none"]):last-of-type {
- display: block; /* or any style you want for visibility */
-}
.status-icon {
display: flex;
@@ -1643,11 +1271,7 @@ input:checked + .slider:before {
font-weight: bold;
}
-/* Math (KaTeX) */
-.katex {
- line-height: 1.2 !important;
- font-size: 1.1em;
-}
+
/* Animations */
@keyframes fadeIn {
@@ -1717,48 +1341,6 @@ input:checked + .slider:before {
display: none;
}
- /* New styles for mobile messages */
-
- .message-followup {
- margin-left: var(--spacing-md);
- margin-bottom: var(--spacing-md);
- }
-
- .msg-kvps {
- display: flex;
- flex-direction: column;
- border-collapse: separate;
- border-spacing: 0 0.5rem;
- }
-
- .msg-kvps tr {
- display: flex;
- flex-direction: column;
- margin-top: 0.3rem;
- padding-bottom: 0;
- }
-
- .msg-kvps th,
- .msg-kvps td {
- display: block;
- width: 100%;
- text-align: left;
- border-bottom: none;
- padding: 0.25rem 0;
- padding-left: 0 !important;
- }
-
- .msg-kvps th {
- color: var(--color-primary);
- margin-bottom: 0.25rem;
- }
-
- .kvps-val {
- margin: 0 0 0.4rem 0;
- white-space: pre-wrap;
- word-break: break-word;
- overflow-wrap: anywhere;
- }
}
@media (max-width: 640px) {
@@ -1962,69 +1544,7 @@ a:active {
--color-input-focus: var(--color-input-focus-light);
}
-.light-mode .msg-kvps tr {
- border-bottom: 1px solid rgb(192 192 192 / 50%);
-}
-
-.light-mode .message-default {
- background-color: #f3f3f3;
- color: #1a242f;
-}
-
-.light-mode .message-agent {
- background-color: #f3f3f3;
- color: #356ca3;
-}
-
-.light-mode .message-agent-response {
- background-color: #f3f3f3;
- color: #188216;
-}
-
-.light-mode .message-agent-delegation {
- background-color: #f3f3f3;
- color: #12685e;
-}
-.light-mode .message-tool {
- background-color: #f3f3f3;
- color: #1c3c88;
-}
-
-.light-mode .message-code-exe {
- background-color: #f3f3f3;
- color: #6c43b0;
-}
-
-.light-mode .message-browser {
- background-color: #ffffff;
- color: #6c43b0;
-}
-
-.light-mode .message-info {
- background-color: #f3f3f3;
- color: #3f3f3f;
-}
-
-.light-mode .message-util {
- background-color: #f3f3f3;
- color: #5b5540;
-}
-
-.light-mode .message-warning {
- background-color: #f3f3f3;
- color: #8f4800;
-}
-
-.light-mode .message-error {
- background-color: #f3f3f3;
- color: #8f1010;
-}
-
-.light-mode .message-user {
- background-color: #f3f3f3;
- color: #4e4e4e;
-}
.light-mode .connected {
color: #4caf50;
@@ -3019,97 +2539,9 @@ nav ul li a img {
text-align: center;
}
-/* Markdown in messages */
-.msg-content {
- font-size: var(--font-size-small);
-}
-
-.message-agent-response .msg-content {
- font-size: var(--font-size-smaller);
-}
-
-.msg-content h1 {
- font-size: 1.25em;
- font-weight: 800;
- margin-bottom: 0.2em;
-}
-
-.msg-content h2 {
- font-size: 1.2em;
- font-weight: 700;
- margin-bottom: 0.2em;
-}
-
-.msg-content h3 {
- font-size: 1.15em;
- font-weight: 600;
- margin-bottom: 0.2em;
-}
-
-.msg-content h4 {
- font-size: 1.1em;
- font-weight: 500;
- margin-bottom: 0.2em;
-}
-
-.msg-content h5 {
- font-size: 1.05em;
- font-weight: 500;
- margin-bottom: 0.2em;
-}
-
-.msg-content h6 {
- font-size: 1em;
- font-weight: 500;
- margin-bottom: 0.2em;
-}
-.msg-content table {
- width: 100%;
- border-collapse: collapse;
- margin: 1em 0;
- font-size: 0.98em;
- background: transparent;
- border-radius: 8px;
- overflow: hidden;
-}
-.msg-content th,
-.msg-content td {
- padding: 0.55em 1em;
- border: 1px solid rgba(142, 142, 142, 0.1);
- text-align: left;
- background: transparent;
-}
-
-.msg-content th {
- font-weight: 600;
- background: rgba(142, 142, 142, 0.1);
-}
-
-.msg-content tr:nth-child(even) {
- background: rgba(142, 142, 142, 0.1);
-}
-
-.msg-content tr:nth-child(odd) {
- background: transparent;
-}
-
-.msg-content table {
- box-shadow: none;
-}
-
-.msg-content pre:has(code) {
- padding: 0.5em;
- border: 1px solid rgba(142, 142, 142, 0.1);
- border-radius: 0.3em;
+.icon {
+ vertical-align: middle;
}
-.msg-min-max-btns {
- position: absolute;
- top: -0.2em;
- right: -0.5em;
- display: flex;
- gap: 0.3em;
- z-index: 1;
-}
diff --git a/webui/index.html b/webui/index.html
index 9e96365f7..82b3c901a 100644
--- a/webui/index.html
+++ b/webui/index.html
@@ -7,6 +7,7 @@
<title>Agent Zero</title>
<link rel="icon" type="image/svg+xml" href="public/favicon.svg">
<link rel="stylesheet" href="index.css">
+ <link rel="stylesheet" href="css/messages.css">
<link rel="stylesheet" href="css/toast.css">
<link rel="stylesheet" href="css/settings.css">
<link rel="stylesheet" href="css/file_browser.css">
diff --git a/webui/index.js b/webui/index.js
index e87e30098..b0097aaf2 100644
--- a/webui/index.js
+++ b/webui/index.js
@@ -235,34 +235,9 @@ updateUserTime();
setInterval(updateUserTime, 1000);
function setMessage(id, type, heading, content, temp, kvps = null) {
- // Search for the existing message container by id
- let messageContainer = document.getElementById(`message-${id}`);
-
- if (messageContainer) {
- // Don't re-render user messages
- if (type === "user") {
- return; // Skip re-rendering
- }
- // For other types, update the message
- messageContainer.innerHTML = "";
- } else {
- // Create a new container if not found
- const sender = type === "user" ? "user" : "ai";
- messageContainer = document.createElement("div");
- messageContainer.id = `message-${id}`;
- messageContainer.classList.add("message-container", `${sender}-container`);
- if (temp) messageContainer.classList.add("message-temp");
- }
-
- const handler = msgs.getHandler(type);
- handler(messageContainer, id, type, heading, content, temp, kvps);
-
- // If the container was found, it was already in the DOM, no need to append again
- if (!document.getElementById(`message-${id}`)) {
- chatHistory.appendChild(messageContainer);
- }
-
+ const result = msgs.setMessage(id, type, heading, content, temp, kvps);
if (autoScroll) chatHistory.scrollTop = chatHistory.scrollHeight;
+ return result;
}
window.loadKnowledge = async function () {
diff --git a/webui/js/messages.js b/webui/js/messages.js
index d5675dd7f..64662c897 100644
--- a/webui/js/messages.js
+++ b/webui/js/messages.js
@@ -3,6 +3,71 @@ import { openImageModal } from "./image_modal.js";
import { marked } from "../vendor/marked/marked.esm.js";
import { store as messageResizeStore } from "/components/messages/resize/message-resize-store.js";
+const chatHistory = document.getElementById("chat-history");
+
+let messageGroup = null;
+
+export function setMessage(id, type, heading, content, temp, kvps = null) {
+ // Search for the existing message container by id
+ let messageContainer = document.getElementById(`message-${id}`);
+
+ if (messageContainer) {
+ // Don't re-render user messages
+ if (type === "user") {
+ return; // Skip re-rendering
+ }
+ // For other types, update the message
+ messageContainer.innerHTML = "";
+ } else {
+ // Create a new container if not found
+ const sender = type === "user" ? "user" : "ai";
+ messageContainer = document.createElement("div");
+ messageContainer.id = `message-${id}`;
+ messageContainer.classList.add("message-container", `${sender}-container`);
+ // if (temp) messageContainer.classList.add("message-temp");
+ }
+
+ const handler = getHandler(type);
+ handler(messageContainer, id, type, heading, content, temp, kvps);
+
+ // If the container was found, it was already in the DOM, no need to append again
+ if (!document.getElementById(`message-${id}`)) {
+ // message type visual grouping
+ const groupTypeMap = {
+ user: "right",
+ info: "mid",
+ warning: "mid",
+ error: "mid",
+ rate_limit: "mid",
+ util: "mid",
+ hint: "mid",
+ // anything else is "left"
+ };
+
+ //force new group on these types
+ const groupStart = {
+ agent: true,
+ // anything else is false
+ };
+
+ const groupType = groupTypeMap[type] || "left";
+
+ if (
+ !messageGroup || // no group yet exists
+ groupStart[type] || // message type forces new group
+ groupType != messageGroup.getAttribute("data-group-type") // message type changes group
+ ) {
+ messageGroup = document.createElement("div");
+ messageGroup.id = `message-group-${id}`;
+ messageGroup.classList.add(`message-group`, `message-group-${groupType}`);
+ messageGroup.setAttribute("data-group-type", groupType);
+ }
+
+ messageGroup.appendChild(messageContainer);
+ chatHistory.appendChild(messageGroup);
+ }
+}
+
function createCopyButton() {
const button = document.createElement("button");
button.className = "copy-button";
@@ -94,9 +159,11 @@ export function _drawMessage(
messageDiv.classList.add("message", mainClass, ...messageClasses);
if (heading) {
- const headingElement = document.createElement("h4");
+ const headingElement = document.createElement("div");
headingElement.classList.add("msg-heading");
- headingElement.textContent = heading;
+ const headingH4 = document.createElement("h4");
+ headingH4.innerHTML = convertIcons(escapeHTML(heading));
+ headingElement.appendChild(headingH4);
messageDiv.appendChild(headingElement);
if (resizeBtns) {
@@ -301,8 +368,8 @@ export function drawMessageUser(
textDiv.classList.add("message-text");
// Create a span for the content
- const spanElement = document.createElement("span");
- spanElement.innerHTML = convertHTML(content);
+ const spanElement = document.createElement("pre");
+ spanElement.innerHTML = escapeHTML(content);
textDiv.appendChild(spanElement);
// Add click handler
@@ -699,6 +766,13 @@ function convertImgFilePaths(str) {
return str.replace("img://", "/image_get?path=");
}
+function convertIcons(str) {
+ return str.replace(
+ /icon:\/\/([a-zA-Z0-9_]+)/g,
+ '<span class="icon material-symbols-outlined">$1</span>'
+ );
+}
+
function escapeHTML(str) {
const escapeChars = {
"&": "&amp;",