mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 19:30:51 +08:00
feat: add vertex provider, oauth model mappings, and routing/log settings
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
import { apiClient } from './client';
|
||||
import type { AuthFilesResponse } from '@/types/authFile';
|
||||
import type { OAuthModelMappingEntry } from '@/types';
|
||||
|
||||
export const authFilesApi = {
|
||||
list: () => apiClient.get<AuthFilesResponse>('/auth-files'),
|
||||
@@ -31,6 +32,37 @@ export const authFilesApi = {
|
||||
deleteOauthExcludedEntry: (provider: string) =>
|
||||
apiClient.delete(`/oauth-excluded-models?provider=${encodeURIComponent(provider)}`),
|
||||
|
||||
// OAuth 模型映射
|
||||
async getOauthModelMappings(): Promise<Record<string, OAuthModelMappingEntry[]>> {
|
||||
const data = await apiClient.get('/oauth-model-mappings');
|
||||
const payload = (data && (data['oauth-model-mappings'] ?? data.items ?? data)) as any;
|
||||
if (!payload || typeof payload !== 'object') return {};
|
||||
const result: Record<string, OAuthModelMappingEntry[]> = {};
|
||||
Object.entries(payload).forEach(([channel, mappings]) => {
|
||||
if (!Array.isArray(mappings)) return;
|
||||
const normalized = mappings
|
||||
.map((item) => {
|
||||
if (!item || typeof item !== 'object') return null;
|
||||
const name = String(item.name ?? item.id ?? item.model ?? '').trim();
|
||||
const alias = String(item.alias ?? '').trim();
|
||||
if (!name || !alias) return null;
|
||||
const fork = item.fork === true;
|
||||
return fork ? { name, alias, fork } : { name, alias };
|
||||
})
|
||||
.filter(Boolean) as OAuthModelMappingEntry[];
|
||||
if (normalized.length) {
|
||||
result[channel] = normalized;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
},
|
||||
|
||||
saveOauthModelMappings: (channel: string, mappings: OAuthModelMappingEntry[]) =>
|
||||
apiClient.patch('/oauth-model-mappings', { channel, mappings }),
|
||||
|
||||
deleteOauthModelMappings: (channel: string) =>
|
||||
apiClient.delete(`/oauth-model-mappings?channel=${encodeURIComponent(channel)}`),
|
||||
|
||||
// 获取认证凭证支持的模型
|
||||
async getModelsForAuthFile(name: string): Promise<{ id: string; display_name?: string; type?: string; owned_by?: string }[]> {
|
||||
const data = await apiClient.get(`/auth-files/models?name=${encodeURIComponent(name)}`);
|
||||
|
||||
@@ -68,8 +68,48 @@ export const configApi = {
|
||||
*/
|
||||
updateLoggingToFile: (enabled: boolean) => apiClient.put('/logging-to-file', { value: enabled }),
|
||||
|
||||
/**
|
||||
* 获取日志总大小上限(MB)
|
||||
*/
|
||||
async getLogsMaxTotalSizeMb(): Promise<number> {
|
||||
const data = await apiClient.get('/logs-max-total-size-mb');
|
||||
return data?.['logs-max-total-size-mb'] ?? data?.logsMaxTotalSizeMb ?? 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新日志总大小上限(MB)
|
||||
*/
|
||||
updateLogsMaxTotalSizeMb: (value: number) =>
|
||||
apiClient.put('/logs-max-total-size-mb', { value }),
|
||||
|
||||
/**
|
||||
* WebSocket 鉴权开关
|
||||
*/
|
||||
updateWsAuth: (enabled: boolean) => apiClient.put('/ws-auth', { value: enabled }),
|
||||
|
||||
/**
|
||||
* 获取强制模型前缀开关
|
||||
*/
|
||||
async getForceModelPrefix(): Promise<boolean> {
|
||||
const data = await apiClient.get('/force-model-prefix');
|
||||
return data?.['force-model-prefix'] ?? data?.forceModelPrefix ?? false;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新强制模型前缀开关
|
||||
*/
|
||||
updateForceModelPrefix: (enabled: boolean) => apiClient.put('/force-model-prefix', { value: enabled }),
|
||||
|
||||
/**
|
||||
* 获取路由策略
|
||||
*/
|
||||
async getRoutingStrategy(): Promise<string> {
|
||||
const data = await apiClient.get('/routing/strategy');
|
||||
return data?.strategy ?? data?.['routing-strategy'] ?? data?.routingStrategy ?? 'round-robin';
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新路由策略
|
||||
*/
|
||||
updateRoutingStrategy: (strategy: string) => apiClient.put('/routing/strategy', { value: strategy }),
|
||||
};
|
||||
|
||||
@@ -61,6 +61,30 @@ const serializeProviderKey = (config: ProviderKeyConfig) => {
|
||||
return payload;
|
||||
};
|
||||
|
||||
const serializeVertexModelAliases = (models?: ModelAlias[]) =>
|
||||
Array.isArray(models)
|
||||
? models
|
||||
.map((model) => {
|
||||
const name = typeof model?.name === 'string' ? model.name.trim() : '';
|
||||
const alias = typeof model?.alias === 'string' ? model.alias.trim() : '';
|
||||
if (!name || !alias) return null;
|
||||
return { name, alias };
|
||||
})
|
||||
.filter(Boolean)
|
||||
: undefined;
|
||||
|
||||
const serializeVertexKey = (config: ProviderKeyConfig) => {
|
||||
const payload: Record<string, any> = { 'api-key': config.apiKey };
|
||||
if (config.prefix?.trim()) payload.prefix = config.prefix.trim();
|
||||
if (config.baseUrl) payload['base-url'] = config.baseUrl;
|
||||
if (config.proxyUrl) payload['proxy-url'] = config.proxyUrl;
|
||||
const headers = serializeHeaders(config.headers);
|
||||
if (headers) payload.headers = headers;
|
||||
const models = serializeVertexModelAliases(config.models);
|
||||
if (models && models.length) payload.models = models;
|
||||
return payload;
|
||||
};
|
||||
|
||||
const serializeGeminiKey = (config: GeminiKeyConfig) => {
|
||||
const payload: Record<string, any> = { 'api-key': config.apiKey };
|
||||
if (config.prefix?.trim()) payload.prefix = config.prefix.trim();
|
||||
@@ -140,6 +164,22 @@ export const providersApi = {
|
||||
deleteClaudeConfig: (apiKey: string) =>
|
||||
apiClient.delete(`/claude-api-key?api-key=${encodeURIComponent(apiKey)}`),
|
||||
|
||||
async getVertexConfigs(): Promise<ProviderKeyConfig[]> {
|
||||
const data = await apiClient.get('/vertex-api-key');
|
||||
const list = (data && (data['vertex-api-key'] ?? data.items ?? data)) as any;
|
||||
if (!Array.isArray(list)) return [];
|
||||
return list.map((item) => normalizeProviderKeyConfig(item)).filter(Boolean) as ProviderKeyConfig[];
|
||||
},
|
||||
|
||||
saveVertexConfigs: (configs: ProviderKeyConfig[]) =>
|
||||
apiClient.put('/vertex-api-key', configs.map((item) => serializeVertexKey(item))),
|
||||
|
||||
updateVertexConfig: (index: number, value: ProviderKeyConfig) =>
|
||||
apiClient.patch('/vertex-api-key', { index, value: serializeVertexKey(value) }),
|
||||
|
||||
deleteVertexConfig: (apiKey: string) =>
|
||||
apiClient.delete(`/vertex-api-key?api-key=${encodeURIComponent(apiKey)}`),
|
||||
|
||||
async getOpenAIProviders(): Promise<OpenAIProviderConfig[]> {
|
||||
const data = await apiClient.get('/openai-compatibility');
|
||||
const list = (data && (data['openai-compatibility'] ?? data.items ?? data)) as any;
|
||||
|
||||
@@ -258,7 +258,15 @@ export const normalizeConfigResponse = (raw: any): Config => {
|
||||
config.usageStatisticsEnabled = raw['usage-statistics-enabled'] ?? raw.usageStatisticsEnabled;
|
||||
config.requestLog = raw['request-log'] ?? raw.requestLog;
|
||||
config.loggingToFile = raw['logging-to-file'] ?? raw.loggingToFile;
|
||||
config.logsMaxTotalSizeMb = raw['logs-max-total-size-mb'] ?? raw.logsMaxTotalSizeMb;
|
||||
config.wsAuth = raw['ws-auth'] ?? raw.wsAuth;
|
||||
config.forceModelPrefix = raw['force-model-prefix'] ?? raw.forceModelPrefix;
|
||||
const routing = raw.routing;
|
||||
if (routing && typeof routing === 'object') {
|
||||
config.routingStrategy = routing.strategy ?? routing['strategy'];
|
||||
} else {
|
||||
config.routingStrategy = raw['routing-strategy'] ?? raw.routingStrategy;
|
||||
}
|
||||
config.apiKeys = Array.isArray(raw['api-keys']) ? raw['api-keys'].slice() : raw.apiKeys;
|
||||
|
||||
const geminiList = raw['gemini-api-key'] ?? raw.geminiApiKey ?? raw.geminiApiKeys;
|
||||
@@ -282,6 +290,13 @@ export const normalizeConfigResponse = (raw: any): Config => {
|
||||
.filter(Boolean) as ProviderKeyConfig[];
|
||||
}
|
||||
|
||||
const vertexList = raw['vertex-api-key'] ?? raw.vertexApiKey ?? raw.vertexApiKeys;
|
||||
if (Array.isArray(vertexList)) {
|
||||
config.vertexApiKeys = vertexList
|
||||
.map((item: any) => normalizeProviderKeyConfig(item))
|
||||
.filter(Boolean) as ProviderKeyConfig[];
|
||||
}
|
||||
|
||||
const openaiList = raw['openai-compatibility'] ?? raw.openaiCompatibility ?? raw.openAICompatibility;
|
||||
if (Array.isArray(openaiList)) {
|
||||
config.openaiCompatibility = openaiList
|
||||
|
||||
Reference in New Issue
Block a user