fix(editor): Fix an issue with an empty chat response if not in output property (#8913)
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
@@ -45,9 +45,19 @@ export const ChatPlugin: Plugin<ChatOptions> = {
|
||||
options,
|
||||
);
|
||||
|
||||
let textMessage = sendMessageResponse.output ?? sendMessageResponse.text ?? '';
|
||||
|
||||
if (textMessage === '' && Object.keys(sendMessageResponse).length > 0) {
|
||||
try {
|
||||
textMessage = JSON.stringify(sendMessageResponse, null, 2);
|
||||
} catch (e) {
|
||||
// Failed to stringify the object so fallback to empty string
|
||||
}
|
||||
}
|
||||
|
||||
const receivedMessage: ChatMessage = {
|
||||
id: uuidv4(),
|
||||
text: sendMessageResponse.output,
|
||||
text: textMessage,
|
||||
sender: 'bot',
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
@@ -13,5 +13,6 @@ export interface LoadPreviousSessionResponse {
|
||||
}
|
||||
|
||||
export interface SendMessageResponse {
|
||||
output: string;
|
||||
output?: string;
|
||||
text?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user