mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
fix: Fix the human relay dialog function and optimize user interaction experience
This commit is contained in:
parent
3bb1d78c17
commit
38c09d09d6
5 changed files with 45 additions and 17 deletions
|
|
@ -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<string | undefined> {
|
||||
return new Promise<string | undefined>((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<string | undefi
|
|||
},
|
||||
)
|
||||
|
||||
// Show the WebView dialog
|
||||
vscode.commands.executeCommand("roo-code.showHumanRelayDialog", {
|
||||
requestId,
|
||||
promptText,
|
||||
})
|
||||
// 检查 panel 是否已经初始化
|
||||
if (!getPanel()) {
|
||||
// 如果 panel 不存在,首先打开一个新面板
|
||||
vscode.commands.executeCommand("roo-cline.openInNewTab").then(() => {
|
||||
// 等待面板创建完成后再显示人工中继对话框
|
||||
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<string | undefi
|
|||
)
|
||||
.then((selection) => {
|
||||
if (selection === "Use Input Box") {
|
||||
// Unregister the callback
|
||||
// 注销回调
|
||||
vscode.commands.executeCommand("roo-code.unregisterHumanRelayCallback", requestId)
|
||||
|
||||
vscode.window
|
||||
|
|
|
|||
|
|
@ -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", {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
</p>
|
||||
<p
|
||||
style={{
|
||||
|
|
@ -1326,8 +1327,9 @@ const ApiOptions = ({
|
|||
color: "var(--vscode-descriptionForeground)",
|
||||
lineHeight: "1.4",
|
||||
}}>
|
||||
在使用过程中,系统会弹出对话框,并自动复制当前消息到剪贴板。您需要将这些内容粘贴给网页版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.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue