Skip to content

Commit 38c09d0

Browse files
committed
fix: Fix the human relay dialog function and optimize user interaction experience
1 parent 3bb1d78 commit 38c09d0

File tree

5 files changed

+45
-17
lines changed

5 files changed

+45
-17
lines changed

src/api/providers/human-relay.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ApiHandler, SingleCompletionHandler } from "../index"
55
import { ApiStream } from "../transform/stream"
66
import * as vscode from "vscode"
77
import { ExtensionMessage } from "../../shared/ExtensionMessage"
8+
import { getPanel } from "../../activate/registerCommands" // 导入 getPanel 函数
89

910
/**
1011
* Human Relay API processor
@@ -114,10 +115,10 @@ function getMessageContent(message: Anthropic.Messages.MessageParam): string {
114115
*/
115116
async function showHumanRelayDialog(promptText: string): Promise<string | undefined> {
116117
return new Promise<string | undefined>((resolve) => {
117-
// Create a unique request ID
118+
// 创建一个唯一的请求 ID
118119
const requestId = Date.now().toString()
119120

120-
// Register callback to the global callback map
121+
// 注册全局回调函数
121122
vscode.commands.executeCommand(
122123
"roo-code.registerHumanRelayCallback",
123124
requestId,
@@ -126,13 +127,27 @@ async function showHumanRelayDialog(promptText: string): Promise<string | undefi
126127
},
127128
)
128129

129-
// Show the WebView dialog
130-
vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
131-
requestId,
132-
promptText,
133-
})
130+
// 检查 panel 是否已经初始化
131+
if (!getPanel()) {
132+
// 如果 panel 不存在,首先打开一个新面板
133+
vscode.commands.executeCommand("roo-cline.openInNewTab").then(() => {
134+
// 等待面板创建完成后再显示人工中继对话框
135+
setTimeout(() => {
136+
vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
137+
requestId,
138+
promptText,
139+
})
140+
}, 500) // 给面板创建留出一点时间
141+
})
142+
} else {
143+
// 如果 panel 已存在,直接显示对话框
144+
vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
145+
requestId,
146+
promptText,
147+
})
148+
}
134149

135-
// Provide a temporary UI in case the WebView fails to load
150+
// 提供临时 UI,以防 WebView 加载失败
136151
vscode.window
137152
.showInformationMessage(
138153
"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<string | undefi
144159
)
145160
.then((selection) => {
146161
if (selection === "Use Input Box") {
147-
// Unregister the callback
162+
// 注销回调
148163
vscode.commands.executeCommand("roo-code.unregisterHumanRelayCallback", requestId)
149164

150165
vscode.window

src/core/webview/ClineProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,8 +1522,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
15221522
// Switch back to default mode after deletion
15231523
await this.updateGlobalState("mode", defaultModeSlug)
15241524
await this.postStateToWebview()
1525-
break
15261525
}
1526+
break
15271527
case "humanRelayResponse":
15281528
if (message.requestId && message.text) {
15291529
vscode.commands.executeCommand("roo-code.handleHumanRelayResponse", {

src/extension.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ export function activate(context: vscode.ExtensionContext) {
5757

5858
registerCommands({ context, outputChannel, provider: sidebarProvider })
5959

60+
// Register human relay callback registration command
61+
context.subscriptions.push(
62+
vscode.commands.registerCommand(
63+
"roo-code.registerHumanRelayCallback",
64+
(requestId: string, callback: (response: string | undefined) => void) => {
65+
registerHumanRelayCallback(requestId, callback)
66+
},
67+
),
68+
)
69+
6070
// Register human relay response processing command
6171
context.subscriptions.push(
6272
vscode.commands.registerCommand(

src/shared/WebviewMessage.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export interface WebviewMessage {
9494
| "checkpointRestore"
9595
| "deleteMcpServer"
9696
| "maxOpenTabsContext"
97-
| "HumanRelayResponseMessage"
98-
| "HumanRelayCancelMessage"
97+
| "humanRelayResponse"
98+
| "humanRelayCancel"
9999
text?: string
100100
disabled?: boolean
101101
askResponse?: ClineAskResponse
@@ -119,16 +119,17 @@ export interface WebviewMessage {
119119
timeout?: number
120120
payload?: WebViewMessagePayload
121121
source?: "global" | "project"
122+
requestId?: string
122123
}
123124

124125
// Human relay related message types
125-
export interface HumanRelayResponseMessage {
126+
export interface HumanRelayResponseMessage extends WebviewMessage {
126127
type: "humanRelayResponse"
127128
requestId: string
128129
text: string
129130
}
130131

131-
export interface HumanRelayCancelMessage {
132+
export interface HumanRelayCancelMessage extends WebviewMessage {
132133
type: "humanRelayCancel"
133134
requestId: string
134135
}

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,8 @@ const ApiOptions = ({
13171317
color: "var(--vscode-descriptionForeground)",
13181318
lineHeight: "1.4",
13191319
}}>
1320-
不需要API key,但需要用户协助复制粘贴信息给web的聊天AI。
1320+
The API key is not required, but the user needs to help copy and paste the information to the
1321+
web chat AI.
13211322
</p>
13221323
<p
13231324
style={{
@@ -1326,8 +1327,9 @@ const ApiOptions = ({
13261327
color: "var(--vscode-descriptionForeground)",
13271328
lineHeight: "1.4",
13281329
}}>
1329-
在使用过程中,系统会弹出对话框,并自动复制当前消息到剪贴板。您需要将这些内容粘贴给网页版AI(如ChatGPT或Claude),
1330-
然后将AI的回复复制回对话框中点击确认按钮。
1330+
During use, a dialog box will pop up and the current message will be copied to the clipboard
1331+
automatically. You need to paste these to web versions of AI (such as ChatGPT or Claude),Then
1332+
copy the AI's reply back to the dialog box and click the confirm button.
13311333
</p>
13321334
</div>
13331335
)}

0 commit comments

Comments
 (0)