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

Function sanitizeOpenAICompatibleBaseUrl

packages/core/src/utils/api.ts:258–281  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

256}
257
258function sanitizeOpenAICompatibleBaseUrl(url: string): string {
259 const trimmed = trimApiUrl(url);
260
261 try {
262 const parsed = new URL(trimmed);
263 const segments = parsed.pathname.split("/").filter(Boolean);
264
265 while (segments.length > 0) {
266 const lastSegment = segments[segments.length - 1]?.toLowerCase();
267 if (!lastSegment || !CONSOLE_PATH_SEGMENTS.has(lastSegment)) {
268 break;
269 }
270 segments.pop();
271 }
272
273 parsed.pathname = segments.length > 0 ? `/${segments.join("/")}` : "/";
274 parsed.search = "";
275 parsed.hash = "";
276
277 return trimApiUrl(parsed.toString());
278 } catch {
279 return trimmed;
280 }
281}
282
283export function providerSupportsExactRequestUrl(providerId: string): boolean {
284 return providerId !== "anthropic" && providerId !== "google";

Callers 1

resolveProviderBaseUrlFunction · 0.85

Calls 1

trimApiUrlFunction · 0.85

Tested by

no test coverage detected