summaryrefslogtreecommitdiff
path: root/packages/core/src/code_assist/codeAssist.ts
blob: 5f3f843e7dab80cfbf6f5ca2e9fc95bd30de2a77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { AuthType, ContentGenerator } from '../core/contentGenerator.js';
import { getOauthClient } from './oauth2.js';
import { setupUser } from './setup.js';
import { CodeAssistServer, HttpOptions } from './server.js';

export async function createCodeAssistContentGenerator(
  httpOptions: HttpOptions,
  authType: AuthType,
  sessionId?: string,
): Promise<ContentGenerator> {
  if (
    authType === AuthType.LOGIN_WITH_GOOGLE ||
    authType === AuthType.CLOUD_SHELL
  ) {
    const authClient = await getOauthClient(authType);
    const projectId = await setupUser(authClient);
    return new CodeAssistServer(authClient, projectId, httpOptions, sessionId);
  }

  throw new Error(`Unsupported authType: ${authType}`);
}