Fix double message send

This commit is contained in:
Weves
2024-04-30 01:40:02 -07:00
committed by Chris Weaver
parent 3fb68af405
commit b89e9127d7
3 changed files with 17 additions and 8 deletions

View File

@@ -408,7 +408,7 @@ def seed_chat(
)
return ChatSeedResponse(
redirect_url=f"{WEB_DOMAIN}/chat?chatId={new_chat_session.id}"
redirect_url=f"{WEB_DOMAIN}/chat?chatId={new_chat_session.id}&seeded=true"
)

View File

@@ -180,6 +180,8 @@ export function ChatPage({
);
const newMessageHistory = processRawChatHistory(chatSession.messages);
// if the last message is an error, don't overwrite it
if (messageHistory[messageHistory.length - 1]?.type !== "error") {
setMessageHistory(newMessageHistory);
const latestMessageId =
@@ -187,13 +189,18 @@ export function ChatPage({
setSelectedMessageForDocDisplay(
latestMessageId !== undefined ? latestMessageId : null
);
}
setChatSessionSharedStatus(chatSession.shared_status);
setIsFetchingChatMessages(false);
// if this is a seeded chat, then kick off the AI message generation
if (newMessageHistory.length === 1 && !submitOnLoadPerformed.current) {
if (
newMessageHistory.length === 1 &&
!submitOnLoadPerformed.current &&
searchParams.get(SEARCH_PARAM_NAMES.SEEDED) === "true"
) {
submitOnLoadPerformed.current = true;
const seededMessage = newMessageHistory[0].message;
await onSubmit({

View File

@@ -13,6 +13,8 @@ export const SEARCH_PARAM_NAMES = {
SUBMIT_ON_LOAD: "submit-on-load",
// chat title
TITLE: "title",
// for seeding chats
SEEDED: "seeded",
};
export function shouldSubmitOnLoad(searchParams: ReadonlyURLSearchParams) {