MCPcopy
hub / github.com/codedogQBY/ReadAny / resolveProviderBaseUrl

Function resolveProviderBaseUrl

packages/core/src/utils/api.ts:287–311  ·  view source on GitHub ↗
(
  providerId: string,
  baseUrl?: string,
  exactRequestUrl = false,
)

Source from the content-addressed store, hash-verified

285}
286
287export 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
313export function buildProviderModelsUrl(
314 providerId: string,

Callers 5

api.test.tsFile · 0.90
testGoogleFunction · 0.90
buildProviderModelsUrlFunction · 0.85
buildOpenAICompatibleUrlFunction · 0.85

Calls 7

ensureUrlProtocolFunction · 0.85
getDefaultBaseUrlFunction · 0.85
getProviderConfigFunction · 0.85
trimApiUrlFunction · 0.85
formatApiHostFunction · 0.85

Tested by

no test coverage detected