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 AI Chat Components and Update Imports for Improved Structure
Salman-Ahamed2f54e069e9b4
diff --git a/packages/app/src/react/features/ai-chat/components/chat/user-message.tsx b/packages/app/src/react/features/ai-chat/components/chat/user-message.tsxindex 6871f232..d9daf1b4 100644--- a/packages/app/src/react/features/ai-chat/components/chat/user-message.tsx+++ b/packages/app/src/react/features/ai-chat/components/chat/user-message.tsx@@ -1,13 +1,13 @@+import { FileItemPreview } from '@react/features/ai-chat/components';+import type { TAttachment } from '@react/features/ai-chat/types';import { FC } from 'react';-import { TAttachment } from '../../types';-import { FileItemPreview } from '../common/FileItemPreview';-interface IProps {+type TUserMessageProps = {message: string;files?: TAttachment[];-}+};-export const UserMessage: FC<IProps> = ({ message, files }) => {+export const UserMessage: FC<TUserMessageProps> = ({ message, files }) => {const hasFiles = files && files.length > 0;return (diff --git a/packages/app/src/react/features/ai-chat/components/common/FileItemPreview.tsx b/packages/app/src/react/features/ai-chat/components/common/file-item-preview.tsxsimilarity index 95%rename from packages/app/src/react/features/ai-chat/components/common/FileItemPreview.tsxrename to packages/app/src/react/features/ai-chat/components/common/file-item-preview.tsxindex e43ad90c..45943526 100644--- a/packages/app/src/react/features/ai-chat/components/common/FileItemPreview.tsx+++ b/packages/app/src/react/features/ai-chat/components/common/file-item-preview.tsx@@ -9,7 +9,7 @@ import {FaRegFileWord,FaXmark,} from 'react-icons/fa6';-import type { TAttachment } from '../../types';+import type { TAttachment } from '@react/features/ai-chat/types';const FILE_ICONS: Record<string, ReactElement> = {pdf: <FaRegFilePdf className="text-white text-xl" />,@@ -34,11 +34,11 @@ const FILE_ICONS: Record<string, ReactElement> = {const DEFAULT_ICON = <FaRegFileLines className="text-white text-xl" />;-interface IRemoveButtonProps {+type TRemoveButtonProps = {onRemove: () => void;-}+};-const RemoveButton: FC<IRemoveButtonProps> = memo(({ onRemove }) => (+const RemoveButton: FC<TRemoveButtonProps> = memo(({ onRemove }) => (<buttononClick={onRemove}className="size-6 flex justify-center items-center bg-white rounded-full text-[#6B7280] border border-[#E5E7EB] opacity-0 transition-opacity duration-200 z-10 cursor-pointer hover:text-[#374151] pt-0.5"@@ -50,11 +50,11 @@ const RemoveButton: FC<IRemoveButtonProps> = memo(({ onRemove }) => (RemoveButton.displayName = 'RemoveButton';-export interface IFileItemPreviewProps {+export type TFileItemPreviewProps = {attachment: TAttachment;onRemove?: () => void;isUploading?: boolean;-}+};const getFileExtension = (fileName: string, url?: string, blobUrl?: string | null): string => {if (fileName) {@@ -93,7 +93,7 @@ const getPreviewUrl = (attachment: TAttachment): string | null => {return attachment.url || null;};-export const FileItemPreview: FC<IFileItemPreviewProps> = memo(+export const FileItemPreview: FC<TFileItemPreviewProps> = memo(({ attachment, onRemove, isUploading = false }) => {const { name, type, file, url, blobUrl } = attachment;@@ -194,3 +194,4 @@ export const FileItemPreview: FC<IFileItemPreviewProps> = memo();FileItemPreview.displayName = 'FileItemPreview';+diff --git a/packages/app/src/react/features/ai-chat/components/common/index.ts b/packages/app/src/react/features/ai-chat/components/common/index.tsindex e5bd1508..151cdd9a 100644--- a/packages/app/src/react/features/ai-chat/components/common/index.ts+++ b/packages/app/src/react/features/ai-chat/components/common/index.ts@@ -1,2 +1,2 @@-export * from './FileItemPreview';+export * from './file-item-preview';export * from './icons';diff --git a/packages/app/src/react/features/ai-chat/components/footer/attachment-button.tsx b/packages/app/src/react/features/ai-chat/components/footer/attachment-button.tsxindex c93e1d88..90e8f7a7 100644--- a/packages/app/src/react/features/ai-chat/components/footer/attachment-button.tsx+++ b/packages/app/src/react/features/ai-chat/components/footer/attachment-button.tsx@@ -1,9 +1,9 @@-import { Tooltip, TooltipContent, TooltipTrigger } from '@src/react/shared/components/ui/tooltip';import { ChangeEvent, FC, RefObject, useCallback } from 'react';-import { AttachmentIcon } from '@react/features/ai-chat/components/common/icons';+import { AttachmentIcon } from '@react/features/ai-chat/components';import { CHAT_ACCEPTED_FILE_TYPES } from '@react/features/ai-chat/constants';-import { FILE_LIMITS } from '@react/features/ai-chat/utils/file';+import { FILE_LIMITS } from '@react/features/ai-chat/utils';+import { Tooltip, TooltipContent, TooltipTrigger } from '@react/shared/components/ui/tooltip';interface IProps {fileInputRef: RefObject<HTMLInputElement | null>;diff --git a/packages/app/src/react/features/ai-chat/components/footer/footer.tsx b/packages/app/src/react/features/ai-chat/components/footer/footer.tsxindex 6599a4da..c70a4a8a 100644--- a/packages/app/src/react/features/ai-chat/components/footer/footer.tsx+++ b/packages/app/src/react/features/ai-chat/components/footer/footer.tsx@@ -2,8 +2,7 @@ import { ChatInput, ErrorToast, ScrollToBottomButton } from '@react/features/ai-import { useChatStores } from '@react/features/ai-chat/hooks';import { FC } from 'react';-const CHAT_WARNING_INFO =- "SmythOS can make mistakes, always check your work. We don't store chat history, save important work."; // eslint-disable-line quotes+const CHAT_WARNING_INFO = `SmythOS can make mistakes, always check your work. We don't store chat history, save important work.`;export const Footer: FC = () => {const { files, scroll } = useChatStores();diff --git a/packages/app/src/react/features/ai-chat/components/footer/input.tsx b/packages/app/src/react/features/ai-chat/components/footer/input.tsxindex 4c1e3239..ca3c0196 100644--- a/packages/app/src/react/features/ai-chat/components/footer/input.tsx+++ b/packages/app/src/react/features/ai-chat/components/footer/input.tsx@@ -1,16 +1,16 @@import { ChangeEvent, KeyboardEvent, useCallback, useEffect, useRef, useState } from 'react';import '../../styles/index.css';-import { AttachmentButton, SendButton } from '@react/features/ai-chat/components';+import { AttachmentButton, FileItemPreview, SendButton } from '@react/features/ai-chat/components';import { useChatStores, useClipboardPaste } from '@react/features/ai-chat/hooks';-import { adjustTextareaHeight, createFileFromText } from '@react/features/ai-chat/utils';-import { MAX_CHAT_MESSAGE_LENGTH } from '@react/shared/constants';-import { cn } from '@react/shared/utils/general';-import { FileItemPreview } from '@src/react/features/ai-chat/components/common/FileItemPreview';import {+ adjustTextareaHeight,+ createFileFromText,forceScrollToBottomImmediate,scrollManager,-} from '@src/react/features/ai-chat/utils/scroll';+} from '@react/features/ai-chat/utils';+import { MAX_CHAT_MESSAGE_LENGTH } from '@react/shared/constants';+import { cn } from '@react/shared/utils/general';const LARGE_TEXT_THRESHOLD = 4000;diff --git a/packages/app/src/react/features/ai-chat/components/header/AgentAvatar.tsx b/packages/app/src/react/features/ai-chat/components/header/agent-avatar.tsxsimilarity index 59%rename from packages/app/src/react/features/ai-chat/components/header/AgentAvatar.tsxrename to packages/app/src/react/features/ai-chat/components/header/agent-avatar.tsxindex 6499d872..666d5bfb 100644--- a/packages/app/src/react/features/ai-chat/components/header/AgentAvatar.tsx+++ b/packages/app/src/react/features/ai-chat/components/header/agent-avatar.tsx@@ -1,13 +1,13 @@import { FC } from 'react';-import { Skeleton } from '..';-import { DEFAULT_AVATAR_URL } from '../../constants';+import { Skeleton } from '@react/features/ai-chat/components';+import { DEFAULT_AVATAR_URL } from '@react/features/ai-chat/constants';-interface AgentAvatarProps {+type TAgentAvatarProps = {avatar: string | undefined;isLoading: boolean;-}+};-export const AgentAvatar: FC<AgentAvatarProps> = ({ avatar, isLoading }) => (+export const AgentAvatar: FC<TAgentAvatarProps> = ({ avatar, isLoading }) => (<figure>{isLoading ? (<Skeleton className="size-8 rounded-full" />@@ -20,3 +20,4 @@ export const AgentAvatar: FC<AgentAvatarProps> = ({ avatar, isLoading }) => ()}</figure>);+diff --git a/packages/app/src/react/features/ai-chat/components/header/AgentName.tsx b/packages/app/src/react/features/ai-chat/components/header/agent-name.tsxsimilarity index 64%rename from packages/app/src/react/features/ai-chat/components/header/AgentName.tsxrename to packages/app/src/react/features/ai-chat/components/header/agent-name.tsxindex 818b090b..e5e7d239 100644--- a/packages/app/src/react/features/ai-chat/components/header/AgentName.tsx+++ b/packages/app/src/react/features/ai-chat/components/header/agent-name.tsx@@ -1,14 +1,14 @@-import { cn } from '@src/react/shared/utils/general';+import { cn } from '@react/shared/utils/general';import { FC } from 'react';-import { Skeleton } from '..';+import { Skeleton } from '@react/features/ai-chat/components';-interface IProps {+type TAgentNameProps = {name: string | undefined;isAgentLoading: boolean;isSettingsLoading: boolean;-}+};-export const AgentName: FC<IProps> = ({ name, isAgentLoading, isSettingsLoading }) => {+export const AgentName: FC<TAgentNameProps> = ({ name, isAgentLoading, isSettingsLoading }) => {if (isAgentLoading) {return (<Skeleton className={cn('w-25 h-[18px] rounded', isSettingsLoading && 'rounded-b-none')} />@@ -21,3 +21,4 @@ export const AgentName: FC<IProps> = ({ name, isAgentLoading, isSettingsLoading</span>);};+diff --git a/packages/app/src/react/features/ai-chat/components/header/index.ts b/packages/app/src/react/features/ai-chat/components/header/index.tsindex 019453a8..d7ff0b56 100644--- a/packages/app/src/react/features/ai-chat/components/header/index.ts+++ b/packages/app/src/react/features/ai-chat/components/header/index.ts@@ -1,5 +1,5 @@-export * from './AgentAvatar';-export * from './AgentName';+export * from './agent-avatar';+export * from './agent-name';export * from './header-actions';export * from './main';export * from './model-dropdown';diff --git a/packages/app/src/react/features/ai-chat/components/header/skeleton.tsx b/packages/app/src/react/features/ai-chat/components/header/skeleton.tsxindex 2e4a3229..e6227b55 100644--- a/packages/app/src/react/features/ai-chat/components/header/skeleton.tsx+++ b/packages/app/src/react/features/ai-chat/components/header/skeleton.tsx@@ -1,4 +1,4 @@-import { cn } from '@src/react/shared/utils/general';+import { cn } from '@react/shared/utils/general';import { FC } from 'react';export const Skeleton: FC<{ className?: string }> = ({ className }) => (diff --git a/packages/app/src/react/features/ai-chat/utils/file.ts b/packages/app/src/react/features/ai-chat/utils/file.tsindex e476f979..ac949463 100644--- a/packages/app/src/react/features/ai-chat/utils/file.ts+++ b/packages/app/src/react/features/ai-chat/utils/file.ts@@ -1,5 +1,14 @@+import { ALLOWED_FILE_SIZE, MAX_UPLOADS } from '@react/features/ai-chat/constants';import type { TUploadFile } from '@react/features/ai-chat/types';+/**+ * File upload limits configuration+ */+export const FILE_LIMITS = {+ MAX_ATTACHED_FILES: MAX_UPLOADS,+ MAX_FILE_SIZE: ALLOWED_FILE_SIZE,+} as const;+/*** Creates a TUploadFile from plain text content* Useful for converting pasted text into a file attachment@@ -15,3 +24,74 @@ export const createFileFromText = (content: string): TUploadFile => {return { file, metadata: { fileType: 'text/plain', isUploading: false }, id };};++/**+ * Validates a single file for upload+ * @param file - File to validate+ * @returns Error message string if invalid, undefined if valid+ */+export const validateSingleFile = (file: File): string | undefined => {+ if (file.size > ALLOWED_FILE_SIZE) {+ return `File "${file.name}" exceeds 5MB size limit`;+ }+ return undefined;+};++/**+ * Generates a unique ID for a file based on name and timestamp+ * @param file - File to generate ID for+ * @returns Unique file ID string+ */+export const generateUniqueFileId = (file: File): string => {+ const timestamp = Date.now();+ const randomSuffix = Math.random().toString(36).substring(2, 8);+ return `${file.name}-${timestamp}-${randomSuffix}`;+};++type TUploadFilesParams = {+ files: File[];+ agentId?: string;+ chatId?: string;+};++type TUploadFilesResponse = {+ files?: Array<{+ url: string;+ name?: string;+ mimetype?: string;+ }>;+};++/**+ * Uploads files to the chat API+ * @param params - Upload parameters including files, agentId, and chatId+ * @returns Promise with uploaded file information+ */+export const uploadFiles = async (params: TUploadFilesParams): Promise<TUploadFilesResponse> => {+ const { files, agentId, chatId } = params;++ const formData = new FormData();+ files.forEach((file) => {+ formData.append('file', file);+ });++ const headers: Record<string, string> = {};+ if (agentId) {+ headers['X-AGENT-ID'] = agentId;+ }+ if (chatId) {+ headers['x-conversation-id'] = chatId;+ }++ const response = await fetch('/api/page/chat/upload', {+ method: 'POST',+ headers,+ body: formData,+ });++ if (!response.ok) {+ throw new Error(`Upload failed: ${response.statusText}`);+ }++ return response.json() as Promise<TUploadFilesResponse>;+};