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 component to utilize MESSAGE_TYPES for improved clarity and maintainability

Salman-Ahamed902355a5c969
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 e93d919d..ce2ba5d0 100644
--- a/packages/app/src/react/features/ai-chat/components/chat.tsx
+++ b/packages/app/src/react/features/ai-chat/components/chat.tsx
@@ -2,12 +2,13 @@ import { FC, memo } from 'react';
import {
ErrorMessage,
+ MetaMessage,
ReplyLoader,
SystemMessage,
- ThinkingMessage,
UserMessage,
} from '@react/features/ai-chat/components';
+import { MESSAGE_TYPES } from '../constants';
import '../styles/index.css';
import { IMessage } from '../types/chat';
@@ -31,15 +32,15 @@ export const Chat: FC<IChatProps> = memo((props) => {
const { type, attachments, avatar, content, metaMessages, onRetryClick, scrollToBottom } = props;
switch (type) {
- case 'loading':
- return <ReplyLoader />;
- case 'meta':
- return <ThinkingMessage avatar={avatar} metaMessages={metaMessages} />;
- case 'user':
+ case MESSAGE_TYPES.USER:
return <UserMessage message={content} files={attachments} />;
- case 'system':
+ case MESSAGE_TYPES.LOADING:
+ return <ReplyLoader />;
+ case MESSAGE_TYPES.META:
+ return <MetaMessage data={{ avatar, metaMessages }} scrollToBottom={scrollToBottom} />;
+ case MESSAGE_TYPES.SYSTEM:
return <SystemMessage message={content} scrollToBottom={scrollToBottom} />;
- case 'error':
+ case MESSAGE_TYPES.ERROR:
return <ErrorMessage message={content} onRetryClick={onRetryClick} />;
default:
return <ErrorMessage message="Something went wrong!" onRetryClick={onRetryClick} />;
diff --git a/packages/app/src/react/features/ai-chat/components/thinking-message.tsx b/packages/app/src/react/features/ai-chat/components/thinking-message.tsx
index 9b4ef1f0..2ded7ec1 100644
--- a/packages/app/src/react/features/ai-chat/components/thinking-message.tsx
+++ b/packages/app/src/react/features/ai-chat/components/thinking-message.tsx
@@ -6,8 +6,11 @@ import { FC, useEffect, useRef, useState } from 'react';
import { IMetaMessages } from '../types/chat';
interface IProps {
- avatar?: string;
- metaMessages?: IMetaMessages;
+ data: {
+ avatar?: string;
+ metaMessages?: IMetaMessages;
+ };
+ scrollToBottom: () => void;
}
// Custom CSS for smooth blinking animation (like the image)
@@ -29,9 +32,15 @@ const blinkAnimation = `
* Manages thinking message cycling internally using ThinkingMessageManager
* Receives metaMessages from parent and handles the cycling logic
*/
-export const ThinkingMessage: FC<IProps> = ({ avatar, metaMessages }) => {
+export const MetaMessage: FC<IProps> = ({ data, scrollToBottom }) => {
+ const { avatar, metaMessages } = data;
+
const [thinkingMessage, setThinkingMessage] = useState<string>('');
const thinkingManagerRef = useRef(createThinkingManager());
+ // thinking-message.tsx
+ useEffect(() => {
+ scrollToBottom?.();
+ }, [scrollToBottom]);
/**
* Effect to manage thinking message lifecycle