@codebolt/agent 1.1.0 → 2.2.2
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/builderpattern/agent.d.ts +86 -0
- package/dist/builderpattern/agent.js +324 -0
- package/dist/builderpattern/followupquestionbuilder.d.ts +75 -0
- package/dist/builderpattern/followupquestionbuilder.js +197 -0
- package/dist/builderpattern/index.d.ts +14 -0
- package/dist/builderpattern/index.js +23 -0
- package/dist/builderpattern/llmoutputhandler.d.ts +102 -0
- package/dist/builderpattern/llmoutputhandler.js +452 -0
- package/dist/builderpattern/promptbuilder.d.ts +382 -0
- package/dist/builderpattern/promptbuilder.js +805 -0
- package/dist/builderpattern/systemprompt.d.ts +20 -0
- package/dist/builderpattern/systemprompt.js +48 -0
- package/dist/builderpattern/taskInstruction.d.ts +37 -0
- package/dist/builderpattern/taskInstruction.js +57 -0
- package/dist/builderpattern/usermessage.d.ts +70 -0
- package/dist/builderpattern/usermessage.js +123 -0
- 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 +405 -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/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 +94 -0
- package/dist/processor/types/interfaces.js +2 -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/addToolsListMessageModifier.d.ts +22 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +144 -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 +15 -0
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +75 -0
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +11 -0
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +46 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +18 -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/environmentContextModifier.d.ts +26 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +260 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +12 -0
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +60 -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 +18 -0
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +222 -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/toolInjectionModifier.d.ts +20 -0
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +152 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +22 -0
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +194 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.d.ts +29 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +174 -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/preInferenceProcessors/chatCompressionModifier.d.ts +35 -0
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +255 -0
- package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -0
- package/dist/processor-pieces/preInferenceProcessors/index.js +2 -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/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/index.d.ts +18 -0
- package/dist/unified/index.js +42 -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 +29 -7
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool creation utilities for the Unified Agent Framework
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Tool = void 0;
|
|
7
|
+
exports.createTool = createTool;
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
class Tool {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.id = config.id;
|
|
12
|
+
this.description = config.description;
|
|
13
|
+
this.inputSchema = config.inputSchema;
|
|
14
|
+
this.outputSchema = config.outputSchema;
|
|
15
|
+
this.executionFunction = config.execute;
|
|
16
|
+
}
|
|
17
|
+
async execute(input, context) {
|
|
18
|
+
const inputValidation = this.validateInput(input);
|
|
19
|
+
if (!inputValidation.valid) {
|
|
20
|
+
return { success: false, error: inputValidation.error };
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
let output = await this.executionFunction({ input, ...context });
|
|
24
|
+
const outputValidation = this.validateOutput(output);
|
|
25
|
+
if (!outputValidation.valid) {
|
|
26
|
+
return { success: false, error: outputValidation.error };
|
|
27
|
+
}
|
|
28
|
+
return { success: true, result: output };
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
error: `Tool "${this.id}" execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getToolDescription() {
|
|
38
|
+
return this.description;
|
|
39
|
+
}
|
|
40
|
+
getToolSchema() {
|
|
41
|
+
return this.inputSchema;
|
|
42
|
+
}
|
|
43
|
+
validateInput(input) {
|
|
44
|
+
try {
|
|
45
|
+
this.inputSchema.parse(input);
|
|
46
|
+
return { valid: true };
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
50
|
+
const errorMessages = error.issues
|
|
51
|
+
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
|
|
52
|
+
.join(', ');
|
|
53
|
+
return {
|
|
54
|
+
valid: false,
|
|
55
|
+
error: `Tool "${this.id}" input validation failed: ${errorMessages}`
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
valid: false,
|
|
60
|
+
error: `Tool "${this.id}" input validation failed: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Validates output against the tool's output schema (if provided)
|
|
66
|
+
* @param output - Raw output to validate
|
|
67
|
+
* @returns Validated and typed output
|
|
68
|
+
* @throws {Error} If validation fails
|
|
69
|
+
*/
|
|
70
|
+
validateOutput(output) {
|
|
71
|
+
if (!this.outputSchema) {
|
|
72
|
+
return { valid: true };
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
this.outputSchema.parse(output);
|
|
76
|
+
return { valid: true };
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
80
|
+
const errorMessages = error.issues
|
|
81
|
+
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
|
|
82
|
+
.join(', ');
|
|
83
|
+
return {
|
|
84
|
+
valid: false,
|
|
85
|
+
error: `Tool "${this.id}" output validation failed: ${errorMessages}`
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
valid: false,
|
|
90
|
+
error: `Tool "${this.id}" output validation failed: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Converts the tool to OpenAI function format
|
|
96
|
+
* @returns OpenAI function specification
|
|
97
|
+
*/
|
|
98
|
+
toOpenAITool() {
|
|
99
|
+
return {
|
|
100
|
+
type: 'function',
|
|
101
|
+
function: {
|
|
102
|
+
name: this.id,
|
|
103
|
+
description: this.description,
|
|
104
|
+
parameters: this.zodSchemaToJsonSchema(this.inputSchema)
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// /**
|
|
109
|
+
// * Converts a Zod schema to JSON Schema format for OpenAI functions
|
|
110
|
+
// */
|
|
111
|
+
zodSchemaToJsonSchema(schema) {
|
|
112
|
+
// This is a simplified conversion - in a real implementation,
|
|
113
|
+
// you might want to use a library like zod-to-json-schema
|
|
114
|
+
if (schema instanceof zod_1.z.ZodObject) {
|
|
115
|
+
const shape = schema.shape;
|
|
116
|
+
const properties = {};
|
|
117
|
+
const required = [];
|
|
118
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
119
|
+
properties[key] = this.zodTypeToJsonSchema(value);
|
|
120
|
+
// Check if field is required (not optional)
|
|
121
|
+
if (!value.isOptional()) {
|
|
122
|
+
required.push(key);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
type: 'object',
|
|
127
|
+
properties,
|
|
128
|
+
required: required.length > 0 ? required : undefined,
|
|
129
|
+
additionalProperties: false
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return this.zodTypeToJsonSchema(schema);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Converts individual Zod types to JSON Schema
|
|
136
|
+
*/
|
|
137
|
+
zodTypeToJsonSchema(zodType) {
|
|
138
|
+
if (zodType instanceof zod_1.z.ZodString) {
|
|
139
|
+
const result = { type: 'string' };
|
|
140
|
+
// Add description if available
|
|
141
|
+
if (zodType._def.description) {
|
|
142
|
+
result.description = zodType._def.description;
|
|
143
|
+
}
|
|
144
|
+
// Add constraints
|
|
145
|
+
const checks = zodType._def.checks || [];
|
|
146
|
+
for (const check of checks) {
|
|
147
|
+
switch (check.kind) {
|
|
148
|
+
case 'min':
|
|
149
|
+
result.minLength = check.value;
|
|
150
|
+
break;
|
|
151
|
+
case 'max':
|
|
152
|
+
result.maxLength = check.value;
|
|
153
|
+
break;
|
|
154
|
+
case 'email':
|
|
155
|
+
result.format = 'email';
|
|
156
|
+
break;
|
|
157
|
+
case 'url':
|
|
158
|
+
result.format = 'uri';
|
|
159
|
+
break;
|
|
160
|
+
case 'regex':
|
|
161
|
+
result.pattern = check.regex.source;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
if (zodType instanceof zod_1.z.ZodNumber) {
|
|
168
|
+
const result = { type: 'number' };
|
|
169
|
+
if (zodType._def.description) {
|
|
170
|
+
result.description = zodType._def.description;
|
|
171
|
+
}
|
|
172
|
+
const checks = zodType._def.checks || [];
|
|
173
|
+
for (const check of checks) {
|
|
174
|
+
switch (check.kind) {
|
|
175
|
+
case 'min':
|
|
176
|
+
result.minimum = check.value;
|
|
177
|
+
break;
|
|
178
|
+
case 'max':
|
|
179
|
+
result.maximum = check.value;
|
|
180
|
+
break;
|
|
181
|
+
case 'int':
|
|
182
|
+
result.type = 'integer';
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
if (zodType instanceof zod_1.z.ZodBoolean) {
|
|
189
|
+
const result = { type: 'boolean' };
|
|
190
|
+
if (zodType._def.description) {
|
|
191
|
+
result.description = zodType._def.description;
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
if (zodType instanceof zod_1.z.ZodArray) {
|
|
196
|
+
const result = {
|
|
197
|
+
type: 'array',
|
|
198
|
+
items: this.zodTypeToJsonSchema(zodType._def.type)
|
|
199
|
+
};
|
|
200
|
+
if (zodType._def.description) {
|
|
201
|
+
result.description = zodType._def.description;
|
|
202
|
+
}
|
|
203
|
+
const checks = zodType._def.checks || [];
|
|
204
|
+
for (const check of checks) {
|
|
205
|
+
switch (check.kind) {
|
|
206
|
+
case 'min':
|
|
207
|
+
result.minItems = check.value;
|
|
208
|
+
break;
|
|
209
|
+
case 'max':
|
|
210
|
+
result.maxItems = check.value;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
if (zodType instanceof zod_1.z.ZodEnum) {
|
|
217
|
+
const result = {
|
|
218
|
+
type: 'string',
|
|
219
|
+
enum: zodType._def.values
|
|
220
|
+
};
|
|
221
|
+
if (zodType._def.description) {
|
|
222
|
+
result.description = zodType._def.description;
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
if (zodType instanceof zod_1.z.ZodLiteral) {
|
|
227
|
+
const result = {
|
|
228
|
+
type: typeof zodType._def.value,
|
|
229
|
+
enum: [zodType._def.value]
|
|
230
|
+
};
|
|
231
|
+
if (zodType._def.description) {
|
|
232
|
+
result.description = zodType._def.description;
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
if (zodType instanceof zod_1.z.ZodUnion) {
|
|
237
|
+
const options = zodType._def.options;
|
|
238
|
+
const anyOf = options.map((option) => this.zodTypeToJsonSchema(option));
|
|
239
|
+
const result = { anyOf };
|
|
240
|
+
if (zodType._def.description) {
|
|
241
|
+
result.description = zodType._def.description;
|
|
242
|
+
}
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
if (zodType instanceof zod_1.z.ZodOptional) {
|
|
246
|
+
return this.zodTypeToJsonSchema(zodType._def.innerType);
|
|
247
|
+
}
|
|
248
|
+
if (zodType instanceof zod_1.z.ZodNullable) {
|
|
249
|
+
const innerSchema = this.zodTypeToJsonSchema(zodType._def.innerType);
|
|
250
|
+
return {
|
|
251
|
+
anyOf: [
|
|
252
|
+
innerSchema,
|
|
253
|
+
{ type: 'null' }
|
|
254
|
+
]
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
if (zodType instanceof zod_1.z.ZodObject) {
|
|
258
|
+
return this.zodSchemaToJsonSchema(zodType);
|
|
259
|
+
}
|
|
260
|
+
// Fallback for unknown types
|
|
261
|
+
return { type: 'string', description: 'Unknown type' };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
exports.Tool = Tool;
|
|
265
|
+
function createTool(config) {
|
|
266
|
+
const toolObject = new Tool(config);
|
|
267
|
+
return toolObject;
|
|
268
|
+
}
|
|
269
|
+
// /**
|
|
270
|
+
// * Creates a simple text-based tool
|
|
271
|
+
// */
|
|
272
|
+
// export function createTextTool(config: {
|
|
273
|
+
// id: string;
|
|
274
|
+
// name: string;
|
|
275
|
+
// description: string;
|
|
276
|
+
// execute: (text: string, context?: Record<string, any>) => Promise<string> | string;
|
|
277
|
+
// timeout?: number;
|
|
278
|
+
// }): Tool<{ text: string }, string> {
|
|
279
|
+
// return createTool({
|
|
280
|
+
// id: config.id,
|
|
281
|
+
// name: config.name,
|
|
282
|
+
// description: config.description,
|
|
283
|
+
// inputSchema: z.object({
|
|
284
|
+
// text: z.string().describe('Input text to process')
|
|
285
|
+
// }),
|
|
286
|
+
// outputSchema: z.string(),
|
|
287
|
+
// execute: async ({ input, context }) => {
|
|
288
|
+
// return await config.execute(input.text, context);
|
|
289
|
+
// },
|
|
290
|
+
// timeout: config.timeout
|
|
291
|
+
// });
|
|
292
|
+
// }
|
|
293
|
+
// /**
|
|
294
|
+
// * Creates a file operation tool
|
|
295
|
+
// */
|
|
296
|
+
// export function createFileTool(config: {
|
|
297
|
+
// id: string;
|
|
298
|
+
// name: string;
|
|
299
|
+
// description: string;
|
|
300
|
+
// operation: 'read' | 'write' | 'delete' | 'list';
|
|
301
|
+
// execute: (params: any, context?: Record<string, any>) => Promise<any> | any;
|
|
302
|
+
// }): Tool {
|
|
303
|
+
// let inputSchema: z.ZodType;
|
|
304
|
+
// switch (config.operation) {
|
|
305
|
+
// case 'read':
|
|
306
|
+
// inputSchema = z.object({
|
|
307
|
+
// filePath: z.string().describe('Path to the file to read'),
|
|
308
|
+
// encoding: z.string().optional().describe('File encoding (default: utf-8)')
|
|
309
|
+
// });
|
|
310
|
+
// break;
|
|
311
|
+
// case 'write':
|
|
312
|
+
// inputSchema = z.object({
|
|
313
|
+
// filePath: z.string().describe('Path to the file to write'),
|
|
314
|
+
// content: z.string().describe('Content to write to the file'),
|
|
315
|
+
// encoding: z.string().optional().describe('File encoding (default: utf-8)')
|
|
316
|
+
// });
|
|
317
|
+
// break;
|
|
318
|
+
// case 'delete':
|
|
319
|
+
// inputSchema = z.object({
|
|
320
|
+
// filePath: z.string().describe('Path to the file to delete')
|
|
321
|
+
// });
|
|
322
|
+
// break;
|
|
323
|
+
// case 'list':
|
|
324
|
+
// inputSchema = z.object({
|
|
325
|
+
// directoryPath: z.string().describe('Path to the directory to list'),
|
|
326
|
+
// recursive: z.boolean().optional().describe('Whether to list recursively')
|
|
327
|
+
// });
|
|
328
|
+
// break;
|
|
329
|
+
// default:
|
|
330
|
+
// throw new Error(`Unknown file operation: ${config.operation}`);
|
|
331
|
+
// }
|
|
332
|
+
// return createTool({
|
|
333
|
+
// id: config.id,
|
|
334
|
+
// name: config.name,
|
|
335
|
+
// description: config.description,
|
|
336
|
+
// inputSchema,
|
|
337
|
+
// execute: config.execute
|
|
338
|
+
// });
|
|
339
|
+
// }
|
|
340
|
+
// /**
|
|
341
|
+
// * Creates an HTTP request tool
|
|
342
|
+
// */
|
|
343
|
+
// export function createHttpTool(config: {
|
|
344
|
+
// id: string;
|
|
345
|
+
// name: string;
|
|
346
|
+
// description: string;
|
|
347
|
+
// method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
348
|
+
// baseUrl?: string;
|
|
349
|
+
// defaultHeaders?: Record<string, string>;
|
|
350
|
+
// execute?: (params: any, context?: Record<string, any>) => Promise<any> | any;
|
|
351
|
+
// }): Tool {
|
|
352
|
+
// const inputSchema = z.object({
|
|
353
|
+
// url: z.string().describe('URL to make the request to'),
|
|
354
|
+
// method: z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH']).optional().describe('HTTP method'),
|
|
355
|
+
// headers: z.record(z.string()).optional().describe('Request headers'),
|
|
356
|
+
// body: z.any().optional().describe('Request body'),
|
|
357
|
+
// timeout: z.number().optional().describe('Request timeout in milliseconds')
|
|
358
|
+
// });
|
|
359
|
+
// const defaultExecute = async ({ input }: { input: any }) => {
|
|
360
|
+
// const url = config.baseUrl ? `${config.baseUrl}${input.url}` : input.url;
|
|
361
|
+
// const method = input.method || config.method || 'GET';
|
|
362
|
+
// const headers = { ...config.defaultHeaders, ...input.headers };
|
|
363
|
+
// // This would use fetch or similar HTTP client
|
|
364
|
+
// return {
|
|
365
|
+
// url,
|
|
366
|
+
// method,
|
|
367
|
+
// headers,
|
|
368
|
+
// status: 200,
|
|
369
|
+
// data: 'HTTP request executed successfully'
|
|
370
|
+
// };
|
|
371
|
+
// };
|
|
372
|
+
// return createTool({
|
|
373
|
+
// id: config.id,
|
|
374
|
+
// name: config.name,
|
|
375
|
+
// description: config.description,
|
|
376
|
+
// inputSchema,
|
|
377
|
+
// execute: config.execute || defaultExecute
|
|
378
|
+
// });
|
|
379
|
+
// }
|
|
380
|
+
// /**
|
|
381
|
+
// * Creates a validation tool
|
|
382
|
+
// */
|
|
383
|
+
// export function createValidationTool<T>(config: {
|
|
384
|
+
// id: string;
|
|
385
|
+
// name: string;
|
|
386
|
+
// description: string;
|
|
387
|
+
// schema: z.ZodType<T>;
|
|
388
|
+
// onValid?: (data: T) => Promise<any> | any;
|
|
389
|
+
// onInvalid?: (errors: string[]) => Promise<any> | any;
|
|
390
|
+
// }): Tool {
|
|
391
|
+
// return createTool({
|
|
392
|
+
// id: config.id,
|
|
393
|
+
// name: config.name,
|
|
394
|
+
// description: config.description,
|
|
395
|
+
// inputSchema: z.object({
|
|
396
|
+
// data: z.any().describe('Data to validate')
|
|
397
|
+
// }),
|
|
398
|
+
// execute: async ({ input }) => {
|
|
399
|
+
// try {
|
|
400
|
+
// const validatedData = config.schema.parse(input.data);
|
|
401
|
+
// const result = config.onValid ? await config.onValid(validatedData) : validatedData;
|
|
402
|
+
// return {
|
|
403
|
+
// valid: true,
|
|
404
|
+
// data: result,
|
|
405
|
+
// errors: []
|
|
406
|
+
// };
|
|
407
|
+
// } catch (error) {
|
|
408
|
+
// if (error instanceof z.ZodError) {
|
|
409
|
+
// const errors = error.issues.map(issue =>
|
|
410
|
+
// `${issue.path.join('.')}: ${issue.message}`
|
|
411
|
+
// );
|
|
412
|
+
// const result = config.onInvalid ? await config.onInvalid(errors) : null;
|
|
413
|
+
// return {
|
|
414
|
+
// valid: false,
|
|
415
|
+
// data: result,
|
|
416
|
+
// errors
|
|
417
|
+
// };
|
|
418
|
+
// }
|
|
419
|
+
// throw error;
|
|
420
|
+
// }
|
|
421
|
+
// }
|
|
422
|
+
// });
|
|
423
|
+
// }
|
|
424
|
+
// /**
|
|
425
|
+
// * Creates a transformation tool
|
|
426
|
+
// */
|
|
427
|
+
// export function createTransformTool<TInput, TOutput>(config: {
|
|
428
|
+
// id: string;
|
|
429
|
+
// name: string;
|
|
430
|
+
// description: string;
|
|
431
|
+
// inputSchema: z.ZodType<TInput>;
|
|
432
|
+
// outputSchema?: z.ZodType<TOutput>;
|
|
433
|
+
// transform: (input: TInput, context?: Record<string, any>) => Promise<TOutput> | TOutput;
|
|
434
|
+
// }): Tool<TInput, TOutput> {
|
|
435
|
+
// return createTool({
|
|
436
|
+
// id: config.id,
|
|
437
|
+
// name: config.name,
|
|
438
|
+
// description: config.description,
|
|
439
|
+
// inputSchema: config.inputSchema,
|
|
440
|
+
// outputSchema: config.outputSchema,
|
|
441
|
+
// execute: async ({ input, context }) => {
|
|
442
|
+
// return await config.transform(input, context);
|
|
443
|
+
// }
|
|
444
|
+
// });
|
|
445
|
+
// }
|
|
446
|
+
// /**
|
|
447
|
+
// * Utility to convert multiple tools to OpenAI format
|
|
448
|
+
// */
|
|
449
|
+
// export function toolsToOpenAIFormat(tools: Tool[]): OpenAITool[] {
|
|
450
|
+
// return tools.map(tool => tool.toOpenAITool());
|
|
451
|
+
// }
|
|
452
|
+
// /**
|
|
453
|
+
// * Utility to execute a tool with validation
|
|
454
|
+
// */
|
|
455
|
+
// export async function executeTool<TInput, TOutput>(
|
|
456
|
+
// tool: Tool<TInput, TOutput>,
|
|
457
|
+
// input: unknown,
|
|
458
|
+
// context?: Record<string, any>,
|
|
459
|
+
// agent?: any
|
|
460
|
+
// ): Promise<TOutput> {
|
|
461
|
+
// // Validate input
|
|
462
|
+
// const validatedInput = tool.validateInput(input);
|
|
463
|
+
// // Execute with timeout if specified
|
|
464
|
+
// let result: TOutput;
|
|
465
|
+
// if (tool.timeout) {
|
|
466
|
+
// const timeoutPromise = new Promise<never>((_, reject) => {
|
|
467
|
+
// setTimeout(() => reject(new Error(`Tool execution timeout: ${tool.id}`)), tool.timeout);
|
|
468
|
+
// });
|
|
469
|
+
// const executionPromise = Promise.resolve(tool.execute({
|
|
470
|
+
// input: validatedInput,
|
|
471
|
+
// context,
|
|
472
|
+
// agent
|
|
473
|
+
// }));
|
|
474
|
+
// result = await Promise.race([executionPromise, timeoutPromise]);
|
|
475
|
+
// } else {
|
|
476
|
+
// result = await tool.execute({
|
|
477
|
+
// input: validatedInput,
|
|
478
|
+
// context,
|
|
479
|
+
// agent
|
|
480
|
+
// });
|
|
481
|
+
// }
|
|
482
|
+
// // Validate output if schema is provided
|
|
483
|
+
// if (tool.validateOutput) {
|
|
484
|
+
// return tool.validateOutput(result);
|
|
485
|
+
// }
|
|
486
|
+
// return result;
|
|
487
|
+
// }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseWorkflow, workflowConfig, WorkflowResult, workflowStepOutput } from "@codebolt/types/agent";
|
|
2
|
+
export declare class Workflow implements BaseWorkflow {
|
|
3
|
+
private config;
|
|
4
|
+
private context;
|
|
5
|
+
private currentStepIndex;
|
|
6
|
+
private executionId;
|
|
7
|
+
private startTime;
|
|
8
|
+
private stepResults;
|
|
9
|
+
constructor(config: workflowConfig);
|
|
10
|
+
execute(): WorkflowResult;
|
|
11
|
+
executeStep(): workflowStepOutput;
|
|
12
|
+
executeSteps(): workflowStepOutput[];
|
|
13
|
+
getContext(): any;
|
|
14
|
+
updateContext(newContext: any): void;
|
|
15
|
+
reset(): void;
|
|
16
|
+
getCurrentStepIndex(): number;
|
|
17
|
+
getTotalSteps(): number;
|
|
18
|
+
getExecutionId(): string;
|
|
19
|
+
setInitialContext(context: any): void;
|
|
20
|
+
getStepResults(): workflowStepOutput[];
|
|
21
|
+
executeAsync(): Promise<WorkflowResult>;
|
|
22
|
+
executeStepAsync(): Promise<workflowStepOutput>;
|
|
23
|
+
executeStepsAsync(): Promise<workflowStepOutput[]>;
|
|
24
|
+
}
|