refactor(types): tighten PluginSettings.backend to union literal

backend is constrained to 'api' | 'claude-code' | 'codex'; normalizeSettings
migrates the old 'anthropic-api' value and rejects unknown strings at runtime.

https://claude.ai/code/session_012cK5rUGQvqkuxUZ59x7dLn
This commit is contained in:
Claude 2026-04-29 08:05:25 +00:00
parent ceea8d6ff0
commit f9c5ca0781
No known key found for this signature in database
3 changed files with 7 additions and 3 deletions

View file

@ -83,7 +83,7 @@ export class ParallelReaderSettingTab extends PluginSettingTab {
.addOption('codex', 'Codex CLI')
.setValue(this.plugin.settings.backend)
.onChange(async (v) => {
this.plugin.settings.backend = v;
this.plugin.settings.backend = v as PluginSettings['backend'];
if (v === 'api' && !this.plugin.settings.apiBaseUrl) {
this.plugin.settings = applyApiProviderPreset(
this.plugin.settings,

View file

@ -193,12 +193,16 @@ export function normalizeSettings(settings: Readonly<PluginSettings>): PluginSet
const preset = getApiPreset(out);
if (!out.apiFormat || !API_FORMATS[out.apiFormat]) out.apiFormat = preset.format;
if (!out.apiAuthType || !(API_AUTH_TYPES as Record<string, string>)[out.apiAuthType]) out.apiAuthType = 'auto';
if (out.backend === 'anthropic-api') {
const rawBackend = out.backend as string;
if (rawBackend === 'anthropic-api') {
out.backend = 'api';
out.apiProvider = out.apiProvider || 'anthropic';
out.apiFormat = out.apiFormat || 'anthropic-messages';
out.apiBaseUrl = out.apiBaseUrl || API_PROVIDER_PRESETS.anthropic.baseUrl;
out.apiAuthType = out.apiAuthType || 'x-api-key';
out.apiKeyEnvVar = out.apiKeyEnvVar || 'ANTHROPIC_API_KEY';
} else if (!(['api', 'claude-code', 'codex'] as string[]).includes(rawBackend)) {
out.backend = DEFAULT_SETTINGS.backend;
}
const n = Number(out.apiMaxTokens);
if (!Number.isFinite(n) || n <= 0) out.apiMaxTokens = DEFAULT_SETTINGS.apiMaxTokens;

View file

@ -46,7 +46,7 @@ export interface CacheFile {
export interface PluginSettings {
uiLanguage: string;
backend: string;
backend: 'api' | 'claude-code' | 'codex';
cliPath: string;
apiProvider: string;
apiFormat: string;