fix(provider): count inherited endpoint formats for model tests

This commit is contained in:
ZheFox
2026-05-17 18:04:16 +08:00
parent ab0d766f47
commit 485d166912
8 changed files with 257 additions and 12 deletions

View File

@@ -441,9 +441,10 @@ const activeEndpoints = computed(() => (props.endpoints ?? [])
if (typeof endpoint.active_keys === 'number') {
return endpoint.is_active !== false
&& isModelTestableApiFormat(endpoint.api_format)
&& endpoint.active_keys > 0
&& (endpoint.active_keys > 0
|| isModelTestableEndpoint(endpoint, providerKeysState.value, props.provider.provider_type))
}
return isModelTestableEndpoint(endpoint, providerKeysState.value)
return isModelTestableEndpoint(endpoint, providerKeysState.value, props.provider.provider_type)
}))
const selectableTestEndpoints = computed(() => mappingTestEndpoints.value ?? activeEndpoints.value)
const parsedTestRequestHeaders = computed(() => parseModelTestRequestHeadersDraft(testRequestHeadersDraft.value))

View File

@@ -312,9 +312,10 @@ const activeEndpoints = computed(() => (props.endpoints ?? [])
if (typeof endpoint.active_keys === 'number') {
return endpoint.is_active !== false
&& isModelTestableApiFormat(endpoint.api_format)
&& endpoint.active_keys > 0
&& (endpoint.active_keys > 0
|| isModelTestableEndpoint(endpoint, props.providerKeys ?? [], props.provider.provider_type))
}
return isModelTestableEndpoint(endpoint, props.providerKeys ?? [])
return isModelTestableEndpoint(endpoint, props.providerKeys ?? [], props.provider.provider_type)
}))
const parsedTestRequestHeaders = computed(() => parseModelTestRequestHeadersDraft(testRequestHeadersDraft.value))
const testRequestHeadersError = computed(() => parsedTestRequestHeaders.value.error)

View File

@@ -55,6 +55,19 @@ describe('buildDefaultModelTestRequestBody', () => {
expect(body.input).toBeUndefined()
})
it('uses image prompt payloads for OpenAI image test requests', () => {
const body = JSON.parse(buildDefaultModelTestRequestBody('gpt-image-2', 'openai:image'))
expect(body).toEqual({
model: 'gpt-image-2',
prompt: 'Hello! This is a test message.',
n: 1,
size: '1024x1024',
stream: true,
})
expect(body.messages).toBeUndefined()
})
it('lists endpoint-scoped provider model mappings in test selection order', () => {
const options = listModelTestMappedModelOptions({
provider_model_name: 'claude-opus-4-6',
@@ -202,6 +215,8 @@ describe('isModelTestableApiFormat', () => {
it.each([
'openai:chat',
'openai:responses',
'openai:responses:compact',
'openai:image',
'claude:messages',
'gemini:generate_content',
'openai:embedding',
@@ -242,6 +257,23 @@ describe('isModelTestableEndpoint', () => {
is_active: true,
}, keys)).toBe(true)
})
it('lets fixed provider OAuth keys inherit testable endpoint formats', () => {
const keys = [{
api_formats: ['legacy:mismatch'],
auth_type: 'oauth',
is_active: true,
}]
expect(isModelTestableEndpoint({
api_format: 'openai:image',
is_active: true,
}, keys, 'chatgpt_web')).toBe(true)
expect(isModelTestableEndpoint({
api_format: 'openai:image',
is_active: true,
}, keys, 'custom')).toBe(false)
})
})
describe('formatModelTestDiagnostic', () => {

View File

@@ -23,6 +23,9 @@ type ModelTestEndpointSource = {
type ModelTestKeySource = {
api_formats?: string[] | null
is_active?: boolean | null
auth_type?: string | null
credential_kind?: string | null
oauth_managed?: boolean | null
}
export type ModelTestMappedModelOption = {
@@ -36,6 +39,20 @@ const MODEL_TEST_UNSUPPORTED_API_FORMATS = new Set([
'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> = {
pool_account_blocked: '账号已失效,需重新授权',
}
@@ -50,12 +67,15 @@ export function isModelTestableApiFormat(apiFormat: string | null | undefined):
export function modelTestKeySupportsEndpoint(
key: ModelTestKeySource,
endpoint: ModelTestEndpointSource,
providerType?: string | null,
): boolean {
if (key.is_active === false) return false
const endpointFormat = normalizeApiFormatAlias(endpoint.api_format)
if (!isModelTestableApiFormat(endpointFormat)) return false
if (modelTestKeyInheritsProviderFormats(key, providerType)) return true
const keyFormats = normalizeStringList(key.api_formats ?? undefined)
if (keyFormats.length === 0) return true
@@ -65,10 +85,11 @@ export function modelTestKeySupportsEndpoint(
export function isModelTestableEndpoint(
endpoint: ModelTestEndpointSource,
keys: ModelTestKeySource[],
providerType?: string | null,
): boolean {
return endpoint.is_active !== false
&& isModelTestableApiFormat(endpoint.api_format)
&& keys.some(key => modelTestKeySupportsEndpoint(key, endpoint))
&& keys.some(key => modelTestKeySupportsEndpoint(key, endpoint, providerType))
}
export function formatModelTestDiagnostic(value: string | null | undefined): string {
@@ -96,6 +117,27 @@ function normalizeStringList(values: string[] | undefined): string[] {
.filter(Boolean)
}
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)
}
function isJsonRecord(value: unknown): value is JsonRecord {
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
}
@@ -409,14 +451,16 @@ export function buildExactModelMappingTestRequest(
}
export function buildDefaultModelTestRequestBody(modelName: string, apiFormat?: string | null): string {
if (apiFormat?.trim().toLowerCase().endsWith(':embedding')) {
const normalizedApiFormat = normalizeApiFormatAlias(apiFormat ?? '')
if (normalizedApiFormat.endsWith(':embedding')) {
return JSON.stringify({
model: modelName,
input: 'This is a test embedding input.',
}, null, 2)
}
if (apiFormat?.trim().toLowerCase().endsWith(':rerank')) {
if (normalizedApiFormat.endsWith(':rerank')) {
return JSON.stringify({
model: modelName,
query: 'Apple',
@@ -431,6 +475,16 @@ export function buildDefaultModelTestRequestBody(modelName: string, apiFormat?:
}, null, 2)
}
if (normalizedApiFormat === 'openai:image') {
return JSON.stringify({
model: modelName,
prompt: DEFAULT_MODEL_TEST_MESSAGE,
n: 1,
size: '1024x1024',
stream: true,
}, null, 2)
}
return JSON.stringify({
model: modelName,
messages: [