@@ -27,13 +27,15 @@ const callAI = async (prompt, systemInstruction = "You are a helpful AI study as
2727 const client = getClient ( key ) ;
2828 if ( ! client ) throw new Error ( "AI_CLIENT_INITIALIZATION_FAILED" ) ;
2929
30- // Valid model names for the current Gemini API in 2026
3130 const models = [
31+ "gemini-2.5-flash-lite" ,
32+ "gemini-2.5-flash" ,
3233 "gemini-3.1-flash" ,
3334 "gemini-3.1-pro" ,
3435 "gemini-3-flash-preview" ,
35- "gemini-2.5-flash" ,
36- "gemini-2.5-pro"
36+ "gemini-2.5-pro" ,
37+ "gemini-2.0-flash-lite" ,
38+ "gemma-3-4b-it"
3739 ] ;
3840
3941 let lastError = null ;
@@ -42,7 +44,7 @@ const callAI = async (prompt, systemInstruction = "You are a helpful AI study as
4244 for ( const modelName of models ) {
4345 try {
4446 console . log ( `🤖 AI Attempt: ${ modelName } via @google/genai` ) ;
45-
47+
4648 const response = await client . models . generateContent ( {
4749 model : modelName ,
4850 contents : `${ systemInstruction } \n\nStudent Input: ${ prompt } ` ,
@@ -323,7 +325,7 @@ router.post('/match-task', auth, async (req, res) => {
323325 try {
324326 const userId = req . userId ;
325327 const { timeAvailable, energyLevel } = req . body ;
326-
328+
327329 if ( ! timeAvailable || ! energyLevel ) {
328330 return res . status ( 400 ) . json ( { message : "Time and energy level are required." } ) ;
329331 }
@@ -366,7 +368,7 @@ router.post('/match-task', auth, async (req, res) => {
366368 bestType = 'assignment' ;
367369 rationale = `With your High energy and ${ timeAvailable } available, this high-priority assignment is the perfect challenge right now.` ;
368370 } else {
369- const sortedTodos = todos . sort ( ( a , b ) => getPriorityScore ( b . priority ) - getPriorityScore ( a . priority ) ) ;
371+ const sortedTodos = todos . sort ( ( a , b ) => getPriorityScore ( b . priority ) - getPriorityScore ( a . priority ) ) ;
370372 bestTask = sortedTodos [ 0 ] . title ;
371373 rationale = `With high energy, knocking out your highest priority task is the best use of your ${ timeAvailable } .` ;
372374 }
@@ -401,7 +403,7 @@ router.post('/match-task', auth, async (req, res) => {
401403router . post ( '/mastery-roadmap' , auth , async ( req , res ) => {
402404 try {
403405 const { topic, timeframe } = req . body ;
404-
406+
405407 if ( ! topic ) return res . status ( 400 ) . json ( { message : "Topic is required" } ) ;
406408
407409 const prompt = `Create a learning roadmap to master the topic of "${ topic } ". The timeframe is ${ timeframe || '7 days' } .
@@ -454,7 +456,7 @@ router.post('/vault/lock', auth, async (req, res) => {
454456 let keys = parseInt ( parsed . keysRequired ) ;
455457 if ( isNaN ( keys ) || keys < 1 ) keys = 2 ;
456458 if ( keys > 10 ) keys = 10 ;
457-
459+
458460 res . json ( { keysRequired : keys , aiMessage : parsed . aiMessage } ) ;
459461 } catch ( e ) {
460462 res . json ( { keysRequired : 3 , aiMessage : `The Vault containing your "${ reward } " is sealed tight. Prove your unshakable focus to unlock it!` } ) ;
@@ -470,7 +472,7 @@ router.post('/vault/break', auth, async (req, res) => {
470472 try {
471473 const userId = req . userId ;
472474 const { reward, keysRemaining } = req . body ;
473-
475+
474476 const assignments = await Assignment . find ( { user : userId , completed : false } ) . sort ( { deadline : 1 } ) . limit ( 3 ) ;
475477 const assignmentContext = assignments . map ( a => `${ a . title } (due ${ a . deadline . toDateString ( ) } )` ) . join ( ', ' ) ;
476478
@@ -516,7 +518,7 @@ router.post('/simulate-procrastination', auth, async (req, res) => {
516518 const insight = await callAI ( prompt , "You are a dramatic, terrifying narrator showing alternate future timelines to stop procrastination. Return only JSON." ) ;
517519 res . json ( extractJson ( insight ) ) ;
518520 } catch ( e ) {
519- res . json ( {
521+ res . json ( {
520522 oneWeek : `You keep pushing "${ taskTitle } " off, and the pile of work doubles. You end up sacrificing your entire weekend.` ,
521523 oneMonth : `The stress from avoiding "${ taskTitle } " bleeds into your other classes. Your grades slip universally.` ,
522524 oneYear : `You look back and realize procrastinating on "${ taskTitle } " was the domino that ruined your semester's momentum.` ,
@@ -550,7 +552,7 @@ router.post('/mind-sweep', auth, async (req, res) => {
550552
551553 const responseText = await callAI ( prompt , "You are an intelligent task extractor and organizer. Respond ONLY with valid JSON." ) ;
552554 const result = extractJson ( responseText ) ;
553-
555+
554556 // ensure default arrays
555557 res . json ( {
556558 todos : result . todos || [ ] ,
0 commit comments