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:
parent
693ab8069d
commit
b56d24ea3e
1 changed files with 19 additions and 0 deletions
|
|
@ -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, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue