@codebolt/codeboltjs 1.0.4 → 1.0.5
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 +164 -0
- package/index.js +88 -0
- package/modules/browser.d.ts +87 -0
- package/modules/browser.js +253 -0
- package/modules/chat.d.ts +33 -0
- package/modules/chat.js +80 -0
- package/modules/codeparsers.d.ts +23 -0
- package/modules/codeparsers.js +30 -0
- package/modules/codeutils.d.ts +14 -0
- package/modules/codeutils.js +20 -0
- package/modules/crawler.d.ts +45 -0
- package/modules/crawler.js +112 -0
- package/modules/dbmemory.d.ts +19 -0
- package/modules/dbmemory.js +54 -0
- package/modules/docutils.d.ts +12 -0
- package/modules/docutils.js +19 -0
- package/modules/fs.d.ts +57 -0
- package/modules/fs.js +167 -0
- package/modules/git.d.ts +76 -0
- package/modules/git.js +240 -0
- package/modules/knowledge.d.ts +2 -0
- package/modules/knowledge.js +6 -0
- package/modules/llm.d.ts +17 -0
- package/modules/llm.js +39 -0
- package/modules/outputparsers.d.ts +24 -0
- package/modules/outputparsers.js +32 -0
- package/modules/project.d.ts +17 -0
- package/modules/project.js +38 -0
- package/modules/rag.d.ts +22 -0
- package/modules/rag.js +30 -0
- package/modules/search.d.ts +23 -0
- package/modules/search.js +37 -0
- package/modules/terminal.d.ts +15 -0
- package/modules/terminal.js +34 -0
- package/modules/websocket.d.ts +25 -0
- package/modules/websocket.js +57 -0
- package/package.json +1 -1
- package/tsconfig.json +1 -1
package/index.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import WebSocket from 'ws';
|
|
3
|
+
/**
|
|
4
|
+
* @class Codebolt
|
|
5
|
+
* @description This class provides a unified interface to interact with various modules.
|
|
6
|
+
*/
|
|
7
|
+
declare class Codebolt {
|
|
8
|
+
/**
|
|
9
|
+
* @constructor
|
|
10
|
+
* @description Initializes the websocket connection.
|
|
11
|
+
*/
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* @method waitForConnection
|
|
15
|
+
* @description Waits for the WebSocket connection to open.
|
|
16
|
+
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
|
|
17
|
+
*/
|
|
18
|
+
waitForConnection(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* @method start_browser
|
|
21
|
+
* @description Starts a new browser page.
|
|
22
|
+
* @param {string} objective - The objective of the browser session.
|
|
23
|
+
* @param {string} url - The URL to navigate to.
|
|
24
|
+
* @param {string} previous_command - The previous command executed.
|
|
25
|
+
* @param {string} browser_content - The content of the browser.
|
|
26
|
+
*/
|
|
27
|
+
start_browser(objective: string, url: string, previous_command: string, browser_content: string): void;
|
|
28
|
+
websocket: WebSocket | null;
|
|
29
|
+
fs: {
|
|
30
|
+
createFile: (fileName: string, source: string, filePath: string) => Promise<any>;
|
|
31
|
+
createFolder: (folderName: string, folderPath: string) => Promise<any>;
|
|
32
|
+
readFile: (filename: string, filePath: string) => Promise<any>;
|
|
33
|
+
updateFile: (filename: string, filePath: string, newContent: string) => Promise<any>;
|
|
34
|
+
deleteFile: (filename: string, filePath: string) => Promise<any>;
|
|
35
|
+
deleteFolder: (foldername: string, folderpath: string) => Promise<any>;
|
|
36
|
+
};
|
|
37
|
+
git: {
|
|
38
|
+
init: (path: string) => Promise<any>;
|
|
39
|
+
clone: (url: string, path: string) => Promise<any>;
|
|
40
|
+
pull: (path: string) => Promise<any>;
|
|
41
|
+
push: (path: string) => Promise<any>;
|
|
42
|
+
status: (path: string) => Promise<any>;
|
|
43
|
+
add: (path: string) => Promise<any>;
|
|
44
|
+
commit: (message: string) => Promise<any>;
|
|
45
|
+
checkout: (path: string, branch: string) => Promise<any>;
|
|
46
|
+
branch: (path: string, branch: string) => Promise<any>;
|
|
47
|
+
logs: (path: string) => Promise<any>;
|
|
48
|
+
diff: (commitHash: string, path: string) => Promise<any>;
|
|
49
|
+
};
|
|
50
|
+
llm: {
|
|
51
|
+
inference: (message: string, llmrole: string) => Promise<any>;
|
|
52
|
+
};
|
|
53
|
+
browser: {
|
|
54
|
+
newPage: () => void;
|
|
55
|
+
getUrl: () => Promise<unknown>;
|
|
56
|
+
goToPage: (url: string) => Promise<unknown>;
|
|
57
|
+
screenshot: () => void;
|
|
58
|
+
getHTML: () => Promise<unknown>;
|
|
59
|
+
getMarkdown: () => Promise<unknown>;
|
|
60
|
+
getPDF: () => void;
|
|
61
|
+
pdfToText: () => void;
|
|
62
|
+
getContent: () => void;
|
|
63
|
+
extractText: () => void;
|
|
64
|
+
close: () => void;
|
|
65
|
+
scroll: (direction: string, pixels: string) => Promise<unknown>;
|
|
66
|
+
type: (elementid: string, text: string) => Promise<unknown>;
|
|
67
|
+
click: (elementid: string) => Promise<unknown>;
|
|
68
|
+
enter: () => Promise<unknown>;
|
|
69
|
+
search: (elementid: string, query: string) => Promise<unknown>;
|
|
70
|
+
};
|
|
71
|
+
chat: {
|
|
72
|
+
eventEmitter: {
|
|
73
|
+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
74
|
+
addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
75
|
+
on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
76
|
+
once<K_3>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
77
|
+
removeListener<K_4>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
78
|
+
off<K_5>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
79
|
+
removeAllListeners(eventName?: string | symbol | undefined): any;
|
|
80
|
+
setMaxListeners(n: number): any;
|
|
81
|
+
getMaxListeners(): number;
|
|
82
|
+
listeners<K_6>(eventName: string | symbol): Function[];
|
|
83
|
+
rawListeners<K_7>(eventName: string | symbol): Function[];
|
|
84
|
+
emit<K_8>(eventName: string | symbol, ...args: any[]): boolean;
|
|
85
|
+
listenerCount<K_9>(eventName: string | symbol, listener?: Function | undefined): number;
|
|
86
|
+
prependListener<K_10>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
87
|
+
prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
88
|
+
eventNames(): (string | symbol)[];
|
|
89
|
+
};
|
|
90
|
+
sendMessage(message: string): void;
|
|
91
|
+
waitforReply(message: string): Promise<any>;
|
|
92
|
+
processStarted(): {
|
|
93
|
+
event: {
|
|
94
|
+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
95
|
+
addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
96
|
+
on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
97
|
+
once<K_3>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
98
|
+
removeListener<K_4>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
99
|
+
off<K_5>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
100
|
+
removeAllListeners(eventName?: string | symbol | undefined): any;
|
|
101
|
+
setMaxListeners(n: number): any;
|
|
102
|
+
getMaxListeners(): number;
|
|
103
|
+
listeners<K_6>(eventName: string | symbol): Function[];
|
|
104
|
+
rawListeners<K_7>(eventName: string | symbol): Function[];
|
|
105
|
+
emit<K_8>(eventName: string | symbol, ...args: any[]): boolean;
|
|
106
|
+
listenerCount<K_9>(eventName: string | symbol, listener?: Function | undefined): number;
|
|
107
|
+
prependListener<K_10>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
108
|
+
prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
109
|
+
eventNames(): (string | symbol)[];
|
|
110
|
+
};
|
|
111
|
+
stopProcess: () => void;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
terminal: {
|
|
115
|
+
executeCommand: (command: string) => Promise<any>;
|
|
116
|
+
};
|
|
117
|
+
codeutils: {
|
|
118
|
+
getCodeTree: (fileName: any, source: any, filePath: any) => Promise<any>;
|
|
119
|
+
};
|
|
120
|
+
docutils: {
|
|
121
|
+
pdf_to_text: (pdf_path: any) => Promise<string>;
|
|
122
|
+
};
|
|
123
|
+
crawler: {
|
|
124
|
+
start: () => void;
|
|
125
|
+
screenshot: () => void;
|
|
126
|
+
goToPage: (url: string) => void;
|
|
127
|
+
scroll: (direction: string) => void;
|
|
128
|
+
click: (id: string) => Promise<unknown>;
|
|
129
|
+
type: (id: string, text: string) => Promise<unknown>;
|
|
130
|
+
enter: () => void;
|
|
131
|
+
crawl: () => void;
|
|
132
|
+
};
|
|
133
|
+
search: {
|
|
134
|
+
init: (engine?: string) => void;
|
|
135
|
+
search: (query: string) => Promise<string>;
|
|
136
|
+
get_first_link: (query: string) => Promise<string>;
|
|
137
|
+
};
|
|
138
|
+
knowledge: {};
|
|
139
|
+
rag: {
|
|
140
|
+
init: () => void;
|
|
141
|
+
add_file: (filename: string, file_path: string) => void;
|
|
142
|
+
retrieve_related_knowledge: (query: string, filename: string) => void;
|
|
143
|
+
};
|
|
144
|
+
codeparsers: {
|
|
145
|
+
getClassesInFile: (file: any) => void;
|
|
146
|
+
getFunctionsinClass: (file: any, className: any) => void;
|
|
147
|
+
getAstTreeInFile: (file: any, className: any) => void;
|
|
148
|
+
};
|
|
149
|
+
outputparsers: {
|
|
150
|
+
init: (output: any) => void;
|
|
151
|
+
parseErrors: (output: any) => string[];
|
|
152
|
+
parseWarnings: (output: any) => string[];
|
|
153
|
+
};
|
|
154
|
+
project: {
|
|
155
|
+
getProjectSettings: (output: any) => void;
|
|
156
|
+
getProjectPath: () => Promise<any>;
|
|
157
|
+
};
|
|
158
|
+
dbmemory: {
|
|
159
|
+
addKnowledge: (key: string, value: any) => Promise<any>;
|
|
160
|
+
getKnowledge: (key: string) => Promise<any>;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
declare const _default: Codebolt;
|
|
164
|
+
export default _default;
|
package/index.js
ADDED
|
@@ -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 websocket_1 = __importDefault(require("./modules/websocket"));
|
|
7
|
+
const fs_1 = __importDefault(require("./modules/fs"));
|
|
8
|
+
const llm_1 = __importDefault(require("./modules/llm"));
|
|
9
|
+
const terminal_1 = __importDefault(require("./modules/terminal"));
|
|
10
|
+
const browser_1 = __importDefault(require("./modules/browser"));
|
|
11
|
+
const chat_1 = __importDefault(require("./modules/chat"));
|
|
12
|
+
const codeutils_1 = __importDefault(require("./modules/codeutils"));
|
|
13
|
+
const docutils_1 = __importDefault(require("./modules/docutils"));
|
|
14
|
+
const crawler_1 = __importDefault(require("./modules/crawler"));
|
|
15
|
+
const search_1 = __importDefault(require("./modules/search"));
|
|
16
|
+
const knowledge_1 = __importDefault(require("./modules/knowledge"));
|
|
17
|
+
const rag_1 = __importDefault(require("./modules/rag"));
|
|
18
|
+
const codeparsers_1 = __importDefault(require("./modules/codeparsers"));
|
|
19
|
+
const outputparsers_1 = __importDefault(require("./modules/outputparsers"));
|
|
20
|
+
const project_1 = __importDefault(require("./modules/project"));
|
|
21
|
+
const git_1 = __importDefault(require("./modules/git"));
|
|
22
|
+
const dbmemory_1 = __importDefault(require("./modules/dbmemory"));
|
|
23
|
+
const ws_1 = __importDefault(require("ws"));
|
|
24
|
+
/**
|
|
25
|
+
* @class Codebolt
|
|
26
|
+
* @description This class provides a unified interface to interact with various modules.
|
|
27
|
+
*/
|
|
28
|
+
class Codebolt {
|
|
29
|
+
/**
|
|
30
|
+
* @constructor
|
|
31
|
+
* @description Initializes the websocket connection.
|
|
32
|
+
*/
|
|
33
|
+
constructor() {
|
|
34
|
+
this.websocket = null;
|
|
35
|
+
this.fs = fs_1.default;
|
|
36
|
+
this.git = git_1.default;
|
|
37
|
+
this.llm = llm_1.default;
|
|
38
|
+
this.browser = browser_1.default;
|
|
39
|
+
this.chat = chat_1.default;
|
|
40
|
+
this.terminal = terminal_1.default;
|
|
41
|
+
this.codeutils = codeutils_1.default;
|
|
42
|
+
this.docutils = docutils_1.default;
|
|
43
|
+
this.crawler = crawler_1.default;
|
|
44
|
+
this.search = search_1.default;
|
|
45
|
+
this.knowledge = knowledge_1.default;
|
|
46
|
+
this.rag = rag_1.default;
|
|
47
|
+
this.codeparsers = codeparsers_1.default;
|
|
48
|
+
this.outputparsers = outputparsers_1.default;
|
|
49
|
+
this.project = project_1.default;
|
|
50
|
+
this.dbmemory = dbmemory_1.default;
|
|
51
|
+
this.websocket = websocket_1.default.getWebsocket;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @method waitForConnection
|
|
55
|
+
* @description Waits for the WebSocket connection to open.
|
|
56
|
+
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
|
|
57
|
+
*/
|
|
58
|
+
async waitForConnection() {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
if (!this.websocket) {
|
|
61
|
+
reject(new Error('WebSocket is not initialized'));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (this.websocket.readyState === ws_1.default.OPEN) {
|
|
65
|
+
resolve();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this.websocket.addEventListener('open', () => {
|
|
69
|
+
resolve();
|
|
70
|
+
});
|
|
71
|
+
this.websocket.addEventListener('error', (error) => {
|
|
72
|
+
reject(error);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @method start_browser
|
|
78
|
+
* @description Starts a new browser page.
|
|
79
|
+
* @param {string} objective - The objective of the browser session.
|
|
80
|
+
* @param {string} url - The URL to navigate to.
|
|
81
|
+
* @param {string} previous_command - The previous command executed.
|
|
82
|
+
* @param {string} browser_content - The content of the browser.
|
|
83
|
+
*/
|
|
84
|
+
start_browser(objective, url, previous_command, browser_content) {
|
|
85
|
+
browser_1.default.newPage();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.default = new Codebolt();
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module for interacting with a browser through WebSockets.
|
|
3
|
+
*/
|
|
4
|
+
declare const cbbrowser: {
|
|
5
|
+
/**
|
|
6
|
+
* Opens a new page in the browser.
|
|
7
|
+
*/
|
|
8
|
+
newPage: () => void;
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the current URL of the browser's active page.
|
|
11
|
+
* @returns {Promise<any>} A promise that resolves with the URL.
|
|
12
|
+
*/
|
|
13
|
+
getUrl: () => Promise<unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Navigates to a specified URL.
|
|
16
|
+
* @param {string} url - The URL to navigate to.
|
|
17
|
+
* @returns {Promise<any>} A promise that resolves when navigation is complete.
|
|
18
|
+
*/
|
|
19
|
+
goToPage: (url: string) => Promise<unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Takes a screenshot of the current page.
|
|
22
|
+
*/
|
|
23
|
+
screenshot: () => void;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the HTML content of the current page.
|
|
26
|
+
* @returns {Promise<string>} A promise that resolves with the HTML content.
|
|
27
|
+
*/
|
|
28
|
+
getHTML: () => Promise<unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the Markdown content of the current page.
|
|
31
|
+
* @returns {Promise<any>} A promise that resolves with the Markdown content.
|
|
32
|
+
*/
|
|
33
|
+
getMarkdown: () => Promise<unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves the PDF content of the current page.
|
|
36
|
+
*/
|
|
37
|
+
getPDF: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Converts the PDF content of the current page to text.
|
|
40
|
+
*/
|
|
41
|
+
pdfToText: () => void;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves the content of the current page.
|
|
44
|
+
*/
|
|
45
|
+
getContent: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Extracts text from the current page.
|
|
48
|
+
*/
|
|
49
|
+
extractText: () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Closes the current page.
|
|
52
|
+
*/
|
|
53
|
+
close: () => void;
|
|
54
|
+
/**
|
|
55
|
+
* Scrolls the current page in a specified direction by a specified number of pixels.
|
|
56
|
+
* @param {string} direction - The direction to scroll.
|
|
57
|
+
* @param {string} pixels - The number of pixels to scroll.
|
|
58
|
+
* @returns {Promise<any>} A promise that resolves when the scroll action is complete.
|
|
59
|
+
*/
|
|
60
|
+
scroll: (direction: string, pixels: string) => Promise<unknown>;
|
|
61
|
+
/**
|
|
62
|
+
* Types text into a specified element on the page.
|
|
63
|
+
* @param {string} elementid - The ID of the element to type into.
|
|
64
|
+
* @param {string} text - The text to type.
|
|
65
|
+
* @returns {Promise<any>} A promise that resolves when the typing action is complete.
|
|
66
|
+
*/
|
|
67
|
+
type: (elementid: string, text: string) => Promise<unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* Clicks on a specified element on the page.
|
|
70
|
+
* @param {string} elementid - The ID of the element to click.
|
|
71
|
+
* @returns {Promise<any>} A promise that resolves when the click action is complete.
|
|
72
|
+
*/
|
|
73
|
+
click: (elementid: string) => Promise<unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Simulates the Enter key press on the current page.
|
|
76
|
+
* @returns {Promise<any>} A promise that resolves when the Enter action is complete.
|
|
77
|
+
*/
|
|
78
|
+
enter: () => Promise<unknown>;
|
|
79
|
+
/**
|
|
80
|
+
* Performs a search on the current page using a specified query.
|
|
81
|
+
* @param {string} elementid - The ID of the element to perform the search in.
|
|
82
|
+
* @param {string} query - The search query.
|
|
83
|
+
* @returns {Promise<any>} A promise that resolves with the search results.
|
|
84
|
+
*/
|
|
85
|
+
search: (elementid: string, query: string) => Promise<unknown>;
|
|
86
|
+
};
|
|
87
|
+
export default cbbrowser;
|
|
@@ -0,0 +1,253 @@
|
|
|
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
|
+
* A module for interacting with a browser through WebSockets.
|
|
9
|
+
*/
|
|
10
|
+
const cbbrowser = {
|
|
11
|
+
/**
|
|
12
|
+
* Opens a new page in the browser.
|
|
13
|
+
*/
|
|
14
|
+
newPage: () => {
|
|
15
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
16
|
+
"type": "browserEvent",
|
|
17
|
+
action: 'newPage'
|
|
18
|
+
}));
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the current URL of the browser's active page.
|
|
22
|
+
* @returns {Promise<any>} A promise that resolves with the URL.
|
|
23
|
+
*/
|
|
24
|
+
getUrl: () => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
27
|
+
"type": "browserEvent",
|
|
28
|
+
action: 'getUrl'
|
|
29
|
+
}));
|
|
30
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
31
|
+
const response = JSON.parse(data);
|
|
32
|
+
if (response.event === "getUrlResponse") {
|
|
33
|
+
resolve(response);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Navigates to a specified URL.
|
|
40
|
+
* @param {string} url - The URL to navigate to.
|
|
41
|
+
* @returns {Promise<any>} A promise that resolves when navigation is complete.
|
|
42
|
+
*/
|
|
43
|
+
goToPage: (url) => {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
46
|
+
"type": "browserEvent",
|
|
47
|
+
action: 'goToPage',
|
|
48
|
+
url
|
|
49
|
+
}));
|
|
50
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
51
|
+
const response = JSON.parse(data);
|
|
52
|
+
if (response.event === "goToPageResponse") {
|
|
53
|
+
resolve(response);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Takes a screenshot of the current page.
|
|
60
|
+
*/
|
|
61
|
+
screenshot: () => {
|
|
62
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
63
|
+
"type": "browserEvent",
|
|
64
|
+
action: 'screenshot'
|
|
65
|
+
}));
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* Retrieves the HTML content of the current page.
|
|
69
|
+
* @returns {Promise<string>} A promise that resolves with the HTML content.
|
|
70
|
+
*/
|
|
71
|
+
getHTML: () => {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
74
|
+
"type": "browserEvent",
|
|
75
|
+
action: 'getHTML'
|
|
76
|
+
}));
|
|
77
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
78
|
+
const response = JSON.parse(data);
|
|
79
|
+
if (response.event === "htmlReceived") {
|
|
80
|
+
resolve(response.htmlResponse);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves the Markdown content of the current page.
|
|
87
|
+
* @returns {Promise<any>} A promise that resolves with the Markdown content.
|
|
88
|
+
*/
|
|
89
|
+
getMarkdown: () => {
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
92
|
+
"type": "browserEvent",
|
|
93
|
+
action: 'getMarkdown'
|
|
94
|
+
}));
|
|
95
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
96
|
+
const response = JSON.parse(data);
|
|
97
|
+
if (response.event === "getMarkdownResponse") {
|
|
98
|
+
resolve(response);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Retrieves the PDF content of the current page.
|
|
105
|
+
*/
|
|
106
|
+
getPDF: () => {
|
|
107
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
108
|
+
"type": "browserEvent",
|
|
109
|
+
action: 'getPDF'
|
|
110
|
+
}));
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* Converts the PDF content of the current page to text.
|
|
114
|
+
*/
|
|
115
|
+
pdfToText: () => {
|
|
116
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
117
|
+
"type": "browserEvent",
|
|
118
|
+
action: 'pdfToText'
|
|
119
|
+
}));
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves the content of the current page.
|
|
123
|
+
*/
|
|
124
|
+
getContent: () => {
|
|
125
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
126
|
+
"type": "browserEvent",
|
|
127
|
+
action: 'getContent'
|
|
128
|
+
}));
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* Extracts text from the current page.
|
|
132
|
+
*/
|
|
133
|
+
extractText: () => {
|
|
134
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
135
|
+
"type": "browserEvent",
|
|
136
|
+
action: 'extractText'
|
|
137
|
+
}));
|
|
138
|
+
},
|
|
139
|
+
/**
|
|
140
|
+
* Closes the current page.
|
|
141
|
+
*/
|
|
142
|
+
close: () => {
|
|
143
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
144
|
+
"type": "browserEvent",
|
|
145
|
+
action: 'close'
|
|
146
|
+
}));
|
|
147
|
+
},
|
|
148
|
+
/**
|
|
149
|
+
* Scrolls the current page in a specified direction by a specified number of pixels.
|
|
150
|
+
* @param {string} direction - The direction to scroll.
|
|
151
|
+
* @param {string} pixels - The number of pixels to scroll.
|
|
152
|
+
* @returns {Promise<any>} A promise that resolves when the scroll action is complete.
|
|
153
|
+
*/
|
|
154
|
+
scroll: (direction, pixels) => {
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
157
|
+
"type": "browserEvent",
|
|
158
|
+
action: 'scroll',
|
|
159
|
+
direction,
|
|
160
|
+
pixels
|
|
161
|
+
}));
|
|
162
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
163
|
+
const response = JSON.parse(data);
|
|
164
|
+
if (response.event === "scrollResponse") {
|
|
165
|
+
resolve(response);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
* Types text into a specified element on the page.
|
|
172
|
+
* @param {string} elementid - The ID of the element to type into.
|
|
173
|
+
* @param {string} text - The text to type.
|
|
174
|
+
* @returns {Promise<any>} A promise that resolves when the typing action is complete.
|
|
175
|
+
*/
|
|
176
|
+
type: (elementid, text) => {
|
|
177
|
+
return new Promise((resolve, reject) => {
|
|
178
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
179
|
+
"type": "browserEvent",
|
|
180
|
+
action: 'type',
|
|
181
|
+
text,
|
|
182
|
+
elementid
|
|
183
|
+
}));
|
|
184
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
185
|
+
const response = JSON.parse(data);
|
|
186
|
+
if (response.event === "typeResponse") {
|
|
187
|
+
resolve(response);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
/**
|
|
193
|
+
* Clicks on a specified element on the page.
|
|
194
|
+
* @param {string} elementid - The ID of the element to click.
|
|
195
|
+
* @returns {Promise<any>} A promise that resolves when the click action is complete.
|
|
196
|
+
*/
|
|
197
|
+
click: (elementid) => {
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
200
|
+
"type": "browserEvent",
|
|
201
|
+
action: 'click',
|
|
202
|
+
elementid
|
|
203
|
+
}));
|
|
204
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
205
|
+
const response = JSON.parse(data);
|
|
206
|
+
if (response.event === "clickResponse") {
|
|
207
|
+
resolve(response);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
/**
|
|
213
|
+
* Simulates the Enter key press on the current page.
|
|
214
|
+
* @returns {Promise<any>} A promise that resolves when the Enter action is complete.
|
|
215
|
+
*/
|
|
216
|
+
enter: () => {
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
219
|
+
"type": "browserEvent",
|
|
220
|
+
action: 'enter'
|
|
221
|
+
}));
|
|
222
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
223
|
+
const response = JSON.parse(data);
|
|
224
|
+
if (response.event === "EnterResponse") {
|
|
225
|
+
resolve(response);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
/**
|
|
231
|
+
* Performs a search on the current page using a specified query.
|
|
232
|
+
* @param {string} elementid - The ID of the element to perform the search in.
|
|
233
|
+
* @param {string} query - The search query.
|
|
234
|
+
* @returns {Promise<any>} A promise that resolves with the search results.
|
|
235
|
+
*/
|
|
236
|
+
search: (elementid, query) => {
|
|
237
|
+
return new Promise((resolve, reject) => {
|
|
238
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
239
|
+
"type": "browserEvent",
|
|
240
|
+
action: 'search',
|
|
241
|
+
elementid,
|
|
242
|
+
query
|
|
243
|
+
}));
|
|
244
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
245
|
+
const response = JSON.parse(data);
|
|
246
|
+
if (response.event === "searchResponse") {
|
|
247
|
+
resolve(response);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
exports.default = cbbrowser;
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Chat module to interact with the WebSocket server.
|
|
10
|
+
*/
|
|
11
|
+
declare const cbchat: {
|
|
12
|
+
eventEmitter: CustomEventEmitter;
|
|
13
|
+
/**
|
|
14
|
+
* Sends a message through the WebSocket connection.
|
|
15
|
+
* @param {string} message - The message to be sent.
|
|
16
|
+
*/
|
|
17
|
+
sendMessage(message: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Waits for a reply to a sent message.
|
|
20
|
+
* @param {string} message - The message for which a reply is expected.
|
|
21
|
+
* @returns {Promise<any>} A promise that resolves with the reply.
|
|
22
|
+
*/
|
|
23
|
+
waitforReply(message: string): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* Notifies the server that a process has started and sets up an event listener for stopProcessClicked events.
|
|
26
|
+
* @returns An object containing the event emitter and a stopProcess method.
|
|
27
|
+
*/
|
|
28
|
+
processStarted(): {
|
|
29
|
+
event: CustomEventEmitter;
|
|
30
|
+
stopProcess: () => void;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export default cbchat;
|