Skip to content

Commit 250c8e9

Browse files
committed
Show old UX for MCP for now
1 parent 3a97641 commit 250c8e9

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

src/vs/workbench/contrib/chat/browser/chatContentParts/toolInvocationParts/chatToolInvocationPart.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Emitter } from '../../../../../../base/common/event.js';
88
import { Disposable, DisposableStore, IDisposable } from '../../../../../../base/common/lifecycle.js';
99
import { IMarkdownRenderer } from '../../../../../../platform/markdown/browser/markdownRenderer.js';
1010
import { IInstantiationService } from '../../../../../../platform/instantiation/common/instantiation.js';
11-
import { IChatToolInvocation, IChatToolInvocationSerialized } from '../../../common/chatService.js';
11+
import { IChatToolInvocation, IChatToolInvocationSerialized, ToolConfirmKind } from '../../../common/chatService.js';
1212
import { IChatRendererContent } from '../../../common/chatViewModel.js';
1313
import { CodeBlockModelCollection } from '../../../common/codeBlockModelCollection.js';
1414
import { isToolResultInputOutputDetails, isToolResultOutputDetails, ToolInvocationPresentation } from '../../../common/languageModelToolsService.js';
@@ -27,6 +27,9 @@ import { ChatToolOutputSubPart } from './chatToolOutputPart.js';
2727
import { ChatToolPostExecuteConfirmationPart } from './chatToolPostExecuteConfirmationPart.js';
2828
import { ChatToolProgressSubPart } from './chatToolProgressPart.js';
2929
import { autorun } from '../../../../../../base/common/observable.js';
30+
import { ChatMcpServersInteractionContentPart } from '../chatMcpServersInteractionContentPart.js';
31+
import { localize } from '../../../../../../nls.js';
32+
import { markdownCommandLink, MarkdownString } from '../../../../../../base/common/htmlContent.js';
3033

3134
export class ChatToolInvocationPart extends Disposable implements IChatContentPart {
3235
public readonly domNode: HTMLElement;
@@ -92,11 +95,65 @@ export class ChatToolInvocationPart extends Disposable implements IChatContentPa
9295
partStore.add(this.subPart.onDidChangeHeight(() => this._onDidChangeHeight.fire()));
9396
partStore.add(this.subPart.onNeedsRerender(render));
9497

98+
// todo@connor4312: Move MCP spinner to left to get consistent auto approval presentation
99+
if (this.subPart instanceof ChatInputOutputMarkdownProgressPart) {
100+
const approval = this.createApprovalMessage();
101+
if (approval) {
102+
this.domNode.appendChild(approval);
103+
}
104+
}
105+
95106
this._onDidChangeHeight.fire();
96107
};
97108
render();
98109
}
99110

111+
/** @deprecated Approval should be centrally managed by passing tool invocation ChatProgressContentPart */
112+
private get autoApproveMessageContent() {
113+
const reason = IChatToolInvocation.executionConfirmedOrDenied(this.toolInvocation);
114+
if (!reason || typeof reason === 'boolean') {
115+
return;
116+
}
117+
118+
let md: string;
119+
switch (reason.type) {
120+
case ToolConfirmKind.Setting:
121+
md = localize('chat.autoapprove.setting', 'Auto approved by {0}', markdownCommandLink({ title: '`' + reason.id + '`', id: 'workbench.action.openSettings', arguments: [reason.id] }, false));
122+
break;
123+
case ToolConfirmKind.LmServicePerTool:
124+
md = reason.scope === 'session'
125+
? localize('chat.autoapprove.lmServicePerTool.session', 'Auto approved for this session')
126+
: reason.scope === 'workspace'
127+
? localize('chat.autoapprove.lmServicePerTool.workspace', 'Auto approved for this workspace')
128+
: localize('chat.autoapprove.lmServicePerTool.profile', 'Auto approved for this profile');
129+
md += ' (' + markdownCommandLink({ title: localize('edit', 'Edit'), id: 'workbench.action.chat.editToolApproval', arguments: [this.toolInvocation.toolId] }) + ')';
130+
break;
131+
case ToolConfirmKind.UserAction:
132+
case ToolConfirmKind.Denied:
133+
case ToolConfirmKind.ConfirmationNotNeeded:
134+
default:
135+
return;
136+
}
137+
138+
139+
return md;
140+
}
141+
142+
/** @deprecated Approval should be centrally managed by passing tool invocation ChatProgressContentPart */
143+
private createApprovalMessage(): HTMLElement | undefined {
144+
const md = this.autoApproveMessageContent;
145+
if (!md) {
146+
return undefined;
147+
}
148+
149+
const markdownString = new MarkdownString('_' + md + '_', { isTrusted: true });
150+
const result = this.renderer.render(markdownString);
151+
this._register(result);
152+
result.element.classList.add('chat-tool-approval-message');
153+
154+
return result.element;
155+
}
156+
100157
private createToolInvocationSubPart(): BaseChatToolInvocationSubPart {
101158
if (this.toolInvocation.kind === 'toolInvocation') {
102159
if (this.toolInvocation.toolSpecificData?.kind === 'extensions') {

0 commit comments

Comments
 (0)