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.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
Refactor Chat Component for Enhanced Type Consistency and Clarity
Salman-Ahamede130247e21b4
diff --git a/packages/app/src/react/features/ai-chat/components/chat.tsx b/packages/app/src/react/features/ai-chat/components/chat.tsxindex ff4b1235..9054695e 100644--- a/packages/app/src/react/features/ai-chat/components/chat.tsx+++ b/packages/app/src/react/features/ai-chat/components/chat.tsx@@ -1,7 +1,3 @@-/**- * Chat Message Component- * Routes to appropriate message component based on message type- */import { FC } from 'react';import { IChatMessage } from '@react/features/ai-chat';@@ -14,12 +10,8 @@ import {import '../styles/index.css';-/**- * Chat component properties- */-interface ChatProps extends IChatMessage {- /** Callback to scroll chat to bottom */- scrollToBottom?: () => void;+interface IChatProps extends IChatMessage {+ scrollToBottom?: () => void; // Callback to scroll chat to bottom}/**@@ -29,61 +21,31 @@ interface ChatProps extends IChatMessage {* @param props - Chat message properties* @returns Appropriate message component*/-export const Chat: FC<ChatProps> = ({- type,- files,- avatar,- message,- onRetryClick,- thinkingMessage,- scrollToBottom,-}) => {- // ✅ Type-based discrimination - type is single source of truth+export const Chat: FC<IChatProps> = (props) => {+ const { type, files, avatar, message, onRetryClick, thinkingMessage, scrollToBottom } = props;// Loading state (replying/retrying)- if (type === 'loading') {- return <ReplyLoader />;- }+ if (type === 'loading') return <ReplyLoader />;// Thinking message- if (type === 'thinking') {- return <ThinkingMessage message={message} avatar={avatar} />;- }+ if (type === 'thinking') return <ThinkingMessage message={message} avatar={avatar} />;// User message- if (type === 'user') {- return <UserMessage message={message} files={files} />;- }+ if (type === 'user') return <UserMessage message={message} files={files} />;// Error message- if (type === 'error') {- return (- <SystemMessage- avatar={avatar}- message={message || 'Something went wrong'}- isError={true}- onRetryClick={onRetryClick}- isRetrying={false}- thinkingMessage={thinkingMessage}- onTypingProgress={() => scrollToBottom?.()}- onTypingComplete={() => scrollToBottom?.()}- typingAnimation={false}- />- );- }+ if (type === 'error')+ return <SystemMessage isError message={message} onRetryClick={onRetryClick} />;- // System message with typing animation+ // System message (default)return (<SystemMessageavatar={avatar}message={message}- isError={false}- onRetryClick={onRetryClick}- isRetrying={false}+ typingAnimationthinkingMessage={thinkingMessage}- onTypingProgress={() => scrollToBottom?.()}onTypingComplete={() => scrollToBottom?.()}- typingAnimation={true}+ onTypingProgress={() => scrollToBottom?.()}/>);};diff --git a/packages/app/src/react/features/ai-chat/components/error-message.tsx b/packages/app/src/react/features/ai-chat/components/error-message.tsxindex e14829b3..111cb63e 100644--- a/packages/app/src/react/features/ai-chat/components/error-message.tsx+++ b/packages/app/src/react/features/ai-chat/components/error-message.tsx@@ -9,8 +9,6 @@ interface IErrorMessage {}export const ErrorMessage: FC<IErrorMessage> = ({ message, onRetryClick, isRetrying }) => {- // Check if this is a 401 API key error-const isApiKeyError =message.includes('Incorrect API key provided') ||(message.includes('401') &&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.tsxindex 45669d80..66674fd7 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@@ -9,7 +9,7 @@ import {Typewriter,} from '@react/features/ai-chat/components';-interface ISystemMessageBubble {+interface ISystemMessageProps {message: string;avatar?: string;isError?: boolean;@@ -21,7 +21,7 @@ interface ISystemMessageBubble {onTypingProgress?: () => void;}-export const SystemMessage: FC<ISystemMessageBubble> = ({+export const SystemMessage: FC<ISystemMessageProps> = ({avatar,message,isError,