feat: restore ai app context support

This commit is contained in:
2026-06-12 10:04:48 +08:00
parent faa14fd3dd
commit 16490392b2
10 changed files with 154 additions and 12 deletions
@@ -4,7 +4,7 @@ import type {
AgentListItem,
} from '#/api/ai-platform/ai-platform';
import { onMounted, reactive, ref } from 'vue';
import { computed, onMounted, reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import { Page } from '@vben/common-ui/es/page';
@@ -39,6 +39,7 @@ import {
ElOption,
ElPagination,
ElSelect,
ElSwitch,
ElTag,
ElTooltip,
} from 'element-plus';
@@ -52,6 +53,7 @@ import {
publishAgentApi,
unpublishAgentMenuApi,
} from '#/api/ai-platform/ai-platform';
import { useAppContextStore } from '#/store/app-context';
import PublishToMenuDialog from './components/PublishToMenuDialog.vue';
import ImportDialog from './modules/import-dialog.vue';
@@ -59,6 +61,8 @@ import ImportDialog from './modules/import-dialog.vue';
defineOptions({ name: 'AgentList' });
const router = useRouter();
const appContextStore = useAppContextStore();
const isMainApp = computed(() => appContextStore.isMainApp);
// 搜索关键词
const searchKeyword = ref('');
@@ -100,6 +104,7 @@ async function fetchList() {
page: pagination.current,
pageSize: pagination.pageSize,
name: searchKeyword.value || undefined,
applicationId: appContextStore.currentApp?.id,
});
agentList.value = res.items;
pagination.total = res.total;
@@ -156,10 +161,13 @@ async function handleCreate() {
try {
const agent = await createAgentApi({
...createForm,
application_id: appContextStore.currentApp?.id,
});
ElMessage.success($t('ai-platform.agent.createSuccess'));
createDialogVisible.value = false;
router.push(`/ai-platform/agent/editor/${agent.id}`);
router.push(
appContextStore.getContextPath(`/ai-platform/agent/editor/${agent.id}`),
);
} catch (error: any) {
ElMessage.error(error.message || $t('ai-platform.agent.createFailed'));
} finally {
@@ -169,12 +177,14 @@ async function handleCreate() {
// 编辑智能体
function handleEdit(agent: AgentListItem) {
router.push(`/ai-platform/agent/editor/${agent.id}`);
router.push(
appContextStore.getContextPath(`/ai-platform/agent/editor/${agent.id}`),
);
}
// 对话
function handleChat(agent: AgentListItem) {
router.push(`/agent-chat/${agent.code}`);
router.push(appContextStore.getContextPath(`/agent-chat/${agent.code}`));
}
// 发布
@@ -497,8 +507,10 @@ onMounted(() => {
<!-- 应用名称 + 创建时间 -->
<div class="flex items-center justify-between">
<div class="text-muted-foreground text-xs">
{{ agent.model_name || '未配置模型' }} ·
{{ agent.conversation_count || 0 }} 次对话
<span v-if="agent.application_name">
{{ agent.application_name }}
</span>
<span v-else>{{ $t('ai-platform.agent.mainApp') }}</span>
</div>
<span class="text-muted-foreground text-xs">
{{ agent.sys_create_datetime }}
@@ -599,6 +611,12 @@ onMounted(() => {
type="textarea"
/>
</ElFormItem>
<ElFormItem
v-if="isMainApp"
:label="$t('ai-platform.agent.form.globalVisible')"
>
<ElSwitch v-model="createForm.is_global" />
</ElFormItem>
</ElForm>
<template #footer>
<ElButton @click="createDialogVisible = false">