Source Code:
src/gaia/agents/code/This is Part 3 of 3. If you haven’t completed the previous parts:
- Time to complete: 15-20 minutes
- What you’ll learn: TypeScript validation, build process, error fixing loop
- Platform: Designed for AI PCs with Ryzen AI (NPU/iGPU acceleration)
The Validation & Build Pipeline
After generating code, GAIA Code doesn’t just stop—it validates, builds, and fixes errors automatically until the application works.Phase 1: TypeScript Validation
The first validation step checks for type errors.What TypeScript Validation Checks
Type Safety
Variables used with correct types
Import Errors
All imports resolve correctly
API Compatibility
Function calls match signatures
Null Safety
Nullable values handled properly
Example: Type Error Detection
Generated code with error:Auto-Fix Process
- Error detected: TypeScript compiler identifies the issue
- LLM analyzes: Understands the error context
- Fix generated: Provides corrected code
- Applied: Code is updated
Phase 2: Next.js Build Process
After TypeScript validation passes, the agent runs the Next.js build.Build Steps
- Compiles TypeScript → JavaScript
- Bundles code → Optimized chunks
- Generates static pages → Pre-rendered HTML
- Optimizes images → Next.js image optimization
- Creates server bundles → API routes
Build Output Example
Common Build Errors
Import Resolution Errors
Import Resolution Errors
Error:Cause: Missing or incorrect path aliasAuto-fix:
- Check tsconfig.json paths
- Verify file exists
- Update import statement
Prisma Client Errors
Prisma Client Errors
Error:Cause: Prisma client not generatedAuto-fix:
- Run
npx prisma generate - Ensure schema is valid
- Check database connection
Type Import Errors
Type Import Errors
Error:Cause: Missing Next.js importsAuto-fix:
- Add missing import
- Verify Next.js version
- Check API route syntax
Phase 3: Error Iteration Loop
When errors are found, the agent enters an iteration loop.Iteration Process
1
Error Collection
Gather all TypeScript and build errors with line numbers and context
2
Error Analysis
LLM analyzes each error:
- What caused it?
- What’s the fix?
- Will this fix break anything else?
3
Fix Generation
Generate minimal fixes:
- Change only what’s needed
- Maintain code style
- Keep functionality intact
4
Apply Fixes
Update files with corrections
5
Re-validate
Run TypeScript validation and build again
6
Repeat or Complete
- More errors? → Back to step 1
- No errors? → Success!
Example: Complete Iteration
Iteration 1:Validation Features
1. Intelligent Error Detection
The agent recognizes different error types:| Error Type | Detection Method | Fix Strategy |
|---|---|---|
| Type Errors | TypeScript compiler | Type conversion, interface updates |
| Import Errors | Module resolution | Add imports, fix paths |
| Build Errors | Next.js build | Configuration fixes, dependency updates |
| Runtime Errors | Code analysis | Logic fixes, null checks |
2. Context-Aware Fixes
Fixes consider the broader context:3. Minimal Changes
The agent makes the smallest possible fix:Build Optimization
The agent ensures optimal build configuration.Generated Configuration Files
- tsconfig.json
- next.config.js
- package.json
Testing the Final Application
Once validation passes and build succeeds, test the application:Run the app
Verification Checklist
Database
✓ Schema applied
✓ Tables created
✓ Migrations work
✓ Tables created
✓ Migrations work
API Routes
✓ GET returns data
✓ POST creates records
✓ PUT updates records
✓ DELETE removes records
✓ POST creates records
✓ PUT updates records
✓ DELETE removes records
UI Components
✓ List view displays data
✓ Create form works
✓ Detail view shows record
✓ Delete confirms action
✓ Create form works
✓ Detail view shows record
✓ Delete confirms action
Validation
✓ Required fields enforced
✓ Type validation works
✓ Error messages display
✓ Edge cases handled
✓ Type validation works
✓ Error messages display
✓ Edge cases handled
Summary
GAIA Code’s validation and build process ensures:- Type Safety - TypeScript catches type errors
- Build Success - Next.js builds without issues
- Automatic Fixes - Errors are fixed iteratively
- Working App - Final output is functional