@codebolt/agent 5.0.8 → 6.0.0
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/unified/base/responseExecutor.js +10 -6
- package/package.json +5 -5
- package/dist/agent.d.ts +0 -86
- package/dist/agent.js +0 -324
- package/dist/builderpattern/agent.d.ts +0 -86
- package/dist/builderpattern/agent.js +0 -324
- package/dist/builderpattern/followupquestionbuilder.d.ts +0 -75
- package/dist/builderpattern/followupquestionbuilder.js +0 -197
- package/dist/builderpattern/index.d.ts +0 -14
- package/dist/builderpattern/index.js +0 -23
- package/dist/builderpattern/llmoutputhandler.d.ts +0 -102
- package/dist/builderpattern/llmoutputhandler.js +0 -452
- package/dist/builderpattern/promptbuilder.d.ts +0 -382
- package/dist/builderpattern/promptbuilder.js +0 -805
- package/dist/builderpattern/systemprompt.d.ts +0 -20
- package/dist/builderpattern/systemprompt.js +0 -48
- package/dist/builderpattern/taskInstruction.d.ts +0 -37
- package/dist/builderpattern/taskInstruction.js +0 -57
- package/dist/builderpattern/usermessage.d.ts +0 -70
- package/dist/builderpattern/usermessage.js +0 -123
- package/dist/composablepattern/agent.d.ts +0 -169
- package/dist/composablepattern/agent.js +0 -598
- package/dist/composablepattern/codebolt-storage.d.ts +0 -67
- package/dist/composablepattern/codebolt-storage.js +0 -320
- package/dist/composablepattern/document.d.ts +0 -149
- package/dist/composablepattern/document.js +0 -405
- package/dist/composablepattern/examples/codebolt-integration-example.d.ts +0 -12
- package/dist/composablepattern/examples/codebolt-integration-example.js +0 -218
- package/dist/composablepattern/examples/codebolt-storage-example.d.ts +0 -40
- package/dist/composablepattern/examples/codebolt-storage-example.js +0 -223
- package/dist/composablepattern/examples/custom-steps-example.d.ts +0 -20
- package/dist/composablepattern/examples/custom-steps-example.js +0 -455
- package/dist/composablepattern/examples/document-agent.d.ts +0 -17
- package/dist/composablepattern/examples/document-agent.js +0 -107
- package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +0 -8
- package/dist/composablepattern/examples/simple-codebolt-integration.js +0 -164
- package/dist/composablepattern/examples/weather-agent.d.ts +0 -18
- package/dist/composablepattern/examples/weather-agent.js +0 -86
- package/dist/composablepattern/examples/workflow-example.d.ts +0 -12
- package/dist/composablepattern/examples/workflow-example.js +0 -463
- package/dist/composablepattern/index.d.ts +0 -63
- package/dist/composablepattern/index.js +0 -115
- package/dist/composablepattern/memory.d.ts +0 -89
- package/dist/composablepattern/memory.js +0 -141
- package/dist/composablepattern/tool.d.ts +0 -84
- package/dist/composablepattern/tool.js +0 -260
- package/dist/composablepattern/types.d.ts +0 -194
- package/dist/composablepattern/types.js +0 -6
- package/dist/composablepattern/user-context.d.ts +0 -214
- package/dist/composablepattern/user-context.js +0 -275
- package/dist/composablepattern/workflow.d.ts +0 -388
- package/dist/composablepattern/workflow.js +0 -562
- 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/processor/agent/agentStep.d.ts +0 -49
- package/dist/processor/agent/agentStep.js +0 -241
- package/dist/processor/agent/toolExecutor.d.ts +0 -19
- package/dist/processor/agent/toolExecutor.js +0 -90
- package/dist/processor/index.d.ts +0 -7
- package/dist/processor/index.js +0 -36
- package/dist/processor/messageModifiers/baseMessageModifier.d.ts +0 -20
- package/dist/processor/messageModifiers/baseMessageModifier.js +0 -55
- package/dist/processor/processors/baseProcessor.d.ts +0 -14
- package/dist/processor/processors/baseProcessor.js +0 -29
- package/dist/processor/tools/baseTool.d.ts +0 -10
- package/dist/processor/tools/baseTool.js +0 -20
- package/dist/processor/tools/toolList.d.ts +0 -9
- package/dist/processor/tools/toolList.js +0 -22
- package/dist/processor/types/interfaces.d.ts +0 -94
- package/dist/processor/types/interfaces.js +0 -2
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +0 -144
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +0 -15
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +0 -75
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +0 -11
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +0 -46
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +0 -12
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +0 -60
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +0 -18
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +0 -222
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +0 -22
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +0 -194
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +0 -41
- package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +0 -197
- package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +0 -26
- package/dist/processor-pieces/processors/chatCompressionProcessor.js +0 -90
- package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +0 -81
- package/dist/processor-pieces/processors/chatRecordingProcessor.js +0 -329
- package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +0 -40
- package/dist/processor-pieces/processors/contextManagementProcessor.js +0 -305
- package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/loopDetectionProcessor.js +0 -137
- package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +0 -30
- package/dist/processor-pieces/processors/responseValidationProcessor.js +0 -228
- package/dist/processor-pieces/processors/telemetryProcessor.d.ts +0 -99
- package/dist/processor-pieces/processors/telemetryProcessor.js +0 -311
- package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +0 -37
- package/dist/processor-pieces/processors/tokenManagementProcessor.js +0 -178
- package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +0 -43
- package/dist/processor-pieces/processors/toolExecutionProcessor.js +0 -207
- package/dist/processor-pieces/tools/fileTools.d.ts +0 -26
- package/dist/processor-pieces/tools/fileTools.js +0 -162
- 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
|
@@ -1,562 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Workflow system for Composable Agent Pattern
|
|
4
|
-
* @description Provides workflow orchestration for multi-step agent processes
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.Workflow = void 0;
|
|
8
|
-
exports.createAgentStep = createAgentStep;
|
|
9
|
-
exports.createTransformStep = createTransformStep;
|
|
10
|
-
exports.createConditionalStep = createConditionalStep;
|
|
11
|
-
exports.createDelayStep = createDelayStep;
|
|
12
|
-
exports.createStep = createStep;
|
|
13
|
-
exports.createSimpleStep = createSimpleStep;
|
|
14
|
-
exports.createAsyncStep = createAsyncStep;
|
|
15
|
-
exports.createValidationStep = createValidationStep;
|
|
16
|
-
exports.createLoggingStep = createLoggingStep;
|
|
17
|
-
exports.createWorkflow = createWorkflow;
|
|
18
|
-
const zod_1 = require("zod");
|
|
19
|
-
// ================================
|
|
20
|
-
// Workflow Engine
|
|
21
|
-
// ================================
|
|
22
|
-
class Workflow {
|
|
23
|
-
constructor(config) {
|
|
24
|
-
this.config = config;
|
|
25
|
-
this.context = {
|
|
26
|
-
data: { ...config.initialData || {} },
|
|
27
|
-
history: [],
|
|
28
|
-
currentStep: 0,
|
|
29
|
-
metadata: {
|
|
30
|
-
workflowName: config.name,
|
|
31
|
-
startTime: new Date().toISOString(),
|
|
32
|
-
steps: config.steps.map(s => ({ id: s.id, name: s.name }))
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Execute the workflow
|
|
38
|
-
*/
|
|
39
|
-
async execute() {
|
|
40
|
-
const startTime = Date.now();
|
|
41
|
-
try {
|
|
42
|
-
await this.executeSteps(this.config.steps);
|
|
43
|
-
const executionTime = Date.now() - startTime;
|
|
44
|
-
return {
|
|
45
|
-
success: true,
|
|
46
|
-
data: this.context.data,
|
|
47
|
-
stepResults: this.context.history,
|
|
48
|
-
executionTime,
|
|
49
|
-
metadata: {
|
|
50
|
-
...this.context.metadata,
|
|
51
|
-
endTime: new Date().toISOString(),
|
|
52
|
-
totalSteps: this.context.history.length
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
const executionTime = Date.now() - startTime;
|
|
58
|
-
return {
|
|
59
|
-
success: false,
|
|
60
|
-
data: this.context.data,
|
|
61
|
-
stepResults: this.context.history,
|
|
62
|
-
executionTime,
|
|
63
|
-
error: error instanceof Error ? error.message : String(error),
|
|
64
|
-
metadata: {
|
|
65
|
-
...this.context.metadata,
|
|
66
|
-
endTime: new Date().toISOString(),
|
|
67
|
-
failedAt: this.context.currentStep
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Execute a list of steps
|
|
74
|
-
*/
|
|
75
|
-
async executeSteps(steps) {
|
|
76
|
-
const parallelSteps = [];
|
|
77
|
-
for (const step of steps) {
|
|
78
|
-
// Check dependencies
|
|
79
|
-
if (step.dependencies) {
|
|
80
|
-
const unmetDeps = step.dependencies.filter(depId => !this.context.history.some(h => h.stepId === depId && h.success));
|
|
81
|
-
if (unmetDeps.length > 0) {
|
|
82
|
-
throw new Error(`Step ${step.id} has unmet dependencies: ${unmetDeps.join(', ')}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Check condition
|
|
86
|
-
if (step.condition && !(await step.condition(this.context))) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
if (step.parallel) {
|
|
90
|
-
parallelSteps.push(step);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
// Execute any pending parallel steps first
|
|
94
|
-
if (parallelSteps.length > 0) {
|
|
95
|
-
await this.executeParallelSteps(parallelSteps);
|
|
96
|
-
parallelSteps.length = 0;
|
|
97
|
-
}
|
|
98
|
-
// Execute this step
|
|
99
|
-
await this.executeStep(step);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// Execute any remaining parallel steps
|
|
103
|
-
if (parallelSteps.length > 0) {
|
|
104
|
-
await this.executeParallelSteps(parallelSteps);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Execute parallel steps
|
|
109
|
-
*/
|
|
110
|
-
async executeParallelSteps(steps) {
|
|
111
|
-
const maxConcurrency = this.config.maxParallelSteps || steps.length;
|
|
112
|
-
const batches = this.chunkArray(steps, maxConcurrency);
|
|
113
|
-
for (const batch of batches) {
|
|
114
|
-
await Promise.all(batch.map(step => this.executeStep(step)));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Execute a single step with retry logic
|
|
119
|
-
*/
|
|
120
|
-
async executeStep(step) {
|
|
121
|
-
var _a;
|
|
122
|
-
const maxAttempts = ((_a = step.retry) === null || _a === void 0 ? void 0 : _a.maxAttempts) || 1;
|
|
123
|
-
let lastError = null;
|
|
124
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
125
|
-
try {
|
|
126
|
-
const startTime = Date.now();
|
|
127
|
-
// Validate input if schema provided
|
|
128
|
-
if (step.inputSchema) {
|
|
129
|
-
step.inputSchema.parse(this.context.data);
|
|
130
|
-
}
|
|
131
|
-
const result = await step.execute(this.context);
|
|
132
|
-
// Validate output if schema provided
|
|
133
|
-
if (step.outputSchema && result.output !== undefined) {
|
|
134
|
-
step.outputSchema.parse(result.output);
|
|
135
|
-
}
|
|
136
|
-
result.executionTime = Date.now() - startTime;
|
|
137
|
-
this.context.history.push(result);
|
|
138
|
-
// Merge step output into context
|
|
139
|
-
if (result.output && typeof result.output === 'object') {
|
|
140
|
-
this.context.data = { ...this.context.data, ...result.output };
|
|
141
|
-
}
|
|
142
|
-
return; // Success, exit retry loop
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
146
|
-
if (attempt < maxAttempts && step.retry) {
|
|
147
|
-
const delay = this.calculateRetryDelay(step.retry, attempt);
|
|
148
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// All attempts failed
|
|
153
|
-
const result = {
|
|
154
|
-
stepId: step.id,
|
|
155
|
-
success: false,
|
|
156
|
-
error: (lastError === null || lastError === void 0 ? void 0 : lastError.message) || 'Unknown error',
|
|
157
|
-
executionTime: 0
|
|
158
|
-
};
|
|
159
|
-
this.context.history.push(result);
|
|
160
|
-
if (!this.config.continueOnError) {
|
|
161
|
-
throw lastError || new Error(`Step ${step.id} failed`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Calculate retry delay with backoff
|
|
166
|
-
*/
|
|
167
|
-
calculateRetryDelay(retryConfig, attempt) {
|
|
168
|
-
const baseDelay = retryConfig.delay;
|
|
169
|
-
switch (retryConfig.backoff) {
|
|
170
|
-
case 'exponential':
|
|
171
|
-
return baseDelay * Math.pow(2, attempt - 1);
|
|
172
|
-
case 'linear':
|
|
173
|
-
default:
|
|
174
|
-
return baseDelay * attempt;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Split array into chunks
|
|
179
|
-
*/
|
|
180
|
-
chunkArray(array, chunkSize) {
|
|
181
|
-
const chunks = [];
|
|
182
|
-
for (let i = 0; i < array.length; i += chunkSize) {
|
|
183
|
-
chunks.push(array.slice(i, i + chunkSize));
|
|
184
|
-
}
|
|
185
|
-
return chunks;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Get current workflow context
|
|
189
|
-
*/
|
|
190
|
-
getContext() {
|
|
191
|
-
return { ...this.context };
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Update workflow context data
|
|
195
|
-
*/
|
|
196
|
-
updateContext(data) {
|
|
197
|
-
this.context.data = { ...this.context.data, ...data };
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
exports.Workflow = Workflow;
|
|
201
|
-
// ================================
|
|
202
|
-
// Step Factory Functions
|
|
203
|
-
// ================================
|
|
204
|
-
/**
|
|
205
|
-
* Create an agent execution step
|
|
206
|
-
*/
|
|
207
|
-
function createAgentStep(config) {
|
|
208
|
-
return {
|
|
209
|
-
id: config.id,
|
|
210
|
-
name: config.name,
|
|
211
|
-
description: `Execute agent: ${config.agent.config.name}`,
|
|
212
|
-
execute: async (context) => {
|
|
213
|
-
try {
|
|
214
|
-
// Apply input mapping
|
|
215
|
-
let stepData = { ...context.data };
|
|
216
|
-
if (config.inputMapping) {
|
|
217
|
-
for (const [stepKey, contextKey] of Object.entries(config.inputMapping)) {
|
|
218
|
-
if (context.data[contextKey] !== undefined) {
|
|
219
|
-
stepData[stepKey] = context.data[contextKey];
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
// Replace template variables in message
|
|
224
|
-
const message = config.messageTemplate.replace(/\{\{(\w+)\}\}/g, (match, key) => {
|
|
225
|
-
return stepData[key] !== undefined ? String(stepData[key]) : match;
|
|
226
|
-
});
|
|
227
|
-
const result = await config.agent.execute(message);
|
|
228
|
-
// Apply output mapping
|
|
229
|
-
let output = { agentResult: result };
|
|
230
|
-
if (config.outputMapping) {
|
|
231
|
-
output = {};
|
|
232
|
-
for (const [contextKey, resultKey] of Object.entries(config.outputMapping)) {
|
|
233
|
-
const value = resultKey.split('.').reduce((obj, key) => obj === null || obj === void 0 ? void 0 : obj[key], { agentResult: result });
|
|
234
|
-
if (value !== undefined) {
|
|
235
|
-
output[contextKey] = value;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
stepId: config.id,
|
|
241
|
-
success: result.success,
|
|
242
|
-
output,
|
|
243
|
-
error: result.error,
|
|
244
|
-
executionTime: 0 // Will be set by executeStep
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
catch (error) {
|
|
248
|
-
return {
|
|
249
|
-
stepId: config.id,
|
|
250
|
-
success: false,
|
|
251
|
-
error: error instanceof Error ? error.message : String(error),
|
|
252
|
-
executionTime: 0
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Create a data transformation step
|
|
260
|
-
*/
|
|
261
|
-
function createTransformStep(config) {
|
|
262
|
-
return {
|
|
263
|
-
id: config.id,
|
|
264
|
-
name: config.name,
|
|
265
|
-
description: 'Transform data',
|
|
266
|
-
inputSchema: config.inputSchema,
|
|
267
|
-
outputSchema: config.outputSchema,
|
|
268
|
-
execute: async (context) => {
|
|
269
|
-
try {
|
|
270
|
-
const output = await config.transform(context.data);
|
|
271
|
-
return {
|
|
272
|
-
stepId: config.id,
|
|
273
|
-
success: true,
|
|
274
|
-
output,
|
|
275
|
-
executionTime: 0
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
catch (error) {
|
|
279
|
-
return {
|
|
280
|
-
stepId: config.id,
|
|
281
|
-
success: false,
|
|
282
|
-
error: error instanceof Error ? error.message : String(error),
|
|
283
|
-
executionTime: 0
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Create a conditional branch step
|
|
291
|
-
*/
|
|
292
|
-
function createConditionalStep(config) {
|
|
293
|
-
return {
|
|
294
|
-
id: config.id,
|
|
295
|
-
name: config.name,
|
|
296
|
-
description: 'Conditional execution',
|
|
297
|
-
execute: async (context) => {
|
|
298
|
-
try {
|
|
299
|
-
const conditionResult = await config.condition(context);
|
|
300
|
-
const stepsToExecute = conditionResult ? config.trueBranch : (config.falseBranch || []);
|
|
301
|
-
// Execute conditional steps
|
|
302
|
-
const subWorkflow = new Workflow({
|
|
303
|
-
name: `${config.id}-branch`,
|
|
304
|
-
steps: stepsToExecute,
|
|
305
|
-
initialData: context.data
|
|
306
|
-
});
|
|
307
|
-
const result = await subWorkflow.execute();
|
|
308
|
-
return {
|
|
309
|
-
stepId: config.id,
|
|
310
|
-
success: result.success,
|
|
311
|
-
output: result.data,
|
|
312
|
-
error: result.error,
|
|
313
|
-
executionTime: result.executionTime,
|
|
314
|
-
metadata: {
|
|
315
|
-
conditionResult,
|
|
316
|
-
branchExecuted: conditionResult ? 'true' : 'false',
|
|
317
|
-
subSteps: result.stepResults.length
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
catch (error) {
|
|
322
|
-
return {
|
|
323
|
-
stepId: config.id,
|
|
324
|
-
success: false,
|
|
325
|
-
error: error instanceof Error ? error.message : String(error),
|
|
326
|
-
executionTime: 0
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Create a delay step
|
|
334
|
-
*/
|
|
335
|
-
function createDelayStep(config) {
|
|
336
|
-
return {
|
|
337
|
-
id: config.id,
|
|
338
|
-
name: config.name,
|
|
339
|
-
description: `Delay for ${config.delay}ms`,
|
|
340
|
-
execute: async () => {
|
|
341
|
-
await new Promise(resolve => setTimeout(resolve, config.delay));
|
|
342
|
-
return {
|
|
343
|
-
stepId: config.id,
|
|
344
|
-
success: true,
|
|
345
|
-
executionTime: config.delay
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Create a simple custom step with your own logic
|
|
352
|
-
*
|
|
353
|
-
* @param config - Step configuration with custom execute function
|
|
354
|
-
* @returns WorkflowStep
|
|
355
|
-
*
|
|
356
|
-
* @example
|
|
357
|
-
* ```typescript
|
|
358
|
-
* const customStep = createStep({
|
|
359
|
-
* id: 'my-step',
|
|
360
|
-
* name: 'My Custom Step',
|
|
361
|
-
* description: 'Does something custom',
|
|
362
|
-
* execute: async (context) => {
|
|
363
|
-
* // Your custom logic here
|
|
364
|
-
* const result = await doSomething(context.data);
|
|
365
|
-
* return {
|
|
366
|
-
* stepId: 'my-step',
|
|
367
|
-
* success: true,
|
|
368
|
-
* output: { customResult: result },
|
|
369
|
-
* executionTime: 0
|
|
370
|
-
* };
|
|
371
|
-
* }
|
|
372
|
-
* });
|
|
373
|
-
* ```
|
|
374
|
-
*/
|
|
375
|
-
function createStep(config) {
|
|
376
|
-
return {
|
|
377
|
-
id: config.id,
|
|
378
|
-
name: config.name,
|
|
379
|
-
description: config.description,
|
|
380
|
-
inputSchema: config.inputSchema,
|
|
381
|
-
outputSchema: config.outputSchema,
|
|
382
|
-
execute: config.execute,
|
|
383
|
-
condition: config.condition,
|
|
384
|
-
dependencies: config.dependencies,
|
|
385
|
-
parallel: config.parallel,
|
|
386
|
-
retry: config.retry
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Create a simple step that executes a function with the context data
|
|
391
|
-
*
|
|
392
|
-
* @param config - Step configuration with transform function
|
|
393
|
-
* @returns WorkflowStep
|
|
394
|
-
*
|
|
395
|
-
* @example
|
|
396
|
-
* ```typescript
|
|
397
|
-
* const mathStep = createSimpleStep({
|
|
398
|
-
* id: 'calculate',
|
|
399
|
-
* name: 'Calculate Total',
|
|
400
|
-
* execute: (data) => {
|
|
401
|
-
* const total = data.items.reduce((sum, item) => sum + item.price, 0);
|
|
402
|
-
* return { total, itemCount: data.items.length };
|
|
403
|
-
* }
|
|
404
|
-
* });
|
|
405
|
-
* ```
|
|
406
|
-
*/
|
|
407
|
-
function createSimpleStep(config) {
|
|
408
|
-
return createStep({
|
|
409
|
-
...config,
|
|
410
|
-
execute: async (context) => {
|
|
411
|
-
try {
|
|
412
|
-
const output = await config.execute(context.data);
|
|
413
|
-
return {
|
|
414
|
-
stepId: config.id,
|
|
415
|
-
success: true,
|
|
416
|
-
output,
|
|
417
|
-
executionTime: 0 // Will be set by executeStep
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
catch (error) {
|
|
421
|
-
return {
|
|
422
|
-
stepId: config.id,
|
|
423
|
-
success: false,
|
|
424
|
-
error: error instanceof Error ? error.message : String(error),
|
|
425
|
-
executionTime: 0
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Create an async step that can perform asynchronous operations
|
|
433
|
-
*
|
|
434
|
-
* @param config - Step configuration with async function
|
|
435
|
-
* @returns WorkflowStep
|
|
436
|
-
*
|
|
437
|
-
* @example
|
|
438
|
-
* ```typescript
|
|
439
|
-
* const apiStep = createAsyncStep({
|
|
440
|
-
* id: 'fetch-data',
|
|
441
|
-
* name: 'Fetch External Data',
|
|
442
|
-
* execute: async (data) => {
|
|
443
|
-
* const response = await fetch(`/api/data/${data.id}`);
|
|
444
|
-
* const result = await response.json();
|
|
445
|
-
* return { fetchedData: result };
|
|
446
|
-
* },
|
|
447
|
-
* retry: {
|
|
448
|
-
* maxAttempts: 3,
|
|
449
|
-
* delay: 1000,
|
|
450
|
-
* backoff: 'exponential'
|
|
451
|
-
* }
|
|
452
|
-
* });
|
|
453
|
-
* ```
|
|
454
|
-
*/
|
|
455
|
-
function createAsyncStep(config) {
|
|
456
|
-
return createStep({
|
|
457
|
-
...config,
|
|
458
|
-
execute: async (context) => {
|
|
459
|
-
try {
|
|
460
|
-
const output = await config.execute(context.data, context);
|
|
461
|
-
return {
|
|
462
|
-
stepId: config.id,
|
|
463
|
-
success: true,
|
|
464
|
-
output,
|
|
465
|
-
executionTime: 0 // Will be set by executeStep
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
catch (error) {
|
|
469
|
-
return {
|
|
470
|
-
stepId: config.id,
|
|
471
|
-
success: false,
|
|
472
|
-
error: error instanceof Error ? error.message : String(error),
|
|
473
|
-
executionTime: 0
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Create a validation step that validates data against a schema
|
|
481
|
-
*
|
|
482
|
-
* @param config - Validation configuration
|
|
483
|
-
* @returns WorkflowStep
|
|
484
|
-
*/
|
|
485
|
-
function createValidationStep(config) {
|
|
486
|
-
return createStep({
|
|
487
|
-
id: config.id,
|
|
488
|
-
name: config.name,
|
|
489
|
-
description: `Validate ${config.field || 'data'} against schema`,
|
|
490
|
-
execute: async (context) => {
|
|
491
|
-
try {
|
|
492
|
-
const dataToValidate = config.field
|
|
493
|
-
? context.data[config.field]
|
|
494
|
-
: context.data;
|
|
495
|
-
const validatedData = config.schema.parse(dataToValidate);
|
|
496
|
-
return {
|
|
497
|
-
stepId: config.id,
|
|
498
|
-
success: true,
|
|
499
|
-
output: config.field
|
|
500
|
-
? { [config.field]: validatedData }
|
|
501
|
-
: validatedData,
|
|
502
|
-
executionTime: 0
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
catch (error) {
|
|
506
|
-
const errorMessage = error instanceof zod_1.z.ZodError
|
|
507
|
-
? `Validation failed: ${error.issues.map(i => `${i.path.join('.')}: ${i.message}`).join(', ')}`
|
|
508
|
-
: error instanceof Error ? error.message : String(error);
|
|
509
|
-
return {
|
|
510
|
-
stepId: config.id,
|
|
511
|
-
success: !config.stopOnFailure,
|
|
512
|
-
error: errorMessage,
|
|
513
|
-
executionTime: 0,
|
|
514
|
-
metadata: { validationError: true }
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
/**
|
|
521
|
-
* Create a logging step for debugging workflows
|
|
522
|
-
*
|
|
523
|
-
* @param config - Logging configuration
|
|
524
|
-
* @returns WorkflowStep
|
|
525
|
-
*/
|
|
526
|
-
function createLoggingStep(config) {
|
|
527
|
-
return createStep({
|
|
528
|
-
id: config.id,
|
|
529
|
-
name: config.name,
|
|
530
|
-
description: `Log workflow state`,
|
|
531
|
-
execute: async (context) => {
|
|
532
|
-
const level = config.level || 'info';
|
|
533
|
-
const message = config.message || `Step ${config.id} executed`;
|
|
534
|
-
// Extract specific fields if specified
|
|
535
|
-
const logData = config.fields
|
|
536
|
-
? config.fields.reduce((acc, field) => {
|
|
537
|
-
acc[field] = context.data[field];
|
|
538
|
-
return acc;
|
|
539
|
-
}, {})
|
|
540
|
-
: context.data;
|
|
541
|
-
// Log to console (in production, you might use a proper logger)
|
|
542
|
-
console[level](`[Workflow] ${message}`, {
|
|
543
|
-
stepId: config.id,
|
|
544
|
-
data: logData,
|
|
545
|
-
executionStep: context.currentStep,
|
|
546
|
-
timestamp: new Date().toISOString()
|
|
547
|
-
});
|
|
548
|
-
return {
|
|
549
|
-
stepId: config.id,
|
|
550
|
-
success: true,
|
|
551
|
-
output: { logged: true, logLevel: level },
|
|
552
|
-
executionTime: 0
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* Create a workflow from configuration
|
|
559
|
-
*/
|
|
560
|
-
function createWorkflow(config) {
|
|
561
|
-
return new Workflow(config);
|
|
562
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { OpenAIMessage, OpenAITool, ToolResult, CodeboltAPI } from "./types/libFunctionTypes";
|
|
2
|
-
/**
|
|
3
|
-
* Builds follow-up prompts for continuing conversations with tool results.
|
|
4
|
-
* Manages conversation history and summarization when conversations get too long.
|
|
5
|
-
*/
|
|
6
|
-
declare class FollowUpPromptBuilder {
|
|
7
|
-
/** Previous conversation messages */
|
|
8
|
-
private previousConversation;
|
|
9
|
-
/** Tool results to add to the conversation */
|
|
10
|
-
private toolResults;
|
|
11
|
-
/** Available tools for the conversation */
|
|
12
|
-
private tools;
|
|
13
|
-
/** The last LLM response, if available */
|
|
14
|
-
private llmResponse?;
|
|
15
|
-
/** Maximum conversation length before summarization */
|
|
16
|
-
private maxConversationLength;
|
|
17
|
-
/** Whether to force summarization */
|
|
18
|
-
private forceSummarization;
|
|
19
|
-
/** Codebolt API instance */
|
|
20
|
-
private codebolt?;
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new FollowUpQuestionBuilder instance.
|
|
23
|
-
*
|
|
24
|
-
* @param codebolt - Optional codebolt API instance
|
|
25
|
-
*/
|
|
26
|
-
constructor(codebolt?: CodeboltAPI);
|
|
27
|
-
/**
|
|
28
|
-
* Adds the previous conversation to the builder.
|
|
29
|
-
*
|
|
30
|
-
* @param previousPrompt - The previous prompt object containing messages and tools
|
|
31
|
-
* @returns The FollowUpQuestionBuilder instance for chaining
|
|
32
|
-
*/
|
|
33
|
-
addPreviousConversation(previousPrompt: {
|
|
34
|
-
messages: OpenAIMessage[];
|
|
35
|
-
tools: OpenAITool[];
|
|
36
|
-
tool_choice?: string;
|
|
37
|
-
}, llmResponse: {
|
|
38
|
-
completion: any;
|
|
39
|
-
}): this;
|
|
40
|
-
addLLMResponseToConverstaion(llmResponse: {
|
|
41
|
-
completion: any;
|
|
42
|
-
}): this;
|
|
43
|
-
/**
|
|
44
|
-
* Adds tool execution results to the conversation.
|
|
45
|
-
*
|
|
46
|
-
* @param toolResults - Array of tool execution results
|
|
47
|
-
* @returns The FollowUpQuestionBuilder instance for chaining
|
|
48
|
-
*/
|
|
49
|
-
addToolResult(toolResults: ToolResult[]): this;
|
|
50
|
-
/**
|
|
51
|
-
* Checks if the conversation is too long and sets up summarization with custom max length.
|
|
52
|
-
*
|
|
53
|
-
* @param maxLength - Maximum number of messages before summarization
|
|
54
|
-
* @returns The FollowUpQuestionBuilder instance for chaining
|
|
55
|
-
*/
|
|
56
|
-
checkAndSummarizeConversationIfLong(maxLength: number): this;
|
|
57
|
-
/**
|
|
58
|
-
* Performs conversation summarization if needed.
|
|
59
|
-
*
|
|
60
|
-
* @returns Promise that resolves to the summarized messages
|
|
61
|
-
*/
|
|
62
|
-
private performSummarization;
|
|
63
|
-
/**
|
|
64
|
-
* Builds the follow-up conversation prompt with tool results.
|
|
65
|
-
*
|
|
66
|
-
* @returns Promise that resolves to the conversation prompt object
|
|
67
|
-
*/
|
|
68
|
-
build(): Promise<{
|
|
69
|
-
messages: OpenAIMessage[];
|
|
70
|
-
tools: OpenAITool[];
|
|
71
|
-
tool_choice: "auto";
|
|
72
|
-
full: boolean;
|
|
73
|
-
}>;
|
|
74
|
-
}
|
|
75
|
-
export { FollowUpPromptBuilder };
|