@codebolt/codeboltjs 1.1.46 → 1.1.48
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.d.ts +1 -0
- package/modules/chat.d.ts +5 -0
- package/modules/chat.js +12 -1
- package/modules/websocket.d.ts +1 -0
- package/modules/websocket.js +17 -4
- package/package.json +1 -1
- package/src/modules/chat.ts +13 -1
- package/src/modules/websocket.ts +17 -4
package/index.d.ts
CHANGED
|
@@ -108,6 +108,7 @@ declare class Codebolt {
|
|
|
108
108
|
};
|
|
109
109
|
stopProcess: () => void;
|
|
110
110
|
sendConfirmationRequest: (confirmationMessage: string, buttons?: string[]) => Promise<string>;
|
|
111
|
+
sendNotificationEvent: (notificationMessage: string, type: "debug" | "git" | "planner" | "browser" | "editor" | "terminal" | "preview") => void;
|
|
111
112
|
};
|
|
112
113
|
terminal: {
|
|
113
114
|
eventEmitter: {
|
package/modules/chat.d.ts
CHANGED
|
@@ -49,5 +49,10 @@ declare const cbchat: {
|
|
|
49
49
|
* @returns {Promise<string>} A promise that resolves with the server's response.
|
|
50
50
|
*/
|
|
51
51
|
sendConfirmationRequest: (confirmationMessage: string, buttons?: string[]) => Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Sends a notification event to the server.
|
|
54
|
+
* @param {string} notificationMessage - The message to be sent in the notification.
|
|
55
|
+
*/
|
|
56
|
+
sendNotificationEvent: (notificationMessage: string, type: 'debug' | 'git' | 'planner' | 'browser' | 'editor' | 'terminal' | 'preview') => void;
|
|
52
57
|
};
|
|
53
58
|
export default cbchat;
|
package/modules/chat.js
CHANGED
|
@@ -144,6 +144,17 @@ const cbchat = {
|
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
|
-
}
|
|
147
|
+
},
|
|
148
|
+
/**
|
|
149
|
+
* Sends a notification event to the server.
|
|
150
|
+
* @param {string} notificationMessage - The message to be sent in the notification.
|
|
151
|
+
*/
|
|
152
|
+
sendNotificationEvent: (notificationMessage, type) => {
|
|
153
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
154
|
+
"type": "notificationEvent",
|
|
155
|
+
"message": notificationMessage,
|
|
156
|
+
"eventType": type
|
|
157
|
+
}));
|
|
158
|
+
},
|
|
148
159
|
};
|
|
149
160
|
exports.default = cbchat;
|
package/modules/websocket.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare class cbws {
|
|
|
9
9
|
*/
|
|
10
10
|
constructor();
|
|
11
11
|
private getUniqueConnectionId;
|
|
12
|
+
private getInitialMessage;
|
|
12
13
|
/**
|
|
13
14
|
* Initializes the WebSocket by setting up event listeners and returning a promise that resolves
|
|
14
15
|
* when the WebSocket connection is successfully opened.
|
package/modules/websocket.js
CHANGED
|
@@ -15,20 +15,32 @@ class cbws {
|
|
|
15
15
|
*/
|
|
16
16
|
constructor() {
|
|
17
17
|
const uniqueConnectionId = this.getUniqueConnectionId();
|
|
18
|
+
const initialMessage = this.getInitialMessage();
|
|
18
19
|
console.log(uniqueConnectionId);
|
|
19
20
|
this.websocket = new ws_1.default(`ws://localhost:12345/codebolt?id=${uniqueConnectionId}`);
|
|
20
|
-
this.initializeWebSocket().catch(error => {
|
|
21
|
+
this.initializeWebSocket(initialMessage).catch(error => {
|
|
21
22
|
console.error("WebSocket connection failed:", error);
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
getUniqueConnectionId() {
|
|
25
26
|
try {
|
|
26
|
-
let fileContents = fs_1.default.readFileSync('./
|
|
27
|
+
let fileContents = fs_1.default.readFileSync('./codeboltagent.yml', 'utf8');
|
|
27
28
|
let data = js_yaml_1.default.load(fileContents);
|
|
28
29
|
return data.uniqueConnectionId;
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
31
|
-
console.error('Unable to locate
|
|
32
|
+
console.error('Unable to locate codeboltagent.yml file.');
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getInitialMessage() {
|
|
37
|
+
try {
|
|
38
|
+
let fileContents = fs_1.default.readFileSync('./codeboltagent.yml', 'utf8');
|
|
39
|
+
let data = js_yaml_1.default.load(fileContents);
|
|
40
|
+
return data.initialMessage;
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
console.error('Unable to locate codeboltagent.yml file.');
|
|
32
44
|
return '';
|
|
33
45
|
}
|
|
34
46
|
}
|
|
@@ -37,7 +49,7 @@ class cbws {
|
|
|
37
49
|
* when the WebSocket connection is successfully opened.
|
|
38
50
|
* @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
|
|
39
51
|
*/
|
|
40
|
-
async initializeWebSocket() {
|
|
52
|
+
async initializeWebSocket(initialMessage) {
|
|
41
53
|
return new Promise((resolve, reject) => {
|
|
42
54
|
this.websocket.on('error', (error) => {
|
|
43
55
|
console.log('WebSocket error:', error);
|
|
@@ -46,6 +58,7 @@ class cbws {
|
|
|
46
58
|
this.websocket.on('open', () => {
|
|
47
59
|
console.log('WebSocket connected');
|
|
48
60
|
if (this.websocket) {
|
|
61
|
+
this.websocket.send(initialMessage);
|
|
49
62
|
resolve(this.websocket);
|
|
50
63
|
}
|
|
51
64
|
});
|
package/package.json
CHANGED
package/src/modules/chat.ts
CHANGED
|
@@ -150,7 +150,19 @@ const cbchat = {
|
|
|
150
150
|
}
|
|
151
151
|
});
|
|
152
152
|
});
|
|
153
|
-
}
|
|
153
|
+
},
|
|
154
|
+
/**
|
|
155
|
+
* Sends a notification event to the server.
|
|
156
|
+
* @param {string} notificationMessage - The message to be sent in the notification.
|
|
157
|
+
*/
|
|
158
|
+
sendNotificationEvent: (notificationMessage: string, type: 'debug' | 'git' | 'planner' | 'browser' | 'editor' | 'terminal' | 'preview'): void => {
|
|
159
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
160
|
+
"type": "notificationEvent",
|
|
161
|
+
"message": notificationMessage,
|
|
162
|
+
"eventType":type
|
|
163
|
+
}));
|
|
164
|
+
},
|
|
165
|
+
|
|
154
166
|
};
|
|
155
167
|
|
|
156
168
|
export default cbchat;
|
package/src/modules/websocket.ts
CHANGED
|
@@ -13,19 +13,31 @@ class cbws {
|
|
|
13
13
|
*/
|
|
14
14
|
constructor() {
|
|
15
15
|
const uniqueConnectionId = this.getUniqueConnectionId();
|
|
16
|
+
const initialMessage = this.getInitialMessage();
|
|
16
17
|
console.log(uniqueConnectionId)
|
|
17
18
|
this.websocket = new WebSocket(`ws://localhost:12345/codebolt?id=${uniqueConnectionId}`);
|
|
18
|
-
this.initializeWebSocket().catch(error => {
|
|
19
|
+
this.initializeWebSocket(initialMessage).catch(error => {
|
|
19
20
|
console.error("WebSocket connection failed:", error);
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
private getUniqueConnectionId(): string {
|
|
23
24
|
try {
|
|
24
|
-
let fileContents = fs.readFileSync('./
|
|
25
|
+
let fileContents = fs.readFileSync('./codeboltagent.yml', 'utf8');
|
|
25
26
|
let data:any = yaml.load(fileContents);
|
|
26
27
|
return data.uniqueConnectionId;
|
|
27
28
|
} catch (e) {
|
|
28
|
-
console.error('Unable to locate
|
|
29
|
+
console.error('Unable to locate codeboltagent.yml file.');
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private getInitialMessage(): string {
|
|
35
|
+
try {
|
|
36
|
+
let fileContents = fs.readFileSync('./codeboltagent.yml', 'utf8');
|
|
37
|
+
let data:any = yaml.load(fileContents);
|
|
38
|
+
return data.initialMessage;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error('Unable to locate codeboltagent.yml file.');
|
|
29
41
|
return '';
|
|
30
42
|
}
|
|
31
43
|
}
|
|
@@ -35,7 +47,7 @@ class cbws {
|
|
|
35
47
|
* when the WebSocket connection is successfully opened.
|
|
36
48
|
* @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
|
|
37
49
|
*/
|
|
38
|
-
private async initializeWebSocket(): Promise<WebSocket> {
|
|
50
|
+
private async initializeWebSocket(initialMessage: string): Promise<WebSocket> {
|
|
39
51
|
return new Promise((resolve, reject) => {
|
|
40
52
|
this.websocket.on('error', (error: Error) => {
|
|
41
53
|
console.log('WebSocket error:', error);
|
|
@@ -45,6 +57,7 @@ class cbws {
|
|
|
45
57
|
this.websocket.on('open', () => {
|
|
46
58
|
console.log('WebSocket connected');
|
|
47
59
|
if (this.websocket) {
|
|
60
|
+
this.websocket.send(initialMessage);
|
|
48
61
|
resolve(this.websocket);
|
|
49
62
|
}
|
|
50
63
|
});
|