feat: add delete chat turn functionality with attachment cleanup#443
Merged
Conversation
e004c79 to
936f654
Compare
… and temp ID resolution
deleteMessage was the one remaining raw fetch() call in session-api.ts. After PR HKUDS#474 wired multi-user auth through apiFetch (which attaches the JWT bearer token from local storage / cookies), this call would fail with 401 Unauthorized in multi-user mode. Switch to apiFetch to match the convention established for every other authenticated session call in this file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
a153ef6 to
b5fcbfe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the ability to delete a specific Q&A turn (user + assistant message pair) from a WebUI Chat session, along with proper cleanup of associated attachment files.
Key changes:
Backend:
AttachmentStore.delete_attachment(session_id, attachment_id)method to delete individual attachment files from diskSQLiteSessionStore.delete_turn_by_message(session_id, message_id)method that:was_running=Trueto prevent data loss)attachments_jsonfor cleanupsummary_up_to_msg_idwhen deleted messages fall within the summary rangeDELETE /api/v1/sessions/{session_id}/messages/{message_id}endpoint with:delete_sessionendpoint now callsAttachmentStore.delete_session()to clean up attachment files (previously implemented but never called)Frontend:
MessageIteminterface withid?: numberfield, mapped from backendSessionMessage.iddeleteMessage(sessionId, messageId)API function insession-api.tsDELETE_TURNreducer action that removes the user+assistant message pair from statedeleteTurn(messageId)context method with temporary ID resolution (reloads session if message has a client-side temporary ID)onDeleteTurncallback throughChatMessageList→UserMessage→ page componentRelated Issues
Module(s) Affected
apiservicesweb(Frontend)Checklist
pre-commit run --all-filesand fixed any issues.Additional Notes
Design decisions:
was_runningcheck happens before any data deletion to prevent data loss. The API returns 409 if the turn is actively streaming