@codebolt/codeboltjs 1.1.39 → 1.1.41
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 +3 -3
- package/modules/chat.d.ts +4 -4
- package/modules/chat.js +9 -3
- package/modules/crawler.d.ts +1 -1
- package/modules/crawler.js +16 -5
- package/modules/websocket.d.ts +1 -0
- package/modules/websocket.js +16 -1
- package/package.json +3 -2
- package/src/modules/chat.ts +11 -5
- package/src/modules/crawler.ts +17 -5
- package/src/modules/websocket.ts +15 -1
package/index.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ declare class Codebolt {
|
|
|
65
65
|
};
|
|
66
66
|
chat: {
|
|
67
67
|
getChatHistory: () => Promise<import("@codebolt/types").ChatMessage[]>;
|
|
68
|
-
|
|
68
|
+
onActionMessage: () => {
|
|
69
69
|
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
70
70
|
addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
71
71
|
on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
@@ -84,7 +84,7 @@ declare class Codebolt {
|
|
|
84
84
|
eventNames(): (string | symbol)[];
|
|
85
85
|
} | undefined;
|
|
86
86
|
sendMessage: (message: string) => void;
|
|
87
|
-
waitforReply: (message: string) => Promise<
|
|
87
|
+
waitforReply: (message: string) => Promise<import("@codebolt/types").UserMessage>;
|
|
88
88
|
processStarted: () => {
|
|
89
89
|
event: {
|
|
90
90
|
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
@@ -150,7 +150,7 @@ declare class Codebolt {
|
|
|
150
150
|
click: (id: string) => Promise<unknown>;
|
|
151
151
|
type: (id: string, text: string) => Promise<unknown>;
|
|
152
152
|
enter: () => void;
|
|
153
|
-
crawl: () =>
|
|
153
|
+
crawl: (query: string) => Promise<unknown>;
|
|
154
154
|
};
|
|
155
155
|
search: {
|
|
156
156
|
init: (engine?: string) => void;
|
package/modules/chat.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import { ChatMessage } from '@codebolt/types';
|
|
3
|
+
import { ChatMessage, UserMessage } from '@codebolt/types';
|
|
4
4
|
/**
|
|
5
5
|
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
6
6
|
*/
|
|
@@ -19,7 +19,7 @@ declare const cbchat: {
|
|
|
19
19
|
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
|
|
20
20
|
* @returns {EventEmitter} The event emitter used for emitting custom events.
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
onActionMessage: () => CustomEventEmitter | undefined;
|
|
23
23
|
/**
|
|
24
24
|
* Sends a message through the WebSocket connection.
|
|
25
25
|
* @param {string} message - The message to be sent.
|
|
@@ -28,9 +28,9 @@ declare const cbchat: {
|
|
|
28
28
|
/**
|
|
29
29
|
* Waits for a reply to a sent message.
|
|
30
30
|
* @param {string} message - The message for which a reply is expected.
|
|
31
|
-
* @returns {Promise<
|
|
31
|
+
* @returns {Promise<UserMessage>} A promise that resolves with the reply.
|
|
32
32
|
*/
|
|
33
|
-
waitforReply: (message: string) => Promise<
|
|
33
|
+
waitforReply: (message: string) => Promise<UserMessage>;
|
|
34
34
|
/**
|
|
35
35
|
* Notifies the server that a process has started and sets up an event listener for stopProcessClicked events.
|
|
36
36
|
* @returns An object containing the event emitter and a stopProcess method.
|
package/modules/chat.js
CHANGED
|
@@ -37,13 +37,19 @@ const cbchat = {
|
|
|
37
37
|
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
|
|
38
38
|
* @returns {EventEmitter} The event emitter used for emitting custom events.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
onActionMessage: () => {
|
|
41
41
|
if (!websocket_1.default.getWebsocket)
|
|
42
42
|
return;
|
|
43
43
|
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
44
44
|
const response = JSON.parse(data);
|
|
45
45
|
if (response.type === "messageResponse") {
|
|
46
|
-
|
|
46
|
+
// Pass a callback function as an argument to the emit method
|
|
47
|
+
eventEmitter.emit("userMessage", response, (message) => {
|
|
48
|
+
console.log("Callback function invoked with message:", message);
|
|
49
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
50
|
+
"type": "processStoped"
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
47
53
|
}
|
|
48
54
|
});
|
|
49
55
|
return eventEmitter;
|
|
@@ -62,7 +68,7 @@ const cbchat = {
|
|
|
62
68
|
/**
|
|
63
69
|
* Waits for a reply to a sent message.
|
|
64
70
|
* @param {string} message - The message for which a reply is expected.
|
|
65
|
-
* @returns {Promise<
|
|
71
|
+
* @returns {Promise<UserMessage>} A promise that resolves with the reply.
|
|
66
72
|
*/
|
|
67
73
|
waitforReply: (message) => {
|
|
68
74
|
return new Promise((resolve, reject) => {
|
package/modules/crawler.d.ts
CHANGED
package/modules/crawler.js
CHANGED
|
@@ -102,11 +102,22 @@ const cbcrawler = {
|
|
|
102
102
|
/**
|
|
103
103
|
* Initiates a crawl process.
|
|
104
104
|
*/
|
|
105
|
-
crawl: () => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
crawl: (query) => {
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
108
|
+
"type": "crawlerEvent",
|
|
109
|
+
"action": 'crawl',
|
|
110
|
+
"message": {
|
|
111
|
+
query
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
115
|
+
const response = JSON.parse(data);
|
|
116
|
+
if (response.type === "crawlResponse") {
|
|
117
|
+
resolve(response); // Resolve the Promise with the response data
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
110
121
|
}
|
|
111
122
|
};
|
|
112
123
|
exports.default = cbcrawler;
|
package/modules/websocket.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare class cbws {
|
|
|
8
8
|
* Constructs a new cbws instance and initializes the WebSocket connection.
|
|
9
9
|
*/
|
|
10
10
|
constructor();
|
|
11
|
+
private getUniqueConnectionId;
|
|
11
12
|
/**
|
|
12
13
|
* Initializes the WebSocket by setting up event listeners and returning a promise that resolves
|
|
13
14
|
* when the WebSocket connection is successfully opened.
|
package/modules/websocket.js
CHANGED
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const ws_1 = __importDefault(require("ws"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
7
9
|
/**
|
|
8
10
|
* Class representing a WebSocket connection.
|
|
9
11
|
*/
|
|
@@ -12,11 +14,24 @@ class cbws {
|
|
|
12
14
|
* Constructs a new cbws instance and initializes the WebSocket connection.
|
|
13
15
|
*/
|
|
14
16
|
constructor() {
|
|
15
|
-
|
|
17
|
+
const uniqueConnectionId = this.getUniqueConnectionId();
|
|
18
|
+
console.log(uniqueConnectionId);
|
|
19
|
+
this.websocket = new ws_1.default(`ws://localhost:12345/codebolt?id=${uniqueConnectionId}`);
|
|
16
20
|
this.initializeWebSocket().catch(error => {
|
|
17
21
|
console.error("WebSocket connection failed:", error);
|
|
18
22
|
});
|
|
19
23
|
}
|
|
24
|
+
getUniqueConnectionId() {
|
|
25
|
+
try {
|
|
26
|
+
let fileContents = fs_1.default.readFileSync('./codebotagent.yml', 'utf8');
|
|
27
|
+
let data = js_yaml_1.default.load(fileContents);
|
|
28
|
+
return data.uniqueConnectionId;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error('Unable to locate codebotagent.yml file.');
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
20
35
|
/**
|
|
21
36
|
* Initializes the WebSocket by setting up event listeners and returning a promise that resolves
|
|
22
37
|
* when the WebSocket connection is successfully opened.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebolt/codeboltjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.41",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://codeboltai.github.io",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@codebolt/types": "^1.0.
|
|
21
|
+
"@codebolt/types": "^1.0.10",
|
|
22
22
|
"tree-sitter": "^0.21.1",
|
|
23
23
|
"tree-sitter-javascript": "^0.21.2",
|
|
24
24
|
"typedoc-plugin-missing-exports": "^2.2.0",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/events": "^3.0.3",
|
|
29
|
+
"@types/js-yaml": "^4.0.9",
|
|
29
30
|
"@types/ws": "^8.5.10",
|
|
30
31
|
"jest": "^29.7.0",
|
|
31
32
|
"jest-serial-runner": "^1.2.1",
|
package/src/modules/chat.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// chat.ts
|
|
2
2
|
import cbws from './websocket';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
|
-
import {ChatMessage} from '@codebolt/types'
|
|
4
|
+
import {ChatMessage,UserMessage} from '@codebolt/types'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
@@ -37,12 +37,18 @@ const cbchat = {
|
|
|
37
37
|
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
|
|
38
38
|
* @returns {EventEmitter} The event emitter used for emitting custom events.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
onActionMessage: () => {
|
|
41
41
|
if (!cbws.getWebsocket) return;
|
|
42
42
|
cbws.getWebsocket.on('message', (data: string) => {
|
|
43
43
|
const response = JSON.parse(data);
|
|
44
44
|
if (response.type === "messageResponse") {
|
|
45
|
-
|
|
45
|
+
// Pass a callback function as an argument to the emit method
|
|
46
|
+
eventEmitter.emit("userMessage", response, (message: string) => {
|
|
47
|
+
console.log("Callback function invoked with message:", message);
|
|
48
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
49
|
+
"type": "processStoped"
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
46
52
|
}
|
|
47
53
|
});
|
|
48
54
|
return eventEmitter;
|
|
@@ -63,9 +69,9 @@ const cbchat = {
|
|
|
63
69
|
/**
|
|
64
70
|
* Waits for a reply to a sent message.
|
|
65
71
|
* @param {string} message - The message for which a reply is expected.
|
|
66
|
-
* @returns {Promise<
|
|
72
|
+
* @returns {Promise<UserMessage>} A promise that resolves with the reply.
|
|
67
73
|
*/
|
|
68
|
-
waitforReply: (message: string): Promise<
|
|
74
|
+
waitforReply: (message: string): Promise<UserMessage> => {
|
|
69
75
|
return new Promise((resolve, reject) => {
|
|
70
76
|
cbws.getWebsocket.send(JSON.stringify({
|
|
71
77
|
"type": "waitforReply",
|
package/src/modules/crawler.ts
CHANGED
|
@@ -98,11 +98,23 @@ const cbcrawler = {
|
|
|
98
98
|
/**
|
|
99
99
|
* Initiates a crawl process.
|
|
100
100
|
*/
|
|
101
|
-
crawl: () => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
crawl: (query:string) => {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
104
|
+
"type": "crawlerEvent",
|
|
105
|
+
"action": 'crawl',
|
|
106
|
+
"message":{
|
|
107
|
+
query
|
|
108
|
+
}
|
|
109
|
+
}));
|
|
110
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
111
|
+
const response = JSON.parse(data);
|
|
112
|
+
if (response.type === "crawlResponse") {
|
|
113
|
+
resolve(response); // Resolve the Promise with the response data
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
106
118
|
}
|
|
107
119
|
};
|
|
108
120
|
|
package/src/modules/websocket.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Class representing a WebSocket connection.
|
|
@@ -10,11 +12,23 @@ class cbws {
|
|
|
10
12
|
* Constructs a new cbws instance and initializes the WebSocket connection.
|
|
11
13
|
*/
|
|
12
14
|
constructor() {
|
|
13
|
-
|
|
15
|
+
const uniqueConnectionId = this.getUniqueConnectionId();
|
|
16
|
+
console.log(uniqueConnectionId)
|
|
17
|
+
this.websocket = new WebSocket(`ws://localhost:12345/codebolt?id=${uniqueConnectionId}`);
|
|
14
18
|
this.initializeWebSocket().catch(error => {
|
|
15
19
|
console.error("WebSocket connection failed:", error);
|
|
16
20
|
});
|
|
17
21
|
}
|
|
22
|
+
private getUniqueConnectionId(): string {
|
|
23
|
+
try {
|
|
24
|
+
let fileContents = fs.readFileSync('./codebotagent.yml', 'utf8');
|
|
25
|
+
let data:any = yaml.load(fileContents);
|
|
26
|
+
return data.uniqueConnectionId;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.error('Unable to locate codebotagent.yml file.');
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
18
32
|
|
|
19
33
|
/**
|
|
20
34
|
* Initializes the WebSocket by setting up event listeners and returning a promise that resolves
|