Skip to content

Commit 09bc257

Browse files
committed
Pass IChatEndpoint in getEnabledTools for calling tools' alternativeDefinition
1 parent fd64a94 commit 09bc257

File tree

11 files changed

+25
-17
lines changed

11 files changed

+25
-17
lines changed

src/extension/intents/node/agentIntent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const getAgentTools = (instaService: IInstantiationService, request: vsco
109109
allowTools[ToolName.MultiReplaceString] = false;
110110
}
111111

112-
const tools = toolsService.getEnabledTools(request, tool => {
112+
const tools = toolsService.getEnabledTools(request, model, tool => {
113113
if (typeof allowTools[tool.name] === 'boolean') {
114114
return allowTools[tool.name];
115115
}

src/extension/intents/node/askAgentIntent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ const getTools = (instaService: IInstantiationService, request: vscode.ChatReque
3636
instaService.invokeFunction(async accessor => {
3737
const toolsService = accessor.get<IToolsService>(IToolsService);
3838
const lookForTags = new Set<string>(['vscode_codesearch']);
39+
const endpointProvider = accessor.get<IEndpointProvider>(IEndpointProvider);
40+
const model = await endpointProvider.getChatEndpoint(request);
3941

4042
// Special case...
4143
// Since AskAgent currently has no tool picker, have to duplicate the toolReference logic here.
4244
// When it's no longer experimental, it should be a custom mode, have a tool picker, etc.
4345
// And must return boolean to avoid falling back on other logic that we don't want, like the `extension_installed_by_tool` check.
44-
return toolsService.getEnabledTools(request, tool => tool.tags.some(tag => lookForTags.has(tag)) || request.toolReferences.some(ref => ref.name === tool.name));
46+
return toolsService.getEnabledTools(request, model, tool => tool.tags.some(tag => lookForTags.has(tag)) || request.toolReferences.some(ref => ref.name === tool.name));
4547
});
4648

4749
export class AskAgentIntent implements IIntent {

src/extension/intents/node/editCodeIntent2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const getTools = (instaService: IInstantiationService, request: vscode.ChatReque
5757
lookForTools.add(ToolName.RunNotebookCell);
5858
}
5959

60-
return toolsService.getEnabledTools(request, tool => lookForTools.has(tool.name));
60+
return toolsService.getEnabledTools(request, model, tool => lookForTools.has(tool.name));
6161
});
6262

6363
export class EditCode2Intent extends EditCodeIntent {

src/extension/intents/node/notebookEditorIntent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const getTools = (instaService: IInstantiationService, request: vscode.ChatReque
5959
lookForTools.add(ToolName.RunNotebookCell);
6060
lookForTools.add(ToolName.ReadCellOutput);
6161

62-
return toolsService.getEnabledTools(request, tool => lookForTools.has(tool.name) || tool.tags.includes('notebooks'));
62+
return toolsService.getEnabledTools(request, model, tool => lookForTools.has(tool.name) || tool.tags.includes('notebooks'));
6363
});
6464

6565
export class NotebookEditorIntent extends EditCodeIntent {

src/extension/intents/node/vscodeIntent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class VSCodeIntentInvocation extends RendererIntentInvocation implements IIntent
5151
}
5252

5353
getAvailableTools(): vscode.LanguageModelToolInformation[] | Promise<vscode.LanguageModelToolInformation[]> | undefined {
54-
return this.toolsService.getEnabledTools(this.request, tool =>
54+
return this.toolsService.getEnabledTools(this.request, this.endpoint, tool =>
5555
tool.name === 'vscode_searchExtensions_internal' ||
5656
tool.name === ToolName.VSCodeAPI
5757
);

src/extension/prompt/node/codebaseToolCalling.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export class CodebaseToolCallingLoop extends ToolCallingLoop<ICodebaseToolCallin
6464
}
6565

6666
protected async getAvailableTools(): Promise<LanguageModelToolInformation[]> {
67-
return this.toolsService.getEnabledTools(this.options.request, tool => tool.tags.includes('vscode_codesearch'));
67+
const endpoint = await this.getEndpoint(this.options.request);
68+
return this.toolsService.getEnabledTools(this.options.request, endpoint, tool => tool.tags.includes('vscode_codesearch'));
6869
}
6970

7071
protected async fetch({ messages, finishedCb, requestOptions }: ToolCallingLoopFetchOptions, token: CancellationToken): Promise<ChatResponse> {

src/extension/tools/common/toolsRegistry.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import type * as vscode from 'vscode';
7+
import { IChatEndpoint } from '../../../platform/networking/common/networking';
78
import { URI } from '../../../util/vs/base/common/uri';
89
import { IBuildPromptContext } from '../../prompt/common/intents';
910
import { ToolName } from './toolNames';
@@ -54,10 +55,10 @@ export interface ICopilotTool<T> extends vscode.LanguageModelTool<T> {
5455
* parameters because the alternative definition will only be applied within
5556
* the Copilot extension, not other extensions' usages via `vscode.lm.tools`.
5657
*
57-
* @param modelInfo Optional information about the currently selected language model.
58-
* If provided, allows customizing the tool definition per model.
58+
* @param endpoint Optional information about the currently selected language model endpoint.
59+
* If provided, allows customizing the tool definition per endpoint.
5960
*/
60-
alternativeDefinition?(modelInfo?: vscode.LanguageModelChat): vscode.LanguageModelToolInformation | undefined;
61+
alternativeDefinition?(endpoint?: IChatEndpoint): vscode.LanguageModelToolInformation | undefined;
6162
}
6263

6364

src/extension/tools/common/toolsService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Ajv, { ValidateFunction } from 'ajv';
77
import type * as vscode from 'vscode';
88
import { ILogService } from '../../../platform/log/common/logService';
9+
import { IChatEndpoint } from '../../../platform/networking/common/networking';
910
import { LRUCache } from '../../../util/common/cache';
1011
import { createServiceIdentifier } from '../../../util/common/services';
1112
import { Emitter, Event } from '../../../util/vs/base/common/event';
@@ -67,7 +68,7 @@ export interface IToolsService {
6768
* pass `filter` function that can explicitl enable (true) or disable (false)
6869
* a tool, or use the default logic (undefined).
6970
*/
70-
getEnabledTools(request: vscode.ChatRequest, filter?: (tool: vscode.LanguageModelToolInformation) => boolean | undefined): vscode.LanguageModelToolInformation[];
71+
getEnabledTools(request: vscode.ChatRequest, endpoint: IChatEndpoint, filter?: (tool: vscode.LanguageModelToolInformation) => boolean | undefined): vscode.LanguageModelToolInformation[];
7172
}
7273

7374
/**
@@ -160,7 +161,7 @@ export abstract class BaseToolsService extends Disposable implements IToolsServi
160161
abstract invokeTool(name: string, options: vscode.LanguageModelToolInvocationOptions<Object>, token: vscode.CancellationToken): Thenable<vscode.LanguageModelToolResult2>;
161162
abstract getTool(name: string): vscode.LanguageModelToolInformation | undefined;
162163
abstract getToolByToolReferenceName(name: string): vscode.LanguageModelToolInformation | undefined;
163-
abstract getEnabledTools(request: vscode.ChatRequest, filter?: (tool: vscode.LanguageModelToolInformation) => boolean | undefined): vscode.LanguageModelToolInformation[];
164+
abstract getEnabledTools(request: vscode.ChatRequest, endpoint: IChatEndpoint, filter?: (tool: vscode.LanguageModelToolInformation) => boolean | undefined): vscode.LanguageModelToolInformation[];
164165

165166
constructor(
166167
@ILogService private readonly logService: ILogService

src/extension/tools/node/test/testToolsService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type * as vscode from 'vscode';
77
import { packageJson } from '../../../../platform/env/common/packagejson';
88
import { ILanguageDiagnosticsService } from '../../../../platform/languages/common/languageDiagnosticsService';
99
import { ILogService } from '../../../../platform/log/common/logService';
10+
import { IChatEndpoint } from '../../../../platform/networking/common/networking';
1011
import { CancellationToken } from '../../../../util/vs/base/common/cancellation';
1112
import { CancellationError } from '../../../../util/vs/base/common/errors';
1213
import { Iterable } from '../../../../util/vs/base/common/iterator';
@@ -139,7 +140,7 @@ export class TestToolsService extends BaseToolsService implements IToolsService
139140
return undefined;
140141
}
141142

142-
getEnabledTools(request: vscode.ChatRequest, filter?: (tool: LanguageModelToolInformation) => boolean | undefined): LanguageModelToolInformation[] {
143+
getEnabledTools(request: vscode.ChatRequest, endpoint: IChatEndpoint, filter?: (tool: LanguageModelToolInformation) => boolean | undefined): LanguageModelToolInformation[] {
143144
const toolMap = new Map(this.tools.map(t => [t.name, t]));
144145

145146
const packageJsonTools = getPackagejsonToolsForTest();
@@ -148,7 +149,7 @@ export class TestToolsService extends BaseToolsService implements IToolsService
148149
// Apply model-specific alternative if available via alternativeDefinition
149150
const owned = this._copilotTools.get(getToolName(tool.name) as ToolName);
150151
if (owned?.value?.alternativeDefinition) {
151-
const alternative = owned.value.alternativeDefinition(request.model);
152+
const alternative = owned.value.alternativeDefinition(endpoint);
152153
if (alternative) {
153154
return alternative;
154155
}

src/extension/tools/vscode-node/toolsService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import { ILogService } from '../../../platform/log/common/logService';
8+
import { IChatEndpoint } from '../../../platform/networking/common/networking';
89
import { equals as arraysEqual } from '../../../util/vs/base/common/arrays';
910
import { Lazy } from '../../../util/vs/base/common/lazy';
1011
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
@@ -91,15 +92,15 @@ export class ToolsService extends BaseToolsService {
9192
throw new Error('This method for tests only');
9293
}
9394

94-
getEnabledTools(request: vscode.ChatRequest, filter?: (tool: vscode.LanguageModelToolInformation) => boolean | undefined): vscode.LanguageModelToolInformation[] {
95+
getEnabledTools(request: vscode.ChatRequest, endpoint: IChatEndpoint, filter?: (tool: vscode.LanguageModelToolInformation) => boolean | undefined): vscode.LanguageModelToolInformation[] {
9596
const toolMap = new Map(this.tools.map(t => [t.name, t]));
9697

9798
return this.tools
9899
.map(tool => {
99100
// Apply model-specific alternative if available via alternativeDefinition
100101
const owned = this._copilotTools.value.get(getToolName(tool.name) as ToolName);
101102
if (owned?.alternativeDefinition) {
102-
const alternative = owned.alternativeDefinition(request.model);
103+
const alternative = owned.alternativeDefinition(endpoint);
103104
if (alternative) {
104105
return alternative;
105106
}

0 commit comments

Comments
 (0)