@@ -124,11 +124,10 @@ Q&A: ${qaText}
124124
125125REQUIREMENTS:
126126- ${ lessonCount } progressive lessons (${ isFirstBatch ? 'fundamentals' : 'intermediate to advanced' } )
127- - Each lesson: 2-3 reading cards (100-150 words each), 2 MCQ cards (4 options), 1 summary card
128- - Canadian context (TFSA, RRSP)
127+ - Each lesson: 1-2 reading cards (50-100 words each), 2 MCQ cards (4 options), 1 summary card
128+ - Canadian context (TFSA, RRSP), Finny's voice
129129- XP: Lessons 1-3 = 30, 4-7 = 35-40, 8-10 = 40-50
130- - Engaging titles, Finny's voice
131- ${ isFirstBatch ? '' : '- These lessons should build on fundamentals from lessons 1-3' }
130+ ${ isFirstBatch ? '' : '- Build on fundamentals from lessons 1-3' }
132131
133132Return ONLY JSON (no markdown):
134133{
@@ -144,10 +143,10 @@ Return ONLY JSON (no markdown):
144143 "prerequisites": [],
145144 "xpReward": ${ startLesson <= 3 ? 30 : startLesson <= 7 ? 35 : 40 } ,
146145 "cards": [
147- {"type": "reading", "content": "100-150 word explanation"},
148- {"type": "mcq", "question": "Question?", "options": ["A", "B", "C", "D"], "correctIndex": 0, "explanation": "Why correct "},
149- {"type": "reading", "content": "100-150 words"},
150- {"type": "mcq", "question": "Question?", "options": ["A", "B", "C", "D"], "correctIndex": 1, "explanation": "Why correct "},
146+ {"type": "reading", "content": "50-100 word explanation"},
147+ {"type": "mcq", "question": "Question?", "options": ["A", "B", "C", "D"], "correctIndex": 0, "explanation": "Brief explanation "},
148+ {"type": "reading", "content": "50-100 words"},
149+ {"type": "mcq", "question": "Question?", "options": ["A", "B", "C", "D"], "correctIndex": 1, "explanation": "Brief explanation "},
151150 {"type": "summary", "xpEarned": ${ startLesson <= 3 ? 30 : startLesson <= 7 ? 35 : 40 } , "streakDays": 1}
152151 ]
153152 }
@@ -163,18 +162,18 @@ Return ONLY JSON (no markdown):
163162 try {
164163 const model = genAI . getGenerativeModel ( { model : modelName } ) ;
165164
166- // Use minimal thinking for faster models to speed up generation
165+ // Use minimal thinking for ALL flash/lite models to speed up generation
167166 const generationConfig : { thinkingConfig : { thinkingLevel : "MINIMAL" } } | undefined =
168- modelName === "gemini-3- flash-preview"
167+ ( modelName . includes ( " flash" ) || modelName . includes ( "lite" ) )
169168 ? {
170169 thinkingConfig : {
171170 thinkingLevel : "MINIMAL" as const
172171 }
173172 }
174173 : undefined ;
175174
176- // Set timeout: 30s for fast models, 60s for slower ones
177- const timeout = modelName . includes ( "flash" ) || modelName . includes ( "lite" ) ? 30000 : 60000 ;
175+ // Set timeout: 20s for fast models, 40s for slower ones (reduced for faster failure)
176+ const timeout = modelName . includes ( "flash" ) || modelName . includes ( "lite" ) ? 20000 : 40000 ;
178177
179178 const generateContentPromise = model . generateContent (
180179 prompt ,
@@ -376,6 +375,7 @@ export default async function handler(
376375
377376 if ( ! firebaseUid ) {
378377 console . error ( "=== API ERROR: Missing firebaseUid ===" ) ;
378+ setCorsHeaders ( res ) ;
379379 return res . status ( 400 ) . json ( { error : "Missing firebaseUid" } ) ;
380380 }
381381
@@ -391,6 +391,7 @@ export default async function handler(
391391
392392 if ( ! user ) {
393393 console . error ( "=== API ERROR: User not found ===" ) ;
394+ setCorsHeaders ( res ) ;
394395 return res . status ( 404 ) . json ( { error : "User not found" } ) ;
395396 }
396397
@@ -399,6 +400,7 @@ export default async function handler(
399400 console . log ( "onboardingCompleted:" , user . onboardingCompleted ) ;
400401 if ( ! user . onboardingCompleted ) {
401402 console . error ( "=== API ERROR: Onboarding not completed ===" ) ;
403+ setCorsHeaders ( res ) ;
402404 return res . status ( 400 ) . json ( {
403405 error : "Onboarding not completed" ,
404406 message : "User must complete onboarding before generating lessons"
@@ -510,6 +512,7 @@ export default async function handler(
510512
511513 } catch ( error ) {
512514 console . error ( "Error generating lessons:" , error ) ;
515+ setCorsHeaders ( res ) ; // Ensure CORS headers on error responses
513516 return res . status ( 500 ) . json ( {
514517 error : "Failed to generate lessons" ,
515518 message : error instanceof Error ? error . message : "Unknown error" ,
0 commit comments