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,18 +82,7 @@
            style="border: none"
          >
          </a-textarea>
          <!-- <div class="prompt">
            <ul>
              <li class="prompt-item" @click="copyText('43234')">
                <span>
                  344343klsdjkjksdjkjksdjk就开始大家看数据库登记卡受打击凯撒登记卡受打击凯撒登记卡受打击凯撒的43</span
                >
                <span style="margin-left: 20px">
                  <icon-right />
                </span>
              </li>
            </ul>
          </div> -->
        </template>
        <template #actions>
          <span
@@ -189,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"
@@ -250,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';
@@ -282,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;
@@ -295,6 +268,8 @@
  let isHistory = ref(false); //是否是历史记录
  let dsl = reactive({});
  const chatDataMeg = reactive({});
  let toStop = false;
  const rules = {
    name: [
@@ -377,7 +352,9 @@
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        converson_id: conversation_id.value,
        id: agentObj.id,
        dsl:agentObj.dsl,
      }),
    });
@@ -420,7 +397,11 @@
    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(); //刷新滚动条位置
@@ -498,7 +479,11 @@
    }
  };
  let message_stop = [];
  let message_id = "";
  const startChat = async (valMsg) => {
    isStopChat = false;
    displayedText.value = '';
    sessionDetailList.value.push({
      content: valMsg,
      role: 'user',
@@ -507,6 +492,7 @@
    refreshScroll();
    let chatStr = {
      id: agentObj.id,
      converson_id: conversation_id.value,
      message: valMsg,
    };
    if (isHistory.value) {
@@ -527,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;
@@ -534,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;
@@ -543,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;
        }
      }
@@ -561,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');
@@ -656,7 +648,7 @@
  watch(
    () => props.modalObj,
    (newVal, oldVal) => {
      // Object.assign(agentObj, newVal);
      Object.assign(agentObj, newVal);
      //调用agent初始化方法
      if (JSON.stringify(newVal) != '{}') {
        // initPage();