@@ -294,15 +294,35 @@ export const determineFileStatus = (file) => {
294294 return "error" ;
295295} ;
296296// Function to format agent type strings
297- export const formatAgent = ( str = "Agents" ) => {
298- if ( ! str ) return "Agents" ;
299- return str
297+ export const formatAgent = ( str = "Agent" ) => {
298+ if ( ! str ) return "agent" ;
299+
300+ const cleaned = str
300301 . replace ( / [ ^ a - z A - Z \s ] / g, " " ) // Remove non-alphabetic characters
301- . replace ( / \s + / g, " " ) // Replace multiple spaces with a single space
302- . trim ( ) // Remove leading/trailing spaces
303- . split ( " " ) // Split words
304- . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( ) ) // Capitalize first letter
305- . join ( " " ) || "Agents" ; // Ensure default "Agent" if empty
302+ . replace ( / \s + / g, " " ) // Collapse multiple spaces
303+ . trim ( )
304+ . replace ( / \b A g e n t s \b / i, "Agent" ) ; // Singularize "Agents" if it's the only word
305+
306+ const words = cleaned
307+ . split ( " " )
308+ . filter ( Boolean )
309+ . map ( w => w . toLowerCase ( ) ) ;
310+
311+ const hasAgent = words . includes ( "agent" ) ;
312+
313+ // Capitalize all except "agent" (unless it's the only word)
314+ const result = words . map ( ( word , index ) => {
315+ if ( word === "agent" ) {
316+ return words . length === 1 ? "Agent" : "agent" ; // Capitalize if it's the only word
317+ }
318+ return word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) ;
319+ } ) ;
320+
321+ if ( ! hasAgent ) {
322+ result . push ( "agent" ) ;
323+ }
324+
325+ return result . join ( " " ) ;
306326} ;
307327
308328// Function to handle rate limit errors and ensure descriptions end with a dot
0 commit comments