(host: string)
| 212 | const VERSION_PATTERN = /\/(v[1-9]\d*|api\/v[1-9]\d*|api\/paas\/v[1-9]\d*|compatible-mode\/v[1-9]\d*|openai\/v[1-9]\d*)$/i; |
| 213 | |
| 214 | export function formatApiHost(host: string): string { |
| 215 | if (!host) return host; |
| 216 | |
| 217 | host = ensureUrlProtocol(host.trim()); |
| 218 | |
| 219 | if (host.endsWith("/")) { |
| 220 | return host; |
| 221 | } |
| 222 | |
| 223 | for (const special of SPECIAL_HOSTS) { |
| 224 | if (host.includes(special)) { |
| 225 | return `${host}/`; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | if (VERSION_PATTERN.test(host)) { |
| 230 | return `${host}/`; |
| 231 | } |
| 232 | |
| 233 | return `${host}/v1/`; |
| 234 | } |
| 235 | |
| 236 | export function trimApiUrl(url: string): string { |
| 237 | return url.replace(/\/+$/, ""); |
no test coverage detected