Skip to content

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

3.8 KB
Raw Blame
import { ArrowRight, X } from "@langfuse/icons";
import { useState } from "react";

import { DismissController } from "@/src/components/DismissController";
import { Badge } from "@/src/components/design-system/Badge/Badge";
import { IconButton } from "@/src/components/design-system/IconButton/IconButton";
import { Button } from "@/src/components/ui/button";
import styles from "@/src/features/ai-gateway/components/GatewayLaunch/gatewayLaunch.module.css";
import { GatewayLaunchDialog } from "@/src/features/ai-gateway/components/GatewayLaunch/GatewayLaunchDialog";
import { GatewaySwitchboard } from "@/src/features/ai-gateway/components/GatewayLaunch/GatewaySwitchboard";
import {
  type GatewayLaunchState,
  type GatewayLaunchTarget,
} from "@/src/features/ai-gateway/hooks/useGatewayLaunchEligibility";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { cn } from "@/src/utils/tailwind";

function ctaLabel(state: GatewayLaunchState) {
  if (state === "get-key") return "Get gateway key";
  if (state === "ask-admin") return "Learn more";
  return "Set up";
}

/** Organizations-page banner; the page renders it only when there is a target. */
export function GatewayLaunchBanner({
  target,
  userId,
}: {
  target: GatewayLaunchTarget;
  userId: string;
}) {
  const [open, setOpen] = useState(false);
  const capture = usePostHogClientCapture();
  const { state, setupOptions } = target;
  const { organizationId } = target;
  const captureCta = () =>
    capture("ai_gateway_launch:banner_cta_clicked", {
      state,
      orgCount: setupOptions.length,
    });
  const arrow = (
    <ArrowRight size="base" __rawClassName="ml-1.5" aria-hidden="true" />
  );

  return (
    <>
      <DismissController
        id={`ai-gateway-launch:v2:${userId}:${state}:${target.organizationId}`}
        family="callouts"
      >
        {({ onDismiss }) => (
          <div
            className={cn(
              "bg-surface-section relative mt-2 mb-4 flex h-24 items-center gap-6 overflow-hidden rounded-lg pr-12 pl-6",
              styles.dotGrid,
              styles.bannerDots,
            )}
          >
            <div className="flex min-w-0 flex-1 flex-col gap-1">
              <div className="flex items-center gap-2">
                <span className="text-base font-bold">AI Gateway</span>
                <Badge text="Beta" color="blue" size="sm" font="mono" />
              </div>
              <p
                className="text-muted-foreground truncate text-base"
                title="Trace and monitor your AI usage by installing the Langfuse AI Gateway in 2 minutes."
              >
                Trace and monitor your AI usage by installing the Langfuse AI
                Gateway in 2 minutes.
              </p>
            </div>
            <div className="mr-12 hidden h-full w-72 shrink-0 xl:block">
              <GatewaySwitchboard variant="banner" />
            </div>
            <div className="flex shrink-0 items-center gap-2">
              <Button
                onClick={() => {
                  captureCta();
                  setOpen(true);
                }}
              >
                {ctaLabel(state)}
                {arrow}
              </Button>
            </div>
            <span className="absolute top-2 right-2">
              <IconButton
                icon={X}
                label="Dismiss"
                size="sm"
                onClick={() => {
                  capture("ai_gateway_launch:banner_dismissed", { state });
                  onDismiss();
                }}
              />
            </span>
          </div>
        )}
      </DismissController>
      <GatewayLaunchDialog
        key={organizationId}
        organizationId={organizationId}
        state={state}
        setupOptions={setupOptions}
        open={open}
        onOpenChange={setOpen}
      />
    </>
  );
}