All files / lib ollama-url.ts

0% Statements 0/16
0% Branches 0/10
0% Functions 0/1
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                                   
export function normalizeOllamaBaseUrl(rawUrl?: string): string | null {
  const trimmed = rawUrl?.trim();
  if (!trimmed) return null;
 
  try {
    const url = new URL(trimmed);
    if (!["http:", "https:"].includes(url.protocol)) {
      return null;
    }
 
    const normalizedPath = url.pathname.replace(/\/+$/, "");
 
    if (!normalizedPath || normalizedPath === "/") {
      url.pathname = "/v1";
    } else if (!normalizedPath.endsWith("/v1")) {
      url.pathname = `${normalizedPath}/v1`;
    } else {
      url.pathname = normalizedPath;
    }
 
    return url.toString();
  } catch {
    return null;
  }
}