mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
feat: Add GEMINI_DEFAULT_AUTH_TYPE support (#4002)
This commit is contained in:
@@ -18,18 +18,47 @@ interface AuthDialogProps {
|
||||
initialErrorMessage?: string | null;
|
||||
}
|
||||
|
||||
function parseDefaultAuthType(
|
||||
defaultAuthType: string | undefined,
|
||||
): AuthType | null {
|
||||
if (
|
||||
defaultAuthType &&
|
||||
Object.values(AuthType).includes(defaultAuthType as AuthType)
|
||||
) {
|
||||
return defaultAuthType as AuthType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function AuthDialog({
|
||||
onSelect,
|
||||
settings,
|
||||
initialErrorMessage,
|
||||
}: AuthDialogProps): React.JSX.Element {
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(
|
||||
initialErrorMessage
|
||||
? initialErrorMessage
|
||||
: process.env.GEMINI_API_KEY
|
||||
? 'Existing API key detected (GEMINI_API_KEY). Select "Gemini API Key" option to use it.'
|
||||
: null,
|
||||
);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(() => {
|
||||
if (initialErrorMessage) {
|
||||
return initialErrorMessage;
|
||||
}
|
||||
|
||||
const defaultAuthType = parseDefaultAuthType(
|
||||
process.env.GEMINI_DEFAULT_AUTH_TYPE,
|
||||
);
|
||||
|
||||
if (process.env.GEMINI_DEFAULT_AUTH_TYPE && defaultAuthType === null) {
|
||||
return (
|
||||
`Invalid value for GEMINI_DEFAULT_AUTH_TYPE: "${process.env.GEMINI_DEFAULT_AUTH_TYPE}". ` +
|
||||
`Valid values are: ${Object.values(AuthType).join(', ')}.`
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
process.env.GEMINI_API_KEY &&
|
||||
(!defaultAuthType || defaultAuthType === AuthType.USE_GEMINI)
|
||||
) {
|
||||
return 'Existing API key detected (GEMINI_API_KEY). Select "Gemini API Key" option to use it.';
|
||||
}
|
||||
return null;
|
||||
});
|
||||
const items = [
|
||||
{
|
||||
label: 'Login with Google',
|
||||
@@ -55,6 +84,13 @@ export function AuthDialog({
|
||||
return item.value === settings.merged.selectedAuthType;
|
||||
}
|
||||
|
||||
const defaultAuthType = parseDefaultAuthType(
|
||||
process.env.GEMINI_DEFAULT_AUTH_TYPE,
|
||||
);
|
||||
if (defaultAuthType) {
|
||||
return item.value === defaultAuthType;
|
||||
}
|
||||
|
||||
if (process.env.GEMINI_API_KEY) {
|
||||
return item.value === AuthType.USE_GEMINI;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user