@codebolt/codeboltjs 1.1.76 → 1.1.77

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 +166 -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 +181 -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,46 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { CommandError, TerminalInterruptResponse } from '@codebolt/types';
4
+ /**
5
+ * CustomEventEmitter class that extends the Node.js EventEmitter class.
6
+ */
7
+ declare class CustomEventEmitter extends EventEmitter {
8
+ }
9
+ /**
10
+ * A module for executing commands in a terminal-like environment via WebSocket.
11
+ */
12
+ declare const cbterminal: {
13
+ eventEmitter: CustomEventEmitter;
14
+ /**
15
+ * Executes a given command and returns the result.
16
+ * Listens for messages from the WebSocket that indicate the output, error, or finish state
17
+ * of the executed command and resolves the promise accordingly.
18
+ *
19
+ * @param {string} command - The command to be executed.
20
+ * @returns {Promise<CommandOutput|CommandError>} A promise that resolves with the command's output, error, or finish signal.
21
+ */
22
+ executeCommand: (command: string, returnEmptyStringOnSuccess?: boolean) => Promise<unknown>;
23
+ /**
24
+ * Executes a given command and keeps running until an error occurs.
25
+ * Listens for messages from the WebSocket and resolves the promise when an error is encountered.
26
+ *
27
+ * @param {string} command - The command to be executed.
28
+ * @returns {Promise<CommandError>} A promise that resolves when an error occurs during command execution.
29
+ */
30
+ executeCommandRunUntilError: (command: string, executeInMain?: boolean) => Promise<CommandError>;
31
+ /**
32
+ * Sends a manual interrupt signal to the terminal.
33
+ *
34
+ * @returns {Promise<TerminalInterruptResponse>}
35
+ */
36
+ sendManualInterrupt(): Promise<TerminalInterruptResponse>;
37
+ /**
38
+ * Executes a given command and streams the output.
39
+ * Listens for messages from the WebSocket and streams the output data.
40
+ *
41
+ * @param {string} command - The command to be executed.
42
+ * @returns {EventEmitter} A promise that streams the output data during command execution.
43
+ */
44
+ executeCommandWithStream(command: string, executeInMain?: boolean): EventEmitter;
45
+ };
46
+ export default cbterminal;
@@ -0,0 +1,108 @@
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
+ const events_1 = require("events");
8
+ /**
9
+ * CustomEventEmitter class that extends the Node.js EventEmitter class.
10
+ */
11
+ class CustomEventEmitter extends events_1.EventEmitter {
12
+ }
13
+ /**
14
+ * A module for executing commands in a terminal-like environment via WebSocket.
15
+ */
16
+ const cbterminal = {
17
+ eventEmitter: new CustomEventEmitter(),
18
+ /**
19
+ * Executes a given command and returns the result.
20
+ * Listens for messages from the WebSocket that indicate the output, error, or finish state
21
+ * of the executed command and resolves the promise accordingly.
22
+ *
23
+ * @param {string} command - The command to be executed.
24
+ * @returns {Promise<CommandOutput|CommandError>} A promise that resolves with the command's output, error, or finish signal.
25
+ */
26
+ executeCommand: async (command, returnEmptyStringOnSuccess = false) => {
27
+ return new Promise((resolve, reject) => {
28
+ websocket_1.default.getWebsocket.send(JSON.stringify({
29
+ "type": "executeCommand",
30
+ "message": command,
31
+ returnEmptyStringOnSuccess
32
+ }));
33
+ let result = "";
34
+ websocket_1.default.getWebsocket.on('message', (data) => {
35
+ const response = JSON.parse(data);
36
+ if (response.type === "commandError" || response.type === "commandFinish") {
37
+ resolve(response);
38
+ }
39
+ });
40
+ });
41
+ },
42
+ /**
43
+ * Executes a given command and keeps running until an error occurs.
44
+ * Listens for messages from the WebSocket and resolves the promise when an error is encountered.
45
+ *
46
+ * @param {string} command - The command to be executed.
47
+ * @returns {Promise<CommandError>} A promise that resolves when an error occurs during command execution.
48
+ */
49
+ executeCommandRunUntilError: async (command, executeInMain = false) => {
50
+ return new Promise((resolve, reject) => {
51
+ websocket_1.default.getWebsocket.send(JSON.stringify({
52
+ "type": "executeCommandRunUntilError",
53
+ "message": command,
54
+ executeInMain
55
+ }));
56
+ websocket_1.default.getWebsocket.on('message', (data) => {
57
+ const response = JSON.parse(data);
58
+ if (response.type === "commandError") {
59
+ resolve(response);
60
+ }
61
+ });
62
+ });
63
+ },
64
+ /**
65
+ * Sends a manual interrupt signal to the terminal.
66
+ *
67
+ * @returns {Promise<TerminalInterruptResponse>}
68
+ */
69
+ sendManualInterrupt() {
70
+ return new Promise((resolve, reject) => {
71
+ websocket_1.default.getWebsocket.send(JSON.stringify({
72
+ "type": "sendInterruptToTerminal"
73
+ }));
74
+ websocket_1.default.getWebsocket.on('message', (data) => {
75
+ const response = JSON.parse(data);
76
+ if (response.type === "terminalInterrupted") {
77
+ resolve(response);
78
+ }
79
+ });
80
+ });
81
+ },
82
+ /**
83
+ * Executes a given command and streams the output.
84
+ * Listens for messages from the WebSocket and streams the output data.
85
+ *
86
+ * @param {string} command - The command to be executed.
87
+ * @returns {EventEmitter} A promise that streams the output data during command execution.
88
+ */
89
+ executeCommandWithStream(command, executeInMain = false) {
90
+ // Send the process started message
91
+ websocket_1.default.getWebsocket.send(JSON.stringify({
92
+ "type": "executeCommandWithStream",
93
+ "message": command,
94
+ executeInMain
95
+ }));
96
+ // Register event listener for WebSocket messages
97
+ websocket_1.default.getWebsocket.on('message', (data) => {
98
+ const response = JSON.parse(data);
99
+ console.log("Received message:", response);
100
+ if (response.type === "commandOutput" || response.type === "commandError" || response.type === "commandFinish") {
101
+ this.eventEmitter.emit(response.type, response);
102
+ }
103
+ });
104
+ // Return an object that includes the event emitter and the stopProcess method
105
+ return this.eventEmitter;
106
+ }
107
+ };
108
+ exports.default = cbterminal;
@@ -0,0 +1,19 @@
1
+ import { AddTokenResponse, GetTokenResponse } from '@codebolt/types';
2
+ /**
3
+ * Tokenizer module for handling token-related operations.
4
+ */
5
+ declare const tokenizer: {
6
+ /**
7
+ * Adds a token to the system via WebSocket.
8
+ * @param {string} key - The key associated with the token to be added.
9
+ * @returns {Promise<AddTokenResponse>} A promise that resolves with the response from the add token event.
10
+ */
11
+ addToken: (key: string) => Promise<AddTokenResponse>;
12
+ /**
13
+ * Retrieves a token from the system via WebSocket.
14
+ * @param {string} key - The key associated with the token to be retrieved.
15
+ * @returns {Promise<GetTokenResponse>} A promise that resolves with the response from the get token event.
16
+ */
17
+ getToken: (key: string) => Promise<GetTokenResponse>;
18
+ };
19
+ export default tokenizer;
@@ -0,0 +1,56 @@
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
+ * Tokenizer module for handling token-related operations.
9
+ */
10
+ const tokenizer = {
11
+ /**
12
+ * Adds a token to the system via WebSocket.
13
+ * @param {string} key - The key associated with the token to be added.
14
+ * @returns {Promise<AddTokenResponse>} A promise that resolves with the response from the add token event.
15
+ */
16
+ addToken: async (key) => {
17
+ return new Promise((resolve, reject) => {
18
+ websocket_1.default.getWebsocket.send(JSON.stringify({
19
+ "type": "tokenizerEvent",
20
+ "action": "addToken",
21
+ "message": {
22
+ item: key
23
+ },
24
+ }));
25
+ websocket_1.default.getWebsocket.on('message', (data) => {
26
+ const response = JSON.parse(data);
27
+ if (response.type === "addTokenResponse") {
28
+ resolve(response);
29
+ }
30
+ });
31
+ });
32
+ },
33
+ /**
34
+ * Retrieves a token from the system via WebSocket.
35
+ * @param {string} key - The key associated with the token to be retrieved.
36
+ * @returns {Promise<GetTokenResponse>} A promise that resolves with the response from the get token event.
37
+ */
38
+ getToken: async (key) => {
39
+ return new Promise((resolve, reject) => {
40
+ websocket_1.default.getWebsocket.send(JSON.stringify({
41
+ "type": "tokenizerEvent",
42
+ "action": "getToken",
43
+ "message": {
44
+ item: key
45
+ },
46
+ }));
47
+ websocket_1.default.getWebsocket.on('message', (data) => {
48
+ const response = JSON.parse(data);
49
+ if (response.type === "getTokenResponse") {
50
+ resolve(response);
51
+ }
52
+ });
53
+ });
54
+ }
55
+ };
56
+ exports.default = tokenizer;
@@ -0,0 +1,33 @@
1
+ import { AddVectorItemResponse, GetVectorResponse, QueryVectorItemResponse } from '@codebolt/types';
2
+ declare const VectorDB: {
3
+ /**
4
+ * Retrieves a vector from the vector database based on the provided key.
5
+ *
6
+ * @param {string} key - The key of the vector to retrieve.
7
+ * @returns {Promise<GetVectorResponse>} A promise that resolves with the retrieved vector.
8
+ */
9
+ getVector: (key: string) => Promise<GetVectorResponse>;
10
+ /**
11
+ * Adds a new vector item to the vector database.
12
+ *
13
+
14
+ * @param {any} item - The item to add to the vector.
15
+ * @returns {Promise<AddVectorItemResponse>} A promise that resolves when the item is successfully added.
16
+ */
17
+ addVectorItem: (item: any) => Promise<AddVectorItemResponse>;
18
+ /**
19
+ * Queries a vector item from the vector database based on the provided key.
20
+ *
21
+ * @param {string} key - The key of the vector to query the item from.
22
+ * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
23
+ */
24
+ queryVectorItem: (key: string) => Promise<QueryVectorItemResponse>;
25
+ /**
26
+ * Queries a vector item from the vector database based on the provided key.
27
+ *
28
+ * @param {string} key - The key of the vector to query the item from.
29
+ * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
30
+ */
31
+ queryVectorItems: (items: [], dbPath: string) => Promise<QueryVectorItemResponse>;
32
+ };
33
+ export default VectorDB;
@@ -0,0 +1,103 @@
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
+ const VectorDB = {
8
+ /**
9
+ * Retrieves a vector from the vector database based on the provided key.
10
+ *
11
+ * @param {string} key - The key of the vector to retrieve.
12
+ * @returns {Promise<GetVectorResponse>} A promise that resolves with the retrieved vector.
13
+ */
14
+ getVector: async (key) => {
15
+ return new Promise((resolve, reject) => {
16
+ websocket_1.default.getWebsocket.send(JSON.stringify({
17
+ "type": "vectordbEvent",
18
+ "action": "getVector",
19
+ "message": {
20
+ item: key
21
+ },
22
+ }));
23
+ websocket_1.default.getWebsocket.on('message', (data) => {
24
+ const response = JSON.parse(data);
25
+ if (response.type === "getVectorResponse") {
26
+ resolve(response);
27
+ }
28
+ });
29
+ });
30
+ },
31
+ /**
32
+ * Adds a new vector item to the vector database.
33
+ *
34
+
35
+ * @param {any} item - The item to add to the vector.
36
+ * @returns {Promise<AddVectorItemResponse>} A promise that resolves when the item is successfully added.
37
+ */
38
+ addVectorItem: async (item) => {
39
+ return new Promise((resolve, reject) => {
40
+ websocket_1.default.getWebsocket.send(JSON.stringify({
41
+ "type": "vectordbEvent",
42
+ "action": "addVectorItem",
43
+ "message": {
44
+ item: item
45
+ },
46
+ }));
47
+ websocket_1.default.getWebsocket.on('message', (data) => {
48
+ const response = JSON.parse(data);
49
+ if (response.type === "addVectorItemResponse") {
50
+ resolve(response);
51
+ }
52
+ });
53
+ });
54
+ },
55
+ /**
56
+ * Queries a vector item from the vector database based on the provided key.
57
+ *
58
+ * @param {string} key - The key of the vector to query the item from.
59
+ * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
60
+ */
61
+ queryVectorItem: async (key) => {
62
+ return new Promise((resolve, reject) => {
63
+ websocket_1.default.getWebsocket.send(JSON.stringify({
64
+ "type": "vectordbEvent",
65
+ "action": "queryVectorItem",
66
+ "message": {
67
+ item: key
68
+ },
69
+ }));
70
+ websocket_1.default.getWebsocket.on('message', (data) => {
71
+ const response = JSON.parse(data);
72
+ if (response.type === "qeryVectorItemResponse") {
73
+ resolve(response);
74
+ }
75
+ });
76
+ });
77
+ },
78
+ /**
79
+ * Queries a vector item from the vector database based on the provided key.
80
+ *
81
+ * @param {string} key - The key of the vector to query the item from.
82
+ * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
83
+ */
84
+ queryVectorItems: async (items, dbPath) => {
85
+ return new Promise((resolve, reject) => {
86
+ websocket_1.default.getWebsocket.send(JSON.stringify({
87
+ "type": "vectordbEvent",
88
+ "action": "queryVectorItems",
89
+ "message": {
90
+ items,
91
+ dbPath
92
+ },
93
+ }));
94
+ websocket_1.default.getWebsocket.on('message', (data) => {
95
+ const response = JSON.parse(data);
96
+ if (response.type === "qeryVectorItemsResponse") {
97
+ resolve(response);
98
+ }
99
+ });
100
+ });
101
+ },
102
+ };
103
+ exports.default = VectorDB;
@@ -0,0 +1,27 @@
1
+ import WebSocket from 'ws';
2
+ /**
3
+ * Class representing a WebSocket connection.
4
+ */
5
+ declare class cbws {
6
+ websocket: WebSocket;
7
+ /**
8
+ * Constructs a new cbws instance and initializes the WebSocket connection.
9
+ */
10
+ constructor();
11
+ private getUniqueConnectionId;
12
+ private getInitialMessage;
13
+ /**
14
+ * Initializes the WebSocket by setting up event listeners and returning a promise that resolves
15
+ * when the WebSocket connection is successfully opened.
16
+ * @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
17
+ */
18
+ private initializeWebSocket;
19
+ /**
20
+ * Getter for the WebSocket instance. Throws an error if the WebSocket is not open.
21
+ * @returns {WebSocket} The WebSocket instance.
22
+ * @throws {Error} If the WebSocket is not open.
23
+ */
24
+ get getWebsocket(): WebSocket;
25
+ }
26
+ declare const _default: cbws;
27
+ export default _default;
@@ -0,0 +1,88 @@
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 ws_1 = __importDefault(require("ws"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const js_yaml_1 = __importDefault(require("js-yaml"));
9
+ /**
10
+ * Class representing a WebSocket connection.
11
+ */
12
+ class cbws {
13
+ /**
14
+ * Constructs a new cbws instance and initializes the WebSocket connection.
15
+ */
16
+ constructor() {
17
+ const uniqueConnectionId = this.getUniqueConnectionId();
18
+ const initialMessage = this.getInitialMessage();
19
+ console.log(uniqueConnectionId);
20
+ this.websocket = new ws_1.default(`ws://localhost:${process.env.SOCKET_PORT}/codebolt?id=${uniqueConnectionId}${process.env.Is_Dev ? '&dev=true' : ''}`);
21
+ this.initializeWebSocket(initialMessage).catch(error => {
22
+ console.error("WebSocket connection failed:", error);
23
+ });
24
+ }
25
+ getUniqueConnectionId() {
26
+ try {
27
+ let fileContents = fs_1.default.readFileSync('./codeboltagent.yaml', 'utf8');
28
+ let data = js_yaml_1.default.load(fileContents);
29
+ return data.unique_connectionid;
30
+ }
31
+ catch (e) {
32
+ console.error('Unable to locate codeboltagent.yaml file.');
33
+ return '';
34
+ }
35
+ }
36
+ getInitialMessage() {
37
+ try {
38
+ let fileContents = fs_1.default.readFileSync('./codeboltagent.yaml', 'utf8');
39
+ let data = js_yaml_1.default.load(fileContents);
40
+ return data.initial_message;
41
+ }
42
+ catch (e) {
43
+ console.error('Unable to locate codeboltagent.yaml file.');
44
+ return '';
45
+ }
46
+ }
47
+ /**
48
+ * Initializes the WebSocket by setting up event listeners and returning a promise that resolves
49
+ * when the WebSocket connection is successfully opened.
50
+ * @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
51
+ */
52
+ async initializeWebSocket(initialMessage) {
53
+ return new Promise((resolve, reject) => {
54
+ this.websocket.on('error', (error) => {
55
+ console.log('WebSocket error:', error);
56
+ reject(error);
57
+ });
58
+ this.websocket.on('open', () => {
59
+ console.log('WebSocket connected');
60
+ // if (this.websocket) {
61
+ // this.websocket.send(JSON.stringify({
62
+ // "type": "sendMessage",
63
+ // "message": initialMessage
64
+ // }));
65
+ // resolve(this.websocket);
66
+ // }
67
+ });
68
+ this.websocket.on('message', (data) => {
69
+ // Handle incoming WebSocket messages here.
70
+ // console.log('WebSocket message received:', data);
71
+ });
72
+ });
73
+ }
74
+ /**
75
+ * Getter for the WebSocket instance. Throws an error if the WebSocket is not open.
76
+ * @returns {WebSocket} The WebSocket instance.
77
+ * @throws {Error} If the WebSocket is not open.
78
+ */
79
+ get getWebsocket() {
80
+ if (!this.websocket.OPEN) {
81
+ throw new Error('WebSocket is not open');
82
+ }
83
+ else {
84
+ return this.websocket;
85
+ }
86
+ }
87
+ }
88
+ exports.default = new cbws();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "1.1.76",
3
+ "version": "1.1.77",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",