mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-11 22:51:00 -07:00
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import {
|
|
IdeClient,
|
|
IdeConnectionEvent,
|
|
IdeConnectionType,
|
|
logIdeConnection,
|
|
type Config,
|
|
StartSessionEvent,
|
|
logCliConfiguration,
|
|
startupProfiler,
|
|
} from '@google/gemini-cli-core';
|
|
import { type LoadedSettings } from '../config/settings.js';
|
|
import { performInitialAuth } from './auth.js';
|
|
import { validateTheme } from './theme.js';
|
|
import type { AccountSuspensionInfo } from '../ui/contexts/UIStateContext.js';
|
|
|
|
export interface InitializationResult {
|
|
authError: string | null;
|
|
accountSuspensionInfo: AccountSuspensionInfo | null;
|
|
themeError: string | null;
|
|
shouldOpenAuthDialog: boolean;
|
|
geminiMdFileCount: number;
|
|
}
|
|
|
|
/**
|
|
* Orchestrates the application's startup initialization.
|
|
* This runs BEFORE the React UI is rendered.
|
|
* @param config The application config.
|
|
* @param settings The loaded application settings.
|
|
* @returns The results of the initialization.
|
|
*/
|
|
export async function initializeApp(
|
|
config: Config,
|
|
settings: LoadedSettings,
|
|
): Promise<InitializationResult> {
|
|
const authHandle = startupProfiler.start('authenticate');
|
|
const { authError, accountSuspensionInfo } = await performInitialAuth(
|
|
config,
|
|
settings.merged.security.auth.selectedType,
|
|
);
|
|
authHandle?.end();
|
|
const themeError = validateTheme(settings);
|
|
|
|
const shouldOpenAuthDialog =
|
|
settings.merged.security.auth.selectedType === undefined || !!authError;
|
|
|
|
logCliConfiguration(
|
|
config,
|
|
new StartSessionEvent(config, config.getToolRegistry()),
|
|
);
|
|
|
|
if (config.getIdeMode()) {
|
|
const ideClient = await IdeClient.getInstance();
|
|
await ideClient.connect();
|
|
logIdeConnection(config, new IdeConnectionEvent(IdeConnectionType.START));
|
|
}
|
|
|
|
return {
|
|
authError,
|
|
accountSuspensionInfo,
|
|
themeError,
|
|
shouldOpenAuthDialog,
|
|
geminiMdFileCount: config.getGeminiMdFileCount(),
|
|
};
|
|
}
|