Files
OmniRoute/open-sse/executors/default/urlNormalizers.ts
Diego Rodrigues de Sa e Souza fa51354e35 refactor(executors): extract pure URL normalizers from default (#6015)
Extract the pure per-provider chat-URL normalizers (normalizeBailianMessagesUrl,
normalizeDataRobotChatUrl, normalizeAzureAiChatUrl, normalizeWatsonxChatUrl,
normalizeOciChatUrl, normalizeSapChatUrl, normalizeXiaomiMimoChatUrl,
normalizeOpenAIChatUrl, getOpenRouterConnectionPreset) verbatim into the leaf
default/urlNormalizers.ts. Host imports them back into buildUrl/transformRequest; the
now-dead build*ChatUrl/normalizeBaseUrl imports move to the leaf. All module-private
(no re-export).

Host 864 -> 815 LOC (shrunk below its frozen baseline). Byte-identical bodies (verbatim
45/45), leaf does not import the host (no cycle). buildHeaders/execute/auth untouched.
Adds a split-guard; consumer tests stay green (executor-default-base 49,
anthropic-compatible-bearer 3, strip-client-metadata 3).
2026-07-02 21:57:52 -03:00

65 lines
2.3 KiB
TypeScript

// Pure per-provider chat-URL normalizers + connection-preset reader.
// Extracted verbatim from default.ts (string transforms only, no host state/this).
import { buildDataRobotChatUrl } from "../../config/datarobot.ts";
import { buildAzureAiChatUrl } from "../../config/azureAi.ts";
import { buildWatsonxChatUrl } from "../../config/watsonx.ts";
import { buildOciChatUrl } from "../../config/oci.ts";
import { buildSapChatUrl } from "../../config/sap.ts";
import { normalizeBaseUrl } from "../../utils/urlSanitize.ts";
export function normalizeBailianMessagesUrl(baseUrl) {
const normalized = normalizeBaseUrl(baseUrl).replace(/\?beta=true$/, "");
const messagesUrl = normalized.endsWith("/messages") ? normalized : `${normalized}/messages`;
return messagesUrl;
}
export function normalizeDataRobotChatUrl(baseUrl) {
return buildDataRobotChatUrl(baseUrl);
}
export function normalizeAzureAiChatUrl(baseUrl: string, apiType: "chat" | "responses" = "chat") {
return buildAzureAiChatUrl(baseUrl, apiType);
}
export function normalizeWatsonxChatUrl(baseUrl: string) {
return buildWatsonxChatUrl(baseUrl);
}
export function normalizeOciChatUrl(baseUrl: string, apiType: "chat" | "responses" = "chat") {
return buildOciChatUrl(baseUrl, apiType);
}
export function normalizeSapChatUrl(baseUrl) {
return buildSapChatUrl(baseUrl);
}
export function normalizeXiaomiMimoChatUrl(baseUrl) {
const normalized = normalizeBaseUrl(baseUrl).replace(/\/chat\/completions$/, "");
return `${normalized}/chat/completions`;
}
export function normalizeOpenAIChatUrl(baseUrl) {
const normalized = normalizeBaseUrl(baseUrl);
if (
normalized.endsWith("/chat/completions") ||
normalized.endsWith("/responses") ||
normalized.endsWith("/chat")
) {
return normalized;
}
if (normalized.endsWith("/v1")) {
return `${normalized}/chat/completions`;
}
// Assume OpenAI-compatible /v1/chat/completions path structure
// when the base URL is a bare hostname or custom path (e.g. llama.cpp, vLLM, LM Studio).
return `${normalized}/v1/chat/completions`;
}
export function getOpenRouterConnectionPreset(
providerSpecificData?: Record<string, unknown> | null
): string | null {
const preset =
typeof providerSpecificData?.preset === "string" ? providerSpecificData.preset.trim() : "";
return preset || null;
}