Skip to content

Commit baef089

Browse files
committed
set interrupted announcement and show the last used query in the message bar
1 parent 51c9c3f commit baef089

12 files changed

Lines changed: 29 additions & 7 deletions

File tree

workspaces/lightspeed/plugins/lightspeed-backend/src/service/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export async function createRouter(
228228
const errormsg = `Error from lightspeed-core server: ${errorBody.error?.message || errorBody?.detail?.cause || 'Unknown error'}`;
229229
logger.error(errormsg);
230230
response.status(500).json({ error: errormsg });
231+
return;
231232
}
232233
response.status(fetchResponse.status).json(await fetchResponse.json());
233234
} catch (error) {

workspaces/lightspeed/plugins/lightspeed/report-alpha.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ readonly "conversation.rename": string;
8484
readonly "conversation.addToPinnedChats": string;
8585
readonly "conversation.removeFromPinnedChats": string;
8686
readonly "conversation.announcement.userMessage": string;
87+
readonly "conversation.announcement.responseStopped": string;
8788
readonly "user.guest": string;
8889
readonly "user.loading": string;
8990
readonly "tooltip.attach": string;

workspaces/lightspeed/plugins/lightspeed/src/components/LightSpeedChat.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
useCallback,
2222
useEffect,
2323
useMemo,
24+
useRef,
2425
useState,
2526
} from 'react';
2627
import {
@@ -167,6 +168,8 @@ export const LightspeedChat = ({
167168
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState<boolean>(false);
168169
const [isRenameModalOpen, setIsRenameModalOpen] = useState<boolean>(false);
169170
const [isSortSelectOpen, setIsSortSelectOpen] = useState<boolean>(false);
171+
const [messageBarKey, setMessageBarKey] = useState(0);
172+
const wasStoppedByUserRef = useRef(false);
170173
const { isReady, lastOpenedId, setLastOpenedId, clearLastOpenedId } =
171174
useLastOpenedConversation(user);
172175
const {
@@ -296,7 +299,10 @@ export const LightspeedChat = ({
296299

297300
const onComplete = (message: string) => {
298301
setIsSendButtonDisabled(false);
299-
setAnnouncement(`Message from Bot: ${message}`);
302+
if (!wasStoppedByUserRef.current) {
303+
setAnnouncement(`Message from Bot: ${message}`);
304+
}
305+
wasStoppedByUserRef.current = false;
300306
queryClient.invalidateQueries({
301307
queryKey: ['conversations'],
302308
});
@@ -324,6 +330,7 @@ export const LightspeedChat = ({
324330
const sendMessage = (message: string | number) => {
325331
if (!message.toString().trim()) return;
326332

333+
wasStoppedByUserRef.current = false;
327334
if (conversationId !== TEMP_CONVERSATION_ID) {
328335
setNewChatCreated(false);
329336
}
@@ -682,13 +689,19 @@ export const LightspeedChat = ({
682689
const { mutate: stopConversation } = useStopConversation();
683690

684691
const handleStopButton = () => {
692+
wasStoppedByUserRef.current = true;
685693
if (requestId) {
686694
stopConversation(requestId);
687695
setRequestId('');
688696
}
689697
setIsSendButtonDisabled(false);
690-
setAnnouncement('');
691-
setDraftMessage('');
698+
setAnnouncement(t('conversation.announcement.responseStopped'));
699+
const lastUserMessage = [...conversationMessages]
700+
.reverse()
701+
.find((m: { role?: string }) => m.role === 'user');
702+
const restoredPrompt = (lastUserMessage?.content as string) ?? '';
703+
setDraftMessage(restoredPrompt.trim());
704+
if (restoredPrompt) setMessageBarKey(k => k + 1);
692705
setFileContents([]);
693706
setUploadError({ message: null });
694707
};
@@ -851,6 +864,7 @@ export const LightspeedChat = ({
851864
<ChatbotFooter className={classes.footer}>
852865
<FilePreview />
853866
<MessageBar
867+
key={messageBarKey}
854868
onSendMessage={sendMessage}
855869
isSendButtonDisabled={isSendButtonDisabled}
856870
hasStopButton={isSendButtonDisabled}

workspaces/lightspeed/plugins/lightspeed/src/components/RenameConversationModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ export const RenameConversationModal = ({
5858
c => c.conversation_id === conversationId,
5959
);
6060
if (conversation) {
61-
setChatName(conversation.topic_summary);
62-
setOriginalChatName(conversation.topic_summary);
61+
setChatName(conversation.topic_summary ?? '');
62+
setOriginalChatName(conversation.topic_summary ?? '');
6363
} else {
6464
setChatName('');
6565
setOriginalChatName('');

workspaces/lightspeed/plugins/lightspeed/src/translations/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const lightspeedTranslationDe = createTranslationMessages({
110110
'conversation.removeFromPinnedChats': 'Lösen',
111111
'conversation.announcement.userMessage':
112112
'Nachricht vom Benutzer: {{prompt}}. Nachricht vom Bot wird geladen.',
113+
'conversation.announcement.responseStopped': 'Antwort angehalten.',
113114
'user.loading': '...',
114115
'tooltip.attach': 'Anhängen',
115116
'tooltip.send': 'Senden',

workspaces/lightspeed/plugins/lightspeed/src/translations/es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const lightspeedTranslationEs = createTranslationMessages({
110110
'conversation.removeFromPinnedChats': 'Quitar fijación',
111111
'conversation.announcement.userMessage':
112112
'Mensaje del usuario: {{prompt}}. El mensaje del bot se está cargando.',
113+
'conversation.announcement.responseStopped': 'Respuesta detenida.',
113114
'user.loading': '...',
114115
'tooltip.attach': 'Adjuntar',
115116
'tooltip.send': 'Enviar',

workspaces/lightspeed/plugins/lightspeed/src/translations/fr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ const lightspeedTranslationFr = createTranslationMessages({
122122
'conversation.removeFromPinnedChats': 'Détacher',
123123
'conversation.announcement.userMessage':
124124
'Message en provenance de l’utilisateur: {{prompt}}. Message en provenance du Bot en cours de chargement.',
125+
'conversation.announcement.responseStopped': 'Réponse arrêtée.',
125126
'user.guest': 'Invité',
126127
'user.loading': '...',
127128
'tooltip.attach': 'Attacher',

workspaces/lightspeed/plugins/lightspeed/src/translations/it.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ const lightspeedTranslationIt = createTranslationMessages({
122122
'conversation.removeFromPinnedChats': 'Sblocca',
123123
'conversation.announcement.userMessage':
124124
"Messaggio dall'utente: {{prompt}}. Caricamento in corso del messaggio del bot.",
125+
'conversation.announcement.responseStopped': 'Risposta interrotta.',
125126
'user.guest': 'Ospite',
126127
'user.loading': '...',
127128
'tooltip.attach': 'Allega',

workspaces/lightspeed/plugins/lightspeed/src/translations/ja.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const lightspeedTranslationJa = createTranslationMessages({
120120
'conversation.removeFromPinnedChats': '固定解除',
121121
'conversation.announcement.userMessage':
122122
'ユーザーからのメッセージ: {{prompt}}。ボットからのメッセージを読み込んでいます。',
123+
'conversation.announcement.responseStopped': '応答を停止しました。',
123124
'user.guest': 'ゲスト',
124125
'user.loading': '...',
125126
'tooltip.attach': '割り当て',

workspaces/lightspeed/plugins/lightspeed/src/translations/ref.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export const lightspeedMessages = {
141141
'conversation.removeFromPinnedChats': 'Unpin',
142142
'conversation.announcement.userMessage':
143143
'Message from User: {{prompt}}. Message from Bot is loading.',
144+
'conversation.announcement.responseStopped': 'Response stopped.',
144145

145146
// User states
146147
'user.guest': 'Guest',

0 commit comments

Comments
 (0)