@codebolt/agent 5.0.7 → 5.0.8

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 (48) hide show
  1. package/dist/processor-pieces/base/basePreToolCallProcessor.js +5 -2
  2. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +1 -1
  3. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +2 -2
  4. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +24 -34
  5. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +1 -1
  6. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +2 -2
  7. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +1 -1
  8. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +2 -2
  9. package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -1
  10. package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +8 -3
  11. package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -1
  12. package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +1 -1
  13. package/dist/processor-pieces/messageModifiers/ideContextModifier.js +114 -17
  14. package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +1 -1
  15. package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +13 -5
  16. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +5 -0
  17. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -0
  18. package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +24 -8
  19. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +202 -5
  20. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +826 -19
  21. package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -1
  22. package/dist/processor-pieces/postToolCallProcessors/index.js +2 -1
  23. package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +7 -4
  24. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +1 -1
  25. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +12 -16
  26. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +2 -3
  27. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +1 -2
  28. package/dist/processor-pieces/utils/messageModifierHelper.js +5 -2
  29. package/dist/types/InternalTypes.d.ts +8 -6
  30. package/dist/unified/agent/agent.js +1 -2
  31. package/dist/unified/agent/codeboltAgent.d.ts +23 -2
  32. package/dist/unified/agent/codeboltAgent.js +55 -12
  33. package/dist/unified/agent/tools.d.ts +7 -11
  34. package/dist/unified/agent/tools.js +12 -3
  35. package/dist/unified/agent/workflow.js +38 -20
  36. package/dist/unified/agent/workflowSteps.d.ts +1 -1
  37. package/dist/unified/agent/workflowSteps.js +58 -23
  38. package/dist/unified/base/agentStep.js +20 -1
  39. package/dist/unified/base/initialPromptGenerator.js +3 -1
  40. package/dist/unified/base/responseExecutor.d.ts +3 -0
  41. package/dist/unified/base/responseExecutor.js +40 -18
  42. package/dist/unified/index.d.ts +1 -0
  43. package/dist/unified/index.js +4 -1
  44. package/dist/unified/services/LoopDetectionService.d.ts +44 -0
  45. package/dist/unified/services/LoopDetectionService.js +79 -0
  46. package/dist/unified/utils/utils.d.ts +20 -1
  47. package/dist/unified/utils/utils.js +8 -4
  48. package/package.json +5 -5
@@ -1,2 +1,2 @@
1
1
  export { ShellProcessorModifier } from './shellProcessorModifier';
2
- export { ConversationCompactorModifier, type ConversationCompactorOptions } from './conversationCompactorModifier';
2
+ export { ConversationCompactorModifier, type ConversationCompactorOptions, type CompressionMetadata, CompressionStatus } from './conversationCompactorModifier';
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConversationCompactorModifier = exports.ShellProcessorModifier = void 0;
3
+ exports.CompressionStatus = exports.ConversationCompactorModifier = exports.ShellProcessorModifier = void 0;
4
4
  var shellProcessorModifier_1 = require("./shellProcessorModifier");
5
5
  Object.defineProperty(exports, "ShellProcessorModifier", { enumerable: true, get: function () { return shellProcessorModifier_1.ShellProcessorModifier; } });
6
6
  var conversationCompactorModifier_1 = require("./conversationCompactorModifier");
7
7
  Object.defineProperty(exports, "ConversationCompactorModifier", { enumerable: true, get: function () { return conversationCompactorModifier_1.ConversationCompactorModifier; } });
8
+ Object.defineProperty(exports, "CompressionStatus", { enumerable: true, get: function () { return conversationCompactorModifier_1.CompressionStatus; } });
@@ -22,7 +22,7 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
22
22
  async modify(input) {
23
23
  var _a;
24
24
  try {
25
- const { llmMessageSent, rawLLMResponseMessage, nextPrompt, toolResults } = input;
25
+ const { nextPrompt, toolResults } = input;
26
26
  // Process shell commands in tool results if they exist
27
27
  let processedNextPrompt = nextPrompt;
28
28
  let shouldExit = false;
@@ -46,7 +46,7 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
46
46
  if (typeof message.content === 'string') {
47
47
  let processedContent = message.content;
48
48
  // Replace {{args}} placeholders if metadata has args
49
- const args = ((_a = processedNextPrompt.metadata) === null || _a === void 0 ? void 0 : _a.args) || '';
49
+ const args = ((_a = processedNextPrompt.metadata) === null || _a === void 0 ? void 0 : _a['args']) || '';
50
50
  if (processedContent.includes(this.ARGS_PLACEHOLDER)) {
51
51
  processedContent = processedContent.replace(new RegExp(this.escapeRegex(this.ARGS_PLACEHOLDER), 'g'), args);
52
52
  contentModified = true;
@@ -97,7 +97,7 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
97
97
  let processedPrompt = nextPrompt;
98
98
  for (const result of shellResults) {
99
99
  if (result.content && typeof result.content === 'string') {
100
- const args = ((_a = processedPrompt.metadata) === null || _a === void 0 ? void 0 : _a.args) || '';
100
+ const args = ((_a = processedPrompt.metadata) === null || _a === void 0 ? void 0 : _a['args']) || '';
101
101
  // Process any shell injections in the tool result content
102
102
  if (result.content.includes(this.SHELL_TRIGGER)) {
103
103
  const processedContent = await this.processShellInjections(result.content, args);
@@ -127,6 +127,8 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
127
127
  // Process injections in reverse order to maintain correct indices
128
128
  for (let i = injections.length - 1; i >= 0; i--) {
129
129
  const injection = injections[i];
130
+ if (!injection)
131
+ continue;
130
132
  try {
131
133
  // Replace {{args}} in the command with shell-escaped args
132
134
  const command = injection.command.replace(new RegExp(this.escapeRegex(this.ARGS_PLACEHOLDER), 'g'), this.escapeShellArg(args));
@@ -175,11 +177,12 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
175
177
  return injections;
176
178
  }
177
179
  validateCommand(command) {
180
+ var _a;
178
181
  if (!this.options.enableShellExecution) {
179
182
  throw new Error('Shell execution is disabled');
180
183
  }
181
184
  // Extract the base command (first word)
182
- const baseCommand = command.trim().split(/\s+/)[0];
185
+ const baseCommand = (_a = command.trim().split(/\s+/)[0]) !== null && _a !== void 0 ? _a : '';
183
186
  // Check blocked commands
184
187
  if (this.options.blockedCommands.some(blocked => baseCommand.includes(blocked))) {
185
188
  throw new Error(`Command '${baseCommand}' is blocked for security reasons`);
@@ -25,7 +25,7 @@ export declare class ChatCompressionModifier extends BasePreInferenceProcessor {
25
25
  private readonly options;
26
26
  private hasFailedCompressionAttempt;
27
27
  constructor(options?: ChatCompressionOptions);
28
- modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
28
+ modify(_originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
29
29
  tryCompressChat(messages: MessageObject[], force?: boolean): Promise<ChatCompressionInfo & {
30
30
  compressedMessages?: MessageObject[];
31
31
  }>;
@@ -27,6 +27,7 @@ var CompressionStatus;
27
27
  * Returns the index of the content after the fraction of the total characters in the history.
28
28
  */
29
29
  function findIndexAfterFraction(history, fraction) {
30
+ var _a;
30
31
  if (fraction <= 0 || fraction >= 1) {
31
32
  throw new Error('Fraction must be between 0 and 1');
32
33
  }
@@ -35,7 +36,8 @@ function findIndexAfterFraction(history, fraction) {
35
36
  const targetCharacters = totalCharacters * fraction;
36
37
  let charactersSoFar = 0;
37
38
  for (let i = 0; i < contentLengths.length; i++) {
38
- charactersSoFar += contentLengths[i];
39
+ const length = (_a = contentLengths[i]) !== null && _a !== void 0 ? _a : 0;
40
+ charactersSoFar += length;
39
41
  if (charactersSoFar >= targetCharacters) {
40
42
  return i;
41
43
  }
@@ -72,7 +74,7 @@ class ChatCompressionModifier extends base_1.BasePreInferenceProcessor {
72
74
  force: options.force || false
73
75
  };
74
76
  }
75
- async modify(originalRequest, createdMessage) {
77
+ async modify(_originalRequest, createdMessage) {
76
78
  try {
77
79
  const compressionResult = await this.tryCompressChat(createdMessage.message.messages, this.options.force || false);
78
80
  if (compressionResult.compressionStatus === CompressionStatus.COMPRESSED) {
@@ -107,7 +109,6 @@ class ChatCompressionModifier extends base_1.BasePreInferenceProcessor {
107
109
  }
108
110
  }
109
111
  async tryCompressChat(messages, force = false) {
110
- var _a;
111
112
  const curatedHistory = messages;
112
113
  // Regardless of `force`, don't do anything if the history is empty.
113
114
  if (curatedHistory.length === 0 ||
@@ -144,9 +145,12 @@ class ChatCompressionModifier extends base_1.BasePreInferenceProcessor {
144
145
  }
145
146
  let compressBeforeIndex = findIndexAfterFraction(curatedHistory, 1 - COMPRESSION_PRESERVE_THRESHOLD);
146
147
  // Find the first user message after the index. This is the start of the next turn.
147
- while (compressBeforeIndex < curatedHistory.length &&
148
- (((_a = curatedHistory[compressBeforeIndex]) === null || _a === void 0 ? void 0 : _a.role) === 'assistant' ||
149
- isFunctionResponse(curatedHistory[compressBeforeIndex]))) {
148
+ while (compressBeforeIndex < curatedHistory.length) {
149
+ const currentMessage = curatedHistory[compressBeforeIndex];
150
+ if (!currentMessage)
151
+ break;
152
+ if (currentMessage.role !== 'assistant' && !isFunctionResponse(currentMessage))
153
+ break;
150
154
  compressBeforeIndex++;
151
155
  }
152
156
  const historyToCompress = curatedHistory.slice(0, compressBeforeIndex);
@@ -189,7 +193,7 @@ class ChatCompressionModifier extends base_1.BasePreInferenceProcessor {
189
193
  compressedMessages,
190
194
  };
191
195
  }
192
- async countTokens(model, messages) {
196
+ async countTokens(_model, messages) {
193
197
  // Mock token counting - should be replaced with actual API call
194
198
  // Rough approximation: 4 characters per token
195
199
  const totalCharacters = messages.reduce((sum, msg) => {
@@ -200,15 +204,7 @@ class ChatCompressionModifier extends base_1.BasePreInferenceProcessor {
200
204
  async generateCompressionSummary(messages) {
201
205
  // This should use the actual compression prompt and LLM call
202
206
  // For now, using a simplified version similar to the original
203
- const compressionPrompt = `You are tasked with creating a concise summary of a conversation history to preserve context while reducing token usage.
204
-
205
- Please analyze the conversation and create a state snapshot that captures:
206
- 1. Key topics discussed
207
- 2. Important decisions made
208
- 3. Current context and progress
209
- 4. Any ongoing tasks or issues
210
-
211
- Format your response as a clear, structured summary that maintains the essential information needed to continue the conversation effectively.`;
207
+ // Compression prompt would be used for LLM summarization in a full implementation
212
208
  // Mock LLM call - should be replaced with actual LLM integration
213
209
  const summaryParts = [];
214
210
  let userQuestions = [];
@@ -7,7 +7,7 @@ import { PreToolCallProcessorInput, PreToolCallProcessorOutput } from '@codebolt
7
7
  export interface ParameterTransformation {
8
8
  sourcePath: string;
9
9
  targetPath: string;
10
- transformation?: (value: any) => any;
10
+ transformation?: (value: unknown) => unknown;
11
11
  description?: string;
12
12
  }
13
13
  export interface ToolParameterModifierOptions {
@@ -15,7 +15,6 @@ export interface ToolParameterModifierOptions {
15
15
  toolNameMappings?: Record<string, string>;
16
16
  }
17
17
  export declare class ToolParameterModifier extends BasePreToolCallProcessor {
18
- private options;
19
- constructor(options: ToolParameterModifierOptions);
18
+ constructor(_options: ToolParameterModifierOptions);
20
19
  modify(input: PreToolCallProcessorInput): Promise<PreToolCallProcessorOutput>;
21
20
  }
@@ -7,9 +7,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.ToolParameterModifier = void 0;
8
8
  const basePreToolCallProcessor_1 = require("../base/basePreToolCallProcessor");
9
9
  class ToolParameterModifier extends basePreToolCallProcessor_1.BasePreToolCallProcessor {
10
- constructor(options) {
10
+ constructor(_options) {
11
11
  super();
12
- this.options = options;
13
12
  }
14
13
  async modify(input) {
15
14
  // For now, pass through unchanged since we need to understand the exact structure
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addUserContext = exports.addSystemMessage = exports.mergeMessages = void 0;
4
4
  // Helper method to merge messages
5
5
  const mergeMessages = (existing, additional) => {
6
- return {
6
+ const result = {
7
7
  message: {
8
8
  ...existing.message,
9
9
  ...additional.message,
10
10
  messages: [...existing.message.messages, ...additional.message.messages],
11
- tools: additional.message.tools
12
11
  },
13
12
  metadata: {
14
13
  ...existing.metadata,
@@ -17,6 +16,10 @@ const mergeMessages = (existing, additional) => {
17
16
  mergedAt: new Date().toISOString()
18
17
  }
19
18
  };
19
+ if (additional.message.tools) {
20
+ result.message.tools = additional.message.tools;
21
+ }
22
+ return result;
20
23
  };
21
24
  exports.mergeMessages = mergeMessages;
22
25
  // Helper method to add system message
@@ -158,20 +158,22 @@ export interface StateChangeEvent {
158
158
  newValue: any;
159
159
  timestamp: number;
160
160
  }
161
- export interface InternalError extends Error {
161
+ export interface InternalErrorInfo {
162
162
  code: string;
163
163
  module: string;
164
164
  severity: 'low' | 'medium' | 'high' | 'critical';
165
- context?: Record<string, any>;
165
+ context?: Record<string, unknown> | undefined;
166
166
  timestamp: number;
167
- stackTrace?: string;
167
+ stackTrace?: string | undefined;
168
168
  }
169
- export declare class InternalError extends Error {
169
+ export declare class InternalError extends Error implements InternalErrorInfo {
170
170
  code: string;
171
171
  module: string;
172
172
  severity: 'low' | 'medium' | 'high' | 'critical';
173
- context?: Record<string, any> | undefined;
174
- constructor(message: string, code: string, module: string, severity?: 'low' | 'medium' | 'high' | 'critical', context?: Record<string, any> | undefined);
173
+ context?: Record<string, unknown> | undefined;
174
+ timestamp: number;
175
+ stackTrace: string | undefined;
176
+ constructor(message: string, code: string, module: string, severity?: 'low' | 'medium' | 'high' | 'critical', context?: Record<string, unknown> | undefined);
175
177
  }
176
178
  export interface InternalEventMap {
177
179
  'websocket:connected': () => void;
@@ -59,8 +59,7 @@ class Agent {
59
59
  }
60
60
  return {
61
61
  success: true,
62
- result: prompt,
63
- error: undefined
62
+ result: prompt
64
63
  };
65
64
  }
66
65
  catch (error) {
@@ -1,4 +1,4 @@
1
- import { AgentConfig, MessageModifier, PostInferenceProcessor, PostToolCallProcessor, PreInferenceProcessor, PreToolCallProcessor } from "@codebolt/types/agent";
1
+ import { AgentConfig, MessageModifier, PostInferenceProcessor, PostToolCallProcessor, PreInferenceProcessor, PreToolCallProcessor, ProcessedMessage } from "@codebolt/types/agent";
2
2
  import { FlatUserMessage } from "@codebolt/types/sdk";
3
3
  /**
4
4
  * Configuration options for CodeboltAgent
@@ -9,6 +9,18 @@ export interface CodeboltAgentConfig extends AgentConfig {
9
9
  * Defaults to true.
10
10
  */
11
11
  enableLogging?: boolean;
12
+ /**
13
+ * Agent context to continue from.
14
+ * When provided, the agent will skip initial prompt generation
15
+ * and continue from where the previous agent left off.
16
+ */
17
+ context?: ProcessedMessage;
18
+ /**
19
+ * List of allowed tool names. If provided, only these tools will be available to the agent.
20
+ * If not provided, all tools will be available.
21
+ * Example: ['readFile', 'writeFile', 'executeCommand']
22
+ */
23
+ allowedTools?: string[];
12
24
  }
13
25
  /**
14
26
  * CodeboltAgent is a high-level agent class that:
@@ -69,18 +81,27 @@ export declare class CodeboltAgent {
69
81
  private readonly postToolCallProcessors;
70
82
  private readonly enableLogging;
71
83
  private readonly baseSystemPrompt;
84
+ private readonly context;
85
+ private readonly allowedTools;
72
86
  constructor(config: CodeboltAgentConfig);
73
87
  /**
74
88
  * Creates default message modifiers when none are provided
75
89
  */
76
90
  private createDefaultMessageModifiers;
91
+ /**
92
+ * Creates a default FlatUserMessage from a string
93
+ */
94
+ private createDefaultUserMessage;
77
95
  /**
78
96
  * Process a message through the agent pipeline.
79
97
  * This is the main entry point - triggered from graph nodes.
98
+ * @param message - Either a string message or a FlatUserMessage object
99
+ * @param context - Optional context from a previous agent to continue from
80
100
  */
81
- processMessage(reqMessage: FlatUserMessage): Promise<{
101
+ processMessage(message: string | FlatUserMessage, context?: ProcessedMessage): Promise<{
82
102
  success: boolean;
83
103
  result: any;
104
+ context: ProcessedMessage | null;
84
105
  error?: string;
85
106
  }>;
86
107
  /**
@@ -62,10 +62,12 @@ class CodeboltAgent {
62
62
  this.config = { ...config };
63
63
  this.enableLogging = config.enableLogging !== false;
64
64
  this.baseSystemPrompt = config.instructions || 'Based on User Message send reply';
65
+ this.context = config.context;
66
+ this.allowedTools = config.allowedTools;
65
67
  // Use provided modifiers or default ones
66
68
  this.messageModifiers = ((_b = (_a = config.processors) === null || _a === void 0 ? void 0 : _a.messageModifiers) === null || _b === void 0 ? void 0 : _b.length)
67
69
  ? config.processors.messageModifiers
68
- : this.createDefaultMessageModifiers(this.baseSystemPrompt);
70
+ : this.createDefaultMessageModifiers(this.baseSystemPrompt, this.allowedTools);
69
71
  this.preInferenceProcessors = ((_c = config.processors) === null || _c === void 0 ? void 0 : _c.preInferenceProcessors) || [];
70
72
  this.postInferenceProcessors = ((_d = config.processors) === null || _d === void 0 ? void 0 : _d.postInferenceProcessors) || [];
71
73
  this.preToolCallProcessors = ((_e = config.processors) === null || _e === void 0 ? void 0 : _e.preToolCallProcessors) || [];
@@ -74,7 +76,7 @@ class CodeboltAgent {
74
76
  /**
75
77
  * Creates default message modifiers when none are provided
76
78
  */
77
- createDefaultMessageModifiers(systemPrompt) {
79
+ createDefaultMessageModifiers(systemPrompt, allowedTools) {
78
80
  return [
79
81
  // 1. Chat History
80
82
  new processor_pieces_1.ChatHistoryMessageModifier({ enableChatHistory: true }),
@@ -92,26 +94,65 @@ class CodeboltAgent {
92
94
  // 5. Core System Prompt (instructions)
93
95
  new processor_pieces_1.CoreSystemPromptModifier({ customSystemPrompt: systemPrompt }),
94
96
  // 6. Tools (function declarations)
95
- new processor_pieces_1.ToolInjectionModifier({ includeToolDescriptions: true }),
97
+ new processor_pieces_1.ToolInjectionModifier({
98
+ includeToolDescriptions: true,
99
+ ...(allowedTools && { allowedTools })
100
+ }),
96
101
  // 7. At-file processing (@file mentions)
97
102
  new processor_pieces_1.AtFileProcessorModifier({ enableRecursiveSearch: true })
98
103
  ];
99
104
  }
105
+ /**
106
+ * Creates a default FlatUserMessage from a string
107
+ */
108
+ createDefaultUserMessage(message) {
109
+ return {
110
+ userMessage: message,
111
+ selectedAgent: {
112
+ id: 'codebolt-agent',
113
+ name: 'Codebolt Agent'
114
+ },
115
+ mentionedFiles: [],
116
+ mentionedFullPaths: [],
117
+ mentionedFolders: [],
118
+ mentionedMCPs: [],
119
+ uploadedImages: [],
120
+ mentionedAgents: [],
121
+ messageId: `msg-${Date.now()}`,
122
+ threadId: `thread-${Date.now()}`
123
+ };
124
+ }
100
125
  /**
101
126
  * Process a message through the agent pipeline.
102
127
  * This is the main entry point - triggered from graph nodes.
128
+ * @param message - Either a string message or a FlatUserMessage object
129
+ * @param context - Optional context from a previous agent to continue from
103
130
  */
104
- async processMessage(reqMessage) {
131
+ async processMessage(message, context) {
105
132
  try {
106
133
  if (this.enableLogging) {
107
134
  console.log('[CodeboltAgent] Processing message');
108
135
  }
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);
136
+ const reqMessage = typeof message === 'string'
137
+ ? this.createDefaultUserMessage(message)
138
+ : message;
139
+ // Use provided context, config context, or generate new one
140
+ const contextToUse = context || this.context;
141
+ let prompt;
142
+ if (contextToUse) {
143
+ if (this.enableLogging) {
144
+ console.log('[CodeboltAgent] Continuing from previous context');
145
+ }
146
+ prompt = contextToUse;
147
+ }
148
+ else {
149
+ const promptGenerator = new base_1.InitialPromptGenerator({
150
+ processors: this.messageModifiers,
151
+ baseSystemPrompt: this.baseSystemPrompt,
152
+ enableLogging: this.enableLogging
153
+ });
154
+ prompt = await promptGenerator.processMessage(reqMessage);
155
+ }
115
156
  let completed = false;
116
157
  while (!completed) {
117
158
  const agentStep = new agentStep_1.AgentStep({
@@ -139,7 +180,7 @@ class CodeboltAgent {
139
180
  return {
140
181
  success: true,
141
182
  result: prompt,
142
- error: undefined
183
+ context: prompt
143
184
  };
144
185
  }
145
186
  catch (error) {
@@ -150,6 +191,7 @@ class CodeboltAgent {
150
191
  return {
151
192
  success: false,
152
193
  result: null,
194
+ context: null,
153
195
  error: errorMessage
154
196
  };
155
197
  }
@@ -196,6 +238,7 @@ exports.CodeboltAgent = CodeboltAgent;
196
238
  * Factory function to create a CodeboltAgent with common defaults
197
239
  */
198
240
  function createCodeboltAgent(options) {
241
+ var _a;
199
242
  return new CodeboltAgent({
200
243
  instructions: options.systemPrompt,
201
244
  processors: {
@@ -205,6 +248,6 @@ function createCodeboltAgent(options) {
205
248
  preToolCallProcessors: options.preToolCallProcessors || [],
206
249
  postToolCallProcessors: options.postToolCallProcessors || []
207
250
  },
208
- enableLogging: options.enableLogging
251
+ enableLogging: (_a = options.enableLogging) !== null && _a !== void 0 ? _a : true
209
252
  });
210
253
  }
@@ -7,21 +7,17 @@ import { ToolConfig, ToolInterface } from '@codebolt/types/agent';
7
7
  export declare class Tool implements ToolInterface {
8
8
  id: string;
9
9
  description: string;
10
- inputSchema: ZodType<any, any, any>;
11
- outputSchema?: ZodType<any, any, any>;
12
- executionFunction: (context: any) => any;
10
+ inputSchema: ZodType;
11
+ outputSchema?: ZodType | undefined;
12
+ executionFunction: (context: unknown) => unknown;
13
13
  constructor(config: ToolConfig);
14
- execute(input: any, context: any): Promise<{
14
+ execute(input: unknown, context: unknown): Promise<{
15
15
  success: boolean;
16
- error: string | undefined;
17
- result?: undefined;
18
- } | {
19
- success: boolean;
20
- result: any;
21
- error?: undefined;
16
+ result?: unknown;
17
+ error?: string;
22
18
  }>;
23
19
  getToolDescription(): string;
24
- getToolSchema(): z.ZodType<any, any, any>;
20
+ getToolSchema(): z.ZodType<any, z.ZodTypeDef, any>;
25
21
  private validateInput;
26
22
  /**
27
23
  * Validates output against the tool's output schema (if provided)
@@ -17,13 +17,22 @@ class Tool {
17
17
  async execute(input, context) {
18
18
  const inputValidation = this.validateInput(input);
19
19
  if (!inputValidation.valid) {
20
- return { success: false, error: inputValidation.error };
20
+ const result = { success: false };
21
+ if (inputValidation.error) {
22
+ result.error = inputValidation.error;
23
+ }
24
+ return result;
21
25
  }
22
26
  try {
23
- let output = await this.executionFunction({ input, ...context });
27
+ const execContext = typeof context === 'object' && context !== null ? context : {};
28
+ const output = await this.executionFunction({ input, ...execContext });
24
29
  const outputValidation = this.validateOutput(output);
25
30
  if (!outputValidation.valid) {
26
- return { success: false, error: outputValidation.error };
31
+ const result = { success: false };
32
+ if (outputValidation.error) {
33
+ result.error = outputValidation.error;
34
+ }
35
+ return result;
27
36
  }
28
37
  return { success: true, result: output };
29
38
  }
@@ -28,26 +28,30 @@ class Workflow {
28
28
  if (this.config.outputSchema && success) {
29
29
  this.config.outputSchema.parse(this.context);
30
30
  }
31
- return {
31
+ const result = {
32
32
  executionId: this.executionId,
33
33
  success,
34
34
  data: this.context,
35
35
  stepResults,
36
- executionTime,
37
- error: success ? undefined : 'One or more steps failed'
36
+ executionTime
38
37
  };
38
+ if (!success) {
39
+ result.error = 'One or more steps failed';
40
+ }
41
+ return result;
39
42
  }
40
43
  catch (error) {
41
44
  const executionTime = Date.now() - this.startTime;
42
45
  const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
43
- return {
46
+ const result = {
44
47
  executionId: this.executionId,
45
48
  success: false,
46
49
  data: this.context,
47
50
  stepResults: this.stepResults,
48
- executionTime,
49
- error: errorMessage
51
+ executionTime
50
52
  };
53
+ result.error = errorMessage;
54
+ return result;
51
55
  }
52
56
  }
53
57
  executeStep() {
@@ -55,6 +59,9 @@ class Workflow {
55
59
  throw new Error('No more steps to execute');
56
60
  }
57
61
  const step = this.config.steps[this.currentStepIndex];
62
+ if (!step) {
63
+ throw new Error('Step not found at current index');
64
+ }
58
65
  try {
59
66
  // Note: Since BaseWorkflow expects sync methods, we can't properly handle async step execution
60
67
  // This is a design limitation that would need to be addressed in the BaseWorkflow interface
@@ -74,9 +81,9 @@ class Workflow {
74
81
  const errorResult = {
75
82
  stepId: step.id,
76
83
  success: false,
77
- result: null,
78
- error: errorMessage
84
+ result: null
79
85
  };
86
+ errorResult.error = errorMessage;
80
87
  this.stepResults.push(errorResult);
81
88
  return errorResult;
82
89
  }
@@ -85,6 +92,8 @@ class Workflow {
85
92
  const allResults = [];
86
93
  for (let i = 0; i < this.config.steps.length; i++) {
87
94
  const step = this.config.steps[i];
95
+ if (!step)
96
+ continue;
88
97
  try {
89
98
  // Note: This is a synchronous implementation due to BaseWorkflow interface constraints
90
99
  // In a real async implementation, you would await step.execute(this.context)
@@ -108,9 +117,9 @@ class Workflow {
108
117
  const errorResult = {
109
118
  stepId: step.id,
110
119
  success: false,
111
- result: null,
112
- error: errorMessage
120
+ result: null
113
121
  };
122
+ errorResult.error = errorMessage;
114
123
  allResults.push(errorResult);
115
124
  // Break on error (can be made configurable)
116
125
  break;
@@ -166,26 +175,30 @@ class Workflow {
166
175
  if (this.config.outputSchema && success) {
167
176
  this.config.outputSchema.parse(this.context);
168
177
  }
169
- return {
178
+ const result = {
170
179
  executionId: this.executionId,
171
180
  success,
172
181
  data: this.context,
173
182
  stepResults,
174
- executionTime,
175
- error: success ? undefined : 'One or more steps failed'
183
+ executionTime
176
184
  };
185
+ if (!success) {
186
+ result.error = 'One or more steps failed';
187
+ }
188
+ return result;
177
189
  }
178
190
  catch (error) {
179
191
  const executionTime = Date.now() - this.startTime;
180
192
  const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
181
- return {
193
+ const result = {
182
194
  executionId: this.executionId,
183
195
  success: false,
184
196
  data: this.context,
185
197
  stepResults: this.stepResults,
186
- executionTime,
187
- error: errorMessage
198
+ executionTime
188
199
  };
200
+ result.error = errorMessage;
201
+ return result;
189
202
  }
190
203
  }
191
204
  async executeStepAsync() {
@@ -193,6 +206,9 @@ class Workflow {
193
206
  throw new Error('No more steps to execute');
194
207
  }
195
208
  const step = this.config.steps[this.currentStepIndex];
209
+ if (!step) {
210
+ throw new Error('Step not found at current index');
211
+ }
196
212
  try {
197
213
  const result = await step.execute(this.context);
198
214
  // Handle different return types based on step type
@@ -216,9 +232,9 @@ class Workflow {
216
232
  const errorResult = {
217
233
  stepId: step.id,
218
234
  success: false,
219
- result: null,
220
- error: errorMessage
235
+ result: null
221
236
  };
237
+ errorResult.error = errorMessage;
222
238
  this.stepResults.push(errorResult);
223
239
  return errorResult;
224
240
  }
@@ -227,6 +243,8 @@ class Workflow {
227
243
  const allResults = [];
228
244
  for (let i = 0; i < this.config.steps.length; i++) {
229
245
  const step = this.config.steps[i];
246
+ if (!step)
247
+ continue;
230
248
  try {
231
249
  const result = await step.execute(this.context);
232
250
  // Handle different return types based on step type
@@ -260,9 +278,9 @@ class Workflow {
260
278
  const errorResult = {
261
279
  stepId: step.id,
262
280
  success: false,
263
- result: null,
264
- error: errorMessage
281
+ result: null
265
282
  };
283
+ errorResult.error = errorMessage;
266
284
  allResults.push(errorResult);
267
285
  // Break on error (can be made configurable)
268
286
  break;
@@ -1,5 +1,5 @@
1
1
  import { AgentInterface, BaseWorkFlowStep, StepConfig, StepType, ToolInterface, workflowContext, workflowStepOutput } from "@codebolt/types/agent";
2
- import { ZodType } from "zod";
2
+ import type { ZodType } from "zod";
3
3
  export declare class ParallelStep implements BaseWorkFlowStep {
4
4
  id: string;
5
5
  description: string;