@codebolt/agent 2.2.2 → 2.2.3
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/builderpattern/agent.js +2 -2
- package/dist/builderpattern/followupquestionbuilder.js +1 -1
- package/dist/builderpattern/llmoutputhandler.js +7 -7
- package/dist/builderpattern/usermessage.d.ts +6 -1
- package/dist/composablepattern/document.js +2 -35
- package/dist/local-tools/fileTools.d.ts +26 -0
- package/dist/local-tools/fileTools.js +162 -0
- package/dist/processor/types/interfaces.d.ts +44 -21
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +13 -0
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +68 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +212 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +23 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +173 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +14 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +93 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +30 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +330 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +26 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +269 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +38 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +217 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +34 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +147 -0
- package/dist/processor-pieces/additionalModifiers/index.d.ts +12 -0
- package/dist/processor-pieces/additionalModifiers/index.js +28 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +29 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +155 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +129 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +169 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +20 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +152 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +93 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +14 -5
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +41 -40
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +9 -0
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +77 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +5 -5
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +5 -13
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +50 -58
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +6 -8
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +66 -22
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +20 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +124 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +41 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.js +355 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +23 -0
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +207 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +26 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +18 -2
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +291 -93
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +1 -0
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +2 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +7 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +24 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +41 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +197 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +26 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +90 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +81 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +329 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +40 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +272 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +291 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +47 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +249 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +137 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +228 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +99 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.js +278 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +37 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +178 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +43 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +207 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +52 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +264 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +7 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +31 -0
- package/dist/processor-pieces/preToolCall/index.d.ts +9 -0
- package/dist/processor-pieces/preToolCall/index.js +18 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +444 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +44 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +367 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +391 -0
- package/dist/unified/agent/agent.js +2 -2
- package/dist/unified/agent/tool.d.ts +99 -0
- package/dist/unified/agent/tool.js +440 -0
- package/dist/unified/base/initialPromptGenerator.js +5 -5
- package/dist/unified/base/responseExecutor.js +6 -6
- package/dist/unified/examples/agentExample.d.ts +46 -0
- package/dist/unified/examples/agentExample.js +464 -0
- package/dist/unified/examples/documentationPatternExample.d.ts +10 -0
- package/dist/unified/examples/documentationPatternExample.js +385 -0
- package/dist/unified/examples/followUpProcessorsExample.d.ts +45 -0
- package/dist/unified/examples/followUpProcessorsExample.js +311 -0
- package/dist/unified/examples/orchestratorExample.d.ts +16 -0
- package/dist/unified/examples/orchestratorExample.js +415 -0
- package/dist/unified/examples/preToolCallProcessorsExample.d.ts +36 -0
- package/dist/unified/examples/preToolCallProcessorsExample.js +458 -0
- package/dist/unified/examples/workflowExample.d.ts +12 -0
- package/dist/unified/examples/workflowExample.js +497 -0
- package/dist/unified/orchestrator/orchestrator.d.ts +260 -0
- package/dist/unified/orchestrator/orchestrator.js +519 -0
- package/package.json +15 -15
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- 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/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
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FollowUpConversationProcessor = void 0;
|
|
4
|
+
const processor_1 = require("../../processor");
|
|
5
|
+
/**
|
|
6
|
+
* Processor that enhances follow-up conversations by adding contextual information,
|
|
7
|
+
* improving tool result presentation, and providing guidance for continued interaction.
|
|
8
|
+
*/
|
|
9
|
+
class FollowUpConversationProcessor extends processor_1.BaseProcessor {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.addFollowUpPrompts = options.addFollowUpPrompts !== false;
|
|
13
|
+
this.enhanceToolResults = options.enhanceToolResults !== false;
|
|
14
|
+
this.addContextualHints = options.addContextualHints !== false;
|
|
15
|
+
this.processingMode = options.processingMode || 'automatic';
|
|
16
|
+
this.maxFollowUpMessages = options.maxFollowUpMessages || 3;
|
|
17
|
+
this.enableToolResultEnhancement = options.enableToolResultEnhancement !== false;
|
|
18
|
+
this.enableConversationGuidance = options.enableConversationGuidance !== false;
|
|
19
|
+
}
|
|
20
|
+
async processInput(input) {
|
|
21
|
+
try {
|
|
22
|
+
const { message, context } = input;
|
|
23
|
+
// Check if this is a follow-up conversation processing
|
|
24
|
+
if (!(context === null || context === void 0 ? void 0 : context.followUpProcessing)) {
|
|
25
|
+
return [this.createEvent('FollowUpProcessingSkipped', {
|
|
26
|
+
reason: 'Not a follow-up conversation processing context'
|
|
27
|
+
})];
|
|
28
|
+
}
|
|
29
|
+
const enhancedMessage = await this.enhanceFollowUpConversation(message, context);
|
|
30
|
+
const processingInfo = this.calculateProcessingInfo(message, enhancedMessage, context);
|
|
31
|
+
return [
|
|
32
|
+
this.createEvent('FollowUpConversationProcessed', processingInfo),
|
|
33
|
+
this.createEvent('ConversationProcessed', enhancedMessage)
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error('Error in FollowUpConversationProcessor:', error);
|
|
38
|
+
return [this.createEvent('FollowUpConversationError', {
|
|
39
|
+
error: error instanceof Error ? error.message : String(error),
|
|
40
|
+
originalLength: input.message.messages.length
|
|
41
|
+
})];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async enhanceFollowUpConversation(message, context) {
|
|
45
|
+
let enhancedMessages = [...message.messages];
|
|
46
|
+
let enhancementsAdded = 0;
|
|
47
|
+
// Enhance tool results if enabled
|
|
48
|
+
if (this.enableToolResultEnhancement && this.enhanceToolResults) {
|
|
49
|
+
enhancedMessages = this.enhanceToolResultMessages(enhancedMessages, context);
|
|
50
|
+
enhancementsAdded++;
|
|
51
|
+
}
|
|
52
|
+
// Add follow-up prompts if enabled
|
|
53
|
+
if (this.addFollowUpPrompts && this.processingMode !== 'minimal') {
|
|
54
|
+
const followUpMessages = this.generateFollowUpPrompts(enhancedMessages, context);
|
|
55
|
+
enhancedMessages.push(...followUpMessages);
|
|
56
|
+
enhancementsAdded += followUpMessages.length;
|
|
57
|
+
}
|
|
58
|
+
// Add contextual hints if enabled
|
|
59
|
+
if (this.addContextualHints && this.enableConversationGuidance) {
|
|
60
|
+
const contextualMessages = this.generateContextualHints(enhancedMessages, context);
|
|
61
|
+
enhancedMessages.push(...contextualMessages);
|
|
62
|
+
enhancementsAdded += contextualMessages.length;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
...message,
|
|
66
|
+
messages: enhancedMessages,
|
|
67
|
+
metadata: {
|
|
68
|
+
...message.metadata,
|
|
69
|
+
followUpEnhanced: true,
|
|
70
|
+
enhancementsAdded,
|
|
71
|
+
processingMode: this.processingMode,
|
|
72
|
+
timestamp: new Date().toISOString()
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
enhanceToolResultMessages(messages, context) {
|
|
77
|
+
return messages.map(message => {
|
|
78
|
+
if (message.role !== 'tool') {
|
|
79
|
+
return message;
|
|
80
|
+
}
|
|
81
|
+
// Enhance tool result presentation
|
|
82
|
+
const enhancedContent = this.enhanceToolResultContent(message.content, context);
|
|
83
|
+
return {
|
|
84
|
+
...message,
|
|
85
|
+
content: enhancedContent,
|
|
86
|
+
name: message.name || 'tool-result'
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
enhanceToolResultContent(content, context) {
|
|
91
|
+
if (typeof content !== 'string') {
|
|
92
|
+
return content;
|
|
93
|
+
}
|
|
94
|
+
// Add formatting and context to tool results
|
|
95
|
+
let enhancedContent = content;
|
|
96
|
+
// Add success/failure indicators
|
|
97
|
+
if (content.toLowerCase().includes('error') || content.toLowerCase().includes('failed')) {
|
|
98
|
+
enhancedContent = `❌ **Tool Execution Result:**\n${content}\n\n*The tool encountered an issue. Please review the error and try again if needed.*`;
|
|
99
|
+
}
|
|
100
|
+
else if (content.toLowerCase().includes('success') || content.toLowerCase().includes('completed')) {
|
|
101
|
+
enhancedContent = `✅ **Tool Execution Result:**\n${content}\n\n*The tool executed successfully.*`;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
enhancedContent = `🔧 **Tool Execution Result:**\n${content}`;
|
|
105
|
+
}
|
|
106
|
+
// Add tool execution context if available
|
|
107
|
+
if (context.toolResults && Array.isArray(context.toolResults)) {
|
|
108
|
+
const toolCount = context.toolResults.length;
|
|
109
|
+
if (toolCount > 1) {
|
|
110
|
+
enhancedContent += `\n\n*This is one of ${toolCount} tool results in this interaction.*`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return enhancedContent;
|
|
114
|
+
}
|
|
115
|
+
generateFollowUpPrompts(messages, context) {
|
|
116
|
+
const followUpMessages = [];
|
|
117
|
+
const toolResults = context.toolResults || [];
|
|
118
|
+
const hasErrors = toolResults.some((result) => result.content && result.content.toLowerCase().includes('error'));
|
|
119
|
+
// Add different prompts based on processing mode
|
|
120
|
+
switch (this.processingMode) {
|
|
121
|
+
case 'guided':
|
|
122
|
+
followUpMessages.push(...this.generateGuidedPrompts(messages, context, hasErrors));
|
|
123
|
+
break;
|
|
124
|
+
case 'automatic':
|
|
125
|
+
followUpMessages.push(...this.generateAutomaticPrompts(messages, context, hasErrors));
|
|
126
|
+
break;
|
|
127
|
+
case 'minimal':
|
|
128
|
+
// Minimal mode doesn't add prompts
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
// Limit the number of follow-up messages
|
|
132
|
+
return followUpMessages.slice(0, this.maxFollowUpMessages);
|
|
133
|
+
}
|
|
134
|
+
generateGuidedPrompts(messages, context, hasErrors) {
|
|
135
|
+
var _a;
|
|
136
|
+
const prompts = [];
|
|
137
|
+
if (hasErrors) {
|
|
138
|
+
prompts.push({
|
|
139
|
+
role: 'user',
|
|
140
|
+
content: "I notice there were some errors in the tool execution. Would you like me to:\n1. Retry the failed operations\n2. Try an alternative approach\n3. Provide more details about the errors\n4. Continue with the successful results\n\nPlease let me know how you'd like to proceed.",
|
|
141
|
+
name: 'error-guidance-prompt'
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const toolCount = ((_a = context.toolResults) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
146
|
+
if (toolCount > 0) {
|
|
147
|
+
prompts.push({
|
|
148
|
+
role: 'user',
|
|
149
|
+
content: `The tools have been executed successfully. Based on the results, would you like me to:\n1. Analyze the results further\n2. Perform additional related tasks\n3. Provide a summary of what was accomplished\n4. Continue with the next steps\n\nWhat would be most helpful?`,
|
|
150
|
+
name: 'success-guidance-prompt'
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return prompts;
|
|
155
|
+
}
|
|
156
|
+
generateAutomaticPrompts(messages, context, hasErrors) {
|
|
157
|
+
var _a;
|
|
158
|
+
const prompts = [];
|
|
159
|
+
if (hasErrors) {
|
|
160
|
+
prompts.push({
|
|
161
|
+
role: 'user',
|
|
162
|
+
content: "Please review the errors above and suggest how to resolve them or continue with alternative approaches.",
|
|
163
|
+
name: 'automatic-error-prompt'
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
const toolCount = ((_a = context.toolResults) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
168
|
+
if (toolCount > 0) {
|
|
169
|
+
prompts.push({
|
|
170
|
+
role: 'user',
|
|
171
|
+
content: "Please analyze the tool execution results and let me know if there are any next steps or if the task has been completed successfully.",
|
|
172
|
+
name: 'automatic-success-prompt'
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return prompts;
|
|
177
|
+
}
|
|
178
|
+
generateContextualHints(messages, context) {
|
|
179
|
+
const hints = [];
|
|
180
|
+
const toolResults = context.toolResults || [];
|
|
181
|
+
const conversationLength = context.conversationLength || 0;
|
|
182
|
+
// Add hints based on conversation state
|
|
183
|
+
if (conversationLength > 30) {
|
|
184
|
+
hints.push({
|
|
185
|
+
role: 'system',
|
|
186
|
+
content: "Note: This conversation is getting quite long. Consider summarizing progress or breaking down remaining tasks into smaller steps.",
|
|
187
|
+
name: 'conversation-length-hint'
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
// Add hints based on tool execution patterns
|
|
191
|
+
if (toolResults.length > 5) {
|
|
192
|
+
hints.push({
|
|
193
|
+
role: 'system',
|
|
194
|
+
content: "Multiple tools have been executed in this interaction. Consider reviewing the overall progress and determining if the objectives have been met.",
|
|
195
|
+
name: 'tool-execution-hint'
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// Add hints for specific tool types
|
|
199
|
+
const fileOperations = toolResults.filter((result) => result.tool_call_id && (result.tool_call_id.includes('file') ||
|
|
200
|
+
result.tool_call_id.includes('read') ||
|
|
201
|
+
result.tool_call_id.includes('write')));
|
|
202
|
+
if (fileOperations.length > 0) {
|
|
203
|
+
hints.push({
|
|
204
|
+
role: 'system',
|
|
205
|
+
content: "File operations have been performed. Consider verifying the changes and ensuring all modifications are correct.",
|
|
206
|
+
name: 'file-operations-hint'
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return hints.slice(0, 2); // Limit hints to avoid clutter
|
|
210
|
+
}
|
|
211
|
+
calculateProcessingInfo(original, enhanced, context) {
|
|
212
|
+
var _a;
|
|
213
|
+
const originalCount = original.messages.length;
|
|
214
|
+
const enhancedCount = enhanced.messages.length;
|
|
215
|
+
const toolResultsCount = ((_a = context.toolResults) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
216
|
+
return {
|
|
217
|
+
toolResultsProcessed: toolResultsCount,
|
|
218
|
+
followUpMessagesAdded: enhancedCount - originalCount,
|
|
219
|
+
conversationEnhanced: enhancedCount > originalCount,
|
|
220
|
+
processingMethod: this.processingMode
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
// Public methods for configuration
|
|
224
|
+
setProcessingMode(mode) {
|
|
225
|
+
this.processingMode = mode;
|
|
226
|
+
}
|
|
227
|
+
setMaxFollowUpMessages(count) {
|
|
228
|
+
this.maxFollowUpMessages = Math.max(0, Math.min(10, count));
|
|
229
|
+
}
|
|
230
|
+
enableFollowUpPromptsForSession() {
|
|
231
|
+
this.addFollowUpPrompts = true;
|
|
232
|
+
}
|
|
233
|
+
disableFollowUpPromptsForSession() {
|
|
234
|
+
this.addFollowUpPrompts = false;
|
|
235
|
+
}
|
|
236
|
+
enableToolResultEnhancementForSession() {
|
|
237
|
+
this.enableToolResultEnhancement = true;
|
|
238
|
+
}
|
|
239
|
+
disableToolResultEnhancementForSession() {
|
|
240
|
+
this.enableToolResultEnhancement = false;
|
|
241
|
+
}
|
|
242
|
+
enableConversationGuidanceForSession() {
|
|
243
|
+
this.enableConversationGuidance = true;
|
|
244
|
+
}
|
|
245
|
+
disableConversationGuidanceForSession() {
|
|
246
|
+
this.enableConversationGuidance = false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.FollowUpConversationProcessor = FollowUpConversationProcessor;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../../processor';
|
|
2
|
+
export interface LoopDetectionInfo {
|
|
3
|
+
promptId: string;
|
|
4
|
+
loopCount: number;
|
|
5
|
+
maxLoops: number;
|
|
6
|
+
recentMessages: any[];
|
|
7
|
+
isLoop: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface LoopDetectionProcessorOptions {
|
|
10
|
+
maxLoops?: number;
|
|
11
|
+
messageThreshold?: number;
|
|
12
|
+
enableLoopDetection?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class LoopDetectionProcessor extends BaseProcessor {
|
|
15
|
+
private readonly maxLoops;
|
|
16
|
+
private readonly messageThreshold;
|
|
17
|
+
private readonly enableLoopDetection;
|
|
18
|
+
private lastPromptId;
|
|
19
|
+
private loopCount;
|
|
20
|
+
constructor(options?: LoopDetectionProcessorOptions);
|
|
21
|
+
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
22
|
+
private generatePromptId;
|
|
23
|
+
private resetLoopDetector;
|
|
24
|
+
private checkLoopDetection;
|
|
25
|
+
resetSession(): void;
|
|
26
|
+
getCurrentLoopCount(): number;
|
|
27
|
+
setMaxLoops(maxLoops: number): void;
|
|
28
|
+
enableLoopDetectionForSession(): void;
|
|
29
|
+
disableLoopDetectionForSession(): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LoopDetectionProcessor = void 0;
|
|
7
|
+
const processor_1 = require("../../processor");
|
|
8
|
+
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
9
|
+
class LoopDetectionProcessor extends processor_1.BaseProcessor {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.lastPromptId = null;
|
|
13
|
+
this.loopCount = 0;
|
|
14
|
+
this.maxLoops = options.maxLoops || 3;
|
|
15
|
+
this.messageThreshold = options.messageThreshold || 6;
|
|
16
|
+
this.enableLoopDetection = options.enableLoopDetection !== false;
|
|
17
|
+
}
|
|
18
|
+
async processInput(input) {
|
|
19
|
+
try {
|
|
20
|
+
const { message, context } = input;
|
|
21
|
+
if (!this.enableLoopDetection) {
|
|
22
|
+
return [this.createEvent('LoopDetectionDisabled', {
|
|
23
|
+
reason: 'Loop detection is disabled for this session'
|
|
24
|
+
})];
|
|
25
|
+
}
|
|
26
|
+
// Get prompt ID from context or generate one
|
|
27
|
+
const promptId = (context === null || context === void 0 ? void 0 : context.promptId) || this.generatePromptId();
|
|
28
|
+
// Reset loop detector if new prompt
|
|
29
|
+
if (this.lastPromptId !== promptId) {
|
|
30
|
+
await this.resetLoopDetector(promptId);
|
|
31
|
+
this.lastPromptId = promptId;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.loopCount++;
|
|
35
|
+
}
|
|
36
|
+
// Check for conversation loops using CodeBolt state
|
|
37
|
+
const loopDetected = await this.checkLoopDetection();
|
|
38
|
+
if (loopDetected) {
|
|
39
|
+
// Send notification about loop detection
|
|
40
|
+
await codeboltjs_1.default.chat.sendNotificationEvent('Loop detected in conversation', 'debug');
|
|
41
|
+
return [this.createEvent('LoopDetected', {
|
|
42
|
+
promptId,
|
|
43
|
+
loopCount: this.loopCount,
|
|
44
|
+
maxLoops: this.maxLoops
|
|
45
|
+
})];
|
|
46
|
+
}
|
|
47
|
+
// Check if max loops reached
|
|
48
|
+
if (this.loopCount > this.maxLoops) {
|
|
49
|
+
return [this.createEvent('MaxLoopsReached', {
|
|
50
|
+
promptId,
|
|
51
|
+
loopCount: this.loopCount,
|
|
52
|
+
maxLoops: this.maxLoops
|
|
53
|
+
})];
|
|
54
|
+
}
|
|
55
|
+
// Continue processing
|
|
56
|
+
return [this.createEvent('LoopDetectionPassed', {
|
|
57
|
+
promptId,
|
|
58
|
+
loopCount: this.loopCount,
|
|
59
|
+
maxLoops: this.maxLoops
|
|
60
|
+
})];
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error('Error in LoopDetectionProcessor:', error);
|
|
64
|
+
return [this.createEvent('LoopDetectionError', {
|
|
65
|
+
error: error instanceof Error ? error.message : String(error)
|
|
66
|
+
})];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
generatePromptId() {
|
|
70
|
+
return `prompt-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
71
|
+
}
|
|
72
|
+
async resetLoopDetector(promptId) {
|
|
73
|
+
this.loopCount = 0;
|
|
74
|
+
this.setContext('currentPromptId', promptId);
|
|
75
|
+
this.setContext('loopDetectorReset', Date.now().toString());
|
|
76
|
+
// Update CodeBolt agent state
|
|
77
|
+
try {
|
|
78
|
+
await codeboltjs_1.default.cbstate.addToAgentState('lastPromptId', promptId);
|
|
79
|
+
await codeboltjs_1.default.cbstate.addToAgentState('loopDetectorReset', Date.now().toString());
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.warn('Failed to update CodeBolt agent state:', error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async checkLoopDetection() {
|
|
86
|
+
var _a;
|
|
87
|
+
try {
|
|
88
|
+
// Get recent messages from CodeBolt state
|
|
89
|
+
const agentState = await codeboltjs_1.default.cbstate.getAgentState();
|
|
90
|
+
const recentMessages = ((_a = agentState.data) === null || _a === void 0 ? void 0 : _a.recentMessages) || [];
|
|
91
|
+
// Simple loop detection: check for repeated patterns
|
|
92
|
+
if (recentMessages.length >= this.messageThreshold) {
|
|
93
|
+
const lastThree = recentMessages.slice(-3);
|
|
94
|
+
const previousThree = recentMessages.slice(-6, -3);
|
|
95
|
+
if (lastThree.length === 3 && previousThree.length === 3) {
|
|
96
|
+
const isLoop = JSON.stringify(lastThree) === JSON.stringify(previousThree);
|
|
97
|
+
if (isLoop) {
|
|
98
|
+
console.log('[Loop Detection] Loop detected in conversation');
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.warn('Failed to check loop detection:', error);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Public methods for external control
|
|
111
|
+
resetSession() {
|
|
112
|
+
this.loopCount = 0;
|
|
113
|
+
this.lastPromptId = null;
|
|
114
|
+
this.clearContext();
|
|
115
|
+
// Clear CodeBolt agent state
|
|
116
|
+
try {
|
|
117
|
+
codeboltjs_1.default.cbstate.addToAgentState('sessionTurnCount', '0');
|
|
118
|
+
codeboltjs_1.default.cbstate.addToAgentState('lastPromptId', '');
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.warn('Failed to clear CodeBolt agent state:', error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getCurrentLoopCount() {
|
|
125
|
+
return this.loopCount;
|
|
126
|
+
}
|
|
127
|
+
setMaxLoops(maxLoops) {
|
|
128
|
+
this.maxLoops = Math.max(1, maxLoops);
|
|
129
|
+
}
|
|
130
|
+
enableLoopDetectionForSession() {
|
|
131
|
+
this.enableLoopDetection = true;
|
|
132
|
+
}
|
|
133
|
+
disableLoopDetectionForSession() {
|
|
134
|
+
this.enableLoopDetection = false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.LoopDetectionProcessor = LoopDetectionProcessor;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../../processor';
|
|
2
|
+
export interface ResponseValidationProcessorOptions {
|
|
3
|
+
validateToolCalls?: boolean;
|
|
4
|
+
validateContent?: boolean;
|
|
5
|
+
validateStructure?: boolean;
|
|
6
|
+
allowEmptyContent?: boolean;
|
|
7
|
+
maxContentLength?: number;
|
|
8
|
+
requiredFields?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface ValidationResult {
|
|
11
|
+
isValid: boolean;
|
|
12
|
+
errors: string[];
|
|
13
|
+
warnings: string[];
|
|
14
|
+
fixes: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare class ResponseValidationProcessor extends BaseProcessor {
|
|
17
|
+
private readonly enableToolCallValidation;
|
|
18
|
+
private readonly validateContent;
|
|
19
|
+
private readonly validateStructure;
|
|
20
|
+
private readonly allowEmptyContent;
|
|
21
|
+
private readonly maxContentLength;
|
|
22
|
+
private readonly requiredFields;
|
|
23
|
+
constructor(options?: ResponseValidationProcessorOptions);
|
|
24
|
+
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
25
|
+
private validateMessage;
|
|
26
|
+
private validateMessageStructure;
|
|
27
|
+
private validateMessageContent;
|
|
28
|
+
private validateToolCallsInMessage;
|
|
29
|
+
getValidationSummary(validationResult: ValidationResult): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseValidationProcessor = void 0;
|
|
4
|
+
const processor_1 = require("../../processor");
|
|
5
|
+
class ResponseValidationProcessor extends processor_1.BaseProcessor {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
super();
|
|
8
|
+
this.enableToolCallValidation = options.validateToolCalls !== false;
|
|
9
|
+
this.validateContent = options.validateContent !== false;
|
|
10
|
+
this.validateStructure = options.validateStructure !== false;
|
|
11
|
+
this.allowEmptyContent = options.allowEmptyContent || false;
|
|
12
|
+
this.maxContentLength = options.maxContentLength || 100000;
|
|
13
|
+
this.requiredFields = options.requiredFields || ['role'];
|
|
14
|
+
}
|
|
15
|
+
async processInput(input) {
|
|
16
|
+
var _a;
|
|
17
|
+
const { message } = input;
|
|
18
|
+
const validationResult = this.validateMessage(message);
|
|
19
|
+
const results = [
|
|
20
|
+
this.createEvent('ValidationCompleted', {
|
|
21
|
+
result: validationResult,
|
|
22
|
+
messageId: ((_a = message.metadata) === null || _a === void 0 ? void 0 : _a.id) || 'unknown'
|
|
23
|
+
})
|
|
24
|
+
];
|
|
25
|
+
if (!validationResult.isValid) {
|
|
26
|
+
results.push(this.createEvent('ValidationFailed', {
|
|
27
|
+
errors: validationResult.errors,
|
|
28
|
+
warnings: validationResult.warnings,
|
|
29
|
+
fixes: validationResult.fixes
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
if (validationResult.warnings.length > 0) {
|
|
33
|
+
results.push(this.createEvent('ValidationWarnings', {
|
|
34
|
+
warnings: validationResult.warnings
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return results;
|
|
38
|
+
}
|
|
39
|
+
validateMessage(message) {
|
|
40
|
+
const errors = [];
|
|
41
|
+
const warnings = [];
|
|
42
|
+
const fixes = [];
|
|
43
|
+
// Structure validation
|
|
44
|
+
if (this.validateStructure) {
|
|
45
|
+
const structureValidation = this.validateMessageStructure(message);
|
|
46
|
+
errors.push(...structureValidation.errors);
|
|
47
|
+
warnings.push(...structureValidation.warnings);
|
|
48
|
+
fixes.push(...structureValidation.fixes);
|
|
49
|
+
}
|
|
50
|
+
// Content validation
|
|
51
|
+
if (this.validateContent && message.messages) {
|
|
52
|
+
for (let i = 0; i < message.messages.length; i++) {
|
|
53
|
+
const msg = message.messages[i];
|
|
54
|
+
const contentValidation = this.validateMessageContent(msg, i);
|
|
55
|
+
errors.push(...contentValidation.errors);
|
|
56
|
+
warnings.push(...contentValidation.warnings);
|
|
57
|
+
fixes.push(...contentValidation.fixes);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Tool calls validation
|
|
61
|
+
if (this.enableToolCallValidation && message.messages) {
|
|
62
|
+
for (let i = 0; i < message.messages.length; i++) {
|
|
63
|
+
const msg = message.messages[i];
|
|
64
|
+
if (msg.tool_calls) {
|
|
65
|
+
const toolValidation = this.validateToolCallsInMessage(msg.tool_calls, i);
|
|
66
|
+
errors.push(...toolValidation.errors);
|
|
67
|
+
warnings.push(...toolValidation.warnings);
|
|
68
|
+
fixes.push(...toolValidation.fixes);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
isValid: errors.length === 0,
|
|
74
|
+
errors,
|
|
75
|
+
warnings,
|
|
76
|
+
fixes
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
validateMessageStructure(message) {
|
|
80
|
+
const errors = [];
|
|
81
|
+
const warnings = [];
|
|
82
|
+
const fixes = [];
|
|
83
|
+
// Check if message exists
|
|
84
|
+
if (!message) {
|
|
85
|
+
errors.push('Message is null or undefined');
|
|
86
|
+
fixes.push('Provide a valid message object');
|
|
87
|
+
return { isValid: false, errors, warnings, fixes };
|
|
88
|
+
}
|
|
89
|
+
// Check if messages array exists
|
|
90
|
+
if (!message.messages) {
|
|
91
|
+
errors.push('Message object missing required "messages" array');
|
|
92
|
+
fixes.push('Add a "messages" array to the message object');
|
|
93
|
+
}
|
|
94
|
+
else if (!Array.isArray(message.messages)) {
|
|
95
|
+
errors.push('Messages field must be an array');
|
|
96
|
+
fixes.push('Convert messages field to an array');
|
|
97
|
+
}
|
|
98
|
+
else if (message.messages.length === 0) {
|
|
99
|
+
warnings.push('Messages array is empty');
|
|
100
|
+
}
|
|
101
|
+
// Check metadata structure
|
|
102
|
+
if (message.metadata && typeof message.metadata !== 'object') {
|
|
103
|
+
warnings.push('Metadata should be an object');
|
|
104
|
+
fixes.push('Convert metadata to an object or remove it');
|
|
105
|
+
}
|
|
106
|
+
return { isValid: errors.length === 0, errors, warnings, fixes };
|
|
107
|
+
}
|
|
108
|
+
validateMessageContent(msg, index) {
|
|
109
|
+
const errors = [];
|
|
110
|
+
const warnings = [];
|
|
111
|
+
const fixes = [];
|
|
112
|
+
// Check required fields
|
|
113
|
+
for (const field of this.requiredFields) {
|
|
114
|
+
if (!(field in msg)) {
|
|
115
|
+
errors.push(`Message at index ${index} missing required field: ${field}`);
|
|
116
|
+
fixes.push(`Add ${field} field to message at index ${index}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Validate role
|
|
120
|
+
if (msg.role) {
|
|
121
|
+
const validRoles = ['user', 'assistant', 'system', 'tool'];
|
|
122
|
+
if (!validRoles.includes(msg.role)) {
|
|
123
|
+
errors.push(`Invalid role "${msg.role}" at index ${index}. Must be one of: ${validRoles.join(', ')}`);
|
|
124
|
+
fixes.push(`Change role to one of: ${validRoles.join(', ')}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Validate content
|
|
128
|
+
if (msg.content !== undefined) {
|
|
129
|
+
if (typeof msg.content === 'string') {
|
|
130
|
+
// String content validation
|
|
131
|
+
if (!this.allowEmptyContent && msg.content.trim() === '') {
|
|
132
|
+
warnings.push(`Empty content in message at index ${index}`);
|
|
133
|
+
fixes.push('Provide meaningful content or remove the message');
|
|
134
|
+
}
|
|
135
|
+
if (msg.content.length > this.maxContentLength) {
|
|
136
|
+
warnings.push(`Content too long at index ${index}: ${msg.content.length} chars (max: ${this.maxContentLength})`);
|
|
137
|
+
fixes.push('Truncate or compress the content');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (Array.isArray(msg.content)) {
|
|
141
|
+
// Array content validation (for multimodal messages)
|
|
142
|
+
for (let partIndex = 0; partIndex < msg.content.length; partIndex++) {
|
|
143
|
+
const part = msg.content[partIndex];
|
|
144
|
+
if (!part || (typeof part !== 'object' && typeof part !== 'string')) {
|
|
145
|
+
errors.push(`Invalid content part at message ${index}, part ${partIndex}`);
|
|
146
|
+
fixes.push('Ensure all content parts are valid objects or strings');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if (typeof msg.content !== 'object') {
|
|
151
|
+
warnings.push(`Unexpected content type at index ${index}: ${typeof msg.content}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Validate name field
|
|
155
|
+
if (msg.name && typeof msg.name !== 'string') {
|
|
156
|
+
warnings.push(`Name field should be a string at index ${index}`);
|
|
157
|
+
fixes.push('Convert name field to string');
|
|
158
|
+
}
|
|
159
|
+
return { isValid: errors.length === 0, errors, warnings, fixes };
|
|
160
|
+
}
|
|
161
|
+
validateToolCallsInMessage(toolCalls, messageIndex) {
|
|
162
|
+
const errors = [];
|
|
163
|
+
const warnings = [];
|
|
164
|
+
const fixes = [];
|
|
165
|
+
if (!Array.isArray(toolCalls)) {
|
|
166
|
+
errors.push(`Tool calls must be an array at message index ${messageIndex}`);
|
|
167
|
+
fixes.push('Convert tool_calls to an array');
|
|
168
|
+
return { isValid: false, errors, warnings, fixes };
|
|
169
|
+
}
|
|
170
|
+
for (let i = 0; i < toolCalls.length; i++) {
|
|
171
|
+
const toolCall = toolCalls[i];
|
|
172
|
+
// Check required tool call fields
|
|
173
|
+
if (!toolCall.id) {
|
|
174
|
+
errors.push(`Tool call at message ${messageIndex}, call ${i} missing required "id" field`);
|
|
175
|
+
fixes.push('Add unique id to tool call');
|
|
176
|
+
}
|
|
177
|
+
if (!toolCall.function) {
|
|
178
|
+
errors.push(`Tool call at message ${messageIndex}, call ${i} missing required "function" field`);
|
|
179
|
+
fixes.push('Add function object to tool call');
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// Validate function object
|
|
183
|
+
if (!toolCall.function.name) {
|
|
184
|
+
errors.push(`Tool call function at message ${messageIndex}, call ${i} missing "name" field`);
|
|
185
|
+
fixes.push('Add function name to tool call');
|
|
186
|
+
}
|
|
187
|
+
if (toolCall.function.arguments === undefined) {
|
|
188
|
+
warnings.push(`Tool call function at message ${messageIndex}, call ${i} missing "arguments" field`);
|
|
189
|
+
fixes.push('Add arguments field (can be empty object)');
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// Validate arguments
|
|
193
|
+
if (typeof toolCall.function.arguments === 'string') {
|
|
194
|
+
try {
|
|
195
|
+
JSON.parse(toolCall.function.arguments);
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
errors.push(`Invalid JSON in tool call arguments at message ${messageIndex}, call ${i}`);
|
|
199
|
+
fixes.push('Ensure arguments are valid JSON string or object');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else if (typeof toolCall.function.arguments !== 'object') {
|
|
203
|
+
warnings.push(`Tool call arguments should be object or JSON string at message ${messageIndex}, call ${i}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return { isValid: errors.length === 0, errors, warnings, fixes };
|
|
209
|
+
}
|
|
210
|
+
// Utility method to get validation summary
|
|
211
|
+
getValidationSummary(validationResult) {
|
|
212
|
+
const summary = [];
|
|
213
|
+
if (validationResult.isValid) {
|
|
214
|
+
summary.push('✅ Validation passed');
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
summary.push('❌ Validation failed');
|
|
218
|
+
}
|
|
219
|
+
if (validationResult.errors.length > 0) {
|
|
220
|
+
summary.push(`${validationResult.errors.length} error(s)`);
|
|
221
|
+
}
|
|
222
|
+
if (validationResult.warnings.length > 0) {
|
|
223
|
+
summary.push(`${validationResult.warnings.length} warning(s)`);
|
|
224
|
+
}
|
|
225
|
+
return summary.join(' - ');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.ResponseValidationProcessor = ResponseValidationProcessor;
|