@@ -22,14 +22,12 @@ const extendedComponentSchema = componentSchema.extend({
22
22
23
23
export async function POST ( request : NextRequest ) {
24
24
try {
25
- console . log ( '🚀 API route started' ) ;
26
25
const body = await request . json ( ) ;
27
26
28
27
// Validate the request using extended schema
29
28
const validationResult = extendedComponentSchema . safeParse ( body ) ;
30
29
31
30
if ( ! validationResult . success ) {
32
- console . log ( '❌ Validation failed:' , validationResult . error . format ( ) ) ;
33
31
return NextResponse . json (
34
32
{ error : 'Invalid request format' , details : validationResult . error . format ( ) } ,
35
33
{ status : 400 }
@@ -38,25 +36,13 @@ export async function POST(request: NextRequest) {
38
36
39
37
const { description, existingFiles, editInstruction, useBuggyCode, useFixer } = validationResult . data ;
40
38
41
- console . log ( '✅ Validation passed, API Request:' , {
42
- isEdit : ! ! ( existingFiles && editInstruction ) ,
43
- filesCount : existingFiles ?. length || 0 ,
44
- editInstruction : editInstruction || 'none' ,
45
- description : description || 'none' ,
46
- useBuggyCode,
47
- useFixer
48
- } ) ;
49
-
50
39
// Process the app request using centralized logic
51
40
const filesToSandbox = await processAppRequest ( description , existingFiles , editInstruction , useBuggyCode ) ;
52
41
53
- console . log ( '📦 Files ready for sandbox:' , filesToSandbox . length ) ;
54
-
55
42
let repairedFiles = filesToSandbox ;
56
43
57
44
// Repair the generated code using Benchify's API if requested
58
45
if ( useFixer ) {
59
- console . log ( '🔧 Running Benchify fixer...' ) ;
60
46
try {
61
47
const { data } = await benchify . fixer . run ( {
62
48
files : filesToSandbox . map ( ( file : { path : string ; content : string } ) => ( {
@@ -69,31 +55,21 @@ export async function POST(request: NextRequest) {
69
55
const { success, diff } = data ;
70
56
71
57
if ( success && diff ) {
72
- console . log ( '✅ Fixer applied successfully' ) ;
73
58
repairedFiles = filesToSandbox . map ( ( file : { path : string ; content : string } ) => {
74
59
const patchResult = applyPatch ( file . content , diff ) ;
75
60
return {
76
61
...file ,
77
62
content : typeof patchResult === 'string' ? patchResult : file . content
78
63
} ;
79
64
} ) ;
80
- } else {
81
- console . log ( '⚠️ Fixer ran but no fixes were applied' ) ;
82
65
}
83
- } else {
84
- console . log ( '⚠️ Fixer returned no data' ) ;
85
66
}
86
67
} catch ( error ) {
87
- console . error ( '❌ Error running fixer:' , error ) ;
88
68
// Continue with original files if fixer fails
89
69
}
90
- } else {
91
- console . log ( '⏭️ Skipping fixer as requested' ) ;
92
70
}
93
71
94
- console . log ( '🏗️ Creating sandbox...' ) ;
95
72
const sandboxResult = await createSandbox ( { files : repairedFiles } ) ;
96
- console . log ( '✅ Sandbox created successfully' ) ;
97
73
98
74
// Return the results to the client
99
75
return NextResponse . json ( {
@@ -106,7 +82,6 @@ export async function POST(request: NextRequest) {
106
82
...( editInstruction && { editInstruction } ) ,
107
83
} ) ;
108
84
} catch ( error ) {
109
- console . error ( '💥 Error in API route:' , error ) ;
110
85
return NextResponse . json (
111
86
{
112
87
error : 'Failed to generate app' ,
0 commit comments