@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 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();
@@ -199,6 +217,13 @@ class Agent {
199
217
  .pop()) === null || _b === void 0 ? void 0 : _b.content) || ''
200
218
  };
201
219
  }
220
+ /**
221
+ * Attempts to make a request to the LLM with conversation history and tools.
222
+ *
223
+ * @param apiConversationHistory - The current conversation history
224
+ * @param tools - The tools available to the LLM
225
+ * @returns Promise with the LLM response
226
+ */
202
227
  async attemptLlmRequest(apiConversationHistory, tools) {
203
228
  try {
204
229
  let systemPrompt = await this.systemPrompt.toPromptText();
@@ -221,14 +246,34 @@ class Agent {
221
246
  return this.attemptApiRequest();
222
247
  }
223
248
  }
249
+ /**
250
+ * Executes a tool with given name and input.
251
+ *
252
+ * @param toolName - The name of the tool to execute
253
+ * @param toolInput - The input parameters for the tool
254
+ * @returns Promise with tuple [userRejected, result]
255
+ */
224
256
  async executeTool(toolName, toolInput) {
225
257
  //codebolttools--readfile
226
258
  const [toolboxName, actualToolName] = toolName.split('--');
227
259
  return tools_1.default.executeTool(toolboxName, actualToolName, toolInput);
228
260
  }
261
+ /**
262
+ * Starts a sub-agent to handle a specific task.
263
+ *
264
+ * @param agentName - The name of the sub-agent to start
265
+ * @param params - Parameters for the sub-agent
266
+ * @returns Promise with tuple [userRejected, result]
267
+ */
229
268
  async startSubAgent(agentName, params) {
230
269
  return agent_1.default.startAgent(agentName, params.task);
231
270
  }
271
+ /**
272
+ * Extracts tool details from a tool call object.
273
+ *
274
+ * @param tool - The tool call object from the LLM response
275
+ * @returns ToolDetails object with name, input, and ID
276
+ */
232
277
  getToolDetail(tool) {
233
278
  return {
234
279
  toolName: tool.function.name,
@@ -236,6 +281,13 @@ class Agent {
236
281
  toolUseId: tool.id
237
282
  };
238
283
  }
284
+ /**
285
+ * Creates a tool result object from the tool execution response.
286
+ *
287
+ * @param tool_call_id - The ID of the tool call
288
+ * @param content - The content returned by the tool
289
+ * @returns ToolResult object
290
+ */
239
291
  getToolResult(tool_call_id, content) {
240
292
  let userMessage = undefined;
241
293
  try {
@@ -255,7 +307,11 @@ class Agent {
255
307
  userMessage
256
308
  };
257
309
  }
258
- // Placeholder for error fallback method
310
+ /**
311
+ * Fallback method for API requests in case of failures.
312
+ *
313
+ * @throws Error API request fallback not implemented
314
+ */
259
315
  attemptApiRequest() {
260
316
  throw new Error("API request fallback not implemented");
261
317
  }
@@ -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);
@@ -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;
@@ -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({