All files / packages/gemini-core/src/config config.ts

68.75% Statements 11/16
100% Branches 0/0
44.44% Functions 4/9
68.75% Lines 11/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75            6x         6x         6x             6x             6x 6x               6x       6x                   6x                         4x               6x
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
 
import process from 'node:process';
import type {
  ContentGenerator,
  ContentGeneratorConfig,
} from '../core/contentGenerator';
import {
  AuthType,
  createContentGenerator,
  createContentGeneratorConfig,
} from '../core/contentGenerator';
import { DEFAULT_GEMINI_FLASH_MODEL } from './models';
 
export interface ConfigParameters {
  sessionId: string;
  model: string;
}
 
export class Config {
  private contentGeneratorConfig!: ContentGeneratorConfig;
  private contentGenerator!: ContentGenerator;
  private readonly sessionId: string;
  private model: string;
 
  constructor(params: ConfigParameters) {
    this.sessionId = params.sessionId;
    this.model = params.model;
  }
 
  getContentGenerator(): ContentGenerator {
    return this.contentGenerator;
  }
 
  async refreshAuth(authMethod: AuthType) {
    const newContentGeneratorConfig = createContentGeneratorConfig(
      this,
      authMethod,
    );
    this.contentGenerator = await createContentGenerator(
      newContentGeneratorConfig,
      this,
      this.getSessionId(),
    );
    // Only assign to instance properties after successful initialization
    this.contentGeneratorConfig = newContentGeneratorConfig;
  }
 
  getSessionId(): string {
    return this.sessionId;
  }
 
  getModel(): string {
    return this.model;
  }
 
  setModel(newModel: string): void {
    this.model = newModel;
  }
 
  // Used by code_assist/oauth2.ts
  isBrowserLaunchSuppressed(): boolean {
    return process.env['NO_BROWSER'] === 'true';
  }
 
  getContentGeneratorConfig(): ContentGeneratorConfig {
    return this.contentGeneratorConfig;
  }
}
// Export model constants for use in CLI
export { DEFAULT_GEMINI_FLASH_MODEL };