mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
feat(models): 添加全局 Key 白名单数据支持模型映射实时匹配
- 新增 GlobalKeyWhitelistItem 类型定义 - 路由预览 API 返回 all_keys_whitelist 字段,包含所有活跃 Provider 的 Key 白名单 - 前端 ModelMappingsTab 改用全局白名单数据进行实时匹配
This commit is contained in:
@@ -687,6 +687,18 @@ export interface RoutingProviderInfo {
|
||||
active_endpoints: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局 Key 白名单项(用于前端实时匹配)
|
||||
*/
|
||||
export interface GlobalKeyWhitelistItem {
|
||||
key_id: string
|
||||
key_name: string
|
||||
masked_key: string
|
||||
provider_id: string
|
||||
provider_name: string
|
||||
allowed_models: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 模型请求链路预览响应
|
||||
*/
|
||||
@@ -700,4 +712,5 @@ export interface ModelRoutingPreviewResponse {
|
||||
active_providers: number
|
||||
scheduling_mode: string
|
||||
priority_mode: string
|
||||
all_keys_whitelist: GlobalKeyWhitelistItem[]
|
||||
}
|
||||
|
||||
@@ -382,41 +382,36 @@ function matchPattern(pattern: string, text: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取指定映射匹配的 Key 列表
|
||||
// 获取指定映射匹配的 Key 列表(使用全局 Key 白名单数据做实时匹配)
|
||||
function getMatchedKeysForMapping(mapping: string): MatchedKeyForMapping[] {
|
||||
if (!routingData.value || !mapping.trim()) return []
|
||||
|
||||
// 使用 Map 按 keyId 去重并合并匹配结果
|
||||
const keyMap = new Map<string, MatchedKeyForMapping>()
|
||||
|
||||
for (const provider of routingData.value.providers) {
|
||||
for (const endpoint of provider.endpoints) {
|
||||
for (const key of endpoint.keys) {
|
||||
if (!key.allowed_models || key.allowed_models.length === 0) continue
|
||||
// 使用 all_keys_whitelist 进行实时匹配(包含所有 Provider 的 Key)
|
||||
for (const keyItem of routingData.value.all_keys_whitelist || []) {
|
||||
if (!keyItem.allowed_models || keyItem.allowed_models.length === 0) continue
|
||||
|
||||
const matchedModels: string[] = []
|
||||
for (const allowedModel of key.allowed_models) {
|
||||
if (matchPattern(mapping, allowedModel)) {
|
||||
matchedModels.push(allowedModel)
|
||||
}
|
||||
}
|
||||
const matchedModels: string[] = []
|
||||
for (const allowedModel of keyItem.allowed_models) {
|
||||
if (matchPattern(mapping, allowedModel)) {
|
||||
matchedModels.push(allowedModel)
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedModels.length > 0) {
|
||||
const existing = keyMap.get(key.id)
|
||||
if (existing) {
|
||||
// 合并匹配结果(去重)
|
||||
const mergedModels = new Set([...existing.matchedModels, ...matchedModels])
|
||||
existing.matchedModels = Array.from(mergedModels)
|
||||
} else {
|
||||
keyMap.set(key.id, {
|
||||
keyId: key.id,
|
||||
keyName: key.name,
|
||||
maskedKey: key.masked_key,
|
||||
providerName: provider.name,
|
||||
matchedModels,
|
||||
})
|
||||
}
|
||||
}
|
||||
if (matchedModels.length > 0) {
|
||||
const existing = keyMap.get(keyItem.key_id)
|
||||
if (existing) {
|
||||
const mergedModels = new Set([...existing.matchedModels, ...matchedModels])
|
||||
existing.matchedModels = Array.from(mergedModels)
|
||||
} else {
|
||||
keyMap.set(keyItem.key_id, {
|
||||
keyId: keyItem.key_id,
|
||||
keyName: keyItem.key_name,
|
||||
maskedKey: keyItem.masked_key,
|
||||
providerName: keyItem.provider_name,
|
||||
matchedModels,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user