( authMethod: string, settings?: LoadedSettings, )
| 9 | import { loadEnvironment, LoadedSettings } from './settings.js'; |
| 10 | |
| 11 | export const validateAuthMethod = ( |
| 12 | authMethod: string, |
| 13 | settings?: LoadedSettings, |
| 14 | ): string | null => { |
| 15 | loadEnvironment(); |
| 16 | |
| 17 | if (authMethod === AuthType.USE_GROK) { |
| 18 | // Check both environment variable and settings |
| 19 | const hasEnvKey = |
| 20 | !!process.env['GROK_API_KEY'] || !!process.env['XAI_API_KEY']; |
| 21 | const hasSettingsKey = !!settings?.merged.grok?.apiKey; |
| 22 | |
| 23 | // If we have a settings key, ensure it gets exported to environment |
| 24 | if (hasSettingsKey && !hasEnvKey) { |
| 25 | process.env['GROK_API_KEY'] = settings!.merged.grok!.apiKey; |
| 26 | } |
| 27 | |
| 28 | if (!hasEnvKey && !hasSettingsKey) { |
| 29 | return 'OpenRouter API key not found. Please set your GROK_API_KEY environment variable or configure it in settings. Get your API key from https://openrouter.ai/keys'; |
| 30 | } |
| 31 | return null; |
| 32 | } |
| 33 | |
| 34 | return 'Invalid auth method selected.'; |
| 35 | }; |
no test coverage detected