@@ -5,6 +5,7 @@ import { ApiHandler, SingleCompletionHandler } from "../index"
55import { ApiStream } from "../transform/stream"
66import * as vscode from "vscode"
77import { 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 */
115116async 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
0 commit comments