@codebolt/codeboltjs 1.1.22 → 1.1.25
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 +18 -10
- package/index.js +46 -1
- package/modules/codeutils.d.ts +1 -0
- package/modules/codeutils.js +18 -0
- package/modules/fs.d.ts +1 -0
- package/modules/fs.js +3 -1
- package/modules/tokenizer.d.ts +12 -0
- package/modules/tokenizer.js +34 -0
- package/package.json +1 -1
- package/src/index.ts +34 -15
- package/src/modules/codeutils.ts +16 -0
- package/src/modules/fs.ts +5 -1
- package/src/modules/tokenizer.ts +32 -0
package/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import WebSocket, { EventEmitter } from 'ws';
|
|
3
|
+
export declare class CustomEventEmitter extends EventEmitter {
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @class Codebolt
|
|
4
7
|
* @description This class provides a unified interface to interact with various modules.
|
|
@@ -9,6 +12,11 @@ declare class Codebolt {
|
|
|
9
12
|
* @description Initializes the websocket connection.
|
|
10
13
|
*/
|
|
11
14
|
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* @method setupMessageListener
|
|
17
|
+
* @description Sets up a listener for incoming WebSocket messages.
|
|
18
|
+
*/
|
|
19
|
+
userMessageListener(): CustomEventEmitter | undefined;
|
|
12
20
|
/**
|
|
13
21
|
* @method waitForConnection
|
|
14
22
|
* @description Waits for the WebSocket connection to open.
|
|
@@ -26,12 +34,16 @@ declare class Codebolt {
|
|
|
26
34
|
start_browser(objective: string, url: string, previous_command: string, browser_content: string): void;
|
|
27
35
|
websocket: WebSocket | null;
|
|
28
36
|
fs: {
|
|
29
|
-
createFile: (fileName: string, source: string, filePath: string) => Promise<any>;
|
|
37
|
+
createFile: (fileName: string, source: string, filePath: string) => Promise<any>; /**
|
|
38
|
+
* @constructor
|
|
39
|
+
* @description Initializes the websocket connection.
|
|
40
|
+
*/
|
|
30
41
|
createFolder: (folderName: string, folderPath: string) => Promise<any>;
|
|
31
42
|
readFile: (filename: string, filePath: string) => Promise<any>;
|
|
32
43
|
updateFile: (filename: string, filePath: string, newContent: string) => Promise<any>;
|
|
33
44
|
deleteFile: (filename: string, filePath: string) => Promise<any>;
|
|
34
45
|
deleteFolder: (foldername: string, folderpath: string) => Promise<any>;
|
|
46
|
+
listFile: (folderPath?: string | undefined) => void;
|
|
35
47
|
};
|
|
36
48
|
git: {
|
|
37
49
|
init: (path: string) => Promise<any>;
|
|
@@ -86,6 +98,7 @@ declare class Codebolt {
|
|
|
86
98
|
};
|
|
87
99
|
codeutils: {
|
|
88
100
|
getCodeTree: (fileName: any, source: any, filePath: any) => Promise<any>;
|
|
101
|
+
getAllFilesAsMarkDown: () => Promise<unknown>;
|
|
89
102
|
};
|
|
90
103
|
docutils: {
|
|
91
104
|
pdf_to_text: (pdf_path: any) => Promise<string>;
|
|
@@ -127,10 +140,6 @@ declare class Codebolt {
|
|
|
127
140
|
};
|
|
128
141
|
dbmemory: {
|
|
129
142
|
addKnowledge: (key: string, value: any) => Promise<any>;
|
|
130
|
-
/**
|
|
131
|
-
* @constructor
|
|
132
|
-
* @description Initializes the websocket connection.
|
|
133
|
-
*/
|
|
134
143
|
getKnowledge: (key: string) => Promise<any>;
|
|
135
144
|
};
|
|
136
145
|
cbstate: {
|
|
@@ -143,16 +152,15 @@ declare class Codebolt {
|
|
|
143
152
|
};
|
|
144
153
|
vectordb: {
|
|
145
154
|
getVector: (key: string) => Promise<any>;
|
|
146
|
-
/**
|
|
147
|
-
* @class Codebolt
|
|
148
|
-
* @description This class provides a unified interface to interact with various modules.
|
|
149
|
-
*/
|
|
150
155
|
addVectorItem: (item: any) => Promise<any>;
|
|
151
156
|
queryVectorItem: (key: string) => Promise<any>;
|
|
152
157
|
};
|
|
153
158
|
debug: {
|
|
154
159
|
debug(log: string, type: import("./modules/debug").logType): Promise<unknown>;
|
|
155
160
|
};
|
|
161
|
+
tokenizer: {
|
|
162
|
+
addToken: (key: string) => Promise<any>;
|
|
163
|
+
};
|
|
156
164
|
}
|
|
157
165
|
declare const _default: Codebolt;
|
|
158
166
|
export default _default;
|
package/index.js
CHANGED
|
@@ -1,8 +1,32 @@
|
|
|
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
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.CustomEventEmitter = void 0;
|
|
6
30
|
const websocket_1 = __importDefault(require("./modules/websocket"));
|
|
7
31
|
const fs_1 = __importDefault(require("./modules/fs"));
|
|
8
32
|
const llm_1 = __importDefault(require("./modules/llm"));
|
|
@@ -24,7 +48,12 @@ const state_1 = __importDefault(require("./modules/state"));
|
|
|
24
48
|
const task_1 = __importDefault(require("./modules/task"));
|
|
25
49
|
const vectordb_1 = __importDefault(require("./modules/vectordb"));
|
|
26
50
|
const debug_1 = __importDefault(require("./modules/debug"));
|
|
27
|
-
const
|
|
51
|
+
const tokenizer_1 = __importDefault(require("./modules/tokenizer"));
|
|
52
|
+
const ws_1 = __importStar(require("ws"));
|
|
53
|
+
class CustomEventEmitter extends ws_1.EventEmitter {
|
|
54
|
+
}
|
|
55
|
+
exports.CustomEventEmitter = CustomEventEmitter;
|
|
56
|
+
let eventEmitter = new CustomEventEmitter();
|
|
28
57
|
/**
|
|
29
58
|
* @class Codebolt
|
|
30
59
|
* @description This class provides a unified interface to interact with various modules.
|
|
@@ -56,8 +85,24 @@ class Codebolt {
|
|
|
56
85
|
this.taskplaner = task_1.default;
|
|
57
86
|
this.vectordb = vectordb_1.default;
|
|
58
87
|
this.debug = debug_1.default;
|
|
88
|
+
this.tokenizer = tokenizer_1.default;
|
|
59
89
|
this.websocket = websocket_1.default.getWebsocket;
|
|
60
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* @method setupMessageListener
|
|
93
|
+
* @description Sets up a listener for incoming WebSocket messages.
|
|
94
|
+
*/
|
|
95
|
+
userMessageListener() {
|
|
96
|
+
if (!this.websocket)
|
|
97
|
+
return;
|
|
98
|
+
this.websocket.on('message', (data) => {
|
|
99
|
+
const response = JSON.parse(data);
|
|
100
|
+
if (response.type === "messageResponse") {
|
|
101
|
+
eventEmitter.emit("userMessage", response.response);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return eventEmitter;
|
|
105
|
+
}
|
|
61
106
|
/**
|
|
62
107
|
* @method waitForConnection
|
|
63
108
|
* @description Waits for the WebSocket connection to open.
|
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/fs.d.ts
CHANGED
package/modules/fs.js
CHANGED
|
@@ -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
package/src/index.ts
CHANGED
|
@@ -19,47 +19,65 @@ 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
|
|
23
|
-
|
|
22
|
+
import tokenizer from './modules/tokenizer'
|
|
23
|
+
import WebSocket, { EventEmitter } from 'ws';
|
|
24
|
+
export class CustomEventEmitter extends EventEmitter {}
|
|
25
|
+
let eventEmitter= new CustomEventEmitter();
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* @class Codebolt
|
|
27
29
|
* @description This class provides a unified interface to interact with various modules.
|
|
28
30
|
*/
|
|
29
|
-
class Codebolt
|
|
31
|
+
class Codebolt { // Extend EventEmitter
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* @constructor
|
|
33
35
|
* @description Initializes the websocket connection.
|
|
34
36
|
*/
|
|
35
|
-
constructor(){
|
|
37
|
+
constructor() {
|
|
38
|
+
|
|
36
39
|
this.websocket = cbws.getWebsocket;
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @method setupMessageListener
|
|
44
|
+
* @description Sets up a listener for incoming WebSocket messages.
|
|
45
|
+
*/
|
|
46
|
+
userMessageListener() {
|
|
47
|
+
if (!this.websocket) return;
|
|
48
|
+
this.websocket.on('message', (data: string) => {
|
|
49
|
+
const response = JSON.parse(data);
|
|
50
|
+
if (response.type === "messageResponse") {
|
|
51
|
+
eventEmitter.emit("userMessage", response.response);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return eventEmitter;
|
|
37
55
|
}
|
|
38
|
-
|
|
39
56
|
/**
|
|
40
57
|
* @method waitForConnection
|
|
41
58
|
* @description Waits for the WebSocket connection to open.
|
|
42
59
|
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
|
|
43
60
|
*/
|
|
44
|
-
|
|
61
|
+
async waitForConnection() {
|
|
45
62
|
return new Promise<void>((resolve, reject) => {
|
|
46
63
|
if (!this.websocket) {
|
|
47
64
|
reject(new Error('WebSocket is not initialized'));
|
|
48
65
|
return;
|
|
49
66
|
}
|
|
50
|
-
|
|
67
|
+
|
|
51
68
|
if (this.websocket.readyState === WebSocket.OPEN) {
|
|
52
69
|
resolve();
|
|
53
70
|
return;
|
|
54
71
|
}
|
|
55
|
-
|
|
72
|
+
|
|
56
73
|
this.websocket.addEventListener('open', () => {
|
|
57
74
|
resolve();
|
|
58
75
|
});
|
|
59
|
-
|
|
76
|
+
|
|
60
77
|
this.websocket.addEventListener('error', (error) => {
|
|
61
78
|
reject(error);
|
|
62
79
|
});
|
|
80
|
+
|
|
63
81
|
});
|
|
64
82
|
}
|
|
65
83
|
|
|
@@ -71,12 +89,12 @@ class Codebolt {
|
|
|
71
89
|
* @param {string} previous_command - The previous command executed.
|
|
72
90
|
* @param {string} browser_content - The content of the browser.
|
|
73
91
|
*/
|
|
74
|
-
start_browser(objective:string, url:string, previous_command:string, browser_content:string) {
|
|
92
|
+
start_browser(objective: string, url: string, previous_command: string, browser_content: string) {
|
|
75
93
|
cbbrowser.newPage();
|
|
76
94
|
}
|
|
77
95
|
websocket: WebSocket | null = null;
|
|
78
96
|
fs = cbfs;
|
|
79
|
-
git=git;
|
|
97
|
+
git = git;
|
|
80
98
|
llm = cbllm;
|
|
81
99
|
browser = cbbrowser;
|
|
82
100
|
chat = cbchat;
|
|
@@ -91,10 +109,11 @@ class Codebolt {
|
|
|
91
109
|
outputparsers = cboutputparsers;
|
|
92
110
|
project = cbproject;
|
|
93
111
|
dbmemory = dbmemory;
|
|
94
|
-
cbstate=cbstate;
|
|
95
|
-
taskplaner=task;
|
|
96
|
-
vectordb=vectorDB;
|
|
97
|
-
debug=debug;
|
|
112
|
+
cbstate = cbstate;
|
|
113
|
+
taskplaner = task;
|
|
114
|
+
vectordb = vectorDB;
|
|
115
|
+
debug = debug;
|
|
116
|
+
tokenizer = tokenizer;
|
|
98
117
|
}
|
|
99
118
|
|
|
100
119
|
export default new Codebolt();
|
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/fs.ts
CHANGED
|
@@ -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
|