@codebolt/codeboltjs 1.1.80 → 1.1.82
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 +5 -9
- package/index.js +2 -0
- package/modules/agent.d.ts +15 -0
- package/modules/agent.js +49 -0
- package/modules/codeutils.js +87 -58
- package/package.json +2 -1
- package/src/index.ts +3 -0
- package/src/modules/agent.ts +53 -0
- package/src/modules/codeutils.ts +66 -67
package/index.d.ts
CHANGED
|
@@ -19,11 +19,7 @@ declare class Codebolt {
|
|
|
19
19
|
waitForConnection(): Promise<void>;
|
|
20
20
|
websocket: WebSocket | null;
|
|
21
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
|
-
*/
|
|
22
|
+
createFile: (fileName: string, source: string, filePath: string) => Promise<import("@codebolt/types").CreateFileResponse>;
|
|
27
23
|
createFolder: (folderName: string, folderPath: string) => Promise<import("@codebolt/types").CreateFolderResponse>;
|
|
28
24
|
readFile: (filePath: string) => Promise<import("@codebolt/types").ReadFileResponse>;
|
|
29
25
|
updateFile: (filename: string, filePath: string, newContent: string) => Promise<import("@codebolt/types").UpdateFileResponse>;
|
|
@@ -193,10 +189,6 @@ declare class Codebolt {
|
|
|
193
189
|
project: {
|
|
194
190
|
getProjectSettings: (output: any) => void;
|
|
195
191
|
getProjectPath: () => Promise<import("@codebolt/types").GetProjectPathResponse>;
|
|
196
|
-
/**
|
|
197
|
-
* @constructor
|
|
198
|
-
* @description Initializes the websocket connection.
|
|
199
|
-
*/
|
|
200
192
|
getRepoMap: (message: any) => Promise<import("@codebolt/types").GetProjectPathResponse>;
|
|
201
193
|
runProject: () => void;
|
|
202
194
|
getEditorFileStatus: () => Promise<unknown>;
|
|
@@ -249,6 +241,10 @@ declare class Codebolt {
|
|
|
249
241
|
getMCPTool: (name: string) => Promise<any>;
|
|
250
242
|
getEnabledMCPS: () => Promise<any>;
|
|
251
243
|
};
|
|
244
|
+
AGENT: {
|
|
245
|
+
getAgent: (task: string) => Promise<any>;
|
|
246
|
+
startAgent: (task: string) => Promise<any>;
|
|
247
|
+
};
|
|
252
248
|
}
|
|
253
249
|
declare const _default: Codebolt;
|
|
254
250
|
export default _default;
|
package/index.js
CHANGED
|
@@ -28,6 +28,7 @@ const tokenizer_1 = __importDefault(require("./modules/tokenizer"));
|
|
|
28
28
|
const ws_1 = __importDefault(require("ws"));
|
|
29
29
|
const history_1 = require("./modules/history");
|
|
30
30
|
const mcp_1 = __importDefault(require("./modules/mcp"));
|
|
31
|
+
const agent_1 = __importDefault(require("./modules/agent"));
|
|
31
32
|
/**
|
|
32
33
|
* @class Codebolt
|
|
33
34
|
* @description This class provides a unified interface to interact with various modules.
|
|
@@ -62,6 +63,7 @@ class Codebolt {
|
|
|
62
63
|
this.tokenizer = tokenizer_1.default;
|
|
63
64
|
this.chatSummary = history_1.chatSummary;
|
|
64
65
|
this.MCP = mcp_1.default;
|
|
66
|
+
this.AGENT = agent_1.default;
|
|
65
67
|
this.websocket = websocket_1.default.getWebsocket;
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const codeboltAgent: {
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves an agent based on the specified task.
|
|
4
|
+
* @param {string} task - The task for which an agent is needed.
|
|
5
|
+
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
|
|
6
|
+
*/
|
|
7
|
+
getAgent: (task: string) => Promise<any>;
|
|
8
|
+
/**
|
|
9
|
+
* Starts an agent for the specified task.
|
|
10
|
+
* @param {string} task - The task for which the agent should be started.
|
|
11
|
+
* @returns {Promise<void>} A promise that resolves when the agent has been successfully started.
|
|
12
|
+
*/
|
|
13
|
+
startAgent: (task: string) => Promise<any>;
|
|
14
|
+
};
|
|
15
|
+
export default codeboltAgent;
|
package/modules/agent.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
const codeboltAgent = {
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves an agent based on the specified task.
|
|
10
|
+
* @param {string} task - The task for which an agent is needed.
|
|
11
|
+
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
|
|
12
|
+
*/
|
|
13
|
+
getAgent: (task) => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
16
|
+
"type": "agentEvent",
|
|
17
|
+
"action": "getAgentByTask",
|
|
18
|
+
"task": task
|
|
19
|
+
}));
|
|
20
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
21
|
+
const response = JSON.parse(data);
|
|
22
|
+
if (response.type === "getAgentByTaskResponse") {
|
|
23
|
+
resolve(response); // Resolve the Promise with the agent details
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Starts an agent for the specified task.
|
|
30
|
+
* @param {string} task - The task for which the agent should be started.
|
|
31
|
+
* @returns {Promise<void>} A promise that resolves when the agent has been successfully started.
|
|
32
|
+
*/
|
|
33
|
+
startAgent: (task) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
36
|
+
"type": "agentEvent",
|
|
37
|
+
"action": "startAgent",
|
|
38
|
+
"task": task
|
|
39
|
+
}));
|
|
40
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
41
|
+
const response = JSON.parse(data);
|
|
42
|
+
if (response.type === "startAgentResponse" && response.task === task) {
|
|
43
|
+
resolve(response); // Resolve the Promise when the agent has been successfully started
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.default = codeboltAgent;
|
package/modules/codeutils.js
CHANGED
|
@@ -1,9 +1,36 @@
|
|
|
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 });
|
|
6
29
|
const websocket_1 = __importDefault(require("./websocket"));
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const tree_sitter_1 = __importDefault(require("tree-sitter"));
|
|
33
|
+
const tree_sitter_javascript_1 = __importDefault(require("tree-sitter-javascript"));
|
|
7
34
|
/**
|
|
8
35
|
* A utility module for working with code.
|
|
9
36
|
*/
|
|
@@ -14,72 +41,74 @@ const cbcodeutils = {
|
|
|
14
41
|
* @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
|
|
15
42
|
*/
|
|
16
43
|
getJsTree: (filePath) => {
|
|
17
|
-
// return new Promise( async (resolve, reject) => {
|
|
18
|
-
// cbws.getWebsocket.send(JSON.stringify({
|
|
19
|
-
// "type": "settingEvent",
|
|
20
|
-
// "action": "getProjectPath"
|
|
21
|
-
// }));
|
|
22
|
-
// cbws.getWebsocket.on('message', (data: string) => {
|
|
23
|
-
// const response = JSON.parse(data);
|
|
24
|
-
// if (response.type === "getProjectPathResponse") {
|
|
25
|
-
// // resolve(response);
|
|
26
|
-
// try {
|
|
27
|
-
// let pathInput= response.projectPath;
|
|
28
|
-
// let parser= new Parser();
|
|
29
|
-
// // Initialize the parser with the JavaScript language
|
|
30
|
-
// parser.setLanguage(JavaScript);
|
|
31
|
-
// const trees = [];
|
|
32
|
-
// const functionNodes = [];
|
|
33
|
-
// const processDirectory = (directory:any) => {
|
|
34
|
-
// console.log("isdir")
|
|
35
|
-
// // Read all files in the directory
|
|
36
|
-
// const files = fs.readdirSync(directory, { withFileTypes: true });
|
|
37
|
-
// files.forEach(file => {
|
|
38
|
-
// if (file.isDirectory()) {
|
|
39
|
-
// if (file.name !== 'node_modules') { // Ignore node_modules directory
|
|
40
|
-
// processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
|
|
41
|
-
// }
|
|
42
|
-
// } else if (path.extname(file.name) === '.js') {
|
|
43
|
-
// const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
|
|
44
|
-
// console.log(code);
|
|
45
|
-
// let tree:any = parser.parse(code);
|
|
46
|
-
// tree.rootNode.path = path.join(directory, file.name); // Set file path for t
|
|
47
|
-
// trees.push(tree);
|
|
48
|
-
// }
|
|
49
|
-
// });
|
|
50
|
-
// };
|
|
51
|
-
// if (fs.lstatSync(pathInput).isDirectory()) {
|
|
52
|
-
// processDirectory(pathInput);
|
|
53
|
-
// } else if (path.extname(pathInput) === '.js') {
|
|
54
|
-
// // Read a single JavaScript file
|
|
55
|
-
// const code = fs.readFileSync(pathInput, 'utf-8');
|
|
56
|
-
// let tree:any = parser.parse(code);
|
|
57
|
-
// tree.rootNode.path = pathInput; // Set file path for t
|
|
58
|
-
// trees.push(tree);
|
|
59
|
-
// }
|
|
60
|
-
// resolve({ event: 'GetJsTreeResponse',payload:trees}); // Return an array of abstract syntax trees (ASTs)
|
|
61
|
-
// } catch (error) {
|
|
62
|
-
// console.error('An error occurred:', error);
|
|
63
|
-
// return { event: 'GetJsTreeResponse',payload:null}; // Return null in case of error
|
|
64
|
-
// }
|
|
65
|
-
// }
|
|
66
|
-
// });
|
|
67
|
-
// });
|
|
68
44
|
return new Promise(async (resolve, reject) => {
|
|
69
45
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
70
|
-
"type": "
|
|
71
|
-
"action": "
|
|
72
|
-
payload: {
|
|
73
|
-
filePath
|
|
74
|
-
}
|
|
46
|
+
"type": "settingEvent",
|
|
47
|
+
"action": "getProjectPath"
|
|
75
48
|
}));
|
|
76
49
|
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
77
50
|
const response = JSON.parse(data);
|
|
78
|
-
if (response.type === "
|
|
79
|
-
resolve(response);
|
|
51
|
+
if (response.type === "getProjectPathResponse") {
|
|
52
|
+
// resolve(response);
|
|
53
|
+
try {
|
|
54
|
+
let pathInput = filePath || response.projectPath;
|
|
55
|
+
let parser = new tree_sitter_1.default();
|
|
56
|
+
// Initialize the parser with the JavaScript language
|
|
57
|
+
parser.setLanguage(tree_sitter_javascript_1.default);
|
|
58
|
+
const trees = [];
|
|
59
|
+
const functionNodes = [];
|
|
60
|
+
const processDirectory = (directory) => {
|
|
61
|
+
// Read all files in the directory
|
|
62
|
+
const files = fs.readdirSync(directory, { withFileTypes: true });
|
|
63
|
+
files.forEach(file => {
|
|
64
|
+
if (file.isDirectory()) {
|
|
65
|
+
if (file.name !== 'node_modules') { // Ignore node_modules directory
|
|
66
|
+
processDirectory(path_1.default.join(directory, file.name)); // Recursive call for subdirectories
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (path_1.default.extname(file.name) === '.js') {
|
|
70
|
+
const code = fs.readFileSync(path_1.default.join(directory, file.name), 'utf-8');
|
|
71
|
+
console.log(code);
|
|
72
|
+
let tree = parser.parse(code);
|
|
73
|
+
tree.rootNode.path = path_1.default.join(directory, file.name); // Set file path for t
|
|
74
|
+
trees.push(tree);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
if (fs.lstatSync(pathInput).isDirectory()) {
|
|
79
|
+
processDirectory(pathInput);
|
|
80
|
+
}
|
|
81
|
+
else if (path_1.default.extname(pathInput) === '.js') {
|
|
82
|
+
// Read a single JavaScript file
|
|
83
|
+
const code = fs.readFileSync(pathInput, 'utf-8');
|
|
84
|
+
let tree = parser.parse(code);
|
|
85
|
+
tree.rootNode.path = pathInput; // Set file path for t
|
|
86
|
+
trees.push(tree);
|
|
87
|
+
}
|
|
88
|
+
resolve({ event: 'GetJsTreeResponse', payload: trees }); // Return an array of abstract syntax trees (ASTs)
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error('An error occurred:', error);
|
|
92
|
+
return { event: 'GetJsTreeResponse', payload: null }; // Return null in case of error
|
|
93
|
+
}
|
|
80
94
|
}
|
|
81
95
|
});
|
|
82
96
|
});
|
|
97
|
+
// return new Promise(async (resolve, reject) => {
|
|
98
|
+
// cbws.getWebsocket.send(JSON.stringify({
|
|
99
|
+
// "type": "codeEvent",
|
|
100
|
+
// "action": "getJsTree",
|
|
101
|
+
// payload: {
|
|
102
|
+
// filePath
|
|
103
|
+
// }
|
|
104
|
+
// }));
|
|
105
|
+
// cbws.getWebsocket.on('message', (data: string) => {
|
|
106
|
+
// const response = JSON.parse(data);
|
|
107
|
+
// if (response.type === "getJsTreeResponse") {
|
|
108
|
+
// resolve(response); // Resolve the Promise with the response data
|
|
109
|
+
// }
|
|
110
|
+
// });
|
|
111
|
+
// });
|
|
83
112
|
},
|
|
84
113
|
/**
|
|
85
114
|
* Retrieves all files as Markdown.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebolt/codeboltjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.82",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"js-yaml": "^4.1.0",
|
|
23
23
|
"tree-sitter": "^0.21.1",
|
|
24
24
|
"tree-sitter-javascript": "^0.23.1",
|
|
25
|
+
"tree-sitter-typescript": "^0.23.2",
|
|
25
26
|
"typedoc-plugin-missing-exports": "^2.2.0",
|
|
26
27
|
"ws": "^8.17.0"
|
|
27
28
|
},
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,8 @@ import WebSocket from 'ws';
|
|
|
24
24
|
import { EventEmitter } from 'events';
|
|
25
25
|
import {chatSummary} from './modules/history'
|
|
26
26
|
import codeboltMCP from './modules/mcp';
|
|
27
|
+
import cbagent from './modules/agent';
|
|
28
|
+
|
|
27
29
|
|
|
28
30
|
|
|
29
31
|
/**
|
|
@@ -93,6 +95,7 @@ class Codebolt { // Extend EventEmitter
|
|
|
93
95
|
tokenizer = tokenizer;
|
|
94
96
|
chatSummary=chatSummary;
|
|
95
97
|
MCP = codeboltMCP;
|
|
98
|
+
AGENT = cbagent;
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
export default new Codebolt();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { GetAgentStateResponse } from '@codebolt/types';
|
|
2
|
+
import cbws from './websocket';
|
|
3
|
+
|
|
4
|
+
const codeboltAgent = {
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves an agent based on the specified task.
|
|
7
|
+
* @param {string} task - The task for which an agent is needed.
|
|
8
|
+
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
|
|
9
|
+
*/
|
|
10
|
+
getAgent: (task: string): Promise<any> => {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
13
|
+
"type": "agentEvent",
|
|
14
|
+
"action": "getAgentByTask",
|
|
15
|
+
"task": task
|
|
16
|
+
}));
|
|
17
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
18
|
+
const response = JSON.parse(data);
|
|
19
|
+
if (response.type === "getAgentByTaskResponse") {
|
|
20
|
+
resolve(response); // Resolve the Promise with the agent details
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Starts an agent for the specified task.
|
|
28
|
+
* @param {string} task - The task for which the agent should be started.
|
|
29
|
+
* @returns {Promise<void>} A promise that resolves when the agent has been successfully started.
|
|
30
|
+
*/
|
|
31
|
+
startAgent: (task: string): Promise<any> => {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
34
|
+
"type": "agentEvent",
|
|
35
|
+
"action": "startAgent",
|
|
36
|
+
"task": task
|
|
37
|
+
}));
|
|
38
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
39
|
+
const response = JSON.parse(data);
|
|
40
|
+
if (response.type === "startAgentResponse" && response.task === task) {
|
|
41
|
+
resolve(response); // Resolve the Promise when the agent has been successfully started
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
export default codeboltAgent;
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
package/src/modules/codeutils.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import cbws from './websocket';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import Parser from 'tree-sitter';
|
|
5
|
+
import JavaScript from 'tree-sitter-javascript';
|
|
6
|
+
import typescript from "tree-sitter-typescript"; // TypeScript and TSX grammar
|
|
6
7
|
|
|
7
8
|
import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
|
|
8
9
|
|
|
@@ -17,79 +18,77 @@ const cbcodeutils = {
|
|
|
17
18
|
* @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
|
|
18
19
|
*/
|
|
19
20
|
getJsTree: (filePath?: string) => {
|
|
20
|
-
// return new Promise( async (resolve, reject) => {
|
|
21
|
-
// cbws.getWebsocket.send(JSON.stringify({
|
|
22
|
-
// "type": "settingEvent",
|
|
23
|
-
// "action": "getProjectPath"
|
|
24
|
-
// }));
|
|
25
|
-
// cbws.getWebsocket.on('message', (data: string) => {
|
|
26
|
-
// const response = JSON.parse(data);
|
|
27
|
-
// if (response.type === "getProjectPathResponse") {
|
|
28
|
-
// // resolve(response);
|
|
29
|
-
// try {
|
|
30
|
-
// let pathInput= response.projectPath;
|
|
31
|
-
// let parser= new Parser();
|
|
32
|
-
// // Initialize the parser with the JavaScript language
|
|
33
|
-
// parser.setLanguage(JavaScript);
|
|
34
|
-
// const trees = [];
|
|
35
|
-
// const functionNodes = [];
|
|
36
|
-
|
|
37
|
-
// const processDirectory = (directory:any) => {
|
|
38
|
-
// console.log("isdir")
|
|
39
|
-
// // Read all files in the directory
|
|
40
|
-
// const files = fs.readdirSync(directory, { withFileTypes: true });
|
|
41
|
-
|
|
42
|
-
// files.forEach(file => {
|
|
43
|
-
// if (file.isDirectory()) {
|
|
44
|
-
// if (file.name !== 'node_modules') { // Ignore node_modules directory
|
|
45
|
-
// processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
|
|
46
|
-
// }
|
|
47
|
-
// } else if (path.extname(file.name) === '.js') {
|
|
48
|
-
// const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
|
|
49
|
-
// console.log(code);
|
|
50
|
-
// let tree:any = parser.parse(code);
|
|
51
|
-
// tree.rootNode.path = path.join(directory, file.name); // Set file path for t
|
|
52
|
-
// trees.push(tree);
|
|
53
|
-
// }
|
|
54
|
-
// });
|
|
55
|
-
// };
|
|
56
|
-
|
|
57
|
-
// if (fs.lstatSync(pathInput).isDirectory()) {
|
|
58
|
-
// processDirectory(pathInput);
|
|
59
|
-
// } else if (path.extname(pathInput) === '.js') {
|
|
60
|
-
// // Read a single JavaScript file
|
|
61
|
-
// const code = fs.readFileSync(pathInput, 'utf-8');
|
|
62
|
-
// let tree:any = parser.parse(code);
|
|
63
|
-
// tree.rootNode.path = pathInput; // Set file path for t
|
|
64
|
-
|
|
65
|
-
// trees.push(tree);
|
|
66
|
-
// }
|
|
67
|
-
|
|
68
|
-
// resolve({ event: 'GetJsTreeResponse',payload:trees}); // Return an array of abstract syntax trees (ASTs)
|
|
69
|
-
// } catch (error) {
|
|
70
|
-
// console.error('An error occurred:', error);
|
|
71
|
-
// return { event: 'GetJsTreeResponse',payload:null}; // Return null in case of error
|
|
72
|
-
// }
|
|
73
|
-
// }
|
|
74
|
-
// });
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// });
|
|
78
21
|
return new Promise(async (resolve, reject) => {
|
|
79
22
|
cbws.getWebsocket.send(JSON.stringify({
|
|
80
|
-
"type": "
|
|
81
|
-
"action": "
|
|
82
|
-
payload: {
|
|
83
|
-
filePath
|
|
84
|
-
}
|
|
23
|
+
"type": "settingEvent",
|
|
24
|
+
"action": "getProjectPath"
|
|
85
25
|
}));
|
|
86
26
|
cbws.getWebsocket.on('message', (data: string) => {
|
|
87
27
|
const response = JSON.parse(data);
|
|
88
|
-
if (response.type === "
|
|
89
|
-
resolve(response);
|
|
28
|
+
if (response.type === "getProjectPathResponse") {
|
|
29
|
+
// resolve(response);
|
|
30
|
+
try {
|
|
31
|
+
let pathInput = filePath || response.projectPath;
|
|
32
|
+
let parser = new Parser();
|
|
33
|
+
// Initialize the parser with the JavaScript language
|
|
34
|
+
parser.setLanguage(JavaScript);
|
|
35
|
+
const trees = [];
|
|
36
|
+
const functionNodes = [];
|
|
37
|
+
const processDirectory = (directory: any) => {
|
|
38
|
+
// Read all files in the directory
|
|
39
|
+
const files = fs.readdirSync(directory, { withFileTypes: true });
|
|
40
|
+
|
|
41
|
+
files.forEach(file => {
|
|
42
|
+
if (file.isDirectory()) {
|
|
43
|
+
if (file.name !== 'node_modules') { // Ignore node_modules directory
|
|
44
|
+
processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
|
|
45
|
+
}
|
|
46
|
+
} else if (path.extname(file.name) === '.js') {
|
|
47
|
+
const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
|
|
48
|
+
console.log(code);
|
|
49
|
+
let tree: any = parser.parse(code);
|
|
50
|
+
tree.rootNode.path = path.join(directory, file.name); // Set file path for t
|
|
51
|
+
trees.push(tree);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (fs.lstatSync(pathInput).isDirectory()) {
|
|
57
|
+
processDirectory(pathInput);
|
|
58
|
+
} else if (path.extname(pathInput) === '.js') {
|
|
59
|
+
// Read a single JavaScript file
|
|
60
|
+
const code = fs.readFileSync(pathInput, 'utf-8');
|
|
61
|
+
let tree: any = parser.parse(code);
|
|
62
|
+
tree.rootNode.path = pathInput; // Set file path for t
|
|
63
|
+
|
|
64
|
+
trees.push(tree);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
resolve({ event: 'GetJsTreeResponse', payload: trees }); // Return an array of abstract syntax trees (ASTs)
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('An error occurred:', error);
|
|
70
|
+
return { event: 'GetJsTreeResponse', payload: null }; // Return null in case of error
|
|
71
|
+
}
|
|
90
72
|
}
|
|
91
73
|
});
|
|
74
|
+
|
|
75
|
+
|
|
92
76
|
});
|
|
77
|
+
// return new Promise(async (resolve, reject) => {
|
|
78
|
+
// cbws.getWebsocket.send(JSON.stringify({
|
|
79
|
+
// "type": "codeEvent",
|
|
80
|
+
// "action": "getJsTree",
|
|
81
|
+
// payload: {
|
|
82
|
+
// filePath
|
|
83
|
+
// }
|
|
84
|
+
// }));
|
|
85
|
+
// cbws.getWebsocket.on('message', (data: string) => {
|
|
86
|
+
// const response = JSON.parse(data);
|
|
87
|
+
// if (response.type === "getJsTreeResponse") {
|
|
88
|
+
// resolve(response); // Resolve the Promise with the response data
|
|
89
|
+
// }
|
|
90
|
+
// });
|
|
91
|
+
// });
|
|
93
92
|
},
|
|
94
93
|
|
|
95
94
|
/**
|