feat(agent): 新增智能体应用功能

- 添加智能体列表页面和相关API
- 实现聊天功能,包括历史对话和当前对话
- 新增工作流功能,包括表单提交和结果展示- 优化路由配置,增加智能体相关路由
- 添加全局常量和枚举,用于智能体类型区分
This commit is contained in:
林志军
2025-07-16 18:49:28 +08:00
parent 616665d219
commit b3af007dd2
15 changed files with 412 additions and 182 deletions

View File

@ -1,27 +1,39 @@
<template>
<a-layout-sider width="250" style="background: #fff">
<div>
<div class="logo">
<img :src="cozeInfo?.icon_url" style="width: 100%; height: 70%" />
<img :src="cozeInfo?.icon_url" class="agent-img" />
</div>
<a-menu mode="inline" theme="light">
<a-menu-item key="1">
<span>{{ cozeInfo.title }}</span>
<span class="menu-title">{{ cozeInfo.title }}</span>
<span style="color: #8492ff; font-size: 12px">{{ cozeInfo.type == 1 ? '智能体' : '对话式' }}</span>
<span style="float: right">{{ cozeInfo.views }}次使用</span>
<p>{{ cozeInfo.description }}</p>
</a-menu-item>
<a-menu-item key="2">历史对话</a-menu-item>
<a-menu-item key="3">梳理这次舆情的时间线和关键节点</a-menu-item>
<a-menu-item key="4">提取事件发展的五阶段脉络</a-menu-item>
<a-menu-item key="5">提炼不同群体的主要观点和态度立场</a-menu-item>
<a-menu-item key="6">分类汇总正面中立负面声音要点</a-menu-item>
<a-menu-item key="7">分析文本中的情绪类型及占比</a-menu-item>
<a-menu-item key="8">识别负面情绪集中的评论内容</a-menu-item>
<div v-for="(item, index) in conversations" :key="index">
<a-dropdown-button>
<span> {{ item.content }} </span>
<template #content>
<a-doption>重命名</a-doption>
<a-popconfirm
content="确认删除对话吗?删除后,聊天记录将不可恢复。"
@ok="delMessage(item.chat_id, item.conversation_id)"
type="error"
>
<a-button>删除</a-button>
</a-popconfirm>
</template>
</a-dropdown-button>
</div>
</a-menu>
</a-layout-sider>
</div>
</template>
<script lang="ts" setup>
import { defineProps } from 'vue';
import { delAgentMessage, getHistoryChat } from '@/api/all/agent';
const props = defineProps({
cozeInfo: {
@ -33,14 +45,29 @@ const props = defineProps({
default: '',
},
});
const getHistoryChat = async () => {
const { code, data } = await getHistoryChat({ botId: props.botId });
console.log(data, 'data');
// 获取历史对话
const delMessage = async (chatId, conversationId) => {
const { code, data } = await delAgentMessage({ chat_id: chatId, conversation_id: conversationId });
if (code === 200) {
console.log(data, 'data');
}
};
const conversations = ref([]);
const getHistoryChatData = async (botId) => {
const { code, data } = await getHistoryChat({ bot_id: botId });
if (code === 200) {
conversations.value = data.list;
}
};
const truncateText = (text: string, maxLength = 30) => {
if (text.length <= maxLength) return text;
return text.slice(0, maxLength) + '...';
};
onMounted(() => {
getHistoryChat();
getHistoryChatData(props.botId);
});
</script>
@ -48,4 +75,19 @@ onMounted(() => {
.logo {
margin-bottom: 20px;
}
.menu-title {
color: var(--Text-1, #211f24);
font-size: 18px;
font-family: Alibaba PuHuiTi;
font-weight: 400;
line-height: 26px;
word-wrap: break-word;
}
.agent-img {
width: 100%;
height: 230px;
border-radius: 4px;
}
</style>

View File

@ -1,9 +1,15 @@
<template>
<div class="chat-wrap">
<span class="span-back"> <icon-left /> 返回空间 </span>
<span class="" @click="goChatIndex"> <icon-left /> 返回空间 </span>
<div class="chat-contain">
<a-layout>
<HistoryChat :cozeInfo="cozeInfo" :botId="cozeWebSDKConfig?.config?.bot_id" />
<a-layout-sider width="15%" style="background: #fff">
<HistoryChat
v-if="cozeWebSDKConfig?.config?.bot_id"
:cozeInfo="cozeInfo"
:botId="cozeWebSDKConfig?.config?.bot_id"
/>
</a-layout-sider>
<a-layout>
<a-layout-content style="padding: 24px; background: #fff; min-height: 280px">
<a-card :bordered="false">
@ -20,8 +26,9 @@
import { ref, onMounted } from 'vue';
import { getChatAgent } from '@/api/all/agent';
import HistoryChat from './components/HistoryChat.vue';
import ChatBox from './components/ChatBox.vue';
import { useRoute } from 'vue-router';
import { useRouter } from 'vue-router';
const router = useRouter();
// 存储认证令牌
const authToken = ref('pat_tuIM7jubM1hLXaIWzbWg1U15lBe66AlYwu9BkXMQXInh8VdPszRFTwlTPmdziHwg');
@ -40,6 +47,12 @@ const refreshToken = async () => {
authToken.value = await fetchToken();
};
const goChatIndex = async () => {
router.push({
path: '/agent/index',
});
};
// 动态加载脚本函数
const loadScript = (src) =>
new Promise((resolve, reject) => {
@ -51,7 +64,7 @@ const loadScript = (src) =>
});
const route = useRoute();
const id = route.params.id;
const id = route.query.id;
const query = reactive({
id: id,
});
@ -78,10 +91,10 @@ const initChat = async () => {
}
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 = data.cozeConfig;
config.ui.chatBot.el = document.getElementById('coze-chat-container');
config.ui.width = '900px';
config.ui = editUi(data);
config.auth.onRefreshToken = function () {
return 'pat_tuIM7jubM1hLXaIWzbWg1U15lBe66AlYwu9BkXMQXInh8VdPszRFTwlTPmdziHwg';
};
@ -89,9 +102,28 @@ const initChat = async () => {
showChatPage();
};
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 = () => {
// 显示聊天页面
console.log(cozeWebSDK, 'chatClient');
cozeWebSDK.showChatBot();
};