@@ -42,6 +42,7 @@ import {
4242 IdeSettings ,
4343 ModelDescription ,
4444 RangeInFile ,
45+ ToolCall ,
4546 type ContextItem ,
4647 type ContextItemId ,
4748 type IDE ,
@@ -147,13 +148,13 @@ export class Core {
147148
148149 MCPManagerSingleton . getInstance ( ) . onConnectionsRefreshed = ( ) => {
149150 void this . configHandler . reloadConfig ( ) ;
150-
151+
151152 // Refresh @mention dropdown submenu items for MCP providers
152153 const mcpManager = MCPManagerSingleton . getInstance ( ) ;
153154 const mcpProviderNames = Array . from ( mcpManager . connections . keys ( ) ) . map (
154- ( mcpId ) => `mcp-${ mcpId } `
155+ ( mcpId ) => `mcp-${ mcpId } ` ,
155156 ) ;
156-
157+
157158 if ( mcpProviderNames . length > 0 ) {
158159 this . messenger . send ( "refreshSubmenuItems" , {
159160 providers : mcpProviderNames ,
@@ -755,44 +756,9 @@ export class Core {
755756 return { url } ;
756757 } ) ;
757758
758- on ( "tools/call" , async ( { data : { toolCall } } ) => {
759- const { config } = await this . configHandler . loadConfig ( ) ;
760- if ( ! config ) {
761- throw new Error ( "Config not loaded" ) ;
762- }
763-
764- const tool = config . tools . find (
765- ( t ) => t . function . name === toolCall . function . name ,
766- ) ;
767-
768- if ( ! tool ) {
769- throw new Error ( `Tool ${ toolCall . function . name } not found` ) ;
770- }
771-
772- if ( ! config . selectedModelByRole . chat ) {
773- throw new Error ( "No chat model selected" ) ;
774- }
775-
776- // Define a callback for streaming output updates
777- const onPartialOutput = ( params : {
778- toolCallId : string ;
779- contextItems : ContextItem [ ] ;
780- } ) => {
781- this . messenger . send ( "toolCallPartialOutput" , params ) ;
782- } ;
783-
784- return await callTool ( tool , toolCall , {
785- config,
786- ide : this . ide ,
787- llm : config . selectedModelByRole . chat ,
788- fetch : ( url , init ) =>
789- fetchwithRequestOptions ( url , init , config . requestOptions ) ,
790- tool,
791- toolCallId : toolCall . id ,
792- onPartialOutput,
793- codeBaseIndexer : this . codeBaseIndexer ,
794- } ) ;
795- } ) ;
759+ on ( "tools/call" , async ( { data : { toolCall } } ) =>
760+ this . handleToolCall ( toolCall ) ,
761+ ) ;
796762
797763 on ( "isItemTooBig" , async ( { data : { item } } ) => {
798764 return this . isItemTooBig ( item ) ;
@@ -817,6 +783,45 @@ export class Core {
817783 } ) ;
818784 }
819785
786+ private async handleToolCall ( toolCall : ToolCall ) {
787+ const { config } = await this . configHandler . loadConfig ( ) ;
788+ if ( ! config ) {
789+ throw new Error ( "Config not loaded" ) ;
790+ }
791+
792+ const tool = config . tools . find (
793+ ( t ) => t . function . name === toolCall . function . name ,
794+ ) ;
795+
796+ if ( ! tool ) {
797+ throw new Error ( `Tool ${ toolCall . function . name } not found` ) ;
798+ }
799+
800+ if ( ! config . selectedModelByRole . chat ) {
801+ throw new Error ( "No chat model selected" ) ;
802+ }
803+
804+ // Define a callback for streaming output updates
805+ const onPartialOutput = ( params : {
806+ toolCallId : string ;
807+ contextItems : ContextItem [ ] ;
808+ } ) => {
809+ this . messenger . send ( "toolCallPartialOutput" , params ) ;
810+ } ;
811+
812+ return await callTool ( tool , toolCall , {
813+ config,
814+ ide : this . ide ,
815+ llm : config . selectedModelByRole . chat ,
816+ fetch : ( url , init ) =>
817+ fetchwithRequestOptions ( url , init , config . requestOptions ) ,
818+ tool,
819+ toolCallId : toolCall . id ,
820+ onPartialOutput,
821+ codeBaseIndexer : this . codeBaseIndexer ,
822+ } ) ;
823+ }
824+
820825 private async isItemTooBig ( item : ContextItemWithId ) {
821826 const { config } = await this . configHandler . loadConfig ( ) ;
822827 if ( ! config ) {
0 commit comments