mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
refactor(providers): trim provider field allowlists to kebab-case
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.
This commit is contained in:
@@ -22,25 +22,18 @@ const serializeHeaders = (headers?: Record<string, string>) =>
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
||||
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<string, readonly string[]> = {
|
||||
'gemini-api-key': ['gemini-api-key', 'geminiApiKey', 'geminiApiKeys'],
|
||||
@@ -121,20 +79,19 @@ const getStringField = (record: Record<string, unknown>, keys: readonly string[]
|
||||
};
|
||||
|
||||
const providerKeyIdentity = (record: Record<string, unknown>) => {
|
||||
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<string, unknown>) =>
|
||||
getStringField(record, ['name', 'id']);
|
||||
getStringField(record, ['name']);
|
||||
|
||||
const modelIdentity = (record: Record<string, unknown>) =>
|
||||
getStringField(record, ['name', 'id', 'model']);
|
||||
const modelIdentity = (record: Record<string, unknown>) => getStringField(record, ['name']);
|
||||
|
||||
const apiKeyEntryIdentity = (record: Record<string, unknown>) =>
|
||||
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<string, unknown>) => {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user