@@ -48,33 +48,48 @@ function loadEnvWithPriority() {
4848loadEnvWithPriority ( ) ;
4949
5050/**
51- * Validate and configure OpenAI API key for AI features.
52- * Uses OPENAI_API_KEY from environment (shell, .env.local, .env) or --openai-key if provided.
51+ * Validate and configure AI API key for AI features.
52+ * Priority:
53+ * 1. CLI flag (--openai-key)
54+ * 2. GEMINI_API_KEY (if model is gemini-*)
55+ * 3. OPENAI_API_KEY
5356 */
54- function validateAISetup ( aiEnabled , openaiApiKey ) {
57+ function validateAISetup ( aiEnabled , openaiApiKey , aiModel ) {
5558 if ( ! aiEnabled ) return false ;
5659
57- // CLI flag has highest priority
58- const finalApiKey = openaiApiKey || process . env . OPENAI_API_KEY ;
60+ const isGemini = aiModel . toLowerCase ( ) . includes ( 'gemini' ) ;
61+
62+ // CLI flag has highest priority (for OpenAI)
63+ let finalApiKey = openaiApiKey ;
64+
65+ if ( ! finalApiKey ) {
66+ if ( isGemini ) {
67+ finalApiKey = process . env . GEMINI_API_KEY || process . env . OPENAI_API_KEY ;
68+ } else {
69+ finalApiKey = process . env . OPENAI_API_KEY ;
70+ }
71+ }
5972
6073 if ( ! finalApiKey ) {
74+ const keyName = isGemini ? 'GEMINI_API_KEY or OPENAI_API_KEY' : 'OPENAI_API_KEY' ;
6175 console . log ( '' ) ;
6276 console . log (
6377 chalk . yellow (
64- ' ⚠️ AI features requested but no OPENAI_API_KEY found (checked env, .env.local, and .env).' ,
78+ ` ⚠️ AI features requested but no ${ keyName } found (checked env, .env.local, and .env).` ,
6579 ) ,
6680 ) ;
6781 console . log (
6882 chalk . white (
69- 'Add OPENAI_API_KEY to your .env.local or .env file, export it in your shell, or pass --openai-key "sk-..."' ,
83+ 'Add the API key to your .env.local or .env file, export it in your shell, or pass --openai-key "sk-..."' ,
7084 ) ,
7185 ) ;
7286 console . log ( chalk . dim ( 'Continuing without AI features...' ) ) ;
7387 console . log ( '' ) ;
7488 return false ;
7589 }
7690
77- if ( ! finalApiKey . startsWith ( 'sk-' ) ) {
91+ // Basic format check (OpenAI starts with sk-, Gemini often doesn't but we'll be flexible)
92+ if ( ! isGemini && ! finalApiKey . startsWith ( 'sk-' ) ) {
7893 console . log ( '' ) ;
7994 console . log (
8095 chalk . yellow ( '⚠️ Invalid OpenAI API key format (must start with "sk-")' ) ,
@@ -84,9 +99,11 @@ function validateAISetup(aiEnabled, openaiApiKey) {
8499 return false ;
85100 }
86101
87- // If provided via flag, ensure it’s in process.env for downstream code
102+ // Ensure key is in process.env for downstream code if provided via flag or specific var
88103 if ( openaiApiKey ) {
89104 process . env . OPENAI_API_KEY = openaiApiKey ;
105+ } else if ( isGemini && process . env . GEMINI_API_KEY ) {
106+ // Already in env
90107 }
91108
92109 return true ;
@@ -112,12 +129,17 @@ program
112129 )
113130 . option (
114131 '--ai' ,
115- 'Enable AI-powered website analysis (reads OPENAI_API_KEY from env, .env.local, or . env)' ,
132+ 'Enable AI-powered website analysis (reads OPENAI_API_KEY or GEMINI_API_KEY from env)' ,
116133 false ,
117134 )
135+ . option (
136+ '--ai-model <model>' ,
137+ 'AI model to use for analysis' ,
138+ 'gemini-3-flash-preview' ,
139+ )
118140 . option (
119141 '--openai-key <key>' ,
120- 'OpenAI API key for AI features (overrides env/.env.local/.env for this run)' ,
142+ 'OpenAI API key for AI features (overrides env for this run)' ,
121143 )
122144 . option ( '--debug' , 'Enable detailed debug logging and error traces' , false )
123145 . option (
@@ -135,12 +157,13 @@ program
135157 if ( ! url . startsWith ( 'http' ) ) url = 'https://' + url ;
136158 new URL ( url ) ; // validate
137159
138- const aiEnabled = validateAISetup ( options . ai , options . openaiKey ) ;
160+ const aiEnabled = validateAISetup ( options . ai , options . openaiKey , options . aiModel ) ;
139161
140162 const config = {
141163 outputDir : options . output ,
142164 clean : options . clean ,
143165 ai : aiEnabled ,
166+ aiModel : options . aiModel ,
144167 debug : options . debug ,
145168 timeout : parseInt ( options . timeout ) ,
146169 headless : options . headless !== 'false' ,
0 commit comments