From 21c2abfe649b35927824683abaa1a71bd0667d30 Mon Sep 17 00:00:00 2001 From: LTbinglingfeng Date: Thu, 28 May 2026 00:35:23 +0800 Subject: [PATCH] refactor(providers): trim provider field allowlists to kebab-case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The backend emits provider config with kebab-case JSON tags only (internal/config/config.go: ClaudeKey/CodexKey/GeminiKey/OpenAICompatibility, internal/api/handlers/management/config_auth_index.go for auth-index). The camelCase / snake_case entries in PROVIDER_KEY_FIELDS, OPENAI_PROVIDER_FIELDS, MODEL_ALIAS_FIELDS, API_KEY_ENTRY_FIELDS, CLOAK_FIELDS, RESPONSE_ONLY_FIELDS were dead — same for the identity helpers and the apiKeyEntries fallback in mergeOpenAIProviderPayload. --- src/services/api/providers.ts | 65 ++++++----------------------------- 1 file changed, 10 insertions(+), 55 deletions(-) diff --git a/src/services/api/providers.ts b/src/services/api/providers.ts index 3d9ee43..1f953ea 100644 --- a/src/services/api/providers.ts +++ b/src/services/api/providers.ts @@ -22,25 +22,18 @@ const serializeHeaders = (headers?: Record) => const isRecord = (value: unknown): value is Record => value !== null && typeof value === 'object' && !Array.isArray(value); -const RESPONSE_ONLY_FIELDS = ['auth-index', 'authIndex', 'auth_index'] as const; +const RESPONSE_ONLY_FIELDS = ['auth-index'] as const; const PROVIDER_KEY_FIELDS = [ 'api-key', - 'apiKey', 'priority', 'prefix', 'base-url', - 'baseUrl', - 'base_url', 'websockets', 'proxy-url', - 'proxyUrl', - 'proxy_url', 'headers', 'models', 'excluded-models', - 'excludedModels', - 'excluded_models', 'cloak', ] as const; @@ -55,52 +48,17 @@ const OPENAI_PROVIDER_FIELDS = [ 'disabled', 'prefix', 'base-url', - 'baseUrl', - 'base_url', 'api-key-entries', - 'apiKeyEntries', - 'api_key_entries', - 'api-keys', - 'apiKeys', - 'api_keys', 'headers', 'models', 'test-model', - 'testModel', - 'test_model', ] as const; -const MODEL_ALIAS_FIELDS = [ - 'name', - 'id', - 'model', - 'alias', - 'display_name', - 'displayName', - 'priority', - 'test-model', - 'testModel', - 'test_model', -] as const; +const MODEL_ALIAS_FIELDS = ['name', 'alias', 'priority', 'test-model'] as const; -const API_KEY_ENTRY_FIELDS = [ - 'api-key', - 'apiKey', - 'key', - 'proxy-url', - 'proxyUrl', - 'proxy_url', -] as const; +const API_KEY_ENTRY_FIELDS = ['api-key', 'proxy-url'] as const; -const CLOAK_FIELDS = [ - 'mode', - 'strict-mode', - 'strictMode', - 'strict_mode', - 'sensitive-words', - 'sensitiveWords', - 'sensitive_words', -] as const; +const CLOAK_FIELDS = ['mode', 'strict-mode', 'sensitive-words'] as const; const RAW_SECTION_ALIASES: Record = { 'gemini-api-key': ['gemini-api-key', 'geminiApiKey', 'geminiApiKeys'], @@ -121,20 +79,19 @@ const getStringField = (record: Record, keys: readonly string[] }; const providerKeyIdentity = (record: Record) => { - const apiKey = getStringField(record, ['api-key', 'apiKey']); + const apiKey = getStringField(record, ['api-key']); if (!apiKey) return ''; - const baseUrl = getStringField(record, ['base-url', 'baseUrl', 'base_url']); + const baseUrl = getStringField(record, ['base-url']); return `${apiKey}\u0000${baseUrl}`; }; const openAIProviderIdentity = (record: Record) => - getStringField(record, ['name', 'id']); + getStringField(record, ['name']); -const modelIdentity = (record: Record) => - getStringField(record, ['name', 'id', 'model']); +const modelIdentity = (record: Record) => getStringField(record, ['name']); const apiKeyEntryIdentity = (record: Record) => - getStringField(record, ['api-key', 'apiKey', 'key']); + getStringField(record, ['api-key']); const cloneWithoutKnownFields = ( raw: unknown, @@ -246,9 +203,7 @@ const mergeProviderKeyPayload = ( const mergeOpenAIProviderPayload = (raw: unknown, payload: Record) => { const next = mergeKnownFields(raw, payload, OPENAI_PROVIDER_FIELDS); - const rawApiKeyEntries = isRecord(raw) - ? (raw['api-key-entries'] ?? raw.apiKeyEntries) - : undefined; + const rawApiKeyEntries = isRecord(raw) ? raw['api-key-entries'] : undefined; const apiKeyEntries = payload['api-key-entries']; if (Array.isArray(apiKeyEntries)) { next['api-key-entries'] = mergeKnownRecordList(