@codebolt/codeboltjs 1.1.95 → 1.1.96
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/modules/agent.js +1 -1
- package/modules/agentlib/agent.d.ts +63 -0
- package/modules/agentlib/agent.js +57 -1
- 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/history.d.ts +22 -0
- package/modules/history.js +22 -0
- 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/package.json +1 -1
- package/src/modules/agent.ts +1 -1
- package/src/modules/agentlib/agent.ts +84 -3
- package/src/modules/agentlib/taskInstruction.ts +43 -4
- package/src/modules/agentlib/usermessage.ts +82 -8
- package/src/modules/history.ts +23 -2
- package/src/modules/toolBox.ts +218 -40
- package/src/modules/tools.ts +67 -0
- package/src/modules/agentlib/package-lock.json +0 -282
- package/src/modules/agentlib/package.json +0 -6
- /package/{src/modules → bkp}/toolBox.bkp.ts +0 -0
package/modules/tools.d.ts
CHANGED
|
@@ -1,16 +1,74 @@
|
|
|
1
1
|
import { UserMessage } from '../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Object containing methods for interacting with Codebolt MCP (Model Context Protocol) tools.
|
|
4
|
+
* Provides functionality to discover, list, and execute tools.
|
|
5
|
+
*/
|
|
2
6
|
declare const codeboltMCP: {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the list of currently enabled toolboxes.
|
|
9
|
+
*
|
|
10
|
+
* @returns Promise with the enabled toolboxes data
|
|
11
|
+
*/
|
|
3
12
|
getEnabledToolBoxes: () => Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the list of locally available toolboxes.
|
|
15
|
+
*
|
|
16
|
+
* @returns Promise with the local toolboxes data
|
|
17
|
+
*/
|
|
4
18
|
getLocalToolBoxes: () => Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Gets toolboxes mentioned in a user message.
|
|
21
|
+
*
|
|
22
|
+
* @param userMessage - The user message to extract mentions from
|
|
23
|
+
* @returns Promise with the mentioned toolboxes
|
|
24
|
+
*/
|
|
5
25
|
getMentionedToolBoxes: (userMessage: UserMessage) => Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* Gets all available toolboxes.
|
|
28
|
+
*
|
|
29
|
+
* @returns Promise with all available toolboxes data
|
|
30
|
+
*/
|
|
6
31
|
getAvailableToolBoxes: () => Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Searches for available toolboxes matching a query.
|
|
34
|
+
*
|
|
35
|
+
* @param query - The search query string
|
|
36
|
+
* @returns Promise with matching toolboxes data
|
|
37
|
+
*/
|
|
7
38
|
searchAvailableToolBoxes: (query: string) => Promise<any>;
|
|
39
|
+
/**
|
|
40
|
+
* Lists all tools from the specified toolboxes.
|
|
41
|
+
*
|
|
42
|
+
* @param toolBoxes - Array of toolbox names to list tools from
|
|
43
|
+
* @returns Promise with tools from the specified toolboxes
|
|
44
|
+
*/
|
|
8
45
|
listToolsFromToolBoxes: (toolBoxes: string[]) => Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* Configures a specific toolbox with provided configuration.
|
|
48
|
+
*
|
|
49
|
+
* @param name - The name of the toolbox to configure
|
|
50
|
+
* @param config - Configuration object for the toolbox
|
|
51
|
+
* @returns Promise with the configuration result
|
|
52
|
+
*/
|
|
9
53
|
configureToolBox: (name: string, config: any) => Promise<any>;
|
|
54
|
+
/**
|
|
55
|
+
* Gets detailed information about specific tools.
|
|
56
|
+
*
|
|
57
|
+
* @param tools - Array of toolbox and tool name pairs
|
|
58
|
+
* @returns Promise with detailed information about the tools
|
|
59
|
+
*/
|
|
10
60
|
getTools: (tools: {
|
|
11
61
|
toolbox: string;
|
|
12
62
|
toolName: string;
|
|
13
63
|
}[]) => Promise<any[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Executes a specific tool with provided parameters.
|
|
66
|
+
*
|
|
67
|
+
* @param toolbox - The name of the toolbox containing the tool
|
|
68
|
+
* @param toolName - The name of the tool to execute
|
|
69
|
+
* @param params - Parameters to pass to the tool
|
|
70
|
+
* @returns Promise with the execution result
|
|
71
|
+
*/
|
|
14
72
|
executeTool: (toolbox: string, toolName: string, params: any) => Promise<any>;
|
|
15
73
|
};
|
|
16
74
|
export default codeboltMCP;
|
package/modules/tools.js
CHANGED
|
@@ -4,7 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const websocket_1 = __importDefault(require("./websocket"));
|
|
7
|
+
/**
|
|
8
|
+
* Object containing methods for interacting with Codebolt MCP (Model Context Protocol) tools.
|
|
9
|
+
* Provides functionality to discover, list, and execute tools.
|
|
10
|
+
*/
|
|
7
11
|
const codeboltMCP = {
|
|
12
|
+
/**
|
|
13
|
+
* Gets the list of currently enabled toolboxes.
|
|
14
|
+
*
|
|
15
|
+
* @returns Promise with the enabled toolboxes data
|
|
16
|
+
*/
|
|
8
17
|
getEnabledToolBoxes: () => {
|
|
9
18
|
return new Promise((resolve, reject) => {
|
|
10
19
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
@@ -27,6 +36,11 @@ const codeboltMCP = {
|
|
|
27
36
|
});
|
|
28
37
|
});
|
|
29
38
|
},
|
|
39
|
+
/**
|
|
40
|
+
* Gets the list of locally available toolboxes.
|
|
41
|
+
*
|
|
42
|
+
* @returns Promise with the local toolboxes data
|
|
43
|
+
*/
|
|
30
44
|
getLocalToolBoxes: () => {
|
|
31
45
|
return new Promise((resolve, reject) => {
|
|
32
46
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
@@ -49,11 +63,22 @@ const codeboltMCP = {
|
|
|
49
63
|
});
|
|
50
64
|
});
|
|
51
65
|
},
|
|
66
|
+
/**
|
|
67
|
+
* Gets toolboxes mentioned in a user message.
|
|
68
|
+
*
|
|
69
|
+
* @param userMessage - The user message to extract mentions from
|
|
70
|
+
* @returns Promise with the mentioned toolboxes
|
|
71
|
+
*/
|
|
52
72
|
getMentionedToolBoxes: (userMessage) => {
|
|
53
73
|
return new Promise((resolve, reject) => {
|
|
54
74
|
resolve(userMessage.mentionedMCPs);
|
|
55
75
|
});
|
|
56
76
|
},
|
|
77
|
+
/**
|
|
78
|
+
* Gets all available toolboxes.
|
|
79
|
+
*
|
|
80
|
+
* @returns Promise with all available toolboxes data
|
|
81
|
+
*/
|
|
57
82
|
getAvailableToolBoxes: () => {
|
|
58
83
|
return new Promise((resolve, reject) => {
|
|
59
84
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
@@ -76,6 +101,12 @@ const codeboltMCP = {
|
|
|
76
101
|
});
|
|
77
102
|
});
|
|
78
103
|
},
|
|
104
|
+
/**
|
|
105
|
+
* Searches for available toolboxes matching a query.
|
|
106
|
+
*
|
|
107
|
+
* @param query - The search query string
|
|
108
|
+
* @returns Promise with matching toolboxes data
|
|
109
|
+
*/
|
|
79
110
|
searchAvailableToolBoxes: (query) => {
|
|
80
111
|
return new Promise((resolve, reject) => {
|
|
81
112
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
@@ -99,6 +130,12 @@ const codeboltMCP = {
|
|
|
99
130
|
});
|
|
100
131
|
});
|
|
101
132
|
},
|
|
133
|
+
/**
|
|
134
|
+
* Lists all tools from the specified toolboxes.
|
|
135
|
+
*
|
|
136
|
+
* @param toolBoxes - Array of toolbox names to list tools from
|
|
137
|
+
* @returns Promise with tools from the specified toolboxes
|
|
138
|
+
*/
|
|
102
139
|
listToolsFromToolBoxes: (toolBoxes) => {
|
|
103
140
|
return new Promise((resolve, reject) => {
|
|
104
141
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
@@ -122,6 +159,13 @@ const codeboltMCP = {
|
|
|
122
159
|
});
|
|
123
160
|
});
|
|
124
161
|
},
|
|
162
|
+
/**
|
|
163
|
+
* Configures a specific toolbox with provided configuration.
|
|
164
|
+
*
|
|
165
|
+
* @param name - The name of the toolbox to configure
|
|
166
|
+
* @param config - Configuration object for the toolbox
|
|
167
|
+
* @returns Promise with the configuration result
|
|
168
|
+
*/
|
|
125
169
|
configureToolBox: (name, config) => {
|
|
126
170
|
return new Promise((resolve, reject) => {
|
|
127
171
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
@@ -146,6 +190,12 @@ const codeboltMCP = {
|
|
|
146
190
|
});
|
|
147
191
|
});
|
|
148
192
|
},
|
|
193
|
+
/**
|
|
194
|
+
* Gets detailed information about specific tools.
|
|
195
|
+
*
|
|
196
|
+
* @param tools - Array of toolbox and tool name pairs
|
|
197
|
+
* @returns Promise with detailed information about the tools
|
|
198
|
+
*/
|
|
149
199
|
getTools: (tools) => {
|
|
150
200
|
return new Promise((resolve, reject) => {
|
|
151
201
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
@@ -169,6 +219,14 @@ const codeboltMCP = {
|
|
|
169
219
|
});
|
|
170
220
|
});
|
|
171
221
|
},
|
|
222
|
+
/**
|
|
223
|
+
* Executes a specific tool with provided parameters.
|
|
224
|
+
*
|
|
225
|
+
* @param toolbox - The name of the toolbox containing the tool
|
|
226
|
+
* @param toolName - The name of the tool to execute
|
|
227
|
+
* @param params - Parameters to pass to the tool
|
|
228
|
+
* @returns Promise with the execution result
|
|
229
|
+
*/
|
|
172
230
|
executeTool: (toolbox, toolName, params) => {
|
|
173
231
|
return new Promise((resolve, reject) => {
|
|
174
232
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
package/package.json
CHANGED
package/src/modules/agent.ts
CHANGED
|
@@ -64,7 +64,7 @@ const codeboltAgent = {
|
|
|
64
64
|
}));
|
|
65
65
|
cbws.getWebsocket.on('message', (data: string) => {
|
|
66
66
|
const response = JSON.parse(data);
|
|
67
|
-
if (response.type === "taskCompletionResponse") {
|
|
67
|
+
if (response.type === "taskCompletionResponse" && response.agentId === agentId) {
|
|
68
68
|
resolve(response); // Resolve the Promise when the agent has been successfully started
|
|
69
69
|
}
|
|
70
70
|
});
|
|
@@ -5,36 +5,71 @@ import codeboltAgent from "./../agent"
|
|
|
5
5
|
import { SystemPrompt } from "./systemprompt";
|
|
6
6
|
import { TaskInstruction } from "./taskInstruction";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Represents a message in the conversation with roles and content.
|
|
10
|
+
*/
|
|
8
11
|
interface Message {
|
|
12
|
+
/** The role of the message sender: user, assistant, tool, or system */
|
|
9
13
|
role: 'user' | 'assistant' | 'tool' | 'system';
|
|
14
|
+
/** The content of the message, can be an array of content blocks or a string */
|
|
10
15
|
content: any[] | string;
|
|
16
|
+
/** Optional ID for tool calls */
|
|
11
17
|
tool_call_id?: string;
|
|
18
|
+
/** Additional properties that might be present */
|
|
12
19
|
[key: string]: any;
|
|
13
20
|
}
|
|
14
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Represents the result from a tool execution.
|
|
24
|
+
*/
|
|
15
25
|
interface ToolResult {
|
|
26
|
+
/** Always 'tool' for tool execution results */
|
|
16
27
|
role: 'tool';
|
|
28
|
+
/** ID that links this result to the original tool call */
|
|
17
29
|
tool_call_id: string;
|
|
30
|
+
/** The content returned by the tool */
|
|
18
31
|
content: any;
|
|
32
|
+
/** Optional user message to be added after tool execution */
|
|
19
33
|
userMessage?: any;
|
|
20
34
|
}
|
|
21
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Details about a tool to be executed.
|
|
38
|
+
*/
|
|
22
39
|
interface ToolDetails {
|
|
40
|
+
/** The name of the tool to execute */
|
|
23
41
|
toolName: string;
|
|
42
|
+
/** Input parameters for the tool */
|
|
24
43
|
toolInput: any;
|
|
44
|
+
/** Unique ID for this tool use instance */
|
|
25
45
|
toolUseId: string;
|
|
26
46
|
}
|
|
27
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Agent class that manages conversations with LLMs and tool executions.
|
|
50
|
+
* Handles the conversation flow, tool calls, and task completions.
|
|
51
|
+
*/
|
|
28
52
|
class Agent {
|
|
53
|
+
/** Available tools for the agent to use */
|
|
29
54
|
private tools: any[];
|
|
30
|
-
|
|
55
|
+
/** Full conversation history for API calls */
|
|
31
56
|
private apiConversationHistory: Message[];
|
|
57
|
+
/** Maximum number of conversation turns (0 means unlimited) */
|
|
32
58
|
private maxRun: number;
|
|
59
|
+
/** System prompt that provides instructions to the model */
|
|
33
60
|
private systemPrompt: SystemPrompt;
|
|
61
|
+
/** Messages from the user */
|
|
34
62
|
private userMessage: Message[];
|
|
63
|
+
/** The next user message to be added to the conversation */
|
|
35
64
|
private nextUserMessage:any;
|
|
36
65
|
|
|
37
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new Agent instance.
|
|
68
|
+
*
|
|
69
|
+
* @param tools - The tools available to the agent
|
|
70
|
+
* @param systemPrompt - The system prompt providing instructions to the LLM
|
|
71
|
+
* @param maxRun - Maximum number of conversation turns (0 means unlimited)
|
|
72
|
+
*/
|
|
38
73
|
constructor(tools: any = [], systemPrompt: SystemPrompt, maxRun: number = 0) {
|
|
39
74
|
this.tools = tools;
|
|
40
75
|
this.userMessage = [];
|
|
@@ -44,6 +79,13 @@ class Agent {
|
|
|
44
79
|
|
|
45
80
|
}
|
|
46
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Runs the agent on a specific task until completion or max runs reached.
|
|
84
|
+
*
|
|
85
|
+
* @param task - The task instruction to be executed
|
|
86
|
+
* @param successCondition - Optional function to determine if the task is successful
|
|
87
|
+
* @returns Promise with success status, error (if any), and the last assistant message
|
|
88
|
+
*/
|
|
47
89
|
async run(task: TaskInstruction, successCondition: () => boolean = () => true): Promise<{ success: boolean; error: string | null, message: string | null }> {
|
|
48
90
|
|
|
49
91
|
|
|
@@ -259,6 +301,13 @@ class Agent {
|
|
|
259
301
|
};
|
|
260
302
|
}
|
|
261
303
|
|
|
304
|
+
/**
|
|
305
|
+
* Attempts to make a request to the LLM with conversation history and tools.
|
|
306
|
+
*
|
|
307
|
+
* @param apiConversationHistory - The current conversation history
|
|
308
|
+
* @param tools - The tools available to the LLM
|
|
309
|
+
* @returns Promise with the LLM response
|
|
310
|
+
*/
|
|
262
311
|
private async attemptLlmRequest(apiConversationHistory: Message[], tools: Record<string, any>): Promise<any> {
|
|
263
312
|
|
|
264
313
|
|
|
@@ -284,15 +333,36 @@ class Agent {
|
|
|
284
333
|
}
|
|
285
334
|
}
|
|
286
335
|
|
|
336
|
+
/**
|
|
337
|
+
* Executes a tool with given name and input.
|
|
338
|
+
*
|
|
339
|
+
* @param toolName - The name of the tool to execute
|
|
340
|
+
* @param toolInput - The input parameters for the tool
|
|
341
|
+
* @returns Promise with tuple [userRejected, result]
|
|
342
|
+
*/
|
|
287
343
|
private async executeTool(toolName: string, toolInput: any): Promise<[boolean, any]> {
|
|
288
344
|
//codebolttools--readfile
|
|
289
345
|
const [toolboxName, actualToolName] = toolName.split('--');
|
|
290
346
|
return tools.executeTool(toolboxName, actualToolName, toolInput);
|
|
291
347
|
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Starts a sub-agent to handle a specific task.
|
|
351
|
+
*
|
|
352
|
+
* @param agentName - The name of the sub-agent to start
|
|
353
|
+
* @param params - Parameters for the sub-agent
|
|
354
|
+
* @returns Promise with tuple [userRejected, result]
|
|
355
|
+
*/
|
|
292
356
|
private async startSubAgent(agentName: string, params: any): Promise<[boolean, any]> {
|
|
293
357
|
return codeboltAgent.startAgent(agentName, params.task);
|
|
294
358
|
}
|
|
295
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Extracts tool details from a tool call object.
|
|
362
|
+
*
|
|
363
|
+
* @param tool - The tool call object from the LLM response
|
|
364
|
+
* @returns ToolDetails object with name, input, and ID
|
|
365
|
+
*/
|
|
296
366
|
private getToolDetail(tool: any): ToolDetails {
|
|
297
367
|
return {
|
|
298
368
|
toolName: tool.function.name,
|
|
@@ -301,6 +371,13 @@ class Agent {
|
|
|
301
371
|
};
|
|
302
372
|
}
|
|
303
373
|
|
|
374
|
+
/**
|
|
375
|
+
* Creates a tool result object from the tool execution response.
|
|
376
|
+
*
|
|
377
|
+
* @param tool_call_id - The ID of the tool call
|
|
378
|
+
* @param content - The content returned by the tool
|
|
379
|
+
* @returns ToolResult object
|
|
380
|
+
*/
|
|
304
381
|
private getToolResult(tool_call_id: string, content: string): ToolResult {
|
|
305
382
|
let userMessage=undefined
|
|
306
383
|
try {
|
|
@@ -322,7 +399,11 @@ class Agent {
|
|
|
322
399
|
};
|
|
323
400
|
}
|
|
324
401
|
|
|
325
|
-
|
|
402
|
+
/**
|
|
403
|
+
* Fallback method for API requests in case of failures.
|
|
404
|
+
*
|
|
405
|
+
* @throws Error API request fallback not implemented
|
|
406
|
+
*/
|
|
326
407
|
private attemptApiRequest(): any {
|
|
327
408
|
throw new Error("API request fallback not implemented");
|
|
328
409
|
}
|
|
@@ -8,37 +8,69 @@ const yaml = require('js-yaml');
|
|
|
8
8
|
const fs = require('fs');
|
|
9
9
|
const path = require('path');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Interface for tools that can be used within tasks.
|
|
13
|
+
* Each tool has a description and usage example.
|
|
14
|
+
*/
|
|
13
15
|
interface Tools {
|
|
14
16
|
[key: string]: {
|
|
17
|
+
/** Description of what the tool does */
|
|
15
18
|
description: string;
|
|
19
|
+
/** How to use the tool correctly */
|
|
16
20
|
usage: string;
|
|
21
|
+
/** Optional example demonstrating tool usage */
|
|
17
22
|
example?: string;
|
|
18
23
|
};
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Interface for task data structure as loaded from YAML.
|
|
28
|
+
* Contains task descriptions and expected outputs.
|
|
29
|
+
*/
|
|
23
30
|
interface TaskData {
|
|
24
31
|
[key: string]: {
|
|
32
|
+
/** Description of what the task should accomplish */
|
|
25
33
|
description: string;
|
|
34
|
+
/** Expected output format or content */
|
|
26
35
|
expected_output: string;
|
|
27
36
|
};
|
|
28
37
|
}
|
|
29
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Interface for user message structure.
|
|
41
|
+
* Contains message type and text content.
|
|
42
|
+
*/
|
|
30
43
|
interface UserMessages {
|
|
44
|
+
/** The type of user message */
|
|
31
45
|
type: string;
|
|
46
|
+
/** The text content of the message */
|
|
32
47
|
text: string;
|
|
33
48
|
}
|
|
34
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Class representing a task instruction.
|
|
52
|
+
* Handles loading task data and converting it to prompts.
|
|
53
|
+
*/
|
|
35
54
|
class TaskInstruction {
|
|
55
|
+
/** Available tools for the task */
|
|
36
56
|
tools: Tools;
|
|
57
|
+
/** Messages from the user for this task */
|
|
37
58
|
userMessages: UserMessageContent[]=[];
|
|
59
|
+
/** The user message object containing input */
|
|
38
60
|
userMessage: UserMessage
|
|
61
|
+
/** Path to the YAML file with task instructions */
|
|
39
62
|
filepath: string;
|
|
63
|
+
/** The section reference within the YAML file */
|
|
40
64
|
refsection: string;
|
|
41
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new TaskInstruction instance.
|
|
68
|
+
*
|
|
69
|
+
* @param tools - Tools available for this task
|
|
70
|
+
* @param userMessage - User message containing task instructions
|
|
71
|
+
* @param filepath - Path to the YAML file with task data
|
|
72
|
+
* @param refsection - Section name within the YAML file
|
|
73
|
+
*/
|
|
42
74
|
constructor(tools: Tools = {}, userMessage: UserMessage , filepath: string = "", refsection: string = "") {
|
|
43
75
|
this.tools = tools;
|
|
44
76
|
this.userMessage = userMessage;
|
|
@@ -46,6 +78,13 @@ class TaskInstruction {
|
|
|
46
78
|
this.refsection = refsection;
|
|
47
79
|
}
|
|
48
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Converts the task instruction to a prompt format.
|
|
83
|
+
* Loads data from YAML file and combines with user message.
|
|
84
|
+
*
|
|
85
|
+
* @returns Promise with an array of user message content blocks
|
|
86
|
+
* @throws Error if there's an issue processing the task instruction
|
|
87
|
+
*/
|
|
49
88
|
async toPrompt(): Promise<UserMessages[]> {
|
|
50
89
|
try {
|
|
51
90
|
this.userMessages = await this.userMessage.toPrompt();
|
|
@@ -1,39 +1,79 @@
|
|
|
1
1
|
import cbfs from "./../fs";
|
|
2
2
|
import project from "./../project";
|
|
3
3
|
import mcp from "./../tools";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Interface representing an agent that can be referenced in user messages.
|
|
7
|
+
*/
|
|
4
8
|
interface agent {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/** Short description of the agent */
|
|
10
|
+
description: string;
|
|
11
|
+
/** Title/name of the agent */
|
|
12
|
+
title: string;
|
|
13
|
+
/** Numeric ID of the agent */
|
|
14
|
+
id: number;
|
|
15
|
+
/** Agent identifier string */
|
|
16
|
+
agent_id: string;
|
|
17
|
+
/** Unique identifier for the agent */
|
|
18
|
+
unique_id: string;
|
|
19
|
+
/** Detailed description of the agent and its capabilities */
|
|
20
|
+
longDescription: string;
|
|
13
21
|
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Interface for the user message structure.
|
|
25
|
+
*/
|
|
14
26
|
interface Message {
|
|
27
|
+
/** The actual text content of the user message */
|
|
15
28
|
userMessage: string;
|
|
29
|
+
/** Optional list of files mentioned in the message */
|
|
16
30
|
mentionedFiles?: string[];
|
|
31
|
+
/** List of MCP (Model Context Protocol) tools mentioned */
|
|
17
32
|
mentionedMCPs: string[];
|
|
33
|
+
/** List of agents mentioned in the message */
|
|
18
34
|
mentionedAgents: agent[];
|
|
19
35
|
}
|
|
20
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Interface for a single content block within a user message.
|
|
39
|
+
*/
|
|
21
40
|
export interface UserMessageContent {
|
|
41
|
+
/** Type of content (e.g., "text", "image") */
|
|
22
42
|
type: string;
|
|
43
|
+
/** The text content */
|
|
23
44
|
text: string;
|
|
24
45
|
}
|
|
25
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Interface for file listing result.
|
|
49
|
+
*/
|
|
26
50
|
interface FileListResult {
|
|
51
|
+
/** Whether the listing operation was successful */
|
|
27
52
|
success: boolean;
|
|
53
|
+
/** The result of the listing operation as a string */
|
|
28
54
|
result: string;
|
|
29
55
|
}
|
|
30
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Class that processes and manages user messages.
|
|
59
|
+
* Handles converting messages to prompts and extracting mentioned entities.
|
|
60
|
+
*/
|
|
31
61
|
class UserMessage {
|
|
62
|
+
/** The message content and metadata */
|
|
32
63
|
message: Message;
|
|
64
|
+
/** Whether to override the default prompt generation */
|
|
33
65
|
promptOverride: boolean;
|
|
66
|
+
/** Array of content blocks for the user message */
|
|
34
67
|
userMessages: UserMessageContent[];
|
|
68
|
+
/** List of MCP tools mentioned in the message */
|
|
35
69
|
mentionedMCPs: string[];
|
|
36
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Creates a new UserMessage instance.
|
|
73
|
+
*
|
|
74
|
+
* @param message - The message content and metadata
|
|
75
|
+
* @param promptOverride - Whether to override default prompt generation
|
|
76
|
+
*/
|
|
37
77
|
constructor(message: Message, promptOverride: boolean = false) {
|
|
38
78
|
this.message = message;
|
|
39
79
|
this.promptOverride = promptOverride;
|
|
@@ -41,10 +81,22 @@ class UserMessage {
|
|
|
41
81
|
this.mentionedMCPs = message.mentionedMCPs || [];
|
|
42
82
|
}
|
|
43
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Gets files mentioned in the message.
|
|
86
|
+
* Currently a placeholder for implementation.
|
|
87
|
+
*/
|
|
44
88
|
getFiles(): void {
|
|
45
89
|
// Implementation to be added
|
|
46
90
|
}
|
|
47
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Converts the user message to a prompt format.
|
|
94
|
+
*
|
|
95
|
+
* @param bAttachFiles - Whether to attach file contents
|
|
96
|
+
* @param bAttachImages - Whether to attach images
|
|
97
|
+
* @param bAttachEnvironment - Whether to attach environment details
|
|
98
|
+
* @returns Promise with an array of content blocks for the prompt
|
|
99
|
+
*/
|
|
48
100
|
async toPrompt(
|
|
49
101
|
bAttachFiles: boolean = true,
|
|
50
102
|
bAttachImages: boolean = true,
|
|
@@ -78,14 +130,30 @@ class UserMessage {
|
|
|
78
130
|
return this.userMessages;
|
|
79
131
|
}
|
|
80
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Gets agents mentioned in the message.
|
|
135
|
+
*
|
|
136
|
+
* @returns Array of agent objects
|
|
137
|
+
*/
|
|
81
138
|
getMentionedAgents() {
|
|
82
139
|
//TODO : get config in tool format if neede
|
|
83
140
|
return this.message.mentionedAgents || [];
|
|
84
141
|
}
|
|
85
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Gets MCP tools mentioned in the message.
|
|
145
|
+
*
|
|
146
|
+
* @returns Array of MCP tool names
|
|
147
|
+
*/
|
|
86
148
|
getMentionedMcps() {
|
|
87
149
|
return this.message.mentionedMCPs || [];
|
|
88
150
|
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Gets MCP tools in a format suitable for the LLM.
|
|
154
|
+
*
|
|
155
|
+
* @returns Promise with an array of MCP tools
|
|
156
|
+
*/
|
|
89
157
|
async getMentionedMcpsTools() {
|
|
90
158
|
if (this.mentionedMCPs.length > 0) {
|
|
91
159
|
let tools = await mcp.listToolsFromToolBoxes(this.mentionedMCPs)
|
|
@@ -96,6 +164,12 @@ class UserMessage {
|
|
|
96
164
|
}
|
|
97
165
|
}
|
|
98
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Gets environment details for the current working directory.
|
|
169
|
+
*
|
|
170
|
+
* @param cwd - The current working directory path
|
|
171
|
+
* @returns Promise with a string containing environment details
|
|
172
|
+
*/
|
|
99
173
|
private getEnvironmentDetail = async (cwd: string): Promise<string> => {
|
|
100
174
|
let details = "";
|
|
101
175
|
const { success, result }: FileListResult = await cbfs.listFile(cwd, true);
|
package/src/modules/history.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import cbws from './websocket';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Enum representing different types of log messages.
|
|
5
|
+
*/
|
|
3
6
|
export enum logType {
|
|
7
|
+
/** Informational messages */
|
|
4
8
|
info = "info",
|
|
9
|
+
/** Error messages */
|
|
5
10
|
error = "error",
|
|
11
|
+
/** Warning messages */
|
|
6
12
|
warning = "warning"
|
|
7
13
|
}
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Object with methods for summarizing chat history.
|
|
17
|
+
* Provides functionality to create summaries of conversation history.
|
|
18
|
+
*/
|
|
10
19
|
export const chatSummary = {
|
|
11
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Summarizes the entire chat history.
|
|
22
|
+
*
|
|
23
|
+
* @returns Promise with an array of message objects containing role and content
|
|
24
|
+
*/
|
|
12
25
|
summarizeAll: (): Promise<{
|
|
13
26
|
role: string;
|
|
14
27
|
content: string;
|
|
@@ -29,6 +42,14 @@ export const chatSummary = {
|
|
|
29
42
|
|
|
30
43
|
|
|
31
44
|
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Summarizes a specific part of the chat history.
|
|
48
|
+
*
|
|
49
|
+
* @param messages - Array of message objects to summarize
|
|
50
|
+
* @param depth - How far back in history to consider
|
|
51
|
+
* @returns Promise with an array of summarized message objects
|
|
52
|
+
*/
|
|
32
53
|
summarize: (messages: {
|
|
33
54
|
role: string;
|
|
34
55
|
content: string;
|