Files
gemini-cli/packages/core/src/code_assist/codeAssist.ts

30 lines
911 B
TypeScript
Raw Normal View History

2025-06-10 16:00:13 -07:00
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { GoogleAuth, AuthClient } from 'google-auth-library';
2025-06-10 16:00:13 -07:00
import { ContentGenerator } from '../core/contentGenerator.js';
2025-06-11 13:26:41 -07:00
import { getOauthClient } from './oauth2.js';
2025-06-10 16:00:13 -07:00
import { setupUser } from './setup.js';
import { CodeAssistServer, HttpOptions } from './server.js';
2025-06-10 16:00:13 -07:00
export async function createCodeAssistContentGenerator(
httpOptions: HttpOptions,
): Promise<ContentGenerator> {
const authClient = await getAuthClient();
const projectId = await setupUser(authClient);
return new CodeAssistServer(authClient, projectId, httpOptions);
}
async function getAuthClient(): Promise<AuthClient> {
try {
// Try for Application Default Credentials.
return await new GoogleAuth().getClient();
} catch (_) {
// No Application Default Credentials so try Oauth.
return await getOauthClient();
}
2025-06-10 16:00:13 -07:00
}