Commit 0ead4239 by heheer Committed by GitHub

add send question condition check (#5130)

* add send question condition check

* fix
parent 2bd53450
...@@ -851,6 +851,8 @@ const ChatBox = ({ ...@@ -851,6 +851,8 @@ const ChatBox = ({
abortRequest('leave'); abortRequest('leave');
}, [chatId, appId, abortRequest, setValue]); }, [chatId, appId, abortRequest, setValue]);
const canSendPrompt = onStartChat && chatStarted && active && !isInteractive;
// Add listener // Add listener
useEffect(() => { useEffect(() => {
const windowMessage = ({ data }: MessageEvent<{ type: 'sendPrompt'; text: string }>) => { const windowMessage = ({ data }: MessageEvent<{ type: 'sendPrompt'; text: string }>) => {
...@@ -863,7 +865,9 @@ const ChatBox = ({ ...@@ -863,7 +865,9 @@ const ChatBox = ({
window.addEventListener('message', windowMessage); window.addEventListener('message', windowMessage);
const fn: SendPromptFnType = (e) => { const fn: SendPromptFnType = (e) => {
sendPrompt(e); if (canSendPrompt || e.isInteractivePrompt) {
sendPrompt(e);
}
}; };
eventBus.on(EventNameEnum.sendQuestion, fn); eventBus.on(EventNameEnum.sendQuestion, fn);
eventBus.on(EventNameEnum.editQuestion, ({ text }: { text: string }) => { eventBus.on(EventNameEnum.editQuestion, ({ text }: { text: string }) => {
...@@ -876,7 +880,7 @@ const ChatBox = ({ ...@@ -876,7 +880,7 @@ const ChatBox = ({
eventBus.off(EventNameEnum.sendQuestion); eventBus.off(EventNameEnum.sendQuestion);
eventBus.off(EventNameEnum.editQuestion); eventBus.off(EventNameEnum.editQuestion);
}; };
}, [isReady, resetInputVal, sendPrompt]); }, [isReady, resetInputVal, sendPrompt, canSendPrompt]);
// Auto send prompt // Auto send prompt
useDebounceEffect( useDebounceEffect(
...@@ -1098,7 +1102,7 @@ const ChatBox = ({ ...@@ -1098,7 +1102,7 @@ const ChatBox = ({
{/* chat box container */} {/* chat box container */}
{RenderRecords} {RenderRecords}
{/* message input */} {/* message input */}
{onStartChat && chatStarted && active && !isInteractive && ( {canSendPrompt && (
<ChatInput <ChatInput
onSendMessage={sendPrompt} onSendMessage={sendPrompt}
onStop={() => chatController.current?.abort('stop')} onStop={() => chatController.current?.abort('stop')}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment