Open History to see the last commit
1import { type CSSProperties, memo } from "react";
2import { type ProviderDriverKind } from "@t3tools/contracts";
3import { providerInstanceInitials } from "@t3tools/client-runtime/state/provider-instance-display";
4
5import { PROVIDER_ICON_BY_PROVIDER } from "./providerIconUtils";
6import { cn } from "~/lib/utils";
7import {
8 AcpRegistryAgentIcon,
9 officialAcpRegistryIconUrlForAgentId,
10 resolveOfficialAcpRegistryIconUrl,
11} from "../settings/AcpRegistryIcon";
12
13export function resolveProviderInstanceAcpRegistryIconUrl(input: {
14 readonly driverKind: ProviderDriverKind;
15 readonly agentId?: string | undefined;
16 readonly iconUrl?: string | undefined;
17}): string | null {
18 if (input.driverKind !== "acpRegistry") return null;
19 return (
20 resolveOfficialAcpRegistryIconUrl(input.iconUrl ?? null) ??
21 officialAcpRegistryIconUrlForAgentId(input.agentId?.trim() || null)
22 );
23}
24
25export { providerInstanceInitials };
26
27export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
28 driverKind: ProviderDriverKind;
29 displayName: string;
30 accentColor?: string | undefined;
31 acpRegistryAgentId?: string | undefined;
32 acpRegistryIconUrl?: string | undefined;
33 showBadge?: boolean;
34 badgeContent?: "initials" | "none";
35 className?: string;
36 iconClassName?: string;
37 badgeClassName?: string;
38 statusDotClassName?: string;
39 indicatorBackground?: string;
40}) {
41 const Icon = PROVIDER_ICON_BY_PROVIDER[props.driverKind] ?? null;
42 const indicatorBackground = props.indicatorBackground ?? "var(--card)";
43 const accentStyle = props.accentColor
44 ? ({ "--provider-accent": props.accentColor } as CSSProperties)
45 : undefined;
46 const badgeContent = props.badgeContent ?? "initials";
47 const isAcpRegistry = props.driverKind === "acpRegistry";
48 const acpRegistryIconUrl = resolveProviderInstanceAcpRegistryIconUrl({
49 driverKind: props.driverKind,
50 agentId: props.acpRegistryAgentId,
51 iconUrl: props.acpRegistryIconUrl,
52 });
53
54 return (
55 <span
56 className={cn(
57 "relative isolate inline-flex shrink-0 items-center justify-center overflow-visible",
58 props.className,
59 )}
60 style={accentStyle}
61 data-provider-accent-color={props.accentColor}
62 >
63 {isAcpRegistry ? (
64 <AcpRegistryAgentIcon
65 // The search-tile radius would crop most of the glyph at these
66 // inline sizes.
67 className={cn("size-5 rounded-none bg-transparent", props.iconClassName)}
68 fallbackClassName="size-full"
69 icon={acpRegistryIconUrl}
70 />
71 ) : Icon ? (
72 <Icon className={cn("size-5 shrink-0", props.iconClassName)} aria-hidden />
73 ) : (
74 <span className={cn("text-[10px] font-semibold leading-none", props.iconClassName)}>
75 {providerInstanceInitials(props.displayName)}
76 </span>
77 )}
78 {props.statusDotClassName ? (
79 <span
80 className={cn(
81 "pointer-events-none absolute -left-0.5 -top-0.5 z-10 size-2 rounded-full",
82 props.statusDotClassName,
83 )}
84 style={{ boxShadow: `0 0 0 2px ${indicatorBackground}` }}
85 aria-hidden
86 />
87 ) : null}
88 {props.showBadge ? (
89 <span
90 className={cn(
91 "pointer-events-none absolute right-0 bottom-0 z-10 flex h-3.5 min-w-3.5 items-center justify-center rounded-full border px-0.5 text-[8px] font-semibold leading-none shadow-sm",
92 props.accentColor
93 ? "bg-[var(--provider-accent)] text-white"
94 : "bg-card text-muted-foreground",
95 props.badgeClassName,
96 )}
97 style={{ borderColor: indicatorBackground }}
98 aria-hidden
99 >
100 {badgeContent === "initials" ? providerInstanceInitials(props.displayName) : null}
101 </span>
102 ) : null}
103 </span>
104 );
105});