| | |
| | | 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" |
| | |
| | | </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" > |
| | |
| | | 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, |
| | | }); |
| | |
| | | }); |
| | | |
| | | const visible = ref(false); |
| | | |
| | | let isHistory = ref(false);//是否是历史记录 |
| | | let dsl = reactive({}); |
| | | const chatDataMeg = reactive({}); |
| | | |
| | | |
| | | const rules = { |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | const createNewAgent = async (session) => { |
| | | Object.assign(agentObj, session); |
| | | isHistory.value = false; |
| | | initPage(); |
| | | |
| | | |
| | |
| | | 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(); //刷新滚动条位置 |
| | | } |
| | | } |
| | | }; |
| | | |
| | |
| | | |
| | | |
| | | 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', |
| | | { |
| | |
| | | 'Authorization': getAuthorization(), |
| | | 'Content-Type': 'application/json', |
| | | }, |
| | | body: JSON.stringify({ |
| | | id: agentObj.id, |
| | | message: valMsg, |
| | | }), |
| | | body: JSON.stringify(chatStr), |
| | | } |
| | | ); |
| | | |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | // 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'); |
| | |
| | | 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(); |
| | |
| | | createNewAgent(data); |
| | | }); |
| | | EventBus.on('queryAgentSessionDetail', (data) => { |
| | | Object.assign(agentObj, data); |
| | | queryAgentSessionDetail(data.id); |
| | | isHistory.value = true; |
| | | querySessionDetail(data); |
| | | }); |
| | | }); |
| | | onBeforeUnmount(() => { |
| | |
| | | |
| | | .btn-send { |
| | | position: absolute !important; |
| | | right: 10px; |
| | | right: 4px; |
| | | top: 80px; |
| | | z-index: 10; |
| | | } |