@codebolt/codeboltjs 1.1.94 → 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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "1.1.94",
3
+ "version": "1.1.96",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -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,63 +5,121 @@ 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
- private subAgents: any[];
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
-
38
- constructor(tools: any = [], systemPrompt: SystemPrompt, maxRun: number = 0, subAgents: any[] = []) {
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
+ */
73
+ constructor(tools: any = [], systemPrompt: SystemPrompt, maxRun: number = 0) {
39
74
  this.tools = tools;
40
75
  this.userMessage = [];
41
76
  this.apiConversationHistory = [];
42
77
  this.maxRun = maxRun;
43
78
  this.systemPrompt = systemPrompt;
44
- this.subAgents = subAgents;
45
- this.subAgents = subAgents.map(subagent => {
46
- subagent.function.name = `subagent--${subagent.function.name}`;
47
- return subagent;
48
- });
49
- this.tools = this.tools.concat(subAgents.map(subagent => ({
50
- ...subagent
51
- })));
52
-
53
-
54
79
 
55
80
  }
56
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
+ */
57
89
  async run(task: TaskInstruction, successCondition: () => boolean = () => true): Promise<{ success: boolean; error: string | null, message: string | null }> {
58
90
 
59
91
 
60
92
  let mentaionedMCPSTool: any[] = await task.userMessage.getMentionedMcpsTools();
93
+
61
94
  this.tools = [
62
95
  ...this.tools,
63
- ...mentaionedMCPSTool
96
+ ...mentaionedMCPSTool,
97
+
64
98
  ]
99
+ let mentionedAgents = await task.userMessage.getMentionedAgents();
100
+
101
+ // Transform agents into tool format
102
+ const agentTools = mentionedAgents.map(agent => {
103
+ return {
104
+ type: "function",
105
+ function: {
106
+ name: `subagent--${agent.unique_id}`,
107
+ description: agent.longDescription || agent.description,
108
+ parameters: {
109
+ type: "object",
110
+ properties: {
111
+ task: {
112
+ type: "string",
113
+ description: "The task to be executed by the tool."
114
+ }
115
+ },
116
+ required: ["task"]
117
+ }
118
+ }
119
+ };
120
+ });
121
+
122
+ this.tools = this.tools.concat(agentTools);
65
123
 
66
124
 
67
125
  let completed = false;
@@ -243,6 +301,13 @@ class Agent {
243
301
  };
244
302
  }
245
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
+ */
246
311
  private async attemptLlmRequest(apiConversationHistory: Message[], tools: Record<string, any>): Promise<any> {
247
312
 
248
313
 
@@ -268,15 +333,36 @@ class Agent {
268
333
  }
269
334
  }
270
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
+ */
271
343
  private async executeTool(toolName: string, toolInput: any): Promise<[boolean, any]> {
272
344
  //codebolttools--readfile
273
345
  const [toolboxName, actualToolName] = toolName.split('--');
274
346
  return tools.executeTool(toolboxName, actualToolName, toolInput);
275
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
+ */
276
356
  private async startSubAgent(agentName: string, params: any): Promise<[boolean, any]> {
277
357
  return codeboltAgent.startAgent(agentName, params.task);
278
358
  }
279
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
+ */
280
366
  private getToolDetail(tool: any): ToolDetails {
281
367
  return {
282
368
  toolName: tool.function.name,
@@ -285,6 +371,13 @@ class Agent {
285
371
  };
286
372
  }
287
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
+ */
288
381
  private getToolResult(tool_call_id: string, content: string): ToolResult {
289
382
  let userMessage=undefined
290
383
  try {
@@ -306,7 +399,11 @@ class Agent {
306
399
  };
307
400
  }
308
401
 
309
- // Placeholder for error fallback method
402
+ /**
403
+ * Fallback method for API requests in case of failures.
404
+ *
405
+ * @throws Error API request fallback not implemented
406
+ */
310
407
  private attemptApiRequest(): any {
311
408
  throw new Error("API request fallback not implemented");
312
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
- // ... existing imports ...
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,31 +1,79 @@
1
1
  import cbfs from "./../fs";
2
2
  import project from "./../project";
3
3
  import mcp from "./../tools";
4
- import { escape } from "querystring";
5
4
 
5
+ /**
6
+ * Interface representing an agent that can be referenced in user messages.
7
+ */
8
+ interface agent {
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;
21
+ }
6
22
 
23
+ /**
24
+ * Interface for the user message structure.
25
+ */
7
26
  interface Message {
27
+ /** The actual text content of the user message */
8
28
  userMessage: string;
29
+ /** Optional list of files mentioned in the message */
9
30
  mentionedFiles?: string[];
31
+ /** List of MCP (Model Context Protocol) tools mentioned */
10
32
  mentionedMCPs: string[];
33
+ /** List of agents mentioned in the message */
34
+ mentionedAgents: agent[];
11
35
  }
12
36
 
37
+ /**
38
+ * Interface for a single content block within a user message.
39
+ */
13
40
  export interface UserMessageContent {
41
+ /** Type of content (e.g., "text", "image") */
14
42
  type: string;
43
+ /** The text content */
15
44
  text: string;
16
45
  }
17
46
 
47
+ /**
48
+ * Interface for file listing result.
49
+ */
18
50
  interface FileListResult {
51
+ /** Whether the listing operation was successful */
19
52
  success: boolean;
53
+ /** The result of the listing operation as a string */
20
54
  result: string;
21
55
  }
22
56
 
57
+ /**
58
+ * Class that processes and manages user messages.
59
+ * Handles converting messages to prompts and extracting mentioned entities.
60
+ */
23
61
  class UserMessage {
62
+ /** The message content and metadata */
24
63
  message: Message;
64
+ /** Whether to override the default prompt generation */
25
65
  promptOverride: boolean;
66
+ /** Array of content blocks for the user message */
26
67
  userMessages: UserMessageContent[];
68
+ /** List of MCP tools mentioned in the message */
27
69
  mentionedMCPs: string[];
28
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
+ */
29
77
  constructor(message: Message, promptOverride: boolean = false) {
30
78
  this.message = message;
31
79
  this.promptOverride = promptOverride;
@@ -33,10 +81,22 @@ class UserMessage {
33
81
  this.mentionedMCPs = message.mentionedMCPs || [];
34
82
  }
35
83
 
84
+ /**
85
+ * Gets files mentioned in the message.
86
+ * Currently a placeholder for implementation.
87
+ */
36
88
  getFiles(): void {
37
89
  // Implementation to be added
38
90
  }
39
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
+ */
40
100
  async toPrompt(
41
101
  bAttachFiles: boolean = true,
42
102
  bAttachImages: boolean = true,
@@ -70,9 +130,30 @@ class UserMessage {
70
130
  return this.userMessages;
71
131
  }
72
132
 
73
- getMentionedMcps(): string[] {
74
- return this.message.mentionedMCPs || [];
133
+ /**
134
+ * Gets agents mentioned in the message.
135
+ *
136
+ * @returns Array of agent objects
137
+ */
138
+ getMentionedAgents() {
139
+ //TODO : get config in tool format if neede
140
+ return this.message.mentionedAgents || [];
141
+ }
142
+
143
+ /**
144
+ * Gets MCP tools mentioned in the message.
145
+ *
146
+ * @returns Array of MCP tool names
147
+ */
148
+ getMentionedMcps() {
149
+ return this.message.mentionedMCPs || [];
75
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
+ */
76
157
  async getMentionedMcpsTools() {
77
158
  if (this.mentionedMCPs.length > 0) {
78
159
  let tools = await mcp.listToolsFromToolBoxes(this.mentionedMCPs)
@@ -83,6 +164,12 @@ class UserMessage {
83
164
  }
84
165
  }
85
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
+ */
86
173
  private getEnvironmentDetail = async (cwd: string): Promise<string> => {
87
174
  let details = "";
88
175
  const { success, result }: FileListResult = await cbfs.listFile(cwd, true);