From ff0ae974a1c561eaf2915988dac63cd066af189f Mon Sep 17 00:00:00 2001
From: yinbangzhong <zhongbangyin@126.com>
Date: 星期四, 12 九月 2024 09:23:44 +0800
Subject: [PATCH] bug fix

---
 src/views/sessionManager/components/agentSession.vue |  110 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 71 insertions(+), 39 deletions(-)

diff --git a/src/views/sessionManager/components/agentSession.vue b/src/views/sessionManager/components/agentSession.vue
index 59f1821..484ad76 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,6 +82,7 @@
             style="border: none"
           >
           </a-textarea>
+
         </template>
         <template #actions>
           <span
@@ -102,6 +99,7 @@
           >
             <icon-refresh /> 閲嶆柊鐢熸垚
           </span>
+          <!-- <span class="action"><icon-to-bottom />涓嬭浇 </span> -->
         </template>
       </a-comment>
       <a-comment v-else-if="sessionDetail.role === 'last'">
@@ -176,19 +174,7 @@
           <icon-send size="32" style="color: #0960bd" />
         </a-button>
       </div>
-      <!--      <div class="btn-send">-->
-      <!--        &lt;!&ndash; <icon-send size="32" /> &ndash;&gt;-->
-      <!--        <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"
@@ -237,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';
@@ -269,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;
@@ -282,6 +268,8 @@
   let isHistory = ref(false); //鏄惁鏄巻鍙茶褰�
   let dsl = reactive({});
   const chatDataMeg = reactive({});
+
+  let toStop = false;
 
   const rules = {
     name: [
@@ -364,7 +352,9 @@
         'Content-Type': 'application/json',
       },
       body: JSON.stringify({
+        converson_id: conversation_id.value,
         id: agentObj.id,
+        dsl:agentObj.dsl,
       }),
     });
 
@@ -407,11 +397,19 @@
     if (code == 0) {
       console.log(data, 'agent浼氳瘽璇︽儏');
       Object.assign(chatObj, data);
-      sessionDetailList.value = data.dsl.messages;
+      // sessionDetailList.value = data.dsl.messages;
+      await updateAgentConversation({
+        converson_id: conversation_id.value,
+        dsl:data.dsl,
+      })
       agentTitle.value = `${data.title}` || '鏈懡鍚嶄細璇�';
       from.name = `${data.title}` || '鏈懡鍚嶄細璇�';
       refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃�
     }
+  };
+
+  const copyText = (text) => {
+    inputMsg.value = text;
   };
 
   // 鍘嗗彶璁板綍璺宠浆鑾峰彇agent浼氳瘽璇︽儏
@@ -481,7 +479,11 @@
     }
   };
 
+  let message_stop = [];
+  let message_id = "";
   const startChat = async (valMsg) => {
+    isStopChat = false;
+    displayedText.value = '';
     sessionDetailList.value.push({
       content: valMsg,
       role: 'user',
@@ -490,6 +492,7 @@
     refreshScroll();
     let chatStr = {
       id: agentObj.id,
+      converson_id: conversation_id.value,
       message: valMsg,
     };
     if (isHistory.value) {
@@ -510,6 +513,11 @@
       .getReader();
     currIndex.value = 0;
     while (true) {
+      if (isStopChat) {
+        message_stop.push(message_id);
+        setChatDataMeg(chatDataMeg);
+        break;
+      }
       const x = await reader?.read();
       if (x) {
         const { done, value } = x;
@@ -517,6 +525,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;
@@ -526,15 +544,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;
         }
       }
@@ -544,13 +557,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');
@@ -639,7 +648,7 @@
   watch(
     () => props.modalObj,
     (newVal, oldVal) => {
-      // Object.assign(agentObj, newVal);
+      Object.assign(agentObj, newVal);
       //璋冪敤agent鍒濆鍖栨柟娉�
       if (JSON.stringify(newVal) != '{}') {
         // initPage();
@@ -661,11 +670,12 @@
     .chatItemAnswer {
       box-sizing: border-box;
       background: #f1f1f1;
-      border-radius: 14px;
+      border-radius: 10px;
+      padding: 5px;
       .light {
         box-sizing: border-box;
         background: #f1f1f1;
-        border-radius: 14px;
+        border-radius: 10px;
       }
     }
     .textItemAnswer {
@@ -781,6 +791,28 @@
       .icon-user-jpg {
         border: 1px solid #d9d9d9;
       }
+      .prompt {
+        ul {
+          margin: 0;
+          padding: 0;
+          display: flex;
+        }
+        ul > li {
+          list-style-type: none;
+        }
+        .prompt-item {
+          display: flex;
+          justify-content: space-between;
+          background-color: #fff;
+          cursor: pointer;
+          border-radius: 8px;
+          padding: 10px;
+          border: #e5e5e5;
+          &:hover {
+            background-color: #eee;
+          }
+        }
+      }
     }
   }
   .header___lEPyH {

--
Gitblit v1.8.0