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