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.

Enhance AIChat initialization logic to ensure fresh conversation on page load. Added a reference to track chat initialization state, preventing multiple session creations when agent settings are applied.

Salman-Ahamed22e715a02f15
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.tsx
index 8a3ac093..0be20465 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
@@ -28,6 +28,7 @@ const AIChat = () => {
const chatInputRef = useRef<ChatInputRef>(null);
const chatContainerRef = useRef<HTMLDivElement>(null);
const isFirstMessageSentRef = useRef(false);
+ const hasInitializedChatRef = useRef(false);
const navigate = useNavigate();
// API Hooks - optimized with minimal dependencies
@@ -122,13 +123,13 @@ const AIChat = () => {
}, [createNewChatSession, clearMessages, stopGenerating, setShowScrollButton]);
useEffect(() => {
- if (agentSettings && agent) {
+ if (agentSettings && agent && !hasInitializedChatRef.current) {
agent.aiAgentSettings = agentSettings;
agent.id = agentId;
- if (!agent?.aiAgentSettings?.lastConversationId) {
- createNewChatSession();
- }
+ // This ensures fresh conversation every time user loads the page
+ hasInitializedChatRef.current = true;
+ createNewChatSession();
}
}, [agentSettings, agent, agentId, createNewChatSession]);