Skip to content

Commit 2b7da0d

Browse files
committed
set interrupted announcement and show the last used query in the message bar
1 parent 2d6519e commit 2b7da0d

12 files changed

Lines changed: 28 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: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ export const LightspeedChat = ({
192192
const [isSortSelectOpen, setIsSortSelectOpen] = useState<boolean>(false);
193193
const contentScrollRef = useRef<HTMLDivElement>(null);
194194
const bottomSentinelRef = useRef<HTMLDivElement>(null);
195+
const [messageBarKey, setMessageBarKey] = useState(0);
196+
const wasStoppedByUserRef = useRef(false);
195197
const { isReady, lastOpenedId, setLastOpenedId, clearLastOpenedId } =
196198
useLastOpenedConversation(user);
197199
const {
@@ -321,7 +323,10 @@ export const LightspeedChat = ({
321323

322324
const onComplete = (message: string) => {
323325
setIsSendButtonDisabled(false);
324-
setAnnouncement(`Message from Bot: ${message}`);
326+
if (!wasStoppedByUserRef.current) {
327+
setAnnouncement(`Message from Bot: ${message}`);
328+
}
329+
wasStoppedByUserRef.current = false;
325330
queryClient.invalidateQueries({
326331
queryKey: ['conversations'],
327332
});
@@ -349,6 +354,7 @@ export const LightspeedChat = ({
349354
const sendMessage = (message: string | number) => {
350355
if (!message.toString().trim()) return;
351356

357+
wasStoppedByUserRef.current = false;
352358
if (conversationId !== TEMP_CONVERSATION_ID) {
353359
setNewChatCreated(false);
354360
}
@@ -745,13 +751,19 @@ export const LightspeedChat = ({
745751
const { mutate: stopConversation } = useStopConversation();
746752

747753
const handleStopButton = () => {
754+
wasStoppedByUserRef.current = true;
748755
if (requestId) {
749756
stopConversation(requestId);
750757
setRequestId('');
751758
}
752759
setIsSendButtonDisabled(false);
753-
setAnnouncement('');
754-
setDraftMessage('');
760+
setAnnouncement(t('conversation.announcement.responseStopped'));
761+
const lastUserMessage = [...conversationMessages]
762+
.reverse()
763+
.find((m: { role?: string }) => m.role === 'user');
764+
const restoredPrompt = (lastUserMessage?.content as string) ?? '';
765+
setDraftMessage(restoredPrompt.trim());
766+
if (restoredPrompt) setMessageBarKey(k => k + 1);
755767
setFileContents([]);
756768
setUploadError({ message: null });
757769
};
@@ -929,6 +941,7 @@ export const LightspeedChat = ({
929941
<ChatbotFooter className={classes.footer}>
930942
<FilePreview />
931943
<MessageBar
944+
key={messageBarKey}
932945
onSendMessage={sendMessage}
933946
isSendButtonDisabled={isSendButtonDisabled}
934947
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)