@@ -681,4 +681,120 @@ describe('ToolSelectionStrategy', () => {
681681 expect ( result . enabledToolIds ) . toContain ( 'hf_doc_fetch' ) ;
682682 } ) ;
683683 } ) ;
684+
685+ describe ( 'Gradio endpoint handling' , ( ) => {
686+ it ( 'should include gradio endpoints in bouquet override mode' , async ( ) => {
687+ const context : ToolSelectionContext = {
688+ headers : {
689+ 'x-mcp-bouquet' : 'search' ,
690+ 'x-mcp-gradio' : 'microsoft/Florence-2-large,meta-llama/Llama-2-7b-chat-hf' ,
691+ } ,
692+ hfToken : 'test-token' ,
693+ } ;
694+
695+ const result = await strategy . selectTools ( context ) ;
696+
697+ expect ( result . mode ) . toBe ( ToolSelectionMode . BOUQUET_OVERRIDE ) ;
698+ expect ( result . enabledToolIds ) . toEqual ( TOOL_ID_GROUPS . search ) ;
699+ expect ( result . reason ) . toBe ( 'Bouquet override: search + 2 gradio endpoints' ) ;
700+ expect ( result . gradioSpaceTools ) . toBeDefined ( ) ;
701+ expect ( result . gradioSpaceTools ) . toHaveLength ( 2 ) ;
702+ expect ( result . gradioSpaceTools ?. [ 0 ] . name ) . toBe ( 'microsoft/Florence-2-large' ) ;
703+ expect ( result . gradioSpaceTools ?. [ 1 ] . name ) . toBe ( 'meta-llama/Llama-2-7b-chat-hf' ) ;
704+ } ) ;
705+
706+ it ( 'should include gradio endpoints in mix mode' , async ( ) => {
707+ const userSettings : AppSettings = {
708+ builtInTools : [ 'hf_whoami' ] ,
709+ spaceTools : [ ] ,
710+ } ;
711+
712+ const context : ToolSelectionContext = {
713+ headers : {
714+ 'x-mcp-mix' : 'hf_api' ,
715+ 'x-mcp-gradio' : 'foo/bar' ,
716+ } ,
717+ userSettings,
718+ hfToken : 'test-token' ,
719+ } ;
720+
721+ const result = await strategy . selectTools ( context ) ;
722+
723+ expect ( result . mode ) . toBe ( ToolSelectionMode . MIX ) ;
724+ expect ( result . reason ) . toBe ( 'User settings + mix(hf_api) + 1 gradio endpoints' ) ;
725+ expect ( result . gradioSpaceTools ) . toBeDefined ( ) ;
726+ expect ( result . gradioSpaceTools ) . toHaveLength ( 1 ) ;
727+ expect ( result . gradioSpaceTools ?. [ 0 ] . name ) . toBe ( 'foo/bar' ) ;
728+ } ) ;
729+
730+ it ( 'should include gradio endpoints in user settings mode' , async ( ) => {
731+ const userSettings : AppSettings = {
732+ builtInTools : [ 'hf_semantic_search' ] ,
733+ spaceTools : [ ] ,
734+ } ;
735+
736+ const context : ToolSelectionContext = {
737+ headers : {
738+ 'x-mcp-gradio' : 'test/space' ,
739+ } ,
740+ userSettings,
741+ hfToken : 'test-token' ,
742+ } ;
743+
744+ const result = await strategy . selectTools ( context ) ;
745+
746+ expect ( result . mode ) . toBe ( ToolSelectionMode . INTERNAL_API ) ;
747+ expect ( result . reason ) . toBe ( 'Internal API user settings + 1 gradio endpoints' ) ;
748+ expect ( result . gradioSpaceTools ) . toBeDefined ( ) ;
749+ expect ( result . gradioSpaceTools ) . toHaveLength ( 1 ) ;
750+ } ) ;
751+
752+ it ( 'should include gradio endpoints in fallback mode' , async ( ) => {
753+ const context : ToolSelectionContext = {
754+ headers : {
755+ 'x-mcp-gradio' : 'fallback/test' ,
756+ } ,
757+ hfToken : 'test-token' ,
758+ } ;
759+
760+ const result = await strategy . selectTools ( context ) ;
761+
762+ expect ( result . mode ) . toBe ( ToolSelectionMode . FALLBACK ) ;
763+ expect ( result . reason ) . toBe ( 'Fallback - no settings available + 1 gradio endpoints' ) ;
764+ expect ( result . gradioSpaceTools ) . toBeDefined ( ) ;
765+ expect ( result . gradioSpaceTools ) . toHaveLength ( 1 ) ;
766+ } ) ;
767+
768+ it ( 'should not include gradio endpoints when not specified' , async ( ) => {
769+ const context : ToolSelectionContext = {
770+ headers : { 'x-mcp-bouquet' : 'search' } ,
771+ hfToken : 'test-token' ,
772+ } ;
773+
774+ const result = await strategy . selectTools ( context ) ;
775+
776+ expect ( result . mode ) . toBe ( ToolSelectionMode . BOUQUET_OVERRIDE ) ;
777+ expect ( result . reason ) . toBe ( 'Bouquet override: search' ) ;
778+ expect ( result . gradioSpaceTools ) . toBeUndefined ( ) ;
779+ } ) ;
780+
781+ it ( 'should handle multiple gradio endpoints with various formats' , async ( ) => {
782+ const context : ToolSelectionContext = {
783+ headers : {
784+ 'x-mcp-bouquet' : 'hf_api' ,
785+ 'x-mcp-gradio' : 'user/space-one,org/space-two' ,
786+ } ,
787+ hfToken : 'test-token' ,
788+ } ;
789+
790+ const result = await strategy . selectTools ( context ) ;
791+
792+ expect ( result . gradioSpaceTools ) . toBeDefined ( ) ;
793+ expect ( result . gradioSpaceTools ) . toHaveLength ( 2 ) ;
794+ expect ( result . gradioSpaceTools ?. map ( s => s . name ) ) . toEqual ( [
795+ 'user/space-one' ,
796+ 'org/space-two' ,
797+ ] ) ;
798+ } ) ;
799+ } ) ;
684800} ) ;
0 commit comments