MCPcopy Create free account
hub / github.com/CopilotKit/aimock / normalizeCompatPath

Function normalizeCompatPath

src/server.ts:159–177  ·  view source on GitHub ↗

* Normalize OpenAI-compatible paths with arbitrary prefixes. * Strips /openai/ prefix and rewrites paths ending in known suffixes to /v1/ . * Skips /v1/ (already standard) and /v2/ (Cohere convention).

(pathname: string, logger?: Logger)

Source from the content-addressed store, hash-verified

157 * Skips /v1/ (already standard) and /v2/ (Cohere convention).
158 */
159function normalizeCompatPath(pathname: string, logger?: Logger): string {
160 // Strip /openai/ prefix (Groq/OpenAI-compat alias)
161 if (pathname.startsWith("/openai/")) {
162 pathname = pathname.slice("/openai".length);
163 }
164
165 // Normalize arbitrary prefixes to /v1/
166 if (!pathname.startsWith("/v1/") && !pathname.startsWith("/v2/")) {
167 for (const suffix of COMPAT_SUFFIXES) {
168 if (pathname.endsWith(suffix)) {
169 if (logger) logger.debug(`Path normalized: ${pathname} → /v1${suffix}`);
170 pathname = "/v1" + suffix;
171 break;
172 }
173 }
174 }
175
176 return pathname;
177}
178
179const GEMINI_INTERACTIONS_PATH = "/v1beta/interactions";
180const GEMINI_PATH_RE = /^\/v1beta\/models\/([^:]+):(generateContent|streamGenerateContent)$/;

Callers 2

handleHttpRequestFunction · 0.85
handleUpgradeRequestFunction · 0.85

Calls 1

debugMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…