@codebolt/codeboltjs 1.1.70 → 1.1.72

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/package.json +3 -3
  2. package/src/index.ts +3 -1
  3. package/webpack.config.js +1 -1
  4. package/docs/modules/_internal_.EventEmitter.html +0 -6
  5. package/docs/modules/_internal_.WebSocket.html +0 -21
  6. package/docs/modules/_internal_._node_stream_consumers_.html +0 -6
  7. package/docs/modules/_internal_._node_stream_promises_.html +0 -3
  8. package/docs/modules/_internal_.html +0 -228
  9. package/docs/modules/_internal_.internal.finished.html +0 -2
  10. package/docs/modules/_internal_.internal.html +0 -36
  11. package/docs/modules/_internal_.internal.pipeline.html +0 -2
  12. package/index.d.ts +0 -238
  13. package/index.js +0 -90
  14. package/modules/browser.d.ts +0 -108
  15. package/modules/browser.js +0 -331
  16. package/modules/chat.d.ts +0 -63
  17. package/modules/chat.js +0 -174
  18. package/modules/codeparsers.d.ts +0 -23
  19. package/modules/codeparsers.js +0 -30
  20. package/modules/codeutils.d.ts +0 -37
  21. package/modules/codeutils.js +0 -166
  22. package/modules/crawler.d.ts +0 -45
  23. package/modules/crawler.js +0 -123
  24. package/modules/dbmemory.d.ts +0 -20
  25. package/modules/dbmemory.js +0 -54
  26. package/modules/debug.d.ts +0 -23
  27. package/modules/debug.js +0 -64
  28. package/modules/docutils.d.ts +0 -12
  29. package/modules/docutils.js +0 -19
  30. package/modules/fs.d.ts +0 -94
  31. package/modules/fs.js +0 -264
  32. package/modules/git.d.ts +0 -76
  33. package/modules/git.js +0 -240
  34. package/modules/history.d.ts +0 -19
  35. package/modules/history.js +0 -46
  36. package/modules/knowledge.d.ts +0 -2
  37. package/modules/knowledge.js +0 -6
  38. package/modules/llm.d.ts +0 -18
  39. package/modules/llm.js +0 -39
  40. package/modules/outputparsers.d.ts +0 -24
  41. package/modules/outputparsers.js +0 -32
  42. package/modules/project.d.ts +0 -21
  43. package/modules/project.js +0 -72
  44. package/modules/rag.d.ts +0 -22
  45. package/modules/rag.js +0 -30
  46. package/modules/search.d.ts +0 -23
  47. package/modules/search.js +0 -37
  48. package/modules/state.d.ts +0 -21
  49. package/modules/state.js +0 -68
  50. package/modules/task.d.ts +0 -23
  51. package/modules/task.js +0 -75
  52. package/modules/terminal.d.ts +0 -46
  53. package/modules/terminal.js +0 -108
  54. package/modules/tokenizer.d.ts +0 -19
  55. package/modules/tokenizer.js +0 -56
  56. package/modules/vectordb.d.ts +0 -33
  57. package/modules/vectordb.js +0 -103
  58. package/modules/websocket.d.ts +0 -27
  59. package/modules/websocket.js +0 -88
  60. package/src/modules/browser.ts +0 -352
  61. package/src/modules/chat.ts +0 -182
  62. package/src/modules/codeparsers.ts +0 -30
  63. package/src/modules/codeutils.ts +0 -181
  64. package/src/modules/crawler.ts +0 -121
  65. package/src/modules/dbmemory.ts +0 -52
  66. package/src/modules/debug.ts +0 -68
  67. package/src/modules/docutils.ts +0 -18
  68. package/src/modules/fs.ts +0 -263
  69. package/src/modules/git.ts +0 -237
  70. package/src/modules/history.ts +0 -61
  71. package/src/modules/knowledge.ts +0 -5
  72. package/src/modules/llm.ts +0 -36
  73. package/src/modules/outputparsers.ts +0 -30
  74. package/src/modules/project.ts +0 -68
  75. package/src/modules/rag.ts +0 -28
  76. package/src/modules/search.ts +0 -35
  77. package/src/modules/state.ts +0 -69
  78. package/src/modules/task.ts +0 -73
  79. package/src/modules/terminal.ts +0 -114
  80. package/src/modules/tokenizer.ts +0 -56
  81. package/src/modules/vectordb.ts +0 -102
  82. package/src/modules/websocket.ts +0 -89
@@ -1,19 +0,0 @@
1
- import { AddTokenResponse, GetTokenResponse } from '@codebolt/types';
2
- /**
3
- * Tokenizer module for handling token-related operations.
4
- */
5
- declare const tokenizer: {
6
- /**
7
- * Adds a token to the system via WebSocket.
8
- * @param {string} key - The key associated with the token to be added.
9
- * @returns {Promise<AddTokenResponse>} A promise that resolves with the response from the add token event.
10
- */
11
- addToken: (key: string) => Promise<AddTokenResponse>;
12
- /**
13
- * Retrieves a token from the system via WebSocket.
14
- * @param {string} key - The key associated with the token to be retrieved.
15
- * @returns {Promise<GetTokenResponse>} A promise that resolves with the response from the get token event.
16
- */
17
- getToken: (key: string) => Promise<GetTokenResponse>;
18
- };
19
- export default tokenizer;
@@ -1,56 +0,0 @@
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
- * Tokenizer module for handling token-related operations.
9
- */
10
- const tokenizer = {
11
- /**
12
- * Adds a token to the system via WebSocket.
13
- * @param {string} key - The key associated with the token to be added.
14
- * @returns {Promise<AddTokenResponse>} A promise that resolves with the response from the add token event.
15
- */
16
- addToken: async (key) => {
17
- return new Promise((resolve, reject) => {
18
- websocket_1.default.getWebsocket.send(JSON.stringify({
19
- "type": "tokenizerEvent",
20
- "action": "addToken",
21
- "message": {
22
- item: key
23
- },
24
- }));
25
- websocket_1.default.getWebsocket.on('message', (data) => {
26
- const response = JSON.parse(data);
27
- if (response.type === "addTokenResponse") {
28
- resolve(response);
29
- }
30
- });
31
- });
32
- },
33
- /**
34
- * Retrieves a token from the system via WebSocket.
35
- * @param {string} key - The key associated with the token to be retrieved.
36
- * @returns {Promise<GetTokenResponse>} A promise that resolves with the response from the get token event.
37
- */
38
- getToken: async (key) => {
39
- return new Promise((resolve, reject) => {
40
- websocket_1.default.getWebsocket.send(JSON.stringify({
41
- "type": "tokenizerEvent",
42
- "action": "getToken",
43
- "message": {
44
- item: key
45
- },
46
- }));
47
- websocket_1.default.getWebsocket.on('message', (data) => {
48
- const response = JSON.parse(data);
49
- if (response.type === "getTokenResponse") {
50
- resolve(response);
51
- }
52
- });
53
- });
54
- }
55
- };
56
- exports.default = tokenizer;
@@ -1,33 +0,0 @@
1
- import { AddVectorItemResponse, GetVectorResponse, QueryVectorItemResponse } from '@codebolt/types';
2
- declare const VectorDB: {
3
- /**
4
- * Retrieves a vector from the vector database based on the provided key.
5
- *
6
- * @param {string} key - The key of the vector to retrieve.
7
- * @returns {Promise<GetVectorResponse>} A promise that resolves with the retrieved vector.
8
- */
9
- getVector: (key: string) => Promise<GetVectorResponse>;
10
- /**
11
- * Adds a new vector item to the vector database.
12
- *
13
-
14
- * @param {any} item - The item to add to the vector.
15
- * @returns {Promise<AddVectorItemResponse>} A promise that resolves when the item is successfully added.
16
- */
17
- addVectorItem: (item: any) => Promise<AddVectorItemResponse>;
18
- /**
19
- * Queries a vector item from the vector database based on the provided key.
20
- *
21
- * @param {string} key - The key of the vector to query the item from.
22
- * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
23
- */
24
- queryVectorItem: (key: string) => Promise<QueryVectorItemResponse>;
25
- /**
26
- * Queries a vector item from the vector database based on the provided key.
27
- *
28
- * @param {string} key - The key of the vector to query the item from.
29
- * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
30
- */
31
- queryVectorItems: (items: [], dbPath: string) => Promise<QueryVectorItemResponse>;
32
- };
33
- export default VectorDB;
@@ -1,103 +0,0 @@
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
- const VectorDB = {
8
- /**
9
- * Retrieves a vector from the vector database based on the provided key.
10
- *
11
- * @param {string} key - The key of the vector to retrieve.
12
- * @returns {Promise<GetVectorResponse>} A promise that resolves with the retrieved vector.
13
- */
14
- getVector: async (key) => {
15
- return new Promise((resolve, reject) => {
16
- websocket_1.default.getWebsocket.send(JSON.stringify({
17
- "type": "vectordbEvent",
18
- "action": "getVector",
19
- "message": {
20
- item: key
21
- },
22
- }));
23
- websocket_1.default.getWebsocket.on('message', (data) => {
24
- const response = JSON.parse(data);
25
- if (response.type === "getVectorResponse") {
26
- resolve(response);
27
- }
28
- });
29
- });
30
- },
31
- /**
32
- * Adds a new vector item to the vector database.
33
- *
34
-
35
- * @param {any} item - The item to add to the vector.
36
- * @returns {Promise<AddVectorItemResponse>} A promise that resolves when the item is successfully added.
37
- */
38
- addVectorItem: async (item) => {
39
- return new Promise((resolve, reject) => {
40
- websocket_1.default.getWebsocket.send(JSON.stringify({
41
- "type": "vectordbEvent",
42
- "action": "addVectorItem",
43
- "message": {
44
- item: item
45
- },
46
- }));
47
- websocket_1.default.getWebsocket.on('message', (data) => {
48
- const response = JSON.parse(data);
49
- if (response.type === "addVectorItemResponse") {
50
- resolve(response);
51
- }
52
- });
53
- });
54
- },
55
- /**
56
- * Queries a vector item from the vector database based on the provided key.
57
- *
58
- * @param {string} key - The key of the vector to query the item from.
59
- * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
60
- */
61
- queryVectorItem: async (key) => {
62
- return new Promise((resolve, reject) => {
63
- websocket_1.default.getWebsocket.send(JSON.stringify({
64
- "type": "vectordbEvent",
65
- "action": "queryVectorItem",
66
- "message": {
67
- item: key
68
- },
69
- }));
70
- websocket_1.default.getWebsocket.on('message', (data) => {
71
- const response = JSON.parse(data);
72
- if (response.type === "qeryVectorItemResponse") {
73
- resolve(response);
74
- }
75
- });
76
- });
77
- },
78
- /**
79
- * Queries a vector item from the vector database based on the provided key.
80
- *
81
- * @param {string} key - The key of the vector to query the item from.
82
- * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
83
- */
84
- queryVectorItems: async (items, dbPath) => {
85
- return new Promise((resolve, reject) => {
86
- websocket_1.default.getWebsocket.send(JSON.stringify({
87
- "type": "vectordbEvent",
88
- "action": "queryVectorItems",
89
- "message": {
90
- items,
91
- dbPath
92
- },
93
- }));
94
- websocket_1.default.getWebsocket.on('message', (data) => {
95
- const response = JSON.parse(data);
96
- if (response.type === "qeryVectorItemsResponse") {
97
- resolve(response);
98
- }
99
- });
100
- });
101
- },
102
- };
103
- exports.default = VectorDB;
@@ -1,27 +0,0 @@
1
- import WebSocket from 'ws';
2
- /**
3
- * Class representing a WebSocket connection.
4
- */
5
- declare class cbws {
6
- websocket: WebSocket;
7
- /**
8
- * Constructs a new cbws instance and initializes the WebSocket connection.
9
- */
10
- constructor();
11
- private getUniqueConnectionId;
12
- private getInitialMessage;
13
- /**
14
- * Initializes the WebSocket by setting up event listeners and returning a promise that resolves
15
- * when the WebSocket connection is successfully opened.
16
- * @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
17
- */
18
- private initializeWebSocket;
19
- /**
20
- * Getter for the WebSocket instance. Throws an error if the WebSocket is not open.
21
- * @returns {WebSocket} The WebSocket instance.
22
- * @throws {Error} If the WebSocket is not open.
23
- */
24
- get getWebsocket(): WebSocket;
25
- }
26
- declare const _default: cbws;
27
- export default _default;
@@ -1,88 +0,0 @@
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 ws_1 = __importDefault(require("ws"));
7
- const fs_1 = __importDefault(require("fs"));
8
- const js_yaml_1 = __importDefault(require("js-yaml"));
9
- /**
10
- * Class representing a WebSocket connection.
11
- */
12
- class cbws {
13
- /**
14
- * Constructs a new cbws instance and initializes the WebSocket connection.
15
- */
16
- constructor() {
17
- const uniqueConnectionId = this.getUniqueConnectionId();
18
- const initialMessage = this.getInitialMessage();
19
- console.log(uniqueConnectionId);
20
- this.websocket = new ws_1.default(`ws://localhost:${process.env.SOCKET_PORT}/codebolt?id=${uniqueConnectionId}`);
21
- this.initializeWebSocket(initialMessage).catch(error => {
22
- console.error("WebSocket connection failed:", error);
23
- });
24
- }
25
- getUniqueConnectionId() {
26
- try {
27
- let fileContents = fs_1.default.readFileSync('./codeboltagent.yaml', 'utf8');
28
- let data = js_yaml_1.default.load(fileContents);
29
- return data.unique_connectionid;
30
- }
31
- catch (e) {
32
- console.error('Unable to locate codeboltagent.yaml file.');
33
- return '';
34
- }
35
- }
36
- getInitialMessage() {
37
- try {
38
- let fileContents = fs_1.default.readFileSync('./codeboltagent.yaml', 'utf8');
39
- let data = js_yaml_1.default.load(fileContents);
40
- return data.initial_message;
41
- }
42
- catch (e) {
43
- console.error('Unable to locate codeboltagent.yaml file.');
44
- return '';
45
- }
46
- }
47
- /**
48
- * Initializes the WebSocket by setting up event listeners and returning a promise that resolves
49
- * when the WebSocket connection is successfully opened.
50
- * @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
51
- */
52
- async initializeWebSocket(initialMessage) {
53
- return new Promise((resolve, reject) => {
54
- this.websocket.on('error', (error) => {
55
- console.log('WebSocket error:', error);
56
- reject(error);
57
- });
58
- this.websocket.on('open', () => {
59
- console.log('WebSocket connected');
60
- // if (this.websocket) {
61
- // this.websocket.send(JSON.stringify({
62
- // "type": "sendMessage",
63
- // "message": initialMessage
64
- // }));
65
- // resolve(this.websocket);
66
- // }
67
- });
68
- this.websocket.on('message', (data) => {
69
- // Handle incoming WebSocket messages here.
70
- // console.log('WebSocket message received:', data);
71
- });
72
- });
73
- }
74
- /**
75
- * Getter for the WebSocket instance. Throws an error if the WebSocket is not open.
76
- * @returns {WebSocket} The WebSocket instance.
77
- * @throws {Error} If the WebSocket is not open.
78
- */
79
- get getWebsocket() {
80
- if (!this.websocket.OPEN) {
81
- throw new Error('WebSocket is not open');
82
- }
83
- else {
84
- return this.websocket;
85
- }
86
- }
87
- }
88
- exports.default = new cbws();
@@ -1,352 +0,0 @@
1
- import cbws from './websocket';
2
- import {GoToPageResponse,UrlResponse,GetMarkdownResponse,HtmlReceived,ExtractTextResponse,GetContentResponse} from '@codebolt/types'
3
- /**
4
- * A module for interacting with a browser through WebSockets.
5
- */
6
- const cbbrowser = {
7
-
8
- /**
9
- * Opens a new page in the browser.
10
- */
11
- newPage: () => {
12
-
13
- return new Promise((resolve, reject) => {
14
- cbws.getWebsocket.send(JSON.stringify({
15
- "type": "browserEvent",
16
- action: 'newPage'
17
- }));
18
- cbws.getWebsocket.on('message', (data: string) => {
19
- const response = JSON.parse(data);
20
- if (response.event === "newPageResponse") {
21
- resolve(response);
22
- }
23
- });
24
- });
25
- },
26
-
27
- /**
28
- * Retrieves the current URL of the browser's active page.
29
- * @returns {Promise<UrlResponse>} A promise that resolves with the URL.
30
- */
31
- getUrl: ():Promise<UrlResponse> => {
32
- return new Promise((resolve, reject) => {
33
- cbws.getWebsocket.send(JSON.stringify({
34
- "type": "browserEvent",
35
- action: 'getUrl'
36
- }));
37
- cbws.getWebsocket.on('message', (data: string) => {
38
- const response = JSON.parse(data);
39
- if (response.event === "getUrlResponse") {
40
- resolve(response);
41
- }
42
- });
43
- });
44
- },
45
-
46
- /**
47
- * Navigates to a specified URL.
48
- * @param {string} url - The URL to navigate to.
49
- * @returns {Promise<GoToPageResponse>} A promise that resolves when navigation is complete.
50
- */
51
- goToPage: (url: string):Promise<GoToPageResponse> => {
52
- return new Promise((resolve, reject) => {
53
- cbws.getWebsocket.send(JSON.stringify({
54
- "type": "browserEvent",
55
- action: 'goToPage',
56
- url
57
- }));
58
- cbws.getWebsocket.on('message', (data: string) => {
59
- const response = JSON.parse(data);
60
- if (response.event === "goToPageResponse") {
61
- resolve(response);
62
- }
63
- });
64
- });
65
- },
66
-
67
- /**
68
- * Takes a screenshot of the current page.
69
- */
70
- screenshot: () => {
71
- return new Promise((resolve, reject) => {
72
- cbws.getWebsocket.send(JSON.stringify({
73
- "type": "browserEvent",
74
- action: 'screenshot'
75
- }));
76
- cbws.getWebsocket.on('message', (data: string) => {
77
- const response = JSON.parse(data);
78
- if (response.event === "screenshotResponse") {
79
- resolve(response.payload);
80
- }
81
- });
82
- });
83
- },
84
-
85
- /**
86
- * Retrieves the HTML content of the current page.
87
- * @returns {Promise<HtmlReceived>} A promise that resolves with the HTML content.
88
- */
89
- getHTML: ():Promise<HtmlReceived> => {
90
- return new Promise((resolve, reject) => {
91
- cbws.getWebsocket.send(JSON.stringify({
92
- "type": "browserEvent",
93
- action: 'getHTML'
94
- }));
95
- cbws.getWebsocket.on('message', (data: string) => {
96
- const response = JSON.parse(data);
97
- if (response.event === "htmlReceived") {
98
- resolve(response.htmlResponse);
99
- }
100
- });
101
- });
102
- },
103
-
104
- /**
105
- * Retrieves the Markdown content of the current page.
106
- * @returns {Promise<GetMarkdownResponse>} A promise that resolves with the Markdown content.
107
- */
108
- getMarkdown: ():Promise<GetMarkdownResponse> => {
109
- return new Promise((resolve, reject) => {
110
- cbws.getWebsocket.send(JSON.stringify({
111
- "type": "browserEvent",
112
- action: 'getMarkdown'
113
- }));
114
- cbws.getWebsocket.on('message', (data: string) => {
115
- const response = JSON.parse(data);
116
- if (response.event === "getMarkdownResponse") {
117
- resolve(response);
118
- }
119
- });
120
- });
121
- },
122
-
123
- /**
124
- * Retrieves the PDF content of the current page.
125
- *
126
- */
127
- getPDF: () => {
128
- cbws.getWebsocket.send(JSON.stringify({
129
- "type": "browserEvent",
130
- action: 'getPDF'
131
- }));
132
- },
133
-
134
- /**
135
- * Converts the PDF content of the current page to text.
136
- */
137
- pdfToText: () => {
138
- cbws.getWebsocket.send(JSON.stringify({
139
- "type": "browserEvent",
140
- action: 'pdfToText'
141
- }));
142
- },
143
-
144
- /**
145
- * Retrieves the content of the current page.
146
- * @returns {Promise<GetContentResponse>} A promise that resolves with the content.
147
- */
148
- getContent: ():Promise<GetContentResponse> => {
149
-
150
- return new Promise((resolve, reject) => {
151
- cbws.getWebsocket.send(JSON.stringify({
152
- "type": "browserEvent",
153
- action: 'getContent'
154
- }));
155
- cbws.getWebsocket.on('message', (data: string) => {
156
- const response = JSON.parse(data);
157
- if (response.event === "getContentResponse") {
158
- resolve(response);
159
- }
160
- });
161
- });
162
- },
163
- /**
164
- * Retrieves the snapshot of the current page.
165
- * @returns {Promise<GetContentResponse>} A promise that resolves with the content.
166
- */
167
- getSnapShot: ():Promise<any> => {
168
-
169
- return new Promise((resolve, reject) => {
170
- cbws.getWebsocket.send(JSON.stringify({
171
- "type": "browserEvent",
172
- action: 'getSnapShot'
173
- }));
174
- cbws.getWebsocket.on('message', (data: string) => {
175
- const response = JSON.parse(data);
176
- if (response.event === "getSnapShotResponse") {
177
- resolve(response);
178
- }
179
- });
180
- });
181
- },
182
- /**
183
- * Retrieves browser info like height width scrollx scrolly of the current page.
184
- * @returns {Promise<GetContentResponse>} A promise that resolves with the content.
185
- */
186
- getBrowserInfo: ():Promise<any> => {
187
-
188
- return new Promise((resolve, reject) => {
189
- cbws.getWebsocket.send(JSON.stringify({
190
- "type": "browserEvent",
191
- action: 'getBrowserInfo'
192
- }));
193
- cbws.getWebsocket.on('message', (data: string) => {
194
- const response = JSON.parse(data);
195
- if (response.event === "getBrowserInfoResponse") {
196
- resolve(response);
197
- }
198
- });
199
- });
200
- },
201
-
202
- /**
203
- * Extracts text from the current page.
204
- * @returns {Promise<ExtractTextResponse>} A promise that resolves with the extracted text.
205
- *
206
- */
207
- extractText: ():Promise<ExtractTextResponse> => {
208
-
209
- return new Promise((resolve, reject) => {
210
- cbws.getWebsocket.send(JSON.stringify({
211
- "type": "browserEvent",
212
- action: 'extractText'
213
- }));
214
- cbws.getWebsocket.on('message', (data: string) => {
215
- const response = JSON.parse(data);
216
- if (response.event === "extractTextResponse") {
217
- resolve(response);
218
- }
219
- });
220
- });
221
- },
222
-
223
- /**
224
- * Closes the current page.
225
- */
226
- close: () => {
227
- cbws.getWebsocket.send(JSON.stringify({
228
- "type": "browserEvent",
229
- action: 'close'
230
- }));
231
- },
232
-
233
- /**
234
- * Scrolls the current page in a specified direction by a specified number of pixels.
235
- * @param {string} direction - The direction to scroll.
236
- * @param {string} pixels - The number of pixels to scroll.
237
- * @returns {Promise<any>} A promise that resolves when the scroll action is complete.
238
- */
239
- scroll: (direction: string, pixels: string) => {
240
- return new Promise((resolve, reject) => {
241
- cbws.getWebsocket.send(JSON.stringify({
242
- "type": "browserEvent",
243
- action: 'scroll',
244
- direction,
245
- pixels
246
- }));
247
- cbws.getWebsocket.on('message', (data: string) => {
248
- const response = JSON.parse(data);
249
- if (response.event === "scrollResponse") {
250
- resolve(response);
251
- }
252
- });
253
- });
254
- },
255
-
256
- /**
257
- * Types text into a specified element on the page.
258
- * @param {string} elementid - The ID of the element to type into.
259
- * @param {string} text - The text to type.
260
- * @returns {Promise<any>} A promise that resolves when the typing action is complete.
261
- */
262
- type: (elementid: string, text: string) => {
263
- return new Promise((resolve, reject) => {
264
- cbws.getWebsocket.send(JSON.stringify({
265
- "type": "browserEvent",
266
- action: 'type',
267
- text,
268
- elementid
269
- }));
270
- cbws.getWebsocket.on('message', (data: string) => {
271
- const response = JSON.parse(data);
272
- if (response.event === "typeResponse") {
273
- resolve(response);
274
- }
275
- });
276
- });
277
- },
278
-
279
- /**
280
- * Clicks on a specified element on the page.
281
- * @param {string} elementid - The ID of the element to click.
282
- * @returns {Promise<any>} A promise that resolves when the click action is complete.
283
- */
284
- click: (elementid: string) => {
285
- return new Promise((resolve, reject) => {
286
- cbws.getWebsocket.send(JSON.stringify({
287
- "type": "browserEvent",
288
- action: 'click',
289
- elementid
290
- }));
291
- cbws.getWebsocket.on('message', (data: string) => {
292
- const response = JSON.parse(data);
293
- if (response.event === "clickResponse") {
294
- resolve(response);
295
- }
296
- });
297
- });
298
- },
299
-
300
- /**
301
- * Simulates the Enter key press on the current page.
302
- * @returns {Promise<any>} A promise that resolves when the Enter action is complete.
303
- */
304
- enter: () => {
305
- return new Promise((resolve, reject) => {
306
- cbws.getWebsocket.send(JSON.stringify({
307
- "type": "browserEvent",
308
- action: 'enter'
309
- }));
310
- cbws.getWebsocket.on('message', (data: string) => {
311
- const response = JSON.parse(data);
312
- if (response.event === "EnterResponse") {
313
- resolve(response);
314
- }
315
- });
316
- });
317
- },
318
-
319
- /**
320
- * Performs a search on the current page using a specified query.
321
- * @param {string} elementid - The ID of the element to perform the search in.
322
- * @param {string} query - The search query.
323
- * @returns {Promise<any>} A promise that resolves with the search results.
324
- */
325
- search: (elementid: string, query: string) => {
326
- return new Promise((resolve, reject) => {
327
- cbws.getWebsocket.send(JSON.stringify({
328
- "type": "browserEvent",
329
- action: 'search',
330
- elementid,
331
- query
332
- }));
333
- cbws.getWebsocket.on('message', (data: string) => {
334
- const response = JSON.parse(data);
335
- if (response.event === "searchResponse") {
336
- resolve(response);
337
- }
338
- });
339
- });
340
- }
341
- }
342
-
343
- export default cbbrowser;
344
-
345
-
346
-
347
- /***
348
-
349
- start_browser(objective: string, url: string, previous_command: string, browser_content: string) {
350
- cbbrowser.newPage();
351
- }
352
- */