Skip to content

Commit 8983b0a

Browse files
Merge pull request #77 from Gyurmatag/stop-the-request
Add stop button to Chat component for interrupting message generation
2 parents 55d8824 + caf8f53 commit 8983b0a

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/app.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Sun,
2222
Trash,
2323
PaperPlaneTilt,
24+
Stop,
2425
} from "@phosphor-icons/react";
2526

2627
// List of tools that require human confirmation
@@ -77,6 +78,8 @@ export default function Chat() {
7778
handleSubmit: handleAgentSubmit,
7879
addToolResult,
7980
clearHistory,
81+
isLoading,
82+
stop,
8083
} = useAgentChat({
8184
agent,
8285
maxSteps: 5,
@@ -342,13 +345,25 @@ export default function Chat() {
342345
style={{ height: textareaHeight }}
343346
/>
344347
<div className="absolute bottom-0 right-0 p-2 w-fit flex flex-row justify-end">
345-
<button
346-
type="submit"
347-
className="inline-flex items-center cursor-pointer justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 bg-primary text-primary-foreground hover:bg-primary/90 rounded-full p-1.5 h-fit border border-neutral-200 dark:border-neutral-800"
348-
disabled={pendingToolCallConfirmation || !agentInput.trim()}
349-
>
350-
<PaperPlaneTilt size={16} />
351-
</button>
348+
{isLoading ? (
349+
<button
350+
type="button"
351+
onClick={stop}
352+
className="inline-flex items-center cursor-pointer justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 bg-primary text-primary-foreground hover:bg-primary/90 rounded-full p-1.5 h-fit border border-neutral-200 dark:border-neutral-800"
353+
aria-label="Stop generation"
354+
>
355+
<Stop size={16} />
356+
</button>
357+
) : (
358+
<button
359+
type="submit"
360+
className="inline-flex items-center cursor-pointer justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 bg-primary text-primary-foreground hover:bg-primary/90 rounded-full p-1.5 h-fit border border-neutral-200 dark:border-neutral-800"
361+
disabled={pendingToolCallConfirmation || !agentInput.trim()}
362+
aria-label="Send message"
363+
>
364+
<PaperPlaneTilt size={16} />
365+
</button>
366+
)}
352367
</div>
353368
</div>
354369
</div>

0 commit comments

Comments
 (0)