feat: rewind conversations while keeping file changes (#11358)
Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
1 parent
25da986037
commit
efccda9ac9
10 files changed
+478
-164
No files matched your search
@@ -6533,8 +6533,18 @@ export default function ChatView(props: ChatViewProps) {
|
||||
return () => window.removeEventListener("paste", handler, true);
|
||||
}, [activeThreadId, composerRef]);
|
||||
|
||||
const [pendingRevert, setPendingRevert] = useState<{
|
||||
turnCount: number;
|
||||
messageId: MessageId;
|
||||
routeThreadKey: string;
|
||||
} | null>(null);
|
||||
|
||||
if (pendingRevert && pendingRevert.routeThreadKey !== routeThreadKey) {
|
||||
setPendingRevert(null);
|
||||
}
|
||||
|
||||
const onRevertToTurnCount = useCallback(
|
||||
async (turnCount: number, messageId: MessageId) => {
|
||||
async (turnCount: number, messageId: MessageId, restoreFiles?: boolean) => {
|
||||
const localApi = readLocalApi();
|
||||
if (!localApi || !activeThread || isRevertingCheckpoint) return;
|
||||
const message = activeThread.messages.find((message) => message.id === messageId);
|
||||
@@ -6558,15 +6568,8 @@ export default function ChatView(props: ChatViewProps) {
|
||||
setThreadError(activeThread.id, "Interrupt the current turn before reverting checkpoints.");
|
||||
return;
|
||||
}
|
||||
const confirmed = await localApi.dialogs.confirm(
|
||||
[
|
||||
"Edit from here?",
|
||||
"Rewind files and chat to before this message.",
|
||||
"Your prompt and attachments return to the composer.",
|
||||
].join("\n"),
|
||||
{ variant: "destructive" },
|
||||
);
|
||||
if (!confirmed) {
|
||||
if (restoreFiles === undefined) {
|
||||
setPendingRevert({ turnCount, messageId, routeThreadKey });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6599,7 +6602,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
await waitForRevertedMessage(routeThreadRef, messageId, turnCount, async () => {
|
||||
const result = await revertThreadCheckpoint({
|
||||
environmentId,
|
||||
input: { threadId: activeThread.id, turnCount },
|
||||
input: { threadId: activeThread.id, turnCount, restoreFiles },
|
||||
});
|
||||
if (result._tag === "Failure") throw squashAtomCommandFailure(result);
|
||||
});
|
||||
@@ -9144,6 +9147,44 @@ export default function ChatView(props: ChatViewProps) {
|
||||
</RightPanelSheet>
|
||||
) : null}
|
||||
|
||||
<AlertDialog
|
||||
open={pendingRevert !== null && pendingRevert.routeThreadKey === routeThreadKey}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setPendingRevert(null);
|
||||
}}
|
||||
>
|
||||
<AlertDialogPopup>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Edit from here?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Rewind chat to before this message. Your prompt and attachments return to the
|
||||
composer.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => {
|
||||
if (!pendingRevert || pendingRevert.routeThreadKey !== routeThreadKey) return;
|
||||
setPendingRevert(null);
|
||||
void onRevertToTurnCount(pendingRevert.turnCount, pendingRevert.messageId, true);
|
||||
}}
|
||||
>
|
||||
Revert files too
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (!pendingRevert || pendingRevert.routeThreadKey !== routeThreadKey) return;
|
||||
setPendingRevert(null);
|
||||
void onRevertToTurnCount(pendingRevert.turnCount, pendingRevert.messageId, false);
|
||||
}}
|
||||
>
|
||||
Revert and keep changes
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogPopup>
|
||||
</AlertDialog>
|
||||
<LinkPullRequestDialogHost />
|
||||
{expandedImage && (
|
||||
<ExpandedImageDialog
|
||||
|
||||
Reference in new issue
Block a user