@codebolt/codeboltjs 1.1.21 → 1.1.24
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 -1
- package/index.js +45 -4
- package/modules/chat.d.ts +1 -1
- package/modules/chat.js +2 -0
- package/modules/codeutils.d.ts +1 -0
- package/modules/codeutils.js +18 -0
- package/modules/debug.d.ts +1 -1
- package/modules/debug.js +2 -2
- package/modules/fs.d.ts +1 -0
- package/modules/fs.js +3 -1
- package/modules/terminal.d.ts +1 -1
- package/modules/terminal.js +2 -0
- package/modules/tokenizer.d.ts +12 -0
- package/modules/tokenizer.js +34 -0
- package/package.json +5 -5
- package/src/index.ts +33 -16
- package/src/modules/chat.ts +1 -1
- package/src/modules/codeutils.ts +16 -0
- package/src/modules/debug.ts +1 -1
- package/src/modules/fs.ts +5 -1
- package/src/modules/terminal.ts +1 -1
- package/src/modules/tokenizer.ts +32 -0
package/index.d.ts
CHANGED
|
@@ -1 +1,164 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import WebSocket, { EventEmitter } from 'ws';
|
|
3
|
+
/**
|
|
4
|
+
* @class Codebolt
|
|
5
|
+
* @description This class provides a unified interface to interact with various modules.
|
|
6
|
+
*/
|
|
7
|
+
declare class Codebolt extends EventEmitter {
|
|
8
|
+
/**
|
|
9
|
+
* @constructor
|
|
10
|
+
* @description Initializes the websocket connection.
|
|
11
|
+
*/
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* @method setupMessageListener
|
|
15
|
+
* @description Sets up a listener for incoming WebSocket messages.
|
|
16
|
+
*/
|
|
17
|
+
userMessageListener(): void;
|
|
18
|
+
/**
|
|
19
|
+
* @method waitForConnection
|
|
20
|
+
* @description Waits for the WebSocket connection to open.
|
|
21
|
+
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
|
|
22
|
+
*/
|
|
23
|
+
waitForConnection(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* @method start_browser
|
|
26
|
+
* @description Starts a new browser page.
|
|
27
|
+
* @param {string} objective - The objective of the browser session.
|
|
28
|
+
* @param {string} url - The URL to navigate to.
|
|
29
|
+
* @param {string} previous_command - The previous command executed.
|
|
30
|
+
* @param {string} browser_content - The content of the browser.
|
|
31
|
+
*/
|
|
32
|
+
start_browser(objective: string, url: string, previous_command: string, browser_content: string): void;
|
|
33
|
+
websocket: WebSocket | null;
|
|
34
|
+
fs: {
|
|
35
|
+
createFile: (fileName: string, source: string, filePath: string) => Promise<any>;
|
|
36
|
+
createFolder: (folderName: string, folderPath: string) => Promise<any>;
|
|
37
|
+
readFile: (filename: string, filePath: string) => Promise<any>;
|
|
38
|
+
updateFile: (filename: string, filePath: string, newContent: string) => Promise<any>;
|
|
39
|
+
deleteFile: (filename: string, filePath: string) => Promise<any>;
|
|
40
|
+
deleteFolder: (foldername: string, folderpath: string) => Promise<any>;
|
|
41
|
+
listFile: (folderPath?: string | undefined) => void;
|
|
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<any>;
|
|
58
|
+
};
|
|
59
|
+
browser: {
|
|
60
|
+
newPage: () => void;
|
|
61
|
+
getUrl: () => Promise<unknown>; /**
|
|
62
|
+
* @class Codebolt
|
|
63
|
+
* @description This class provides a unified interface to interact with various modules.
|
|
64
|
+
*/
|
|
65
|
+
goToPage: (url: string) => Promise<unknown>;
|
|
66
|
+
screenshot: () => void;
|
|
67
|
+
getHTML: () => Promise<unknown>;
|
|
68
|
+
getMarkdown: () => Promise<unknown>;
|
|
69
|
+
getPDF: () => void;
|
|
70
|
+
pdfToText: () => void;
|
|
71
|
+
getContent: () => void;
|
|
72
|
+
extractText: () => void;
|
|
73
|
+
close: () => void;
|
|
74
|
+
scroll: (direction: string, pixels: string) => Promise<unknown>;
|
|
75
|
+
type: (elementid: string, text: string) => Promise<unknown>;
|
|
76
|
+
click: (elementid: string) => Promise<unknown>;
|
|
77
|
+
enter: () => Promise<unknown>;
|
|
78
|
+
search: (elementid: string, query: string) => Promise<unknown>;
|
|
79
|
+
};
|
|
80
|
+
chat: {
|
|
81
|
+
eventEmitter: import("./modules/chat").CustomEventEmitter;
|
|
82
|
+
getChatHistory(): Promise<unknown>;
|
|
83
|
+
sendMessage(message: string): void;
|
|
84
|
+
waitforReply(message: string): Promise<any>;
|
|
85
|
+
processStarted(): {
|
|
86
|
+
event: import("./modules/chat").CustomEventEmitter;
|
|
87
|
+
stopProcess: () => void;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
terminal: {
|
|
91
|
+
eventEmitter: import("./modules/terminal").CustomEventEmitter;
|
|
92
|
+
executeCommand: (command: string) => Promise<any>;
|
|
93
|
+
executeCommandRunUntilError: (command: string) => Promise<any>;
|
|
94
|
+
sendManualInterrupt(): Promise<any>;
|
|
95
|
+
executeCommandWithStream(command: string): import("./modules/terminal").CustomEventEmitter;
|
|
96
|
+
};
|
|
97
|
+
codeutils: {
|
|
98
|
+
getCodeTree: (fileName: any, source: any, filePath: any) => Promise<any>;
|
|
99
|
+
getAllFilesAsMarkDown: () => Promise<unknown>;
|
|
100
|
+
};
|
|
101
|
+
docutils: {
|
|
102
|
+
pdf_to_text: (pdf_path: any) => Promise<string>;
|
|
103
|
+
};
|
|
104
|
+
crawler: {
|
|
105
|
+
start: () => void;
|
|
106
|
+
screenshot: () => void;
|
|
107
|
+
goToPage: (url: string) => void;
|
|
108
|
+
scroll: (direction: string) => void;
|
|
109
|
+
click: (id: string) => Promise<unknown>;
|
|
110
|
+
type: (id: string, text: string) => Promise<unknown>;
|
|
111
|
+
enter: () => void;
|
|
112
|
+
crawl: () => void;
|
|
113
|
+
};
|
|
114
|
+
search: {
|
|
115
|
+
init: (engine?: string) => void;
|
|
116
|
+
search: (query: string) => Promise<string>;
|
|
117
|
+
get_first_link: (query: string) => Promise<string>;
|
|
118
|
+
};
|
|
119
|
+
knowledge: {};
|
|
120
|
+
rag: {
|
|
121
|
+
init: () => void;
|
|
122
|
+
add_file: (filename: string, file_path: string) => void;
|
|
123
|
+
retrieve_related_knowledge: (query: string, filename: string) => void;
|
|
124
|
+
};
|
|
125
|
+
codeparsers: {
|
|
126
|
+
getClassesInFile: (file: any) => void;
|
|
127
|
+
getFunctionsinClass: (file: any, className: any) => void;
|
|
128
|
+
getAstTreeInFile: (file: any, className: any) => void;
|
|
129
|
+
};
|
|
130
|
+
outputparsers: {
|
|
131
|
+
init: (output: any) => void;
|
|
132
|
+
parseErrors: (output: any) => string[];
|
|
133
|
+
parseWarnings: (output: any) => string[];
|
|
134
|
+
};
|
|
135
|
+
project: {
|
|
136
|
+
getProjectSettings: (output: any) => void;
|
|
137
|
+
getProjectPath: () => Promise<any>;
|
|
138
|
+
};
|
|
139
|
+
dbmemory: {
|
|
140
|
+
addKnowledge: (key: string, value: any) => Promise<any>;
|
|
141
|
+
getKnowledge: (key: string) => Promise<any>;
|
|
142
|
+
};
|
|
143
|
+
cbstate: {
|
|
144
|
+
getApplicationState: () => Promise<any>;
|
|
145
|
+
};
|
|
146
|
+
taskplaner: {
|
|
147
|
+
addTask: (task: string) => Promise<any>;
|
|
148
|
+
getTasks: () => Promise<any>;
|
|
149
|
+
updateTask: (task: string) => Promise<any>;
|
|
150
|
+
};
|
|
151
|
+
vectordb: {
|
|
152
|
+
getVector: (key: string) => Promise<any>;
|
|
153
|
+
addVectorItem: (item: any) => Promise<any>;
|
|
154
|
+
queryVectorItem: (key: string) => Promise<any>;
|
|
155
|
+
};
|
|
156
|
+
debug: {
|
|
157
|
+
debug(log: string, type: import("./modules/debug").logType): Promise<unknown>;
|
|
158
|
+
};
|
|
159
|
+
tokenizer: {
|
|
160
|
+
addToken: (key: string) => Promise<any>;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
declare const _default: Codebolt;
|
|
164
|
+
export default _default;
|
package/index.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -24,17 +47,19 @@ const state_1 = __importDefault(require("./modules/state"));
|
|
|
24
47
|
const task_1 = __importDefault(require("./modules/task"));
|
|
25
48
|
const vectordb_1 = __importDefault(require("./modules/vectordb"));
|
|
26
49
|
const debug_1 = __importDefault(require("./modules/debug"));
|
|
27
|
-
const
|
|
50
|
+
const tokenizer_1 = __importDefault(require("./modules/tokenizer"));
|
|
51
|
+
const ws_1 = __importStar(require("ws"));
|
|
28
52
|
/**
|
|
29
53
|
* @class Codebolt
|
|
30
54
|
* @description This class provides a unified interface to interact with various modules.
|
|
31
55
|
*/
|
|
32
|
-
class Codebolt {
|
|
56
|
+
class Codebolt extends ws_1.EventEmitter {
|
|
33
57
|
/**
|
|
34
58
|
* @constructor
|
|
35
59
|
* @description Initializes the websocket connection.
|
|
36
60
|
*/
|
|
37
61
|
constructor() {
|
|
62
|
+
super();
|
|
38
63
|
this.websocket = null;
|
|
39
64
|
this.fs = fs_1.default;
|
|
40
65
|
this.git = git_1.default;
|
|
@@ -56,7 +81,23 @@ class Codebolt {
|
|
|
56
81
|
this.taskplaner = task_1.default;
|
|
57
82
|
this.vectordb = vectordb_1.default;
|
|
58
83
|
this.debug = debug_1.default;
|
|
84
|
+
this.tokenizer = tokenizer_1.default;
|
|
59
85
|
this.websocket = websocket_1.default.getWebsocket;
|
|
86
|
+
this.userMessageListener(); // Call setupMessageListener() to subscribe to WebSocket messages
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @method setupMessageListener
|
|
90
|
+
* @description Sets up a listener for incoming WebSocket messages.
|
|
91
|
+
*/
|
|
92
|
+
userMessageListener() {
|
|
93
|
+
if (!this.websocket)
|
|
94
|
+
return;
|
|
95
|
+
this.websocket.on('message', (data) => {
|
|
96
|
+
const response = JSON.parse(data);
|
|
97
|
+
if (response.type === "messageResponse") {
|
|
98
|
+
this.emit(response.message);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
60
101
|
}
|
|
61
102
|
/**
|
|
62
103
|
* @method waitForConnection
|
|
@@ -93,5 +134,5 @@ class Codebolt {
|
|
|
93
134
|
browser_1.default.newPage();
|
|
94
135
|
}
|
|
95
136
|
}
|
|
96
|
-
|
|
97
|
-
module.exports = new Codebolt();
|
|
137
|
+
exports.default = new Codebolt();
|
|
138
|
+
// module.exports = new Codebolt();
|
package/modules/chat.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
|
|
|
3
3
|
/**
|
|
4
4
|
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
5
5
|
*/
|
|
6
|
-
declare class CustomEventEmitter extends EventEmitter {
|
|
6
|
+
export declare class CustomEventEmitter extends EventEmitter {
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Chat module to interact with the WebSocket server.
|
package/modules/chat.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CustomEventEmitter = void 0;
|
|
6
7
|
// chat.ts
|
|
7
8
|
const websocket_1 = __importDefault(require("./websocket"));
|
|
8
9
|
const events_1 = require("events");
|
|
@@ -11,6 +12,7 @@ const events_1 = require("events");
|
|
|
11
12
|
*/
|
|
12
13
|
class CustomEventEmitter extends events_1.EventEmitter {
|
|
13
14
|
}
|
|
15
|
+
exports.CustomEventEmitter = CustomEventEmitter;
|
|
14
16
|
/**
|
|
15
17
|
* Chat module to interact with the WebSocket server.
|
|
16
18
|
*/
|
package/modules/codeutils.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ declare const cbcodeutils: {
|
|
|
10
10
|
* @returns {Promise<any>} A promise that resolves with the code tree.
|
|
11
11
|
*/
|
|
12
12
|
getCodeTree: (fileName: any, source: any, filePath: any) => Promise<any>;
|
|
13
|
+
getAllFilesAsMarkDown: () => Promise<unknown>;
|
|
13
14
|
};
|
|
14
15
|
export default cbcodeutils;
|
package/modules/codeutils.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const websocket_1 = __importDefault(require("./websocket"));
|
|
3
7
|
/**
|
|
4
8
|
* A utility module for working with code.
|
|
5
9
|
*/
|
|
@@ -15,6 +19,20 @@ const cbcodeutils = {
|
|
|
15
19
|
return new Promise((resolve, reject) => {
|
|
16
20
|
// Implementation would go here
|
|
17
21
|
});
|
|
22
|
+
},
|
|
23
|
+
getAllFilesAsMarkDown: () => {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
26
|
+
"type": "codeEvent",
|
|
27
|
+
"action": "getAllFilesMarkdown"
|
|
28
|
+
}));
|
|
29
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
30
|
+
const response = JSON.parse(data);
|
|
31
|
+
if (response.type === "getAllFilesMarkdownResponse") {
|
|
32
|
+
resolve(response.markdown); // Resolve the Promise with the response data
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
18
36
|
}
|
|
19
37
|
};
|
|
20
38
|
exports.default = cbcodeutils;
|
package/modules/debug.d.ts
CHANGED
package/modules/debug.js
CHANGED
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.debug = void 0;
|
|
6
|
+
exports.debug = exports.logType = void 0;
|
|
7
7
|
const websocket_1 = __importDefault(require("./websocket"));
|
|
8
8
|
var logType;
|
|
9
9
|
(function (logType) {
|
|
10
10
|
logType["info"] = "info";
|
|
11
11
|
logType["error"] = "error";
|
|
12
12
|
logType["warning"] = "warning";
|
|
13
|
-
})(logType || (logType = {}));
|
|
13
|
+
})(logType || (exports.logType = logType = {}));
|
|
14
14
|
exports.debug = {
|
|
15
15
|
debug(log, type) {
|
|
16
16
|
return new Promise((resolve, reject) => {
|
package/modules/fs.d.ts
CHANGED
package/modules/fs.js
CHANGED
package/modules/terminal.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
|
|
|
3
3
|
/**
|
|
4
4
|
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
5
5
|
*/
|
|
6
|
-
declare class CustomEventEmitter extends EventEmitter {
|
|
6
|
+
export declare class CustomEventEmitter extends EventEmitter {
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* A module for executing commands in a terminal-like environment via WebSocket.
|
package/modules/terminal.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CustomEventEmitter = void 0;
|
|
6
7
|
const websocket_1 = __importDefault(require("./websocket"));
|
|
7
8
|
const events_1 = require("events");
|
|
8
9
|
/**
|
|
@@ -10,6 +11,7 @@ const events_1 = require("events");
|
|
|
10
11
|
*/
|
|
11
12
|
class CustomEventEmitter extends events_1.EventEmitter {
|
|
12
13
|
}
|
|
14
|
+
exports.CustomEventEmitter = CustomEventEmitter;
|
|
13
15
|
/**
|
|
14
16
|
* A module for executing commands in a terminal-like environment via WebSocket.
|
|
15
17
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokenizer module for handling token-related operations.
|
|
3
|
+
*/
|
|
4
|
+
declare const tokenizer: {
|
|
5
|
+
/**
|
|
6
|
+
* Adds a token asynchronously.
|
|
7
|
+
* @param {string} key - The key of the token to add.
|
|
8
|
+
* @returns {Promise<any>} A promise that resolves with the response.
|
|
9
|
+
*/
|
|
10
|
+
addToken: (key: string) => Promise<any>;
|
|
11
|
+
};
|
|
12
|
+
export default tokenizer;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 asynchronously.
|
|
13
|
+
* @param {string} key - The key of the token to add.
|
|
14
|
+
* @returns {Promise<any>} A promise that resolves with the response.
|
|
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
|
+
exports.default = tokenizer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebolt/codeboltjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
"homepage": "https://codeboltai.github.io",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"typedoc-plugin-missing-exports": "^2.2.0",
|
|
22
|
-
"ws": "^8.
|
|
22
|
+
"ws": "^8.17.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/ws": "^8.5.10",
|
|
26
|
+
"jest": "^29.7.0",
|
|
27
|
+
"jest-serial-runner": "^1.2.1",
|
|
26
28
|
"ts-loader": "^9.5.1",
|
|
27
29
|
"typedoc": "^0.25.13",
|
|
28
30
|
"typescript": "^5.4.5",
|
|
29
31
|
"webpack": "^5.91.0",
|
|
30
|
-
"webpack-cli": "^5.1.4"
|
|
31
|
-
"jest": "^29.7.0",
|
|
32
|
-
"jest-serial-runner": "^1.2.1"
|
|
32
|
+
"webpack-cli": "^5.1.4"
|
|
33
33
|
},
|
|
34
34
|
"jest": {
|
|
35
35
|
"testTimeout": 50000
|
package/src/index.ts
CHANGED
|
@@ -19,47 +19,63 @@ import cbstate from './modules/state';
|
|
|
19
19
|
import task from './modules/task';
|
|
20
20
|
import vectorDB from './modules/vectordb';
|
|
21
21
|
import debug from './modules/debug'
|
|
22
|
-
import
|
|
22
|
+
import tokenizer from './modules/tokenizer'
|
|
23
|
+
import WebSocket, { EventEmitter } from 'ws';
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* @class Codebolt
|
|
27
28
|
* @description This class provides a unified interface to interact with various modules.
|
|
28
29
|
*/
|
|
29
|
-
class Codebolt {
|
|
30
|
+
class Codebolt extends EventEmitter { // Extend EventEmitter
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* @constructor
|
|
33
34
|
* @description Initializes the websocket connection.
|
|
34
35
|
*/
|
|
35
|
-
constructor(){
|
|
36
|
+
constructor() {
|
|
37
|
+
super()
|
|
36
38
|
this.websocket = cbws.getWebsocket;
|
|
39
|
+
this.userMessageListener(); // Call setupMessageListener() to subscribe to WebSocket messages
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @method setupMessageListener
|
|
43
|
+
* @description Sets up a listener for incoming WebSocket messages.
|
|
44
|
+
*/
|
|
45
|
+
userMessageListener() {
|
|
46
|
+
if (!this.websocket) return;
|
|
47
|
+
this.websocket.on('message', (data: string) => {
|
|
48
|
+
const response = JSON.parse(data);
|
|
49
|
+
if (response.type === "messageResponse") {
|
|
50
|
+
this.emit(response.message)
|
|
51
|
+
}
|
|
52
|
+
});
|
|
37
53
|
}
|
|
38
|
-
|
|
39
54
|
/**
|
|
40
55
|
* @method waitForConnection
|
|
41
56
|
* @description Waits for the WebSocket connection to open.
|
|
42
57
|
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
|
|
43
58
|
*/
|
|
44
|
-
|
|
59
|
+
async waitForConnection() {
|
|
45
60
|
return new Promise<void>((resolve, reject) => {
|
|
46
61
|
if (!this.websocket) {
|
|
47
62
|
reject(new Error('WebSocket is not initialized'));
|
|
48
63
|
return;
|
|
49
64
|
}
|
|
50
|
-
|
|
65
|
+
|
|
51
66
|
if (this.websocket.readyState === WebSocket.OPEN) {
|
|
52
67
|
resolve();
|
|
53
68
|
return;
|
|
54
69
|
}
|
|
55
|
-
|
|
70
|
+
|
|
56
71
|
this.websocket.addEventListener('open', () => {
|
|
57
72
|
resolve();
|
|
58
73
|
});
|
|
59
|
-
|
|
74
|
+
|
|
60
75
|
this.websocket.addEventListener('error', (error) => {
|
|
61
76
|
reject(error);
|
|
62
77
|
});
|
|
78
|
+
|
|
63
79
|
});
|
|
64
80
|
}
|
|
65
81
|
|
|
@@ -71,12 +87,12 @@ class Codebolt {
|
|
|
71
87
|
* @param {string} previous_command - The previous command executed.
|
|
72
88
|
* @param {string} browser_content - The content of the browser.
|
|
73
89
|
*/
|
|
74
|
-
start_browser(objective:string, url:string, previous_command:string, browser_content:string) {
|
|
90
|
+
start_browser(objective: string, url: string, previous_command: string, browser_content: string) {
|
|
75
91
|
cbbrowser.newPage();
|
|
76
92
|
}
|
|
77
93
|
websocket: WebSocket | null = null;
|
|
78
94
|
fs = cbfs;
|
|
79
|
-
git=git;
|
|
95
|
+
git = git;
|
|
80
96
|
llm = cbllm;
|
|
81
97
|
browser = cbbrowser;
|
|
82
98
|
chat = cbchat;
|
|
@@ -91,12 +107,13 @@ class Codebolt {
|
|
|
91
107
|
outputparsers = cboutputparsers;
|
|
92
108
|
project = cbproject;
|
|
93
109
|
dbmemory = dbmemory;
|
|
94
|
-
cbstate=cbstate;
|
|
95
|
-
taskplaner=task;
|
|
96
|
-
vectordb=vectorDB;
|
|
97
|
-
debug=debug;
|
|
110
|
+
cbstate = cbstate;
|
|
111
|
+
taskplaner = task;
|
|
112
|
+
vectordb = vectorDB;
|
|
113
|
+
debug = debug;
|
|
114
|
+
tokenizer = tokenizer;
|
|
98
115
|
}
|
|
99
116
|
|
|
100
|
-
|
|
117
|
+
export default new Codebolt();
|
|
101
118
|
|
|
102
|
-
module.exports = new Codebolt();
|
|
119
|
+
// module.exports = new Codebolt();
|
package/src/modules/chat.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { EventEmitter } from 'events';
|
|
|
5
5
|
/**
|
|
6
6
|
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
7
7
|
*/
|
|
8
|
-
class CustomEventEmitter extends EventEmitter {}
|
|
8
|
+
export class CustomEventEmitter extends EventEmitter {}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Chat module to interact with the WebSocket server.
|
package/src/modules/codeutils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* A utility module for working with code.
|
|
3
5
|
*/
|
|
@@ -13,6 +15,20 @@ const cbcodeutils = {
|
|
|
13
15
|
return new Promise((resolve, reject) => {
|
|
14
16
|
// Implementation would go here
|
|
15
17
|
});
|
|
18
|
+
},
|
|
19
|
+
getAllFilesAsMarkDown:()=>{
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
22
|
+
"type": "codeEvent",
|
|
23
|
+
"action":"getAllFilesMarkdown"
|
|
24
|
+
}));
|
|
25
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
26
|
+
const response = JSON.parse(data);
|
|
27
|
+
if (response.type === "getAllFilesMarkdownResponse") {
|
|
28
|
+
resolve(response.markdown); // Resolve the Promise with the response data
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
16
32
|
}
|
|
17
33
|
};
|
|
18
34
|
|
package/src/modules/debug.ts
CHANGED
package/src/modules/fs.ts
CHANGED
package/src/modules/terminal.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { EventEmitter } from 'events';
|
|
|
4
4
|
/**
|
|
5
5
|
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
6
6
|
*/
|
|
7
|
-
class CustomEventEmitter extends EventEmitter {}
|
|
7
|
+
export class CustomEventEmitter extends EventEmitter {}
|
|
8
8
|
/**
|
|
9
9
|
* A module for executing commands in a terminal-like environment via WebSocket.
|
|
10
10
|
*/
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tokenizer module for handling token-related operations.
|
|
5
|
+
*/
|
|
6
|
+
const tokenizer = {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Adds a token asynchronously.
|
|
10
|
+
* @param {string} key - The key of the token to add.
|
|
11
|
+
* @returns {Promise<any>} A promise that resolves with the response.
|
|
12
|
+
*/
|
|
13
|
+
addToken: async (key: string): Promise<any> => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
16
|
+
"type":"tokenizerEvent",
|
|
17
|
+
"action": "addToken",
|
|
18
|
+
"message": {
|
|
19
|
+
item: key
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
23
|
+
const response = JSON.parse(data);
|
|
24
|
+
if (response.type === "addTokenResponse") {
|
|
25
|
+
resolve(response);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default tokenizer
|