diff --git a/server/routes/ask.js b/server/routes/ask.js index c64be8e0ad..20c2f94e9f 100644 --- a/server/routes/ask.js +++ b/server/routes/ask.js @@ -17,7 +17,7 @@ const sendMessage = (res, message) => { }; router.post('/bing', async (req, res) => { - const { model, text, conversationSignature, conversationId } = req.body; + const { model, text, ...convo } = req.body; if (!text.trim().includes(' ') && text.length < 5) { return handleError(res, 'Prompt empty or too short'); } @@ -25,7 +25,7 @@ router.post('/bing', async (req, res) => { const userMessageId = crypto.randomUUID(); let userMessage = { id: userMessageId, sender: 'User', text }; - console.log('ask log', { model, ...userMessage, conversationSignature, conversationId }); + console.log('ask log', { model, ...userMessage, ...convo }); res.writeHead(200, { Connection: 'keep-alive', @@ -45,19 +45,16 @@ router.post('/bing', async (req, res) => { let response = await askBing({ text, - progressCallback - // convo: { - // parentMessageId, - // conversationId - // } + progressCallback, + convo }); console.log('CLIENT RESPONSE'); console.dir(response, { depth: null }); userMessage.conversationSignature = - conversationSignature || response.conversationSignature; - userMessage.conversationId = conversationId || response.conversationId; + convo.conversationSignature || response.conversationSignature; + userMessage.conversationId = convo.conversationId || response.conversationId; userMessage.invocationId = response.invocationId; await saveMessage(userMessage); @@ -69,7 +66,7 @@ router.post('/bing', async (req, res) => { // return handleError(res, 'Prompt empty or too short'); // } - if (!conversationSignature) { + if (!convo.conversationSignature) { response.title = await titleConvo(text, response.response); } @@ -176,4 +173,4 @@ router.post('/', async (req, res) => { } }); -module.exports = router; +module.exports = router; \ No newline at end of file diff --git a/src/components/Conversations/Conversation.jsx b/src/components/Conversations/Conversation.jsx index fda1d0c24c..0da9ff6881 100644 --- a/src/components/Conversations/Conversation.jsx +++ b/src/components/Conversations/Conversation.jsx @@ -8,7 +8,13 @@ import { setText } from '~/store/textSlice'; import manualSWR from '~/utils/fetchers'; import ConvoIcon from '../svg/ConvoIcon'; -export default function Conversation({ id, parentMessageId, conversationId, title = 'New conversation' }) { +export default function Conversation({ + id, + parentMessageId, + conversationId, + title = 'New conversation', + bingData +}) { const [renaming, setRenaming] = useState(false); const [titleInput, setTitleInput] = useState(title); const inputRef = useRef(null); @@ -21,7 +27,34 @@ export default function Conversation({ id, parentMessageId, conversationId, titl return; } - dispatch(setConversation({ title, error: false, conversationId: id, parentMessageId })); + if (bingData) { + const { title, conversationSignature, clientId, conversationId, invocationId } = + bingData; + dispatch( + setConversation({ + title, + conversationSignature, + clientId, + conversationId, + invocationId, + error: false, + conversationId: id, + parentMessageId: null + }) + ); + } else { + dispatch( + setConversation({ + title, + error: false, + conversationId: id, + parentMessageId, + conversationSignature: null, + clientId: null, + invocationId: null + }) + ); + } const data = await trigger(); dispatch(setMessages(data)); dispatch(setText('')); @@ -71,12 +104,12 @@ export default function Conversation({ id, parentMessageId, conversationId, titl {...aProps} > -
+
{renaming === true ? ( setTitleInput(e.target.value)} onBlur={onRename} diff --git a/src/components/Conversations/index.jsx b/src/components/Conversations/index.jsx index d14bd654f5..8cbd57e024 100644 --- a/src/components/Conversations/index.jsx +++ b/src/components/Conversations/index.jsx @@ -2,7 +2,6 @@ import React, { useState } from 'react'; import Conversation from './Conversation'; export default function Conversations({ conversations, conversationId }) { - // const currentRef = useRef(null); // const scrollToTop = () => { @@ -20,15 +19,26 @@ export default function Conversations({ conversations, conversationId }) { {/*
*/} {conversations && conversations.length > 0 && - conversations.map((convo, i) => ( - - ))} + conversations.map((convo, i) => { + const bingData = convo.conversationSignature + ? { + conversationSignature: convo.conversationSignature, + clientId: convo.clientId, + invocationId: convo.invocationId + } + : null; + + return ( + + ); + })} {conversations && conversations.length >= 12 && (
); -} +} \ No newline at end of file diff --git a/src/store/convoSlice.js b/src/store/convoSlice.js index 601575c5cb..1edabfb771 100644 --- a/src/store/convoSlice.js +++ b/src/store/convoSlice.js @@ -8,7 +8,7 @@ const initialState = { conversationSignature: null, clientId: null, invocationId: null, - convosLoading: false, + convosLoading: false }; const currentSlice = createSlice({ @@ -20,7 +20,7 @@ const currentSlice = createSlice({ }, setError: (state, action) => { state.error = action.payload; - }, + } // setConvos: (state, action) => state.convos = action.payload, } });