|
|
@@ -30,7 +30,7 @@ export const useChatInput = ({
|
|
|
}: Props) => {
|
|
|
let myMsgUk = "";
|
|
|
let mySessionId = "";
|
|
|
-
|
|
|
+
|
|
|
// 聊天框 store
|
|
|
const {
|
|
|
pushRobotMessage,
|
|
|
@@ -47,8 +47,8 @@ export const useChatInput = ({
|
|
|
setScrollTop,
|
|
|
setAutoScroll,
|
|
|
} = useTextChat();
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// 聊天框内消息定时上报
|
|
|
const { startTimedMessage, stopTimedMessage } =
|
|
|
@@ -72,14 +72,14 @@ export const useChatInput = ({
|
|
|
setMessageStopHandle(null)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
// 聊天
|
|
|
const chatWithGpt = async (
|
|
|
message: string,
|
|
|
sessionId: string,
|
|
|
msgUk: string
|
|
|
) => {
|
|
|
-
|
|
|
+
|
|
|
if (!agent?.agentId) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -99,7 +99,7 @@ export const useChatInput = ({
|
|
|
let currentRobotMsgUk = "";
|
|
|
await delay(300);
|
|
|
setDisabled?.(true);
|
|
|
-
|
|
|
+
|
|
|
const submitMyMessageSuccess = await sendMyMessageToServer({
|
|
|
agentId: agent.agentId,
|
|
|
message,
|
|
|
@@ -107,15 +107,15 @@ export const useChatInput = ({
|
|
|
msgUk,
|
|
|
sessionId
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
// todo: 如果自己发送的消息失败了,需要显示错误信息提示用户?
|
|
|
if (!submitMyMessageSuccess) {
|
|
|
setReacting(false)
|
|
|
setDisabled?.(false);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
let isFirstChunk = true;
|
|
|
console.log('==== start new chat ====')
|
|
|
@@ -222,7 +222,7 @@ export const useChatInput = ({
|
|
|
if(!enableOutputAudioStream){
|
|
|
enableUserInput()
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
stopTimedMessage();
|
|
|
if (!agent.agentId) {
|
|
|
return;
|
|
|
@@ -266,7 +266,7 @@ export const useChatInput = ({
|
|
|
sessionId
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
onError: () => {
|
|
|
setDisabled?.(false);
|
|
|
@@ -283,7 +283,7 @@ export const useChatInput = ({
|
|
|
if(!message.length){
|
|
|
console.log('empty message')
|
|
|
myMsgUk && deleteMessage(myMsgUk);
|
|
|
- return
|
|
|
+ return
|
|
|
}
|
|
|
updateMessage(message, myMsgUk);
|
|
|
chatWithGpt(message, mySessionId, myMsgUk);
|
|
|
@@ -298,6 +298,7 @@ export const useChatInput = ({
|
|
|
const handleBeforeSend = () => {
|
|
|
console.log('bubble started')
|
|
|
const { sessionId, msgUk } = pushMessage("");
|
|
|
+ setQuestions([]);
|
|
|
console.log('bubble end')
|
|
|
myMsgUk = msgUk;
|
|
|
mySessionId = sessionId;
|
|
|
@@ -327,7 +328,7 @@ export const useChatInput = ({
|
|
|
}
|
|
|
}
|
|
|
}, [enableOutputAudioStream]);
|
|
|
-
|
|
|
+
|
|
|
// 清理
|
|
|
useEffect(() => {
|
|
|
console.log('chat input ')
|