@codebolt/codeboltjs 1.0.0 → 1.0.1

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 (43) hide show
  1. package/.github/workflows/publish-to-npm.yml +18 -0
  2. package/License.md +21 -0
  3. package/Readme.md +27 -0
  4. package/package.json +22 -1
  5. package/src/index.ts +92 -0
  6. package/src/modules/browser.ts +266 -0
  7. package/src/modules/chat.ts +82 -0
  8. package/src/modules/codeparsers.ts +30 -0
  9. package/src/modules/codeutils.ts +19 -0
  10. package/src/modules/crawler.ts +109 -0
  11. package/src/modules/dbmemory.ts +51 -0
  12. package/src/modules/docutils.ts +18 -0
  13. package/src/modules/fs.ts +164 -0
  14. package/src/modules/git.ts +237 -0
  15. package/src/modules/knowledge.ts +5 -0
  16. package/src/modules/llm.ts +36 -0
  17. package/src/modules/outputparsers.ts +30 -0
  18. package/src/modules/project.ts +34 -0
  19. package/src/modules/rag.ts +28 -0
  20. package/src/modules/search.ts +35 -0
  21. package/src/modules/terminal.ts +31 -0
  22. package/src/modules/websocket.ts +59 -0
  23. package/tests/fs.test.js +89 -0
  24. package/tests/index.test.js +4 -0
  25. package/tsconfig.json +122 -0
  26. package/webpack.config.js +25 -0
  27. package/index.js +0 -41
  28. package/modules/browser.js +0 -88
  29. package/modules/chat.js +0 -27
  30. package/modules/codeboltfs.js +0 -119
  31. package/modules/codeparsers.js +0 -9
  32. package/modules/codeutils.js +0 -9
  33. package/modules/crawler.js +0 -63
  34. package/modules/dbmemory.js +0 -7
  35. package/modules/docutils.js +0 -5
  36. package/modules/git.js +0 -3
  37. package/modules/llm.js +0 -29
  38. package/modules/outputparsers.js +0 -12
  39. package/modules/rag.js +0 -10
  40. package/modules/search.js +0 -18
  41. package/modules/terminal.js +0 -28
  42. package/modules/websocket.js +0 -24
  43. /package/{modules/knowledge.js → tests/chat.test.js} +0 -0
@@ -0,0 +1,18 @@
1
+ name: Publish Package to npmjs
2
+ on:
3
+ release:
4
+ types: [published]
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v4
10
+ # Setup .npmrc file to publish to npm
11
+ - uses: actions/setup-node@v4
12
+ with:
13
+ node-version: '20.x'
14
+ registry-url: 'https://registry.npmjs.org'
15
+ - run: npm ci
16
+ - run: npm publish
17
+ env:
18
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/License.md ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included
12
+ * in all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
+ * IN THE SOFTWARE.
21
+ */
package/Readme.md ADDED
@@ -0,0 +1,27 @@
1
+ # Codebolt Agent Library
2
+
3
+ This library provides a set of tools and utilities for creating Codebolt agents, enabling seamless integration with the Codebolt platform.
4
+
5
+ ## Features
6
+ - Create and manage Codebolt agents
7
+ - Interact with the Codebolt platform
8
+ - Utilize Codebolt's powerful API
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @codebolt/codeboltjs
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```javascript
19
+ const codebolt = require('@codebolt/codeboltjs');
20
+
21
+ // Your code here
22
+ ```
23
+
24
+ ## Documentation
25
+
26
+ For More Documentation visit [Codebolt's Documentation](https://docs.codebolt.ai)
27
+
package/package.json CHANGED
@@ -1,11 +1,32 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
7
+ "main": "src/index.ts",
7
8
  "license": "ISC",
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "build:docs": "typedoc --plugin typedoc-plugin-missing-exports",
12
+ "build:jsondocs": "typedoc --plugin typedoc-plugin-missing-exports --json out.json --pretty",
13
+ "test": "jest fs.test.js"
14
+ },
8
15
  "dependencies": {
16
+ "typedoc-plugin-missing-exports": "^2.2.0",
9
17
  "ws": "^8.16.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/ws": "^8.5.10",
21
+ "ts-loader": "^9.5.1",
22
+ "typedoc": "^0.25.13",
23
+ "typescript": "^5.4.5",
24
+ "webpack": "^5.91.0",
25
+ "webpack-cli": "^5.1.4",
26
+ "jest": "^29.7.0",
27
+ "jest-serial-runner": "^1.2.1"
28
+ },
29
+ "jest": {
30
+ "testTimeout": 50000
10
31
  }
11
32
  }
package/src/index.ts ADDED
@@ -0,0 +1,92 @@
1
+ import cbws from './modules/websocket';
2
+ import cbfs from './modules/fs';
3
+ import cbllm from './modules/llm';
4
+ import cbterminal from './modules/terminal';
5
+ import cbbrowser from './modules/browser';
6
+ import cbchat from './modules/chat';
7
+ import cbcodeutils from './modules/codeutils';
8
+ import cbdocutils from './modules/docutils';
9
+ import cbcrawler from './modules/crawler';
10
+ import cbsearch from './modules/search';
11
+ import cbknowledge from './modules/knowledge';
12
+ import cbrag from './modules/rag';
13
+ import cbcodeparsers from './modules/codeparsers';
14
+ import cboutputparsers from './modules/outputparsers';
15
+ import cbproject from './modules/project';
16
+ import git from './modules/git';
17
+ import dbmemory from './modules/dbmemory';
18
+ import WebSocket from 'ws';
19
+
20
+ /**
21
+ * @class Codebolt
22
+ * @description This class provides a unified interface to interact with various modules.
23
+ */
24
+ class Codebolt {
25
+
26
+ /**
27
+ * @constructor
28
+ * @description Initializes the websocket connection.
29
+ */
30
+ constructor(){
31
+ this.websocket = cbws.getWebsocket;
32
+ }
33
+
34
+ /**
35
+ * @method waitForConnection
36
+ * @description Waits for the WebSocket connection to open.
37
+ * @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
38
+ */
39
+ async waitForConnection() {
40
+ return new Promise<void>((resolve, reject) => {
41
+ if (!this.websocket) {
42
+ reject(new Error('WebSocket is not initialized'));
43
+ return;
44
+ }
45
+
46
+ if (this.websocket.readyState === WebSocket.OPEN) {
47
+ resolve();
48
+ return;
49
+ }
50
+
51
+ this.websocket.addEventListener('open', () => {
52
+ resolve();
53
+ });
54
+
55
+ this.websocket.addEventListener('error', (error) => {
56
+ reject(error);
57
+ });
58
+ });
59
+ }
60
+
61
+ /**
62
+ * @method start_browser
63
+ * @description Starts a new browser page.
64
+ * @param {string} objective - The objective of the browser session.
65
+ * @param {string} url - The URL to navigate to.
66
+ * @param {string} previous_command - The previous command executed.
67
+ * @param {string} browser_content - The content of the browser.
68
+ */
69
+ start_browser(objective:string, url:string, previous_command:string, browser_content:string) {
70
+ cbbrowser.newPage();
71
+ }
72
+
73
+ websocket: WebSocket | null = null;
74
+ fs = cbfs;
75
+ git=git;
76
+ llm = cbllm;
77
+ browser = cbbrowser;
78
+ chat = cbchat;
79
+ terminal = cbterminal;
80
+ codeutils = cbcodeutils;
81
+ docutils = cbdocutils;
82
+ crawler = cbcrawler;
83
+ search = cbsearch;
84
+ knowledge = cbknowledge;
85
+ rag = cbrag;
86
+ codeparsers = cbcodeparsers;
87
+ outputparsers = cboutputparsers;
88
+ project = cbproject;
89
+ dbmemory = dbmemory;
90
+ }
91
+
92
+ export default new Codebolt();
@@ -0,0 +1,266 @@
1
+ import cbws from './websocket';
2
+
3
+ /**
4
+ * A module for interacting with a browser through WebSockets.
5
+ */
6
+ const cbbrowser = {
7
+
8
+ /**
9
+ * Opens a new page in the browser.
10
+ */
11
+ newPage: () => {
12
+ cbws.getWebsocket.send(JSON.stringify({
13
+ "type": "browserEvent",
14
+ action: 'newPage'
15
+ }));
16
+ },
17
+
18
+ /**
19
+ * Retrieves the current URL of the browser's active page.
20
+ * @returns {Promise<any>} A promise that resolves with the URL.
21
+ */
22
+ getUrl: () => {
23
+ return new Promise((resolve, reject) => {
24
+ cbws.getWebsocket.send(JSON.stringify({
25
+ "type": "browserEvent",
26
+ action: 'getUrl'
27
+ }));
28
+ cbws.getWebsocket.on('message', (data: string) => {
29
+ const response = JSON.parse(data);
30
+ if (response.event === "getUrlResponse") {
31
+ resolve(response);
32
+ }
33
+ });
34
+ });
35
+ },
36
+
37
+ /**
38
+ * Navigates to a specified URL.
39
+ * @param {string} url - The URL to navigate to.
40
+ * @returns {Promise<any>} A promise that resolves when navigation is complete.
41
+ */
42
+ goToPage: (url: string) => {
43
+ return new Promise((resolve, reject) => {
44
+ cbws.getWebsocket.send(JSON.stringify({
45
+ "type": "browserEvent",
46
+ action: 'goToPage',
47
+ url
48
+ }));
49
+ cbws.getWebsocket.on('message', (data: string) => {
50
+ const response = JSON.parse(data);
51
+ if (response.event === "goToPageResponse") {
52
+ resolve(response);
53
+ }
54
+ });
55
+ });
56
+ },
57
+
58
+ /**
59
+ * Takes a screenshot of the current page.
60
+ */
61
+ screenshot: () => {
62
+ cbws.getWebsocket.send(JSON.stringify({
63
+ "type": "browserEvent",
64
+ action: 'screenshot'
65
+ }));
66
+ },
67
+
68
+ /**
69
+ * Retrieves the HTML content of the current page.
70
+ * @returns {Promise<string>} A promise that resolves with the HTML content.
71
+ */
72
+ getHTML: () => {
73
+ return new Promise((resolve, reject) => {
74
+ cbws.getWebsocket.send(JSON.stringify({
75
+ "type": "browserEvent",
76
+ action: 'getHTML'
77
+ }));
78
+ cbws.getWebsocket.on('message', (data: string) => {
79
+ const response = JSON.parse(data);
80
+ if (response.event === "htmlReceived") {
81
+ resolve(response.htmlResponse);
82
+ }
83
+ });
84
+ });
85
+ },
86
+
87
+ /**
88
+ * Retrieves the Markdown content of the current page.
89
+ * @returns {Promise<any>} A promise that resolves with the Markdown content.
90
+ */
91
+ getMarkdown: () => {
92
+ return new Promise((resolve, reject) => {
93
+ cbws.getWebsocket.send(JSON.stringify({
94
+ "type": "browserEvent",
95
+ action: 'getMarkdown'
96
+ }));
97
+ cbws.getWebsocket.on('message', (data: string) => {
98
+ const response = JSON.parse(data);
99
+ if (response.event === "getMarkdownResponse") {
100
+ resolve(response);
101
+ }
102
+ });
103
+ });
104
+ },
105
+
106
+ /**
107
+ * Retrieves the PDF content of the current page.
108
+ */
109
+ getPDF: () => {
110
+ cbws.getWebsocket.send(JSON.stringify({
111
+ "type": "browserEvent",
112
+ action: 'getPDF'
113
+ }));
114
+ },
115
+
116
+ /**
117
+ * Converts the PDF content of the current page to text.
118
+ */
119
+ pdfToText: () => {
120
+ cbws.getWebsocket.send(JSON.stringify({
121
+ "type": "browserEvent",
122
+ action: 'pdfToText'
123
+ }));
124
+ },
125
+
126
+ /**
127
+ * Retrieves the content of the current page.
128
+ */
129
+ getContent: () => {
130
+ cbws.getWebsocket.send(JSON.stringify({
131
+ "type": "browserEvent",
132
+ action: 'getContent'
133
+ }));
134
+ },
135
+
136
+ /**
137
+ * Extracts text from the current page.
138
+ */
139
+ extractText: () => {
140
+ cbws.getWebsocket.send(JSON.stringify({
141
+ "type": "browserEvent",
142
+ action: 'extractText'
143
+ }));
144
+ },
145
+
146
+ /**
147
+ * Closes the current page.
148
+ */
149
+ close: () => {
150
+ cbws.getWebsocket.send(JSON.stringify({
151
+ "type": "browserEvent",
152
+ action: 'close'
153
+ }));
154
+ },
155
+
156
+ /**
157
+ * Scrolls the current page in a specified direction by a specified number of pixels.
158
+ * @param {string} direction - The direction to scroll.
159
+ * @param {string} pixels - The number of pixels to scroll.
160
+ * @returns {Promise<any>} A promise that resolves when the scroll action is complete.
161
+ */
162
+ scroll: (direction: string, pixels: string) => {
163
+ return new Promise((resolve, reject) => {
164
+ cbws.getWebsocket.send(JSON.stringify({
165
+ "type": "browserEvent",
166
+ action: 'scroll',
167
+ direction,
168
+ pixels
169
+ }));
170
+ cbws.getWebsocket.on('message', (data: string) => {
171
+ const response = JSON.parse(data);
172
+ if (response.event === "scrollResponse") {
173
+ resolve(response);
174
+ }
175
+ });
176
+ });
177
+ },
178
+
179
+ /**
180
+ * Types text into a specified element on the page.
181
+ * @param {string} elementid - The ID of the element to type into.
182
+ * @param {string} text - The text to type.
183
+ * @returns {Promise<any>} A promise that resolves when the typing action is complete.
184
+ */
185
+ type: (elementid: string, text: string) => {
186
+ return new Promise((resolve, reject) => {
187
+ cbws.getWebsocket.send(JSON.stringify({
188
+ "type": "browserEvent",
189
+ action: 'type',
190
+ text,
191
+ elementid
192
+ }));
193
+ cbws.getWebsocket.on('message', (data: string) => {
194
+ const response = JSON.parse(data);
195
+ if (response.event === "typeResponse") {
196
+ resolve(response);
197
+ }
198
+ });
199
+ });
200
+ },
201
+
202
+ /**
203
+ * Clicks on a specified element on the page.
204
+ * @param {string} elementid - The ID of the element to click.
205
+ * @returns {Promise<any>} A promise that resolves when the click action is complete.
206
+ */
207
+ click: (elementid: string) => {
208
+ return new Promise((resolve, reject) => {
209
+ cbws.getWebsocket.send(JSON.stringify({
210
+ "type": "browserEvent",
211
+ action: 'click',
212
+ elementid
213
+ }));
214
+ cbws.getWebsocket.on('message', (data: string) => {
215
+ const response = JSON.parse(data);
216
+ if (response.event === "clickResponse") {
217
+ resolve(response);
218
+ }
219
+ });
220
+ });
221
+ },
222
+
223
+ /**
224
+ * Simulates the Enter key press on the current page.
225
+ * @returns {Promise<any>} A promise that resolves when the Enter action is complete.
226
+ */
227
+ enter: () => {
228
+ return new Promise((resolve, reject) => {
229
+ cbws.getWebsocket.send(JSON.stringify({
230
+ "type": "browserEvent",
231
+ action: 'enter'
232
+ }));
233
+ cbws.getWebsocket.on('message', (data: string) => {
234
+ const response = JSON.parse(data);
235
+ if (response.event === "EnterResponse") {
236
+ resolve(response);
237
+ }
238
+ });
239
+ });
240
+ },
241
+
242
+ /**
243
+ * Performs a search on the current page using a specified query.
244
+ * @param {string} elementid - The ID of the element to perform the search in.
245
+ * @param {string} query - The search query.
246
+ * @returns {Promise<any>} A promise that resolves with the search results.
247
+ */
248
+ search: (elementid: string, query: string) => {
249
+ return new Promise((resolve, reject) => {
250
+ cbws.getWebsocket.send(JSON.stringify({
251
+ "type": "browserEvent",
252
+ action: 'search',
253
+ elementid,
254
+ query
255
+ }));
256
+ cbws.getWebsocket.on('message', (data: string) => {
257
+ const response = JSON.parse(data);
258
+ if (response.event === "searchResponse") {
259
+ resolve(response);
260
+ }
261
+ });
262
+ });
263
+ }
264
+ }
265
+
266
+ export default cbbrowser;
@@ -0,0 +1,82 @@
1
+ // chat.ts
2
+ import cbws from './websocket';
3
+ import { EventEmitter } from 'events';
4
+
5
+ /**
6
+ * CustomEventEmitter class that extends the Node.js EventEmitter class.
7
+ */
8
+ class CustomEventEmitter extends EventEmitter {}
9
+
10
+ /**
11
+ * Chat module to interact with the WebSocket server.
12
+ */
13
+ const cbchat = {
14
+ eventEmitter: new CustomEventEmitter(),
15
+
16
+ /**
17
+ * Sends a message through the WebSocket connection.
18
+ * @param {string} message - The message to be sent.
19
+ */
20
+ sendMessage(message: string) {
21
+ console.log(message);
22
+ cbws.getWebsocket.send(JSON.stringify({
23
+ "type": "sendMessage",
24
+ "message": message
25
+ }));
26
+ },
27
+
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<any>} A promise that resolves with the reply.
32
+ */
33
+ waitforReply(message: string): Promise<any> {
34
+ return new Promise((resolve, reject) => {
35
+ cbws.getWebsocket.send(JSON.stringify({
36
+ "type": "waitforReply",
37
+ "message": message
38
+ }));
39
+ cbws.getWebsocket.on('message', (data: string) => {
40
+ const response = JSON.parse(data);
41
+ if (response.type === "messageResponse") {
42
+ resolve(response); // Resolve the Promise with the response data
43
+ }
44
+ });
45
+ });
46
+ },
47
+
48
+ /**
49
+ * Notifies the server that a process has started and sets up an event listener for stopProcessClicked events.
50
+ * @returns An object containing the event emitter and a stopProcess method.
51
+ */
52
+ processStarted() {
53
+ // Send the process started message
54
+ cbws.getWebsocket.send(JSON.stringify({
55
+ "type": "processStarted"
56
+ }));
57
+ // Register event listener for WebSocket messages
58
+ cbws.getWebsocket.on('message', (data: string) => {
59
+ const message = JSON.parse(data);
60
+ console.log("Received message:", message);
61
+ if(message.type==='stopProcessClicked')
62
+
63
+ // Emit a custom event based on the message type
64
+ this.eventEmitter.emit("stopProcessClicked", message);
65
+ });
66
+
67
+ // Return an object that includes the event emitter and the stopProcess method
68
+ return {
69
+ event: this.eventEmitter,
70
+ stopProcess: () => {
71
+ // Implement the logic to stop the process here
72
+ console.log("Stopping process...");
73
+ // For example, you might want to send a specific message to the server to stop the process
74
+ cbws.getWebsocket.send(JSON.stringify({
75
+ "type": "processStoped"
76
+ }));
77
+ }
78
+ };
79
+ }
80
+ };
81
+
82
+ export default cbchat;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A collection of code parser functions.
3
+ */
4
+ 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) => {
10
+ console.log('Code parsers initialized');
11
+ },
12
+ /**
13
+ * Retrieves the functions in a given class within a file.
14
+ * @param file The file containing the class.
15
+ * @param className The name of the class to parse for functions.
16
+ */
17
+ getFunctionsinClass: (file: any, className: any) => {
18
+ console.log('Code parsers initialized');
19
+ },
20
+ /**
21
+ * Generates an Abstract Syntax Tree (AST) for a given file.
22
+ * @param file The file to generate an AST for.
23
+ * @param className The name of the class to focus the AST generation on.
24
+ */
25
+ getAstTreeInFile: (file: any, className: any) => {
26
+
27
+ }
28
+ };
29
+
30
+ export default cbcodeparsers;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A utility module for working with code.
3
+ */
4
+ const cbcodeutils = {
5
+ /**
6
+ * Asynchronously generates a code tree from the provided source code.
7
+ * @param {any} fileName - The name of the file.
8
+ * @param {any} source - The source code to generate the tree from.
9
+ * @param {any} filePath - The file path where the source code is located.
10
+ * @returns {Promise<any>} A promise that resolves with the code tree.
11
+ */
12
+ getCodeTree: (fileName: any, source: any, filePath: any): Promise<any> => {
13
+ return new Promise((resolve, reject) => {
14
+ // Implementation would go here
15
+ });
16
+ }
17
+ };
18
+
19
+ export default cbcodeutils;