| | |
| | | <!-- 内容--> |
| | | <a-scrollbar |
| | | ref="scrollbar" |
| | | id="home" |
| | | id="agentHome" |
| | | class="chat-list" |
| | | style=" |
| | | width: 90%; |
| | |
| | | import { getAuthorization } from "@/utils/auth"; |
| | | import { EventSourceParserStream } from 'eventsource-parser/stream'; |
| | | import { agentResetApi, agentSetApi, getAgentSessionDetailsApi } from "@/api/agentSession"; |
| | | import EventBus from '@/utils/EventBus'; |
| | | const props = defineProps({ |
| | | modalObj: Object, |
| | | }); |
| | |
| | | queryAgentSessionDetail(agentObj.id); |
| | | }; |
| | | |
| | | const createNewAgent = async (session) => { |
| | | Object.assign(agentObj, session); |
| | | initPage(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | // 调用set方法 |
| | | const agentSet = async () => { |
| | | const res = await agentSetApi({ |
| | |
| | | title: agentObj.title, |
| | | dsl: agentObj.dsl, |
| | | }); |
| | | if (res.code === 200) { |
| | | console.log(res,'agentSet'); |
| | | if (res.code == 0) { |
| | | // sessionDetailList.value = res.data.dsl.messages; |
| | | // Message.success('修改成功'); |
| | | } |
| | | } |
| | |
| | | .pipeThrough(new EventSourceParserStream()) |
| | | .getReader(); |
| | | currIndex.value = 0; |
| | | while (true) { |
| | | const x = await reader?.read(); |
| | | if (x) { |
| | | const { done, value } = x; |
| | | console.log(x, 999); |
| | | try { |
| | | const val = JSON.parse(value?.data || ''); |
| | | const d = val?.data; |
| | | if (typeof d !== 'boolean') { |
| | | console.info('data:', d); |
| | | streamStr.value = d.content; |
| | | startDisplayStr(); |
| | | } |
| | | } catch (e) { |
| | | console.warn(e); |
| | | } |
| | | if (done) { |
| | | console.info('done'); |
| | | displayedText.value = ''; |
| | | queryAgentSessionDetail(agentObj.id); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | // while (true) { |
| | | // const x = await reader?.read(); |
| | | // if (x) { |
| | | // const { done, value } = x; |
| | | // console.log(x, 999); |
| | | // try { |
| | | // const val = JSON.parse(value?.data || ''); |
| | | // const d = val?.data; |
| | | // if (typeof d !== 'boolean') { |
| | | // console.info('data:', d); |
| | | // streamStr.value = d.content; |
| | | // startDisplayStr(); |
| | | // } |
| | | // } catch (e) { |
| | | // console.warn(e); |
| | | // } |
| | | // if (done) { |
| | | // console.info('done'); |
| | | // displayedText.value = ''; |
| | | // queryAgentSessionDetail(agentObj.id); |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | chatDis.value = false; |
| | | loading.value = false; |
| | | inputMsg.value = ''; |
| | |
| | | if (code == 0) { |
| | | console.log(data,'会话详情'); |
| | | sessionDetailList.value = data.dsl.messages; |
| | | // refreshScroll(); //刷新滚动条位置 |
| | | refreshScroll(); //刷新滚动条位置 |
| | | } |
| | | }; |
| | | |
| | |
| | | |
| | | chatDis.value = true; |
| | | loading.value = true; |
| | | if (!activeSessionId.value) { |
| | | Message.warning('请选择会话'); |
| | | chatDis.value = false; |
| | | loading.value = false; |
| | | return; |
| | | } |
| | | // if (!agentObj.id) { |
| | | // Message.warning('请选择会话'); |
| | | // chatDis.value = false; |
| | | // loading.value = false; |
| | | // return; |
| | | // } |
| | | |
| | | // if (displayedText.value) { |
| | | // querySessionList(); |
| | |
| | | 'Content-Type': 'application/json', |
| | | }, |
| | | body: JSON.stringify({ |
| | | conversation_id: activeSessionId.value, |
| | | messages: inputMsg.value, |
| | | id: agentObj.id, |
| | | message: inputMsg.value, |
| | | }), |
| | | } |
| | | ); |
| | |
| | | const scrollbar = ref(null); |
| | | const refreshScroll = () => { |
| | | nextTick(() => { |
| | | const container = document.getElementById('home'); |
| | | const container = document.getElementById('agentHome'); |
| | | scrollbar.value.scrollTop(container.scrollHeight); |
| | | }); |
| | | }; |
| | | |
| | | |
| | | onMounted(() => { |
| | | |
| | | EventBus.on('createAgent', (data) => { |
| | | createNewAgent(data); |
| | | }); |
| | | }); |
| | | |
| | | watch( |
| | | () => props.modalObj, |
| | | (newVal, oldVal) => { |
| | | console.log(newVal,'监听变化'); |
| | | Object.assign(agentObj, newVal); |
| | | // Object.assign(agentObj, newVal); |
| | | //调用agent初始化方法 |
| | | if(JSON.stringify(newVal) != '{}'){ |
| | | initPage(); |
| | | // initPage(); |
| | | } |
| | | },{ |
| | | immediate: true, |