feat: Phase 2.2 - Implement Codegen SDK Integration#74
feat: Phase 2.2 - Implement Codegen SDK Integration#74codegen-sh[bot] wants to merge 4 commits intomainfrom
Conversation
- Automated setup script for local Postgres exposure via Cloudflare Workers - Creates dedicated database and read-only user for Codegen - Deploys Cloudflare Worker proxy with health endpoints - Saves credentials to .env file for easy integration - Includes Windows batch and PowerShell scripts for easy setup - Comprehensive testing and status reporting - Full documentation with troubleshooting guide
- Add support for multiple authentication methods - Try common default passwords automatically - Support environment variables for admin credentials - Add interactive password prompt as fallback - Update documentation with authentication troubleshooting - Handle Windows authentication scenarios
- Switch from API token to Global API Key authentication - Add support for Cloudflare email requirement - Update environment variables and batch scripts - Create specialized script with user's credentials - Fix Cloudflare Worker creation authentication
- Add comprehensive Codegen SDK client with authentication, retry logic, and circuit breaker - Implement authentication manager with secure token storage and validation - Create repository operations module for Git and file management - Add code generation services with template management and code analysis - Build orchestrator for coordinating all Codegen operations and workflows - Include TypeScript types and Zod validation schemas - Add configuration management with environment variable support - Create comprehensive example with usage patterns and best practices - Support for task execution, code review, workflow management, and event handling - Integrate with existing VoltAgent architecture and patterns Implements requirements from ZAM-841 Phase 2.2: - SDK client setup with connection pooling and interceptors - Authentication manager with token management and security - Repository operations with branch and file management - Code generation services with template and analysis capabilities - PR management integration - Event integration with orchestrator - Task coordination and workflow execution - Comprehensive error handling and retry logic - Performance monitoring and health checks
Reviewer's GuideThis PR introduces a full Codegen SDK integration in the VoltAgent framework by adding a new codegen module under packages/core/src, updating dependencies and core exports, and supplying configuration schemas, types, and an example project—enabling authenticated API calls, repository management, code generation/review, task/workflow orchestration, and robust error handling. Sequence Diagram: Task Execution Lifecycle via OrchestratorsequenceDiagram
actor User
User->>CodegenOrchestrator: executeTask(request)
alt Tasks limit reached
CodegenOrchestrator->>CodegenOrchestrator: Add to taskQueue
CodegenOrchestrator->>User: Emit task_queued event
CodegenOrchestrator->>User: Return pending task object
else Limit not reached
CodegenOrchestrator->>CodegenOrchestrator: executeTaskInternal(request)
CodegenOrchestrator->>CodegenSDKClient: createTask(request)
CodegenSDKClient->>Codegen API: POST /agents/tasks
Codegen API-->>CodegenSDKClient: taskDetails
CodegenSDKClient-->>CodegenOrchestrator: codegenTask
CodegenOrchestrator->>User: Emit task_started event
CodegenOrchestrator->>CodegenOrchestrator: monitorTask(taskId)
loop Task Monitoring
CodegenOrchestrator->>CodegenSDKClient: waitForTask(taskId)
CodegenSDKClient->>CodegenSDKClient: refreshTask(taskId)
CodegenSDKClient->>Codegen API: GET /agents/tasks/{taskId}
Codegen API-->>CodegenSDKClient: updatedTaskDetails
CodegenSDKClient-->>CodegenOrchestrator: onProgress(updatedTask)
CodegenOrchestrator->>User: Emit task_progress event
end
alt Task Completed
CodegenOrchestrator->>User: Emit task_completed event
else Task Failed
CodegenOrchestrator->>User: Emit task_failed event
end
CodegenOrchestrator->>CodegenOrchestrator: processTaskQueue()
CodegenOrchestrator-->>User: finalTask
end
Sequence Diagram: Direct Code Generation via OrchestratorsequenceDiagram
actor User
User->>CodegenOrchestrator: generateCode(request)
CodegenOrchestrator->>User: Emit code_generation_started event
CodegenOrchestrator->>CodegenCodeGeneration: generateCode(request)
CodegenCodeGeneration->>CodegenSDKClient: generateCode(request)
CodegenSDKClient->>Codegen API: POST /code/generate
Codegen API-->>CodegenSDKClient: generatedCodeResult
CodegenSDKClient-->>CodegenCodeGeneration: result
CodegenCodeGeneration-->>CodegenOrchestrator: result
alt Code Generation Successful
CodegenOrchestrator->>User: Emit code_generation_completed event
else Code Generation Failed
CodegenOrchestrator->>User: Emit code_generation_failed event
end
CodegenOrchestrator-->>User: result
Class Diagram: Codegen Service ComponentsclassDiagram
class CodegenOrchestrator {
+EventEmitter
-client: CodegenSDKClient
-authManager: CodegenAuthManager
-repositoryOps: CodegenRepositoryOps
-codeGeneration: CodegenCodeGeneration
-config: OrchestratorConfig
-activeTasks: Map
-taskQueue: CreateTaskRequest[]
+constructor(config: OrchestratorConfig)
+initialize()
+executeTask(request: CreateTaskRequest): CodegenTask
+monitorTask(taskId: string)
+generateCode(request: CodeGenerationRequest): any
+reviewCode(request: CodeReviewRequest): any
+createWorkflow(workflow: Workflow): Workflow
+executeWorkflow(workflowId: string): WorkflowExecution
+cancelTask(taskId: string)
+getStatus()
+destroy()
}
class CodegenSDKClient {
-client: AxiosInstance
-cache: NodeCache
-circuitBreaker: CircuitBreaker
-config: CodegenConfig
+constructor(config: CodegenConfig)
+validateAuth(): AuthenticationInfo
+createTask(request: CreateTaskRequest): CodegenTask
+getTask(taskId: string): CodegenTask
+cancelTask(taskId: string)
+listRepositories(): RepositoryInfo[]
+getRepository(repoId: string): RepositoryInfo
+createPullRequest(repoId: string, data: any): PullRequestInfo
+generateCode(request: CodeGenerationRequest): any
+analyzeCode(code: string, language: string): CodeAnalysisResult
+waitForTask(taskId: string, options: any): CodegenTask
+getHealthStatus()
+close()
}
class CodegenAuthManager {
-cache: NodeCache
-config: AuthConfig
+constructor(config: AuthConfig)
+storeCredentials(orgId: string, token: string): StoredCredentials
+getCredentials(orgId: string): any
+removeCredentials(orgId: string)
+validateTokenFormat(token: string): boolean
+cacheValidationResult(orgId: string, authInfo: AuthenticationInfo)
+getHealthStatus()
+destroy()
}
class CodegenRepositoryOps {
-client: CodegenSDKClient
-cache: NodeCache
-config: RepositoryConfig
+constructor(client: CodegenSDKClient, config: RepositoryConfig)
+listRepositories(): RepositoryInfo[]
+getRepository(repoId: string): RepositoryInfo
+createBranch(repoId: string, branchName: string): BranchInfo
+mergeBranches(repoId: string, options: any): GitOperationResult
+readFile(repoId: string, filePath: string): any
+writeFile(repoId: string, filePath: string, content: string): GitOperationResult
+commitChanges(repoId: string, options: any): GitOperationResult
+createPullRequest(repoId: string, options: any): PullRequestInfo
+getHealthStatus()
+destroy()
}
class CodegenCodeGeneration {
-client: CodegenSDKClient
+constructor(client: CodegenSDKClient)
+generateCode(request: CodeGenerationRequest): any
+reviewCode(request: CodeReviewRequest): any
}
CodegenOrchestrator o-- "1" CodegenSDKClient : uses
CodegenOrchestrator o-- "1" CodegenAuthManager : uses
CodegenOrchestrator o-- "1" CodegenRepositoryOps : uses
CodegenOrchestrator o-- "1" CodegenCodeGeneration : uses
CodegenRepositoryOps o-- "1" CodegenSDKClient : uses
CodegenCodeGeneration o-- "1" CodegenSDKClient : uses
Class Diagram: Core Codegen Data Structures and Configuration InterfacesclassDiagram
class CodegenConfig {
+orgId: string
+token: string
+baseURL: string
+timeout: number
+retries: number
}
class OrchestratorConfig {
<<Interface>>
+CodegenConfig
+enableEvents: boolean
+maxConcurrentTasks: number
+taskTimeout: number
}
CodegenConfig <|-- OrchestratorConfig
class CodegenTask {
<<Interface>>
+id: string
+status: TaskStatus
+prompt: string
+result: TaskResult
+error: TaskError
+createdAt: string
}
class CreateTaskRequest {
<<Interface>>
+prompt: string
+repository: RepositoryContext
+parameters: TaskParameters
}
class Workflow {
<<Interface>>
+id: string
+name: string
+steps: WorkflowStep[]
}
class WorkflowStep {
<<Interface>>
+id: string
+name: string
+type: string
+parameters: object
+dependencies: string[]
}
class RepositoryInfo {
<<Interface>>
+id: string
+name: string
+url: string
+defaultBranch: string
}
class AuthenticationInfo {
<<Interface>>
+orgId: string
+valid: boolean
+quota: object
}
class CodeGenerationRequest {
<<Interface>>
+prompt: string
+context: CodebaseContext
+parameters: CodeGenerationParameters
}
CodegenTask --> "0..1" TaskResult
CodegenTask --> "0..1" TaskError
CreateTaskRequest --> "0..1" RepositoryContext
CreateTaskRequest --> "0..1" TaskParameters
Workflow --> "*" WorkflowStep
CodeGenerationRequest --> "0..1" CodebaseContext
CodeGenerationRequest --> "0..1" CodeGenerationParameters
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
🔧 Codegen SDK Integration Implementation
This PR implements Phase 2.2 of the Task Master architecture restructuring, adding comprehensive Codegen SDK integration to the VoltAgent framework.
🎯 Overview
Implements a complete integration layer that handles authentication, code generation requests, repository operations, and PR management through the Codegen API.
📋 Key Components Implemented
1. SDK Client Setup (
packages/core/src/codegen/sdk-client.ts)2. Authentication Manager (
packages/core/src/codegen/auth-manager.ts)3. Repository Operations (
packages/core/src/codegen/repository-ops.ts)4. Code Generation Services (
packages/core/src/codegen/code-generation.ts)5. Orchestrator Integration (
packages/core/src/codegen/orchestrator.ts)6. Configuration & Validation (
packages/core/src/codegen/config.ts)🔗 Integration Points
📊 Technical Features
🧪 Example Usage
📁 Files Added
Core Implementation:
packages/core/src/codegen/sdk-client.ts- Main SDK clientpackages/core/src/codegen/auth-manager.ts- Authentication managementpackages/core/src/codegen/repository-ops.ts- Repository operationspackages/core/src/codegen/code-generation.ts- Code generation servicespackages/core/src/codegen/orchestrator.ts- Main orchestratorpackages/core/src/codegen/types.ts- TypeScript type definitionspackages/core/src/codegen/config.ts- Configuration and validationpackages/core/src/codegen/index.ts- Main exportsExample & Documentation:
examples/codegen-integration/- Complete usage exampleexamples/codegen-integration/README.md- Comprehensive documentationexamples/codegen-integration/.env.example- Environment configurationDependencies Added:
axios- HTTP client for API requestsnode-cache- In-memory cachingretry- Retry logic implementationcircuit-breaker- Circuit breaker pattern✅ Acceptance Criteria Met
🔄 Next Steps
This implementation provides the foundation for:
🧪 Testing
The implementation includes:
📚 Documentation
Related Issue: ZAM-841 - Phase 2.2: Implement Codegen SDK Integration
Dependencies: Requires Phase 2.1 (AgentAPI middleware)
Blocks: Phase 3.1 (Linear integration)
💻 View my work • About Codegen
Summary by Sourcery
Implement Phase 2.2 Codegen SDK integration in VoltAgent core by adding a full Codegen client, authentication manager, repository operations, code generation and review services, an orchestrator for task and workflow management, configuration validation, and a working example with documentation.
New Features:
Enhancements:
Build:
Documentation: