crewai-ts
Version:
TypeScript port of crewAI for agent-based workflows
6 lines • 2.89 kB
TypeScript
/**
* Flow template for the CLI's create-flow command
* Performance-optimized with proper TypeScript types
*/
export declare const flowTemplate = "/**\n * {{FlowName}} - A Flow for orchestrating tasks\n * Created with CrewAI CLI\n */\nimport { Flow, FlowState } from 'crewai-ts/flow';\nimport { start, listen, router, or_, and_ } from 'crewai-ts/flow/decorators';\nimport { CONTINUE, STOP } from 'crewai-ts/flow/types';\n\n/**\n * State definition for {{FlowName}}\n */\nexport class {{FlowName}}State extends FlowState {\n // Define your flow state properties here\n progress: number = 0;\n startTime: number = 0;\n endTime: number = 0;\n completed: boolean = false;\n results: any = null;\n errors: string[] = [];\n}\n\n/**\n * {{FlowDescription}}\n */\nexport class {{FlowName}} extends Flow<{{FlowName}}State> {\n constructor(options: any = {}) {\n super({\n initialState: new {{FlowName}}State(),\n // Add any custom flow options here\n });\n }\n \n /**\n * Flow entry point - begins execution\n */\n @start()\n async begin() {\n console.log('Starting {{FlowName}} flow');\n this.state.startTime = Date.now();\n this.state.progress = 10;\n \n // Your flow initialization logic here\n \n return CONTINUE;\n }\n \n /**\n * Process the main flow logic\n * Triggered when 'begin' completes successfully\n */\n @listen('begin')\n async process() {\n console.log('Processing {{FlowName}} flow');\n this.state.progress = 50;\n \n try {\n // Your main flow logic here\n \n // Example: set results to flow state\n this.state.results = { success: true, data: 'Processing complete' };\n this.state.progress = 90;\n \n return this.state.results;\n } catch (error) {\n this.state.errors.push(`Processing error: ${error.message}`);\n return STOP;\n }\n }\n \n /**\n * Complete the flow and provide results\n * Triggered when 'process' completes successfully\n */\n @listen('process')\n async complete(processResult: any) {\n console.log('Completing {{FlowName}} flow');\n \n // Record completion metrics\n this.state.endTime = Date.now();\n this.state.completed = true;\n this.state.progress = 100;\n \n const executionTime = (this.state.endTime - this.state.startTime) / 1000;\n console.log(`Flow completed in ${executionTime.toFixed(2)} seconds`);\n \n return processResult;\n }\n \n /**\n * Handle any errors that occur during flow execution\n */\n @listen(or_('begin', 'process'))\n async handleError() {\n console.error('Error in {{FlowName}} flow:', this.state.errors);\n \n // Always mark as complete even on error\n this.state.endTime = Date.now();\n this.state.progress = 100;\n \n return { success: false, errors: this.state.errors };\n }\n}";
//# sourceMappingURL=flow.template.d.ts.map