2025-06-11 07:00:13 +08:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-26 06:04:53 +08:00
|
|
|
import type { ContentGenerator } from '../core/contentGenerator.js';
|
|
|
|
|
import { AuthType } from '../core/contentGenerator.js';
|
2025-06-12 04:26:41 +08:00
|
|
|
import { getOauthClient } from './oauth2.js';
|
2025-06-11 07:00:13 +08:00
|
|
|
import { setupUser } from './setup.js';
|
2025-08-26 06:04:53 +08:00
|
|
|
import type { HttpOptions } from './server.js';
|
|
|
|
|
import { CodeAssistServer } from './server.js';
|
|
|
|
|
import type { Config } from '../config/config.js';
|
2025-06-11 07:00:13 +08:00
|
|
|
|
2025-06-17 03:03:06 +08:00
|
|
|
export async function createCodeAssistContentGenerator(
|
|
|
|
|
httpOptions: HttpOptions,
|
2025-06-20 07:52:22 +08:00
|
|
|
authType: AuthType,
|
2025-07-11 09:59:02 +08:00
|
|
|
config: Config,
|
2025-07-02 07:16:09 +08:00
|
|
|
sessionId?: string,
|
2025-06-17 03:03:06 +08:00
|
|
|
): Promise<ContentGenerator> {
|
2025-07-08 06:02:13 +08:00
|
|
|
if (
|
|
|
|
|
authType === AuthType.LOGIN_WITH_GOOGLE ||
|
|
|
|
|
authType === AuthType.CLOUD_SHELL
|
|
|
|
|
) {
|
2025-07-11 09:59:02 +08:00
|
|
|
const authClient = await getOauthClient(authType, config);
|
2025-08-26 07:16:30 +08:00
|
|
|
const userData = await setupUser(authClient);
|
2025-07-22 04:44:43 +08:00
|
|
|
return new CodeAssistServer(
|
|
|
|
|
authClient,
|
|
|
|
|
userData.projectId,
|
|
|
|
|
httpOptions,
|
|
|
|
|
sessionId,
|
|
|
|
|
userData.userTier,
|
|
|
|
|
);
|
2025-06-20 07:52:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Error(`Unsupported authType: ${authType}`);
|
2025-06-19 00:49:13 +08:00
|
|
|
}
|