Add "Clear Chat" feature with backend support and markdown parsing#11
Conversation
- Implemented a "Clear Chat" button in the UI to reset chat history and personality selection.
- Backend enhancements include a `DELETE /api/v1/chat/{sessionId}` endpoint for clearing chat history while preserving the session.
- Added markdown rendering for chat messages using Marked.js.
- Updated related tests and README documentation to reflect changes.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR implements a complete "clear chat history" feature across backend and frontend. The backend adds a DELETE endpoint ( ChangesClear Chat History Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Line 149: appendMessage currently assigns parsed markdown directly into the
DOM via contentDiv.innerHTML = window.marked.parse(text), which allows XSS from
untrusted LLM output; fix by either installing and importing DOMPurify and
replacing that assignment with a sanitized string (use
DOMPurify.sanitize(window.marked.parse(text))) or by configuring Marked to
disallow raw HTML (disable HTML parsing in Marked options) and then inserting
the safe output, ensuring you update appendMessage and any direct uses of
window.marked.parse to use the sanitized output instead.
In `@src/main/resources/static/app.js`:
- Around line 101-125: clearChat can race with an in-flight send and a late POST
response may repopulate the cleared UI; modify clearChat to
check/chatState.isWaiting and return early when true, or abort the active send
request before issuing the DELETE by wiring an AbortController used by your send
routine; also disable dom.clearBtn while chatState.isWaiting (you can reuse the
provided setLoading(active) to toggle chatState.isWaiting,
dom.clearBtn.disabled, dom.button.disabled and dom.typing visibility) so clears
are gated until the send completes or is aborted.
- Around line 139-143: The code injects HTML from window.marked.parse(text)
directly into contentDiv.innerHTML causing stored/reflected XSS; fix by
sanitizing the parsed HTML before assigning innerHTML — e.g., call a sanitizer
like DOMPurify.sanitize(...) on the string returned by window.marked.parse(text)
(or enable/plug a safe renderer option in marked if available) and then assign
the sanitized result to contentDiv.innerHTML; update the code paths around
contentDiv, window.marked.parse, and msgDiv to ensure all
user/model/backend-provided text is parsed then sanitized before DOM insertion.
In `@src/main/resources/static/index.html`:
- Line 8: Update the external marked.js import in
src/main/resources/static/index.html to pin to a specific version (use
marked@18.0.3) and add Subresource Integrity and crossorigin attributes on the
<script> tag; generate the SHA-256 SRI hash for the exact versioned file (e.g.,
marked.umd.js) using the suggested curl/openssl command or an SRI tool and place
that base64 hash in the integrity attribute while adding crossorigin="anonymous"
to the same <script> element so the browser can verify the CDN payload before
execution.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 35709376-0d48-47cf-9f98-6998160a4ca8
📒 Files selected for processing (11)
README.mdsrc/main/java/org/example/projectbifrost/controller/BifrostController.javasrc/main/java/org/example/projectbifrost/domain/ChatSession.javasrc/main/java/org/example/projectbifrost/service/ChatService.javasrc/main/java/org/example/projectbifrost/storage/ChatSessionStorage.javasrc/main/resources/static/app.jssrc/main/resources/static/index.htmlsrc/main/resources/static/style.csssrc/test/java/org/example/projectbifrost/controller/BifrostControllerTest.javasrc/test/java/org/example/projectbifrost/service/ChatServiceTest.javasrc/test/java/org/example/projectbifrost/storage/ChatSessionStorageTest.java
- Integrated DOMPurify to sanitize AI-generated markdown and prevent XSS attacks. - Enhanced UI by disabling "Clear Chat" button during active responses to avoid race conditions. - Updated README to document added XSS protection.
This pull request introduces a new "Clear Chat" feature, allowing users to erase their chat history for a session both on the frontend and backend. It also improves markdown rendering in chat messages and updates documentation and tests accordingly. The changes enhance user experience and maintainability by providing a more robust chat management system and clearer feedback.
Backend API and Logic Enhancements
DELETE /api/v1/chat/{sessionId}endpoint inBifrostControllerto clear chat history for a session, along with corresponding service and storage methods to empty the chat history while preserving the session itself. [1] [2] [3] [4]Frontend Features and UI Improvements
index.html,app.js,style.css) that calls the new backend endpoint, resets the personality selection to default, and displays a confirmation prompt and thematic message. [1] [2] [3] [4]Documentation Updates
README.mdto document the new clear chat functionality, including updated API documentation, backend and frontend descriptions, and tech stack notes. [1] [2] [3]Project Structure and Test Cleanup
BifrostController.javato reside in thecontrollerpackage for better project organization and updated test imports accordingly. [1] [2] [3]Minor Improvements
README.md.These changes collectively provide users with more control over their chat sessions, improve the chat interface, and ensure the system is well-documented and tested.
Summary by CodeRabbit
New Features
Documentation
Tests