Repository navigation
Conversation
…the portal is disabled
| <span>清空对话</span> | ||
| </MkDropdownItem> | ||
| </MkDropdownMenu> | ||
| </template> |
There was a problem hiding this comment.
Review findings
-
Async flow may not actually wait for the clear operation
.then(() => portalList.clearGroupConversations(group.id, () => { ... }), ) .then(() => MsgSuccess('清空成功'))
If
portalList.clearGroupConversationsreturnsvoidinstead of aPromise, the success message will be shown immediately, and the callback/UI reset may happen later or not at all. Ensure the store method returns aPromisethat resolves only after the backend clear and callback have completed. -
.catch(() => {})swallows real errors
This hides both confirmation cancellation and actual API failures. Users will not know clearing failed. Distinguish cancellation from failure and show an error message for real failures. -
The loading flag is not reflected in the UI
clearGroupConversationLoadingonly prevents re-entry. The menu item remains clickable, and the user gets no feedback while the request is running. Bind it todisabledor a loading state:<MkDropdownItem divided :disabled="clearGroupConversationLoading" @click="handleClearGroupConversations(group)" >
-
Store accepts a UI callback, which couples store and view
Prefer returning aPromisefrom the store and performing UI updates in the component. This is easier to test and less error-prone. -
Current-conversation reset may be incomplete
conversations.value = []only clears the list. If there are other related states, such as selected conversation ID, message list, pagination, search results, cached group conversation counts, or last-message metadata, they may become stale. Centralize the reset logic in a single function. -
Possible ID type mismatch
group.id === currentApplicationId.valueuses strict equality. If one is anumberand the other astring, the condition will silently fail. Normalize types or verify both are always the same type. -
Stale comment
The old comment still says “删除智能体历史分组”; the action is now “清空对话”. Update the comment to avoid confusion. -
Synchronous errors before the promise chain could leave loading stuck
IfMsgConfirmthrows synchronously before returning a promise,.finallywill not run. Anasync/await+try/finallystructure is safer.
Suggested refactor
const 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
- Rename
clearGroupConversationLoadingtoisClearingGroupConversationfor clarity. - Add a permission check if not every user should be allowed to clear all conversations.
- Consider disabling the menu item when the group has no conversations.
- Verify that
switchShared(false)andnewConversation()do not duplicate or contradict the reset logic, especially if either is asynchronous.
| clearGroupConversations, | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Code Review
Issues / Potential Problems
-
No error handling on
clearApplicationConversations- If the API call rejects,
onCleared()and local state updates never happen — that's actually correct, but the error propagates unhandled. Consider wrapping in try/catch to surface a user-facing error or log it, consistent with howremoveConversationis (or isn't) handled elsewhere.
- If the API call rejects,
-
Local state mutation only; no rollback
- After a successful API call you mutate
group.conversations = []andgroup.count = 0. If the server later fails on the next refresh, the list will still show empty until a refetch. Acceptable if you trust the backend, but worth noting. - More importantly, other groups' data isn't touched — verify
countis not derived (e.g., from a separate aggregate endpoint) that could become stale after clearing.
- After a successful API call you mutate
-
onClearedcallback contract is implicit- The signature
(applicationId: string, onCleared: () => void)uses a positional callback. This is inconsistent withclearConversations(onRemoved)which takes one callback. Consider naming/signature consistency, or document clearly thatonClearedmust sync the current-application store. Also: shouldonClearedfire before or after the group state is reset? Ordering matters if the callee readsapplicationGroups.
- The signature
-
Missing guard for empty/invalid
applicationId- No validation that
applicationIdis non-empty. A stray call would hit the backend unnecessarily.
- No validation that
-
Duplicate "clear" methods may confuse
- You now have both
clearConversations(all groups) andclearGroupConversations(single app). Their names are close but behavior differs significantly. Consider renaming toclearAllConversationsvsclearConversationGroup, or add JSDoc clarifying scope.
- You now have both
-
Possible race condition
- If the user clears while
pageGroupConversationsis in-flight for the same group, the response could repopulateconversationsafter the clear. Consider a request token / generation counter per group, similar to cancellation patterns used elsewhere.
- If the user clears while
-
count = 0assumption- Assumes
countsemantically equals "current user's conversations". Ifcountincludes shared/other-user sessions, this becomes incorrect. Confirm the backend semantics ofclearApplicationConversationsmatches whatcountreflects.
- Assumes
-
Promise<unknown>return type- Returning
unknowngives no type safety at the call site. If the API returns something useful (e.g., number cleared), type it. Otherwise,Promise<void>would be clearer.
- Returning
Optimization Suggestions
- Consider optimistic update pattern (clear UI first, rollback on failure) since this action is destructive and user-initiated — improves perceived latency.
- Extract the group lookup into a small helper (
findGroup(id)) to reduce repetition; you already do similar lookups elsewhere. - Add unit tests covering: successful clear, failed clear (state unchanged + no
onCleared), in-flight refresh race. - Consider exposing
clearGroupConversationsresult (boolean) so callers know whether anything was cleared.
Minor / Style
- The added destructuring line is getting long; consider grouping deps or using
deps.xdirectly for rarely-used ones. - Since you're adding to a public-ish store surface (
clearGroupConversationsin the returned object), ensure the correspondingPortalConversationListDepsdoc and consumer wiring are updated (diff shows deps added — good).
Overall the change is small and coherent; main risks are error propagation, callback ordering contract, and race conditions with group refreshes.
| getShareConversation, | ||
| postSpeechToText, | ||
| clearConversations, | ||
| } |
There was a problem hiding this comment.
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.- Ensure this is protected by:
- authentication and authorization checks on the server,
- confirmation in the UI,
- audit logging if history deletion is sensitive.
- Make sure the backend validates that the current user actually owns/can access
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:clearChatHistoryclearConversationHistoryclearCurrentUserConversations
- Update the JSDoc to make “current authenticated user only” explicit.
-
HTTP method / endpoint contract
- Confirm the backend really expects
DELETE /.../chat/clear. - Some proxies/clients handle
DELETEinconsistently, and some APIs usePOSTfor bulk-clear operations. Ifdeldoes not support a request body and the backend requires one, this will fail. - Confirm the expected response, especially if it returns
204 No Content. The API client should handle empty responses correctly.
- Confirm the backend really expects
-
Return type
- Consider adding an explicit return type, e.g.
Promise<void>or whateverdelreturns, if the project follows that convention:const clearConversations = (applicationId: string): Promise<void> => del(`${getApplicationPath(applicationId)}/chat/clear`)
- This improves type safety and documents the expected behavior.
- Consider adding an explicit return type, e.g.
-
UI/cache invalidation
- After calling this API, invalidate/refetch conversation lists and reset any active chat state. Otherwise the UI may still show deleted conversations.
-
Tests
- Add tests for:
- successful clearing,
- error handling,
- unauthorized access,
- empty-history behavior,
- UI cache/state reset after success.
- Add tests for:
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.
fix: the delete button in the agent conversation grouping section of the portal is disabled