@@ -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!
1827type CreatorModeState = "OVERLAY_CLOSED" | "OVERLAY_OPEN" | "OVERLAY_CLOSED_CREATOR_ACTIVE"
1928
2029export 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
0 commit comments