Skip to content

Commit 6e25c09

Browse files
payload sent to message
1 parent 041ac19 commit 6e25c09

File tree

13 files changed

+478
-730
lines changed

13 files changed

+478
-730
lines changed

index.d.ts

Lines changed: 209 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,227 @@
1+
import WebSocket from 'ws';
2+
import { EventEmitter } from 'events';
13
/**
24
* @class Codebolt
35
* @description This class provides a unified interface to interact with various modules.
46
*/
57
declare class Codebolt {
6-
private static instance;
7-
private wsManager;
8-
private chat;
98
/**
109
* @constructor
1110
* @description Initializes the websocket connection.
1211
*/
1312
constructor();
14-
static getInstance(): Codebolt;
1513
/**
1614
* @method waitForConnection
1715
* @description Waits for the WebSocket connection to open.
1816
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
1917
*/
20-
connect(): Promise<void>;
21-
disconnect(): Promise<void>;
18+
waitForConnection(): Promise<void>;
19+
websocket: WebSocket | null;
20+
fs: {
21+
createFile: (fileName: string, source: string, filePath: string) => Promise<import("@codebolt/types").CreateFileResponse>;
22+
createFolder: (folderName: string, folderPath: string) => Promise<import("@codebolt/types").CreateFolderResponse>;
23+
readFile: (filename: string, filePath: string) => Promise<import("@codebolt/types").ReadFileResponse>;
24+
updateFile: (filename: string, filePath: string, newContent: string) => Promise<import("@codebolt/types").UpdateFileResponse>;
25+
deleteFile: (filename: string, filePath: string) => Promise<import("@codebolt/types").DeleteFileResponse>;
26+
deleteFolder: (foldername: string, folderpath: string) => Promise<import("@codebolt/types").DeleteFolderResponse>;
27+
listFile: (folderPath: string, isRecursive?: boolean) => Promise<unknown>;
28+
};
29+
git: {
30+
init: (path: string) => Promise<any>;
31+
clone: (url: string, path: string) => Promise<any>;
32+
pull: (path: string) => Promise<any>;
33+
push: (path: string) => Promise<any>;
34+
status: (path: string) => Promise<any>;
35+
add: (path: string) => Promise<any>;
36+
commit: (message: string) => Promise<any>;
37+
checkout: (path: string, branch: string) => Promise<any>;
38+
branch: (path: string, branch: string) => Promise<any>;
39+
logs: (path: string) => Promise<any>;
40+
diff: (commitHash: string, path: string) => Promise<any>;
41+
};
42+
llm: {
43+
inference: (message: string, llmrole: string) => Promise<import("@codebolt/types").LLMResponse>;
44+
};
45+
browser: {
46+
newPage: () => Promise<unknown>;
47+
getUrl: () => Promise<import("@codebolt/types").UrlResponse>;
48+
goToPage: (url: string) => Promise<import("@codebolt/types").GoToPageResponse>;
49+
screenshot: () => Promise<unknown>;
50+
getHTML: () => Promise<import("@codebolt/types").HtmlReceived>;
51+
getMarkdown: () => Promise<import("@codebolt/types").GetMarkdownResponse>;
52+
getPDF: () => void;
53+
pdfToText: () => void;
54+
getContent: () => Promise<import("@codebolt/types").GetContentResponse>;
55+
getSnapShot: () => Promise<any>;
56+
getBrowserInfo: () => Promise<any>;
57+
extractText: () => Promise<import("@codebolt/types").ExtractTextResponse>;
58+
close: () => void;
59+
scroll: (direction: string, pixels: string) => Promise<unknown>;
60+
type: (elementid: string, text: string) => Promise<unknown>;
61+
click: (elementid: string) => Promise<unknown>;
62+
enter: () => Promise<unknown>;
63+
search: (elementid: string, query: string) => Promise<unknown>;
64+
};
65+
chat: {
66+
getChatHistory: () => Promise<import("@codebolt/types").ChatMessage[]>;
67+
onActionMessage: () => {
68+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
69+
addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
70+
on<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
71+
once<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
72+
removeListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
73+
off<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
74+
removeAllListeners(eventName?: string | symbol | undefined): any;
75+
setMaxListeners(n: number): any;
76+
getMaxListeners(): number;
77+
listeners<K>(eventName: string | symbol): Function[];
78+
rawListeners<K>(eventName: string | symbol): Function[];
79+
emit<K>(eventName: string | symbol, ...args: any[]): boolean;
80+
listenerCount<K>(eventName: string | symbol, listener?: Function | undefined): number;
81+
prependListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
82+
prependOnceListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
83+
eventNames(): (string | symbol)[];
84+
} | undefined;
85+
sendMessage: (message: string, payload: any) => void;
86+
waitforReply: (message: string) => Promise<import("@codebolt/types").UserMessage>;
87+
processStarted: () => {
88+
event: {
89+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
90+
addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
91+
on<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
92+
once<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
93+
removeListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
94+
off<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
95+
removeAllListeners(eventName?: string | symbol | undefined): any;
96+
setMaxListeners(n: number): any;
97+
getMaxListeners(): number;
98+
listeners<K>(eventName: string | symbol): Function[];
99+
rawListeners<K>(eventName: string | symbol): Function[];
100+
emit<K>(eventName: string | symbol, ...args: any[]): boolean;
101+
listenerCount<K>(eventName: string | symbol, listener?: Function | undefined): number;
102+
prependListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
103+
prependOnceListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
104+
eventNames(): (string | symbol)[];
105+
};
106+
stopProcess: () => void;
107+
};
108+
stopProcess: () => void;
109+
processFinished: () => void;
110+
sendConfirmationRequest: (confirmationMessage: string, buttons?: string[]) => Promise<string>;
111+
sendNotificationEvent: (notificationMessage: string, type: "debug" | "git" | "planner" | "browser" | "editor" | "terminal" | "preview") => void;
112+
};
113+
terminal: {
114+
eventEmitter: {
115+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
116+
addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
117+
on<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
118+
once<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
119+
removeListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
120+
off<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
121+
removeAllListeners(eventName?: string | symbol | undefined): any;
122+
setMaxListeners(n: number): any;
123+
getMaxListeners(): number;
124+
listeners<K>(eventName: string | symbol): Function[];
125+
rawListeners<K>(eventName: string | symbol): Function[];
126+
emit<K>(eventName: string | symbol, ...args: any[]): boolean;
127+
listenerCount<K>(eventName: string | symbol, listener?: Function | undefined): number;
128+
prependListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
129+
prependOnceListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
130+
eventNames(): (string | symbol)[];
131+
};
132+
executeCommand: (command: string, executeInMain?: boolean) => Promise<import("@codebolt/types").CommandOutput | import("@codebolt/types").CommandError>;
133+
executeCommandRunUntilError: (command: string, executeInMain?: boolean) => Promise<import("@codebolt/types").CommandError>;
134+
sendManualInterrupt(): Promise<import("@codebolt/types").TerminalInterruptResponse>;
135+
executeCommandWithStream(command: string, executeInMain?: boolean): EventEmitter;
136+
};
137+
codeutils: {
138+
getJsTree: (filePath?: string) => Promise<any>;
139+
getAllFilesAsMarkDown: () => Promise<string>;
140+
performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<import("@codebolt/types").MatchProblemResponse>;
141+
getMatcherList: () => Promise<import("@codebolt/types").GetMatcherListTreeResponse>;
142+
matchDetail: (matcher: string) => Promise<import("@codebolt/types").getMatchDetail>;
143+
};
144+
docutils: {
145+
pdf_to_text: (pdf_path: any) => Promise<string>;
146+
};
147+
crawler: {
148+
start: () => void;
149+
screenshot: () => void;
150+
goToPage: (url: string) => void;
151+
scroll: (direction: string) => void;
152+
click: (id: string) => Promise<unknown>;
153+
type: (id: string, text: string) => Promise<unknown>;
154+
enter: () => void;
155+
crawl: (query: string) => Promise<unknown>;
156+
};
157+
search: {
158+
init: (engine?: string) => void;
159+
search: (query: string) => Promise<string>;
160+
get_first_link: (query: string) => Promise<string>;
161+
};
162+
knowledge: {};
163+
rag: {
164+
init: () => void;
165+
add_file: (filename: string, file_path: string) => void;
166+
retrieve_related_knowledge: (query: string, filename: string) => void;
167+
};
168+
codeparsers: {
169+
getClassesInFile: (file: any) => void;
170+
getFunctionsinClass: (file: any, className: any) => void;
171+
getAstTreeInFile: (file: any, className: any) => void;
172+
};
173+
outputparsers: {
174+
init: (output: any) => void;
175+
parseErrors: (output: any) => string[];
176+
parseWarnings: (output: any) => string[];
177+
};
178+
project: {
179+
getProjectSettings: (output: any) => void;
180+
getProjectPath: () => Promise<import("@codebolt/types").GetProjectPathResponse>;
181+
getRepoMap: (message: any) => Promise<import("@codebolt/types").GetProjectPathResponse>;
182+
runProject: () => void;
183+
};
184+
dbmemory: {
185+
addKnowledge: (key: string, value: any) => Promise<import("@codebolt/types").MemorySetResponse>;
186+
getKnowledge: (key: string) => Promise<import("@codebolt/types").MemoryGetResponse>;
187+
};
188+
cbstate: {
189+
getApplicationState: () => Promise<import("@codebolt/types").ApplicationState>;
190+
addToAgentState: (key: string, value: string) => Promise<import("@codebolt/types").AddToAgentStateResponse>;
191+
getAgentState: () => Promise<import("@codebolt/types").GetAgentStateResponse>;
192+
};
193+
taskplaner: {
194+
addTask: (task: string) => Promise<any>;
195+
getTasks: () => Promise<any>;
196+
updateTask: (task: string) => Promise<any>;
197+
};
198+
vectordb: {
199+
getVector: (key: string) => Promise<import("@codebolt/types").GetVectorResponse>;
200+
addVectorItem: (item: any) => Promise<import("@codebolt/types").AddVectorItemResponse>;
201+
queryVectorItem: (key: string) => Promise<import("@codebolt/types").QueryVectorItemResponse>;
202+
queryVectorItems: (items: [], dbPath: string) => Promise<import("@codebolt/types").QueryVectorItemResponse>;
203+
};
204+
debug: {
205+
debug: (log: string, type: import("./modules/debug").logType) => Promise<import("@codebolt/types").DebugAddLogResponse>;
206+
openDebugBrowser: (url: string, port: number) => Promise<import("@codebolt/types").OpenDebugBrowserResponse>;
207+
};
208+
tokenizer: {
209+
addToken: (key: string) => Promise<import("@codebolt/types").AddTokenResponse>;
210+
getToken: (key: string) => Promise<import("@codebolt/types").GetTokenResponse>;
211+
};
212+
chatSummary: {
213+
summarizeAll: () => Promise<{
214+
role: string;
215+
content: string;
216+
}[]>;
217+
summarize: (messages: {
218+
role: string;
219+
content: string;
220+
}[], depth: number) => Promise<{
221+
role: string;
222+
content: string;
223+
}[]>;
224+
};
22225
}
23226
declare const _default: Codebolt;
24227
export default _default;

index.js

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
66
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"));
711
const chat_1 = __importDefault(require("./modules/chat"));
8-
// import {chatSummary} from './modules/history'
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 state_1 = __importDefault(require("./modules/state"));
24+
const task_1 = __importDefault(require("./modules/task"));
25+
const vectordb_1 = __importDefault(require("./modules/vectordb"));
26+
const debug_1 = __importDefault(require("./modules/debug"));
27+
const tokenizer_1 = __importDefault(require("./modules/tokenizer"));
28+
const ws_1 = __importDefault(require("ws"));
29+
const history_1 = require("./modules/history");
930
/**
1031
* @class Codebolt
1132
* @description This class provides a unified interface to interact with various modules.
@@ -16,50 +37,54 @@ class Codebolt {
1637
* @description Initializes the websocket connection.
1738
*/
1839
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;
40+
this.websocket = null;
41+
this.fs = fs_1.default;
42+
this.git = git_1.default;
43+
this.llm = llm_1.default;
44+
this.browser = browser_1.default;
45+
this.chat = chat_1.default;
46+
this.terminal = terminal_1.default;
47+
this.codeutils = codeutils_1.default;
48+
this.docutils = docutils_1.default;
49+
this.crawler = crawler_1.default;
50+
this.search = search_1.default;
51+
this.knowledge = knowledge_1.default;
52+
this.rag = rag_1.default;
53+
this.codeparsers = codeparsers_1.default;
54+
this.outputparsers = outputparsers_1.default;
55+
this.project = project_1.default;
56+
this.dbmemory = dbmemory_1.default;
57+
this.cbstate = state_1.default;
58+
this.taskplaner = task_1.default;
59+
this.vectordb = vectordb_1.default;
60+
this.debug = debug_1.default;
61+
this.tokenizer = tokenizer_1.default;
62+
this.chatSummary = history_1.chatSummary;
63+
this.websocket = websocket_1.default.getWebsocket;
2964
}
3065
/**
3166
* @method waitForConnection
3267
* @description Waits for the WebSocket connection to open.
3368
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
3469
*/
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;
70+
async waitForConnection() {
71+
return new Promise((resolve, reject) => {
72+
if (!this.websocket) {
73+
reject(new Error('WebSocket is not initialized'));
74+
return;
75+
}
76+
if (this.websocket.readyState === ws_1.default.OPEN) {
77+
resolve();
78+
return;
79+
}
80+
this.websocket.addEventListener('open', () => {
81+
resolve();
82+
});
83+
this.websocket.addEventListener('error', (error) => {
84+
reject(error);
85+
});
86+
});
6187
}
6288
}
63-
Codebolt.instance = null;
64-
exports.default = Codebolt.getInstance();
89+
exports.default = new Codebolt();
6590
// module.exports = new Codebolt();

modules/chat.d.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)