@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.
- package/docs/modules/_internal_.EventEmitter.html +6 -0
- package/docs/modules/_internal_.WebSocket.html +21 -0
- package/docs/modules/_internal_._node_stream_consumers_.html +6 -0
- package/docs/modules/_internal_._node_stream_promises_.html +3 -0
- package/docs/modules/_internal_.html +228 -0
- package/docs/modules/_internal_.internal.finished.html +2 -0
- package/docs/modules/_internal_.internal.html +36 -0
- package/docs/modules/_internal_.internal.pipeline.html +2 -0
- package/index.d.ts +254 -0
- package/modules/browser.d.ts +108 -0
- package/modules/browser.js +331 -0
- package/modules/chat.d.ts +64 -0
- package/modules/chat.js +190 -0
- package/modules/codeparsers.d.ts +23 -0
- package/modules/codeparsers.js +30 -0
- package/modules/codeutils.d.ts +37 -0
- package/modules/codeutils.js +117 -0
- package/modules/crawler.d.ts +45 -0
- package/modules/crawler.js +123 -0
- package/modules/dbmemory.d.ts +20 -0
- package/modules/dbmemory.js +54 -0
- package/modules/debug.d.ts +23 -0
- package/modules/debug.js +64 -0
- package/modules/docutils.d.ts +12 -0
- package/modules/docutils.js +19 -0
- package/modules/fs.d.ts +94 -0
- package/modules/fs.js +264 -0
- package/modules/git.d.ts +76 -0
- package/modules/git.js +240 -0
- package/modules/history.d.ts +19 -0
- package/modules/history.js +46 -0
- package/modules/knowledge.d.ts +2 -0
- package/modules/knowledge.js +6 -0
- package/modules/llm.d.ts +18 -0
- package/modules/llm.js +39 -0
- package/modules/mcp.d.ts +8 -0
- package/modules/mcp.js +139 -0
- package/modules/outputparsers.d.ts +24 -0
- package/modules/outputparsers.js +32 -0
- package/modules/project.d.ts +21 -0
- package/modules/project.js +72 -0
- package/modules/rag.d.ts +22 -0
- package/modules/rag.js +30 -0
- package/modules/search.d.ts +23 -0
- package/modules/search.js +37 -0
- package/modules/state.d.ts +21 -0
- package/modules/state.js +68 -0
- package/modules/task.d.ts +23 -0
- package/modules/task.js +75 -0
- package/modules/terminal.d.ts +46 -0
- package/modules/terminal.js +108 -0
- package/modules/tokenizer.d.ts +19 -0
- package/modules/tokenizer.js +56 -0
- package/modules/vectordb.d.ts +33 -0
- package/modules/vectordb.js +103 -0
- package/modules/websocket.d.ts +27 -0
- package/modules/websocket.js +88 -0
- package/package.json +1 -1
- package/src/modules/browser.ts +352 -0
- package/src/modules/chat.ts +193 -0
- package/src/modules/codeparsers.ts +30 -0
- package/src/modules/codeutils.ts +126 -0
- package/src/modules/crawler.ts +121 -0
- package/src/modules/dbmemory.ts +52 -0
- package/src/modules/debug.ts +68 -0
- package/src/modules/docutils.ts +18 -0
- package/src/modules/fs.ts +263 -0
- package/src/modules/git.ts +237 -0
- package/src/modules/history.ts +61 -0
- package/src/modules/knowledge.ts +5 -0
- package/src/modules/llm.ts +36 -0
- package/src/modules/mcp.ts +127 -0
- package/src/modules/outputparsers.ts +30 -0
- package/src/modules/project.ts +68 -0
- package/src/modules/rag.ts +28 -0
- package/src/modules/search.ts +35 -0
- package/src/modules/state.ts +69 -0
- package/src/modules/task.ts +73 -0
- package/src/modules/terminal.ts +114 -0
- package/src/modules/tokenizer.ts +56 -0
- package/src/modules/vectordb.ts +102 -0
- package/src/modules/websocket.ts +89 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const websocket_1 = __importDefault(require("./websocket"));
|
|
7
|
+
/**
|
|
8
|
+
* A module for interacting with a browser through WebSockets.
|
|
9
|
+
*/
|
|
10
|
+
const cbbrowser = {
|
|
11
|
+
/**
|
|
12
|
+
* Opens a new page in the browser.
|
|
13
|
+
*/
|
|
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
|
+
});
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the current URL of the browser's active page.
|
|
30
|
+
* @returns {Promise<UrlResponse>} A promise that resolves with the URL.
|
|
31
|
+
*/
|
|
32
|
+
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
|
+
});
|
|
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) => {
|
|
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
|
+
});
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Takes a screenshot of the current page.
|
|
68
|
+
*/
|
|
69
|
+
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
|
+
});
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves the HTML content of the current page.
|
|
85
|
+
* @returns {Promise<HtmlReceived>} A promise that resolves with the HTML content.
|
|
86
|
+
*/
|
|
87
|
+
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
|
+
});
|
|
100
|
+
},
|
|
101
|
+
/**
|
|
102
|
+
* Retrieves the Markdown content of the current page.
|
|
103
|
+
* @returns {Promise<GetMarkdownResponse>} A promise that resolves with the Markdown content.
|
|
104
|
+
*/
|
|
105
|
+
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
|
+
});
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* Retrieves the PDF content of the current page.
|
|
121
|
+
*
|
|
122
|
+
*/
|
|
123
|
+
getPDF: () => {
|
|
124
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
125
|
+
"type": "browserEvent",
|
|
126
|
+
action: 'getPDF'
|
|
127
|
+
}));
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Converts the PDF content of the current page to text.
|
|
131
|
+
*/
|
|
132
|
+
pdfToText: () => {
|
|
133
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
134
|
+
"type": "browserEvent",
|
|
135
|
+
action: 'pdfToText'
|
|
136
|
+
}));
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Retrieves the content of the current page.
|
|
140
|
+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
|
|
141
|
+
*/
|
|
142
|
+
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
|
+
});
|
|
155
|
+
},
|
|
156
|
+
/**
|
|
157
|
+
* Retrieves the snapshot of the current page.
|
|
158
|
+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
|
|
159
|
+
*/
|
|
160
|
+
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
|
+
});
|
|
173
|
+
},
|
|
174
|
+
/**
|
|
175
|
+
* Retrieves browser info like height width scrollx scrolly of the current page.
|
|
176
|
+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
|
|
177
|
+
*/
|
|
178
|
+
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
|
+
});
|
|
191
|
+
},
|
|
192
|
+
/**
|
|
193
|
+
* Extracts text from the current page.
|
|
194
|
+
* @returns {Promise<ExtractTextResponse>} A promise that resolves with the extracted text.
|
|
195
|
+
*
|
|
196
|
+
*/
|
|
197
|
+
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
|
+
});
|
|
210
|
+
},
|
|
211
|
+
/**
|
|
212
|
+
* Closes the current page.
|
|
213
|
+
*/
|
|
214
|
+
close: () => {
|
|
215
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
216
|
+
"type": "browserEvent",
|
|
217
|
+
action: 'close'
|
|
218
|
+
}));
|
|
219
|
+
},
|
|
220
|
+
/**
|
|
221
|
+
* Scrolls the current page in a specified direction by a specified number of pixels.
|
|
222
|
+
* @param {string} direction - The direction to scroll.
|
|
223
|
+
* @param {string} pixels - The number of pixels to scroll.
|
|
224
|
+
* @returns {Promise<any>} A promise that resolves when the scroll action is complete.
|
|
225
|
+
*/
|
|
226
|
+
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
|
+
});
|
|
241
|
+
},
|
|
242
|
+
/**
|
|
243
|
+
* Types text into a specified element on the page.
|
|
244
|
+
* @param {string} elementid - The ID of the element to type into.
|
|
245
|
+
* @param {string} text - The text to type.
|
|
246
|
+
* @returns {Promise<any>} A promise that resolves when the typing action is complete.
|
|
247
|
+
*/
|
|
248
|
+
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
|
+
});
|
|
263
|
+
},
|
|
264
|
+
/**
|
|
265
|
+
* Clicks on a specified element on the page.
|
|
266
|
+
* @param {string} elementid - The ID of the element to click.
|
|
267
|
+
* @returns {Promise<any>} A promise that resolves when the click action is complete.
|
|
268
|
+
*/
|
|
269
|
+
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
|
+
});
|
|
283
|
+
},
|
|
284
|
+
/**
|
|
285
|
+
* Simulates the Enter key press on the current page.
|
|
286
|
+
* @returns {Promise<any>} A promise that resolves when the Enter action is complete.
|
|
287
|
+
*/
|
|
288
|
+
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
|
+
});
|
|
301
|
+
},
|
|
302
|
+
/**
|
|
303
|
+
* Performs a search on the current page using a specified query.
|
|
304
|
+
* @param {string} elementid - The ID of the element to perform the search in.
|
|
305
|
+
* @param {string} query - The search query.
|
|
306
|
+
* @returns {Promise<any>} A promise that resolves with the search results.
|
|
307
|
+
*/
|
|
308
|
+
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
|
+
});
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
exports.default = cbbrowser;
|
|
326
|
+
/***
|
|
327
|
+
|
|
328
|
+
start_browser(objective: string, url: string, previous_command: string, browser_content: string) {
|
|
329
|
+
cbbrowser.newPage();
|
|
330
|
+
}
|
|
331
|
+
*/
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { ChatMessage, UserMessage } from '@codebolt/types';
|
|
4
|
+
/**
|
|
5
|
+
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
6
|
+
*/
|
|
7
|
+
declare class CustomEventEmitter extends EventEmitter {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Chat module to interact with the WebSocket server.
|
|
11
|
+
*/
|
|
12
|
+
declare const cbchat: {
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the chat history from the server.
|
|
15
|
+
* @returns {Promise<ChatMessage[]>} A promise that resolves with an array of ChatMessage objects representing the chat history.
|
|
16
|
+
*/
|
|
17
|
+
getChatHistory: () => Promise<ChatMessage[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
|
|
20
|
+
* @returns {EventEmitter} The event emitter used for emitting custom events.
|
|
21
|
+
*/
|
|
22
|
+
onActionMessage: () => CustomEventEmitter | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Sends a message through the WebSocket connection.
|
|
25
|
+
* @param {string} message - The message to be sent.
|
|
26
|
+
*/
|
|
27
|
+
sendMessage: (message: string, payload: any) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Waits for a reply to a sent message.
|
|
30
|
+
* @param {string} message - The message for which a reply is expected.
|
|
31
|
+
* @returns {Promise<UserMessage>} A promise that resolves with the reply.
|
|
32
|
+
*/
|
|
33
|
+
waitforReply: (message: string) => Promise<UserMessage>;
|
|
34
|
+
/**
|
|
35
|
+
* Notifies the server that a process has started and sets up an event listener for stopProcessClicked events.
|
|
36
|
+
* @returns An object containing the event emitter and a stopProcess method.
|
|
37
|
+
*/
|
|
38
|
+
processStarted: () => {
|
|
39
|
+
event: CustomEventEmitter;
|
|
40
|
+
stopProcess: () => void;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Stops the ongoing process.
|
|
44
|
+
* Sends a specific message to the server to stop the process.
|
|
45
|
+
*/
|
|
46
|
+
stopProcess: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Stops the ongoing process.
|
|
49
|
+
* Sends a specific message to the server to stop the process.
|
|
50
|
+
*/
|
|
51
|
+
processFinished: () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Sends a confirmation request to the server with two options: Yes or No.
|
|
54
|
+
* @returns {Promise<string>} A promise that resolves with the server's response.
|
|
55
|
+
*/
|
|
56
|
+
sendConfirmationRequest: (confirmationMessage: string, buttons?: string[], withFeedback?: boolean) => Promise<string>;
|
|
57
|
+
askQuestion: (question: string, buttons?: string[], withFeedback?: boolean) => Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Sends a notification event to the server.
|
|
60
|
+
* @param {string} notificationMessage - The message to be sent in the notification.
|
|
61
|
+
*/
|
|
62
|
+
sendNotificationEvent: (notificationMessage: string, type: 'debug' | 'git' | 'planner' | 'browser' | 'editor' | 'terminal' | 'preview') => void;
|
|
63
|
+
};
|
|
64
|
+
export default cbchat;
|
package/modules/chat.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// chat.ts
|
|
7
|
+
const websocket_1 = __importDefault(require("./websocket"));
|
|
8
|
+
const events_1 = require("events");
|
|
9
|
+
/**
|
|
10
|
+
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
11
|
+
*/
|
|
12
|
+
class CustomEventEmitter extends events_1.EventEmitter {
|
|
13
|
+
}
|
|
14
|
+
let eventEmitter = new CustomEventEmitter();
|
|
15
|
+
/**
|
|
16
|
+
* Chat module to interact with the WebSocket server.
|
|
17
|
+
*/
|
|
18
|
+
const cbchat = {
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the chat history from the server.
|
|
21
|
+
* @returns {Promise<ChatMessage[]>} A promise that resolves with an array of ChatMessage objects representing the chat history.
|
|
22
|
+
*/
|
|
23
|
+
getChatHistory: () => {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
26
|
+
"type": "getChatHistory"
|
|
27
|
+
}));
|
|
28
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
29
|
+
const response = JSON.parse(data);
|
|
30
|
+
if (response.type === "getChatHistoryResponse") {
|
|
31
|
+
resolve(response); // Resolve the Promise with the response data
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
|
|
38
|
+
* @returns {EventEmitter} The event emitter used for emitting custom events.
|
|
39
|
+
*/
|
|
40
|
+
onActionMessage: () => {
|
|
41
|
+
if (!websocket_1.default.getWebsocket)
|
|
42
|
+
return;
|
|
43
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
44
|
+
const response = JSON.parse(data);
|
|
45
|
+
if (response.type === "messageResponse") {
|
|
46
|
+
// Pass a callback function as an argument to the emit method
|
|
47
|
+
eventEmitter.emit("userMessage", response, (message) => {
|
|
48
|
+
console.log("Callback function invoked with message:", message);
|
|
49
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
50
|
+
"type": "processStoped"
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return eventEmitter;
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Sends a message through the WebSocket connection.
|
|
59
|
+
* @param {string} message - The message to be sent.
|
|
60
|
+
*/
|
|
61
|
+
sendMessage: (message, payload) => {
|
|
62
|
+
console.log(message);
|
|
63
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
64
|
+
"type": "sendMessage",
|
|
65
|
+
"message": message,
|
|
66
|
+
payload
|
|
67
|
+
}));
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* Waits for a reply to a sent message.
|
|
71
|
+
* @param {string} message - The message for which a reply is expected.
|
|
72
|
+
* @returns {Promise<UserMessage>} A promise that resolves with the reply.
|
|
73
|
+
*/
|
|
74
|
+
waitforReply: (message) => {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
77
|
+
"type": "waitforReply",
|
|
78
|
+
"message": message
|
|
79
|
+
}));
|
|
80
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
81
|
+
const response = JSON.parse(data);
|
|
82
|
+
if (response.type === "waitFormessageResponse") {
|
|
83
|
+
resolve(response); // Resolve the Promise with the response data
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Notifies the server that a process has started and sets up an event listener for stopProcessClicked events.
|
|
90
|
+
* @returns An object containing the event emitter and a stopProcess method.
|
|
91
|
+
*/
|
|
92
|
+
processStarted: () => {
|
|
93
|
+
// Send the process started message
|
|
94
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
95
|
+
"type": "processStarted"
|
|
96
|
+
}));
|
|
97
|
+
// Register event listener for WebSocket messages
|
|
98
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
99
|
+
const message = JSON.parse(data);
|
|
100
|
+
console.log("Received message:", message);
|
|
101
|
+
if (message.type === 'stopProcessClicked')
|
|
102
|
+
// Emit a custom event based on the message type
|
|
103
|
+
eventEmitter.emit("stopProcessClicked", message);
|
|
104
|
+
});
|
|
105
|
+
// Return an object that includes the event emitter and the stopProcess method
|
|
106
|
+
return {
|
|
107
|
+
event: eventEmitter,
|
|
108
|
+
stopProcess: () => {
|
|
109
|
+
// Implement the logic to stop the process here
|
|
110
|
+
console.log("Stopping process...");
|
|
111
|
+
// For example, you might want to send a specific message to the server to stop the process
|
|
112
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
113
|
+
"type": "processStoped"
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Stops the ongoing process.
|
|
120
|
+
* Sends a specific message to the server to stop the process.
|
|
121
|
+
*/
|
|
122
|
+
stopProcess: () => {
|
|
123
|
+
// Implement the logic to stop the process here
|
|
124
|
+
console.log("Stopping process...");
|
|
125
|
+
// For example, you might want to send a specific message to the server to stop the process
|
|
126
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
127
|
+
"type": "processStoped"
|
|
128
|
+
}));
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* Stops the ongoing process.
|
|
132
|
+
* Sends a specific message to the server to stop the process.
|
|
133
|
+
*/
|
|
134
|
+
processFinished: () => {
|
|
135
|
+
// Implement the logic to stop the process here
|
|
136
|
+
console.log("Process Finished ...");
|
|
137
|
+
// For example, you might want to send a specific message to the server to stop the process
|
|
138
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
139
|
+
"type": "processFinished"
|
|
140
|
+
}));
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* Sends a confirmation request to the server with two options: Yes or No.
|
|
144
|
+
* @returns {Promise<string>} A promise that resolves with the server's response.
|
|
145
|
+
*/
|
|
146
|
+
sendConfirmationRequest: (confirmationMessage, buttons = [], withFeedback = false) => {
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
149
|
+
"type": "confirmationRequest",
|
|
150
|
+
"message": confirmationMessage,
|
|
151
|
+
buttons: buttons,
|
|
152
|
+
withFeedback
|
|
153
|
+
}));
|
|
154
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
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, buttons = [], withFeedback = false) => {
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
165
|
+
"type": "confirmationRequest",
|
|
166
|
+
"message": question,
|
|
167
|
+
buttons: buttons,
|
|
168
|
+
withFeedback
|
|
169
|
+
}));
|
|
170
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
171
|
+
const response = JSON.parse(data);
|
|
172
|
+
if (response.type === "confirmationResponse" || response.type === "feedbackResponse") {
|
|
173
|
+
resolve(response); // Resolve the Promise with the server's response
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
/**
|
|
179
|
+
* Sends a notification event to the server.
|
|
180
|
+
* @param {string} notificationMessage - The message to be sent in the notification.
|
|
181
|
+
*/
|
|
182
|
+
sendNotificationEvent: (notificationMessage, type) => {
|
|
183
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
184
|
+
"type": "notificationEvent",
|
|
185
|
+
"message": notificationMessage,
|
|
186
|
+
"eventType": type
|
|
187
|
+
}));
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
exports.default = cbchat;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A collection of code parser functions.
|
|
3
|
+
*/
|
|
4
|
+
declare 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) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the functions in a given class within a file.
|
|
12
|
+
* @param file The file containing the class.
|
|
13
|
+
* @param className The name of the class to parse for functions.
|
|
14
|
+
*/
|
|
15
|
+
getFunctionsinClass: (file: any, className: any) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Generates an Abstract Syntax Tree (AST) for a given file.
|
|
18
|
+
* @param file The file to generate an AST for.
|
|
19
|
+
* @param className The name of the class to focus the AST generation on.
|
|
20
|
+
*/
|
|
21
|
+
getAstTreeInFile: (file: any, className: any) => void;
|
|
22
|
+
};
|
|
23
|
+
export default cbcodeparsers;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* A collection of code parser functions.
|
|
5
|
+
*/
|
|
6
|
+
const cbcodeparsers = {
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves the classes in a given file.
|
|
9
|
+
* @param file The file to parse for classes.
|
|
10
|
+
*/
|
|
11
|
+
getClassesInFile: (file) => {
|
|
12
|
+
console.log('Code parsers initialized');
|
|
13
|
+
},
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the functions in a given class within a file.
|
|
16
|
+
* @param file The file containing the class.
|
|
17
|
+
* @param className The name of the class to parse for functions.
|
|
18
|
+
*/
|
|
19
|
+
getFunctionsinClass: (file, className) => {
|
|
20
|
+
console.log('Code parsers initialized');
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Generates an Abstract Syntax Tree (AST) for a given file.
|
|
24
|
+
* @param file The file to generate an AST for.
|
|
25
|
+
* @param className The name of the class to focus the AST generation on.
|
|
26
|
+
*/
|
|
27
|
+
getAstTreeInFile: (file, className) => {
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.default = cbcodeparsers;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
|
|
2
|
+
/**
|
|
3
|
+
* A utility module for working with code.
|
|
4
|
+
*/
|
|
5
|
+
declare const cbcodeutils: {
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves a JavaScript tree structure for a given file path.
|
|
8
|
+
* @param {string} filePath - The path of the file to retrieve the JS tree for.
|
|
9
|
+
* @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
|
|
10
|
+
*/
|
|
11
|
+
getJsTree: (filePath?: string) => Promise<unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves all files as Markdown.
|
|
14
|
+
* @returns {Promise<string>} A promise that resolves with the Markdown content of all files.
|
|
15
|
+
*/
|
|
16
|
+
getAllFilesAsMarkDown: () => Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Performs a matching operation based on the provided matcher definition and problem patterns.
|
|
19
|
+
* @param {object} matcherDefinition - The definition of the matcher.
|
|
20
|
+
* @param {Array} problemPatterns - The patterns to match against.
|
|
21
|
+
* @param {Array} problems - The list of problems.
|
|
22
|
+
* @returns {Promise<MatchProblemResponse>} A promise that resolves with the matching problem response.
|
|
23
|
+
*/
|
|
24
|
+
performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<MatchProblemResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the list of matchers.
|
|
27
|
+
* @returns {Promise<GetMatcherListTreeResponse>} A promise that resolves with the list of matchers response.
|
|
28
|
+
*/
|
|
29
|
+
getMatcherList: () => Promise<GetMatcherListTreeResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves details of a match.
|
|
32
|
+
* @param {string} matcher - The matcher to retrieve details for.
|
|
33
|
+
* @returns {Promise<getMatchDetail>} A promise that resolves with the match detail response.
|
|
34
|
+
*/
|
|
35
|
+
matchDetail: (matcher: string) => Promise<getMatchDetail>;
|
|
36
|
+
};
|
|
37
|
+
export default cbcodeutils;
|