Address code review feedback: Improve URL normalization and remove duplication

Co-authored-by: Siumauricio <47042324+Siumauricio@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-20 06:48:47 +00:00
parent 2f9987970a
commit 136edfd4c5
3 changed files with 25 additions and 18 deletions

View File

@@ -13,14 +13,11 @@ import { createOllama } from "ai-sdk-ollama";
* to avoid duplicate paths in the final URL (e.g., /v1/v1/chat/completions)
*/
export function normalizeAzureUrl(url: string): string {
let normalized = url;
// Remove trailing /openai/v1 if present
normalized = normalized.replace(/\/openai\/v1\/?$/, "");
// Remove trailing /v1 if present
normalized = normalized.replace(/\/v1\/?$/, "");
// Remove trailing slash
normalized = normalized.replace(/\/$/, "");
return normalized;
// Use a single regex to handle all variations in one pass
// This matches: /openai/v1 or /v1 at the end, with optional trailing slash
let normalized = url.replace(/\/(?:openai\/v1|v1)\/?$/, "");
// Remove any remaining trailing slash
return normalized.replace(/\/$/, "");
}
export function getProviderName(apiUrl: string) {