|
|
@@ -58,22 +58,6 @@
|
|
|
<div :class="{ chartUserText: theme === 'light' }"
|
|
|
>{{ sessionDetail.content }}
|
|
|
</div>
|
|
|
-
|
|
|
- <!-- <div class="uploadFileList fileList">
|
|
|
- <a-comment
|
|
|
- content="232323"
|
|
|
- style="
|
|
|
- background: var(--color-bg-2);
|
|
|
- padding: 10px;
|
|
|
- border-radius: 10px;
|
|
|
- font-size: 12px;
|
|
|
- "
|
|
|
- >
|
|
|
- <template #avatar>
|
|
|
- <img :src="getIconByExtension('wps')" alt="" />
|
|
|
- </template>
|
|
|
- </a-comment>
|
|
|
- </div> -->
|
|
|
</template>
|
|
|
</a-comment>
|
|
|
<a-comment v-else-if="sessionDetail?.role === 'assistant'">
|
|
|
@@ -85,58 +69,29 @@
|
|
|
/>
|
|
|
</template>
|
|
|
<template #content>
|
|
|
- <!-- <a-card :class="{ chatItemAnswer: theme === 'light' }">-->
|
|
|
- <!-- <div :class="{ light: theme === 'light' }"-->
|
|
|
- <!-- >{{ sessionDetail.content }}-->
|
|
|
- <!-- </div>-->
|
|
|
- <!-- </a-card>-->
|
|
|
- <a-textarea
|
|
|
- v-if="sessionDetail?.content"
|
|
|
- readonly
|
|
|
- auto-size
|
|
|
- v-model="sessionDetail.content"
|
|
|
- :class="{ chatItemAnswer: theme === 'light' }"
|
|
|
- :style="{
|
|
|
- backgroundColor: theme === 'light' ? '#ffffff' : '#000000',
|
|
|
- }"
|
|
|
- style="border: none"
|
|
|
- >
|
|
|
- </a-textarea>
|
|
|
- <div v-else>
|
|
|
- <!-- <a-textarea
|
|
|
- readonly
|
|
|
- auto-size
|
|
|
- :default-value="chartText(sessionDetail.code, sessionDetail.sql)"
|
|
|
- :class="{ chatItemAnswer: theme === 'light' }"
|
|
|
- :style="{
|
|
|
- backgroundColor: theme === 'light' ? '#ffffff' : '#000000',
|
|
|
- }"
|
|
|
- style="border: none"
|
|
|
- >
|
|
|
- </a-textarea> -->
|
|
|
- <!-- <codemirror
|
|
|
- v-model="sessionDetail.code"
|
|
|
- placeholder="Code gose here..."
|
|
|
- :style="{ height: '100%' }"
|
|
|
- :autofocus="true"
|
|
|
- :tabSize="2"
|
|
|
- /> -->
|
|
|
- <div class="codeStle">
|
|
|
- <div class="language">python</div>
|
|
|
- <pre
|
|
|
- style="
|
|
|
+ <div v-if="isExistTip(sessionDetail.content)" class="chartUserText">
|
|
|
+ <div v-for="(item, breakIndex) in breakLine(sessionDetail)">
|
|
|
+ <span v-if="item.preIndex==0">
|
|
|
+ {{ sessionDetail.content.substring(0, item.index) }}
|
|
|
+ </span>
|
|
|
+ <span v-else>
|
|
|
+ {{ sessionDetail.content.substring(item.preIndex+item.preItem.length, item.index) }}
|
|
|
+ </span>
|
|
|
+ <div class="codeStle">
|
|
|
+ <div class="language">{{ item.item }}</div>
|
|
|
+ <pre
|
|
|
+ style="
|
|
|
background: #2c2c36;
|
|
|
padding: 10px;
|
|
|
margin-top: 0;
|
|
|
margin-bottom: 0;
|
|
|
"
|
|
|
- ><code class="language-js line-numbers">{{ sessionDetail?.code}}</code></pre>
|
|
|
- <div class="language">SQL</div>
|
|
|
- <pre
|
|
|
- style="background: #2c2c36; padding: 10px; margin-top: 0"
|
|
|
- ><code class="language-js line-numbers">{{sessionDetail?.sql}}</code></pre>
|
|
|
+ ><code class="language-js line-numbers">{{ item?.tip_content }}</code></pre>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
-
|
|
|
+ </div>
|
|
|
+ <div v-else :class="{ chartUserText: theme === 'light' }">{{ sessionDetail.content }}</div>
|
|
|
+ <div>
|
|
|
<a-image
|
|
|
v-if="sessionDetail?.image_name"
|
|
|
:src="getImg(sessionDetail)"
|
|
|
@@ -436,8 +391,8 @@
|
|
|
agentConversationSetApi,
|
|
|
agentConverDownloadApi,
|
|
|
downloadFile,
|
|
|
- agentUploadApi,
|
|
|
- } from '@/api/agentSession';
|
|
|
+ agentUploadApi, updateAgentConversation, updateSeniorAgentConversation
|
|
|
+ } from "@/api/agentSession";
|
|
|
import EventBus from '@/utils/EventBus';
|
|
|
import useClipboard from 'vue-clipboard3';
|
|
|
import { addSessionApi, getSessionDetailsApi } from '@/api/session';
|
|
|
@@ -519,6 +474,45 @@
|
|
|
],
|
|
|
};
|
|
|
|
|
|
+ const isExistTip = (message: string): boolean => {
|
|
|
+ if (/\$([a-z]+)\$/g.test(message)) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const breakLine = (detail): string[] => {
|
|
|
+ let indexs: any[] = [];
|
|
|
+ let tip_content: any;
|
|
|
+ let preTip = 0;
|
|
|
+ let preItem="";
|
|
|
+ let matches = detail.content.match(/\$([a-z]+)\$/g);
|
|
|
+ matches?.map((item) => {
|
|
|
+ let i = detail.content.indexOf(item);
|
|
|
+ if (item == "$metadata$") {
|
|
|
+ tip_content = detail.metadata;
|
|
|
+ }
|
|
|
+ if (item == "$sql$") {
|
|
|
+ tip_content = detail.sql;
|
|
|
+ }
|
|
|
+ if (item == "$code$") {
|
|
|
+ tip_content = detail.code;
|
|
|
+ }
|
|
|
+ indexs.push({
|
|
|
+ index: i,
|
|
|
+ item: item,
|
|
|
+ preIndex: preTip,
|
|
|
+ preItem: preItem,
|
|
|
+ tip_content: tip_content,
|
|
|
+ len: matches.length
|
|
|
+ });
|
|
|
+ preTip = i;
|
|
|
+ preItem = item;
|
|
|
+ });
|
|
|
+ return indexs;
|
|
|
+ };
|
|
|
+
|
|
|
const handleSubmit = async ({ values, errors }) => {
|
|
|
if (errors) return;
|
|
|
|
|
|
@@ -578,87 +572,7 @@
|
|
|
isHistory.value = false;
|
|
|
initPage();
|
|
|
};
|
|
|
- // 调用set方法
|
|
|
- const agentSet = async () => {
|
|
|
- const res = await agentSetApi({
|
|
|
- id: agentObj.id,
|
|
|
- title: agentObj.title,
|
|
|
- dsl: agentObj.dsl,
|
|
|
- });
|
|
|
- // console.log(res,'agentSet');
|
|
|
- if (res.code == 0) {
|
|
|
- conversation_id.value = res.data.conversation_id;
|
|
|
- agentReset();
|
|
|
- }
|
|
|
- };
|
|
|
- // 调用reset方法
|
|
|
- const agentReset = async () => {
|
|
|
- const res = await agentResetApi({
|
|
|
- id: agentObj.id,
|
|
|
- });
|
|
|
- if (res.code == 0) {
|
|
|
- // Message.success('修改成功');
|
|
|
- agentCompletion();
|
|
|
- }
|
|
|
- };
|
|
|
- // 调用completion方法
|
|
|
- const agentCompletion = async () => {
|
|
|
- const response = await fetch('/api/v1/canvas/completion', {
|
|
|
- method: 'POST',
|
|
|
- headers: {
|
|
|
- 'Authorization': getAuthorization(),
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- },
|
|
|
- body: JSON.stringify({
|
|
|
- id: agentObj.id,
|
|
|
- }),
|
|
|
- });
|
|
|
- refreshScroll();
|
|
|
|
|
|
- const reader = response?.body
|
|
|
- ?.pipeThrough(new TextDecoderStream())
|
|
|
- .pipeThrough(new EventSourceParserStream())
|
|
|
- .getReader();
|
|
|
- currIndex.value = 0;
|
|
|
- while (true) {
|
|
|
- const x = await reader?.read();
|
|
|
- if (x) {
|
|
|
- const { done, value } = x;
|
|
|
-
|
|
|
- try {
|
|
|
- const val = JSON.parse(value?.data || '');
|
|
|
- const d = val?.data;
|
|
|
- if (typeof d !== 'boolean') {
|
|
|
- console.info('data:', d);
|
|
|
- if (d?.content) {
|
|
|
- streamStr.value = d.content;
|
|
|
- } else {
|
|
|
- streamStr.value = d?.code + d?.sql;
|
|
|
- }
|
|
|
- startDisplayStr();
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- console.warn(e);
|
|
|
- }
|
|
|
- if (done) {
|
|
|
- console.info('done');
|
|
|
- displayedText.value = '';
|
|
|
- // queryAgentSessionDetail(activeSessionId.value);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- chatDis.value = false;
|
|
|
- loading.value = false;
|
|
|
- inputMsg.value = '';
|
|
|
- uploaditemList.value = [];
|
|
|
- };
|
|
|
-
|
|
|
- //渲染文字
|
|
|
- const chartText = (val, sql) => {
|
|
|
- console.log(val + sql, 77);
|
|
|
- return val + '\n' + sql;
|
|
|
- };
|
|
|
|
|
|
//获取图片地址
|
|
|
const getImg = (val) => {
|
|
|
@@ -716,19 +630,7 @@
|
|
|
|
|
|
getAentId(session.dialog_id);
|
|
|
from.name = session.name;
|
|
|
- const { code, data } = await getSessionDetailsApi(session.id);
|
|
|
-
|
|
|
- if (code == 200) {
|
|
|
- sessionDetailList.value = data.message;
|
|
|
- refreshScroll(); //刷新滚动条位置
|
|
|
- // const res = await getAgentSessionDetailsApi(session.dialog_id);
|
|
|
- // if (res.code == 0) {
|
|
|
- // Object.assign(agentObj, res.data);
|
|
|
- // Object.assign(chatObj, res.data);
|
|
|
- // Object.assign(dsl, res.data.dsl);
|
|
|
- // refreshScroll(); //刷新滚动条位置
|
|
|
- // }
|
|
|
- }
|
|
|
+ queryAgentSessionDetails(activeSessionId.value);
|
|
|
};
|
|
|
|
|
|
const { toClipboard } = useClipboard();
|
|
|
@@ -955,24 +857,34 @@
|
|
|
.pipeThrough(new EventSourceParserStream())
|
|
|
.getReader();
|
|
|
currIndex.value = 0;
|
|
|
+ let end_msg={};
|
|
|
while (true) {
|
|
|
const x = await reader?.read();
|
|
|
if (x) {
|
|
|
const { done, value } = x;
|
|
|
console.log(x, 999);
|
|
|
-
|
|
|
+ loading.value = false;
|
|
|
if (value && value?.event == 'message') {
|
|
|
try {
|
|
|
const val = JSON.parse(value?.data || '');
|
|
|
- const d = val?.data;
|
|
|
+ const d = val?.data;
|
|
|
|
|
|
if (typeof d !== 'boolean') {
|
|
|
console.info('data:', d);
|
|
|
-
|
|
|
if (d?.content) {
|
|
|
- streamStr.value = d.content;
|
|
|
- } else {
|
|
|
- streamStr.value = d?.code + d?.sql;
|
|
|
+ let msg = d.content;
|
|
|
+ //将d.output中$metadata$替换为d.metadata
|
|
|
+ msg = msg.replace('$metadata$', d.metadata);
|
|
|
+ //d.content中存在$sql$
|
|
|
+ if (d.content.includes('$sql$')) {
|
|
|
+ msg = msg.replace('$sql$', d.sql);
|
|
|
+ }
|
|
|
+ //d.content中存在$code$
|
|
|
+ if (d.content.includes('$code$')) {
|
|
|
+ msg = msg.replace('$code$', d.code);
|
|
|
+ }
|
|
|
+ end_msg=d;
|
|
|
+ streamStr.value = msg;
|
|
|
}
|
|
|
EventBus.emit('queryAgent', uploaditemList.value);
|
|
|
startDisplayStr();
|
|
|
@@ -984,20 +896,20 @@
|
|
|
|
|
|
if (done) {
|
|
|
console.info('done');
|
|
|
- // displayedText.value = '';
|
|
|
- if (isStopChat.value) {
|
|
|
- isStopChat.value = false;
|
|
|
- setChatDataMeg(chatDataMeg);
|
|
|
- } else {
|
|
|
- // queryAgentSessionDetail(activeSessionId.value);
|
|
|
- // EventBus.emit('queryAppUsageList');
|
|
|
+ if (!chatObj?.message) {
|
|
|
+ chatObj.message = [];
|
|
|
}
|
|
|
+ chatObj.message.push(end_msg) ;
|
|
|
+ await updateSeniorAgentConversation({
|
|
|
+ converson_id: activeSessionId.value,
|
|
|
+ message: chatObj.message
|
|
|
+ });
|
|
|
+ setChatDataMeg(chatDataMeg);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
chatDis.value = false;
|
|
|
- loading.value = false;
|
|
|
};
|
|
|
|
|
|
const stopChat = async () => {
|
|
|
@@ -1061,13 +973,10 @@
|
|
|
|
|
|
if (currIndex.value < res.length) {
|
|
|
displayedText.value += res[currIndex.value];
|
|
|
-
|
|
|
currIndex.value++;
|
|
|
- setTimeout(startDisplayStr, 100);
|
|
|
+ setTimeout(startDisplayStr, 50);
|
|
|
refreshScroll();
|
|
|
} else {
|
|
|
- displayedText.value = '';
|
|
|
- queryAgentSessionDetails(activeSessionId.value);
|
|
|
clearTimeout(timer!);
|
|
|
timer = null;
|
|
|
}
|