mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
fix(frontend): preserve fixed provider model test key inheritance
This commit is contained in:
@@ -15,6 +15,9 @@ export type ModelTestImageSource = {
|
|||||||
export type ModelTestKeySource = {
|
export type ModelTestKeySource = {
|
||||||
api_formats?: string[] | null
|
api_formats?: string[] | null
|
||||||
is_active?: boolean | null
|
is_active?: boolean | null
|
||||||
|
auth_type?: string | null
|
||||||
|
credential_kind?: string | null
|
||||||
|
oauth_managed?: boolean | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const MODEL_TEST_UNSUPPORTED_API_FORMATS = new Set([
|
const MODEL_TEST_UNSUPPORTED_API_FORMATS = new Set([
|
||||||
@@ -23,6 +26,20 @@ const MODEL_TEST_UNSUPPORTED_API_FORMATS = new Set([
|
|||||||
'gemini:files',
|
'gemini:files',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const MODEL_TEST_OAUTH_INHERITS_PROVIDER_FORMATS = new Set([
|
||||||
|
'claude_code',
|
||||||
|
'codex',
|
||||||
|
'chatgpt_web',
|
||||||
|
'gemini_cli',
|
||||||
|
'vertex_ai',
|
||||||
|
'antigravity',
|
||||||
|
'kiro',
|
||||||
|
])
|
||||||
|
|
||||||
|
const MODEL_TEST_BEARER_INHERITS_PROVIDER_FORMATS = new Set([
|
||||||
|
'chatgpt_web',
|
||||||
|
])
|
||||||
|
|
||||||
const MODEL_TEST_DIAGNOSTIC_LABELS: Record<string, string> = {
|
const MODEL_TEST_DIAGNOSTIC_LABELS: Record<string, string> = {
|
||||||
pool_account_blocked: '账号已失效,需重新授权',
|
pool_account_blocked: '账号已失效,需重新授权',
|
||||||
}
|
}
|
||||||
@@ -41,12 +58,15 @@ export function isModelTestableApiFormat(apiFormat: string | null | undefined):
|
|||||||
export function modelTestKeySupportsEndpoint(
|
export function modelTestKeySupportsEndpoint(
|
||||||
key: ModelTestKeySource,
|
key: ModelTestKeySource,
|
||||||
endpoint: ModelTestEndpointSource,
|
endpoint: ModelTestEndpointSource,
|
||||||
|
providerType?: string | null,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (key.is_active === false) return false
|
if (key.is_active === false) return false
|
||||||
|
|
||||||
const endpointFormat = normalizeApiFormatAlias(endpoint.api_format)
|
const endpointFormat = normalizeApiFormatAlias(endpoint.api_format)
|
||||||
if (!isModelTestableApiFormat(endpointFormat)) return false
|
if (!isModelTestableApiFormat(endpointFormat)) return false
|
||||||
|
|
||||||
|
if (modelTestKeyInheritsProviderFormats(key, providerType)) return true
|
||||||
|
|
||||||
const keyFormats = normalizeModelTestStringList(key.api_formats)
|
const keyFormats = normalizeModelTestStringList(key.api_formats)
|
||||||
if (keyFormats.length === 0) return true
|
if (keyFormats.length === 0) return true
|
||||||
|
|
||||||
@@ -56,10 +76,32 @@ export function modelTestKeySupportsEndpoint(
|
|||||||
export function isModelTestableEndpoint(
|
export function isModelTestableEndpoint(
|
||||||
endpoint: ModelTestEndpointSource,
|
endpoint: ModelTestEndpointSource,
|
||||||
keys: ModelTestKeySource[],
|
keys: ModelTestKeySource[],
|
||||||
|
providerType?: string | null,
|
||||||
): boolean {
|
): boolean {
|
||||||
return endpoint.is_active !== false
|
return endpoint.is_active !== false
|
||||||
&& isModelTestableApiFormat(endpoint.api_format)
|
&& isModelTestableApiFormat(endpoint.api_format)
|
||||||
&& keys.some(key => modelTestKeySupportsEndpoint(key, endpoint))
|
&& keys.some(key => modelTestKeySupportsEndpoint(key, endpoint, providerType))
|
||||||
|
}
|
||||||
|
|
||||||
|
function modelTestKeyInheritsProviderFormats(
|
||||||
|
key: ModelTestKeySource,
|
||||||
|
providerType: string | null | undefined,
|
||||||
|
): boolean {
|
||||||
|
const normalizedProviderType = providerType?.trim().toLowerCase()
|
||||||
|
if (!normalizedProviderType) return false
|
||||||
|
|
||||||
|
const authType = key.auth_type?.trim().toLowerCase()
|
||||||
|
const credentialKind = key.credential_kind?.trim().toLowerCase()
|
||||||
|
const oauthManaged = key.oauth_managed === true
|
||||||
|
|| credentialKind === 'oauth_session'
|
||||||
|
|| authType === 'oauth'
|
||||||
|
|
||||||
|
if (oauthManaged && MODEL_TEST_OAUTH_INHERITS_PROVIDER_FORMATS.has(normalizedProviderType)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return authType === 'bearer'
|
||||||
|
&& MODEL_TEST_BEARER_INHERITS_PROVIDER_FORMATS.has(normalizedProviderType)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectPreferredModelTestEndpoint<T extends ModelTestEndpointSource>(
|
export function selectPreferredModelTestEndpoint<T extends ModelTestEndpointSource>(
|
||||||
|
|||||||
Reference in New Issue
Block a user