From a1e4eddb72b7f8ac1a4ece9c17622e11943cb1c4 Mon Sep 17 00:00:00 2001 From: akhisud3195 Date: Mon, 21 Jul 2025 16:05:31 +0530 Subject: [PATCH] Add stop button in playground --- .../playground/components/chat.tsx | 15 ++++++++ .../common/compose-box-playground.tsx | 34 +++++++++++++++---- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/apps/rowboat/app/projects/[projectId]/playground/components/chat.tsx b/apps/rowboat/app/projects/[projectId]/playground/components/chat.tsx index 386d4201..18f8910e 100644 --- a/apps/rowboat/app/projects/[projectId]/playground/components/chat.tsx +++ b/apps/rowboat/app/projects/[projectId]/playground/components/chat.tsx @@ -57,6 +57,7 @@ export function Chat({ // --- Scroll/auto-scroll/unread bubble logic --- const scrollContainerRef = useRef(null); + const eventSourceRef = useRef(null); const [autoScroll, setAutoScroll] = useState(true); const [showUnreadBubble, setShowUnreadBubble] = useState(false); @@ -215,6 +216,7 @@ export function Chat({ console.log(`chat.tsx: got streamid: ${streamId}`); eventSource = new EventSource(`/api/stream-response/${streamId}`); + eventSourceRef.current = eventSource; eventSource.addEventListener("message", (event) => { console.log(`chat.tsx: got message: ${event.data}`); @@ -238,6 +240,7 @@ export function Chat({ console.log(`chat.tsx: got done event: ${event.data}`); if (eventSource) { eventSource.close(); + eventSourceRef.current = null; } const parsed = JSON.parse(event.data); @@ -256,6 +259,7 @@ export function Chat({ console.log(`chat.tsx: got stream_error event: ${event.data}`); if (eventSource) { eventSource.close(); + eventSourceRef.current = null; } console.error('SSE Error:', event); @@ -296,6 +300,7 @@ export function Chat({ ignore = true; if (eventSource) { eventSource.close(); + eventSourceRef.current = null; } }; }, [ @@ -309,6 +314,15 @@ export function Chat({ projectTools, ]); + // Add a stop handler function + const handleStop = useCallback(() => { + if (eventSourceRef.current) { + eventSourceRef.current.close(); + eventSourceRef.current = null; + setLoadingAssistantResponse(false); + } + }, []); + return
@@ -387,6 +401,7 @@ export function Chat({ loading={loadingAssistantResponse} shouldAutoFocus={isLastInteracted} onFocus={() => setIsLastInteracted(true)} + onCancel={handleStop} />
diff --git a/apps/rowboat/components/common/compose-box-playground.tsx b/apps/rowboat/components/common/compose-box-playground.tsx index 05498981..2c43a455 100644 --- a/apps/rowboat/components/common/compose-box-playground.tsx +++ b/apps/rowboat/components/common/compose-box-playground.tsx @@ -9,6 +9,7 @@ interface ComposeBoxPlaygroundProps { disabled?: boolean; shouldAutoFocus?: boolean; onFocus?: () => void; + onCancel?: () => void; // Add this prop } export function ComposeBoxPlayground({ @@ -18,6 +19,7 @@ export function ComposeBoxPlayground({ disabled = false, shouldAutoFocus = false, onFocus, + onCancel, }: ComposeBoxPlaygroundProps) { const [input, setInput] = useState(''); const [isFocused, setIsFocused] = useState(false); @@ -93,17 +95,19 @@ export function ComposeBoxPlayground({ /> - {/* Send button */} + {/* Send/Stop button */}