import { TrashIcon } from "lucide-react"; import { useState } from "react"; import Header from "@/src/components/layouts/header"; import { Button } from "@/src/components/ui/button"; import { Card } from "@/src/components/ui/card"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/src/components/ui/dialog"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/src/components/ui/table"; import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture"; import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess"; import { api } from "@/src/utils/api"; import { DialogDescription } from "@radix-ui/react-dialog"; import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert"; import { CreateLLMApiKeyDialog } from "./CreateLLMApiKeyDialog"; import { UpdateLLMApiKeyDialog } from "./UpdateLLMApiKeyDialog"; export function LlmApiKeyList(props: { projectId: string }) { const [editingKeyId, setEditingKeyId] = useState(null); const [open, setOpen] = useState(false); const hasAccess = useHasProjectAccess({ projectId: props.projectId, scope: "llmApiKeys:read", }); const apiKeys = api.llmApiKey.all.useQuery( { projectId: props.projectId, }, { enabled: hasAccess, }, ); const hasExtraHeaderKeys = apiKeys.data?.data.some( (key) => key.extraHeaderKeys.length > 0, ); if (!hasAccess) { return (
Access Denied You do not have permission to view LLM API keys for this project.
); } return (

Connect your LLM services to enable evaluations and playground features. Your provider will charge based on usage.

Provider Adapter Base URL API Key {hasExtraHeaderKeys ? ( Extra headers ) : null} {apiKeys.data?.data.length === 0 ? ( None ) : ( apiKeys.data?.data.map((apiKey) => ( setEditingKeyId(apiKey.id)} > {apiKey.provider} {apiKey.adapter} {apiKey.baseURL ?? "default"} {apiKey.displaySecretKey} {hasExtraHeaderKeys ? ( {apiKey.extraHeaderKeys.join(", ")} ) : null}
e.stopPropagation()} > { if (open) { setEditingKeyId(apiKey.id); } else { setEditingKeyId(null); } }} />
)) )}
); } // show dialog to let user confirm that this is a destructive action function DeleteApiKeyButton(props: { projectId: string; apiKeyId: string }) { const capture = usePostHogClientCapture(); const hasAccess = useHasProjectAccess({ projectId: props.projectId, scope: "llmApiKeys:delete", }); const utils = api.useUtils(); const mutDeleteApiKey = api.llmApiKey.delete.useMutation({ onSuccess: () => utils.llmApiKey.invalidate(), }); const [open, setOpen] = useState(false); if (!hasAccess) return null; return ( Delete LLM Connection Are you sure you want to delete this connection? This action cannot be undone. ); }