|  |  |  | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <script setup lang="ts"> | 
|---|
|  |  |  | import { defineProps, ref, watch, defineEmits, onMounted, reactive, computed, nextTick } from "vue"; | 
|---|
|  |  |  | import { defineProps, ref, watch, defineEmits, onMounted, reactive, computed, nextTick, onBeforeUnmount } from "vue"; | 
|---|
|  |  |  | import { Message } from '@arco-design/web-vue'; | 
|---|
|  |  |  | import { useAppStore } from "@/store"; | 
|---|
|  |  |  | import { getAuthorization } from "@/utils/auth"; | 
|---|
|  |  |  | 
|---|
|  |  |  | // 初始化页面 | 
|---|
|  |  |  | const initPage = async () => { | 
|---|
|  |  |  | agentSet(); | 
|---|
|  |  |  | agentReset(); | 
|---|
|  |  |  | agentCompletion(); | 
|---|
|  |  |  | queryAgentSessionDetail(agentObj.id); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const createNewAgent = async (session) => { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (res.code == 0) { | 
|---|
|  |  |  | // sessionDetailList.value = res.data.dsl.messages; | 
|---|
|  |  |  | // Message.success('修改成功'); | 
|---|
|  |  |  | agentReset(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 调用reset方法 | 
|---|
|  |  |  | 
|---|
|  |  |  | const res = await agentResetApi({ | 
|---|
|  |  |  | id: agentObj.id, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | if (res.code === 200) { | 
|---|
|  |  |  | if (res.code == 0) { | 
|---|
|  |  |  | // Message.success('修改成功'); | 
|---|
|  |  |  | agentCompletion(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 调用completion方法 | 
|---|
|  |  |  | 
|---|
|  |  |  | .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 = ''; | 
|---|
|  |  |  | 
|---|
|  |  |  | createNewAgent(data); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | onBeforeUnmount(() => { | 
|---|
|  |  |  | EventBus.off('createAgent'); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | watch( | 
|---|
|  |  |  | () => props.modalObj, | 
|---|