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