@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,223 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Example demonstrating CodeBolt backend storage for ComposableAgent
|
|
4
|
-
* @description Shows how to use CodeBolt's state and memory functions instead of SQLite
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.knowledgeAgentWithDbStorage = exports.taskAgentWithProjectStorage = exports.weatherAgentWithAgentStorage = void 0;
|
|
11
|
-
exports.setupCodeBoltStorageExample = setupCodeBoltStorageExample;
|
|
12
|
-
exports.createCustomStorageAgent = createCustomStorageAgent;
|
|
13
|
-
exports.setupMultiStorageAgents = setupMultiStorageAgents;
|
|
14
|
-
exports.storageComparison = storageComparison;
|
|
15
|
-
const index_1 = require("../index");
|
|
16
|
-
const zod_1 = require("zod");
|
|
17
|
-
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
18
|
-
/**
|
|
19
|
-
* Example: Weather Agent with CodeBolt Agent State Storage
|
|
20
|
-
* Data is stored in CodeBolt's agent state backend
|
|
21
|
-
*/
|
|
22
|
-
exports.weatherAgentWithAgentStorage = new index_1.ComposableAgent({
|
|
23
|
-
name: 'Weather Agent',
|
|
24
|
-
instructions: `
|
|
25
|
-
You are a helpful weather assistant that provides accurate weather information.
|
|
26
|
-
Always ask for a location if none is provided.
|
|
27
|
-
Keep responses concise but informative.
|
|
28
|
-
`,
|
|
29
|
-
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
30
|
-
tools: {
|
|
31
|
-
weatherTool: (0, index_1.createTool)({
|
|
32
|
-
id: 'get-weather',
|
|
33
|
-
description: 'Get current weather for a location',
|
|
34
|
-
inputSchema: zod_1.z.object({
|
|
35
|
-
location: zod_1.z.string().describe('City name'),
|
|
36
|
-
}),
|
|
37
|
-
outputSchema: zod_1.z.object({
|
|
38
|
-
temperature: zod_1.z.number(),
|
|
39
|
-
conditions: zod_1.z.string(),
|
|
40
|
-
location: zod_1.z.string(),
|
|
41
|
-
}),
|
|
42
|
-
execute: async ({ context }) => {
|
|
43
|
-
// Mock weather data
|
|
44
|
-
return {
|
|
45
|
-
temperature: 22,
|
|
46
|
-
conditions: 'Partly cloudy',
|
|
47
|
-
location: context.location
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
})
|
|
51
|
-
},
|
|
52
|
-
// Use CodeBolt agent state for memory storage
|
|
53
|
-
memory: (0, index_1.createCodeBoltAgentMemory)('weather_agent'),
|
|
54
|
-
maxTurns: 10
|
|
55
|
-
});
|
|
56
|
-
/**
|
|
57
|
-
* Example: Task Management Agent with CodeBolt Project State Storage
|
|
58
|
-
* Data is stored in CodeBolt's project state backend
|
|
59
|
-
*/
|
|
60
|
-
exports.taskAgentWithProjectStorage = new index_1.ComposableAgent({
|
|
61
|
-
name: 'Task Manager',
|
|
62
|
-
instructions: `
|
|
63
|
-
You are a task management assistant that helps users organize their work.
|
|
64
|
-
You can create, list, update, and complete tasks.
|
|
65
|
-
Keep track of task status and priorities.
|
|
66
|
-
`,
|
|
67
|
-
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
68
|
-
tools: {
|
|
69
|
-
createTaskTool: (0, index_1.createTool)({
|
|
70
|
-
id: 'create-task',
|
|
71
|
-
description: 'Create a new task',
|
|
72
|
-
inputSchema: zod_1.z.object({
|
|
73
|
-
title: zod_1.z.string().describe('Task title'),
|
|
74
|
-
description: zod_1.z.string().optional().describe('Task description'),
|
|
75
|
-
priority: zod_1.z.enum(['low', 'medium', 'high']).default('medium'),
|
|
76
|
-
}),
|
|
77
|
-
outputSchema: zod_1.z.object({
|
|
78
|
-
taskId: zod_1.z.string(),
|
|
79
|
-
title: zod_1.z.string(),
|
|
80
|
-
status: zod_1.z.string(),
|
|
81
|
-
}),
|
|
82
|
-
execute: async ({ context }) => {
|
|
83
|
-
const taskId = `task_${Date.now()}`;
|
|
84
|
-
return {
|
|
85
|
-
taskId,
|
|
86
|
-
title: context.title,
|
|
87
|
-
status: 'created'
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
})
|
|
91
|
-
},
|
|
92
|
-
// Use CodeBolt project state for memory storage
|
|
93
|
-
memory: (0, index_1.createCodeBoltProjectMemory)('task_agent'),
|
|
94
|
-
maxTurns: 15
|
|
95
|
-
});
|
|
96
|
-
/**
|
|
97
|
-
* Example: Knowledge Agent with CodeBolt Memory Database Storage
|
|
98
|
-
* Data is stored in CodeBolt's in-memory database backend
|
|
99
|
-
*/
|
|
100
|
-
exports.knowledgeAgentWithDbStorage = new index_1.ComposableAgent({
|
|
101
|
-
name: 'Knowledge Assistant',
|
|
102
|
-
instructions: `
|
|
103
|
-
You are a knowledge management assistant that helps users store and retrieve information.
|
|
104
|
-
You can save facts, remember conversations, and answer questions based on stored knowledge.
|
|
105
|
-
`,
|
|
106
|
-
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
107
|
-
tools: {
|
|
108
|
-
saveKnowledgeTool: (0, index_1.createTool)({
|
|
109
|
-
id: 'save-knowledge',
|
|
110
|
-
description: 'Save a piece of knowledge',
|
|
111
|
-
inputSchema: zod_1.z.object({
|
|
112
|
-
topic: zod_1.z.string().describe('Knowledge topic'),
|
|
113
|
-
content: zod_1.z.string().describe('Knowledge content'),
|
|
114
|
-
tags: zod_1.z.array(zod_1.z.string()).optional().describe('Optional tags'),
|
|
115
|
-
}),
|
|
116
|
-
outputSchema: zod_1.z.object({
|
|
117
|
-
success: zod_1.z.boolean(),
|
|
118
|
-
knowledgeId: zod_1.z.string(),
|
|
119
|
-
}),
|
|
120
|
-
execute: async ({ context }) => {
|
|
121
|
-
const knowledgeId = `knowledge_${Date.now()}`;
|
|
122
|
-
return {
|
|
123
|
-
success: true,
|
|
124
|
-
knowledgeId
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
})
|
|
128
|
-
},
|
|
129
|
-
// Use CodeBolt memory database for storage
|
|
130
|
-
memory: (0, index_1.createCodeBoltDbMemory)('knowledge_agent'),
|
|
131
|
-
maxTurns: 20
|
|
132
|
-
});
|
|
133
|
-
/**
|
|
134
|
-
* Example usage within CodeBolt onMessage
|
|
135
|
-
*/
|
|
136
|
-
function setupCodeBoltStorageExample() {
|
|
137
|
-
codeboltjs_1.default.onMessage(async (reqMessage) => {
|
|
138
|
-
try {
|
|
139
|
-
// Example 1: Weather agent with agent state storage
|
|
140
|
-
if (reqMessage.userMessage.includes('weather')) {
|
|
141
|
-
const result = await exports.weatherAgentWithAgentStorage.run();
|
|
142
|
-
return result.message;
|
|
143
|
-
}
|
|
144
|
-
// Example 2: Task agent with project state storage
|
|
145
|
-
if (reqMessage.userMessage.includes('task')) {
|
|
146
|
-
const result = await exports.taskAgentWithProjectStorage.run();
|
|
147
|
-
return result.message;
|
|
148
|
-
}
|
|
149
|
-
// Example 3: Knowledge agent with memory database storage
|
|
150
|
-
if (reqMessage.userMessage.includes('knowledge') || reqMessage.userMessage.includes('remember')) {
|
|
151
|
-
const result = await exports.knowledgeAgentWithDbStorage.run();
|
|
152
|
-
return result.message;
|
|
153
|
-
}
|
|
154
|
-
return 'Please specify what you need help with: weather, tasks, or knowledge management.';
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
console.error('Agent execution error:', error);
|
|
158
|
-
return 'Sorry, I encountered an error while processing your request.';
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Example: Custom storage configuration
|
|
164
|
-
*/
|
|
165
|
-
function createCustomStorageAgent() {
|
|
166
|
-
return new index_1.ComposableAgent({
|
|
167
|
-
name: 'Custom Storage Agent',
|
|
168
|
-
instructions: 'I use custom storage prefixes to avoid conflicts.',
|
|
169
|
-
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
170
|
-
// Use custom prefix to avoid storage conflicts
|
|
171
|
-
memory: (0, index_1.createCodeBoltAgentMemory)('my_app_agent_v2'),
|
|
172
|
-
maxTurns: 10
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Example: Multiple agents with different storage backends
|
|
177
|
-
*/
|
|
178
|
-
function setupMultiStorageAgents() {
|
|
179
|
-
const sessionAgent = new index_1.ComposableAgent({
|
|
180
|
-
name: 'Session Agent',
|
|
181
|
-
instructions: 'I handle session-specific data.',
|
|
182
|
-
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
183
|
-
// Session data stored in agent state
|
|
184
|
-
memory: (0, index_1.createCodeBoltAgentMemory)('session'),
|
|
185
|
-
});
|
|
186
|
-
const globalAgent = new index_1.ComposableAgent({
|
|
187
|
-
name: 'Global Agent',
|
|
188
|
-
instructions: 'I handle project-wide data.',
|
|
189
|
-
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
190
|
-
// Global data stored in project state
|
|
191
|
-
memory: (0, index_1.createCodeBoltProjectMemory)('global'),
|
|
192
|
-
});
|
|
193
|
-
const cacheAgent = new index_1.ComposableAgent({
|
|
194
|
-
name: 'Cache Agent',
|
|
195
|
-
instructions: 'I handle temporary cached data.',
|
|
196
|
-
model: 'gpt-4o-mini', // References configuration in codeboltagents.yaml
|
|
197
|
-
// Cache data stored in memory database
|
|
198
|
-
memory: (0, index_1.createCodeBoltDbMemory)('cache'),
|
|
199
|
-
});
|
|
200
|
-
return { sessionAgent, globalAgent, cacheAgent };
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Storage comparison and migration helper
|
|
204
|
-
*/
|
|
205
|
-
async function storageComparison() {
|
|
206
|
-
console.log('=== CodeBolt Storage Options ===');
|
|
207
|
-
console.log('1. Agent State Storage:');
|
|
208
|
-
console.log(' - Persisted across agent sessions');
|
|
209
|
-
console.log(' - Scoped to agent/user context');
|
|
210
|
-
console.log(' - Best for: User preferences, agent settings');
|
|
211
|
-
console.log('2. Project State Storage:');
|
|
212
|
-
console.log(' - Persisted across project sessions');
|
|
213
|
-
console.log(' - Scoped to current project');
|
|
214
|
-
console.log(' - Best for: Project-specific data, global settings');
|
|
215
|
-
console.log('3. Memory Database Storage:');
|
|
216
|
-
console.log(' - Fast in-memory access');
|
|
217
|
-
console.log(' - May not persist across restarts');
|
|
218
|
-
console.log(' - Best for: Temporary data, caching, session data');
|
|
219
|
-
console.log('4. Migration from SQLite:');
|
|
220
|
-
console.log(' - No need for external database dependencies');
|
|
221
|
-
console.log(' - Seamless integration with CodeBolt ecosystem');
|
|
222
|
-
console.log(' - Automatic backup and sync (if supported by CodeBolt)');
|
|
223
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Custom Step Creation Examples
|
|
3
|
-
* @description Examples showing how to create custom workflow steps with your own logic
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* E-commerce order processing workflow
|
|
7
|
-
*/
|
|
8
|
-
export declare const orderProcessingWorkflow: import("../workflow").Workflow;
|
|
9
|
-
/**
|
|
10
|
-
* Data analysis workflow
|
|
11
|
-
*/
|
|
12
|
-
export declare const dataAnalysisWorkflow: import("../workflow").Workflow;
|
|
13
|
-
/**
|
|
14
|
-
* Text processing workflow
|
|
15
|
-
*/
|
|
16
|
-
export declare const textProcessingWorkflow: import("../workflow").Workflow;
|
|
17
|
-
export declare function runOrderProcessingExample(): Promise<import("../workflow").WorkflowResult>;
|
|
18
|
-
export declare function runDataAnalysisExample(): Promise<import("../workflow").WorkflowResult>;
|
|
19
|
-
export declare function runTextProcessingExample(): Promise<import("../workflow").WorkflowResult>;
|
|
20
|
-
export declare function runAllCustomStepExamples(): Promise<void>;
|
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Custom Step Creation Examples
|
|
4
|
-
* @description Examples showing how to create custom workflow steps with your own logic
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.textProcessingWorkflow = exports.dataAnalysisWorkflow = exports.orderProcessingWorkflow = void 0;
|
|
8
|
-
exports.runOrderProcessingExample = runOrderProcessingExample;
|
|
9
|
-
exports.runDataAnalysisExample = runDataAnalysisExample;
|
|
10
|
-
exports.runTextProcessingExample = runTextProcessingExample;
|
|
11
|
-
exports.runAllCustomStepExamples = runAllCustomStepExamples;
|
|
12
|
-
const index_1 = require("../index");
|
|
13
|
-
// ================================
|
|
14
|
-
// Basic Custom Step Examples
|
|
15
|
-
// ================================
|
|
16
|
-
/**
|
|
17
|
-
* Example: Simple math calculation step
|
|
18
|
-
*/
|
|
19
|
-
const mathStep = (0, index_1.createSimpleStep)({
|
|
20
|
-
id: 'calculate-total',
|
|
21
|
-
name: 'Calculate Order Total',
|
|
22
|
-
description: 'Calculate total price with tax and shipping',
|
|
23
|
-
inputSchema: index_1.z.object({
|
|
24
|
-
items: index_1.z.array(index_1.z.object({
|
|
25
|
-
price: index_1.z.number(),
|
|
26
|
-
quantity: index_1.z.number()
|
|
27
|
-
})),
|
|
28
|
-
taxRate: index_1.z.number().default(0.08),
|
|
29
|
-
shippingCost: index_1.z.number().default(10)
|
|
30
|
-
}),
|
|
31
|
-
execute: (data) => {
|
|
32
|
-
const subtotal = data.items.reduce((sum, item) => sum + (item.price * item.quantity), 0);
|
|
33
|
-
const tax = subtotal * data.taxRate;
|
|
34
|
-
const total = subtotal + tax + data.shippingCost;
|
|
35
|
-
return {
|
|
36
|
-
subtotal,
|
|
37
|
-
tax,
|
|
38
|
-
shipping: data.shippingCost,
|
|
39
|
-
total,
|
|
40
|
-
itemCount: data.items.length
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
/**
|
|
45
|
-
* Example: String processing step
|
|
46
|
-
*/
|
|
47
|
-
const textProcessingStep = (0, index_1.createSimpleStep)({
|
|
48
|
-
id: 'process-text',
|
|
49
|
-
name: 'Process Text Data',
|
|
50
|
-
execute: (data) => {
|
|
51
|
-
const text = data.rawText || '';
|
|
52
|
-
return {
|
|
53
|
-
processedText: text.toLowerCase().trim(),
|
|
54
|
-
wordCount: text.split(/\s+/).filter((w) => w.length > 0).length,
|
|
55
|
-
characterCount: text.length,
|
|
56
|
-
sentences: text.split(/[.!?]+/).filter((s) => s.trim().length > 0).length,
|
|
57
|
-
containsEmail: /\S+@\S+\.\S+/.test(text),
|
|
58
|
-
containsPhone: /\d{3}-\d{3}-\d{4}/.test(text)
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
/**
|
|
63
|
-
* Example: Async API call step
|
|
64
|
-
*/
|
|
65
|
-
const fetchDataStep = (0, index_1.createAsyncStep)({
|
|
66
|
-
id: 'fetch-user-data',
|
|
67
|
-
name: 'Fetch User Information',
|
|
68
|
-
description: 'Fetch user data from external API',
|
|
69
|
-
retry: {
|
|
70
|
-
maxAttempts: 3,
|
|
71
|
-
delay: 1000,
|
|
72
|
-
backoff: 'exponential'
|
|
73
|
-
},
|
|
74
|
-
execute: async (data, context) => {
|
|
75
|
-
// Simulate API call
|
|
76
|
-
const userId = data.userId;
|
|
77
|
-
// Mock API response (in real usage, this would be an actual fetch call)
|
|
78
|
-
await new Promise(resolve => setTimeout(resolve, 500)); // Simulate network delay
|
|
79
|
-
const userData = {
|
|
80
|
-
id: userId,
|
|
81
|
-
name: 'John Doe',
|
|
82
|
-
email: 'john.doe@example.com',
|
|
83
|
-
preferences: {
|
|
84
|
-
theme: 'dark',
|
|
85
|
-
notifications: true
|
|
86
|
-
},
|
|
87
|
-
lastLogin: new Date().toISOString()
|
|
88
|
-
};
|
|
89
|
-
return { userData };
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
/**
|
|
93
|
-
* Example: Advanced custom step with full control
|
|
94
|
-
*/
|
|
95
|
-
const advancedProcessingStep = (0, index_1.createStep)({
|
|
96
|
-
id: 'advanced-processing',
|
|
97
|
-
name: 'Advanced Data Processing',
|
|
98
|
-
description: 'Complex data processing with validation and error handling',
|
|
99
|
-
inputSchema: index_1.z.object({
|
|
100
|
-
dataset: index_1.z.array(index_1.z.record(index_1.z.any())),
|
|
101
|
-
processingOptions: index_1.z.object({
|
|
102
|
-
filterBy: index_1.z.string().optional(),
|
|
103
|
-
sortBy: index_1.z.string().optional(),
|
|
104
|
-
groupBy: index_1.z.string().optional()
|
|
105
|
-
}).optional()
|
|
106
|
-
}),
|
|
107
|
-
execute: async (context) => {
|
|
108
|
-
const { dataset, processingOptions = {} } = context.data;
|
|
109
|
-
try {
|
|
110
|
-
let processedData = [...dataset];
|
|
111
|
-
// Apply filtering
|
|
112
|
-
if (processingOptions.filterBy) {
|
|
113
|
-
processedData = processedData.filter(item => item[processingOptions.filterBy] !== undefined);
|
|
114
|
-
}
|
|
115
|
-
// Apply sorting
|
|
116
|
-
if (processingOptions.sortBy) {
|
|
117
|
-
processedData.sort((a, b) => {
|
|
118
|
-
const aVal = a[processingOptions.sortBy];
|
|
119
|
-
const bVal = b[processingOptions.sortBy];
|
|
120
|
-
return aVal > bVal ? 1 : aVal < bVal ? -1 : 0;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
// Apply grouping
|
|
124
|
-
let groupedData = null;
|
|
125
|
-
if (processingOptions.groupBy) {
|
|
126
|
-
groupedData = processedData.reduce((groups, item) => {
|
|
127
|
-
const key = item[processingOptions.groupBy];
|
|
128
|
-
if (!groups[key])
|
|
129
|
-
groups[key] = [];
|
|
130
|
-
groups[key].push(item);
|
|
131
|
-
return groups;
|
|
132
|
-
}, {});
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
stepId: 'advanced-processing',
|
|
136
|
-
success: true,
|
|
137
|
-
output: {
|
|
138
|
-
processedData,
|
|
139
|
-
groupedData,
|
|
140
|
-
statistics: {
|
|
141
|
-
originalCount: dataset.length,
|
|
142
|
-
processedCount: processedData.length,
|
|
143
|
-
processingOptions
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
executionTime: 0
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
return {
|
|
151
|
-
stepId: 'advanced-processing',
|
|
152
|
-
success: false,
|
|
153
|
-
error: error instanceof Error ? error.message : String(error),
|
|
154
|
-
executionTime: 0
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
/**
|
|
160
|
-
* Example: Conditional step based on data
|
|
161
|
-
*/
|
|
162
|
-
const conditionalStep = (0, index_1.createStep)({
|
|
163
|
-
id: 'conditional-logic',
|
|
164
|
-
name: 'Conditional Processing',
|
|
165
|
-
condition: (context) => context.data.shouldProcess === true,
|
|
166
|
-
execute: async (context) => {
|
|
167
|
-
const processingType = context.data.processingType || 'default';
|
|
168
|
-
let result;
|
|
169
|
-
switch (processingType) {
|
|
170
|
-
case 'fast':
|
|
171
|
-
result = { processed: true, method: 'fast', duration: 100 };
|
|
172
|
-
break;
|
|
173
|
-
case 'thorough':
|
|
174
|
-
result = { processed: true, method: 'thorough', duration: 500 };
|
|
175
|
-
break;
|
|
176
|
-
default:
|
|
177
|
-
result = { processed: true, method: 'default', duration: 200 };
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
stepId: 'conditional-logic',
|
|
181
|
-
success: true,
|
|
182
|
-
output: result,
|
|
183
|
-
executionTime: 0
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
// ================================
|
|
188
|
-
// Workflow Examples Using Custom Steps
|
|
189
|
-
// ================================
|
|
190
|
-
/**
|
|
191
|
-
* E-commerce order processing workflow
|
|
192
|
-
*/
|
|
193
|
-
exports.orderProcessingWorkflow = (0, index_1.createWorkflow)({
|
|
194
|
-
name: 'Order Processing Pipeline',
|
|
195
|
-
description: 'Process e-commerce orders with calculations, validation, and data fetching',
|
|
196
|
-
initialData: {
|
|
197
|
-
orderId: 'ORD-12345',
|
|
198
|
-
userId: 'USER-789',
|
|
199
|
-
items: [
|
|
200
|
-
{ price: 29.99, quantity: 2 },
|
|
201
|
-
{ price: 15.50, quantity: 1 }
|
|
202
|
-
],
|
|
203
|
-
taxRate: 0.08,
|
|
204
|
-
shippingCost: 10
|
|
205
|
-
},
|
|
206
|
-
steps: [
|
|
207
|
-
// Step 1: Log the start
|
|
208
|
-
(0, index_1.createLoggingStep)({
|
|
209
|
-
id: 'log-start',
|
|
210
|
-
name: 'Log Order Start',
|
|
211
|
-
level: 'info',
|
|
212
|
-
message: 'Starting order processing',
|
|
213
|
-
fields: ['orderId', 'userId']
|
|
214
|
-
}),
|
|
215
|
-
// Step 2: Validate order data
|
|
216
|
-
(0, index_1.createValidationStep)({
|
|
217
|
-
id: 'validate-order',
|
|
218
|
-
name: 'Validate Order',
|
|
219
|
-
schema: index_1.z.object({
|
|
220
|
-
orderId: index_1.z.string(),
|
|
221
|
-
userId: index_1.z.string(),
|
|
222
|
-
items: index_1.z.array(index_1.z.object({
|
|
223
|
-
price: index_1.z.number().positive(),
|
|
224
|
-
quantity: index_1.z.number().int().positive()
|
|
225
|
-
})).min(1)
|
|
226
|
-
}),
|
|
227
|
-
stopOnFailure: true
|
|
228
|
-
}),
|
|
229
|
-
// Step 3: Calculate totals
|
|
230
|
-
mathStep,
|
|
231
|
-
// Step 4: Fetch user data (parallel with calculations)
|
|
232
|
-
fetchDataStep,
|
|
233
|
-
// Step 5: Process order summary
|
|
234
|
-
(0, index_1.createSimpleStep)({
|
|
235
|
-
id: 'create-summary',
|
|
236
|
-
name: 'Create Order Summary',
|
|
237
|
-
dependencies: ['calculate-total', 'fetch-user-data'],
|
|
238
|
-
execute: (data) => ({
|
|
239
|
-
orderSummary: {
|
|
240
|
-
orderId: data.orderId,
|
|
241
|
-
customer: data.userData,
|
|
242
|
-
billing: {
|
|
243
|
-
subtotal: data.subtotal,
|
|
244
|
-
tax: data.tax,
|
|
245
|
-
shipping: data.shipping,
|
|
246
|
-
total: data.total
|
|
247
|
-
},
|
|
248
|
-
items: data.items,
|
|
249
|
-
processedAt: new Date().toISOString()
|
|
250
|
-
}
|
|
251
|
-
})
|
|
252
|
-
}),
|
|
253
|
-
// Step 6: Log completion
|
|
254
|
-
(0, index_1.createLoggingStep)({
|
|
255
|
-
id: 'log-completion',
|
|
256
|
-
name: 'Log Order Completion',
|
|
257
|
-
level: 'info',
|
|
258
|
-
message: 'Order processing completed',
|
|
259
|
-
fields: ['orderId', 'total']
|
|
260
|
-
})
|
|
261
|
-
]
|
|
262
|
-
});
|
|
263
|
-
/**
|
|
264
|
-
* Data analysis workflow
|
|
265
|
-
*/
|
|
266
|
-
exports.dataAnalysisWorkflow = (0, index_1.createWorkflow)({
|
|
267
|
-
name: 'Data Analysis Pipeline',
|
|
268
|
-
description: 'Analyze dataset with preprocessing, validation, and statistics',
|
|
269
|
-
initialData: {
|
|
270
|
-
dataset: [
|
|
271
|
-
{ id: 1, name: 'Alice', age: 25, department: 'Engineering' },
|
|
272
|
-
{ id: 2, name: 'Bob', age: 30, department: 'Marketing' },
|
|
273
|
-
{ id: 3, name: 'Charlie', age: 35, department: 'Engineering' },
|
|
274
|
-
{ id: 4, name: 'Diana', age: 28, department: 'Sales' }
|
|
275
|
-
],
|
|
276
|
-
processingOptions: {
|
|
277
|
-
sortBy: 'age',
|
|
278
|
-
groupBy: 'department'
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
steps: [
|
|
282
|
-
// Step 1: Validate dataset
|
|
283
|
-
(0, index_1.createValidationStep)({
|
|
284
|
-
id: 'validate-dataset',
|
|
285
|
-
name: 'Validate Dataset',
|
|
286
|
-
field: 'dataset',
|
|
287
|
-
schema: index_1.z.array(index_1.z.object({
|
|
288
|
-
id: index_1.z.number(),
|
|
289
|
-
name: index_1.z.string(),
|
|
290
|
-
age: index_1.z.number(),
|
|
291
|
-
department: index_1.z.string()
|
|
292
|
-
})).min(1)
|
|
293
|
-
}),
|
|
294
|
-
// Step 2: Advanced processing
|
|
295
|
-
advancedProcessingStep,
|
|
296
|
-
// Step 3: Calculate statistics
|
|
297
|
-
(0, index_1.createSimpleStep)({
|
|
298
|
-
id: 'calculate-stats',
|
|
299
|
-
name: 'Calculate Statistics',
|
|
300
|
-
execute: (data) => {
|
|
301
|
-
const dataset = data.processedData;
|
|
302
|
-
const ages = dataset.map((item) => item.age);
|
|
303
|
-
return {
|
|
304
|
-
statistics: {
|
|
305
|
-
totalRecords: dataset.length,
|
|
306
|
-
averageAge: ages.reduce((sum, age) => sum + age, 0) / ages.length,
|
|
307
|
-
minAge: Math.min(...ages),
|
|
308
|
-
maxAge: Math.max(...ages),
|
|
309
|
-
departments: [...new Set(dataset.map((item) => item.department))],
|
|
310
|
-
groupSizes: Object.entries(data.groupedData || {}).map(([dept, items]) => ({
|
|
311
|
-
department: dept,
|
|
312
|
-
count: items.length
|
|
313
|
-
}))
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
}),
|
|
318
|
-
// Step 4: Generate report
|
|
319
|
-
(0, index_1.createSimpleStep)({
|
|
320
|
-
id: 'generate-report',
|
|
321
|
-
name: 'Generate Analysis Report',
|
|
322
|
-
execute: (data) => ({
|
|
323
|
-
report: {
|
|
324
|
-
summary: `Analyzed ${data.statistics.totalRecords} records`,
|
|
325
|
-
demographics: {
|
|
326
|
-
averageAge: data.statistics.averageAge,
|
|
327
|
-
ageRange: `${data.statistics.minAge} - ${data.statistics.maxAge}`
|
|
328
|
-
},
|
|
329
|
-
departments: data.statistics.departments,
|
|
330
|
-
groupBreakdown: data.statistics.groupSizes,
|
|
331
|
-
generatedAt: new Date().toISOString()
|
|
332
|
-
}
|
|
333
|
-
})
|
|
334
|
-
})
|
|
335
|
-
]
|
|
336
|
-
});
|
|
337
|
-
/**
|
|
338
|
-
* Text processing workflow
|
|
339
|
-
*/
|
|
340
|
-
exports.textProcessingWorkflow = (0, index_1.createWorkflow)({
|
|
341
|
-
name: 'Text Processing Pipeline',
|
|
342
|
-
description: 'Process and analyze text content',
|
|
343
|
-
initialData: {
|
|
344
|
-
rawText: `
|
|
345
|
-
Hello! My name is John Doe. You can reach me at john.doe@example.com
|
|
346
|
-
or call me at 555-123-4567. I'm excited to work with your team on this
|
|
347
|
-
new project. We have three main goals: improve efficiency, reduce costs,
|
|
348
|
-
and enhance user experience.
|
|
349
|
-
`,
|
|
350
|
-
shouldProcess: true,
|
|
351
|
-
processingType: 'thorough'
|
|
352
|
-
},
|
|
353
|
-
steps: [
|
|
354
|
-
// Step 1: Basic text processing
|
|
355
|
-
textProcessingStep,
|
|
356
|
-
// Step 2: Conditional advanced processing
|
|
357
|
-
conditionalStep,
|
|
358
|
-
// Step 3: Extract entities
|
|
359
|
-
(0, index_1.createSimpleStep)({
|
|
360
|
-
id: 'extract-entities',
|
|
361
|
-
name: 'Extract Entities',
|
|
362
|
-
execute: (data) => {
|
|
363
|
-
const text = data.processedText || data.rawText;
|
|
364
|
-
// Simple entity extraction (in real usage, you might use NLP libraries)
|
|
365
|
-
const emails = text.match(/\S+@\S+\.\S+/g) || [];
|
|
366
|
-
const phones = text.match(/\d{3}-\d{3}-\d{4}/g) || [];
|
|
367
|
-
const names = text.match(/[A-Z][a-z]+ [A-Z][a-z]+/g) || [];
|
|
368
|
-
return {
|
|
369
|
-
entities: {
|
|
370
|
-
emails,
|
|
371
|
-
phones,
|
|
372
|
-
names,
|
|
373
|
-
total: emails.length + phones.length + names.length
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
}),
|
|
378
|
-
// Step 4: Create analysis summary
|
|
379
|
-
(0, index_1.createSimpleStep)({
|
|
380
|
-
id: 'create-text-summary',
|
|
381
|
-
name: 'Create Text Analysis Summary',
|
|
382
|
-
execute: (data) => ({
|
|
383
|
-
textAnalysis: {
|
|
384
|
-
content: {
|
|
385
|
-
wordCount: data.wordCount,
|
|
386
|
-
characterCount: data.characterCount,
|
|
387
|
-
sentences: data.sentences
|
|
388
|
-
},
|
|
389
|
-
entities: data.entities,
|
|
390
|
-
processingMethod: data.method || 'none',
|
|
391
|
-
containsPersonalInfo: data.containsEmail || data.containsPhone,
|
|
392
|
-
analysisScore: Math.min(10, (data.wordCount / 10) + data.entities.total)
|
|
393
|
-
}
|
|
394
|
-
})
|
|
395
|
-
})
|
|
396
|
-
]
|
|
397
|
-
});
|
|
398
|
-
// ================================
|
|
399
|
-
// Example Usage Functions
|
|
400
|
-
// ================================
|
|
401
|
-
async function runOrderProcessingExample() {
|
|
402
|
-
console.log('Running order processing workflow...');
|
|
403
|
-
const result = await exports.orderProcessingWorkflow.execute();
|
|
404
|
-
if (result.success) {
|
|
405
|
-
console.log('Order processed successfully!');
|
|
406
|
-
console.log('Order summary:', result.data.orderSummary);
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
console.error('Order processing failed:', result.error);
|
|
410
|
-
}
|
|
411
|
-
return result;
|
|
412
|
-
}
|
|
413
|
-
async function runDataAnalysisExample() {
|
|
414
|
-
console.log('Running data analysis workflow...');
|
|
415
|
-
const result = await exports.dataAnalysisWorkflow.execute();
|
|
416
|
-
if (result.success) {
|
|
417
|
-
console.log('Data analysis completed!');
|
|
418
|
-
console.log('Report:', result.data.report);
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
console.error('Data analysis failed:', result.error);
|
|
422
|
-
}
|
|
423
|
-
return result;
|
|
424
|
-
}
|
|
425
|
-
async function runTextProcessingExample() {
|
|
426
|
-
console.log('Running text processing workflow...');
|
|
427
|
-
const result = await exports.textProcessingWorkflow.execute();
|
|
428
|
-
if (result.success) {
|
|
429
|
-
console.log('Text processing completed!');
|
|
430
|
-
console.log('Analysis:', result.data.textAnalysis);
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
console.error('Text processing failed:', result.error);
|
|
434
|
-
}
|
|
435
|
-
return result;
|
|
436
|
-
}
|
|
437
|
-
// Run all examples
|
|
438
|
-
async function runAllCustomStepExamples() {
|
|
439
|
-
try {
|
|
440
|
-
console.log('=== Running All Custom Step Examples ===\n');
|
|
441
|
-
await runOrderProcessingExample();
|
|
442
|
-
console.log('\n' + '='.repeat(50) + '\n');
|
|
443
|
-
await runDataAnalysisExample();
|
|
444
|
-
console.log('\n' + '='.repeat(50) + '\n');
|
|
445
|
-
await runTextProcessingExample();
|
|
446
|
-
console.log('\n=== All Custom Step Examples Completed ===');
|
|
447
|
-
}
|
|
448
|
-
catch (error) {
|
|
449
|
-
console.error('Example execution failed:', error);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
// Run examples if this file is executed directly
|
|
453
|
-
if (require.main === module) {
|
|
454
|
-
runAllCustomStepExamples().catch(console.error);
|
|
455
|
-
}
|