Path: blob/main/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsBanner.ts
13406 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 { $, addDisposableListener } from '../../../../../base/browser/dom.js';6import { DisposableStore } from '../../../../../base/common/lifecycle.js';7import { localize } from '../../../../../nls.js';8import { ICommandService, CommandsRegistry } from '../../../../../platform/commands/common/commands.js';9import { IProductService } from '../../../../../platform/product/common/productService.js';10import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js';1112import { OPEN_AGENTS_WINDOW_COMMAND_ID } from '../../common/constants.js';131415type AgentsBannerClickedEvent = {16source: string;17action: string;18};1920type AgentsBannerClickedClassification = {21source: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Where the banner was clicked from.' };22action: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The action taken on the banner.' };23owner: 'benibenj';24comment: 'Tracks clicks on the agents app banner across welcome pages.';25};2627export interface IAgentsBannerResult {28readonly element: HTMLElement;29readonly disposables: DisposableStore;30}3132/**33* Returns whether the agents banner can be shown.34* The banner requires the `workbench.action.openAgentsWindow` command35* to be registered (desktop builds only) and is limited to Insiders quality.36*/37export function canShowAgentsBanner(productService: IProductService): boolean {38return productService.quality !== 'stable'39&& !!CommandsRegistry.getCommand(OPEN_AGENTS_WINDOW_COMMAND_ID);40}4142export interface IAgentsBannerOptions {43/** Dot-separated CSS classes for the banner container (e.g. 'my-banner' or 'foo.bar'). */44readonly cssClass: string;45/** Identifies where the banner is displayed (e.g. 'welcomePage', 'agentSessionsWelcome'). */46readonly source: string;47/** Override the default button label. */48readonly label?: string;49/** Optional callback invoked when the banner button is clicked. */50readonly onButtonClick?: () => void;51}5253/**54* Creates a banner that promotes the Agents app.55* The banner contains a button that opens the Agents window.56*/57export function createAgentsBanner(58options: IAgentsBannerOptions,59commandService: ICommandService,60telemetryService: ITelemetryService,61): IAgentsBannerResult {62const disposables = new DisposableStore();63const label = options.label ?? localize('agentsBanner.tryAgentsAppLabel', "Try out the new Agents app");6465const button = $('button.agents-banner-button', {66title: label,67},68$('.codicon.codicon-agent.icon-widget'),69$('span.category-title', {}, label),70);71disposables.add(addDisposableListener(button, 'click', () => {72options.onButtonClick?.();73telemetryService.publicLog2<AgentsBannerClickedEvent, AgentsBannerClickedClassification>('agentsBanner.clicked', { source: options.source, action: 'openAgentsWindow' });74commandService.executeCommand(OPEN_AGENTS_WINDOW_COMMAND_ID, { forceNewWindow: true });75}));7677const element = $(`.${options.cssClass}`, {}, button);7879return { element, disposables };80}818283