Skip to content

Commit 041ac19

Browse files
changes
1 parent 4bf1cd0 commit 041ac19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1674
-657
lines changed

index.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @class Codebolt
3+
* @description This class provides a unified interface to interact with various modules.
4+
*/
5+
declare class Codebolt {
6+
private static instance;
7+
private wsManager;
8+
private chat;
9+
/**
10+
* @constructor
11+
* @description Initializes the websocket connection.
12+
*/
13+
constructor();
14+
static getInstance(): Codebolt;
15+
/**
16+
* @method waitForConnection
17+
* @description Waits for the WebSocket connection to open.
18+
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
19+
*/
20+
connect(): Promise<void>;
21+
disconnect(): Promise<void>;
22+
}
23+
declare const _default: Codebolt;
24+
export default _default;

index.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 chat_1 = __importDefault(require("./modules/chat"));
8+
// import {chatSummary} from './modules/history'
9+
/**
10+
* @class Codebolt
11+
* @description This class provides a unified interface to interact with various modules.
12+
*/
13+
class Codebolt {
14+
/**
15+
* @constructor
16+
* @description Initializes the websocket connection.
17+
*/
18+
constructor() {
19+
this.wsManager = new websocket_1.default();
20+
this.chat = new chat_1.default(this.wsManager);
21+
// this.websocket = cbws.getWebsocket;
22+
// ... initialize other modules ...
23+
}
24+
static getInstance() {
25+
if (!Codebolt.instance) {
26+
Codebolt.instance = new Codebolt();
27+
}
28+
return Codebolt.instance;
29+
}
30+
/**
31+
* @method waitForConnection
32+
* @description Waits for the WebSocket connection to open.
33+
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
34+
*/
35+
// async waitForConnection() {
36+
// return new Promise<void>((resolve, reject) => {
37+
// if (!this.websocket) {
38+
// reject(new Error('WebSocket is not initialized'));
39+
// return;
40+
// }
41+
// if (this.websocket.readyState === WebSocket.OPEN) {
42+
// resolve();
43+
// return;
44+
// }
45+
// this.websocket.addEventListener('open', () => {
46+
// resolve();
47+
// });
48+
// this.websocket.addEventListener('error', (error) => {
49+
// reject(error);
50+
// });
51+
// });
52+
// }
53+
async connect() {
54+
var _a;
55+
await ((_a = this.wsManager) === null || _a === void 0 ? void 0 : _a.connect());
56+
}
57+
async disconnect() {
58+
var _a;
59+
await ((_a = this.wsManager) === null || _a === void 0 ? void 0 : _a.disconnect());
60+
this.wsManager = null;
61+
}
62+
}
63+
Codebolt.instance = null;
64+
exports.default = Codebolt.getInstance();
65+
// module.exports = new Codebolt();

modules/browser.d.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { GoToPageResponse, UrlResponse, GetMarkdownResponse, HtmlReceived, ExtractTextResponse, GetContentResponse } from '@codebolt/types';
2+
/**
3+
* A module for interacting with a browser through WebSockets.
4+
*/
5+
declare const cbbrowser: {
6+
/**
7+
* Opens a new page in the browser.
8+
*/
9+
newPage: () => Promise<unknown>;
10+
/**
11+
* Retrieves the current URL of the browser's active page.
12+
* @returns {Promise<UrlResponse>} A promise that resolves with the URL.
13+
*/
14+
getUrl: () => Promise<UrlResponse>;
15+
/**
16+
* Navigates to a specified URL.
17+
* @param {string} url - The URL to navigate to.
18+
* @returns {Promise<GoToPageResponse>} A promise that resolves when navigation is complete.
19+
*/
20+
goToPage: (url: string) => Promise<GoToPageResponse>;
21+
/**
22+
* Takes a screenshot of the current page.
23+
*/
24+
screenshot: () => Promise<unknown>;
25+
/**
26+
* Retrieves the HTML content of the current page.
27+
* @returns {Promise<HtmlReceived>} A promise that resolves with the HTML content.
28+
*/
29+
getHTML: () => Promise<HtmlReceived>;
30+
/**
31+
* Retrieves the Markdown content of the current page.
32+
* @returns {Promise<GetMarkdownResponse>} A promise that resolves with the Markdown content.
33+
*/
34+
getMarkdown: () => Promise<GetMarkdownResponse>;
35+
/**
36+
* Retrieves the PDF content of the current page.
37+
*
38+
*/
39+
getPDF: () => void;
40+
/**
41+
* Converts the PDF content of the current page to text.
42+
*/
43+
pdfToText: () => void;
44+
/**
45+
* Retrieves the content of the current page.
46+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
47+
*/
48+
getContent: () => Promise<GetContentResponse>;
49+
/**
50+
* Retrieves the snapshot of the current page.
51+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
52+
*/
53+
getSnapShot: () => Promise<any>;
54+
/**
55+
* Retrieves browser info like height width scrollx scrolly of the current page.
56+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
57+
*/
58+
getBrowserInfo: () => Promise<any>;
59+
/**
60+
* Extracts text from the current page.
61+
* @returns {Promise<ExtractTextResponse>} A promise that resolves with the extracted text.
62+
*
63+
*/
64+
extractText: () => Promise<ExtractTextResponse>;
65+
/**
66+
* Closes the current page.
67+
*/
68+
close: () => void;
69+
/**
70+
* Scrolls the current page in a specified direction by a specified number of pixels.
71+
* @param {string} direction - The direction to scroll.
72+
* @param {string} pixels - The number of pixels to scroll.
73+
* @returns {Promise<any>} A promise that resolves when the scroll action is complete.
74+
*/
75+
scroll: (direction: string, pixels: string) => Promise<unknown>;
76+
/**
77+
* Types text into a specified element on the page.
78+
* @param {string} elementid - The ID of the element to type into.
79+
* @param {string} text - The text to type.
80+
* @returns {Promise<any>} A promise that resolves when the typing action is complete.
81+
*/
82+
type: (elementid: string, text: string) => Promise<unknown>;
83+
/**
84+
* Clicks on a specified element on the page.
85+
* @param {string} elementid - The ID of the element to click.
86+
* @returns {Promise<any>} A promise that resolves when the click action is complete.
87+
*/
88+
click: (elementid: string) => Promise<unknown>;
89+
/**
90+
* Simulates the Enter key press on the current page.
91+
* @returns {Promise<any>} A promise that resolves when the Enter action is complete.
92+
*/
93+
enter: () => Promise<unknown>;
94+
/**
95+
* Performs a search on the current page using a specified query.
96+
* @param {string} elementid - The ID of the element to perform the search in.
97+
* @param {string} query - The search query.
98+
* @returns {Promise<any>} A promise that resolves with the search results.
99+
*/
100+
search: (elementid: string, query: string) => Promise<unknown>;
101+
};
102+
export default cbbrowser;
103+
/***
104+
105+
start_browser(objective: string, url: string, previous_command: string, browser_content: string) {
106+
cbbrowser.newPage();
107+
}
108+
*/

0 commit comments

Comments
 (0)