mirror of
https://github.com/fawney19/Aether.git
synced 2026-01-03 00:02:28 +08:00
- 后端添加 GET /api/admin/endpoints/keys/{key_id}/reveal 接口
- 前端密钥列表添加眼睛按钮(显示/隐藏完整密钥)和复制按钮
- 关闭抽屉时自动清除已显示的密钥(安全考虑)
Fixes #53
141 lines
4.4 KiB
TypeScript
141 lines
4.4 KiB
TypeScript
import client from '../client'
|
||
import type { EndpointAPIKey } from './types'
|
||
|
||
/**
|
||
* 能力定义类型
|
||
*/
|
||
export interface CapabilityDefinition {
|
||
name: string
|
||
display_name: string
|
||
description: string
|
||
match_mode: 'exclusive' | 'compatible'
|
||
config_mode?: 'user_configurable' | 'auto_detect' | 'request_param'
|
||
short_name?: string
|
||
}
|
||
|
||
/**
|
||
* 模型支持的能力响应类型
|
||
*/
|
||
export interface ModelCapabilitiesResponse {
|
||
model: string
|
||
global_model_id?: string
|
||
global_model_name?: string
|
||
supported_capabilities: string[]
|
||
capability_details: CapabilityDefinition[]
|
||
error?: string
|
||
}
|
||
|
||
/**
|
||
* 获取所有能力定义
|
||
*/
|
||
export async function getAllCapabilities(): Promise<CapabilityDefinition[]> {
|
||
const response = await client.get('/api/capabilities')
|
||
return response.data.capabilities
|
||
}
|
||
|
||
/**
|
||
* 获取用户可配置的能力列表
|
||
*/
|
||
export async function getUserConfigurableCapabilities(): Promise<CapabilityDefinition[]> {
|
||
const response = await client.get('/api/capabilities/user-configurable')
|
||
return response.data.capabilities
|
||
}
|
||
|
||
/**
|
||
* 获取指定模型支持的能力列表
|
||
*/
|
||
export async function getModelCapabilities(modelName: string): Promise<ModelCapabilitiesResponse> {
|
||
const response = await client.get(`/api/capabilities/model/${encodeURIComponent(modelName)}`)
|
||
return response.data
|
||
}
|
||
|
||
/**
|
||
* 获取 Endpoint 的所有 Keys
|
||
*/
|
||
export async function getEndpointKeys(endpointId: string): Promise<EndpointAPIKey[]> {
|
||
const response = await client.get(`/api/admin/endpoints/${endpointId}/keys`)
|
||
return response.data
|
||
}
|
||
|
||
/**
|
||
* 为 Endpoint 添加 Key
|
||
*/
|
||
export async function addEndpointKey(
|
||
endpointId: string,
|
||
data: {
|
||
endpoint_id: string
|
||
api_key: string
|
||
name: string // 密钥名称(必填)
|
||
rate_multiplier?: number // 成本倍率(默认 1.0)
|
||
internal_priority?: number // Endpoint 内部优先级(数字越小越优先)
|
||
max_concurrent?: number // 最大并发数(留空=自适应模式)
|
||
rate_limit?: number
|
||
daily_limit?: number
|
||
monthly_limit?: number
|
||
cache_ttl_minutes?: number // 缓存 TTL(分钟),0=禁用
|
||
max_probe_interval_minutes?: number // 熔断探测间隔(分钟)
|
||
allowed_models?: string[] // 允许使用的模型列表
|
||
capabilities?: Record<string, boolean> // 能力标签配置
|
||
note?: string // 备注说明(可选)
|
||
}
|
||
): Promise<EndpointAPIKey> {
|
||
const response = await client.post(`/api/admin/endpoints/${endpointId}/keys`, data)
|
||
return response.data
|
||
}
|
||
|
||
/**
|
||
* 更新 Endpoint Key
|
||
*/
|
||
export async function updateEndpointKey(
|
||
keyId: string,
|
||
data: Partial<{
|
||
api_key: string
|
||
name: string // 密钥名称
|
||
rate_multiplier: number // 成本倍率
|
||
internal_priority: number // Endpoint 内部优先级(提供商优先模式,数字越小越优先)
|
||
global_priority: number // 全局 Key 优先级(全局 Key 优先模式,数字越小越优先)
|
||
max_concurrent: number // 最大并发数(留空=自适应模式)
|
||
rate_limit: number
|
||
daily_limit: number
|
||
monthly_limit: number
|
||
cache_ttl_minutes: number // 缓存 TTL(分钟),0=禁用
|
||
max_probe_interval_minutes: number // 熔断探测间隔(分钟)
|
||
allowed_models: string[] | null // 允许使用的模型列表,null 表示允许所有
|
||
capabilities: Record<string, boolean> | null // 能力标签配置
|
||
is_active: boolean
|
||
note: string // 备注说明
|
||
}>
|
||
): Promise<EndpointAPIKey> {
|
||
const response = await client.put(`/api/admin/endpoints/keys/${keyId}`, data)
|
||
return response.data
|
||
}
|
||
|
||
/**
|
||
* 获取完整的 API Key(用于查看和复制)
|
||
*/
|
||
export async function revealEndpointKey(keyId: string): Promise<{ api_key: string }> {
|
||
const response = await client.get(`/api/admin/endpoints/keys/${keyId}/reveal`)
|
||
return response.data
|
||
}
|
||
|
||
/**
|
||
* 删除 Endpoint Key
|
||
*/
|
||
export async function deleteEndpointKey(keyId: string): Promise<{ message: string }> {
|
||
const response = await client.delete(`/api/admin/endpoints/keys/${keyId}`)
|
||
return response.data
|
||
}
|
||
|
||
/**
|
||
* 批量更新 Endpoint Keys 的优先级(用于拖动排序)
|
||
*/
|
||
export async function batchUpdateKeyPriority(
|
||
endpointId: string,
|
||
priorities: Array<{ key_id: string; internal_priority: number }>
|
||
): Promise<{ message: string; updated_count: number }> {
|
||
const response = await client.put(`/api/admin/endpoints/${endpointId}/keys/batch-priority`, {
|
||
priorities
|
||
})
|
||
return response.data
|
||
}
|