From 83149b017e1974d096ef1c8f4e9d01e0dc0d9818 Mon Sep 17 00:00:00 2001 From: Pascal MERCIER Date: Tue, 5 Nov 2024 15:02:35 +0100 Subject: [PATCH] fix: AskUserMessage answer was added in js memory without parentId resulting in wrongly ordered messages --- libs/react-client/src/types/file.ts | 1 + libs/react-client/src/useChatInteract.ts | 1 + libs/react-client/src/useChatSession.ts | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/react-client/src/types/file.ts b/libs/react-client/src/types/file.ts index af3fde1eba..9099a4163d 100644 --- a/libs/react-client/src/types/file.ts +++ b/libs/react-client/src/types/file.ts @@ -22,4 +22,5 @@ export interface IAsk { timeout: number; } & FileSpec & ActionSpec; + parentId?: string; } diff --git a/libs/react-client/src/useChatInteract.ts b/libs/react-client/src/useChatInteract.ts index ab646de970..b598093034 100644 --- a/libs/react-client/src/useChatInteract.ts +++ b/libs/react-client/src/useChatInteract.ts @@ -118,6 +118,7 @@ const useChatInteract = () => { const replyMessage = useCallback( (message: IStep) => { if (askUser) { + if (askUser.parentId) message.parentId = askUser.parentId; setMessages((oldMessages) => addMessage(oldMessages, message)); askUser.callback(message); } diff --git a/libs/react-client/src/useChatSession.ts b/libs/react-client/src/useChatSession.ts index 94f8d74eb5..9020847d2a 100644 --- a/libs/react-client/src/useChatSession.ts +++ b/libs/react-client/src/useChatSession.ts @@ -277,7 +277,7 @@ const useChatSession = () => { ); socket.on('ask', ({ msg, spec }, callback) => { - setAskUser({ spec, callback }); + setAskUser({ spec, callback, parentId: msg.parentId }); setMessages((oldMessages) => addMessage(oldMessages, msg)); setLoading(false);