🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
refactor(web): Migrate llm connections table to design-system components (#17732)
Ben Bachem1b148489470a
diff --git a/web/src/components/SettingsTable/SettingsTable.tsx b/web/src/components/SettingsTable/SettingsTable.tsxindex 07d4b24543..ab41e231e7 100644--- a/web/src/components/SettingsTable/SettingsTable.tsx+++ b/web/src/components/SettingsTable/SettingsTable.tsx@@ -39,7 +39,7 @@ export type SettingsTableProps<TData extends object> = Omit<onChange: (value: string) => void;};toolbarActions?: SettingsTableToolbarAction[];- pagination: PaginationBarProps;+ pagination?: PaginationBarProps;};export function SettingsTable<TData extends object>({@@ -123,7 +123,7 @@ export function SettingsTable<TData extends object>({onColumnOrderChange={setColumnOrder}{...tableProps}/>- <PaginationBar {...pagination} />+ {pagination && <PaginationBar {...pagination} />}</SettingsTableCard></div>);diff --git a/web/src/features/public-api/components/CreateLLMApiKeyDialogController.tsx b/web/src/features/public-api/components/CreateLLMApiKeyDialogController.tsxnew file mode 100644index 0000000000..b48aa63f84--- /dev/null+++ b/web/src/features/public-api/components/CreateLLMApiKeyDialogController.tsx@@ -0,0 +1,50 @@+import { type ReactNode, useState } from "react";++import { DialogController } from "@/src/components/design-system/DialogController/DialogController";+import {+ DialogContent,+ DialogHeader,+ DialogTitle,+} from "@/src/components/ui/dialog";+import { useUiCustomization } from "@/src/ee/features/ui-customization/useUiCustomization";+import { CreateLLMApiKeyForm } from "@/src/features/public-api/components/CreateLLMApiKeyForm";+import { useHasProjectAccess } from "@/src/features/rbac";++export function CreateLLMApiKeyDialogController({+ projectId,+ children,+}: {+ projectId: string;+ children: (control: {+ hasAccess: boolean;+ openDialog: () => void;+ }) => ReactNode;+}) {+ const hasAccess = useHasProjectAccess({+ projectId,+ scope: "llmApiKeys:create",+ });+ const uiCustomization = useUiCustomization();+ const [formKey, setFormKey] = useState(0);++ return (+ <DialogController+ onDismiss={() => setFormKey((currentKey) => currentKey + 1)}+ renderDialog={({ closeDialog }) => (+ <DialogContent className="max-h-[90%] min-w-[40vw] overflow-auto">+ <DialogHeader>+ <DialogTitle>New LLM Connection</DialogTitle>+ </DialogHeader>+ <CreateLLMApiKeyForm+ key={formKey}+ projectId={projectId}+ onSuccess={closeDialog}+ customization={uiCustomization}+ />+ </DialogContent>+ )}+ >+ {({ openDialog }) => children({ hasAccess, openDialog })}+ </DialogController>+ );+}diff --git a/web/src/features/public-api/components/LLMApiKeyList.clienttest.tsx b/web/src/features/public-api/components/LLMApiKeyList.clienttest.tsxindex df251c3553..21fa612456 100644--- a/web/src/features/public-api/components/LLMApiKeyList.clienttest.tsx+++ b/web/src/features/public-api/components/LLMApiKeyList.clienttest.tsx@@ -24,11 +24,11 @@ vi.mock("./CreateLLMApiKeyForm", () => ({existingKey,onSuccess,}: {- existingKey: { provider: string };+ existingKey?: { provider: string };onSuccess: () => void;}) => (<>- <output>{existingKey.provider}</output>+ {existingKey && <output>{existingKey.provider}</output>}<input aria-label="API key" defaultValue="" /><button onClick={onSuccess}>Save connection</button></>@@ -67,7 +67,7 @@ describe("LLM connection editing", () => {const { rerender } = render(<LlmApiKeyList projectId="project" />, {wrapper: LayerProvider,});- fireEvent.click(screen.getByRole("row", { name: "Edit First connection" }));+ fireEvent.click(screen.getByText("First").closest("tr")!);const dialog = screen.getByRole("dialog");fireEvent.change(screen.getByRole("textbox", { name: "API key" }), {target: { value: "Unsaved draft" },@@ -84,13 +84,58 @@ describe("LLM connection editing", () => {);fireEvent.click(screen.getByRole("button", { name: "Save connection" }));expect(screen.queryByRole("dialog")).not.toBeInTheDocument();- fireEvent.keyDown(- screen.getByRole("row", { name: "Edit Second connection" }),- { key: "Enter" },- );+ fireEvent.keyDown(screen.getByText("Second").closest("tr")!, {+ key: "Enter",+ });expect(within(screen.getByRole("dialog")).getByText("Second"),).toBeInTheDocument();expect(screen.getByRole("textbox", { name: "API key" })).toHaveValue("");});++ it("resets an unsaved create draft after dismissing the dialog", () => {+ vi.mocked(api.llmApiKey.all.useQuery).mockReturnValue({+ data: { data: [] },+ isLoading: false,+ isError: false,+ } as ReturnType<typeof api.llmApiKey.all.useQuery>);++ render(<LlmApiKeyList projectId="project" />, {+ wrapper: LayerProvider,+ });+ fireEvent.click(screen.getByRole("button", { name: "Add LLM Connection" }));+ fireEvent.change(screen.getByRole("textbox", { name: "API key" }), {+ target: { value: "Unsaved draft" },+ });+ fireEvent.keyDown(screen.getByRole("dialog"), { key: "Escape" });+ fireEvent.click(screen.getByRole("button", { name: "Add LLM Connection" }));++ expect(screen.getByRole("textbox", { name: "API key" })).toHaveValue("");+ });++ it("renders all connections without pagination", () => {+ const keys = Array.from({ length: 11 }, (_, index) => ({+ id: `${index}`,+ provider: `Provider ${index}`,+ adapter: "openai",+ baseURL: null,+ displaySecretKey: "sk-...test",+ extraHeaderKeys: [] as string[],+ }));+ vi.mocked(api.llmApiKey.all.useQuery).mockReturnValue({+ data: { data: keys },+ isLoading: false,+ isError: false,+ } as ReturnType<typeof api.llmApiKey.all.useQuery>);++ render(<LlmApiKeyList projectId="project" />, {+ wrapper: LayerProvider,+ });++ expect(screen.getByText("Provider 0")).toBeInTheDocument();+ expect(screen.getByText("Provider 10")).toBeInTheDocument();+ expect(+ screen.queryByRole("button", { name: "Go to next page" }),+ ).not.toBeInTheDocument();+ });});diff --git a/web/src/features/public-api/components/LLMApiKeyList.tsx b/web/src/features/public-api/components/LLMApiKeyList.tsxindex f4a9248af5..c934399037 100644--- a/web/src/features/public-api/components/LLMApiKeyList.tsx+++ b/web/src/features/public-api/components/LLMApiKeyList.tsx@@ -1,122 +1,13 @@import { useHasProjectAccess } from "@/src/features/rbac";-import { PencilIcon, 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 { ConfirmDialog } from "@/src/components/ui/confirm-dialog";-import { SimpleDataTable } from "@/src/components/table/simple-data-table";-import { type LangfuseColumnDef } from "@/src/components/table/types";-import { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";-import { usePostHogClientCapture } from "@/src/features/posthog-analytics";-import { api, reportNonTrpcError } from "@/src/utils/api";import { Alert } from "@/src/components/design-system/Alert/Alert";-import { CreateLLMApiKeyDialog } from "./CreateLLMApiKeyDialog";-import { UpdateLLMApiKeyDialog } from "./UpdateLLMApiKeyDialog";-import { type RouterOutput } from "@/src/utils/types";--type LlmApiKeyRow = RouterOutput["llmApiKey"]["all"]["data"][number];+import { ConnectedLLMApiKeySettingsTable } from "./LLMApiKeySettingsTable/ConnectedLLMApiKeySettingsTable";export function LlmApiKeyList(props: { projectId: string }) {- const [open, setOpen] = useState(false);-const hasAccess = useHasProjectAccess({projectId: props.projectId,scope: "llmApiKeys:read",});- const hasDeleteAccess = useHasProjectAccess({- projectId: props.projectId,- scope: "llmApiKeys:delete",- });- const hasUpdateAccess = useHasProjectAccess({- projectId: props.projectId,- scope: "llmApiKeys:update",- });-- const apiKeys = api.llmApiKey.all.useQuery(- {- projectId: props.projectId,- },- {- enabled: hasAccess,- },- );-- const hasExtraHeaderKeys = apiKeys.data?.data.some(- (key) => key.extraHeaderKeys.length > 0,- );-- const getColumns = (- openDialog: (apiKey: LlmApiKeyRow) => void,- ): LangfuseColumnDef<LlmApiKeyRow>[] => [- {- accessorKey: "provider",- header: "Provider",- cell: ({ getValue }) => (- <span className="font-mono">{getValue<string>()}</span>- ),- },- {- accessorKey: "adapter",- header: "Adapter",- cell: ({ getValue }) => (- <span className="font-mono">{getValue<string>()}</span>- ),- },- {- accessorKey: "baseURL",- header: "Base URL",- cell: ({ getValue }) => (- <div className="max-w-md overflow-auto font-mono">- {getValue<string | null>() ?? "default"}- </div>- ),- },- {- accessorKey: "displaySecretKey",- header: "API Key",- cell: ({ getValue }) => (- <span className="font-mono">{getValue<string>()}</span>- ),- },- ...(hasExtraHeaderKeys- ? [- createTextTableColumn<LlmApiKeyRow, string[]>({- accessorKey: "extraHeaderKeys",- header: "Extra headers",- mapValue: (value) => value?.join(", "),- }),- ]- : []),- {- accessorKey: "id",- header: "",- cell: ({ row }) => {- const apiKey = row.original;- return (- <div data-row-click-ignore className="flex justify-end space-x-2">- {hasUpdateAccess && (- <Button- variant="ghost"- size="icon"- aria-label={`Edit ${apiKey.provider} connection`}- onClick={() => openDialog(apiKey)}- >- <PencilIcon className="h-4 w-4" />- </Button>- )}- {hasDeleteAccess && (- <DeleteApiKeyButton- projectId={props.projectId}- apiKeyId={apiKey.id}- />- )}- </div>- );- },- },- ];-if (!hasAccess) {return (<div>@@ -138,72 +29,7 @@ export function LlmApiKeyList(props: { projectId: string }) {Connect your LLM services to enable evaluations and playground features.Your provider will charge based on usage.</p>- <UpdateLLMApiKeyDialog projectId={props.projectId}>- {({ openDialog }) => (- <Card className="mb-4 overflow-auto">- <SimpleDataTable- columns={getColumns(openDialog)}- data={apiKeys.data?.data ?? []}- isLoading={apiKeys.isLoading}- noResults={- apiKeys.isError ? (- <span className="text-destructive">- Failed to load LLM connections. Please try again.- </span>- ) : (- "None"- )- }- bodyTone="muted"- rowVariant="primary-hover-static"- onRowClick={(apiKey) => {- if (hasUpdateAccess) openDialog(apiKey);- }}- getRowLabel={(apiKey) => `Edit ${apiKey.provider} connection`}- />- </Card>- )}- </UpdateLLMApiKeyDialog>- <CreateLLMApiKeyDialog open={open} setOpen={setOpen} />+ <ConnectedLLMApiKeySettingsTable projectId={props.projectId} /></div>);}--// show dialog to let user confirm that this is a destructive action-function DeleteApiKeyButton(props: { projectId: string; apiKeyId: string }) {- const capture = usePostHogClientCapture();-- const utils = api.useUtils();- const mutDeleteApiKey = api.llmApiKey.delete.useMutation({- onSuccess: () => utils.llmApiKey.invalidate(),- });- const [open, setOpen] = useState(false);-- return (- <ConfirmDialog- open={open}- onOpenChange={setOpen}- trigger={- <Button variant="ghost" size="icon">- <TrashIcon className="h-4 w-4" />- </Button>- }- title="Delete LLM Connection"- description="Are you sure you want to delete this connection? This action cannot be undone."- confirmLabel="Permanently delete"- loading={mutDeleteApiKey.isPending}- onConfirm={() => {- mutDeleteApiKey- .mutateAsync({- projectId: props.projectId,- id: props.apiKeyId,- })- .then(() => {- capture("project_settings:llm_api_key_delete");- setOpen(false);- })- .catch((error) => reportNonTrpcError(error, "llm-api-keys"));- }}- />- );-}diff --git a/web/src/features/public-api/components/LLMApiKeySettingsTable/ConnectedLLMApiKeySettingsTable.tsx b/web/src/features/public-api/components/LLMApiKeySettingsTable/ConnectedLLMApiKeySettingsTable.tsxnew file mode 100644index 0000000000..fdbadcef37--- /dev/null+++ b/web/src/features/public-api/components/LLMApiKeySettingsTable/ConnectedLLMApiKeySettingsTable.tsx@@ -0,0 +1,96 @@+import { useMemo } from "react";++import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";+import { type AsyncTableData } from "@/src/components/design-system/table/Table";+import { CreateLLMApiKeyDialogController } from "@/src/features/public-api/components/CreateLLMApiKeyDialogController";+import { UpdateLLMApiKeyDialog } from "@/src/features/public-api/components/UpdateLLMApiKeyDialog";+import { useHasProjectAccess } from "@/src/features/rbac";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics";+import { api, reportNonTrpcError } from "@/src/utils/api";+import {+ LLMApiKeySettingsTable,+ type LLMApiKeySettingsTableRow,+} from "./LLMApiKeySettingsTable";++export function ConnectedLLMApiKeySettingsTable({+ projectId,+}: {+ projectId: string;+}) {+ const capture = usePostHogClientCapture();+ const utils = api.useUtils();++ const hasDeleteAccess = useHasProjectAccess({+ projectId,+ scope: "llmApiKeys:delete",+ });+ const hasUpdateAccess = useHasProjectAccess({+ projectId,+ scope: "llmApiKeys:update",+ });++ const apiKeys = api.llmApiKey.all.useQuery({ projectId });+ const deleteApiKey = api.llmApiKey.delete.useMutation({+ onSuccess: () => utils.llmApiKey.invalidate(),+ });++ const tableData = useMemo<AsyncTableData<LLMApiKeySettingsTableRow[]>>(() => {+ if (apiKeys.isLoading) return { status: "loading" };+ if (apiKeys.isError) {+ return { status: "error", error: "Failed to load LLM connections" };+ }++ return {+ status: "success",+ data: apiKeys.data?.data ?? [],+ };+ }, [apiKeys.data?.data, apiKeys.isError, apiKeys.isLoading]);++ return (+ <CreateLLMApiKeyDialogController projectId={projectId}>+ {({ hasAccess: hasCreateAccess, openDialog: openCreateDialog }) => (+ <UpdateLLMApiKeyDialog projectId={projectId}>+ {({ openDialog: openUpdateDialog }) => (+ <ConfirmationDialogController<{ id: string }>+ title="Delete LLM Connection"+ text="Are you sure you want to delete this connection? This action cannot be undone."+ confirmLabel="Permanently delete"+ variant="destructive"+ loading={deleteApiKey.isPending}+ error={deleteApiKey.error?.message}+ onAfterDismiss={deleteApiKey.reset}+ onConfirm={async (apiKey) => {+ try {+ await deleteApiKey.mutateAsync({ projectId, id: apiKey.id });+ capture("project_settings:llm_api_key_delete");+ } catch (error) {+ reportNonTrpcError(error, "llm-api-keys");+ throw error;+ }+ }}+ >+ {({ openDialog: openDeleteDialog }) => (+ <LLMApiKeySettingsTable+ createAction={{+ hasAccess: hasCreateAccess,+ onClick: openCreateDialog,+ }}+ deleteAction={{+ hasAccess: hasDeleteAccess,+ onClick: openDeleteDialog,+ }}+ updateAction={{+ hasAccess: hasUpdateAccess,+ onClick: openUpdateDialog,+ }}+ data={tableData}+ noResultsMessage="None"+ />+ )}+ </ConfirmationDialogController>+ )}+ </UpdateLLMApiKeyDialog>+ )}+ </CreateLLMApiKeyDialogController>+ );+}diff --git a/web/src/features/public-api/components/LLMApiKeySettingsTable/LLMApiKeySettingsTable.stories.tsx b/web/src/features/public-api/components/LLMApiKeySettingsTable/LLMApiKeySettingsTable.stories.tsxnew file mode 100644index 0000000000..7093d0570b--- /dev/null+++ b/web/src/features/public-api/components/LLMApiKeySettingsTable/LLMApiKeySettingsTable.stories.tsx@@ -0,0 +1,66 @@+import { fn } from "storybook/test";++import preview from "../../../../../.storybook/preview";+import {+ LLMApiKeySettingsTable,+ type LLMApiKeySettingsTableRow,+} from "./LLMApiKeySettingsTable";++const meta = preview.meta({ component: LLMApiKeySettingsTable });++export const Default = meta.story({+ args: {+ createAction: { hasAccess: true, onClick: fn() },+ deleteAction: { hasAccess: true, onClick: fn() },+ updateAction: { hasAccess: true, onClick: fn() },+ data: {+ status: "success",+ data: [+ {+ id: "connection-1",+ projectId: "project-1",+ createdAt: new Date("2026-09-01"),+ updatedAt: new Date("2026-09-01"),+ provider: "OpenAI",+ adapter: "openai" as LLMApiKeySettingsTableRow["adapter"],+ baseURL: null,+ displaySecretKey: "sk-...test",+ customModels: [],+ withDefaultModels: true,+ extraHeaderKeys: [],+ config: null,+ secretKey: undefined,+ extraHeaders: undefined,+ authMethod: undefined,+ },+ {+ id: "connection-2",+ projectId: "project-1",+ createdAt: new Date("2026-09-02"),+ updatedAt: new Date("2026-09-02"),+ provider: "Azure OpenAI",+ adapter: "openai" as LLMApiKeySettingsTableRow["adapter"],+ baseURL: "https://example.openai.azure.com",+ displaySecretKey: "••••••••",+ customModels: [],+ withDefaultModels: true,+ extraHeaderKeys: ["api-version"],+ config: null,+ secretKey: undefined,+ extraHeaders: undefined,+ authMethod: undefined,+ },+ ],+ },+ },+});++export const Loading = meta.story({+ args: {+ createAction: { hasAccess: true, onClick: fn() },+ deleteAction: { hasAccess: true, onClick: fn() },+ updateAction: { hasAccess: true, onClick: fn() },+ data: { status: "loading" },+ loadingRowCount: 5,+ },+});diff --git a/web/src/features/public-api/components/LLMApiKeySettingsTable/LLMApiKeySettingsTable.tsx b/web/src/features/public-api/components/LLMApiKeySettingsTable/LLMApiKeySettingsTable.tsxnew file mode 100644index 0000000000..5d5a82713c--- /dev/null+++ b/web/src/features/public-api/components/LLMApiKeySettingsTable/LLMApiKeySettingsTable.tsx@@ -0,0 +1,129 @@+import { useCallback, useMemo } from "react";+import { Pencil, PlusIcon, Trash } from "lucide-react";++import { type TableProps } from "@/src/components/design-system/table/Table";+import { createBadgeTableColumn } from "@/src/components/design-system/table/columns/createBadgeTableColumn";+import { createTextTableColumn } from "@/src/components/design-system/table/columns/createTextTableColumn";+import {+ SettingsTable,+ type SettingsTableProps,+} from "@/src/components/SettingsTable/SettingsTable";+import { type LangfuseColumnDef } from "@/src/components/table/types";+import { type RouterOutput } from "@/src/utils/types";++export type LLMApiKeySettingsTableRow =+ RouterOutput["llmApiKey"]["all"]["data"][number];++export function LLMApiKeySettingsTable({+ createAction,+ deleteAction,+ updateAction,+ ...tableProps+}: Pick<+ TableProps<LLMApiKeySettingsTableRow>,+ "data" | "loadingRowCount" | "noResultsMessage"+> & {+ createAction: { hasAccess: boolean; onClick: () => void };+ deleteAction: {+ hasAccess: boolean;+ onClick: (apiKey: LLMApiKeySettingsTableRow) => void;+ };+ updateAction: {+ hasAccess: boolean;+ onClick: (apiKey: LLMApiKeySettingsTableRow) => void;+ };+}) {+ const showExtraHeaderKeys =+ tableProps.data.status === "success" &&+ tableProps.data.data.some((apiKey) => apiKey.extraHeaderKeys.length > 0);++ const columns = useMemo<LangfuseColumnDef<LLMApiKeySettingsTableRow>[]>(+ () => [+ createTextTableColumn<LLMApiKeySettingsTableRow>({+ accessorKey: "provider",+ header: "Provider",+ enableResizing: false,+ }),+ createBadgeTableColumn<LLMApiKeySettingsTableRow>({+ accessorKey: "adapter",+ header: "Adapter",+ enableResizing: false,+ }),+ createTextTableColumn<LLMApiKeySettingsTableRow>({+ accessorKey: "baseURL",+ header: "Base URL",+ nullValue: "default",+ enableResizing: false,+ }),+ createTextTableColumn<LLMApiKeySettingsTableRow>({+ accessorKey: "displaySecretKey",+ header: "API Key",+ enableResizing: false,+ }),+ ...(showExtraHeaderKeys+ ? [+ createTextTableColumn<LLMApiKeySettingsTableRow, string[]>({+ accessorKey: "extraHeaderKeys",+ header: "Extra headers",+ mapValue: (value) => value?.join(", "),+ enableResizing: false,+ }),+ ]+ : []),+ ],+ [showExtraHeaderKeys],+ );++ const actions = useCallback<+ NonNullable<TableProps<LLMApiKeySettingsTableRow>["actions"]>+ >(+ (apiKey) => [+ {+ id: "edit",+ type: "item",+ title: "Edit connection",+ icon: Pencil,+ disabled: updateAction.hasAccess+ ? undefined+ : { reason: "You do not have permission to edit this connection" },+ onClick: () => updateAction.onClick(apiKey),+ },+ {+ id: "delete",+ type: "item",+ title: "Delete connection",+ icon: Trash,+ variant: "destructive",+ disabled: deleteAction.hasAccess+ ? undefined+ : { reason: "You do not have permission to delete this connection" },+ onClick: () => deleteAction.onClick(apiKey),+ },+ ],+ [deleteAction, updateAction],+ );++ const toolbarActions: SettingsTableProps<LLMApiKeySettingsTableRow>["toolbarActions"] =+ createAction.hasAccess+ ? [+ {+ id: "add-connection",+ label: "Add LLM Connection",+ variant: "secondary",+ icon: <PlusIcon className="size-4" aria-hidden="true" />,+ onClick: createAction.onClick,+ },+ ]+ : undefined;++ return (+ <SettingsTable+ tableName="LLM connections"+ columns={columns}+ actions={actions}+ toolbarActions={toolbarActions}+ onRowClick={updateAction.hasAccess ? updateAction.onClick : undefined}+ {...tableProps}+ />+ );+}