@codebolt/agent 5.0.2 → 5.0.7

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