feat: 我的记忆独立页并迁出模型管理

This commit is contained in:
2026-09-20 16:15:03 +08:00
parent aac3424911
commit d7e4a987c1
5 changed files with 133 additions and 40 deletions
+4 -1
View File
@@ -251,6 +251,7 @@ SSE 事件:`token`(正文,可落库)/ `tool`(`{phase,name,label}` 状
- 聊天:`/agent/chat`,菜单「智能助手」(仅 `agent:chat`)
- 模型管理:`/agent/llm-settings`,一级菜单「模型管理」(仅 `agent:llm-settings`)
- 我的记忆:`/agent/memories`,头像下拉入口(有 `agent:chat` 时显示;静态路由)
- 聊天顶栏:`Select` 切换当前会话模型(PATCH `llmModel`);新对话草稿本地暂存,创建时带上
- 布局:**左会话列表 + 右消息区 + 底输入**;全页 `flex` + `min-h-0` 滚动(遵守现有 Spin/滚动规范)
@@ -261,7 +262,9 @@ views/agent/chat/
index.vue # 聊天:会话列表 + 消息 + 顶栏选模型
catalog-cite*.vue/ts # 店铺/商品引用输入
views/agent/llm-settings/
index.vue # 模型管理:凭证 / 启用列表 / 记忆
index.vue # 模型管理:凭证 / 启用列表
views/agent/memories/
index.vue # 我的记忆:列表 / 删除(用户中心入口)
api/agent/ # 调 Agent + Server 公司 LLM API
```
@@ -18,10 +18,12 @@ import { useAccessStore, useUserStore } from '@vben/stores';
import SwitchAccountModal from '#/components/SwitchAccountModal.vue';
import SwitchCompanyModal from '#/components/SwitchCompanyModal.vue';
import { usePermission } from '#/composables/use-permission';
import { useAuthStore, useRealtimeStore } from '#/store';
import LoginForm from '#/views/_core/authentication/login.vue';
const router = useRouter();
const { hasPermission } = usePermission();
const notifications = ref<NotificationItem[]>([
{
@@ -81,11 +83,16 @@ const SwitchCompanyIcon = createIconifyIcon('lucide:building-2');
const SwitchAccountIcon = createIconifyIcon('lucide:arrow-left-right');
// 用户图标
const UserIcon = createIconifyIcon('lucide:user');
// 记忆图标
const MemoryIcon = createIconifyIcon('lucide:brain');
// 意见反馈图标
const FeedbackIcon = createIconifyIcon('lucide:message-square-plus');
// 锁图标
const LockIcon = createIconifyIcon('lucide:lock');
/** 是否具备智能助手聊天权限(用于「我的记忆」入口;含超管) */
const canUseAgentChat = computed(() => hasPermission('agent:chat'));
/** 当前用户可切换的可用公司数 */
const companyCount = computed(() => {
const info = userStore.userInfo as null | { companyCount?: number };
@@ -103,6 +110,16 @@ const menus = computed(() => {
icon: UserIcon,
text: '个人信息',
});
// 我的记忆(有助手聊天权才显示)
if (canUseAgentChat.value) {
menuItems.push({
handler: () => {
router.push('/agent/memories');
},
icon: MemoryIcon,
text: '我的记忆',
});
}
// 意见反馈
menuItems.push({
handler: () => {
@@ -0,0 +1,20 @@
import type { RouteRecordRaw } from 'vue-router';
/**
* 用户记忆管理(头像下拉入口;不进侧栏菜单)
*/
const staticRoutes: RouteRecordRaw[] = [
{
name: 'AgentMemories',
path: '/agent/memories',
component: () => import('#/views/agent/memories/index.vue'),
meta: {
icon: 'lucide:brain',
title: '我的记忆',
hideInMenu: true,
ignoreAccess: true,
},
},
];
export default staticRoutes;
@@ -17,9 +17,7 @@ import {
} from 'ant-design-vue';
import {
deleteAgentMemoryApi,
getAgentLlmSettingsApi,
listAgentMemoriesApi,
probeAgentLlmModelsApi,
type AgentVO,
updateAgentLlmSettingsApi,
@@ -30,7 +28,6 @@ defineOptions({ name: 'AgentLlmSettings' });
const loading = ref(true);
const saving = ref(false);
const probingModels = ref(false);
const memories = ref<AgentVO.Memory[]>([]);
const probedModels = ref<AgentVO.ProbedLlmModel[]>([]);
const manualModelId = ref('');
@@ -54,10 +51,7 @@ async function loadAll() {
probedModels.value = [];
manualModelId.value = '';
try {
const [s, mem] = await Promise.all([
getAgentLlmSettingsApi(),
listAgentMemoriesApi().catch(() => ({ items: [] as AgentVO.Memory[] })),
]);
const s = await getAgentLlmSettingsApi();
llmForm.value = {
baseUrl: s.baseUrl || '',
apiKey: '',
@@ -73,7 +67,6 @@ async function loadAll() {
: '',
isDefault: !!m.isDefault,
}));
memories.value = mem.items || [];
} catch (e: any) {
message.error(e?.message || '加载模型配置失败');
} finally {
@@ -175,16 +168,6 @@ async function probeModels() {
}
}
async function removeMemory(id: string) {
try {
await deleteAgentMemoryApi(id);
memories.value = memories.value.filter((m) => m.id !== id);
message.success('已删除记忆');
} catch (e: any) {
message.error(e?.message || '删除失败');
}
}
async function saveSettings() {
if (!llmForm.value.baseUrl.trim()) {
message.warning('请填写 Base URL');
@@ -379,27 +362,6 @@ onMounted(() => {
</Button>
</Form>
</Card>
<Card title="我的记忆" :bordered="false">
<p class="text-muted-foreground mb-3 text-xs">
对话中发送「记住:…」可写入;助手按需检索,不会默认注入全部记忆。
</p>
<div v-if="memories.length === 0" class="text-muted-foreground text-sm">
暂无记忆
</div>
<div
v-for="m in memories"
:key="m.id"
class="mb-2 flex items-start gap-2 rounded-md bg-muted/50 px-3 py-2 text-sm"
>
<span class="min-w-0 flex-1 break-words">{{
m.summary || m.text
}}</span>
<Button type="link" size="small" danger @click="removeMemory(m.id)">
删
</Button>
</div>
</Card>
</div>
</Page>
</template>
@@ -0,0 +1,91 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Card, Empty, Spin, message } from 'ant-design-vue';
import {
deleteAgentMemoryApi,
listAgentMemoriesApi,
type AgentVO,
} from '#/api/agent';
defineOptions({ name: 'AgentMemories' });
const loading = ref(true);
const memories = ref<AgentVO.Memory[]>([]);
async function loadMemories() {
loading.value = true;
try {
const res = await listAgentMemoriesApi();
memories.value = res.items || [];
} catch (e: any) {
message.error(e?.message || '加载记忆失败');
} finally {
loading.value = false;
}
}
async function removeMemory(id: string) {
try {
await deleteAgentMemoryApi(id);
memories.value = memories.value.filter((m) => m.id !== id);
message.success('已删除记忆');
} catch (e: any) {
message.error(e?.message || '删除失败');
}
}
onMounted(() => {
void loadMemories();
});
</script>
<template>
<Page auto-content-height>
<div class="relative mx-auto max-w-3xl pb-8">
<div
v-if="loading"
class="absolute inset-0 z-10 flex items-center justify-center bg-background/50"
>
<Spin />
</div>
<Card title="我的记忆" :bordered="false">
<p class="text-muted-foreground mb-4 text-sm">
在智能助手对话中发送「记住:…」可写入;助手按需检索,不会默认注入全部记忆。
</p>
<Empty
v-if="!loading && memories.length === 0"
description="暂无记忆"
/>
<div
v-for="m in memories"
:key="m.id"
class="mb-2 flex items-start gap-2 rounded-md bg-muted/50 px-3 py-2 text-sm"
>
<div class="min-w-0 flex-1">
<div class="break-words">{{ m.summary || m.text }}</div>
<div
v-if="m.summary && m.text && m.summary !== m.text"
class="text-muted-foreground mt-1 break-words text-xs"
>
{{ m.text }}
</div>
<div
v-if="m.updatedAt"
class="text-muted-foreground mt-1 text-xs"
>
{{ m.updatedAt }}
</div>
</div>
<Button type="link" size="small" danger @click="removeMemory(m.id)">
删除
</Button>
</div>
</Card>
</div>
</Page>
</template>