@@ -506,12 +506,14 @@ func callAI(prompt, orKey, geminiKey string) (string, error) {
506506 ocKey := strings .TrimSpace (os .Getenv ("OPENCODE_API_KEY" ))
507507 zaiKey := strings .TrimSpace (os .Getenv ("ZHIPU_API_KEY" ))
508508
509+ var errs []string
509510 if ocKey != "" {
510511 res , err := callOpenCode (prompt , ocKey )
511512 if err == nil {
512513 return res , nil
513514 }
514515 logger .GetLogger ().Infof ("[BRAIN] OpenCode failed, falling back to other providers: %v" , err )
516+ errs = append (errs , "OpenCode(" + openCodeModel ()+ "): " + err .Error ())
515517 }
516518
517519 if orKey != "" {
@@ -520,6 +522,7 @@ func callAI(prompt, orKey, geminiKey string) (string, error) {
520522 return res , nil
521523 }
522524 logger .GetLogger ().Infof ("[BRAIN] OpenRouter failed, falling back to other providers: %v" , err )
525+ errs = append (errs , "OpenRouter(" + openRouterModel ()+ "): " + err .Error ())
523526 }
524527
525528 if zaiKey != "" {
@@ -528,13 +531,21 @@ func callAI(prompt, orKey, geminiKey string) (string, error) {
528531 return res , nil
529532 }
530533 logger .GetLogger ().Infof ("[BRAIN] Z.ai failed, falling back to direct Gemini: %v" , err )
534+ errs = append (errs , "Z.ai: " + err .Error ())
531535 }
532536
533537 if geminiKey != "" {
534- return callGeminiDirect (prompt , geminiKey )
538+ res , err := callGeminiDirect (prompt , geminiKey )
539+ if err == nil {
540+ return res , nil
541+ }
542+ errs = append (errs , "Gemini: " + err .Error ())
535543 }
536544
537- return "" , fmt .Errorf ("no valid AI key found or all services failed" )
545+ if len (errs ) == 0 {
546+ return "" , fmt .Errorf ("%s" , errNoAIKey )
547+ }
548+ return "" , fmt .Errorf ("all configured AI providers failed — %s" , strings .Join (errs , " | " ))
538549}
539550
540551func callOpenRouter (prompt , apiKey string ) (string , error ) {
@@ -683,12 +694,14 @@ func ChatWithAI(history []Message, userMessage string, systemPrompt string) (str
683694 messages = append (messages , history ... )
684695 messages = append (messages , Message {Role : "user" , Content : userMessage })
685696
697+ var errs []string
686698 if openCodeKey != "" {
687699 res , err := callOpenCodeMulti (messages , openCodeKey )
688700 if err == nil {
689701 return res , nil
690702 }
691703 logger .GetLogger ().Infof ("[BRAIN] OpenCode failed, falling back to other providers: %v" , err )
704+ errs = append (errs , "OpenCode(" + openCodeModel ()+ "): " + err .Error ())
692705 }
693706
694707 if openRouterKey != "" {
@@ -697,6 +710,7 @@ func ChatWithAI(history []Message, userMessage string, systemPrompt string) (str
697710 return res , nil
698711 }
699712 logger .GetLogger ().Infof ("[BRAIN] OpenRouter failed, falling back to other providers: %v" , err )
713+ errs = append (errs , "OpenRouter(" + openRouterModel ()+ "): " + err .Error ())
700714 }
701715
702716 zaiKey := strings .TrimSpace (os .Getenv ("ZHIPU_API_KEY" ))
@@ -706,13 +720,21 @@ func ChatWithAI(history []Message, userMessage string, systemPrompt string) (str
706720 return res , nil
707721 }
708722 logger .GetLogger ().Infof ("[BRAIN] Z.ai failed, falling back to Gemini: %v" , err )
723+ errs = append (errs , "Z.ai: " + err .Error ())
709724 }
710725
711726 if geminiKey != "" {
712- return callGeminiDirectMulti (messages , geminiKey )
727+ res , err := callGeminiDirectMulti (messages , geminiKey )
728+ if err == nil {
729+ return res , nil
730+ }
731+ errs = append (errs , "Gemini: " + err .Error ())
713732 }
714733
715- return "" , fmt .Errorf ("no valid AI key found or all services failed" )
734+ if len (errs ) == 0 {
735+ return "" , fmt .Errorf ("%s" , errNoAIKey )
736+ }
737+ return "" , fmt .Errorf ("all configured AI providers failed — %s" , strings .Join (errs , " | " ))
716738}
717739
718740// callOpenRouterMulti sends a multi-message conversation to OpenRouter
0 commit comments