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
Enhance Chat Context and AgentChatPage for Improved Scroll Behavior and Input Management
Salman-Ahamed529ec4191cc5
diff --git a/packages/app/src/react/features/ai-chat/contexts/index.new.tsx b/packages/app/src/react/features/ai-chat/contexts/index.new.tsxindex 82df322b..aca8bec0 100644--- a/packages/app/src/react/features/ai-chat/contexts/index.new.tsx+++ b/packages/app/src/react/features/ai-chat/contexts/index.new.tsx@@ -57,6 +57,12 @@ export const ChatContextProvider: FC<IProps> = ({ children }) => {const files = useAttachments({ agentId, chatId: agentSettings?.lastConversationId });+ // ============================================================================+ // SCROLL BEHAVIOR+ // ============================================================================++ const scroll = useScrollToBottom(containerRef);+// ============================================================================// CHAT STATE MANAGEMENT// ============================================================================@@ -153,11 +159,6 @@ export const ChatContextProvider: FC<IProps> = ({ children }) => {Observability.observeInteraction(EVENTS.CHAT_EVENTS.SESSION_START);}, [createSession, clearMessages, files, stopGenerating, inputRef]);- // ============================================================================- // SCROLL BEHAVIOR- // ============================================================================- const scroll = useScrollToBottom(containerRef);-// ============================================================================// LIFECYCLE EFFECTS// ============================================================================@@ -186,6 +187,14 @@ export const ChatContextProvider: FC<IProps> = ({ children }) => {return () => Observability.observeInteraction(EVENTS.CHAT_EVENTS.SESSION_END);}, []);+ /**+ * Auto-focus input when agent is loaded and not disabled+ */+ useEffect(() => {+ const inputDisabled = isChatCreating || isAgentLoading || isProcessing;+ if (!isAgentLoading && !inputDisabled) inputRef.current?.focus();+ }, [isAgentLoading, isChatCreating, isProcessing]);+// Memoize the store to avoid unnecessary re-rendersconst values: IChatContext = useMemo(() => ({diff --git a/packages/app/src/react/features/ai-chat/pages/ai-chat.tsx b/packages/app/src/react/features/ai-chat/pages/ai-chat.tsxindex 527d8c08..b5fc5c64 100644--- a/packages/app/src/react/features/ai-chat/pages/ai-chat.tsx+++ b/packages/app/src/react/features/ai-chat/pages/ai-chat.tsx@@ -1,65 +1,17 @@-import { useEffect, useRef } from 'react';-import { useParams } from 'react-router-dom';-import { ChatHeader, Chats, Container, Footer } from '@react/features/ai-chat/components';-import { ChatProvider } from '@react/features/ai-chat/contexts';import { ChatContextProvider } from '@react/features/ai-chat/contexts/index.new';-import { useAgentChatContext } from '@react/features/ai-chat/hooks';-import { ChatInputRef } from '@react/features/ai-chat/types/chat.types';+import { memo } from 'react';-/**- * Agent Chat Page Component- * Modern implementation using new chat hooks with professional architecture- *- * This component is a thin wrapper that:- * 1. Extracts route params- * 2. Sets up chat context via useAgentChatContext hook- * 3. Manages UI refs (input, container)- * 4. Handles scroll behavior- * 5. Renders chat UI components- */const AgentChatPage = () => {- const params = useParams<{ agentId: string }>();- const agentId = params?.agentId;-- // UI refs for input focus and scroll management- const chatInputRef = useRef<ChatInputRef>(null);-- // ============================================================================- // CHAT CONTEXT SETUP- // ============================================================================- // All chat logic is now encapsulated in this single hook- const { isLoading, chatContextValue } = useAgentChatContext({- agentId: agentId || '',- inputRef: chatInputRef,- });-- // ============================================================================- // UI EFFECTS- // ============================================================================-- /**- * Auto-focus input when agent is loaded and not disabled- */- useEffect(() => {- if (!isLoading.agent && !chatContextValue.inputDisabled) chatInputRef.current?.focus();- }, [isLoading.agent, chatContextValue.inputDisabled]);-- // ============================================================================- // RENDER- // ============================================================================-return (<ChatContextProvider>- <ChatProvider value={chatContextValue}>- <Container>- <ChatHeader />- <Chats />- <Footer />- </Container>- </ChatProvider>+ <Container>+ <ChatHeader />+ <Chats />+ <Footer />+ </Container></ChatContextProvider>);};-export default AgentChatPage;+export default memo(AgentChatPage);