Skip to content

Commit 1e3965b

Browse files
changes
1 parent ce7cd9d commit 1e3965b

Some content is hidden

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

51 files changed

+3537
-3
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
build
22
node_modules
3-
modules
4-
index.js
5-
index.d.ts
3+
# modules
4+
# index.js
5+
# index.d.ts

index.d.ts

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

index.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 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");
30+
const mcp_1 = __importDefault(require("./modules/mcp"));
31+
/**
32+
* @class Codebolt
33+
* @description This class provides a unified interface to interact with various modules.
34+
*/
35+
class Codebolt {
36+
/**
37+
* @constructor
38+
* @description Initializes the websocket connection.
39+
*/
40+
constructor() {
41+
this.websocket = null;
42+
this.fs = fs_1.default;
43+
this.git = git_1.default;
44+
this.llm = llm_1.default;
45+
this.browser = browser_1.default;
46+
this.chat = chat_1.default;
47+
this.terminal = terminal_1.default;
48+
this.codeutils = codeutils_1.default;
49+
this.docutils = docutils_1.default;
50+
this.crawler = crawler_1.default;
51+
this.search = search_1.default;
52+
this.knowledge = knowledge_1.default;
53+
this.rag = rag_1.default;
54+
this.codeparsers = codeparsers_1.default;
55+
this.outputparsers = outputparsers_1.default;
56+
this.project = project_1.default;
57+
this.dbmemory = dbmemory_1.default;
58+
this.cbstate = state_1.default;
59+
this.taskplaner = task_1.default;
60+
this.vectordb = vectordb_1.default;
61+
this.debug = debug_1.default;
62+
this.tokenizer = tokenizer_1.default;
63+
this.chatSummary = history_1.chatSummary;
64+
this.MCP = mcp_1.default;
65+
this.websocket = websocket_1.default.getWebsocket;
66+
}
67+
/**
68+
* @method waitForConnection
69+
* @description Waits for the WebSocket connection to open.
70+
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
71+
*/
72+
async waitForConnection() {
73+
return new Promise((resolve, reject) => {
74+
if (!this.websocket) {
75+
reject(new Error('WebSocket is not initialized'));
76+
return;
77+
}
78+
if (this.websocket.readyState === ws_1.default.OPEN) {
79+
resolve();
80+
return;
81+
}
82+
this.websocket.addEventListener('open', () => {
83+
resolve();
84+
});
85+
this.websocket.addEventListener('error', (error) => {
86+
reject(error);
87+
});
88+
});
89+
}
90+
}
91+
exports.default = new Codebolt();
92+
// module.exports = new Codebolt();

0 commit comments

Comments
 (0)