@codebolt/codeboltjs 1.1.76 → 1.1.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/docs/modules/_internal_.EventEmitter.html +6 -0
  2. package/docs/modules/_internal_.WebSocket.html +21 -0
  3. package/docs/modules/_internal_._node_stream_consumers_.html +6 -0
  4. package/docs/modules/_internal_._node_stream_promises_.html +3 -0
  5. package/docs/modules/_internal_.html +228 -0
  6. package/docs/modules/_internal_.internal.finished.html +2 -0
  7. package/docs/modules/_internal_.internal.html +36 -0
  8. package/docs/modules/_internal_.internal.pipeline.html +2 -0
  9. package/index.d.ts +254 -0
  10. package/modules/browser.d.ts +108 -0
  11. package/modules/browser.js +331 -0
  12. package/modules/chat.d.ts +64 -0
  13. package/modules/chat.js +190 -0
  14. package/modules/codeparsers.d.ts +23 -0
  15. package/modules/codeparsers.js +30 -0
  16. package/modules/codeutils.d.ts +37 -0
  17. package/modules/codeutils.js +117 -0
  18. package/modules/crawler.d.ts +45 -0
  19. package/modules/crawler.js +123 -0
  20. package/modules/dbmemory.d.ts +20 -0
  21. package/modules/dbmemory.js +54 -0
  22. package/modules/debug.d.ts +23 -0
  23. package/modules/debug.js +64 -0
  24. package/modules/docutils.d.ts +12 -0
  25. package/modules/docutils.js +19 -0
  26. package/modules/fs.d.ts +94 -0
  27. package/modules/fs.js +264 -0
  28. package/modules/git.d.ts +76 -0
  29. package/modules/git.js +240 -0
  30. package/modules/history.d.ts +19 -0
  31. package/modules/history.js +46 -0
  32. package/modules/knowledge.d.ts +2 -0
  33. package/modules/knowledge.js +6 -0
  34. package/modules/llm.d.ts +18 -0
  35. package/modules/llm.js +39 -0
  36. package/modules/mcp.d.ts +8 -0
  37. package/modules/mcp.js +139 -0
  38. package/modules/outputparsers.d.ts +24 -0
  39. package/modules/outputparsers.js +32 -0
  40. package/modules/project.d.ts +21 -0
  41. package/modules/project.js +72 -0
  42. package/modules/rag.d.ts +22 -0
  43. package/modules/rag.js +30 -0
  44. package/modules/search.d.ts +23 -0
  45. package/modules/search.js +37 -0
  46. package/modules/state.d.ts +21 -0
  47. package/modules/state.js +68 -0
  48. package/modules/task.d.ts +23 -0
  49. package/modules/task.js +75 -0
  50. package/modules/terminal.d.ts +46 -0
  51. package/modules/terminal.js +108 -0
  52. package/modules/tokenizer.d.ts +19 -0
  53. package/modules/tokenizer.js +56 -0
  54. package/modules/vectordb.d.ts +33 -0
  55. package/modules/vectordb.js +103 -0
  56. package/modules/websocket.d.ts +27 -0
  57. package/modules/websocket.js +88 -0
  58. package/package.json +1 -1
  59. package/src/modules/browser.ts +352 -0
  60. package/src/modules/chat.ts +193 -0
  61. package/src/modules/codeparsers.ts +30 -0
  62. package/src/modules/codeutils.ts +126 -0
  63. package/src/modules/crawler.ts +121 -0
  64. package/src/modules/dbmemory.ts +52 -0
  65. package/src/modules/debug.ts +68 -0
  66. package/src/modules/docutils.ts +18 -0
  67. package/src/modules/fs.ts +263 -0
  68. package/src/modules/git.ts +237 -0
  69. package/src/modules/history.ts +61 -0
  70. package/src/modules/knowledge.ts +5 -0
  71. package/src/modules/llm.ts +36 -0
  72. package/src/modules/mcp.ts +127 -0
  73. package/src/modules/outputparsers.ts +30 -0
  74. package/src/modules/project.ts +68 -0
  75. package/src/modules/rag.ts +28 -0
  76. package/src/modules/search.ts +35 -0
  77. package/src/modules/state.ts +69 -0
  78. package/src/modules/task.ts +73 -0
  79. package/src/modules/terminal.ts +114 -0
  80. package/src/modules/tokenizer.ts +56 -0
  81. package/src/modules/vectordb.ts +102 -0
  82. package/src/modules/websocket.ts +89 -0
@@ -0,0 +1,121 @@
1
+ import cbws from './websocket';
2
+
3
+ /**
4
+ * A module for controlling a web crawler through WebSocket messages.
5
+ */
6
+ const cbcrawler = {
7
+ /**
8
+ * Starts the crawler.
9
+ */
10
+ start: () => {
11
+ cbws.getWebsocket.send(JSON.stringify({
12
+ "type": "crawlerEvent",
13
+ action: 'start'
14
+ }));
15
+ },
16
+ /**
17
+ * Takes a screenshot using the crawler.
18
+ */
19
+ screenshot: () => {
20
+ cbws.getWebsocket.send(JSON.stringify({
21
+ "type": "crawlerEvent",
22
+ action: 'screenshot'
23
+ }));
24
+ },
25
+ /**
26
+ * Directs the crawler to navigate to a specified URL.
27
+ * @param url - The URL for the crawler to navigate to.
28
+ */
29
+ goToPage: (url: string) => {
30
+ cbws.getWebsocket.send(JSON.stringify({
31
+ "type": "crawlerEvent",
32
+ action: 'goToPage',
33
+ url
34
+ }));
35
+ },
36
+ /**
37
+ * Scrolls the crawler in a specified direction.
38
+ * @param direction - The direction to scroll ('up', 'down', 'left', 'right').
39
+ */
40
+ scroll: (direction: string) => {
41
+ cbws.getWebsocket.send(JSON.stringify({
42
+ "type": "crawlerEvent",
43
+ action: 'scroll',
44
+ direction
45
+ }));
46
+ },
47
+ /**
48
+ * Simulates a click event on an element with the specified ID.
49
+ * @param id - The ID of the element to be clicked.
50
+ * @returns {Promise<any>} A promise that resolves when the click action is complete.
51
+ */
52
+ click: (id: string) => {
53
+ return new Promise((resolve, reject) => {
54
+ cbws.getWebsocket.send(JSON.stringify({
55
+ "type": "crawlerEvent",
56
+ action: 'click',
57
+ id
58
+ }));
59
+ cbws.getWebsocket.on('message', (data: string) => {
60
+ const response = JSON.parse(data);
61
+ if (response.event === "clickFinished") {
62
+ resolve(response);
63
+ }
64
+ });
65
+ });
66
+ },
67
+ /**
68
+ * Types the provided text into an element with the specified ID.
69
+ * @param id - The ID of the element where text will be typed.
70
+ * @param text - The text to type into the element.
71
+ * @returns {Promise<any>} A promise that resolves when the type action is complete.
72
+ */
73
+ type: (id: string, text: string) => {
74
+ return new Promise((resolve, reject) => {
75
+ cbws.getWebsocket.send(JSON.stringify({
76
+ "type": "crawlerEvent",
77
+ action: 'type',
78
+ id,
79
+ text
80
+ }));
81
+ cbws.getWebsocket.on('message', (data: string) => {
82
+ const response = JSON.parse(data);
83
+ if (response.event === "typeFinished") {
84
+ resolve(response);
85
+ }
86
+ });
87
+ });
88
+ },
89
+ /**
90
+ * Simulates the Enter key press using the crawler.
91
+ */
92
+ enter: () => {
93
+ cbws.getWebsocket.send(JSON.stringify({
94
+ "type": "crawlerEvent",
95
+ action: 'enter'
96
+ }));
97
+ },
98
+ /**
99
+ * Initiates a crawl process.
100
+ */
101
+ crawl: (query:string) => {
102
+ return new Promise((resolve, reject) => {
103
+ cbws.getWebsocket.send(JSON.stringify({
104
+ "type": "crawlerEvent",
105
+ "action": 'crawl',
106
+ "message":{
107
+ query
108
+ }
109
+ }));
110
+ cbws.getWebsocket.on('message', (data: string) => {
111
+ const response = JSON.parse(data);
112
+ if (response.type === "crawlResponse") {
113
+ resolve(response); // Resolve the Promise with the response data
114
+ }
115
+ });
116
+ });
117
+
118
+ }
119
+ };
120
+
121
+ export default cbcrawler;
@@ -0,0 +1,52 @@
1
+ import cbws from './websocket';
2
+ import {MemorySetResponse,MemoryGetResponse } from '@codebolt/types';
3
+
4
+ /**
5
+ * A module for handling in-memory database operations via WebSocket.
6
+ */
7
+ const dbmemory = {
8
+ /**
9
+ * Adds a key-value pair to the in-memory database.
10
+ * @param {string} key - The key under which to store the value.
11
+ * @param {any} value - The value to be stored.
12
+ * @returns {Promise<MemorySetResponse>} A promise that resolves with the response from the memory set event.
13
+ */
14
+ addKnowledge: (key: string, value: any): Promise<MemorySetResponse> => {
15
+ return new Promise((resolve, reject) => {
16
+ cbws.getWebsocket.send(JSON.stringify({
17
+ "type": "memoryEvent",
18
+ 'action': 'set',
19
+ key,
20
+ value
21
+ }));
22
+ cbws.getWebsocket.on('message', (data: string) => {
23
+ const response = JSON.parse(data);
24
+ if (response.type === "memorySetResponse") {
25
+ resolve(response); // Resolve the Promise with the response data
26
+ }
27
+ });
28
+ });
29
+ },
30
+ /**
31
+ * Retrieves a value from the in-memory database by key.
32
+ * @param {string} key - The key of the value to retrieve.
33
+ * @returns {Promise<MemoryGetResponse>} A promise that resolves with the response from the memory get event.
34
+ */
35
+ getKnowledge: (key: string): Promise<MemoryGetResponse> => {
36
+ return new Promise((resolve, reject) => {
37
+ cbws.getWebsocket.send(JSON.stringify({
38
+ "type": "memoryEvent",
39
+ 'action': 'get',
40
+ key
41
+ }));
42
+ cbws.getWebsocket.on('message', (data: string) => {
43
+ const response = JSON.parse(data);
44
+ if (response.type === "memoryGetResponse") {
45
+ resolve(response); // Resolve the Promise with the response data
46
+ }
47
+ });
48
+ });
49
+ }
50
+ };
51
+
52
+ export default dbmemory;
@@ -0,0 +1,68 @@
1
+ import cbws from './websocket';
2
+ import {DebugAddLogResponse,OpenDebugBrowserResponse } from '@codebolt/types';
3
+ export enum logType{
4
+ info="info",
5
+ error="error",
6
+ warning="warning"
7
+ }
8
+
9
+
10
+ export const debug={
11
+ /**
12
+ * Sends a log message to the debug websocket and waits for a response.
13
+ * @param {string} log - The log message to send.
14
+ * @param {logType} type - The type of the log message (info, error, warning).
15
+ * @returns {Promise<DebugAddLogResponse>} A promise that resolves with the response from the debug event.
16
+ */
17
+ debug:(log:string,type:logType):Promise<DebugAddLogResponse>=> {
18
+ return new Promise((resolve, reject) => {
19
+ cbws.getWebsocket.send(JSON.stringify({
20
+ "type": "debugEvent",
21
+ "action":"addLog",
22
+ message:{
23
+ log,
24
+ type
25
+ }
26
+ }));
27
+ cbws.getWebsocket.on('message', (data: string) => {
28
+ const response = JSON.parse(data);
29
+ if (response.type === "debugEventResponse") {
30
+ resolve(response); // Resolve the Promise with the response data
31
+ }
32
+ })
33
+ })
34
+
35
+
36
+ },
37
+ /**
38
+ * Requests to open a debug browser at the specified URL and port.
39
+ * @param {string} url - The URL where the debug browser should be opened.
40
+ * @param {number} port - The port on which the debug browser will listen.
41
+ * @returns {Promise<OpenDebugBrowserResponse>} A promise that resolves with the response from the open debug browser event.
42
+ */
43
+ openDebugBrowser:(url:string,port:number):Promise<OpenDebugBrowserResponse>=>{
44
+ return new Promise((resolve, reject) => {
45
+ cbws.getWebsocket.send(JSON.stringify({
46
+ "type": "debugEvent",
47
+ "action":"openDebugBrowser",
48
+ message:{
49
+ url,
50
+ port
51
+ }
52
+ }));
53
+ cbws.getWebsocket.on('message', (data: string) => {
54
+ const response = JSON.parse(data);
55
+ if (response.type === "openDebugBrowserResponse") {
56
+ resolve(response); // Resolve the Promise with the response data
57
+ }
58
+ })
59
+ })
60
+
61
+ }
62
+ }
63
+
64
+
65
+ export default debug;
66
+
67
+
68
+
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A module for document utility functions.
3
+ */
4
+ const cbdocutils = {
5
+ /**
6
+ * Converts a PDF document to text.
7
+ * @param pdf_path - The file path to the PDF document to be converted.
8
+ * @returns {Promise<string>} A promise that resolves with the converted text.
9
+ */
10
+ pdf_to_text: (pdf_path: any): Promise<string> => {
11
+ // Implementation would go here
12
+ return new Promise((resolve, reject) => {
13
+ // PDF to text conversion logic
14
+ });
15
+ }
16
+ };
17
+
18
+ export default cbdocutils;
@@ -0,0 +1,263 @@
1
+ import cbws from './websocket';
2
+ import {CreateFileResponse,CreateFolderResponse,ReadFileResponse,UpdateFileResponse,DeleteFileResponse,DeleteFolderResponse} from '@codebolt/types'
3
+ /**
4
+ * @module cbfs
5
+ * @description This module provides functionality to interact with the filesystem.
6
+ */
7
+ const cbfs = {
8
+ /**
9
+ * @function createFile
10
+ * @description Creates a new file.
11
+ * @param {string} fileName - The name of the file to create.
12
+ * @param {string} source - The source content to write into the file.
13
+ * @param {string} filePath - The path where the file should be created.
14
+ * @returns {Promise<CreateFileResponse>} A promise that resolves with the server response.
15
+ */
16
+ createFile: (fileName: string, source: string, filePath: string): Promise<CreateFileResponse> => {
17
+ return new Promise((resolve, reject) => {
18
+ cbws.getWebsocket.send(JSON.stringify({
19
+ "type":"fsEvent",
20
+ "action": "createFile",
21
+ "message": {
22
+ fileName,
23
+ source,
24
+ filePath
25
+ },
26
+ }));
27
+ cbws.getWebsocket.on('message', (data: string) => {
28
+ const response = JSON.parse(data);
29
+ if (response.type === "createFileResponse") {
30
+ resolve(response);
31
+ }
32
+ });
33
+ });
34
+ },
35
+ /**
36
+ * @function createFolder
37
+ * @description Creates a new folder.
38
+ * @param {string} folderName - The name of the folder to create.
39
+ * @param {string} folderPath - The path where the folder should be created.
40
+ * @returns {Promise<CreateFolderResponse>} A promise that resolves with the server response.
41
+ */
42
+ createFolder: (folderName: string, folderPath: string): Promise<CreateFolderResponse> => {
43
+ return new Promise((resolve, reject) => {
44
+ cbws.getWebsocket.send(JSON.stringify({
45
+ "type":"fsEvent",
46
+ "action": "createFolder",
47
+ "message": {
48
+ folderName,
49
+ folderPath
50
+ },
51
+ }));
52
+ cbws.getWebsocket.on('message', (data: string) => {
53
+ const response = JSON.parse(data);
54
+ if (response.type === "createFolderResponse") {
55
+ resolve(response);
56
+ }
57
+ });
58
+ });
59
+ },
60
+ /**
61
+ * @function readFile
62
+ * @description Reads the content of a file.
63
+ * @param {string} filename - The name of the file to read.
64
+ * @param {string} filePath - The path of the file to read.
65
+ * @returns {Promise<ReadFileResponse>} A promise that resolves with the server response.
66
+ */
67
+ readFile: (filePath: string): Promise<ReadFileResponse> => {
68
+ return new Promise((resolve, reject) => {
69
+ cbws.getWebsocket.send(JSON.stringify({
70
+ "type":"fsEvent",
71
+ "action": "readFile",
72
+ "message": {
73
+ filePath
74
+ },
75
+ }));
76
+ cbws.getWebsocket.on('message', (data: string) => {
77
+ const response = JSON.parse(data);
78
+ if (response.type === "readFileResponse") {
79
+ resolve(response);
80
+ }
81
+ });
82
+ });
83
+ },
84
+ /**
85
+ * @function updateFile
86
+ * @description Updates the content of a file.
87
+ * @param {string} filename - The name of the file to update.
88
+ * @param {string} filePath - The path of the file to update.
89
+ * @param {string} newContent - The new content to write into the file.
90
+ * @returns {Promise<UpdateFileResponse>} A promise that resolves with the server response.
91
+ */
92
+ updateFile: (filename: string, filePath: string, newContent: string): Promise<UpdateFileResponse> => {
93
+ return new Promise((resolve, reject) => {
94
+ cbws.getWebsocket.send(JSON.stringify({
95
+ "type":"fsEvent",
96
+ "action": "updateFile",
97
+ "message": {
98
+ filename,
99
+ filePath,
100
+ newContent
101
+ },
102
+ }));
103
+ cbws.getWebsocket.on('message', (data: string) => {
104
+ const response = JSON.parse(data);
105
+ if (response.type === "commandOutput") {
106
+ resolve(response);
107
+ }
108
+ });
109
+ });
110
+ },
111
+ /**
112
+ * @function deleteFile
113
+ * @description Deletes a file.
114
+ * @param {string} filename - The name of the file to delete.
115
+ * @param {string} filePath - The path of the file to delete.
116
+ * @returns {Promise<DeleteFileResponse>} A promise that resolves with the server response.
117
+ */
118
+ deleteFile: (filename: string, filePath: string): Promise<DeleteFileResponse> => {
119
+ return new Promise((resolve, reject) => {
120
+ cbws.getWebsocket.send(JSON.stringify({
121
+ "type":"fsEvent",
122
+ "action": "deleteFile",
123
+ "message": {
124
+ filename,
125
+ filePath
126
+ },
127
+ }));
128
+ cbws.getWebsocket.on('message', (data: string) => {
129
+ const response = JSON.parse(data);
130
+ if (response.type === "deleteFileResponse") {
131
+ resolve(response);
132
+ }
133
+ });
134
+ });
135
+ },
136
+ /**
137
+ * @function deleteFolder
138
+ * @description Deletes a folder.
139
+ * @param {string} foldername - The name of the folder to delete.
140
+ * @param {string} folderpath - The path of the folder to delete.
141
+ * @returns {Promise<DeleteFolderResponse>} A promise that resolves with the server response.
142
+ */
143
+ deleteFolder: (foldername: string, folderpath: string): Promise<DeleteFolderResponse> => {
144
+ return new Promise((resolve, reject) => {
145
+ cbws.getWebsocket.send(JSON.stringify({
146
+ "type":"fsEvent",
147
+ "action": "deleteFolder",
148
+ "message": {
149
+ foldername,
150
+ folderpath
151
+ },
152
+ }));
153
+ cbws.getWebsocket.on('message', (data: string) => {
154
+ const response = JSON.parse(data);
155
+ if (response.type === "deleteFolderResponse") {
156
+ resolve(response);
157
+ }
158
+ });
159
+ });
160
+ },
161
+ /**
162
+ * @function listFile
163
+ * @description Lists all files.
164
+ * @returns {Promise<FileListResponse>} A promise that resolves with the list of files.
165
+ */
166
+ listFile: (folderPath:string,isRecursive=false) => {
167
+ return new Promise((resolve, reject) => {
168
+ cbws.getWebsocket.send(JSON.stringify({
169
+ "type": "fsEvent",
170
+ "action": "fileList",
171
+ message:{
172
+ folderPath,
173
+ isRecursive
174
+ }
175
+ }));
176
+ cbws.getWebsocket.on('message', (data: string) => {
177
+ const response = JSON.parse(data);
178
+ if (response.type === "fileListResponse") {
179
+ resolve(response);
180
+ }
181
+ });
182
+ });
183
+ },
184
+ /**
185
+ * @function listCodeDefinitionNames
186
+ * @description Lists all code definition names in a given path.
187
+ * @param {string} path - The path to search for code definitions.
188
+ * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the list of code definition names.
189
+ */
190
+ listCodeDefinitionNames: (path: string): Promise<{success: boolean, result: any}> => {
191
+ return new Promise((resolve, reject) => {
192
+ cbws.getWebsocket.send(JSON.stringify({
193
+ "type": "fsEvent",
194
+ "action": "listCodeDefinitionNames",
195
+ "message": {
196
+ path
197
+ }
198
+ }));
199
+ cbws.getWebsocket.on('message', (data: string) => {
200
+ const response = JSON.parse(data);
201
+ if (response.type === "listCodeDefinitionNamesResponse") {
202
+ resolve(response);
203
+ }
204
+ });
205
+ });
206
+ },
207
+
208
+ /**
209
+ * @function searchFiles
210
+ * @description Searches files in a given path using a regex pattern.
211
+ * @param {string} path - The path to search within.
212
+ * @param {string} regex - The regex pattern to search for.
213
+ * @param {string} filePattern - The file pattern to match files.
214
+ * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the search results.
215
+ */
216
+ searchFiles: (path: string, regex: string, filePattern: string): Promise<{success: boolean, result: any}> => {
217
+ return new Promise((resolve, reject) => {
218
+ cbws.getWebsocket.send(JSON.stringify({
219
+ "type": "fsEvent",
220
+ "action": "searchFiles",
221
+ "message": {
222
+ path,
223
+ regex,
224
+ filePattern
225
+ }
226
+ }));
227
+ cbws.getWebsocket.on('message', (data: string) => {
228
+ const response = JSON.parse(data);
229
+ if (response.type === "searchFilesResponse") {
230
+ resolve(response);
231
+ }
232
+ });
233
+ });
234
+ },
235
+ /**
236
+ * @function writeToFile
237
+ * @description Writes content to a file.
238
+ * @param {string} relPath - The relative path of the file to write to.
239
+ * @param {string} newContent - The new content to write into the file.
240
+ * @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the write operation result.
241
+ */
242
+ writeToFile: (relPath:string, newContent:string) => {
243
+ return new Promise((resolve, reject) => {
244
+ cbws.getWebsocket.send(JSON.stringify({
245
+ "type": "fsEvent",
246
+ "action": "writeToFile",
247
+ "message": {
248
+ relPath,
249
+ newContent
250
+ }
251
+ }));
252
+ cbws.getWebsocket.on('message', (data:string) => {
253
+ const response = JSON.parse(data);
254
+ if (response.type === "writeToFileResponse") {
255
+ resolve(response);
256
+ }
257
+ });
258
+ });
259
+ },
260
+
261
+ };
262
+
263
+ export default cbfs;