/** Remove a URL's trailing slashes in one pass, including long malformed input. */ export function stripTrailingSlashes(value: string): string { let end = value.length; while (end > 0 && value.charCodeAt(end - 1) === 47) end--; return value.slice(0, end); } /** Gateway callers append their own /v1 path; accept either base URL form. */ export function normalizeGatewayBaseUrl(value: string): string { const base = stripTrailingSlashes(value); return base.endsWith("/v1") ? base.slice(0, -3) : base; }