Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

2.3 KB
Raw Blame
const cloudRegions = [
  {
    name: "DEV",
    flag: "🚧",
    hostname: null,
    rootUrl: null,
    isProduction: false,
  },
  {
    name: "STAGING",
    flag: "🇪🇺",
    hostname: "staging.langfuse.com",
    rootUrl: "https://staging.langfuse.com",
    isProduction: false,
  },
  {
    name: "EU",
    flag: "🇪🇺",
    hostname: "cloud.langfuse.com",
    rootUrl: "https://cloud.langfuse.com",
    isProduction: true,
  },
  {
    name: "US",
    flag: "🇺🇸",
    hostname: "us.cloud.langfuse.com",
    rootUrl: "https://us.cloud.langfuse.com",
    isProduction: true,
  },
  {
    name: "JP",
    flag: "🇯🇵",
    hostname: "jp.cloud.langfuse.com",
    rootUrl: "https://jp.cloud.langfuse.com",
    isProduction: true,
  },
  {
    name: "HIPAA",
    flag: "⚕️",
    hostname: "hipaa.cloud.langfuse.com",
    rootUrl: "https://hipaa.cloud.langfuse.com",
    isProduction: true,
  },
] as const;

export type CloudRegion = (typeof cloudRegions)[number];

export type CloudRegionName = CloudRegion["name"];

type ProductionCloudRegionName = Extract<
  CloudRegion,
  { isProduction: true }
>["name"];

const availableRegionsByCurrentRegion = {
  STAGING: ["STAGING"],
  DEV: ["DEV"],
  default: ["US", "EU", "JP", "HIPAA"],
} as const;

const getCloudRegion = (name: CloudRegionName) => {
  const region = cloudRegions.find((region) => region.name === name);
  if (!region) {
    throw new Error(`Unknown cloud region: ${name}`);
  }

  return region;
};

export const getAvailableCloudRegionOptions = (currentRegion?: string) => {
  if (currentRegion === "STAGING") {
    return availableRegionsByCurrentRegion.STAGING.map(getCloudRegion);
  }

  if (currentRegion === "DEV") {
    return availableRegionsByCurrentRegion.DEV.map(getCloudRegion);
  }

  return availableRegionsByCurrentRegion.default.map(getCloudRegion);
};

export const getCloudRegionAuthUrl = (
  rootUrl: string,
  email?: string | null,
): string => {
  const authUrl = new URL("/auth/sign-in", rootUrl);

  if (email) {
    authUrl.searchParams.set("email", email);
  }

  return authUrl.toString();
};

export const isRegionProduction = (
  regionName: CloudRegionName,
): regionName is ProductionCloudRegionName =>
  cloudRegions.some(
    (region) => region.name === regionName && region.isProduction,
  );