Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsBanner.ts
13406 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 { $, 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
import { OPEN_AGENTS_WINDOW_COMMAND_ID } from '../../common/constants.js';
14
15
16
type AgentsBannerClickedEvent = {
17
source: string;
18
action: string;
19
};
20
21
type AgentsBannerClickedClassification = {
22
source: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Where the banner was clicked from.' };
23
action: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The action taken on the banner.' };
24
owner: 'benibenj';
25
comment: 'Tracks clicks on the agents app banner across welcome pages.';
26
};
27
28
export interface IAgentsBannerResult {
29
readonly element: HTMLElement;
30
readonly disposables: DisposableStore;
31
}
32
33
/**
34
* Returns whether the agents banner can be shown.
35
* The banner requires the `workbench.action.openAgentsWindow` command
36
* to be registered (desktop builds only) and is limited to Insiders quality.
37
*/
38
export function canShowAgentsBanner(productService: IProductService): boolean {
39
return productService.quality !== 'stable'
40
&& !!CommandsRegistry.getCommand(OPEN_AGENTS_WINDOW_COMMAND_ID);
41
}
42
43
export interface IAgentsBannerOptions {
44
/** Dot-separated CSS classes for the banner container (e.g. 'my-banner' or 'foo.bar'). */
45
readonly cssClass: string;
46
/** Identifies where the banner is displayed (e.g. 'welcomePage', 'agentSessionsWelcome'). */
47
readonly source: string;
48
/** Override the default button label. */
49
readonly label?: string;
50
/** Optional callback invoked when the banner button is clicked. */
51
readonly onButtonClick?: () => void;
52
}
53
54
/**
55
* Creates a banner that promotes the Agents app.
56
* The banner contains a button that opens the Agents window.
57
*/
58
export function createAgentsBanner(
59
options: IAgentsBannerOptions,
60
commandService: ICommandService,
61
telemetryService: ITelemetryService,
62
): IAgentsBannerResult {
63
const disposables = new DisposableStore();
64
const label = options.label ?? localize('agentsBanner.tryAgentsAppLabel', "Try out the new Agents app");
65
66
const button = $('button.agents-banner-button', {
67
title: label,
68
},
69
$('.codicon.codicon-agent.icon-widget'),
70
$('span.category-title', {}, label),
71
);
72
disposables.add(addDisposableListener(button, 'click', () => {
73
options.onButtonClick?.();
74
telemetryService.publicLog2<AgentsBannerClickedEvent, AgentsBannerClickedClassification>('agentsBanner.clicked', { source: options.source, action: 'openAgentsWindow' });
75
commandService.executeCommand(OPEN_AGENTS_WINDOW_COMMAND_ID, { forceNewWindow: true });
76
}));
77
78
const element = $(`.${options.cssClass}`, {}, button);
79
80
return { element, disposables };
81
}
82
83