refactor(agent): 重构智能体模块
- 优化了路由配置,调整了菜单项的层级结构 - 重构了聊天页面的逻辑,简化了配置项 - 优化了历史聊天组件的使用方式 - 调整了智能体列表的展示样式
This commit is contained in:
@ -4,11 +4,7 @@
|
||||
<div class="chat-contain">
|
||||
<a-layout>
|
||||
<a-layout-sider width="15%" style="background: #fff">
|
||||
<HistoryChat
|
||||
v-if="cozeWebSDKConfig?.config?.bot_id"
|
||||
:cozeInfo="cozeInfo"
|
||||
:botId="cozeWebSDKConfig?.config?.bot_id"
|
||||
/>
|
||||
<HistoryChat v-if="cozeInfo?.bot_id" :cozeInfo="cozeInfo" />
|
||||
</a-layout-sider>
|
||||
<a-layout>
|
||||
<a-layout-content style="padding: 24px; background: #fff; min-height: 280px">
|
||||
@ -23,7 +19,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onUnmounted } from 'vue';
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { getChatAgent } from '@/api/all/agent';
|
||||
import HistoryChat from './components/HistoryChat.vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
@ -70,90 +66,47 @@ const query = reactive({
|
||||
id: id,
|
||||
});
|
||||
|
||||
const cozeWebSDKConfig = reactive({
|
||||
config: {},
|
||||
auth: {},
|
||||
userInfo: {},
|
||||
ui: {},
|
||||
});
|
||||
|
||||
const cozeInfo = reactive({
|
||||
title: '',
|
||||
description: '',
|
||||
icon_url: '',
|
||||
bot_id: '',
|
||||
auth: {},
|
||||
});
|
||||
|
||||
const cozeWebSDK = null;
|
||||
let cozeWebSDK = null;
|
||||
const initChat = async () => {
|
||||
console.log(2323);
|
||||
const { code, data } = await getChatAgent(query.id);
|
||||
if (code != 200) {
|
||||
return false;
|
||||
}
|
||||
Object.assign(cozeWebSDKConfig, data.cozeConfig);
|
||||
|
||||
Object.assign(cozeInfo, data.info);
|
||||
console.log(cozeWebSDKConfig?.config?.bot_id, 'cozeWebSDKConfig?.config?.bot_id');
|
||||
await loadScript('https://lf-cdn.coze.cn/obj/unpkg/flow-platform/chat-app-sdk/1.2.0-beta.10/libs/cn/index.js');
|
||||
let config = await getChatAgent(data.info.bot_id, data.info.title);
|
||||
config.ui = editUi(data);
|
||||
config.auth.onRefreshToken = function () {
|
||||
return 'pat_tuIM7jubM1hLXaIWzbWg1U15lBe66AlYwu9BkXMQXInh8VdPszRFTwlTPmdziHwg';
|
||||
};
|
||||
cozeWebSDK = new CozeWebSDK.WebChatClient(config);
|
||||
let cozeConfig = await cozeWebSdkConfig(data.info.bot_id, data.info.name, data.info.auth);
|
||||
cozeWebSDK = cozeWebSDK = new CozeWebSDK.WebChatClient(cozeConfig);
|
||||
showChatPage();
|
||||
};
|
||||
|
||||
//扣子配置
|
||||
const cozeWebSdkConfig = (botId, title) => {
|
||||
const cozeWebSdkConfig = (botId, name, auth) => {
|
||||
console.log(name, 'title');
|
||||
auth.onRefreshToken = function () {
|
||||
return 'pat_tuIM7jubM1hLXaIWzbWg1U15lBe66AlYwu9BkXMQXInh8VdPszRFTwlTPmdziHwg';
|
||||
};
|
||||
let config = {
|
||||
config: {
|
||||
bot_id: botId,
|
||||
botId: botId,
|
||||
},
|
||||
ui: {
|
||||
chatBot: {
|
||||
el: document.getElementById('coze-chat-container'),
|
||||
width: '70%',
|
||||
width: '80%',
|
||||
height: '100%',
|
||||
title: title,
|
||||
title: name,
|
||||
isNeedFunctionCallMessage: true,
|
||||
},
|
||||
base: {
|
||||
icon: '',
|
||||
zIndex: 1000,
|
||||
},
|
||||
header: {
|
||||
isShow: true,
|
||||
isNeedClose: false,
|
||||
},
|
||||
feedback: {
|
||||
isNeedFeedback: true,
|
||||
feedbackPanel: {
|
||||
title: '您对这个回答有什么看法?请告诉我们',
|
||||
placeholder: '请详细描述您的问题...',
|
||||
tags: [
|
||||
{
|
||||
label: '信息不正确',
|
||||
},
|
||||
{
|
||||
label: '敏感涉及 信息',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
return config;
|
||||
};
|
||||
|
||||
const editUi = (config) => {
|
||||
let uiConfig = {
|
||||
chatBot: {
|
||||
el: document.getElementById('coze-chat-container'),
|
||||
width: '70%',
|
||||
height: '100%',
|
||||
title: config?.info?.title,
|
||||
isNeedFunctionCallMessage: true,
|
||||
},
|
||||
auth: auth,
|
||||
base: {
|
||||
icon: '',
|
||||
zIndex: 1000,
|
||||
@ -163,7 +116,7 @@ const editUi = (config) => {
|
||||
isNeedClose: false,
|
||||
},
|
||||
};
|
||||
return uiConfig;
|
||||
return config;
|
||||
};
|
||||
|
||||
const showChatPage = () => {
|
||||
@ -173,7 +126,6 @@ const showChatPage = () => {
|
||||
onMounted(() => {
|
||||
initChat();
|
||||
});
|
||||
//销毁组件
|
||||
onUnmounted(() => {
|
||||
cozeWebSDK.destroy();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user