* 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)
| 157 | * Skips /v1/ (already standard) and /v2/ (Cohere convention). |
| 158 | */ |
| 159 | function 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 | |
| 179 | const GEMINI_INTERACTIONS_PATH = "/v1beta/interactions"; |
| 180 | const GEMINI_PATH_RE = /^\/v1beta\/models\/([^:]+):(generateContent|streamGenerateContent)$/; |
no test coverage detected
searching dependent graphs…