11import React from 'react' ;
2- import {
3- Desktop20Regular ,
4- Code20Regular ,
2+ import {
3+ Desktop20Regular ,
4+ Code20Regular ,
55 Building20Regular ,
66 Organization20Regular ,
77 Search20Regular ,
@@ -113,18 +113,18 @@ const generateHash = (str: string): number => {
113113 */
114114const matchStringToFluentIcon = ( iconString : string ) : React . ComponentType < any > | null => {
115115 if ( ! iconString || typeof iconString !== 'string' ) return null ;
116-
116+
117117 // Try exact match first
118118 if ( fluentIconMap [ iconString ] ) {
119119 return fluentIconMap [ iconString ] ;
120120 }
121-
121+
122122 // Try case-insensitive match
123123 const lowerIconString = iconString . toLowerCase ( ) ;
124124 if ( fluentIconMap [ lowerIconString ] ) {
125125 return fluentIconMap [ lowerIconString ] ;
126126 }
127-
127+
128128 // Try removing common suffixes and prefixes
129129 const cleanedIconString = iconString
130130 . replace ( / 2 0 R e g u l a r $ / i, '' )
@@ -134,11 +134,11 @@ const matchStringToFluentIcon = (iconString: string): React.ComponentType<any> |
134134 . replace ( / ^ i c o n / i, '' )
135135 . toLowerCase ( )
136136 . trim ( ) ;
137-
137+
138138 if ( fluentIconMap [ cleanedIconString ] ) {
139139 return fluentIconMap [ cleanedIconString ] ;
140140 }
141-
141+
142142 return null ;
143143} ;
144144
@@ -200,20 +200,20 @@ const getUniqueAgentIcon = (
200200 iconStyle : React . CSSProperties
201201) : React . ReactNode => {
202202 const cleanName = TaskService . cleanTextToSpaces ( agentName ) . toLowerCase ( ) ;
203-
203+
204204 // If we already assigned an icon to this agent, use it
205205 if ( agentIconAssignments [ cleanName ] ) {
206206 const IconComponent = agentIconAssignments [ cleanName ] ;
207207 return React . createElement ( IconComponent , { style : iconStyle } ) ;
208208 }
209-
209+
210210 // Get deterministic icon based on agent name patterns
211211 // This ensures same names always get the same icon regardless of assignment order
212212 const selectedIcon = getDeterministicAgentIcon ( cleanName ) ;
213-
213+
214214 // Cache the assignment for future lookups
215215 agentIconAssignments [ cleanName ] = selectedIcon ;
216-
216+
217217 return React . createElement ( selectedIcon , { style : iconStyle } ) ;
218218} ;
219219
@@ -222,8 +222,8 @@ const getUniqueAgentIcon = (
222222 * with consistent fallback patterns across all components
223223 */
224224export const getAgentIcon = (
225- agentName : string ,
226- planData ?: any ,
225+ agentName : string ,
226+ planData ?: any ,
227227 planApprovalRequest ?: any ,
228228 iconColor : string = 'var(--colorNeutralForeground2)'
229229) : React . ReactNode => {
@@ -245,7 +245,7 @@ export const getAgentIcon = (
245245 if ( FluentIconComponent ) {
246246 return React . createElement ( FluentIconComponent , { style : iconStyle } ) ;
247247 }
248-
248+
249249 // Fallback: check if it's in the existing iconMap
250250 if ( iconMap [ agent . icon ] ) {
251251 return React . cloneElement ( iconMap [ agent . icon ] as React . ReactElement , {
@@ -259,8 +259,8 @@ export const getAgentIcon = (
259259 const storedTeam = TeamService . getStoredTeam ( ) ;
260260 if ( storedTeam ?. agents ) {
261261 const cleanAgentName = TaskService . cleanTextToSpaces ( agentName ) ;
262-
263- const agent = storedTeam . agents . find ( a =>
262+
263+ const agent = storedTeam . agents . find ( a =>
264264 TaskService . cleanTextToSpaces ( a . name ) . toLowerCase ( ) . includes ( cleanAgentName . toLowerCase ( ) ) ||
265265 a . type . toLowerCase ( ) . includes ( cleanAgentName . toLowerCase ( ) ) ||
266266 a . input_key . toLowerCase ( ) . includes ( cleanAgentName . toLowerCase ( ) )
@@ -286,15 +286,15 @@ export const getAgentIcon = (
286286 // 4. Deterministic icon assignment - ensures same names get same icons
287287 // Get all agent names from current context for unique assignment
288288 let allAgentNames : string [ ] = [ ] ;
289-
289+
290290 if ( planApprovalRequest ?. team ) {
291291 allAgentNames = planApprovalRequest . team ;
292292 } else if ( planData ?. team ?. agents ) {
293293 allAgentNames = planData . team . agents . map ( ( a : any ) => a . name || a . type || '' ) ;
294294 } else if ( storedTeam ?. agents ) {
295295 allAgentNames = storedTeam . agents . map ( a => a . name ) ;
296296 }
297-
297+
298298 return getUniqueAgentIcon ( agentName , allAgentNames , iconStyle ) ;
299299} ;
300300
@@ -313,13 +313,13 @@ export const clearAgentIconAssignments = (): void => {
313313 */
314314export const getAgentDisplayName = ( agentName : string ) : string => {
315315 if ( ! agentName ) return 'Assistant' ;
316-
316+
317317 // Clean and format the name
318318 let cleanName = TaskService . cleanTextToSpaces ( agentName ) ;
319-
319+
320320 // Remove "Agent" suffix if it exists (case insensitive)
321321 cleanName = cleanName . replace ( / \s * a g e n t \s * $ / gi, '' ) . trim ( ) ;
322-
322+
323323 // Convert to proper case
324324 cleanName = cleanName
325325 . replace ( / \b H R H e l p e r \b / gi, 'HR Helper' )
@@ -329,8 +329,8 @@ export const getAgentDisplayName = (agentName: string): string => {
329329
330330 // Convert to proper case
331331 cleanName = cleanName . replace ( / \b \w / g, l => l . toUpperCase ( ) ) ;
332-
333-
332+
333+
334334 // Handle special cases for better readability
335335 cleanName = cleanName
336336 . replace ( / \b K b \b / g, 'KB' ) // KB instead of Kb
@@ -340,7 +340,7 @@ export const getAgentDisplayName = (agentName: string): string => {
340340 . replace ( / \b A i \b / g, 'AI' ) // AI instead of Ai
341341 . replace ( / \b U i \b / g, 'UI' ) // UI instead of Ui
342342 . replace ( / \b D b \b / g, 'DB' ) ; // DB instead of Db
343-
343+
344344 return cleanName || 'Assistant' ;
345345} ;
346346
@@ -352,22 +352,37 @@ export const getAgentDisplayNameWithSuffix = (agentName: string): string => {
352352 return `${ baseName } Agent` ;
353353} ;
354354
355+ /**
356+ * Get agent icon with custom styling override
357+ */
355358/**
356359 * Get agent icon with custom styling override
357360 */
358361export const getStyledAgentIcon = (
359- agentName : string ,
362+ agentName : string ,
360363 customStyle : React . CSSProperties ,
361- planData ?: any ,
364+ planData ?: any ,
362365 planApprovalRequest ?: any
363366) : React . ReactNode => {
364367 const icon = getAgentIcon ( agentName , planData , planApprovalRequest ) ;
365-
368+
366369 if ( React . isValidElement ( icon ) ) {
367- return React . cloneElement ( icon , {
368- style : { ...icon . props . style , ...customStyle }
369- } ) ;
370+ try {
371+ // Safely merge styles
372+ const mergedStyle = {
373+ ...( icon . props as any ) ?. style ,
374+ ...customStyle
375+ } ;
376+
377+ return React . cloneElement ( icon as React . ReactElement < any > , {
378+ style : mergedStyle
379+ } ) ;
380+ } catch ( error ) {
381+ // Fallback: return original icon if cloning fails
382+ console . warn ( 'Failed to apply custom style to agent icon:' , error ) ;
383+ return icon ;
384+ }
370385 }
371-
386+
372387 return icon ;
373388} ;
0 commit comments