From bd546f1dacd07fbdc6c3473c80210f53eb8e704b Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Sat, 31 Oct 2026 14:19:17 -0700 Subject: [PATCH 1/3] feat(ui): rebuild the public AI Hub as a searchable list with a details pane The public AI Hub at /ui/model_hub_table (and the older /ui/model_hub) now renders PublicAiHub, built from shadcn parts only: a header with the gateway's base URL and the admin's links, segmented tabs for models, agents, MCP servers and skills, and a list beside a details pane on desktop that becomes a bottom sheet on phones. The open item and tab live in the URL. It keeps every feature the old page had: server-side search, provider, mode and feature filters, sorting, paging, health, rate limits, prices, custom metadata, supported params, usage snippets, the require-auth redirect and the not-enabled state. cURL shows only for chat models, since the old one called chat completions for every mode. The navbar hides the community buttons below the sm breakpoint on every page, and the public navbar uses a smaller logo on phones, so Docs and Blog no longer collide with them. --- .../src/app/model_hub/page.tsx | 24 +- .../src/app/model_hub_table/page.tsx | 33 +-- .../src/components/navbar.tsx | 11 +- .../publicModelHub/AgentInspector.tsx | 77 ++++++ .../components/publicModelHub/FilterChip.tsx | 91 +++++++ .../components/publicModelHub/HubEmpty.tsx | 59 +++++ .../components/publicModelHub/HubHeader.tsx | 107 +++++++++ .../publicModelHub/HubMasterDetail.tsx | 204 ++++++++++++++++ .../components/publicModelHub/HubParts.tsx | 187 +++++++++++++++ .../components/publicModelHub/HubStatus.tsx | 49 ++++ .../publicModelHub/InspectorHeader.tsx | 49 ++++ .../publicModelHub/McpInspector.tsx | 33 +++ .../publicModelHub/ModelInspector.tsx | 160 +++++++++++++ .../components/publicModelHub/ModelsPane.tsx | 222 ++++++++++++++++++ .../PublicAiHub.integration.test.tsx | 169 +++++++++++++ .../components/publicModelHub/PublicAiHub.tsx | 93 ++++++++ .../publicModelHub/ResourcePanes.tsx | 172 ++++++++++++++ .../publicModelHub/SkillInspector.tsx | 38 +++ .../publicModelHub/hubFormat.test.ts | 126 ++++++++++ .../components/publicModelHub/hubFormat.ts | 125 ++++++++++ .../publicModelHub/hubSnippets.test.ts | 54 +++++ .../components/publicModelHub/hubSnippets.ts | 93 ++++++++ .../components/publicModelHub/useHubData.ts | 63 +++++ .../publicModelHub/useHubUrlState.ts | 32 +++ .../components/publicModelHub/useIsNarrow.ts | 16 ++ .../publicModelHub/useRequirePublicHubAuth.ts | 19 ++ 26 files changed, 2262 insertions(+), 44 deletions(-) create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/AgentInspector.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/FilterChip.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/HubEmpty.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/HubHeader.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/HubMasterDetail.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/HubParts.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/HubStatus.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/InspectorHeader.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/McpInspector.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/ModelInspector.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/ResourcePanes.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/SkillInspector.tsx create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/hubFormat.test.ts create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/hubFormat.ts create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.test.ts create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.ts create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/useHubData.ts create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/useHubUrlState.ts create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/useIsNarrow.ts create mode 100644 ui/litellm-dashboard/src/components/publicModelHub/useRequirePublicHubAuth.ts diff --git a/ui/litellm-dashboard/src/app/model_hub/page.tsx b/ui/litellm-dashboard/src/app/model_hub/page.tsx index df6228f3b36..60a2f054dff 100644 --- a/ui/litellm-dashboard/src/app/model_hub/page.tsx +++ b/ui/litellm-dashboard/src/app/model_hub/page.tsx @@ -1,27 +1,19 @@ "use client"; -import React, { Suspense, useEffect, useState } from "react"; + import { useSearchParams } from "next/navigation"; -import PublicModelHubPage from "@/components/public_model_hub"; +import { Suspense } from "react"; -function PublicModelHubContent() { - const searchParams = useSearchParams()!; - const key = searchParams.get("key"); - const [accessToken, setAccessToken] = useState(null); +import PublicAiHub from "@/components/publicModelHub/PublicAiHub"; - useEffect(() => { - if (!key) { - return; - } - setAccessToken(key); - }, [key]); - - return ; +function PublicAiHubPage() { + const accessToken = useSearchParams()?.get("key") ?? null; + return ; } export default function PublicModelHub() { return ( - Loading...}> - + Loading...}> + ); } diff --git a/ui/litellm-dashboard/src/app/model_hub_table/page.tsx b/ui/litellm-dashboard/src/app/model_hub_table/page.tsx index af6764dcd4c..99df5ed8cfd 100644 --- a/ui/litellm-dashboard/src/app/model_hub_table/page.tsx +++ b/ui/litellm-dashboard/src/app/model_hub_table/page.tsx @@ -1,36 +1,19 @@ "use client"; -import React, { Suspense, useEffect, useState } from "react"; + import { useSearchParams } from "next/navigation"; -import ModelHubTable from "@/components/AIHub/ModelHubTable"; +import { Suspense } from "react"; -function PublicModelHubTableContent() { - const searchParams = useSearchParams()!; - const key = searchParams.get("key"); - const [accessToken, setAccessToken] = useState(null); +import PublicAiHub from "@/components/publicModelHub/PublicAiHub"; - useEffect(() => { - if (!key) { - return; - } - setAccessToken(key); - }, [key]); - - return ( - - ); +function PublicAiHubPage() { + const accessToken = useSearchParams()?.get("key") ?? null; + return ; } export default function PublicModelHubTable() { return ( - Loading...}> - + Loading...}> + ); } diff --git a/ui/litellm-dashboard/src/components/navbar.tsx b/ui/litellm-dashboard/src/components/navbar.tsx index cece15663ec..c3f31644c8a 100644 --- a/ui/litellm-dashboard/src/components/navbar.tsx +++ b/ui/litellm-dashboard/src/components/navbar.tsx @@ -61,7 +61,7 @@ const Navbar: React.FC = ({ return ( {!hideCommunityLinks && ( -
+
)} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/AgentInspector.tsx b/ui/litellm-dashboard/src/components/publicModelHub/AgentInspector.tsx new file mode 100644 index 00000000000..493578b4f16 --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/AgentInspector.tsx @@ -0,0 +1,77 @@ +"use client"; + +import { ExternalLink } from "lucide-react"; + +import type { AgentCard } from "@/components/PublicModelHubTableColumns"; +import { Button } from "@/components/ui/button"; +import { Field, FieldDescription } from "@/components/ui/field"; +import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemTitle } from "@/components/ui/item"; + +import { agentCapabilities } from "./hubFormat"; +import { Badges, CodeBlock, EndpointField, Facts, PaneSection } from "./HubParts"; +import { agentSnippets } from "./hubSnippets"; +import { InspectorHeader } from "./InspectorHeader"; + +const modes = (agent: AgentCard) => + `${(agent.defaultInputModes ?? []).join(", ")} / ${(agent.defaultOutputModes ?? []).join(", ")}`; + +export function AgentInspector({ agent }: { agent: AgentCard }) { + const capabilities = agentCapabilities(agent); + return ( +
+ + 0 && }, + ], + ]} + /> + + {agent.documentationUrl && ( + + )} + {(agent.skills ?? []).length > 0 && ( + + + {agent.skills.map((skill) => ( + + + {skill.name} + {skill.description} + + + + + + ))} + + + )} + + {agentSnippets(agent).map((snippet, index) => ( + + + Step {index + 1}: {snippet.title} + + + + ))} + +
+ ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/FilterChip.tsx b/ui/litellm-dashboard/src/components/publicModelHub/FilterChip.tsx new file mode 100644 index 00000000000..c25a1619845 --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/FilterChip.tsx @@ -0,0 +1,91 @@ +"use client"; + +import { CirclePlus, X } from "lucide-react"; + +import { Button } from "@/components/ui/button"; +import { ButtonGroup } from "@/components/ui/button-group"; +import { + Combobox, + ComboboxContent, + ComboboxEmpty, + ComboboxInput, + ComboboxItem, + ComboboxList, + ComboboxTrigger, +} from "@/components/ui/combobox"; +import { cn } from "@/lib/cva.config"; + +import { firstPlus } from "./hubFormat"; +import { ProviderAvatar } from "./HubParts"; + +interface FilterOption { + value: string; + label: string; + provider?: string; +} + +export function FilterChip({ + label, + noun, + options, + value, + onChange, +}: { + label: string; + noun: string; + options: FilterOption[]; + value: string[]; + onChange: (value: string[]) => void; +}) { + const byValue = new Map(options.map((option) => [option.value, option])); + const selected = value.map((v) => byValue.get(v)?.label ?? v); + const active = value.length > 0; + return ( + + + multiple + items={options} + value={options.filter((option) => value.includes(option.value))} + onValueChange={(next) => onChange(next.map((option) => option.value))} + itemToStringLabel={(option) => option.label} + isItemEqualToValue={(a, b) => a.value === b.value} + > + svg:last-child]:hidden", !active && "border-dashed text-muted-foreground")} + /> + } + > + {!active && } + {label} + {active && {firstPlus(selected)}} + + + + No {noun} found + + {(option: FilterOption) => ( + + {option.provider && } + {option.label} + + )} + + + + {active && ( + + )} + + ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/HubEmpty.tsx b/ui/litellm-dashboard/src/components/publicModelHub/HubEmpty.tsx new file mode 100644 index 00000000000..bcf142f1fa6 --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/HubEmpty.tsx @@ -0,0 +1,59 @@ +"use client"; + +import { LayoutGrid } from "lucide-react"; +import * as React from "react"; + +import { Button } from "@/components/ui/button"; +import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "@/components/ui/empty"; + +import { SECTION_TITLE } from "./hubFormat"; + +const noResultsTitle = (noun: string, query: string, filtered: boolean) => { + if (!filtered) return `No ${noun} published yet`; + return query ? `No ${noun} match "${query}"` : `No ${noun} match these filters`; +}; + +export function NoResults({ + icon, + noun, + query, + onClear, +}: { + icon: React.ReactNode; + noun: string; + query: string; + onClear?: () => void; +}) { + return ( + + + {icon} + {noResultsTitle(noun, query, Boolean(onClear))} + + {onClear ? "Try a shorter search or fewer filters" : "Your admin publishes them from the AI Hub page"} + + + {onClear && ( + + + + )} + + ); +} + +export function HubNotEnabled() { + return ( + + + + + + This AI Hub isn't available + Ask your proxy admin to make it public from their Admin UI + + + ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/HubHeader.tsx b/ui/litellm-dashboard/src/components/publicModelHub/HubHeader.tsx new file mode 100644 index 00000000000..527953052be --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/HubHeader.tsx @@ -0,0 +1,107 @@ +"use client"; + +import { ChevronDown, ExternalLink, LayoutGrid } from "lucide-react"; + +import { Button } from "@/components/ui/button"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuGroup, + DropdownMenuItem, + DropdownMenuLabel, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; +import { Field, FieldDescription } from "@/components/ui/field"; +import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from "@/components/ui/input-group"; + +import { gatewayUrl, usefulLinkList } from "./hubFormat"; +import { CopyIconButton } from "./HubParts"; +import { StatusBadge } from "./HubStatus"; +import type { HubInfo } from "./useHubData"; + +function LinksMenu({ info }: { info: HubInfo | undefined }) { + const links = usefulLinkList(info?.useful_links); + if (links.length === 0) return null; + return ( + + }> + Links + + + + {links.map((link) => ( + }> + + {link.title} + + ))} + {info?.litellm_version && ( + <> + + + LiteLLM v{info.litellm_version} + + + )} + + + ); +} + +function BaseUrlField() { + const url = gatewayUrl(); + return ( + + + + Base URL + + + + + + + + Use your LiteLLM key as the API key in any OpenAI-compatible SDK + + + ); +} + +export function HubHeader({ + info, + status, +}: { + info: HubInfo | undefined; + status: "loading" | "operational" | "unavailable"; +}) { + return ( +
+
+
+

+ + AI Hub +

+ {status === "operational" && } +
+

+ {info?.custom_docs_description || "Models, agents, MCP servers and skills you can call through this gateway"} +

+
+ {status !== "unavailable" && ( +
+ + +
+ )} +
+ ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/HubMasterDetail.tsx b/ui/litellm-dashboard/src/components/publicModelHub/HubMasterDetail.tsx new file mode 100644 index 00000000000..b21a16c5a86 --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/HubMasterDetail.tsx @@ -0,0 +1,204 @@ +"use client"; + +import * as React from "react"; + +import { Item, ItemContent, ItemGroup, ItemMedia } from "@/components/ui/item"; +import { ScrollArea } from "@/components/ui/scroll-area"; +import { Sheet, SheetContent, SheetTitle } from "@/components/ui/sheet"; +import { Skeleton } from "@/components/ui/skeleton"; +import { cn } from "@/lib/cva.config"; + +import { InSheet } from "./InspectorHeader"; +import { useOpenHref } from "./useHubUrlState"; +import { useIsNarrow } from "./useIsNarrow"; + +function ListSkeleton() { + return ( + + {[0, 1, 2].map((i) => ( +
+ + + + + + + + + +
+ ))} +
+ ); +} + +function DetailSkeleton() { + return ( +
+ +
+ {[0, 1, 2, 3].map((i) => ( +
+ + +
+ ))} +
+ +
+ ); +} + +const isPlainClick = (event: React.MouseEvent) => { + const opensElsewhere = event.metaKey || event.ctrlKey || event.shiftKey; + return event.button === 0 && !opensElsewhere; +}; + +function Rows({ + rows, + activeKey, + explicit, + getKey, + onSelect, + renderItem, +}: { + rows: T[]; + activeKey: string | undefined; + explicit: boolean; + getKey: (row: T) => string; + onSelect: (key: string) => void; + renderItem: (row: T) => React.ReactNode; +}) { + const hrefFor = useOpenHref(); + const follow = (key: string) => (event: React.MouseEvent) => { + if (!isPlainClick(event)) return; + event.preventDefault(); + onSelect(key); + }; + return ( + + {rows.map((row) => { + const key = getKey(row); + const active = key === activeKey; + return ( +
+ + } + className={cn(active && (explicit ? "bg-muted" : "lg:bg-muted"))} + > + {renderItem(row)} + +
+ ); + })} +
+ ); +} + +export function HubMasterDetail({ + switcher, + toolbar, + rows, + loading, + selectedKey, + getKey, + onSelect, + renderItem, + renderDetail, + empty, + footer, +}: { + switcher?: React.ReactNode; + toolbar: React.ReactNode; + rows: T[]; + loading: boolean; + selectedKey: string | null; + getKey: (row: T) => string; + onSelect: (key: string | null) => void; + renderItem: (row: T) => React.ReactNode; + renderDetail: (row: T) => React.ReactNode; + empty: React.ReactNode; + footer?: React.ReactNode; +}) { + const narrow = useIsNarrow(); + const chosen = rows.find((row) => getKey(row) === selectedKey); + const selected = chosen ?? rows[0]; + const [sheetRow, setSheetRow] = React.useState(chosen); + if (chosen !== undefined && chosen !== sheetRow) setSheetRow(chosen); + const isEmpty = !loading && rows.length === 0; + const list = isEmpty ? ( + empty + ) : ( + <> + + {footer} + + ); + return ( +
+
+
+ {switcher} +
{toolbar}
+
+ {loading ? : list} +
+ {!isEmpty && ( + + {loading ? : selected && renderDetail(selected)} + + )} + onSelect(null)} + > + {sheetRow && renderDetail(sheetRow)} + +
+ ); +} + +function DetailSheet({ + open, + title, + onClose, + children, +}: { + open: boolean; + title: string; + onClose: () => void; + children: React.ReactNode; +}) { + const body = React.useRef(null); + return ( + !next && onClose()}> + + {title} +
+ {children} +
+
+
+ ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/HubParts.tsx b/ui/litellm-dashboard/src/components/publicModelHub/HubParts.tsx new file mode 100644 index 00000000000..e325bd42eed --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/HubParts.tsx @@ -0,0 +1,187 @@ +"use client"; + +import { Copy, Search, X } from "lucide-react"; +import * as React from "react"; + +import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { Field, FieldLabel } from "@/components/ui/field"; +import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group"; +import { ItemTitle } from "@/components/ui/item"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; +import { cn } from "@/lib/cva.config"; +import { copyToClipboard } from "@/utils/dataUtils"; + +import { providerLogo, providerName, SECTION_TITLE } from "./hubFormat"; + +export function CopyIconButton({ value, label, className }: { value: string; label: string; className?: string }) { + return ( + + void copyToClipboard(value, "Copied")} + /> + } + > + + + {label} + + ); +} + +export function CodeBlock({ code, label = "Copy code" }: { code: string; label?: string }) { + return ( +
+ +
+        {code}
+      
+
+ ); +} + +export function ProviderAvatar({ provider, className }: { provider: string; className?: string }) { + const logo = providerLogo(provider); + return ( + + {logo && } + {providerName(provider).charAt(0)} + + ); +} + +export function ProviderName({ provider }: { provider: string }) { + return ( + + + {providerName(provider)} + + ); +} + +export function Badges({ items, mono }: { items: string[]; mono?: boolean }) { + if (items.length === 0) return null; + return ( +
+ {items.map((item) => ( + + {item} + + ))} +
+ ); +} + +export function PaneSection({ + title, + aside, + children, +}: { + title: string; + aside?: React.ReactNode; + children: React.ReactNode; +}) { + return ( +
+
+

{title}

+ {aside} +
+ {children} +
+ ); +} + +export type Fact = { label: string; value: React.ReactNode; wide?: boolean }; + +const BLANK: React.ReactNode[] = [null, undefined, false, "", "-"]; + +const present = (value: React.ReactNode) => !BLANK.includes(value); + +export function Facts({ groups }: { groups: Fact[][] }) { + const shown = groups.map((group) => group.filter((fact) => present(fact.value))).filter((group) => group.length); + if (shown.length === 0) return null; + return ( +
+ {shown.map((group) => ( +
+ {group.map((fact) => ( +
+
{fact.label}
+
{fact.value}
+
+ ))} +
+ ))} +
+ ); +} + +export function EndpointField({ id, value }: { id: string; value: string }) { + return ( + + Endpoint + + + + + + + + ); +} + +export function SearchInput({ + value, + onChange, + placeholder, +}: { + value: string; + onChange: (value: string) => void; + placeholder: string; +}) { + return ( + + + + + onChange(event.target.value)} + placeholder={placeholder} + aria-label={placeholder} + /> + {value && ( + + onChange("")}> + + + + )} + + ); +} + +export function RowTitle({ children }: { children: React.ReactNode }) { + return ( + + {children} + + ); +} + +export function Joined({ parts }: { parts: (string | null | undefined)[] }) { + return parts.filter(Boolean).map((part, index) => ( + + {index > 0 && " · "} + {part} + + )); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/HubStatus.tsx b/ui/litellm-dashboard/src/components/publicModelHub/HubStatus.tsx new file mode 100644 index 00000000000..cae5211f3ab --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/HubStatus.tsx @@ -0,0 +1,49 @@ +"use client"; + +import { CircleCheck, CircleDashed, CircleX } from "lucide-react"; + +import type { ModelGroupInfo } from "@/components/PublicModelHubTableColumns"; +import { Badge } from "@/components/ui/badge"; +import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/ui/hover-card"; +import { cn } from "@/lib/cva.config"; + +import { healthOf, type HealthTone, relativeTime } from "./hubFormat"; + +const TONE_ICON = { success: CircleCheck, error: CircleX, neutral: CircleDashed } as const; +const TONE_CLASS = { + success: "border-success/25 bg-success/10 text-success", + error: "border-destructive/25 bg-destructive/10 text-destructive", + neutral: "text-muted-foreground", +} as const; + +export function StatusBadge({ tone, label }: { tone: HealthTone; label: string }) { + const Icon = TONE_ICON[tone]; + return ( + + + {label} + + ); +} + +export function HealthBadge({ model }: { model: ModelGroupInfo }) { + const badge = ; + if (!model.health_status) return badge; + return ( + + }> + {badge} + + +
+
Response time
+
+ {model.health_response_time ? `${Math.round(model.health_response_time)} ms` : "-"} +
+
Last checked
+
{relativeTime(model.health_checked_at)}
+
+
+
+ ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/InspectorHeader.tsx b/ui/litellm-dashboard/src/components/publicModelHub/InspectorHeader.tsx new file mode 100644 index 00000000000..4400b18ce1f --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/InspectorHeader.tsx @@ -0,0 +1,49 @@ +"use client"; + +import { X } from "lucide-react"; +import * as React from "react"; + +import { Button } from "@/components/ui/button"; +import { SheetClose } from "@/components/ui/sheet"; +import { cn } from "@/lib/cva.config"; + +import { SECTION_TITLE } from "./hubFormat"; +import { CopyIconButton } from "./HubParts"; + +export const InSheet = React.createContext(false); + +export function InspectorHeader({ + media, + title, + copyLabel, + status, + description, +}: { + media?: React.ReactNode; + title: string; + copyLabel: string; + status?: React.ReactNode; + description?: React.ReactNode; +}) { + const inSheet = React.useContext(InSheet); + return ( +
+
+ {media} +

{title}

+ + + {status && {status}} + {inSheet && ( + } + > + + + )} +
+ {status && {status}} + {description &&

{description}

} +
+ ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/McpInspector.tsx b/ui/litellm-dashboard/src/components/publicModelHub/McpInspector.tsx new file mode 100644 index 00000000000..b20d6273551 --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/McpInspector.tsx @@ -0,0 +1,33 @@ +"use client"; + +import type { MCPServerData } from "@/components/PublicModelHubTableColumns"; + +import { mcpAuthLabel } from "./hubFormat"; +import { CodeBlock, EndpointField, Facts, PaneSection } from "./HubParts"; +import { mcpEndpoint, mcpSnippet } from "./hubSnippets"; +import { InspectorHeader } from "./InspectorHeader"; + +export function McpInspector({ server }: { server: MCPServerData }) { + return ( +
+ + + + + + +
+ ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/ModelInspector.tsx b/ui/litellm-dashboard/src/components/publicModelHub/ModelInspector.tsx new file mode 100644 index 00000000000..1130b3d625e --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/ModelInspector.tsx @@ -0,0 +1,160 @@ +"use client"; + +import { ChevronDown } from "lucide-react"; +import * as React from "react"; + +import type { ModelGroupInfo } from "@/components/PublicModelHubTableColumns"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; +import { Button } from "@/components/ui/button"; +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; + +import { + formatPerMillion, + formatTokens, + modeLabel, + modelCapabilities, + providerName, + wildcardExample, +} from "./hubFormat"; +import { Badges, CodeBlock, type Fact, Facts, PaneSection, ProviderAvatar, ProviderName } from "./HubParts"; +import { curlSnippet, modelSnippet } from "./hubSnippets"; +import { HealthBadge } from "./HubStatus"; +import { InspectorHeader } from "./InspectorHeader"; + +const tokens = (value: number | undefined) => (value ? `${formatTokens(value)} tokens` : null); + +const modelFacts = (model: ModelGroupInfo): Fact[][] => { + const providers = model.providers ?? []; + const tags = model.custom_tags ?? []; + return [ + [ + { label: "Mode", value: model.mode ? modeLabel(model.mode) : null }, + { label: "Context", value: tokens(model.max_input_tokens) }, + { label: "Max output", value: tokens(model.max_output_tokens) }, + ], + [ + { label: "Input / 1M tokens", value: formatPerMillion(model.input_cost_per_token) }, + { label: "Output / 1M tokens", value: formatPerMillion(model.output_cost_per_token) }, + ], + [ + { label: "Requests per minute", value: model.rpm }, + { label: "Tokens per minute", value: model.tpm ? formatTokens(model.tpm) : null }, + ], + [ + { + label: providers.length > 1 ? "Providers" : "Provider", + wide: true, + value: providers.length > 0 && ( + + {providers.map((provider) => ( + + ))} + + ), + }, + { label: "Tags", wide: true, value: tags.length > 0 && }, + ], + ]; +}; + +function CallThisModel({ model }: { model: ModelGroupInfo }) { + const curl = curlSnippet(model); + if (!curl) { + return ( + + + + ); + } + return ( + + + + Python + cURL + + + + + + + + + + ); +} + +function CustomMetadata({ model }: { model: ModelGroupInfo }) { + const metadata = Object.entries(model.custom_metadata ?? {}); + if (metadata.length === 0) return null; + return ( + +
+ {metadata.map(([key, value]) => ( + +
{key}
+
{String(value)}
+
+ ))} +
+
+ ); +} + +function SupportedParams({ params }: { params: string[] }) { + if (params.length === 0) return null; + return ( + + }> + Show {params.length} + + + } + > + + + + + + ); +} + +export function ModelInspector({ model }: { model: ModelGroupInfo }) { + const providers = model.providers ?? []; + const capabilities = modelCapabilities(model); + return ( +
+ } + title={model.model_group} + copyLabel="Copy model name" + status={} + description={ + model.description || `${modeLabel(model.mode)} model from ${providers.map(providerName).join(", ")}` + } + /> + {model.model_group.includes("*") && ( + + Wildcard model + + Call it as {wildcardExample(model.model_group)}, with any model name this + provider offers + + + )} + + {capabilities.length > 0 && ( + + + + )} + + + +
+ ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx b/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx new file mode 100644 index 00000000000..91818b28ad5 --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx @@ -0,0 +1,222 @@ +"use client"; + +import { ArrowDownWideNarrow, ArrowUpNarrowWide, Boxes, ChevronLeft, ChevronRight } from "lucide-react"; + +import type { ModelGroupInfo } from "@/components/PublicModelHubTableColumns"; +import { Button } from "@/components/ui/button"; +import { ButtonGroup } from "@/components/ui/button-group"; +import { ItemActions, ItemContent, ItemDescription, ItemMedia } from "@/components/ui/item"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Toggle } from "@/components/ui/toggle"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; + +import { FilterChip } from "./FilterChip"; +import { featureFacetLabel, firstPlus, formatPerMillion, formatTokens, modeLabel, providerName } from "./hubFormat"; +import { HubMasterDetail } from "./HubMasterDetail"; +import { NoResults } from "./HubEmpty"; +import { Joined, ProviderAvatar, RowTitle, SearchInput } from "./HubParts"; +import type { HubData } from "./useHubData"; +import { ModelInspector } from "./ModelInspector"; + +const SORTS = [ + { value: "model_group", label: "Name", desc: false }, + { value: "providers", label: "Provider", desc: false }, + { value: "mode", label: "Mode", desc: false }, + { value: "input_cost_per_token", label: "Input price", desc: false }, + { value: "output_cost_per_token", label: "Output price", desc: false }, + { value: "max_input_tokens", label: "Context", desc: true }, + { value: "max_output_tokens", label: "Max output", desc: true }, + { value: "rpm", label: "Rate limit", desc: true }, +]; + +type Models = HubData["models"]; + +function ModelsPager({ models }: { models: Models }) { + const { pagination, rowCount, rows, onPaginationChange } = models; + if (!rowCount) return null; + const start = pagination.pageIndex * pagination.pageSize + 1; + const end = start + rows.length - 1; + const go = (pageIndex: number) => onPaginationChange({ ...pagination, pageIndex }); + return ( +
+ + {start}–{end} of {rowCount} + + + + + +
+ ); +} + +function SortControl({ models }: { models: Models }) { + const field = models.sorting[0]?.id ?? "model_group"; + const desc = models.sorting[0]?.desc ?? false; + const pick = (value: string | null) => { + const sort = SORTS.find((option) => option.value === value) ?? SORTS[0]; + models.onSortingChange([{ id: sort.value, desc: sort.desc }]); + }; + return ( + + + + models.onSortingChange([{ id: field, desc: pressed }])} + className="dark:bg-input/30 dark:hover:bg-input/50" + /> + } + > + {desc ? : } + + Sort descending + + + ); +} + +function ModelsToolbar({ hub }: { hub: HubData }) { + const { models, facets } = hub; + return ( + <> +
+ + +
+
+ ({ value: p, label: providerName(p), provider: p }))} + value={models.providerValues} + onChange={models.onProvidersChange} + /> + ({ value: m, label: modeLabel(m) }))} + value={models.modeValues} + onChange={models.onModesChange} + /> + ({ value: f, label: featureFacetLabel(f) }))} + value={models.featureValues} + onChange={models.onFeaturesChange} + /> +
+ + ); +} + +const prices = (model: ModelGroupInfo) => [ + model.input_cost_per_token ? `${formatPerMillion(model.input_cost_per_token)} / 1M in` : null, + model.output_cost_per_token ? `${formatPerMillion(model.output_cost_per_token)} / 1M out` : null, +]; + +function ModelRow({ model }: { model: ModelGroupInfo }) { + const [input, output] = prices(model); + const priced = Boolean(input || output); + return ( + <> + + + + + {model.model_group} + + + + {priced && ( + + + + )} + + {priced && ( + + {input && {input}} + {output && {output}} + + )} + + ); +} + +export function ModelsPane({ + hub, + selected, + onSelect, +}: { + hub: HubData; + selected: string | null; + onSelect: (key: string | null) => void; +}) { + const { models } = hub; + const clear = () => { + models.onSearchChange(""); + models.onColumnFiltersChange([]); + }; + return ( + model.model_group} + onSelect={onSelect} + empty={ + } + noun="models" + query={models.searchValue} + onClear={models.hasActiveQuery ? clear : undefined} + /> + } + toolbar={} + renderItem={(model) => } + renderDetail={(model) => } + footer={} + /> + ); +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx b/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx new file mode 100644 index 00000000000..3f873eb8b59 --- /dev/null +++ b/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx @@ -0,0 +1,169 @@ +import { fireEvent } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; + +import { renderWithProviders, screen, testQueryClient, waitFor } from "../../../tests/test-utils"; +import PublicAiHub from "./PublicAiHub"; + +const { apiGetMock, uiSettings, replaceMock, hubInfo } = vi.hoisted(() => ({ + apiGetMock: vi.fn(), + uiSettings: { values: {} as Record }, + replaceMock: vi.fn(), + hubInfo: { + docs_title: "", + custom_docs_description: null, + litellm_version: "1.90.0", + useful_links: { "Getting started": { url: "https://docs.example.com", index: 0 } }, + }, +})); + +vi.mock("next/navigation", () => ({ + useSearchParams: () => new URLSearchParams(), + usePathname: () => "/model_hub_table", + useRouter: () => ({ push: vi.fn(), replace: vi.fn(), refresh: vi.fn() }), +})); + +vi.mock("@/components/navbar", () => ({ default: () =>
- {!isEmpty && ( - - {loading ? : selected && renderDetail(selected)} - - )} + {!isEmpty && {detail()}} - + { + if (model.description) return model.description; + const providers = (model.providers ?? []).map(providerName).join(", "); + return model.mode && providers ? `${modeLabel(model.mode)} model from ${providers}` : undefined; +}; + const tokens = (value: number | undefined) => (value ? `${formatTokens(value)} tokens` : null); const modelFacts = (model: ModelGroupInfo): Fact[][] => { @@ -133,9 +139,7 @@ export function ModelInspector({ model }: { model: ModelGroupInfo }) { title={model.model_group} copyLabel="Copy model name" status={} - description={ - model.description || `${modeLabel(model.mode)} model from ${providers.map(providerName).join(", ")}` - } + description={summary(model)} /> {model.model_group.includes("*") && ( diff --git a/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx b/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx index 91818b28ad5..7120d14feb1 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx +++ b/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx @@ -9,13 +9,14 @@ import { ItemActions, ItemContent, ItemDescription, ItemMedia } from "@/componen import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Toggle } from "@/components/ui/toggle"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; +import { displayMode } from "@/lib/decisionModels"; import { FilterChip } from "./FilterChip"; import { featureFacetLabel, firstPlus, formatPerMillion, formatTokens, modeLabel, providerName } from "./hubFormat"; import { HubMasterDetail } from "./HubMasterDetail"; -import { NoResults } from "./HubEmpty"; +import { LoadFailed, NoResults } from "./HubEmpty"; import { Joined, ProviderAvatar, RowTitle, SearchInput } from "./HubParts"; -import type { HubData } from "./useHubData"; +import { type HubData, useOpenedModel } from "./useHubData"; import { ModelInspector } from "./ModelInspector"; const SORTS = [ @@ -128,7 +129,10 @@ function ModelsToolbar({ hub }: { hub: HubData }) { ({ value: m, label: modeLabel(m) }))} + options={[...new Set(facets.modes.map((m) => displayMode(m) ?? m))].map((m) => ({ + value: m, + label: modeLabel(m), + }))} value={models.modeValues} onChange={models.onModesChange} /> @@ -194,6 +198,7 @@ export function ModelsPane({ onSelect: (key: string | null) => void; }) { const { models } = hub; + const opened = useOpenedModel(selected, models.rows, !models.isLoading); const clear = () => { models.onSearchChange(""); models.onColumnFiltersChange([]); @@ -203,15 +208,21 @@ export function ModelsPane({ rows={models.rows} loading={models.isLoading} selectedKey={selected} + opened={opened.model} + openPending={opened.pending} getKey={(model) => model.model_group} onSelect={onSelect} empty={ - } - noun="models" - query={models.searchValue} - onClear={models.hasActiveQuery ? clear : undefined} - /> + models.error ? ( + + ) : ( + } + noun="models" + query={models.searchValue} + onClear={models.hasActiveQuery ? clear : undefined} + /> + ) } toolbar={} renderItem={(model) => } diff --git a/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx b/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx index 3f873eb8b59..b51da66ce27 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx +++ b/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx @@ -2,11 +2,14 @@ import { fireEvent } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { agentHubPublicModelsCall, mcpHubPublicServersCall, skillHubPublicCall } from "@/components/networking"; + import { renderWithProviders, screen, testQueryClient, waitFor } from "../../../tests/test-utils"; import PublicAiHub from "./PublicAiHub"; -const { apiGetMock, uiSettings, replaceMock, hubInfo } = vi.hoisted(() => ({ +const { apiGetMock, navigation, uiSettings, replaceMock, hubInfo } = vi.hoisted(() => ({ apiGetMock: vi.fn(), + navigation: { params: new URLSearchParams() }, uiSettings: { values: {} as Record }, replaceMock: vi.fn(), hubInfo: { @@ -18,7 +21,7 @@ const { apiGetMock, uiSettings, replaceMock, hubInfo } = vi.hoisted(() => ({ })); vi.mock("next/navigation", () => ({ - useSearchParams: () => new URLSearchParams(), + useSearchParams: () => navigation.params, usePathname: () => "/model_hub_table", useRouter: () => ({ push: vi.fn(), replace: vi.fn(), refresh: vi.fn() }), })); @@ -75,10 +78,18 @@ const page = (data: unknown[]) => ({ links: { self: MODEL_HUB_PATH, first: MODEL_HUB_PATH, prev: null, next: null, last: MODEL_HUB_PATH }, }); +const OFF_PAGE_MODEL = { model_group: "o1-pro", providers: ["openai"], mode: "chat", description: "Deep reasoning" }; + const respondWithModels = () => - apiGetMock.mockImplementation((path: string) => - Promise.resolve(path === MODEL_HUB_PATH ? page(MODELS) : { ...page([]), meta: { page: 1, page_size: 100 } }), - ); + apiGetMock.mockImplementation((path: string, options?: { query?: Record }) => { + if (path !== MODEL_HUB_PATH) return Promise.resolve({ ...page([]), meta: { page: 1, page_size: 100 } }); + return Promise.resolve(options?.query?.q === "o1-pro" ? page([OFF_PAGE_MODEL]) : page(MODELS)); + }); + +const tokenExpiringIn = (seconds: number) => { + const encode = (value: object) => btoa(JSON.stringify(value)).replace(/=+$/, ""); + return `${encode({ alg: "HS256" })}.${encode({ exp: Math.floor(Date.now() / 1000) + seconds })}.signature`; +}; beforeAll(() => { Object.defineProperty(window, "matchMedia", { @@ -96,6 +107,8 @@ beforeEach(() => { vi.clearAllMocks(); testQueryClient.clear(); uiSettings.values = {}; + navigation.params = new URLSearchParams(); + document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"; respondWithModels(); vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response("{}", { status: 404 })); Object.defineProperty(window, "location", { @@ -152,18 +165,78 @@ describe("PublicAiHub", () => { expect(screen.getByText("LiteLLM v1.90.0")).toBeInTheDocument(); }); - it("says the hub is unavailable when the public models call fails", async () => { - apiGetMock.mockRejectedValue(new Error("Public model hub is not enabled")); + it("keeps agents reachable when only the models call fails", async () => { + const user = userEvent.setup(); + apiGetMock.mockRejectedValue(new Error("No models configured")); + renderWithProviders(); + + expect(await screen.findByText("Couldn't load models")).toBeInTheDocument(); + expect(screen.getByRole("textbox", { name: "Search models" })).toBeInTheDocument(); + await user.click(screen.getByRole("tab", { name: /^Agents\s*1$/ })); + expect(await screen.findByRole("link", { name: /research-assistant/ })).toBeInTheDocument(); + }); + + it("says the hub is unavailable when every hub call fails", async () => { + apiGetMock.mockRejectedValue(new Error("Not found")); + vi.mocked(agentHubPublicModelsCall).mockRejectedValueOnce(new Error("Not found")); + vi.mocked(mcpHubPublicServersCall).mockRejectedValueOnce(new Error("Not found")); + vi.mocked(skillHubPublicCall).mockRejectedValueOnce(new Error("Not found")); renderWithProviders(); expect(await screen.findByText("This AI Hub isn't available")).toBeInTheDocument(); expect(screen.queryByRole("tablist")).not.toBeInTheDocument(); }); + it("keeps the page's other query params in each row's link", async () => { + navigation.params = new URLSearchParams("tab=agents&key=abc"); + renderWithProviders(, { searchParams: { tab: "agents", key: "abc" } }); + + expect(await screen.findByRole("link", { name: /research-assistant/ })).toHaveAttribute( + "href", + "?tab=agents&key=abc&open=research-assistant", + ); + }); + + it("clears the open item when switching tabs", async () => { + const onUrlUpdate = vi.fn(); + const user = userEvent.setup(); + renderWithProviders(, { searchParams: { open: "gpt-5" }, onUrlUpdate }); + + expect(await screen.findByRole("heading", { level: 2, name: "gpt-5" })).toBeInTheDocument(); + await user.click(screen.getByRole("tab", { name: /^Agents/ })); + + await waitFor(() => + expect(onUrlUpdate).toHaveBeenLastCalledWith(expect.objectContaining({ queryString: "?tab=agents" })), + ); + }); + + it("opens a shared link to a model that is not on the first page", async () => { + renderWithProviders(, { searchParams: { open: "o1-pro" } }); + + expect(await screen.findByRole("heading", { level: 2, name: "o1-pro" })).toBeInTheDocument(); + expect(screen.getByText("Deep reasoning")).toBeInTheDocument(); + }); + + it("says when a shared link names something that is no longer listed", async () => { + renderWithProviders(, { searchParams: { open: "retired-model" } }); + + expect(await screen.findByText("\u201cretired-model\u201d isn't listed here")).toBeInTheDocument(); + expect(screen.queryByRole("heading", { level: 2, name: "claude-sonnet-4-5" })).not.toBeInTheDocument(); + }); + it("sends visitors without a session to login when the admin requires it", async () => { uiSettings.values = { require_auth_for_public_ai_hub: true }; renderWithProviders(); await waitFor(() => expect(replaceMock).toHaveBeenCalledWith(expect.stringContaining("login"))); }); + + it("keeps a signed-in visitor on the hub when the admin requires sign-in", async () => { + uiSettings.values = { require_auth_for_public_ai_hub: true }; + document.cookie = `token=${tokenExpiringIn(3600)}; path=/`; + renderWithProviders(); + + expect(await screen.findByRole("heading", { level: 2, name: "claude-sonnet-4-5" })).toBeInTheDocument(); + expect(replaceMock).not.toHaveBeenCalled(); + }); }); diff --git a/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.tsx b/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.tsx index e32578cfa2c..07c612e840c 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.tsx +++ b/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.tsx @@ -7,7 +7,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { TooltipProvider } from "@/components/ui/tooltip"; import { ThemeProvider } from "@/contexts/ThemeContext"; -import { HubHeader } from "./HubHeader"; +import { HubHeader, type HubStatus } from "./HubHeader"; import { HubNotEnabled } from "./HubEmpty"; import { ModelsPane } from "./ModelsPane"; import { AgentsPane, McpPane, SkillsPane } from "./ResourcePanes"; @@ -24,9 +24,11 @@ function TabLabel({ children, count }: { children: ReactNode; count: number | un ); } -const hubStatus = (hub: HubData) => { +const hubStatus = (hub: HubData): HubStatus => { + const failures = [hub.models.error, hub.agents.error, hub.mcp.error, hub.skills.error].filter(Boolean); + if (failures.length === 4) return "unavailable"; if (hub.models.isLoading) return "loading"; - return hub.models.error ? "unavailable" : "operational"; + return failures.length > 0 ? "degraded" : "operational"; }; function HubTabs({ hub }: { hub: HubData }) { @@ -55,13 +57,31 @@ function HubTabs({ hub }: { hub: HubData }) { - + void hub.agents.refetch()} + {...paneProps} + /> - + void hub.mcp.refetch()} + {...paneProps} + /> - + void hub.skills.refetch()} + {...paneProps} + /> ); diff --git a/ui/litellm-dashboard/src/components/publicModelHub/ResourcePanes.tsx b/ui/litellm-dashboard/src/components/publicModelHub/ResourcePanes.tsx index a1623a7495a..d9b1030ce50 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/ResourcePanes.tsx +++ b/ui/litellm-dashboard/src/components/publicModelHub/ResourcePanes.tsx @@ -6,24 +6,22 @@ import * as React from "react"; import type { Plugin } from "@/components/claude_code_plugins/types"; import type { AgentCard, MCPServerData } from "@/components/PublicModelHubTableColumns"; import { ItemActions, ItemContent, ItemDescription, ItemMedia } from "@/components/ui/item"; +import { matchesSearchTerm } from "@/utils/searchUtils"; import { AgentInspector } from "./AgentInspector"; import { FilterChip } from "./FilterChip"; import { mcpAuthLabel } from "./hubFormat"; import { HubMasterDetail } from "./HubMasterDetail"; -import { NoResults } from "./HubEmpty"; +import { LoadFailed, NoResults } from "./HubEmpty"; import { RowTitle, SearchInput } from "./HubParts"; import { McpInspector } from "./McpInspector"; import { SkillInspector } from "./SkillInspector"; -const matches = (fields: (string | null | undefined)[], query: string) => { - const needle = query.trim().toLowerCase(); - return !needle || fields.some((field) => field?.toLowerCase().includes(needle)); -}; - interface ResourcePaneProps { rows: T[]; loading: boolean; + error: boolean; + onRetry: () => void; noun: string; icon: React.ReactNode; search: (row: T) => (string | null | undefined)[]; @@ -40,6 +38,8 @@ interface ResourcePaneProps { function ResourcePane({ rows, loading, + error, + onRetry, noun, icon, search, @@ -55,8 +55,11 @@ function ResourcePane({ const [query, setQuery] = React.useState(""); const [chosen, setChosen] = React.useState([]); const options = [...new Set(rows.flatMap(filter.values))].sort(); - const shown = rows.filter( - (row) => matches(search(row), query) && (chosen.length === 0 || filter.values(row).some((v) => chosen.includes(v))), + const sorted = [...rows].sort((a, b) => title(a).localeCompare(title(b))); + const shown = sorted.filter( + (row) => + matchesSearchTerm(query, search(row)) && + (chosen.length === 0 || filter.values(row).some((v) => chosen.includes(v))), ); const filtered = query.trim() !== "" || chosen.length > 0; const clear = () => { @@ -68,9 +71,16 @@ function ResourcePane({ rows={shown} loading={loading} selectedKey={selected} + opened={rows.find((row) => getKey(row) === selected)} getKey={getKey} onSelect={onSelect} - empty={} + empty={ + error ? ( + + ) : ( + + ) + } toolbar={
@@ -105,6 +115,8 @@ function ResourcePane({ interface PaneProps { rows: T[] | undefined; loading: boolean; + error: boolean; + onRetry: () => void; selected: string | null; onSelect: (key: string | null) => void; } @@ -138,16 +150,16 @@ export function McpPane({ rows, ...props }: PaneProps) { rows={rows ?? []} noun="MCP servers" icon={} - search={(server) => [server.server_name, server.mcp_info?.description]} + search={(server) => [server.name, server.mcp_info?.description]} filter={{ label: "Transport", noun: "transports", values: (server) => (server.transport ? [server.transport] : []), }} - getKey={(server) => server.server_name} - title={(server) => server.server_name} + getKey={(server) => server.name} + title={(server) => server.name} description={(server) => server.mcp_info?.description} - meta={(server) => mcpAuthLabel(server.auth_type)} + meta={(server) => (server.auth_type ? mcpAuthLabel(server.auth_type) : undefined)} renderDetail={(server) => } /> ); diff --git a/ui/litellm-dashboard/src/components/publicModelHub/SkillInspector.tsx b/ui/litellm-dashboard/src/components/publicModelHub/SkillInspector.tsx index 2434f0d9bff..773ff62830e 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/SkillInspector.tsx +++ b/ui/litellm-dashboard/src/components/publicModelHub/SkillInspector.tsx @@ -1,14 +1,36 @@ "use client"; +import { ExternalLink } from "lucide-react"; + +import { getSourceDisplayText, getSourceLink } from "@/components/claude_code_plugins/helpers"; import type { Plugin } from "@/components/claude_code_plugins/types"; +import { Button } from "@/components/ui/button"; import { Field, FieldDescription } from "@/components/ui/field"; import { Badges, CodeBlock, Facts, PaneSection } from "./HubParts"; import { marketplaceCommand, skillInstallCommand } from "./hubSnippets"; import { InspectorHeader } from "./InspectorHeader"; +function sourceValue(source: Plugin["source"]) { + const link = getSourceLink(source); + const href = link && source.source === "git-subdir" && source.path ? `${link}/tree/main/${source.path}` : link; + if (!href) return getSourceDisplayText(source) || null; + return ( + + ); +} + export function SkillInspector({ skill }: { skill: Plugin }) { const keywords = skill.keywords ?? []; + const added = skill.created_at ? new Date(skill.created_at).toLocaleDateString() : null; return (
@@ -20,6 +42,11 @@ export function SkillInspector({ skill }: { skill: Plugin }) { { label: "Version", value: skill.version }, { label: "Category", value: skill.category }, ], + [ + { label: "Source", wide: true, value: sourceValue(skill.source) }, + { label: "Author", value: skill.author?.name }, + { label: "Added", value: added }, + ], [{ label: "Keywords", wide: true, value: keywords.length > 0 && }], ]} /> diff --git a/ui/litellm-dashboard/src/components/publicModelHub/hubFormat.test.ts b/ui/litellm-dashboard/src/components/publicModelHub/hubFormat.test.ts index b2db644c199..fa668481145 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/hubFormat.test.ts +++ b/ui/litellm-dashboard/src/components/publicModelHub/hubFormat.test.ts @@ -34,6 +34,7 @@ describe("modeLabel", () => { expect(modeLabel("image_generation")).toBe("Image generation"); expect(modeLabel("audio_speech")).toBe("Text to speech"); expect(modeLabel("custom_thing")).toBe("Custom thing"); + expect(modeLabel("evaluation")).toBe("Decisions"); expect(modeLabel(undefined)).toBe("-"); }); }); @@ -50,10 +51,13 @@ describe("formatTokens", () => { }); describe("formatPerMillion", () => { - it("prices per million tokens with two decimals", () => { + it("prices per million tokens with at least two decimals and keeps sub-cent prices", () => { expect(formatPerMillion(0.000003)).toBe("$3.00"); expect(formatPerMillion(0.0000165)).toBe("$16.50"); - expect(formatPerMillion(0)).toBe("-"); + expect(formatPerMillion(3.75e-8)).toBe("$0.0375"); + expect(formatPerMillion(2e-9)).toBe("$0.002"); + expect(formatPerMillion(0)).toBe("Free"); + expect(formatPerMillion(undefined)).toBe("-"); }); }); @@ -70,8 +74,14 @@ describe("capabilities", () => { }); it("lists an agent's enabled capabilities", () => { - const agent = { capabilities: { streaming: true, pushNotifications: true, stateTransitionHistory: false } }; - expect(agentCapabilities(agent as AgentCard)).toEqual(["Streaming", "Push notifications"]); + const agent = { + capabilities: { streaming: true, pushNotifications: true, stateTransitionHistory: true, x: false }, + }; + expect(agentCapabilities(agent as AgentCard)).toEqual([ + "Streaming", + "Push notifications", + "State transition history", + ]); }); }); @@ -90,8 +100,10 @@ describe("relativeTime", () => { expect(relativeTime("2026-10-31T11:59:45Z", now)).toBe("just now"); expect(relativeTime("2026-10-31T11:45:00Z", now)).toBe("15 min ago"); expect(relativeTime("2026-10-31T09:00:00Z", now)).toBe("3 h ago"); + expect(relativeTime("2026-10-30T12:00:00Z", now)).toBe("1 day ago"); expect(relativeTime("2026-10-29T12:00:00Z", now)).toBe("2 days ago"); expect(relativeTime(undefined, now)).toBe("-"); + expect(relativeTime("not-a-date", now)).toBe("-"); }); }); diff --git a/ui/litellm-dashboard/src/components/publicModelHub/hubFormat.ts b/ui/litellm-dashboard/src/components/publicModelHub/hubFormat.ts index a8516a15c8b..f64e32c0edd 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/hubFormat.ts +++ b/ui/litellm-dashboard/src/components/publicModelHub/hubFormat.ts @@ -1,6 +1,7 @@ import { getProxyBaseUrl } from "@/components/networking"; import type { AgentCard, ModelGroupInfo } from "@/components/PublicModelHubTableColumns"; import { getProviderLogoAndName } from "@/components/provider_info_helpers"; +import { displayMode } from "@/lib/decisionModels"; export const SECTION_TITLE = "text-[15px] leading-[22px] font-semibold"; @@ -23,8 +24,10 @@ const MODE_LABELS: Record = { const sentenceCase = (text: string): string => text.replaceAll("_", " ").replace(/^./, (c) => c.toUpperCase()); -export const modeLabel = (mode: string | null | undefined): string => - mode ? MODE_LABELS[mode] ?? sentenceCase(mode) : "-"; +export const modeLabel = (mode: string | null | undefined): string => { + const shown = displayMode(mode); + return shown ? MODE_LABELS[shown] ?? sentenceCase(shown) : "-"; +}; export const formatTokens = (tokens: number | null | undefined): string => { if (!tokens) return "-"; @@ -33,8 +36,20 @@ export const formatTokens = (tokens: number | null | undefined): string => { return String(tokens); }; -export const formatPerMillion = (cost: number | null | undefined): string => - cost ? `$${(cost * 1_000_000).toFixed(2)}` : "-"; +const PER_MILLION_FORMAT: Intl.NumberFormatOptions = { + style: "currency", + currency: "USD", + minimumFractionDigits: 2, + maximumFractionDigits: 4, + useGrouping: false, +}; + +const PER_MILLION = new Intl.NumberFormat("en-US", PER_MILLION_FORMAT); + +export const formatPerMillion = (cost: number | null | undefined): string => { + if (cost === 0) return "Free"; + return cost ? PER_MILLION.format(cost * 1_000_000) : "-"; +}; export const providerName = (provider: string): string => getProviderLogoAndName(provider).displayName.replace(/\s*\(.*\)$/, ""); @@ -73,7 +88,7 @@ export const modelCapabilities = (model: ModelGroupInfo): string[] => export const agentCapabilities = (agent: AgentCard): string[] => Object.entries(agent.capabilities ?? {}) .filter(([, on]) => on === true) - .map(([key]) => (key === "pushNotifications" ? "Push notifications" : sentenceCase(key))); + .map(([key]) => sentenceCase(key.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase())); export type HealthTone = "success" | "error" | "neutral"; @@ -86,13 +101,15 @@ export const healthOf = (model: ModelGroupInfo): { tone: HealthTone; label: stri HEALTH[model.health_status ?? ""] ?? { tone: "neutral", label: "Not checked" }; export const relativeTime = (iso: string | null | undefined, now: number = Date.now()): string => { - if (!iso) return "-"; - const minutes = Math.max(0, Math.round((now - new Date(iso).getTime()) / 60_000)); + const then = iso ? new Date(iso).getTime() : NaN; + if (Number.isNaN(then)) return "-"; + const minutes = Math.max(0, Math.round((now - then) / 60_000)); if (minutes < 1) return "just now"; if (minutes < 60) return `${minutes} min ago`; const hours = Math.round(minutes / 60); if (hours < 24) return `${hours} h ago`; - return `${Math.round(hours / 24)} days ago`; + const days = Math.round(hours / 24); + return `${days} ${days === 1 ? "day" : "days"} ago`; }; export const gatewayUrl = (): string => getProxyBaseUrl(); diff --git a/ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.test.ts b/ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.test.ts index 91c3cac0ca2..548afeb1755 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.test.ts +++ b/ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.test.ts @@ -18,7 +18,7 @@ const model = (overrides: Partial): ModelGroupInfo => ({ ...overrides, }); -const server = { server_id: "s1", server_name: "github" } as MCPServerData; +const server = { server_id: "s1", name: "github", server_name: "github" } as MCPServerData; afterEach(() => { vi.unstubAllGlobals(); @@ -46,6 +46,11 @@ describe("MCP and skill snippets", () => { expect(mcpSnippet(server)).toContain('"url": "https://gateway.example.com/github/mcp"'); }); + it("routes a server without a server name through its listed name", () => { + const aliased = { server_id: "s2", name: "my_alias", server_name: null } as unknown as MCPServerData; + expect(mcpEndpoint(aliased)).toBe("https://gateway.example.com/my_alias/mcp"); + }); + it("adds the gateway's marketplace", () => { expect(marketplaceCommand()).toBe( "/plugin marketplace add https://gateway.example.com/claude-code/marketplace.json", diff --git a/ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.ts b/ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.ts index 8dc81e13ac6..b34db7c1b39 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.ts +++ b/ui/litellm-dashboard/src/components/publicModelHub/hubSnippets.ts @@ -72,15 +72,15 @@ response = await client.send_message(request)`, }, ]; -export const mcpEndpoint = (server: MCPServerData): string => `${gatewayUrl()}/${server.server_name}/mcp`; +export const mcpEndpoint = (server: MCPServerData): string => `${gatewayUrl()}/${server.name}/mcp`; export const mcpSnippet = (server: MCPServerData): string => `from fastmcp import Client client = Client({ "mcpServers": { - "${server.server_name}": { + "${server.name}": { "url": "${mcpEndpoint(server)}", - "headers": {"x-litellm-api-key": "Bearer $LITELLM_API_KEY"}, + "headers": {"x-litellm-api-key": "Bearer your_api_key"}, } } }) diff --git a/ui/litellm-dashboard/src/components/publicModelHub/useHubData.ts b/ui/litellm-dashboard/src/components/publicModelHub/useHubData.ts index 4bf7d3b91e9..cf53307a072 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/useHubData.ts +++ b/ui/litellm-dashboard/src/components/publicModelHub/useHubData.ts @@ -3,18 +3,20 @@ import { useQuery } from "@tanstack/react-query"; import { useState } from "react"; +import type { ResourceListPage } from "@/app/(dashboard)/hooks/common/useResourceList"; import type { Plugin } from "@/components/claude_code_plugins/types"; import { agentHubPublicModelsCall, + apiClient, getPublicModelHubInfo, getUiConfig, mcpHubPublicServersCall, skillHubPublicCall, } from "@/components/networking"; -import type { AgentCard, MCPServerData } from "@/components/PublicModelHubTableColumns"; +import type { AgentCard, MCPServerData, ModelGroupInfo } from "@/components/PublicModelHubTableColumns"; import { usePublicModelHubFacets } from "./usePublicModelHubFacets"; -import { usePublicModelHubList } from "./usePublicModelHubList"; +import { PUBLIC_MODEL_HUB_PAGE_SIZE, PUBLIC_MODEL_HUB_PATH, usePublicModelHubList } from "./usePublicModelHubList"; export interface HubInfo { docs_title: string; @@ -25,8 +27,15 @@ export interface HubInfo { const asArray = (data: unknown): T[] => (Array.isArray(data) ? (data as T[]) : []); +const UI_CONFIG_QUERY = { + queryKey: ["publicAiHub", "uiConfig"], + queryFn: () => getUiConfig(), + staleTime: Infinity, + retry: false, +}; + export function useHubData() { - const config = useQuery({ queryKey: ["publicAiHub", "uiConfig"], queryFn: () => getUiConfig(), staleTime: Infinity }); + const config = useQuery(UI_CONFIG_QUERY); const ready = config.isSuccess || config.isError; const info = useQuery({ @@ -51,13 +60,31 @@ export function useHubData() { }); const list = usePublicModelHubList(ready); - const models = { ...list, isLoading: !ready || list.isLoading }; + const listLoading = !ready || list.isLoading; + const [listSettled, setListSettled] = useState(false); + if (!listLoading && !listSettled) setListSettled(true); + const models = { ...list, isLoading: listLoading && !listSettled }; const facets = usePublicModelHubFacets(ready); const [modelTotal, setModelTotal] = useState(undefined); - const settledTotal = !models.isLoading && !models.hasActiveQuery && !models.error ? models.rowCount : modelTotal; + const settledTotal = !listLoading && !models.hasActiveQuery && !models.error ? models.rowCount : modelTotal; if (settledTotal !== modelTotal) setModelTotal(settledTotal); return { info, agents, mcp, skills, models, facets, modelTotal: settledTotal }; } export type HubData = ReturnType; + +export function useOpenedModel(open: string | null, rows: ModelGroupInfo[], enabled: boolean) { + const onPage = rows.find((model) => model.model_group === open); + const lookup = useQuery({ + queryKey: ["publicAiHub", "openedModel", open], + queryFn: ({ signal }) => + apiClient.get>(PUBLIC_MODEL_HUB_PATH, { + query: { q: open ?? "", page_size: PUBLIC_MODEL_HUB_PAGE_SIZE }, + signal, + }), + enabled: enabled && open !== null && onPage === undefined, + }); + const found = lookup.data?.data.find((model) => model.model_group === open); + return { model: onPage ?? found, pending: onPage === undefined && lookup.isLoading }; +} diff --git a/ui/litellm-dashboard/src/components/publicModelHub/useHubUrlState.ts b/ui/litellm-dashboard/src/components/publicModelHub/useHubUrlState.ts index 62fcb148c58..9abe57e872f 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/useHubUrlState.ts +++ b/ui/litellm-dashboard/src/components/publicModelHub/useHubUrlState.ts @@ -28,5 +28,5 @@ export function useHubUrlState() { export function useOpenHref() { const params = useSearchParams(); - return useCallback((key: string) => serializeOpen(params?.toString() ?? "", { open: key }), [params]); + return useCallback((key: string) => serializeOpen(params ?? new URLSearchParams(), { open: key }), [params]); } diff --git a/ui/litellm-dashboard/src/components/publicModelHub/useIsNarrow.ts b/ui/litellm-dashboard/src/components/publicModelHub/useIsNarrow.ts index 7d17a23d52e..d9af009eb23 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/useIsNarrow.ts +++ b/ui/litellm-dashboard/src/components/publicModelHub/useIsNarrow.ts @@ -1,6 +1,6 @@ import { useSyncExternalStore } from "react"; -const NARROW = "(max-width: 1023px)"; +const NARROW = "(width < 64rem)"; const subscribe = (onChange: () => void) => { const query = window.matchMedia(NARROW); From 0da546e11ad285bef810728ea262324c98d712d6 Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Sat, 31 Oct 2026 15:23:30 -0700 Subject: [PATCH 3/3] fix(ui): surface hub load errors and keep the open item steady Agents, MCP servers and skills now load through apiClient so an HTTP error shows the inline error instead of an empty "published yet" state, and an all-failing gateway reaches the unavailable page. Try again shows loading instead of an empty hub, the open model stays in the details pane when a search or page change hides its row, a zero-result search keeps the pane, phones get the not-listed sheet for a stale link, an empty open param means nothing opened, free models read Free in the list, and an invalid skill date is hidden --- .../publicModelHub/HubMasterDetail.tsx | 50 +++-- .../components/publicModelHub/ModelsPane.tsx | 13 +- .../PublicAiHub.integration.test.tsx | 180 ++++++++++++++---- .../publicModelHub/SkillInspector.tsx | 3 +- .../components/publicModelHub/useHubData.ts | 48 +++-- .../publicModelHub/useHubUrlState.ts | 2 +- 6 files changed, 212 insertions(+), 84 deletions(-) diff --git a/ui/litellm-dashboard/src/components/publicModelHub/HubMasterDetail.tsx b/ui/litellm-dashboard/src/components/publicModelHub/HubMasterDetail.tsx index f317522e217..63153c63c76 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/HubMasterDetail.tsx +++ b/ui/litellm-dashboard/src/components/publicModelHub/HubMasterDetail.tsx @@ -99,6 +99,33 @@ function Rows({ ); } +const resolveSelection = ( + rows: T[], + selectedKey: string | null, + opened: T | undefined, + getKey: (row: T) => string, +) => { + const chosen = selectedKey === null ? undefined : opened ?? rows.find((row) => getKey(row) === selectedKey); + return { chosen, selected: selectedKey === null ? rows[0] : chosen }; +}; + +function useSheet( + chosen: T | undefined, + missingKey: string | undefined, + getKey: (row: T) => string, + renderDetail: (row: T) => React.ReactNode, +) { + const [content, setContent] = React.useState<{ row?: T; missingKey?: string }>({ row: chosen }); + if (chosen !== undefined && chosen !== content.row) setContent({ row: chosen }); + if (missingKey !== undefined && missingKey !== content.missingKey) setContent({ missingKey }); + const { row } = content; + return { + open: chosen !== undefined || missingKey !== undefined, + title: row ? getKey(row) : content.missingKey ?? "Details", + body: row ? renderDetail(row) : content.missingKey && , + }; +} + export function HubMasterDetail({ switcher, toolbar, @@ -129,11 +156,12 @@ export function HubMasterDetail({ footer?: React.ReactNode; }) { const narrow = useIsNarrow(); - const chosen = selectedKey === null ? undefined : opened ?? rows.find((row) => getKey(row) === selectedKey); - const selected = selectedKey === null ? rows[0] : chosen; - const [sheetRow, setSheetRow] = React.useState(chosen); - if (chosen !== undefined && chosen !== sheetRow) setSheetRow(chosen); + const { chosen, selected } = resolveSelection(rows, selectedKey, opened, getKey); const isEmpty = !loading && rows.length === 0; + const settled = !loading && !openPending && !isEmpty; + const missingKey = selectedKey !== null && chosen === undefined && settled ? selectedKey : undefined; + const sheet = useSheet(chosen, missingKey, getKey, renderDetail); + const listOnly = isEmpty && chosen === undefined && !openPending; const detail = () => { if (loading || (selected === undefined && openPending)) return ; if (selected === undefined) return selectedKey && ; @@ -158,23 +186,19 @@ export function HubMasterDetail({
-
+
{switcher}
{toolbar}
{loading ? : list}
- {!isEmpty && {detail()}} - onSelect(null)} - > - {sheetRow && renderDetail(sheetRow)} + {!listOnly && {detail()}} + onSelect(null)}> + {sheet.body}
); diff --git a/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx b/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx index 7120d14feb1..1de09e554c1 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx +++ b/ui/litellm-dashboard/src/components/publicModelHub/ModelsPane.tsx @@ -148,10 +148,15 @@ function ModelsToolbar({ hub }: { hub: HubData }) { ); } -const prices = (model: ModelGroupInfo) => [ - model.input_cost_per_token ? `${formatPerMillion(model.input_cost_per_token)} / 1M in` : null, - model.output_cost_per_token ? `${formatPerMillion(model.output_cost_per_token)} / 1M out` : null, -]; +const price = (cost: number | null | undefined, direction: "input" | "output") => { + if (cost === 0) return `Free ${direction}`; + return cost ? `${formatPerMillion(cost)} / 1M ${direction === "input" ? "in" : "out"}` : null; +}; + +const prices = (model: ModelGroupInfo) => + model.input_cost_per_token === 0 && model.output_cost_per_token === 0 + ? ["Free", null] + : [price(model.input_cost_per_token, "input"), price(model.output_cost_per_token, "output")]; function ModelRow({ model }: { model: ModelGroupInfo }) { const [input, output] = prices(model); diff --git a/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx b/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx index b51da66ce27..bcddc1fe364 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx +++ b/ui/litellm-dashboard/src/components/publicModelHub/PublicAiHub.integration.test.tsx @@ -1,14 +1,13 @@ -import { fireEvent } from "@testing-library/react"; +import { fireEvent, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; - -import { agentHubPublicModelsCall, mcpHubPublicServersCall, skillHubPublicCall } from "@/components/networking"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { renderWithProviders, screen, testQueryClient, waitFor } from "../../../tests/test-utils"; import PublicAiHub from "./PublicAiHub"; -const { apiGetMock, navigation, uiSettings, replaceMock, hubInfo } = vi.hoisted(() => ({ +const { apiGetMock, realGet, navigation, uiSettings, replaceMock, hubInfo } = vi.hoisted(() => ({ apiGetMock: vi.fn(), + realGet: { current: (..._args: unknown[]): Promise => Promise.reject(new Error("unset")) }, navigation: { params: new URLSearchParams() }, uiSettings: { values: {} as Record }, replaceMock: vi.fn(), @@ -36,26 +35,13 @@ vi.mock("@/app/(dashboard)/hooks/uiSettings/useUISettings", () => ({ vi.mock("@/components/networking", async (importOriginal) => { const actual = await importOriginal(); + realGet.current = actual.apiClient.get; return { ...actual, apiClient: { ...actual.apiClient, get: apiGetMock }, getUiConfig: vi.fn().mockResolvedValue({}), getProxyBaseUrl: vi.fn(() => "https://gateway.example.com"), getPublicModelHubInfo: vi.fn().mockResolvedValue(hubInfo), - agentHubPublicModelsCall: vi.fn().mockResolvedValue([ - { - name: "research-assistant", - description: "Answers research questions", - version: "1.4.0", - url: "https://gateway.example.com/a2a/research", - protocolVersion: "0.3.0", - defaultInputModes: ["text"], - defaultOutputModes: ["text"], - skills: [], - }, - ]), - mcpHubPublicServersCall: vi.fn().mockResolvedValue([]), - skillHubPublicCall: vi.fn().mockResolvedValue({ plugins: [] }), }; }); @@ -69,9 +55,35 @@ const MODELS = [ input_cost_per_token: 0.000003, description: "Best for agentic coding", }, - { model_group: "gpt-5", providers: ["openai"], mode: "chat", description: "General purpose" }, + { + model_group: "gpt-5", + providers: ["openai"], + mode: "chat", + input_cost_per_token: 0, + output_cost_per_token: 0, + description: "General purpose", + }, ]; +const AGENTS = [ + { + name: "research-assistant", + description: "Answers research questions", + version: "1.4.0", + url: "https://gateway.example.com/a2a/research", + protocolVersion: "0.3.0", + defaultInputModes: ["text"], + defaultOutputModes: ["text"], + skills: [], + }, +]; + +const HUBS: Record = { + "/public/agent_hub": AGENTS, + "/public/mcp_hub": [], + "/public/skill_hub": { plugins: [] }, +}; + const page = (data: unknown[]) => ({ data, meta: { total_count: data.length, page: 1, page_size: 50, total_pages: 1 }, @@ -80,10 +92,32 @@ const page = (data: unknown[]) => ({ const OFF_PAGE_MODEL = { model_group: "o1-pro", providers: ["openai"], mode: "chat", description: "Deep reasoning" }; -const respondWithModels = () => - apiGetMock.mockImplementation((path: string, options?: { query?: Record }) => { - if (path !== MODEL_HUB_PATH) return Promise.resolve({ ...page([]), meta: { page: 1, page_size: 100 } }); - return Promise.resolve(options?.query?.q === "o1-pro" ? page([OFF_PAGE_MODEL]) : page(MODELS)); +type Query = { query?: Record }; + +const respond = (path: string, options?: Query): Promise => { + if (path in HUBS) return Promise.resolve(HUBS[path]); + if (path !== MODEL_HUB_PATH) return Promise.resolve({ ...page([]), meta: { page: 1, page_size: 100 } }); + const q = String(options?.query?.q ?? ""); + if (q === "o1-pro") return Promise.resolve(page([OFF_PAGE_MODEL])); + return Promise.resolve(page(MODELS.filter((model) => model.model_group.includes(q)))); +}; + +const respondWithModels = () => apiGetMock.mockImplementation(respond); + +const failModelsWith = (next: (options?: Query) => Promise) => + apiGetMock.mockImplementation((path: string, options?: Query) => + path === MODEL_HUB_PATH ? next(options) : respond(path, options), + ); + +const narrowScreen = (narrow: boolean) => + Object.defineProperty(window, "matchMedia", { + writable: true, + value: (query: string) => ({ + matches: narrow, + media: query, + addEventListener: () => {}, + removeEventListener: () => {}, + }), }); const tokenExpiringIn = (seconds: number) => { @@ -91,19 +125,8 @@ const tokenExpiringIn = (seconds: number) => { return `${encode({ alg: "HS256" })}.${encode({ exp: Math.floor(Date.now() / 1000) + seconds })}.signature`; }; -beforeAll(() => { - Object.defineProperty(window, "matchMedia", { - writable: true, - value: (query: string) => ({ - matches: false, - media: query, - addEventListener: () => {}, - removeEventListener: () => {}, - }), - }); -}); - beforeEach(() => { + narrowScreen(false); vi.clearAllMocks(); testQueryClient.clear(); uiSettings.values = {}; @@ -167,7 +190,7 @@ describe("PublicAiHub", () => { it("keeps agents reachable when only the models call fails", async () => { const user = userEvent.setup(); - apiGetMock.mockRejectedValue(new Error("No models configured")); + failModelsWith(() => Promise.reject(new Error("No models configured"))); renderWithProviders(); expect(await screen.findByText("Couldn't load models")).toBeInTheDocument(); @@ -178,15 +201,92 @@ describe("PublicAiHub", () => { it("says the hub is unavailable when every hub call fails", async () => { apiGetMock.mockRejectedValue(new Error("Not found")); - vi.mocked(agentHubPublicModelsCall).mockRejectedValueOnce(new Error("Not found")); - vi.mocked(mcpHubPublicServersCall).mockRejectedValueOnce(new Error("Not found")); - vi.mocked(skillHubPublicCall).mockRejectedValueOnce(new Error("Not found")); renderWithProviders(); expect(await screen.findByText("This AI Hub isn't available")).toBeInTheDocument(); expect(screen.queryByRole("tablist")).not.toBeInTheDocument(); }); + it("shows a load error when a hub answers with an HTTP error status", async () => { + const user = userEvent.setup(); + vi.mocked(fetch).mockResolvedValue(new Response(JSON.stringify({ detail: "Database error" }), { status: 500 })); + apiGetMock.mockImplementation((path: string, options?: Query) => + path === "/public/agent_hub" ? realGet.current(path, options) : respond(path, options), + ); + renderWithProviders(); + + await user.click(await screen.findByRole("tab", { name: /^Agents/ })); + + expect(await screen.findByText("Couldn't load agents")).toBeInTheDocument(); + expect(screen.queryByText("No agents published yet")).not.toBeInTheDocument(); + }); + + it("shows loading rather than an empty hub while Try again reloads models", async () => { + const user = userEvent.setup(); + let finishRetry: (value: unknown) => void = () => {}; + failModelsWith(() => Promise.reject(new Error("Gateway timeout"))); + renderWithProviders(); + await screen.findByText("Couldn't load models"); + failModelsWith(() => new Promise((resolve) => (finishRetry = resolve))); + + await user.click(screen.getByRole("button", { name: "Try again" })); + + expect(screen.queryByText("No models published yet")).not.toBeInTheDocument(); + expect(screen.queryByText("Couldn't load models")).not.toBeInTheDocument(); + finishRetry(page(MODELS)); + expect(await screen.findByRole("heading", { level: 2, name: "claude-sonnet-4-5" })).toBeInTheDocument(); + }); + + it("keeps the open model and its snippet tab while a search hides its row", async () => { + const user = userEvent.setup(); + failModelsWith((options) => + options?.query?.q === "gpt-5" ? new Promise(() => {}) : respond(MODEL_HUB_PATH, options), + ); + renderWithProviders(, { searchParams: { open: "gpt-5" } }); + await screen.findByRole("heading", { level: 2, name: "gpt-5" }); + await user.click(screen.getByRole("tab", { name: "cURL" })); + + fireEvent.change(screen.getByRole("textbox", { name: "Search models" }), { target: { value: "claude" } }); + + await waitFor(() => expect(screen.queryByRole("link", { name: /gpt-5/ })).not.toBeInTheDocument()); + expect(screen.getByRole("heading", { level: 2, name: "gpt-5" })).toBeInTheDocument(); + expect(screen.getByRole("tab", { name: "cURL" })).toHaveAttribute("aria-selected", "true"); + }); + + it("keeps the open item's details when a search matches nothing", async () => { + renderWithProviders(, { + searchParams: { tab: "agents", open: "research-assistant" }, + }); + + fireEvent.change(await screen.findByRole("textbox", { name: "Search agents" }), { target: { value: "billing" } }); + + expect(await screen.findByText('No agents match "billing"')).toBeInTheDocument(); + expect(screen.getByRole("heading", { level: 2, name: "research-assistant" })).toBeInTheDocument(); + }); + + it("marks a free model as free in its row", async () => { + renderWithProviders(); + + const row = await screen.findByRole("link", { name: /gpt-5/ }); + + expect(within(row).getAllByText("Free").length).toBeGreaterThan(0); + }); + + it("treats an empty open param as nothing opened", async () => { + renderWithProviders(, { searchParams: { open: "" } }); + + expect(await screen.findByRole("heading", { level: 2, name: "claude-sonnet-4-5" })).toBeInTheDocument(); + }); + + it("tells phone visitors when a shared link names something no longer listed", async () => { + narrowScreen(true); + renderWithProviders(, { searchParams: { open: "retired-model" } }); + + const sheet = await screen.findByRole("dialog"); + + expect(within(sheet).getByText("\u201cretired-model\u201d isn't listed here")).toBeInTheDocument(); + }); + it("keeps the page's other query params in each row's link", async () => { navigation.params = new URLSearchParams("tab=agents&key=abc"); renderWithProviders(, { searchParams: { tab: "agents", key: "abc" } }); diff --git a/ui/litellm-dashboard/src/components/publicModelHub/SkillInspector.tsx b/ui/litellm-dashboard/src/components/publicModelHub/SkillInspector.tsx index 773ff62830e..fdc2467e5da 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/SkillInspector.tsx +++ b/ui/litellm-dashboard/src/components/publicModelHub/SkillInspector.tsx @@ -30,7 +30,8 @@ function sourceValue(source: Plugin["source"]) { export function SkillInspector({ skill }: { skill: Plugin }) { const keywords = skill.keywords ?? []; - const added = skill.created_at ? new Date(skill.created_at).toLocaleDateString() : null; + const addedAt = skill.created_at ? new Date(skill.created_at) : null; + const added = addedAt && !Number.isNaN(addedAt.getTime()) ? addedAt.toLocaleDateString() : null; return (
diff --git a/ui/litellm-dashboard/src/components/publicModelHub/useHubData.ts b/ui/litellm-dashboard/src/components/publicModelHub/useHubData.ts index cf53307a072..65c2a2c5873 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/useHubData.ts +++ b/ui/litellm-dashboard/src/components/publicModelHub/useHubData.ts @@ -5,14 +5,7 @@ import { useState } from "react"; import type { ResourceListPage } from "@/app/(dashboard)/hooks/common/useResourceList"; import type { Plugin } from "@/components/claude_code_plugins/types"; -import { - agentHubPublicModelsCall, - apiClient, - getPublicModelHubInfo, - getUiConfig, - mcpHubPublicServersCall, - skillHubPublicCall, -} from "@/components/networking"; +import { apiClient, getPublicModelHubInfo, getUiConfig } from "@/components/networking"; import type { AgentCard, MCPServerData, ModelGroupInfo } from "@/components/PublicModelHubTableColumns"; import { usePublicModelHubFacets } from "./usePublicModelHubFacets"; @@ -45,25 +38,24 @@ export function useHubData() { }); const agents = useQuery({ queryKey: ["publicAiHub", "agents"], - queryFn: async () => asArray(await agentHubPublicModelsCall()), + queryFn: async ({ signal }) => asArray(await apiClient.get("/public/agent_hub", { signal })), enabled: ready, }); const mcp = useQuery({ queryKey: ["publicAiHub", "mcp"], - queryFn: async () => asArray(await mcpHubPublicServersCall()), + queryFn: async ({ signal }) => asArray(await apiClient.get("/public/mcp_hub", { signal })), enabled: ready, }); const skills = useQuery({ queryKey: ["publicAiHub", "skills"], - queryFn: async () => (await skillHubPublicCall()).plugins ?? [], + queryFn: async ({ signal }) => + (await apiClient.get<{ plugins?: Plugin[] }>("/public/skill_hub", { signal })).plugins ?? [], enabled: ready, }); const list = usePublicModelHubList(ready); const listLoading = !ready || list.isLoading; - const [listSettled, setListSettled] = useState(false); - if (!listLoading && !listSettled) setListSettled(true); - const models = { ...list, isLoading: listLoading && !listSettled }; + const models = { ...list, isLoading: listLoading && list.rows.length === 0 }; const facets = usePublicModelHubFacets(ready); const [modelTotal, setModelTotal] = useState(undefined); const settledTotal = !listLoading && !models.hasActiveQuery && !models.error ? models.rowCount : modelTotal; @@ -74,17 +66,23 @@ export function useHubData() { export type HubData = ReturnType; +const openedModelQuery = (open: string | null, enabled: boolean) => ({ + queryKey: ["publicAiHub", "openedModel", open], + queryFn: ({ signal }: { signal: AbortSignal }) => + apiClient.get>(PUBLIC_MODEL_HUB_PATH, { + query: { q: open ?? "", page_size: PUBLIC_MODEL_HUB_PAGE_SIZE }, + signal, + }), + enabled, + retry: false, +}); + export function useOpenedModel(open: string | null, rows: ModelGroupInfo[], enabled: boolean) { const onPage = rows.find((model) => model.model_group === open); - const lookup = useQuery({ - queryKey: ["publicAiHub", "openedModel", open], - queryFn: ({ signal }) => - apiClient.get>(PUBLIC_MODEL_HUB_PATH, { - query: { q: open ?? "", page_size: PUBLIC_MODEL_HUB_PAGE_SIZE }, - signal, - }), - enabled: enabled && open !== null && onPage === undefined, - }); - const found = lookup.data?.data.find((model) => model.model_group === open); - return { model: onPage ?? found, pending: onPage === undefined && lookup.isLoading }; + const [kept, setKept] = useState(undefined); + const known = onPage ?? (kept?.model_group === open ? kept : undefined); + const lookup = useQuery(openedModelQuery(open, enabled && open !== null && known === undefined)); + const model = known ?? lookup.data?.data.find((found) => found.model_group === open); + if (model !== undefined && model !== kept) setKept(model); + return { model, pending: model === undefined && lookup.isLoading }; } diff --git a/ui/litellm-dashboard/src/components/publicModelHub/useHubUrlState.ts b/ui/litellm-dashboard/src/components/publicModelHub/useHubUrlState.ts index 9abe57e872f..632c372d36c 100644 --- a/ui/litellm-dashboard/src/components/publicModelHub/useHubUrlState.ts +++ b/ui/litellm-dashboard/src/components/publicModelHub/useHubUrlState.ts @@ -23,7 +23,7 @@ export function useHubUrlState() { }, [setUrlTab, setOpen], ); - return { tab, setTab, open, setOpen }; + return { tab, setTab, open: open || null, setOpen }; } export function useOpenHref() {