refactor: improve config consistency and token limits

- Remove legacy childKey field from settingsSchema

- Add contextWindowSize and maxOutputTokens to documentation

- Refactor ContextUsageDisplay to accept contextWindowSize directly instead of Config object

- Add useMemo optimization for contextWindowSize in Footer component

- Fix logic gaps in contentGenerator for contextWindowSize and maxOutputTokens initialization

- Increase DEFAULT_OUTPUT_TOKEN_LIMIT from 4K to 8K for better usability

- Add fallback to default values when model is not available
This commit is contained in:
xwj02155382 2026-01-26 10:26:44 +08:00
parent 25a1bbad45
commit f9db8d5a73
5 changed files with 64 additions and 45 deletions

View file

@ -69,7 +69,6 @@ export interface SettingDefinition {
default: SettingsValue;
description?: string;
parentKey?: string;
childKey?: string;
key?: string;
properties?: SettingsSchema;
showInDialog?: boolean;
@ -603,7 +602,6 @@ const SETTINGS_SCHEMA = {
default: undefined as number | undefined,
description: 'Request timeout in milliseconds.',
parentKey: 'generationConfig',
childKey: 'timeout',
showInDialog: false,
},
maxRetries: {
@ -614,7 +612,6 @@ const SETTINGS_SCHEMA = {
default: undefined as number | undefined,
description: 'Maximum number of retries for failed requests.',
parentKey: 'generationConfig',
childKey: 'maxRetries',
showInDialog: false,
},
disableCacheControl: {
@ -625,7 +622,6 @@ const SETTINGS_SCHEMA = {
default: false,
description: 'Disable cache control for DashScope providers.',
parentKey: 'generationConfig',
childKey: 'disableCacheControl',
showInDialog: false,
},
schemaCompliance: {
@ -637,7 +633,6 @@ const SETTINGS_SCHEMA = {
description:
'The compliance mode for tool schemas sent to the model. Use "openapi_30" for strict OpenAPI 3.0 compatibility (e.g., for Gemini).',
parentKey: 'generationConfig',
childKey: 'schemaCompliance',
showInDialog: false,
options: [
{ value: 'auto', label: 'Auto (Default)' },
@ -653,7 +648,6 @@ const SETTINGS_SCHEMA = {
description:
"Overrides the default context window size for the selected model. Use this setting when a provider's effective context limit differs from Qwen Code's default. This value defines the model's assumed maximum context capacity, not a per-request token limit.",
parentKey: 'generationConfig',
childKey: 'contextWindowSize',
showInDialog: false,
},
},

View file

@ -6,26 +6,22 @@
import { Text } from 'ink';
import { theme } from '../semantic-colors.js';
import { DEFAULT_TOKEN_LIMIT, type Config } from '@qwen-code/qwen-code-core';
import { DEFAULT_TOKEN_LIMIT } from '@qwen-code/qwen-code-core';
export const ContextUsageDisplay = ({
promptTokenCount,
model: _model,
terminalWidth,
config,
contextWindowSize,
}: {
promptTokenCount: number;
model: string;
terminalWidth: number;
config: Config;
contextWindowSize?: number;
}) => {
if (promptTokenCount === 0) {
return null;
}
const contextLimit =
config.getContentGeneratorConfig()?.contextWindowSize ??
DEFAULT_TOKEN_LIMIT;
const contextLimit = contextWindowSize ?? DEFAULT_TOKEN_LIMIT;
const percentage = promptTokenCount / contextLimit;
const percentageUsed = (percentage * 100).toFixed(1);

View file

@ -5,6 +5,7 @@
*/
import type React from 'react';
import { useMemo } from 'react';
import { Box, Text } from 'ink';
import { theme } from '../semantic-colors.js';
import { ConsoleSummaryDisplay } from './ConsoleSummaryDisplay.js';
@ -57,6 +58,12 @@ export const Footer: React.FC = () => {
// Check if debug mode is enabled
const debugMode = config.getDebugMode();
// Memoize contextWindowSize to avoid recalculating on every render
const contextWindowSize = useMemo(
() => config.getContentGeneratorConfig()?.contextWindowSize,
[config]
);
// Left section should show exactly ONE thing at any time, in priority order.
const leftContent = uiState.ctrlCPressedOnce ? (
<Text color={theme.status.warning}>{t('Press Ctrl+C again to exit.')}</Text>
@ -95,9 +102,8 @@ export const Footer: React.FC = () => {
<Text color={theme.text.accent}>
<ContextUsageDisplay
promptTokenCount={promptTokenCount}
model={model}
terminalWidth={terminalWidth}
config={config}
contextWindowSize={contextWindowSize}
/>
</Text>
),