@codebolt/codeboltjs 2.0.7 → 2.0.11
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/dist/agentlib/agent.js +12 -4
- package/dist/agentlib/promptbuilder.d.ts +228 -0
- package/dist/agentlib/promptbuilder.js +487 -0
- package/dist/agentlib/taskInstruction.d.ts +3 -25
- package/dist/agentlib/usermessage.d.ts +13 -43
- package/dist/agentlib/usermessage.js +8 -8
- package/dist/core/messageManager.d.ts +4 -6
- package/dist/core/messageManager.js +24 -17
- package/dist/core/websocket.d.ts +10 -0
- package/dist/core/websocket.js +92 -8
- package/dist/index.d.ts +97 -95
- package/dist/index.js +63 -57
- package/dist/modules/agent.d.ts +9 -8
- package/dist/modules/agent.js +4 -4
- package/dist/modules/browser.d.ts +17 -17
- package/dist/modules/browser.js +7 -7
- package/dist/modules/chat.d.ts +1 -1
- package/dist/modules/codeparsers.d.ts +1 -16
- package/dist/modules/codeutils.d.ts +3 -18
- package/dist/modules/dbmemory.d.ts +1 -1
- package/dist/modules/debug.d.ts +1 -1
- package/dist/modules/fs.d.ts +1 -1
- package/dist/modules/git.d.ts +21 -20
- package/dist/modules/git.js +10 -10
- package/dist/modules/history.d.ts +6 -8
- package/dist/modules/history.js +4 -1
- package/dist/modules/llm.d.ts +13 -5
- package/dist/modules/llm.js +29 -4
- package/dist/modules/{tools.d.ts → mcp.d.ts} +9 -8
- package/dist/modules/{tools.js → mcp.js} +6 -6
- package/dist/modules/project.d.ts +1 -1
- package/dist/modules/state.d.ts +2 -1
- package/dist/modules/task.js +0 -1
- package/dist/modules/terminal.d.ts +1 -1
- package/dist/modules/tokenizer.d.ts +1 -1
- package/dist/modules/utils.d.ts +11 -1
- package/dist/modules/utils.js +9 -0
- package/dist/modules/vectordb.d.ts +1 -1
- package/dist/types/InternalTypes.d.ts +501 -0
- package/dist/types/InternalTypes.js +30 -0
- package/dist/types/commonTypes.d.ts +346 -0
- package/dist/types/commonTypes.js +37 -0
- package/dist/types/libFunctionTypes.d.ts +589 -0
- package/dist/types/libFunctionTypes.js +11 -0
- package/dist/types/socketMessageTypes.d.ts +951 -0
- package/dist/types/socketMessageTypes.js +51 -0
- package/dist/utils/{toolBox.d.ts → mcpServer.d.ts} +1 -1
- package/dist/utils/{toolBox.js → mcpServer.js} +36 -36
- package/dist/utils/parse-source-code/languageParser.d.ts +1 -7
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +3 -3
- package/package.json +6 -1
package/dist/agentlib/agent.js
CHANGED
|
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Agent = void 0;
|
|
7
7
|
const chat_1 = __importDefault(require("../modules/chat"));
|
|
8
|
-
const
|
|
8
|
+
const mcp_1 = __importDefault(require("../modules/mcp"));
|
|
9
9
|
const llm_1 = __importDefault(require("../modules/llm"));
|
|
10
10
|
const agent_1 = __importDefault(require("../modules/agent"));
|
|
11
|
+
// All interfaces moved to libFunctionTypes.ts
|
|
11
12
|
/**
|
|
12
13
|
* Agent class that manages conversations with LLMs and tool executions.
|
|
13
14
|
* Handles the conversation flow, tool calls, and task completions.
|
|
@@ -39,7 +40,7 @@ class Agent {
|
|
|
39
40
|
let mentaionedMCPSTool = await task.userMessage.getMentionedMcpsTools();
|
|
40
41
|
this.tools = [
|
|
41
42
|
...this.tools,
|
|
42
|
-
...mentaionedMCPSTool,
|
|
43
|
+
...(mentaionedMCPSTool || []),
|
|
43
44
|
];
|
|
44
45
|
let mentionedAgents = await task.userMessage.getMentionedAgents();
|
|
45
46
|
// Transform agents into tool format
|
|
@@ -122,7 +123,9 @@ class Agent {
|
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
else {
|
|
126
|
+
console.log("Executing tool: ", toolName, toolInput);
|
|
125
127
|
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
|
|
128
|
+
console.log("Tool result: ", result);
|
|
126
129
|
// toolResults.push(this.getToolResult(toolUseId, result));
|
|
127
130
|
let toolResult = this.getToolResult(toolUseId, result);
|
|
128
131
|
toolResults.push({
|
|
@@ -258,8 +261,12 @@ class Agent {
|
|
|
258
261
|
*/
|
|
259
262
|
async executeTool(toolName, toolInput) {
|
|
260
263
|
//codebolttools--readfile
|
|
264
|
+
console.log("Executing tool: ", toolName, toolInput);
|
|
261
265
|
const [toolboxName, actualToolName] = toolName.split('--');
|
|
262
|
-
|
|
266
|
+
console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
|
|
267
|
+
const { data } = await mcp_1.default.executeTool(toolboxName, actualToolName, toolInput);
|
|
268
|
+
console.log("Tool result: ", data);
|
|
269
|
+
return [false, data];
|
|
263
270
|
}
|
|
264
271
|
/**
|
|
265
272
|
* Starts a sub-agent to handle a specific task.
|
|
@@ -269,7 +276,7 @@ class Agent {
|
|
|
269
276
|
* @returns Promise with tuple [userRejected, result]
|
|
270
277
|
*/
|
|
271
278
|
async startSubAgent(agentName, params) {
|
|
272
|
-
return agent_1.default.startAgent(agentName, params.task);
|
|
279
|
+
return [false, await agent_1.default.startAgent(agentName, params.task)];
|
|
273
280
|
}
|
|
274
281
|
/**
|
|
275
282
|
* Extracts tool details from a tool call object.
|
|
@@ -295,6 +302,7 @@ class Agent {
|
|
|
295
302
|
let userMessage = undefined;
|
|
296
303
|
try {
|
|
297
304
|
let parsed = JSON.parse(content);
|
|
305
|
+
console.log("Parsed Content: ", parsed);
|
|
298
306
|
if (parsed.payload && parsed.payload.content) {
|
|
299
307
|
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`;
|
|
300
308
|
// this.apiConversationHistory.push()
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { UserMessage as CLIUserMessage } from "../types/socketMessageTypes";
|
|
2
|
+
import type { OpenAIMessage, OpenAITool, ConversationEntry, CodeboltAPI } from "../types/libFunctionTypes";
|
|
3
|
+
import type { MCPTool, Agent, InitialUserMessage } from "../types/commonTypes";
|
|
4
|
+
/**
|
|
5
|
+
* PromptBuilder class for constructing prompts using a fluent interface.
|
|
6
|
+
* Allows chaining methods to build complex prompts from user messages.
|
|
7
|
+
*/
|
|
8
|
+
declare class PromptBuilder {
|
|
9
|
+
/** The main message text */
|
|
10
|
+
private message;
|
|
11
|
+
/** List of mentioned files */
|
|
12
|
+
private mentionedFiles;
|
|
13
|
+
/** List of mentioned MCP tools */
|
|
14
|
+
private mentionedMCPs;
|
|
15
|
+
/** List of mentioned agents */
|
|
16
|
+
private mentionedAgents;
|
|
17
|
+
/** Array of prompt parts that will be joined */
|
|
18
|
+
private promptParts;
|
|
19
|
+
/** System prompt text */
|
|
20
|
+
private systemPromptText;
|
|
21
|
+
/** Task instruction text */
|
|
22
|
+
private taskInstructionText;
|
|
23
|
+
/** Available tools */
|
|
24
|
+
private tools;
|
|
25
|
+
/** Conversation history */
|
|
26
|
+
private conversationHistory;
|
|
27
|
+
/** Environment details */
|
|
28
|
+
private environmentDetails;
|
|
29
|
+
/** File contents cache */
|
|
30
|
+
private fileContents;
|
|
31
|
+
/** Codebolt API instance */
|
|
32
|
+
private codebolt?;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new PromptBuilder instance.
|
|
35
|
+
*
|
|
36
|
+
* @param userMessage - The initial user message containing text and mentioned entities
|
|
37
|
+
* @param codebolt - Optional codebolt API instance for automatic tool and environment loading
|
|
38
|
+
*/
|
|
39
|
+
constructor(userMessage: InitialUserMessage | CLIUserMessage, codebolt?: CodeboltAPI);
|
|
40
|
+
/**
|
|
41
|
+
* Sets the codebolt API instance for automatic operations.
|
|
42
|
+
*
|
|
43
|
+
* @param codebolt - The codebolt API instance
|
|
44
|
+
* @returns The PromptBuilder instance for chaining
|
|
45
|
+
*/
|
|
46
|
+
setCodeboltAPI(codebolt: CodeboltAPI): this;
|
|
47
|
+
/**
|
|
48
|
+
* Automatically loads and adds MCP tools from the mentioned MCPs in the user message.
|
|
49
|
+
* Also loads default codebolt tools.
|
|
50
|
+
*
|
|
51
|
+
* @param additionalServers - Additional MCP servers to load tools from
|
|
52
|
+
* @returns The PromptBuilder instance for chaining
|
|
53
|
+
*/
|
|
54
|
+
addMCPTools(additionalServers?: string[]): Promise<this>;
|
|
55
|
+
/**
|
|
56
|
+
* Automatically converts mentioned agents to OpenAI tool format and adds them.
|
|
57
|
+
*
|
|
58
|
+
* @returns The PromptBuilder instance for chaining
|
|
59
|
+
*/
|
|
60
|
+
addAgentTools(): this;
|
|
61
|
+
/**
|
|
62
|
+
* Automatically loads file contents for mentioned files and adds environment details.
|
|
63
|
+
*
|
|
64
|
+
* @returns The PromptBuilder instance for chaining
|
|
65
|
+
*/
|
|
66
|
+
addEnvironmentDetails(): Promise<this>;
|
|
67
|
+
/**
|
|
68
|
+
* Convenience method to automatically add all tools and environment details.
|
|
69
|
+
* Equivalent to calling addMCPTools(), addAgentTools(), and addEnvironmentDetails().
|
|
70
|
+
*
|
|
71
|
+
* @param additionalServers - Additional MCP servers to load tools from
|
|
72
|
+
* @returns The PromptBuilder instance for chaining
|
|
73
|
+
*/
|
|
74
|
+
addAllAutomatic(additionalServers?: string[]): Promise<this>;
|
|
75
|
+
/**
|
|
76
|
+
* Adds system prompt from a YAML file.
|
|
77
|
+
*
|
|
78
|
+
* @param filepath - Path to the YAML file containing system prompts
|
|
79
|
+
* @param key - Key identifier for the specific prompt
|
|
80
|
+
* @param exampleFilePath - Optional path to example file to append
|
|
81
|
+
* @returns The PromptBuilder instance for chaining
|
|
82
|
+
*/
|
|
83
|
+
addSystemPrompt(filepath: string, key: string, exampleFilePath?: string): this;
|
|
84
|
+
/**
|
|
85
|
+
* Adds task instruction from a YAML file.
|
|
86
|
+
*
|
|
87
|
+
* @param filepath - Path to the YAML file containing task instructions
|
|
88
|
+
* @param refsection - Section name within the YAML file
|
|
89
|
+
* @returns The PromptBuilder instance for chaining
|
|
90
|
+
*/
|
|
91
|
+
addTaskInstruction(filepath: string, refsection: string): this;
|
|
92
|
+
/**
|
|
93
|
+
* Manually adds environment details with file listing.
|
|
94
|
+
* Use addEnvironmentDetails() for automatic loading instead.
|
|
95
|
+
*
|
|
96
|
+
* @param projectPath - The project path
|
|
97
|
+
* @param fileListResult - The file listing result
|
|
98
|
+
* @returns The PromptBuilder instance for chaining
|
|
99
|
+
*/
|
|
100
|
+
setEnvironmentDetails(projectPath: string, fileListResult: string): this;
|
|
101
|
+
/**
|
|
102
|
+
* Adds MCP tools information to the prompt.
|
|
103
|
+
* Only adds content if there are mentioned MCPs.
|
|
104
|
+
*
|
|
105
|
+
* @returns The PromptBuilder instance for chaining
|
|
106
|
+
*/
|
|
107
|
+
addMCPToolsToPrompt(): this;
|
|
108
|
+
/**
|
|
109
|
+
* Adds agent information to the prompt.
|
|
110
|
+
* Only adds content if there are mentioned agents.
|
|
111
|
+
*
|
|
112
|
+
* @returns The PromptBuilder instance for chaining
|
|
113
|
+
*/
|
|
114
|
+
addAgentsToPrompt(): this;
|
|
115
|
+
/**
|
|
116
|
+
* Manually sets the available tools for the conversation.
|
|
117
|
+
* Use addMCPTools() and addAgentTools() for automatic loading instead.
|
|
118
|
+
*
|
|
119
|
+
* @param tools - Array of OpenAI tools
|
|
120
|
+
* @returns The PromptBuilder instance for chaining
|
|
121
|
+
*/
|
|
122
|
+
setTools(tools: OpenAITool[]): this;
|
|
123
|
+
/**
|
|
124
|
+
* Adds additional tools to the existing tool list.
|
|
125
|
+
*
|
|
126
|
+
* @param tools - Array of OpenAI tools to add
|
|
127
|
+
* @returns The PromptBuilder instance for chaining
|
|
128
|
+
*/
|
|
129
|
+
addTools(tools: OpenAITool[]): this;
|
|
130
|
+
/**
|
|
131
|
+
* Builds the user message content with files and environment details.
|
|
132
|
+
*
|
|
133
|
+
* @returns Array of content blocks
|
|
134
|
+
*/
|
|
135
|
+
private buildUserMessageContent;
|
|
136
|
+
/**
|
|
137
|
+
* Builds the OpenAI conversation format.
|
|
138
|
+
*
|
|
139
|
+
* @returns Array of OpenAI messages
|
|
140
|
+
*/
|
|
141
|
+
buildOpenAIMessages(): OpenAIMessage[];
|
|
142
|
+
/**
|
|
143
|
+
* Gets the available tools in OpenAI format.
|
|
144
|
+
*
|
|
145
|
+
* @returns Array of OpenAI tools
|
|
146
|
+
*/
|
|
147
|
+
getTools(): OpenAITool[];
|
|
148
|
+
/**
|
|
149
|
+
* Gets the loaded file contents.
|
|
150
|
+
*
|
|
151
|
+
* @returns Map of file paths to their contents
|
|
152
|
+
*/
|
|
153
|
+
getFileContents(): Map<string, string>;
|
|
154
|
+
/**
|
|
155
|
+
* Adds a message to the conversation history.
|
|
156
|
+
*
|
|
157
|
+
* @param role - The role of the message sender
|
|
158
|
+
* @param content - The content of the message
|
|
159
|
+
* @param toolCallId - Optional tool call ID for tool messages
|
|
160
|
+
* @param toolCalls - Optional tool calls for assistant messages
|
|
161
|
+
* @returns The PromptBuilder instance for chaining
|
|
162
|
+
*/
|
|
163
|
+
addToConversationHistory(role: 'user' | 'assistant' | 'tool', content: string | Array<{
|
|
164
|
+
type: string;
|
|
165
|
+
text: string;
|
|
166
|
+
}>, toolCallId?: string, toolCalls?: any[]): this;
|
|
167
|
+
/**
|
|
168
|
+
* Gets the current conversation history.
|
|
169
|
+
*
|
|
170
|
+
* @returns Array of conversation entries
|
|
171
|
+
*/
|
|
172
|
+
getConversationHistory(): ConversationEntry[];
|
|
173
|
+
/**
|
|
174
|
+
* Adds a custom text section to the prompt.
|
|
175
|
+
*
|
|
176
|
+
* @param title - Optional title for the section
|
|
177
|
+
* @param content - The content to add
|
|
178
|
+
* @returns The PromptBuilder instance for chaining
|
|
179
|
+
*/
|
|
180
|
+
addCustomSection(title: string, content: string): this;
|
|
181
|
+
/**
|
|
182
|
+
* Adds a system instruction to the prompt.
|
|
183
|
+
*
|
|
184
|
+
* @param instruction - The system instruction to add
|
|
185
|
+
* @returns The PromptBuilder instance for chaining
|
|
186
|
+
*/
|
|
187
|
+
addSystemInstruction(instruction: string): this;
|
|
188
|
+
/**
|
|
189
|
+
* Adds context information to the prompt.
|
|
190
|
+
*
|
|
191
|
+
* @param context - The context information to add
|
|
192
|
+
* @returns The PromptBuilder instance for chaining
|
|
193
|
+
*/
|
|
194
|
+
addContext(context: string): this;
|
|
195
|
+
/**
|
|
196
|
+
* Builds and returns the final prompt string.
|
|
197
|
+
* Joins all prompt parts with double newlines.
|
|
198
|
+
*
|
|
199
|
+
* @returns The complete prompt string
|
|
200
|
+
*/
|
|
201
|
+
build(): string;
|
|
202
|
+
/**
|
|
203
|
+
* Gets the current prompt parts without building the final string.
|
|
204
|
+
* Useful for debugging or inspection.
|
|
205
|
+
*
|
|
206
|
+
* @returns Array of current prompt parts
|
|
207
|
+
*/
|
|
208
|
+
getPromptParts(): string[];
|
|
209
|
+
/**
|
|
210
|
+
* Clears all prompt parts except the initial message.
|
|
211
|
+
* Useful for starting over with the same message.
|
|
212
|
+
*
|
|
213
|
+
* @returns The PromptBuilder instance for chaining
|
|
214
|
+
*/
|
|
215
|
+
reset(): this;
|
|
216
|
+
/**
|
|
217
|
+
* Creates an LLM inference parameters object in the format expected by the sample code.
|
|
218
|
+
*
|
|
219
|
+
* @returns Object with messages, tools, and other LLM parameters
|
|
220
|
+
*/
|
|
221
|
+
buildInferenceParams(): {
|
|
222
|
+
full: boolean;
|
|
223
|
+
messages: OpenAIMessage[];
|
|
224
|
+
tools: OpenAITool[];
|
|
225
|
+
tool_choice: "auto";
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
export { PromptBuilder, MCPTool, Agent, InitialUserMessage, OpenAIMessage, OpenAITool, ConversationEntry, CodeboltAPI };
|