(url: string)
| 245 | * "endpoint did not return JSON" error chain on connect. |
| 246 | */ |
| 247 | export function ensureUrlProtocol(url: string): string { |
| 248 | const trimmed = url.trim(); |
| 249 | if (!trimmed) return trimmed; |
| 250 | if (/^[a-z][a-z0-9+\-.]*:\/\//i.test(trimmed)) return trimmed; |
| 251 | if (trimmed.startsWith("//")) return trimmed; |
| 252 | const stripped = trimmed.replace(/^\/+/, ""); |
| 253 | const isLoopback = |
| 254 | /^(localhost(?:[:/]|$)|127\.\d+\.\d+\.\d+|0\.0\.0\.0(?:[:/]|$)|\[::1?\])/i.test(stripped); |
| 255 | return `${isLoopback ? "http://" : "https://"}${stripped}`; |
| 256 | } |
| 257 | |
| 258 | function sanitizeOpenAICompatibleBaseUrl(url: string): string { |
| 259 | const trimmed = trimApiUrl(url); |
no test coverage detected