Skip to content

Commit 5a4e405

Browse files
authored
Allow registering toolSets that reference disabled tools (microsoft#250167)
Needed for built-in toolsets that include some tools that are disabled by default
1 parent edb8128 commit 5a4e405

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

src/vs/workbench/contrib/chat/browser/languageModelToolsService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ export class LanguageModelToolsService extends Disposable implements ILanguageMo
160160
});
161161
}
162162

163-
getTools(): Iterable<Readonly<IToolData>> {
163+
getTools(includeDisabled?: boolean): Iterable<Readonly<IToolData>> {
164164
const toolDatas = Iterable.map(this._tools.values(), i => i.data);
165165
const extensionToolsEnabled = this._configurationService.getValue<boolean>(ChatConfiguration.ExtensionToolsEnabled);
166166
return Iterable.filter(
167167
toolDatas,
168168
toolData => {
169-
const satisfiesWhenClause = !toolData.when || this._contextKeyService.contextMatchesRules(toolData.when);
169+
const satisfiesWhenClause = includeDisabled || !toolData.when || this._contextKeyService.contextMatchesRules(toolData.when);
170170
const satisfiesExternalToolCheck = toolData.source.type !== 'extension' || !!extensionToolsEnabled;
171171
return satisfiesWhenClause && satisfiesExternalToolCheck;
172172
});
@@ -185,10 +185,10 @@ export class LanguageModelToolsService extends Disposable implements ILanguageMo
185185
}
186186
}
187187

188-
getToolByName(name: string): IToolData | undefined {
189-
for (const toolData of this.getTools()) {
190-
if (toolData.toolReferenceName === name) {
191-
return toolData;
188+
getToolByName(name: string, includeDisabled?: boolean): IToolData | undefined {
189+
for (const tool of this.getTools(!!includeDisabled)) {
190+
if (tool.toolReferenceName === name) {
191+
return tool;
192192
}
193193
}
194194
return undefined;

src/vs/workbench/contrib/chat/common/languageModelToolsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export interface ILanguageModelToolsService {
250250
registerToolImplementation(id: string, tool: IToolImpl): IDisposable;
251251
getTools(): Iterable<Readonly<IToolData>>;
252252
getTool(id: string): IToolData | undefined;
253-
getToolByName(name: string): IToolData | undefined;
253+
getToolByName(name: string, includeDisabled?: boolean): IToolData | undefined;
254254
invokeTool(invocation: IToolInvocation, countTokens: CountTokensCallback, token: CancellationToken): Promise<IToolResult>;
255255
setToolAutoConfirmation(toolId: string, scope: 'workspace' | 'profile' | 'memory', autoConfirm?: boolean): void;
256256
resetToolAutoConfirmation(): void;

src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export class LanguageModelToolsExtensionPointHandler implements IWorkbenchContri
316316
const toolSets: ToolSet[] = [];
317317

318318
for (const toolName of toolSet.tools) {
319-
const toolObj = languageModelToolsService.getToolByName(toolName);
319+
const toolObj = languageModelToolsService.getToolByName(toolName, true);
320320
if (toolObj) {
321321
tools.push(toolObj);
322322
continue;

src/vs/workbench/contrib/chat/test/browser/languageModelToolsService.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,44 @@ suite('LanguageModelToolsService', () => {
102102
assert.strictEqual(tools[1].id, 'testTool3');
103103
});
104104

105+
test('getToolByName', () => {
106+
contextKeyService.createKey('testKey', true);
107+
const toolData1: IToolData = {
108+
id: 'testTool1',
109+
toolReferenceName: 'testTool1',
110+
modelDescription: 'Test Tool 1',
111+
when: ContextKeyEqualsExpr.create('testKey', false),
112+
displayName: 'Test Tool',
113+
source: ToolDataSource.Internal,
114+
};
115+
116+
const toolData2: IToolData = {
117+
id: 'testTool2',
118+
toolReferenceName: 'testTool2',
119+
modelDescription: 'Test Tool 2',
120+
when: ContextKeyEqualsExpr.create('testKey', true),
121+
displayName: 'Test Tool',
122+
source: ToolDataSource.Internal,
123+
};
124+
125+
const toolData3: IToolData = {
126+
id: 'testTool3',
127+
toolReferenceName: 'testTool3',
128+
modelDescription: 'Test Tool 3',
129+
displayName: 'Test Tool',
130+
source: ToolDataSource.Internal,
131+
};
132+
133+
store.add(service.registerToolData(toolData1));
134+
store.add(service.registerToolData(toolData2));
135+
store.add(service.registerToolData(toolData3));
136+
137+
assert.strictEqual(service.getToolByName('testTool1'), undefined);
138+
assert.strictEqual(service.getToolByName('testTool1', true)?.id, 'testTool1');
139+
assert.strictEqual(service.getToolByName('testTool2')?.id, 'testTool2');
140+
assert.strictEqual(service.getToolByName('testTool3')?.id, 'testTool3');
141+
});
142+
105143
test('invokeTool', async () => {
106144
const toolData: IToolData = {
107145
id: 'testTool',

src/vs/workbench/contrib/chat/test/common/mockLanguageModelToolsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class MockLanguageModelToolsService implements ILanguageModelToolsService
4444
return undefined;
4545
}
4646

47-
getToolByName(name: string): IToolData | undefined {
47+
getToolByName(name: string, includeDisabled?: boolean): IToolData | undefined {
4848
return undefined;
4949
}
5050

0 commit comments

Comments
 (0)