@@ -94,39 +94,51 @@ export class ToolsService extends BaseToolsService {
9494 getEnabledTools ( request : vscode . ChatRequest , filter ?: ( tool : vscode . LanguageModelToolInformation ) => boolean | undefined ) : vscode . LanguageModelToolInformation [ ] {
9595 const toolMap = new Map ( this . tools . map ( t => [ t . name , t ] ) ) ;
9696
97- return this . tools . filter ( tool => {
98- // 0. Check if the tool was disabled via the tool picker. If so, it must be disabled here
99- const toolPickerSelection = request . tools . get ( getContributedToolName ( tool . name ) ) ;
100- if ( toolPickerSelection === false ) {
101- return false ;
102- }
103-
104- // 1. Check for what the consumer wants explicitly
105- const explicit = filter ?.( tool ) ;
106- if ( explicit !== undefined ) {
107- return explicit ;
108- }
109-
110- // 2. Check if the request's tools explicitly asked for this tool to be enabled
111- for ( const ref of request . toolReferences ) {
112- const usedTool = toolMap . get ( ref . name ) ;
113- if ( usedTool ?. tags . includes ( `enable_other_tool_${ tool . name } ` ) ) {
114- return true ;
97+ return this . tools
98+ . map ( tool => {
99+ // Apply model-specific alternative if available via alternativeDefinition
100+ const owned = this . _copilotTools . value . get ( getToolName ( tool . name ) as ToolName ) ;
101+ if ( owned ?. alternativeDefinition ) {
102+ const alternative = owned . alternativeDefinition ( request . model ) ;
103+ if ( alternative ) {
104+ return alternative ;
105+ }
106+ }
107+ return tool ;
108+ } )
109+ . filter ( tool => {
110+ // 0. Check if the tool was disabled via the tool picker. If so, it must be disabled here
111+ const toolPickerSelection = request . tools . get ( getContributedToolName ( tool . name ) ) ;
112+ if ( toolPickerSelection === false ) {
113+ return false ;
115114 }
116- }
117115
118- // 3. If this tool is neither enabled nor disabled, then consumer didn't have opportunity to enable/disable it.
119- // This can happen when a tool is added during another tool call (e.g. installExt tool installs an extension that contributes tools).
120- if ( toolPickerSelection === undefined && tool . tags . includes ( 'extension_installed_by_tool' ) ) {
121- return true ;
122- }
116+ // 1. Check for what the consumer wants explicitly
117+ const explicit = filter ?. ( tool ) ;
118+ if ( explicit !== undefined ) {
119+ return explicit ;
120+ }
123121
124- // Tool was enabled via tool picker
125- if ( toolPickerSelection === true ) {
126- return true ;
127- }
122+ // 2. Check if the request's tools explicitly asked for this tool to be enabled
123+ for ( const ref of request . toolReferences ) {
124+ const usedTool = toolMap . get ( ref . name ) ;
125+ if ( usedTool ?. tags . includes ( `enable_other_tool_${ tool . name } ` ) ) {
126+ return true ;
127+ }
128+ }
128129
129- return false ;
130- } ) ;
130+ // 3. If this tool is neither enabled nor disabled, then consumer didn't have opportunity to enable/disable it.
131+ // This can happen when a tool is added during another tool call (e.g. installExt tool installs an extension that contributes tools).
132+ if ( toolPickerSelection === undefined && tool . tags . includes ( 'extension_installed_by_tool' ) ) {
133+ return true ;
134+ }
135+
136+ // Tool was enabled via tool picker
137+ if ( toolPickerSelection === true ) {
138+ return true ;
139+ }
140+
141+ return false ;
142+ } ) ;
131143 }
132144}
0 commit comments