@codebolt/agent 1.2.1 → 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/README.md +157 -66
- package/dist/{agent.js → builderpattern/agent.js} +2 -2
- package/dist/{followupquestionbuilder.d.ts → builderpattern/followupquestionbuilder.d.ts} +1 -1
- package/dist/{followupquestionbuilder.js → builderpattern/followupquestionbuilder.js} +1 -1
- package/dist/{index.d.ts → builderpattern/index.d.ts} +3 -3
- package/dist/{llmoutputhandler.d.ts → builderpattern/llmoutputhandler.d.ts} +1 -1
- package/dist/{llmoutputhandler.js → builderpattern/llmoutputhandler.js} +7 -7
- package/dist/{promptbuilder.d.ts → builderpattern/promptbuilder.d.ts} +3 -3
- package/dist/{taskInstruction.d.ts → builderpattern/taskInstruction.d.ts} +2 -2
- package/dist/{usermessage.d.ts → builderpattern/usermessage.d.ts} +9 -4
- package/dist/composablepattern/agent.d.ts +169 -0
- package/dist/composablepattern/agent.js +598 -0
- package/dist/composablepattern/codebolt-storage.d.ts +67 -0
- package/dist/composablepattern/codebolt-storage.js +320 -0
- package/dist/composablepattern/document.d.ts +149 -0
- package/dist/composablepattern/document.js +372 -0
- package/dist/composablepattern/examples/codebolt-integration-example.d.ts +12 -0
- package/dist/composablepattern/examples/codebolt-integration-example.js +218 -0
- package/dist/composablepattern/examples/codebolt-storage-example.d.ts +40 -0
- package/dist/composablepattern/examples/codebolt-storage-example.js +223 -0
- package/dist/composablepattern/examples/custom-steps-example.d.ts +20 -0
- package/dist/composablepattern/examples/custom-steps-example.js +455 -0
- package/dist/composablepattern/examples/document-agent.d.ts +17 -0
- package/dist/composablepattern/examples/document-agent.js +107 -0
- package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +8 -0
- package/dist/composablepattern/examples/simple-codebolt-integration.js +164 -0
- package/dist/composablepattern/examples/weather-agent.d.ts +18 -0
- package/dist/composablepattern/examples/weather-agent.js +86 -0
- package/dist/composablepattern/examples/workflow-example.d.ts +12 -0
- package/dist/composablepattern/examples/workflow-example.js +463 -0
- package/dist/composablepattern/index.d.ts +63 -0
- package/dist/composablepattern/index.js +115 -0
- package/dist/composablepattern/memory.d.ts +89 -0
- package/dist/composablepattern/memory.js +141 -0
- package/dist/composablepattern/tool.d.ts +84 -0
- package/dist/composablepattern/tool.js +260 -0
- package/dist/composablepattern/types.d.ts +194 -0
- package/dist/composablepattern/types.js +6 -0
- package/dist/composablepattern/user-context.d.ts +214 -0
- package/dist/composablepattern/user-context.js +275 -0
- package/dist/composablepattern/workflow.d.ts +388 -0
- package/dist/composablepattern/workflow.js +562 -0
- package/dist/local-tools/fileTools.d.ts +26 -0
- package/dist/local-tools/fileTools.js +162 -0
- package/dist/processor/agent/agentStep.d.ts +49 -0
- package/dist/processor/agent/agentStep.js +241 -0
- package/dist/processor/agent/toolExecutor.d.ts +19 -0
- package/dist/processor/agent/toolExecutor.js +90 -0
- package/dist/processor/index.d.ts +7 -0
- package/dist/processor/index.js +36 -0
- package/dist/processor/messageModifiers/baseMessageModifier.d.ts +20 -0
- package/dist/processor/messageModifiers/baseMessageModifier.js +55 -0
- package/dist/processor/processors/baseProcessor.d.ts +14 -0
- package/dist/processor/processors/baseProcessor.js +29 -0
- package/dist/processor/tools/baseTool.d.ts +10 -0
- package/dist/processor/tools/baseTool.js +20 -0
- package/dist/processor/tools/toolList.d.ts +9 -0
- package/dist/processor/tools/toolList.js +22 -0
- package/dist/processor/types/interfaces.d.ts +117 -0
- package/dist/processor/types/interfaces.js +2 -0
- 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/base/baseMessageModifier.d.ts +12 -0
- package/dist/processor-pieces/base/baseMessageModifier.js +15 -0
- package/dist/processor-pieces/base/basePostInferenceProcessor.d.ts +13 -0
- package/dist/processor-pieces/base/basePostInferenceProcessor.js +18 -0
- package/dist/processor-pieces/base/basePostToolCallProcessor.d.ts +15 -0
- package/dist/processor-pieces/base/basePostToolCallProcessor.js +25 -0
- package/dist/processor-pieces/base/basePreInferenceProcessor.d.ts +12 -0
- package/dist/processor-pieces/base/basePreInferenceProcessor.js +17 -0
- package/dist/processor-pieces/base/basePreToolCallProcessor.d.ts +18 -0
- package/dist/processor-pieces/base/basePreToolCallProcessor.js +66 -0
- package/dist/processor-pieces/base/index.d.ts +9 -0
- package/dist/processor-pieces/base/index.js +18 -0
- package/dist/processor-pieces/index.d.ts +1 -0
- package/dist/processor-pieces/index.js +59 -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 +31 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +145 -0
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +9 -0
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +77 -0
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +13 -0
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +68 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +453 -0
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +67 -0
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +9 -0
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +90 -0
- 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.d.ts +18 -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/chatHistoryMessageModifier.js +104 -0
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +23 -0
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +173 -0
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +14 -0
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +130 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +36 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +418 -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/environmentContextModifier.d.ts +26 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +260 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +13 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +59 -0
- package/dist/processor-pieces/messageModifiers/ideContextModifier.d.ts +34 -0
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +157 -0
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +19 -0
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +221 -0
- package/dist/processor-pieces/messageModifiers/index.d.ts +11 -0
- package/dist/processor-pieces/messageModifiers/index.js +26 -0
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +15 -0
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +129 -0
- 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/toolInjectionModifier.d.ts +20 -0
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +152 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +38 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +392 -0
- 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/postInferenceProcessors/loopDetectionModifier.d.ts +29 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +174 -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/postToolCallProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/postToolCallProcessors/index.js +2 -0
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +225 -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/chatCompressionModifier.d.ts +35 -0
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +255 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +7 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +31 -0
- package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/preInferenceProcessors/index.js +2 -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/processor-pieces/pretoolCallProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/pretoolCallProcessors/index.js +2 -0
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +41 -0
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +197 -0
- package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +26 -0
- package/dist/processor-pieces/processors/chatCompressionProcessor.js +90 -0
- package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +81 -0
- package/dist/processor-pieces/processors/chatRecordingProcessor.js +329 -0
- package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +40 -0
- package/dist/processor-pieces/processors/contextManagementProcessor.js +305 -0
- package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +30 -0
- package/dist/processor-pieces/processors/loopDetectionProcessor.js +137 -0
- package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +30 -0
- package/dist/processor-pieces/processors/responseValidationProcessor.js +228 -0
- package/dist/processor-pieces/processors/telemetryProcessor.d.ts +99 -0
- package/dist/processor-pieces/processors/telemetryProcessor.js +311 -0
- package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +37 -0
- package/dist/processor-pieces/processors/tokenManagementProcessor.js +178 -0
- package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +43 -0
- package/dist/processor-pieces/processors/toolExecutionProcessor.js +207 -0
- package/dist/processor-pieces/tools/fileTools.d.ts +26 -0
- package/dist/processor-pieces/tools/fileTools.js +162 -0
- package/dist/processor-pieces/utils/messageModifierHelper.d.ts +4 -0
- package/dist/processor-pieces/utils/messageModifierHelper.js +58 -0
- package/dist/types/commonTypes.d.ts +4 -0
- package/dist/types/processorTypes.d.ts +67 -0
- package/dist/types/processorTypes.js +58 -0
- package/dist/unified/agent/agent.d.ts +17 -0
- package/dist/unified/agent/agent.js +79 -0
- package/dist/unified/agent/team.d.ts +2 -0
- package/dist/unified/agent/team.js +6 -0
- package/dist/unified/agent/tool.d.ts +99 -0
- package/dist/unified/agent/tool.js +440 -0
- package/dist/unified/agent/tools.d.ts +44 -0
- package/dist/unified/agent/tools.js +487 -0
- package/dist/unified/agent/workflow.d.ts +24 -0
- package/dist/unified/agent/workflow.js +275 -0
- package/dist/unified/agent/workflowControls.d.ts +11 -0
- package/dist/unified/agent/workflowControls.js +20 -0
- package/dist/unified/agent/workflowSteps.d.ts +63 -0
- package/dist/unified/agent/workflowSteps.js +284 -0
- package/dist/unified/base/agentStep.d.ts +32 -0
- package/dist/unified/base/agentStep.js +96 -0
- package/dist/unified/base/create/createInitialPromptGenerators.d.ts +5 -0
- package/dist/unified/base/create/createInitialPromptGenerators.js +17 -0
- package/dist/unified/base/index.d.ts +5 -0
- package/dist/unified/base/index.js +13 -0
- package/dist/unified/base/initialPromptGenerator.d.ts +48 -0
- package/dist/unified/base/initialPromptGenerator.js +118 -0
- package/dist/unified/base/responseExecutor.d.ts +36 -0
- package/dist/unified/base/responseExecutor.js +283 -0
- 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/index.d.ts +18 -0
- package/dist/unified/index.js +42 -0
- package/dist/unified/orchestrator/orchestrator.d.ts +260 -0
- package/dist/unified/orchestrator/orchestrator.js +519 -0
- package/dist/unified/team/team.d.ts +1 -0
- package/dist/unified/team/team.js +2 -0
- package/dist/unified/types/libTypes.d.ts +378 -0
- package/dist/unified/types/libTypes.js +6 -0
- package/dist/unified/types/types.d.ts +212 -0
- package/dist/unified/types/types.js +43 -0
- package/dist/unified/utils/utils.d.ts +40 -0
- package/dist/unified/utils/utils.js +219 -0
- package/package.json +35 -13
- /package/dist/{agent.d.ts → builderpattern/agent.d.ts} +0 -0
- /package/dist/{index.js → builderpattern/index.js} +0 -0
- /package/dist/{promptbuilder.js → builderpattern/promptbuilder.js} +0 -0
- /package/dist/{systemprompt.d.ts → builderpattern/systemprompt.d.ts} +0 -0
- /package/dist/{systemprompt.js → builderpattern/systemprompt.js} +0 -0
- /package/dist/{taskInstruction.js → builderpattern/taskInstruction.js} +0 -0
- /package/dist/{usermessage.js → builderpattern/usermessage.js} +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
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.ToolExecutionProcessor = void 0;
|
|
7
|
+
const processor_1 = require("../../processor");
|
|
8
|
+
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
9
|
+
class ToolExecutionProcessor extends processor_1.BaseProcessor {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.executedTools = new Map();
|
|
13
|
+
this.enableToolConfirmation = options.enableToolConfirmation !== false;
|
|
14
|
+
this.maxRetries = options.maxRetries || 3;
|
|
15
|
+
this.retryDelay = options.retryDelay || 1000;
|
|
16
|
+
this.enableLogging = options.enableLogging !== false;
|
|
17
|
+
}
|
|
18
|
+
async processInput(input) {
|
|
19
|
+
try {
|
|
20
|
+
const { message, context } = input;
|
|
21
|
+
// Check if message contains tool calls
|
|
22
|
+
const toolCalls = this.extractToolCalls(message);
|
|
23
|
+
if (toolCalls.length === 0) {
|
|
24
|
+
return [this.createEvent('NoToolCalls', {
|
|
25
|
+
reason: 'No tool calls found in message'
|
|
26
|
+
})];
|
|
27
|
+
}
|
|
28
|
+
const events = [
|
|
29
|
+
this.createEvent('ToolCallsDetected', {
|
|
30
|
+
count: toolCalls.length,
|
|
31
|
+
tools: toolCalls.map(tc => tc.function.name)
|
|
32
|
+
})
|
|
33
|
+
];
|
|
34
|
+
// Process each tool call
|
|
35
|
+
for (const toolCall of toolCalls) {
|
|
36
|
+
const executionInfo = await this.processToolCall(toolCall, context);
|
|
37
|
+
if (executionInfo.needsConfirmation) {
|
|
38
|
+
events.push(this.createEvent('ToolConfirmationRequired', executionInfo));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const result = await this.executeTool(executionInfo);
|
|
42
|
+
events.push(this.createEvent('ToolExecuted', result));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Add summary event
|
|
46
|
+
events.push(this.createEvent('ToolExecutionSummary', {
|
|
47
|
+
totalTools: toolCalls.length,
|
|
48
|
+
executedTools: Array.from(this.executedTools.values()),
|
|
49
|
+
successRate: this.calculateSuccessRate()
|
|
50
|
+
}));
|
|
51
|
+
return events;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Error in ToolExecutionProcessor:', error);
|
|
55
|
+
return [this.createEvent('ToolExecutionError', {
|
|
56
|
+
error: error instanceof Error ? error.message : String(error)
|
|
57
|
+
})];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
extractToolCalls(message) {
|
|
61
|
+
const toolCalls = [];
|
|
62
|
+
message.messages.forEach((msg) => {
|
|
63
|
+
if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
|
|
64
|
+
toolCalls.push(...msg.tool_calls);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return toolCalls;
|
|
68
|
+
}
|
|
69
|
+
async processToolCall(toolCall, context) {
|
|
70
|
+
const [toolbox, toolName] = toolCall.function.name.split('--');
|
|
71
|
+
if (!toolbox || !toolName) {
|
|
72
|
+
throw new Error(`Invalid tool name format: ${toolCall.function.name}`);
|
|
73
|
+
}
|
|
74
|
+
// Parse tool arguments
|
|
75
|
+
let parameters = {};
|
|
76
|
+
try {
|
|
77
|
+
parameters = typeof toolCall.function.arguments === 'string'
|
|
78
|
+
? JSON.parse(toolCall.function.arguments)
|
|
79
|
+
: toolCall.function.arguments;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.warn(`Failed to parse tool arguments for ${toolCall.function.name}:`, error);
|
|
83
|
+
}
|
|
84
|
+
// Check if tool needs confirmation
|
|
85
|
+
const needsConfirmation = this.shouldConfirmTool(toolCall, parameters);
|
|
86
|
+
return {
|
|
87
|
+
toolCall,
|
|
88
|
+
toolName,
|
|
89
|
+
toolbox,
|
|
90
|
+
parameters,
|
|
91
|
+
needsConfirmation
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
shouldConfirmTool(toolCall, parameters) {
|
|
95
|
+
// Check for dangerous operations
|
|
96
|
+
const dangerousOperations = [
|
|
97
|
+
'delete', 'remove', 'drop', 'destroy', 'format', 'wipe',
|
|
98
|
+
'shutdown', 'restart', 'kill', 'terminate'
|
|
99
|
+
];
|
|
100
|
+
const toolName = toolCall.function.name.toLowerCase();
|
|
101
|
+
const hasDangerousOperation = dangerousOperations.some(op => toolName.includes(op));
|
|
102
|
+
// Check for file system operations with important paths
|
|
103
|
+
if (parameters.filePath || parameters.path) {
|
|
104
|
+
const path = (parameters.filePath || parameters.path || '').toLowerCase();
|
|
105
|
+
const importantPaths = ['/', 'c:', 'system', 'windows', 'etc', 'usr'];
|
|
106
|
+
const hasImportantPath = importantPaths.some(ip => path.includes(ip));
|
|
107
|
+
if (hasImportantPath) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Check for network operations
|
|
112
|
+
if (parameters.url || parameters.host || parameters.port) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return hasDangerousOperation;
|
|
116
|
+
}
|
|
117
|
+
async executeTool(executionInfo) {
|
|
118
|
+
const startTime = Date.now();
|
|
119
|
+
const { toolCall, toolbox, toolName, parameters } = executionInfo;
|
|
120
|
+
try {
|
|
121
|
+
// Execute tool using CodeBolt's MCP
|
|
122
|
+
const { data } = await codeboltjs_1.default.mcp.executeTool(toolbox, toolName, parameters);
|
|
123
|
+
// Data comes as [failure: boolean, content: string] from CodeBolt MCP
|
|
124
|
+
let resultData;
|
|
125
|
+
let success = true;
|
|
126
|
+
if (Array.isArray(data) && data.length >= 2) {
|
|
127
|
+
const [failure, content] = data;
|
|
128
|
+
if (failure) {
|
|
129
|
+
success = false;
|
|
130
|
+
resultData = content; // Content is error message on failure
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
resultData = content; // Content is result on success
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// Fallback for unexpected data format
|
|
138
|
+
console.warn(`[Tool] Unexpected data format from ${toolCall.function.name}:`, data);
|
|
139
|
+
resultData = data;
|
|
140
|
+
}
|
|
141
|
+
const executionResult = {
|
|
142
|
+
toolCallId: toolCall.id,
|
|
143
|
+
result: resultData,
|
|
144
|
+
success: success,
|
|
145
|
+
executionTime: Date.now() - startTime,
|
|
146
|
+
error: success ? undefined : String(resultData)
|
|
147
|
+
};
|
|
148
|
+
// Store result
|
|
149
|
+
this.executedTools.set(toolCall.id, executionResult);
|
|
150
|
+
// Log execution if enabled
|
|
151
|
+
if (this.enableLogging) {
|
|
152
|
+
console.log(`[Tool] Successfully executed ${toolbox}--${toolName} in ${executionResult.executionTime}ms`);
|
|
153
|
+
}
|
|
154
|
+
return executionResult;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
const executionResult = {
|
|
158
|
+
toolCallId: toolCall.id,
|
|
159
|
+
result: null,
|
|
160
|
+
error: error instanceof Error ? error.message : String(error),
|
|
161
|
+
success: false,
|
|
162
|
+
executionTime: Date.now() - startTime
|
|
163
|
+
};
|
|
164
|
+
// Store result
|
|
165
|
+
this.executedTools.set(toolCall.id, executionResult);
|
|
166
|
+
// Log error if enabled
|
|
167
|
+
if (this.enableLogging) {
|
|
168
|
+
console.error(`[Tool] Failed to execute ${toolbox}--${toolName}:`, error);
|
|
169
|
+
}
|
|
170
|
+
return executionResult;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
calculateSuccessRate() {
|
|
174
|
+
if (this.executedTools.size === 0)
|
|
175
|
+
return 0;
|
|
176
|
+
const successfulTools = Array.from(this.executedTools.values())
|
|
177
|
+
.filter(result => result.success).length;
|
|
178
|
+
return (successfulTools / this.executedTools.size) * 100;
|
|
179
|
+
}
|
|
180
|
+
// Public methods for external control
|
|
181
|
+
async confirmToolExecution(toolCallId, confirmed) {
|
|
182
|
+
// This method can be used to track confirmation status in the future
|
|
183
|
+
// For now, we'll just log the confirmation
|
|
184
|
+
if (this.enableLogging) {
|
|
185
|
+
console.log(`[ToolExecutor] Tool ${toolCallId} confirmation: ${confirmed}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
getToolExecutionHistory() {
|
|
189
|
+
return Array.from(this.executedTools.values());
|
|
190
|
+
}
|
|
191
|
+
clearToolHistory() {
|
|
192
|
+
this.executedTools.clear();
|
|
193
|
+
}
|
|
194
|
+
setMaxRetries(maxRetries) {
|
|
195
|
+
this.maxRetries = Math.max(1, maxRetries);
|
|
196
|
+
}
|
|
197
|
+
setRetryDelay(delay) {
|
|
198
|
+
this.retryDelay = Math.max(100, delay);
|
|
199
|
+
}
|
|
200
|
+
enableLoggingForSession() {
|
|
201
|
+
this.enableLogging = true;
|
|
202
|
+
}
|
|
203
|
+
disableLoggingForSession() {
|
|
204
|
+
this.enableLogging = false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.ToolExecutionProcessor = ToolExecutionProcessor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PostToolCallProcessorInput, PostToolCallProcessorOutput } from "@codebolt/types/agent";
|
|
2
|
+
import { BasePostToolCallProcessor } from "../base";
|
|
3
|
+
export interface ShellProcessorOptions {
|
|
4
|
+
enableShellExecution?: boolean;
|
|
5
|
+
maxExecutionTime?: number;
|
|
6
|
+
allowedCommands?: string[];
|
|
7
|
+
blockedCommands?: string[];
|
|
8
|
+
workingDirectory?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class ShellProcessorModifier extends BasePostToolCallProcessor {
|
|
11
|
+
private readonly options;
|
|
12
|
+
private readonly execAsync;
|
|
13
|
+
private readonly SHELL_TRIGGER;
|
|
14
|
+
private readonly SHELL_CLOSE;
|
|
15
|
+
private readonly ARGS_PLACEHOLDER;
|
|
16
|
+
constructor(options?: ShellProcessorOptions);
|
|
17
|
+
modify(input: PostToolCallProcessorInput): Promise<PostToolCallProcessorOutput>;
|
|
18
|
+
private processShellInToolResults;
|
|
19
|
+
private processShellInjections;
|
|
20
|
+
private extractShellInjections;
|
|
21
|
+
private validateCommand;
|
|
22
|
+
private executeCommand;
|
|
23
|
+
private escapeShellArg;
|
|
24
|
+
private escapeRegex;
|
|
25
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ShellProcessorModifier = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const util_1 = require("util");
|
|
7
|
+
class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
super();
|
|
10
|
+
this.execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
11
|
+
this.SHELL_TRIGGER = '!{';
|
|
12
|
+
this.SHELL_CLOSE = '}';
|
|
13
|
+
this.ARGS_PLACEHOLDER = '{{args}}';
|
|
14
|
+
this.options = {
|
|
15
|
+
enableShellExecution: options.enableShellExecution || false, // Disabled by default for security
|
|
16
|
+
maxExecutionTime: options.maxExecutionTime || 10000, // 10 seconds
|
|
17
|
+
allowedCommands: options.allowedCommands || ['ls', 'pwd', 'echo', 'cat', 'head', 'tail', 'grep', 'find', 'wc'],
|
|
18
|
+
blockedCommands: options.blockedCommands || ['rm', 'del', 'format', 'sudo', 'su', 'chmod', 'chown', 'kill', 'killall'],
|
|
19
|
+
workingDirectory: options.workingDirectory || process.cwd()
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async modify(input) {
|
|
23
|
+
var _a;
|
|
24
|
+
try {
|
|
25
|
+
const { llmMessageSent, rawLLMResponseMessage, nextPrompt, toolResults } = input;
|
|
26
|
+
// Process shell commands in tool results if they exist
|
|
27
|
+
let processedNextPrompt = nextPrompt;
|
|
28
|
+
let shouldExit = false;
|
|
29
|
+
if (toolResults && toolResults.length > 0) {
|
|
30
|
+
// Look for shell-related tool results or commands in the content
|
|
31
|
+
const shellResults = toolResults.filter(result =>
|
|
32
|
+
// Check if the tool call ID suggests it's a shell command
|
|
33
|
+
(result.tool_call_id && (result.tool_call_id.includes('run_terminal_cmd') ||
|
|
34
|
+
result.tool_call_id.includes('shell'))) ||
|
|
35
|
+
// Check if content contains shell triggers or placeholders
|
|
36
|
+
(result.content && typeof result.content === 'string' &&
|
|
37
|
+
(result.content.includes(this.SHELL_TRIGGER) || result.content.includes(this.ARGS_PLACEHOLDER))));
|
|
38
|
+
if (shellResults.length > 0) {
|
|
39
|
+
processedNextPrompt = await this.processShellInToolResults(nextPrompt, shellResults);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Also process any shell injections in the next prompt messages
|
|
43
|
+
const updatedMessages = [];
|
|
44
|
+
let contentModified = false;
|
|
45
|
+
for (const message of processedNextPrompt.message.messages) {
|
|
46
|
+
if (typeof message.content === 'string') {
|
|
47
|
+
let processedContent = message.content;
|
|
48
|
+
// Replace {{args}} placeholders if metadata has args
|
|
49
|
+
const args = ((_a = processedNextPrompt.metadata) === null || _a === void 0 ? void 0 : _a.args) || '';
|
|
50
|
+
if (processedContent.includes(this.ARGS_PLACEHOLDER)) {
|
|
51
|
+
processedContent = processedContent.replace(new RegExp(this.escapeRegex(this.ARGS_PLACEHOLDER), 'g'), args);
|
|
52
|
+
contentModified = true;
|
|
53
|
+
}
|
|
54
|
+
// Process shell injections if enabled
|
|
55
|
+
if (this.options.enableShellExecution && processedContent.includes(this.SHELL_TRIGGER)) {
|
|
56
|
+
processedContent = await this.processShellInjections(processedContent, args);
|
|
57
|
+
contentModified = true;
|
|
58
|
+
}
|
|
59
|
+
updatedMessages.push({
|
|
60
|
+
...message,
|
|
61
|
+
content: processedContent
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
updatedMessages.push(message);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (contentModified) {
|
|
69
|
+
processedNextPrompt = {
|
|
70
|
+
message: {
|
|
71
|
+
...processedNextPrompt.message,
|
|
72
|
+
messages: updatedMessages
|
|
73
|
+
},
|
|
74
|
+
metadata: {
|
|
75
|
+
...processedNextPrompt.metadata,
|
|
76
|
+
shellProcessed: true,
|
|
77
|
+
argsReplaced: true
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
nextPrompt: processedNextPrompt,
|
|
83
|
+
shouldExit
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.error('Error in ShellProcessorModifier:', error);
|
|
88
|
+
return {
|
|
89
|
+
nextPrompt: input.nextPrompt,
|
|
90
|
+
shouldExit: false
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async processShellInToolResults(nextPrompt, shellResults) {
|
|
95
|
+
var _a;
|
|
96
|
+
// Process shell commands found in tool results
|
|
97
|
+
let processedPrompt = nextPrompt;
|
|
98
|
+
for (const result of shellResults) {
|
|
99
|
+
if (result.content && typeof result.content === 'string') {
|
|
100
|
+
const args = ((_a = processedPrompt.metadata) === null || _a === void 0 ? void 0 : _a.args) || '';
|
|
101
|
+
// Process any shell injections in the tool result content
|
|
102
|
+
if (result.content.includes(this.SHELL_TRIGGER)) {
|
|
103
|
+
const processedContent = await this.processShellInjections(result.content, args);
|
|
104
|
+
// Add the processed result as a system message
|
|
105
|
+
const systemMessage = {
|
|
106
|
+
role: 'system',
|
|
107
|
+
content: `[Shell Tool Result]: ${processedContent}`
|
|
108
|
+
};
|
|
109
|
+
processedPrompt = {
|
|
110
|
+
message: {
|
|
111
|
+
...processedPrompt.message,
|
|
112
|
+
messages: [...processedPrompt.message.messages, systemMessage]
|
|
113
|
+
},
|
|
114
|
+
metadata: {
|
|
115
|
+
...processedPrompt.metadata,
|
|
116
|
+
shellToolResultsProcessed: true
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return processedPrompt;
|
|
123
|
+
}
|
|
124
|
+
async processShellInjections(content, args) {
|
|
125
|
+
let processedContent = content;
|
|
126
|
+
const injections = this.extractShellInjections(content);
|
|
127
|
+
// Process injections in reverse order to maintain correct indices
|
|
128
|
+
for (let i = injections.length - 1; i >= 0; i--) {
|
|
129
|
+
const injection = injections[i];
|
|
130
|
+
try {
|
|
131
|
+
// Replace {{args}} in the command with shell-escaped args
|
|
132
|
+
const command = injection.command.replace(new RegExp(this.escapeRegex(this.ARGS_PLACEHOLDER), 'g'), this.escapeShellArg(args));
|
|
133
|
+
// Validate and execute command
|
|
134
|
+
this.validateCommand(command);
|
|
135
|
+
const result = await this.executeCommand(command);
|
|
136
|
+
const replacement = result;
|
|
137
|
+
processedContent = processedContent.substring(0, injection.startIndex) +
|
|
138
|
+
replacement +
|
|
139
|
+
processedContent.substring(injection.endIndex);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
143
|
+
const replacement = `[Shell command error: ${errorMessage}]`;
|
|
144
|
+
processedContent = processedContent.substring(0, injection.startIndex) +
|
|
145
|
+
replacement +
|
|
146
|
+
processedContent.substring(injection.endIndex);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return processedContent;
|
|
150
|
+
}
|
|
151
|
+
extractShellInjections(content) {
|
|
152
|
+
const injections = [];
|
|
153
|
+
let searchIndex = 0;
|
|
154
|
+
while (true) {
|
|
155
|
+
const startIndex = content.indexOf(this.SHELL_TRIGGER, searchIndex);
|
|
156
|
+
if (startIndex === -1)
|
|
157
|
+
break;
|
|
158
|
+
const contentStart = startIndex + this.SHELL_TRIGGER.length;
|
|
159
|
+
const endIndex = content.indexOf(this.SHELL_CLOSE, contentStart);
|
|
160
|
+
if (endIndex === -1) {
|
|
161
|
+
// No closing brace found, skip this occurrence
|
|
162
|
+
searchIndex = contentStart;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const command = content.substring(contentStart, endIndex).trim();
|
|
166
|
+
if (command.length > 0) {
|
|
167
|
+
injections.push({
|
|
168
|
+
startIndex,
|
|
169
|
+
endIndex: endIndex + this.SHELL_CLOSE.length,
|
|
170
|
+
command
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
searchIndex = endIndex + this.SHELL_CLOSE.length;
|
|
174
|
+
}
|
|
175
|
+
return injections;
|
|
176
|
+
}
|
|
177
|
+
validateCommand(command) {
|
|
178
|
+
if (!this.options.enableShellExecution) {
|
|
179
|
+
throw new Error('Shell execution is disabled');
|
|
180
|
+
}
|
|
181
|
+
// Extract the base command (first word)
|
|
182
|
+
const baseCommand = command.trim().split(/\s+/)[0];
|
|
183
|
+
// Check blocked commands
|
|
184
|
+
if (this.options.blockedCommands.some(blocked => baseCommand.includes(blocked))) {
|
|
185
|
+
throw new Error(`Command '${baseCommand}' is blocked for security reasons`);
|
|
186
|
+
}
|
|
187
|
+
// Check allowed commands (if allowlist is defined)
|
|
188
|
+
if (this.options.allowedCommands.length > 0 &&
|
|
189
|
+
!this.options.allowedCommands.some(allowed => baseCommand.includes(allowed))) {
|
|
190
|
+
throw new Error(`Command '${baseCommand}' is not in the allowed commands list`);
|
|
191
|
+
}
|
|
192
|
+
// Additional security checks
|
|
193
|
+
if (command.includes('&&') || command.includes('||') || command.includes(';') || command.includes('|')) {
|
|
194
|
+
throw new Error('Command chaining and piping are not allowed');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async executeCommand(command) {
|
|
198
|
+
try {
|
|
199
|
+
const { stdout, stderr } = await this.execAsync(command, {
|
|
200
|
+
cwd: this.options.workingDirectory,
|
|
201
|
+
timeout: this.options.maxExecutionTime,
|
|
202
|
+
maxBuffer: 1024 * 1024 // 1MB buffer
|
|
203
|
+
});
|
|
204
|
+
let result = stdout;
|
|
205
|
+
if (stderr) {
|
|
206
|
+
result += `\n[stderr]: ${stderr}`;
|
|
207
|
+
}
|
|
208
|
+
return result || '[Command executed successfully with no output]';
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
if (error.killed && error.signal === 'SIGTERM') {
|
|
212
|
+
throw new Error(`Command timed out after ${this.options.maxExecutionTime}ms`);
|
|
213
|
+
}
|
|
214
|
+
throw new Error(`Command failed: ${error.message}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
escapeShellArg(arg) {
|
|
218
|
+
// Basic shell escaping - in production, use a proper shell escaping library
|
|
219
|
+
return `"${arg.replace(/"/g, '\\"')}"`;
|
|
220
|
+
}
|
|
221
|
+
escapeRegex(str) {
|
|
222
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.ShellProcessorModifier = ShellProcessorModifier;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../types/processorTypes';
|
|
2
|
+
export interface ConversationCompactorInfo {
|
|
3
|
+
originalMessageCount: number;
|
|
4
|
+
compactedMessageCount: number;
|
|
5
|
+
compressionRatio: number;
|
|
6
|
+
compactionMethod: 'summarization' | 'truncation' | 'smart_removal';
|
|
7
|
+
preservedMessages: number;
|
|
8
|
+
removedMessages: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ConversationCompactorProcessorOptions {
|
|
11
|
+
maxConversationLength?: number;
|
|
12
|
+
compactionThreshold?: number;
|
|
13
|
+
preserveRecentMessages?: number;
|
|
14
|
+
preserveSystemMessages?: boolean;
|
|
15
|
+
preserveToolMessages?: boolean;
|
|
16
|
+
enableSummarization?: boolean;
|
|
17
|
+
enableSmartRemoval?: boolean;
|
|
18
|
+
compressionRatio?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Processor that compacts long conversations to keep them within manageable limits
|
|
22
|
+
* while preserving important context and recent interactions.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ConversationCompactorProcessor extends BaseProcessor {
|
|
25
|
+
private readonly maxConversationLength;
|
|
26
|
+
private readonly compactionThreshold;
|
|
27
|
+
private readonly preserveRecentMessages;
|
|
28
|
+
private readonly preserveSystemMessages;
|
|
29
|
+
private readonly preserveToolMessages;
|
|
30
|
+
private readonly enableSummarization;
|
|
31
|
+
private readonly enableSmartRemoval;
|
|
32
|
+
private readonly compressionRatio;
|
|
33
|
+
constructor(options?: ConversationCompactorProcessorOptions);
|
|
34
|
+
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
35
|
+
private shouldCompactConversation;
|
|
36
|
+
private compactConversation;
|
|
37
|
+
private compactWithSummarization;
|
|
38
|
+
private compactWithSmartRemoval;
|
|
39
|
+
private compactWithTruncation;
|
|
40
|
+
private calculateMessageImportance;
|
|
41
|
+
getMaxConversationLength(): number;
|
|
42
|
+
getCompactionThreshold(): number;
|
|
43
|
+
isCompactionNeeded(messageCount: number): boolean;
|
|
44
|
+
getCompressionRatio(): number;
|
|
45
|
+
getProcessorStats(): {
|
|
46
|
+
maxLength: number;
|
|
47
|
+
threshold: number;
|
|
48
|
+
preserveRecent: number;
|
|
49
|
+
compressionRatio: number;
|
|
50
|
+
enabledFeatures: string[];
|
|
51
|
+
};
|
|
52
|
+
}
|