Files
kandev/apps/web/components/task/chat/reset-context-button.tsx
T

87 lines
2.9 KiB
TypeScript

"use client";
import { useState, useCallback } from "react";
import { IconRotateClockwise2 } from "@tabler/icons-react";
import { GridSpinner } from "@/components/grid-spinner";
import { Button } from "@kandev/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@kandev/ui/alert-dialog";
import { getWebSocketClient } from "@/lib/ws/connection";
export function ResetContextButton({ sessionId }: { sessionId: string }) {
const [confirmOpen, setConfirmOpen] = useState(false);
const [isResetting, setIsResetting] = useState(false);
const handleReset = useCallback(async () => {
setIsResetting(true);
try {
const client = getWebSocketClient();
if (!client) return;
await client.request("session.reset_context", { session_id: sessionId }, 30000);
} catch (error) {
console.error("Failed to reset agent context:", error);
} finally {
setIsResetting(false);
setConfirmOpen(false);
}
}, [sessionId]);
return (
<>
<Tooltip>
<TooltipTrigger asChild>
<Button
type="button"
variant="ghost"
size="icon"
className="h-7 w-7 cursor-pointer hover:bg-muted/40 text-muted-foreground"
onClick={() => setConfirmOpen(true)}
disabled={isResetting}
data-testid="reset-context-button"
>
{isResetting ? (
<GridSpinner className="h-4 w-4" />
) : (
<IconRotateClockwise2 className="h-4 w-4" />
)}
</Button>
</TooltipTrigger>
<TooltipContent>
Reset agent context — clears conversation history, preserves workspace
</TooltipContent>
</Tooltip>
<AlertDialog open={confirmOpen} onOpenChange={setConfirmOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Reset agent context?</AlertDialogTitle>
<AlertDialogDescription>
This will clear the agent&apos;s conversation history and start a fresh context. Your
workspace, files, and git state will be preserved.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel className="cursor-pointer">Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleReset}
disabled={isResetting}
className="cursor-pointer"
data-testid="reset-context-confirm"
>
{isResetting ? "Resetting..." : "Reset Context"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
);
}