Studio: cascade user message deletion to include assistant reply (#6720)

* cascade user message deletion to include assistant reply

* Fix comment typo in delete-thread-message

---------

Co-authored-by: Daniel Han <danielhanchen@gmail.com>
This commit is contained in:
Nilay 2026-06-28 16:46:03 +05:30 committed by GitHub
commit b56d24ea3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -112,7 +112,26 @@ export async function deleteThreadMessage(args: {
const exported = thread.export();
const repo = new MessageRepository();
repo.import(exported);
const target = exported.messages.find(
({ message }) => message.id === messageId,
);
const assistantReplyIds =
target?.message.role === "user"
? exported.messages
.filter(
({ parentId, message }) =>
parentId === messageId && message.role === "assistant",
)
.map(({ message }) => message.id)
: [];
// Delete the prompt first; that relinks its replies up to the prompt's parent
repo.deleteMessage(messageId);
for (const replyId of assistantReplyIds) {
repo.deleteMessage(replyId);
}
const next = repo.export();
if (remoteId) {
await syncExportedRepositoryToBackend(remoteId, next, {