@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,367 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolParameterModifierProcessor = void 0;
|
|
4
|
+
const processor_1 = require("../../processor");
|
|
5
|
+
/**
|
|
6
|
+
* Processor that modifies tool parameters before execution, applying transformations,
|
|
7
|
+
* enrichments, and sanitization to improve tool execution.
|
|
8
|
+
*/
|
|
9
|
+
class ToolParameterModifierProcessor extends processor_1.BaseProcessor {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.enableParameterTransformation = options.enableParameterTransformation !== false;
|
|
13
|
+
this.enableParameterEnrichment = options.enableParameterEnrichment !== false;
|
|
14
|
+
this.enableParameterSanitization = options.enableParameterSanitization !== false;
|
|
15
|
+
this.enableLogging = options.enableLogging !== false;
|
|
16
|
+
this.transformations = [
|
|
17
|
+
...(options.transformations || []),
|
|
18
|
+
...(options.defaultTransformations !== false ? this.getDefaultTransformations() : [])
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
async processInput(input) {
|
|
22
|
+
var _a;
|
|
23
|
+
try {
|
|
24
|
+
const { message, context } = input;
|
|
25
|
+
// Check if this is a pre-tool call processing
|
|
26
|
+
if (!(context === null || context === void 0 ? void 0 : context.preToolCallProcessing)) {
|
|
27
|
+
return [this.createEvent('ToolParameterModificationSkipped', {
|
|
28
|
+
reason: 'Not a pre-tool call processing context'
|
|
29
|
+
})];
|
|
30
|
+
}
|
|
31
|
+
const toolName = context.toolName;
|
|
32
|
+
const originalParameters = context.toolInput;
|
|
33
|
+
const toolUseId = context.toolUseId;
|
|
34
|
+
// Apply parameter modifications
|
|
35
|
+
const modificationResult = await this.modifyParameters(toolName, originalParameters, context);
|
|
36
|
+
if (modificationResult.modificationsApplied.length === 0) {
|
|
37
|
+
return [this.createEvent('ToolParameterModificationSkipped', {
|
|
38
|
+
toolName,
|
|
39
|
+
reason: 'No modifications needed'
|
|
40
|
+
})];
|
|
41
|
+
}
|
|
42
|
+
// Return modification results
|
|
43
|
+
return [
|
|
44
|
+
this.createEvent('ToolParametersModified', modificationResult),
|
|
45
|
+
this.createEvent('ToolModified', {
|
|
46
|
+
toolName,
|
|
47
|
+
toolInput: modificationResult.modifiedParameters,
|
|
48
|
+
originalInput: originalParameters,
|
|
49
|
+
modifications: modificationResult.modificationsApplied
|
|
50
|
+
})
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Error in ToolParameterModifierProcessor:', error);
|
|
55
|
+
return [this.createEvent('ToolParameterModificationError', {
|
|
56
|
+
error: error instanceof Error ? error.message : String(error),
|
|
57
|
+
toolName: (_a = input.context) === null || _a === void 0 ? void 0 : _a.toolName
|
|
58
|
+
})];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async modifyParameters(toolName, originalParameters, context) {
|
|
62
|
+
let modifiedParameters = this.deepClone(originalParameters);
|
|
63
|
+
const modificationsApplied = [];
|
|
64
|
+
const transformationsApplied = [];
|
|
65
|
+
// Apply sanitization
|
|
66
|
+
if (this.enableParameterSanitization) {
|
|
67
|
+
const sanitized = this.sanitizeParameters(toolName, modifiedParameters);
|
|
68
|
+
if (sanitized.modified) {
|
|
69
|
+
modifiedParameters = sanitized.parameters;
|
|
70
|
+
modificationsApplied.push('sanitization');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Apply enrichment
|
|
74
|
+
if (this.enableParameterEnrichment) {
|
|
75
|
+
const enriched = await this.enrichParameters(toolName, modifiedParameters, context);
|
|
76
|
+
if (enriched.modified) {
|
|
77
|
+
modifiedParameters = enriched.parameters;
|
|
78
|
+
modificationsApplied.push('enrichment');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Apply transformations
|
|
82
|
+
if (this.enableParameterTransformation) {
|
|
83
|
+
for (const transformation of this.transformations) {
|
|
84
|
+
try {
|
|
85
|
+
// Check if transformation condition is met
|
|
86
|
+
if (transformation.condition && !transformation.condition(toolName, modifiedParameters)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const beforeTransform = this.deepClone(modifiedParameters);
|
|
90
|
+
modifiedParameters = transformation.transform(modifiedParameters, context);
|
|
91
|
+
// Check if transformation actually changed something
|
|
92
|
+
if (JSON.stringify(beforeTransform) !== JSON.stringify(modifiedParameters)) {
|
|
93
|
+
transformationsApplied.push(transformation.name);
|
|
94
|
+
modificationsApplied.push(`transformation:${transformation.name}`);
|
|
95
|
+
if (this.enableLogging) {
|
|
96
|
+
console.log(`[ToolParameterModifier] Applied transformation '${transformation.name}' to tool '${toolName}'`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (this.enableLogging) {
|
|
102
|
+
console.error(`[ToolParameterModifier] Error applying transformation '${transformation.name}':`, error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
toolName,
|
|
109
|
+
originalParameters,
|
|
110
|
+
modifiedParameters,
|
|
111
|
+
modificationsApplied,
|
|
112
|
+
transformationsApplied
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
sanitizeParameters(toolName, parameters) {
|
|
116
|
+
if (!parameters || typeof parameters !== 'object') {
|
|
117
|
+
return { parameters, modified: false };
|
|
118
|
+
}
|
|
119
|
+
let modified = false;
|
|
120
|
+
const sanitized = this.deepClone(parameters);
|
|
121
|
+
// Sanitize string parameters
|
|
122
|
+
for (const [key, value] of Object.entries(sanitized)) {
|
|
123
|
+
if (typeof value === 'string') {
|
|
124
|
+
const originalValue = value;
|
|
125
|
+
let sanitizedValue = value;
|
|
126
|
+
// Remove potentially dangerous characters
|
|
127
|
+
sanitizedValue = sanitizedValue.replace(/[<>\"'&]/g, '');
|
|
128
|
+
// Trim whitespace
|
|
129
|
+
sanitizedValue = sanitizedValue.trim();
|
|
130
|
+
// Remove null bytes
|
|
131
|
+
sanitizedValue = sanitizedValue.replace(/\0/g, '');
|
|
132
|
+
if (sanitizedValue !== originalValue) {
|
|
133
|
+
sanitized[key] = sanitizedValue;
|
|
134
|
+
modified = true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Tool-specific sanitization
|
|
139
|
+
if (toolName.includes('file') || toolName.includes('path')) {
|
|
140
|
+
const pathFields = ['filePath', 'path', 'file', 'directory'];
|
|
141
|
+
for (const field of pathFields) {
|
|
142
|
+
if (field in sanitized && typeof sanitized[field] === 'string') {
|
|
143
|
+
const originalPath = sanitized[field];
|
|
144
|
+
let sanitizedPath = originalPath;
|
|
145
|
+
// Normalize path separators
|
|
146
|
+
sanitizedPath = sanitizedPath.replace(/\\/g, '/');
|
|
147
|
+
// Remove dangerous path components
|
|
148
|
+
sanitizedPath = sanitizedPath.replace(/\.\.\/|\.\.\\+/g, '');
|
|
149
|
+
// Remove multiple slashes
|
|
150
|
+
sanitizedPath = sanitizedPath.replace(/\/+/g, '/');
|
|
151
|
+
if (sanitizedPath !== originalPath) {
|
|
152
|
+
sanitized[field] = sanitizedPath;
|
|
153
|
+
modified = true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { parameters: sanitized, modified };
|
|
159
|
+
}
|
|
160
|
+
async enrichParameters(toolName, parameters, context) {
|
|
161
|
+
if (!parameters || typeof parameters !== 'object') {
|
|
162
|
+
return { parameters, modified: false };
|
|
163
|
+
}
|
|
164
|
+
let modified = false;
|
|
165
|
+
const enriched = this.deepClone(parameters);
|
|
166
|
+
// Add timestamp if not present
|
|
167
|
+
if (!enriched.timestamp) {
|
|
168
|
+
enriched.timestamp = new Date().toISOString();
|
|
169
|
+
modified = true;
|
|
170
|
+
}
|
|
171
|
+
// Add execution context
|
|
172
|
+
if (!enriched.executionContext) {
|
|
173
|
+
enriched.executionContext = {
|
|
174
|
+
toolName,
|
|
175
|
+
sessionId: context.sessionId || 'unknown',
|
|
176
|
+
requestId: context.toolUseId || 'unknown'
|
|
177
|
+
};
|
|
178
|
+
modified = true;
|
|
179
|
+
}
|
|
180
|
+
// Tool-specific enrichment
|
|
181
|
+
switch (toolName) {
|
|
182
|
+
case 'file_read':
|
|
183
|
+
case 'file_write':
|
|
184
|
+
if (!enriched.encoding && !enriched.hasOwnProperty('encoding')) {
|
|
185
|
+
enriched.encoding = 'utf-8';
|
|
186
|
+
modified = true;
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
case 'http_request':
|
|
190
|
+
if (!enriched.timeout) {
|
|
191
|
+
enriched.timeout = 30000; // 30 seconds
|
|
192
|
+
modified = true;
|
|
193
|
+
}
|
|
194
|
+
if (!enriched.headers) {
|
|
195
|
+
enriched.headers = {
|
|
196
|
+
'User-Agent': 'UnifiedAgent/1.0'
|
|
197
|
+
};
|
|
198
|
+
modified = true;
|
|
199
|
+
}
|
|
200
|
+
break;
|
|
201
|
+
case 'database_query':
|
|
202
|
+
if (!enriched.timeout) {
|
|
203
|
+
enriched.timeout = 60000; // 60 seconds
|
|
204
|
+
modified = true;
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
// Add retry configuration if not present for network operations
|
|
209
|
+
if (toolName.includes('http') || toolName.includes('api') || toolName.includes('request')) {
|
|
210
|
+
if (!enriched.retryConfig) {
|
|
211
|
+
enriched.retryConfig = {
|
|
212
|
+
maxRetries: 3,
|
|
213
|
+
retryDelay: 1000
|
|
214
|
+
};
|
|
215
|
+
modified = true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return { parameters: enriched, modified };
|
|
219
|
+
}
|
|
220
|
+
getDefaultTransformations() {
|
|
221
|
+
return [
|
|
222
|
+
{
|
|
223
|
+
name: 'normalize-file-paths',
|
|
224
|
+
condition: (toolName) => toolName.includes('file') || toolName.includes('path'),
|
|
225
|
+
transform: (params) => {
|
|
226
|
+
const result = { ...params };
|
|
227
|
+
const pathFields = ['filePath', 'path', 'file', 'directory'];
|
|
228
|
+
for (const field of pathFields) {
|
|
229
|
+
if (field in result && typeof result[field] === 'string') {
|
|
230
|
+
// Normalize path separators and resolve relative paths
|
|
231
|
+
result[field] = result[field].replace(/\\/g, '/');
|
|
232
|
+
// Convert relative paths to absolute if they don't start with /
|
|
233
|
+
if (!result[field].startsWith('/') && !result[field].match(/^[a-zA-Z]:/)) {
|
|
234
|
+
result[field] = `./${result[field]}`;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
239
|
+
},
|
|
240
|
+
description: 'Normalize file paths for consistency'
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: 'add-default-headers',
|
|
244
|
+
condition: (toolName) => toolName.includes('http') || toolName.includes('api'),
|
|
245
|
+
transform: (params) => {
|
|
246
|
+
const result = { ...params };
|
|
247
|
+
if (!result.headers) {
|
|
248
|
+
result.headers = {};
|
|
249
|
+
}
|
|
250
|
+
// Add default headers if not present
|
|
251
|
+
if (!result.headers['Content-Type'] && (result.body || result.data)) {
|
|
252
|
+
result.headers['Content-Type'] = 'application/json';
|
|
253
|
+
}
|
|
254
|
+
if (!result.headers['Accept']) {
|
|
255
|
+
result.headers['Accept'] = 'application/json';
|
|
256
|
+
}
|
|
257
|
+
return result;
|
|
258
|
+
},
|
|
259
|
+
description: 'Add default HTTP headers'
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
name: 'validate-and-format-json',
|
|
263
|
+
condition: (toolName, params) => {
|
|
264
|
+
return params && (params.json || params.data) && typeof params.data === 'string';
|
|
265
|
+
},
|
|
266
|
+
transform: (params) => {
|
|
267
|
+
const result = { ...params };
|
|
268
|
+
try {
|
|
269
|
+
// Try to parse and reformat JSON
|
|
270
|
+
if (result.data && typeof result.data === 'string') {
|
|
271
|
+
const parsed = JSON.parse(result.data);
|
|
272
|
+
result.data = JSON.stringify(parsed, null, 2);
|
|
273
|
+
}
|
|
274
|
+
if (result.json && typeof result.json === 'string') {
|
|
275
|
+
const parsed = JSON.parse(result.json);
|
|
276
|
+
result.json = JSON.stringify(parsed, null, 2);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
// If JSON is invalid, leave it as is
|
|
281
|
+
}
|
|
282
|
+
return result;
|
|
283
|
+
},
|
|
284
|
+
description: 'Validate and format JSON parameters'
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: 'add-safety-limits',
|
|
288
|
+
condition: () => true,
|
|
289
|
+
transform: (params) => {
|
|
290
|
+
const result = { ...params };
|
|
291
|
+
// Add timeout if not present
|
|
292
|
+
if (!result.timeout) {
|
|
293
|
+
result.timeout = 30000; // 30 seconds default
|
|
294
|
+
}
|
|
295
|
+
// Add size limits for file operations
|
|
296
|
+
if (!result.maxSize && (result.filePath || result.path)) {
|
|
297
|
+
result.maxSize = 10 * 1024 * 1024; // 10MB
|
|
298
|
+
}
|
|
299
|
+
return result;
|
|
300
|
+
},
|
|
301
|
+
description: 'Add safety limits to prevent resource exhaustion'
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
name: 'convert-relative-urls',
|
|
305
|
+
condition: (toolName) => toolName.includes('http') || toolName.includes('url'),
|
|
306
|
+
transform: (params) => {
|
|
307
|
+
const result = { ...params };
|
|
308
|
+
if (result.url && typeof result.url === 'string') {
|
|
309
|
+
// Convert relative URLs to absolute if a base URL is available
|
|
310
|
+
if (result.url.startsWith('/') && result.baseUrl) {
|
|
311
|
+
result.url = result.baseUrl.replace(/\/$/, '') + result.url;
|
|
312
|
+
}
|
|
313
|
+
// Ensure protocol is present
|
|
314
|
+
if (!result.url.match(/^https?:\/\//)) {
|
|
315
|
+
result.url = 'https://' + result.url;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return result;
|
|
319
|
+
},
|
|
320
|
+
description: 'Convert relative URLs to absolute URLs'
|
|
321
|
+
}
|
|
322
|
+
];
|
|
323
|
+
}
|
|
324
|
+
deepClone(obj) {
|
|
325
|
+
if (obj === null || typeof obj !== 'object') {
|
|
326
|
+
return obj;
|
|
327
|
+
}
|
|
328
|
+
if (obj instanceof Date) {
|
|
329
|
+
return new Date(obj.getTime());
|
|
330
|
+
}
|
|
331
|
+
if (Array.isArray(obj)) {
|
|
332
|
+
return obj.map(item => this.deepClone(item));
|
|
333
|
+
}
|
|
334
|
+
const cloned = {};
|
|
335
|
+
for (const key in obj) {
|
|
336
|
+
if (obj.hasOwnProperty(key)) {
|
|
337
|
+
cloned[key] = this.deepClone(obj[key]);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return cloned;
|
|
341
|
+
}
|
|
342
|
+
// Public methods for transformation management
|
|
343
|
+
addTransformation(transformation) {
|
|
344
|
+
this.transformations.push(transformation);
|
|
345
|
+
if (this.enableLogging) {
|
|
346
|
+
console.log(`[ToolParameterModifier] Added transformation: ${transformation.name}`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
removeTransformation(name) {
|
|
350
|
+
const index = this.transformations.findIndex(t => t.name === name);
|
|
351
|
+
if (index > -1) {
|
|
352
|
+
this.transformations.splice(index, 1);
|
|
353
|
+
if (this.enableLogging) {
|
|
354
|
+
console.log(`[ToolParameterModifier] Removed transformation: ${name}`);
|
|
355
|
+
}
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
getTransformations() {
|
|
361
|
+
return this.transformations.map(t => t.name);
|
|
362
|
+
}
|
|
363
|
+
hasTransformation(name) {
|
|
364
|
+
return this.transformations.some(t => t.name === name);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
exports.ToolParameterModifierProcessor = ToolParameterModifierProcessor;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { BaseProcessor, ProcessorInput, ProcessorOutput } from '../../processor';
|
|
2
|
+
export interface ToolValidationInfo {
|
|
3
|
+
toolName: string;
|
|
4
|
+
isValid: boolean;
|
|
5
|
+
validationErrors: string[];
|
|
6
|
+
validationWarnings: string[];
|
|
7
|
+
parameterValidation: {
|
|
8
|
+
required: string[];
|
|
9
|
+
missing: string[];
|
|
10
|
+
invalid: string[];
|
|
11
|
+
};
|
|
12
|
+
securityChecks: {
|
|
13
|
+
passed: boolean;
|
|
14
|
+
issues: string[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface ToolValidationProcessorOptions {
|
|
18
|
+
enableParameterValidation?: boolean;
|
|
19
|
+
enableSecurityValidation?: boolean;
|
|
20
|
+
enableTypeValidation?: boolean;
|
|
21
|
+
strictMode?: boolean;
|
|
22
|
+
allowedTools?: string[];
|
|
23
|
+
blockedTools?: string[];
|
|
24
|
+
maxParameterSize?: number;
|
|
25
|
+
enableLogging?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Processor that validates tool calls before execution, checking parameters,
|
|
29
|
+
* security constraints, and tool availability.
|
|
30
|
+
*/
|
|
31
|
+
export declare class ToolValidationProcessor extends BaseProcessor {
|
|
32
|
+
private readonly enableParameterValidation;
|
|
33
|
+
private readonly enableSecurityValidation;
|
|
34
|
+
private readonly enableTypeValidation;
|
|
35
|
+
private readonly strictMode;
|
|
36
|
+
private readonly allowedTools;
|
|
37
|
+
private readonly blockedTools;
|
|
38
|
+
private readonly maxParameterSize;
|
|
39
|
+
private readonly enableLogging;
|
|
40
|
+
constructor(options?: ToolValidationProcessorOptions);
|
|
41
|
+
processInput(input: ProcessorInput): Promise<ProcessorOutput[]>;
|
|
42
|
+
private validateTool;
|
|
43
|
+
private validateToolAvailability;
|
|
44
|
+
private validateParameters;
|
|
45
|
+
private validateSecurity;
|
|
46
|
+
private validateTypes;
|
|
47
|
+
private validateSize;
|
|
48
|
+
private getExpectedParameters;
|
|
49
|
+
private hasCircularReference;
|
|
50
|
+
private formatValidationErrors;
|
|
51
|
+
addAllowedTool(toolName: string): void;
|
|
52
|
+
removeAllowedTool(toolName: string): boolean;
|
|
53
|
+
addBlockedTool(toolName: string): void;
|
|
54
|
+
removeBlockedTool(toolName: string): boolean;
|
|
55
|
+
getAllowedTools(): string[];
|
|
56
|
+
getBlockedTools(): string[];
|
|
57
|
+
isToolAllowed(toolName: string): boolean;
|
|
58
|
+
}
|