@codebolt/codeboltjs 1.1.76 → 1.1.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/docs/modules/_internal_.EventEmitter.html +6 -0
  2. package/docs/modules/_internal_.WebSocket.html +21 -0
  3. package/docs/modules/_internal_._node_stream_consumers_.html +6 -0
  4. package/docs/modules/_internal_._node_stream_promises_.html +3 -0
  5. package/docs/modules/_internal_.html +228 -0
  6. package/docs/modules/_internal_.internal.finished.html +2 -0
  7. package/docs/modules/_internal_.internal.html +36 -0
  8. package/docs/modules/_internal_.internal.pipeline.html +2 -0
  9. package/index.d.ts +254 -0
  10. package/modules/browser.d.ts +108 -0
  11. package/modules/browser.js +331 -0
  12. package/modules/chat.d.ts +64 -0
  13. package/modules/chat.js +190 -0
  14. package/modules/codeparsers.d.ts +23 -0
  15. package/modules/codeparsers.js +30 -0
  16. package/modules/codeutils.d.ts +37 -0
  17. package/modules/codeutils.js +117 -0
  18. package/modules/crawler.d.ts +45 -0
  19. package/modules/crawler.js +123 -0
  20. package/modules/dbmemory.d.ts +20 -0
  21. package/modules/dbmemory.js +54 -0
  22. package/modules/debug.d.ts +23 -0
  23. package/modules/debug.js +64 -0
  24. package/modules/docutils.d.ts +12 -0
  25. package/modules/docutils.js +19 -0
  26. package/modules/fs.d.ts +94 -0
  27. package/modules/fs.js +264 -0
  28. package/modules/git.d.ts +76 -0
  29. package/modules/git.js +240 -0
  30. package/modules/history.d.ts +19 -0
  31. package/modules/history.js +46 -0
  32. package/modules/knowledge.d.ts +2 -0
  33. package/modules/knowledge.js +6 -0
  34. package/modules/llm.d.ts +18 -0
  35. package/modules/llm.js +39 -0
  36. package/modules/mcp.d.ts +8 -0
  37. package/modules/mcp.js +139 -0
  38. package/modules/outputparsers.d.ts +24 -0
  39. package/modules/outputparsers.js +32 -0
  40. package/modules/project.d.ts +21 -0
  41. package/modules/project.js +72 -0
  42. package/modules/rag.d.ts +22 -0
  43. package/modules/rag.js +30 -0
  44. package/modules/search.d.ts +23 -0
  45. package/modules/search.js +37 -0
  46. package/modules/state.d.ts +21 -0
  47. package/modules/state.js +68 -0
  48. package/modules/task.d.ts +23 -0
  49. package/modules/task.js +75 -0
  50. package/modules/terminal.d.ts +46 -0
  51. package/modules/terminal.js +108 -0
  52. package/modules/tokenizer.d.ts +19 -0
  53. package/modules/tokenizer.js +56 -0
  54. package/modules/vectordb.d.ts +33 -0
  55. package/modules/vectordb.js +103 -0
  56. package/modules/websocket.d.ts +27 -0
  57. package/modules/websocket.js +88 -0
  58. package/package.json +1 -1
  59. package/src/modules/browser.ts +352 -0
  60. package/src/modules/chat.ts +193 -0
  61. package/src/modules/codeparsers.ts +30 -0
  62. package/src/modules/codeutils.ts +126 -0
  63. package/src/modules/crawler.ts +121 -0
  64. package/src/modules/dbmemory.ts +52 -0
  65. package/src/modules/debug.ts +68 -0
  66. package/src/modules/docutils.ts +18 -0
  67. package/src/modules/fs.ts +263 -0
  68. package/src/modules/git.ts +237 -0
  69. package/src/modules/history.ts +61 -0
  70. package/src/modules/knowledge.ts +5 -0
  71. package/src/modules/llm.ts +36 -0
  72. package/src/modules/mcp.ts +127 -0
  73. package/src/modules/outputparsers.ts +30 -0
  74. package/src/modules/project.ts +68 -0
  75. package/src/modules/rag.ts +28 -0
  76. package/src/modules/search.ts +35 -0
  77. package/src/modules/state.ts +69 -0
  78. package/src/modules/task.ts +73 -0
  79. package/src/modules/terminal.ts +114 -0
  80. package/src/modules/tokenizer.ts +56 -0
  81. package/src/modules/vectordb.ts +102 -0
  82. package/src/modules/websocket.ts +89 -0
@@ -0,0 +1,352 @@
1
+ import cbws from './websocket';
2
+ import {GoToPageResponse,UrlResponse,GetMarkdownResponse,HtmlReceived,ExtractTextResponse,GetContentResponse} from '@codebolt/types'
3
+ /**
4
+ * A module for interacting with a browser through WebSockets.
5
+ */
6
+ const cbbrowser = {
7
+
8
+ /**
9
+ * Opens a new page in the browser.
10
+ */
11
+ newPage: () => {
12
+
13
+ return new Promise((resolve, reject) => {
14
+ cbws.getWebsocket.send(JSON.stringify({
15
+ "type": "browserEvent",
16
+ action: 'newPage'
17
+ }));
18
+ cbws.getWebsocket.on('message', (data: string) => {
19
+ const response = JSON.parse(data);
20
+ if (response.event === "newPageResponse") {
21
+ resolve(response);
22
+ }
23
+ });
24
+ });
25
+ },
26
+
27
+ /**
28
+ * Retrieves the current URL of the browser's active page.
29
+ * @returns {Promise<UrlResponse>} A promise that resolves with the URL.
30
+ */
31
+ getUrl: ():Promise<UrlResponse> => {
32
+ return new Promise((resolve, reject) => {
33
+ cbws.getWebsocket.send(JSON.stringify({
34
+ "type": "browserEvent",
35
+ action: 'getUrl'
36
+ }));
37
+ cbws.getWebsocket.on('message', (data: string) => {
38
+ const response = JSON.parse(data);
39
+ if (response.event === "getUrlResponse") {
40
+ resolve(response);
41
+ }
42
+ });
43
+ });
44
+ },
45
+
46
+ /**
47
+ * Navigates to a specified URL.
48
+ * @param {string} url - The URL to navigate to.
49
+ * @returns {Promise<GoToPageResponse>} A promise that resolves when navigation is complete.
50
+ */
51
+ goToPage: (url: string):Promise<GoToPageResponse> => {
52
+ return new Promise((resolve, reject) => {
53
+ cbws.getWebsocket.send(JSON.stringify({
54
+ "type": "browserEvent",
55
+ action: 'goToPage',
56
+ url
57
+ }));
58
+ cbws.getWebsocket.on('message', (data: string) => {
59
+ const response = JSON.parse(data);
60
+ if (response.event === "goToPageResponse") {
61
+ resolve(response);
62
+ }
63
+ });
64
+ });
65
+ },
66
+
67
+ /**
68
+ * Takes a screenshot of the current page.
69
+ */
70
+ screenshot: () => {
71
+ return new Promise((resolve, reject) => {
72
+ cbws.getWebsocket.send(JSON.stringify({
73
+ "type": "browserEvent",
74
+ action: 'screenshot'
75
+ }));
76
+ cbws.getWebsocket.on('message', (data: string) => {
77
+ const response = JSON.parse(data);
78
+ if (response.event === "screenshotResponse") {
79
+ resolve(response.payload);
80
+ }
81
+ });
82
+ });
83
+ },
84
+
85
+ /**
86
+ * Retrieves the HTML content of the current page.
87
+ * @returns {Promise<HtmlReceived>} A promise that resolves with the HTML content.
88
+ */
89
+ getHTML: ():Promise<HtmlReceived> => {
90
+ return new Promise((resolve, reject) => {
91
+ cbws.getWebsocket.send(JSON.stringify({
92
+ "type": "browserEvent",
93
+ action: 'getHTML'
94
+ }));
95
+ cbws.getWebsocket.on('message', (data: string) => {
96
+ const response = JSON.parse(data);
97
+ if (response.event === "htmlReceived") {
98
+ resolve(response.htmlResponse);
99
+ }
100
+ });
101
+ });
102
+ },
103
+
104
+ /**
105
+ * Retrieves the Markdown content of the current page.
106
+ * @returns {Promise<GetMarkdownResponse>} A promise that resolves with the Markdown content.
107
+ */
108
+ getMarkdown: ():Promise<GetMarkdownResponse> => {
109
+ return new Promise((resolve, reject) => {
110
+ cbws.getWebsocket.send(JSON.stringify({
111
+ "type": "browserEvent",
112
+ action: 'getMarkdown'
113
+ }));
114
+ cbws.getWebsocket.on('message', (data: string) => {
115
+ const response = JSON.parse(data);
116
+ if (response.event === "getMarkdownResponse") {
117
+ resolve(response);
118
+ }
119
+ });
120
+ });
121
+ },
122
+
123
+ /**
124
+ * Retrieves the PDF content of the current page.
125
+ *
126
+ */
127
+ getPDF: () => {
128
+ cbws.getWebsocket.send(JSON.stringify({
129
+ "type": "browserEvent",
130
+ action: 'getPDF'
131
+ }));
132
+ },
133
+
134
+ /**
135
+ * Converts the PDF content of the current page to text.
136
+ */
137
+ pdfToText: () => {
138
+ cbws.getWebsocket.send(JSON.stringify({
139
+ "type": "browserEvent",
140
+ action: 'pdfToText'
141
+ }));
142
+ },
143
+
144
+ /**
145
+ * Retrieves the content of the current page.
146
+ * @returns {Promise<GetContentResponse>} A promise that resolves with the content.
147
+ */
148
+ getContent: ():Promise<GetContentResponse> => {
149
+
150
+ return new Promise((resolve, reject) => {
151
+ cbws.getWebsocket.send(JSON.stringify({
152
+ "type": "browserEvent",
153
+ action: 'getContent'
154
+ }));
155
+ cbws.getWebsocket.on('message', (data: string) => {
156
+ const response = JSON.parse(data);
157
+ if (response.event === "getContentResponse") {
158
+ resolve(response);
159
+ }
160
+ });
161
+ });
162
+ },
163
+ /**
164
+ * Retrieves the snapshot of the current page.
165
+ * @returns {Promise<GetContentResponse>} A promise that resolves with the content.
166
+ */
167
+ getSnapShot: ():Promise<any> => {
168
+
169
+ return new Promise((resolve, reject) => {
170
+ cbws.getWebsocket.send(JSON.stringify({
171
+ "type": "browserEvent",
172
+ action: 'getSnapShot'
173
+ }));
174
+ cbws.getWebsocket.on('message', (data: string) => {
175
+ const response = JSON.parse(data);
176
+ if (response.event === "getSnapShotResponse") {
177
+ resolve(response);
178
+ }
179
+ });
180
+ });
181
+ },
182
+ /**
183
+ * Retrieves browser info like height width scrollx scrolly of the current page.
184
+ * @returns {Promise<GetContentResponse>} A promise that resolves with the content.
185
+ */
186
+ getBrowserInfo: ():Promise<any> => {
187
+
188
+ return new Promise((resolve, reject) => {
189
+ cbws.getWebsocket.send(JSON.stringify({
190
+ "type": "browserEvent",
191
+ action: 'getBrowserInfo'
192
+ }));
193
+ cbws.getWebsocket.on('message', (data: string) => {
194
+ const response = JSON.parse(data);
195
+ if (response.event === "getBrowserInfoResponse") {
196
+ resolve(response);
197
+ }
198
+ });
199
+ });
200
+ },
201
+
202
+ /**
203
+ * Extracts text from the current page.
204
+ * @returns {Promise<ExtractTextResponse>} A promise that resolves with the extracted text.
205
+ *
206
+ */
207
+ extractText: ():Promise<ExtractTextResponse> => {
208
+
209
+ return new Promise((resolve, reject) => {
210
+ cbws.getWebsocket.send(JSON.stringify({
211
+ "type": "browserEvent",
212
+ action: 'extractText'
213
+ }));
214
+ cbws.getWebsocket.on('message', (data: string) => {
215
+ const response = JSON.parse(data);
216
+ if (response.event === "extractTextResponse") {
217
+ resolve(response);
218
+ }
219
+ });
220
+ });
221
+ },
222
+
223
+ /**
224
+ * Closes the current page.
225
+ */
226
+ close: () => {
227
+ cbws.getWebsocket.send(JSON.stringify({
228
+ "type": "browserEvent",
229
+ action: 'close'
230
+ }));
231
+ },
232
+
233
+ /**
234
+ * Scrolls the current page in a specified direction by a specified number of pixels.
235
+ * @param {string} direction - The direction to scroll.
236
+ * @param {string} pixels - The number of pixels to scroll.
237
+ * @returns {Promise<any>} A promise that resolves when the scroll action is complete.
238
+ */
239
+ scroll: (direction: string, pixels: string) => {
240
+ return new Promise((resolve, reject) => {
241
+ cbws.getWebsocket.send(JSON.stringify({
242
+ "type": "browserEvent",
243
+ action: 'scroll',
244
+ direction,
245
+ pixels
246
+ }));
247
+ cbws.getWebsocket.on('message', (data: string) => {
248
+ const response = JSON.parse(data);
249
+ if (response.event === "scrollResponse") {
250
+ resolve(response);
251
+ }
252
+ });
253
+ });
254
+ },
255
+
256
+ /**
257
+ * Types text into a specified element on the page.
258
+ * @param {string} elementid - The ID of the element to type into.
259
+ * @param {string} text - The text to type.
260
+ * @returns {Promise<any>} A promise that resolves when the typing action is complete.
261
+ */
262
+ type: (elementid: string, text: string) => {
263
+ return new Promise((resolve, reject) => {
264
+ cbws.getWebsocket.send(JSON.stringify({
265
+ "type": "browserEvent",
266
+ action: 'type',
267
+ text,
268
+ elementid
269
+ }));
270
+ cbws.getWebsocket.on('message', (data: string) => {
271
+ const response = JSON.parse(data);
272
+ if (response.event === "typeResponse") {
273
+ resolve(response);
274
+ }
275
+ });
276
+ });
277
+ },
278
+
279
+ /**
280
+ * Clicks on a specified element on the page.
281
+ * @param {string} elementid - The ID of the element to click.
282
+ * @returns {Promise<any>} A promise that resolves when the click action is complete.
283
+ */
284
+ click: (elementid: string) => {
285
+ return new Promise((resolve, reject) => {
286
+ cbws.getWebsocket.send(JSON.stringify({
287
+ "type": "browserEvent",
288
+ action: 'click',
289
+ elementid
290
+ }));
291
+ cbws.getWebsocket.on('message', (data: string) => {
292
+ const response = JSON.parse(data);
293
+ if (response.event === "clickResponse") {
294
+ resolve(response);
295
+ }
296
+ });
297
+ });
298
+ },
299
+
300
+ /**
301
+ * Simulates the Enter key press on the current page.
302
+ * @returns {Promise<any>} A promise that resolves when the Enter action is complete.
303
+ */
304
+ enter: () => {
305
+ return new Promise((resolve, reject) => {
306
+ cbws.getWebsocket.send(JSON.stringify({
307
+ "type": "browserEvent",
308
+ action: 'enter'
309
+ }));
310
+ cbws.getWebsocket.on('message', (data: string) => {
311
+ const response = JSON.parse(data);
312
+ if (response.event === "EnterResponse") {
313
+ resolve(response);
314
+ }
315
+ });
316
+ });
317
+ },
318
+
319
+ /**
320
+ * Performs a search on the current page using a specified query.
321
+ * @param {string} elementid - The ID of the element to perform the search in.
322
+ * @param {string} query - The search query.
323
+ * @returns {Promise<any>} A promise that resolves with the search results.
324
+ */
325
+ search: (elementid: string, query: string) => {
326
+ return new Promise((resolve, reject) => {
327
+ cbws.getWebsocket.send(JSON.stringify({
328
+ "type": "browserEvent",
329
+ action: 'search',
330
+ elementid,
331
+ query
332
+ }));
333
+ cbws.getWebsocket.on('message', (data: string) => {
334
+ const response = JSON.parse(data);
335
+ if (response.event === "searchResponse") {
336
+ resolve(response);
337
+ }
338
+ });
339
+ });
340
+ }
341
+ }
342
+
343
+ export default cbbrowser;
344
+
345
+
346
+
347
+ /***
348
+
349
+ start_browser(objective: string, url: string, previous_command: string, browser_content: string) {
350
+ cbbrowser.newPage();
351
+ }
352
+ */
@@ -0,0 +1,193 @@
1
+ // chat.ts
2
+ import cbws from './websocket';
3
+ import { EventEmitter } from 'events';
4
+ import { ChatMessage, UserMessage } from '@codebolt/types'
5
+
6
+
7
+
8
+ /**
9
+ * CustomEventEmitter class that extends the Node.js EventEmitter class.
10
+ */
11
+ class CustomEventEmitter extends EventEmitter { }
12
+ let eventEmitter = new CustomEventEmitter()
13
+ /**
14
+ * Chat module to interact with the WebSocket server.
15
+ */
16
+ const cbchat = {
17
+ /**
18
+ * Retrieves the chat history from the server.
19
+ * @returns {Promise<ChatMessage[]>} A promise that resolves with an array of ChatMessage objects representing the chat history.
20
+ */
21
+ getChatHistory: (): Promise<ChatMessage[]> => {
22
+ return new Promise((resolve, reject) => {
23
+ cbws.getWebsocket.send(JSON.stringify({
24
+ "type": "getChatHistory"
25
+ }));
26
+ cbws.getWebsocket.on('message', (data: string) => {
27
+ const response = JSON.parse(data);
28
+ if (response.type === "getChatHistoryResponse") {
29
+ resolve(response); // Resolve the Promise with the response data
30
+ }
31
+ })
32
+ })
33
+ },
34
+ /**
35
+ * Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
36
+ * @returns {EventEmitter} The event emitter used for emitting custom events.
37
+ */
38
+ onActionMessage: () => {
39
+ if (!cbws.getWebsocket) return;
40
+ cbws.getWebsocket.on('message', (data: string) => {
41
+ const response = JSON.parse(data);
42
+ if (response.type === "messageResponse") {
43
+ // Pass a callback function as an argument to the emit method
44
+ eventEmitter.emit("userMessage", response, (message: string) => {
45
+ console.log("Callback function invoked with message:", message);
46
+ cbws.getWebsocket.send(JSON.stringify({
47
+ "type": "processStoped"
48
+ }));
49
+ });
50
+ }
51
+ });
52
+ return eventEmitter;
53
+ },
54
+ /**
55
+ * Sends a message through the WebSocket connection.
56
+ * @param {string} message - The message to be sent.
57
+ */
58
+ sendMessage: (message: string, payload: any) => {
59
+ console.log(message);
60
+ cbws.getWebsocket.send(JSON.stringify({
61
+ "type": "sendMessage",
62
+ "message": message,
63
+ payload
64
+ }));
65
+ },
66
+ /**
67
+ * Waits for a reply to a sent message.
68
+ * @param {string} message - The message for which a reply is expected.
69
+ * @returns {Promise<UserMessage>} A promise that resolves with the reply.
70
+ */
71
+ waitforReply: (message: string): Promise<UserMessage> => {
72
+ return new Promise((resolve, reject) => {
73
+ cbws.getWebsocket.send(JSON.stringify({
74
+ "type": "waitforReply",
75
+ "message": message
76
+ }));
77
+ cbws.getWebsocket.on('message', (data: string) => {
78
+ const response = JSON.parse(data);
79
+ if (response.type === "waitFormessageResponse") {
80
+ resolve(response); // Resolve the Promise with the response data
81
+ }
82
+ });
83
+ });
84
+ },
85
+ /**
86
+ * Notifies the server that a process has started and sets up an event listener for stopProcessClicked events.
87
+ * @returns An object containing the event emitter and a stopProcess method.
88
+ */
89
+ processStarted: () => {
90
+ // Send the process started message
91
+ cbws.getWebsocket.send(JSON.stringify({
92
+ "type": "processStarted"
93
+ }));
94
+ // Register event listener for WebSocket messages
95
+ cbws.getWebsocket.on('message', (data: string) => {
96
+ const message = JSON.parse(data);
97
+ console.log("Received message:", message);
98
+ if (message.type === 'stopProcessClicked')
99
+
100
+ // Emit a custom event based on the message type
101
+ eventEmitter.emit("stopProcessClicked", message);
102
+ });
103
+
104
+ // Return an object that includes the event emitter and the stopProcess method
105
+ return {
106
+ event: eventEmitter,
107
+ stopProcess: () => {
108
+ // Implement the logic to stop the process here
109
+ console.log("Stopping process...");
110
+ // For example, you might want to send a specific message to the server to stop the process
111
+ cbws.getWebsocket.send(JSON.stringify({
112
+ "type": "processStoped"
113
+ }));
114
+ }
115
+ };
116
+ },
117
+ /**
118
+ * Stops the ongoing process.
119
+ * Sends a specific message to the server to stop the process.
120
+ */
121
+ stopProcess: () => {
122
+ // Implement the logic to stop the process here
123
+ console.log("Stopping process...");
124
+ // For example, you might want to send a specific message to the server to stop the process
125
+ cbws.getWebsocket.send(JSON.stringify({
126
+ "type": "processStoped"
127
+ }));
128
+ },
129
+ /**
130
+ * Stops the ongoing process.
131
+ * Sends a specific message to the server to stop the process.
132
+ */
133
+ processFinished: () => {
134
+ // Implement the logic to stop the process here
135
+ console.log("Process Finished ...");
136
+ // For example, you might want to send a specific message to the server to stop the process
137
+ cbws.getWebsocket.send(JSON.stringify({
138
+ "type": "processFinished"
139
+ }));
140
+ },
141
+ /**
142
+ * Sends a confirmation request to the server with two options: Yes or No.
143
+ * @returns {Promise<string>} A promise that resolves with the server's response.
144
+ */
145
+ sendConfirmationRequest: (confirmationMessage: string, buttons: string[] = [],withFeedback:boolean=false): Promise<string> => {
146
+ return new Promise((resolve, reject) => {
147
+ cbws.getWebsocket.send(JSON.stringify({
148
+ "type": "confirmationRequest",
149
+ "message": confirmationMessage,
150
+ buttons: buttons,
151
+ withFeedback
152
+
153
+ }));
154
+ cbws.getWebsocket.on('message', (data: string) => {
155
+ const response = JSON.parse(data);
156
+ if (response.type === "confirmationResponse" || response.type === "feedbackResponse" ) {
157
+ resolve(response); // Resolve the Promise with the server's response
158
+ }
159
+ });
160
+ });
161
+ },
162
+ askQuestion: (question: string, buttons: string[] = [],withFeedback:boolean=false): Promise<string> => {
163
+ return new Promise((resolve, reject) => {
164
+ cbws.getWebsocket.send(JSON.stringify({
165
+ "type": "confirmationRequest",
166
+ "message": question,
167
+ buttons: buttons,
168
+ withFeedback
169
+
170
+ }));
171
+ cbws.getWebsocket.on('message', (data: string) => {
172
+ const response = JSON.parse(data);
173
+ if (response.type === "confirmationResponse" || response.type === "feedbackResponse" ) {
174
+ resolve(response); // Resolve the Promise with the server's response
175
+ }
176
+ });
177
+ });
178
+ },
179
+ /**
180
+ * Sends a notification event to the server.
181
+ * @param {string} notificationMessage - The message to be sent in the notification.
182
+ */
183
+ sendNotificationEvent: (notificationMessage: string, type: 'debug' | 'git' | 'planner' | 'browser' | 'editor' | 'terminal' | 'preview'): void => {
184
+ cbws.getWebsocket.send(JSON.stringify({
185
+ "type": "notificationEvent",
186
+ "message": notificationMessage,
187
+ "eventType": type
188
+ }));
189
+ },
190
+
191
+ };
192
+
193
+ export default cbchat;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A collection of code parser functions.
3
+ */
4
+ const cbcodeparsers = {
5
+ /**
6
+ * Retrieves the classes in a given file.
7
+ * @param file The file to parse for classes.
8
+ */
9
+ getClassesInFile: (file: any) => {
10
+ console.log('Code parsers initialized');
11
+ },
12
+ /**
13
+ * Retrieves the functions in a given class within a file.
14
+ * @param file The file containing the class.
15
+ * @param className The name of the class to parse for functions.
16
+ */
17
+ getFunctionsinClass: (file: any, className: any) => {
18
+ console.log('Code parsers initialized');
19
+ },
20
+ /**
21
+ * Generates an Abstract Syntax Tree (AST) for a given file.
22
+ * @param file The file to generate an AST for.
23
+ * @param className The name of the class to focus the AST generation on.
24
+ */
25
+ getAstTreeInFile: (file: any, className: any) => {
26
+
27
+ }
28
+ };
29
+
30
+ export default cbcodeparsers;
@@ -0,0 +1,126 @@
1
+ import cbws from './websocket';
2
+ import * as fs from 'fs';
3
+ import path from 'path';
4
+ // import Parser from 'tree-sitter';
5
+ // import JavaScript from 'tree-sitter-javascript';
6
+
7
+ import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
8
+
9
+ /**
10
+ * A utility module for working with code.
11
+ */
12
+ const cbcodeutils = {
13
+
14
+ /**
15
+ * Retrieves a JavaScript tree structure for a given file path.
16
+ * @param {string} filePath - The path of the file to retrieve the JS tree for.
17
+ * @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
18
+ */
19
+ getJsTree: (filePath?: string) => {
20
+ return new Promise(async (resolve, reject) => {
21
+ cbws.getWebsocket.send(JSON.stringify({
22
+ "type": "codeEvent",
23
+ "action": "getJsTree",
24
+ payload: {
25
+ filePath
26
+ }
27
+ }));
28
+ cbws.getWebsocket.on('message', (data: string) => {
29
+ const response = JSON.parse(data);
30
+ if (response.type === "getJsTreeResponse") {
31
+ resolve(response); // Resolve the Promise with the response data
32
+ }
33
+ });
34
+ });
35
+ },
36
+
37
+ /**
38
+ * Retrieves all files as Markdown.
39
+ * @returns {Promise<string>} A promise that resolves with the Markdown content of all files.
40
+ */
41
+ getAllFilesAsMarkDown: (): Promise<string> => {
42
+ return new Promise((resolve, reject) => {
43
+ cbws.getWebsocket.send(JSON.stringify({
44
+ "type": "codeEvent",
45
+ "action": "getAllFilesMarkdown"
46
+ }));
47
+ cbws.getWebsocket.on('message', (data: string) => {
48
+ const response = JSON.parse(data);
49
+ if (response.type === "getAllFilesMarkdownResponse") {
50
+ resolve(response); // Resolve the Promise with the response data
51
+ }
52
+ });
53
+ });
54
+ },
55
+
56
+ /**
57
+ * Performs a matching operation based on the provided matcher definition and problem patterns.
58
+ * @param {object} matcherDefinition - The definition of the matcher.
59
+ * @param {Array} problemPatterns - The patterns to match against.
60
+ * @param {Array} problems - The list of problems.
61
+ * @returns {Promise<MatchProblemResponse>} A promise that resolves with the matching problem response.
62
+ */
63
+ performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]): Promise<MatchProblemResponse> => {
64
+ return new Promise((resolve, reject) => {
65
+ cbws.getWebsocket.send(JSON.stringify({
66
+ "type": "codeEvent",
67
+ "action": "performMatch",
68
+ payload: {
69
+ matcherDefinition,
70
+ problemPatterns,
71
+ }
72
+ }));
73
+ cbws.getWebsocket.on('message', (data: string) => {
74
+ const response = JSON.parse(data);
75
+ if (response.type === "getgetJsTreeResponse") {
76
+ resolve(response); // Resolve the Promise with the response data
77
+ }
78
+ });
79
+ });
80
+ },
81
+
82
+ /**
83
+ * Retrieves the list of matchers.
84
+ * @returns {Promise<GetMatcherListTreeResponse>} A promise that resolves with the list of matchers response.
85
+ */
86
+ getMatcherList: (): Promise<GetMatcherListTreeResponse> => {
87
+ return new Promise((resolve, reject) => {
88
+ cbws.getWebsocket.send(JSON.stringify({
89
+ "type": "codeEvent",
90
+ "action": "getMatcherList",
91
+ }));
92
+ cbws.getWebsocket.on('message', (data: string) => {
93
+ const response = JSON.parse(data);
94
+ if (response.type === "getMatcherListTreeResponse") {
95
+ resolve(response); // Resolve the Promise with the response data
96
+ }
97
+ });
98
+ });
99
+ },
100
+
101
+ /**
102
+ * Retrieves details of a match.
103
+ * @param {string} matcher - The matcher to retrieve details for.
104
+ * @returns {Promise<getMatchDetail>} A promise that resolves with the match detail response.
105
+ */
106
+ matchDetail: (matcher: string): Promise<getMatchDetail> => {
107
+ return new Promise((resolve, reject) => {
108
+ cbws.getWebsocket.send(JSON.stringify({
109
+ "type": "codeEvent",
110
+ "action": "getMatchDetail",
111
+ payload: {
112
+ match: matcher
113
+ }
114
+ }));
115
+ cbws.getWebsocket.on('message', (data: string) => {
116
+ const response = JSON.parse(data);
117
+ if (response.type === "matchDetailTreeResponse") {
118
+ resolve(response); // Resolve the Promise with the response data
119
+ }
120
+ });
121
+ });
122
+ }
123
+
124
+ };
125
+
126
+ export default cbcodeutils;