zhangxiao
2024-08-15 f74f264d875b003730484f3fe7cb242c7f91294e
src/views/sessionManager/components/agentSession.vue
@@ -2,7 +2,7 @@
  <!--      内容-->
  <a-scrollbar
    ref="scrollbar"
    id="home"
    id="agentHome"
    class="chat-list"
    style="
              width: 90%;
@@ -153,7 +153,9 @@
    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('修改成功');
  }
}
@@ -187,30 +189,30 @@
    .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 = '';
@@ -222,7 +224,7 @@
  if (code == 0) {
    console.log(data,'会话详情');
    sessionDetailList.value = data.dsl.messages;
    // refreshScroll(); //刷新滚动条位置
    refreshScroll(); //刷新滚动条位置
  }
};
@@ -243,12 +245,12 @@
      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();
@@ -270,8 +272,8 @@
              'Content-Type': 'application/json',
            },
            body: JSON.stringify({
              conversation_id: activeSessionId.value,
              messages: inputMsg.value,
              id: agentObj.id,
              message: inputMsg.value,
            }),
          }
        );
@@ -345,7 +347,7 @@
const scrollbar = ref(null);
const refreshScroll = () => {
  nextTick(() => {
    const container = document.getElementById('home');
    const container = document.getElementById('agentHome');
    scrollbar.value.scrollTop(container.scrollHeight);
  });
};
@@ -358,7 +360,6 @@
watch(
  () => props.modalObj,
  (newVal, oldVal) => {
    console.log(newVal,'监听变化');
    Object.assign(agentObj, newVal);
    //调用agent初始化方法
    if(JSON.stringify(newVal) != '{}'){