@codebolt/agent 5.0.6 → 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.
- 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/types/libFunctionTypes.d.ts +13 -19
- package/dist/types/libFunctionTypes.js +3 -0
- package/dist/types/processorTypes.d.ts +8 -8
- package/dist/types/processorTypes.js +6 -23
- 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 +41 -10
- 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 +11 -6
|
@@ -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;
|
|
@@ -6,9 +6,17 @@
|
|
|
6
6
|
* - API interfaces exposed to library users
|
|
7
7
|
* - Configuration options for library functions
|
|
8
8
|
* - User-facing data structures
|
|
9
|
+
*
|
|
10
|
+
* Note: Core message and tool types are imported from @codebolt/types/sdk.
|
|
11
|
+
* Local extensions are provided for backward compatibility.
|
|
9
12
|
*/
|
|
13
|
+
import type { MessageObject, ToolCall as SDKToolCall, ToolChoice, LLMCompletion } from '@codebolt/types/sdk';
|
|
14
|
+
import type { ToolResult as AgentToolResult } from '@codebolt/types/agent';
|
|
15
|
+
export type { MessageObject, ToolChoice, LLMCompletion };
|
|
16
|
+
export type { AgentToolResult };
|
|
10
17
|
/**
|
|
11
18
|
* Represents a message in the conversation with roles and content.
|
|
19
|
+
* Extended version with looser typing for backward compatibility.
|
|
12
20
|
*/
|
|
13
21
|
export interface Message {
|
|
14
22
|
/** The role of the message sender: user, assistant, tool, or system */
|
|
@@ -24,22 +32,12 @@ export interface Message {
|
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* Represents a tool call in OpenAI format
|
|
35
|
+
* Re-exported from SDK with same structure
|
|
27
36
|
*/
|
|
28
|
-
export
|
|
29
|
-
/** Unique identifier for this tool call */
|
|
30
|
-
id: string;
|
|
31
|
-
/** The type of tool call */
|
|
32
|
-
type: 'function';
|
|
33
|
-
/** Function call details */
|
|
34
|
-
function: {
|
|
35
|
-
/** Name of the function to call */
|
|
36
|
-
name: string;
|
|
37
|
-
/** Arguments for the function call as JSON string */
|
|
38
|
-
arguments: string;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
37
|
+
export type ToolCall = SDKToolCall;
|
|
41
38
|
/**
|
|
42
39
|
* Represents a tool definition in OpenAI format
|
|
40
|
+
* Extended with looser parameter typing for flexibility
|
|
43
41
|
*/
|
|
44
42
|
export interface Tool {
|
|
45
43
|
/** The type of tool */
|
|
@@ -56,6 +54,7 @@ export interface Tool {
|
|
|
56
54
|
}
|
|
57
55
|
/**
|
|
58
56
|
* LLM inference request parameters
|
|
57
|
+
* Local version with required llmrole for backward compatibility
|
|
59
58
|
*/
|
|
60
59
|
export interface LLMInferenceParams {
|
|
61
60
|
/** Array of messages in the conversation */
|
|
@@ -63,12 +62,7 @@ export interface LLMInferenceParams {
|
|
|
63
62
|
/** Available tools for the model to use */
|
|
64
63
|
tools?: Tool[];
|
|
65
64
|
/** How the model should use tools */
|
|
66
|
-
tool_choice?:
|
|
67
|
-
type: 'function';
|
|
68
|
-
function: {
|
|
69
|
-
name: string;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
65
|
+
tool_choice?: ToolChoice;
|
|
72
66
|
/** The LLM role to determine which model to use */
|
|
73
67
|
llmrole: string;
|
|
74
68
|
/** Maximum number of tokens to generate */
|
|
@@ -7,5 +7,8 @@
|
|
|
7
7
|
* - API interfaces exposed to library users
|
|
8
8
|
* - Configuration options for library functions
|
|
9
9
|
* - User-facing data structures
|
|
10
|
+
*
|
|
11
|
+
* Note: Core message and tool types are imported from @codebolt/types/sdk.
|
|
12
|
+
* Local extensions are provided for backward compatibility.
|
|
10
13
|
*/
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Processor types and interfaces for the Unified Agent Framework
|
|
3
|
-
* @deprecated Use
|
|
3
|
+
* @deprecated Use types from @codebolt/types/agent instead
|
|
4
4
|
*
|
|
5
5
|
* This file is kept for backward compatibility.
|
|
6
|
-
* New code should import from
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* - './processorTypes/postToolCallProcessorTypes'
|
|
6
|
+
* New code should import from @codebolt/types/agent:
|
|
7
|
+
* - MessageModifier, MessageModifierOptions
|
|
8
|
+
* - PreInferenceProcessor, PostInferenceProcessor
|
|
9
|
+
* - PreToolCallProcessor, PostToolCallProcessor
|
|
10
|
+
* - ProcessedMessage, ToolCall, ToolResult
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
import type { ToolResult } from '@codebolt/types/agent';
|
|
13
|
+
export type { ToolResult };
|
|
14
14
|
export interface ToolCall {
|
|
15
15
|
id: string;
|
|
16
16
|
function: {
|
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Processor types and interfaces for the Unified Agent Framework
|
|
4
|
-
* @deprecated Use
|
|
4
|
+
* @deprecated Use types from @codebolt/types/agent instead
|
|
5
5
|
*
|
|
6
6
|
* This file is kept for backward compatibility.
|
|
7
|
-
* New code should import from
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
* - './processorTypes/postToolCallProcessorTypes'
|
|
7
|
+
* New code should import from @codebolt/types/agent:
|
|
8
|
+
* - MessageModifier, MessageModifierOptions
|
|
9
|
+
* - PreInferenceProcessor, PostInferenceProcessor
|
|
10
|
+
* - PreToolCallProcessor, PostToolCallProcessor
|
|
11
|
+
* - ProcessedMessage, ToolCall, ToolResult
|
|
13
12
|
*/
|
|
14
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
-
}
|
|
20
|
-
Object.defineProperty(o, k2, desc);
|
|
21
|
-
}) : (function(o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
}));
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
14
|
exports.BaseProcessor = void 0;
|
|
30
|
-
// Re-export all processor types from their specific modules
|
|
31
|
-
__exportStar(require("./processorTypes"), exports);
|
|
32
15
|
// Base processor class
|
|
33
16
|
class BaseProcessor {
|
|
34
17
|
constructor(options) {
|
|
@@ -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
|
}
|