feat: add deleteAllSessions functionality and update batch delete logic

- Introduced a new API function `deleteAllSessions` to allow deletion of all sessions for a tenant.
- Updated the `BatchManageDialog` component to support a confirmation dialog for deleting all sessions.
- Enhanced the menu component to reflect the new delete all functionality with appropriate confirmation messages.
- Added internationalization support for the new delete all confirmation message in multiple languages.

These changes improve session management by providing users with the ability to delete all sessions at once, enhancing the overall user experience.
This commit is contained in:
wizardchen
2026-03-02 20:58:09 +08:00
committed by lyingbug
parent 5ba42633ba
commit 284d6c623e
11 changed files with 113 additions and 447 deletions
@@ -95,3 +95,8 @@ func (r *sessionRepository) BatchDelete(ctx context.Context, tenantID uint64, id
}
return r.db.WithContext(ctx).Where("tenant_id = ? AND id IN ?", tenantID, ids).Delete(&types.Session{}).Error
}
// DeleteAllByTenantID deletes all sessions for a tenant
func (r *sessionRepository) DeleteAllByTenantID(ctx context.Context, tenantID uint64) error {
return r.db.WithContext(ctx).Where("tenant_id = ?", tenantID).Delete(&types.Session{}).Error
}
+30
View File
@@ -260,6 +260,36 @@ func (s *sessionService) BatchDeleteSessions(ctx context.Context, ids []string)
return nil
}
// DeleteAllSessions deletes all sessions for the current tenant
func (s *sessionService) DeleteAllSessions(ctx context.Context) error {
tenantID := types.MustTenantIDFromContext(ctx)
logger.Infof(ctx, "Deleting all sessions for tenant %d", tenantID)
sessions, err := s.sessionRepo.GetByTenantID(ctx, tenantID)
if err != nil {
logger.Warnf(ctx, "Failed to list sessions for cleanup: %v", err)
} else {
for _, session := range sessions {
if err := s.webSearchStateRepo.DeleteWebSearchTempKBState(ctx, session.ID); err != nil {
logger.Warnf(ctx, "Failed to cleanup temporary KB for session %s: %v", session.ID, err)
}
if err := s.sessionStorage.Delete(ctx, session.ID); err != nil {
logger.Warnf(ctx, "Failed to cleanup conversation context for session %s: %v", session.ID, err)
}
}
}
if err := s.sessionRepo.DeleteAllByTenantID(ctx, tenantID); err != nil {
logger.ErrorWithFields(ctx, err, map[string]interface{}{
"tenant_id": tenantID,
})
return err
}
logger.Infof(ctx, "All sessions deleted for tenant %d", tenantID)
return nil
}
// GenerateTitle generates a title for the current conversation content
// modelID: optional model ID to use for title generation (if empty, uses first available KnowledgeQA model)
func (s *sessionService) GenerateTitle(ctx context.Context,