feat: add clear session messages functionality
- Implemented a new API endpoint to clear all messages in a session, enhancing session management capabilities. - Updated the frontend to include a clear messages option in the session menu, allowing users to easily remove chat history. - Added localization support for the new feature in English, Korean, Russian, and Chinese, improving accessibility for a broader audience. - Enhanced the chat view to handle session message clearing events, ensuring a responsive user experience. These changes significantly improve the user experience by providing a straightforward method to manage session messages effectively.
This commit is contained in:
@@ -284,6 +284,29 @@ func (s *messageService) DeleteMessage(ctx context.Context, sessionID string, me
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearSessionMessages deletes all messages in a session, along with their chat history KB entries.
|
||||
func (s *messageService) ClearSessionMessages(ctx context.Context, sessionID string) error {
|
||||
logger.Infof(ctx, "Start clearing all messages for session: %s", sessionID)
|
||||
|
||||
tenantID := types.MustTenantIDFromContext(ctx)
|
||||
if _, err := s.sessionRepo.Get(ctx, tenantID, sessionID); err != nil {
|
||||
logger.Errorf(ctx, "Failed to get session: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Async cleanup: delete associated Knowledge entries from the chat history KB
|
||||
bgCtx := context.WithoutCancel(ctx)
|
||||
go s.DeleteSessionKnowledge(bgCtx, sessionID)
|
||||
|
||||
if err := s.messageRepo.DeleteMessagesBySessionID(ctx, sessionID); err != nil {
|
||||
logger.Errorf(ctx, "Failed to delete messages for session %s: %v", sessionID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "All messages cleared for session: %s", sessionID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Chat History Knowledge Base — Configuration-driven (via Tenant.ChatHistoryConfig)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user