Download src/shared/utils/codexBaseUrl.ts from automindy/fiemwl: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/automindy/fiemwl/resolve/main/src/shared/utils/codexBaseUrl.ts
- Command line
-
hf download hf://spaces/automindy/fiemwl/src/shared/utils/codexBaseUrl.ts
-
curl -L -o codexBaseUrl.ts https://huggingface.co/spaces/automindy/fiemwl/resolve/main/src/shared/utils/codexBaseUrl.ts
1.11 kB
| export type CodexWireApi = "chat" | "responses"; | |
| function normalizeUrlPath(pathname: string, wireApi: CodexWireApi): string { | |
| let path = pathname.replace(/\/+$/g, ""); | |
| if (wireApi === "responses") { | |
| path = path.replace(/\/responses(?:\/.*)?$/i, ""); | |
| } | |
| path = path.replace(/\/v1$/i, "").replace(/\/api$/i, ""); | |
| const apiPath = `${path}/api/v1`.replace(/\/{2,}/g, "/"); | |
| return apiPath.startsWith("/") ? apiPath : `/${apiPath}`; | |
| } | |
| export function normalizeCodexBaseUrl(baseUrl: string, wireApi: CodexWireApi = "chat"): string { | |
| const trimmed = baseUrl.trim().replace(/\/+$/g, ""); | |
| if (!trimmed) return trimmed; | |
| try { | |
| const parsed = new URL(trimmed); | |
| parsed.search = ""; | |
| parsed.hash = ""; | |
| parsed.pathname = normalizeUrlPath(parsed.pathname, wireApi); | |
| return parsed.toString().replace(/\/+$/g, ""); | |
| } catch { | |
| let normalized = trimmed; | |
| if (wireApi === "responses") { | |
| normalized = normalized.replace(/\/responses(?:\/.*)?$/i, ""); | |
| } | |
| return normalized.replace(/\/v1$/i, "").replace(/\/api$/i, "") + "/api/v1"; | |
| } | |
| } | |