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-07-10 18:59:02 -07:00
|
|
|
import { Config } from '../config/config.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-07-10 18:59:02 -07:00
|
|
|
config: Config,
|
2025-07-01 19:16:09 -04:00
|
|
|
sessionId?: string,
|
2025-06-16 12:03:06 -07:00
|
|
|
): Promise<ContentGenerator> {
|
2025-07-07 15:02:13 -07:00
|
|
|
if (
|
|
|
|
|
authType === AuthType.LOGIN_WITH_GOOGLE ||
|
|
|
|
|
authType === AuthType.CLOUD_SHELL
|
|
|
|
|
) {
|
2025-07-10 18:59:02 -07:00
|
|
|
const authClient = await getOauthClient(authType, config);
|
2025-06-19 16:52:22 -07:00
|
|
|
const projectId = await setupUser(authClient);
|
2025-07-01 19:16:09 -04:00
|
|
|
return new CodeAssistServer(authClient, projectId, httpOptions, sessionId);
|
2025-06-19 16:52:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Error(`Unsupported authType: ${authType}`);
|
2025-06-18 09:49:13 -07:00
|
|
|
}
|