@@ -612,6 +612,28 @@ export const filterAvailableAgents = (agents: BuddyDetails[], logger?): BuddyDet
612612 }
613613} ;
614614
615+ /**
616+ * Filters buddy agents by a free-text query across name, dn and id.
617+ */
618+ export const filterAgentsByQuery = ( agents : BuddyDetails [ ] , query : string ) : BuddyDetails [ ] => {
619+ const searchTerm = ( query ?? '' ) . trim ( ) . toLowerCase ( ) ;
620+ if ( ! searchTerm ) return agents ?? [ ] ;
621+ return ( agents ?? [ ] ) . filter ( ( agent ) =>
622+ `${ agent . agentName ?? '' } |${ ( agent as { dn ?: string } ) . dn ?? '' } |${ agent . agentId ?? '' } `
623+ . toLowerCase ( )
624+ . includes ( searchTerm )
625+ ) ;
626+ } ;
627+
628+ /**
629+ * Returns agents to display for current category, applying search only for Agents tab, since other tabs support via the SDK
630+ */
631+ export const getAgentsForDisplay = (
632+ selectedCategory : 'Agents' | string ,
633+ agents : BuddyDetails [ ] ,
634+ query : string
635+ ) : BuddyDetails [ ] => ( selectedCategory === 'Agents' ? filterAgentsByQuery ( agents , query ) : agents || [ ] ) ;
636+
615637/**
616638 * Filters available queues
617639 */
@@ -655,3 +677,36 @@ export const debounce = <T extends (...args: unknown[]) => unknown>(
655677 } ;
656678 }
657679} ;
680+
681+ /**
682+ * Helpers for Dial Number / Entry Point manual actions
683+ */
684+ export const shouldAddConsultTransferAction = (
685+ selectedCategory : string ,
686+ isEntryPointTabVisible : boolean ,
687+ query : string ,
688+ entryPoints : { id : string ; name : string } [ ] ,
689+ onDialNumberSelect : ( ( dialNumber : string ) => void ) | undefined ,
690+ onEntryPointSelect : ( ( entryPointId : string , entryPointName : string ) => void ) | undefined
691+ ) : { visible : boolean ; onClick ?: ( ) => void ; title ?: string } => {
692+ const DN_REGEX = new RegExp ( '^[+1][0-9]{3,18}$|^[*#:][+1][0-9*#:]{3,18}$|^[0-9*#:]{3,18}$' ) ;
693+
694+ const isDial = selectedCategory === 'Dial Number' ;
695+ const isEntry = selectedCategory === 'Entry Point' && isEntryPointTabVisible ;
696+ const valid = DN_REGEX . test ( query || '' ) ;
697+
698+ if ( isDial ) {
699+ return valid && onDialNumberSelect
700+ ? { visible : true , onClick : ( ) => onDialNumberSelect ( query ) , title : query }
701+ : { visible : false } ;
702+ }
703+
704+ if ( isEntry ) {
705+ const match = query ? entryPoints ?. find ( ( e ) => e . name === query || e . id === query ) : null ;
706+ return valid && match && onEntryPointSelect
707+ ? { visible : true , onClick : ( ) => onEntryPointSelect ( match . id , match . name ) , title : match . name }
708+ : { visible : false } ;
709+ }
710+
711+ return { visible : false } ;
712+ } ;
0 commit comments