Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 69 additions & 24 deletions webview-ui/src/components/chat/ChatTextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { forwardRef, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"
import { useEvent } from "react-use"
import DynamicTextArea from "react-textarea-autosize"
import { VolumeX, Image, WandSparkles, SendHorizontal, MessageSquareX } from "lucide-react"
import { VolumeX, Image, WandSparkles, SendHorizontal, MessageSquareX, ListEnd, Square } from "lucide-react"

import type { ExtensionMessage } from "@roo-code/types"

Expand Down Expand Up @@ -55,6 +55,10 @@ interface ChatTextAreaProps {
// Browser session status
isBrowserSessionActive?: boolean
showBrowserDockToggle?: boolean
// Stop/Queue functionality
isStreaming?: boolean
onStop?: () => void
onEnqueueMessage?: () => void
}

export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
Expand All @@ -77,6 +81,9 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
onCancel,
isBrowserSessionActive = false,
showBrowserDockToggle = false,
isStreaming = false,
onStop,
onEnqueueMessage,
},
ref,
) => {
Expand Down Expand Up @@ -1185,30 +1192,68 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
</button>
</StandardTooltip>
)}
<StandardTooltip
content={t("chat:pressToSend", { keyCombination: sendKeyCombination })}>
<button
aria-label={t("chat:pressToSend", { keyCombination: sendKeyCombination })}
disabled={false}
onClick={onSend}
className={cn(
"relative inline-flex items-center justify-center",
"bg-transparent border-none p-1.5",
"rounded-md min-w-[28px] min-h-[28px]",
"text-vscode-descriptionForeground hover:text-vscode-foreground",
"transition-all duration-200",
hasInputContent
? "opacity-100 hover:opacity-100 pointer-events-auto"
: "opacity-0 pointer-events-none",
hasInputContent &&
{/* Queue button - shown when streaming and user has typed content */}
{!isEditMode && isStreaming && hasInputContent && onEnqueueMessage && (
<StandardTooltip content={t("chat:enqueueMessage")}>
<button
aria-label={t("chat:enqueueMessage")}
disabled={false}
onClick={onEnqueueMessage}
className={cn(
"relative inline-flex items-center justify-center",
"bg-transparent border-none p-1.5",
"rounded-md min-w-[28px] min-h-[28px]",
"text-vscode-descriptionForeground hover:text-vscode-foreground",
"transition-all duration-200",
"opacity-100 hover:opacity-100 pointer-events-auto",
"hover:bg-[rgba(255,255,255,0.03)] hover:border-[rgba(255,255,255,0.15)]",
"focus:outline-none focus-visible:ring-1 focus-visible:ring-vscode-focusBorder",
hasInputContent && "active:bg-[rgba(255,255,255,0.1)]",
hasInputContent && "cursor-pointer",
)}>
<SendHorizontal className="w-4 h-4" />
</button>
</StandardTooltip>
"focus:outline-none focus-visible:ring-1 focus-visible:ring-vscode-focusBorder",
"active:bg-[rgba(255,255,255,0.1)]",
"cursor-pointer",
)}>
<ListEnd className="w-4 h-4" />
</button>
</StandardTooltip>
)}
{/* Send/Stop button - morphs based on streaming state */}
{!isEditMode && (
<StandardTooltip
content={
isStreaming
? t("chat:stop.title")
: t("chat:pressToSend", { keyCombination: sendKeyCombination })
}>
<button
aria-label={
isStreaming
? t("chat:stop.title")
: t("chat:pressToSend", { keyCombination: sendKeyCombination })
}
disabled={false}
onClick={isStreaming ? onStop : onSend}
className={cn(
"relative inline-flex items-center justify-center",
"bg-transparent border-none p-1.5",
"rounded-md min-w-[28px] min-h-[28px]",
"text-vscode-descriptionForeground hover:text-vscode-foreground",
"transition-all duration-200",
isStreaming || hasInputContent
? "opacity-100 hover:opacity-100 pointer-events-auto"
: "opacity-0 pointer-events-none",
(isStreaming || hasInputContent) &&
"hover:bg-[rgba(255,255,255,0.03)] hover:border-[rgba(255,255,255,0.15)]",
"focus:outline-none focus-visible:ring-1 focus-visible:ring-vscode-focusBorder",
(isStreaming || hasInputContent) && "active:bg-[rgba(255,255,255,0.1)]",
(isStreaming || hasInputContent) && "cursor-pointer",
)}>
{isStreaming ? (
<Square className="size-4 fill-vscode-descriptionForeground" />
) : (
<SendHorizontal className="size-4" />
)}
</button>
</StandardTooltip>
)}
</div>

{!inputValue && (
Expand Down
63 changes: 42 additions & 21 deletions webview-ui/src/components/chat/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
const [enableButtons, setEnableButtons] = useState<boolean>(false)
const [primaryButtonText, setPrimaryButtonText] = useState<string | undefined>(undefined)
const [secondaryButtonText, setSecondaryButtonText] = useState<string | undefined>(undefined)
const [didClickCancel, setDidClickCancel] = useState(false)
const [_didClickCancel, setDidClickCancel] = useState(false)
const virtuosoRef = useRef<VirtuosoHandle>(null)
const [expandedRows, setExpandedRows] = useState<Record<number, boolean>>({})
const prevExpandedRowsRef = useRef<Record<number, boolean>>()
Expand Down Expand Up @@ -661,6 +661,26 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro

const startNewTask = useCallback(() => vscode.postMessage({ type: "clearTask" }), [])

// Handle stop button click from textarea
const handleStopTask = useCallback(() => {
vscode.postMessage({ type: "cancelTask" })
setDidClickCancel(true)
}, [setDidClickCancel])

// Handle enqueue button click from textarea
const handleEnqueueCurrentMessage = useCallback(() => {
const text = inputValue.trim()
if (text || selectedImages.length > 0) {
vscode.postMessage({
type: "queueMessage",
text,
images: selectedImages,
})
setInputValue("")
setSelectedImages([])
}
}, [inputValue, selectedImages])

// This logic depends on the useEffect[messages] above to set clineAsk,
// after which buttons are shown and we then send an askResponse to the
// extension.
Expand Down Expand Up @@ -733,6 +753,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
setSendingDisabled(true)
setClineAsk(undefined)
setEnableButtons(false)
setPrimaryButtonText(undefined)
setSecondaryButtonText(undefined)
},
[clineAsk, startNewTask, currentTaskItem?.parentTaskId],
)
Expand Down Expand Up @@ -784,7 +806,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
setClineAsk(undefined)
setEnableButtons(false)
},
[clineAsk, startNewTask, isStreaming],
[clineAsk, startNewTask, isStreaming, setDidClickCancel],
)

const { info: model } = useSelectedModel(apiConfiguration)
Expand Down Expand Up @@ -1386,7 +1408,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
vscode.postMessage({ type: "condenseTaskContextRequest", text: taskId })
}

const areButtonsVisible = showScrollToBottom || primaryButtonText || secondaryButtonText || isStreaming
const areButtonsVisible = showScrollToBottom || primaryButtonText || secondaryButtonText

return (
<div
Expand Down Expand Up @@ -1489,11 +1511,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
{areButtonsVisible && (
<div
className={`flex h-9 items-center mb-1 px-[15px] ${
showScrollToBottom
? "opacity-100"
: enableButtons || (isStreaming && !didClickCancel)
? "opacity-100"
: "opacity-50"
showScrollToBottom ? "opacity-100" : enableButtons ? "opacity-100" : "opacity-50"
}`}>
{showScrollToBottom ? (
<StandardTooltip content={t("chat:scrollToBottom")}>
Expand All @@ -1513,7 +1531,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
</StandardTooltip>
) : (
<>
{primaryButtonText && !isStreaming && (
{primaryButtonText && (
<StandardTooltip
content={
primaryButtonText === t("chat:retry.title")
Expand Down Expand Up @@ -1545,25 +1563,25 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
</Button>
</StandardTooltip>
)}
{(secondaryButtonText || isStreaming) && (
{secondaryButtonText && (
<StandardTooltip
content={
isStreaming
? t("chat:cancel.tooltip")
: secondaryButtonText === t("chat:startNewTask.title")
? t("chat:startNewTask.tooltip")
: secondaryButtonText === t("chat:reject.title")
? t("chat:reject.tooltip")
: secondaryButtonText === t("chat:terminate.title")
? t("chat:terminate.tooltip")
secondaryButtonText === t("chat:startNewTask.title")
? t("chat:startNewTask.tooltip")
: secondaryButtonText === t("chat:reject.title")
? t("chat:reject.tooltip")
: secondaryButtonText === t("chat:terminate.title")
? t("chat:terminate.tooltip")
: secondaryButtonText === t("chat:killCommand.title")
? t("chat:killCommand.tooltip")
: undefined
}>
<Button
variant="secondary"
disabled={!enableButtons && !(isStreaming && !didClickCancel)}
className={isStreaming ? "flex-[2] ml-0" : "flex-1 ml-[6px]"}
disabled={!enableButtons}
className="flex-1 ml-[6px]"
onClick={() => handleSecondaryButtonClick(inputValue, selectedImages)}>
{isStreaming ? t("chat:cancel.title") : secondaryButtonText}
{secondaryButtonText}
</Button>
</StandardTooltip>
)}
Expand Down Expand Up @@ -1612,6 +1630,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
modeShortcutText={modeShortcutText}
isBrowserSessionActive={!!isBrowserSessionActive}
showBrowserDockToggle={showBrowserDockToggle}
isStreaming={isStreaming}
onStop={handleStopTask}
onEnqueueMessage={handleEnqueueCurrentMessage}
/>

{isProfileDisabled && (
Expand Down
5 changes: 5 additions & 0 deletions webview-ui/src/i18n/locales/ca/chat.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions webview-ui/src/i18n/locales/de/chat.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions webview-ui/src/i18n/locales/en/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
"reservedForResponse": "Reserved for model response: {{amount}} tokens"
},
"reject": {
"title": "Reject",
"tooltip": "Reject this action"
"title": "Deny",
"tooltip": "Prevent this action from occurring"
},
"completeSubtaskAndReturn": "Complete Subtask and Return",
"approve": {
"title": "Approve",
"tooltip": "Approve this action"
"tooltip": "Allow this action to happen"
},
"read-batch": {
"approve": {
Expand All @@ -75,25 +75,30 @@
"tooltip": "Execute this command"
},
"proceedWhileRunning": {
"title": "Proceed While Running",
"tooltip": "Continue despite warnings"
"title": "Continue While Running",
"tooltip": "Keep going despite warnings"
},
"killCommand": {
"title": "Kill Command",
"tooltip": "Kill the current command"
},
"resumeTask": {
"title": "Resume Task",
"tooltip": "Continue the current task"
"title": "Continue",
"tooltip": "Resume the current task"
},
"terminate": {
"title": "Terminate",
"tooltip": "End the current task"
"title": "New task",
"tooltip": "Start a new task"
},
"cancel": {
"title": "Cancel",
"tooltip": "Cancel the current operation"
},
"stop": {
"title": "Stop",
"tooltip": "Stop the current task"
},
"enqueueMessage": "Add message to queue (will be sent after current task completes)",
"editMessage": {
"placeholder": "Edit your message..."
},
Expand Down
5 changes: 5 additions & 0 deletions webview-ui/src/i18n/locales/es/chat.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions webview-ui/src/i18n/locales/fr/chat.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions webview-ui/src/i18n/locales/hi/chat.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading