🪢 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
feat(web): friendly AI Gateway tile for gateway-only members on the organizations overview (#19646)
Tobias Wochinger8c80fdf2d2d0
diff --git a/web/src/features/organizations/components/OrganizationProjectOverview.tsx b/web/src/features/organizations/components/OrganizationProjectOverview.tsxindex e83c0b67e7..4cc73e4579 100644--- a/web/src/features/organizations/components/OrganizationProjectOverview.tsx+++ b/web/src/features/organizations/components/OrganizationProjectOverview.tsx@@ -56,6 +56,8 @@ import { useGatewayLaunchTarget } from "@/src/features/ai-gateway/hooks/useGatewimport { useGatewaySettingsAccess } from "@/src/features/ai-gateway/hooks/useGatewaySettingsAccess";import { getContextualFeatureFlags } from "@/src/features/feature-flags/utils";import { gatewayOnlyLanding } from "@/src/features/organizations/utils/gatewayOnlyLanding";+import { OrganizationSettingsTile } from "@/src/features/organizations/components/OrganizationSettingsTile/OrganizationSettingsTile";+import { useGatewayMemberStatus } from "@/src/features/organizations/hooks/useGatewayMemberStatus";const lastTraceLabel = (lastTraceAt: Date | string | null | undefined) =>lastTraceAt@@ -381,7 +383,7 @@ const SingleOrganizationProjectOverviewTile = ({);};-/** OrganizationProjects lists the org's projects, or points to its settings when the user has none */+/** OrganizationProjects lists the org's projects, or points to its settings (gateway-only members: the gateway) when the user has none */const OrganizationProjects = ({org,search,@@ -389,55 +391,33 @@ const OrganizationProjects = ({org: Organization;search?: string;}) => {- if (org.projects.length === 0) {- return <OrganizationSettingsTile orgId={org.id} />;- }- return <OrganizationProjectTiles org={org} search={search} />;-};--/** OrganizationSettingsTile links to the org's settings, and to project creation when allowed */-const OrganizationSettingsTile = ({ orgId }: { orgId: string }) => {+ const session = useSession();const canCreateProject = useHasOrganizationAccess({- organizationId: orgId,+ organizationId: org.id,scope: "projects:create",});+ if (org.projects.length > 0) {+ return <OrganizationProjectTiles org={org} search={search} />;+ }+ if (gatewayOnlyLanding(session.data, org.id)?.canUseGateway === true) {+ return <ConnectedGatewayMemberTile org={org} />;+ }return (- <Card>- <CardHeader>- <CardTitle className="text-base">No projects</CardTitle>- <CardDescription>- <NoProjectsDescription canCreateProject={canCreateProject} />- </CardDescription>- </CardHeader>- <CardFooter className="gap-2">- {canCreateProject && (- <Button asChild>- <Link href={createProjectRoute(orgId)}>- <PlusIcon size="base" __rawClassName="mr-2" aria-hidden="true" />- New project- </Link>- </Button>- )}- <Button asChild variant="secondary">- <Link href={`/organization/${orgId}/settings`}>- <Settings size="base" __rawClassName="mr-2" aria-hidden="true" />- Organization settings- </Link>- </Button>- </CardFooter>- </Card>+ <OrganizationSettingsTile+ orgId={org.id}+ orgName={org.name}+ state={canCreateProject ? "noProjects" : "noProjectAccess"}+ />);};-/** NoProjectsDescription explains an empty project list by whether the user can create projects */-const NoProjectsDescription = ({- canCreateProject,-}: {- canCreateProject: boolean;-}) => {- if (canCreateProject) return <>This organization has no projects yet.</>;- return <>You don't have access to any projects in this organization.</>;+/** ConnectedGatewayMemberTile loads the member's gateway status into the tile */+const ConnectedGatewayMemberTile = ({ org }: { org: Organization }) => {+ const state = useGatewayMemberStatus(org.id);+ return (+ <OrganizationSettingsTile orgId={org.id} orgName={org.name} state={state} />+ );};export const OrganizationProjectOverview = () => {diff --git a/web/src/features/organizations/components/OrganizationSettingsTile/OrganizationSettingsTile.stories.tsx b/web/src/features/organizations/components/OrganizationSettingsTile/OrganizationSettingsTile.stories.tsxnew file mode 100644index 0000000000..f85026f791--- /dev/null+++ b/web/src/features/organizations/components/OrganizationSettingsTile/OrganizationSettingsTile.stories.tsx@@ -0,0 +1,31 @@+import preview from "@/.storybook/preview";+import { OrganizationSettingsTile } from "./OrganizationSettingsTile";++const meta = preview.meta({+ component: OrganizationSettingsTile,+ args: { orgId: "org-acme", orgName: "Acme" },+});++export const NoProjects = meta.story({+ args: { state: "noProjects" },+});++export const NoProjectAccess = meta.story({+ args: { state: "noProjectAccess" },+});++export const GatewayNoKey = meta.story({+ args: { state: "gatewayNoKey" },+});++export const GatewayHasKey = meta.story({+ args: { state: "gatewayHasKey" },+});++export const GatewaySetupPending = meta.story({+ args: { state: "gatewaySetupPending" },+});++export const GatewayLoading = meta.story({+ args: { state: "gatewayLoading" },+});diff --git a/web/src/features/organizations/components/OrganizationSettingsTile/OrganizationSettingsTile.tsx b/web/src/features/organizations/components/OrganizationSettingsTile/OrganizationSettingsTile.tsxnew file mode 100644index 0000000000..c7cb8831f2--- /dev/null+++ b/web/src/features/organizations/components/OrganizationSettingsTile/OrganizationSettingsTile.tsx@@ -0,0 +1,147 @@+import {+ BookOpen,+ KeyRound,+ PlusIcon,+ Settings,+ Waypoints,+} from "@langfuse/icons";++import { Button } from "@/src/components/design-system/Button/Button";+import {+ Card,+ CardDescription,+ CardFooter,+ CardHeader,+ CardTitle,+} from "@/src/components/ui/card";+import { Skeleton } from "@/src/components/ui/skeleton";+import { GATEWAY_OVERVIEW_DOCS_URL } from "@/src/features/ai-gateway/constants/gatewayDocsUrls";+import { createProjectRoute } from "@/src/features/setup/setupRoutes";++export type OrganizationSettingsTileState =+ | "noProjects"+ | "noProjectAccess"+ | "gatewayLoading"+ | "gatewaySetupPending"+ | "gatewayNoKey"+ | "gatewayHasKey";++export type OrganizationSettingsTileProps = {+ orgId: string;+ orgName: string;+ state: OrganizationSettingsTileState;+};++/** OrganizationSettingsTile shows a member without projects their next step in the org */+export function OrganizationSettingsTile({+ orgId,+ orgName,+ state,+}: OrganizationSettingsTileProps) {+ const actions = tileActions(state, orgId);+ return (+ <Card>+ <CardHeader>+ <CardTitle className="flex items-center gap-2 text-base">+ {isGatewayState(state) && (+ <Waypoints size="base" color="default" aria-hidden="true" />+ )}+ {isGatewayState(state) ? "AI Gateway" : "No projects"}+ </CardTitle>+ <CardDescription>+ {state === "gatewayLoading" ? (+ <Skeleton className="h-5 w-2/3" />+ ) : (+ tileDescription(state, orgName)+ )}+ </CardDescription>+ </CardHeader>+ {actions !== null && <CardFooter className="gap-2">{actions}</CardFooter>}+ </Card>+ );+}++function isGatewayState(state: OrganizationSettingsTileState) {+ return state.startsWith("gateway");+}++function tileDescription(+ state: Exclude<OrganizationSettingsTileState, "gatewayLoading">,+ orgName: string,+) {+ switch (state) {+ case "noProjects":+ return "This organization has no projects yet.";+ case "noProjectAccess":+ return "You don't have access to any projects in this organization.";+ case "gatewaySetupPending":+ return `The AI Gateway of ${orgName} isn't ready yet. Your admin is still setting it up, so check back soon.`;+ case "gatewayNoKey":+ return `You've been invited to use the AI Gateway of ${orgName}. Create your personal gateway key to start using your team's AI models.`;+ case "gatewayHasKey":+ return `You're set up with the AI Gateway of ${orgName}. Manage your gateway keys or see which AI models you can use.`;+ }+}++function tileActions(state: OrganizationSettingsTileState, orgId: string) {+ const settingsButton = (+ <Button+ variant="secondary"+ href={`/organization/${orgId}/settings`}+ icon={Settings}+ text="Organization settings"+ />+ );+ const keysHref = `/organization/${orgId}/settings/ai-gateway-api-keys`;+ const docsButton = (+ <Button+ variant="secondary"+ href={GATEWAY_OVERVIEW_DOCS_URL}+ icon={BookOpen}+ text="What's the AI Gateway?"+ />+ );++ switch (state) {+ case "noProjects":+ return (+ <>+ <Button+ href={createProjectRoute(orgId)}+ icon={PlusIcon}+ text="New project"+ />+ {settingsButton}+ </>+ );+ case "noProjectAccess":+ return settingsButton;+ case "gatewayLoading":+ return null;+ case "gatewaySetupPending":+ return docsButton;+ case "gatewayNoKey":+ return (+ <>+ <Button href={keysHref} icon={KeyRound} text="Create gateway key" />+ {docsButton}+ </>+ );+ case "gatewayHasKey":+ return (+ <>+ <Button+ variant="secondary"+ href={keysHref}+ icon={KeyRound}+ text="Manage gateway keys"+ />+ <Button+ variant="secondary"+ href={`/organization/${orgId}/settings/ai-gateway-models`}+ text="View models"+ />+ </>+ );+ }+}diff --git a/web/src/features/organizations/hooks/useGatewayMemberStatus.ts b/web/src/features/organizations/hooks/useGatewayMemberStatus.tsnew file mode 100644index 0000000000..ee115142dd--- /dev/null+++ b/web/src/features/organizations/hooks/useGatewayMemberStatus.ts@@ -0,0 +1,37 @@+import { useGatewaySettingsAccess } from "@/src/features/ai-gateway/hooks/useGatewaySettingsAccess";+import { isApiKeyExpired } from "@/src/features/apiKey/helpers/isApiKeyExpired";+import { type OrganizationSettingsTileState } from "@/src/features/organizations/components/OrganizationSettingsTile/OrganizationSettingsTile";+import { api } from "@/src/utils/api";++/** A gateway member's next step in an org, as an OrganizationSettingsTile state */+export function useGatewayMemberStatus(+ organizationId: string,+): OrganizationSettingsTileState {+ const { isIngestionConfigured, isSetupStatusPending } =+ useGatewaySettingsAccess(organizationId);+ // Members only see their own keys. Sorted by expiry descending (no expiry+ // first), the first row is live exactly when the member has a live key.+ const longestLivedKey = api.aiGateway.listApiKeys.useQuery(+ {+ orgId: organizationId,+ page: 0,+ limit: 1,+ orderBy: { column: "expiresAt", order: "DESC" },+ },+ { enabled: isIngestionConfigured === true },+ );++ if (isIngestionConfigured === false) return "gatewaySetupPending";+ // On a failed status query, still offer key creation; the keys page reports the error.+ if (+ longestLivedKey.isError ||+ (!isSetupStatusPending && isIngestionConfigured === undefined)+ ) {+ return "gatewayNoKey";+ }+ if (longestLivedKey.data === undefined) return "gatewayLoading";+ const key = longestLivedKey.data.data[0];+ return key === undefined || isApiKeyExpired(key.apiKey.expiresAt)+ ? "gatewayNoKey"+ : "gatewayHasKey";+}