@codebolt/codeboltjs 2.0.16 → 2.0.17
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/dist/core/Codebolt.d.ts +1 -1
- package/dist/modules/mcp.d.ts +1 -2
- package/dist/modules/mcp.js +2 -0
- package/dist/utils.d.ts +0 -7
- package/dist/utils.js +1 -15
- package/package.json +1 -1
- package/dist/agentlib/agent.d.ts +0 -86
- package/dist/agentlib/agent.js +0 -326
- package/dist/agentlib/followupquestionbuilder.d.ts +0 -75
- package/dist/agentlib/followupquestionbuilder.js +0 -193
- package/dist/agentlib/llmoutputhandler.d.ts +0 -102
- package/dist/agentlib/llmoutputhandler.js +0 -451
- package/dist/agentlib/promptbuilder.d.ts +0 -382
- package/dist/agentlib/promptbuilder.js +0 -805
- package/dist/agentlib/systemprompt.d.ts +0 -20
- package/dist/agentlib/systemprompt.js +0 -48
- package/dist/agentlib/taskInstruction.d.ts +0 -37
- package/dist/agentlib/taskInstruction.js +0 -57
- package/dist/agentlib/usermessage.d.ts +0 -70
- package/dist/agentlib/usermessage.js +0 -124
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
import { UserMessage as CLIUserMessage } from "../types/socketMessageTypes";
|
|
2
|
-
import type { OpenAIMessage, OpenAITool, ConversationEntry, CodeboltAPI, ToolResult } from "../types/libFunctionTypes";
|
|
3
|
-
import type { MCPTool, Agent, InitialUserMessage } from "../types/commonTypes";
|
|
4
|
-
/**
|
|
5
|
-
* PromptBuilder class for constructing prompts using a fluent interface.
|
|
6
|
-
* Allows chaining methods to build complex prompts from user messages.
|
|
7
|
-
*/
|
|
8
|
-
declare class InitialPromptBuilder {
|
|
9
|
-
/** The main message text */
|
|
10
|
-
private message;
|
|
11
|
-
/** List of mentioned files */
|
|
12
|
-
private mentionedFiles;
|
|
13
|
-
/** List of mentioned MCP tools */
|
|
14
|
-
private mentionedMCPs;
|
|
15
|
-
/** List of mentioned agents */
|
|
16
|
-
private mentionedAgents;
|
|
17
|
-
/** Array of prompt parts that will be joined */
|
|
18
|
-
private promptParts;
|
|
19
|
-
/** System prompt text */
|
|
20
|
-
private systemPromptText;
|
|
21
|
-
/** Task instruction text */
|
|
22
|
-
private taskInstructionText;
|
|
23
|
-
/** Available tools */
|
|
24
|
-
private tools;
|
|
25
|
-
/** Conversation history */
|
|
26
|
-
private conversationHistory;
|
|
27
|
-
/** Environment details */
|
|
28
|
-
private environmentDetails;
|
|
29
|
-
/** File contents cache */
|
|
30
|
-
private fileContents;
|
|
31
|
-
/** Codebolt API instance */
|
|
32
|
-
private codebolt?;
|
|
33
|
-
private shouldLoadMCPTools;
|
|
34
|
-
private mcpAdditionalServers;
|
|
35
|
-
private shouldLoadAgentTools;
|
|
36
|
-
private shouldLoadEnvironmentDetails;
|
|
37
|
-
private shouldLoadAll;
|
|
38
|
-
/**
|
|
39
|
-
* Creates a new PromptBuilder instance.
|
|
40
|
-
*
|
|
41
|
-
* @param userMessage - The initial user message containing text and mentioned entities
|
|
42
|
-
* @param codebolt - Optional codebolt API instance for automatic tool and environment loading
|
|
43
|
-
*/
|
|
44
|
-
constructor(userMessage: InitialUserMessage | CLIUserMessage, codebolt?: CodeboltAPI);
|
|
45
|
-
/**
|
|
46
|
-
* Sets the codebolt API instance for automatic operations.
|
|
47
|
-
*
|
|
48
|
-
* @param codebolt - The codebolt API instance
|
|
49
|
-
* @returns The PromptBuilder instance for chaining
|
|
50
|
-
*/
|
|
51
|
-
setCodeboltAPI(codebolt: CodeboltAPI): this;
|
|
52
|
-
/**
|
|
53
|
-
* Marks MCP tools to be loaded during build from the mentioned MCPs and additional servers.
|
|
54
|
-
*
|
|
55
|
-
* @param additionalServers - Additional MCP servers to load tools from
|
|
56
|
-
* @returns The PromptBuilder instance for chaining
|
|
57
|
-
*/
|
|
58
|
-
addMCPTools(additionalServers?: string[]): this;
|
|
59
|
-
/**
|
|
60
|
-
* Marks mentioned agents to be converted to OpenAI tool format during build.
|
|
61
|
-
*
|
|
62
|
-
* @returns The PromptBuilder instance for chaining
|
|
63
|
-
*/
|
|
64
|
-
addAgentTools(): this;
|
|
65
|
-
/**
|
|
66
|
-
* Marks environment details to be loaded during build.
|
|
67
|
-
*
|
|
68
|
-
* @returns The PromptBuilder instance for chaining
|
|
69
|
-
*/
|
|
70
|
-
addEnvironmentDetails(): this;
|
|
71
|
-
/**
|
|
72
|
-
* Convenience method to mark all tools and environment details to be loaded during build.
|
|
73
|
-
* Equivalent to calling addMCPTools(), addAgentTools(), and addEnvironmentDetails().
|
|
74
|
-
*
|
|
75
|
-
* @param additionalServers - Additional MCP servers to load tools from
|
|
76
|
-
* @returns The PromptBuilder instance for chaining
|
|
77
|
-
*/
|
|
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;
|
|
94
|
-
/**
|
|
95
|
-
* Adds system prompt from a YAML file.
|
|
96
|
-
*
|
|
97
|
-
* @param filepath - Path to the YAML file containing system prompts
|
|
98
|
-
* @param key - Key identifier for the specific prompt
|
|
99
|
-
* @param exampleFilePath - Optional path to example file to append
|
|
100
|
-
* @returns The PromptBuilder instance for chaining
|
|
101
|
-
*/
|
|
102
|
-
addSystemPrompt(filepath: string, key: string, exampleFilePath?: string): this;
|
|
103
|
-
/**
|
|
104
|
-
* Adds task instruction from a YAML file.
|
|
105
|
-
*
|
|
106
|
-
* @param filepath - Path to the YAML file containing task instructions
|
|
107
|
-
* @param refsection - Section name within the YAML file
|
|
108
|
-
* @returns The PromptBuilder instance for chaining
|
|
109
|
-
*/
|
|
110
|
-
addTaskInstruction(filepath: string, refsection: string): this;
|
|
111
|
-
/**
|
|
112
|
-
* Manually adds environment details with file listing.
|
|
113
|
-
* Use addEnvironmentDetails() for automatic loading instead.
|
|
114
|
-
*
|
|
115
|
-
* @param projectPath - The project path
|
|
116
|
-
* @param fileListResult - The file listing result
|
|
117
|
-
* @returns The PromptBuilder instance for chaining
|
|
118
|
-
*/
|
|
119
|
-
setEnvironmentDetails(projectPath: string, fileListResult: string): this;
|
|
120
|
-
/**
|
|
121
|
-
* Adds MCP tools information to the prompt.
|
|
122
|
-
* Only adds content if there are mentioned MCPs.
|
|
123
|
-
*
|
|
124
|
-
* @returns The PromptBuilder instance for chaining
|
|
125
|
-
*/
|
|
126
|
-
addMCPToolsToPrompt(): this;
|
|
127
|
-
/**
|
|
128
|
-
* Adds agent information to the prompt.
|
|
129
|
-
* Only adds content if there are mentioned agents.
|
|
130
|
-
*
|
|
131
|
-
* @returns The PromptBuilder instance for chaining
|
|
132
|
-
*/
|
|
133
|
-
addAgentsToPrompt(): this;
|
|
134
|
-
/**
|
|
135
|
-
* Manually sets the available tools for the conversation.
|
|
136
|
-
* Use addMCPTools() and addAgentTools() for automatic loading instead.
|
|
137
|
-
*
|
|
138
|
-
* @param tools - Array of OpenAI tools
|
|
139
|
-
* @returns The PromptBuilder instance for chaining
|
|
140
|
-
*/
|
|
141
|
-
setTools(tools: OpenAITool[]): this;
|
|
142
|
-
/**
|
|
143
|
-
* Adds additional tools to the existing tool list.
|
|
144
|
-
*
|
|
145
|
-
* @param tools - Array of OpenAI tools to add
|
|
146
|
-
* @returns The PromptBuilder instance for chaining
|
|
147
|
-
*/
|
|
148
|
-
addTools(tools: OpenAITool[]): this;
|
|
149
|
-
/**
|
|
150
|
-
* Builds the user message content with files (without environment details).
|
|
151
|
-
*
|
|
152
|
-
* @returns Array of content blocks
|
|
153
|
-
*/
|
|
154
|
-
private buildUserMessageContent;
|
|
155
|
-
/**
|
|
156
|
-
* Builds the OpenAI conversation format.
|
|
157
|
-
*
|
|
158
|
-
* @returns Array of OpenAI messages
|
|
159
|
-
*/
|
|
160
|
-
buildOpenAIMessages(): OpenAIMessage[];
|
|
161
|
-
/**
|
|
162
|
-
* Gets the available tools in OpenAI format.
|
|
163
|
-
*
|
|
164
|
-
* @returns Array of OpenAI tools
|
|
165
|
-
*/
|
|
166
|
-
getTools(): OpenAITool[];
|
|
167
|
-
/**
|
|
168
|
-
* Gets the loaded file contents.
|
|
169
|
-
*
|
|
170
|
-
* @returns Map of file paths to their contents
|
|
171
|
-
*/
|
|
172
|
-
getFileContents(): Map<string, string>;
|
|
173
|
-
/**
|
|
174
|
-
* Adds a message to the conversation history.
|
|
175
|
-
*
|
|
176
|
-
* @param role - The role of the message sender
|
|
177
|
-
* @param content - The content of the message
|
|
178
|
-
* @param toolCallId - Optional tool call ID for tool messages
|
|
179
|
-
* @param toolCalls - Optional tool calls for assistant messages
|
|
180
|
-
* @returns The PromptBuilder instance for chaining
|
|
181
|
-
*/
|
|
182
|
-
addToConversationHistory(role: 'user' | 'assistant' | 'tool', content: string | Array<{
|
|
183
|
-
type: string;
|
|
184
|
-
text: string;
|
|
185
|
-
}>, toolCallId?: string, toolCalls?: any[]): this;
|
|
186
|
-
/**
|
|
187
|
-
* Gets the current conversation history.
|
|
188
|
-
*
|
|
189
|
-
* @returns Array of conversation entries
|
|
190
|
-
*/
|
|
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;
|
|
287
|
-
/**
|
|
288
|
-
* Adds a custom text section to the prompt.
|
|
289
|
-
*
|
|
290
|
-
* @param title - Optional title for the section
|
|
291
|
-
* @param content - The content to add
|
|
292
|
-
* @returns The PromptBuilder instance for chaining
|
|
293
|
-
*/
|
|
294
|
-
addCustomSection(title: string, content: string): this;
|
|
295
|
-
/**
|
|
296
|
-
* Adds a system instruction to the prompt.
|
|
297
|
-
*
|
|
298
|
-
* @param instruction - The system instruction to add
|
|
299
|
-
* @returns The PromptBuilder instance for chaining
|
|
300
|
-
*/
|
|
301
|
-
addSystemInstruction(instruction: string): this;
|
|
302
|
-
/**
|
|
303
|
-
* Adds context information to the prompt.
|
|
304
|
-
*
|
|
305
|
-
* @param context - The context information to add
|
|
306
|
-
* @returns The PromptBuilder instance for chaining
|
|
307
|
-
*/
|
|
308
|
-
addContext(context: string): this;
|
|
309
|
-
/**
|
|
310
|
-
* Builds and returns the OpenAI message format with tools.
|
|
311
|
-
* This method performs all async operations that were marked during setup.
|
|
312
|
-
*
|
|
313
|
-
* @returns Object with messages, tools, and other LLM parameters
|
|
314
|
-
*/
|
|
315
|
-
build(): Promise<{
|
|
316
|
-
messages: OpenAIMessage[];
|
|
317
|
-
tools: OpenAITool[];
|
|
318
|
-
full: boolean;
|
|
319
|
-
max_tokens: number;
|
|
320
|
-
tool_choice: "auto";
|
|
321
|
-
}>;
|
|
322
|
-
/**
|
|
323
|
-
* Gets the current prompt parts without building the final string.
|
|
324
|
-
* Useful for debugging or inspection.
|
|
325
|
-
*
|
|
326
|
-
* @returns Array of current prompt parts
|
|
327
|
-
*/
|
|
328
|
-
getPromptParts(): string[];
|
|
329
|
-
/**
|
|
330
|
-
* Clears all prompt parts except the initial message.
|
|
331
|
-
* Useful for starting over with the same message.
|
|
332
|
-
*
|
|
333
|
-
* @returns The PromptBuilder instance for chaining
|
|
334
|
-
*/
|
|
335
|
-
reset(): this;
|
|
336
|
-
/**
|
|
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.
|
|
339
|
-
*
|
|
340
|
-
* @returns Object with messages, tools, and other LLM parameters
|
|
341
|
-
*/
|
|
342
|
-
buildInferenceParams(): Promise<{
|
|
343
|
-
full: boolean;
|
|
344
|
-
messages: OpenAIMessage[];
|
|
345
|
-
tools: OpenAITool[];
|
|
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";
|
|
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;
|
|
381
|
-
}
|
|
382
|
-
export { InitialPromptBuilder, MCPTool, Agent, InitialUserMessage, OpenAIMessage, OpenAITool, ConversationEntry, CodeboltAPI };
|