mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +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,10 +13,7 @@ export async function createCodeAssistContentGenerator(
|
||||
httpOptions: HttpOptions,
|
||||
authType: AuthType,
|
||||
): Promise<ContentGenerator> {
|
||||
if (
|
||||
authType === AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE ||
|
||||
authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL
|
||||
) {
|
||||
if (authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL) {
|
||||
const authClient = await getOauthClient();
|
||||
const projectId = await setupUser(authClient);
|
||||
return new CodeAssistServer(authClient, projectId, httpOptions);
|
||||
|
||||
@@ -505,10 +505,7 @@ export class GeminiClient {
|
||||
*/
|
||||
private async handleFlashFallback(authType?: string): Promise<string | null> {
|
||||
// Only handle fallback for OAuth users
|
||||
if (
|
||||
authType !== AuthType.LOGIN_WITH_GOOGLE_PERSONAL &&
|
||||
authType !== AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE
|
||||
) {
|
||||
if (authType !== AuthType.LOGIN_WITH_GOOGLE_PERSONAL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ export interface ContentGenerator {
|
||||
|
||||
export enum AuthType {
|
||||
LOGIN_WITH_GOOGLE_PERSONAL = 'oauth-personal',
|
||||
LOGIN_WITH_GOOGLE_ENTERPRISE = 'oauth-enterprise',
|
||||
USE_GEMINI = 'gemini-api-key',
|
||||
USE_VERTEX_AI = 'vertex-ai',
|
||||
}
|
||||
@@ -71,14 +70,6 @@ export async function createContentGeneratorConfig(
|
||||
return contentGeneratorConfig;
|
||||
}
|
||||
|
||||
// if its enterprise make sure we have a cloud project
|
||||
if (
|
||||
authType === AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE &&
|
||||
!!googleCloudProject
|
||||
) {
|
||||
return contentGeneratorConfig;
|
||||
}
|
||||
|
||||
//
|
||||
if (authType === AuthType.USE_GEMINI && geminiApiKey) {
|
||||
contentGeneratorConfig.apiKey = geminiApiKey;
|
||||
@@ -118,10 +109,7 @@ export async function createContentGenerator(
|
||||
'User-Agent': `GeminiCLI/${version} (${process.platform}; ${process.arch})`,
|
||||
},
|
||||
};
|
||||
if (
|
||||
config.authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL ||
|
||||
config.authType === AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE
|
||||
) {
|
||||
if (config.authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL) {
|
||||
return createCodeAssistContentGenerator(httpOptions, config.authType);
|
||||
}
|
||||
|
||||
|
||||
@@ -188,10 +188,7 @@ export class GeminiChat {
|
||||
*/
|
||||
private async handleFlashFallback(authType?: string): Promise<string | null> {
|
||||
// Only handle fallback for OAuth users
|
||||
if (
|
||||
authType !== AuthType.LOGIN_WITH_GOOGLE_PERSONAL &&
|
||||
authType !== AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE
|
||||
) {
|
||||
if (authType !== AuthType.LOGIN_WITH_GOOGLE_PERSONAL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -275,35 +275,6 @@ describe('retryWithBackoff', () => {
|
||||
expect(mockFn).toHaveBeenCalledTimes(4); // 3 initial attempts + 1 after fallback
|
||||
});
|
||||
|
||||
it('should trigger fallback for OAuth enterprise users after persistent 429 errors', async () => {
|
||||
const fallbackCallback = vi.fn().mockResolvedValue('gemini-2.5-flash');
|
||||
|
||||
let fallbackOccurred = false;
|
||||
const mockFn = vi.fn().mockImplementation(async () => {
|
||||
if (!fallbackOccurred) {
|
||||
const error: HttpError = new Error('Rate limit exceeded');
|
||||
error.status = 429;
|
||||
throw error;
|
||||
}
|
||||
return 'success';
|
||||
});
|
||||
|
||||
const promise = retryWithBackoff(mockFn, {
|
||||
maxAttempts: 3,
|
||||
initialDelayMs: 100,
|
||||
onPersistent429: async (authType?: string) => {
|
||||
fallbackOccurred = true;
|
||||
return await fallbackCallback(authType);
|
||||
},
|
||||
authType: 'oauth-enterprise',
|
||||
});
|
||||
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
await expect(promise).resolves.toBe('success');
|
||||
expect(fallbackCallback).toHaveBeenCalledWith('oauth-enterprise');
|
||||
});
|
||||
|
||||
it('should NOT trigger fallback for API key users', async () => {
|
||||
const fallbackCallback = vi.fn();
|
||||
|
||||
|
||||
@@ -99,8 +99,7 @@ export async function retryWithBackoff<T>(
|
||||
if (
|
||||
consecutive429Count >= 2 &&
|
||||
onPersistent429 &&
|
||||
(authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL ||
|
||||
authType === AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE)
|
||||
authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL
|
||||
) {
|
||||
try {
|
||||
const fallbackModel = await onPersistent429(authType);
|
||||
|
||||
Reference in New Issue
Block a user