@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
@@ -1,11 +1,11 @@
1
1
  import { UserMessage as CLIUserMessage } from "../types/socketMessageTypes";
2
- import type { OpenAIMessage, OpenAITool, ConversationEntry, CodeboltAPI } from "../types/libFunctionTypes";
2
+ import type { OpenAIMessage, OpenAITool, ConversationEntry, CodeboltAPI, ToolResult } from "../types/libFunctionTypes";
3
3
  import type { MCPTool, Agent, InitialUserMessage } from "../types/commonTypes";
4
4
  /**
5
5
  * PromptBuilder class for constructing prompts using a fluent interface.
6
6
  * Allows chaining methods to build complex prompts from user messages.
7
7
  */
8
- declare class PromptBuilder {
8
+ declare class InitialPromptBuilder {
9
9
  /** The main message text */
10
10
  private message;
11
11
  /** List of mentioned files */
@@ -30,6 +30,11 @@ declare class PromptBuilder {
30
30
  private fileContents;
31
31
  /** Codebolt API instance */
32
32
  private codebolt?;
33
+ private shouldLoadMCPTools;
34
+ private mcpAdditionalServers;
35
+ private shouldLoadAgentTools;
36
+ private shouldLoadEnvironmentDetails;
37
+ private shouldLoadAll;
33
38
  /**
34
39
  * Creates a new PromptBuilder instance.
35
40
  *
@@ -45,33 +50,47 @@ declare class PromptBuilder {
45
50
  */
46
51
  setCodeboltAPI(codebolt: CodeboltAPI): this;
47
52
  /**
48
- * Automatically loads and adds MCP tools from the mentioned MCPs in the user message.
49
- * Also loads default codebolt tools.
53
+ * Marks MCP tools to be loaded during build from the mentioned MCPs and additional servers.
50
54
  *
51
55
  * @param additionalServers - Additional MCP servers to load tools from
52
56
  * @returns The PromptBuilder instance for chaining
53
57
  */
54
- addMCPTools(additionalServers?: string[]): Promise<this>;
58
+ addMCPTools(additionalServers?: string[]): this;
55
59
  /**
56
- * Automatically converts mentioned agents to OpenAI tool format and adds them.
60
+ * Marks mentioned agents to be converted to OpenAI tool format during build.
57
61
  *
58
62
  * @returns The PromptBuilder instance for chaining
59
63
  */
60
64
  addAgentTools(): this;
61
65
  /**
62
- * Automatically loads file contents for mentioned files and adds environment details.
66
+ * Marks environment details to be loaded during build.
63
67
  *
64
68
  * @returns The PromptBuilder instance for chaining
65
69
  */
66
- addEnvironmentDetails(): Promise<this>;
70
+ addEnvironmentDetails(): this;
67
71
  /**
68
- * Convenience method to automatically add all tools and environment details.
72
+ * Convenience method to mark all tools and environment details to be loaded during build.
69
73
  * Equivalent to calling addMCPTools(), addAgentTools(), and addEnvironmentDetails().
70
74
  *
71
75
  * @param additionalServers - Additional MCP servers to load tools from
72
76
  * @returns The PromptBuilder instance for chaining
73
77
  */
74
- addAllAutomatic(additionalServers?: string[]): Promise<this>;
78
+ addAllAutomatic(additionalServers?: string[]): this;
79
+ /**
80
+ * Loads MCP tools from the codebolt API.
81
+ * Internal method called during build.
82
+ */
83
+ private loadMCPTools;
84
+ /**
85
+ * Converts mentioned agents to OpenAI tool format.
86
+ * Internal method called during build.
87
+ */
88
+ private loadAgentTools;
89
+ /**
90
+ * Loads file contents and environment details from the codebolt API.
91
+ * Internal method called during build.
92
+ */
93
+ private loadEnvironmentDetails;
75
94
  /**
76
95
  * Adds system prompt from a YAML file.
77
96
  *
@@ -128,7 +147,7 @@ declare class PromptBuilder {
128
147
  */
129
148
  addTools(tools: OpenAITool[]): this;
130
149
  /**
131
- * Builds the user message content with files and environment details.
150
+ * Builds the user message content with files (without environment details).
132
151
  *
133
152
  * @returns Array of content blocks
134
153
  */
@@ -170,6 +189,101 @@ declare class PromptBuilder {
170
189
  * @returns Array of conversation entries
171
190
  */
172
191
  getConversationHistory(): ConversationEntry[];
192
+ /**
193
+ * Adds an LLM response to the conversation history.
194
+ * This method processes the LLM response and adds the assistant's message to the conversation.
195
+ * It handles both resolved responses and promises that resolve to responses.
196
+ *
197
+ * @param llmResponse - The LLM response (can be a promise or resolved response)
198
+ * @returns The PromptBuilder instance for chaining
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * // Example of using addLLMResponse in an agent workflow loop
203
+ * import { PromptBuilder } from './promptbuilder';
204
+ * import llm from '../modules/llm';
205
+ *
206
+ * async function agentWorkflowWithLLMResponse(userMessage: any, codebolt: CodeboltAPI) {
207
+ * // Step 1: Build initial prompt
208
+ * const promptBuilder = new PromptBuilder(userMessage, codebolt);
209
+ * let currentPrompt = await promptBuilder
210
+ * .addMCPTools()
211
+ * .addAgentTools()
212
+ * .addEnvironmentDetails()
213
+ * .buildInferenceParams();
214
+ *
215
+ * let completed = false;
216
+ * let maxTurns = 20;
217
+ * let turn = 0;
218
+ *
219
+ * // Step 2: Main conversation loop (similar to agent.ts while loop)
220
+ * while (!completed && turn < maxTurns) {
221
+ * // Get LLM response
222
+ * const llmResponse = llm.inference(currentPrompt);
223
+ *
224
+ * // Add LLM response to conversation history
225
+ * await promptBuilder.addLLMResponse(llmResponse);
226
+ *
227
+ * // Process the response using LLMOutputHandler
228
+ * const outputHandler = new LLMOutputHandler(llmResponse, codebolt);
229
+ * await outputHandler.sendMessageToUser();
230
+ *
231
+ * // Check if task is completed
232
+ * if (outputHandler.isCompleted()) {
233
+ * completed = true;
234
+ * break;
235
+ * }
236
+ *
237
+ * // Execute tools and get results
238
+ * const toolResults = await outputHandler.runTools();
239
+ *
240
+ * // Add tool results to conversation
241
+ * if (toolResults.length > 0) {
242
+ * promptBuilder.addToolResults(toolResults);
243
+ * } else {
244
+ * // Add default continuation message when no tools executed
245
+ * promptBuilder.addDefaultContinuationMessage();
246
+ * }
247
+ *
248
+ * // Build next prompt for the loop
249
+ * currentPrompt = await promptBuilder.buildInferenceParams();
250
+ * turn++;
251
+ * }
252
+ * }
253
+ * ```
254
+ */
255
+ addLLMResponse(llmResponse: Promise<{
256
+ completion: any;
257
+ }> | {
258
+ completion: any;
259
+ }): Promise<this>;
260
+ /**
261
+ * Adds tool results to the conversation history.
262
+ * This method is typically used after executing tools from an LLM response.
263
+ *
264
+ * @param toolResults - Array of tool results to add to the conversation
265
+ * @returns The PromptBuilder instance for chaining
266
+ */
267
+ addToolResults(toolResults: ToolResult[]): this;
268
+ /**
269
+ * Adds a user message to the conversation history.
270
+ * Useful for adding follow-up questions or additional context during the conversation.
271
+ *
272
+ * @param message - The user message to add
273
+ * @returns The PromptBuilder instance for chaining
274
+ */
275
+ addUserMessage(message: string | Array<{
276
+ type: string;
277
+ text: string;
278
+ }>): this;
279
+ /**
280
+ * Adds a default continuation message when no tools were executed.
281
+ * This is used in the agent workflow to prompt the LLM to either complete the task
282
+ * or ask for more information.
283
+ *
284
+ * @returns The PromptBuilder instance for chaining
285
+ */
286
+ addDefaultContinuationMessage(): this;
173
287
  /**
174
288
  * Adds a custom text section to the prompt.
175
289
  *
@@ -193,12 +307,18 @@ declare class PromptBuilder {
193
307
  */
194
308
  addContext(context: string): this;
195
309
  /**
196
- * Builds and returns the final prompt string.
197
- * Joins all prompt parts with double newlines.
310
+ * Builds and returns the OpenAI message format with tools.
311
+ * This method performs all async operations that were marked during setup.
198
312
  *
199
- * @returns The complete prompt string
313
+ * @returns Object with messages, tools, and other LLM parameters
200
314
  */
201
- build(): string;
315
+ build(): Promise<{
316
+ messages: OpenAIMessage[];
317
+ tools: OpenAITool[];
318
+ full: boolean;
319
+ max_tokens: number;
320
+ tool_choice: "auto";
321
+ }>;
202
322
  /**
203
323
  * Gets the current prompt parts without building the final string.
204
324
  * Useful for debugging or inspection.
@@ -215,14 +335,48 @@ declare class PromptBuilder {
215
335
  reset(): this;
216
336
  /**
217
337
  * Creates an LLM inference parameters object in the format expected by the sample code.
338
+ * This method performs all async operations that were marked during setup.
218
339
  *
219
340
  * @returns Object with messages, tools, and other LLM parameters
220
341
  */
221
- buildInferenceParams(): {
342
+ buildInferenceParams(): Promise<{
222
343
  full: boolean;
223
344
  messages: OpenAIMessage[];
224
345
  tools: OpenAITool[];
225
346
  tool_choice: "auto";
347
+ }>;
348
+ /**
349
+ * Creates a minimal LLM inference parameters object with only the user message.
350
+ * This is useful for simple completions or when no tools/context are needed.
351
+ *
352
+ * @returns Object with messages (user only), no tools, and default tool_choice
353
+ */
354
+ buildDefaultInferenceParams(): {
355
+ full: boolean;
356
+ messages: string[];
357
+ tools: never[];
358
+ tool_choice: "auto";
226
359
  };
360
+ /**
361
+ * Checks if the last LLM response indicates task completion.
362
+ * This method examines the conversation history for completion signals.
363
+ *
364
+ * @returns Boolean indicating if the task appears to be completed
365
+ */
366
+ isTaskCompleted(): boolean;
367
+ /**
368
+ * Gets the current conversation length (number of messages).
369
+ * Useful for determining when to summarize the conversation.
370
+ *
371
+ * @returns Number of messages in the conversation history
372
+ */
373
+ getConversationLength(): number;
374
+ /**
375
+ * Checks if the conversation should be summarized based on length.
376
+ *
377
+ * @param maxLength - Maximum conversation length before summarization (default: 50)
378
+ * @returns Boolean indicating if summarization is needed
379
+ */
380
+ shouldSummarizeConversation(maxLength?: number): boolean;
227
381
  }
228
- export { PromptBuilder, MCPTool, Agent, InitialUserMessage, OpenAIMessage, OpenAITool, ConversationEntry, CodeboltAPI };
382
+ export { InitialPromptBuilder, MCPTool, Agent, InitialUserMessage, OpenAIMessage, OpenAITool, ConversationEntry, CodeboltAPI };