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.

Update chat route to include 'X-AGENT-ID' header; modify AIChat component to use 'isPending' for chat creation status and add conditional session initialization based on last conversation ID.

Salman-Ahamed54649340801e
diff --git a/packages/app/src/backend/routes/api/page/chat.ts b/packages/app/src/backend/routes/api/page/chat.ts
index 73c8a097..9a3739ec 100644
--- a/packages/app/src/backend/routes/api/page/chat.ts
+++ b/packages/app/src/backend/routes/api/page/chat.ts
@@ -149,9 +149,9 @@ router.post('/new', async (req, res) => {
...includeAxiosAuth(token).headers,
'x-user-id': userId,
'x-team-id': teamId,
+ 'X-AGENT-ID': agentId,
'x-agent-id': agentId,
'x-smyth-team-id': teamId,
- 'X-AGENT-ID': agentId,
},
},
);
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 8740b9da..ccfb62e3 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
@@ -70,7 +70,7 @@ const AIChat: FC<AIChatProps> = ({
});
const { data: agentSettingsData } = useAgentSettings(agentId || '');
- const { mutateAsync: createChat, isLoading: isChatCreating } = useCreateChatMutation();
+ const { mutateAsync: createChat, isPending: isChatCreating } = useCreateChatMutation();
const { mutateAsync: updateAgentSettings } = useUpdateAgentSettingsMutation();
// Custom Hooks - optimized
@@ -149,28 +149,19 @@ const AIChat: FC<AIChatProps> = ({
Analytics.track(EVENTS.CHAT_EVENTS.SESSION_START);
}, [createNewChatSession, clearMessages, stopGenerating, setShowScrollButton]);
- // Fast effects - minimal dependencies
useEffect(() => {
if (agentSettingsData?.settings && currentAgent) {
currentAgent.aiAgentSettings = agentSettingsData.settings;
currentAgent.id = agentId;
- // Always start with a clear session when opening the chat
- createNewChatSession();
+ if (!currentAgent?.aiAgentSettings?.lastConversationId) {
+ createNewChatSession();
+ }
}
}, [agentSettingsData, currentAgent, agentId, createNewChatSession]);
- // Ensure clean state on mount - clear chat history every time page loads
useEffect(() => {
- clearMessages();
- setShowScrollButton(false);
- isFirstMessageSentRef.current = false;
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
-
- useEffect(() => {
- if (!isAgentLoading && !isQueryInputDisabled) {
- queryInputRef.current?.focus();
- }
+ if (!isAgentLoading && !isQueryInputDisabled) queryInputRef.current?.focus();
}, [isAgentLoading, isQueryInputDisabled]);
useEffect(() => {