@codebolt/agent 2.2.2 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builderpattern/agent.js +2 -2
- package/dist/builderpattern/followupquestionbuilder.js +1 -1
- package/dist/builderpattern/llmoutputhandler.js +7 -7
- package/dist/builderpattern/usermessage.d.ts +6 -1
- package/dist/composablepattern/document.js +2 -35
- package/dist/local-tools/fileTools.d.ts +26 -0
- package/dist/local-tools/fileTools.js +162 -0
- package/dist/processor/types/interfaces.d.ts +44 -21
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +13 -0
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +68 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +212 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +23 -0
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +173 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +14 -0
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +93 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +30 -0
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +330 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +26 -0
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +269 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +38 -0
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +217 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +34 -0
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +147 -0
- package/dist/processor-pieces/additionalModifiers/index.d.ts +12 -0
- package/dist/processor-pieces/additionalModifiers/index.js +28 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +29 -0
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +155 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +15 -0
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +129 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +25 -0
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +169 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +20 -0
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +152 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +93 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +14 -5
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +41 -40
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +9 -0
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +77 -0
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +5 -5
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +5 -13
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +50 -58
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +6 -8
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +66 -22
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +19 -0
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +110 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +20 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +124 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +41 -0
- package/dist/processor-pieces/messageModifiers/environmentContext.js +355 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +3 -2
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +1 -2
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +23 -0
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +207 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +26 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +18 -2
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +291 -93
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +1 -0
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +2 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +7 -0
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +24 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +41 -0
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +197 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +26 -0
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +90 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +81 -0
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +329 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +40 -0
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +272 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +291 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +47 -0
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +249 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +137 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +30 -0
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +228 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +99 -0
- package/dist/processor-pieces/postToolCall/telemetryProcessor.js +278 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +37 -0
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +178 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +43 -0
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +207 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +52 -0
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +264 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +49 -0
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +293 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +7 -0
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +31 -0
- package/dist/processor-pieces/preToolCall/index.d.ts +9 -0
- package/dist/processor-pieces/preToolCall/index.js +18 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +444 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +44 -0
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +367 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +58 -0
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +391 -0
- package/dist/unified/agent/agent.js +2 -2
- package/dist/unified/agent/tool.d.ts +99 -0
- package/dist/unified/agent/tool.js +440 -0
- package/dist/unified/base/initialPromptGenerator.js +5 -5
- package/dist/unified/base/responseExecutor.js +6 -6
- package/dist/unified/examples/agentExample.d.ts +46 -0
- package/dist/unified/examples/agentExample.js +464 -0
- package/dist/unified/examples/documentationPatternExample.d.ts +10 -0
- package/dist/unified/examples/documentationPatternExample.js +385 -0
- package/dist/unified/examples/followUpProcessorsExample.d.ts +45 -0
- package/dist/unified/examples/followUpProcessorsExample.js +311 -0
- package/dist/unified/examples/orchestratorExample.d.ts +16 -0
- package/dist/unified/examples/orchestratorExample.js +415 -0
- package/dist/unified/examples/preToolCallProcessorsExample.d.ts +36 -0
- package/dist/unified/examples/preToolCallProcessorsExample.js +458 -0
- package/dist/unified/examples/workflowExample.d.ts +12 -0
- package/dist/unified/examples/workflowExample.js +497 -0
- package/dist/unified/orchestrator/orchestrator.d.ts +260 -0
- package/dist/unified/orchestrator/orchestrator.js +519 -0
- package/package.json +15 -15
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- package/dist/followupquestionbuilder.d.ts +0 -75
- package/dist/followupquestionbuilder.js +0 -197
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -23
- package/dist/llmoutputhandler.d.ts +0 -102
- package/dist/llmoutputhandler.js +0 -452
- package/dist/promptbuilder.d.ts +0 -382
- package/dist/promptbuilder.js +0 -805
- package/dist/systemprompt.d.ts +0 -20
- package/dist/systemprompt.js +0 -48
- package/dist/taskInstruction.d.ts +0 -37
- package/dist/taskInstruction.js +0 -57
- package/dist/usermessage.d.ts +0 -70
- package/dist/usermessage.js +0 -123
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool creation utilities for the Unified Agent Framework
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createTool = createTool;
|
|
7
|
+
exports.createTextTool = createTextTool;
|
|
8
|
+
exports.createFileTool = createFileTool;
|
|
9
|
+
exports.createHttpTool = createHttpTool;
|
|
10
|
+
exports.createValidationTool = createValidationTool;
|
|
11
|
+
exports.createTransformTool = createTransformTool;
|
|
12
|
+
exports.toolsToOpenAIFormat = toolsToOpenAIFormat;
|
|
13
|
+
exports.executeTool = executeTool;
|
|
14
|
+
const zod_1 = require("zod");
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new tool with input/output validation and execution logic
|
|
17
|
+
*
|
|
18
|
+
* @template TInput - Type for tool input parameters
|
|
19
|
+
* @template TOutput - Type for tool output
|
|
20
|
+
* @param config - Tool configuration object
|
|
21
|
+
* @returns Fully configured tool with validation methods
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const calculatorTool = createTool({
|
|
26
|
+
* id: 'calculator',
|
|
27
|
+
* name: 'Calculator',
|
|
28
|
+
* description: 'Performs basic mathematical calculations',
|
|
29
|
+
* inputSchema: z.object({
|
|
30
|
+
* expression: z.string().describe('Mathematical expression to evaluate'),
|
|
31
|
+
* }),
|
|
32
|
+
* outputSchema: z.object({
|
|
33
|
+
* result: z.number(),
|
|
34
|
+
* expression: z.string(),
|
|
35
|
+
* }),
|
|
36
|
+
* execute: async ({ input }) => {
|
|
37
|
+
* const result = eval(input.expression); // Note: eval is dangerous, use a proper parser
|
|
38
|
+
* return { result, expression: input.expression };
|
|
39
|
+
* },
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
function createTool(config) {
|
|
44
|
+
const tool = {
|
|
45
|
+
...config,
|
|
46
|
+
/**
|
|
47
|
+
* Validates input against the tool's input schema
|
|
48
|
+
* @param input - Raw input to validate
|
|
49
|
+
* @returns Validated and typed input
|
|
50
|
+
* @throws {Error} If validation fails
|
|
51
|
+
*/
|
|
52
|
+
validateInput(input) {
|
|
53
|
+
try {
|
|
54
|
+
return config.inputSchema.parse(input);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
58
|
+
const errorMessages = error.issues
|
|
59
|
+
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
|
|
60
|
+
.join(', ');
|
|
61
|
+
throw new Error(`Tool "${config.id}" input validation failed: ${errorMessages}`);
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Validates output against the tool's output schema (if provided)
|
|
68
|
+
* @param output - Raw output to validate
|
|
69
|
+
* @returns Validated and typed output
|
|
70
|
+
* @throws {Error} If validation fails
|
|
71
|
+
*/
|
|
72
|
+
validateOutput(output) {
|
|
73
|
+
if (!config.outputSchema) {
|
|
74
|
+
return output;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
return config.outputSchema.parse(output);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
81
|
+
const errorMessages = error.issues
|
|
82
|
+
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
|
|
83
|
+
.join(', ');
|
|
84
|
+
throw new Error(`Tool "${config.id}" output validation failed: ${errorMessages}`);
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* Converts the tool to OpenAI function format
|
|
91
|
+
* @returns OpenAI function specification
|
|
92
|
+
*/
|
|
93
|
+
toOpenAITool() {
|
|
94
|
+
return {
|
|
95
|
+
type: 'function',
|
|
96
|
+
function: {
|
|
97
|
+
name: config.id,
|
|
98
|
+
description: config.description,
|
|
99
|
+
parameters: zodSchemaToJsonSchema(config.inputSchema)
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
return tool;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Converts a Zod schema to JSON Schema format for OpenAI functions
|
|
108
|
+
*/
|
|
109
|
+
function zodSchemaToJsonSchema(schema) {
|
|
110
|
+
// This is a simplified conversion - in a real implementation,
|
|
111
|
+
// you might want to use a library like zod-to-json-schema
|
|
112
|
+
if (schema instanceof zod_1.z.ZodObject) {
|
|
113
|
+
const shape = schema.shape;
|
|
114
|
+
const properties = {};
|
|
115
|
+
const required = [];
|
|
116
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
117
|
+
properties[key] = zodTypeToJsonSchema(value);
|
|
118
|
+
// Check if field is required (not optional)
|
|
119
|
+
if (!value.isOptional()) {
|
|
120
|
+
required.push(key);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
type: 'object',
|
|
125
|
+
properties,
|
|
126
|
+
required: required.length > 0 ? required : undefined,
|
|
127
|
+
additionalProperties: false
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return zodTypeToJsonSchema(schema);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Converts individual Zod types to JSON Schema
|
|
134
|
+
*/
|
|
135
|
+
function zodTypeToJsonSchema(zodType) {
|
|
136
|
+
if (zodType instanceof zod_1.z.ZodString) {
|
|
137
|
+
const result = { type: 'string' };
|
|
138
|
+
// Add description if available
|
|
139
|
+
if (zodType._def.description) {
|
|
140
|
+
result.description = zodType._def.description;
|
|
141
|
+
}
|
|
142
|
+
// Add constraints
|
|
143
|
+
const checks = zodType._def.checks || [];
|
|
144
|
+
for (const check of checks) {
|
|
145
|
+
switch (check.kind) {
|
|
146
|
+
case 'min':
|
|
147
|
+
result.minLength = check.value;
|
|
148
|
+
break;
|
|
149
|
+
case 'max':
|
|
150
|
+
result.maxLength = check.value;
|
|
151
|
+
break;
|
|
152
|
+
case 'email':
|
|
153
|
+
result.format = 'email';
|
|
154
|
+
break;
|
|
155
|
+
case 'url':
|
|
156
|
+
result.format = 'uri';
|
|
157
|
+
break;
|
|
158
|
+
case 'regex':
|
|
159
|
+
result.pattern = check.regex.source;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
if (zodType instanceof zod_1.z.ZodNumber) {
|
|
166
|
+
const result = { type: 'number' };
|
|
167
|
+
if (zodType._def.description) {
|
|
168
|
+
result.description = zodType._def.description;
|
|
169
|
+
}
|
|
170
|
+
const checks = zodType._def.checks || [];
|
|
171
|
+
for (const check of checks) {
|
|
172
|
+
switch (check.kind) {
|
|
173
|
+
case 'min':
|
|
174
|
+
result.minimum = check.value;
|
|
175
|
+
break;
|
|
176
|
+
case 'max':
|
|
177
|
+
result.maximum = check.value;
|
|
178
|
+
break;
|
|
179
|
+
case 'int':
|
|
180
|
+
result.type = 'integer';
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
if (zodType instanceof zod_1.z.ZodBoolean) {
|
|
187
|
+
const result = { type: 'boolean' };
|
|
188
|
+
if (zodType._def.description) {
|
|
189
|
+
result.description = zodType._def.description;
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
if (zodType instanceof zod_1.z.ZodArray) {
|
|
194
|
+
const result = {
|
|
195
|
+
type: 'array',
|
|
196
|
+
items: zodTypeToJsonSchema(zodType._def.type)
|
|
197
|
+
};
|
|
198
|
+
if (zodType._def.description) {
|
|
199
|
+
result.description = zodType._def.description;
|
|
200
|
+
}
|
|
201
|
+
const checks = zodType._def.checks || [];
|
|
202
|
+
for (const check of checks) {
|
|
203
|
+
switch (check.kind) {
|
|
204
|
+
case 'min':
|
|
205
|
+
result.minItems = check.value;
|
|
206
|
+
break;
|
|
207
|
+
case 'max':
|
|
208
|
+
result.maxItems = check.value;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
if (zodType instanceof zod_1.z.ZodEnum) {
|
|
215
|
+
const result = {
|
|
216
|
+
type: 'string',
|
|
217
|
+
enum: zodType._def.values
|
|
218
|
+
};
|
|
219
|
+
if (zodType._def.description) {
|
|
220
|
+
result.description = zodType._def.description;
|
|
221
|
+
}
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
if (zodType instanceof zod_1.z.ZodLiteral) {
|
|
225
|
+
const result = {
|
|
226
|
+
type: typeof zodType._def.value,
|
|
227
|
+
enum: [zodType._def.value]
|
|
228
|
+
};
|
|
229
|
+
if (zodType._def.description) {
|
|
230
|
+
result.description = zodType._def.description;
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
if (zodType instanceof zod_1.z.ZodUnion) {
|
|
235
|
+
const options = zodType._def.options;
|
|
236
|
+
const anyOf = options.map((option) => zodTypeToJsonSchema(option));
|
|
237
|
+
const result = { anyOf };
|
|
238
|
+
if (zodType._def.description) {
|
|
239
|
+
result.description = zodType._def.description;
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
if (zodType instanceof zod_1.z.ZodOptional) {
|
|
244
|
+
return zodTypeToJsonSchema(zodType._def.innerType);
|
|
245
|
+
}
|
|
246
|
+
if (zodType instanceof zod_1.z.ZodNullable) {
|
|
247
|
+
const innerSchema = zodTypeToJsonSchema(zodType._def.innerType);
|
|
248
|
+
return {
|
|
249
|
+
anyOf: [
|
|
250
|
+
innerSchema,
|
|
251
|
+
{ type: 'null' }
|
|
252
|
+
]
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
if (zodType instanceof zod_1.z.ZodObject) {
|
|
256
|
+
return zodSchemaToJsonSchema(zodType);
|
|
257
|
+
}
|
|
258
|
+
// Fallback for unknown types
|
|
259
|
+
return { type: 'string', description: 'Unknown type' };
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Creates a simple text-based tool
|
|
263
|
+
*/
|
|
264
|
+
function createTextTool(config) {
|
|
265
|
+
return createTool({
|
|
266
|
+
id: config.id,
|
|
267
|
+
name: config.name,
|
|
268
|
+
description: config.description,
|
|
269
|
+
inputSchema: zod_1.z.object({
|
|
270
|
+
text: zod_1.z.string().describe('Input text to process')
|
|
271
|
+
}),
|
|
272
|
+
outputSchema: zod_1.z.string(),
|
|
273
|
+
execute: async ({ input, context }) => {
|
|
274
|
+
return await config.execute(input.text, context);
|
|
275
|
+
},
|
|
276
|
+
timeout: config.timeout
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Creates a file operation tool
|
|
281
|
+
*/
|
|
282
|
+
function createFileTool(config) {
|
|
283
|
+
let inputSchema;
|
|
284
|
+
switch (config.operation) {
|
|
285
|
+
case 'read':
|
|
286
|
+
inputSchema = zod_1.z.object({
|
|
287
|
+
filePath: zod_1.z.string().describe('Path to the file to read'),
|
|
288
|
+
encoding: zod_1.z.string().optional().describe('File encoding (default: utf-8)')
|
|
289
|
+
});
|
|
290
|
+
break;
|
|
291
|
+
case 'write':
|
|
292
|
+
inputSchema = zod_1.z.object({
|
|
293
|
+
filePath: zod_1.z.string().describe('Path to the file to write'),
|
|
294
|
+
content: zod_1.z.string().describe('Content to write to the file'),
|
|
295
|
+
encoding: zod_1.z.string().optional().describe('File encoding (default: utf-8)')
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
case 'delete':
|
|
299
|
+
inputSchema = zod_1.z.object({
|
|
300
|
+
filePath: zod_1.z.string().describe('Path to the file to delete')
|
|
301
|
+
});
|
|
302
|
+
break;
|
|
303
|
+
case 'list':
|
|
304
|
+
inputSchema = zod_1.z.object({
|
|
305
|
+
directoryPath: zod_1.z.string().describe('Path to the directory to list'),
|
|
306
|
+
recursive: zod_1.z.boolean().optional().describe('Whether to list recursively')
|
|
307
|
+
});
|
|
308
|
+
break;
|
|
309
|
+
default:
|
|
310
|
+
throw new Error(`Unknown file operation: ${config.operation}`);
|
|
311
|
+
}
|
|
312
|
+
return createTool({
|
|
313
|
+
id: config.id,
|
|
314
|
+
name: config.name,
|
|
315
|
+
description: config.description,
|
|
316
|
+
inputSchema,
|
|
317
|
+
execute: config.execute
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Creates an HTTP request tool
|
|
322
|
+
*/
|
|
323
|
+
function createHttpTool(config) {
|
|
324
|
+
const inputSchema = zod_1.z.object({
|
|
325
|
+
url: zod_1.z.string().describe('URL to make the request to'),
|
|
326
|
+
method: zod_1.z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH']).optional().describe('HTTP method'),
|
|
327
|
+
headers: zod_1.z.record(zod_1.z.string()).optional().describe('Request headers'),
|
|
328
|
+
body: zod_1.z.any().optional().describe('Request body'),
|
|
329
|
+
timeout: zod_1.z.number().optional().describe('Request timeout in milliseconds')
|
|
330
|
+
});
|
|
331
|
+
const defaultExecute = async ({ input }) => {
|
|
332
|
+
const url = config.baseUrl ? `${config.baseUrl}${input.url}` : input.url;
|
|
333
|
+
const method = input.method || config.method || 'GET';
|
|
334
|
+
const headers = { ...config.defaultHeaders, ...input.headers };
|
|
335
|
+
// This would use fetch or similar HTTP client
|
|
336
|
+
return {
|
|
337
|
+
url,
|
|
338
|
+
method,
|
|
339
|
+
headers,
|
|
340
|
+
status: 200,
|
|
341
|
+
data: 'HTTP request executed successfully'
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
return createTool({
|
|
345
|
+
id: config.id,
|
|
346
|
+
name: config.name,
|
|
347
|
+
description: config.description,
|
|
348
|
+
inputSchema,
|
|
349
|
+
execute: config.execute || defaultExecute
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Creates a validation tool
|
|
354
|
+
*/
|
|
355
|
+
function createValidationTool(config) {
|
|
356
|
+
return createTool({
|
|
357
|
+
id: config.id,
|
|
358
|
+
name: config.name,
|
|
359
|
+
description: config.description,
|
|
360
|
+
inputSchema: zod_1.z.object({
|
|
361
|
+
data: zod_1.z.any().describe('Data to validate')
|
|
362
|
+
}),
|
|
363
|
+
execute: async ({ input }) => {
|
|
364
|
+
try {
|
|
365
|
+
const validatedData = config.schema.parse(input.data);
|
|
366
|
+
const result = config.onValid ? await config.onValid(validatedData) : validatedData;
|
|
367
|
+
return {
|
|
368
|
+
valid: true,
|
|
369
|
+
data: result,
|
|
370
|
+
errors: []
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
375
|
+
const errors = error.issues.map(issue => `${issue.path.join('.')}: ${issue.message}`);
|
|
376
|
+
const result = config.onInvalid ? await config.onInvalid(errors) : null;
|
|
377
|
+
return {
|
|
378
|
+
valid: false,
|
|
379
|
+
data: result,
|
|
380
|
+
errors
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Creates a transformation tool
|
|
390
|
+
*/
|
|
391
|
+
function createTransformTool(config) {
|
|
392
|
+
return createTool({
|
|
393
|
+
id: config.id,
|
|
394
|
+
name: config.name,
|
|
395
|
+
description: config.description,
|
|
396
|
+
inputSchema: config.inputSchema,
|
|
397
|
+
outputSchema: config.outputSchema,
|
|
398
|
+
execute: async ({ input, context }) => {
|
|
399
|
+
return await config.transform(input, context);
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Utility to convert multiple tools to OpenAI format
|
|
405
|
+
*/
|
|
406
|
+
function toolsToOpenAIFormat(tools) {
|
|
407
|
+
return tools.map(tool => tool.toOpenAITool());
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Utility to execute a tool with validation
|
|
411
|
+
*/
|
|
412
|
+
async function executeTool(tool, input, context, agent) {
|
|
413
|
+
// Validate input
|
|
414
|
+
const validatedInput = tool.validateInput(input);
|
|
415
|
+
// Execute with timeout if specified
|
|
416
|
+
let result;
|
|
417
|
+
if (tool.timeout) {
|
|
418
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
419
|
+
setTimeout(() => reject(new Error(`Tool execution timeout: ${tool.id}`)), tool.timeout);
|
|
420
|
+
});
|
|
421
|
+
const executionPromise = Promise.resolve(tool.execute({
|
|
422
|
+
input: validatedInput,
|
|
423
|
+
context,
|
|
424
|
+
agent
|
|
425
|
+
}));
|
|
426
|
+
result = await Promise.race([executionPromise, timeoutPromise]);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
result = await tool.execute({
|
|
430
|
+
input: validatedInput,
|
|
431
|
+
context,
|
|
432
|
+
agent
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
// Validate output if schema is provided
|
|
436
|
+
if (tool.validateOutput) {
|
|
437
|
+
return tool.validateOutput(result);
|
|
438
|
+
}
|
|
439
|
+
return result;
|
|
440
|
+
}
|
|
@@ -21,7 +21,7 @@ class InitialPromptGenerator {
|
|
|
21
21
|
async processMessage(input) {
|
|
22
22
|
try {
|
|
23
23
|
if (this.enableLogging) {
|
|
24
|
-
console.log('[InitialPromptGenerator] Processing message:', input);
|
|
24
|
+
// console.log('[InitialPromptGenerator] Processing message:', input);
|
|
25
25
|
}
|
|
26
26
|
// Create initial ProcessedMessage from FlatUserMessage
|
|
27
27
|
const content = input.userMessage;
|
|
@@ -59,10 +59,10 @@ class InitialPromptGenerator {
|
|
|
59
59
|
content: content.trim()
|
|
60
60
|
});
|
|
61
61
|
if (this.enableLogging) {
|
|
62
|
-
console.log('[InitialPromptGenerator] Processing completed:', {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
62
|
+
// console.log('[InitialPromptGenerator] Processing completed:', {
|
|
63
|
+
// messageCount: createdMessage.message.messages.length,
|
|
64
|
+
// metadata: createdMessage.metadata
|
|
65
|
+
// });
|
|
66
66
|
}
|
|
67
67
|
if (this.baseSystemPrompt !== undefined) {
|
|
68
68
|
const hasSystem = createdMessage.message.messages.some(msg => msg.role === 'system');
|
|
@@ -150,9 +150,9 @@ class ResponseExecutor {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
else {
|
|
153
|
-
console.log("Executing tool: ", toolName, toolInput);
|
|
153
|
+
// console.log("Executing tool: ", toolName, toolInput);
|
|
154
154
|
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
|
|
155
|
-
console.log("Tool result: ", result);
|
|
155
|
+
// console.log("Tool result: ", result);
|
|
156
156
|
// toolResults.push(this.parseToolResult(toolUseId, result));
|
|
157
157
|
let toolResult = this.parseToolResult(toolUseId, result);
|
|
158
158
|
toolResults.push({
|
|
@@ -233,11 +233,11 @@ class ResponseExecutor {
|
|
|
233
233
|
*/
|
|
234
234
|
async executeTool(toolName, toolInput) {
|
|
235
235
|
//codebolttools--readfile
|
|
236
|
-
console.log("Executing tool: ", toolName, toolInput);
|
|
236
|
+
// console.log("Executing tool: ", toolName, toolInput);
|
|
237
237
|
const [toolboxName, actualToolName] = toolName.split('--');
|
|
238
|
-
console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
|
|
238
|
+
// console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
|
|
239
239
|
const { data } = await codeboltjs_1.default.mcp.executeTool(toolboxName, actualToolName, toolInput);
|
|
240
|
-
console.log("Tool result: ", data);
|
|
240
|
+
// console.log("Tool result: ", data);
|
|
241
241
|
return [false, data];
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
@@ -251,7 +251,7 @@ class ResponseExecutor {
|
|
|
251
251
|
let userMessage = undefined;
|
|
252
252
|
try {
|
|
253
253
|
let parsed = JSON.parse(content);
|
|
254
|
-
console.log("Parsed Content: ", parsed);
|
|
254
|
+
// console.log("Parsed Content: ", parsed);
|
|
255
255
|
if (parsed.payload && parsed.payload.content) {
|
|
256
256
|
content = `The browser action has been executed. The screenshot have been captured for your analysis. The tool response is provided in the next user message`;
|
|
257
257
|
// this.apiConversationHistory.push()
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Examples demonstrating how to use the high-level Agent class
|
|
3
|
+
* with the Unified Agent Framework
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Example 1: Basic Agent with Default Processors
|
|
7
|
+
*/
|
|
8
|
+
export declare function basicAgentExample(): Promise<{
|
|
9
|
+
result1: any;
|
|
10
|
+
result2: any;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Example 2: Agent with Custom Tools and Processors
|
|
14
|
+
*/
|
|
15
|
+
export declare function customAgentExample(): Promise<{
|
|
16
|
+
result1: any;
|
|
17
|
+
result2: any;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Example 3: Agent with Local Tool Interception
|
|
21
|
+
*/
|
|
22
|
+
export declare function localToolInterceptionExample(): Promise<{
|
|
23
|
+
result1: any;
|
|
24
|
+
result2: any;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Example 4: Data Processing Agent with Validation and Transformation
|
|
28
|
+
*/
|
|
29
|
+
export declare function dataProcessingAgentExample(): Promise<{
|
|
30
|
+
result1: any;
|
|
31
|
+
result2: any;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Example 5: Dynamic Agent Configuration
|
|
35
|
+
*/
|
|
36
|
+
export declare function dynamicAgentExample(): Promise<{
|
|
37
|
+
result1: any;
|
|
38
|
+
result2: any;
|
|
39
|
+
result3: any;
|
|
40
|
+
tools: any;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Run all examples
|
|
44
|
+
*/
|
|
45
|
+
export declare function runAllExamples(): Promise<void>;
|
|
46
|
+
export { basicAgentExample, customAgentExample, localToolInterceptionExample, dataProcessingAgentExample, dynamicAgentExample };
|