From 64d15d8c26baae5bdff0dcfbcfdd4f13d219041c Mon Sep 17 00:00:00 2001 From: zhangxiao <898441624@qq.com> Date: 星期四, 26 九月 2024 14:54:18 +0800 Subject: [PATCH] 修改注册功能url --- src/views/sessionManager/components/agentSession.vue | 140 +++++++++++++++++++++------------------------- 1 files changed, 63 insertions(+), 77 deletions(-) diff --git a/src/views/sessionManager/components/agentSession.vue b/src/views/sessionManager/components/agentSession.vue index 2e65936..e10748a 100644 --- a/src/views/sessionManager/components/agentSession.vue +++ b/src/views/sessionManager/components/agentSession.vue @@ -70,11 +70,7 @@ /> </template> <template #content> - <!-- <a-card :class="{ chatItemAnswer: theme === 'light' }">--> - <!-- <div :class="{ light: theme === 'light' }"--> - <!-- >{{ sessionDetail.content }}--> - <!-- </div>--> - <!-- </a-card>--> + <a-textarea readonly auto-size @@ -86,18 +82,7 @@ style="border: none" > </a-textarea> - <!-- <div class="prompt"> - <ul> - <li class="prompt-item" @click="copyText('43234')"> - <span> - 344343klsdjkjksdjkjksdjk灏卞紑濮嬪ぇ瀹剁湅鏁版嵁搴撶櫥璁板崱鍙楁墦鍑诲嚡鎾掔櫥璁板崱鍙楁墦鍑诲嚡鎾掔櫥璁板崱鍙楁墦鍑诲嚡鎾掔殑43</span - > - <span style="margin-left: 20px"> - <icon-right /> - </span> - </li> - </ul> - </div> --> + </template> <template #actions> <span @@ -189,19 +174,7 @@ <icon-send size="32" style="color: #0960bd" /> </a-button> </div> - <!-- <div class="btn-send">--> - <!-- <!– <icon-send size="32" /> –>--> - <!-- <a-button--> - <!-- :disabled="chatDis"--> - <!-- @click="sentClick"--> - <!-- type="text"--> - <!-- style="border-radius: 24px"--> - <!-- :loading="loading"--> - <!-- >--> - <!-- <icon-send size="32" style="color: #0960bd;"/>--> - <!-- </a-button--> - <!-- >--> - <!-- </div>--> + </div> <a-modal v-model:visible="visible" @@ -250,8 +223,8 @@ import { agentResetApi, agentSetApi, - getAgentSessionDetailsApi, - } from '@/api/agentSession'; + getAgentSessionDetailsApi, updateAgentConversation + } from "@/api/agentSession"; import EventBus from '@/utils/EventBus'; import useClipboard from 'vue-clipboard3'; import { addSessionApi, getSessionDetailsApi } from '@/api/session'; @@ -282,7 +255,7 @@ const selectValue = ref(''); const sectionList = ref({}); let chatObj = reactive({}); - const isStopChat = ref(false); + let isStopChat = false; const appStore = useAppStore(); const theme = computed(() => { return appStore.theme; @@ -294,7 +267,9 @@ const visible = ref(false); let isHistory = ref(false); //鏄惁鏄巻鍙茶褰� let dsl = reactive({}); - const chatDataMeg = reactive({}); + + + let toStop = false; const rules = { name: [ @@ -377,7 +352,9 @@ 'Content-Type': 'application/json', }, body: JSON.stringify({ + converson_id: conversation_id.value, id: agentObj.id, + dsl:agentObj.dsl, }), }); @@ -419,8 +396,17 @@ const { code, data } = await getAgentSessionDetailsApi(id); if (code == 0) { console.log(data, 'agent浼氳瘽璇︽儏'); - Object.assign(chatObj, data); - sessionDetailList.value = data.dsl.messages; + let l = data.dsl.messages.length; + if (l > 1) { + chatObj.dsl.messages[chatObj.dsl.messages.length-1] = data.dsl.messages[l - 1]; + await updateAgentConversation({ + converson_id: conversation_id.value, + dsl: chatObj.dsl + }); + } else { + chatObj.dsl = data.dsl; + } + sessionDetailList.value = chatObj.dsl.messages; agentTitle.value = `${data.title}` || '鏈懡鍚嶄細璇�'; from.name = `${data.title}` || '鏈懡鍚嶄細璇�'; refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃� @@ -437,12 +423,18 @@ from.name = session.name; const { code, data } = await getSessionDetailsApi(session.id); if (code == 200) { - sessionDetailList.value = data.message.messages; const res = await getAgentSessionDetailsApi(session.dialog_id); if (res.code == 0) { - console.log(res.data, 'agent浼氳瘽璇︽儏'); + console.log(res.data, "agent浼氳瘽璇︽儏"); Object.assign(agentObj, res.data); - Object.assign(chatObj, res.data); + if (data?.message?.messages) { + sessionDetailList.value = data.message.messages; + let dsl = data.message; + Object.assign(chatObj, { "dsl": dsl }); + } else { + Object.assign(chatObj, res.data); + sessionDetailList.value = res.data.dsl.messages; + } Object.assign(dsl, res.data.dsl); refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃� } @@ -473,18 +465,6 @@ event.preventDefault(); // 闃绘榛樿琛屼负锛屽嵆涓嶆崲琛� } - // chatDis.value = true; - // loading.value = true; - // if (!agentObj.id) { - // Message.warning('璇烽�夋嫨浼氳瘽'); - // chatDis.value = false; - // loading.value = false; - // return; - // } - - // if (displayedText.value) { - // querySessionList(); - // } if (inputMsg.value) { startChat(inputMsg.value); @@ -498,7 +478,11 @@ } }; + let message_stop = []; + let message_id = ""; const startChat = async (valMsg) => { + isStopChat = false; + displayedText.value = ''; sessionDetailList.value.push({ content: valMsg, role: 'user', @@ -507,6 +491,7 @@ refreshScroll(); let chatStr = { id: agentObj.id, + converson_id: conversation_id.value, message: valMsg, }; if (isHistory.value) { @@ -527,6 +512,10 @@ .getReader(); currIndex.value = 0; while (true) { + if (isStopChat) { + message_stop.push(message_id); + break; + } const x = await reader?.read(); if (x) { const { done, value } = x; @@ -534,6 +523,16 @@ try { const val = JSON.parse(value?.data || ''); const d = val?.data; + if (message_id != d.message_id) { + message_id = d.message_id; + message_stop = []; + } else { + //message_stop涓煡鎵緈essage_id + const index = message_stop.findIndex(item => item === message_id); + if (index > -1) { + break; + } + } if (typeof d !== 'boolean') { console.info('data:', d); streamStr.value = d.content; @@ -543,15 +542,10 @@ console.warn(e); } if (done) { - console.info('done'); - displayedText.value = ''; - if (isStopChat.value) { - isStopChat.value = false; - setChatDataMeg(chatDataMeg); - } else { - queryAgentSessionDetail(agentObj.id); - EventBus.emit('queryAppUsageList'); - } + console.info("done"); + displayedText.value = ""; + queryAgentSessionDetail(agentObj.id); + EventBus.emit("queryAppUsageList"); break; } } @@ -561,13 +555,9 @@ }; const stopChat = async () => { - // const { code, data } = await stopChatApi(agentObj.id); - // if (code === 200) { - // Message.success("宸插仠姝�"); - // } loading.value = false; chatDis.value = false; - isStopChat.value = true; + isStopChat = true; console.log('stopChat'); console.log(displayedText.value, 'displayedText'); console.log(sessionDetailList.value, 'sessionDetailList'); @@ -589,24 +579,20 @@ .concat(lastArr); console.log(sessionDetailList.value, 'sessionDetailList2'); console.log(chatObj, 'chatObj瀵硅薄'); - chatObj.dsl.messages = chatObj.dsl.messages.concat(lastArr); - Object.assign(chatDataMeg, { - id: chatObj.id, - conversation_id: chatObj.id, - message: sessionDetailList.value, - }); - }; + chatObj.dsl.messages = sessionDetailList.value; - const setChatDataMeg = async (chatData) => { - const { code, data } = await addSessionApi(chatData); + const { code, data } = await updateAgentConversation({ + converson_id: conversation_id.value, + dsl:chatObj.dsl, + }); if (data) { //鍋滄瀹氭椂鍣� clearTimeout(timer!); timer = null; - // displayedText.value = ""; - queryAgentSessionDetail(chatObj.id); } }; + + const handleShiftEnter = (event) => { event.preventDefault(); @@ -656,7 +642,7 @@ watch( () => props.modalObj, (newVal, oldVal) => { - // Object.assign(agentObj, newVal); + Object.assign(agentObj, newVal); //璋冪敤agent鍒濆鍖栨柟娉� if (JSON.stringify(newVal) != '{}') { // initPage(); -- Gitblit v1.8.0