Open History to see the last commit
1import { type ServerProvider } from "@t3tools/contracts";
2import { memo } from "react";
3import { InfoIcon } from "lucide-react";
4import { cn } from "~/lib/utils";
5import { formatProviderDriverKindLabel } from "../../providerModels";
6import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
7
8export const ProviderStatusBanner = memo(function ProviderStatusBanner({
9 status,
10}: {
11 status: ServerProvider | null;
12}) {
13 if (!status || status.status === "ready" || status.status === "disabled") {
14 return null;
15 }
16
17 const providerName = status.displayName?.trim() || formatProviderDriverKindLabel(status.driver);
18 const isUnauthenticated = status.status === "error" && status.auth.status === "unauthenticated";
19 const title = isUnauthenticated
20 ? `${providerName} is unauthenticated`
21 : `${providerName} provider status`;
22 const message = isUnauthenticated
23 ? "Sign in via the CLI to authenticate again."
24 : (status.message ??
25 (status.status === "error"
26 ? `${providerName} provider is unavailable.`
27 : `${providerName} provider has limited availability.`));
28
29 return (
30 <div className="mx-auto w-fit max-w-[calc(100%-2rem)] pt-3">
31 <div
32 className={cn(
33 "inline-flex items-center gap-3 rounded-xl border px-3.5 py-3 text-card-foreground text-sm",
34 status.status === "warning"
35 ? "border-warning/32 bg-warning/4 [&_svg]:text-warning"
36 : "border-destructive/32 bg-destructive/4 text-destructive-foreground [&_svg]:text-destructive",
37 )}
38 role="alert"
39 >
40 <InfoIcon className="size-4 shrink-0" aria-hidden />
41 <div className="flex min-w-0 flex-col gap-1">
42 <div className="font-medium">{title}</div>
43 <Tooltip>
44 <TooltipTrigger
45 render={<div className="line-clamp-3 text-muted-foreground">{message}</div>}
46 />
47 <TooltipPopup side="top" className="max-w-96 whitespace-pre-wrap">
48 {message}
49 </TooltipPopup>
50 </Tooltip>
51 </div>
52 </div>
53 </div>
54 );
55});