@codebolt/agent 5.0.7 → 5.0.9
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/processor-pieces/base/basePreToolCallProcessor.js +5 -2
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +2 -2
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +24 -34
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +2 -2
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +2 -2
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +8 -3
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +1 -1
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +114 -17
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +13 -5
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +5 -0
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +24 -8
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +202 -5
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +826 -19
- package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -1
- package/dist/processor-pieces/postToolCallProcessors/index.js +2 -1
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +7 -4
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +1 -1
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +12 -16
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +2 -3
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +1 -2
- package/dist/processor-pieces/utils/messageModifierHelper.js +5 -2
- package/dist/types/InternalTypes.d.ts +8 -6
- package/dist/unified/agent/agent.js +1 -2
- package/dist/unified/agent/codeboltAgent.d.ts +23 -2
- package/dist/unified/agent/codeboltAgent.js +55 -12
- package/dist/unified/agent/tools.d.ts +7 -11
- package/dist/unified/agent/tools.js +12 -3
- package/dist/unified/agent/workflow.js +38 -20
- package/dist/unified/agent/workflowSteps.d.ts +1 -1
- package/dist/unified/agent/workflowSteps.js +58 -23
- package/dist/unified/base/agentStep.js +20 -1
- package/dist/unified/base/initialPromptGenerator.js +3 -1
- package/dist/unified/base/responseExecutor.d.ts +3 -0
- package/dist/unified/base/responseExecutor.js +47 -21
- package/dist/unified/index.d.ts +1 -0
- package/dist/unified/index.js +4 -1
- package/dist/unified/services/LoopDetectionService.d.ts +44 -0
- package/dist/unified/services/LoopDetectionService.js +79 -0
- package/dist/unified/utils/utils.d.ts +20 -1
- package/dist/unified/utils/utils.js +8 -4
- package/package.json +5 -5
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- package/dist/builderpattern/agent.d.ts +0 -86
- package/dist/builderpattern/agent.js +0 -324
- package/dist/builderpattern/followupquestionbuilder.d.ts +0 -75
- package/dist/builderpattern/followupquestionbuilder.js +0 -197
- package/dist/builderpattern/index.d.ts +0 -14
- package/dist/builderpattern/index.js +0 -23
- package/dist/builderpattern/llmoutputhandler.d.ts +0 -102
- package/dist/builderpattern/llmoutputhandler.js +0 -452
- package/dist/builderpattern/promptbuilder.d.ts +0 -382
- package/dist/builderpattern/promptbuilder.js +0 -805
- package/dist/builderpattern/systemprompt.d.ts +0 -20
- package/dist/builderpattern/systemprompt.js +0 -48
- package/dist/builderpattern/taskInstruction.d.ts +0 -37
- package/dist/builderpattern/taskInstruction.js +0 -57
- package/dist/builderpattern/usermessage.d.ts +0 -70
- package/dist/builderpattern/usermessage.js +0 -123
- package/dist/composablepattern/agent.d.ts +0 -169
- package/dist/composablepattern/agent.js +0 -598
- package/dist/composablepattern/codebolt-storage.d.ts +0 -67
- package/dist/composablepattern/codebolt-storage.js +0 -320
- package/dist/composablepattern/document.d.ts +0 -149
- package/dist/composablepattern/document.js +0 -405
- package/dist/composablepattern/examples/codebolt-integration-example.d.ts +0 -12
- package/dist/composablepattern/examples/codebolt-integration-example.js +0 -218
- package/dist/composablepattern/examples/codebolt-storage-example.d.ts +0 -40
- package/dist/composablepattern/examples/codebolt-storage-example.js +0 -223
- package/dist/composablepattern/examples/custom-steps-example.d.ts +0 -20
- package/dist/composablepattern/examples/custom-steps-example.js +0 -455
- package/dist/composablepattern/examples/document-agent.d.ts +0 -17
- package/dist/composablepattern/examples/document-agent.js +0 -107
- package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +0 -8
- package/dist/composablepattern/examples/simple-codebolt-integration.js +0 -164
- package/dist/composablepattern/examples/weather-agent.d.ts +0 -18
- package/dist/composablepattern/examples/weather-agent.js +0 -86
- package/dist/composablepattern/examples/workflow-example.d.ts +0 -12
- package/dist/composablepattern/examples/workflow-example.js +0 -463
- package/dist/composablepattern/index.d.ts +0 -63
- package/dist/composablepattern/index.js +0 -115
- package/dist/composablepattern/memory.d.ts +0 -89
- package/dist/composablepattern/memory.js +0 -141
- package/dist/composablepattern/tool.d.ts +0 -84
- package/dist/composablepattern/tool.js +0 -260
- package/dist/composablepattern/types.d.ts +0 -194
- package/dist/composablepattern/types.js +0 -6
- package/dist/composablepattern/user-context.d.ts +0 -214
- package/dist/composablepattern/user-context.js +0 -275
- package/dist/composablepattern/workflow.d.ts +0 -388
- package/dist/composablepattern/workflow.js +0 -562
- package/dist/followupquestionbuilder.d.ts +0 -75
- package/dist/followupquestionbuilder.js +0 -197
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -23
- package/dist/llmoutputhandler.d.ts +0 -102
- package/dist/llmoutputhandler.js +0 -452
- package/dist/processor/agent/agentStep.d.ts +0 -49
- package/dist/processor/agent/agentStep.js +0 -241
- package/dist/processor/agent/toolExecutor.d.ts +0 -19
- package/dist/processor/agent/toolExecutor.js +0 -90
- package/dist/processor/index.d.ts +0 -7
- package/dist/processor/index.js +0 -36
- package/dist/processor/messageModifiers/baseMessageModifier.d.ts +0 -20
- package/dist/processor/messageModifiers/baseMessageModifier.js +0 -55
- package/dist/processor/processors/baseProcessor.d.ts +0 -14
- package/dist/processor/processors/baseProcessor.js +0 -29
- package/dist/processor/tools/baseTool.d.ts +0 -10
- package/dist/processor/tools/baseTool.js +0 -20
- package/dist/processor/tools/toolList.d.ts +0 -9
- package/dist/processor/tools/toolList.js +0 -22
- package/dist/processor/types/interfaces.d.ts +0 -94
- package/dist/processor/types/interfaces.js +0 -2
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +0 -144
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +0 -15
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +0 -75
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +0 -11
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +0 -46
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +0 -12
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +0 -60
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +0 -18
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +0 -222
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +0 -194
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +0 -41
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +0 -197
- package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +0 -26
- package/dist/processor-pieces/processors/chatCompressionProcessor.js +0 -90
- package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +0 -81
- package/dist/processor-pieces/processors/chatRecordingProcessor.js +0 -329
- package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +0 -40
- package/dist/processor-pieces/processors/contextManagementProcessor.js +0 -305
- package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/loopDetectionProcessor.js +0 -137
- package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/responseValidationProcessor.js +0 -228
- package/dist/processor-pieces/processors/telemetryProcessor.d.ts +0 -99
- package/dist/processor-pieces/processors/telemetryProcessor.js +0 -311
- package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +0 -37
- package/dist/processor-pieces/processors/tokenManagementProcessor.js +0 -178
- package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +0 -43
- package/dist/processor-pieces/processors/toolExecutionProcessor.js +0 -207
- package/dist/processor-pieces/tools/fileTools.d.ts +0 -26
- package/dist/processor-pieces/tools/fileTools.js +0 -162
- package/dist/promptbuilder.d.ts +0 -382
- package/dist/promptbuilder.js +0 -805
- package/dist/systemprompt.d.ts +0 -20
- package/dist/systemprompt.js +0 -48
- package/dist/taskInstruction.d.ts +0 -37
- package/dist/taskInstruction.js +0 -57
- package/dist/usermessage.d.ts +0 -70
- package/dist/usermessage.js +0 -123
|
@@ -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 {
|
|
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
|
|
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
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
149
|
-
|
|
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(
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
|
161
|
+
export interface InternalErrorInfo {
|
|
162
162
|
code: string;
|
|
163
163
|
module: string;
|
|
164
164
|
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
165
|
-
context?: Record<string,
|
|
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,
|
|
174
|
-
|
|
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;
|
|
@@ -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(
|
|
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({
|
|
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(
|
|
131
|
+
async processMessage(message, context) {
|
|
105
132
|
try {
|
|
106
133
|
if (this.enableLogging) {
|
|
107
134
|
console.log('[CodeboltAgent] Processing message');
|
|
108
135
|
}
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
let prompt
|
|
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
|
-
|
|
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
|
|
11
|
-
outputSchema?: ZodType
|
|
12
|
-
executionFunction: (context:
|
|
10
|
+
inputSchema: ZodType;
|
|
11
|
+
outputSchema?: ZodType | undefined;
|
|
12
|
+
executionFunction: (context: unknown) => unknown;
|
|
13
13
|
constructor(config: ToolConfig);
|
|
14
|
-
execute(input:
|
|
14
|
+
execute(input: unknown, context: unknown): Promise<{
|
|
15
15
|
success: boolean;
|
|
16
|
-
|
|
17
|
-
|
|
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,
|
|
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
|
-
|
|
20
|
+
const result = { success: false };
|
|
21
|
+
if (inputValidation.error) {
|
|
22
|
+
result.error = inputValidation.error;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
21
25
|
}
|
|
22
26
|
try {
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|