Skip to content

Commit 12e5a4e

Browse files
committed
feat: handling the feedback button
1 parent 23b1c19 commit 12e5a4e

4 files changed

Lines changed: 73 additions & 58 deletions

File tree

src/activate/registerPearListener.ts

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,69 +14,73 @@ export const getPearaiExtension = async () => {
1414
return pearAiExtension
1515
}
1616

17+
// TODO: TYPES
18+
export const getpearAIExports = async () => {
19+
const pearAiExtension = await getPearaiExtension()
20+
21+
assert(!!pearAiExtension.exports, "⚠️⚠️ Error, no PearAI Exports could be found :( ⚠️⚠️");
22+
23+
return pearAiExtension.exports;
24+
}
25+
1726
// TODO: SHOULD HAVE TYPE SYNCED WITH THE PEARAI SUBMODULE!
1827
type CreatorModeState = "OVERLAY_CLOSED" | "OVERLAY_OPEN" | "OVERLAY_CLOSED_CREATOR_ACTIVE"
1928

2029
export const registerPearListener = async () => {
2130
// Getting the pear ai extension instance
22-
const pearAiExtension = await getPearaiExtension()
31+
const exports = await getpearAIExports()
32+
33+
exports.pearAPI.creatorMode.onDidRequestExecutePlan(async (msg: any) => {
34+
console.dir(`onDidRequestNewTask triggered with: ${JSON.stringify(msg)}`)
35+
// Get the sidebar provider
36+
let sidebarProvider = ClineProvider.getVisibleInstance()
37+
38+
// TODO: LOOK INTO THIS - THIS IS A JANKY FIX AND IT FEELS LIKE THIS IS TEMPERAMENTAL
39+
while (!sidebarProvider) {
40+
await new Promise((resolve) => setTimeout(resolve, 500))
41+
sidebarProvider = ClineProvider.getVisibleInstance()
42+
}
43+
44+
// Focus the sidebar first
45+
await vscode.commands.executeCommand("pearai-roo-cline.SidebarProvider.focus")
46+
47+
// Wait for the view to be ready using a helper function
48+
await ensureViewIsReady(sidebarProvider)
49+
// Wait a brief moment for UI to update
50+
await new Promise((resolve) => setTimeout(resolve, 300))
51+
52+
// * This does actually work but the UI update does not happen. This method calls this.postStateToWebview() so not sure what is going on - James
53+
await sidebarProvider.handleModeSwitch("Creator")
54+
55+
// Clicl the chat btn
56+
await sidebarProvider.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
57+
58+
const creatorModeConfig = {
59+
creatorMode: true,
60+
newProjectType: msg.newProjectType,
61+
newProjectPath: msg.newProjectPath,
62+
}
63+
64+
65+
// Initialize with task
66+
await sidebarProvider.initClineWithTask(msg.plan, undefined, undefined, undefined, creatorModeConfig);
67+
});
68+
// If there's a creator event in the cache after the extensions were refreshed, we need to get it!
69+
exports.pearAPI.creatorMode.triggerCachedCreatorEvent(true);
70+
71+
exports.pearAPI.creatorMode.onDidChangeCreatorModeState(async (state: CreatorModeState) => {
72+
// Get the sidebar provider
73+
const sidebarProvider = ClineProvider.getVisibleInstance();
74+
75+
if (sidebarProvider) {
76+
// Send a message to the webview that will trigger a window event
77+
sidebarProvider.postMessageToWebview({
78+
type: "creatorModeUpdate",
79+
text: state,
80+
});
81+
}
82+
});
2383

24-
// Access the API directly from exports
25-
if (pearAiExtension.exports) {
26-
pearAiExtension.exports.pearAPI.creatorMode.onDidRequestExecutePlan(async (msg: any) => {
27-
console.dir(`onDidRequestNewTask triggered with: ${JSON.stringify(msg)}`)
28-
// Get the sidebar provider
29-
let sidebarProvider = ClineProvider.getVisibleInstance()
30-
31-
// TODO: LOOK INTO THIS - THIS IS A JANKY FIX AND IT FEELS LIKE THIS IS TEMPERAMENTAL
32-
while (!sidebarProvider) {
33-
await new Promise((resolve) => setTimeout(resolve, 500))
34-
sidebarProvider = ClineProvider.getVisibleInstance()
35-
}
36-
37-
// Focus the sidebar first
38-
await vscode.commands.executeCommand("pearai-roo-cline.SidebarProvider.focus")
39-
40-
// Wait for the view to be ready using a helper function
41-
await ensureViewIsReady(sidebarProvider)
42-
// Wait a brief moment for UI to update
43-
await new Promise((resolve) => setTimeout(resolve, 300))
44-
45-
// * This does actually work but the UI update does not happen. This method calls this.postStateToWebview() so not sure what is going on - James
46-
await sidebarProvider.handleModeSwitch("Creator")
47-
48-
// Clicl the chat btn
49-
await sidebarProvider.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
50-
51-
const creatorModeConfig = {
52-
creatorMode: true,
53-
newProjectType: msg.newProjectType,
54-
newProjectPath: msg.newProjectPath,
55-
}
56-
57-
58-
// Initialize with task
59-
await sidebarProvider.initClineWithTask(msg.plan, undefined, undefined, undefined, creatorModeConfig);
60-
});
61-
// If there's a creator event in the cache after the extensions were refreshed, we need to get it!
62-
pearAiExtension.exports.pearAPI.creatorMode.triggerCachedCreatorEvent(true);
63-
64-
pearAiExtension.exports.pearAPI.creatorMode.onDidChangeCreatorModeState(async (state: CreatorModeState) => {
65-
// Get the sidebar provider
66-
const sidebarProvider = ClineProvider.getVisibleInstance();
67-
68-
if (sidebarProvider) {
69-
// Send a message to the webview that will trigger a window event
70-
sidebarProvider.postMessageToWebview({
71-
type: "creatorModeUpdate",
72-
text: state,
73-
});
74-
}
75-
});
76-
77-
} else {
78-
console.error("⚠️⚠️ PearAI API not available in exports ⚠️⚠️")
79-
}
8084
}
8185

8286
// TODO: decide if this is needed

src/core/webview/webviewMessageHandler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { buildApiHandler } from "../../api"
3838
import { GlobalState } from "../../schemas"
3939
import { MultiSearchReplaceDiffStrategy } from "../diff/strategies/multi-search-replace"
4040
import { getModels } from "../../api/providers/fetchers/cache"
41+
import { getpearAIExports } from "../../activate/registerPearListener"
4142

4243
export const webviewMessageHandler = async (provider: ClineProvider, message: WebviewMessage) => {
4344
// Utility functions provided for concise get/update of global state via contextProxy API.
@@ -1269,6 +1270,14 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
12691270
),
12701271
)
12711272
break
1273+
case "openPearAICreatorFeedbackOverlay":
1274+
const pearAIExports = await getpearAIExports();
1275+
const currentCline = provider.getCurrentCline();
1276+
1277+
1278+
// Open the feedback form with the chat history
1279+
pearAIExports.pearAPI.creatorMode.openFeedbackForm(currentCline?.clineMessages || []);
1280+
break
12721281
}
12731282
}
12741283

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export interface WebviewMessage {
128128
| "toggleApiConfigPin"
129129
| "setHistoryPreviewCollapsed"
130130
| "openPearAIAuth"
131+
| "openPearAICreatorFeedbackOverlay"
131132
text?: string
132133
disabled?: boolean
133134
askResponse?: ClineAskResponse

webview-ui/src/components/chat/PlanningBar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Button } from "./button"
33
import { DocumentTextIcon as SolidDocumentTextIcon, StopCircleIcon, StopIcon } from "@heroicons/react/24/solid"
44
import { FC } from "react"
55
import { cn } from "@/lib/utils"
6+
import { vscode } from "@src/utils/vscode"
67

78
export type PlanningBarProps = {
89
isGenerating?: boolean;
@@ -52,7 +53,7 @@ export const PlanningBar: FC<PlanningBarProps> = ({
5253
</Button>
5354
</div>
5455

55-
<Button variant="default" className="my-auto">
56+
<Button variant="default" className="my-auto" onClick={() => vscode.postMessage({ type: "openPearAICreatorFeedbackOverlay" })}>
5657
Not Working?
5758
</Button>
5859
<Button className="my-auto bg-red-500/20 hover:bg-red-500/40" disabled={!isGenerating} onClick={stopCallback}>

0 commit comments

Comments
 (0)