@@ -10,13 +10,17 @@ import { equals as arraysEqual } from '../../../util/vs/base/common/arrays';
1010import { Lazy } from '../../../util/vs/base/common/lazy' ;
1111import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation' ;
1212import { getContributedToolName , getToolName , mapContributedToolNamesInSchema , mapContributedToolNamesInString , ToolName } from '../common/toolNames' ;
13- import { ICopilotTool , ToolRegistry } from '../common/toolsRegistry' ;
13+ import { ICopilotTool , ICopilotToolExtension , ToolRegistry } from '../common/toolsRegistry' ;
1414import { BaseToolsService } from '../common/toolsService' ;
1515
1616export class ToolsService extends BaseToolsService {
1717 declare _serviceBrand : undefined ;
1818
1919 private readonly _copilotTools : Lazy < Map < ToolName , ICopilotTool < any > > > ;
20+
21+ // Extensions to override definitions for existing tools.
22+ private readonly _toolExtensions : Lazy < Map < ToolName , ICopilotToolExtension < any > > > ;
23+
2024 private readonly _contributedToolCache : {
2125 input : readonly vscode . LanguageModelToolInformation [ ] ;
2226 output : readonly vscode . LanguageModelToolInformation [ ] ;
@@ -43,7 +47,7 @@ export class ToolsService extends BaseToolsService {
4347 } )
4448 . map ( tool => {
4549 const owned = this . _copilotTools . value . get ( getToolName ( tool . name ) as ToolName ) ;
46- return owned ?. alternativeDefinition ?.( ) ?? tool ;
50+ return owned ?. alternativeDefinition ?.( tool ) ?? tool ;
4751 } ) ;
4852
4953 const result : vscode . LanguageModelToolInformation [ ] = contributedTools . map ( tool => {
@@ -71,6 +75,7 @@ export class ToolsService extends BaseToolsService {
7175 ) {
7276 super ( logService ) ;
7377 this . _copilotTools = new Lazy ( ( ) => new Map ( ToolRegistry . getTools ( ) . map ( t => [ t . toolName , instantiationService . createInstance ( t ) ] as const ) ) ) ;
78+ this . _toolExtensions = new Lazy ( ( ) => new Map ( ToolRegistry . getToolExtensions ( ) . map ( t => [ t . toolName , instantiationService . createInstance ( t ) ] as const ) ) ) ;
7479 }
7580
7681 invokeTool ( name : string | ToolName , options : vscode . LanguageModelToolInvocationOptions < Object > , token : vscode . CancellationToken ) : Thenable < vscode . LanguageModelToolResult | vscode . LanguageModelToolResult2 > {
@@ -99,13 +104,17 @@ export class ToolsService extends BaseToolsService {
99104 . map ( tool => {
100105 // Apply model-specific alternative if available via alternativeDefinition
101106 const owned = this . _copilotTools . value . get ( getToolName ( tool . name ) as ToolName ) ;
107+ let resultTool = tool ;
102108 if ( owned ?. alternativeDefinition ) {
103- const alternative = owned . alternativeDefinition ( endpoint ) ;
104- if ( alternative ) {
105- return alternative ;
106- }
109+ resultTool = owned . alternativeDefinition ( resultTool , endpoint ) ;
107110 }
108- return tool ;
111+
112+ const extension = this . _toolExtensions . value . get ( getToolName ( tool . name ) as ToolName ) ;
113+ if ( extension ?. alternativeDefinition ) {
114+ resultTool = extension . alternativeDefinition ( resultTool , endpoint ) ;
115+ }
116+
117+ return resultTool ;
109118 } )
110119 . filter ( tool => {
111120 // 0. Check if the tool was disabled via the tool picker. If so, it must be disabled here
0 commit comments