+ )}
+
{selectedProvider === "openrouter" && (
Date: Fri, 28 Feb 2025 10:54:25 +0800
Subject: [PATCH 02/10] fix: Fix the human relay dialog function and optimize
user interaction experience
---
src/api/providers/human-relay.ts | 33 ++++++++++++++-----
src/core/webview/ClineProvider.ts | 2 +-
src/extension.ts | 10 ++++++
src/shared/WebviewMessage.ts | 9 ++---
.../src/components/settings/ApiOptions.tsx | 8 +++--
5 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/src/api/providers/human-relay.ts b/src/api/providers/human-relay.ts
index 8454a7c9af..85292a27dc 100644
--- a/src/api/providers/human-relay.ts
+++ b/src/api/providers/human-relay.ts
@@ -5,6 +5,7 @@ import { ApiHandler, SingleCompletionHandler } from "../index"
import { ApiStream } from "../transform/stream"
import * as vscode from "vscode"
import { ExtensionMessage } from "../../shared/ExtensionMessage"
+import { getPanel } from "../../activate/registerCommands" // 导入 getPanel 函数
/**
* Human Relay API processor
@@ -114,10 +115,10 @@ function getMessageContent(message: Anthropic.Messages.MessageParam): string {
*/
async function showHumanRelayDialog(promptText: string): Promise {
return new Promise((resolve) => {
- // Create a unique request ID
+ // 创建一个唯一的请求 ID
const requestId = Date.now().toString()
- // Register callback to the global callback map
+ // 注册全局回调函数
vscode.commands.executeCommand(
"roo-code.registerHumanRelayCallback",
requestId,
@@ -126,13 +127,27 @@ async function showHumanRelayDialog(promptText: string): Promise {
+ // 等待面板创建完成后再显示人工中继对话框
+ setTimeout(() => {
+ vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
+ requestId,
+ promptText,
+ })
+ }, 500) // 给面板创建留出一点时间
+ })
+ } else {
+ // 如果 panel 已存在,直接显示对话框
+ vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
+ requestId,
+ promptText,
+ })
+ }
- // Provide a temporary UI in case the WebView fails to load
+ // 提供临时 UI,以防 WebView 加载失败
vscode.window
.showInformationMessage(
"Please paste the copied message to the AI, then copy the response back into the dialog",
@@ -144,7 +159,7 @@ async function showHumanRelayDialog(promptText: string): Promise {
if (selection === "Use Input Box") {
- // Unregister the callback
+ // 注销回调
vscode.commands.executeCommand("roo-code.unregisterHumanRelayCallback", requestId)
vscode.window
diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts
index 1c2ffea550..e781a36dbe 100644
--- a/src/core/webview/ClineProvider.ts
+++ b/src/core/webview/ClineProvider.ts
@@ -1522,8 +1522,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
// Switch back to default mode after deletion
await this.updateGlobalState("mode", defaultModeSlug)
await this.postStateToWebview()
- break
}
+ break
case "humanRelayResponse":
if (message.requestId && message.text) {
vscode.commands.executeCommand("roo-code.handleHumanRelayResponse", {
diff --git a/src/extension.ts b/src/extension.ts
index 3b148a41ac..87dc7405a3 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -57,6 +57,16 @@ export function activate(context: vscode.ExtensionContext) {
registerCommands({ context, outputChannel, provider: sidebarProvider })
+ // Register human relay callback registration command
+ context.subscriptions.push(
+ vscode.commands.registerCommand(
+ "roo-code.registerHumanRelayCallback",
+ (requestId: string, callback: (response: string | undefined) => void) => {
+ registerHumanRelayCallback(requestId, callback)
+ },
+ ),
+ )
+
// Register human relay response processing command
context.subscriptions.push(
vscode.commands.registerCommand(
diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts
index 2b0c68f7be..a45a727253 100644
--- a/src/shared/WebviewMessage.ts
+++ b/src/shared/WebviewMessage.ts
@@ -94,8 +94,8 @@ export interface WebviewMessage {
| "checkpointRestore"
| "deleteMcpServer"
| "maxOpenTabsContext"
- | "HumanRelayResponseMessage"
- | "HumanRelayCancelMessage"
+ | "humanRelayResponse"
+ | "humanRelayCancel"
text?: string
disabled?: boolean
askResponse?: ClineAskResponse
@@ -119,16 +119,17 @@ export interface WebviewMessage {
timeout?: number
payload?: WebViewMessagePayload
source?: "global" | "project"
+ requestId?: string
}
// Human relay related message types
-export interface HumanRelayResponseMessage {
+export interface HumanRelayResponseMessage extends WebviewMessage {
type: "humanRelayResponse"
requestId: string
text: string
}
-export interface HumanRelayCancelMessage {
+export interface HumanRelayCancelMessage extends WebviewMessage {
type: "humanRelayCancel"
requestId: string
}
diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx
index c8598ec101..b125014a62 100644
--- a/webview-ui/src/components/settings/ApiOptions.tsx
+++ b/webview-ui/src/components/settings/ApiOptions.tsx
@@ -1317,7 +1317,8 @@ const ApiOptions = ({
color: "var(--vscode-descriptionForeground)",
lineHeight: "1.4",
}}>
- 不需要API key,但需要用户协助复制粘贴信息给web的聊天AI。
+ The API key is not required, but the user needs to help copy and paste the information to the
+ web chat AI.
- 在使用过程中,系统会弹出对话框,并自动复制当前消息到剪贴板。您需要将这些内容粘贴给网页版AI(如ChatGPT或Claude),
- 然后将AI的回复复制回对话框中点击确认按钮。
+ During use, a dialog box will pop up and the current message will be copied to the clipboard
+ automatically. You need to paste these to web versions of AI (such as ChatGPT or Claude),Then
+ copy the AI's reply back to the dialog box and click the confirm button.
)}
From 1ae4eaa80ebc3f8bc91f669acda4c74b5fd1520f Mon Sep 17 00:00:00 2001
From: Felix NyxJae <18661811993@163.com>
Date: Fri, 28 Feb 2025 11:42:45 +0800
Subject: [PATCH 03/10] fix: Update comments to the human relay
---
src/api/providers/human-relay.ts | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/api/providers/human-relay.ts b/src/api/providers/human-relay.ts
index 85292a27dc..2911e24eaf 100644
--- a/src/api/providers/human-relay.ts
+++ b/src/api/providers/human-relay.ts
@@ -5,7 +5,7 @@ import { ApiHandler, SingleCompletionHandler } from "../index"
import { ApiStream } from "../transform/stream"
import * as vscode from "vscode"
import { ExtensionMessage } from "../../shared/ExtensionMessage"
-import { getPanel } from "../../activate/registerCommands" // 导入 getPanel 函数
+import { getPanel } from "../../activate/registerCommands" // Import the getPanel function
/**
* Human Relay API processor
@@ -115,10 +115,10 @@ function getMessageContent(message: Anthropic.Messages.MessageParam): string {
*/
async function showHumanRelayDialog(promptText: string): Promise {
return new Promise((resolve) => {
- // 创建一个唯一的请求 ID
+ // Create a unique request ID
const requestId = Date.now().toString()
- // 注册全局回调函数
+ // Register a global callback function
vscode.commands.executeCommand(
"roo-code.registerHumanRelayCallback",
requestId,
@@ -127,27 +127,27 @@ async function showHumanRelayDialog(promptText: string): Promise {
- // 等待面板创建完成后再显示人工中继对话框
+ // Wait for the panel to be created before showing the human relay dialog
setTimeout(() => {
vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
requestId,
promptText,
})
- }, 500) // 给面板创建留出一点时间
+ }, 500) // Allow some time for the panel to be created
})
} else {
- // 如果 panel 已存在,直接显示对话框
+ // If the panel already exists, directly show the dialog
vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
requestId,
promptText,
})
}
- // 提供临时 UI,以防 WebView 加载失败
+ // Provide a temporary UI in case the WebView fails to load
vscode.window
.showInformationMessage(
"Please paste the copied message to the AI, then copy the response back into the dialog",
@@ -159,7 +159,7 @@ async function showHumanRelayDialog(promptText: string): Promise {
if (selection === "Use Input Box") {
- // 注销回调
+ // Unregister the callback
vscode.commands.executeCommand("roo-code.unregisterHumanRelayCallback", requestId)
vscode.window
From 156fe0d9fb74169e2bc9a4367708f4f963917cbf Mon Sep 17 00:00:00 2001
From: Felix NyxJae <18661811993@163.com>
Date: Fri, 28 Feb 2025 12:06:39 +0800
Subject: [PATCH 04/10] fix: Optimize panel management, support panel
references for sidebar and tab types
---
src/activate/registerCommands.ts | 37 ++++++++++----
src/api/providers/human-relay.ts | 51 ++-----------------
src/core/webview/ClineProvider.ts | 10 ++++
.../human-relay/HumanRelayDialog.tsx | 12 ++++-
4 files changed, 51 insertions(+), 59 deletions(-)
diff --git a/src/activate/registerCommands.ts b/src/activate/registerCommands.ts
index 8cc895f291..b520e0cb8e 100644
--- a/src/activate/registerCommands.ts
+++ b/src/activate/registerCommands.ts
@@ -3,17 +3,32 @@ import delay from "delay"
import { ClineProvider } from "../core/webview/ClineProvider"
-// Add a global variable to store panel references
-let panel: vscode.WebviewPanel | undefined = undefined
+// Store panel references in both modes
+let sidebarPanel: vscode.WebviewView | undefined = undefined
+let tabPanel: vscode.WebviewPanel | undefined = undefined
-// Get the panel function for command access
-export function getPanel(): vscode.WebviewPanel | undefined {
- return panel
+/**
+ * Get the currently active panel
+ * @returns WebviewPanel或WebviewView
+ */
+export function getPanel(): vscode.WebviewPanel | vscode.WebviewView | undefined {
+ return tabPanel || sidebarPanel
}
-// Setting the function of the panel
-export function setPanel(newPanel: vscode.WebviewPanel | undefined): void {
- panel = newPanel
+/**
+ * Set panel references
+ */
+export function setPanel(
+ newPanel: vscode.WebviewPanel | vscode.WebviewView | undefined,
+ type: "sidebar" | "tab",
+): void {
+ if (type === "sidebar") {
+ sidebarPanel = newPanel as vscode.WebviewView
+ tabPanel = undefined
+ } else {
+ tabPanel = newPanel as vscode.WebviewPanel
+ sidebarPanel = undefined
+ }
}
export type RegisterCommandOptions = {
@@ -100,8 +115,8 @@ const openClineInNewTab = async ({ context, outputChannel }: Omit {
- setPanel(undefined)
+ setPanel(undefined, "tab")
})
// Lock the editor group so clicking on files doesn't open them over the panel
diff --git a/src/api/providers/human-relay.ts b/src/api/providers/human-relay.ts
index 2911e24eaf..618ae847de 100644
--- a/src/api/providers/human-relay.ts
+++ b/src/api/providers/human-relay.ts
@@ -127,51 +127,10 @@ async function showHumanRelayDialog(promptText: string): Promise {
- // Wait for the panel to be created before showing the human relay dialog
- setTimeout(() => {
- vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
- requestId,
- promptText,
- })
- }, 500) // Allow some time for the panel to be created
- })
- } else {
- // If the panel already exists, directly show the dialog
- vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
- requestId,
- promptText,
- })
- }
-
- // Provide a temporary UI in case the WebView fails to load
- vscode.window
- .showInformationMessage(
- "Please paste the copied message to the AI, then copy the response back into the dialog",
- {
- modal: true,
- detail: "The message has been copied to the clipboard. If the dialog does not open, please try using the input box.",
- },
- "Use Input Box",
- )
- .then((selection) => {
- if (selection === "Use Input Box") {
- // Unregister the callback
- vscode.commands.executeCommand("roo-code.unregisterHumanRelayCallback", requestId)
-
- vscode.window
- .showInputBox({
- prompt: "Please paste the AI's response here",
- placeHolder: "Paste the AI's response here...",
- ignoreFocusOut: true,
- })
- .then((input) => {
- resolve(input || undefined)
- })
- }
- })
+ // Open the dialog box directly using the current panel
+ vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
+ requestId,
+ promptText,
+ })
})
}
diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts
index e781a36dbe..c87406d3d4 100644
--- a/src/core/webview/ClineProvider.ts
+++ b/src/core/webview/ClineProvider.ts
@@ -7,6 +7,7 @@ import pWaitFor from "p-wait-for"
import * as path from "path"
import * as vscode from "vscode"
import simpleGit from "simple-git"
+import { setPanel } from "../../activate/registerCommands"
import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api"
import { findLast } from "../../shared/array"
@@ -233,6 +234,15 @@ export class ClineProvider implements vscode.WebviewViewProvider {
this.outputChannel.appendLine("Resolving webview view")
this.view = webviewView
+ // Set panel reference according to webview type
+ if ("onDidChangeViewState" in webviewView) {
+ // Tag page type
+ setPanel(webviewView, "tab")
+ } else if ("onDidChangeVisibility" in webviewView) {
+ // Sidebar Type
+ setPanel(webviewView, "sidebar")
+ }
+
// Initialize sound enabled state
this.getState().then(({ soundEnabled }) => {
setSoundEnabled(soundEnabled ?? false)
diff --git a/webview-ui/src/components/human-relay/HumanRelayDialog.tsx b/webview-ui/src/components/human-relay/HumanRelayDialog.tsx
index ea306d11d7..61d4cbe213 100644
--- a/webview-ui/src/components/human-relay/HumanRelayDialog.tsx
+++ b/webview-ui/src/components/human-relay/HumanRelayDialog.tsx
@@ -27,12 +27,20 @@ export const HumanRelayDialog: React.FC = ({
onCancel,
}) => {
const [response, setResponse] = React.useState("")
- const { onCopy } = useClipboard(promptText)
+ const { copy } = useClipboard()
const [isCopyClicked, setIsCopyClicked] = React.useState(false)
+ // Listen to isOpen changes, clear the input box when the dialog box is opened
+ React.useEffect(() => {
+ if (isOpen) {
+ setResponse("")
+ setIsCopyClicked(false)
+ }
+ }, [isOpen])
+
// Copy to clipboard and show a success message
const handleCopy = () => {
- onCopy()
+ copy(promptText)
setIsCopyClicked(true)
setTimeout(() => {
setIsCopyClicked(false)
From db65520adb862e52a8e0f30ecb7e003e3e878959 Mon Sep 17 00:00:00 2001
From: Felix NyxJae <18661811993@163.com>
Date: Fri, 28 Feb 2025 12:32:06 +0800
Subject: [PATCH 05/10] fix: Fixed human relay dialog message processing,
optimized type use
---
webview-ui/src/App.tsx | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/webview-ui/src/App.tsx b/webview-ui/src/App.tsx
index 5909a3eaef..8c37236adb 100644
--- a/webview-ui/src/App.tsx
+++ b/webview-ui/src/App.tsx
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from "react"
import { useEvent } from "react-use"
import { ExtensionMessage } from "../../src/shared/ExtensionMessage"
+import { ShowHumanRelayDialogMessage } from "../../src/shared/ExtensionMessage"
import { vscode } from "./utils/vscode"
import { ExtensionStateContextProvider, useExtensionState } from "./context/ExtensionStateContext"
@@ -59,13 +60,13 @@ const App = () => {
switchTab(newTab)
}
}
-
+ const mes: ShowHumanRelayDialogMessage = message as ShowHumanRelayDialogMessage
// Processing displays human relay dialog messages
- if (message.type === "showHumanRelayDialog" && message.requestId && message.promptText) {
+ if (mes.type === "showHumanRelayDialog" && mes.requestId && mes.promptText) {
setHumanRelayDialogState({
isOpen: true,
- requestId: message.requestId,
- promptText: message.promptText,
+ requestId: mes.requestId,
+ promptText: mes.promptText,
})
}
},
From aceeb0b5c5fd20cc2bb90f08e2dd66d12e584b06 Mon Sep 17 00:00:00 2001
From: Felix NyxJae <18661811993@163.com>
Date: Fri, 28 Feb 2025 14:53:54 +0800
Subject: [PATCH 06/10] chore: Restore .gitignore, remove unnecessary file
rules
---
.gitignore | 5 -----
1 file changed, 5 deletions(-)
diff --git a/.gitignore b/.gitignore
index bdae7b5b26..211d06aa19 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,8 +28,3 @@ docs/_site/
#Logging
logs
-.clinerules-architect
-.clinerules-ask
-.clinerules-code
-MemoryBank
-.github/copilot-instructions.md
From ee7650cd0f83a32d6ea733a92112445feaae2923 Mon Sep 17 00:00:00 2001
From: Felix NyxJae <18661811993@163.com>
Date: Mon, 3 Mar 2025 12:07:00 +0800
Subject: [PATCH 07/10] Merged temp-branch into origin/human-relay and resolved
conflicts
---
src/api/providers/human-relay.ts | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/api/providers/human-relay.ts b/src/api/providers/human-relay.ts
index 618ae847de..4700208cda 100644
--- a/src/api/providers/human-relay.ts
+++ b/src/api/providers/human-relay.ts
@@ -17,6 +17,10 @@ export class HumanRelayHandler implements ApiHandler, SingleCompletionHandler {
constructor(options: ApiHandlerOptions) {
this.options = options
}
+ async countTokens(content: Array): Promise {
+ // Count the number of tokens in the content blocks
+ return 0
+ }
/**
* Create a message processing flow, display a dialog box to request human assistance
From b47de72cec5891a1b1162ffeefa69fc74ef08ead Mon Sep 17 00:00:00 2001
From: Felix NyxJae <18661811993@163.com>
Date: Mon, 3 Mar 2025 12:11:43 +0800
Subject: [PATCH 08/10] Add countTokens method to HumanRelayHandler class in
human-relay.ts
---
src/api/providers/human-relay.ts | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/api/providers/human-relay.ts b/src/api/providers/human-relay.ts
index 618ae847de..90a82b9bfe 100644
--- a/src/api/providers/human-relay.ts
+++ b/src/api/providers/human-relay.ts
@@ -17,6 +17,9 @@ export class HumanRelayHandler implements ApiHandler, SingleCompletionHandler {
constructor(options: ApiHandlerOptions) {
this.options = options
}
+ countTokens(content: Array): Promise {
+ return Promise.resolve(0)
+ }
/**
* Create a message processing flow, display a dialog box to request human assistance
From e4fb0081b1c78943c63dd0a4dc00bf95fb3f937c Mon Sep 17 00:00:00 2001
From: Matt Rubens
Date: Wed, 5 Mar 2025 10:39:36 -0500
Subject: [PATCH 09/10] Update commands to roo-cline to be consistent with
others
---
src/activate/registerCommands.ts | 2 +-
src/api/providers/human-relay.ts | 4 ++--
src/core/webview/ClineProvider.ts | 4 ++--
src/extension.ts | 6 +++---
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/activate/registerCommands.ts b/src/activate/registerCommands.ts
index b520e0cb8e..4aeb87168c 100644
--- a/src/activate/registerCommands.ts
+++ b/src/activate/registerCommands.ts
@@ -47,7 +47,7 @@ export const registerCommands = (options: RegisterCommandOptions) => {
// Human Relay Dialog Command
context.subscriptions.push(
vscode.commands.registerCommand(
- "roo-code.showHumanRelayDialog",
+ "roo-cline.showHumanRelayDialog",
(params: { requestId: string; promptText: string }) => {
if (getPanel()) {
getPanel()?.webview.postMessage({
diff --git a/src/api/providers/human-relay.ts b/src/api/providers/human-relay.ts
index 90a82b9bfe..b8bd4c2829 100644
--- a/src/api/providers/human-relay.ts
+++ b/src/api/providers/human-relay.ts
@@ -123,7 +123,7 @@ async function showHumanRelayDialog(promptText: string): Promise {
resolve(response)
@@ -131,7 +131,7 @@ async function showHumanRelayDialog(promptText: string): Promise void) => {
registerHumanRelayCallback(requestId, callback)
},
@@ -70,7 +70,7 @@ export function activate(context: vscode.ExtensionContext) {
// Register human relay response processing command
context.subscriptions.push(
vscode.commands.registerCommand(
- "roo-code.handleHumanRelayResponse",
+ "roo-cline.handleHumanRelayResponse",
(response: { requestId: string; text?: string; cancelled?: boolean }) => {
const callback = humanRelayCallbacks.get(response.requestId)
if (callback) {
@@ -86,7 +86,7 @@ export function activate(context: vscode.ExtensionContext) {
)
context.subscriptions.push(
- vscode.commands.registerCommand("roo-code.unregisterHumanRelayCallback", (requestId: string) => {
+ vscode.commands.registerCommand("roo-cline.unregisterHumanRelayCallback", (requestId: string) => {
humanRelayCallbacks.delete(requestId)
}),
)
From f4441e31e18fa50f9f7b1ab747d65d91b38cf37e Mon Sep 17 00:00:00 2001
From: Matt Rubens
Date: Wed, 5 Mar 2025 11:06:54 -0500
Subject: [PATCH 10/10] Update
webview-ui/src/components/settings/ApiOptions.tsx
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
---
webview-ui/src/components/settings/ApiOptions.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx
index ee21a136a7..d38ef752a6 100644
--- a/webview-ui/src/components/settings/ApiOptions.tsx
+++ b/webview-ui/src/components/settings/ApiOptions.tsx
@@ -1399,7 +1399,7 @@ const ApiOptions = ({
lineHeight: "1.4",
}}>
During use, a dialog box will pop up and the current message will be copied to the clipboard
- automatically. You need to paste these to web versions of AI (such as ChatGPT or Claude),Then
+ automatically. You need to paste these to web versions of AI (such as ChatGPT or Claude), then
copy the AI's reply back to the dialog box and click the confirm button.