Repository navigation
fix: the delete button in the agent conversation grouping section of the portal is disabled #7937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ export interface PortalConversationListDeps { | |
| /** 分页获取某个智能体的历史会话,展开分组时刷新。 */ | ||
| pageGroupConversations: (applicationId: string, page: number, size: number) => Promise<{ records?: Conversation[] } | null | undefined> | ||
| removeConversation: (applicationId: string, chatId: string) => Promise<unknown> | ||
| /** 清空某个智能体当前用户的全部历史会话。 */ | ||
| clearApplicationConversations: (applicationId: string) => Promise<unknown> | ||
| /** 当前对话的智能体 ID;门户首页与全部智能体页为空。 */ | ||
| currentApplicationId: Readonly<Ref<string>> | ||
| /** 当前是否处于全部智能体页。 */ | ||
|
|
@@ -45,7 +47,7 @@ const GROUP_CONVERSATION_LIMIT = 20 | |
| * 侧栏展示时以其为准,保证新建、重命名和删除即时生效;其他智能体使用分组接口返回的最近会话。 | ||
| */ | ||
| export function createPortalConversationListStore(deps: PortalConversationListDeps) { | ||
| const { pageApplicationConversations, pageApplications, pageGroupConversations, removeConversation, currentApplicationId } = deps | ||
| const { pageApplicationConversations, pageApplications, pageGroupConversations, removeConversation, clearApplicationConversations, currentApplicationId } = deps | ||
|
|
||
| // 历史对话分组 | ||
| const applicationGroups = ref<PortalApplicationGroup[]>([]) | ||
|
|
@@ -97,6 +99,17 @@ export function createPortalConversationListStore(deps: PortalConversationListDe | |
| } | ||
| } | ||
|
|
||
| // 清空某一智能体的全部历史对话;onCleared 用于同步当前智能体会话列表 Store。 | ||
| const clearGroupConversations = async (applicationId: string, onCleared: () => void) => { | ||
| await clearApplicationConversations(applicationId) | ||
| const group = applicationGroups.value.find((applicationGroup) => applicationGroup.id === applicationId) | ||
| if (group) { | ||
| group.conversations = [] | ||
| group.count = 0 | ||
| } | ||
| onCleared() | ||
| } | ||
|
|
||
| // 先查询全部分组和会话,再删除,避免边删除边翻页造成记录遗漏。 | ||
| const clearConversations = async (onRemoved: (applicationId: string, chatId: string) => void) => { | ||
| const applicationIds = new Set<string>() | ||
|
|
@@ -170,6 +183,7 @@ export function createPortalConversationListStore(deps: PortalConversationListDe | |
| shareConversation: deps.shareConversation, | ||
| openApplicationList: deps.openApplicationList, | ||
| newConversation, | ||
| clearGroupConversations, | ||
| } | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code ReviewIssues / Potential Problems
Optimization Suggestions
Minor / Style
Overall the change is small and coherent; main risks are error propagation, callback ordering contract, and race conditions with group refreshes. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,28 @@ const handleClearConversations = () => { | |
| clearing.value = false | ||
| }) | ||
| } | ||
|
|
||
| // 清空指定智能体的全部历史对话;若为当前智能体,同步清空会话列表并新建对话。 | ||
| const clearGroupConversationLoading = ref(false) | ||
| const handleClearGroupConversations = (group: PortalApplicationGroup) => { | ||
| if (clearGroupConversationLoading.value) return | ||
| clearGroupConversationLoading.value = true | ||
| MsgConfirm('确认清空该智能体的全部历史对话?', '清空后无法恢复。', { confirmButtonText: '清空' }) | ||
| .then(() => | ||
| portalList.clearGroupConversations(group.id, () => { | ||
| if (group.id === currentApplicationId.value) { | ||
| conversations.value = [] | ||
| switchShared(false) | ||
| newConversation() | ||
| } | ||
| }), | ||
| ) | ||
| .then(() => MsgSuccess('清空成功')) | ||
| .catch(() => {}) | ||
| .finally(() => { | ||
| clearGroupConversationLoading.value = false | ||
| }) | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
|
|
@@ -174,9 +196,9 @@ const handleClearConversations = () => { | |
| <span>新建对话</span> | ||
| </MkDropdownItem> | ||
| <!-- 删除智能体历史分组,待接入对应接口 --> | ||
| <MkDropdownItem divided disabled> | ||
| <MkDropdownItem divided @click="handleClearGroupConversations(group)"> | ||
| <template #icon><MkIcon name="icon_delete-trash_outlined" /></template> | ||
| <span>删除</span> | ||
| <span>清空对话</span> | ||
| </MkDropdownItem> | ||
| </MkDropdownMenu> | ||
| </template> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review findings
Suggested refactorconst clearGroupConversationLoading = ref(false)
const handleClearGroupConversations = async (group: PortalApplicationGroup) => {
if (clearGroupConversationLoading.value) return
clearGroupConversationLoading.value = true
let confirmed = false
try {
await MsgConfirm(
'确认清空该智能体的全部历史对话?',
'清空后无法恢复。',
{ confirmButtonText: '清空', type: 'warning' },
)
confirmed = true
// Prefer the store method to return Promise<void>.
await portalList.clearGroupConversations(group.id)
if (group.id === currentApplicationId.value) {
resetCurrentConversationState() // clear list, selection, messages, pagination, etc.
switchShared(false)
newConversation()
}
MsgSuccess('清空成功')
} catch (err) {
// Do not show an error when the user simply cancels the confirmation.
if (confirmed) {
MsgError('清空失败,请稍后重试')
}
} finally {
clearGroupConversationLoading.value = false
}
}Store change: // Before: callback style, possibly returns void
clearGroupConversations(groupId: string, callback?: () => void)
// Better: return a promise and reject on failure
async clearGroupConversations(groupId: string): Promise<void> {
await api.clearGroupConversations(groupId)
}Minor suggestions
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff is syntactically fine and follows the existing API-module style. There are no obvious implementation bugs, but there are several things to verify/improve:
Destructive operation risk
clearConversationsdeletes all chat history for the current user under the given agent.applicationIdto avoid IDOR-style issues.Naming clarity
clearConversationsis somewhat ambiguous. It clears the current user’s conversation history for one agent, so a clearer name could be:clearChatHistoryclearConversationHistoryclearCurrentUserConversationsHTTP method / endpoint contract
DELETE /.../chat/clear.DELETEinconsistently, and some APIs usePOSTfor bulk-clear operations. Ifdeldoes not support a request body and the backend requires one, this will fail.204 No Content. The API client should handle empty responses correctly.Return type
Promise<void>or whateverdelreturns, if the project follows that convention:UI/cache invalidation
Tests
Overall: the diff is safe code-wise, but the main concerns are the destructive nature of the endpoint, backend authorization, correct HTTP method/response handling, and cache/UI refresh after clearing.