@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.
Files changed (141) hide show
  1. package/dist/builderpattern/agent.js +2 -2
  2. package/dist/builderpattern/followupquestionbuilder.js +1 -1
  3. package/dist/builderpattern/llmoutputhandler.js +7 -7
  4. package/dist/builderpattern/usermessage.d.ts +6 -1
  5. package/dist/composablepattern/document.js +2 -35
  6. package/dist/local-tools/fileTools.d.ts +26 -0
  7. package/dist/local-tools/fileTools.js +162 -0
  8. package/dist/processor/types/interfaces.d.ts +44 -21
  9. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +13 -0
  10. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +68 -0
  11. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +15 -0
  12. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +212 -0
  13. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +19 -0
  14. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +110 -0
  15. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +23 -0
  16. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +173 -0
  17. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +14 -0
  18. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +93 -0
  19. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +30 -0
  20. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +330 -0
  21. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +26 -0
  22. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +269 -0
  23. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +38 -0
  24. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +217 -0
  25. package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +34 -0
  26. package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +147 -0
  27. package/dist/processor-pieces/additionalModifiers/index.d.ts +12 -0
  28. package/dist/processor-pieces/additionalModifiers/index.js +28 -0
  29. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +29 -0
  30. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +155 -0
  31. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +15 -0
  32. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +129 -0
  33. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +25 -0
  34. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +169 -0
  35. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +20 -0
  36. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +152 -0
  37. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +7 -0
  38. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +93 -0
  39. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +14 -5
  40. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +41 -40
  41. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +9 -0
  42. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +77 -0
  43. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +5 -5
  44. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +5 -13
  45. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +50 -58
  46. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +6 -8
  47. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +66 -22
  48. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +19 -0
  49. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +110 -0
  50. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +20 -0
  51. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +124 -0
  52. package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +41 -0
  53. package/dist/processor-pieces/messageModifiers/environmentContext.js +355 -0
  54. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +3 -2
  55. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +1 -2
  56. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +3 -2
  57. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +1 -2
  58. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +23 -0
  59. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +207 -0
  60. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +7 -0
  61. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +26 -0
  62. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +18 -2
  63. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +291 -93
  64. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +1 -0
  65. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +2 -0
  66. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +7 -0
  67. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +24 -0
  68. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +41 -0
  69. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +197 -0
  70. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +26 -0
  71. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +90 -0
  72. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +81 -0
  73. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +329 -0
  74. package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +40 -0
  75. package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +272 -0
  76. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +49 -0
  77. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +291 -0
  78. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +49 -0
  79. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +293 -0
  80. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +47 -0
  81. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +249 -0
  82. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +30 -0
  83. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +137 -0
  84. package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +30 -0
  85. package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +228 -0
  86. package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +99 -0
  87. package/dist/processor-pieces/postToolCall/telemetryProcessor.js +278 -0
  88. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +37 -0
  89. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +178 -0
  90. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +43 -0
  91. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +207 -0
  92. package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +52 -0
  93. package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +264 -0
  94. package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +49 -0
  95. package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +293 -0
  96. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +7 -0
  97. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +31 -0
  98. package/dist/processor-pieces/preToolCall/index.d.ts +9 -0
  99. package/dist/processor-pieces/preToolCall/index.js +18 -0
  100. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +58 -0
  101. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +444 -0
  102. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +44 -0
  103. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +367 -0
  104. package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +58 -0
  105. package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +391 -0
  106. package/dist/unified/agent/agent.js +2 -2
  107. package/dist/unified/agent/tool.d.ts +99 -0
  108. package/dist/unified/agent/tool.js +440 -0
  109. package/dist/unified/base/initialPromptGenerator.js +5 -5
  110. package/dist/unified/base/responseExecutor.js +6 -6
  111. package/dist/unified/examples/agentExample.d.ts +46 -0
  112. package/dist/unified/examples/agentExample.js +464 -0
  113. package/dist/unified/examples/documentationPatternExample.d.ts +10 -0
  114. package/dist/unified/examples/documentationPatternExample.js +385 -0
  115. package/dist/unified/examples/followUpProcessorsExample.d.ts +45 -0
  116. package/dist/unified/examples/followUpProcessorsExample.js +311 -0
  117. package/dist/unified/examples/orchestratorExample.d.ts +16 -0
  118. package/dist/unified/examples/orchestratorExample.js +415 -0
  119. package/dist/unified/examples/preToolCallProcessorsExample.d.ts +36 -0
  120. package/dist/unified/examples/preToolCallProcessorsExample.js +458 -0
  121. package/dist/unified/examples/workflowExample.d.ts +12 -0
  122. package/dist/unified/examples/workflowExample.js +497 -0
  123. package/dist/unified/orchestrator/orchestrator.d.ts +260 -0
  124. package/dist/unified/orchestrator/orchestrator.js +519 -0
  125. package/package.json +15 -15
  126. package/dist/agent.d.ts +0 -86
  127. package/dist/agent.js +0 -324
  128. package/dist/followupquestionbuilder.d.ts +0 -75
  129. package/dist/followupquestionbuilder.js +0 -197
  130. package/dist/index.d.ts +0 -14
  131. package/dist/index.js +0 -23
  132. package/dist/llmoutputhandler.d.ts +0 -102
  133. package/dist/llmoutputhandler.js +0 -452
  134. package/dist/promptbuilder.d.ts +0 -382
  135. package/dist/promptbuilder.js +0 -805
  136. package/dist/systemprompt.d.ts +0 -20
  137. package/dist/systemprompt.js +0 -48
  138. package/dist/taskInstruction.d.ts +0 -37
  139. package/dist/taskInstruction.js +0 -57
  140. package/dist/usermessage.d.ts +0 -70
  141. package/dist/usermessage.js +0 -123
@@ -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
+ }