Skip to content

Commit aae3af1

Browse files
authored
Hide models contributed by background agents (microsoft#295669)
* Hide models contributed by background agents * Updates * Add additioknal tests
1 parent 44724dc commit aae3af1

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,8 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
21722172
this.setCurrentLanguageModel(model);
21732173
this.renderAttachedContext();
21742174
},
2175-
getModels: () => this.getModels()
2175+
getModels: () => this.getModels(),
2176+
canManageModels: () => !this.getCurrentSessionType()
21762177
};
21772178
return this.modelWidget = this.instantiationService.createInstance(ModelPickerActionItem, action, undefined, itemDelegate, pickerOptions);
21782179
} else if (action.id === OpenModePickerAction.ID && action instanceof MenuItemAction) {

src/vs/workbench/contrib/chat/browser/widget/input/modelPickerActionItem.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface IModelPickerDelegate {
2929
readonly currentModel: IObservable<ILanguageModelChatMetadataAndIdentifier | undefined>;
3030
setModel(model: ILanguageModelChatMetadataAndIdentifier): void;
3131
getModels(): ILanguageModelChatMetadataAndIdentifier[];
32+
canManageModels(): boolean;
3233
}
3334

3435
type ChatModelChangeClassification = {
@@ -165,9 +166,10 @@ export class ModelPickerActionItem extends ChatInputPickerActionViewItem {
165166
run: () => { }
166167
};
167168

169+
const baseActionBarActionProvider = getModelPickerActionBarActionProvider(commandService, chatEntitlementService, productService);
168170
const modelPickerActionWidgetOptions: Omit<IActionWidgetDropdownOptions, 'label' | 'labelRenderer'> = {
169171
actionProvider: modelDelegateToWidgetActionsProvider(delegate, telemetryService, pickerOptions),
170-
actionBarActionProvider: getModelPickerActionBarActionProvider(commandService, chatEntitlementService, productService),
172+
actionBarActionProvider: { getActions: () => delegate.canManageModels() ? baseActionBarActionProvider.getActions() : [] },
171173
reporter: { id: 'ChatModelPicker', name: 'ChatModelPicker', includeOptions: true },
172174
};
173175

src/vs/workbench/contrib/chat/common/promptSyntax/languageProviders/promptHeaderAutocompletion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export class PromptHeaderAutocompletion implements CompletionItemProvider {
317317
const result = [];
318318
for (const model of this.languageModelsService.getLanguageModelIds()) {
319319
const metadata = this.languageModelsService.lookupLanguageModel(model);
320-
if (metadata && metadata.isUserSelectable !== false) {
320+
if (metadata && metadata.isUserSelectable !== false && !metadata.targetChatSessionType) {
321321
if (!agentModeOnly || ILanguageModelChatMetadata.suitableForAgentMode(metadata)) {
322322
result.push({
323323
name: ILanguageModelChatMetadata.asQualifiedName(metadata),

src/vs/workbench/contrib/chat/test/browser/promptSyntax/languageProviders/promptHeaderAutocompletion.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ suite('PromptHeaderAutocompletion', () => {
5656
{ id: 'mae-4', name: 'MAE 4', vendor: 'olama', version: '1.0', family: 'mae', modelPickerCategory: undefined, extension: new ExtensionIdentifier('a.b'), isUserSelectable: true, maxInputTokens: 8192, maxOutputTokens: 1024, capabilities: { agentMode: true, toolCalling: true }, isDefaultForLocation: { [ChatAgentLocation.Chat]: true } } satisfies ILanguageModelChatMetadata,
5757
{ id: 'mae-4.1', name: 'MAE 4.1', vendor: 'copilot', version: '1.0', family: 'mae', modelPickerCategory: undefined, extension: new ExtensionIdentifier('a.b'), isUserSelectable: true, maxInputTokens: 8192, maxOutputTokens: 1024, capabilities: { agentMode: true, toolCalling: true }, isDefaultForLocation: { [ChatAgentLocation.Chat]: true } } satisfies ILanguageModelChatMetadata,
5858
{ id: 'gpt-4', name: 'GPT 4', vendor: 'openai', version: '1.0', family: 'gpt', modelPickerCategory: undefined, extension: new ExtensionIdentifier('a.b'), isUserSelectable: true, maxInputTokens: 8192, maxOutputTokens: 1024, capabilities: { agentMode: false, toolCalling: true }, isDefaultForLocation: { [ChatAgentLocation.Chat]: true } } satisfies ILanguageModelChatMetadata,
59+
{ id: 'bg-agent-model', name: 'BG Agent Model', vendor: 'copilot', version: '1.0', family: 'bg', modelPickerCategory: undefined, extension: new ExtensionIdentifier('a.b'), isUserSelectable: true, maxInputTokens: 8192, maxOutputTokens: 1024, capabilities: { agentMode: true, toolCalling: true }, isDefaultForLocation: { [ChatAgentLocation.Chat]: true }, targetChatSessionType: 'background' } satisfies ILanguageModelChatMetadata,
5960
];
6061

6162
instaService.stub(ILanguageModelsService, {
@@ -361,6 +362,33 @@ suite('PromptHeaderAutocompletion', () => {
361362
{ label: 'true', result: 'disable-model-invocation: true' },
362363
].sort(sortByLabel));
363364
});
365+
366+
test('exclude models with targetChatSessionType from agent model completions', async () => {
367+
const content = [
368+
'---',
369+
'description: "Test"',
370+
'model: |',
371+
'---',
372+
].join('\n');
373+
374+
const actual = await getCompletions(content, PromptsType.agent);
375+
const labels = actual.map(a => a.label);
376+
// BG Agent Model has targetChatSessionType set, so it should be excluded
377+
assert.ok(!labels.includes('BG Agent Model (copilot)'), 'Models with targetChatSessionType should be excluded from agent model completions');
378+
});
379+
380+
test('exclude models with targetChatSessionType from agent model array completions', async () => {
381+
const content = [
382+
'---',
383+
'description: "Test"',
384+
'model: [|]',
385+
'---',
386+
].join('\n');
387+
388+
const actual = await getCompletions(content, PromptsType.agent);
389+
const labels = actual.map(a => a.label);
390+
assert.ok(!labels.includes('BG Agent Model (copilot)'), 'Models with targetChatSessionType should be excluded from agent model array completions');
391+
});
364392
});
365393

366394
suite('claude agent header completions', () => {
@@ -546,5 +574,18 @@ suite('PromptHeaderAutocompletion', () => {
546574
{ label: 'GPT 4 (openai)', result: 'model: GPT 4 (openai)' },
547575
].sort(sortByLabel));
548576
});
577+
578+
test('exclude models with targetChatSessionType from prompt model completions', async () => {
579+
const content = [
580+
'---',
581+
'description: "Test"',
582+
'model: |',
583+
'---',
584+
].join('\n');
585+
586+
const actual = await getCompletions(content, PromptsType.prompt);
587+
const labels = actual.map(a => a.label);
588+
assert.ok(!labels.includes('BG Agent Model (copilot)'), 'Models with targetChatSessionType should be excluded from prompt model completions');
589+
});
549590
});
550591
});

0 commit comments

Comments
 (0)