fix(provider): support unversioned API roots in model fetch

This commit is contained in:
zhefox
2026-05-26 15:39:56 +08:00
parent c4927162b7
commit d28a389a93
11 changed files with 525 additions and 41 deletions
@@ -15,6 +15,25 @@ function isCodexUrl(baseUrl: string): boolean {
return url.includes('/backend-api/codex') || url.endsWith('/codex')
}
function baseUrlEndsWithApiRoot(baseUrl?: string | null): boolean {
const raw = (baseUrl || '').trim()
if (!raw) return false
try {
const parsed = new URL(raw)
return parsed.pathname.replace(/\/+$/, '').toLowerCase().endsWith('/api')
} catch {
return raw.split('?')[0].replace(/\/+$/, '').toLowerCase().endsWith('/api')
}
}
function stripV1PrefixForApiRoot(path: string): string {
return path.replace(/^\/v1(?=\/)/i, '')
}
function isOpenAiCompatibleFormat(apiFormat: string): boolean {
return apiFormat.startsWith('openai:') || apiFormat.startsWith('jina:')
}
export function getDefaultEndpointPath(params: {
apiFormat: string
providerType?: string | null
@@ -43,5 +62,8 @@ export function getDefaultEndpointPath(params: {
if (normalizedApiFormat === 'openai:responses' && isCodex) {
return '/responses'
}
if (baseUrlEndsWithApiRoot(params.baseUrl) && isOpenAiCompatibleFormat(normalizedApiFormat)) {
return stripV1PrefixForApiRoot(defaultPath)
}
return defaultPath
}