MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / normalizeOpenAIBaseUrl

Function normalizeOpenAIBaseUrl

ai/ai.ts:1747–1794  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

1745
1746const normalizeOpenAIBaseUrl = (url: string): string => {
1747 try {
1748 const u = new URL(url);
1749
1750 if (u.hostname.includes("gateway.ai.cloudflare.com")) {
1751 const openAiIndex = u.pathname.indexOf("/openai");
1752 if (openAiIndex >= 0) {
1753 u.pathname = u.pathname.slice(0, openAiIndex + "/openai".length);
1754 }
1755 u.search = "";
1756 return u.toString();
1757 }
1758
1759 const stripSuffixes = [
1760 "/chat/completions",
1761 "/completions",
1762 "/responses",
1763 "/messages",
1764 "/images/generations",
1765 ];
1766 for (const s of stripSuffixes) {
1767 if (u.pathname.endsWith(s)) {
1768 u.pathname = u.pathname.slice(0, -s.length);
1769 break;
1770 }
1771 }
1772
1773 const apiV1Index = u.pathname.indexOf("/api/v1");
1774 if (apiV1Index >= 0) {
1775 u.pathname = u.pathname.slice(0, apiV1Index + "/api/v1".length);
1776 u.search = "";
1777 return u.toString();
1778 }
1779
1780 const v1Index = u.pathname.indexOf("/v1");
1781 if (v1Index >= 0) {
1782 u.pathname = u.pathname.slice(0, v1Index + "/v1".length);
1783 u.search = "";
1784 return u.toString();
1785 }
1786
1787 u.pathname = "/v1";
1788 u.search = "";
1789 return u.toString();
1790 } catch {
1791 return url;
1792 }
1793};
1794
1795const normalizeGeminiBaseUrl = (url: string): string => {
1796 try {
1797 const u = new URL(url);

Callers 2

resolveBaseUrlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected