open-swe/apps/web/src/components/v2/cancel-stream-button.tsx
Dylan Boudro 4793ee3d3a
Feat: cancel-run buttons [manager, planner, programmer] (#330)
* cancel run: manager, programmer, planner

* improve error handling + useCancelStream hook abstraction

* cancel stream button

* minor format

* Code review

* CR: remove duplicate stream

* Apply suggestions from code review

* cr

* use cancelStreamButton

* cleanup and fix flash

* cr

---------

Co-authored-by: Brace Sproul <braceasproul@gmail.com>
2025-07-08 11:04:27 -04:00

43 lines
906 B
TypeScript

import { Button } from "@/components/ui/button";
import { Loader2 } from "lucide-react";
import { UseStream } from "@langchain/langgraph-sdk/react";
import { useCancelStream } from "@/hooks/useCancelStream";
interface CancelStreamButtonProps {
stream: UseStream<any>;
threadId?: string;
runId?: string;
streamName: "Planner" | "Programmer";
}
export function CancelStreamButton({
stream,
threadId,
runId,
streamName,
}: CancelStreamButtonProps) {
const { cancelRun } = useCancelStream({
stream,
threadId,
runId,
streamName,
});
const shouldShow = stream.isLoading && threadId && runId;
if (!shouldShow) {
return null;
}
return (
<Button
onClick={cancelRun}
size="sm"
variant="destructive"
className="h-8 px-3 text-xs"
>
<Loader2 className="mr-1 h-3 w-3 animate-spin" />
Stop {streamName}
</Button>
);
}