Browse Source

feat: Add 'roo.acceptInput' command (#2598)

* feat: Add 'roo.acceptInput' command

* Update package.nls.json

* Update translations

---------

Co-authored-by: Matt Rubens <[email protected]>
Aleksandr Kirillov 8 months ago
parent
commit
1cca4f47c7

+ 5 - 0
package.json

@@ -179,6 +179,11 @@
 				"command": "roo-cline.focusInput",
 				"title": "%command.focusInput.title%",
 				"category": "%extension.displayName%"
+			},
+			{
+				"command": "roo.acceptInput",
+				"title": "%command.acceptInput.title%",
+				"category": "%extension.displayName%"
 			}
 		],
 		"menus": {

+ 1 - 0
package.nls.ca.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "Explicar Aquesta Ordre",
 	"command.terminal.fixCommandInCurrentTask.title": "Corregir Aquesta Ordre (Tasca Actual)",
 	"command.terminal.explainCommandInCurrentTask.title": "Explicar Aquesta Ordre (Tasca Actual)",
+	"command.acceptInput.title": "Acceptar Entrada/Suggeriment",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.de.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "Diesen Befehl Erklären",
 	"command.terminal.fixCommandInCurrentTask.title": "Diesen Befehl Reparieren (Aktuelle Aufgabe)",
 	"command.terminal.explainCommandInCurrentTask.title": "Diesen Befehl Erklären (Aktuelle Aufgabe)",
+	"command.acceptInput.title": "Eingabe/Vorschlag Akzeptieren",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.es.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "Explicar Este Comando",
 	"command.terminal.fixCommandInCurrentTask.title": "Corregir Este Comando (Tarea Actual)",
 	"command.terminal.explainCommandInCurrentTask.title": "Explicar Este Comando (Tarea Actual)",
+	"command.acceptInput.title": "Aceptar Entrada/Sugerencia",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.fr.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "Expliquer cette Commande",
 	"command.terminal.fixCommandInCurrentTask.title": "Corriger cette Commande (Tâche Actuelle)",
 	"command.terminal.explainCommandInCurrentTask.title": "Expliquer cette Commande (Tâche Actuelle)",
+	"command.acceptInput.title": "Accepter l'Entrée/Suggestion",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.hi.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "यह कमांड समझाएं",
 	"command.terminal.fixCommandInCurrentTask.title": "यह कमांड ठीक करें (वर्तमान कार्य)",
 	"command.terminal.explainCommandInCurrentTask.title": "यह कमांड समझाएं (वर्तमान कार्य)",
+	"command.acceptInput.title": "इनपुट/सुझाव स्वीकारें",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.it.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "Spiega Questo Comando",
 	"command.terminal.fixCommandInCurrentTask.title": "Correggi Questo Comando (Task Corrente)",
 	"command.terminal.explainCommandInCurrentTask.title": "Spiega Questo Comando (Task Corrente)",
+	"command.acceptInput.title": "Accetta Input/Suggerimento",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.ja.json

@@ -23,6 +23,7 @@
 	"command.terminal.explainCommand.title": "このコマンドを説明",
 	"command.terminal.fixCommandInCurrentTask.title": "このコマンドを修正(現在のタスク)",
 	"command.terminal.explainCommandInCurrentTask.title": "このコマンドを説明(現在のタスク)",
+	"command.acceptInput.title": "入力/提案を承認",
 	"configuration.title": "Roo Code",
 	"commands.allowedCommands.description": "'常に実行操作を承認する'が有効な場合に自動実行できるコマンド",
 	"settings.vsCodeLmModelSelector.description": "VSCode 言語モデル API の設定",

+ 1 - 0
package.nls.json

@@ -23,6 +23,7 @@
 	"command.terminal.explainCommand.title": "Explain This Command",
 	"command.terminal.fixCommandInCurrentTask.title": "Fix This Command (Current Task)",
 	"command.terminal.explainCommandInCurrentTask.title": "Explain This Command (Current Task)",
+	"command.acceptInput.title": "Accept Input/Suggestion",
 	"configuration.title": "Roo Code",
 	"commands.allowedCommands.description": "Commands that can be auto-executed when 'Always approve execute operations' is enabled",
 	"settings.vsCodeLmModelSelector.description": "Settings for VSCode Language Model API",

+ 1 - 0
package.nls.ko.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "이 명령어 설명",
 	"command.terminal.fixCommandInCurrentTask.title": "이 명령어 수정 (현재 작업)",
 	"command.terminal.explainCommandInCurrentTask.title": "이 명령어 설명 (현재 작업)",
+	"command.acceptInput.title": "입력/제안 수락",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.pl.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "Wyjaśnij tę Komendę",
 	"command.terminal.fixCommandInCurrentTask.title": "Napraw tę Komendę (Bieżące Zadanie)",
 	"command.terminal.explainCommandInCurrentTask.title": "Wyjaśnij tę Komendę (Bieżące Zadanie)",
+	"command.acceptInput.title": "Akceptuj Wprowadzanie/Sugestię",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.pt-BR.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "Explicar Este Comando",
 	"command.terminal.fixCommandInCurrentTask.title": "Corrigir Este Comando (Tarefa Atual)",
 	"command.terminal.explainCommandInCurrentTask.title": "Explicar Este Comando (Tarefa Atual)",
+	"command.acceptInput.title": "Aceitar Entrada/Sugestão",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.tr.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "Bu Komutu Açıkla",
 	"command.terminal.fixCommandInCurrentTask.title": "Bu Komutu Düzelt (Mevcut Görev)",
 	"command.terminal.explainCommandInCurrentTask.title": "Bu Komutu Açıkla (Mevcut Görev)",
+	"command.acceptInput.title": "Girişi/Öneriyi Kabul Et",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.vi.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "Giải Thích Lệnh Này",
 	"command.terminal.fixCommandInCurrentTask.title": "Sửa Lệnh Này (Tác Vụ Hiện Tại)",
 	"command.terminal.explainCommandInCurrentTask.title": "Giải Thích Lệnh Này (Tác Vụ Hiện Tại)",
+	"command.acceptInput.title": "Chấp Nhận Đầu Vào/Gợi Ý",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.zh-CN.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "解释此命令",
 	"command.terminal.fixCommandInCurrentTask.title": "修复此命令(当前任务)",
 	"command.terminal.explainCommandInCurrentTask.title": "解释此命令(当前任务)",
+	"command.acceptInput.title": "接受输入/建议",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 1 - 0
package.nls.zh-TW.json

@@ -14,6 +14,7 @@
 	"command.terminal.explainCommand.title": "解釋此命令",
 	"command.terminal.fixCommandInCurrentTask.title": "修復此命令(當前任務)",
 	"command.terminal.explainCommandInCurrentTask.title": "解釋此命令(當前任務)",
+	"command.acceptInput.title": "接受輸入/建議",
 	"views.activitybar.title": "Roo Code",
 	"views.contextMenu.label": "Roo Code",
 	"views.terminalMenu.label": "Roo Code",

+ 5 - 0
src/activate/registerCommands.ts

@@ -117,6 +117,11 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
 		"roo-cline.focusInput": () => {
 			provider.postMessageToWebview({ type: "action", action: "focusInput" })
 		},
+		"roo.acceptInput": () => {
+			const visibleProvider = getVisibleProviderOrLog(outputChannel)
+			if (!visibleProvider) return
+			visibleProvider.postMessageToWebview({ type: "acceptInput" })
+		},
 	}
 }
 

+ 1 - 0
src/shared/ExtensionMessage.ts

@@ -68,6 +68,7 @@ export interface ExtensionMessage {
 		| "maxReadFileLine"
 		| "fileSearchResults"
 		| "toggleApiConfigPin"
+		| "acceptInput"
 	text?: string
 	action?:
 		| "chatButtonClicked"

+ 7 - 1
webview-ui/src/App.tsx

@@ -8,7 +8,7 @@ import TranslationProvider from "./i18n/TranslationContext"
 import { vscode } from "./utils/vscode"
 import { telemetryClient } from "./utils/TelemetryClient"
 import { ExtensionStateContextProvider, useExtensionState } from "./context/ExtensionStateContext"
-import ChatView from "./components/chat/ChatView"
+import ChatView, { ChatViewRef } from "./components/chat/ChatView"
 import HistoryView from "./components/history/HistoryView"
 import SettingsView, { SettingsViewRef } from "./components/settings/SettingsView"
 import WelcomeView from "./components/welcome/WelcomeView"
@@ -44,6 +44,7 @@ const App = () => {
 	})
 
 	const settingsRef = useRef<SettingsViewRef>(null)
+	const chatViewRef = useRef<ChatViewRef>(null)
 
 	const switchTab = useCallback((newTab: Tab) => {
 		setCurrentSection(undefined)
@@ -75,6 +76,10 @@ const App = () => {
 				const { requestId, promptText } = message
 				setHumanRelayDialogState({ isOpen: true, requestId, promptText })
 			}
+
+			if (message.type === "acceptInput") {
+				chatViewRef.current?.acceptInput()
+			}
 		},
 		[switchTab],
 	)
@@ -114,6 +119,7 @@ const App = () => {
 				<SettingsView ref={settingsRef} onDone={() => setTab("chat")} targetSection={currentSection} />
 			)}
 			<ChatView
+				ref={chatViewRef}
 				isHidden={tab !== "chat"}
 				showAnnouncement={showAnnouncement}
 				hideAnnouncement={() => setShowAnnouncement(false)}

+ 21 - 2
webview-ui/src/components/chat/ChatView.tsx

@@ -1,6 +1,6 @@
 import { VSCodeButton, VSCodeLink } from "@vscode/webview-ui-toolkit/react"
 import debounce from "debounce"
-import { useCallback, useEffect, useMemo, useRef, useState } from "react"
+import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react"
 import { useDeepCompareEffect, useEvent, useMount } from "react-use"
 import { Virtuoso, type VirtuosoHandle } from "react-virtuoso"
 import styled from "styled-components"
@@ -40,11 +40,18 @@ interface ChatViewProps {
 	showHistoryView: () => void
 }
 
+export interface ChatViewRef {
+	acceptInput: () => void
+}
+
 export const MAX_IMAGES_PER_MESSAGE = 20 // Anthropic limits to 20 images
 
 const isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0
 
-const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryView }: ChatViewProps) => {
+const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewProps> = (
+	{ isHidden, showAnnouncement, hideAnnouncement, showHistoryView },
+	ref,
+) => {
 	const { t } = useAppTranslation()
 	const modeShortcutText = `${isMac ? "⌘" : "Ctrl"} + . ${t("chat:forNextMode")}`
 	const {
@@ -1162,6 +1169,16 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
 		}
 	}, [handleKeyDown])
 
+	useImperativeHandle(ref, () => ({
+		acceptInput: () => {
+			if (enableButtons && primaryButtonText) {
+				handlePrimaryButtonClick(inputValue, selectedImages)
+			} else if (!textAreaDisabled && (inputValue.trim() || selectedImages.length > 0)) {
+				handleSendMessage(inputValue, selectedImages)
+			}
+		},
+	}))
+
 	return (
 		<div
 			style={{
@@ -1386,6 +1403,8 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
 	)
 }
 
+const ChatView = forwardRef(ChatViewComponent)
+
 const ScrollToBottomButton = styled.div`
 	background-color: color-mix(in srgb, var(--vscode-toolbar-hoverBackground) 55%, transparent);
 	border-radius: 3px;