Skip to content

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

2.3 KB
Raw Blame
/* eslint-disable @repo/no-abstracted-overlay-trigger, @repo/no-null-render, @typescript-eslint/no-deprecated -- Legacy UI usage retained during migration to design-system components. */
import { PlusIcon } from "@langfuse/icons";
import { Button } from "@/src/components/ui/button";
import {
  Dialog,
  DialogContent,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/src/components/ui/dialog";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";
import { useUiCustomization } from "@/src/ee/features/ui-customization/useUiCustomization";
import { CreateLLMApiKeyForm } from "@/src/features/public-api/components/CreateLLMApiKeyForm";

export function CreateLLMApiKeyDialog({
  open,
  setOpen,
  hideTrigger = false,
}: {
  open: boolean;
  setOpen: (open: boolean) => void;
  /**
   * Hide the built-in "Add LLM Connection" trigger button and render only the
   * (controlled) dialog. Use this when the dialog is opened from elsewhere — e.g.
   * from inside a Select/dropdown, where the dialog must live OUTSIDE the
   * dropdown content so it survives the dropdown closing. See the overlay
   * lifecycle note in web/AGENTS.md.
   */
  hideTrigger?: boolean;
}) {
  const projectId = useProjectIdFromURL();
  const hasAccess = useHasProjectAccess({
    projectId,
    scope: "llmApiKeys:create",
  });
  const uiCustomization = useUiCustomization();

  if (!projectId || !hasAccess) return null;

  return (
    <Dialog
      open={open}
      onOpenChange={(isOpen) => {
        setOpen(isOpen);
      }}
    >
      {!hideTrigger && (
        <DialogTrigger asChild>
          <Button variant="secondary">
            <PlusIcon
              size="base"
              __rawClassName="mr-1.5 -ml-0.5"
              aria-hidden="true"
            />
            Add LLM Connection
          </Button>
        </DialogTrigger>
      )}
      <DialogContent className="max-h-[90%] min-w-[40vw] overflow-auto">
        <DialogHeader>
          <DialogTitle>New LLM Connection</DialogTitle>
        </DialogHeader>
        {open && (
          <CreateLLMApiKeyForm
            owner={{ scope: "project", projectId }}
            onSuccess={() => setOpen(false)}
            customization={uiCustomization}
          />
        )}
      </DialogContent>
    </Dialog>
  );
}