feat: Add SendMessage capability during Mode Switch

This commit is contained in:
Dennis Bartlett 2025-02-11 04:26:35 -06:00
parent 9c8254cf92
commit 9e76cfd44a
6 changed files with 42 additions and 5 deletions

View file

@ -2707,14 +2707,15 @@ export class Cline {
this.isAwaitingPlanResponse = false
if (this.didRespondToPlanAskBySwitchingMode) {
// await this.say("user_feedback", text ?? "", images)
pushToolResult(
formatResponse.toolResult(
`[The user has switched to ACT MODE, so you may now proceed with the task.]`,
images,
),
)
} else {
}
if (text) {
await this.say("user_feedback", text ?? "", images)
pushToolResult(formatResponse.toolResult(`<user_message>\n${text}\n</user_message>`, images))
}

View file

@ -618,7 +618,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
await this.postMessageToWebview({
type: "invoke",
invoke: "sendMessage",
text: "[Proceeding with the task...]",
text: message.chatContent?.message || "[Proceeding with the task...]",
images: message.chatContent?.images,
})
} else {
this.cancelTask()

View file

@ -0,0 +1,4 @@
export interface ChatContent {
message?: string
images?: string[]
}

View file

@ -2,6 +2,7 @@ import { ApiConfiguration } from "./api"
import { AutoApprovalSettings } from "./AutoApprovalSettings"
import { BrowserSettings } from "./BrowserSettings"
import { ChatSettings } from "./ChatSettings"
import { ChatContent } from "./ChatContent"
export interface WebviewMessage {
type:
@ -53,6 +54,7 @@ export interface WebviewMessage {
autoApprovalSettings?: AutoApprovalSettings
browserSettings?: BrowserSettings
chatSettings?: ChatSettings
chatContent?: ChatContent
// For toggleToolAutoApprove
serverName?: string

View file

@ -28,7 +28,13 @@ describe("Chat Integration Tests", () => {
vscode.postMessage({ type: 'newTask', text: message.text });
break;
case 'toggleMode':
vscode.postMessage({ type: 'chatSettings', chatSettings: { mode: 'act' } });
vscode.postMessage({
type: 'chatSettings',
chatSettings: { mode: 'act' },
chatContent: {
message: "message test",
}
});
break;
case 'invoke':
if (message.invoke === 'primaryButtonClick') {
@ -92,6 +98,25 @@ describe("Chat Integration Tests", () => {
assert.equal(stateChange.chatSettings.mode, "act")
})
it("should toggle between plan and act modes with messages", async () => {
// Set up state change listener
const stateChangePromise = new Promise<any>((resolve) => {
panel.webview.onDidReceiveMessage((message) => {
if (message.type === "chatSettings") {
resolve(message)
}
})
})
// Trigger mode toggle
await panel.webview.postMessage({ type: "toggleMode" })
// Verify mode changed
const stateChange = await stateChangePromise
assert.equal(stateChange.chatSettings.mode, "act")
assert.equal(stateChange.chatContent.message, "message test")
})
it("should handle tool approval flow", async () => {
// Set up approval listener
const approvalPromise = new Promise<any>((resolve) => {

View file

@ -616,13 +616,17 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
chatSettings: {
mode: newMode,
},
chatContent: {
message: inputValue.trim() ? inputValue : undefined,
images: selectedImages.length > 0 ? selectedImages : undefined,
},
})
// Focus the textarea after mode toggle with slight delay
setTimeout(() => {
textAreaRef.current?.focus()
}, 100)
}, changeModeDelay)
}, [chatSettings.mode, showModelSelector, submitApiConfig])
}, [chatSettings.mode, showModelSelector, submitApiConfig, inputValue, selectedImages])
useShortcut("Meta+Shift+a", onModeToggle, { disableTextInputs: false }) // important that we don't disable the text input here