mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 09:49:19 +08:00
feat: 智能助手支持软删会话并级联隐藏消息
This commit is contained in:
@@ -112,6 +112,11 @@ export async function patchAgentSessionApi(
|
||||
);
|
||||
}
|
||||
|
||||
/** 软删会话(级联软删消息) */
|
||||
export async function deleteAgentSessionApi(threadId: string) {
|
||||
return requestClient.delete<AgentVO.Session>(`/agent/sessions/${threadId}`);
|
||||
}
|
||||
|
||||
export async function listAgentMessagesApi(threadId: string) {
|
||||
return requestClient.get<{ items: AgentVO.Message[] }>(
|
||||
`/agent/sessions/${threadId}/messages`,
|
||||
|
||||
@@ -4,6 +4,7 @@ export {
|
||||
createAgentSessionApi,
|
||||
deleteAgentLlmProviderApi,
|
||||
deleteAgentMemoryApi,
|
||||
deleteAgentSessionApi,
|
||||
getAgentLlmProviderApi,
|
||||
listAgentEnabledLlmModelsApi,
|
||||
listAgentLlmProvidersApi,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { computed, h, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||
|
||||
import { EllipsisText, Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
@@ -12,13 +12,26 @@ import {
|
||||
} from '@ant-design/icons-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { Empty, Popover, Select, Spin, Tooltip, message } from 'ant-design-vue';
|
||||
import type { MenuProps } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
Dropdown,
|
||||
Empty,
|
||||
Menu,
|
||||
Modal,
|
||||
Popover,
|
||||
Select,
|
||||
Spin,
|
||||
Tooltip,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
import { ChatItem, ChatLoading } from '@tdesign-vue-next/chat';
|
||||
import 'tdesign-vue-next/es/style/index.css';
|
||||
import '@tdesign-vue-next/chat/es/style/index.css';
|
||||
|
||||
import {
|
||||
createAgentSessionApi,
|
||||
deleteAgentSessionApi,
|
||||
listAgentEnabledLlmModelsApi,
|
||||
listAgentMessagesApi,
|
||||
listAgentSessionsApi,
|
||||
@@ -43,6 +56,8 @@ const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
|
||||
const PanelOpenIcon = createIconifyIcon('lucide:panel-left');
|
||||
const NewChatIcon = createIconifyIcon('lucide:square-pen');
|
||||
const RecentChatIcon = createIconifyIcon('lucide:message-square');
|
||||
const MoreIcon = createIconifyIcon('lucide:ellipsis');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
const SIDER_COLLAPSED_KEY = 'agent-chat-sider-collapsed';
|
||||
|
||||
@@ -334,6 +349,71 @@ function onSessionClick(threadId: string) {
|
||||
activeThreadId.value = threadId;
|
||||
}
|
||||
|
||||
const deletingThreadId = ref<string | null>(null);
|
||||
/** 打开中的会话操作菜单;用于悬停三点在菜单打开时保持可见 */
|
||||
const sessionMenuOpenThreadId = ref<string | null>(null);
|
||||
|
||||
const sessionMenuItems: MenuProps['items'] = [
|
||||
{
|
||||
key: 'delete',
|
||||
danger: true,
|
||||
label: '删除',
|
||||
icon: () => h(TrashIcon, { class: 'size-3.5' }),
|
||||
},
|
||||
];
|
||||
|
||||
function onSessionMenuOpenChange(threadId: string, open: boolean) {
|
||||
sessionMenuOpenThreadId.value = open ? threadId : null;
|
||||
}
|
||||
|
||||
function onSessionMenuClick(
|
||||
threadId: string,
|
||||
info: Parameters<NonNullable<MenuProps['onClick']>>[0],
|
||||
) {
|
||||
sessionMenuOpenThreadId.value = null;
|
||||
if (info.key === 'delete') {
|
||||
confirmDeleteSession(threadId);
|
||||
}
|
||||
}
|
||||
|
||||
/** 确认后软删会话;若删的是当前会话则回到新对话空态 */
|
||||
function confirmDeleteSession(threadId: string) {
|
||||
Modal.confirm({
|
||||
title: '删除会话',
|
||||
content: '删除后无法在列表中恢复,确定删除该会话?',
|
||||
okText: '删除',
|
||||
okType: 'danger',
|
||||
cancelText: '取消',
|
||||
async onOk() {
|
||||
await onDeleteSession(threadId);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function onDeleteSession(threadId: string) {
|
||||
if (sending.value) {
|
||||
message.warning('回复生成中,请稍候再删除');
|
||||
return Promise.reject(new Error('busy'));
|
||||
}
|
||||
if (deletingThreadId.value) {
|
||||
return Promise.reject(new Error('deleting'));
|
||||
}
|
||||
deletingThreadId.value = threadId;
|
||||
try {
|
||||
await deleteAgentSessionApi(threadId);
|
||||
sessions.value = sessions.value.filter((s) => s.threadId !== threadId);
|
||||
if (activeThreadId.value === threadId) {
|
||||
beginNewChat();
|
||||
}
|
||||
message.success('会话已删除');
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '删除会话失败');
|
||||
return Promise.reject(e);
|
||||
} finally {
|
||||
deletingThreadId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshSessions() {
|
||||
loadingSessions.value = true;
|
||||
try {
|
||||
@@ -757,22 +837,57 @@ void loadEnabledModels().then(() => refreshSessions());
|
||||
>
|
||||
{{ group.label }}
|
||||
</div>
|
||||
<button
|
||||
<div
|
||||
v-for="s in group.items"
|
||||
:key="s.threadId"
|
||||
type="button"
|
||||
class="agent-session-item mb-0.5 w-full cursor-pointer rounded-lg px-3 py-2 text-left text-sm transition-colors"
|
||||
class="agent-session-item group mb-0.5 flex w-full cursor-pointer items-center gap-1 rounded-lg px-2 py-1.5 text-left text-sm transition-colors"
|
||||
:class="
|
||||
s.threadId === activeThreadId
|
||||
? 'agent-session-item--active'
|
||||
: ''
|
||||
"
|
||||
@click="onSessionClick(s.threadId)"
|
||||
>
|
||||
<EllipsisText :tooltip-when-ellipsis="true" class="w-full">
|
||||
{{ s.title || '新对话' }}
|
||||
</EllipsisText>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="min-w-0 flex-1 truncate px-1 py-0.5 text-left"
|
||||
@click="onSessionClick(s.threadId)"
|
||||
>
|
||||
<EllipsisText :tooltip-when-ellipsis="true" class="w-full">
|
||||
{{ s.title || '新对话' }}
|
||||
</EllipsisText>
|
||||
</button>
|
||||
<Dropdown
|
||||
:trigger="['click']"
|
||||
:open="sessionMenuOpenThreadId === s.threadId"
|
||||
@open-change="
|
||||
(open: boolean) =>
|
||||
onSessionMenuOpenChange(s.threadId, open)
|
||||
"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="text-muted-foreground hover:bg-accent hover:text-foreground flex size-7 shrink-0 items-center justify-center rounded-md opacity-0 transition-opacity group-hover:opacity-100"
|
||||
:class="
|
||||
sessionMenuOpenThreadId === s.threadId ||
|
||||
s.threadId === activeThreadId
|
||||
? 'opacity-100'
|
||||
: ''
|
||||
"
|
||||
aria-label="会话操作"
|
||||
@click.stop
|
||||
>
|
||||
<MoreIcon class="size-3.5" />
|
||||
</button>
|
||||
<template #overlay>
|
||||
<Menu
|
||||
:items="sessionMenuItems"
|
||||
@click="
|
||||
(info) => onSessionMenuClick(s.threadId, info)
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user