mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
Fix Input losing focus (#382)
* fix(PaLM2): input losing focus on message stream ending * fix(askOpenAI.js): fix typo in variable name from newUserMassageId to newUserMessageId * feat(chatgpt-browser.js, askBingAI.js, askChatGPTBrowser.js): add onEventMessage callback to browserClient Add onEventMessage callback to browserClient to handle event messages from the server. In askChatGPTBrowser.js, add a getPartialMessage variable to store the partial message text. In askBingAI.js, fix a typo in the variable name newUserMassageId to newUserMessageId. In askChatGPTBrowser.js, remove the preSendRequest parameter and move the sendMessage call to the onEventMessage callback. In askChatGPTBrowser.js, add a check for null or undefined value of getPartialMessage before appending it to the error message. * fix(bing): input no longer loses input focus as convoId is persisted from beginning of convo * refactor(Input): remove unused code and fix input autofocus feat(package.json): add e2e:test-auth script to test authentication flow with saved storage
This commit is contained in:
parent
11b98d3d13
commit
c0845ad0b1
8 changed files with 59 additions and 72 deletions
|
|
@ -129,10 +129,15 @@ const ask = async ({
|
|||
}
|
||||
});
|
||||
const abortController = new AbortController();
|
||||
let bingConversationId = null;
|
||||
if (!isNewConversation) {
|
||||
const convo = await getConvo(req.user.id, conversationId);
|
||||
bingConversationId = convo.bingConversationId;
|
||||
}
|
||||
let response = await askBing({
|
||||
text,
|
||||
parentMessageId: userParentMessageId,
|
||||
conversationId,
|
||||
conversationId: bingConversationId ?? conversationId,
|
||||
...endpointOption,
|
||||
onProgress: progressCallback.call(null, {
|
||||
res,
|
||||
|
|
@ -147,7 +152,7 @@ const ask = async ({
|
|||
const newConversationId = endpointOption?.jailbreak
|
||||
? response.jailbreakConversationId
|
||||
: response.conversationId || conversationId;
|
||||
const newUserMassageId =
|
||||
const newUserMessageId =
|
||||
response.parentMessageId || response.details.requestId || userMessageId;
|
||||
const newResponseMessageId = response.messageId || response.details.messageId;
|
||||
|
||||
|
|
@ -156,10 +161,11 @@ const ask = async ({
|
|||
response.response || response.details.spokenText || '**Bing refused to answer.**';
|
||||
|
||||
let responseMessage = {
|
||||
conversationId: newConversationId,
|
||||
conversationId,
|
||||
bingConversationId: newConversationId,
|
||||
messageId: responseMessageId,
|
||||
newMessageId: newResponseMessageId,
|
||||
parentMessageId: overrideParentMessageId || newUserMassageId,
|
||||
parentMessageId: overrideParentMessageId || newUserMessageId,
|
||||
sender: endpointOption?.jailbreak ? 'Sydney' : 'BingAI',
|
||||
text: await handleText(response, true),
|
||||
suggestions:
|
||||
|
|
@ -173,31 +179,7 @@ const ask = async ({
|
|||
await saveMessage(responseMessage);
|
||||
responseMessage.messageId = newResponseMessageId;
|
||||
|
||||
// STEP2 update the convosation.
|
||||
|
||||
// First update conversationId if needed
|
||||
// Note!
|
||||
// Bing API will not use our conversationId at the first time,
|
||||
// so change the placeholder conversationId to the real one.
|
||||
// Attition: the api will also create new conversationId while using invalid userMessage.parentMessageId,
|
||||
// but in this situation, don't change the conversationId, but create new convo.
|
||||
|
||||
let conversationUpdate = { conversationId: newConversationId, endpoint: 'bingAI' };
|
||||
if (conversationId != newConversationId)
|
||||
if (isNewConversation) {
|
||||
// change the conversationId to new one
|
||||
conversationUpdate = {
|
||||
...conversationUpdate,
|
||||
conversationId: conversationId,
|
||||
newConversationId: newConversationId
|
||||
};
|
||||
} else {
|
||||
// create new conversation
|
||||
conversationUpdate = {
|
||||
...conversationUpdate,
|
||||
...endpointOption
|
||||
};
|
||||
}
|
||||
let conversationUpdate = { conversationId, bingConversationId: newConversationId, endpoint: 'bingAI' };
|
||||
|
||||
if (endpointOption?.jailbreak) {
|
||||
conversationUpdate.jailbreak = true;
|
||||
|
|
@ -210,20 +192,16 @@ const ask = async ({
|
|||
}
|
||||
|
||||
await saveConvo(req.user.id, conversationUpdate);
|
||||
conversationId = newConversationId;
|
||||
|
||||
// STEP3 update the user message
|
||||
userMessage.conversationId = newConversationId;
|
||||
userMessage.messageId = newUserMassageId;
|
||||
userMessage.messageId = newUserMessageId;
|
||||
|
||||
// If response has parentMessageId, the fake userMessage.messageId should be updated to the real one.
|
||||
if (!overrideParentMessageId)
|
||||
await saveMessage({
|
||||
...userMessage,
|
||||
messageId: userMessageId,
|
||||
newMessageId: newUserMassageId
|
||||
newMessageId: newUserMessageId
|
||||
});
|
||||
userMessageId = newUserMassageId;
|
||||
userMessageId = newUserMessageId;
|
||||
|
||||
sendMessage(res, {
|
||||
title: await getConvoTitle(req.user.id, conversationId),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue