Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/chatFollowups.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as dom from '../../../../base/browser/dom.js';
7
import { Button, IButtonStyles } from '../../../../base/browser/ui/button/button.js';
8
import { MarkdownString } from '../../../../base/common/htmlContent.js';
9
import { Disposable } from '../../../../base/common/lifecycle.js';
10
import { localize } from '../../../../nls.js';
11
import { IChatAgentService } from '../common/chatAgents.js';
12
import { formatChatQuestion } from '../common/chatParserTypes.js';
13
import { IChatFollowup } from '../common/chatService.js';
14
import { ChatAgentLocation } from '../common/constants.js';
15
16
const $ = dom.$;
17
18
export class ChatFollowups<T extends IChatFollowup> extends Disposable {
19
constructor(
20
container: HTMLElement,
21
followups: T[],
22
private readonly location: ChatAgentLocation,
23
private readonly options: IButtonStyles | undefined,
24
private readonly clickHandler: (followup: T) => void,
25
@IChatAgentService private readonly chatAgentService: IChatAgentService
26
) {
27
super();
28
29
const followupsContainer = dom.append(container, $('.interactive-session-followups'));
30
followups.forEach(followup => this.renderFollowup(followupsContainer, followup));
31
}
32
33
private renderFollowup(container: HTMLElement, followup: T): void {
34
35
if (!this.chatAgentService.getDefaultAgent(this.location)) {
36
// No default agent yet, which affects how followups are rendered, so can't render this yet
37
return;
38
}
39
40
const tooltipPrefix = formatChatQuestion(this.chatAgentService, this.location, '', followup.agentId, followup.subCommand);
41
if (tooltipPrefix === undefined) {
42
return;
43
}
44
45
const baseTitle = followup.kind === 'reply' ?
46
(followup.title || followup.message)
47
: followup.title;
48
const message = followup.kind === 'reply' ? followup.message : followup.title;
49
const tooltip = (tooltipPrefix +
50
('tooltip' in followup && followup.tooltip || message)).trim();
51
const button = this._register(new Button(container, { ...this.options, title: tooltip }));
52
if (followup.kind === 'reply') {
53
button.element.classList.add('interactive-followup-reply');
54
} else if (followup.kind === 'command') {
55
button.element.classList.add('interactive-followup-command');
56
}
57
button.element.ariaLabel = localize('followUpAriaLabel', "Follow up question: {0}", baseTitle);
58
button.label = new MarkdownString(baseTitle);
59
60
this._register(button.onDidClick(() => this.clickHandler(followup)));
61
}
62
}
63
64