@codebolt/codeboltjs 1.1.91 → 1.1.94
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 +15 -8
- package/index.js +3 -3
- package/modules/agentlib/agent.d.ts +1 -0
- package/modules/agentlib/agent.js +68 -6
- package/modules/agentlib/usermessage.d.ts +1 -1
- package/modules/agentlib/usermessage.js +4 -4
- package/modules/chat.js +2 -1
- package/modules/mcp.d.ts +1 -0
- package/modules/mcp.js +24 -0
- package/modules/toolBox.bkp.d.ts +262 -0
- package/modules/toolBox.bkp.js +721 -0
- package/modules/toolBox.d.ts +36 -17
- package/modules/toolBox.js +62 -21
- package/modules/tools.d.ts +16 -0
- package/modules/tools.js +197 -0
- package/package.json +3 -2
- package/src/index.ts +3 -3
- package/src/modules/agentlib/agent.ts +83 -11
- package/src/modules/agentlib/usermessage.ts +5 -5
- package/src/modules/chat.ts +2 -1
- package/src/modules/toolBox.bkp.ts +1165 -0
- package/src/modules/toolBox.ts +108 -66
- package/src/modules/tools.ts +187 -0
- package/src/modules/mcp.ts +0 -117
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chatlib from "./../chat"
|
|
2
|
-
import
|
|
2
|
+
import tools from "./../tools"
|
|
3
3
|
import llm from "./../llm"
|
|
4
4
|
import codeboltAgent from "./../agent"
|
|
5
5
|
import { SystemPrompt } from "./systemprompt";
|
|
@@ -16,6 +16,7 @@ interface ToolResult {
|
|
|
16
16
|
role: 'tool';
|
|
17
17
|
tool_call_id: string;
|
|
18
18
|
content: any;
|
|
19
|
+
userMessage?: any;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
interface ToolDetails {
|
|
@@ -31,6 +32,7 @@ class Agent {
|
|
|
31
32
|
private maxRun: number;
|
|
32
33
|
private systemPrompt: SystemPrompt;
|
|
33
34
|
private userMessage: Message[];
|
|
35
|
+
private nextUserMessage:any;
|
|
34
36
|
|
|
35
37
|
|
|
36
38
|
constructor(tools: any = [], systemPrompt: SystemPrompt, maxRun: number = 0, subAgents: any[] = []) {
|
|
@@ -47,6 +49,7 @@ class Agent {
|
|
|
47
49
|
this.tools = this.tools.concat(subAgents.map(subagent => ({
|
|
48
50
|
...subagent
|
|
49
51
|
})));
|
|
52
|
+
|
|
50
53
|
|
|
51
54
|
|
|
52
55
|
}
|
|
@@ -112,20 +115,44 @@ class Agent {
|
|
|
112
115
|
|
|
113
116
|
const agentResponse = await codeboltAgent.startAgent(toolName.replace("subagent--", ''), toolInput.task);
|
|
114
117
|
console.log("got sub agent resonse result", agentResponse);
|
|
115
|
-
const [didUserReject, result] = [false,"tool result is successful"];
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
toolResults.push(
|
|
118
|
+
const [didUserReject, result] = [false, "tool result is successful"];
|
|
119
|
+
console.log("got sub agent resonse result", didUserReject, result);
|
|
120
|
+
let toolResult = this.getToolResult(toolUseId, result)
|
|
121
|
+
toolResults.push({
|
|
122
|
+
role: "tool",
|
|
123
|
+
tool_call_id: toolResult.tool_call_id,
|
|
124
|
+
content: toolResult.content,
|
|
125
|
+
|
|
126
|
+
});
|
|
127
|
+
if (toolResult.userMessage) {
|
|
128
|
+
this.nextUserMessage = {
|
|
129
|
+
role: "user",
|
|
130
|
+
content: toolResult.userMessage
|
|
131
|
+
}
|
|
132
|
+
}
|
|
119
133
|
if (didUserReject) {
|
|
120
134
|
userRejectedToolUse = true;
|
|
121
135
|
}
|
|
136
|
+
|
|
122
137
|
}
|
|
123
138
|
else {
|
|
124
139
|
console.log("calling tool with params", toolName, toolInput);
|
|
125
140
|
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
|
|
126
141
|
console.log("tool result", result);
|
|
127
|
-
toolResults.push(this.getToolResult(toolUseId, result));
|
|
128
|
-
|
|
142
|
+
// toolResults.push(this.getToolResult(toolUseId, result));
|
|
143
|
+
let toolResult = this.getToolResult(toolUseId, result)
|
|
144
|
+
toolResults.push({
|
|
145
|
+
role: "tool",
|
|
146
|
+
tool_call_id: toolResult.tool_call_id,
|
|
147
|
+
content: toolResult.content,
|
|
148
|
+
|
|
149
|
+
});
|
|
150
|
+
if (toolResult.userMessage) {
|
|
151
|
+
this.nextUserMessage = {
|
|
152
|
+
role: "user",
|
|
153
|
+
content: toolResult.userMessage
|
|
154
|
+
}
|
|
155
|
+
}
|
|
129
156
|
if (didUserReject) {
|
|
130
157
|
userRejectedToolUse = true;
|
|
131
158
|
}
|
|
@@ -133,7 +160,21 @@ class Agent {
|
|
|
133
160
|
|
|
134
161
|
}
|
|
135
162
|
} else {
|
|
136
|
-
|
|
163
|
+
let toolResult = this.getToolResult(toolUseId, "Skipping tool execution due to previous tool user rejection.")
|
|
164
|
+
|
|
165
|
+
toolResults.push({
|
|
166
|
+
role: "tool",
|
|
167
|
+
tool_call_id: toolResult.tool_call_id,
|
|
168
|
+
content: toolResult.content,
|
|
169
|
+
|
|
170
|
+
});
|
|
171
|
+
if (toolResult.userMessage) {
|
|
172
|
+
this.nextUserMessage = {
|
|
173
|
+
role: "user",
|
|
174
|
+
content: toolResult.userMessage
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
137
178
|
}
|
|
138
179
|
}
|
|
139
180
|
}
|
|
@@ -148,10 +189,26 @@ class Agent {
|
|
|
148
189
|
completed = true;
|
|
149
190
|
result = "The user is satisfied with the result.";
|
|
150
191
|
}
|
|
151
|
-
|
|
192
|
+
let toolResult = this.getToolResult(taskCompletedBlock.id, result)
|
|
193
|
+
toolResults.push({
|
|
194
|
+
role: "tool",
|
|
195
|
+
tool_call_id: toolResult.tool_call_id,
|
|
196
|
+
content: toolResult.content,
|
|
197
|
+
|
|
198
|
+
});
|
|
199
|
+
if (toolResult.userMessage) {
|
|
200
|
+
this.nextUserMessage = {
|
|
201
|
+
role: "user",
|
|
202
|
+
content: toolResult.userMessage
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
152
206
|
}
|
|
153
207
|
|
|
154
208
|
this.apiConversationHistory.push(...toolResults);
|
|
209
|
+
if (this.nextUserMessage) {
|
|
210
|
+
this.apiConversationHistory.push(this.nextUserMessage);
|
|
211
|
+
}
|
|
155
212
|
let nextUserMessage: Message[] = toolResults;
|
|
156
213
|
|
|
157
214
|
if (toolResults.length === 0) {
|
|
@@ -212,7 +269,9 @@ class Agent {
|
|
|
212
269
|
}
|
|
213
270
|
|
|
214
271
|
private async executeTool(toolName: string, toolInput: any): Promise<[boolean, any]> {
|
|
215
|
-
|
|
272
|
+
//codebolttools--readfile
|
|
273
|
+
const [toolboxName, actualToolName] = toolName.split('--');
|
|
274
|
+
return tools.executeTool(toolboxName, actualToolName, toolInput);
|
|
216
275
|
}
|
|
217
276
|
private async startSubAgent(agentName: string, params: any): Promise<[boolean, any]> {
|
|
218
277
|
return codeboltAgent.startAgent(agentName, params.task);
|
|
@@ -226,11 +285,24 @@ class Agent {
|
|
|
226
285
|
};
|
|
227
286
|
}
|
|
228
287
|
|
|
229
|
-
private getToolResult(tool_call_id: string, content:
|
|
288
|
+
private getToolResult(tool_call_id: string, content: string): ToolResult {
|
|
289
|
+
let userMessage=undefined
|
|
290
|
+
try {
|
|
291
|
+
let parsed = JSON.parse(content);
|
|
292
|
+
|
|
293
|
+
if (parsed.payload && parsed.payload.content) {
|
|
294
|
+
content = `The browser action has been executed. The screenshot have been captured for your analysis. The tool response is provided in the next user message`
|
|
295
|
+
// this.apiConversationHistory.push()
|
|
296
|
+
userMessage = parsed.payload.content
|
|
297
|
+
}
|
|
298
|
+
} catch (error) {
|
|
299
|
+
|
|
300
|
+
}
|
|
230
301
|
return {
|
|
231
302
|
role: "tool",
|
|
232
303
|
tool_call_id,
|
|
233
304
|
content,
|
|
305
|
+
userMessage
|
|
234
306
|
};
|
|
235
307
|
}
|
|
236
308
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cbfs from "./../fs";
|
|
2
2
|
import project from "./../project";
|
|
3
|
-
import mcp from "./../
|
|
3
|
+
import mcp from "./../tools";
|
|
4
4
|
import { escape } from "querystring";
|
|
5
5
|
|
|
6
6
|
|
|
@@ -24,13 +24,13 @@ class UserMessage {
|
|
|
24
24
|
message: Message;
|
|
25
25
|
promptOverride: boolean;
|
|
26
26
|
userMessages: UserMessageContent[];
|
|
27
|
-
|
|
27
|
+
mentionedMCPs: string[];
|
|
28
28
|
|
|
29
29
|
constructor(message: Message, promptOverride: boolean = false) {
|
|
30
30
|
this.message = message;
|
|
31
31
|
this.promptOverride = promptOverride;
|
|
32
32
|
this.userMessages = [];
|
|
33
|
-
this.
|
|
33
|
+
this.mentionedMCPs = message.mentionedMCPs || [];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
getFiles(): void {
|
|
@@ -74,8 +74,8 @@ class UserMessage {
|
|
|
74
74
|
return this.message.mentionedMCPs || [];
|
|
75
75
|
}
|
|
76
76
|
async getMentionedMcpsTools() {
|
|
77
|
-
if (this.
|
|
78
|
-
let tools = await mcp.
|
|
77
|
+
if (this.mentionedMCPs.length > 0) {
|
|
78
|
+
let tools = await mcp.listToolsFromToolBoxes(this.mentionedMCPs)
|
|
79
79
|
return tools
|
|
80
80
|
}
|
|
81
81
|
else {
|
package/src/modules/chat.ts
CHANGED
|
@@ -79,7 +79,8 @@ const cbchat = {
|
|
|
79
79
|
eventEmitter.emit("userMessage", response, (message: string) => {
|
|
80
80
|
console.log("Callback function invoked with message:", message);
|
|
81
81
|
cbws.getWebsocket.send(JSON.stringify({
|
|
82
|
-
"type": "processStoped"
|
|
82
|
+
"type": "processStoped",
|
|
83
|
+
"message": message
|
|
83
84
|
}));
|
|
84
85
|
});
|
|
85
86
|
}
|