@codebolt/codeboltjs 1.1.13 → 1.1.16
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.
- package/index.js +2 -0
- package/modules/state.d.ts +4 -0
- package/modules/state.js +4 -0
- package/modules/task.d.ts +23 -0
- package/modules/task.js +74 -0
- package/modules/terminal.d.ts +34 -0
- package/modules/terminal.js +75 -0
- package/package.json +1 -1
- package/src/index.ts +4 -2
- package/src/modules/state.ts +4 -2
- package/src/modules/task.ts +73 -0
- package/src/modules/terminal.ts +81 -0
package/index.js
CHANGED
|
@@ -21,6 +21,7 @@ const project_1 = __importDefault(require("./modules/project"));
|
|
|
21
21
|
const git_1 = __importDefault(require("./modules/git"));
|
|
22
22
|
const dbmemory_1 = __importDefault(require("./modules/dbmemory"));
|
|
23
23
|
const state_1 = __importDefault(require("./modules/state"));
|
|
24
|
+
const task_1 = __importDefault(require("./modules/task"));
|
|
24
25
|
const ws_1 = __importDefault(require("ws"));
|
|
25
26
|
/**
|
|
26
27
|
* @class Codebolt
|
|
@@ -50,6 +51,7 @@ class Codebolt {
|
|
|
50
51
|
this.project = project_1.default;
|
|
51
52
|
this.dbmemory = dbmemory_1.default;
|
|
52
53
|
this.cbstate = state_1.default;
|
|
54
|
+
this.taskplaner = task_1.default;
|
|
53
55
|
this.websocket = websocket_1.default.getWebsocket;
|
|
54
56
|
}
|
|
55
57
|
/**
|
package/modules/state.d.ts
CHANGED
package/modules/state.js
CHANGED
|
@@ -4,6 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const websocket_1 = __importDefault(require("./websocket"));
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves the application state asynchronously.
|
|
9
|
+
* @returns {Promise<any>} A promise that resolves with the application state.
|
|
10
|
+
*/
|
|
7
11
|
const cbstate = {
|
|
8
12
|
getApplicationState: async () => {
|
|
9
13
|
return new Promise((resolve, reject) => {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages task operations via WebSocket communication.
|
|
3
|
+
*/
|
|
4
|
+
declare const taskplaner: {
|
|
5
|
+
/**
|
|
6
|
+
* Adds a task using a WebSocket message.
|
|
7
|
+
* @param {string} task - The task to be added.
|
|
8
|
+
* @returns {Promise<any>} A promise that resolves with the response from the add task event.
|
|
9
|
+
*/
|
|
10
|
+
addTask: (task: string) => Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves all tasks using a WebSocket message.
|
|
13
|
+
* @returns {Promise<any>} A promise that resolves with the response from the get tasks event.
|
|
14
|
+
*/
|
|
15
|
+
getTasks: () => Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* Updates an existing task using a WebSocket message.
|
|
18
|
+
* @param {string} task - The updated task information.
|
|
19
|
+
* @returns {Promise<any>} A promise that resolves with the response from the update task event.
|
|
20
|
+
*/
|
|
21
|
+
updateTask: (task: string) => Promise<any>;
|
|
22
|
+
};
|
|
23
|
+
export default taskplaner;
|
package/modules/task.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
* Manages task operations via WebSocket communication.
|
|
9
|
+
*/
|
|
10
|
+
const taskplaner = {
|
|
11
|
+
/**
|
|
12
|
+
* Adds a task using a WebSocket message.
|
|
13
|
+
* @param {string} task - The task to be added.
|
|
14
|
+
* @returns {Promise<any>} A promise that resolves with the response from the add task event.
|
|
15
|
+
*/
|
|
16
|
+
addTask: async (task) => {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
19
|
+
"type": "taskEvent",
|
|
20
|
+
"action": "addTask",
|
|
21
|
+
message: {
|
|
22
|
+
"task": task
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
26
|
+
const response = JSON.parse(data);
|
|
27
|
+
if (response.type === "addTaskResponse") {
|
|
28
|
+
resolve(response); // Resolve the promise with the response data from adding the task
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves all tasks using a WebSocket message.
|
|
35
|
+
* @returns {Promise<any>} A promise that resolves with the response from the get tasks event.
|
|
36
|
+
*/
|
|
37
|
+
getTasks: async () => {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
40
|
+
"type": "taskEvent",
|
|
41
|
+
"action": "getTasks"
|
|
42
|
+
}));
|
|
43
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
44
|
+
const response = JSON.parse(data);
|
|
45
|
+
if (response.type === "getTasksResponse") {
|
|
46
|
+
resolve(response); // Resolve the promise with the response data from retrieving tasks
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* Updates an existing task using a WebSocket message.
|
|
53
|
+
* @param {string} task - The updated task information.
|
|
54
|
+
* @returns {Promise<any>} A promise that resolves with the response from the update task event.
|
|
55
|
+
*/
|
|
56
|
+
updateTask: async (task) => {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
59
|
+
"type": "taskEvent",
|
|
60
|
+
"action": "updateTask",
|
|
61
|
+
message: {
|
|
62
|
+
"task": task
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
66
|
+
const response = JSON.parse(data);
|
|
67
|
+
if (response.type === "updateTaskResponse") {
|
|
68
|
+
resolve(response); // Resolve the promise with the response data from updating the task
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.default = taskplaner;
|
package/modules/terminal.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
/**
|
|
4
|
+
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
5
|
+
*/
|
|
6
|
+
declare class CustomEventEmitter extends EventEmitter {
|
|
7
|
+
}
|
|
1
8
|
/**
|
|
2
9
|
* A module for executing commands in a terminal-like environment via WebSocket.
|
|
3
10
|
*/
|
|
4
11
|
declare const cbterminal: {
|
|
12
|
+
eventEmitter: CustomEventEmitter;
|
|
5
13
|
/**
|
|
6
14
|
* Executes a given command and returns the result.
|
|
7
15
|
* Listens for messages from the WebSocket that indicate the output, error, or finish state
|
|
@@ -11,5 +19,31 @@ declare const cbterminal: {
|
|
|
11
19
|
* @returns {Promise<any>} A promise that resolves with the command's output, error, or finish signal.
|
|
12
20
|
*/
|
|
13
21
|
executeCommand: (command: string) => Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* Executes a given command and keeps running until an error occurs.
|
|
24
|
+
* Listens for messages from the WebSocket and resolves the promise when an error is encountered.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} command - The command to be executed.
|
|
27
|
+
* @returns {Promise<any>} A promise that resolves when an error occurs during command execution.
|
|
28
|
+
*/
|
|
29
|
+
executeCommandRunUntilError: (command: string) => Promise<any>;
|
|
30
|
+
/**
|
|
31
|
+
* Executes a given command and keeps running until interrupted.
|
|
32
|
+
* Listens for messages from the WebSocket and resolves the promise when an interruption signal is received.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} command - The command to be executed.
|
|
35
|
+
* @returns {Promise<any>} A promise that resolves when an interruption signal is received during command execution.
|
|
36
|
+
*/
|
|
37
|
+
executeCommandRunUnitlIntrupt: (command: string) => Promise<any>;
|
|
38
|
+
/**
|
|
39
|
+
* Executes a given command and streams the output.
|
|
40
|
+
* Listens for messages from the WebSocket and streams the output data.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} command - The command to be executed.
|
|
43
|
+
* @returns {Promise<any>} A promise that streams the output data during command execution.
|
|
44
|
+
*/
|
|
45
|
+
executeCommandWithStream(command: string): {
|
|
46
|
+
event: CustomEventEmitter;
|
|
47
|
+
};
|
|
14
48
|
};
|
|
15
49
|
export default cbterminal;
|
package/modules/terminal.js
CHANGED
|
@@ -4,10 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
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
|
+
}
|
|
7
13
|
/**
|
|
8
14
|
* A module for executing commands in a terminal-like environment via WebSocket.
|
|
9
15
|
*/
|
|
10
16
|
const cbterminal = {
|
|
17
|
+
eventEmitter: new CustomEventEmitter(),
|
|
11
18
|
/**
|
|
12
19
|
* Executes a given command and returns the result.
|
|
13
20
|
* Listens for messages from the WebSocket that indicate the output, error, or finish state
|
|
@@ -29,6 +36,74 @@ const cbterminal = {
|
|
|
29
36
|
}
|
|
30
37
|
});
|
|
31
38
|
});
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Executes a given command and keeps running until an error occurs.
|
|
42
|
+
* Listens for messages from the WebSocket and resolves the promise when an error is encountered.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} command - The command to be executed.
|
|
45
|
+
* @returns {Promise<any>} A promise that resolves when an error occurs during command execution.
|
|
46
|
+
*/
|
|
47
|
+
executeCommandRunUntilError: async (command) => {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
50
|
+
"type": "executeCommandRunUntilError",
|
|
51
|
+
"message": command,
|
|
52
|
+
}));
|
|
53
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
54
|
+
const response = JSON.parse(data);
|
|
55
|
+
if (response.type === "commandError") {
|
|
56
|
+
resolve(response);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Executes a given command and keeps running until interrupted.
|
|
63
|
+
* Listens for messages from the WebSocket and resolves the promise when an interruption signal is received.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} command - The command to be executed.
|
|
66
|
+
* @returns {Promise<any>} A promise that resolves when an interruption signal is received during command execution.
|
|
67
|
+
*/
|
|
68
|
+
executeCommandRunUnitlIntrupt: async (command) => {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
71
|
+
"type": "executeCommandRunUnitlIntrupt",
|
|
72
|
+
"message": command,
|
|
73
|
+
}));
|
|
74
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
75
|
+
const response = JSON.parse(data);
|
|
76
|
+
if (response.type === "terminalIntruptResponse") {
|
|
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 {Promise<any>} A promise that streams the output data during command execution.
|
|
88
|
+
*/
|
|
89
|
+
executeCommandWithStream(command) {
|
|
90
|
+
// Send the process started message
|
|
91
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
92
|
+
"type": "executeCommandWithStream",
|
|
93
|
+
"message": command,
|
|
94
|
+
}));
|
|
95
|
+
// Register event listener for WebSocket messages
|
|
96
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
97
|
+
const response = JSON.parse(data);
|
|
98
|
+
console.log("Received message:", response);
|
|
99
|
+
if (response.type === "commandOutput" || response.type === "commandError" || response.type === "commandFinish")
|
|
100
|
+
// Emit a custom event based on the message type
|
|
101
|
+
this.eventEmitter.emit("serverEvents", response.response);
|
|
102
|
+
});
|
|
103
|
+
// Return an object that includes the event emitter and the stopProcess method
|
|
104
|
+
return {
|
|
105
|
+
event: this.eventEmitter
|
|
106
|
+
};
|
|
32
107
|
}
|
|
33
108
|
};
|
|
34
109
|
exports.default = cbterminal;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -15,9 +15,11 @@ import cboutputparsers from './modules/outputparsers';
|
|
|
15
15
|
import cbproject from './modules/project';
|
|
16
16
|
import git from './modules/git';
|
|
17
17
|
import dbmemory from './modules/dbmemory';
|
|
18
|
-
import cbstate from './modules/state'
|
|
18
|
+
import cbstate from './modules/state';
|
|
19
|
+
import task from './modules/task';
|
|
19
20
|
import WebSocket from 'ws';
|
|
20
21
|
|
|
22
|
+
|
|
21
23
|
/**
|
|
22
24
|
* @class Codebolt
|
|
23
25
|
* @description This class provides a unified interface to interact with various modules.
|
|
@@ -70,7 +72,6 @@ class Codebolt {
|
|
|
70
72
|
start_browser(objective:string, url:string, previous_command:string, browser_content:string) {
|
|
71
73
|
cbbrowser.newPage();
|
|
72
74
|
}
|
|
73
|
-
|
|
74
75
|
websocket: WebSocket | null = null;
|
|
75
76
|
fs = cbfs;
|
|
76
77
|
git=git;
|
|
@@ -89,6 +90,7 @@ class Codebolt {
|
|
|
89
90
|
project = cbproject;
|
|
90
91
|
dbmemory = dbmemory;
|
|
91
92
|
cbstate=cbstate;
|
|
93
|
+
taskplaner=task
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
// export default new Codebolt();
|
package/src/modules/state.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import cbws from './websocket';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the application state asynchronously.
|
|
5
|
+
* @returns {Promise<any>} A promise that resolves with the application state.
|
|
6
|
+
*/
|
|
4
7
|
const cbstate = {
|
|
5
8
|
getApplicationState: async (): Promise<any> => {
|
|
6
9
|
return new Promise((resolve, reject) => {
|
|
@@ -19,4 +22,3 @@ const cbstate = {
|
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export default cbstate;
|
|
22
|
-
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
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<any>} 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<any>} 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<any>} 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;
|
package/src/modules/terminal.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import cbws from './websocket';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
6
|
+
*/
|
|
7
|
+
class CustomEventEmitter extends EventEmitter {}
|
|
3
8
|
/**
|
|
4
9
|
* A module for executing commands in a terminal-like environment via WebSocket.
|
|
5
10
|
*/
|
|
6
11
|
const cbterminal = {
|
|
12
|
+
eventEmitter: new CustomEventEmitter(),
|
|
7
13
|
|
|
8
14
|
/**
|
|
9
15
|
* Executes a given command and returns the result.
|
|
@@ -26,6 +32,81 @@ const cbterminal = {
|
|
|
26
32
|
}
|
|
27
33
|
});
|
|
28
34
|
});
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Executes a given command and keeps running until an error occurs.
|
|
39
|
+
* Listens for messages from the WebSocket and resolves the promise when an error is encountered.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} command - The command to be executed.
|
|
42
|
+
* @returns {Promise<any>} A promise that resolves when an error occurs during command execution.
|
|
43
|
+
*/
|
|
44
|
+
executeCommandRunUntilError: async (command: string): Promise<any> => {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
47
|
+
"type": "executeCommandRunUntilError",
|
|
48
|
+
"message": command,
|
|
49
|
+
}));
|
|
50
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
51
|
+
const response = JSON.parse(data);
|
|
52
|
+
if ( response.type === "commandError") {
|
|
53
|
+
resolve(response);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Executes a given command and keeps running until interrupted.
|
|
61
|
+
* Listens for messages from the WebSocket and resolves the promise when an interruption signal is received.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} command - The command to be executed.
|
|
64
|
+
* @returns {Promise<any>} A promise that resolves when an interruption signal is received during command execution.
|
|
65
|
+
*/
|
|
66
|
+
executeCommandRunUnitlIntrupt: async (command: string): Promise<any> => {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
69
|
+
"type": "executeCommandRunUnitlIntrupt",
|
|
70
|
+
"message": command,
|
|
71
|
+
}));
|
|
72
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
73
|
+
const response = JSON.parse(data);
|
|
74
|
+
if (response.type === "terminalIntruptResponse") {
|
|
75
|
+
resolve(response);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Executes a given command and streams the output.
|
|
83
|
+
* Listens for messages from the WebSocket and streams the output data.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} command - The command to be executed.
|
|
86
|
+
* @returns {Promise<any>} A promise that streams the output data during command execution.
|
|
87
|
+
*/
|
|
88
|
+
executeCommandWithStream(command: string) {
|
|
89
|
+
// Send the process started message
|
|
90
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
91
|
+
"type": "executeCommandWithStream",
|
|
92
|
+
"message": command,
|
|
93
|
+
}));
|
|
94
|
+
// Register event listener for WebSocket messages
|
|
95
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
96
|
+
const response = JSON.parse(data);
|
|
97
|
+
console.log("Received message:", response);
|
|
98
|
+
if (response.type === "commandOutput" || response.type === "commandError" || response.type === "commandFinish")
|
|
99
|
+
// Emit a custom event based on the message type
|
|
100
|
+
this.eventEmitter.emit("serverEvents", response.response);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Return an object that includes the event emitter and the stopProcess method
|
|
104
|
+
return {
|
|
105
|
+
event: this.eventEmitter
|
|
106
|
+
};
|
|
29
107
|
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
30
111
|
};
|
|
31
112
|
export default cbterminal;
|