mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Merge "Login with Google Workspace" auth option into "Login with Google" (#1574)
Co-authored-by: Scott Densmore <scottdensmore@mac.com>
This commit is contained in:
committed by
GitHub
parent
00b24c917e
commit
79c647d486
@@ -13,13 +13,6 @@ export const validateAuthMethod = (authMethod: string): string | null => {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (authMethod === AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE) {
|
||||
if (!process.env.GOOGLE_CLOUD_PROJECT) {
|
||||
return 'GOOGLE_CLOUD_PROJECT environment variable not found. Add that to your .env and try again, no reload needed!';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (authMethod === AuthType.USE_GEMINI) {
|
||||
if (!process.env.GEMINI_API_KEY) {
|
||||
return 'GEMINI_API_KEY environment variable not found. Add that to your .env and try again, no reload needed!';
|
||||
|
||||
@@ -29,32 +29,15 @@ export function AuthDialog({
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(
|
||||
initialErrorMessage || null,
|
||||
);
|
||||
const allAuthItems = [
|
||||
const items = [
|
||||
{
|
||||
label: 'Login with Google',
|
||||
value: AuthType.LOGIN_WITH_GOOGLE_PERSONAL,
|
||||
},
|
||||
{ label: 'Gemini API Key', value: AuthType.USE_GEMINI },
|
||||
{
|
||||
label: 'Login with Google (for Workspace or licensed Code Assist users)',
|
||||
value: AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE,
|
||||
},
|
||||
{ label: 'Vertex AI', value: AuthType.USE_VERTEX_AI },
|
||||
];
|
||||
|
||||
const isSelectedAuthInMore = allAuthItems
|
||||
.slice(2)
|
||||
.some((item) => item.value === settings.merged.selectedAuthType);
|
||||
|
||||
const [showAll, setShowAll] = useState(isSelectedAuthInMore);
|
||||
|
||||
const initialAuthItems = [
|
||||
...allAuthItems.slice(0, 2),
|
||||
{ label: 'More...', value: 'more' },
|
||||
];
|
||||
|
||||
const items = showAll ? allAuthItems : initialAuthItems;
|
||||
|
||||
let initialAuthIndex = items.findIndex(
|
||||
(item) => item.value === settings.merged.selectedAuthType,
|
||||
);
|
||||
@@ -64,10 +47,6 @@ export function AuthDialog({
|
||||
}
|
||||
|
||||
const handleAuthSelect = (authMethod: string) => {
|
||||
if (authMethod === 'more') {
|
||||
setShowAll(true);
|
||||
return;
|
||||
}
|
||||
const error = validateAuthMethod(authMethod);
|
||||
if (error) {
|
||||
setErrorMessage(error);
|
||||
|
||||
@@ -46,12 +46,16 @@ export const useAuthCommand = (
|
||||
config,
|
||||
);
|
||||
} catch (e) {
|
||||
const errorMessage =
|
||||
let errorMessage = `Failed to login.\nMessage: ${getErrorMessage(e)}`;
|
||||
if (
|
||||
settings.merged.selectedAuthType ===
|
||||
AuthType.LOGIN_WITH_GOOGLE_PERSONAL
|
||||
? `Failed to login. Ensure the Google account you are using is not a Workspace account and that you are not a licensed Code Assist user (see https://goo.gle/gemini-cli-auth-docs#workspace-gca).
|
||||
Message: ${getErrorMessage(e)}`
|
||||
: `Failed to login. Message: ${getErrorMessage(e)}`;
|
||||
AuthType.LOGIN_WITH_GOOGLE_PERSONAL &&
|
||||
!process.env.GOOGLE_CLOUD_PROJECT
|
||||
) {
|
||||
errorMessage =
|
||||
'Failed to login. Workspace accounts and licensed Code Assist users must configure' +
|
||||
` GOOGLE_CLOUD_PROJECT (see https://goo.gle/gemini-cli-auth-docs#workspace-gca).\nMessage: ${getErrorMessage(e)}`;
|
||||
}
|
||||
setAuthError(errorMessage);
|
||||
openAuthDialog();
|
||||
} finally {
|
||||
|
||||
@@ -1043,7 +1043,7 @@ describe('useGeminiStream', () => {
|
||||
it('should call parseAndFormatApiError with the correct authType on stream initialization failure', async () => {
|
||||
// 1. Setup
|
||||
const mockError = new Error('Rate limit exceeded');
|
||||
const mockAuthType = AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE;
|
||||
const mockAuthType = AuthType.LOGIN_WITH_GOOGLE_PERSONAL;
|
||||
mockParseAndFormatApiError.mockClear();
|
||||
mockSendMessageStream.mockReturnValue(
|
||||
(async function* () {
|
||||
|
||||
@@ -29,12 +29,12 @@ describe('parseAndFormatApiError', () => {
|
||||
expect(result).toContain('Your request has been rate limited');
|
||||
});
|
||||
|
||||
it('should format a 429 API error with the enterprise message', () => {
|
||||
it('should format a 429 API error with the personal message', () => {
|
||||
const errorMessage =
|
||||
'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Rate limit exceeded","status":"RESOURCE_EXHAUSTED"}}';
|
||||
const result = parseAndFormatApiError(
|
||||
errorMessage,
|
||||
AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE,
|
||||
AuthType.LOGIN_WITH_GOOGLE_PERSONAL,
|
||||
);
|
||||
expect(result).toContain('[API Error: Rate limit exceeded');
|
||||
expect(result).toContain(enterpriseMessage);
|
||||
|
||||
@@ -46,7 +46,6 @@ function isStructuredError(error: unknown): error is StructuredError {
|
||||
function getRateLimitMessage(authType?: AuthType): string {
|
||||
switch (authType) {
|
||||
case AuthType.LOGIN_WITH_GOOGLE_PERSONAL:
|
||||
case AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE:
|
||||
return RATE_LIMIT_ERROR_MESSAGE_GOOGLE;
|
||||
case AuthType.USE_GEMINI:
|
||||
return RATE_LIMIT_ERROR_MESSAGE_USE_GEMINI;
|
||||
|
||||
Reference in New Issue
Block a user