2025-06-10 16:00:13 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-26 00:04:53 +02:00
|
|
|
import type { ContentGenerator } from '../core/contentGenerator.js';
|
|
|
|
|
import { AuthType } 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-08-26 00:04:53 +02:00
|
|
|
import type { HttpOptions } from './server.js';
|
|
|
|
|
import { CodeAssistServer } from './server.js';
|
|
|
|
|
import type { 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-08-25 16:16:30 -07:00
|
|
|
const userData = await setupUser(authClient);
|
2025-07-21 13:44:43 -07:00
|
|
|
return new CodeAssistServer(
|
|
|
|
|
authClient,
|
|
|
|
|
userData.projectId,
|
|
|
|
|
httpOptions,
|
|
|
|
|
sessionId,
|
|
|
|
|
userData.userTier,
|
|
|
|
|
);
|
2025-06-19 16:52:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Error(`Unsupported authType: ${authType}`);
|
2025-06-18 09:49:13 -07:00
|
|
|
}
|