@codebolt/codeboltjs 2.0.6 → 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 +95 -88
- package/dist/index.js +63 -59
- 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/{modules → utils}/docutils.d.ts +2 -2
- package/dist/{modules → utils}/docutils.js +2 -2
- 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 +2 -1
- package/dist/utils.js +8 -3
- package/package.json +6 -1
|
@@ -0,0 +1,487 @@
|
|
|
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
|
+
exports.PromptBuilder = void 0;
|
|
7
|
+
const systemprompt_1 = require("./systemprompt");
|
|
8
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
// All interfaces moved to appropriate type files
|
|
12
|
+
/**
|
|
13
|
+
* PromptBuilder class for constructing prompts using a fluent interface.
|
|
14
|
+
* Allows chaining methods to build complex prompts from user messages.
|
|
15
|
+
*/
|
|
16
|
+
class PromptBuilder {
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new PromptBuilder instance.
|
|
19
|
+
*
|
|
20
|
+
* @param userMessage - The initial user message containing text and mentioned entities
|
|
21
|
+
* @param codebolt - Optional codebolt API instance for automatic tool and environment loading
|
|
22
|
+
*/
|
|
23
|
+
constructor(userMessage, codebolt) {
|
|
24
|
+
var _a;
|
|
25
|
+
/** System prompt text */
|
|
26
|
+
this.systemPromptText = "";
|
|
27
|
+
/** Task instruction text */
|
|
28
|
+
this.taskInstructionText = "";
|
|
29
|
+
/** Available tools */
|
|
30
|
+
this.tools = [];
|
|
31
|
+
/** Conversation history */
|
|
32
|
+
this.conversationHistory = [];
|
|
33
|
+
/** Environment details */
|
|
34
|
+
this.environmentDetails = "";
|
|
35
|
+
/** File contents cache */
|
|
36
|
+
this.fileContents = new Map();
|
|
37
|
+
// Handle both InitialUserMessage and CLIUserMessage types
|
|
38
|
+
if ('message' in userMessage && typeof userMessage.message === 'object') {
|
|
39
|
+
// This is a CLIUserMessage with nested message structure
|
|
40
|
+
this.message = userMessage.message.userMessage || ((_a = userMessage.data) === null || _a === void 0 ? void 0 : _a.text) || "";
|
|
41
|
+
this.mentionedFiles = userMessage.message.mentionedFiles || [];
|
|
42
|
+
// Convert string array to MCPTool array for CLIUserMessage
|
|
43
|
+
this.mentionedMCPs = (userMessage.message.mentionedMCPs || []).map((name) => ({ name }));
|
|
44
|
+
this.mentionedAgents = userMessage.message.mentionedAgents || [];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// This is an InitialUserMessage
|
|
48
|
+
this.message = userMessage.messageText || userMessage.userMessage || "";
|
|
49
|
+
this.mentionedFiles = userMessage.mentionedFiles || [];
|
|
50
|
+
this.mentionedMCPs = userMessage.mentionedMCPs || [];
|
|
51
|
+
this.mentionedAgents = userMessage.mentionedAgents || [];
|
|
52
|
+
}
|
|
53
|
+
this.promptParts = [this.message];
|
|
54
|
+
this.codebolt = codebolt;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Sets the codebolt API instance for automatic operations.
|
|
58
|
+
*
|
|
59
|
+
* @param codebolt - The codebolt API instance
|
|
60
|
+
* @returns The PromptBuilder instance for chaining
|
|
61
|
+
*/
|
|
62
|
+
setCodeboltAPI(codebolt) {
|
|
63
|
+
this.codebolt = codebolt;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Automatically loads and adds MCP tools from the mentioned MCPs in the user message.
|
|
68
|
+
* Also loads default codebolt tools.
|
|
69
|
+
*
|
|
70
|
+
* @param additionalServers - Additional MCP servers to load tools from
|
|
71
|
+
* @returns The PromptBuilder instance for chaining
|
|
72
|
+
*/
|
|
73
|
+
async addMCPTools(additionalServers = ["codebolt"]) {
|
|
74
|
+
if (!this.codebolt) {
|
|
75
|
+
console.warn("Codebolt API not available. Cannot load MCP tools automatically.");
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
// Get default tools from specified servers
|
|
80
|
+
const { data: defaultTools } = await this.codebolt.mcp.listMcpFromServers(additionalServers);
|
|
81
|
+
this.tools = [...this.tools, ...defaultTools];
|
|
82
|
+
// Get tools from mentioned MCPs
|
|
83
|
+
if (this.mentionedMCPs && this.mentionedMCPs.length > 0) {
|
|
84
|
+
const { data: mcpTools } = await this.codebolt.mcp.getTools(this.mentionedMCPs);
|
|
85
|
+
this.tools = [...this.tools, ...mcpTools];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error(`Error loading MCP tools: ${error}`);
|
|
90
|
+
}
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Automatically converts mentioned agents to OpenAI tool format and adds them.
|
|
95
|
+
*
|
|
96
|
+
* @returns The PromptBuilder instance for chaining
|
|
97
|
+
*/
|
|
98
|
+
addAgentTools() {
|
|
99
|
+
if (this.mentionedAgents && this.mentionedAgents.length > 0) {
|
|
100
|
+
const agentTools = this.mentionedAgents.map(agent => ({
|
|
101
|
+
type: "function",
|
|
102
|
+
function: {
|
|
103
|
+
name: `subagent--${agent.unique_id}`,
|
|
104
|
+
description: agent.longDescription || agent.description || "Agent tool",
|
|
105
|
+
parameters: {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: {
|
|
108
|
+
task: {
|
|
109
|
+
type: "string",
|
|
110
|
+
description: "The task to be executed by the tool."
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
required: ["task"]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
this.tools = [...this.tools, ...agentTools];
|
|
118
|
+
}
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Automatically loads file contents for mentioned files and adds environment details.
|
|
123
|
+
*
|
|
124
|
+
* @returns The PromptBuilder instance for chaining
|
|
125
|
+
*/
|
|
126
|
+
async addEnvironmentDetails() {
|
|
127
|
+
if (!this.codebolt) {
|
|
128
|
+
console.warn("Codebolt API not available. Cannot load environment details automatically.");
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
// Load mentioned file contents
|
|
133
|
+
if (this.mentionedFiles && this.mentionedFiles.length > 0) {
|
|
134
|
+
for (const file of this.mentionedFiles) {
|
|
135
|
+
try {
|
|
136
|
+
const fileData = await this.codebolt.fs.readFile(file);
|
|
137
|
+
this.fileContents.set(file, fileData);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error(`Error reading file ${file}: ${error}`);
|
|
141
|
+
this.fileContents.set(file, "[File could not be read]");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Get project path and file listing
|
|
146
|
+
const { projectPath } = await this.codebolt.project.getProjectPath();
|
|
147
|
+
if (projectPath) {
|
|
148
|
+
const { success, result } = await this.codebolt.fs.listFile(projectPath, true);
|
|
149
|
+
if (success) {
|
|
150
|
+
this.environmentDetails = `\n\n<environment_details>\n\n# Current Working Directory (${projectPath}) Files\n${result}\n</environment_details>`;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
console.error(`Error loading environment details: ${error}`);
|
|
156
|
+
}
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Convenience method to automatically add all tools and environment details.
|
|
161
|
+
* Equivalent to calling addMCPTools(), addAgentTools(), and addEnvironmentDetails().
|
|
162
|
+
*
|
|
163
|
+
* @param additionalServers - Additional MCP servers to load tools from
|
|
164
|
+
* @returns The PromptBuilder instance for chaining
|
|
165
|
+
*/
|
|
166
|
+
async addAllAutomatic(additionalServers = ["codebolt"]) {
|
|
167
|
+
await this.addMCPTools(additionalServers);
|
|
168
|
+
this.addAgentTools();
|
|
169
|
+
await this.addEnvironmentDetails();
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Adds system prompt from a YAML file.
|
|
174
|
+
*
|
|
175
|
+
* @param filepath - Path to the YAML file containing system prompts
|
|
176
|
+
* @param key - Key identifier for the specific prompt
|
|
177
|
+
* @param exampleFilePath - Optional path to example file to append
|
|
178
|
+
* @returns The PromptBuilder instance for chaining
|
|
179
|
+
*/
|
|
180
|
+
addSystemPrompt(filepath, key, exampleFilePath) {
|
|
181
|
+
try {
|
|
182
|
+
const systemPrompt = new systemprompt_1.SystemPrompt(filepath, key);
|
|
183
|
+
this.systemPromptText = systemPrompt.toPromptText();
|
|
184
|
+
// Add example file if provided
|
|
185
|
+
if (exampleFilePath) {
|
|
186
|
+
try {
|
|
187
|
+
const example = fs_1.default.readFileSync(path_1.default.resolve(exampleFilePath), 'utf8');
|
|
188
|
+
this.systemPromptText += `\n\n<example_agent>\n\n${example}\n</example_agent>`;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
console.error(`Error loading example file: ${error}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
console.error(`Error loading system prompt: ${error}`);
|
|
197
|
+
}
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Adds task instruction from a YAML file.
|
|
202
|
+
*
|
|
203
|
+
* @param filepath - Path to the YAML file containing task instructions
|
|
204
|
+
* @param refsection - Section name within the YAML file
|
|
205
|
+
* @returns The PromptBuilder instance for chaining
|
|
206
|
+
*/
|
|
207
|
+
addTaskInstruction(filepath, refsection) {
|
|
208
|
+
try {
|
|
209
|
+
const fileContents = fs_1.default.readFileSync(path_1.default.resolve(filepath), 'utf8');
|
|
210
|
+
const data = js_yaml_1.default.load(fileContents);
|
|
211
|
+
const task = data[refsection];
|
|
212
|
+
if (task) {
|
|
213
|
+
this.taskInstructionText = `Task Description: ${task.description}\nExpected Output: ${task.expected_output}`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
console.error(`Error loading task instruction: ${error}`);
|
|
218
|
+
}
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Manually adds environment details with file listing.
|
|
223
|
+
* Use addEnvironmentDetails() for automatic loading instead.
|
|
224
|
+
*
|
|
225
|
+
* @param projectPath - The project path
|
|
226
|
+
* @param fileListResult - The file listing result
|
|
227
|
+
* @returns The PromptBuilder instance for chaining
|
|
228
|
+
*/
|
|
229
|
+
setEnvironmentDetails(projectPath, fileListResult) {
|
|
230
|
+
if (projectPath && fileListResult) {
|
|
231
|
+
this.environmentDetails = `\n\n<environment_details>\n\n# Current Working Directory (${projectPath}) Files\n${fileListResult}\n</environment_details>`;
|
|
232
|
+
}
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Adds MCP tools information to the prompt.
|
|
237
|
+
* Only adds content if there are mentioned MCPs.
|
|
238
|
+
*
|
|
239
|
+
* @returns The PromptBuilder instance for chaining
|
|
240
|
+
*/
|
|
241
|
+
addMCPToolsToPrompt() {
|
|
242
|
+
if (this.mentionedMCPs.length > 0) {
|
|
243
|
+
const mcpTools = this.mentionedMCPs.map(mcp => {
|
|
244
|
+
const name = mcp.name || mcp.toolbox || "Unknown";
|
|
245
|
+
const toolName = mcp.toolName || "";
|
|
246
|
+
const tools = mcp.tools ? JSON.stringify(mcp.tools) : "[]";
|
|
247
|
+
let mcpInfo = `MCP: ${name}`;
|
|
248
|
+
if (toolName) {
|
|
249
|
+
mcpInfo += `, Tool: ${toolName}`;
|
|
250
|
+
}
|
|
251
|
+
mcpInfo += `, Tools: ${tools}`;
|
|
252
|
+
return mcpInfo;
|
|
253
|
+
}).join("\n");
|
|
254
|
+
this.promptParts.push(`[MCP Tools]\n${mcpTools}`);
|
|
255
|
+
}
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Adds agent information to the prompt.
|
|
260
|
+
* Only adds content if there are mentioned agents.
|
|
261
|
+
*
|
|
262
|
+
* @returns The PromptBuilder instance for chaining
|
|
263
|
+
*/
|
|
264
|
+
addAgentsToPrompt() {
|
|
265
|
+
if (this.mentionedAgents.length > 0) {
|
|
266
|
+
const agentList = this.mentionedAgents.map(agent => {
|
|
267
|
+
const identifier = agent.name || agent.title || agent.id || agent.agent_id || "Unknown";
|
|
268
|
+
let agentInfo = `Agent: ${identifier}`;
|
|
269
|
+
if (agent.description) {
|
|
270
|
+
agentInfo += ` - ${agent.description}`;
|
|
271
|
+
}
|
|
272
|
+
return agentInfo;
|
|
273
|
+
}).join("\n");
|
|
274
|
+
this.promptParts.push(`[Agents]\n${agentList}`);
|
|
275
|
+
}
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Manually sets the available tools for the conversation.
|
|
280
|
+
* Use addMCPTools() and addAgentTools() for automatic loading instead.
|
|
281
|
+
*
|
|
282
|
+
* @param tools - Array of OpenAI tools
|
|
283
|
+
* @returns The PromptBuilder instance for chaining
|
|
284
|
+
*/
|
|
285
|
+
setTools(tools) {
|
|
286
|
+
this.tools = [...tools];
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Adds additional tools to the existing tool list.
|
|
291
|
+
*
|
|
292
|
+
* @param tools - Array of OpenAI tools to add
|
|
293
|
+
* @returns The PromptBuilder instance for chaining
|
|
294
|
+
*/
|
|
295
|
+
addTools(tools) {
|
|
296
|
+
this.tools = [...this.tools, ...tools];
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Builds the user message content with files and environment details.
|
|
301
|
+
*
|
|
302
|
+
* @returns Array of content blocks
|
|
303
|
+
*/
|
|
304
|
+
buildUserMessageContent() {
|
|
305
|
+
let finalPrompt = `
|
|
306
|
+
The user has sent the following query:
|
|
307
|
+
<user_query> ${this.message} </user_query>.
|
|
308
|
+
`;
|
|
309
|
+
// Attach files if mentioned
|
|
310
|
+
if (this.mentionedFiles && this.mentionedFiles.length > 0) {
|
|
311
|
+
finalPrompt += `The Attached files are:`;
|
|
312
|
+
for (const file of this.mentionedFiles) {
|
|
313
|
+
const fileData = this.fileContents.get(file) || "[File content not available]";
|
|
314
|
+
finalPrompt += `File Name: ${file}, File Path: ${file}, Filedata: ${fileData}`;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// Add environment details
|
|
318
|
+
if (this.environmentDetails) {
|
|
319
|
+
finalPrompt += this.environmentDetails;
|
|
320
|
+
}
|
|
321
|
+
const content = [
|
|
322
|
+
{ type: "text", text: finalPrompt }
|
|
323
|
+
];
|
|
324
|
+
// Add task instruction if available
|
|
325
|
+
if (this.taskInstructionText) {
|
|
326
|
+
content.push({
|
|
327
|
+
type: "text",
|
|
328
|
+
text: this.taskInstructionText
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return content;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Builds the OpenAI conversation format.
|
|
335
|
+
*
|
|
336
|
+
* @returns Array of OpenAI messages
|
|
337
|
+
*/
|
|
338
|
+
buildOpenAIMessages() {
|
|
339
|
+
const messages = [];
|
|
340
|
+
// Add system message if available
|
|
341
|
+
if (this.systemPromptText) {
|
|
342
|
+
messages.push({
|
|
343
|
+
role: "system",
|
|
344
|
+
content: this.systemPromptText
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
// Add user message
|
|
348
|
+
const userContent = this.buildUserMessageContent();
|
|
349
|
+
messages.push({
|
|
350
|
+
role: "user",
|
|
351
|
+
content: userContent
|
|
352
|
+
});
|
|
353
|
+
// Add any existing conversation history
|
|
354
|
+
messages.push(...this.conversationHistory);
|
|
355
|
+
return messages;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Gets the available tools in OpenAI format.
|
|
359
|
+
*
|
|
360
|
+
* @returns Array of OpenAI tools
|
|
361
|
+
*/
|
|
362
|
+
getTools() {
|
|
363
|
+
return this.tools;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Gets the loaded file contents.
|
|
367
|
+
*
|
|
368
|
+
* @returns Map of file paths to their contents
|
|
369
|
+
*/
|
|
370
|
+
getFileContents() {
|
|
371
|
+
return new Map(this.fileContents);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Adds a message to the conversation history.
|
|
375
|
+
*
|
|
376
|
+
* @param role - The role of the message sender
|
|
377
|
+
* @param content - The content of the message
|
|
378
|
+
* @param toolCallId - Optional tool call ID for tool messages
|
|
379
|
+
* @param toolCalls - Optional tool calls for assistant messages
|
|
380
|
+
* @returns The PromptBuilder instance for chaining
|
|
381
|
+
*/
|
|
382
|
+
addToConversationHistory(role, content, toolCallId, toolCalls) {
|
|
383
|
+
const message = { role, content };
|
|
384
|
+
if (toolCallId) {
|
|
385
|
+
message.tool_call_id = toolCallId;
|
|
386
|
+
}
|
|
387
|
+
if (toolCalls) {
|
|
388
|
+
message.tool_calls = toolCalls;
|
|
389
|
+
}
|
|
390
|
+
this.conversationHistory.push(message);
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Gets the current conversation history.
|
|
395
|
+
*
|
|
396
|
+
* @returns Array of conversation entries
|
|
397
|
+
*/
|
|
398
|
+
getConversationHistory() {
|
|
399
|
+
return [...this.conversationHistory];
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Adds a custom text section to the prompt.
|
|
403
|
+
*
|
|
404
|
+
* @param title - Optional title for the section
|
|
405
|
+
* @param content - The content to add
|
|
406
|
+
* @returns The PromptBuilder instance for chaining
|
|
407
|
+
*/
|
|
408
|
+
addCustomSection(title, content) {
|
|
409
|
+
if (content.trim()) {
|
|
410
|
+
const section = title ? `[${title}]\n${content}` : content;
|
|
411
|
+
this.promptParts.push(section);
|
|
412
|
+
}
|
|
413
|
+
return this;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Adds a system instruction to the prompt.
|
|
417
|
+
*
|
|
418
|
+
* @param instruction - The system instruction to add
|
|
419
|
+
* @returns The PromptBuilder instance for chaining
|
|
420
|
+
*/
|
|
421
|
+
addSystemInstruction(instruction) {
|
|
422
|
+
if (instruction.trim()) {
|
|
423
|
+
this.promptParts.push(`[System Instruction]\n${instruction}`);
|
|
424
|
+
}
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Adds context information to the prompt.
|
|
429
|
+
*
|
|
430
|
+
* @param context - The context information to add
|
|
431
|
+
* @returns The PromptBuilder instance for chaining
|
|
432
|
+
*/
|
|
433
|
+
addContext(context) {
|
|
434
|
+
if (context.trim()) {
|
|
435
|
+
this.promptParts.push(`[Context]\n${context}`);
|
|
436
|
+
}
|
|
437
|
+
return this;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Builds and returns the final prompt string.
|
|
441
|
+
* Joins all prompt parts with double newlines.
|
|
442
|
+
*
|
|
443
|
+
* @returns The complete prompt string
|
|
444
|
+
*/
|
|
445
|
+
build() {
|
|
446
|
+
return this.promptParts.join("\n\n");
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Gets the current prompt parts without building the final string.
|
|
450
|
+
* Useful for debugging or inspection.
|
|
451
|
+
*
|
|
452
|
+
* @returns Array of current prompt parts
|
|
453
|
+
*/
|
|
454
|
+
getPromptParts() {
|
|
455
|
+
return [...this.promptParts];
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Clears all prompt parts except the initial message.
|
|
459
|
+
* Useful for starting over with the same message.
|
|
460
|
+
*
|
|
461
|
+
* @returns The PromptBuilder instance for chaining
|
|
462
|
+
*/
|
|
463
|
+
reset() {
|
|
464
|
+
this.promptParts = [this.message];
|
|
465
|
+
this.conversationHistory = [];
|
|
466
|
+
this.systemPromptText = "";
|
|
467
|
+
this.taskInstructionText = "";
|
|
468
|
+
this.tools = [];
|
|
469
|
+
this.environmentDetails = "";
|
|
470
|
+
this.fileContents.clear();
|
|
471
|
+
return this;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Creates an LLM inference parameters object in the format expected by the sample code.
|
|
475
|
+
*
|
|
476
|
+
* @returns Object with messages, tools, and other LLM parameters
|
|
477
|
+
*/
|
|
478
|
+
buildInferenceParams() {
|
|
479
|
+
return {
|
|
480
|
+
full: true,
|
|
481
|
+
messages: this.buildOpenAIMessages(),
|
|
482
|
+
tools: this.getTools(),
|
|
483
|
+
tool_choice: "auto",
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
exports.PromptBuilder = PromptBuilder;
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
import { UserMessage
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Each tool has a description and usage example.
|
|
5
|
-
*/
|
|
6
|
-
interface Tools {
|
|
7
|
-
[key: string]: {
|
|
8
|
-
/** Description of what the tool does */
|
|
9
|
-
description: string;
|
|
10
|
-
/** How to use the tool correctly */
|
|
11
|
-
usage: string;
|
|
12
|
-
/** Optional example demonstrating tool usage */
|
|
13
|
-
example?: string;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Interface for user message structure.
|
|
18
|
-
* Contains message type and text content.
|
|
19
|
-
*/
|
|
20
|
-
interface UserMessages {
|
|
21
|
-
/** The type of user message */
|
|
22
|
-
type: string;
|
|
23
|
-
/** The text content of the message */
|
|
24
|
-
text: string;
|
|
25
|
-
}
|
|
1
|
+
import { UserMessage } from "./usermessage";
|
|
2
|
+
import type { UserMessageContent } from "../types/libFunctionTypes";
|
|
3
|
+
import type { Tools, UserMessages } from "../types/InternalTypes";
|
|
26
4
|
/**
|
|
27
5
|
* Class representing a task instruction.
|
|
28
6
|
* Handles loading task data and converting it to prompts.
|
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface agent {
|
|
5
|
-
/** Short description of the agent */
|
|
6
|
-
description: string;
|
|
7
|
-
/** Title/name of the agent */
|
|
8
|
-
title: string;
|
|
9
|
-
/** Numeric ID of the agent */
|
|
10
|
-
id: number;
|
|
11
|
-
/** Agent identifier string */
|
|
12
|
-
agent_id: string;
|
|
13
|
-
/** Unique identifier for the agent */
|
|
14
|
-
unique_id: string;
|
|
15
|
-
/** Detailed description of the agent and its capabilities */
|
|
16
|
-
longDescription: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Interface for the user message structure.
|
|
20
|
-
*/
|
|
21
|
-
interface Message {
|
|
22
|
-
/** The actual text content of the user message */
|
|
23
|
-
userMessage: string;
|
|
24
|
-
/** Optional list of files mentioned in the message */
|
|
25
|
-
mentionedFiles?: string[];
|
|
26
|
-
/** List of MCP (Model Context Protocol) tools mentioned */
|
|
27
|
-
mentionedMCPs: string[];
|
|
28
|
-
/** List of agents mentioned in the message */
|
|
29
|
-
mentionedAgents: agent[];
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Interface for a single content block within a user message.
|
|
33
|
-
*/
|
|
34
|
-
export interface UserMessageContent {
|
|
35
|
-
/** Type of content (e.g., "text", "image") */
|
|
36
|
-
type: string;
|
|
37
|
-
/** The text content */
|
|
38
|
-
text: string;
|
|
39
|
-
}
|
|
1
|
+
import type { UserMessageContent } from "../types/libFunctionTypes";
|
|
2
|
+
import type { Agent } from "../types/commonTypes";
|
|
3
|
+
import type { Message } from "../types/InternalTypes";
|
|
40
4
|
/**
|
|
41
5
|
* Class that processes and manages user messages.
|
|
42
6
|
* Handles converting messages to prompts and extracting mentioned entities.
|
|
@@ -49,7 +13,10 @@ declare class UserMessage {
|
|
|
49
13
|
/** Array of content blocks for the user message */
|
|
50
14
|
userMessages: UserMessageContent[];
|
|
51
15
|
/** List of MCP tools mentioned in the message */
|
|
52
|
-
mentionedMCPs:
|
|
16
|
+
mentionedMCPs: {
|
|
17
|
+
toolbox: string;
|
|
18
|
+
toolName: string;
|
|
19
|
+
}[];
|
|
53
20
|
/**
|
|
54
21
|
* Creates a new UserMessage instance.
|
|
55
22
|
*
|
|
@@ -76,19 +43,22 @@ declare class UserMessage {
|
|
|
76
43
|
*
|
|
77
44
|
* @returns Array of agent objects
|
|
78
45
|
*/
|
|
79
|
-
getMentionedAgents():
|
|
46
|
+
getMentionedAgents(): Agent[];
|
|
80
47
|
/**
|
|
81
48
|
* Gets MCP tools mentioned in the message.
|
|
82
49
|
*
|
|
83
50
|
* @returns Array of MCP tool names
|
|
84
51
|
*/
|
|
85
|
-
getMentionedMcps():
|
|
52
|
+
getMentionedMcps(): {
|
|
53
|
+
toolbox: string;
|
|
54
|
+
toolName: string;
|
|
55
|
+
}[];
|
|
86
56
|
/**
|
|
87
57
|
* Gets MCP tools in a format suitable for the LLM.
|
|
88
58
|
*
|
|
89
59
|
* @returns Promise with an array of MCP tools
|
|
90
60
|
*/
|
|
91
|
-
getMentionedMcpsTools(): Promise<any>;
|
|
61
|
+
getMentionedMcpsTools(): Promise<any[] | undefined>;
|
|
92
62
|
/**
|
|
93
63
|
* Gets environment details for the current working directory.
|
|
94
64
|
*
|
|
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.UserMessage = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("../modules/fs"));
|
|
8
8
|
const project_1 = __importDefault(require("../modules/project"));
|
|
9
|
-
const
|
|
9
|
+
const mcp_1 = __importDefault(require("../modules/mcp"));
|
|
10
|
+
// All interfaces moved to appropriate type files
|
|
10
11
|
/**
|
|
11
12
|
* Class that processes and manages user messages.
|
|
12
13
|
* Handles converting messages to prompts and extracting mentioned entities.
|
|
@@ -77,8 +78,10 @@ class UserMessage {
|
|
|
77
78
|
}
|
|
78
79
|
if (bAttachEnvironment) {
|
|
79
80
|
let { projectPath } = await project_1.default.getProjectPath();
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
if (projectPath) {
|
|
82
|
+
const environmentDetail = await this.getEnvironmentDetail(projectPath);
|
|
83
|
+
this.userMessages.push({ type: "text", text: environmentDetail });
|
|
84
|
+
}
|
|
82
85
|
}
|
|
83
86
|
return this.userMessages;
|
|
84
87
|
}
|
|
@@ -105,12 +108,9 @@ class UserMessage {
|
|
|
105
108
|
* @returns Promise with an array of MCP tools
|
|
106
109
|
*/
|
|
107
110
|
async getMentionedMcpsTools() {
|
|
108
|
-
console.log("mentionedMCPs", this.mentionedMCPs);
|
|
109
111
|
if (this.mentionedMCPs.length > 0) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
console.log("tools", tools);
|
|
113
|
-
return tools;
|
|
112
|
+
const { data } = await mcp_1.default.getTools(this.mentionedMCPs);
|
|
113
|
+
return data;
|
|
114
114
|
}
|
|
115
115
|
else {
|
|
116
116
|
return [];
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import WebSocket from 'ws';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
|
-
|
|
5
|
-
resolve: (value: any) => void;
|
|
6
|
-
reject: (reason?: any) => void;
|
|
7
|
-
messageTypes: string[];
|
|
8
|
-
requestId?: string;
|
|
9
|
-
}
|
|
4
|
+
import type { PendingRequest } from '../types/commonTypes';
|
|
10
5
|
/**
|
|
11
6
|
* Centralized message manager for handling WebSocket communications
|
|
12
7
|
*/
|
|
@@ -28,6 +23,9 @@ export declare class MessageManager extends EventEmitter {
|
|
|
28
23
|
handleMessage(response: any): void;
|
|
29
24
|
/**
|
|
30
25
|
* Send a message and wait for a specific response type
|
|
26
|
+
* @param message The message to send
|
|
27
|
+
* @param expectedResponseType The type of response to wait for
|
|
28
|
+
* @param timeout Optional timeout in milliseconds. If not provided or set to 0, will wait indefinitely
|
|
31
29
|
*/
|
|
32
30
|
sendAndWaitForResponse<T = any>(message: any, expectedResponseType: string, timeout?: number): Promise<T>;
|
|
33
31
|
/**
|