@codebolt/codeboltjs 2.0.1 → 2.0.3
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 +3 -0
- package/index.js +2 -0
- package/modules/agentlib/agent.js +59 -50
- package/modules/codeutils.js +37 -67
- package/package.json +1 -5
- package/src/index.ts +2 -1
- package/src/modules/agentlib/agent.ts +65 -54
- package/src/modules/codeutils.ts +40 -40
- package/src/modules/toolBox.ts +1 -1
- package/src/utils/editFile.ts +30 -0
- package/utils/editFile.d.ts +4 -0
- package/utils/editFile.js +30 -0
package/index.d.ts
CHANGED
|
@@ -257,6 +257,9 @@ declare class Codebolt {
|
|
|
257
257
|
getAgentsList: (type?: import("./modules/agent").Agents) => Promise<any>;
|
|
258
258
|
getAgentsDetail: (agentList?: never[]) => Promise<any>;
|
|
259
259
|
};
|
|
260
|
+
utils: {
|
|
261
|
+
editFileAndApplyDiff: (filePath: string, diff: string, diffIdentifier: string, prompt: string, applyModel?: string | undefined) => Promise<any>;
|
|
262
|
+
};
|
|
260
263
|
}
|
|
261
264
|
declare const _default: Codebolt;
|
|
262
265
|
export default _default;
|
package/index.js
CHANGED
|
@@ -29,6 +29,7 @@ const ws_1 = __importDefault(require("ws"));
|
|
|
29
29
|
const history_1 = require("./modules/history");
|
|
30
30
|
const tools_1 = __importDefault(require("./modules/tools"));
|
|
31
31
|
const agent_1 = __importDefault(require("./modules/agent"));
|
|
32
|
+
const editFile_1 = __importDefault(require("./utils/editFile"));
|
|
32
33
|
/**
|
|
33
34
|
* @class Codebolt
|
|
34
35
|
* @description This class provides a unified interface to interact with various modules.
|
|
@@ -64,6 +65,7 @@ class Codebolt {
|
|
|
64
65
|
this.chatSummary = history_1.chatSummary;
|
|
65
66
|
this.tools = tools_1.default;
|
|
66
67
|
this.agent = agent_1.default;
|
|
68
|
+
this.utils = editFile_1.default;
|
|
67
69
|
websocket_1.default.initializeWebSocket();
|
|
68
70
|
this.websocket = websocket_1.default.getWebsocket;
|
|
69
71
|
}
|
|
@@ -94,66 +94,75 @@ class Agent {
|
|
|
94
94
|
const contentBlock = response.choices[0];
|
|
95
95
|
if ((_a = contentBlock.message) === null || _a === void 0 ? void 0 : _a.tool_calls) {
|
|
96
96
|
for (const tool of contentBlock.message.tool_calls) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
else {
|
|
103
|
-
let [serverName] = toolName.replace('--', ':').split(':');
|
|
104
|
-
if (serverName == 'subagent') {
|
|
105
|
-
const agentResponse = await agent_1.default.startAgent(toolName.replace("subagent--", ''), toolInput.task);
|
|
106
|
-
const [didUserReject, result] = [false, "tool result is successful"];
|
|
107
|
-
let toolResult = this.getToolResult(toolUseId, result);
|
|
108
|
-
toolResults.push({
|
|
109
|
-
role: "tool",
|
|
110
|
-
tool_call_id: toolResult.tool_call_id,
|
|
111
|
-
content: toolResult.content,
|
|
112
|
-
});
|
|
113
|
-
if (toolResult.userMessage) {
|
|
114
|
-
this.nextUserMessage = {
|
|
115
|
-
role: "user",
|
|
116
|
-
content: toolResult.userMessage
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
if (didUserReject) {
|
|
120
|
-
userRejectedToolUse = true;
|
|
121
|
-
}
|
|
97
|
+
try {
|
|
98
|
+
const { toolInput, toolName, toolUseId } = this.getToolDetail(tool);
|
|
99
|
+
if (!userRejectedToolUse) {
|
|
100
|
+
if (toolName.includes("attempt_completion")) {
|
|
101
|
+
taskCompletedBlock = tool;
|
|
122
102
|
}
|
|
123
103
|
else {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
104
|
+
let [serverName] = toolName.replace('--', ':').split(':');
|
|
105
|
+
if (serverName == 'subagent') {
|
|
106
|
+
const agentResponse = await agent_1.default.startAgent(toolName.replace("subagent--", ''), toolInput.task);
|
|
107
|
+
const [didUserReject, result] = [false, "tool result is successful"];
|
|
108
|
+
let toolResult = this.getToolResult(toolUseId, result);
|
|
109
|
+
toolResults.push({
|
|
110
|
+
role: "tool",
|
|
111
|
+
tool_call_id: toolResult.tool_call_id,
|
|
112
|
+
content: toolResult.content,
|
|
113
|
+
});
|
|
114
|
+
if (toolResult.userMessage) {
|
|
115
|
+
this.nextUserMessage = {
|
|
116
|
+
role: "user",
|
|
117
|
+
content: toolResult.userMessage
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (didUserReject) {
|
|
121
|
+
userRejectedToolUse = true;
|
|
122
|
+
}
|
|
137
123
|
}
|
|
138
|
-
|
|
139
|
-
|
|
124
|
+
else {
|
|
125
|
+
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
|
|
126
|
+
// toolResults.push(this.getToolResult(toolUseId, result));
|
|
127
|
+
let toolResult = this.getToolResult(toolUseId, result);
|
|
128
|
+
toolResults.push({
|
|
129
|
+
role: "tool",
|
|
130
|
+
tool_call_id: toolResult.tool_call_id,
|
|
131
|
+
content: toolResult.content,
|
|
132
|
+
});
|
|
133
|
+
if (toolResult.userMessage) {
|
|
134
|
+
this.nextUserMessage = {
|
|
135
|
+
role: "user",
|
|
136
|
+
content: toolResult.userMessage
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (didUserReject) {
|
|
140
|
+
userRejectedToolUse = true;
|
|
141
|
+
}
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
}
|
|
145
|
+
else {
|
|
146
|
+
let toolResult = this.getToolResult(toolUseId, "Skipping tool execution due to previous tool user rejection.");
|
|
147
|
+
toolResults.push({
|
|
148
|
+
role: "tool",
|
|
149
|
+
tool_call_id: toolResult.tool_call_id,
|
|
150
|
+
content: toolResult.content,
|
|
151
|
+
});
|
|
152
|
+
if (toolResult.userMessage) {
|
|
153
|
+
this.nextUserMessage = {
|
|
154
|
+
role: "user",
|
|
155
|
+
content: toolResult.userMessage
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
143
159
|
}
|
|
144
|
-
|
|
145
|
-
let toolResult = this.getToolResult(toolUseId, "Skipping tool execution due to previous tool user rejection.");
|
|
160
|
+
catch (error) {
|
|
146
161
|
toolResults.push({
|
|
147
162
|
role: "tool",
|
|
148
|
-
tool_call_id:
|
|
149
|
-
content:
|
|
163
|
+
tool_call_id: tool.id,
|
|
164
|
+
content: String(error),
|
|
150
165
|
});
|
|
151
|
-
if (toolResult.userMessage) {
|
|
152
|
-
this.nextUserMessage = {
|
|
153
|
-
role: "user",
|
|
154
|
-
content: toolResult.userMessage
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
166
|
}
|
|
158
167
|
}
|
|
159
168
|
}
|
package/modules/codeutils.js
CHANGED
|
@@ -1,36 +1,9 @@
|
|
|
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
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
6
|
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"));
|
|
34
7
|
/**
|
|
35
8
|
* A utility module for working with code.
|
|
36
9
|
*/
|
|
@@ -50,46 +23,43 @@ const cbcodeutils = {
|
|
|
50
23
|
const response = JSON.parse(data);
|
|
51
24
|
if (response.type === "getProjectPathResponse") {
|
|
52
25
|
// resolve(response);
|
|
53
|
-
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
console.error('An error occurred:', error);
|
|
91
|
-
return { event: 'GetJsTreeResponse', payload: null }; // Return null in case of error
|
|
92
|
-
}
|
|
26
|
+
// try {
|
|
27
|
+
// let pathInput = filePath || 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
|
+
// // Read all files in the directory
|
|
35
|
+
// const files = fs.readdirSync(directory, { withFileTypes: true });
|
|
36
|
+
// files.forEach(file => {
|
|
37
|
+
// if (file.isDirectory()) {
|
|
38
|
+
// if (file.name !== 'node_modules') { // Ignore node_modules directory
|
|
39
|
+
// processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
|
|
40
|
+
// }
|
|
41
|
+
// } else if (path.extname(file.name) === '.js') {
|
|
42
|
+
// const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
|
|
43
|
+
// let tree: any = parser.parse(code);
|
|
44
|
+
// tree.rootNode.path = path.join(directory, file.name); // Set file path for t
|
|
45
|
+
// trees.push(tree);
|
|
46
|
+
// }
|
|
47
|
+
// });
|
|
48
|
+
// };
|
|
49
|
+
// if (fs.lstatSync(pathInput).isDirectory()) {
|
|
50
|
+
// processDirectory(pathInput);
|
|
51
|
+
// } else if (path.extname(pathInput) === '.js') {
|
|
52
|
+
// // Read a single JavaScript file
|
|
53
|
+
// const code = fs.readFileSync(pathInput, 'utf-8');
|
|
54
|
+
// let tree: any = parser.parse(code);
|
|
55
|
+
// tree.rootNode.path = pathInput; // Set file path for t
|
|
56
|
+
// trees.push(tree);
|
|
57
|
+
// }
|
|
58
|
+
// resolve({ event: 'GetJsTreeResponse', payload: trees }); // Return an array of abstract syntax trees (ASTs)
|
|
59
|
+
// } catch (error) {
|
|
60
|
+
// console.error('An error occurred:', error);
|
|
61
|
+
// return { event: 'GetJsTreeResponse', payload: null }; // Return null in case of error
|
|
62
|
+
// }
|
|
93
63
|
}
|
|
94
64
|
});
|
|
95
65
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebolt/codeboltjs",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -29,10 +29,6 @@
|
|
|
29
29
|
"mcp-proxy": "^2.4.0",
|
|
30
30
|
"strict-event-emitter-types": "^2.0.0",
|
|
31
31
|
"timers": "^0.1.1",
|
|
32
|
-
"tree-sitter": "^0.21.1",
|
|
33
|
-
"tree-sitter-javascript": "^0.23.1",
|
|
34
|
-
"tree-sitter-typescript": "^0.23.2",
|
|
35
|
-
"typedoc-plugin-missing-exports": "^2.2.0",
|
|
36
32
|
"undici": "^7.4.0",
|
|
37
33
|
"uri-templates": "^0.2.0",
|
|
38
34
|
"ws": "^8.17.0",
|
package/src/index.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { EventEmitter } from 'events';
|
|
|
25
25
|
import {chatSummary} from './modules/history'
|
|
26
26
|
import codeboltTools from './modules/tools';
|
|
27
27
|
import cbagent from './modules/agent';
|
|
28
|
-
|
|
28
|
+
import cbutils from './utils/editFile';
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
|
|
@@ -98,6 +98,7 @@ class Codebolt { // Extend EventEmitter
|
|
|
98
98
|
chatSummary=chatSummary;
|
|
99
99
|
tools = codeboltTools;
|
|
100
100
|
agent = cbagent;
|
|
101
|
+
utils = cbutils;
|
|
101
102
|
|
|
102
103
|
}
|
|
103
104
|
|
|
@@ -61,7 +61,7 @@ class Agent {
|
|
|
61
61
|
/** Messages from the user */
|
|
62
62
|
private userMessage: Message[];
|
|
63
63
|
/** The next user message to be added to the conversation */
|
|
64
|
-
private nextUserMessage:any;
|
|
64
|
+
private nextUserMessage: any;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Creates a new Agent instance.
|
|
@@ -94,7 +94,7 @@ class Agent {
|
|
|
94
94
|
this.tools = [
|
|
95
95
|
...this.tools,
|
|
96
96
|
...mentaionedMCPSTool,
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
]
|
|
99
99
|
let mentionedAgents = await task.userMessage.getMentionedAgents();
|
|
100
100
|
|
|
@@ -118,7 +118,7 @@ class Agent {
|
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
120
|
});
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
this.tools = this.tools.concat(agentTools);
|
|
123
123
|
|
|
124
124
|
|
|
@@ -158,75 +158,86 @@ class Agent {
|
|
|
158
158
|
|
|
159
159
|
if (contentBlock.message?.tool_calls) {
|
|
160
160
|
for (const tool of contentBlock.message.tool_calls) {
|
|
161
|
-
|
|
161
|
+
try {
|
|
162
|
+
const { toolInput, toolName, toolUseId } = this.getToolDetail(tool);
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
if (!userRejectedToolUse) {
|
|
165
|
+
if (toolName.includes("attempt_completion")) {
|
|
166
|
+
taskCompletedBlock = tool;
|
|
167
|
+
} else {
|
|
167
168
|
|
|
168
|
-
|
|
169
|
+
let [serverName] = toolName.replace('--', ':').split(':');
|
|
169
170
|
|
|
170
171
|
|
|
171
|
-
|
|
172
|
+
if (serverName == 'subagent') {
|
|
172
173
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
174
|
+
const agentResponse = await codeboltAgent.startAgent(toolName.replace("subagent--", ''), toolInput.task);
|
|
175
|
+
const [didUserReject, result] = [false, "tool result is successful"];
|
|
176
|
+
let toolResult = this.getToolResult(toolUseId, result)
|
|
177
|
+
toolResults.push({
|
|
178
|
+
role: "tool",
|
|
179
|
+
tool_call_id: toolResult.tool_call_id,
|
|
180
|
+
content: toolResult.content,
|
|
180
181
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
});
|
|
183
|
+
if (toolResult.userMessage) {
|
|
184
|
+
this.nextUserMessage = {
|
|
185
|
+
role: "user",
|
|
186
|
+
content: toolResult.userMessage
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (didUserReject) {
|
|
190
|
+
userRejectedToolUse = true;
|
|
186
191
|
}
|
|
192
|
+
|
|
187
193
|
}
|
|
188
|
-
|
|
189
|
-
|
|
194
|
+
else {
|
|
195
|
+
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
|
|
196
|
+
// toolResults.push(this.getToolResult(toolUseId, result));
|
|
197
|
+
let toolResult = this.getToolResult(toolUseId, result)
|
|
198
|
+
toolResults.push({
|
|
199
|
+
role: "tool",
|
|
200
|
+
tool_call_id: toolResult.tool_call_id,
|
|
201
|
+
content: toolResult.content,
|
|
202
|
+
|
|
203
|
+
});
|
|
204
|
+
if (toolResult.userMessage) {
|
|
205
|
+
this.nextUserMessage = {
|
|
206
|
+
role: "user",
|
|
207
|
+
content: toolResult.userMessage
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (didUserReject) {
|
|
211
|
+
userRejectedToolUse = true;
|
|
212
|
+
}
|
|
190
213
|
}
|
|
191
214
|
|
|
192
215
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
content: toolResult.userMessage
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (didUserReject) {
|
|
210
|
-
userRejectedToolUse = true;
|
|
216
|
+
} else {
|
|
217
|
+
let toolResult = this.getToolResult(toolUseId, "Skipping tool execution due to previous tool user rejection.")
|
|
218
|
+
|
|
219
|
+
toolResults.push({
|
|
220
|
+
role: "tool",
|
|
221
|
+
tool_call_id: toolResult.tool_call_id,
|
|
222
|
+
content: toolResult.content,
|
|
223
|
+
|
|
224
|
+
});
|
|
225
|
+
if (toolResult.userMessage) {
|
|
226
|
+
this.nextUserMessage = {
|
|
227
|
+
role: "user",
|
|
228
|
+
content: toolResult.userMessage
|
|
211
229
|
}
|
|
212
230
|
}
|
|
213
231
|
|
|
214
232
|
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
233
|
+
} catch (error) {
|
|
234
|
+
|
|
218
235
|
toolResults.push({
|
|
219
236
|
role: "tool",
|
|
220
|
-
tool_call_id:
|
|
221
|
-
content:
|
|
237
|
+
tool_call_id: tool.id,
|
|
238
|
+
content: String(error),
|
|
222
239
|
|
|
223
240
|
});
|
|
224
|
-
if (toolResult.userMessage) {
|
|
225
|
-
this.nextUserMessage = {
|
|
226
|
-
role: "user",
|
|
227
|
-
content: toolResult.userMessage
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
241
|
|
|
231
242
|
}
|
|
232
243
|
}
|
|
@@ -373,7 +384,7 @@ class Agent {
|
|
|
373
384
|
* @returns ToolResult object
|
|
374
385
|
*/
|
|
375
386
|
private getToolResult(tool_call_id: string, content: string): ToolResult {
|
|
376
|
-
let userMessage=undefined
|
|
387
|
+
let userMessage = undefined
|
|
377
388
|
try {
|
|
378
389
|
let parsed = JSON.parse(content);
|
|
379
390
|
|
package/src/modules/codeutils.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import cbws from './websocket';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import Parser from 'tree-sitter';
|
|
5
|
-
import JavaScript from 'tree-sitter-javascript';
|
|
6
|
-
import typescript from "tree-sitter-typescript"; // TypeScript and TSX grammar
|
|
4
|
+
// import Parser from 'tree-sitter';
|
|
5
|
+
// import JavaScript from 'tree-sitter-javascript';
|
|
6
|
+
// import typescript from "tree-sitter-typescript"; // TypeScript and TSX grammar
|
|
7
7
|
|
|
8
8
|
import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
|
|
9
9
|
|
|
@@ -27,47 +27,47 @@ const cbcodeutils = {
|
|
|
27
27
|
const response = JSON.parse(data);
|
|
28
28
|
if (response.type === "getProjectPathResponse") {
|
|
29
29
|
// resolve(response);
|
|
30
|
-
try {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
+
// let tree: any = parser.parse(code);
|
|
49
|
+
// tree.rootNode.path = path.join(directory, file.name); // Set file path for t
|
|
50
|
+
// trees.push(tree);
|
|
51
|
+
// }
|
|
52
|
+
// });
|
|
53
|
+
// };
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
// if (fs.lstatSync(pathInput).isDirectory()) {
|
|
56
|
+
// processDirectory(pathInput);
|
|
57
|
+
// } else if (path.extname(pathInput) === '.js') {
|
|
58
|
+
// // Read a single JavaScript file
|
|
59
|
+
// const code = fs.readFileSync(pathInput, 'utf-8');
|
|
60
|
+
// let tree: any = parser.parse(code);
|
|
61
|
+
// tree.rootNode.path = pathInput; // Set file path for t
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
// trees.push(tree);
|
|
64
|
+
// }
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
} catch (error) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
66
|
+
// resolve({ event: 'GetJsTreeResponse', payload: trees }); // Return an array of abstract syntax trees (ASTs)
|
|
67
|
+
// } catch (error) {
|
|
68
|
+
// console.error('An error occurred:', error);
|
|
69
|
+
// return { event: 'GetJsTreeResponse', payload: null }; // Return null in case of error
|
|
70
|
+
// }
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
73
|
|
package/src/modules/toolBox.ts
CHANGED
|
@@ -728,7 +728,7 @@ export class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth> e
|
|
|
728
728
|
public async requestSampling(
|
|
729
729
|
message: z.infer<typeof CreateMessageRequestSchema>["params"],
|
|
730
730
|
): Promise<SamplingResponse> {
|
|
731
|
-
return this.#server.createMessage(message);
|
|
731
|
+
return this.#server.createMessage(message) as unknown as SamplingResponse;
|
|
732
732
|
}
|
|
733
733
|
|
|
734
734
|
public async connect(transport: Transport) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import cbws from '../modules/websocket';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const cbutils = {
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
editFileAndApplyDiff:(filePath: string, diff: string,diffIdentifier:string,prompt:string,applyModel?:string): Promise<any> => {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
10
|
+
"type": "fsEvent",
|
|
11
|
+
"action": "editFileAndApplyDiff",
|
|
12
|
+
message:{
|
|
13
|
+
filePath,
|
|
14
|
+
diff,
|
|
15
|
+
diffIdentifier,
|
|
16
|
+
prompt,
|
|
17
|
+
applyModel
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
21
|
+
const response = JSON.parse(data);
|
|
22
|
+
if (response.type === "editFileAndApplyDiffResponse") {
|
|
23
|
+
resolve(response);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default cbutils;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 cbutils = {
|
|
8
|
+
editFileAndApplyDiff: (filePath, diff, diffIdentifier, prompt, applyModel) => {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
11
|
+
"type": "fsEvent",
|
|
12
|
+
"action": "editFileAndApplyDiff",
|
|
13
|
+
message: {
|
|
14
|
+
filePath,
|
|
15
|
+
diff,
|
|
16
|
+
diffIdentifier,
|
|
17
|
+
prompt,
|
|
18
|
+
applyModel
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
22
|
+
const response = JSON.parse(data);
|
|
23
|
+
if (response.type === "editFileAndApplyDiffResponse") {
|
|
24
|
+
resolve(response);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.default = cbutils;
|