review: stage1

This commit is contained in:
mingholy.lmh 2025-12-30 19:49:15 +08:00
parent 570ec432af
commit aa9cdf2a3c
10 changed files with 206 additions and 19 deletions

View file

@ -32,7 +32,7 @@ describe('validateAuthMethod', () => {
it('should return an error message for USE_OPENAI if OPENAI_API_KEY is not set', () => {
delete process.env['OPENAI_API_KEY'];
expect(validateAuthMethod(AuthType.USE_OPENAI)).toBe(
'OPENAI_API_KEY environment variable not found. You can enter it interactively or add it to your .env file.',
"Missing API key for OpenAI-compatible auth. Set settings.security.auth.apiKey, or set the 'OPENAI_API_KEY' environment variable. If you configured a model in settings.modelProviders with an envKey, set that env var as well.",
);
});

View file

@ -15,7 +15,11 @@ export function validateAuthMethod(authMethod: string): string | null {
const hasApiKey =
process.env['OPENAI_API_KEY'] || settings.merged.security?.auth?.apiKey;
if (!hasApiKey) {
return 'OPENAI_API_KEY environment variable not found. You can enter it interactively or add it to your .env file.';
return (
'Missing API key for OpenAI-compatible auth. ' +
"Set settings.security.auth.apiKey, or set the 'OPENAI_API_KEY' environment variable. " +
'If you configured a model in settings.modelProviders with an envKey, set that env var as well.'
);
}
return null;
}

View file

@ -31,6 +31,10 @@ import {
} from '@qwen-code/qwen-code-core';
import { extensionsCommand } from '../commands/extensions.js';
import type { Settings } from './settings.js';
import {
buildGenerationConfigSources,
getModelProvidersConfigFromSettings,
} from '../utils/modelProviderUtils.js';
import yargs, { type Argv } from 'yargs';
import { hideBin } from 'yargs/helpers';
import * as fs from 'node:fs';
@ -979,6 +983,18 @@ export async function loadCliConfig(
}
}
const modelProvidersConfig = getModelProvidersConfigFromSettings(settings);
const generationConfigSources = buildGenerationConfigSources({
argv: {
model: argv.model,
openaiApiKey: argv.openaiApiKey,
openaiBaseUrl: argv.openaiBaseUrl,
},
settings,
selectedAuthType,
env: process.env as Record<string, string | undefined>,
});
return new Config({
sessionId,
sessionData,
@ -1036,6 +1052,8 @@ export async function loadCliConfig(
inputFormat,
outputFormat,
includePartialMessages,
modelProvidersConfig,
generationConfigSources,
generationConfig: {
...(settings.model?.generationConfig || {}),
model: resolvedModel,

View file

@ -10,6 +10,7 @@ import type {
TelemetrySettings,
AuthType,
ChatCompressionSettings,
ModelProvidersConfig,
} from '@qwen-code/qwen-code-core';
import {
ApprovalMode,
@ -102,6 +103,19 @@ const SETTINGS_SCHEMA = {
mergeStrategy: MergeStrategy.SHALLOW_MERGE,
},
// Model providers configuration grouped by authType
modelProviders: {
type: 'object',
label: 'Model Providers',
category: 'Model',
requiresRestart: false,
default: {} as ModelProvidersConfig,
description:
'Model providers configuration grouped by authType. Each authType contains an array of model configurations.',
showInDialog: false,
mergeStrategy: MergeStrategy.SHALLOW_MERGE,
},
general: {
type: 'object',
label: 'General',