@@ -4,16 +4,7 @@ import Attachment from "./helpers/attachment.js";
44import main from "./main.js" ;
55const { API_HOST } = require ( '../../../lib/brand.js' ) ;
66
7- let authToken = { } ;
8-
9- var mainWorkspace ;
10-
11-
12- window . addEventListener ( 'blockError' , ( event ) => {
13- document . AI_INTEGRATION . errorsDetected . push ( event . detail ) ;
14- } ) ;
15-
16- document . AI_INTEGRATION = { //probably the dumbest way to possibly do this, it just make debugging alot easier (will do it properly later)
7+ const AI_INTEGRATION = {
178 AI_currently_blabbering : false ,
189 CodeChunks : [ ] ,
1910 AllCodeChunksEverAdded : [ ] ,
@@ -24,7 +15,18 @@ document.AI_INTEGRATION = { //probably the dumbest way to possibly do this, it j
2415 errorsDetected : [ ] ,
2516 AIModels : [ ] ,
2617} ;
18+ // TODO: possibly push this into the addons api?
19+ document . AI_INTEGRATION = AI_INTEGRATION ;
20+
21+ let authToken = { } ;
22+ let mainWorkspace ;
23+
24+ // TODO: dont use global events
25+ window . addEventListener ( 'blockError' , ( event ) => {
26+ AI_INTEGRATION . errorsDetected . push ( event . detail ) ;
27+ } ) ;
2728
29+ // TODO: find a better way to do this, this may break other monkey-patching and it eats RAM...
2830function workspaceOverride ( ) {
2931 if ( typeof Blockly !== 'undefined' ) {
3032 Blockly . getMainWorkspace = function ( ) { // I have to do this as the getmainworkspace gets linked to the getSVG parsing one
@@ -38,9 +40,10 @@ function workspaceOverride() {
3840}
3941workspaceOverride ( ) ;
4042
43+ // TODO: this should use a global hook
4144document . addEventListener ( "mousemove" , ( event ) => {
42- document . AI_INTEGRATION . X_COORDINATE = event . clientX ;
43- document . AI_INTEGRATION . Y_COORDINATE = event . clientY ;
45+ AI_INTEGRATION . X_COORDINATE = event . clientX ;
46+ AI_INTEGRATION . Y_COORDINATE = event . clientY ;
4447} ) ;
4548
4649export default async function ( { addon, console } ) {
@@ -62,7 +65,7 @@ export default async function ({ addon, console }) {
6265 document . head . appendChild ( style ) ;
6366
6467 if ( authToken . gemini == "" && authToken . openrouter == "" ) {
65- document . AI_INTEGRATION . canUse = false ;
68+ AI_INTEGRATION . canUse = false ;
6669 window . addEventListener ( 'ai-button-clicked' , function ( ) {
6770 main . createBasePopup ( 2 , "" ) ;
6871 } ) ;
@@ -84,7 +87,7 @@ export default async function ({ addon, console }) {
8487 }
8588 } )
8689 . then ( data => {
87- document . AI_INTEGRATION . AIModels = data ;
90+ AI_INTEGRATION . AIModels = data ;
8891 helpers . updateAIModels ( authToken . gemini , authToken . openrouter ) ;
8992 } )
9093 . catch ( error => {
@@ -166,6 +169,7 @@ export default async function ({ addon, console }) {
166169 }
167170 } ) ;
168171
172+ // TODO: dont use global events
169173 window . addEventListener ( 'ai-button-clicked' , function ( ) {
170174 main . createBasePopup ( 2 , "" ) ;
171175 } ) ;
0 commit comments