yinbangzhong
2024-09-12 ff0ae974a1c561eaf2915988dac63cd066af189f
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中查找message_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 {