@codebolt/agent 5.0.1 → 5.0.6

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 (160) hide show
  1. package/dist/agent.d.ts +86 -0
  2. package/dist/agent.js +324 -0
  3. package/dist/builderpattern/agent.js +2 -2
  4. package/dist/builderpattern/followupquestionbuilder.js +1 -1
  5. package/dist/builderpattern/llmoutputhandler.js +7 -7
  6. package/dist/builderpattern/usermessage.d.ts +1 -6
  7. package/dist/composablepattern/document.js +35 -2
  8. package/dist/followupquestionbuilder.d.ts +75 -0
  9. package/dist/followupquestionbuilder.js +197 -0
  10. package/dist/index.d.ts +14 -0
  11. package/dist/index.js +23 -0
  12. package/dist/llmoutputhandler.d.ts +102 -0
  13. package/dist/llmoutputhandler.js +452 -0
  14. package/dist/processor/types/interfaces.d.ts +21 -44
  15. package/dist/processor-pieces/index.d.ts +3 -0
  16. package/dist/processor-pieces/index.js +3 -0
  17. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +5 -14
  18. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +40 -41
  19. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +13 -5
  20. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +58 -50
  21. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +8 -6
  22. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +22 -66
  23. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +2 -3
  24. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +2 -1
  25. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +2 -3
  26. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +2 -1
  27. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -1
  28. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +2 -18
  29. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +93 -291
  30. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +18 -0
  31. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +41 -0
  32. package/dist/processor-pieces/postToolCallProcessors/index.d.ts +2 -1
  33. package/dist/processor-pieces/postToolCallProcessors/index.js +5 -0
  34. package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -1
  35. package/dist/processor-pieces/preInferenceProcessors/index.js +3 -0
  36. package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +2 -1
  37. package/dist/processor-pieces/pretoolCallProcessors/index.js +5 -0
  38. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +21 -0
  39. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +32 -0
  40. package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.d.ts +16 -0
  41. package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.js +37 -0
  42. package/dist/promptbuilder.d.ts +382 -0
  43. package/dist/promptbuilder.js +805 -0
  44. package/dist/systemprompt.d.ts +20 -0
  45. package/dist/systemprompt.js +48 -0
  46. package/dist/taskInstruction.d.ts +37 -0
  47. package/dist/taskInstruction.js +57 -0
  48. package/dist/unified/agent/agent.js +2 -2
  49. package/dist/unified/agent/codeboltAgent.d.ts +122 -0
  50. package/dist/unified/agent/codeboltAgent.js +210 -0
  51. package/dist/unified/base/initialPromptGenerator.js +18 -4
  52. package/dist/unified/base/responseExecutor.d.ts +3 -2
  53. package/dist/unified/base/responseExecutor.js +100 -56
  54. package/dist/unified/index.d.ts +4 -0
  55. package/dist/unified/index.js +12 -1
  56. package/dist/usermessage.d.ts +70 -0
  57. package/dist/usermessage.js +123 -0
  58. package/package.json +5 -5
  59. package/dist/local-tools/fileTools.d.ts +0 -26
  60. package/dist/local-tools/fileTools.js +0 -162
  61. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +0 -13
  62. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +0 -68
  63. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +0 -15
  64. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +0 -212
  65. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +0 -19
  66. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +0 -110
  67. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +0 -23
  68. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +0 -173
  69. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +0 -14
  70. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +0 -93
  71. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +0 -30
  72. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +0 -330
  73. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +0 -26
  74. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +0 -269
  75. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +0 -38
  76. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +0 -217
  77. package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +0 -34
  78. package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +0 -147
  79. package/dist/processor-pieces/additionalModifiers/index.d.ts +0 -12
  80. package/dist/processor-pieces/additionalModifiers/index.js +0 -28
  81. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +0 -29
  82. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +0 -155
  83. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +0 -15
  84. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +0 -129
  85. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +0 -25
  86. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +0 -169
  87. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +0 -20
  88. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +0 -152
  89. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +0 -7
  90. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +0 -93
  91. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +0 -9
  92. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +0 -77
  93. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +0 -19
  94. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +0 -110
  95. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +0 -20
  96. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +0 -124
  97. package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +0 -41
  98. package/dist/processor-pieces/messageModifiers/environmentContext.js +0 -355
  99. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +0 -23
  100. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +0 -207
  101. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +0 -7
  102. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +0 -26
  103. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +0 -1
  104. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +0 -2
  105. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +0 -7
  106. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +0 -24
  107. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +0 -41
  108. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +0 -197
  109. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +0 -26
  110. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +0 -90
  111. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +0 -81
  112. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +0 -329
  113. package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +0 -40
  114. package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +0 -272
  115. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +0 -49
  116. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +0 -291
  117. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +0 -49
  118. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +0 -293
  119. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +0 -47
  120. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +0 -249
  121. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +0 -30
  122. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +0 -137
  123. package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +0 -30
  124. package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +0 -228
  125. package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +0 -99
  126. package/dist/processor-pieces/postToolCall/telemetryProcessor.js +0 -278
  127. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +0 -37
  128. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +0 -178
  129. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +0 -43
  130. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +0 -207
  131. package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +0 -52
  132. package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +0 -264
  133. package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +0 -49
  134. package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +0 -293
  135. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +0 -7
  136. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +0 -31
  137. package/dist/processor-pieces/preToolCall/index.d.ts +0 -9
  138. package/dist/processor-pieces/preToolCall/index.js +0 -18
  139. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +0 -58
  140. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +0 -444
  141. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +0 -44
  142. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +0 -367
  143. package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +0 -58
  144. package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +0 -391
  145. package/dist/unified/agent/tool.d.ts +0 -99
  146. package/dist/unified/agent/tool.js +0 -440
  147. package/dist/unified/examples/agentExample.d.ts +0 -46
  148. package/dist/unified/examples/agentExample.js +0 -464
  149. package/dist/unified/examples/documentationPatternExample.d.ts +0 -10
  150. package/dist/unified/examples/documentationPatternExample.js +0 -385
  151. package/dist/unified/examples/followUpProcessorsExample.d.ts +0 -45
  152. package/dist/unified/examples/followUpProcessorsExample.js +0 -311
  153. package/dist/unified/examples/orchestratorExample.d.ts +0 -16
  154. package/dist/unified/examples/orchestratorExample.js +0 -415
  155. package/dist/unified/examples/preToolCallProcessorsExample.d.ts +0 -36
  156. package/dist/unified/examples/preToolCallProcessorsExample.js +0 -458
  157. package/dist/unified/examples/workflowExample.d.ts +0 -12
  158. package/dist/unified/examples/workflowExample.js +0 -497
  159. package/dist/unified/orchestrator/orchestrator.d.ts +0 -260
  160. package/dist/unified/orchestrator/orchestrator.js +0 -519
@@ -0,0 +1,20 @@
1
+ /**
2
+ * SystemPrompt class for loading and managing system prompts from YAML files
3
+ */
4
+ declare class SystemPrompt {
5
+ private filepath;
6
+ private key;
7
+ /**
8
+ * Creates a SystemPrompt instance
9
+ * @param {string} filepath - Path to the YAML file containing prompts
10
+ * @param {string} key - Key identifier for the specific prompt
11
+ */
12
+ constructor(filepath?: string, key?: string);
13
+ /**
14
+ * Loads and returns the prompt text
15
+ * @returns {string} The prompt text
16
+ * @throws {Error} If file cannot be read or parsed
17
+ */
18
+ toPromptText(): string;
19
+ }
20
+ export { SystemPrompt };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SystemPrompt = void 0;
7
+ const js_yaml_1 = __importDefault(require("js-yaml"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * SystemPrompt class for loading and managing system prompts from YAML files
12
+ */
13
+ class SystemPrompt {
14
+ /**
15
+ * Creates a SystemPrompt instance
16
+ * @param {string} filepath - Path to the YAML file containing prompts
17
+ * @param {string} key - Key identifier for the specific prompt
18
+ */
19
+ constructor(filepath = "", key = "") {
20
+ this.filepath = filepath;
21
+ this.key = key;
22
+ }
23
+ /**
24
+ * Loads and returns the prompt text
25
+ * @returns {string} The prompt text
26
+ * @throws {Error} If file cannot be read or parsed
27
+ */
28
+ toPromptText() {
29
+ try {
30
+ const absolutePath = path_1.default.resolve(this.filepath);
31
+ const fileContents = fs_1.default.readFileSync(absolutePath, 'utf8');
32
+ const data = js_yaml_1.default.load(fileContents);
33
+ if (!data || typeof data !== 'object') {
34
+ throw new Error('Invalid YAML structure');
35
+ }
36
+ if (!data[this.key]) {
37
+ throw new Error(`Prompt not found for key: ${this.key}`);
38
+ }
39
+ const promptData = data[this.key];
40
+ return typeof promptData === 'string' ? promptData : promptData.prompt;
41
+ }
42
+ catch (error) {
43
+ console.error(`SystemPrompt Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
44
+ throw error; // Re-throw to allow caller handling
45
+ }
46
+ }
47
+ }
48
+ exports.SystemPrompt = SystemPrompt;
@@ -0,0 +1,37 @@
1
+ import { UserMessage } from "./usermessage";
2
+ import type { UserMessageContent } from "./types/libFunctionTypes";
3
+ import type { Tools, UserMessages } from "./types/InternalTypes";
4
+ /**
5
+ * Class representing a task instruction.
6
+ * Handles loading task data and converting it to prompts.
7
+ */
8
+ declare class TaskInstruction {
9
+ /** Available tools for the task */
10
+ tools: Tools;
11
+ /** Messages from the user for this task */
12
+ userMessages: UserMessageContent[];
13
+ /** The user message object containing input */
14
+ userMessage: UserMessage;
15
+ /** Path to the YAML file with task instructions */
16
+ filepath: string;
17
+ /** The section reference within the YAML file */
18
+ refsection: string;
19
+ /**
20
+ * Creates a new TaskInstruction instance.
21
+ *
22
+ * @param tools - Tools available for this task
23
+ * @param userMessage - User message containing task instructions
24
+ * @param filepath - Path to the YAML file with task data
25
+ * @param refsection - Section name within the YAML file
26
+ */
27
+ constructor(tools: Tools | undefined, userMessage: UserMessage, filepath?: string, refsection?: string);
28
+ /**
29
+ * Converts the task instruction to a prompt format.
30
+ * Loads data from YAML file and combines with user message.
31
+ *
32
+ * @returns Promise with an array of user message content blocks
33
+ * @throws Error if there's an issue processing the task instruction
34
+ */
35
+ toPrompt(): Promise<UserMessages[]>;
36
+ }
37
+ export { TaskInstruction };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskInstruction = void 0;
4
+ /**
5
+ * Encapsulates task instructions and their related metadata.
6
+ * Handles loading and processing of task instructions from YAML files.
7
+ */
8
+ const yaml = require('js-yaml');
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ /**
12
+ * Class representing a task instruction.
13
+ * Handles loading task data and converting it to prompts.
14
+ */
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
+ */
24
+ constructor(tools = {}, userMessage, filepath = "", refsection = "") {
25
+ /** Messages from the user for this task */
26
+ this.userMessages = [];
27
+ this.tools = tools;
28
+ this.userMessage = userMessage;
29
+ this.filepath = filepath;
30
+ this.refsection = refsection;
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
+ */
39
+ async toPrompt() {
40
+ try {
41
+ this.userMessages = await this.userMessage.toPrompt();
42
+ const fileContents = fs.readFileSync(path.resolve(this.filepath), 'utf8');
43
+ const data = yaml.load(fileContents);
44
+ const task = data[this.refsection];
45
+ this.userMessages.push({
46
+ type: "text",
47
+ text: `Task Description: ${task.description}\nExpected Output: ${task.expected_output}`
48
+ });
49
+ return this.userMessages;
50
+ }
51
+ catch (error) {
52
+ console.error(`Error processing task instruction: ${error}`);
53
+ throw error;
54
+ }
55
+ }
56
+ }
57
+ exports.TaskInstruction = TaskInstruction;
@@ -42,11 +42,11 @@ class Agent {
42
42
  // console.log('[Agent] Step completed, processing response');
43
43
  }
44
44
  const responseExecutor = new responseExecutor_1.ResponseExecutor({
45
- preToolCalProcessors: this.preToolCallProcessors,
45
+ preToolCallProcessors: this.preToolCallProcessors,
46
46
  postToolCallProcessors: this.postToolCallProcessors
47
47
  });
48
48
  const executionResult = await responseExecutor.executeResponse({
49
- initailUserMessage: reqMessage,
49
+ initialUserMessage: reqMessage,
50
50
  actualMessageSentToLLM: stepResult.actualMessageSentToLLM,
51
51
  rawLLMOutput: stepResult.rawLLMResponse,
52
52
  nextMessage: stepResult.nextMessage
@@ -0,0 +1,122 @@
1
+ import { AgentConfig, MessageModifier, PostInferenceProcessor, PostToolCallProcessor, PreInferenceProcessor, PreToolCallProcessor } from "@codebolt/types/agent";
2
+ import { FlatUserMessage } from "@codebolt/types/sdk";
3
+ /**
4
+ * Configuration options for CodeboltAgent
5
+ */
6
+ export interface CodeboltAgentConfig extends AgentConfig {
7
+ /**
8
+ * Enable logging for debugging purposes.
9
+ * Defaults to true.
10
+ */
11
+ enableLogging?: boolean;
12
+ }
13
+ /**
14
+ * CodeboltAgent is a high-level agent class that:
15
+ * - Uses InitialPromptGenerator with configurable processors/modifiers
16
+ * - Runs an agent loop with AgentStep and ResponseExecutor
17
+ * - Handles tool execution and conversation flow automatically
18
+ * - Is triggered via processMessage (not via onMessage listener)
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { CodeboltAgent } from '@codebolt/agent/unified';
23
+ * import {
24
+ * EnvironmentContextModifier,
25
+ * CoreSystemPromptModifier,
26
+ * DirectoryContextModifier,
27
+ * IdeContextModifier,
28
+ * AtFileProcessorModifier,
29
+ * ToolInjectionModifier,
30
+ * ChatHistoryMessageModifier
31
+ * } from '@codebolt/agent/processor-pieces';
32
+ *
33
+ * const systemPrompt = `You are an AI coding assistant...`;
34
+ *
35
+ * const agent = new CodeboltAgent({
36
+ * instructions: systemPrompt,
37
+ * processors: {
38
+ * messageModifiers: [
39
+ * new ChatHistoryMessageModifier({ enableChatHistory: true }),
40
+ * new EnvironmentContextModifier({ enableFullContext: true }),
41
+ * new DirectoryContextModifier(),
42
+ * new IdeContextModifier({
43
+ * includeActiveFile: true,
44
+ * includeOpenFiles: true,
45
+ * includeCursorPosition: true,
46
+ * includeSelectedText: true
47
+ * }),
48
+ * new CoreSystemPromptModifier({ customSystemPrompt: systemPrompt }),
49
+ * new ToolInjectionModifier({ includeToolDescriptions: true }),
50
+ * new AtFileProcessorModifier({ enableRecursiveSearch: true })
51
+ * ],
52
+ * preInferenceProcessors: [],
53
+ * postInferenceProcessors: [],
54
+ * preToolCallProcessors: [],
55
+ * postToolCallProcessors: []
56
+ * }
57
+ * });
58
+ *
59
+ * // Process a message (triggered from graph node)
60
+ * const result = await agent.processMessage(userMessage);
61
+ * ```
62
+ */
63
+ export declare class CodeboltAgent {
64
+ private readonly config;
65
+ private readonly messageModifiers;
66
+ private readonly preInferenceProcessors;
67
+ private readonly postInferenceProcessors;
68
+ private readonly preToolCallProcessors;
69
+ private readonly postToolCallProcessors;
70
+ private readonly enableLogging;
71
+ private readonly baseSystemPrompt;
72
+ constructor(config: CodeboltAgentConfig);
73
+ /**
74
+ * Creates default message modifiers when none are provided
75
+ */
76
+ private createDefaultMessageModifiers;
77
+ /**
78
+ * Process a message through the agent pipeline.
79
+ * This is the main entry point - triggered from graph nodes.
80
+ */
81
+ processMessage(reqMessage: FlatUserMessage): Promise<{
82
+ success: boolean;
83
+ result: any;
84
+ error?: string;
85
+ }>;
86
+ /**
87
+ * Get the current configuration
88
+ */
89
+ getConfig(): CodeboltAgentConfig;
90
+ /**
91
+ * Get all message modifiers
92
+ */
93
+ getMessageModifiers(): MessageModifier[];
94
+ /**
95
+ * Get all pre-inference processors
96
+ */
97
+ getPreInferenceProcessors(): PreInferenceProcessor[];
98
+ /**
99
+ * Get all post-inference processors
100
+ */
101
+ getPostInferenceProcessors(): PostInferenceProcessor[];
102
+ /**
103
+ * Get all pre-tool-call processors
104
+ */
105
+ getPreToolCallProcessors(): PreToolCallProcessor[];
106
+ /**
107
+ * Get all post-tool-call processors
108
+ */
109
+ getPostToolCallProcessors(): PostToolCallProcessor[];
110
+ }
111
+ /**
112
+ * Factory function to create a CodeboltAgent with common defaults
113
+ */
114
+ export declare function createCodeboltAgent(options: {
115
+ systemPrompt: string;
116
+ messageModifiers?: MessageModifier[];
117
+ preInferenceProcessors?: PreInferenceProcessor[];
118
+ postInferenceProcessors?: PostInferenceProcessor[];
119
+ preToolCallProcessors?: PreToolCallProcessor[];
120
+ postToolCallProcessors?: PostToolCallProcessor[];
121
+ enableLogging?: boolean;
122
+ }): CodeboltAgent;
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CodeboltAgent = void 0;
4
+ exports.createCodeboltAgent = createCodeboltAgent;
5
+ const base_1 = require("../base");
6
+ const responseExecutor_1 = require("../base/responseExecutor");
7
+ const agentStep_1 = require("../base/agentStep");
8
+ const processor_pieces_1 = require("../../processor-pieces");
9
+ /**
10
+ * CodeboltAgent is a high-level agent class that:
11
+ * - Uses InitialPromptGenerator with configurable processors/modifiers
12
+ * - Runs an agent loop with AgentStep and ResponseExecutor
13
+ * - Handles tool execution and conversation flow automatically
14
+ * - Is triggered via processMessage (not via onMessage listener)
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { CodeboltAgent } from '@codebolt/agent/unified';
19
+ * import {
20
+ * EnvironmentContextModifier,
21
+ * CoreSystemPromptModifier,
22
+ * DirectoryContextModifier,
23
+ * IdeContextModifier,
24
+ * AtFileProcessorModifier,
25
+ * ToolInjectionModifier,
26
+ * ChatHistoryMessageModifier
27
+ * } from '@codebolt/agent/processor-pieces';
28
+ *
29
+ * const systemPrompt = `You are an AI coding assistant...`;
30
+ *
31
+ * const agent = new CodeboltAgent({
32
+ * instructions: systemPrompt,
33
+ * processors: {
34
+ * messageModifiers: [
35
+ * new ChatHistoryMessageModifier({ enableChatHistory: true }),
36
+ * new EnvironmentContextModifier({ enableFullContext: true }),
37
+ * new DirectoryContextModifier(),
38
+ * new IdeContextModifier({
39
+ * includeActiveFile: true,
40
+ * includeOpenFiles: true,
41
+ * includeCursorPosition: true,
42
+ * includeSelectedText: true
43
+ * }),
44
+ * new CoreSystemPromptModifier({ customSystemPrompt: systemPrompt }),
45
+ * new ToolInjectionModifier({ includeToolDescriptions: true }),
46
+ * new AtFileProcessorModifier({ enableRecursiveSearch: true })
47
+ * ],
48
+ * preInferenceProcessors: [],
49
+ * postInferenceProcessors: [],
50
+ * preToolCallProcessors: [],
51
+ * postToolCallProcessors: []
52
+ * }
53
+ * });
54
+ *
55
+ * // Process a message (triggered from graph node)
56
+ * const result = await agent.processMessage(userMessage);
57
+ * ```
58
+ */
59
+ class CodeboltAgent {
60
+ constructor(config) {
61
+ var _a, _b, _c, _d, _e, _f;
62
+ this.config = { ...config };
63
+ this.enableLogging = config.enableLogging !== false;
64
+ this.baseSystemPrompt = config.instructions || 'Based on User Message send reply';
65
+ // Use provided modifiers or default ones
66
+ this.messageModifiers = ((_b = (_a = config.processors) === null || _a === void 0 ? void 0 : _a.messageModifiers) === null || _b === void 0 ? void 0 : _b.length)
67
+ ? config.processors.messageModifiers
68
+ : this.createDefaultMessageModifiers(this.baseSystemPrompt);
69
+ this.preInferenceProcessors = ((_c = config.processors) === null || _c === void 0 ? void 0 : _c.preInferenceProcessors) || [];
70
+ this.postInferenceProcessors = ((_d = config.processors) === null || _d === void 0 ? void 0 : _d.postInferenceProcessors) || [];
71
+ this.preToolCallProcessors = ((_e = config.processors) === null || _e === void 0 ? void 0 : _e.preToolCallProcessors) || [];
72
+ this.postToolCallProcessors = ((_f = config.processors) === null || _f === void 0 ? void 0 : _f.postToolCallProcessors) || [];
73
+ }
74
+ /**
75
+ * Creates default message modifiers when none are provided
76
+ */
77
+ createDefaultMessageModifiers(systemPrompt) {
78
+ return [
79
+ // 1. Chat History
80
+ new processor_pieces_1.ChatHistoryMessageModifier({ enableChatHistory: true }),
81
+ // 2. Environment Context (date, OS)
82
+ new processor_pieces_1.EnvironmentContextModifier({ enableFullContext: true }),
83
+ // 3. Directory Context (folder structure)
84
+ new processor_pieces_1.DirectoryContextModifier(),
85
+ // 4. IDE Context (active file, opened files)
86
+ new processor_pieces_1.IdeContextModifier({
87
+ includeActiveFile: true,
88
+ includeOpenFiles: true,
89
+ includeCursorPosition: true,
90
+ includeSelectedText: true
91
+ }),
92
+ // 5. Core System Prompt (instructions)
93
+ new processor_pieces_1.CoreSystemPromptModifier({ customSystemPrompt: systemPrompt }),
94
+ // 6. Tools (function declarations)
95
+ new processor_pieces_1.ToolInjectionModifier({ includeToolDescriptions: true }),
96
+ // 7. At-file processing (@file mentions)
97
+ new processor_pieces_1.AtFileProcessorModifier({ enableRecursiveSearch: true })
98
+ ];
99
+ }
100
+ /**
101
+ * Process a message through the agent pipeline.
102
+ * This is the main entry point - triggered from graph nodes.
103
+ */
104
+ async processMessage(reqMessage) {
105
+ try {
106
+ if (this.enableLogging) {
107
+ console.log('[CodeboltAgent] Processing message');
108
+ }
109
+ const promptGenerator = new base_1.InitialPromptGenerator({
110
+ processors: this.messageModifiers,
111
+ baseSystemPrompt: this.baseSystemPrompt,
112
+ enableLogging: this.enableLogging
113
+ });
114
+ let prompt = await promptGenerator.processMessage(reqMessage);
115
+ let completed = false;
116
+ while (!completed) {
117
+ const agentStep = new agentStep_1.AgentStep({
118
+ preInferenceProcessors: this.preInferenceProcessors,
119
+ postInferenceProcessors: this.postInferenceProcessors
120
+ });
121
+ const stepResult = await agentStep.executeStep(reqMessage, prompt);
122
+ prompt = stepResult.nextMessage;
123
+ const responseExecutor = new responseExecutor_1.ResponseExecutor({
124
+ preToolCallProcessors: this.preToolCallProcessors,
125
+ postToolCallProcessors: this.postToolCallProcessors
126
+ });
127
+ const executionResult = await responseExecutor.executeResponse({
128
+ initialUserMessage: reqMessage,
129
+ actualMessageSentToLLM: stepResult.actualMessageSentToLLM,
130
+ rawLLMOutput: stepResult.rawLLMResponse,
131
+ nextMessage: stepResult.nextMessage
132
+ });
133
+ completed = executionResult.completed;
134
+ prompt = executionResult.nextMessage;
135
+ }
136
+ if (this.enableLogging) {
137
+ console.log('[CodeboltAgent] Message processing completed');
138
+ }
139
+ return {
140
+ success: true,
141
+ result: prompt,
142
+ error: undefined
143
+ };
144
+ }
145
+ catch (error) {
146
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
147
+ if (this.enableLogging) {
148
+ console.error('[CodeboltAgent] Execution failed:', error);
149
+ }
150
+ return {
151
+ success: false,
152
+ result: null,
153
+ error: errorMessage
154
+ };
155
+ }
156
+ }
157
+ /**
158
+ * Get the current configuration
159
+ */
160
+ getConfig() {
161
+ return { ...this.config };
162
+ }
163
+ /**
164
+ * Get all message modifiers
165
+ */
166
+ getMessageModifiers() {
167
+ return [...this.messageModifiers];
168
+ }
169
+ /**
170
+ * Get all pre-inference processors
171
+ */
172
+ getPreInferenceProcessors() {
173
+ return [...this.preInferenceProcessors];
174
+ }
175
+ /**
176
+ * Get all post-inference processors
177
+ */
178
+ getPostInferenceProcessors() {
179
+ return [...this.postInferenceProcessors];
180
+ }
181
+ /**
182
+ * Get all pre-tool-call processors
183
+ */
184
+ getPreToolCallProcessors() {
185
+ return [...this.preToolCallProcessors];
186
+ }
187
+ /**
188
+ * Get all post-tool-call processors
189
+ */
190
+ getPostToolCallProcessors() {
191
+ return [...this.postToolCallProcessors];
192
+ }
193
+ }
194
+ exports.CodeboltAgent = CodeboltAgent;
195
+ /**
196
+ * Factory function to create a CodeboltAgent with common defaults
197
+ */
198
+ function createCodeboltAgent(options) {
199
+ return new CodeboltAgent({
200
+ instructions: options.systemPrompt,
201
+ processors: {
202
+ messageModifiers: options.messageModifiers || [],
203
+ preInferenceProcessors: options.preInferenceProcessors || [],
204
+ postInferenceProcessors: options.postInferenceProcessors || [],
205
+ preToolCallProcessors: options.preToolCallProcessors || [],
206
+ postToolCallProcessors: options.postToolCallProcessors || []
207
+ },
208
+ enableLogging: options.enableLogging
209
+ });
210
+ }
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.InitialPromptGenerator = void 0;
4
7
  exports.createUnifiedMessageProcessor = createUnifiedMessageProcessor;
5
8
  const types_1 = require("../types/types");
9
+ const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
6
10
  /**
7
11
  * Initial prompt generator that combines message modifiers with unified processing
8
12
  */
@@ -50,10 +54,20 @@ class InitialPromptGenerator {
50
54
  // Continue with other modifiers
51
55
  }
52
56
  }
53
- createdMessage.message.messages.push({
54
- role: 'assistant',
55
- content: "Got it. Thanks for the context!"
56
- });
57
+ const lastMessage = createdMessage.message.messages[createdMessage.message.messages.length - 1];
58
+ if (!lastMessage || lastMessage.role !== 'system') {
59
+ createdMessage.message.messages.push({
60
+ role: 'assistant',
61
+ content: "Got it. Thanks for the context!"
62
+ });
63
+ }
64
+ let { todos } = await codeboltjs_1.default.todo.getAllIncompleteTodos();
65
+ if (todos && todos.length == 0) {
66
+ createdMessage.message.messages.push({
67
+ role: 'user',
68
+ content: "<system-reminder>\nThis is a reminder that your todo list is currently empty. DO NOT mention this to the user explicitly because they are already aware. If you are working on tasks that would benefit from a todo list please use the TodoWrite tool to create one. If not, please feel free to ignore. Again do not mention this message to the user.\n</system-reminder>"
69
+ });
70
+ }
57
71
  createdMessage.message.messages.push({
58
72
  role: 'user',
59
73
  content: content.trim()
@@ -1,10 +1,11 @@
1
1
  import { AgentResponseExecutor, PostToolCallProcessor, PreToolCallProcessor, ResponseInput, ResponseOutput } from '@codebolt/types/agent';
2
2
  export declare class ResponseExecutor implements AgentResponseExecutor {
3
- private preToolCalProcessors;
3
+ private preToolCallProcessors;
4
4
  private postToolCallProcessors;
5
5
  private completed;
6
+ private finalMessage;
6
7
  constructor(options: {
7
- preToolCalProcessors: PreToolCallProcessor[];
8
+ preToolCallProcessors: PreToolCallProcessor[];
8
9
  postToolCallProcessors: PostToolCallProcessor[];
9
10
  });
10
11
  executeResponse(input: ResponseInput): Promise<ResponseOutput>;