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.
)}