Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

Refactor Chat and SystemMessage Components for Improved Clarity and Consistency

Salman-Ahamedbc3185a3cf4c
diff --git a/packages/app/src/react/features/ai-chat/components/chat.tsx b/packages/app/src/react/features/ai-chat/components/chat.tsx
index 9054695e..9295afe8 100644
--- a/packages/app/src/react/features/ai-chat/components/chat.tsx
+++ b/packages/app/src/react/features/ai-chat/components/chat.tsx
@@ -24,28 +24,27 @@ interface IChatProps extends IChatMessage {
export const Chat: FC<IChatProps> = (props) => {
const { type, files, avatar, message, onRetryClick, thinkingMessage, scrollToBottom } = props;
- // Loading state (replying/retrying)
- if (type === 'loading') return <ReplyLoader />;
-
- // Thinking message
- if (type === 'thinking') return <ThinkingMessage message={message} avatar={avatar} />;
-
- // User message
- if (type === 'user') return <UserMessage message={message} files={files} />;
-
- // Error message
- if (type === 'error')
- return <SystemMessage isError message={message} onRetryClick={onRetryClick} />;
-
- // System message (default)
- return (
- <SystemMessage
- avatar={avatar}
- message={message}
- typingAnimation
- thinkingMessage={thinkingMessage}
- onTypingComplete={() => scrollToBottom?.()}
- onTypingProgress={() => scrollToBottom?.()}
- />
- );
+ switch (type) {
+ case 'loading':
+ return <ReplyLoader />;
+ case 'thinking':
+ return <ThinkingMessage message={message} avatar={avatar} />;
+ case 'user':
+ return <UserMessage message={message} files={files} />;
+ case 'system':
+ return (
+ <SystemMessage
+ avatar={avatar}
+ message={message}
+ typingAnimation
+ thinkingMessage={thinkingMessage}
+ onTypingComplete={() => scrollToBottom?.()}
+ onTypingProgress={() => scrollToBottom?.()}
+ />
+ );
+ case 'error':
+ return <SystemMessage isError message={message} onRetryClick={onRetryClick} />;
+ default:
+ return <SystemMessage isError message="Something went wrong!" onRetryClick={onRetryClick} />;
+ }
};
diff --git a/packages/app/src/react/features/ai-chat/components/chats.tsx b/packages/app/src/react/features/ai-chat/components/chats.tsx
index c2fbdcf8..0f68ef1d 100644
--- a/packages/app/src/react/features/ai-chat/components/chats.tsx
+++ b/packages/app/src/react/features/ai-chat/components/chats.tsx
@@ -70,7 +70,7 @@ export const Chats: FC<IChatsProps> = (props) => {
<div
ref={ref}
onScroll={handleScroll}
- className="w-full h-full max-w-4xl flex-1 pb-4 space-y-6 px-2.5"
+ className="w-full h-full max-w-4xl flex-1 pb-4 space-y-2.5 px-2.5"
>
{messages.map((message, index) => {
const isLastMessage = index === messages.length - 1;
diff --git a/packages/app/src/react/features/ai-chat/components/system-message.tsx b/packages/app/src/react/features/ai-chat/components/system-message.tsx
index 66674fd7..885c3fe1 100644
--- a/packages/app/src/react/features/ai-chat/components/system-message.tsx
+++ b/packages/app/src/react/features/ai-chat/components/system-message.tsx
@@ -21,17 +21,18 @@ interface ISystemMessageProps {
onTypingProgress?: () => void;
}
-export const SystemMessage: FC<ISystemMessageProps> = ({
- avatar,
- message,
- isError,
- isRetrying,
- onRetryClick,
- thinkingMessage,
- onTypingComplete,
- onTypingProgress,
- typingAnimation = true,
-}) => {
+export const SystemMessage: FC<ISystemMessageProps> = (props) => {
+ const {
+ avatar,
+ message,
+ isError,
+ isRetrying,
+ onRetryClick,
+ thinkingMessage,
+ onTypingComplete,
+ onTypingProgress,
+ typingAnimation = true,
+ } = props;
const [copied, setCopied] = useState(false);
const contentRef = useRef<HTMLDivElement>(null);
@@ -57,31 +58,32 @@ export const SystemMessage: FC<ISystemMessageProps> = ({
return (
<div className="system-message-bubble relative">
- <div className="flex-1" ref={contentRef}>
- {isError ? (
- <ErrorMessage message={message} onRetryClick={onRetryClick} isRetrying={isRetrying} />
- ) : (
- <div className="chat-rich-text-response space-y-1 rounded-lg p-3 text-[#141414]">
- {typingAnimation ? (
- <Typewriter
- message={message}
- speed={2}
- isTyping={typingAnimation}
- onComplete={onTypingComplete}
- onTypingProgress={onTypingProgress}
- />
- ) : (
- <MarkdownRenderer message={message} />
- )}
+ {isError ? (
+ <ErrorMessage message={message} onRetryClick={onRetryClick} isRetrying={isRetrying} />
+ ) : (
+ <div
+ ref={contentRef}
+ className="chat-rich-text-response space-y-1 rounded-lg p-3 text-[#141414]"
+ >
+ {typingAnimation ? (
+ <Typewriter
+ message={message}
+ speed={2}
+ isTyping={typingAnimation}
+ onComplete={onTypingComplete}
+ onTypingProgress={onTypingProgress}
+ />
+ ) : (
+ <MarkdownRenderer message={message} />
+ )}
- {/* Display thinking message inline if present */}
- {thinkingMessage && <ThinkingMessage message={thinkingMessage} avatar={avatar} />}
- </div>
- )}
- </div>
+ {/* Display thinking message inline if present */}
+ {thinkingMessage && <ThinkingMessage message={thinkingMessage} avatar={avatar} />}
+ </div>
+ )}
{!isError && !thinkingMessage && (
- <div className="flex gap-4 p-4 pl-0">
+ <div className="ps-2.5 -mt-2.5">
<Tooltip content={copied ? 'Copied!' : 'Copy'} placement="bottom">
<button
onClick={handleCopy}