2025-06-10 16:00:13 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-06-19 16:52:22 -07:00
|
|
|
import { AuthType, 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';
|
2025-06-16 12:03:06 -07:00
|
|
|
import { CodeAssistServer, HttpOptions } from './server.js';
|
2025-06-10 16:00:13 -07:00
|
|
|
|
2025-06-16 12:03:06 -07:00
|
|
|
export async function createCodeAssistContentGenerator(
|
|
|
|
|
httpOptions: HttpOptions,
|
2025-06-19 16:52:22 -07:00
|
|
|
authType: AuthType,
|
2025-06-16 12:03:06 -07:00
|
|
|
): Promise<ContentGenerator> {
|
2025-06-30 17:11:54 -07:00
|
|
|
if (authType === AuthType.LOGIN_WITH_GOOGLE) {
|
2025-06-19 16:52:22 -07:00
|
|
|
const authClient = await getOauthClient();
|
|
|
|
|
const projectId = await setupUser(authClient);
|
|
|
|
|
return new CodeAssistServer(authClient, projectId, httpOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Error(`Unsupported authType: ${authType}`);
|
2025-06-18 09:49:13 -07:00
|
|
|
}
|