-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (61 loc) · 2.4 KB
/
Copy pathindex.js
File metadata and controls
70 lines (61 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const codebolt = require("@codebolt/codeboltjs").default;
const {CodeRunner} = require("./agents/runner/runner");
const {Bugfix} = require("./agents/bugfix/bugfix");
const path = require("path")
codebolt.chat.onActionMessage().on("userMessage", async (req, response) => {
await codebolt.waitForConnection();
// codebolt.chat.stopProcess();
// var message = await codebolt.chat.waitforReply(" ");
// del
codebolt.chat.processStarted();
const {markdown} = await codebolt.codeutils.getAllFilesAsMarkDown();
const extractdata = await CodeRunner(markdown);
const commands= JSON.parse(extractdata).commands.join(' && ');
const port = JSON.parse(extractdata).port
const {projectPath} = await codebolt.project.getProjectPath();
// let executeApp = await codebolt.terminal.executeCommandRunUntilError(commands);
console.log("commands---",commands)
let executeApp = await executeWithTimeout(commands, 60000,port);
console.log("executeApp----", executeApp);
codebolt.chat.stopProcess();
message = await codebolt.chat.waitforReply("This is error " + executeApp.response);
codebolt.chat.processStarted();
var BugResponse;
BugResponse = await Bugfix(markdown, executeApp ?. response, projectPath);
console.log("BugResponse-----", BugResponse)
if(BugResponse?.message){
BugResponse = await Bugfix(markdown, BugResponse?.message, projectPath);
}
else {
codebolt.fs.updateFile('', path.basename(BugResponse.filePath), BugResponse.fixedCode, 'utf-8');
codebolt.chat.sendMessage("I Have Fix this error of this file " + path.basename(BugResponse.filePath));
codebolt.chat.stopProcess();
}
if(executeApp?.response){
await execute();
// await codebolt.terminal.executeCommand(`npx kill-port ${port}`);
}
})
function executeWithTimeout(command, timeout, port) {
return new Promise( (resolve, reject) => {
let timer = setTimeout(() => {
clearTimeout(timer);
codebolt.terminal.executeCommand(`npx kill-port ${port}`);
codebolt.chat.waitforReply("There are no Error! ");
codebolt.chat.stopProcess();
reject('There are no error ');
}, timeout);
codebolt.terminal.executeCommandRunUntilError(command)
.then(result => {
clearTimeout(timer);
resolve(result);
})
.catch(error => {
clearTimeout(timer);
reject(error);
});
});
}
// (async () => {
// await execute();
// })();