MCPcopy
hub / github.com/codedogQBY/ReadAny / formatApiHost

Function formatApiHost

packages/core/src/utils/api.ts:214–234  ·  view source on GitHub ↗
(host: string)

Source from the content-addressed store, hash-verified

212const VERSION_PATTERN = /\/(v[1-9]\d*|api\/v[1-9]\d*|api\/paas\/v[1-9]\d*|compatible-mode\/v[1-9]\d*|openai\/v[1-9]\d*)$/i;
213
214export function formatApiHost(host: string): string {
215 if (!host) return host;
216
217 host = ensureUrlProtocol(host.trim());
218
219 if (host.endsWith("/")) {
220 return host;
221 }
222
223 for (const special of SPECIAL_HOSTS) {
224 if (host.includes(special)) {
225 return `${host}/`;
226 }
227 }
228
229 if (VERSION_PATTERN.test(host)) {
230 return `${host}/`;
231 }
232
233 return `${host}/v1/`;
234}
235
236export function trimApiUrl(url: string): string {
237 return url.replace(/\/+$/, "");

Callers 3

api.test.tsFile · 0.90
getEndpointBaseUrlFunction · 0.90
resolveProviderBaseUrlFunction · 0.85

Calls 1

ensureUrlProtocolFunction · 0.85

Tested by

no test coverage detected