refactor(agent): 重构智能体模块

- 优化了路由配置,调整了菜单项的层级结构
- 重构了聊天页面的逻辑,简化了配置项
- 优化了历史聊天组件的使用方式
- 调整了智能体列表的展示样式
This commit is contained in:
林志军
2025-07-18 10:11:13 +08:00
parent af147625ae
commit 81a36d72cc
4 changed files with 26 additions and 90 deletions

View File

@ -1,6 +1,7 @@
import Http from '@/api'; import Http from '@/api';
// 获取聊天智能体 // 获取聊天智能体
export const getChatAgent = (id: number) => { export const getChatAgent = (id: number) => {
console.log('param.id',id);
return Http.get(`/v1/agent/getChatAgent/${id}`); return Http.get(`/v1/agent/getChatAgent/${id}`);
}; };

View File

@ -7,24 +7,24 @@ const COMPONENTS: AppRouteRecordRaw[] = [
{ {
path: '/agent', path: '/agent',
name: 'Agent', name: 'Agent',
redirect: 'agent/listData', redirect: 'agent/index',
meta: { meta: {
locale: '扣子智能体', locale: '扣子智能体',
icon: IconRepository, icon: IconRepository,
requiresAuth: true, requiresAuth: true,
requireLogin: true, requireLogin: true,
roles: ['*'], roles: ['*'],
id: MENU_GROUP_IDS.AGENT, id: MENU_GROUP_IDS.PROPERTY_ID,
}, },
children: [ children: [
{ {
path: 'index', path: 'index',
name: 'AgentListData', name: 'AgentIndex',
component: () => import('@/views/agent/index'), component: () => import('@/views/agent/index'),
meta: { meta: {
locale: '智能体列表',
requiresAuth: false, requiresAuth: false,
requireLogin: true, requireLogin: true,
id: MENU_GROUP_IDS.WORK_BENCH_ID,
}, },
}, },
{ {
@ -35,16 +35,7 @@ const COMPONENTS: AppRouteRecordRaw[] = [
hideSidebar: true, hideSidebar: true,
requiresAuth: false, requiresAuth: false,
requireLogin: true, requireLogin: true,
}, id: MENU_GROUP_IDS.WORK_BENCH_ID,
},
{
path: 'workFlow',
name: 'AgentWorkFlow',
component: () => import('@/views/agent/work-flow'),
meta: {
hideSidebar: true,
requiresAuth: false,
requireLogin: true,
}, },
}, },
], ],

View File

@ -4,11 +4,7 @@
<div class="chat-contain"> <div class="chat-contain">
<a-layout> <a-layout>
<a-layout-sider width="15%" style="background: #fff"> <a-layout-sider width="15%" style="background: #fff">
<HistoryChat <HistoryChat v-if="cozeInfo?.bot_id" :cozeInfo="cozeInfo" />
v-if="cozeWebSDKConfig?.config?.bot_id"
:cozeInfo="cozeInfo"
:botId="cozeWebSDKConfig?.config?.bot_id"
/>
</a-layout-sider> </a-layout-sider>
<a-layout> <a-layout>
<a-layout-content style="padding: 24px; background: #fff; min-height: 280px"> <a-layout-content style="padding: 24px; background: #fff; min-height: 280px">
@ -23,7 +19,7 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted, onUnmounted } from 'vue'; import { ref, onMounted } from 'vue';
import { getChatAgent } from '@/api/all/agent'; import { getChatAgent } from '@/api/all/agent';
import HistoryChat from './components/HistoryChat.vue'; import HistoryChat from './components/HistoryChat.vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
@ -70,53 +66,47 @@ const query = reactive({
id: id, id: id,
}); });
const cozeWebSDKConfig = reactive({
config: {},
auth: {},
userInfo: {},
ui: {},
});
const cozeInfo = reactive({ const cozeInfo = reactive({
title: '', title: '',
description: '', description: '',
icon_url: '', icon_url: '',
bot_id: '',
auth: {},
}); });
const cozeWebSDK = null; let cozeWebSDK = null;
const initChat = async () => { const initChat = async () => {
console.log(2323);
const { code, data } = await getChatAgent(query.id); const { code, data } = await getChatAgent(query.id);
if (code != 200) { if (code != 200) {
return false; return false;
} }
Object.assign(cozeWebSDKConfig, data.cozeConfig);
Object.assign(cozeInfo, data.info); 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'); 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); let cozeConfig = await cozeWebSdkConfig(data.info.bot_id, data.info.name, data.info.auth);
config.ui = editUi(data); cozeWebSDK = cozeWebSDK = new CozeWebSDK.WebChatClient(cozeConfig);
config.auth.onRefreshToken = function () {
return 'pat_tuIM7jubM1hLXaIWzbWg1U15lBe66AlYwu9BkXMQXInh8VdPszRFTwlTPmdziHwg';
};
cozeWebSDK = new CozeWebSDK.WebChatClient(config);
showChatPage(); showChatPage();
}; };
//扣子配置 const cozeWebSdkConfig = (botId, name, auth) => {
const cozeWebSdkConfig = (botId, title) => { console.log(name, 'title');
auth.onRefreshToken = function () {
return 'pat_tuIM7jubM1hLXaIWzbWg1U15lBe66AlYwu9BkXMQXInh8VdPszRFTwlTPmdziHwg';
};
let config = { let config = {
config: { config: {
bot_id: botId, botId: botId,
}, },
ui: { ui: {
chatBot: { chatBot: {
el: document.getElementById('coze-chat-container'), el: document.getElementById('coze-chat-container'),
width: '70%', width: '80%',
height: '100%', height: '100%',
title: title, title: name,
isNeedFunctionCallMessage: true, isNeedFunctionCallMessage: true,
}, },
},
auth: auth,
base: { base: {
icon: '', icon: '',
zIndex: 1000, zIndex: 1000,
@ -125,47 +115,10 @@ const cozeWebSdkConfig = (botId, title) => {
isShow: true, isShow: true,
isNeedClose: false, isNeedClose: false,
}, },
feedback: {
isNeedFeedback: true,
feedbackPanel: {
title: '您对这个回答有什么看法?请告诉我们',
placeholder: '请详细描述您的问题...',
tags: [
{
label: '信息不正确',
},
{
label: '敏感涉及 信息',
},
],
},
},
},
}; };
return config; return config;
}; };
const editUi = (config) => {
let uiConfig = {
chatBot: {
el: document.getElementById('coze-chat-container'),
width: '70%',
height: '100%',
title: config?.info?.title,
isNeedFunctionCallMessage: true,
},
base: {
icon: '',
zIndex: 1000,
},
header: {
isShow: true,
isNeedClose: false,
},
};
return uiConfig;
};
const showChatPage = () => { const showChatPage = () => {
cozeWebSDK.showChatBot(); cozeWebSDK.showChatBot();
}; };
@ -173,7 +126,6 @@ const showChatPage = () => {
onMounted(() => { onMounted(() => {
initChat(); initChat();
}); });
//销毁组件
onUnmounted(() => { onUnmounted(() => {
cozeWebSDK.destroy(); cozeWebSDK.destroy();
}); });

View File

@ -25,15 +25,8 @@
<div class="card-description">{{ product?.description }}</div> <div class="card-description">{{ product?.description }}</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<div <div :class="['tag', { red: product?.type === 1, blue: product?.type === 2 }]">
:class="['tag', { red: product?.type === 1, blue: product?.type === 2 }]" <div :class="['tag-text', { red: product?.type === 1, blue: product?.type === 2 }]">
>
<div
:class="[
'tag-text',
{ red: product?.type === 1, blue: product?.type === 2 },
]"
>
{{ product?.type == 1 ? '对话式' : '工作流' }} {{ product?.type == 1 ? '对话式' : '工作流' }}
</div> </div>
</div> </div>
@ -67,7 +60,6 @@ const query = reactive({
title: '', title: '',
}); });
const goDetail = (type: number, id: number) => { const goDetail = (type: number, id: number) => {
if (type === 1) { if (type === 1) {
router.push({ router.push({
path: '/agent/chat', path: '/agent/chat',