@@ -5,6 +5,7 @@ import { execa } from "execa"
55import { Logger } from "@services/logging/Logger"
66import { WebviewProvider } from "@core/webview"
77import { AutoApprovalSettings } from "@shared/AutoApprovalSettings"
8+ import { TaskServiceClient } from "webview-ui/src/services/grpc-client"
89import {
910 getWorkspacePath ,
1011 validateWorkspacePath ,
@@ -15,7 +16,6 @@ import {
1516import { updateGlobalState , getAllExtensionState , updateApiConfiguration , storeSecret } from "@core/storage/state"
1617import { ClineAsk , ExtensionMessage } from "@shared/ExtensionMessage"
1718import { ApiProvider } from "@shared/api"
18- import { WebviewMessage } from "@shared/WebviewMessage"
1919import { HistoryItem } from "@shared/HistoryItem"
2020import { getSavedClineMessages , getSavedApiConversationHistory } from "@core/storage/disk"
2121
@@ -515,8 +515,8 @@ export function createMessageCatcher(webviewProvider: WebviewProvider): vscode.D
515515 const askText = message . partialMessage . text
516516
517517 // Automatically respond to different types of asks
518- setTimeout ( ( ) => {
519- autoRespondToAsk ( webviewProvider , askType , askText )
518+ setTimeout ( async ( ) => {
519+ await autoRespondToAsk ( webviewProvider , askType , askText )
520520 } , 100 ) // Small delay to ensure the message is processed first
521521 }
522522
@@ -538,65 +538,64 @@ export function createMessageCatcher(webviewProvider: WebviewProvider): vscode.D
538538 * @param askType The type of ask message
539539 * @param askText The text content of the ask message
540540 */
541- function autoRespondToAsk ( webviewProvider : WebviewProvider , askType : ClineAsk , askText ?: string ) : void {
541+ async function autoRespondToAsk ( webviewProvider : WebviewProvider , askType : ClineAsk , askText ?: string ) : Promise < void > {
542542 if ( ! webviewProvider . controller ) {
543543 return
544544 }
545545
546546 Logger . log ( `Auto-responding to ask type: ${ askType } ` )
547547
548- // Create a response message based on the ask type
549- const response : WebviewMessage = {
550- type : "askResponse" ,
551- askResponse : "yesButtonClicked" , // Default to approving most actions
552- }
548+ // Default to approving most actions
549+ let responseType = "yesButtonClicked"
550+ let responseText : string | undefined
551+ let responseImages : string [ ] | undefined
553552
554553 // Handle specific ask types differently if needed
555554 switch ( askType ) {
556555 case "followup" :
557556 // For follow-up questions, provide a generic response
558- response . askResponse = "messageResponse"
559- response . text = "I can't answer any questions right now, use your best judgment."
557+ responseType = "messageResponse"
558+ responseText = "I can't answer any questions right now, use your best judgment."
560559 break
561560
562561 case "api_req_failed" :
563562 // Always retry API requests
564- response . askResponse = "yesButtonClicked" // "Retry" button
563+ responseType = "yesButtonClicked" // "Retry" button
565564 break
566565
567566 case "completion_result" :
568567 // Accept the completion
569- response . askResponse = "messageResponse"
570- response . text = "Task completed successfully."
568+ responseType = "messageResponse"
569+ responseText = "Task completed successfully."
571570 break
572571
573572 case "mistake_limit_reached" :
574573 // Provide guidance to continue
575- response . askResponse = "messageResponse"
576- response . text = "Try breaking down the task into smaller steps."
574+ responseType = "messageResponse"
575+ responseText = "Try breaking down the task into smaller steps."
577576 break
578577
579578 case "auto_approval_max_req_reached" :
580579 // Reset the count to continue
581- response . askResponse = "yesButtonClicked" // "Reset and continue" button
580+ responseType = "yesButtonClicked" // "Reset and continue" button
582581 break
583582
584583 case "resume_task" :
585584 case "resume_completed_task" :
586585 // Resume the task
587- response . askResponse = "messageResponse"
586+ responseType = "messageResponse"
588587 break
589588
590589 case "new_task" :
591590 // Decline creating a new task to keep the current task running
592- response . askResponse = "messageResponse"
593- response . text = "Continue with the current task."
591+ responseType = "messageResponse"
592+ responseText = "Continue with the current task."
594593 break
595594
596595 case "plan_mode_respond" :
597596 // Respond to plan mode with a message to toggle to Act mode
598- response . askResponse = "messageResponse"
599- response . text = "PLAN_MODE_TOGGLE_RESPONSE" // Special marker to toggle to Act mode
597+ responseType = "messageResponse"
598+ responseText = "PLAN_MODE_TOGGLE_RESPONSE" // Special marker to toggle to Act mode
600599
601600 // Automatically toggle to Act mode after responding
602601 setTimeout ( async ( ) => {
@@ -616,8 +615,16 @@ function autoRespondToAsk(webviewProvider: WebviewProvider, askType: ClineAsk, a
616615 }
617616
618617 // Send the response message
619- webviewProvider . controller . handleWebviewMessage ( response )
620- Logger . log ( `Auto-responded to ${ askType } with ${ response . askResponse } ` )
618+ try {
619+ await TaskServiceClient . askResponse ( {
620+ responseType,
621+ text : responseText ,
622+ images : responseImages ,
623+ } )
624+ Logger . log ( `Auto-responded to ${ askType } with ${ responseType } ` )
625+ } catch ( error ) {
626+ Logger . log ( `Error sending askResponse: ${ error } ` )
627+ }
621628}
622629
623630/**
0 commit comments