Skip to content

Commit

Permalink
add timeout to chat
Browse files Browse the repository at this point in the history
  • Loading branch information
lokesh-couchbase committed Jan 25, 2024
1 parent be3cc49 commit 3a77988
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/reactViews/iq/pages/chatscreen/IqChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const IqChat = ({ org, setIsLoading }) => {
qaId: "",
});
const [actions, setActions] = useState<IActionBarButton[]>([]);
const [runningConversation, setRunningConversation] = useState<string | undefined>(undefined);

useEffect(() => {
setIsLoading(false);
Expand Down Expand Up @@ -297,6 +298,16 @@ const IqChat = ({ org, setIsLoading }) => {
setShowNewChatModal(true);
};

const onChatCompleted = (error) => {
setIsTyping(false);
setShowFeedbackModal(false);
setShowNewChatModal(false);
setActions([]);
setIsChatCompleted(true);
const formattedError = parseErrorMessages(JSON.parse(error));
setErrorMessage(formattedError);
};

window.addEventListener("message", (event) => {
const message = event.data;
switch (message.command) {
Expand All @@ -314,6 +325,7 @@ const IqChat = ({ org, setIsLoading }) => {
msgDate: message.msgDate,
qaId: message.qaId,
};
setRunningConversation(undefined);
const updatedMessages = [...messages.userChats, newMessage];

setMessages({
Expand Down Expand Up @@ -360,13 +372,7 @@ const IqChat = ({ org, setIsLoading }) => {
}
case "vscode-couchbase.iq.chatCompleted": {
// The chat has ran into some errors and can no longer be continued.
setIsTyping(false);
setShowFeedbackModal(false);
setShowNewChatModal(false);
setActions([]);
setIsChatCompleted(true);
const formattedError = parseErrorMessages(JSON.parse(message.error));
setErrorMessage(formattedError);
onChatCompleted(message.error);
break;
}
}
Expand Down Expand Up @@ -403,6 +409,15 @@ const IqChat = ({ org, setIsLoading }) => {
qaId: newMessage.qaId,
},
});

setRunningConversation(newMessage.qaId);

setTimeout(()=>{
if(runningConversation === newMessage.qaId){
onChatCompleted("The chat has timed out. Please ask again with a new conversation");
}
}, 60000);

} catch (error) {
console.error("Error processing message:", error);
}
Expand Down

0 comments on commit 3a77988

Please sign in to comment.