@codebolt/codeboltjs 2.0.4 → 2.0.5
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/dist/core/messageManager.d.ts +47 -0
- package/dist/core/messageManager.js +128 -0
- package/dist/{modules → core}/websocket.d.ts +5 -0
- package/dist/{modules → core}/websocket.js +13 -9
- package/dist/index.d.ts +42 -53
- package/dist/index.js +49 -4
- package/dist/modules/agent.js +26 -58
- package/dist/modules/browser.d.ts +7 -7
- package/dist/modules/browser.js +75 -195
- package/dist/modules/chat.d.ts +8 -20
- package/dist/modules/chat.js +60 -123
- package/dist/modules/codeutils.d.ts +1 -1
- package/dist/modules/codeutils.js +30 -107
- package/dist/modules/crawler.d.ts +1 -16
- package/dist/modules/crawler.js +13 -72
- package/dist/modules/dbmemory.js +12 -28
- package/dist/modules/debug.js +17 -33
- package/dist/modules/fs.d.ts +1 -1
- package/dist/modules/fs.js +82 -162
- package/dist/modules/git.js +60 -148
- package/dist/modules/history.js +11 -27
- package/dist/modules/llm.js +8 -16
- package/dist/modules/project.d.ts +1 -1
- package/dist/modules/project.js +16 -40
- package/dist/modules/state.js +29 -69
- package/dist/modules/task.js +19 -43
- package/dist/modules/terminal.d.ts +3 -2
- package/dist/modules/terminal.js +36 -47
- package/dist/modules/tokenizer.js +15 -31
- package/dist/modules/tools.d.ts +0 -6
- package/dist/modules/tools.js +41 -179
- package/dist/modules/utils.js +22 -0
- package/dist/modules/vectordb.js +30 -62
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/dist/utils/editFile.js +0 -30
- /package/dist/{utils/editFile.d.ts → modules/utils.d.ts} +0 -0
- /package/dist/{modules → utils}/toolBox.d.ts +0 -0
- /package/dist/{modules → utils}/toolBox.js +0 -0
package/dist/modules/browser.js
CHANGED
|
@@ -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("
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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.
|
|
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.
|
|
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
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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.
|
|
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
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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;
|
package/dist/modules/chat.d.ts
CHANGED
|
@@ -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
|
|
46
|
-
* @
|
|
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
|
-
|
|
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.
|