feat: edit message - #1653
Open
maekawataiki wants to merge 1 commit into
Open
Conversation
Contributor
|
This PR is stale because it has been open for 30 days with no activity. |
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 of Changes
Extends the message edit feature (#1120) so that a message in the middle of a conversation can be edited, and fixes the data consistency issues that blocked it.
Problem
The edit feature only allowed editing the last user message. Extending it to earlier messages surfaced two issues in the existing implementation:
state only, and there was no API to delete messages. On reload, the discarded
messages came back and were mixed with the regenerated response (the edited user
message keeps its original
createdDatewhile the new response gets a newer one,so the restored order was broken).
pushed to
toBeRecordedMessagesbyaddMessageIdsToUnrecordedMessages()and thenagain by the
generationMode === 'edit'branch, producing two DynamoDB items withthe same
messageIdand differentcreatedDate.Changes
Backend
DELETE /chats/{chatId}/messages?fromCreatedDate=...deleteMessagesFrom()inrepository.tsqueries the keys withcreatedDate >= :fromCreatedDateand deletes them with chunkedBatchWriteItem(same pattern as the existingdeleteChat())fromCreatedDateand 403 when the chat belongs to another user (findChatById())messages.addMethod('DELETE')is declared explicitly inapi.tsbecause theaddProxy()catch-all does not apply to methods of an already declared Resource.API_DEPLOYMENT_VERSIONis bumped tov3accordingly.Frontend
useChat.edit()now takes the targetmessageId, truncates the conversation at that message, and deletes the discarded messages from the table before updating the local state. The deletion range starts at the message after the target, so if the regeneration fails the stored conversation is still consistent (truncated at the edited message, with its original content).produce()recipe: if the target is not found, an error toast is shown and the regeneration is not started (previously it silently fell through and regenerated on top of the existing response).loadingis set while the delete request is in flight so the conversation cannot be modified underneath the operation.editcase is removed from the assistant update branch).messageId(not recorded yet) are not editable, to avoid editing the wrong message through the fallback path.editing the last message stays a single click as before.
Scope
RAG Chat (KB) and Agent Chat send only the last message plus a
sessionId(RetrieveAndGenerateStream/InvokeAgent), so the conversation history lives in the server-side session. Truncating the conversation on the client cannot be reflected there, which means the model would keep answering based on messages the user has just deleted.RetrieveAndGeneratehas no equivalent ofsessionState.conversationHistory, so a truncated history cannot be seeded either, and resetting the session would drop the whole context. Middle-of-conversation editing is therefore enabled only on the plain Chat page, where the full message list is sent on every request. Editing the last message behaves as before on all three pages.Impact on existing users
messageId) instead of being updated in place. Feedback on that message was already reset bybatchCreateMessages()before this change, so the visible behavior is the same.chat.edit_message_confirmation,chat.edit_message_warning,error.editFailed,error.editTargetNotFound(added for all 6 languages).Checklist
npm run cdk:testand if there are snapshot differences, executenpm run cdk:test:update-snapshotto update snapshotsTests
packages/cdk/test/lambda/deleteMessages.test.ts: 204 / 400 / 403 / 500packages/web/tests/components/ChatMessage.test.tsx: the edit button is shown for anyrecorded user message, and hidden when the message has no
messageIdor is not editablenpm run lint,npm run web:test(281 passed),npx jest test/lambda(34 passed)Related Issues