@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.
Files changed (40) 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 +13 -9
  5. package/dist/index.d.ts +42 -53
  6. package/dist/index.js +49 -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/codeutils.d.ts +1 -1
  13. package/dist/modules/codeutils.js +30 -107
  14. package/dist/modules/crawler.d.ts +1 -16
  15. package/dist/modules/crawler.js +13 -72
  16. package/dist/modules/dbmemory.js +12 -28
  17. package/dist/modules/debug.js +17 -33
  18. package/dist/modules/fs.d.ts +1 -1
  19. package/dist/modules/fs.js +82 -162
  20. package/dist/modules/git.js +60 -148
  21. package/dist/modules/history.js +11 -27
  22. package/dist/modules/llm.js +8 -16
  23. package/dist/modules/project.d.ts +1 -1
  24. package/dist/modules/project.js +16 -40
  25. package/dist/modules/state.js +29 -69
  26. package/dist/modules/task.js +19 -43
  27. package/dist/modules/terminal.d.ts +3 -2
  28. package/dist/modules/terminal.js +36 -47
  29. package/dist/modules/tokenizer.js +15 -31
  30. package/dist/modules/tools.d.ts +0 -6
  31. package/dist/modules/tools.js +41 -179
  32. package/dist/modules/utils.js +22 -0
  33. package/dist/modules/vectordb.js +30 -62
  34. package/dist/utils.d.ts +1 -1
  35. package/dist/utils.js +1 -1
  36. package/package.json +1 -1
  37. package/dist/utils/editFile.js +0 -30
  38. /package/dist/{utils/editFile.d.ts → modules/utils.d.ts} +0 -0
  39. /package/dist/{modules → utils}/toolBox.d.ts +0 -0
  40. /package/dist/{modules → utils}/toolBox.js +0 -0
@@ -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 handling in-memory database operations via WebSocket.
9
9
  */
@@ -15,20 +15,12 @@ const dbmemory = {
15
15
  * @returns {Promise<MemorySetResponse>} A promise that resolves with the response from the memory set event.
16
16
  */
17
17
  addKnowledge: (key, value) => {
18
- return new Promise((resolve, reject) => {
19
- websocket_1.default.getWebsocket.send(JSON.stringify({
20
- "type": "memoryEvent",
21
- 'action': 'set',
22
- key,
23
- value
24
- }));
25
- websocket_1.default.getWebsocket.on('message', (data) => {
26
- const response = JSON.parse(data);
27
- if (response.type === "memorySetResponse") {
28
- resolve(response); // Resolve the Promise with the response data
29
- }
30
- });
31
- });
18
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
19
+ "type": "memoryEvent",
20
+ 'action': 'set',
21
+ key,
22
+ value
23
+ }, "memorySetResponse");
32
24
  },
33
25
  /**
34
26
  * Retrieves a value from the in-memory database by key.
@@ -36,19 +28,11 @@ const dbmemory = {
36
28
  * @returns {Promise<MemoryGetResponse>} A promise that resolves with the response from the memory get event.
37
29
  */
38
30
  getKnowledge: (key) => {
39
- return new Promise((resolve, reject) => {
40
- websocket_1.default.getWebsocket.send(JSON.stringify({
41
- "type": "memoryEvent",
42
- 'action': 'get',
43
- key
44
- }));
45
- websocket_1.default.getWebsocket.on('message', (data) => {
46
- const response = JSON.parse(data);
47
- if (response.type === "memoryGetResponse") {
48
- resolve(response); // Resolve the Promise with the response data
49
- }
50
- });
51
- });
31
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
32
+ "type": "memoryEvent",
33
+ 'action': 'get',
34
+ key
35
+ }, "memoryGetResponse");
52
36
  }
53
37
  };
54
38
  exports.default = dbmemory;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.debug = exports.logType = void 0;
7
- const websocket_1 = __importDefault(require("./websocket"));
7
+ const websocket_1 = __importDefault(require("../core/websocket"));
8
8
  var logType;
9
9
  (function (logType) {
10
10
  logType["info"] = "info";
@@ -19,22 +19,14 @@ exports.debug = {
19
19
  * @returns {Promise<DebugAddLogResponse>} A promise that resolves with the response from the debug event.
20
20
  */
21
21
  debug: (log, type) => {
22
- return new Promise((resolve, reject) => {
23
- websocket_1.default.getWebsocket.send(JSON.stringify({
24
- "type": "debugEvent",
25
- "action": "addLog",
26
- message: {
27
- log,
28
- type
29
- }
30
- }));
31
- websocket_1.default.getWebsocket.on('message', (data) => {
32
- const response = JSON.parse(data);
33
- if (response.type === "debugEventResponse") {
34
- resolve(response); // Resolve the Promise with the response data
35
- }
36
- });
37
- });
22
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
23
+ "type": "debugEvent",
24
+ "action": "addLog",
25
+ message: {
26
+ log,
27
+ type
28
+ }
29
+ }, "debugEventResponse");
38
30
  },
39
31
  /**
40
32
  * Requests to open a debug browser at the specified URL and port.
@@ -43,22 +35,14 @@ exports.debug = {
43
35
  * @returns {Promise<OpenDebugBrowserResponse>} A promise that resolves with the response from the open debug browser event.
44
36
  */
45
37
  openDebugBrowser: (url, port) => {
46
- return new Promise((resolve, reject) => {
47
- websocket_1.default.getWebsocket.send(JSON.stringify({
48
- "type": "debugEvent",
49
- "action": "openDebugBrowser",
50
- message: {
51
- url,
52
- port
53
- }
54
- }));
55
- websocket_1.default.getWebsocket.on('message', (data) => {
56
- const response = JSON.parse(data);
57
- if (response.type === "openDebugBrowserResponse") {
58
- resolve(response); // Resolve the Promise with the response data
59
- }
60
- });
61
- });
38
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
39
+ "type": "debugEvent",
40
+ "action": "openDebugBrowser",
41
+ message: {
42
+ url,
43
+ port
44
+ }
45
+ }, "openDebugBrowserResponse");
62
46
  }
63
47
  };
64
48
  exports.default = exports.debug;
@@ -89,6 +89,6 @@ declare const cbfs: {
89
89
  * @param {string} newContent - The new content to write into the file.
90
90
  * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the write operation result.
91
91
  */
92
- writeToFile: (relPath: string, newContent: string) => Promise<unknown>;
92
+ writeToFile: (relPath: string, newContent: string) => Promise<any>;
93
93
  };
94
94
  export default cbfs;
@@ -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
  * @module cbfs
9
9
  * @description This module provides functionality to interact with the filesystem.
@@ -18,23 +18,15 @@ const cbfs = {
18
18
  * @returns {Promise<CreateFileResponse>} A promise that resolves with the server response.
19
19
  */
20
20
  createFile: (fileName, source, filePath) => {
21
- return new Promise((resolve, reject) => {
22
- websocket_1.default.getWebsocket.send(JSON.stringify({
23
- "type": "fsEvent",
24
- "action": "createFile",
25
- "message": {
26
- fileName,
27
- source,
28
- filePath
29
- },
30
- }));
31
- websocket_1.default.getWebsocket.on('message', (data) => {
32
- const response = JSON.parse(data);
33
- if (response.type === "createFileResponse") {
34
- resolve(response);
35
- }
36
- });
37
- });
21
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
22
+ "type": "fsEvent",
23
+ "action": "createFile",
24
+ "message": {
25
+ fileName,
26
+ source,
27
+ filePath
28
+ },
29
+ }, "createFileResponse");
38
30
  },
39
31
  /**
40
32
  * @function createFolder
@@ -44,22 +36,14 @@ const cbfs = {
44
36
  * @returns {Promise<CreateFolderResponse>} A promise that resolves with the server response.
45
37
  */
46
38
  createFolder: (folderName, folderPath) => {
47
- return new Promise((resolve, reject) => {
48
- websocket_1.default.getWebsocket.send(JSON.stringify({
49
- "type": "fsEvent",
50
- "action": "createFolder",
51
- "message": {
52
- folderName,
53
- folderPath
54
- },
55
- }));
56
- websocket_1.default.getWebsocket.on('message', (data) => {
57
- const response = JSON.parse(data);
58
- if (response.type === "createFolderResponse") {
59
- resolve(response);
60
- }
61
- });
62
- });
39
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
40
+ "type": "fsEvent",
41
+ "action": "createFolder",
42
+ "message": {
43
+ folderName,
44
+ folderPath
45
+ },
46
+ }, "createFolderResponse");
63
47
  },
64
48
  /**
65
49
  * @function readFile
@@ -69,21 +53,13 @@ const cbfs = {
69
53
  * @returns {Promise<ReadFileResponse>} A promise that resolves with the server response.
70
54
  */
71
55
  readFile: (filePath) => {
72
- return new Promise((resolve, reject) => {
73
- websocket_1.default.getWebsocket.send(JSON.stringify({
74
- "type": "fsEvent",
75
- "action": "readFile",
76
- "message": {
77
- filePath
78
- },
79
- }));
80
- websocket_1.default.getWebsocket.on('message', (data) => {
81
- const response = JSON.parse(data);
82
- if (response.type === "readFileResponse") {
83
- resolve(response);
84
- }
85
- });
86
- });
56
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
57
+ "type": "fsEvent",
58
+ "action": "readFile",
59
+ "message": {
60
+ filePath
61
+ },
62
+ }, "readFileResponse");
87
63
  },
88
64
  /**
89
65
  * @function updateFile
@@ -94,23 +70,15 @@ const cbfs = {
94
70
  * @returns {Promise<UpdateFileResponse>} A promise that resolves with the server response.
95
71
  */
96
72
  updateFile: (filename, filePath, newContent) => {
97
- return new Promise((resolve, reject) => {
98
- websocket_1.default.getWebsocket.send(JSON.stringify({
99
- "type": "fsEvent",
100
- "action": "updateFile",
101
- "message": {
102
- filename,
103
- filePath,
104
- newContent
105
- },
106
- }));
107
- websocket_1.default.getWebsocket.on('message', (data) => {
108
- const response = JSON.parse(data);
109
- if (response.type === "commandOutput") {
110
- resolve(response);
111
- }
112
- });
113
- });
73
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
74
+ "type": "fsEvent",
75
+ "action": "updateFile",
76
+ "message": {
77
+ filename,
78
+ filePath,
79
+ newContent
80
+ },
81
+ }, "commandOutput");
114
82
  },
115
83
  /**
116
84
  * @function deleteFile
@@ -120,22 +88,14 @@ const cbfs = {
120
88
  * @returns {Promise<DeleteFileResponse>} A promise that resolves with the server response.
121
89
  */
122
90
  deleteFile: (filename, filePath) => {
123
- return new Promise((resolve, reject) => {
124
- websocket_1.default.getWebsocket.send(JSON.stringify({
125
- "type": "fsEvent",
126
- "action": "deleteFile",
127
- "message": {
128
- filename,
129
- filePath
130
- },
131
- }));
132
- websocket_1.default.getWebsocket.on('message', (data) => {
133
- const response = JSON.parse(data);
134
- if (response.type === "deleteFileResponse") {
135
- resolve(response);
136
- }
137
- });
138
- });
91
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
92
+ "type": "fsEvent",
93
+ "action": "deleteFile",
94
+ "message": {
95
+ filename,
96
+ filePath
97
+ },
98
+ }, "deleteFileResponse");
139
99
  },
140
100
  /**
141
101
  * @function deleteFolder
@@ -145,22 +105,14 @@ const cbfs = {
145
105
  * @returns {Promise<DeleteFolderResponse>} A promise that resolves with the server response.
146
106
  */
147
107
  deleteFolder: (foldername, folderpath) => {
148
- return new Promise((resolve, reject) => {
149
- websocket_1.default.getWebsocket.send(JSON.stringify({
150
- "type": "fsEvent",
151
- "action": "deleteFolder",
152
- "message": {
153
- foldername,
154
- folderpath
155
- },
156
- }));
157
- websocket_1.default.getWebsocket.on('message', (data) => {
158
- const response = JSON.parse(data);
159
- if (response.type === "deleteFolderResponse") {
160
- resolve(response);
161
- }
162
- });
163
- });
108
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
109
+ "type": "fsEvent",
110
+ "action": "deleteFolder",
111
+ "message": {
112
+ foldername,
113
+ folderpath
114
+ },
115
+ }, "deleteFolderResponse");
164
116
  },
165
117
  /**
166
118
  * @function listFile
@@ -168,22 +120,14 @@ const cbfs = {
168
120
  * @returns {Promise<FileListResponse>} A promise that resolves with the list of files.
169
121
  */
170
122
  listFile: (folderPath, isRecursive = false) => {
171
- return new Promise((resolve, reject) => {
172
- websocket_1.default.getWebsocket.send(JSON.stringify({
173
- "type": "fsEvent",
174
- "action": "fileList",
175
- message: {
176
- folderPath,
177
- isRecursive
178
- }
179
- }));
180
- websocket_1.default.getWebsocket.on('message', (data) => {
181
- const response = JSON.parse(data);
182
- if (response.type === "fileListResponse") {
183
- resolve(response);
184
- }
185
- });
186
- });
123
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
124
+ "type": "fsEvent",
125
+ "action": "fileList",
126
+ message: {
127
+ folderPath,
128
+ isRecursive
129
+ }
130
+ }, "fileListResponse");
187
131
  },
188
132
  /**
189
133
  * @function listCodeDefinitionNames
@@ -192,21 +136,13 @@ const cbfs = {
192
136
  * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the list of code definition names.
193
137
  */
194
138
  listCodeDefinitionNames: (path) => {
195
- return new Promise((resolve, reject) => {
196
- websocket_1.default.getWebsocket.send(JSON.stringify({
197
- "type": "fsEvent",
198
- "action": "listCodeDefinitionNames",
199
- "message": {
200
- path
201
- }
202
- }));
203
- websocket_1.default.getWebsocket.on('message', (data) => {
204
- const response = JSON.parse(data);
205
- if (response.type === "listCodeDefinitionNamesResponse") {
206
- resolve(response);
207
- }
208
- });
209
- });
139
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
140
+ "type": "fsEvent",
141
+ "action": "listCodeDefinitionNames",
142
+ "message": {
143
+ path
144
+ }
145
+ }, "listCodeDefinitionNamesResponse");
210
146
  },
211
147
  /**
212
148
  * @function searchFiles
@@ -217,23 +153,15 @@ const cbfs = {
217
153
  * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the search results.
218
154
  */
219
155
  searchFiles: (path, regex, filePattern) => {
220
- return new Promise((resolve, reject) => {
221
- websocket_1.default.getWebsocket.send(JSON.stringify({
222
- "type": "fsEvent",
223
- "action": "searchFiles",
224
- "message": {
225
- path,
226
- regex,
227
- filePattern
228
- }
229
- }));
230
- websocket_1.default.getWebsocket.on('message', (data) => {
231
- const response = JSON.parse(data);
232
- if (response.type === "searchFilesResponse") {
233
- resolve(response);
234
- }
235
- });
236
- });
156
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
157
+ "type": "fsEvent",
158
+ "action": "searchFiles",
159
+ "message": {
160
+ path,
161
+ regex,
162
+ filePattern
163
+ }
164
+ }, "searchFilesResponse");
237
165
  },
238
166
  /**
239
167
  * @function writeToFile
@@ -243,22 +171,14 @@ const cbfs = {
243
171
  * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the write operation result.
244
172
  */
245
173
  writeToFile: (relPath, newContent) => {
246
- return new Promise((resolve, reject) => {
247
- websocket_1.default.getWebsocket.send(JSON.stringify({
248
- "type": "fsEvent",
249
- "action": "writeToFile",
250
- "message": {
251
- relPath,
252
- newContent
253
- }
254
- }));
255
- websocket_1.default.getWebsocket.on('message', (data) => {
256
- const response = JSON.parse(data);
257
- if (response.type === "writeToFileResponse") {
258
- resolve(response);
259
- }
260
- });
261
- });
174
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
175
+ "type": "fsEvent",
176
+ "action": "writeToFile",
177
+ "message": {
178
+ relPath,
179
+ newContent
180
+ }
181
+ }, "writeToFileResponse");
262
182
  },
263
183
  };
264
184
  exports.default = cbfs;