refactor: optimize token limit handling and simplify API

- Initialize contextWindowSize and maxOutputTokens in contentGeneratorConfig during config resolution
- Remove third parameter from tokenLimit() function for cleaner API
- Replace all tokenLimit() calls with direct config property access for better performance
- Add maxOutputTokens field to ContentGeneratorConfig type
- Update dashscope provider to use config.maxOutputTokens
- Auto-detect token limits from model during initialization if not user-configured
- Update settingsSchema: set contextWindowSize default to undefined and showInDialog to false

Benefits:
- Token limits calculated once during initialization instead of repeatedly
- Cleaner API with fewer parameters
- Better performance by caching computed values
- User configuration takes precedence over auto-detection
- All 72 unit tests passing
This commit is contained in:
xwj02155382 2026-01-23 16:27:10 +08:00
parent 53e34cb40a
commit 3bd460a9cc
9 changed files with 86 additions and 36 deletions

View file

@ -649,12 +649,12 @@ const SETTINGS_SCHEMA = {
label: 'Context Window Size',
category: 'Generation Configuration',
requiresRestart: false,
default: -1,
default: undefined,
description:
'Override the automatic context window size detection. Set to -1 to use automatic detection based on the model. Set to a positive number to use a custom context window size.',
"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: true,
showInDialog: false,
},
},
},