@codebolt/codeboltjs 1.1.95 → 1.1.97
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/{src/modules → bkp}/toolBox.bkp.ts +0 -3
- package/modules/agent.js +1 -1
- package/modules/agentlib/agent.d.ts +63 -0
- package/modules/agentlib/agent.js +57 -7
- package/modules/agentlib/taskInstruction.d.ts +37 -0
- package/modules/agentlib/taskInstruction.js +20 -0
- package/modules/agentlib/usermessage.d.ts +68 -0
- package/modules/agentlib/usermessage.js +43 -0
- package/modules/chat.js +0 -6
- package/modules/codeparsers.js +0 -2
- package/modules/codeutils.js +0 -1
- package/modules/history.d.ts +22 -0
- package/modules/history.js +22 -0
- package/modules/rag.js +0 -1
- package/modules/search.js +0 -3
- package/modules/terminal.js +0 -1
- package/modules/toolBox.d.ts +202 -2
- package/modules/toolBox.js +53 -35
- package/modules/tools.d.ts +58 -0
- package/modules/tools.js +58 -0
- package/modules/websocket.js +0 -3
- package/package.json +1 -1
- package/src/modules/agent.ts +1 -1
- package/src/modules/agentlib/agent.ts +84 -9
- package/src/modules/agentlib/taskInstruction.ts +43 -4
- package/src/modules/agentlib/usermessage.ts +82 -8
- package/src/modules/chat.ts +0 -6
- package/src/modules/codeparsers.ts +0 -2
- package/src/modules/codeutils.ts +0 -1
- package/src/modules/history.ts +23 -2
- package/src/modules/rag.ts +0 -1
- package/src/modules/search.ts +0 -3
- package/src/modules/terminal.ts +0 -1
- package/src/modules/toolBox.ts +218 -40
- package/src/modules/tools.ts +67 -0
- package/src/modules/websocket.ts +0 -3
- package/modules/mcp.d.ts +0 -9
- package/modules/mcp.js +0 -148
- package/modules/toolBox.bkp.d.ts +0 -262
- package/modules/toolBox.bkp.js +0 -721
- package/src/modules/agentlib/package-lock.json +0 -282
- package/src/modules/agentlib/package.json +0 -6
|
@@ -73,7 +73,6 @@ export const imageContent = async (
|
|
|
73
73
|
}
|
|
74
74
|
const { fileTypeFromBuffer } = await loadEsm('file-type');
|
|
75
75
|
const mimeType = await fileTypeFromBuffer(rawData);
|
|
76
|
-
console.log(mimeType);
|
|
77
76
|
|
|
78
77
|
const base64Data = rawData.toString("base64");
|
|
79
78
|
|
|
@@ -1074,7 +1073,6 @@ export class ToolBox extends FastMCPEventEmitter {
|
|
|
1074
1073
|
) {
|
|
1075
1074
|
if (options.transportType === "stdio") {
|
|
1076
1075
|
const transport = new StdioServerTransport();
|
|
1077
|
-
// console.log("tools", this.#tools);
|
|
1078
1076
|
|
|
1079
1077
|
const session = new FastMCPSession({
|
|
1080
1078
|
name: this.#options.name,
|
|
@@ -1084,7 +1082,6 @@ export class ToolBox extends FastMCPEventEmitter {
|
|
|
1084
1082
|
resourcesTemplates: this.#resourcesTemplates,
|
|
1085
1083
|
prompts: this.#prompts,
|
|
1086
1084
|
});
|
|
1087
|
-
// console.log("session", session);
|
|
1088
1085
|
await session.connect(transport);
|
|
1089
1086
|
|
|
1090
1087
|
this.#sessions.push(session);
|
package/modules/agent.js
CHANGED
|
@@ -63,7 +63,7 @@ const codeboltAgent = {
|
|
|
63
63
|
}));
|
|
64
64
|
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
65
65
|
const response = JSON.parse(data);
|
|
66
|
-
if (response.type === "taskCompletionResponse") {
|
|
66
|
+
if (response.type === "taskCompletionResponse" && response.agentId === agentId) {
|
|
67
67
|
resolve(response); // Resolve the Promise when the agent has been successfully started
|
|
68
68
|
}
|
|
69
69
|
});
|
|
@@ -1,23 +1,86 @@
|
|
|
1
1
|
import { SystemPrompt } from "./systemprompt";
|
|
2
2
|
import { TaskInstruction } from "./taskInstruction";
|
|
3
|
+
/**
|
|
4
|
+
* Agent class that manages conversations with LLMs and tool executions.
|
|
5
|
+
* Handles the conversation flow, tool calls, and task completions.
|
|
6
|
+
*/
|
|
3
7
|
declare class Agent {
|
|
8
|
+
/** Available tools for the agent to use */
|
|
4
9
|
private tools;
|
|
10
|
+
/** Full conversation history for API calls */
|
|
5
11
|
private apiConversationHistory;
|
|
12
|
+
/** Maximum number of conversation turns (0 means unlimited) */
|
|
6
13
|
private maxRun;
|
|
14
|
+
/** System prompt that provides instructions to the model */
|
|
7
15
|
private systemPrompt;
|
|
16
|
+
/** Messages from the user */
|
|
8
17
|
private userMessage;
|
|
18
|
+
/** The next user message to be added to the conversation */
|
|
9
19
|
private nextUserMessage;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new Agent instance.
|
|
22
|
+
*
|
|
23
|
+
* @param tools - The tools available to the agent
|
|
24
|
+
* @param systemPrompt - The system prompt providing instructions to the LLM
|
|
25
|
+
* @param maxRun - Maximum number of conversation turns (0 means unlimited)
|
|
26
|
+
*/
|
|
10
27
|
constructor(tools: any, systemPrompt: SystemPrompt, maxRun?: number);
|
|
28
|
+
/**
|
|
29
|
+
* Runs the agent on a specific task until completion or max runs reached.
|
|
30
|
+
*
|
|
31
|
+
* @param task - The task instruction to be executed
|
|
32
|
+
* @param successCondition - Optional function to determine if the task is successful
|
|
33
|
+
* @returns Promise with success status, error (if any), and the last assistant message
|
|
34
|
+
*/
|
|
11
35
|
run(task: TaskInstruction, successCondition?: () => boolean): Promise<{
|
|
12
36
|
success: boolean;
|
|
13
37
|
error: string | null;
|
|
14
38
|
message: string | null;
|
|
15
39
|
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Attempts to make a request to the LLM with conversation history and tools.
|
|
42
|
+
*
|
|
43
|
+
* @param apiConversationHistory - The current conversation history
|
|
44
|
+
* @param tools - The tools available to the LLM
|
|
45
|
+
* @returns Promise with the LLM response
|
|
46
|
+
*/
|
|
16
47
|
private attemptLlmRequest;
|
|
48
|
+
/**
|
|
49
|
+
* Executes a tool with given name and input.
|
|
50
|
+
*
|
|
51
|
+
* @param toolName - The name of the tool to execute
|
|
52
|
+
* @param toolInput - The input parameters for the tool
|
|
53
|
+
* @returns Promise with tuple [userRejected, result]
|
|
54
|
+
*/
|
|
17
55
|
private executeTool;
|
|
56
|
+
/**
|
|
57
|
+
* Starts a sub-agent to handle a specific task.
|
|
58
|
+
*
|
|
59
|
+
* @param agentName - The name of the sub-agent to start
|
|
60
|
+
* @param params - Parameters for the sub-agent
|
|
61
|
+
* @returns Promise with tuple [userRejected, result]
|
|
62
|
+
*/
|
|
18
63
|
private startSubAgent;
|
|
64
|
+
/**
|
|
65
|
+
* Extracts tool details from a tool call object.
|
|
66
|
+
*
|
|
67
|
+
* @param tool - The tool call object from the LLM response
|
|
68
|
+
* @returns ToolDetails object with name, input, and ID
|
|
69
|
+
*/
|
|
19
70
|
private getToolDetail;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a tool result object from the tool execution response.
|
|
73
|
+
*
|
|
74
|
+
* @param tool_call_id - The ID of the tool call
|
|
75
|
+
* @param content - The content returned by the tool
|
|
76
|
+
* @returns ToolResult object
|
|
77
|
+
*/
|
|
20
78
|
private getToolResult;
|
|
79
|
+
/**
|
|
80
|
+
* Fallback method for API requests in case of failures.
|
|
81
|
+
*
|
|
82
|
+
* @throws Error API request fallback not implemented
|
|
83
|
+
*/
|
|
21
84
|
private attemptApiRequest;
|
|
22
85
|
}
|
|
23
86
|
export { Agent };
|
|
@@ -8,7 +8,18 @@ const chat_1 = __importDefault(require("./../chat"));
|
|
|
8
8
|
const tools_1 = __importDefault(require("./../tools"));
|
|
9
9
|
const llm_1 = __importDefault(require("./../llm"));
|
|
10
10
|
const agent_1 = __importDefault(require("./../agent"));
|
|
11
|
+
/**
|
|
12
|
+
* Agent class that manages conversations with LLMs and tool executions.
|
|
13
|
+
* Handles the conversation flow, tool calls, and task completions.
|
|
14
|
+
*/
|
|
11
15
|
class Agent {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new Agent instance.
|
|
18
|
+
*
|
|
19
|
+
* @param tools - The tools available to the agent
|
|
20
|
+
* @param systemPrompt - The system prompt providing instructions to the LLM
|
|
21
|
+
* @param maxRun - Maximum number of conversation turns (0 means unlimited)
|
|
22
|
+
*/
|
|
12
23
|
constructor(tools = [], systemPrompt, maxRun = 0) {
|
|
13
24
|
this.tools = tools;
|
|
14
25
|
this.userMessage = [];
|
|
@@ -16,6 +27,13 @@ class Agent {
|
|
|
16
27
|
this.maxRun = maxRun;
|
|
17
28
|
this.systemPrompt = systemPrompt;
|
|
18
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Runs the agent on a specific task until completion or max runs reached.
|
|
32
|
+
*
|
|
33
|
+
* @param task - The task instruction to be executed
|
|
34
|
+
* @param successCondition - Optional function to determine if the task is successful
|
|
35
|
+
* @returns Promise with success status, error (if any), and the last assistant message
|
|
36
|
+
*/
|
|
19
37
|
async run(task, successCondition = () => true) {
|
|
20
38
|
var _a, _b;
|
|
21
39
|
let mentaionedMCPSTool = await task.userMessage.getMentionedMcpsTools();
|
|
@@ -84,11 +102,8 @@ class Agent {
|
|
|
84
102
|
else {
|
|
85
103
|
let [serverName] = toolName.replace('--', ':').split(':');
|
|
86
104
|
if (serverName == 'subagent') {
|
|
87
|
-
console.log("calling agent with params", toolName, toolInput);
|
|
88
105
|
const agentResponse = await agent_1.default.startAgent(toolName.replace("subagent--", ''), toolInput.task);
|
|
89
|
-
console.log("got sub agent resonse result", agentResponse);
|
|
90
106
|
const [didUserReject, result] = [false, "tool result is successful"];
|
|
91
|
-
console.log("got sub agent resonse result", didUserReject, result);
|
|
92
107
|
let toolResult = this.getToolResult(toolUseId, result);
|
|
93
108
|
toolResults.push({
|
|
94
109
|
role: "tool",
|
|
@@ -106,9 +121,7 @@ class Agent {
|
|
|
106
121
|
}
|
|
107
122
|
}
|
|
108
123
|
else {
|
|
109
|
-
console.log("calling tool with params", toolName, toolInput);
|
|
110
124
|
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
|
|
111
|
-
console.log("tool result", result);
|
|
112
125
|
// toolResults.push(this.getToolResult(toolUseId, result));
|
|
113
126
|
let toolResult = this.getToolResult(toolUseId, result);
|
|
114
127
|
toolResults.push({
|
|
@@ -199,6 +212,13 @@ class Agent {
|
|
|
199
212
|
.pop()) === null || _b === void 0 ? void 0 : _b.content) || ''
|
|
200
213
|
};
|
|
201
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Attempts to make a request to the LLM with conversation history and tools.
|
|
217
|
+
*
|
|
218
|
+
* @param apiConversationHistory - The current conversation history
|
|
219
|
+
* @param tools - The tools available to the LLM
|
|
220
|
+
* @returns Promise with the LLM response
|
|
221
|
+
*/
|
|
202
222
|
async attemptLlmRequest(apiConversationHistory, tools) {
|
|
203
223
|
try {
|
|
204
224
|
let systemPrompt = await this.systemPrompt.toPromptText();
|
|
@@ -217,18 +237,37 @@ class Agent {
|
|
|
217
237
|
return completion;
|
|
218
238
|
}
|
|
219
239
|
catch (error) {
|
|
220
|
-
console.log(error);
|
|
221
240
|
return this.attemptApiRequest();
|
|
222
241
|
}
|
|
223
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Executes a tool with given name and input.
|
|
245
|
+
*
|
|
246
|
+
* @param toolName - The name of the tool to execute
|
|
247
|
+
* @param toolInput - The input parameters for the tool
|
|
248
|
+
* @returns Promise with tuple [userRejected, result]
|
|
249
|
+
*/
|
|
224
250
|
async executeTool(toolName, toolInput) {
|
|
225
251
|
//codebolttools--readfile
|
|
226
252
|
const [toolboxName, actualToolName] = toolName.split('--');
|
|
227
253
|
return tools_1.default.executeTool(toolboxName, actualToolName, toolInput);
|
|
228
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Starts a sub-agent to handle a specific task.
|
|
257
|
+
*
|
|
258
|
+
* @param agentName - The name of the sub-agent to start
|
|
259
|
+
* @param params - Parameters for the sub-agent
|
|
260
|
+
* @returns Promise with tuple [userRejected, result]
|
|
261
|
+
*/
|
|
229
262
|
async startSubAgent(agentName, params) {
|
|
230
263
|
return agent_1.default.startAgent(agentName, params.task);
|
|
231
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Extracts tool details from a tool call object.
|
|
267
|
+
*
|
|
268
|
+
* @param tool - The tool call object from the LLM response
|
|
269
|
+
* @returns ToolDetails object with name, input, and ID
|
|
270
|
+
*/
|
|
232
271
|
getToolDetail(tool) {
|
|
233
272
|
return {
|
|
234
273
|
toolName: tool.function.name,
|
|
@@ -236,6 +275,13 @@ class Agent {
|
|
|
236
275
|
toolUseId: tool.id
|
|
237
276
|
};
|
|
238
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Creates a tool result object from the tool execution response.
|
|
280
|
+
*
|
|
281
|
+
* @param tool_call_id - The ID of the tool call
|
|
282
|
+
* @param content - The content returned by the tool
|
|
283
|
+
* @returns ToolResult object
|
|
284
|
+
*/
|
|
239
285
|
getToolResult(tool_call_id, content) {
|
|
240
286
|
let userMessage = undefined;
|
|
241
287
|
try {
|
|
@@ -255,7 +301,11 @@ class Agent {
|
|
|
255
301
|
userMessage
|
|
256
302
|
};
|
|
257
303
|
}
|
|
258
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Fallback method for API requests in case of failures.
|
|
306
|
+
*
|
|
307
|
+
* @throws Error API request fallback not implemented
|
|
308
|
+
*/
|
|
259
309
|
attemptApiRequest() {
|
|
260
310
|
throw new Error("API request fallback not implemented");
|
|
261
311
|
}
|
|
@@ -1,22 +1,59 @@
|
|
|
1
1
|
import { UserMessage, UserMessageContent } from "./usermessage";
|
|
2
|
+
/**
|
|
3
|
+
* Interface for tools that can be used within tasks.
|
|
4
|
+
* Each tool has a description and usage example.
|
|
5
|
+
*/
|
|
2
6
|
interface Tools {
|
|
3
7
|
[key: string]: {
|
|
8
|
+
/** Description of what the tool does */
|
|
4
9
|
description: string;
|
|
10
|
+
/** How to use the tool correctly */
|
|
5
11
|
usage: string;
|
|
12
|
+
/** Optional example demonstrating tool usage */
|
|
6
13
|
example?: string;
|
|
7
14
|
};
|
|
8
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Interface for user message structure.
|
|
18
|
+
* Contains message type and text content.
|
|
19
|
+
*/
|
|
9
20
|
interface UserMessages {
|
|
21
|
+
/** The type of user message */
|
|
10
22
|
type: string;
|
|
23
|
+
/** The text content of the message */
|
|
11
24
|
text: string;
|
|
12
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Class representing a task instruction.
|
|
28
|
+
* Handles loading task data and converting it to prompts.
|
|
29
|
+
*/
|
|
13
30
|
declare class TaskInstruction {
|
|
31
|
+
/** Available tools for the task */
|
|
14
32
|
tools: Tools;
|
|
33
|
+
/** Messages from the user for this task */
|
|
15
34
|
userMessages: UserMessageContent[];
|
|
35
|
+
/** The user message object containing input */
|
|
16
36
|
userMessage: UserMessage;
|
|
37
|
+
/** Path to the YAML file with task instructions */
|
|
17
38
|
filepath: string;
|
|
39
|
+
/** The section reference within the YAML file */
|
|
18
40
|
refsection: string;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new TaskInstruction instance.
|
|
43
|
+
*
|
|
44
|
+
* @param tools - Tools available for this task
|
|
45
|
+
* @param userMessage - User message containing task instructions
|
|
46
|
+
* @param filepath - Path to the YAML file with task data
|
|
47
|
+
* @param refsection - Section name within the YAML file
|
|
48
|
+
*/
|
|
19
49
|
constructor(tools: Tools | undefined, userMessage: UserMessage, filepath?: string, refsection?: string);
|
|
50
|
+
/**
|
|
51
|
+
* Converts the task instruction to a prompt format.
|
|
52
|
+
* Loads data from YAML file and combines with user message.
|
|
53
|
+
*
|
|
54
|
+
* @returns Promise with an array of user message content blocks
|
|
55
|
+
* @throws Error if there's an issue processing the task instruction
|
|
56
|
+
*/
|
|
20
57
|
toPrompt(): Promise<UserMessages[]>;
|
|
21
58
|
}
|
|
22
59
|
export { TaskInstruction };
|
|
@@ -8,14 +8,34 @@ exports.TaskInstruction = void 0;
|
|
|
8
8
|
const yaml = require('js-yaml');
|
|
9
9
|
const fs = require('fs');
|
|
10
10
|
const path = require('path');
|
|
11
|
+
/**
|
|
12
|
+
* Class representing a task instruction.
|
|
13
|
+
* Handles loading task data and converting it to prompts.
|
|
14
|
+
*/
|
|
11
15
|
class TaskInstruction {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new TaskInstruction instance.
|
|
18
|
+
*
|
|
19
|
+
* @param tools - Tools available for this task
|
|
20
|
+
* @param userMessage - User message containing task instructions
|
|
21
|
+
* @param filepath - Path to the YAML file with task data
|
|
22
|
+
* @param refsection - Section name within the YAML file
|
|
23
|
+
*/
|
|
12
24
|
constructor(tools = {}, userMessage, filepath = "", refsection = "") {
|
|
25
|
+
/** Messages from the user for this task */
|
|
13
26
|
this.userMessages = [];
|
|
14
27
|
this.tools = tools;
|
|
15
28
|
this.userMessage = userMessage;
|
|
16
29
|
this.filepath = filepath;
|
|
17
30
|
this.refsection = refsection;
|
|
18
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Converts the task instruction to a prompt format.
|
|
34
|
+
* Loads data from YAML file and combines with user message.
|
|
35
|
+
*
|
|
36
|
+
* @returns Promise with an array of user message content blocks
|
|
37
|
+
* @throws Error if there's an issue processing the task instruction
|
|
38
|
+
*/
|
|
19
39
|
async toPrompt() {
|
|
20
40
|
try {
|
|
21
41
|
this.userMessages = await this.userMessage.toPrompt();
|
|
@@ -1,32 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface representing an agent that can be referenced in user messages.
|
|
3
|
+
*/
|
|
1
4
|
interface agent {
|
|
5
|
+
/** Short description of the agent */
|
|
2
6
|
description: string;
|
|
7
|
+
/** Title/name of the agent */
|
|
3
8
|
title: string;
|
|
9
|
+
/** Numeric ID of the agent */
|
|
4
10
|
id: number;
|
|
11
|
+
/** Agent identifier string */
|
|
5
12
|
agent_id: string;
|
|
13
|
+
/** Unique identifier for the agent */
|
|
6
14
|
unique_id: string;
|
|
15
|
+
/** Detailed description of the agent and its capabilities */
|
|
7
16
|
longDescription: string;
|
|
8
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Interface for the user message structure.
|
|
20
|
+
*/
|
|
9
21
|
interface Message {
|
|
22
|
+
/** The actual text content of the user message */
|
|
10
23
|
userMessage: string;
|
|
24
|
+
/** Optional list of files mentioned in the message */
|
|
11
25
|
mentionedFiles?: string[];
|
|
26
|
+
/** List of MCP (Model Context Protocol) tools mentioned */
|
|
12
27
|
mentionedMCPs: string[];
|
|
28
|
+
/** List of agents mentioned in the message */
|
|
13
29
|
mentionedAgents: agent[];
|
|
14
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Interface for a single content block within a user message.
|
|
33
|
+
*/
|
|
15
34
|
export interface UserMessageContent {
|
|
35
|
+
/** Type of content (e.g., "text", "image") */
|
|
16
36
|
type: string;
|
|
37
|
+
/** The text content */
|
|
17
38
|
text: string;
|
|
18
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Class that processes and manages user messages.
|
|
42
|
+
* Handles converting messages to prompts and extracting mentioned entities.
|
|
43
|
+
*/
|
|
19
44
|
declare class UserMessage {
|
|
45
|
+
/** The message content and metadata */
|
|
20
46
|
message: Message;
|
|
47
|
+
/** Whether to override the default prompt generation */
|
|
21
48
|
promptOverride: boolean;
|
|
49
|
+
/** Array of content blocks for the user message */
|
|
22
50
|
userMessages: UserMessageContent[];
|
|
51
|
+
/** List of MCP tools mentioned in the message */
|
|
23
52
|
mentionedMCPs: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new UserMessage instance.
|
|
55
|
+
*
|
|
56
|
+
* @param message - The message content and metadata
|
|
57
|
+
* @param promptOverride - Whether to override default prompt generation
|
|
58
|
+
*/
|
|
24
59
|
constructor(message: Message, promptOverride?: boolean);
|
|
60
|
+
/**
|
|
61
|
+
* Gets files mentioned in the message.
|
|
62
|
+
* Currently a placeholder for implementation.
|
|
63
|
+
*/
|
|
25
64
|
getFiles(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Converts the user message to a prompt format.
|
|
67
|
+
*
|
|
68
|
+
* @param bAttachFiles - Whether to attach file contents
|
|
69
|
+
* @param bAttachImages - Whether to attach images
|
|
70
|
+
* @param bAttachEnvironment - Whether to attach environment details
|
|
71
|
+
* @returns Promise with an array of content blocks for the prompt
|
|
72
|
+
*/
|
|
26
73
|
toPrompt(bAttachFiles?: boolean, bAttachImages?: boolean, bAttachEnvironment?: boolean): Promise<UserMessageContent[]>;
|
|
74
|
+
/**
|
|
75
|
+
* Gets agents mentioned in the message.
|
|
76
|
+
*
|
|
77
|
+
* @returns Array of agent objects
|
|
78
|
+
*/
|
|
27
79
|
getMentionedAgents(): agent[];
|
|
80
|
+
/**
|
|
81
|
+
* Gets MCP tools mentioned in the message.
|
|
82
|
+
*
|
|
83
|
+
* @returns Array of MCP tool names
|
|
84
|
+
*/
|
|
28
85
|
getMentionedMcps(): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Gets MCP tools in a format suitable for the LLM.
|
|
88
|
+
*
|
|
89
|
+
* @returns Promise with an array of MCP tools
|
|
90
|
+
*/
|
|
29
91
|
getMentionedMcpsTools(): Promise<any>;
|
|
92
|
+
/**
|
|
93
|
+
* Gets environment details for the current working directory.
|
|
94
|
+
*
|
|
95
|
+
* @param cwd - The current working directory path
|
|
96
|
+
* @returns Promise with a string containing environment details
|
|
97
|
+
*/
|
|
30
98
|
private getEnvironmentDetail;
|
|
31
99
|
}
|
|
32
100
|
export { UserMessage };
|
|
@@ -7,8 +7,24 @@ exports.UserMessage = void 0;
|
|
|
7
7
|
const fs_1 = __importDefault(require("./../fs"));
|
|
8
8
|
const project_1 = __importDefault(require("./../project"));
|
|
9
9
|
const tools_1 = __importDefault(require("./../tools"));
|
|
10
|
+
/**
|
|
11
|
+
* Class that processes and manages user messages.
|
|
12
|
+
* Handles converting messages to prompts and extracting mentioned entities.
|
|
13
|
+
*/
|
|
10
14
|
class UserMessage {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new UserMessage instance.
|
|
17
|
+
*
|
|
18
|
+
* @param message - The message content and metadata
|
|
19
|
+
* @param promptOverride - Whether to override default prompt generation
|
|
20
|
+
*/
|
|
11
21
|
constructor(message, promptOverride = false) {
|
|
22
|
+
/**
|
|
23
|
+
* Gets environment details for the current working directory.
|
|
24
|
+
*
|
|
25
|
+
* @param cwd - The current working directory path
|
|
26
|
+
* @returns Promise with a string containing environment details
|
|
27
|
+
*/
|
|
12
28
|
this.getEnvironmentDetail = async (cwd) => {
|
|
13
29
|
let details = "";
|
|
14
30
|
const { success, result } = await fs_1.default.listFile(cwd, true);
|
|
@@ -23,9 +39,21 @@ class UserMessage {
|
|
|
23
39
|
this.userMessages = [];
|
|
24
40
|
this.mentionedMCPs = message.mentionedMCPs || [];
|
|
25
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Gets files mentioned in the message.
|
|
44
|
+
* Currently a placeholder for implementation.
|
|
45
|
+
*/
|
|
26
46
|
getFiles() {
|
|
27
47
|
// Implementation to be added
|
|
28
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Converts the user message to a prompt format.
|
|
51
|
+
*
|
|
52
|
+
* @param bAttachFiles - Whether to attach file contents
|
|
53
|
+
* @param bAttachImages - Whether to attach images
|
|
54
|
+
* @param bAttachEnvironment - Whether to attach environment details
|
|
55
|
+
* @returns Promise with an array of content blocks for the prompt
|
|
56
|
+
*/
|
|
29
57
|
async toPrompt(bAttachFiles = true, bAttachImages = true, bAttachEnvironment = true) {
|
|
30
58
|
var _a;
|
|
31
59
|
if (bAttachFiles) {
|
|
@@ -54,13 +82,28 @@ class UserMessage {
|
|
|
54
82
|
}
|
|
55
83
|
return this.userMessages;
|
|
56
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets agents mentioned in the message.
|
|
87
|
+
*
|
|
88
|
+
* @returns Array of agent objects
|
|
89
|
+
*/
|
|
57
90
|
getMentionedAgents() {
|
|
58
91
|
//TODO : get config in tool format if neede
|
|
59
92
|
return this.message.mentionedAgents || [];
|
|
60
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets MCP tools mentioned in the message.
|
|
96
|
+
*
|
|
97
|
+
* @returns Array of MCP tool names
|
|
98
|
+
*/
|
|
61
99
|
getMentionedMcps() {
|
|
62
100
|
return this.message.mentionedMCPs || [];
|
|
63
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Gets MCP tools in a format suitable for the LLM.
|
|
104
|
+
*
|
|
105
|
+
* @returns Promise with an array of MCP tools
|
|
106
|
+
*/
|
|
64
107
|
async getMentionedMcpsTools() {
|
|
65
108
|
if (this.mentionedMCPs.length > 0) {
|
|
66
109
|
let tools = await tools_1.default.listToolsFromToolBoxes(this.mentionedMCPs);
|
package/modules/chat.js
CHANGED
|
@@ -79,7 +79,6 @@ const cbchat = {
|
|
|
79
79
|
const response = JSON.parse(data);
|
|
80
80
|
if (response.type === "messageResponse") {
|
|
81
81
|
eventEmitter.emit("userMessage", response, (message) => {
|
|
82
|
-
console.log("Callback function invoked with message:", message);
|
|
83
82
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
84
83
|
"type": "processStoped",
|
|
85
84
|
"message": message
|
|
@@ -100,7 +99,6 @@ const cbchat = {
|
|
|
100
99
|
* @param {string} message - The message to be sent.
|
|
101
100
|
*/
|
|
102
101
|
sendMessage: (message, payload) => {
|
|
103
|
-
console.log(message);
|
|
104
102
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
105
103
|
"type": "sendMessage",
|
|
106
104
|
"message": message,
|
|
@@ -138,7 +136,6 @@ const cbchat = {
|
|
|
138
136
|
// Register event listener for WebSocket messages
|
|
139
137
|
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
140
138
|
const message = JSON.parse(data);
|
|
141
|
-
console.log("Received message:", message);
|
|
142
139
|
if (message.type === 'stopProcessClicked')
|
|
143
140
|
// Emit a custom event based on the message type
|
|
144
141
|
eventEmitter.emit("stopProcessClicked", message);
|
|
@@ -148,7 +145,6 @@ const cbchat = {
|
|
|
148
145
|
event: eventEmitter,
|
|
149
146
|
stopProcess: () => {
|
|
150
147
|
// Implement the logic to stop the process here
|
|
151
|
-
console.log("Stopping process...");
|
|
152
148
|
// For example, you might want to send a specific message to the server to stop the process
|
|
153
149
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
154
150
|
"type": "processStoped"
|
|
@@ -162,7 +158,6 @@ const cbchat = {
|
|
|
162
158
|
*/
|
|
163
159
|
stopProcess: () => {
|
|
164
160
|
// Implement the logic to stop the process here
|
|
165
|
-
console.log("Stopping process...");
|
|
166
161
|
// For example, you might want to send a specific message to the server to stop the process
|
|
167
162
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
168
163
|
"type": "processStoped"
|
|
@@ -174,7 +169,6 @@ const cbchat = {
|
|
|
174
169
|
*/
|
|
175
170
|
processFinished: () => {
|
|
176
171
|
// Implement the logic to stop the process here
|
|
177
|
-
console.log("Process Finished ...");
|
|
178
172
|
// For example, you might want to send a specific message to the server to stop the process
|
|
179
173
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
180
174
|
"type": "processFinished"
|
package/modules/codeparsers.js
CHANGED
|
@@ -9,7 +9,6 @@ const cbcodeparsers = {
|
|
|
9
9
|
* @param file The file to parse for classes.
|
|
10
10
|
*/
|
|
11
11
|
getClassesInFile: (file) => {
|
|
12
|
-
console.log('Code parsers initialized');
|
|
13
12
|
},
|
|
14
13
|
/**
|
|
15
14
|
* Retrieves the functions in a given class within a file.
|
|
@@ -17,7 +16,6 @@ const cbcodeparsers = {
|
|
|
17
16
|
* @param className The name of the class to parse for functions.
|
|
18
17
|
*/
|
|
19
18
|
getFunctionsinClass: (file, className) => {
|
|
20
|
-
console.log('Code parsers initialized');
|
|
21
19
|
},
|
|
22
20
|
/**
|
|
23
21
|
* Generates an Abstract Syntax Tree (AST) for a given file.
|
package/modules/codeutils.js
CHANGED
|
@@ -68,7 +68,6 @@ const cbcodeutils = {
|
|
|
68
68
|
}
|
|
69
69
|
else if (path_1.default.extname(file.name) === '.js') {
|
|
70
70
|
const code = fs.readFileSync(path_1.default.join(directory, file.name), 'utf-8');
|
|
71
|
-
console.log(code);
|
|
72
71
|
let tree = parser.parse(code);
|
|
73
72
|
tree.rootNode.path = path_1.default.join(directory, file.name); // Set file path for t
|
|
74
73
|
trees.push(tree);
|
package/modules/history.d.ts
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing different types of log messages.
|
|
3
|
+
*/
|
|
1
4
|
export declare enum logType {
|
|
5
|
+
/** Informational messages */
|
|
2
6
|
info = "info",
|
|
7
|
+
/** Error messages */
|
|
3
8
|
error = "error",
|
|
9
|
+
/** Warning messages */
|
|
4
10
|
warning = "warning"
|
|
5
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Object with methods for summarizing chat history.
|
|
14
|
+
* Provides functionality to create summaries of conversation history.
|
|
15
|
+
*/
|
|
6
16
|
export declare const chatSummary: {
|
|
17
|
+
/**
|
|
18
|
+
* Summarizes the entire chat history.
|
|
19
|
+
*
|
|
20
|
+
* @returns Promise with an array of message objects containing role and content
|
|
21
|
+
*/
|
|
7
22
|
summarizeAll: () => Promise<{
|
|
8
23
|
role: string;
|
|
9
24
|
content: string;
|
|
10
25
|
}[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Summarizes a specific part of the chat history.
|
|
28
|
+
*
|
|
29
|
+
* @param messages - Array of message objects to summarize
|
|
30
|
+
* @param depth - How far back in history to consider
|
|
31
|
+
* @returns Promise with an array of summarized message objects
|
|
32
|
+
*/
|
|
11
33
|
summarize: (messages: {
|
|
12
34
|
role: string;
|
|
13
35
|
content: string;
|
package/modules/history.js
CHANGED
|
@@ -5,13 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.chatSummary = exports.logType = void 0;
|
|
7
7
|
const websocket_1 = __importDefault(require("./websocket"));
|
|
8
|
+
/**
|
|
9
|
+
* Enum representing different types of log messages.
|
|
10
|
+
*/
|
|
8
11
|
var logType;
|
|
9
12
|
(function (logType) {
|
|
13
|
+
/** Informational messages */
|
|
10
14
|
logType["info"] = "info";
|
|
15
|
+
/** Error messages */
|
|
11
16
|
logType["error"] = "error";
|
|
17
|
+
/** Warning messages */
|
|
12
18
|
logType["warning"] = "warning";
|
|
13
19
|
})(logType || (exports.logType = logType = {}));
|
|
20
|
+
/**
|
|
21
|
+
* Object with methods for summarizing chat history.
|
|
22
|
+
* Provides functionality to create summaries of conversation history.
|
|
23
|
+
*/
|
|
14
24
|
exports.chatSummary = {
|
|
25
|
+
/**
|
|
26
|
+
* Summarizes the entire chat history.
|
|
27
|
+
*
|
|
28
|
+
* @returns Promise with an array of message objects containing role and content
|
|
29
|
+
*/
|
|
15
30
|
summarizeAll: () => {
|
|
16
31
|
return new Promise((resolve, reject) => {
|
|
17
32
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
@@ -26,6 +41,13 @@ exports.chatSummary = {
|
|
|
26
41
|
});
|
|
27
42
|
});
|
|
28
43
|
},
|
|
44
|
+
/**
|
|
45
|
+
* Summarizes a specific part of the chat history.
|
|
46
|
+
*
|
|
47
|
+
* @param messages - Array of message objects to summarize
|
|
48
|
+
* @param depth - How far back in history to consider
|
|
49
|
+
* @returns Promise with an array of summarized message objects
|
|
50
|
+
*/
|
|
29
51
|
summarize: (messages, depth) => {
|
|
30
52
|
return new Promise((resolve, reject) => {
|
|
31
53
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|