|
| 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 { $, addDisposableListener } from '../../../../../base/browser/dom.js'; |
| 7 | +import { DisposableStore } from '../../../../../base/common/lifecycle.js'; |
| 8 | +import { localize } from '../../../../../nls.js'; |
| 9 | +import { ICommandService, CommandsRegistry } from '../../../../../platform/commands/common/commands.js'; |
| 10 | +import { IProductService } from '../../../../../platform/product/common/productService.js'; |
| 11 | +import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js'; |
| 12 | + |
| 13 | +const OPEN_AGENTS_WINDOW_COMMAND = 'workbench.action.openAgentsWindow'; |
| 14 | + |
| 15 | +type AgentsBannerClickedEvent = { |
| 16 | + source: string; |
| 17 | + action: string; |
| 18 | +}; |
| 19 | + |
| 20 | +type AgentsBannerClickedClassification = { |
| 21 | + source: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Where the banner was clicked from.' }; |
| 22 | + action: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The action taken on the banner.' }; |
| 23 | + owner: 'benibenj'; |
| 24 | + comment: 'Tracks clicks on the agents app banner across welcome pages.'; |
| 25 | +}; |
| 26 | + |
| 27 | +export interface IAgentsBannerResult { |
| 28 | + readonly element: HTMLElement; |
| 29 | + readonly disposables: DisposableStore; |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Returns whether the agents banner can be shown. |
| 34 | + * The banner requires the `workbench.action.openAgentsWindow` command |
| 35 | + * to be registered (desktop builds only) and is limited to Insiders quality. |
| 36 | + */ |
| 37 | +export function canShowAgentsBanner(productService: IProductService): boolean { |
| 38 | + return productService.quality !== 'stable' |
| 39 | + && !!CommandsRegistry.getCommand(OPEN_AGENTS_WINDOW_COMMAND); |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * Creates a banner that promotes the Agents app. |
| 44 | + * The banner contains a button that opens the Agents window. |
| 45 | + * |
| 46 | + * @param cssClass Dot-separated CSS classes for the banner container (e.g. 'my-banner' or 'foo.bar'). |
| 47 | + * @param source Identifies where the banner is displayed (e.g. 'welcomePage', 'agentSessionsWelcome'). |
| 48 | + * @param commandService Used to execute the open command. |
| 49 | + * @param telemetryService Used to log banner interactions. |
| 50 | + * @param onButtonClick Optional callback invoked when the banner button is clicked. |
| 51 | + */ |
| 52 | +export function createAgentsBanner( |
| 53 | + cssClass: string, |
| 54 | + source: string, |
| 55 | + commandService: ICommandService, |
| 56 | + telemetryService: ITelemetryService, |
| 57 | + onButtonClick?: () => void, |
| 58 | +): IAgentsBannerResult { |
| 59 | + const disposables = new DisposableStore(); |
| 60 | + |
| 61 | + const button = $('button.agents-banner-button', { |
| 62 | + title: localize('agentsBanner.tryAgentsApp', "Try out the new Agents app"), |
| 63 | + }, |
| 64 | + $('.codicon.codicon-agent.icon-widget'), |
| 65 | + $('span.category-title', {}, localize('agentsBanner.tryAgentsAppLabel', "Try out the new Agents app")), |
| 66 | + ); |
| 67 | + disposables.add(addDisposableListener(button, 'click', () => { |
| 68 | + onButtonClick?.(); |
| 69 | + telemetryService.publicLog2<AgentsBannerClickedEvent, AgentsBannerClickedClassification>('agentsBanner.clicked', { source, action: 'openAgentsWindow' }); |
| 70 | + commandService.executeCommand(OPEN_AGENTS_WINDOW_COMMAND, { forceNewWindow: true }); |
| 71 | + })); |
| 72 | + |
| 73 | + const element = $(`.${cssClass}`, {}, button); |
| 74 | + |
| 75 | + return { element, disposables }; |
| 76 | +} |
0 commit comments