qwen-code/packages/cli/src/core/initializer.ts
pomelo 33281c8108
Merge pull request #1637 from QwenLM/fix/output-language-init-timing
fix: ensure output-language.md is created before config initialization
2026-01-29 11:14:07 +08:00

74 lines
2.1 KiB
TypeScript

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {
IdeClient,
IdeConnectionEvent,
IdeConnectionType,
logIdeConnection,
type Config,
} from '@qwen-code/qwen-code-core';
import { type LoadedSettings, SettingScope } from '../config/settings.js';
import { performInitialAuth } from './auth.js';
import { validateTheme } from './theme.js';
import { initializeI18n, type SupportedLanguage } from '../i18n/index.js';
export interface InitializationResult {
authError: string | 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> {
// Initialize i18n system
const languageSetting =
process.env['QWEN_CODE_LANG'] ||
(settings.merged.general?.language as string) ||
'auto';
await initializeI18n(languageSetting as SupportedLanguage | 'auto');
// Use authType from modelsConfig which respects CLI --auth-type argument
// over settings.security.auth.selectedType
const authType = config.getModelsConfig().getCurrentAuthType();
const authError = await performInitialAuth(config, authType);
// Fallback to user select when initial authentication fails
if (authError) {
settings.setValue(
SettingScope.User,
'security.auth.selectedType',
undefined,
);
}
const themeError = validateTheme(settings);
const shouldOpenAuthDialog =
!config.getModelsConfig().wasAuthTypeExplicitlyProvided() || !!authError;
if (config.getIdeMode()) {
const ideClient = await IdeClient.getInstance();
await ideClient.connect();
logIdeConnection(config, new IdeConnectionEvent(IdeConnectionType.START));
}
return {
authError,
themeError,
shouldOpenAuthDialog,
geminiMdFileCount: config.getGeminiMdFileCount(),
};
}