@codebolt/codeboltjs 2.0.12 → 2.0.15

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.
Files changed (129) hide show
  1. package/Readme.md +138 -4
  2. package/dist/agentlib/agent.js +3 -7
  3. package/dist/agentlib/followupquestionbuilder.d.ts +75 -0
  4. package/dist/agentlib/followupquestionbuilder.js +193 -0
  5. package/dist/agentlib/llmoutputhandler.d.ts +102 -0
  6. package/dist/agentlib/llmoutputhandler.js +451 -0
  7. package/dist/agentlib/promptbuilder.d.ts +171 -17
  8. package/dist/agentlib/promptbuilder.js +367 -49
  9. package/dist/agentlib/systemprompt.js +3 -3
  10. package/dist/agentlib/usermessage.d.ts +1 -1
  11. package/dist/agentlib/usermessage.js +5 -1
  12. package/dist/core/Codebolt.d.ts +342 -0
  13. package/dist/core/Codebolt.js +201 -0
  14. package/dist/core/websocket.js +2 -1
  15. package/dist/index.d.ts +4 -300
  16. package/dist/index.js +11 -137
  17. package/dist/modules/llm.d.ts +23 -3
  18. package/dist/modules/llm.js +20 -3
  19. package/dist/modules/project.d.ts +3 -3
  20. package/dist/modules/project.js +1 -1
  21. package/dist/modules/state.d.ts +5 -3
  22. package/dist/modules/state.js +2 -0
  23. package/dist/modules/task.d.ts +126 -11
  24. package/dist/modules/task.js +262 -20
  25. package/dist/notificationfunctions/agent.d.ts +48 -0
  26. package/dist/notificationfunctions/agent.js +115 -0
  27. package/dist/notificationfunctions/browser.d.ts +60 -0
  28. package/dist/notificationfunctions/browser.js +145 -0
  29. package/dist/notificationfunctions/chat.d.ts +53 -0
  30. package/dist/notificationfunctions/chat.js +125 -0
  31. package/dist/notificationfunctions/codeutils.d.ts +60 -0
  32. package/dist/notificationfunctions/codeutils.js +145 -0
  33. package/dist/notificationfunctions/crawler.d.ts +59 -0
  34. package/dist/notificationfunctions/crawler.js +159 -0
  35. package/dist/notificationfunctions/dbmemory.d.ts +50 -0
  36. package/dist/notificationfunctions/dbmemory.js +132 -0
  37. package/dist/notificationfunctions/fs.d.ts +125 -0
  38. package/dist/notificationfunctions/fs.js +472 -0
  39. package/dist/notificationfunctions/git.d.ts +174 -0
  40. package/dist/notificationfunctions/git.js +521 -0
  41. package/dist/notificationfunctions/history.d.ts +38 -0
  42. package/dist/notificationfunctions/history.js +97 -0
  43. package/dist/notificationfunctions/index.d.ts +79 -0
  44. package/dist/notificationfunctions/index.js +102 -0
  45. package/dist/notificationfunctions/llm.d.ts +39 -0
  46. package/dist/notificationfunctions/llm.js +99 -0
  47. package/dist/notificationfunctions/mcp.d.ts +67 -0
  48. package/dist/notificationfunctions/mcp.js +192 -0
  49. package/dist/notificationfunctions/search.d.ts +50 -0
  50. package/dist/notificationfunctions/search.js +146 -0
  51. package/dist/notificationfunctions/system.d.ts +25 -0
  52. package/dist/notificationfunctions/system.js +59 -0
  53. package/dist/notificationfunctions/terminal.d.ts +26 -0
  54. package/dist/notificationfunctions/terminal.js +64 -0
  55. package/dist/notificationfunctions/todo.d.ts +63 -0
  56. package/dist/notificationfunctions/todo.js +164 -0
  57. package/dist/notificationfunctions/utils.d.ts +81 -0
  58. package/dist/notificationfunctions/utils.js +177 -0
  59. package/dist/types/InternalTypes.d.ts +1 -0
  60. package/dist/types/commonTypes.d.ts +26 -3
  61. package/dist/types/index.d.ts +15 -0
  62. package/dist/types/index.js +15 -0
  63. package/dist/types/libFunctionTypes.d.ts +110 -4
  64. package/dist/types/notificationFunctions/agent.d.ts +8 -0
  65. package/dist/types/notificationFunctions/agent.js +2 -0
  66. package/dist/types/notificationFunctions/browser.d.ts +10 -0
  67. package/dist/types/notificationFunctions/browser.js +2 -0
  68. package/dist/types/notificationFunctions/chat.d.ts +10 -0
  69. package/dist/types/notificationFunctions/chat.js +2 -0
  70. package/dist/types/notificationFunctions/codeutils.d.ts +10 -0
  71. package/dist/types/notificationFunctions/codeutils.js +2 -0
  72. package/dist/types/notificationFunctions/crawler.d.ts +10 -0
  73. package/dist/types/notificationFunctions/crawler.js +2 -0
  74. package/dist/types/notificationFunctions/dbmemory.d.ts +9 -0
  75. package/dist/types/notificationFunctions/dbmemory.js +2 -0
  76. package/dist/types/notificationFunctions/fs.d.ts +27 -0
  77. package/dist/types/notificationFunctions/fs.js +2 -0
  78. package/dist/types/notificationFunctions/git.d.ts +29 -0
  79. package/dist/types/notificationFunctions/git.js +2 -0
  80. package/dist/types/notificationFunctions/history.d.ts +10 -0
  81. package/dist/types/notificationFunctions/history.js +2 -0
  82. package/dist/types/notificationFunctions/index.d.ts +0 -0
  83. package/dist/types/notificationFunctions/index.js +1 -0
  84. package/dist/types/notificationFunctions/llm.d.ts +10 -0
  85. package/dist/types/notificationFunctions/llm.js +2 -0
  86. package/dist/types/notificationFunctions/mcp.d.ts +16 -0
  87. package/dist/types/notificationFunctions/mcp.js +2 -0
  88. package/dist/types/notificationFunctions/search.d.ts +11 -0
  89. package/dist/types/notificationFunctions/search.js +2 -0
  90. package/dist/types/notificationFunctions/system.d.ts +7 -0
  91. package/dist/types/notificationFunctions/system.js +2 -0
  92. package/dist/types/notificationFunctions/terminal.d.ts +7 -0
  93. package/dist/types/notificationFunctions/terminal.js +2 -0
  94. package/dist/types/notificationFunctions/todo.d.ts +11 -0
  95. package/dist/types/notificationFunctions/todo.js +2 -0
  96. package/dist/types/notifications/agent.d.ts +31 -0
  97. package/dist/types/notifications/agent.js +3 -0
  98. package/dist/types/notifications/browser.d.ts +53 -0
  99. package/dist/types/notifications/browser.js +3 -0
  100. package/dist/types/notifications/chat.d.ts +37 -0
  101. package/dist/types/notifications/chat.js +3 -0
  102. package/dist/types/notifications/codeutils.d.ts +55 -0
  103. package/dist/types/notifications/codeutils.js +3 -0
  104. package/dist/types/notifications/crawler.d.ts +55 -0
  105. package/dist/types/notifications/crawler.js +3 -0
  106. package/dist/types/notifications/dbmemory.d.ts +31 -0
  107. package/dist/types/notifications/dbmemory.js +3 -0
  108. package/dist/types/notifications/fs.d.ts +180 -0
  109. package/dist/types/notifications/fs.js +3 -0
  110. package/dist/types/notifications/git.d.ts +205 -0
  111. package/dist/types/notifications/git.js +3 -0
  112. package/dist/types/notifications/history.d.ts +32 -0
  113. package/dist/types/notifications/history.js +3 -0
  114. package/dist/types/notifications/llm.d.ts +45 -0
  115. package/dist/types/notifications/llm.js +2 -0
  116. package/dist/types/notifications/mcp.d.ts +63 -0
  117. package/dist/types/notifications/mcp.js +3 -0
  118. package/dist/types/notifications/search.d.ts +47 -0
  119. package/dist/types/notifications/search.js +3 -0
  120. package/dist/types/notifications/system.d.ts +20 -0
  121. package/dist/types/notifications/system.js +2 -0
  122. package/dist/types/notifications/terminal.d.ts +17 -0
  123. package/dist/types/notifications/terminal.js +2 -0
  124. package/dist/types/notifications/todo.d.ts +60 -0
  125. package/dist/types/notifications/todo.js +3 -0
  126. package/dist/types/socketMessageTypes.d.ts +3 -0
  127. package/dist/utils.d.ts +3 -0
  128. package/dist/utils.js +7 -1
  129. package/package.json +1 -1
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PromptBuilder = void 0;
6
+ exports.InitialPromptBuilder = void 0;
7
7
  const systemprompt_1 = require("./systemprompt");
8
8
  const js_yaml_1 = __importDefault(require("js-yaml"));
9
9
  const fs_1 = __importDefault(require("fs"));
@@ -13,7 +13,7 @@ const path_1 = __importDefault(require("path"));
13
13
  * PromptBuilder class for constructing prompts using a fluent interface.
14
14
  * Allows chaining methods to build complex prompts from user messages.
15
15
  */
16
- class PromptBuilder {
16
+ class InitialPromptBuilder {
17
17
  /**
18
18
  * Creates a new PromptBuilder instance.
19
19
  *
@@ -34,10 +34,16 @@ class PromptBuilder {
34
34
  this.environmentDetails = "";
35
35
  /** File contents cache */
36
36
  this.fileContents = new Map();
37
+ // Flags for what needs to be loaded during build
38
+ this.shouldLoadMCPTools = false;
39
+ this.mcpAdditionalServers = ["codebolt"];
40
+ this.shouldLoadAgentTools = false;
41
+ this.shouldLoadEnvironmentDetails = false;
42
+ this.shouldLoadAll = false;
37
43
  // Handle both InitialUserMessage and CLIUserMessage types
38
44
  if ('message' in userMessage && typeof userMessage.message === 'object') {
39
45
  // This is a CLIUserMessage with nested message structure
40
- this.message = userMessage.message.userMessage || ((_a = userMessage.data) === null || _a === void 0 ? void 0 : _a.text) || "";
46
+ this.message = userMessage.message.userMessage || ((_a = userMessage.data) === null || _a === void 0 ? void 0 : _a.text.trim()) || "";
41
47
  this.mentionedFiles = userMessage.message.mentionedFiles || [];
42
48
  // Convert string array to MCPTool array for CLIUserMessage
43
49
  this.mentionedMCPs = (userMessage.message.mentionedMCPs || []).map((name) => ({ name }));
@@ -64,20 +70,58 @@ class PromptBuilder {
64
70
  return this;
65
71
  }
66
72
  /**
67
- * Automatically loads and adds MCP tools from the mentioned MCPs in the user message.
68
- * Also loads default codebolt tools.
73
+ * Marks MCP tools to be loaded during build from the mentioned MCPs and additional servers.
69
74
  *
70
75
  * @param additionalServers - Additional MCP servers to load tools from
71
76
  * @returns The PromptBuilder instance for chaining
72
77
  */
73
- async addMCPTools(additionalServers = ["codebolt"]) {
78
+ addMCPTools(additionalServers = ["codebolt"]) {
79
+ this.shouldLoadMCPTools = true;
80
+ this.mcpAdditionalServers = additionalServers;
81
+ return this;
82
+ }
83
+ /**
84
+ * Marks mentioned agents to be converted to OpenAI tool format during build.
85
+ *
86
+ * @returns The PromptBuilder instance for chaining
87
+ */
88
+ addAgentTools() {
89
+ this.shouldLoadAgentTools = true;
90
+ return this;
91
+ }
92
+ /**
93
+ * Marks environment details to be loaded during build.
94
+ *
95
+ * @returns The PromptBuilder instance for chaining
96
+ */
97
+ addEnvironmentDetails() {
98
+ this.shouldLoadEnvironmentDetails = true;
99
+ return this;
100
+ }
101
+ /**
102
+ * Convenience method to mark all tools and environment details to be loaded during build.
103
+ * Equivalent to calling addMCPTools(), addAgentTools(), and addEnvironmentDetails().
104
+ *
105
+ * @param additionalServers - Additional MCP servers to load tools from
106
+ * @returns The PromptBuilder instance for chaining
107
+ */
108
+ addAllAutomatic(additionalServers = ["codebolt"]) {
109
+ this.shouldLoadAll = true;
110
+ this.mcpAdditionalServers = additionalServers;
111
+ return this;
112
+ }
113
+ /**
114
+ * Loads MCP tools from the codebolt API.
115
+ * Internal method called during build.
116
+ */
117
+ async loadMCPTools() {
74
118
  if (!this.codebolt) {
75
119
  console.warn("Codebolt API not available. Cannot load MCP tools automatically.");
76
- return this;
120
+ return;
77
121
  }
78
122
  try {
79
123
  // Get default tools from specified servers
80
- const { data: defaultTools } = await this.codebolt.mcp.listMcpFromServers(additionalServers);
124
+ const { data: defaultTools } = await this.codebolt.mcp.listMcpFromServers(this.mcpAdditionalServers);
81
125
  this.tools = [...this.tools, ...defaultTools];
82
126
  // Get tools from mentioned MCPs
83
127
  if (this.mentionedMCPs && this.mentionedMCPs.length > 0) {
@@ -88,14 +132,12 @@ class PromptBuilder {
88
132
  catch (error) {
89
133
  console.error(`Error loading MCP tools: ${error}`);
90
134
  }
91
- return this;
92
135
  }
93
136
  /**
94
- * Automatically converts mentioned agents to OpenAI tool format and adds them.
95
- *
96
- * @returns The PromptBuilder instance for chaining
137
+ * Converts mentioned agents to OpenAI tool format.
138
+ * Internal method called during build.
97
139
  */
98
- addAgentTools() {
140
+ loadAgentTools() {
99
141
  if (this.mentionedAgents && this.mentionedAgents.length > 0) {
100
142
  const agentTools = this.mentionedAgents.map(agent => ({
101
143
  type: "function",
@@ -116,17 +158,15 @@ class PromptBuilder {
116
158
  }));
117
159
  this.tools = [...this.tools, ...agentTools];
118
160
  }
119
- return this;
120
161
  }
121
162
  /**
122
- * Automatically loads file contents for mentioned files and adds environment details.
123
- *
124
- * @returns The PromptBuilder instance for chaining
163
+ * Loads file contents and environment details from the codebolt API.
164
+ * Internal method called during build.
125
165
  */
126
- async addEnvironmentDetails() {
166
+ async loadEnvironmentDetails() {
127
167
  if (!this.codebolt) {
128
168
  console.warn("Codebolt API not available. Cannot load environment details automatically.");
129
- return this;
169
+ return;
130
170
  }
131
171
  try {
132
172
  // Load mentioned file contents
@@ -154,20 +194,6 @@ class PromptBuilder {
154
194
  catch (error) {
155
195
  console.error(`Error loading environment details: ${error}`);
156
196
  }
157
- return this;
158
- }
159
- /**
160
- * Convenience method to automatically add all tools and environment details.
161
- * Equivalent to calling addMCPTools(), addAgentTools(), and addEnvironmentDetails().
162
- *
163
- * @param additionalServers - Additional MCP servers to load tools from
164
- * @returns The PromptBuilder instance for chaining
165
- */
166
- async addAllAutomatic(additionalServers = ["codebolt"]) {
167
- await this.addMCPTools(additionalServers);
168
- this.addAgentTools();
169
- await this.addEnvironmentDetails();
170
- return this;
171
197
  }
172
198
  /**
173
199
  * Adds system prompt from a YAML file.
@@ -185,7 +211,7 @@ class PromptBuilder {
185
211
  if (exampleFilePath) {
186
212
  try {
187
213
  const example = fs_1.default.readFileSync(path_1.default.resolve(exampleFilePath), 'utf8');
188
- this.systemPromptText += `\n\n<example_agent>\n\n${example}\n</example_agent>`;
214
+ this.systemPromptText += `\n\n<example_agent>\n\`\`\`\n${example}\n\`\`\`\n</example_agent>`;
189
215
  }
190
216
  catch (error) {
191
217
  console.error(`Error loading example file: ${error}`);
@@ -297,7 +323,7 @@ class PromptBuilder {
297
323
  return this;
298
324
  }
299
325
  /**
300
- * Builds the user message content with files and environment details.
326
+ * Builds the user message content with files (without environment details).
301
327
  *
302
328
  * @returns Array of content blocks
303
329
  */
@@ -314,13 +340,13 @@ class PromptBuilder {
314
340
  finalPrompt += `File Name: ${file}, File Path: ${file}, Filedata: ${fileData}`;
315
341
  }
316
342
  }
317
- // Add environment details
318
- if (this.environmentDetails) {
319
- finalPrompt += this.environmentDetails;
320
- }
321
343
  const content = [
322
344
  { type: "text", text: finalPrompt }
323
345
  ];
346
+ // Add environment details
347
+ if (this.environmentDetails) {
348
+ content.push({ type: "text", text: this.environmentDetails });
349
+ }
324
350
  // Add task instruction if available
325
351
  if (this.taskInstructionText) {
326
352
  content.push({
@@ -398,6 +424,178 @@ class PromptBuilder {
398
424
  getConversationHistory() {
399
425
  return [...this.conversationHistory];
400
426
  }
427
+ /**
428
+ * Adds an LLM response to the conversation history.
429
+ * This method processes the LLM response and adds the assistant's message to the conversation.
430
+ * It handles both resolved responses and promises that resolve to responses.
431
+ *
432
+ * @param llmResponse - The LLM response (can be a promise or resolved response)
433
+ * @returns The PromptBuilder instance for chaining
434
+ *
435
+ * @example
436
+ * ```typescript
437
+ * // Example of using addLLMResponse in an agent workflow loop
438
+ * import { PromptBuilder } from './promptbuilder';
439
+ * import llm from '../modules/llm';
440
+ *
441
+ * async function agentWorkflowWithLLMResponse(userMessage: any, codebolt: CodeboltAPI) {
442
+ * // Step 1: Build initial prompt
443
+ * const promptBuilder = new PromptBuilder(userMessage, codebolt);
444
+ * let currentPrompt = await promptBuilder
445
+ * .addMCPTools()
446
+ * .addAgentTools()
447
+ * .addEnvironmentDetails()
448
+ * .buildInferenceParams();
449
+ *
450
+ * let completed = false;
451
+ * let maxTurns = 20;
452
+ * let turn = 0;
453
+ *
454
+ * // Step 2: Main conversation loop (similar to agent.ts while loop)
455
+ * while (!completed && turn < maxTurns) {
456
+ * // Get LLM response
457
+ * const llmResponse = llm.inference(currentPrompt);
458
+ *
459
+ * // Add LLM response to conversation history
460
+ * await promptBuilder.addLLMResponse(llmResponse);
461
+ *
462
+ * // Process the response using LLMOutputHandler
463
+ * const outputHandler = new LLMOutputHandler(llmResponse, codebolt);
464
+ * await outputHandler.sendMessageToUser();
465
+ *
466
+ * // Check if task is completed
467
+ * if (outputHandler.isCompleted()) {
468
+ * completed = true;
469
+ * break;
470
+ * }
471
+ *
472
+ * // Execute tools and get results
473
+ * const toolResults = await outputHandler.runTools();
474
+ *
475
+ * // Add tool results to conversation
476
+ * if (toolResults.length > 0) {
477
+ * promptBuilder.addToolResults(toolResults);
478
+ * } else {
479
+ * // Add default continuation message when no tools executed
480
+ * promptBuilder.addDefaultContinuationMessage();
481
+ * }
482
+ *
483
+ * // Build next prompt for the loop
484
+ * currentPrompt = await promptBuilder.buildInferenceParams();
485
+ * turn++;
486
+ * }
487
+ * }
488
+ * ```
489
+ */
490
+ async addLLMResponse(llmResponse) {
491
+ try {
492
+ // Resolve the response if it's a promise
493
+ const resolvedResponse = await Promise.resolve(llmResponse);
494
+ if (!resolvedResponse || !resolvedResponse.completion) {
495
+ console.warn("Invalid LLM response provided");
496
+ return this;
497
+ }
498
+ const completion = resolvedResponse.completion;
499
+ let assistantMessage = null;
500
+ // Handle different response formats
501
+ if (completion.choices && completion.choices.length > 0) {
502
+ // OpenAI-style response with choices
503
+ const choice = completion.choices[0];
504
+ if (choice.message) {
505
+ assistantMessage = {
506
+ role: "assistant",
507
+ content: choice.message.content || "",
508
+ tool_calls: choice.message.tool_calls || undefined
509
+ };
510
+ }
511
+ }
512
+ else if (completion.content) {
513
+ // Direct content response
514
+ assistantMessage = {
515
+ role: "assistant",
516
+ content: completion.content
517
+ };
518
+ }
519
+ else if (completion.message) {
520
+ // Message format response
521
+ assistantMessage = {
522
+ role: "assistant",
523
+ content: completion.message.content || "",
524
+ tool_calls: completion.message.tool_calls || undefined
525
+ };
526
+ }
527
+ // Add the assistant message to conversation history
528
+ if (assistantMessage) {
529
+ this.conversationHistory.push(assistantMessage);
530
+ }
531
+ else {
532
+ // Fallback for cases where no valid message is found
533
+ this.conversationHistory.push({
534
+ role: "assistant",
535
+ content: "I apologize, but I was unable to provide a proper response."
536
+ });
537
+ }
538
+ }
539
+ catch (error) {
540
+ console.error("Error adding LLM response to conversation:", error);
541
+ // Add error message to conversation history
542
+ this.conversationHistory.push({
543
+ role: "assistant",
544
+ content: "An error occurred while processing my response."
545
+ });
546
+ }
547
+ return this;
548
+ }
549
+ /**
550
+ * Adds tool results to the conversation history.
551
+ * This method is typically used after executing tools from an LLM response.
552
+ *
553
+ * @param toolResults - Array of tool results to add to the conversation
554
+ * @returns The PromptBuilder instance for chaining
555
+ */
556
+ addToolResults(toolResults) {
557
+ if (toolResults && toolResults.length > 0) {
558
+ // Add each tool result as a separate message
559
+ toolResults.forEach(toolResult => {
560
+ this.conversationHistory.push({
561
+ role: "tool",
562
+ content: toolResult.content,
563
+ tool_call_id: toolResult.tool_call_id
564
+ });
565
+ });
566
+ }
567
+ return this;
568
+ }
569
+ /**
570
+ * Adds a user message to the conversation history.
571
+ * Useful for adding follow-up questions or additional context during the conversation.
572
+ *
573
+ * @param message - The user message to add
574
+ * @returns The PromptBuilder instance for chaining
575
+ */
576
+ addUserMessage(message) {
577
+ const userMessage = {
578
+ role: "user",
579
+ content: message
580
+ };
581
+ this.conversationHistory.push(userMessage);
582
+ return this;
583
+ }
584
+ /**
585
+ * Adds a default continuation message when no tools were executed.
586
+ * This is used in the agent workflow to prompt the LLM to either complete the task
587
+ * or ask for more information.
588
+ *
589
+ * @returns The PromptBuilder instance for chaining
590
+ */
591
+ addDefaultContinuationMessage() {
592
+ const defaultMessage = "If you have completed the user's task, use the attempt_completion tool. If you require additional information from the user, use the ask_followup_question tool. Otherwise, if you have not completed the task and do not need additional information, then proceed with the next step of the task. (This is an automated message, so do not respond to it conversationally.)";
593
+ this.addUserMessage([{
594
+ type: "text",
595
+ text: defaultMessage
596
+ }]);
597
+ return this;
598
+ }
401
599
  /**
402
600
  * Adds a custom text section to the prompt.
403
601
  *
@@ -431,19 +629,44 @@ class PromptBuilder {
431
629
  * @returns The PromptBuilder instance for chaining
432
630
  */
433
631
  addContext(context) {
434
- if (context.trim()) {
435
- this.promptParts.push(`[Context]\n${context}`);
436
- }
632
+ const userMessage = {
633
+ role: "user",
634
+ content: context
635
+ };
636
+ this.conversationHistory.push(userMessage);
437
637
  return this;
438
638
  }
439
639
  /**
440
- * Builds and returns the final prompt string.
441
- * Joins all prompt parts with double newlines.
640
+ * Builds and returns the OpenAI message format with tools.
641
+ * This method performs all async operations that were marked during setup.
442
642
  *
443
- * @returns The complete prompt string
643
+ * @returns Object with messages, tools, and other LLM parameters
444
644
  */
445
- build() {
446
- return this.promptParts.join("\n\n");
645
+ async build() {
646
+ // Perform all async operations based on what was requested
647
+ if (this.shouldLoadAll) {
648
+ await this.loadMCPTools();
649
+ this.loadAgentTools();
650
+ await this.loadEnvironmentDetails();
651
+ }
652
+ else {
653
+ if (this.shouldLoadMCPTools) {
654
+ await this.loadMCPTools();
655
+ }
656
+ if (this.shouldLoadAgentTools) {
657
+ this.loadAgentTools();
658
+ }
659
+ if (this.shouldLoadEnvironmentDetails) {
660
+ await this.loadEnvironmentDetails();
661
+ }
662
+ }
663
+ return {
664
+ messages: this.buildOpenAIMessages(),
665
+ tools: this.getTools(),
666
+ full: true,
667
+ max_tokens: 8192,
668
+ tool_choice: "auto",
669
+ };
447
670
  }
448
671
  /**
449
672
  * Gets the current prompt parts without building the final string.
@@ -468,14 +691,38 @@ class PromptBuilder {
468
691
  this.tools = [];
469
692
  this.environmentDetails = "";
470
693
  this.fileContents.clear();
694
+ // Reset async loading flags
695
+ this.shouldLoadMCPTools = false;
696
+ this.shouldLoadAgentTools = false;
697
+ this.shouldLoadEnvironmentDetails = false;
698
+ this.shouldLoadAll = false;
699
+ this.mcpAdditionalServers = ["codebolt"];
471
700
  return this;
472
701
  }
473
702
  /**
474
703
  * Creates an LLM inference parameters object in the format expected by the sample code.
704
+ * This method performs all async operations that were marked during setup.
475
705
  *
476
706
  * @returns Object with messages, tools, and other LLM parameters
477
707
  */
478
- buildInferenceParams() {
708
+ async buildInferenceParams() {
709
+ // Perform all async operations based on what was requested
710
+ if (this.shouldLoadAll) {
711
+ await this.loadMCPTools();
712
+ this.loadAgentTools();
713
+ await this.loadEnvironmentDetails();
714
+ }
715
+ else {
716
+ if (this.shouldLoadMCPTools) {
717
+ await this.loadMCPTools();
718
+ }
719
+ if (this.shouldLoadAgentTools) {
720
+ this.loadAgentTools();
721
+ }
722
+ if (this.shouldLoadEnvironmentDetails) {
723
+ await this.loadEnvironmentDetails();
724
+ }
725
+ }
479
726
  return {
480
727
  full: true,
481
728
  messages: this.buildOpenAIMessages(),
@@ -483,5 +730,76 @@ class PromptBuilder {
483
730
  tool_choice: "auto",
484
731
  };
485
732
  }
733
+ /**
734
+ * Creates a minimal LLM inference parameters object with only the user message.
735
+ * This is useful for simple completions or when no tools/context are needed.
736
+ *
737
+ * @returns Object with messages (user only), no tools, and default tool_choice
738
+ */
739
+ //TODO: implement this
740
+ buildDefaultInferenceParams() {
741
+ return {
742
+ full: false,
743
+ messages: [this.message],
744
+ tools: [],
745
+ tool_choice: "auto",
746
+ };
747
+ }
748
+ /**
749
+ * Checks if the last LLM response indicates task completion.
750
+ * This method examines the conversation history for completion signals.
751
+ *
752
+ * @returns Boolean indicating if the task appears to be completed
753
+ */
754
+ isTaskCompleted() {
755
+ if (this.conversationHistory.length === 0) {
756
+ return false;
757
+ }
758
+ // Get the last assistant message
759
+ const lastAssistantMessage = this.conversationHistory
760
+ .slice()
761
+ .reverse()
762
+ .find(msg => msg.role === 'assistant');
763
+ if (!lastAssistantMessage) {
764
+ return false;
765
+ }
766
+ // Check if the message has tool calls with completion tools
767
+ if (lastAssistantMessage.tool_calls) {
768
+ const hasCompletionTool = lastAssistantMessage.tool_calls.some(toolCall => toolCall.function && toolCall.function.name.includes('attempt_completion'));
769
+ if (hasCompletionTool) {
770
+ return true;
771
+ }
772
+ }
773
+ // Check for completion keywords in the message content
774
+ const content = typeof lastAssistantMessage.content === 'string'
775
+ ? lastAssistantMessage.content
776
+ : '';
777
+ const completionKeywords = [
778
+ 'task completed',
779
+ 'task is completed',
780
+ 'successfully completed',
781
+ 'finished the task',
782
+ 'task has been completed'
783
+ ];
784
+ return completionKeywords.some(keyword => content.toLowerCase().includes(keyword.toLowerCase()));
785
+ }
786
+ /**
787
+ * Gets the current conversation length (number of messages).
788
+ * Useful for determining when to summarize the conversation.
789
+ *
790
+ * @returns Number of messages in the conversation history
791
+ */
792
+ getConversationLength() {
793
+ return this.conversationHistory.length;
794
+ }
795
+ /**
796
+ * Checks if the conversation should be summarized based on length.
797
+ *
798
+ * @param maxLength - Maximum conversation length before summarization (default: 50)
799
+ * @returns Boolean indicating if summarization is needed
800
+ */
801
+ shouldSummarizeConversation(maxLength = 50) {
802
+ return this.getConversationLength() > maxLength;
803
+ }
486
804
  }
487
- exports.PromptBuilder = PromptBuilder;
805
+ exports.InitialPromptBuilder = InitialPromptBuilder;
@@ -26,7 +26,6 @@ class SystemPrompt {
26
26
  * @throws {Error} If file cannot be read or parsed
27
27
  */
28
28
  toPromptText() {
29
- var _a;
30
29
  try {
31
30
  const absolutePath = path_1.default.resolve(this.filepath);
32
31
  const fileContents = fs_1.default.readFileSync(absolutePath, 'utf8');
@@ -34,10 +33,11 @@ class SystemPrompt {
34
33
  if (!data || typeof data !== 'object') {
35
34
  throw new Error('Invalid YAML structure');
36
35
  }
37
- if (!((_a = data[this.key]) === null || _a === void 0 ? void 0 : _a.prompt)) {
36
+ if (!data[this.key]) {
38
37
  throw new Error(`Prompt not found for key: ${this.key}`);
39
38
  }
40
- return data[this.key].prompt;
39
+ const promptData = data[this.key];
40
+ return typeof promptData === 'string' ? promptData : promptData.prompt;
41
41
  }
42
42
  catch (error) {
43
43
  console.error(`SystemPrompt Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
@@ -37,7 +37,7 @@ declare class UserMessage {
37
37
  * @param bAttachEnvironment - Whether to attach environment details
38
38
  * @returns Promise with an array of content blocks for the prompt
39
39
  */
40
- toPrompt(bAttachFiles?: boolean, bAttachImages?: boolean, bAttachEnvironment?: boolean): Promise<UserMessageContent[]>;
40
+ toPrompt(bAttachFiles?: boolean, bAttachImages?: boolean, bAttachEnvironment?: boolean, supportRemix?: boolean): Promise<UserMessageContent[]>;
41
41
  /**
42
42
  * Gets agents mentioned in the message.
43
43
  *
@@ -55,7 +55,7 @@ class UserMessage {
55
55
  * @param bAttachEnvironment - Whether to attach environment details
56
56
  * @returns Promise with an array of content blocks for the prompt
57
57
  */
58
- async toPrompt(bAttachFiles = true, bAttachImages = true, bAttachEnvironment = true) {
58
+ async toPrompt(bAttachFiles = true, bAttachImages = true, bAttachEnvironment = true, supportRemix = true) {
59
59
  var _a;
60
60
  if (bAttachFiles) {
61
61
  if (this.promptOverride) {
@@ -83,6 +83,10 @@ class UserMessage {
83
83
  this.userMessages.push({ type: "text", text: environmentDetail });
84
84
  }
85
85
  }
86
+ if (supportRemix) {
87
+ if (this.message.remixPrompt)
88
+ this.userMessages.push({ type: "text", text: this.message.remixPrompt });
89
+ }
86
90
  return this.userMessages;
87
91
  }
88
92
  /**