mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 17:27:54 +00:00
feat(cli): add pro model availability check and fallback to flash (#608)
This commit is contained in:
@@ -82,29 +82,29 @@ describe('loadCliConfig', () => {
|
||||
it('should set showMemoryUsage to true when --memory flag is present', async () => {
|
||||
process.argv = ['node', 'script.js', '--show_memory_usage'];
|
||||
const settings: Settings = {};
|
||||
const config = await loadCliConfig(settings);
|
||||
expect(config.getShowMemoryUsage()).toBe(true);
|
||||
const result = await loadCliConfig(settings);
|
||||
expect(result.config.getShowMemoryUsage()).toBe(true);
|
||||
});
|
||||
|
||||
it('should set showMemoryUsage to false when --memory flag is not present', async () => {
|
||||
process.argv = ['node', 'script.js'];
|
||||
const settings: Settings = {};
|
||||
const config = await loadCliConfig(settings);
|
||||
expect(config.getShowMemoryUsage()).toBe(false);
|
||||
const result = await loadCliConfig(settings);
|
||||
expect(result.config.getShowMemoryUsage()).toBe(false);
|
||||
});
|
||||
|
||||
it('should set showMemoryUsage to false by default from settings if CLI flag is not present', async () => {
|
||||
process.argv = ['node', 'script.js'];
|
||||
const settings: Settings = { showMemoryUsage: false };
|
||||
const config = await loadCliConfig(settings);
|
||||
expect(config.getShowMemoryUsage()).toBe(false);
|
||||
const result = await loadCliConfig(settings);
|
||||
expect(result.config.getShowMemoryUsage()).toBe(false);
|
||||
});
|
||||
|
||||
it('should prioritize CLI flag over settings for showMemoryUsage (CLI true, settings false)', async () => {
|
||||
process.argv = ['node', 'script.js', '--show_memory_usage'];
|
||||
const settings: Settings = { showMemoryUsage: false };
|
||||
const config = await loadCliConfig(settings);
|
||||
expect(config.getShowMemoryUsage()).toBe(true);
|
||||
const result = await loadCliConfig(settings);
|
||||
expect(result.config.getShowMemoryUsage()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -19,6 +19,10 @@ import {
|
||||
} from '@gemini-code/core';
|
||||
import { Settings } from './settings.js';
|
||||
import { readPackageUp } from 'read-package-up';
|
||||
import {
|
||||
getEffectiveModel,
|
||||
type EffectiveModelCheckResult,
|
||||
} from '../utils/modelCheck.js';
|
||||
|
||||
// Simple console logger for now - replace with actual logger if available
|
||||
const logger = {
|
||||
@@ -30,7 +34,8 @@ const logger = {
|
||||
error: (...args: any[]) => console.error('[ERROR]', ...args),
|
||||
};
|
||||
|
||||
const DEFAULT_GEMINI_MODEL = 'gemini-2.5-pro-preview-05-06';
|
||||
export const DEFAULT_GEMINI_MODEL = 'gemini-2.5-pro-preview-05-06';
|
||||
export const DEFAULT_GEMINI_FLASH_MODEL = 'gemini-2.5-flash-preview-05-20';
|
||||
|
||||
interface CliArgs {
|
||||
model: string | undefined;
|
||||
@@ -114,7 +119,16 @@ export async function loadHierarchicalGeminiMemory(
|
||||
return loadServerHierarchicalMemory(currentWorkingDirectory, debugMode);
|
||||
}
|
||||
|
||||
export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||
export interface LoadCliConfigResult {
|
||||
config: Config;
|
||||
modelWasSwitched: boolean;
|
||||
originalModelBeforeSwitch?: string;
|
||||
finalModel: string;
|
||||
}
|
||||
|
||||
export async function loadCliConfig(
|
||||
settings: Settings,
|
||||
): Promise<LoadCliConfigResult> {
|
||||
loadEnvironment();
|
||||
|
||||
const geminiApiKey = process.env.GEMINI_API_KEY;
|
||||
@@ -164,9 +178,27 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||
const apiKeyForServer = geminiApiKey || googleApiKey || '';
|
||||
const useVertexAI = hasGeminiApiKey ? false : undefined;
|
||||
|
||||
let modelToUse = argv.model || DEFAULT_GEMINI_MODEL;
|
||||
let modelSwitched = false;
|
||||
let originalModel: string | undefined = undefined;
|
||||
|
||||
if (apiKeyForServer) {
|
||||
const checkResult: EffectiveModelCheckResult = await getEffectiveModel(
|
||||
apiKeyForServer,
|
||||
modelToUse,
|
||||
);
|
||||
if (checkResult.switched) {
|
||||
modelSwitched = true;
|
||||
originalModel = checkResult.originalModelIfSwitched;
|
||||
modelToUse = checkResult.effectiveModel;
|
||||
}
|
||||
} else {
|
||||
// logger.debug('API key not available during config load. Skipping model availability check.');
|
||||
}
|
||||
|
||||
const configParams: ConfigParameters = {
|
||||
apiKey: apiKeyForServer,
|
||||
model: argv.model || DEFAULT_GEMINI_MODEL,
|
||||
model: modelToUse,
|
||||
sandbox: argv.sandbox ?? settings.sandbox ?? argv.yolo ?? false,
|
||||
targetDir: process.cwd(),
|
||||
debugMode,
|
||||
@@ -186,7 +218,13 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||
argv.show_memory_usage || settings.showMemoryUsage || false,
|
||||
};
|
||||
|
||||
return createServerConfig(configParams);
|
||||
const config = createServerConfig(configParams);
|
||||
return {
|
||||
config,
|
||||
modelWasSwitched: modelSwitched,
|
||||
originalModelBeforeSwitch: originalModel,
|
||||
finalModel: modelToUse,
|
||||
};
|
||||
}
|
||||
|
||||
async function createUserAgent(): Promise<string> {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { MCPServerConfig } from '@gemini-code/core/src/config/config.js';
|
||||
import { MCPServerConfig } from '@gemini-code/core';
|
||||
import stripJsonComments from 'strip-json-comments';
|
||||
import { DefaultLight } from '../ui/themes/default-light.js';
|
||||
import { DefaultDark } from '../ui/themes/default.js';
|
||||
|
||||
Reference in New Issue
Block a user