diff --git a/src/assistant/AssistantProvider.jsx b/src/assistant/AssistantProvider.jsx index adeaf5f22..818c60e39 100644 --- a/src/assistant/AssistantProvider.jsx +++ b/src/assistant/AssistantProvider.jsx @@ -52,6 +52,7 @@ const AssistantProvider = ({ children }) => { useRealtime(client, { [CHAT_EVENTS_DOCTYPE]: { created: res => { + // to exclude realtime messages if not relevant to the actual conversation if (!isMessageForThisConversation(res, assistantState.messagesId)) { return } @@ -79,17 +80,23 @@ const AssistantProvider = ({ children }) => { } }) + const clearAssistant = useCallback( + () => + setAssistantState({ + message: '', + status: 'idle', + messagesId: [] + }), + [] + ) + const onAssistantExecute = useCallback( async ({ value, conversationId }, callback) => { if (!value) return callback?.() - setAssistantState(v => ({ - ...v, - message: '', - status: 'idle' - })) + clearAssistant() await client.stackClient.fetchJSON( 'POST', @@ -101,21 +108,10 @@ const AssistantProvider = ({ children }) => { setAssistantState(v => ({ ...v, - message: '', status: 'pending' })) }, - [client] - ) - - const clearAssistant = useCallback( - () => - setAssistantState({ - message: '', - status: 'idle', - messagesId: [] - }), - [] + [client, clearAssistant] ) const value = useMemo( diff --git a/src/assistant/Views/AssistantDialog.jsx b/src/assistant/Views/AssistantDialog.jsx index 14614bbf0..f774a0156 100644 --- a/src/assistant/Views/AssistantDialog.jsx +++ b/src/assistant/Views/AssistantDialog.jsx @@ -9,14 +9,13 @@ import ConversationBar from '../Conversations/ConversationBar' import { useAssistant } from '../AssistantProvider' const AssistantDialog = () => { - const { assistantState, clearAssistant } = useAssistant() + const { assistantState } = useAssistant() const { isMobile } = useBreakpoints() const navigate = useNavigate() const { conversationId } = useParams() const onClose = () => { navigate('..') - clearAssistant() } return (