From 278f014d606f5cd4ca61a3b6586f305379a08f6a Mon Sep 17 00:00:00 2001 From: liudong <liudong> Date: 星期四, 22 八月 2024 14:44:11 +0800 Subject: [PATCH] agent会话停止功能 --- src/views/sessionManager/components/agentSession.vue | 136 ++++++++++++++++++++++++++++++++++----------- 1 files changed, 103 insertions(+), 33 deletions(-) diff --git a/src/views/sessionManager/components/agentSession.vue b/src/views/sessionManager/components/agentSession.vue index 093bc27..679d534 100644 --- a/src/views/sessionManager/components/agentSession.vue +++ b/src/views/sessionManager/components/agentSession.vue @@ -141,8 +141,8 @@ maxRows: 5, }" /> - <div class="btn-send"> - <!-- <icon-send size="32" /> --> + <div style="width: 100%;display: flex;justify-content: space-between"> + <span></span> <a-button :disabled="chatDis" @click="sentClick" @@ -154,6 +154,19 @@ </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" title="淇敼鍚嶇О" @before-open="handleOpened" @cancel="handleCancel" :footer="false" title-align="start"> <a-form ref="formRef" :rules="rules" :model="agentObj" @submit="handleSubmit" > @@ -180,7 +193,7 @@ import { agentResetApi, agentSetApi, getAgentSessionDetailsApi } from "@/api/agentSession"; import EventBus from '@/utils/EventBus'; import useClipboard from "vue-clipboard3"; -import { addSessionApi } from "@/api/session"; +import { addSessionApi, getSessionDetailsApi } from "@/api/session"; const props = defineProps({ modalObj: Object, }); @@ -215,7 +228,9 @@ }); const visible = ref(false); - +let isHistory = ref(false);//鏄惁鏄巻鍙茶褰� +let dsl = reactive({}); +const chatDataMeg = reactive({}); const rules = { @@ -229,12 +244,19 @@ const handleSubmit = async({values, errors}) => { if(errors) return; - agentObj.name = agentTitle.value; - const { code, data } = await addSessionApi(agentObj); + // agentObj.name = agentTitle.value; + // agentObj.conversation_id = agentObj.id; + console.log(agentObj, 'agentObj'); + let chatData = { + id:activeSessionId.value, + conversation_id:activeSessionId.value, + name: agentTitle.value + } + const { code, data } = await addSessionApi(chatData); if (data) { Message.success("淇敼鎴愬姛"); handleCancel() - queryAgentSessionDetail(agentObj.id); + // queryAgentSessionDetail(agentObj.id); } } @@ -260,6 +282,7 @@ const createNewAgent = async (session) => { Object.assign(agentObj, session); + isHistory.value = false; initPage(); @@ -341,14 +364,34 @@ inputMsg.value = ''; } // 璋冪敤get鏂规硶 - const queryAgentSessionDetail = async (id) => { const { code, data } = await getAgentSessionDetailsApi(id); if (code == 0) { - console.log(data,'浼氳瘽璇︽儏'); + console.log(data,'agent浼氳瘽璇︽儏'); + Object.assign(chatObj, data); sessionDetailList.value = data.dsl.messages; - agentTitle.value = `鍜�${data.title}鐨勪細璇漙 || '鏈懡鍚嶄細璇�'; + agentTitle.value = `${data.title}` || '鏈懡鍚嶄細璇�'; refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃� + } +}; + +// 鍘嗗彶璁板綍璺宠浆鑾峰彇agent浼氳瘽璇︽儏 +const querySessionDetail = async (session) => { + Object.assign(agentObj, session); + agentObj.id = session.dialog_id; + activeSessionId.value = session.id; + agentTitle.value = session.name; + console.log(agentTitle.value, '浼氳瘽鍚嶇О'); + 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浼氳瘽璇︽儏'); + Object.assign(chatObj, data); + Object.assign(dsl, res.data.dsl); + refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃� + } } }; @@ -404,13 +447,19 @@ const startChat = async(valMsg)=>{ - sessionDetailList.value.push({ content: valMsg, role: 'user', }); sessionDetailList.value.push({ role: 'last' }); refreshScroll(); + let chatStr = { + id: agentObj.id, + message: valMsg, + } + if(isHistory.value){ + chatStr.dsl = dsl; + } const response = await fetch( '/api/v1/canvas/completion', { @@ -419,10 +468,7 @@ 'Authorization': getAuthorization(), 'Content-Type': 'application/json', }, - body: JSON.stringify({ - id: agentObj.id, - message: valMsg, - }), + body: JSON.stringify(chatStr), } ); @@ -450,8 +496,13 @@ if (done) { console.info('done'); displayedText.value = ''; - queryAgentSessionDetail(agentObj.id); - EventBus.emit('queryAppUsageList'); + if (isStopChat.value) { + isStopChat.value = false; + setChatDataMeg(chatDataMeg); + } else { + queryAgentSessionDetail(agentObj.id); + EventBus.emit('queryAppUsageList'); + } break; } } @@ -464,8 +515,9 @@ // const { code, data } = await stopChatApi(activeSessionId.value); // if (code === 200) { // Message.success("宸插仠姝�"); - // queryNewSessionDetail(activeSessionId.value); // } + loading.value = false; + chatDis.value = false; isStopChat.value = true; console.log('stopChat'); console.log(displayedText.value, 'displayedText'); @@ -482,20 +534,38 @@ sessionDetailList.value = sessionDetailList.value.splice(0, sessionDetailList.value.length-2).concat(lastArr); console.log(sessionDetailList.value, 'sessionDetailList2'); console.log(chatObj, 'chatObj瀵硅薄'); - chatObj.message = chatObj.message.concat(lastArr); - // clearTimeout(timer!); - // timer = null; - // const { code, data } = await addSessionApi(chatObj); - // if (data) { - // //鍋滄瀹氭椂鍣� - // clearTimeout(timer!); - // timer = null; - // displayedText.value = ""; - // queryNewSessionDetail(activeSessionId.value); - // } - + chatObj.dsl.messages = chatObj.dsl.messages.concat(lastArr); + Object.assign(chatDataMeg, { + id: chatObj.id, + conversation_id: chatObj.id, + message: sessionDetailList.value, + }); } + + +const setChatDataMeg = async (chatData) => { + const { code, data } = await addSessionApi(chatData); + if (data) { + //鍋滄瀹氭椂鍣� + clearTimeout(timer!); + timer = null; + // displayedText.value = ""; + queryAgentSessionDetail(chatObj.id); + } +}; + +// const queryNewSessionDetail = async (id) => { +// activeSessionId.value = id; +// const { code, data } = await getSessionDetailsApi(id); +// if (code === 200) { +// console.log(data, 'agent浼氳瘽璇︽儏'); +// Object.assign(chatObj, data); +// sessionDetailList.value = data.message; +// agentTitle.value = data.name; +// refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃� +// } +// }; const handleShiftEnter = (event) => { event.preventDefault(); @@ -536,8 +606,8 @@ createNewAgent(data); }); EventBus.on('queryAgentSessionDetail', (data) => { - Object.assign(agentObj, data); - queryAgentSessionDetail(data.id); + isHistory.value = true; + querySessionDetail(data); }); }); onBeforeUnmount(() => { @@ -665,7 +735,7 @@ .btn-send { position: absolute !important; - right: 10px; + right: 4px; top: 80px; z-index: 10; } -- Gitblit v1.8.0