diff --git a/packages/cli/src/ui/auth/AuthDialog.tsx b/packages/cli/src/ui/auth/AuthDialog.tsx index 4104a775..9d9baa89 100644 --- a/packages/cli/src/ui/auth/AuthDialog.tsx +++ b/packages/cli/src/ui/auth/AuthDialog.tsx @@ -78,20 +78,17 @@ export function AuthDialog({ ); const handleAuthSelect = (authMethod: AuthType) => { - const error = validateAuthMethod(authMethod); - if (error) { - if ( - authMethod === AuthType.USE_OPENAI && - !process.env['OPENAI_API_KEY'] - ) { - setShowOpenAIKeyPrompt(true); - setErrorMessage(null); - } else { - setErrorMessage(error); - } - } else { + if (authMethod === AuthType.USE_OPENAI) { + setShowOpenAIKeyPrompt(true); setErrorMessage(null); - onSelect(authMethod, SettingScope.User); + } else { + const error = validateAuthMethod(authMethod); + if (error) { + setErrorMessage(error); + } else { + setErrorMessage(null); + onSelect(authMethod, SettingScope.User); + } } }; @@ -137,10 +134,23 @@ export function AuthDialog({ }, { isActive: true }, ); + const getDefaultOpenAIConfig = () => { + const fromSettings = settings.merged.security?.auth; + const modelSettings = settings.merged.model; + return { + apiKey: fromSettings?.apiKey || process.env['OPENAI_API_KEY'] || '', + baseUrl: fromSettings?.baseUrl || process.env['OPENAI_BASE_URL'] || '', + model: modelSettings?.name || process.env['OPENAI_MODEL'] || '', + }; + }; if (showOpenAIKeyPrompt) { + const defaults = getDefaultOpenAIConfig(); return ( diff --git a/packages/cli/src/ui/components/OpenAIKeyPrompt.tsx b/packages/cli/src/ui/components/OpenAIKeyPrompt.tsx index 365f557e..bc78b8c5 100644 --- a/packages/cli/src/ui/components/OpenAIKeyPrompt.tsx +++ b/packages/cli/src/ui/components/OpenAIKeyPrompt.tsx @@ -13,15 +13,21 @@ import { useKeypress } from '../hooks/useKeypress.js'; interface OpenAIKeyPromptProps { onSubmit: (apiKey: string, baseUrl: string, model: string) => void; onCancel: () => void; + defaultApiKey?: string; + defaultBaseUrl?: string; + defaultModel?: string; } export function OpenAIKeyPrompt({ onSubmit, onCancel, + defaultApiKey, + defaultBaseUrl, + defaultModel, }: OpenAIKeyPromptProps): React.JSX.Element { - const [apiKey, setApiKey] = useState(''); - const [baseUrl, setBaseUrl] = useState(''); - const [model, setModel] = useState(''); + const [apiKey, setApiKey] = useState(defaultApiKey || ''); + const [baseUrl, setBaseUrl] = useState(defaultBaseUrl || ''); + const [model, setModel] = useState(defaultModel || ''); const [currentField, setCurrentField] = useState< 'apiKey' | 'baseUrl' | 'model' >('apiKey');