@codebolt/codeboltjs 1.1.92 → 1.1.95
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 +2 -2
- package/modules/agentlib/agent.js +92 -16
- package/modules/agentlib/usermessage.d.ts +11 -1
- package/modules/agentlib/usermessage.js +8 -4
- 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 +111 -23
- package/src/modules/agentlib/usermessage.ts +23 -10
- 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 {
|
|
@@ -26,28 +27,20 @@ interface ToolDetails {
|
|
|
26
27
|
|
|
27
28
|
class Agent {
|
|
28
29
|
private tools: any[];
|
|
29
|
-
private subAgents: any[];
|
|
30
|
+
// private subAgents: any[];
|
|
30
31
|
private apiConversationHistory: Message[];
|
|
31
32
|
private maxRun: number;
|
|
32
33
|
private systemPrompt: SystemPrompt;
|
|
33
34
|
private userMessage: Message[];
|
|
35
|
+
private nextUserMessage:any;
|
|
34
36
|
|
|
35
37
|
|
|
36
|
-
constructor(tools: any = [], systemPrompt: SystemPrompt, maxRun: number = 0
|
|
38
|
+
constructor(tools: any = [], systemPrompt: SystemPrompt, maxRun: number = 0) {
|
|
37
39
|
this.tools = tools;
|
|
38
40
|
this.userMessage = [];
|
|
39
41
|
this.apiConversationHistory = [];
|
|
40
42
|
this.maxRun = maxRun;
|
|
41
43
|
this.systemPrompt = systemPrompt;
|
|
42
|
-
this.subAgents = subAgents;
|
|
43
|
-
this.subAgents = subAgents.map(subagent => {
|
|
44
|
-
subagent.function.name = `subagent--${subagent.function.name}`;
|
|
45
|
-
return subagent;
|
|
46
|
-
});
|
|
47
|
-
this.tools = this.tools.concat(subAgents.map(subagent => ({
|
|
48
|
-
...subagent
|
|
49
|
-
})));
|
|
50
|
-
|
|
51
44
|
|
|
52
45
|
}
|
|
53
46
|
|
|
@@ -55,10 +48,36 @@ class Agent {
|
|
|
55
48
|
|
|
56
49
|
|
|
57
50
|
let mentaionedMCPSTool: any[] = await task.userMessage.getMentionedMcpsTools();
|
|
51
|
+
|
|
58
52
|
this.tools = [
|
|
59
53
|
...this.tools,
|
|
60
|
-
...mentaionedMCPSTool
|
|
54
|
+
...mentaionedMCPSTool,
|
|
55
|
+
|
|
61
56
|
]
|
|
57
|
+
let mentionedAgents = await task.userMessage.getMentionedAgents();
|
|
58
|
+
|
|
59
|
+
// Transform agents into tool format
|
|
60
|
+
const agentTools = mentionedAgents.map(agent => {
|
|
61
|
+
return {
|
|
62
|
+
type: "function",
|
|
63
|
+
function: {
|
|
64
|
+
name: `subagent--${agent.unique_id}`,
|
|
65
|
+
description: agent.longDescription || agent.description,
|
|
66
|
+
parameters: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: {
|
|
69
|
+
task: {
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "The task to be executed by the tool."
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
required: ["task"]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.tools = this.tools.concat(agentTools);
|
|
62
81
|
|
|
63
82
|
|
|
64
83
|
let completed = false;
|
|
@@ -112,20 +131,44 @@ class Agent {
|
|
|
112
131
|
|
|
113
132
|
const agentResponse = await codeboltAgent.startAgent(toolName.replace("subagent--", ''), toolInput.task);
|
|
114
133
|
console.log("got sub agent resonse result", agentResponse);
|
|
115
|
-
const [didUserReject, result] = [false,"tool result is successful"];
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
toolResults.push(
|
|
134
|
+
const [didUserReject, result] = [false, "tool result is successful"];
|
|
135
|
+
console.log("got sub agent resonse result", didUserReject, result);
|
|
136
|
+
let toolResult = this.getToolResult(toolUseId, result)
|
|
137
|
+
toolResults.push({
|
|
138
|
+
role: "tool",
|
|
139
|
+
tool_call_id: toolResult.tool_call_id,
|
|
140
|
+
content: toolResult.content,
|
|
141
|
+
|
|
142
|
+
});
|
|
143
|
+
if (toolResult.userMessage) {
|
|
144
|
+
this.nextUserMessage = {
|
|
145
|
+
role: "user",
|
|
146
|
+
content: toolResult.userMessage
|
|
147
|
+
}
|
|
148
|
+
}
|
|
119
149
|
if (didUserReject) {
|
|
120
150
|
userRejectedToolUse = true;
|
|
121
151
|
}
|
|
152
|
+
|
|
122
153
|
}
|
|
123
154
|
else {
|
|
124
155
|
console.log("calling tool with params", toolName, toolInput);
|
|
125
156
|
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
|
|
126
157
|
console.log("tool result", result);
|
|
127
|
-
toolResults.push(this.getToolResult(toolUseId, result));
|
|
128
|
-
|
|
158
|
+
// toolResults.push(this.getToolResult(toolUseId, result));
|
|
159
|
+
let toolResult = this.getToolResult(toolUseId, result)
|
|
160
|
+
toolResults.push({
|
|
161
|
+
role: "tool",
|
|
162
|
+
tool_call_id: toolResult.tool_call_id,
|
|
163
|
+
content: toolResult.content,
|
|
164
|
+
|
|
165
|
+
});
|
|
166
|
+
if (toolResult.userMessage) {
|
|
167
|
+
this.nextUserMessage = {
|
|
168
|
+
role: "user",
|
|
169
|
+
content: toolResult.userMessage
|
|
170
|
+
}
|
|
171
|
+
}
|
|
129
172
|
if (didUserReject) {
|
|
130
173
|
userRejectedToolUse = true;
|
|
131
174
|
}
|
|
@@ -133,7 +176,21 @@ class Agent {
|
|
|
133
176
|
|
|
134
177
|
}
|
|
135
178
|
} else {
|
|
136
|
-
|
|
179
|
+
let toolResult = this.getToolResult(toolUseId, "Skipping tool execution due to previous tool user rejection.")
|
|
180
|
+
|
|
181
|
+
toolResults.push({
|
|
182
|
+
role: "tool",
|
|
183
|
+
tool_call_id: toolResult.tool_call_id,
|
|
184
|
+
content: toolResult.content,
|
|
185
|
+
|
|
186
|
+
});
|
|
187
|
+
if (toolResult.userMessage) {
|
|
188
|
+
this.nextUserMessage = {
|
|
189
|
+
role: "user",
|
|
190
|
+
content: toolResult.userMessage
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
137
194
|
}
|
|
138
195
|
}
|
|
139
196
|
}
|
|
@@ -148,10 +205,26 @@ class Agent {
|
|
|
148
205
|
completed = true;
|
|
149
206
|
result = "The user is satisfied with the result.";
|
|
150
207
|
}
|
|
151
|
-
|
|
208
|
+
let toolResult = this.getToolResult(taskCompletedBlock.id, result)
|
|
209
|
+
toolResults.push({
|
|
210
|
+
role: "tool",
|
|
211
|
+
tool_call_id: toolResult.tool_call_id,
|
|
212
|
+
content: toolResult.content,
|
|
213
|
+
|
|
214
|
+
});
|
|
215
|
+
if (toolResult.userMessage) {
|
|
216
|
+
this.nextUserMessage = {
|
|
217
|
+
role: "user",
|
|
218
|
+
content: toolResult.userMessage
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
152
222
|
}
|
|
153
223
|
|
|
154
224
|
this.apiConversationHistory.push(...toolResults);
|
|
225
|
+
if (this.nextUserMessage) {
|
|
226
|
+
this.apiConversationHistory.push(this.nextUserMessage);
|
|
227
|
+
}
|
|
155
228
|
let nextUserMessage: Message[] = toolResults;
|
|
156
229
|
|
|
157
230
|
if (toolResults.length === 0) {
|
|
@@ -212,7 +285,9 @@ class Agent {
|
|
|
212
285
|
}
|
|
213
286
|
|
|
214
287
|
private async executeTool(toolName: string, toolInput: any): Promise<[boolean, any]> {
|
|
215
|
-
|
|
288
|
+
//codebolttools--readfile
|
|
289
|
+
const [toolboxName, actualToolName] = toolName.split('--');
|
|
290
|
+
return tools.executeTool(toolboxName, actualToolName, toolInput);
|
|
216
291
|
}
|
|
217
292
|
private async startSubAgent(agentName: string, params: any): Promise<[boolean, any]> {
|
|
218
293
|
return codeboltAgent.startAgent(agentName, params.task);
|
|
@@ -226,11 +301,24 @@ class Agent {
|
|
|
226
301
|
};
|
|
227
302
|
}
|
|
228
303
|
|
|
229
|
-
private getToolResult(tool_call_id: string, content:
|
|
304
|
+
private getToolResult(tool_call_id: string, content: string): ToolResult {
|
|
305
|
+
let userMessage=undefined
|
|
306
|
+
try {
|
|
307
|
+
let parsed = JSON.parse(content);
|
|
308
|
+
|
|
309
|
+
if (parsed.payload && parsed.payload.content) {
|
|
310
|
+
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`
|
|
311
|
+
// this.apiConversationHistory.push()
|
|
312
|
+
userMessage = parsed.payload.content
|
|
313
|
+
}
|
|
314
|
+
} catch (error) {
|
|
315
|
+
|
|
316
|
+
}
|
|
230
317
|
return {
|
|
231
318
|
role: "tool",
|
|
232
319
|
tool_call_id,
|
|
233
320
|
content,
|
|
321
|
+
userMessage
|
|
234
322
|
};
|
|
235
323
|
}
|
|
236
324
|
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import cbfs from "./../fs";
|
|
2
2
|
import project from "./../project";
|
|
3
|
-
import mcp from "./../
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import mcp from "./../tools";
|
|
4
|
+
interface agent {
|
|
5
|
+
|
|
6
|
+
description: string;
|
|
7
|
+
title: string;
|
|
8
|
+
id: number;
|
|
9
|
+
agent_id: string;
|
|
10
|
+
unique_id: string;
|
|
11
|
+
longDescription: string;
|
|
12
|
+
|
|
13
|
+
}
|
|
7
14
|
interface Message {
|
|
8
15
|
userMessage: string;
|
|
9
16
|
mentionedFiles?: string[];
|
|
10
17
|
mentionedMCPs: string[];
|
|
18
|
+
mentionedAgents: agent[];
|
|
11
19
|
}
|
|
12
20
|
|
|
13
21
|
export interface UserMessageContent {
|
|
@@ -24,13 +32,13 @@ class UserMessage {
|
|
|
24
32
|
message: Message;
|
|
25
33
|
promptOverride: boolean;
|
|
26
34
|
userMessages: UserMessageContent[];
|
|
27
|
-
|
|
35
|
+
mentionedMCPs: string[];
|
|
28
36
|
|
|
29
37
|
constructor(message: Message, promptOverride: boolean = false) {
|
|
30
38
|
this.message = message;
|
|
31
39
|
this.promptOverride = promptOverride;
|
|
32
40
|
this.userMessages = [];
|
|
33
|
-
this.
|
|
41
|
+
this.mentionedMCPs = message.mentionedMCPs || [];
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
getFiles(): void {
|
|
@@ -70,12 +78,17 @@ class UserMessage {
|
|
|
70
78
|
return this.userMessages;
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
getMentionedAgents() {
|
|
82
|
+
//TODO : get config in tool format if neede
|
|
83
|
+
return this.message.mentionedAgents || [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getMentionedMcps() {
|
|
87
|
+
return this.message.mentionedMCPs || [];
|
|
75
88
|
}
|
|
76
89
|
async getMentionedMcpsTools() {
|
|
77
|
-
if (this.
|
|
78
|
-
let tools = await mcp.
|
|
90
|
+
if (this.mentionedMCPs.length > 0) {
|
|
91
|
+
let tools = await mcp.listToolsFromToolBoxes(this.mentionedMCPs)
|
|
79
92
|
return tools
|
|
80
93
|
}
|
|
81
94
|
else {
|