11import { Image } from "expo-image" ;
22import { Defs , LinearGradient , Path , Stop , Svg } from "react-native-svg" ;
33import { View } from "react-native" ;
4- import { providerInstanceInitials } from "@t3tools/client-runtime/state/provider-instance-display" ;
4+ import {
5+ isProviderInstanceInitialsIcon ,
6+ providerInstanceInitialsGlyphScale ,
7+ resolveProviderInstanceBadgeLabel ,
8+ resolveProviderInstanceGlyphDriver ,
9+ } from "@t3tools/client-runtime/state/provider-instance-display" ;
10+ import type { ProviderDriverKind } from "@t3tools/contracts" ;
511import { useId , useState } from "react" ;
612import { resolveOfficialAcpRegistryIconUrl } from "@t3tools/contracts" ;
713import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider" ;
814import { AppText as Text } from "./ui/AppText" ;
915import { getProviderClient } from "../lib/providerClients" ;
1016
17+ /** What a configured instance chose to look like; a `ServerProvider` satisfies it. */
18+ export interface ProviderGlyphAppearance {
19+ readonly icon ?: string | undefined ;
20+ readonly badgeLabel ?: string | undefined ;
21+ readonly displayName ?: string | undefined ;
22+ readonly accentColor ?: string | undefined ;
23+ }
24+
1125type ProviderIconProps = {
1226 readonly provider : string | null | undefined ;
1327 readonly iconUrl ?: string | null | undefined ;
1428 readonly size ?: number ;
29+ readonly appearance ?: ProviderGlyphAppearance | undefined ;
1530} ;
1631
1732function AcpRegistryFallbackIcon ( props : { readonly color : string ; readonly size : number } ) {
@@ -69,8 +84,39 @@ export function ProviderIcon(props: ProviderIconProps) {
6984 const gradientId = useId ( ) ;
7085 const size = props . size ?? 16 ;
7186 const mono = isDarkMode ? "#e5e5e5" : "#171717" ;
87+ const appearance = props . appearance ;
88+ if ( isProviderInstanceInitialsIcon ( appearance ?. icon ) ) {
89+ const label = resolveProviderInstanceBadgeLabel ( {
90+ displayName : appearance ?. displayName ?? "" ,
91+ badgeLabel : appearance ?. badgeLabel ,
92+ } ) ;
93+ const fontSize = size * providerInstanceInitialsGlyphScale ( label ) ;
94+ return (
95+ < View style = { { width : size , height : size , alignItems : "center" , justifyContent : "center" } } >
96+ < Text
97+ numberOfLines = { 1 }
98+ adjustsFontSizeToFit
99+ className = { appearance ?. accentColor ? undefined : "text-foreground-muted" }
100+ style = { {
101+ fontSize,
102+ fontWeight : "700" ,
103+ lineHeight : fontSize * 1.15 ,
104+ color : appearance ?. accentColor ,
105+ } }
106+ >
107+ { label }
108+ </ Text >
109+ </ View >
110+ ) ;
111+ }
112+ const provider = props . provider
113+ ? resolveProviderInstanceGlyphDriver ( {
114+ driverKind : props . provider as ProviderDriverKind ,
115+ icon : appearance ?. icon ,
116+ } )
117+ : props . provider ;
72118
73- if ( props . provider ?. trim ( ) . toLowerCase ( ) === "antigravity" ) {
119+ if ( provider ?. trim ( ) . toLowerCase ( ) === "antigravity" ) {
74120 return (
75121 < Image
76122 source = { require ( "../../assets/antigravity.png" ) }
@@ -79,11 +125,11 @@ export function ProviderIcon(props: ProviderIconProps) {
79125 />
80126 ) ;
81127 }
82- if ( props . provider === "acpRegistry" ) {
128+ if ( provider === "acpRegistry" ) {
83129 return < AcpRegistryProviderIcon color = { mono } iconUrl = { props . iconUrl } size = { size } /> ;
84130 }
85131
86- if ( props . provider === "claudeAgent" ) {
132+ if ( provider === "claudeAgent" ) {
87133 return (
88134 < Svg width = { size } height = { size } viewBox = "0 0 256 257" fill = "none" >
89135 < Path
@@ -94,7 +140,7 @@ export function ProviderIcon(props: ProviderIconProps) {
94140 ) ;
95141 }
96142
97- const packageIcon = getProviderClient ( props . provider ) ?. icon ;
143+ const packageIcon = getProviderClient ( provider ) ?. icon ;
98144 if ( packageIcon ) {
99145 const themeFill = ( fill : { readonly light : string ; readonly dark : string } ) =>
100146 isDarkMode ? fill . dark : fill . light ;
@@ -153,13 +199,21 @@ export function ProviderInstanceIcon(props: {
153199 readonly size ?: number ;
154200 readonly displayName : string ;
155201 readonly accentColor ?: string ;
202+ /** Chosen glyph: a driver slug with a logo, or the initials icon. */
203+ readonly icon ?: string ;
204+ readonly badgeLabel ?: string ;
156205 readonly showBadge ?: boolean ;
157206 readonly surfaceColor : string ;
158207} ) {
159208 return (
160209 < View style = { { position : "relative" } } >
161210 < View style = { { opacity : 0.6 } } >
162- < ProviderIcon iconUrl = { props . iconUrl } provider = { props . provider } size = { props . size } />
211+ < ProviderIcon
212+ iconUrl = { props . iconUrl }
213+ provider = { props . provider }
214+ size = { props . size }
215+ appearance = { props }
216+ />
163217 </ View >
164218 { props . showBadge ? (
165219 < View
@@ -188,7 +242,7 @@ export function ProviderInstanceIcon(props: {
188242 color : props . accentColor ? "#ffffff" : undefined ,
189243 } }
190244 >
191- { providerInstanceInitials ( props . displayName ) }
245+ { resolveProviderInstanceBadgeLabel ( props ) }
192246 </ Text >
193247 </ View >
194248 ) : null }
0 commit comments