@codebolt/codeboltjs 2.0.4 → 2.0.6

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 (91) hide show
  1. package/dist/core/messageManager.d.ts +47 -0
  2. package/dist/core/messageManager.js +128 -0
  3. package/dist/{modules → core}/websocket.d.ts +5 -0
  4. package/dist/{modules → core}/websocket.js +15 -10
  5. package/dist/index.d.ts +98 -68
  6. package/dist/index.js +51 -4
  7. package/dist/modules/agent.js +26 -58
  8. package/dist/modules/browser.d.ts +7 -7
  9. package/dist/modules/browser.js +75 -195
  10. package/dist/modules/chat.d.ts +8 -20
  11. package/dist/modules/chat.js +60 -123
  12. package/dist/modules/codeparsers.d.ts +32 -3
  13. package/dist/modules/codeparsers.js +295 -3
  14. package/dist/modules/codeutils.d.ts +24 -7
  15. package/dist/modules/codeutils.js +113 -126
  16. package/dist/modules/crawler.d.ts +1 -16
  17. package/dist/modules/crawler.js +13 -72
  18. package/dist/modules/dbmemory.js +12 -28
  19. package/dist/modules/debug.js +17 -33
  20. package/dist/modules/docutils.d.ts +1 -4
  21. package/dist/modules/docutils.js +52 -2
  22. package/dist/modules/fs.d.ts +47 -1
  23. package/dist/modules/fs.js +151 -162
  24. package/dist/modules/git.d.ts +7 -14
  25. package/dist/modules/git.js +54 -163
  26. package/dist/modules/history.js +11 -27
  27. package/dist/modules/llm.js +8 -16
  28. package/dist/modules/outputparsers.d.ts +36 -4
  29. package/dist/modules/outputparsers.js +56 -5
  30. package/dist/modules/project.d.ts +4 -5
  31. package/dist/modules/project.js +23 -45
  32. package/dist/modules/state.js +29 -69
  33. package/dist/modules/task.js +19 -43
  34. package/dist/modules/terminal.d.ts +3 -2
  35. package/dist/modules/terminal.js +36 -47
  36. package/dist/modules/tokenizer.js +15 -31
  37. package/dist/modules/tools.d.ts +0 -6
  38. package/dist/modules/tools.js +41 -179
  39. package/dist/modules/utils.js +22 -0
  40. package/dist/modules/vectordb.js +30 -62
  41. package/dist/utils/parse-source-code/index.d.ts +9 -0
  42. package/dist/utils/parse-source-code/index.js +233 -0
  43. package/dist/utils/parse-source-code/languageParser.d.ts +8 -0
  44. package/dist/utils/parse-source-code/languageParser.js +137 -0
  45. package/dist/utils/parse-source-code/queries/c-sharp.d.ts +2 -0
  46. package/dist/utils/parse-source-code/queries/c-sharp.js +25 -0
  47. package/dist/utils/parse-source-code/queries/c.d.ts +2 -0
  48. package/dist/utils/parse-source-code/queries/c.js +17 -0
  49. package/dist/utils/parse-source-code/queries/cpp.d.ts +2 -0
  50. package/dist/utils/parse-source-code/queries/cpp.js +25 -0
  51. package/dist/utils/parse-source-code/queries/go.d.ts +2 -0
  52. package/dist/utils/parse-source-code/queries/go.js +29 -0
  53. package/dist/utils/parse-source-code/queries/index.d.ts +12 -0
  54. package/dist/utils/parse-source-code/queries/index.js +30 -0
  55. package/dist/utils/parse-source-code/queries/java.d.ts +2 -0
  56. package/dist/utils/parse-source-code/queries/java.js +17 -0
  57. package/dist/utils/parse-source-code/queries/javascript.d.ts +2 -0
  58. package/dist/utils/parse-source-code/queries/javascript.js +67 -0
  59. package/dist/utils/parse-source-code/queries/php.d.ts +2 -0
  60. package/dist/utils/parse-source-code/queries/php.js +17 -0
  61. package/dist/utils/parse-source-code/queries/python.d.ts +2 -0
  62. package/dist/utils/parse-source-code/queries/python.js +13 -0
  63. package/dist/utils/parse-source-code/queries/ruby.d.ts +2 -0
  64. package/dist/utils/parse-source-code/queries/ruby.js +54 -0
  65. package/dist/utils/parse-source-code/queries/rust.d.ts +2 -0
  66. package/dist/utils/parse-source-code/queries/rust.js +18 -0
  67. package/dist/utils/parse-source-code/queries/swift.d.ts +2 -0
  68. package/dist/utils/parse-source-code/queries/swift.js +47 -0
  69. package/dist/utils/parse-source-code/queries/typescript.d.ts +2 -0
  70. package/dist/utils/parse-source-code/queries/typescript.js +34 -0
  71. package/dist/utils/parse-source-code/tree-sitter-c.wasm +0 -0
  72. package/dist/utils/parse-source-code/tree-sitter-c_sharp.wasm +0 -0
  73. package/dist/utils/parse-source-code/tree-sitter-cpp.wasm +0 -0
  74. package/dist/utils/parse-source-code/tree-sitter-go.wasm +0 -0
  75. package/dist/utils/parse-source-code/tree-sitter-java.wasm +0 -0
  76. package/dist/utils/parse-source-code/tree-sitter-javascript.wasm +0 -0
  77. package/dist/utils/parse-source-code/tree-sitter-php.wasm +0 -0
  78. package/dist/utils/parse-source-code/tree-sitter-python.wasm +0 -0
  79. package/dist/utils/parse-source-code/tree-sitter-ruby.wasm +0 -0
  80. package/dist/utils/parse-source-code/tree-sitter-rust.wasm +0 -0
  81. package/dist/utils/parse-source-code/tree-sitter-swift.wasm +0 -0
  82. package/dist/utils/parse-source-code/tree-sitter-tsx.wasm +0 -0
  83. package/dist/utils/parse-source-code/tree-sitter-typescript.wasm +0 -0
  84. package/dist/utils/parse-source-code/tree-sitter.wasm +0 -0
  85. package/dist/utils.d.ts +1 -1
  86. package/dist/utils.js +1 -1
  87. package/package.json +6 -2
  88. package/dist/utils/editFile.js +0 -30
  89. /package/dist/{utils/editFile.d.ts → modules/utils.d.ts} +0 -0
  90. /package/dist/{modules → utils}/toolBox.d.ts +0 -0
  91. /package/dist/{modules → utils}/toolBox.js +0 -0
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FilterUsing = exports.Agents = exports.AgentLocation = void 0;
7
- const websocket_1 = __importDefault(require("./websocket"));
7
+ const websocket_1 = __importDefault(require("../core/websocket"));
8
8
  var AgentLocation;
9
9
  (function (AgentLocation) {
10
10
  AgentLocation["ALL"] = "all";
@@ -30,23 +30,15 @@ const codeboltAgent = {
30
30
  * @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
31
31
  */
32
32
  findAgent: (task, maxResult = 1, agents = [], agentLocaltion = AgentLocation.ALL, getFrom) => {
33
- return new Promise((resolve, reject) => {
34
- websocket_1.default.getWebsocket.send(JSON.stringify({
35
- "type": "agentEvent",
36
- "action": "findAgent",
37
- "task": task,
38
- "agents": agents, // for filter in vector db
39
- "maxResult": maxResult,
40
- "location": agentLocaltion,
41
- "getFrom": getFrom
42
- }));
43
- websocket_1.default.getWebsocket.on('message', (data) => {
44
- const response = JSON.parse(data);
45
- if (response.type === "findAgentByTaskResponse") {
46
- resolve(response); // Resolve the Promise with the agent details
47
- }
48
- });
49
- });
33
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
34
+ "type": "agentEvent",
35
+ "action": "findAgent",
36
+ "task": task,
37
+ "agents": agents, // for filter in vector db
38
+ "maxResult": maxResult,
39
+ "location": agentLocaltion,
40
+ "getFrom": getFrom
41
+ }, "findAgentByTaskResponse");
50
42
  },
51
43
  /**
52
44
  * Starts an agent for the specified task.
@@ -54,58 +46,34 @@ const codeboltAgent = {
54
46
  * @returns {Promise<void>} A promise that resolves when the agent has been successfully started.
55
47
  */
56
48
  startAgent: (agentId, task) => {
57
- return new Promise((resolve, reject) => {
58
- websocket_1.default.getWebsocket.send(JSON.stringify({
59
- "type": "agentEvent",
60
- "action": "startAgent",
61
- "agentId": agentId,
62
- "task": task
63
- }));
64
- websocket_1.default.getWebsocket.on('message', (data) => {
65
- const response = JSON.parse(data);
66
- if (response.type === "taskCompletionResponse" && response.agentId === agentId) {
67
- resolve(response); // Resolve the Promise when the agent has been successfully started
68
- }
69
- });
70
- });
49
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
50
+ "type": "agentEvent",
51
+ "action": "startAgent",
52
+ "agentId": agentId,
53
+ "task": task
54
+ }, "taskCompletionResponse");
71
55
  },
72
56
  /**
73
57
  * Lists all available agents.
74
58
  * @returns {Promise<any>} A promise that resolves with the list of agents.
75
59
  */
76
60
  getAgentsList: (type = Agents.DOWNLOADED) => {
77
- return new Promise((resolve, reject) => {
78
- websocket_1.default.getWebsocket.send(JSON.stringify({
79
- "type": "agentEvent",
80
- "action": "listAgents",
81
- "agentType": type,
82
- }));
83
- websocket_1.default.getWebsocket.on('message', (data) => {
84
- const response = JSON.parse(data);
85
- if (response.type === "listAgentsResponse") {
86
- resolve(response); // Resolve the Promise with the list of agents
87
- }
88
- });
89
- });
61
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
62
+ "type": "agentEvent",
63
+ "action": "listAgents",
64
+ "agentType": type,
65
+ }, "listAgentsResponse");
90
66
  },
91
67
  /**
92
68
  * Lists all available agents.
93
69
  * @returns {Promise<any>} A promise that resolves with the list of agents.
94
70
  */
95
71
  getAgentsDetail: (agentList = []) => {
96
- return new Promise((resolve, reject) => {
97
- websocket_1.default.getWebsocket.send(JSON.stringify({
98
- "type": "agentEvent",
99
- "action": "agentsDetail",
100
- "agentList": agentList
101
- }));
102
- websocket_1.default.getWebsocket.on('message', (data) => {
103
- const response = JSON.parse(data);
104
- if (response.type === "listAgentsResponse") {
105
- resolve(response); // Resolve the Promise with the list of agents
106
- }
107
- });
108
- });
72
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
73
+ "type": "agentEvent",
74
+ "action": "agentsDetail",
75
+ "agentList": agentList
76
+ }, "agentsDetailResponse");
109
77
  }
110
78
  };
111
79
  exports.default = codeboltAgent;
@@ -6,7 +6,7 @@ declare const cbbrowser: {
6
6
  /**
7
7
  * Opens a new page in the browser.
8
8
  */
9
- newPage: () => Promise<unknown>;
9
+ newPage: () => Promise<any>;
10
10
  /**
11
11
  * Retrieves the current URL of the browser's active page.
12
12
  * @returns {Promise<UrlResponse>} A promise that resolves with the URL.
@@ -21,7 +21,7 @@ declare const cbbrowser: {
21
21
  /**
22
22
  * Takes a screenshot of the current page.
23
23
  */
24
- screenshot: () => Promise<unknown>;
24
+ screenshot: () => Promise<any>;
25
25
  /**
26
26
  * Retrieves the HTML content of the current page.
27
27
  * @returns {Promise<HtmlReceived>} A promise that resolves with the HTML content.
@@ -72,32 +72,32 @@ declare const cbbrowser: {
72
72
  * @param {string} pixels - The number of pixels to scroll.
73
73
  * @returns {Promise<any>} A promise that resolves when the scroll action is complete.
74
74
  */
75
- scroll: (direction: string, pixels: string) => Promise<unknown>;
75
+ scroll: (direction: string, pixels: string) => Promise<any>;
76
76
  /**
77
77
  * Types text into a specified element on the page.
78
78
  * @param {string} elementid - The ID of the element to type into.
79
79
  * @param {string} text - The text to type.
80
80
  * @returns {Promise<any>} A promise that resolves when the typing action is complete.
81
81
  */
82
- type: (elementid: string, text: string) => Promise<unknown>;
82
+ type: (elementid: string, text: string) => Promise<any>;
83
83
  /**
84
84
  * Clicks on a specified element on the page.
85
85
  * @param {string} elementid - The ID of the element to click.
86
86
  * @returns {Promise<any>} A promise that resolves when the click action is complete.
87
87
  */
88
- click: (elementid: string) => Promise<unknown>;
88
+ click: (elementid: string) => Promise<any>;
89
89
  /**
90
90
  * Simulates the Enter key press on the current page.
91
91
  * @returns {Promise<any>} A promise that resolves when the Enter action is complete.
92
92
  */
93
- enter: () => Promise<unknown>;
93
+ enter: () => Promise<any>;
94
94
  /**
95
95
  * Performs a search on the current page using a specified query.
96
96
  * @param {string} elementid - The ID of the element to perform the search in.
97
97
  * @param {string} query - The search query.
98
98
  * @returns {Promise<any>} A promise that resolves with the search results.
99
99
  */
100
- search: (elementid: string, query: string) => Promise<unknown>;
100
+ search: (elementid: string, query: string) => Promise<any>;
101
101
  };
102
102
  export default cbbrowser;
103
103
  /***
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const websocket_1 = __importDefault(require("./websocket"));
6
+ const websocket_1 = __importDefault(require("../core/websocket"));
7
7
  /**
8
8
  * A module for interacting with a browser through WebSockets.
9
9
  */
@@ -12,36 +12,20 @@ const cbbrowser = {
12
12
  * Opens a new page in the browser.
13
13
  */
14
14
  newPage: () => {
15
- return new Promise((resolve, reject) => {
16
- websocket_1.default.getWebsocket.send(JSON.stringify({
17
- "type": "browserEvent",
18
- action: 'newPage'
19
- }));
20
- websocket_1.default.getWebsocket.on('message', (data) => {
21
- const response = JSON.parse(data);
22
- if (response.event === "newPageResponse") {
23
- resolve(response);
24
- }
25
- });
26
- });
15
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
16
+ "type": "browserEvent",
17
+ action: 'newPage'
18
+ }, "newPageResponse");
27
19
  },
28
20
  /**
29
21
  * Retrieves the current URL of the browser's active page.
30
22
  * @returns {Promise<UrlResponse>} A promise that resolves with the URL.
31
23
  */
32
24
  getUrl: () => {
33
- return new Promise((resolve, reject) => {
34
- websocket_1.default.getWebsocket.send(JSON.stringify({
35
- "type": "browserEvent",
36
- action: 'getUrl'
37
- }));
38
- websocket_1.default.getWebsocket.on('message', (data) => {
39
- const response = JSON.parse(data);
40
- if (response.event === "getUrlResponse") {
41
- resolve(response);
42
- }
43
- });
44
- });
25
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
26
+ "type": "browserEvent",
27
+ action: 'getUrl'
28
+ }, "getUrlResponse");
45
29
  },
46
30
  /**
47
31
  * Navigates to a specified URL.
@@ -49,145 +33,89 @@ const cbbrowser = {
49
33
  * @returns {Promise<GoToPageResponse>} A promise that resolves when navigation is complete.
50
34
  */
51
35
  goToPage: (url) => {
52
- return new Promise((resolve, reject) => {
53
- websocket_1.default.getWebsocket.send(JSON.stringify({
54
- "type": "browserEvent",
55
- action: 'goToPage',
56
- url
57
- }));
58
- websocket_1.default.getWebsocket.on('message', (data) => {
59
- const response = JSON.parse(data);
60
- if (response.event === "goToPageResponse") {
61
- resolve(response);
62
- }
63
- });
64
- });
36
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
37
+ "type": "browserEvent",
38
+ action: 'goToPage',
39
+ url
40
+ }, "goToPageResponse");
65
41
  },
66
42
  /**
67
43
  * Takes a screenshot of the current page.
68
44
  */
69
45
  screenshot: () => {
70
- return new Promise((resolve, reject) => {
71
- websocket_1.default.getWebsocket.send(JSON.stringify({
72
- "type": "browserEvent",
73
- action: 'screenshot'
74
- }));
75
- websocket_1.default.getWebsocket.on('message', (data) => {
76
- const response = JSON.parse(data);
77
- if (response.event === "screenshotResponse") {
78
- resolve(response.payload);
79
- }
80
- });
81
- });
46
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
47
+ "type": "browserEvent",
48
+ action: 'screenshot'
49
+ }, "screenshotResponse");
82
50
  },
83
51
  /**
84
52
  * Retrieves the HTML content of the current page.
85
53
  * @returns {Promise<HtmlReceived>} A promise that resolves with the HTML content.
86
54
  */
87
55
  getHTML: () => {
88
- return new Promise((resolve, reject) => {
89
- websocket_1.default.getWebsocket.send(JSON.stringify({
90
- "type": "browserEvent",
91
- action: 'getHTML'
92
- }));
93
- websocket_1.default.getWebsocket.on('message', (data) => {
94
- const response = JSON.parse(data);
95
- if (response.event === "htmlReceived") {
96
- resolve(response.htmlResponse);
97
- }
98
- });
99
- });
56
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
57
+ "type": "browserEvent",
58
+ action: 'getHTML'
59
+ }, "htmlReceived");
100
60
  },
101
61
  /**
102
62
  * Retrieves the Markdown content of the current page.
103
63
  * @returns {Promise<GetMarkdownResponse>} A promise that resolves with the Markdown content.
104
64
  */
105
65
  getMarkdown: () => {
106
- return new Promise((resolve, reject) => {
107
- websocket_1.default.getWebsocket.send(JSON.stringify({
108
- "type": "browserEvent",
109
- action: 'getMarkdown'
110
- }));
111
- websocket_1.default.getWebsocket.on('message', (data) => {
112
- const response = JSON.parse(data);
113
- if (response.event === "getMarkdownResponse") {
114
- resolve(response);
115
- }
116
- });
117
- });
66
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
67
+ "type": "browserEvent",
68
+ action: 'getMarkdown'
69
+ }, "getMarkdownResponse");
118
70
  },
119
71
  /**
120
72
  * Retrieves the PDF content of the current page.
121
73
  *
122
74
  */
123
75
  getPDF: () => {
124
- websocket_1.default.getWebsocket.send(JSON.stringify({
76
+ websocket_1.default.messageManager.send({
125
77
  "type": "browserEvent",
126
78
  action: 'getPDF'
127
- }));
79
+ });
128
80
  },
129
81
  /**
130
82
  * Converts the PDF content of the current page to text.
131
83
  */
132
84
  pdfToText: () => {
133
- websocket_1.default.getWebsocket.send(JSON.stringify({
85
+ websocket_1.default.messageManager.send({
134
86
  "type": "browserEvent",
135
87
  action: 'pdfToText'
136
- }));
88
+ });
137
89
  },
138
90
  /**
139
91
  * Retrieves the content of the current page.
140
92
  * @returns {Promise<GetContentResponse>} A promise that resolves with the content.
141
93
  */
142
94
  getContent: () => {
143
- return new Promise((resolve, reject) => {
144
- websocket_1.default.getWebsocket.send(JSON.stringify({
145
- "type": "browserEvent",
146
- action: 'getContent'
147
- }));
148
- websocket_1.default.getWebsocket.on('message', (data) => {
149
- const response = JSON.parse(data);
150
- if (response.event === "getContentResponse") {
151
- resolve(response);
152
- }
153
- });
154
- });
95
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
96
+ "type": "browserEvent",
97
+ action: 'getContent'
98
+ }, "getContentResponse");
155
99
  },
156
100
  /**
157
101
  * Retrieves the snapshot of the current page.
158
102
  * @returns {Promise<GetContentResponse>} A promise that resolves with the content.
159
103
  */
160
104
  getSnapShot: () => {
161
- return new Promise((resolve, reject) => {
162
- websocket_1.default.getWebsocket.send(JSON.stringify({
163
- "type": "browserEvent",
164
- action: 'getSnapShot'
165
- }));
166
- websocket_1.default.getWebsocket.on('message', (data) => {
167
- const response = JSON.parse(data);
168
- if (response.event === "getSnapShotResponse") {
169
- resolve(response);
170
- }
171
- });
172
- });
105
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
106
+ "type": "browserEvent",
107
+ action: 'getSnapShot'
108
+ }, "getSnapShotResponse");
173
109
  },
174
110
  /**
175
111
  * Retrieves browser info like height width scrollx scrolly of the current page.
176
112
  * @returns {Promise<GetContentResponse>} A promise that resolves with the content.
177
113
  */
178
114
  getBrowserInfo: () => {
179
- return new Promise((resolve, reject) => {
180
- websocket_1.default.getWebsocket.send(JSON.stringify({
181
- "type": "browserEvent",
182
- action: 'getBrowserInfo'
183
- }));
184
- websocket_1.default.getWebsocket.on('message', (data) => {
185
- const response = JSON.parse(data);
186
- if (response.event === "getBrowserInfoResponse") {
187
- resolve(response);
188
- }
189
- });
190
- });
115
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
116
+ "type": "browserEvent",
117
+ action: 'getBrowserInfo'
118
+ }, "getBrowserInfoResponse");
191
119
  },
192
120
  /**
193
121
  * Extracts text from the current page.
@@ -195,27 +123,19 @@ const cbbrowser = {
195
123
  *
196
124
  */
197
125
  extractText: () => {
198
- return new Promise((resolve, reject) => {
199
- websocket_1.default.getWebsocket.send(JSON.stringify({
200
- "type": "browserEvent",
201
- action: 'extractText'
202
- }));
203
- websocket_1.default.getWebsocket.on('message', (data) => {
204
- const response = JSON.parse(data);
205
- if (response.event === "extractTextResponse") {
206
- resolve(response);
207
- }
208
- });
209
- });
126
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
127
+ "type": "browserEvent",
128
+ action: 'extractText'
129
+ }, "extractTextResponse");
210
130
  },
211
131
  /**
212
132
  * Closes the current page.
213
133
  */
214
134
  close: () => {
215
- websocket_1.default.getWebsocket.send(JSON.stringify({
135
+ websocket_1.default.messageManager.send({
216
136
  "type": "browserEvent",
217
137
  action: 'close'
218
- }));
138
+ });
219
139
  },
220
140
  /**
221
141
  * Scrolls the current page in a specified direction by a specified number of pixels.
@@ -224,20 +144,12 @@ const cbbrowser = {
224
144
  * @returns {Promise<any>} A promise that resolves when the scroll action is complete.
225
145
  */
226
146
  scroll: (direction, pixels) => {
227
- return new Promise((resolve, reject) => {
228
- websocket_1.default.getWebsocket.send(JSON.stringify({
229
- "type": "browserEvent",
230
- action: 'scroll',
231
- direction,
232
- pixels
233
- }));
234
- websocket_1.default.getWebsocket.on('message', (data) => {
235
- const response = JSON.parse(data);
236
- if (response.event === "scrollResponse") {
237
- resolve(response);
238
- }
239
- });
240
- });
147
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
148
+ "type": "browserEvent",
149
+ action: 'scroll',
150
+ direction,
151
+ pixels
152
+ }, "scrollResponse");
241
153
  },
242
154
  /**
243
155
  * Types text into a specified element on the page.
@@ -246,20 +158,12 @@ const cbbrowser = {
246
158
  * @returns {Promise<any>} A promise that resolves when the typing action is complete.
247
159
  */
248
160
  type: (elementid, text) => {
249
- return new Promise((resolve, reject) => {
250
- websocket_1.default.getWebsocket.send(JSON.stringify({
251
- "type": "browserEvent",
252
- action: 'type',
253
- text,
254
- elementid
255
- }));
256
- websocket_1.default.getWebsocket.on('message', (data) => {
257
- const response = JSON.parse(data);
258
- if (response.event === "typeResponse") {
259
- resolve(response);
260
- }
261
- });
262
- });
161
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
162
+ "type": "browserEvent",
163
+ action: 'type',
164
+ text,
165
+ elementid
166
+ }, "typeResponse");
263
167
  },
264
168
  /**
265
169
  * Clicks on a specified element on the page.
@@ -267,37 +171,21 @@ const cbbrowser = {
267
171
  * @returns {Promise<any>} A promise that resolves when the click action is complete.
268
172
  */
269
173
  click: (elementid) => {
270
- return new Promise((resolve, reject) => {
271
- websocket_1.default.getWebsocket.send(JSON.stringify({
272
- "type": "browserEvent",
273
- action: 'click',
274
- elementid
275
- }));
276
- websocket_1.default.getWebsocket.on('message', (data) => {
277
- const response = JSON.parse(data);
278
- if (response.event === "clickResponse") {
279
- resolve(response);
280
- }
281
- });
282
- });
174
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
175
+ "type": "browserEvent",
176
+ action: 'click',
177
+ elementid
178
+ }, "clickResponse");
283
179
  },
284
180
  /**
285
181
  * Simulates the Enter key press on the current page.
286
182
  * @returns {Promise<any>} A promise that resolves when the Enter action is complete.
287
183
  */
288
184
  enter: () => {
289
- return new Promise((resolve, reject) => {
290
- websocket_1.default.getWebsocket.send(JSON.stringify({
291
- "type": "browserEvent",
292
- action: 'enter'
293
- }));
294
- websocket_1.default.getWebsocket.on('message', (data) => {
295
- const response = JSON.parse(data);
296
- if (response.event === "EnterResponse") {
297
- resolve(response);
298
- }
299
- });
300
- });
185
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
186
+ "type": "browserEvent",
187
+ action: 'enter'
188
+ }, "EnterResponse");
301
189
  },
302
190
  /**
303
191
  * Performs a search on the current page using a specified query.
@@ -306,20 +194,12 @@ const cbbrowser = {
306
194
  * @returns {Promise<any>} A promise that resolves with the search results.
307
195
  */
308
196
  search: (elementid, query) => {
309
- return new Promise((resolve, reject) => {
310
- websocket_1.default.getWebsocket.send(JSON.stringify({
311
- "type": "browserEvent",
312
- action: 'search',
313
- elementid,
314
- query
315
- }));
316
- websocket_1.default.getWebsocket.on('message', (data) => {
317
- const response = JSON.parse(data);
318
- if (response.event === "searchResponse") {
319
- resolve(response);
320
- }
321
- });
322
- });
197
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
198
+ "type": "browserEvent",
199
+ action: 'search',
200
+ elementid,
201
+ query
202
+ }, "searchResponse");
323
203
  }
324
204
  };
325
205
  exports.default = cbbrowser;
@@ -1,12 +1,5 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
1
  import { ChatMessage, UserMessage } from '@codebolt/types';
4
2
  type RequestHandler = (request: any, response: (data: any) => void) => Promise<void> | void;
5
- /**
6
- * CustomEventEmitter class that extends the Node.js EventEmitter class.
7
- */
8
- declare class CustomEventEmitter extends EventEmitter {
9
- }
10
3
  /**
11
4
  * Chat module to interact with the WebSocket server.
12
5
  */
@@ -21,15 +14,6 @@ declare const cbchat: {
21
14
  * @param handler The async handler function
22
15
  */
23
16
  setRequestHandler: (handler: RequestHandler) => void;
24
- /**
25
- * Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
26
- * @returns {EventEmitter} The event emitter used for emitting custom events.
27
- */
28
- /**
29
- * Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
30
- * @returns {EventEmitter} The event emitter used for emitting custom events.
31
- */
32
- onActionMessage: () => CustomEventEmitter;
33
17
  /**
34
18
  * Sends a message through the WebSocket connection.
35
19
  * @param {string} message - The message to be sent.
@@ -42,12 +26,16 @@ declare const cbchat: {
42
26
  */
43
27
  waitforReply: (message: string) => Promise<UserMessage>;
44
28
  /**
45
- * Notifies the server that a process has started and sets up an event listener for stopProcessClicked events.
46
- * @returns An object containing the event emitter and a stopProcess method.
29
+ * Notifies the server that a process has started and sets up a listener for stopProcessClicked events.
30
+ * @param {Function} onStopClicked - Callback function to handle stop process events.
31
+ * @returns An object containing a stopProcess method.
47
32
  */
48
- processStarted: () => {
49
- event: CustomEventEmitter;
33
+ processStarted: (onStopClicked?: (message: any) => void) => {
34
+ stopProcess: () => void;
35
+ cleanup: () => void;
36
+ } | {
50
37
  stopProcess: () => void;
38
+ cleanup?: undefined;
51
39
  };
52
40
  /**
53
41
  * Stops the ongoing process.