( providerId: string, baseUrl?: string, exactRequestUrl = false, )
| 285 | } |
| 286 | |
| 287 | export function resolveProviderBaseUrl( |
| 288 | providerId: string, |
| 289 | baseUrl?: string, |
| 290 | exactRequestUrl = false, |
| 291 | ): string { |
| 292 | const rawBaseUrl = ensureUrlProtocol((baseUrl || getDefaultBaseUrl(providerId) || "").trim()); |
| 293 | if (!rawBaseUrl) return ""; |
| 294 | const providerConfig = getProviderConfig(providerId); |
| 295 | const trimmedRawBaseUrl = trimApiUrl(rawBaseUrl); |
| 296 | const rawLastSegment = trimmedRawBaseUrl.split("/").filter(Boolean).pop()?.toLowerCase(); |
| 297 | |
| 298 | if (exactRequestUrl && providerSupportsExactRequestUrl(providerId)) { |
| 299 | return rawBaseUrl; |
| 300 | } |
| 301 | |
| 302 | if (!providerConfig.needsV1Suffix) { |
| 303 | return trimApiUrl(rawBaseUrl); |
| 304 | } |
| 305 | |
| 306 | if (rawBaseUrl.endsWith("/") && (!rawLastSegment || !CONSOLE_PATH_SEGMENTS.has(rawLastSegment))) { |
| 307 | return trimApiUrl(rawBaseUrl); |
| 308 | } |
| 309 | |
| 310 | return trimApiUrl(formatApiHost(sanitizeOpenAICompatibleBaseUrl(rawBaseUrl))); |
| 311 | } |
| 312 | |
| 313 | export function buildProviderModelsUrl( |
| 314 | providerId: string, |
no test coverage detected